Merge branch 'next'

This commit is contained in:
Michael Stapelberg 2011-11-11 22:49:20 +00:00
commit 0adbffb386
256 changed files with 10893 additions and 5120 deletions

1
.gitignore vendored
View File

@ -31,6 +31,7 @@ i3-input/i3-input
i3-nagbar/i3-nagbar
i3-msg/i3-msg
i3-config-wizard/i3-config-wizard
libi3/libi3.a
docs/*.html
docs/*.aux
docs/*.out

47
CMDMODE
View File

@ -1,47 +0,0 @@
---------------------
- Command mode
---------------------
This is the grammar for the 'command mode' (your configuration file
uses these commands, too).
left := <h> | <cursor-left>
right := <l> | <cursor-right>
up := <j> | <cursor-up>
down := <k> | <cursor-down>
where := <left|right|up|down> | <tag>
move := <m>
snap := <s>
cmd := [ <times> ] [ <move> | <snap> ] <where>
with := <w> { [ <times> ] <where> }+ <space> <cmd>
jump := [ "<window class>[/<window title>]" | <workspace> [ <column> <row> ] ]
focus := focus [ <times> | floating | tiling | ft ]
(travels the focus stack backwards, <times> number of times (by default 1).
So by specifying "focus 1" it selects the window which last had the focus
before you focused the current one window.
The following 3 special values are also valid:
'floating' (select the next floating window).
'tiling' (select the next tiling window).
'ft' (toggle tiling/floating: if the current window is floating,
select the next tiling window and vice-versa)
special := [ exec <path> | kill | exit | restart ]
input := [ <cmd> | <with> | <jump> | <focus> | <special> ]
you can cancel command mode by pressing escape anytime.
Some examples:
Select the window on the left:
h
Select the window two places on the left:
2h
Move window to the right:
ml
Move window and window on the bottom to the right:
wk ml

19
DEPENDS
View File

@ -11,7 +11,7 @@
│ xcb-proto │ 1.3 │ 1.6 │ http://xcb.freedesktop.org/dist/ │
│ libxcb │ 1.1.93 │ 1.7 │ http://xcb.freedesktop.org/dist/ │
│ xcb-util │ 0.3.3 │ 0.3.8 │ http://xcb.freedesktop.org/dist/ │
│ libev │ 3.0 │ 4.04 │ http://libev.schmorp.de/ │
│ libev │ 4.0 │ 4.04 │ http://libev.schmorp.de/ │
│ flex │ 2.5.35 │ 2.5.35 │ http://flex.sourceforge.net/ │
│ bison │ 2.4.1 │ 2.4.1 │ http://www.gnu.org/software/bison/ │
│ yajl │ 1.0.8 │ 2.0.1 │ http://lloyd.github.com/yajl/ │
@ -20,20 +20,13 @@
│ docbook-xml │ 4.5 │ 4.5 │ http://www.methods.co.nz/asciidoc/ │
│ libxcursor │ 1.1.11 │ 1.1.11 │ http://ftp.x.org/pub/current/src/lib/ │
│ Xlib │ 1.3.3 │ 1.4.3 │ http://ftp.x.org/pub/current/src/lib/ │
│ PCRE │ 8.12 │ 8.12 │ http://www.pcre.org/ │
│ libsn¹ │ 0.10 │ 0.12 │ http://freedesktop.org/wiki/Software/startup-notification
└─────────────┴────────┴────────┴────────────────────────────────────────┘
¹ libsn = libstartup-notification
i3-msg, i3-input, i3-nagbar and i3-config-wizard do not introduce any new
dependencies.
i3-wsbar is implemented in Perl and has the following dependencies:
• IPC::Run
• Try::Tiny
• AnyEvent
• AnyEvent::I3
All of them are available at CPAN, see http://search.cpan.org/
Use your distributions packages or cpan(1) to install them.
i3bar, i3-msg, i3-input, i3-nagbar and i3-config-wizard do not introduce any
new dependencies.
i3-migrate-config-to-v4 is implemented in Perl, but it has no dependencies
besides Perl 5.10.

View File

@ -1,4 +1,4 @@
Copyright (c) 2009, Michael Stapelberg
Copyright © 2009-2011, Michael Stapelberg and contributors
All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -18,18 +18,21 @@ else
UNUSED:=$(shell $(MAKE) loglevels.h)
endif
SUBDIRS=i3-msg i3-input i3-nagbar i3-config-wizard i3bar
SUBDIRS:=i3-msg i3-input i3-nagbar i3-config-wizard i3bar
# Depend on the specific file (.c for each .o) and on all headers
src/%.o: src/%.c ${HEADERS}
echo "CC $<"
echo "[i3] CC $<"
$(CC) $(CPPFLAGS) $(CFLAGS) -DLOGLEVEL="((uint64_t)1 << $(shell awk '/$(shell basename $< .c)/ { print NR; exit 0; }' loglevels.tmp))" -c -o $@ $<
all: i3 subdirs
i3: src/cfgparse.y.o src/cfgparse.yy.o src/cmdparse.y.o src/cmdparse.yy.o ${FILES}
echo "LINK i3"
$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
i3: libi3/libi3.a src/cfgparse.y.o src/cfgparse.yy.o src/cmdparse.y.o src/cmdparse.yy.o ${FILES}
echo "[i3] LINK i3"
$(CC) $(LDFLAGS) -o $@ $(filter-out libi3/libi3.a,$^) $(LIBS)
libi3/%.a: libi3/*.c
$(MAKE) -C libi3
subdirs:
for dir in $(SUBDIRS); do \
@ -39,7 +42,7 @@ subdirs:
done
loglevels.h:
echo "LOGLEVELS"
echo "[i3] LOGLEVELS"
for file in $$(ls src/*.c src/*.y src/*.l | grep -v 'cfgparse.\(tab\|yy\).c'); \
do \
echo $$(basename $$file .c); \
@ -51,35 +54,38 @@ loglevels.h:
echo "};") > include/loglevels.h;
src/cfgparse.yy.o: src/cfgparse.l src/cfgparse.y.o ${HEADERS}
echo "LEX $<"
echo "[i3] LEX $<"
flex -i -o$(@:.o=.c) $<
$(CC) $(CPPFLAGS) $(CFLAGS) -DLOGLEVEL="(1 << $(shell awk '/cfgparse.l/ { print NR }' loglevels.tmp))" -c -o $@ $(@:.o=.c)
src/cmdparse.yy.o: src/cmdparse.l src/cmdparse.y.o ${HEADERS}
echo "LEX $<"
echo "[i3] LEX $<"
flex -Pcmdyy -i -o$(@:.o=.c) $<
$(CC) $(CPPFLAGS) $(CFLAGS) -DLOGLEVEL="(1 << $(shell awk '/cmdparse.l/ { print NR }' loglevels.tmp))" -c -o $@ $(@:.o=.c)
src/cfgparse.y.o: src/cfgparse.y ${HEADERS}
echo "YACC $<"
echo "[i3] YACC $<"
bison --debug --verbose -b $(basename $< .y) -d $<
$(CC) $(CPPFLAGS) $(CFLAGS) -DLOGLEVEL="(1 << $(shell awk '/cfgparse.y/ { print NR }' loglevels.tmp))" -c -o $@ $(<:.y=.tab.c)
src/cmdparse.y.o: src/cmdparse.y ${HEADERS}
echo "YACC $<"
echo "[i3] YACC $<"
bison -p cmdyy --debug --verbose -b $(basename $< .y) -d $<
$(CC) $(CPPFLAGS) $(CFLAGS) -DLOGLEVEL="(1 << $(shell awk '/cmdparse.y/ { print NR }' loglevels.tmp))" -c -o $@ $(<:.y=.tab.c)
install: all
echo "INSTALL"
echo "[i3] INSTALL"
$(INSTALL) -d -m 0755 $(DESTDIR)$(PREFIX)/bin
$(INSTALL) -d -m 0755 $(DESTDIR)$(SYSCONFDIR)/i3
$(INSTALL) -d -m 0755 $(DESTDIR)$(PREFIX)/include/i3
$(INSTALL) -d -m 0755 $(DESTDIR)$(PREFIX)/share/xsessions
$(INSTALL) -m 0755 i3 $(DESTDIR)$(PREFIX)/bin/
$(INSTALL) -m 0755 i3-migrate-config-to-v4 $(DESTDIR)$(PREFIX)/bin/
$(INSTALL) -m 0755 i3-sensible-editor $(DESTDIR)$(PREFIX)/bin/
$(INSTALL) -m 0755 i3-sensible-pager $(DESTDIR)$(PREFIX)/bin/
$(INSTALL) -m 0755 i3-sensible-terminal $(DESTDIR)$(PREFIX)/bin/
test -e $(DESTDIR)$(SYSCONFDIR)/i3/config || $(INSTALL) -m 0644 i3.config $(DESTDIR)$(SYSCONFDIR)/i3/config
test -e $(DESTDIR)$(SYSCONFDIR)/i3/config.keycodes || $(INSTALL) -m 0644 i3.config.keycodes $(DESTDIR)$(SYSCONFDIR)/i3/config.keycodes
$(INSTALL) -m 0644 i3.welcome $(DESTDIR)$(SYSCONFDIR)/i3/welcome
@ -93,20 +99,20 @@ dist: distclean
[ ! -d i3-${VERSION} ] || rm -rf i3-${VERSION}
[ ! -e i3-${VERSION}.tar.bz2 ] || rm i3-${VERSION}.tar.bz2
mkdir i3-${VERSION}
cp i3-migrate-config-to-v4 i3.config.keycodes DEPENDS GOALS LICENSE PACKAGE-MAINTAINER TODO RELEASE-NOTES-${VERSION} i3.config i3.desktop i3.welcome pseudo-doc.doxygen i3-wsbar Makefile i3-${VERSION}
cp -r src i3-msg i3-nagbar i3-config-wizard i3bar yajl-fallback include man i3-${VERSION}
cp i3-migrate-config-to-v4 i3-sensible-* i3.config.keycodes DEPENDS GOALS LICENSE PACKAGE-MAINTAINER RELEASE-NOTES-${VERSION} i3.config i3.desktop i3.welcome pseudo-doc.doxygen i3-wsbar Makefile i3-${VERSION}
cp -r src libi3 i3-msg i3-nagbar i3-config-wizard i3bar yajl-fallback include man i3-${VERSION}
# Only copy toplevel documentation (important stuff)
mkdir i3-${VERSION}/docs
# Pre-generate documentation
make -C docs
make -C i3bar/doc
$(MAKE) -C docs
$(MAKE) -C i3bar/doc
# Cleanup τεχ output files
find docs -regex ".*\.\(aux\|out\|log\|toc\|bm\|dvi\|log\)" -exec rm '{}' \;
find docs -maxdepth 1 -type f ! \( -name "*.xcf" -or -name "*.svg" \) -exec cp '{}' i3-${VERSION}/docs \;
# Only copy source code from i3-input
mkdir i3-${VERSION}/i3-input
find i3-input -maxdepth 1 -type f \( -name "*.c" -or -name "*.h" -or -name "Makefile" \) -exec cp '{}' i3-${VERSION}/i3-input \;
sed -e 's/^GIT_VERSION:=\(.*\)/GIT_VERSION:=$(shell echo '${GIT_VERSION}' | sed 's/\\/\\\\/g')/g;s/^VERSION:=\(.*\)/VERSION:=${VERSION}/g' common.mk > i3-${VERSION}/common.mk
sed -e 's/^GIT_VERSION:=\(.*\)/GIT_VERSION:=$(shell /bin/echo '${GIT_VERSION}' | sed 's/\\/\\\\/g')/g;s/^VERSION:=\(.*\)/VERSION:=${VERSION}/g' common.mk > i3-${VERSION}/common.mk
# Pre-generate a manpage to allow distributors to skip this step and save some dependencies
$(MAKE) -C man
cp man/*.1 i3-${VERSION}/man/
@ -117,6 +123,7 @@ dist: distclean
clean:
rm -f src/*.o src/*.gcno src/cfgparse.tab.{c,h} src/cfgparse.yy.c src/cfgparse.{output,dot} src/cmdparse.tab.{c,h} src/cmdparse.yy.c src/cmdparse.{output,dot} loglevels.tmp include/loglevels.h
(which lcov >/dev/null 2>&1 && lcov -d . --zerocounters) || true
$(MAKE) -C libi3 clean
$(MAKE) -C docs clean
$(MAKE) -C man clean
for dir in $(SUBDIRS); do \

View File

@ -10,15 +10,21 @@ packages for them.
Please make sure the manpage for i3 will be properly created and installed
in your package.
Also please provide the path to a suitable terminal emulator which is installed
as a dependency of your package (e.g. urxvt). On systems which have a special
commend to launch the best available terminal emulator, please use this one
(e.g. x-terminal-emulator on debian).
Please check the i3-sensible-{editor,pager,terminal} scripts and modify them if
necessary. The former two provide fallbacks in case $PAGER or $EDITOR is not
set (which might be more common than you think, because they have to be set in
~/.xsession, not in the shell configuration!) while the latter tries to launch
a terminal emulator. The scripts are most prominently used in i3-nagbar, which
alerts the user when the configuration is broken for some reason. Also,
i3-sensible-terminal is used in the default configuration.
On debian, this looks like this:
If your distribution has a mechanism to get the preferred terminal, such as the
x-terminal-emulator symlink in Debian, please use it in i3-sensible-terminal.
On debian, compilation and installing the manpages looks like this:
# Compilation
$(MAKE) TERM_EMU=x-terminal-emulator
$(MAKE)
$(MAKE) -C man
# Installation

100
RELEASE-NOTES-4.1 Normal file
View File

@ -0,0 +1,100 @@
┌────────────────────────────┐
│ Release notes for i3 v4.1 │
└────────────────────────────┘
This is the second release of the new major version of i3, v4.1. It brings some
new (and long-awaited) features, the most prominent being tray support in i3bar
(for NetworkManager, Skype, etc.).
The assign syntax has changed to support criteria now. Also, criteria support
regular expressions (using PCRE) now. Check the userguide for the new syntax.
i3-nagbar will automatically display a warning when you use the old syntax.
i3 now supports startup notifications, meaning that during an application
starts up, the mouse cursor will change to 'watch' on the root window. Also,
the application window will appear on the workspace on which it was launched
(not on the currently focused workspace). Some applications dont support
startup notifications. If the cursor change bothers you, turn it off by using
the --no-startup-id flag (see the userguide).
This release has been in use by many users and is considered stable. Please
upgrade.
┌────────────────────────────┐
│ New features │
└────────────────────────────┘
• Switch to dpkg-source 3.0 (quilt) and compat level 7
• Implement system tray support in i3bar (for NetworkManager, Skype, …)
• i3bar is now configurable in the i3 configfile
• Implement support for PCRE regular expressions in criteria
• Implement a new assign syntax which uses criteria
• Sort named workspaces whose name starts with a number accordingly
• Warn on duplicate bindings for the same key
• Restrict 'resize' command to left/right for horizontal containers, up/down
for vertical containers
• Implement support for startup notifications (cursor will change to 'watch',
started applications show up on the workspace they have been launched on)
• Implement the GET_MARKS IPC request to get all marks
• Implement the new_float config option (border style for floating windows)
• Implement passing IPC sockets to i3 (systemd-style socket activation)
• Implement the 'move output' command to move containers to a specific output
• Implement focus switching for floating windows
• Implement the window_role criterion (for matching multi-window apps)
• Implement a force_xinerama configuration directive
• Implement the --get-socketpath, useful for scripts using the IPC interface
• Implement the 'move workspace next' and 'move workspace prev' commands
• Implement the 'workspace back_and_forth' command and related configuration
option
• Implement the move command for floating windows
• i3 will now handle arbitrary text arguments by sending them as an IPC
command, like i3-msg: 'i3 reload' or 'i3 move workspace 3'
• Introduce the i3-sensible-{pager,editor,terminal} scripts to execute
$PAGER, $EDITOR or an available terminal emulator
• i3-input: implement -F (format) option
┌────────────────────────────┐
│ Bugfixes │
└────────────────────────────┘
• Bugfix: Preserve marks when restarting
• Bugfix: Correctly free old assignments when reloading
• Bugfix: Fix flickering when moving floating windows between monitors
• Bugfix: Correctly handle ConfigureRequests for floating windows in a
multi-monitor environment.
• Bugfix: Fix size of floating windows with X11 borders
• Bugfix: Always adjust floating window position when moving to another
output
• Bugfix: Avoid out-of-bounds coordinates when moving floating windows
• Bugfix: Dont steal focus when a window gets destroyed
• Bugfix: Correctly split key/value when parsing variables
• Bugfix: Correctly revert focus to other floating windows when closing a
floating window
• Bugfix: Dont leak the error logfile file descriptor
• Bugfix: Dont steal focus when a window opens on an invisible workspace due
to assignments
• Bugfix: Fix handling of Mode_switch in i3-input
• Bugfix: Close invisible workspaces when they become empty
• Bugfix: Dont invoke interactive resizing when clicking on the decoration
of a split container with more than one child (switch focus instead)
• Bugfix: Make named workspace assignments work again
• Bugfix: RandR: Correctly keep focus on the focused workspace when an output
disappears
• Bugfix: Insert container at the correct position on workspace level when
workspace_layout == default
┌────────────────────────────┐
│ Thanks! │
└────────────────────────────┘
Thanks for testing, bugfixes, discussions and everything I forgot go out to:
aksr, alexanderb, atsutane, bacardi55, bjonnh, brian, cls, don, donald,
eeemsi, f8l, fernandotcl, isolnchip, julien, motif, mw, mxf, phnom, pl,
pnutzh4x0r, raphael, sardemff7, stfn, thomasba, xeen
-- Michael Stapelberg, 2011-11-11

7
TODO
View File

@ -1,7 +0,0 @@
Please see http://i3wm.org/ for our bugtracker.
Some old notes, just to not lose them:
* was passiert, wenn zwei fenster fullscreen wollen auf dem selben workspace?
* OpenOffice
* funktioniert xinerama etc. mit --below? insbesondere das fokus-verschieben in andere screens

View File

@ -12,7 +12,6 @@ ifndef SYSCONFDIR
SYSCONFDIR=$(PREFIX)/etc
endif
endif
TERM_EMU=xterm
# The escaping is absurd, but we need to escape for shell, sed, make, define
GIT_VERSION:="$(shell git describe --tags --always) ($(shell git log --pretty=format:%cd --date=short -n1), branch $(shell [ -f $(TOPDIR)/.git/HEAD ] && sed 's/ref: refs\/heads\/\(.*\)/\\\\\\"\1\\\\\\"/g' $(TOPDIR)/.git/HEAD || echo 'unknown'))"
VERSION:=$(shell git describe --tags --abbrev=0)
@ -22,9 +21,17 @@ $(error "pkg-config was not found")
endif
# An easier way to get CFLAGS and LDFLAGS falling back in case there's
# no pkg-config support for certain libraries
cflags_for_lib = $(shell pkg-config --silence-errors --cflags $(1))
ldflags_for_lib = $(shell pkg-config --exists $(1) && pkg-config --libs $(1) || echo -l$(2))
# no pkg-config support for certain libraries.
#
# NOTE that you must not use a blank after comma when calling this:
# $(call ldflags_for_lib name, fallback) # bad
# $(call ldflags_for_lib name,fallback) # good
# Otherwise, the compiler will get -l foo instead of -lfoo
#
# We redirect stderr to /dev/null because pkg-config prints an error if support
# for gnome-config was enabled but gnome-config is not actually installed.
cflags_for_lib = $(shell pkg-config --silence-errors --cflags $(1) 2>/dev/null)
ldflags_for_lib = $(shell pkg-config --exists 2>/dev/null $(1) && pkg-config --libs $(1) 2>/dev/null || echo -l$(2))
CFLAGS += -std=c99
CFLAGS += -pipe
@ -34,7 +41,7 @@ CFLAGS += -Wall
CFLAGS += -Wunused-value
CFLAGS += -Iinclude
CFLAGS += $(call cflags_for_lib, xcb-keysyms)
ifeq ($(shell pkg-config --exists xcb-util || echo 1),1)
ifeq ($(shell pkg-config --exists xcb-util 2>/dev/null || echo 1),1)
CPPFLAGS += -DXCB_COMPAT
CFLAGS += $(call cflags_for_lib, xcb-atom)
CFLAGS += $(call cflags_for_lib, xcb-aux)
@ -49,14 +56,20 @@ CFLAGS += $(call cflags_for_lib, xcursor)
CFLAGS += $(call cflags_for_lib, x11)
CFLAGS += $(call cflags_for_lib, yajl)
CFLAGS += $(call cflags_for_lib, libev)
CFLAGS += $(call cflags_for_lib, libpcre)
CFLAGS += $(call cflags_for_lib, libstartup-notification-1.0)
CPPFLAGS += -DI3_VERSION=\"${GIT_VERSION}\"
CPPFLAGS += -DSYSCONFDIR=\"${SYSCONFDIR}\"
CPPFLAGS += -DTERM_EMU=\"$(TERM_EMU)\"
ifeq ($(shell pkg-config --atleast-version=8.10 libpcre 2>/dev/null && echo 1),1)
CPPFLAGS += -DPCRE_HAS_UCP=1
endif
LIBS += -lm
LIBS += -L $(TOPDIR)/libi3 -li3
LIBS += $(call ldflags_for_lib, xcb-event,xcb-event)
LIBS += $(call ldflags_for_lib, xcb-keysyms,xcb-keysyms)
ifeq ($(shell pkg-config --exists xcb-util || echo 1),1)
ifeq ($(shell pkg-config --exists xcb-util 2>/dev/null || echo 1),1)
LIBS += $(call ldflags_for_lib, xcb-atom,xcb-atom)
LIBS += $(call ldflags_for_lib, xcb-aux,xcb-aux)
else
@ -70,6 +83,8 @@ LIBS += $(call ldflags_for_lib, xcursor, Xcursor)
LIBS += $(call ldflags_for_lib, x11,X11)
LIBS += $(call ldflags_for_lib, yajl,yajl)
LIBS += $(call ldflags_for_lib, libev,ev)
LIBS += $(call ldflags_for_lib, libpcre,pcre)
LIBS += $(call ldflags_for_lib, libstartup-notification-1.0,startup-notification-1)
# Please test if -Wl,--as-needed works on your platform and send me a patch.
# it is known not to work on Darwin (Mac OS X)

58
debian/changelog vendored
View File

@ -1,8 +1,60 @@
i3-wm (4.0.3-0) unstable; urgency=low
i3-wm (4.1-1) unstable; urgency=low
* NOT YET RELEASED!
* Switch to dpkg-source 3.0 (quilt) and compat level 7
* Implement system tray support in i3bar (for NetworkManager, Skype, …)
* i3bar is now configurable in the i3 configfile
* Implement support for PCRE regular expressions in criteria
* Implement a new assign syntax which uses criteria
* Sort named workspaces whose name starts with a number accordingly
* Warn on duplicate bindings for the same key
* Restrict 'resize' command to left/right for horizontal containers, up/down
for vertical containers
* Implement support for startup notifications (cursor will change to 'watch',
started applications show up on the workspace they have been launched on)
* Implement the GET_MARKS IPC request to get all marks
* Implement the new_float config option (border style for floating windows)
* Implement passing IPC sockets to i3 (systemd-style socket activation)
* Implement the 'move output' command to move containers to a specific output
* Implement focus switching for floating windows
* Implement the window_role criterion (for matching multi-window apps)
* Implement a force_xinerama configuration directive
* Implement the --get-socketpath, useful for scripts using the IPC interface
* Implement the 'move workspace next' and 'move workspace prev' commands
* Implement the 'workspace back_and_forth' command and related configuration
option
* Implement the move command for floating windows
* i3 will now handle arbitrary text arguments by sending them as an IPC
command, like i3-msg: 'i3 reload' or 'i3 move workspace 3'
* Introduce the i3-sensible-{pager,editor,terminal} scripts to execute
$PAGER, $EDITOR or an available terminal emulator
* i3-input: implement -F (format) option
* Bugfix: Preserve marks when restarting
* Bugfix: Correctly free old assignments when reloading
* Bugfix: Fix flickering when moving floating windows between monitors
* Bugfix: Correctly handle ConfigureRequests for floating windows in a
multi-monitor environment.
* Bugfix: Fix size of floating windows with X11 borders
* Bugfix: Always adjust floating window position when moving to another
output
* Bugfix: Avoid out-of-bounds coordinates when moving floating windows
* Bugfix: Dont steal focus when a window gets destroyed
* Bugfix: Correctly split key/value when parsing variables
* Bugfix: Correctly revert focus to other floating windows when closing a
floating window
* Bugfix: Dont leak the error logfile file descriptor
* Bugfix: Dont steal focus when a window opens on an invisible workspace due
to assignments
* Bugfix: Fix handling of Mode_switch in i3-input
* Bugfix: Close invisible workspaces when they become empty
* Bugfix: Dont invoke interactive resizing when clicking on the decoration
of a split container with more than one child (switch focus instead)
* Bugfix: Make named workspace assignments work again
* Bugfix: RandR: Correctly keep focus on the focused workspace when an output
disappears
* Bugfix: Insert container at the correct position on workspace level when
workspace_layout == default
-- Michael Stapelberg <michael@stapelberg.de> Sun, 28 Aug 2011 20:17:31 +0200
-- Michael Stapelberg <michael@stapelberg.de> Fri, 11 Nov 2011 21:28:15 +0000
i3-wm (4.0.2-1) unstable; urgency=low

2
debian/compat vendored
View File

@ -1 +1 @@
6
7

23
debian/control vendored
View File

@ -3,7 +3,7 @@ Section: utils
Priority: extra
Maintainer: Michael Stapelberg <michael@stapelberg.de>
DM-Upload-Allowed: yes
Build-Depends: debhelper (>= 6), libx11-dev, libxcb-util0-dev (>= 0.3.8), libxcb-keysyms1-dev, libxcb-xinerama0-dev (>= 1.1), libxcb-randr0-dev, libxcb-icccm4-dev, libxcursor-dev, asciidoc (>= 8.4.4), xmlto, docbook-xml, pkg-config, libev-dev, flex, bison, libyajl-dev, perl, texlive-latex-base, texlive-latex-recommended, texlive-latex-extra
Build-Depends: debhelper (>= 7.0.50~), libx11-dev, libxcb-util0-dev (>= 0.3.8), libxcb-keysyms1-dev, libxcb-xinerama0-dev (>= 1.1), libxcb-randr0-dev, libxcb-icccm4-dev, libxcursor-dev, asciidoc (>= 8.4.4), xmlto, docbook-xml, pkg-config, libev-dev, flex, bison, libyajl-dev, texlive-latex-base, texlive-latex-recommended, texlive-latex-extra, libpcre3-dev, libstartup-notification0-dev (>= 0.10)
Standards-Version: 3.9.2
Homepage: http://i3wm.org/
@ -14,25 +14,22 @@ Depends: i3-wm, ${misc:Depends}
Recommends: i3lock, suckless-tools, i3status
Description: metapackage (i3 window manager, screen locker, menu, statusbar)
This metapackage installs the i3 window manager (i3-wm), the i3lock screen
locker (slightly improved version of slock), suckless-tools which contains
dmenu and i3status, which displays useful information about your system in
combination with dzen2. These are all the tools you need to use the i3 window
manager efficiently.
locker, i3status (for system information) and suckless-tools (for dmenu).
These are all the tools you need to use the i3 window manager efficiently.
Package: i3-wm
Architecture: any
Section: x11
Depends: ${shlibs:Depends}, ${misc:Depends}, x11-utils
Depends: ${shlibs:Depends}, ${misc:Depends}, ${perl:Depends}, x11-utils
Provides: x-window-manager
Suggests: rxvt-unicode | x-terminal-emulator
Recommends: xfonts-base, libanyevent-i3-perl, libanyevent-perl, libipc-run-perl
Recommends: xfonts-base
Description: improved dynamic tiling window manager
Key features of i3 are correct implementation of Xinerama (workspaces are
assigned to virtual screens, i3 does the right thing when attaching new
monitors), XrandR support (not done yet), horizontal and vertical columns
(think of a table) in tiling. Also, special focus is on writing clean,
readable and well documented code. i3 uses xcb for asynchronous
communication with X11, and has several measures to be very fast.
Key features of i3 are good documentation, reasonable defaults (changeable in
a simple configuration file) and good multi-monitor support. The user
interface is designed for power users and emphasizes keyboard usage. i3 uses
XCB for asynchronous communication with X11 and aims to be fast and
light-weight.
.
Please be aware i3 is primarily targeted at advanced users and developers.

3
debian/i3-wm.docs vendored
View File

@ -14,3 +14,6 @@ docs/wsbar.html
docs/wsbar.png
docs/keyboard-layer1.png
docs/keyboard-layer2.png
docs/testsuite.html
docs/i3-sync-working.png
docs/i3-sync.png

10
debian/i3-wm.manpages vendored Normal file
View File

@ -0,0 +1,10 @@
man/i3.1
man/i3-msg.1
man/i3-input.1
man/i3-nagbar.1
man/i3-config-wizard.1
man/i3-migrate-config-to-v4.1
man/i3-sensible-pager.1
man/i3-sensible-editor.1
man/i3-sensible-terminal.1
i3bar/doc/i3bar.1

View File

@ -0,0 +1,14 @@
## Description: Document Debian-specific x-terminal-emulator in the manpage.
## Origin/Author: Michael Stapelberg
Index: i3-4.1/man/i3-sensible-terminal.man
===================================================================
--- i3-4.1.orig/man/i3-sensible-terminal.man 2011-11-11 22:38:06.508025537 +0000
+++ i3-4.1/man/i3-sensible-terminal.man 2011-11-11 22:38:04.752994892 +0000
@@ -22,6 +22,7 @@
It tries to start one of the following (in that order):
* $TERMINAL (this is a non-standard variable)
+* x-terminal-emulator (only on Debian)
* xterm
* urxvt
* rxvt

2
debian/patches/series vendored Normal file
View File

@ -0,0 +1,2 @@
use-x-terminal-emulator.patch
manpage-x-terminal-emulator.patch

View File

@ -0,0 +1,21 @@
## Description: Use Debian-specific x-terminal-emulator in i3-sensible-terminal
## Origin/Author: Michael Stapelberg
--- a/i3-sensible-terminal.O 2011-11-11 22:03:52.414218386 +0000
+++ b/i3-sensible-terminal 2011-11-11 22:04:38.372020210 +0000
@@ -1,13 +1,11 @@
#!/bin/sh
# This script tries to exec a terminal emulator by trying some known terminal
# emulators.
-#
-# Distributions/packagers should enhance this script with a
-# distribution-specific mechanism to find the preferred terminal emulator. On
-# Debian, there is the x-terminal-emulator symlink for example.
-# Please don't touch the first line, though:
which $TERMINAL >/dev/null && exec $TERMINAL "$@"
+# Debian-specific: use x-terminal-emulator
+which x-terminal-emulator >/dev/null && exec x-terminal-emulator "$@"
+
# Hopefully one of these is installed:
which xterm >/dev/null && exec xterm "$@"
which urxvt >/dev/null && exec urxvt "$@"

100
debian/rules vendored
View File

@ -1,85 +1,37 @@
#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.
# vi: ts=8 sw=8 noet
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
config.status: configure
dh_testdir
touch $@
build: build-arch build-indep
build-arch: build-stamp
build-indep: build-stamp
DPKG_EXPORT_BUILDFLAGS = 1
-include /usr/share/dpkg/buildflags.mk
build: build-stamp
build-stamp:
dh_testdir
dh build
touch build-stamp
# Add here commands to compile the package.
$(MAKE) TERM_EMU=x-terminal-emulator
clean:
dh clean
install: build install-stamp
install-stamp:
dh install
touch install-stamp
binary-arch: install
dh binary-arch
binary-indep: install
dh binary-indep
binary: binary-arch binary-indep
override_dh_auto_build:
$(MAKE)
$(MAKE) -C man
$(MAKE) -C docs
touch $@
clean:
dh_testdir
dh_testroot
rm -f build-stamp
# Add here commands to clean up after the build process.
[ ! -f Makefile ] || $(MAKE) distclean
dh_clean
install: build
dh_testdir
dh_testroot
dh_clean -k
dh_installdirs
# Add here commands to install the package into debian/i3-wm
override_dh_install:
$(MAKE) DESTDIR=$(CURDIR)/debian/i3-wm/ install
mkdir -p $(CURDIR)/debian/i3-wm/usr/share/man/man1
cp man/i3.1 $(CURDIR)/debian/i3-wm/usr/share/man/man1
cp man/i3-msg.1 $(CURDIR)/debian/i3-wm/usr/share/man/man1
cp man/i3-input.1 $(CURDIR)/debian/i3-wm/usr/share/man/man1
cp man/i3-nagbar.1 $(CURDIR)/debian/i3-wm/usr/share/man/man1
cp man/i3-config-wizard.1 $(CURDIR)/debian/i3-wm/usr/share/man/man1
cp man/i3-migrate-config-to-v4.1 $(CURDIR)/debian/i3-wm/usr/share/man/man1
cp i3bar/doc/i3bar.1 $(CURDIR)/debian/i3-wm/usr/share/man/man1
# Build architecture-independent files here.
binary-indep: build install
# We have nothing to do by default.
# Build architecture-dependent files here.
binary-arch: build install
dh_testdir
dh_testroot
dh_installchangelogs
dh_installdocs
dh_installexamples
dh_installdebconf
dh_installinit
dh_installman
dh_installwm
dh_link
override_dh_strip:
dh_strip --dbg-package=i3-wm-dbg
dh_compress
dh_fixperms
dh_installdeb
dh_shlibdeps
dh_gencontrol
dh_md5sums
dh_builddeb
binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install

View File

@ -1,23 +1,28 @@
# To pass additional parameters for asciidoc
ASCIIDOC=asciidoc
all: hacking-howto.html debugging.html userguide.html ipc.html multi-monitor.html wsbar.html refcard.pdf
all: hacking-howto.html debugging.html userguide.html ipc.html multi-monitor.html wsbar.html refcard.pdf testsuite.html
hacking-howto.html: hacking-howto
asciidoc -a toc -n $<
$(ASCIIDOC) -a toc -n $<
debugging.html: debugging
asciidoc -n $<
$(ASCIIDOC) -n $<
userguide.html: userguide
asciidoc -a toc -n $<
$(ASCIIDOC) -a toc -n $<
testsuite.html: testsuite
$(ASCIIDOC) -a toc -n $<
ipc.html: ipc
asciidoc -a toc -n $<
$(ASCIIDOC) -a toc -n $<
multi-monitor.html: multi-monitor
asciidoc -a toc -n $<
$(ASCIIDOC) -a toc -n $<
wsbar.html: wsbar
asciidoc -a toc -n $<
$(ASCIIDOC) -a toc -n $<
refcard.pdf: refcard.tex
pdflatex refcard.tex && pdflatex refcard.tex

662
docs/asciidoc-git.conf Normal file
View File

@ -0,0 +1,662 @@
#
# xhtml11.conf
#
# Asciidoc configuration file.
# xhtml11 backend, generates XHTML 1.1 conformant markup.
#
[miscellaneous]
outfilesuffix=.html
[attributes]
basebackend=html
basebackend-html=
basebackend-xhtml11=
[replacements2]
# Line break.
(?m)^(.*)\s\+$=\1<br />
[replacements]
ifdef::asciidoc7compatible[]
# Superscripts.
\^(.+?)\^=<sup>\1</sup>
# Subscripts.
~(.+?)~=<sub>\1</sub>
endif::asciidoc7compatible[]
[ruler-blockmacro]
<hr />
[pagebreak-blockmacro]
<div style="page-break-after:always"></div>
[blockdef-pass]
asciimath-style=template="asciimathblock",subs=[]
latexmath-style=template="latexmathblock",subs=[]
[macros]
# math macros.
# Special characters are escaped in HTML math markup.
(?su)[\\]?(?P<name>asciimath|latexmath):(?P<subslist>\S*?)\[(?P<passtext>.*?)(?<!\\)\]=[specialcharacters]
(?u)^(?P<name>asciimath|latexmath)::(?P<subslist>\S*?)(\[(?P<passtext>.*?)\])$=#[specialcharacters]
[asciimath-inlinemacro]
`{passtext}`
[asciimath-blockmacro]
<div class="mathblock{role? {role}}"{id? id="{id}"}>
<div class="content">
<div class="title">{title}</div>
`{passtext}`
</div></div>
[asciimathblock]
<div class="mathblock{role? {role}}"{id? id="{id}"}>
<div class="content">
<div class="title">{title}</div>
`|`
</div></div>
[latexmath-inlinemacro]
{passtext}
[latexmath-blockmacro]
<div class="mathblock{role? {role}}"{id? id="{id}"}>
<div class="content">
<div class="title">{title}</div>
{passtext}
</div></div>
[latexmathblock]
<div class="mathblock{role? {role}}"{id? id="{id}"}>
<div class="content">
<div class="title">{title}</div>
|
</div></div>
[image-inlinemacro]
<span class="image{role? {role}}">
<a class="image" href="{link}">
{data-uri%}<img src="{imagesdir=}{imagesdir?/}{target}" alt="{alt={target}}"{width? width="{width}"}{height? height="{height}"}{title? title="{title}"} />
{data-uri#}<img alt="{alt={target}}"{width? width="{width}"}{height? height="{height}"}{title? title="{title}"} src="data:image/{eval:os.path.splitext('{target}')[1][1:]};base64,
{data-uri#}{sys3:python -uc "import base64,sys; base64.encode(sys.stdin,sys.stdout)" < "{eval:os.path.join("{indir={outdir}}","{imagesdir=}","{target}")}"}" />
{link#}</a>
</span>
[image-blockmacro]
<div class="imageblock{style? {style}}{role? {role}}"{id? id="{id}"}{align? style="text-align:{align};"}{float? style="float:{float};"}>
<div class="content">
<a class="image" href="{link}">
{data-uri%}<img src="{imagesdir=}{imagesdir?/}{target}" alt="{alt={target}}"{width? width="{width}"}{height? height="{height}"} />
{data-uri#}<img alt="{alt={target}}"{width? width="{width}"}{height? height="{height}"} src="data:image/{eval:os.path.splitext('{target}')[1][1:]};base64,
{data-uri#}{sys:python -uc "import base64,sys; base64.encode(sys.stdin,sys.stdout)" < "{eval:os.path.join("{indir={outdir}}","{imagesdir=}","{target}")}"}" />
{link#}</a>
</div>
<div class="title">{caption={figure-caption} {counter:figure-number}. }{title}</div>
</div>
[unfloat-blockmacro]
<div style="clear:both;"></div>
[indexterm-inlinemacro]
# Index term.
{empty}
[indexterm2-inlinemacro]
# Index term.
# Single entry index term that is visible in the primary text flow.
{1}
[footnote-inlinemacro]
# footnote:[<text>].
<span class="footnote"><br />[{0}]<br /></span>
[footnoteref-inlinemacro]
# footnoteref:[<id>], create reference to footnote.
{2%}<span class="footnoteref"><br /><a href="#_footnote_{1}">[{1}]</a><br /></span>
# footnoteref:[<id>,<text>], create footnote with ID.
{2#}<span class="footnote" id="_footnote_{1}"><br />[{2}]<br /></span>
[callout-inlinemacro]
ifndef::icons[]
<b>&lt;{index}&gt;</b>
endif::icons[]
ifdef::icons[]
ifndef::data-uri[]
<img src="{icon={iconsdir}/callouts/{index}.png}" alt="{index}" />
endif::data-uri[]
ifdef::data-uri[]
<img alt="{index}" src="data:image/png;base64,
{sys:python -uc "import base64,sys; base64.encode(sys.stdin,sys.stdout)" < "{eval:os.path.join("{indir={outdir}}","{icon={iconsdir}/callouts/{index}.png}")}"}" />
endif::data-uri[]
endif::icons[]
# Comment line macros.
[comment-inlinemacro]
{showcomments#}<br /><span class="comment">{passtext}</span><br />
[comment-blockmacro]
{showcomments#}<p><span class="comment">{passtext}</span></p>
[literal-inlinemacro]
# Inline literal.
<tt>{passtext}</tt>
# List tags.
[listtags-bulleted]
list=<div class="ulist{style? {style}}{compact-option? compact}{role? {role}}"{id? id="{id}"}>{title?<div class="title">{title}</div>}<ul>|</ul></div>
item=<li>|</li>
text=<p>|</p>
[listtags-numbered]
# The start attribute is not valid XHTML 1.1 but all browsers support it.
list=<div class="olist{style? {style}}{compact-option? compact}{role? {role}}"{id? id="{id}"}>{title?<div class="title">{title}</div>}<ol class="{style}"{start? start="{start}"}>|</ol></div>
item=<li>|</li>
text=<p>|</p>
[listtags-labeled]
list=<div class="dlist{compact-option? compact}{role? {role}}"{id? id="{id}"}>{title?<div class="title">{title}</div>}<dl>|</dl></div>
entry=
label=
term=<dt class="hdlist1{strong-option? strong}">|</dt>
item=<dd>|</dd>
text=<p>|</p>
[listtags-horizontal]
list=<div class="hdlist{compact-option? compact}{role? {role}}"{id? id="{id}"}>{title?<div class="title">{title}</div>}<table>{labelwidth?<col width="{labelwidth}%" />}{itemwidth?<col width="{itemwidth}%" />}|</table></div>
label=<td class="hdlist1{strong-option? strong}">|</td>
term=|<br />
entry=<tr>|</tr>
item=<td class="hdlist2">|</td>
text=<p style="margin-top: 0;">|</p>
[listtags-qanda]
list=<div class="qlist{style? {style}}{role? {role}}"{id? id="{id}"}>{title?<div class="title">{title}</div>}<ol>|</ol></div>
entry=<li>|</li>
label=
term=<p><em>|</em></p>
item=
text=<p>|</p>
[listtags-callout]
ifndef::icons[]
list=<div class="colist{style? {style}}{role? {role}}"{id? id="{id}"}>{title?<div class="title">{title}</div>}<ol>|</ol></div>
item=<li>|</li>
text=<p>|</p>
endif::icons[]
ifdef::icons[]
list=<div class="colist{style? {style}}{role? {role}}"{id? id="{id}"}>{title?<div class="title">{title}</div>}<table>|</table></div>
ifndef::data-uri[]
item=<tr><td><img src="{iconsdir}/callouts/{listindex}.png" alt="{listindex}" /></td><td>|</td></tr>
endif::data-uri[]
ifdef::data-uri[]
item=<tr><td><img alt="{listindex}" src="data:image/png;base64, {sys:python -uc "import base64,sys; base64.encode(sys.stdin,sys.stdout)" < "{eval:os.path.join("{indir={outdir}}","{icon={iconsdir}/callouts/{listindex}.png}")}"}" /></td><td>|</td></tr>
endif::data-uri[]
text=|
endif::icons[]
[listtags-glossary]
list=<div class="dlist{style? {style}}{role? {role}}"{id? id="{id}"}>{title?<div class="title">{title}</div>}<dl>|</dl></div>
label=
entry=
term=<dt>|</dt>
item=<dd>|</dd>
text=<p>|</p>
[listtags-bibliography]
list=<div class="ulist{style? {style}}{role? {role}}"{id? id="{id}"}>{title?<div class="title">{title}</div>}<ul>|</ul></div>
item=<li>|</li>
text=<p>|</p>
[tags]
# Quoted text.
emphasis=<em>{1?<span class="{1}">}|{1?</span>}</em>
strong=<strong>{1?<span class="{1}">}|{1?</span>}</strong>
monospaced=<tt>{1?<span class="{1}">}|{1?</span>}</tt>
singlequoted={lsquo}{1?<span class="{1}">}|{1?</span>}{rsquo}
doublequoted={ldquo}{1?<span class="{1}">}|{1?</span>}{rdquo}
unquoted={1?<span class="{1}">}|{1?</span>}
superscript=<sup>{1?<span class="{1}">}|{1?</span>}</sup>
subscript=<sub>{1?<span class="{1}">}|{1?</span>}</sub>
ifdef::deprecated-quotes[]
# Override with deprecated quote attributes.
emphasis={role?<span class="{role}">}<em{1,2,3? style="}{1?color:{1};}{2?background-color:{2};}{3?font-size:{3}em;}{1,2,3?"}>|</em>{role?</span>}
strong={role?<span class="{role}">}<strong{1,2,3? style="}{1?color:{1};}{2?background-color:{2};}{3?font-size:{3}em;}{1,2,3?"}>|</strong>{role?</span>}
monospaced={role?<span class="{role}">}<tt{1,2,3? style="}{1?color:{1};}{2?background-color:{2};}{3?font-size:{3}em;}{1,2,3?"}>|</tt>{role?</span>}
singlequoted={role?<span class="{role}">}{1,2,3?<span style="}{1?color:{1};}{2?background-color:{2};}{3?font-size:{3}em;}{1,2,3?">}{amp}#8216;|{amp}#8217;{1,2,3?</span>}{role?</span>}
doublequoted={role?<span class="{role}">}{1,2,3?<span style="}{1?color:{1};}{2?background-color:{2};}{3?font-size:{3}em;}{1,2,3?">}{amp}#8220;|{amp}#8221;{1,2,3?</span>}{role?</span>}
unquoted={role?<span class="{role}">}{1,2,3?<span style="{1?color:{1};}{2?background-color:{2};}{3?font-size:{3}em;}">}|{1,2,3?</span>}{role?</span>}
superscript={role?<span class="{role}">}<sup{1,2,3? style="}{1?color:{1};}{2?background-color:{2};}{3?font-size:{3}em;}{1,2,3?"}>|</sup>{role?</span>}
subscript={role?<span class="{role}">}<sub{1,2,3? style="}{1?color:{1};}{2?background-color:{2};}{3?font-size:{3}em;}{1,2,3?"}>|</sub>{role?</span>}
endif::deprecated-quotes[]
# Inline macros
[http-inlinemacro]
<a href="{name}:{target}">{0={name}:{target}}</a>
[https-inlinemacro]
<a href="{name}:{target}">{0={name}:{target}}</a>
[ftp-inlinemacro]
<a href="{name}:{target}">{0={name}:{target}}</a>
[file-inlinemacro]
<a href="{name}:{target}">{0={name}:{target}}</a>
[irc-inlinemacro]
<a href="{name}:{target}">{0={name}:{target}}</a>
[mailto-inlinemacro]
<a href="mailto:{target}">{0={target}}</a>
[link-inlinemacro]
<a href="{target}">{0={target}}</a>
[callto-inlinemacro]
<a href="{name}:{target}">{0={target}}</a>
# anchor:id[text]
[anchor-inlinemacro]
<a id="{target}"></a>
# [[id,text]]
[anchor2-inlinemacro]
<a id="{1}"></a>
# [[[id]]]
[anchor3-inlinemacro]
<a id="{1}"></a>[{1}]
# xref:id[text]
[xref-inlinemacro]
<a href="#{target}">{0=[{target}]}</a>
# <<id,text>>
[xref2-inlinemacro]
<a href="#{1}">{2=[{1}]}</a>
# Special word substitution.
[emphasizedwords]
<em>{words}</em>
[monospacedwords]
<tt>{words}</tt>
[strongwords]
<strong>{words}</strong>
# Paragraph substitution.
[paragraph]
<div class="paragraph{role? {role}}"{id? id="{id}"}>{title?<div class="title">{title}</div>}<p>
|
</p></div>
[admonitionparagraph]
template::[admonitionblock]
# Delimited blocks.
[listingblock]
<div class="listingblock{role? {role}}"{id? id="{id}"}>
<div class="title">{caption=}{title}</div>
<div class="content">
<pre><tt>
|
</tt></pre>
</div></div>
[literalblock]
<div class="literalblock{role? {role}}"{id? id="{id}"}>
<div class="title">{title}</div>
<div class="content">
<pre><tt>
|
</tt></pre>
</div></div>
[sidebarblock]
<div class="sidebarblock{role? {role}}"{id? id="{id}"}>
<div class="content">
<div class="title">{title}</div>
|
</div></div>
[openblock]
<div class="openblock{role? {role}}"{id? id="{id}"}>
<div class="title">{title}</div>
<div class="content">
|
</div></div>
[partintroblock]
template::[openblock]
[abstractblock]
template::[quoteblock]
[quoteblock]
<div class="quoteblock{role? {role}}"{id? id="{id}"}>
<div class="title">{title}</div>
<div class="content">
|
</div>
<div class="attribution">
<em>{citetitle}</em>{attribution?<br />}
&#8212; {attribution}
</div></div>
[verseblock]
<div class="verseblock{role? {role}}"{id? id="{id}"}>
<div class="title">{title}</div>
<pre class="content">
|
</pre>
<div class="attribution">
<em>{citetitle}</em>{attribution?<br />}
&#8212; {attribution}
</div></div>
[exampleblock]
<div class="exampleblock{role? {role}}"{id? id="{id}"}>
<div class="title">{caption={example-caption} {counter:example-number}. }{title}</div>
<div class="content">
|
</div></div>
[admonitionblock]
<div class="admonitionblock{role? {role}}"{id? id="{id}"}>
<table><tr>
<td class="icon">
{data-uri%}{icons#}<img src="{icon={iconsdir}/{name}.png}" alt="{caption}" />
{data-uri#}{icons#}<img alt="{caption}" src="data:image/png;base64,
{data-uri#}{icons#}{sys:python -uc "import base64,sys; base64.encode(sys.stdin,sys.stdout)" < "{eval:os.path.join("{indir={outdir}}","{icon={iconsdir}/{name}.png}")}"}" />
{icons%}<div class="title">{caption}</div>
</td>
<td class="content">
<div class="title">{title}</div>
|
</td>
</tr></table>
</div>
# Tables.
[tabletags-default]
colspec=<col{autowidth-option! width="{colpcwidth}%"} />
bodyrow=<tr>|</tr>
headdata=<th {colspan@1::colspan="{colspan}" }{rowspan@1::rowspan="{rowspan}" }align="{halign}" valign="{valign}">|</th>
bodydata=<td {colspan@1::colspan="{colspan}" }{rowspan@1::rowspan="{rowspan}" }align="{halign}" valign="{valign}">|</td>
paragraph=<p class="table">|</p>
[tabletags-header]
paragraph=<p class="table header">|</p>
[tabletags-emphasis]
paragraph=<p class="table"><em>|</em></p>
[tabletags-strong]
paragraph=<p class="table"><strong>|</strong></p>
[tabletags-monospaced]
paragraph=<p class="table"><tt>|</tt></p>
[tabletags-verse]
bodydata=<td {colspan@1::colspan="{colspan}" }{rowspan@1::rowspan="{rowspan}" }align="{halign}" valign="{valign}"><div class="verse">|</div></td>
paragraph=
[tabletags-literal]
bodydata=<td {colspan@1::colspan="{colspan}" }{rowspan@1::rowspan="{rowspan}" }align="{halign}" valign="{valign}"><div class="literal"><pre><tt>|</tt></pre></div></td>
paragraph=
[tabletags-asciidoc]
bodydata=<td {colspan@1::colspan="{colspan}" }{rowspan@1::rowspan="{rowspan}" }align="{halign}" valign="{valign}"><div>|</div></td>
paragraph=
[table]
<div class="tableblock{role? {role}}"{id? id="{id}"}>
<table rules="{grid=all}"
style="margin-left:{align@left:0}{align@center|right:auto}; margin-right:{align@left|center:auto}{align@right:0};"
style="float:{float};"
{autowidth-option%}width="{tablepcwidth}%"
{autowidth-option#}{width#width="{tablepcwidth}%"}
frame="{frame%border}"
frame="{frame@topbot:hsides}{frame@all:border}{frame@none:void}{frame@sides:vsides}"
cellspacing="0" cellpadding="4">
<caption class="title">{caption={table-caption} {counter:table-number}. }{title}</caption>
{colspecs}
{headrows#}<thead>
{headrows}
{headrows#}</thead>
{footrows#}<tfoot>
{footrows}
{footrows#}</tfoot>
<tbody>
{bodyrows}
</tbody>
</table>
</div>
#--------------------------------------------------------------------
# Deprecated old table definitions.
#
[miscellaneous]
# Screen width in pixels.
pagewidth=800
pageunits=
[old_tabledef-default]
template=old_table
colspec=<col width="{colwidth}{pageunits}" />
bodyrow=<tr>|</tr>
headdata=<th align="{colalign}">|</th>
footdata=<td align="{colalign}">|</td>
bodydata=<td align="{colalign}">|</td>
[old_table]
<div class="tableblock"{id? id="{id}"}>
<table rules="{grid=none}"
frame="{frame%hsides}"
frame="{frame@topbot:hsides}{frame@all:border}{frame@none:void}{frame@sides:vsides}"
cellspacing="0" cellpadding="4">
<caption class="title">{caption={table-caption}}{title}</caption>
{colspecs}
{headrows#}<thead>
{headrows}
{headrows#}</thead>
{footrows#}<tfoot>
{footrows}
{footrows#}</tfoot>
<tbody valign="top">
{bodyrows}
</tbody>
</table>
</div>
# End of deprecated old table definitions.
#--------------------------------------------------------------------
[floatingtitle]
<h{level@0:1}{level@1:2}{level@2:3}{level@3:4}{level@4:5}{id? id="{id}"} class="float">{title}</h{level@0:1}{level@1:2}{level@2:3}{level@3:4}{level@4:5}>
[preamble]
# Untitled elements between header and first section title.
<div id="preamble">
<div class="sectionbody">
|
</div>
</div>
# Document sections.
[sect0]
<h1{id? id="{id}"}>{title}</h1>
|
[sect1]
<div class="sect1{style? {style}}{role? {role}}">
<h2{id? id="{id}"}>{numbered?{sectnum} }{title}</h2>
<div class="sectionbody">
|
</div>
</div>
[sect2]
<div class="sect2{style? {style}}{role? {role}}">
<h3{id? id="{id}"}>{numbered?{sectnum} }{title}</h3>
|
</div>
[sect3]
<div class="sect3{style? {style}}{role? {role}}">
<h4{id? id="{id}"}>{numbered?{sectnum} }{title}</h4>
|
</div>
[sect4]
<div class="sect4{style? {style}}{role? {role}}">
<h5{id? id="{id}"}>{title}</h5>
|
</div>
[appendix]
<div class="sect1{style? {style}}{role? {role}}">
<h2{id? id="{id}"}>{numbered?{sectnum} }{appendix-caption} {counter:appendix-number:A}: {title}</h2>
<div class="sectionbody">
|
</div>
</div>
[toc]
<div id="toc">
<div id="toctitle">{toc-title}</div>
<noscript><p><b>JavaScript must be enabled in your browser to display the table of contents.</b></p></noscript>
</div>
[header]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="{lang=en}">
<head>
<link rel="icon" type="image/png" href="/favicon.png">
<meta http-equiv="Content-Type" content="{quirks=application/xhtml+xml}{quirks?text/html}; charset={encoding}" />
<meta name="generator" content="AsciiDoc {asciidoc-version}" />
<meta name="description" content="{description}" />
<meta name="keywords" content="{keywords}" />
<title>i3: {title}</title>
{title%}<title>i3: {doctitle=}</title>
<link rel="stylesheet" href="{stylesdir=.}/style.css" type="text/css" />
ifdef::linkcss[]
<link rel="stylesheet" href="{stylesdir=.}/{theme={backend}}.css" type="text/css" />
{doctype-manpage}<link rel="stylesheet" href="{stylesdir=.}/{theme={backend}}-manpage.css" type="text/css" />
ifdef::quirks[]
<link rel="stylesheet" href="{stylesdir=.}/{theme={backend}}-quirks.css" type="text/css" />
endif::quirks[]
<link rel="stylesheet" href="{stylesdir=.}/{stylesheet}" type="text/css" />
ifdef::pygments[<link rel="stylesheet" href="{stylesdir=.}/pygments.css" type="text/css" />]
endif::linkcss[]
ifndef::linkcss[]
<style type="text/css">
include1::{stylesdir=./stylesheets}/{theme={backend}}.css[]
ifdef::doctype-manpage[]
include1::{stylesdir=./stylesheets}/{theme={backend}}-manpage.css[]
endif::doctype-manpage[]
ifdef::quirks[]
include1::{stylesdir=./stylesheets}/{theme={backend}}-quirks.css[]
endif::quirks[]
include1::{stylesheet}[]
ifdef::pygments[]
include1::{stylesdir=./stylesheets}/pygments.css[]
endif::pygments[]
</style>
endif::linkcss[]
ifndef::disable-javascript[]
ifdef::linkcss[]
<script type="text/javascript">
# Escape as CDATA to pass validators.
/*<![CDATA[*/
window.onload = function()\{asciidoc.footnotes();{toc? asciidoc.toc({toclevels});}\}
/*]]>*/
</script>
<script type="text/javascript" src="{scriptsdir=.}/asciidoc-xhtml11.js"></script>
endif::linkcss[]
ifndef::linkcss[]
<script type="text/javascript">
# Escape as CDATA to pass validators.
/*<![CDATA[*/
window.onload = function()\{asciidoc.footnotes();{toc? asciidoc.toc({toclevels});}\}
include1::{scriptsdir=./javascripts}/asciidoc-xhtml11.js[]
/*]]>*/
</script>
endif::linkcss[]
endif::disable-javascript[]
ifdef::asciimath[]
ifdef::linkcss[]
<script type="text/javascript" src="{scriptsdir=.}/ASCIIMathML.js"></script>
endif::linkcss[]
ifndef::linkcss[]
<script type="text/javascript">
# Escape as CDATA to pass validators.
/*<![CDATA[*/
include1::{scriptsdir=./javascripts}/ASCIIMathML.js[]
/*]]>*/
</script>
endif::linkcss[]
endif::asciimath[]
ifdef::latexmath[]
ifdef::linkcss[]
<script type="text/javascript" src="{scriptsdir=.}/LaTeXMathML.js"></script>
endif::linkcss[]
ifndef::linkcss[]
<script type="text/javascript">
# Escape as CDATA to pass validators.
/*<![CDATA[*/
include1::{scriptsdir=./javascripts}/LaTeXMathML.js[]
/*]]>*/
</script>
endif::linkcss[]
endif::latexmath[]
{docinfo1,docinfo2#}{include:{docdir}/docinfo.html}
{docinfo,docinfo2#}{include:{docdir}/{docname}-docinfo.html}
</head>
<body class="{doctype}"{max-width? style="max-width:{max-width}"}>
<div id="main">
<a href="/"><h1 id="title">i3 - improved tiling WM</h1></a>
<ul id="nav">
<li style=" background-color: #FFD000; font-size: 2em;padding: 0.25em;-webkit-border-radius: 0.25em;border: 4px dashed black;color: #000000;">latest git docs</li>
</ul>
<br style="clear: both">
<div id="content">
# Article, book header.
ifndef::doctype-manpage[]
<div id="header">
ifndef::notitle[<h1>{doctitle}</h1>]
ifdef::doctitle[]
<span id="author">{author}</span><br />
<span id="email"><tt>&lt;<a href="mailto:{email}">{email}</a>&gt;</tt></span><br />
<span id="revnumber">version {revnumber}{revdate?,}</span>
<span id="revdate">{revdate}</span>
<br /><span id="revremark">{revremark}</span>
endif::doctitle[]
ifdef::toc[{template:toc}]
</div>
endif::doctype-manpage[]
# Man page header.
ifdef::doctype-manpage[]
<div id="header">
<h1>
{doctitle} Manual Page
</h1>
ifdef::toc[{template:toc}]
<h2>{manname-title}</h2>
<div class="sectionbody">
<p>{manname} -
{manpurpose}
</p>
</div>
</div>
endif::doctype-manpage[]
[footer]
</div>
{disable-javascript%<div id="footnotes"><hr /></div>}
<div id="footer" lang="de">
© 2009-2011 Michael Stapelberg, <a href="/impress.html">Impressum</a>
</div>
</body>
</html>
ifdef::doctype-manpage[]
[synopsis]
template::[sect1]
endif::doctype-manpage[]
ifdef::quirks[]
include::{backend}-quirks.conf[]
endif::quirks[]

BIN
docs/i3-sync-working.dia Normal file

Binary file not shown.

BIN
docs/i3-sync-working.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

BIN
docs/i3-sync.dia Normal file

Binary file not shown.

BIN
docs/i3-sync.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

111
docs/ipc
View File

@ -1,7 +1,7 @@
IPC interface (interprocess communication)
==========================================
Michael Stapelberg <michael+i3@stapelberg.de>
March 2010
October 2011
This document describes how to interface with i3 from a separate process. This
is useful for example to remote-control i3 (to write test cases for example) or
@ -12,7 +12,7 @@ The method of choice for IPC in our case is a unix socket because it has very
little overhead on both sides and is usually available without headaches in
most languages. In the default configuration file, the ipc-socket gets created
in +/tmp/i3-%u/ipc-socket.%p+ where +%u+ is your UNIX username and +%p+ is the
PID of i3.
PID of i3. You can get the socketpath from i3 by calling +i3 --get-socketpath+.
All i3 utilities, like +i3-msg+ and +i3-input+ will read the +I3_SOCKET_PATH+
X11 property, stored on the X11 root window.
@ -24,7 +24,8 @@ snippet illustrates this in Perl:
-------------------------------------------------------------
use IO::Socket::UNIX;
my $sock = IO::Socket::UNIX->new(Peer => '/tmp/i3-ipc.sock');
chomp(my $path = qx(i3 --get-socketpath));
my $sock = IO::Socket::UNIX->new(Peer => $path);
-------------------------------------------------------------
== Sending messages to i3
@ -59,6 +60,14 @@ GET_TREE (4)::
Gets the layout tree. i3 uses a tree as data structure which includes
every container. The reply will be the JSON-encoded tree (see the reply
section).
GET_MARKS (5)::
Gets a list of marks (identifiers for containers to easily jump to them
later). The reply will be a JSON-encoded list of window marks (see
reply section).
GET_BAR_CONFIG (6)::
Gets the configuration (as JSON map) of the workspace bar with the
given ID. If no ID is provided, an array with all configured bar IDs is
returned instead.
So, a typical message could look like this:
--------------------------------------------------
@ -110,6 +119,10 @@ GET_OUTPUTS (3)::
Reply to the GET_OUTPUTS message.
GET_TREE (4)::
Reply to the GET_TREE message.
GET_MARKS (5)::
Reply to the GET_MARKS message.
GET_BAR_CONFIG (6)::
Reply to the GET_BAR_CONFIG message.
=== COMMAND reply
@ -418,6 +431,98 @@ JSON dump:
}
------------------------
=== GET_MARKS reply
The reply consists of a single array of strings for each container that has a
mark. The order of that array is undefined. If more than one container has the
same mark, it will be represented multiple times in the reply (the array
contents are not unique).
If no window has a mark the response will be the empty array [].
=== GET_BAR_CONFIG reply
This can be used by third-party workspace bars (especially i3bar, but others
are free to implement compatible alternatives) to get the +bar+ block
configuration from i3.
Depending on the input, the reply is either:
empty input::
An array of configured bar IDs
Bar ID::
A JSON map containing the configuration for the specified bar.
Each bar configuration has the following properties:
id (string)::
The ID for this bar. Included in case you request multiple
configurations and want to differentiate the different replies.
mode (string)::
Either +dock+ (the bar sets the dock window type) or +hide+ (the bar
does not show unless a specific key is pressed).
position (string)::
Either +bottom+ or +top+ at the moment.
status_command (string)::
Command which will be run to generate a statusline. Each line on stdout
of this command will be displayed in the bar. At the moment, no
formatting is supported.
font (string)::
The font to use for text on the bar.
workspace_buttons (boolean)::
Display workspace buttons or not? Defaults to true.
verbose (boolean)::
Should the bar enable verbose output for debugging? Defaults to false.
colors (map)::
Contains key/value pairs of colors. Each value is a color code in hex,
formatted #rrggbb (like in HTML).
The following colors can be configured at the moment:
background::
Background color of the bar.
statusline::
Text color to be used for the statusline.
focused_workspace_text/focused_workspace_bg::
Text color/background color for a workspace button when the workspace
has focus.
active_workspace_text/active_workspace_bg::
Text color/background color for a workspace button when the workspace
is active (visible) on some output, but the focus is on another one.
You can only tell this apart from the focused workspace when you are
using multiple monitors.
inactive_workspace_text/inactive_workspace_bg::
Text color/background color for a workspace button when the workspace
does not have focus and is not active (visible) on any output. This
will be the case for most workspaces.
urgent_workspace_text/urgent_workspace_bar::
Text color/background color for workspaces which contain at least one
window with the urgency hint set.
*Example of configured bars:*
--------------
["bar-bxuqzf"]
--------------
*Example of bar configuration:*
--------------
{
"id": "bar-bxuqzf",
"mode": "dock",
"position": "bottom",
"status_command": "i3status",
"font": "-misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1",
"workspace_buttons": true,
"verbose": false,
"colors": {
"background": "#c0c0c0",
"statusline": "#00ff00",
"focused_workspace_text": "#ffffff",
"focused_workspace_bg": "#000000"
}
}
--------------
== Events

View File

@ -1,7 +1,7 @@
The multi-monitor situation
===========================
Michael Stapelberg <michael+i3@stapelberg.de>
March 2010
September 2011
…or: oh no, I have an nVidia graphics card!
@ -16,6 +16,8 @@ i3, like so:
exec i3 --force-xinerama -V >>~/.i3/i3log 2>&1
----------------------------------------------
…or use +force_xinerama yes+ in your configuration file.
== The explanation
Starting with version 3.ε, i3 uses the RandR (Rotate and Resize) API instead
@ -50,9 +52,13 @@ these are two screens).
For this very reason, we decided to implement the following workaround: As
long as the nVidia driver does not support RandR, an option called
+--force-xinerama+ is available in i3. This option gets the list of screens
*once* when starting, and never updates it. As the nVidia driver cannot do
dynamic configuration anyways, this is not a big deal.
+--force-xinerama+ is available in i3 (alternatively, you can use the
+force_xinerama+ configuration file directive). This option gets the list of
screens *once* when starting, and never updates it. As the nVidia driver cannot
do dynamic configuration anyways, this is not a big deal.
Also note that your output names are not descriptive (like +HDMI1+) when using
Xinerama, instead they are counted up, starting at 0: +xinerama-0+, +xinerama-1+, …
== See also

540
docs/testsuite Normal file
View File

@ -0,0 +1,540 @@
i3 testsuite
============
Michael Stapelberg <michael+i3@stapelberg.de>
September 2011
This document explains how the i3 testsuite works, how to use it and extend it.
It is targeted at developers who not necessarily have been doing testing before
or have not been testing in Perl before. In general, the testsuite is not of
interest for end users.
== Introduction
The i3 testsuite is a collection of files which contain testcases for various
i3 features. Some of them test if a certain workflow works correctly (moving
windows, focus behaviour, …). Others are regression tests and contain code
which previously made i3 crash or lead to unexpected behaviour. They then check
if i3 still runs (meaning it did not crash) and if it handled everything
correctly.
The goal of having these tests is to automatically find problems and to
automatically get a feel for whether a change in the source code breaks any
existing feature. After every modification of the i3 sourcecode, the developer
should run the full testsuite. If one of the tests fails, the corresponding
problem should be fixed (or, in some cases, the testcase has to be modified).
For every bugreport, a testcase should be written to test the correct
behaviour. Initially, it will fail, but after fixing the bug, it will pass.
This ensures (or increases the chance) that bugs which have been fixed once
will never be found again.
Also, when implementing a new feature, a testcase might be a good way to be
able to easily test if the feature is working correctly. Many developers will
test manually if everything works. Having a testcase not only helps you with
that, but it will also be useful for every future change.
== Implementation
For several reasons, the i3 testsuite has been implemented in Perl:
1. Perl has a long tradition of testing. Every popular/bigger Perl module which
you can find on CPAN will not only come with documentation, but also with
tests. Therefore, the available infrastructure for tests is comprehensive.
See for example the excellent http://search.cpan.org/perldoc?Test::More
and the referenced http://search.cpan.org/perldoc?Test::Tutorial.
2. Perl is widely available and has a well-working package infrastructure.
3. The author is familiar with Perl :).
Please do not start programming language flamewars at this point.
=== Mechanisms
==== Script: complete-run
The testcases are run by a script called +complete-run.pl+. It runs all
testcases by default, but you can be more specific and let it only run one or
more testcases. Also, it takes care of starting up a separate instance of i3
with an appropriate configuration file and creates a folder for each run
containing the appropriate i3 logfile for each testcase. The latest folder can
always be found under the symlink +latest/+. Unless told differently, it will
run the tests on a separate X server instance (using the Xdummy script).
.Example invocation of complete-run.pl+
---------------------------------------
$ cd ~/i3/testcases
$ ./complete-run.pl
# output omitted because it is very long
All tests successful.
Files=78, Tests=734, 27 wallclock secs ( 0.38 usr 0.48 sys + 17.65 cusr 3.21 csys = 21.72 CPU)
Result: PASS
$ ./complete-run.pl t/04-floating.t
[:3] i3 startup: took 0.07s, status = 1
[:3] Running t/04-floating.t with logfile testsuite-2011-09-24-16-06-04-4.0.2-226-g1eb011a/i3-log-for-04-floating.t
[:3] t/04-floating.t finished
[:3] killing i3
output for t/04-floating.t:
ok 1 - use X11::XCB::Window;
ok 2 - The object isa X11::XCB::Window
ok 3 - Window is mapped
ok 4 - i3 raised the width to 75
ok 5 - i3 raised the height to 50
ok 6 - i3 did not map it to (0x0)
ok 7 - The object isa X11::XCB::Window
ok 8 - i3 let the width at 80
ok 9 - i3 let the height at 90
ok 10 - i3 mapped it to x=1
ok 11 - i3 mapped it to y=18
ok 12 - The object isa X11::XCB::Window
ok 13 - i3 let the width at 80
ok 14 - i3 let the height at 90
1..14
All tests successful.
Files=1, Tests=14, 0 wallclock secs ( 0.01 usr 0.00 sys + 0.19 cusr 0.03 csys = 0.23 CPU)
Result: PASS
$ less latest/i3-log-for-04-floating.t
----------------------------------------
==== IPC interface
The testsuite makes extensive use of the IPC (Inter-Process Communication)
interface which i3 provides. It is used for the startup process of i3, for
terminating it cleanly and (most importantly) for modifying and getting the
current state (layout tree).
See [http://i3wm.org/docs/ipc.html] for documentation on the IPC interface.
==== X11::XCB
In order to open new windows, change attributes, get events, etc., the
testsuite uses X11::XCB, a new (and quite specific to i3 at the moment) Perl
module which uses the XCB protocol description to generate Perl bindings to
X11. They work in a very similar way to libxcb (which i3 uses) and provide
relatively high-level interfaces (objects such as +X11::XCB::Window+) aswell as
access to the low-level interface, which is very useful when testing a window
manager.
=== Filesystem structure
In the git root of i3, the testcases live in the folder +testcases+. This
folder contains the +complete-run.pl+ and +Xdummy+ scripts and a base
configuration file which will be used for the tests. The different testcases
(their file extension is .t, not .pl) themselves can be found in the
conventionally named subfolder +t+:
.Filesystem structure
--------------------------------------------
├── testcases
│   ├── complete-run.pl
│   ├── i3-test.config
│   ├── lib
│   │   ├── i3test.pm
│   │   ├── SocketActivation.pm
│   │   └── StartXDummy.pm
│   ├── t
│   │   ├── 00-load.t
│   │   ├── 01-tile.t
│   │   ├── 02-fullscreen.t
│   │   ├── ...
│   │   ├── omitted for brevity
│   │   ├── ...
│   │   └── 74-regress-focus-toggle.t
│   └── Xdummy
--------------------------------------------
== Anatomy of a testcase
Learning by example is definitely a good strategy when you are wondering how to
write a testcase. Let's take +t/11-goto.t+ as an easy example and go through it
step by step:
.t/11-goto.t: Boilerplate
----------------------
#!perl
# vim:ts=4:sw=4:expandtab
use i3test;
use File::Temp;
my $x = X11::XCB::Connection->new;
-----------------------
This is what we call boilerplate. It exists at the top of every test file (to
some extent). The first line is the shebang, which specifies that this file is
a Perl script. The second line contains VIM specific settings on how to
edit/format this file (use spaces instead of tabs, indent using 4 spaces).
Afterwards, the +i3test+ module is used. This module contains i3 testsuite
specific functions which you are strongly encouraged to use. They make writing
testcases a lot easier and will make it easier for other people to read your
tests.
The next line uses the +File::Temp+ module. This is specific to this testcase,
because it needs to generate a temporary name during the test. Many testcases
use only the +i3test+ module.
The last line opens a connection to X11. You might or might not need this in
your testcase, depending on whether you are going to open windows (etc.) or
only use i3 commands.
.t/11-goto.t: Setup
----------------------
my $tmp = fresh_workspace;
cmd 'split h';
----------------------
The first line calls i3test's +fresh_workspace+ function which looks for a
currently unused workspace, switches to it, and returns its name. The variable
+$tmp+ will end up having a value such as +"/tmp/87kBVcHbA9"+. Note that this
is not (necessarily) a valid path, it's just a random workspace name.
So, now that we are on a new workspace, we ensure that the workspace uses
horizontal orientation by issuing the +split h+ command (see the i3 User's
Guide for a list of commands). This is not strictly necessary, but good style.
In general, the +cmd+ function executes the specified i3 command by using the
IPC interface and returns once i3 acknowledged the command.
.t/11-goto.t: Setup
----------------------
#####################################################################
# Create two windows and make sure focus switching works
#####################################################################
my $top = open_window($x);
my $mid = open_window($x);
my $bottom = open_window($x);
----------------------
In every major section of a testcase, you should put a comment like the one
above. This makes it immediately clear how the file is structured.
The +open_window+ function opens a standard window, which will then be put into
tiling mode by i3. If you want a floating window, use the
+open_floating_window+ function. These functions accept the same parameters as
+X11::XCB::Window->new+, see the i3test documentation at TODO.
.t/11-goto.t: Helper function
----------------------
#
# Returns the input focus after sending the given command to i3 via IPC
# and syncing with i3
#
sub focus_after {
my $msg = shift;
cmd $msg;
sync_with_i3 $x;
return $x->input_focus;
}
----------------------
This section defines a helper function which will be used over and over in this
testcase. If you have code which gets executed more than once or twice
(depending on the length of your test, use your best judgement), please put it
in a function. Tests should be short, concise and clear.
The +focus_after+ function executes a command and returns the X11 focus after
the command was executed. The +sync_with_i3+ command makes sure that i3 could
push its state to X11. See <<i3_sync>> to learn how this works exactly.
.t/11-goto.t: Test assumptions
----------------------
$focus = $x->input_focus;
is($focus, $bottom->id, "Latest window focused");
$focus = focus_after('focus left');
is($focus, $mid->id, "Middle window focused");
----------------------
Now, we run the first two real tests. They use +Test::More+'s +is+ function,
which compares two values and prints the differences if they are not the same.
After the arguments, we supply a short comment to indicate what we are testing
here. This makes it vastly more easy for the developer to spot which testcase
is the problem in case one fails.
The first test checks that the most recently opened window is focused.
Afterwards, the command +focus left+ is issued and it is verified that the
middle window now has focus.
Note that this is not a comprehensive test of the +focus+ command -- we would
have to test wrapping, focus when using a more complex layout, focusing the
parent/child containers, etc. But that is not the point of this testcase.
Instead, we just want to know if +$x->input_focus+ corresponds with what we are
expecting. If not, something is completely wrong with the test environment and
this trivial test will fail.
.t/11-goto.t: Test that the feature does not work (yet)
----------------------
#####################################################################
# Now goto a mark which does not exist
#####################################################################
my $random_mark = mktemp('mark.XXXXXX');
$focus = focus_after(qq|[con_mark="$random_mark"] focus|);
is($focus, $mid->id, "focus unchanged");
----------------------
Syntax hint: The qq keyword is the interpolating quote operator. It lets you
chose a quote character (in this case the +|+ character, a pipe). This makes
having double quotes in our string easy.
In this new major section, a random mark (mark is an identifier for a window,
see "VIM-like marks" in the i3 Users Guide) will be generated. Afterwards, we
test that trying to focus that mark will not do anything. This is important: Do
not only test that using a feature has the expected outcome, but also test that
using it without properly initializing it does no harm. This command could for
example have changed focus anyways (a bug) or crash i3 (obviously a bug).
.t/11-goto.t: Test that the feature does work
----------------------
cmd "mark $random_mark";
$focus = focus_after('focus left');
is($focus, $top->id, "Top window focused");
$focus = focus_after(qq|[con_mark="$random_mark"] focus|);
is($focus, $mid->id, "goto worked");
----------------------
Remember: Focus was on the middle window (we verified that earlier in "Test
assumptions"). We now mark the middle window with our randomly generated mark.
Afterwards, we switch focus away from the middle window to be able to tell if
focusing it via its mark will work. If the test works, the goto command seems
to be working.
.t/11-goto.t: Test corner case
----------------------
# check that we can specify multiple criteria
$focus = focus_after('focus left');
is($focus, $top->id, "Top window focused");
$focus = focus_after(qq|[con_mark="$random_mark" con_mark="$random_mark"] focus|);
is($focus, $mid->id, "goto worked");
----------------------
Now we test the same feature, but specifying the mark twice in the command.
This should have no effect, but lets be sure: test it and see if things go
wrong.
.t/11-goto.t: Test second code path
----------------------
#####################################################################
# Check whether the focus command will switch to a different
# workspace if necessary
#####################################################################
my $tmp2 = fresh_workspace;
is(focused_ws(), $tmp2, 'tmp2 now focused');
cmd qq|[con_mark="$random_mark"] focus|;
is(focused_ws(), $tmp, 'tmp now focused');
----------------------
This part of the test checks that focusing windows by mark works across
workspaces. It uses i3test's +focused_ws+ function to get the current
workspace.
.t/11-goto.t: Test second code path
----------------------
done_testing;
----------------------
The end of every testcase has to contain the +done_testing+ line. This tells
+complete-run.pl+ that the test was finished successfully. If it does not
occur, the test might have crashed during execution -- some of the reasons why
that could happen are bugs in the used modules, bugs in the testcase itself or
an i3 crash resulting in the testcase being unable to communicate with i3 via
IPC anymore.
[[i3_sync]]
== Appendix A: The i3 sync protocol
Consider the following situation: You open two windows in your testcase, then
you use +focus left+ and want to verify that the X11 focus has been updated
properly. Sounds simple, right? Lets assume you use this straight-forward
implementation:
.Racey focus testcase
-----------
my $left = open_window($x);
my $right = open_window($x);
cmd 'focus left';
is($x->input_focus, $left->id, 'left window focused');
----------
However, the test fails. Sometimes. Apparantly, there is a race condition in
your test. If you think about it, this is because you are using two different
pieces of software: You tell i3 to update focus, i3 confirms that, and then you
ask X11 to give you the current focus. There is a certain time i3 needs to
update the X11 state. If the testcase gets CPU time before X11 processed i3's
requests, the test will fail.
image::i3-sync.png["Diagram of the race condition", title="Diagram of the race condition"]
One way to "solve" this would be to add +sleep 0.5;+ after the +cmd+ call.
After 0.5 seconds it should be safe to assume that focus has been updated,
right?
In practice, this usually works. However, it has several problems:
1. This is obviously not a clean solution, but a workaround. Ugly.
2. On very slow machines, this might not work. Unlikely, but in different
situations (a delay to wait for i3 to startup) the necessary time is much
harder to guess, even for fast machines.
3. This *wastes a lot of time*. Usually, your computer is much faster than 0.5s
to update the status. However, sometimes, it might take 0.4s, so we cant
make it +sleep 0.1+.
To illustrate how grave the problem with wasting time actually is: Before
removing all sleeps from the testsuite, a typical run using 4 separate X
servers took around 50 seconds on my machine. After removing all the sleeps,
we achieved times of about 25 seconds. This is very significant and influences
the way you think about tests -- the faster they are, the more likely you are
to check whether everything still works quite often (which you should).
What I am trying to say is: Delays adds up quickly and make the test suite
less robust.
The real solution for this problem is a mechanism which I call "the i3 sync
protocol". The idea is to send a request (which does not modify state) via X11
to i3 which will then be answered. Due to the request's position in the event
queue (*after* all previous events), you can be sure that by the time you
receive the reply, all other events have been dealt with by i3 (and, more
importantly, X11).
image::i3-sync-working.png["Diagram of the i3 sync solution", title="Diagram of the i3 sync solution"]
=== Implementation details
The client which wants to sync with i3 initiates the protocol by sending a
ClientMessage to the X11 root window:
.Send ClientMessage
-------------------
# Generate a ClientMessage, see xcb_client_message_t
my $msg = pack "CCSLLLLLLL",
CLIENT_MESSAGE, # response_type
32, # format
0, # sequence
$root, # destination window
$x->atom(name => 'I3_SYNC')->id,
$_sync_window->id, # data[0]: our own window id
$myrnd, # data[1]: a random value to identify the request
0,
0,
0;
# Send it to the root window -- since i3 uses the SubstructureRedirect
# event mask, it will get the ClientMessage.
$x->send_event(0, $root, EVENT_MASK_SUBSTRUCTURE_REDIRECT, $msg);
-------------------
i3 will then reply with the same ClientMessage, sent to the window specified in
+data[0]+. In the reply, +data[0]+ and +data[1]+ are exactly the same as in the
request. You should use a random value in +data[1]+ and check that you received
the same one when getting the reply.
== Appendix B: Socket activation
Socket activation is a mechanism which was made popular by systemd, an init
replacement. It basically describes creating a listening socket before starting
a program. systemd will invoke the program only when an actual connection to
the socket is made, hence the term socket activation.
The interesting part of this (in the i3 context) is that you can very precisely
detect when the program is ready (finished its initialization).
=== Preparing the listening socket
+complete-run.pl+ will create a listening UNIX socket which it will then pass
to i3. This socket will be used by i3 as an additional IPC socket, just like
the one it will create on its own. Passing the socket happens implicitly
because children will inherit the parents sockets when fork()ing and sockets
will continue to exist after an exec() call (unless CLOEXEC is set of course).
The only explicit things +complete-run.pl+ has to do is setting the +LISTEN_FDS+
environment variable to the number of sockets which exist (1 in our case) and
setting the +LISTEN_PID+ environment variable to the current process ID. Both
variables are necessary so that the program (i3) knows how many sockets it
should use and if the environment variable is actually intended for it. i3 will
then start looking for sockets at file descriptor 3 (since 0, 1 and 2 are used
for stdin, stdout and stderr, respectively).
The actual Perl code which sets up the socket, fork()s, makes sure the socket
has file descriptor 3 and sets up the environment variables follows (shortened
a bit):
.Setup socket and environment
-----------------------------
my $socket = IO::Socket::UNIX->new(
Listen => 1,
Local => $args{unix_socket_path},
);
my $pid = fork;
if ($pid == 0) {
$ENV{LISTEN_PID} = $$;
$ENV{LISTEN_FDS} = 1;
# Only pass file descriptors 0 (stdin), 1 (stdout),
# 2 (stderr) and 3 (socket) to the child.
$^F = 3;
# If the socket does not use file descriptor 3 by chance
# already, we close fd 3 and dup2() the socket to 3.
if (fileno($socket) != 3) {
POSIX::close(3);
POSIX::dup2(fileno($socket), 3);
}
exec "/usr/bin/i3";
}
-----------------------------
=== Waiting for a reply
In the parent process, we want to know when i3 is ready to answer our IPC
requests and handle our windows. Therefore, after forking, we immediately close
the listening socket (i3 will handle this side of the socket) and connect to it
(remember, we are talking about a named UNIX socket) as a client. This connect
call will immediately succeed because the kernel buffers it. Then, we send a
request (of type GET_TREE, but that is not really relevant). Writing data to
the socket will also succeed immediately because, again, the kernel buffers it
(only up to a certain amount of data of course).
Afterwards, we just blockingly wait until we get an answer. In the child
process, i3 will setup the listening socket in its event loop. Immediately
after actually starting the event loop, it will notice a new client connecting
(the parent process) and handle its request. Since all initialization has been
completed successfully by the time the event loop is entered, we can now assume
that i3 is ready.
=== Timing and conclusion
A beautiful feature of this mechanism is that it does not depend on timing. It
does not matter when the child process gets CPU time or when the parent process
gets CPU time. On heavily loaded machines (or machines with multiple CPUs,
cores or unreliable schedulers), this makes waiting for i3 much more robust.
Before using socket activation, we typically used a +sleep(1)+ and hoped that
i3 was initialized by that time. Of course, this breaks on some (slow)
computers and wastes a lot of time on faster computers. By using socket
activation, we decreased the total amount of time necessary to run all tests
(72 files at the time of writing) from > 100 seconds to 16 seconds. This makes
it significantly more attractive to run the test suite more often (or at all)
during development.
An alternative approach to using socket activation is polling for the existance
of the IPC socket and connecting to it. While this might be slightly easier to
implement, it wastes CPU time and is considerably uglier than this solution
:). After all, +lib/SocketActivation.pm+ contains only 54 SLOC.

View File

@ -1,7 +1,7 @@
i3 Users Guide
===============
Michael Stapelberg <michael+i3@stapelberg.de>
August 2011
October 2011
This document contains all the information you need to configure and use the i3
window manager. If it does not, please contact us on IRC (preferred) or post your
@ -357,7 +357,8 @@ it to the position you want.
When holding the floating modifier, you can resize a floating window by
pressing the right mouse button on it and moving around while holding it. If
you hold the shift button as well, the resize will be proportional.
you hold the shift button as well, the resize will be proportional (the aspect
ratio will be preserved).
*Syntax*:
--------------------------------
@ -431,7 +432,7 @@ change their border style, for example.
*Syntax*:
-----------------------------
for_window [criteria] command
for_window <criteria> command
-----------------------------
*Examples*:
@ -478,37 +479,59 @@ configuration file and run it before starting i3 (for example in your
[[assign_workspace]]
Specific windows can be matched by window class and/or window title. It is
recommended that you match on window classes instead of window titles whenever
possible because some applications first create their window, and then worry
about setting the correct title. Firefox with Vimperator comes to mind. The
window starts up being named Firefox, and only when Vimperator is loaded does
the title change. As i3 will get the title as soon as the application maps the
To automatically make a specific window show up on a specific workspace, you
can use an *assignment*. You can match windows by using any criteria,
see <<command_criteria>>. It is recommended that you match on window classes
(and instances, when appropriate) instead of window titles whenever possible
because some applications first create their window, and then worry about
setting the correct title. Firefox with Vimperator comes to mind. The window
starts up being named Firefox, and only when Vimperator is loaded does the
title change. As i3 will get the title as soon as the application maps the
window (mapping means actually displaying it on the screen), youd need to have
to match on 'Firefox' in this case.
You can prefix or suffix workspaces with a `~` to specify that matching clients
should be put into floating mode. If you specify only a `~`, the client will
not be put onto any workspace, but will be set floating on the current one.
*Syntax*:
------------------------------------------------------------
assign ["]window class[/window title]["] [→] [workspace]
assign <criteria> [→] workspace
------------------------------------------------------------
*Examples*:
----------------------
assign urxvt 2
assign urxvt → 2
assign urxvt → work
assign "urxvt" → 2
assign "urxvt/VIM" → 3
assign "gecko" → 4
# Assign URxvt terminals to workspace 2
assign [class="URxvt"] 2
# Same thing, but more precise (exact match instead of substring)
assign [class="^URxvt$"] 2
# Same thing, but with a beautiful arrow :)
assign [class="^URxvt$"] → 2
# Assignment to a named workspace
assign [class="^URxvt$"] → work
# Start urxvt -name irssi
assign [class="^URxvt$" instance="^irssi$"] → 3
----------------------
Note that the arrow is not required, it just looks good :-). If you decide to
use it, it has to be a UTF-8 encoded arrow, not `->` or something like that.
To get the class and instance, you can use +xprop+. After clicking on the
window, you will see the following output:
*xwininfo*:
-----------------------------------
WM_CLASS(STRING) = "irssi", "URxvt"
-----------------------------------
The first part of the WM_CLASS is the instance ("irssi" in this example), the
second part is the class ("URxvt" in this example).
Should you have any problems with assignments, make sure to check the i3
logfile first (see http://i3wm.org/docs/debugging.html). It includes more
details about the matching process and the windows actual class, instance and
title when starting up.
=== Automatically starting applications on i3 startup
By using the +exec+ keyword outside a keybinding, you can configure
@ -519,16 +542,21 @@ keyword. These commands will be run in order.
*Syntax*:
-------------------
exec command
exec_always command
exec [--no-startup-id] command
exec_always [--no-startup-id] command
-------------------
*Examples*:
--------------------------------
exec i3status | i3bar -d
exec chromium
exec_always ~/my_script.sh
# Execute the terminal emulator urxvt, which is not yet startup-notification aware.
exec --no-startup-id urxvt
--------------------------------
The flag --no-startup-id is explained in <<exec>>.
[[workspace_screen]]
=== Automatically putting workspaces on specific screens
@ -541,17 +569,20 @@ the second screen and so on).
*Syntax*:
----------------------------------
workspace <number> output <output>
workspace <workspace> output <output>
----------------------------------
The 'output' is the name of the RandR output you attach your screen to. On a
laptop, you might have VGA1 and LVDS1 as output names. You can see the
available outputs by running +xrandr --current+.
If you use named workspaces, they must be quoted:
*Examples*:
---------------------------
workspace 1 output LVDS1
workspace 5 output VGA1
workspace "2: vim" output VGA1
---------------------------
=== Changing colors
@ -690,6 +721,270 @@ force_focus_wrapping <yes|no>
force_focus_wrapping yes
------------------------
=== Forcing Xinerama
As explained in-depth in <http://i3wm.org/docs/multi-monitor.html>, some X11
video drivers (especially the nVidia binary driver) only provide support for
Xinerama instead of RandR. In such a situation, i3 must be told to use the
inferior Xinerama API explicitly and therefore dont provide support for
reconfiguring your screens on the fly (they are read only once on startup and
thats it).
For people who do cannot modify their +~/.xsession+ to add the
+--force-xinerama+ commandline parameter, a configuration option is provided:
*Syntax*:
-----------------------
force_xinerama <yes|no>
-----------------------
*Example*:
------------------
force_xinerama yes
------------------
Also note that your output names are not descriptive (like +HDMI1+) when using
Xinerama, instead they are counted up, starting at 0: +xinerama-0+, +xinerama-1+, …
=== Automatic back-and-forth when switching to the current workspace
This configuration directive enables automatic +workspace back_and_forth+ (see
<<back_and_forth>>) when switching to the workspace that is currently focused.
For instance: Assume you are on workspace "1: www" and switch to "2: IM" using
mod+2 because somebody sent you a message. You dont need to remember where you
came from now, you can just press mod+2 again to switch back to "1: www".
*Syntax*:
--------------------------------------
workspace_auto_back_and_forth <yes|no>
--------------------------------------
*Example*:
---------------------------------
workspace_auto_back_and_forth yes
---------------------------------
== Configuring i3bar
The bar at the bottom of your monitor is drawn by a separate process called
i3bar. Having this part of "the i3 user interface" in a separate process has
several advantages:
1. It is a modular approach. If you dont need a workspace bar at all, or if
you prefer a different one (dzen2, xmobar, maybe even gnome-panel?), you can
just remove the i3bar configuration and start your favorite bar instead.
2. It follows the UNIX philosophy of "Make each program do one thing well".
While i3 manages your windows well, i3bar is good at displaying a bar on
each monitor (unless you configure it otherwise).
3. It leads to two separate, clean codebases. If you want to understand i3, you
dont need to bother with the details of i3bar and vice versa.
That said, i3bar is configured in the same configuration file as i3. This is
because it is tightly coupled with i3 (in contrary to i3lock or i3status which
are useful for people using other window managers). Therefore, it makes no
sense to use a different configuration place when we already have a good
configuration infrastructure in place.
Configuring your workspace bar starts with opening a +bar+ block. You can have
multiple bar blocks to use different settings for different outputs (monitors):
*Example*:
---------------------------
bar {
status_command i3status
}
---------------------------
=== Statusline command
i3bar can run a program and display every line of its +stdout+ output on the
right hand side of the bar. This is useful to display system information like
your current IP address, battery status or date/time.
The specified command will be passed to +sh -c+, so you can use globbing and
have to have correct quoting etc.
*Syntax*:
----------------------
status_command command
----------------------
*Example*:
-------------------------------------------------
status_command i3status --config ~/.i3status.conf
-------------------------------------------------
=== Display mode
You can have i3bar either be visible permanently at one edge of the screen
(+dock+ mode) or make it show up when you press your modifier key (+hide+
mode).
The hide mode maximizes screen space that can be used for actual windows. Also,
i3bar sends the +SIGSTOP+ and +SIGCONT+ signals to the statusline process to
save battery power.
The default is dock mode.
*Syntax*:
----------------
mode <dock|hide>
----------------
*Example*:
----------------
mode hide
----------------
=== Position
This option determines in which edge of the screen i3bar should show up.
The default is bottom.
*Syntax*:
---------------------
position <top|bottom>
---------------------
*Example*:
---------------------
position top
---------------------
=== Output(s)
You can restrict i3bar to one or more outputs (monitors). The default is to
handle all outputs. Restricting the outputs is useful for using different
options for different outputs by using multiple 'bar' blocks.
*Syntax*:
---------------
output <output>
---------------
*Example*:
-------------------------------
# big monitor: everything
bar {
output HDMI2
status_command i3status
}
# laptop monitor: bright colors and i3status with less modules.
bar {
output LVDS1
status_command i3status --config ~/.i3status-small.conf
colors {
background #000000
statusline #ffffff
}
}
-------------------------------
=== Tray output
i3bar by default provides a system tray area where programs such as
NetworkManager, VLC, Pidgin, etc. can place little icons.
You can configure on which output (monitor) the icons should be displayed or
you can turn off the functionality entirely.
*Syntax*:
-------------------------
tray_output <none|output>
-------------------------
*Example*:
-------------------------
# disable system tray
tray_output none
# show tray icons on the big monitor
tray_output HDMI2
-------------------------
=== Font
Specifies the font (again, X core font, not Xft, just like in i3) to be used in
the bar.
*Syntax*:
---------------------
font <font>
---------------------
*Example*:
--------------------------------------------------------------
font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
--------------------------------------------------------------
=== Workspace buttons
Specifies whether workspace buttons should be shown or not. This is useful if
you want to display a statusline-only bar containing additional information.
The default is to show workspace buttons.
*Syntax*:
--------------------------
workspace_buttons <yes|no>
--------------------------
*Example*:
--------------------
workspace_buttons no
--------------------
=== Colors
As with i3, colors are in HTML hex format (#rrggbb). The following colors can
be configured at the moment:
background::
Background color of the bar.
statusline::
Text color to be used for the statusline.
focused_workspace::
Text color/background color for a workspace button when the workspace
has focus.
active_workspace::
Text color/background color for a workspace button when the workspace
is active (visible) on some output, but the focus is on another one.
You can only tell this apart from the focused workspace when you are
using multiple monitors.
inactive_workspace::
Text color/background color for a workspace button when the workspace
does not have focus and is not active (visible) on any output. This
will be the case for most workspaces.
urgent_workspace::
Text color/background color for workspaces which contain at least one
window with the urgency hint set.
*Syntax*:
----------------------------------------
colors {
background <color>
statusline <color>
colorclass <foreground> <background>
}
----------------------------------------
*Example*:
--------------------------------------
colors {
background #000000
statusline #ffffff
focused_workspace #ffffff #285577
active_workspace #ffffff #333333
inactive_workspace #888888 #222222
urgent_workspace #ffffff #900000
}
--------------------------------------
== List of commands
Commands are what you bind to specific keypresses. You can also issue commands
@ -721,6 +1016,9 @@ which have the class Firefox, use:
*Example*:
------------------------------------
bindsym mod+x [class="Firefox"] kill
# same thing, but case-insensitive
bindsym mod+x [class="(?i)firefox"] kill
------------------------------------
The criteria which are currently implemented are:
@ -729,6 +1027,8 @@ class::
Compares the window class (the second part of WM_CLASS)
instance::
Compares the window instance (the first part of WM_CLASS)
window_role::
Compares the window role (WM_WINDOW_ROLE).
id::
Compares the X11 window ID, which you can get via +xwininfo+ for example.
title::
@ -739,8 +1039,40 @@ con_id::
Compares the i3-internal container ID, which you can get via the IPC
interface. Handy for scripting.
Note that currently all criteria are compared case-insensitive and do not
support regular expressions. This is planned to change in the future.
The criteria +class+, +instance+, +role+, +title+ and +mark+ are actually
regular expressions (PCRE). See +pcresyntax(3)+ or +perldoc perlre+ for
information on how to use them.
[[exec]]
=== Executing applications (exec)
What good is a window manager if you cant actually start any applications?
The exec command starts an application by passing the command you specify to a
shell. This implies that you can use globbing (wildcards) and programs will be
searched in your $PATH.
*Syntax*:
------------------------------
exec [--no-startup-id] command
------------------------------
*Example*:
------------------------------
# Start the GIMP
bindsym mod+g exec gimp
# Start the terminal emulator urxvt which is not yet startup-notification-aware
bindsym mod+enter exec --no-startup-id urxvt
------------------------------
The +--no-startup-id+ parameter disables startup-notification support for this
particular exec command. With startup-notification, i3 can make sure that a
window appears on the workspace on which you used the exec command. Also, it
will change the X11 cursor to +watch+ (a clock) while the application is
launching. So, if an application is not startup-notification aware (most GTK
and Qt using applications seem to be, though), you will end up with a watch
cursor for 60 seconds.
=== Splitting containers
@ -806,9 +1138,19 @@ mode_toggle::
For moving, use +move left+, +move right+, +move down+ and +move up+.
*Syntax*:
-----------------------------------
focus <left|right|down|up>
focus <parent|child|floating|tiling|mode_toggle>
move <left|right|down|up> [<px> px]
-----------------------------------
Note that the amount of pixels you can specify for the +move+ command is only
relevant for floating containers. The default amount is 10 pixels.
*Examples*:
----------------------
# Focus clients on the left, bottom, top, right:
# Focus container on the left, bottom, top, right:
bindsym mod+j focus left
bindsym mod+k focus down
bindsym mod+l focus up
@ -820,11 +1162,15 @@ bindsym mod+u focus parent
# Focus last floating/tiling container
bindsym mod+g focus mode_toggle
# Move client to the left, bottom, top, right:
# Move container to the left, bottom, top, right:
bindsym mod+j move left
bindsym mod+k move down
bindsym mod+l move up
bindsym mod+semicolon move right
# Move container, but make floating containers
# move more than the default
bindsym mod+j move left 20 px
----------------------
=== Changing (named) workspaces/moving to workspaces
@ -836,7 +1182,17 @@ number or name of the workspace. To move containers to specific workspaces, use
You can also switch to the next and previous workspace with the commands
+workspace next+ and +workspace prev+, which is handy, for example, if you have
workspace 1, 3, 4 and 9 and you want to cycle through them with a single key
combination.
combination. Similarily, you can use +move workspace next+ and +move workspace
prev+ to move a container to the next/previous workspace.
[[back_and_forth]]
To switch back to the previously focused workspace, use +workspace
back_and_forth+.
To move a container to another xrandr output such as +LVDS1+ or +VGA1+, you can
use the +move output+ command followed by the name of the target output. You
may also use +left+, +right+, +up+, +down+ instead of the xrandr output name to
move to the the next output in the specified direction.
*Examples*:
-------------------------
@ -847,6 +1203,9 @@ bindsym mod+2 workspace 2
bindsym mod+Shift+1 move workspace 1
bindsym mod+Shift+2 move workspace 2
...
# switch between the current and the previously focused one
bindsym mod+b workspace back_and_forth
-------------------------
==== Named workspaces
@ -889,9 +1248,9 @@ resize <grow|shrink> <direction> [<px> px] [or <ppt> ppt]
Direction can be one of +up+, +down+, +left+ or +right+. The optional pixel
argument specifies by how many pixels a *floating container* should be grown or
shrinked (the default is 10 pixels). The ppt argument means percentage points
shrunk (the default is 10 pixels). The ppt argument means percentage points
and specifies by how many percentage points a *tiling container* should be
grown or shrinked (the default is 10 percentage points).
grown or shrunk (the default is 10 percentage points).
I recommend using the resize command inside a so called +mode+:

View File

@ -8,30 +8,35 @@ AUTOGENERATED:=cfgparse.tab.c cfgparse.yy.c
FILES:=$(patsubst %.c,%.o,$(filter-out $(AUTOGENERATED),$(wildcard *.c)))
HEADERS:=$(wildcard *.h)
CPPFLAGS += -I$(TOPDIR)/include
# Depend on the specific file (.c for each .o) and on all headers
%.o: %.c ${HEADERS}
echo "CC $<"
echo "[i3-config-wizard] CC $<"
$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
all: i3-config-wizard
i3-config-wizard: cfgparse.y.o cfgparse.yy.o ${FILES}
echo "LINK i3-config-wizard"
$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
i3-config-wizard: $(TOPDIR)/libi3/libi3.a cfgparse.y.o cfgparse.yy.o ${FILES}
echo "[i3-config-wizard] LINK i3-config-wizard"
$(CC) $(LDFLAGS) -o $@ $(filter-out libi3/libi3.a,$^) $(LIBS)
$(TOPDIR)/libi3/%.a: $(TOPDIR)/libi3/*.c
$(MAKE) -C $(TOPDIR)/libi3
cfgparse.yy.o: cfgparse.l cfgparse.y.o ${HEADERS}
echo "LEX $<"
echo "[i3-config-wizard] LEX $<"
flex -i -o$(@:.o=.c) $<
$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(@:.o=.c)
cfgparse.y.o: cfgparse.y ${HEADERS}
echo "YACC $<"
echo "[i3-config-wizard] YACC $<"
bison --debug --verbose -b $(basename $< .y) -d $<
$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(<:.y=.tab.c)
install: all
echo "INSTALL"
echo "[i3-config-wizard] INSTALL"
$(INSTALL) -d -m 0755 $(DESTDIR)$(PREFIX)/bin
$(INSTALL) -m 0755 i3-config-wizard $(DESTDIR)$(PREFIX)/bin/

View File

@ -14,6 +14,8 @@
#include <X11/Xlib.h>
#include "libi3.h"
extern Display *dpy;
struct context {
@ -141,7 +143,7 @@ bindcode:
char *str = XKeysymToString(sym);
char *modifiers = modifier_to_string($<number>3);
// TODO: modifier to string
asprintf(&(context->result), "bindsym %s%s %s\n", modifiers, str, $<string>6);
sasprintf(&(context->result), "bindsym %s%s %s\n", modifiers, str, $<string>6);
free(modifiers);
}
;

View File

@ -1,68 +0,0 @@
/*
* vim:ts=8:expandtab
*
* i3 - an improved dynamic tiling window manager
*
* © 2009 Michael Stapelberg and contributors
*
* See file LICENSE for license information.
*
*/
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
#include <err.h>
/*
* Formats a message (payload) of the given size and type and sends it to i3 via
* the given socket file descriptor.
*
*/
void ipc_send_message(int sockfd, uint32_t message_size,
uint32_t message_type, uint8_t *payload) {
int buffer_size = strlen("i3-ipc") + sizeof(uint32_t) + sizeof(uint32_t) + message_size;
char msg[buffer_size];
char *walk = msg;
strcpy(walk, "i3-ipc");
walk += strlen("i3-ipc");
memcpy(walk, &message_size, sizeof(uint32_t));
walk += sizeof(uint32_t);
memcpy(walk, &message_type, sizeof(uint32_t));
walk += sizeof(uint32_t);
memcpy(walk, payload, message_size);
int sent_bytes = 0;
int bytes_to_go = buffer_size;
while (sent_bytes < bytes_to_go) {
int n = write(sockfd, msg + sent_bytes, bytes_to_go);
if (n == -1)
err(EXIT_FAILURE, "write() failed");
sent_bytes += n;
bytes_to_go -= n;
}
}
/*
* Connects to the i3 IPC socket and returns the file descriptor for the
* socket. die()s if anything goes wrong.
*
*/
int connect_ipc(char *socket_path) {
int sockfd = socket(AF_LOCAL, SOCK_STREAM, 0);
if (sockfd == -1)
err(EXIT_FAILURE, "Could not create socket");
struct sockaddr_un addr;
memset(&addr, 0, sizeof(struct sockaddr_un));
addr.sun_family = AF_LOCAL;
strcpy(addr.sun_path, socket_path);
if (connect(sockfd, (const struct sockaddr*)&addr, sizeof(struct sockaddr_un)) < 0)
err(EXIT_FAILURE, "Could not connect to i3");
return sockfd;
}

View File

@ -1,9 +0,0 @@
#ifndef _IPC_H
#define _IPC_H
void ipc_send_message(int sockfd, uint32_t message_size,
uint32_t message_type, uint8_t *payload);
int connect_ipc(char *socket_path);
#endif

View File

@ -2,10 +2,7 @@
* vim:ts=4:sw=4:expandtab
*
* i3 - an improved dynamic tiling window manager
*
* © 2011 Michael Stapelberg and contributors
*
* See file LICENSE for license information.
* © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
*
* i3-config-wizard: Program to convert configs using keycodes to configs using
* keysyms.
@ -51,19 +48,18 @@
while (0)
#include "xcb.h"
#include "ipc.h"
#include "libi3.h"
enum { STEP_WELCOME, STEP_GENERATE } current_step = STEP_WELCOME;
enum { MOD_Mod1, MOD_Mod4 } modifier = MOD_Mod4;
static char *config_path;
static xcb_connection_t *conn;
static uint32_t xcb_numlock_mask;
xcb_connection_t *conn;
static xcb_get_modifier_mapping_reply_t *modmap_reply;
static uint32_t font_id;
static uint32_t font_bold_id;
static i3Font font;
static i3Font bold_font;
static char *socket_path;
static int font_height;
static int font_bold_height;
static xcb_window_t win;
static xcb_pixmap_t pixmap;
static xcb_gcontext_t pixmap_gc;
@ -74,30 +70,6 @@ Display *dpy;
char *rewrite_binding(const char *bindingline);
static void finish();
#if defined(__APPLE__)
/*
* Taken from FreeBSD
* Returns a pointer to a new string which is a duplicate of the
* string, but only copies at most n characters.
*
*/
char *strndup(const char *str, size_t n) {
size_t len;
char *copy;
for (len = 0; len < n && str[len]; len++)
continue;
if ((copy = malloc(len + 1)) == NULL)
return (NULL);
memcpy(copy, str, len);
copy[len] = '\0';
return (copy);
}
#endif
/*
* This function resolves ~ in pathnames.
* It may resolve wildcards in the first part of the path, but if no match
@ -130,59 +102,23 @@ static char *resolve_tilde(const char *path) {
return result;
}
/*
* Try to get the socket path from X11 and return NULL if it doesnt work.
* As i3-msg is a short-running tool, we dont bother with cleaning up the
* connection and leave it up to the operating system on exit.
*
*/
static char *socket_path_from_x11() {
xcb_connection_t *conn;
int screen;
if ((conn = xcb_connect(NULL, &screen)) == NULL ||
xcb_connection_has_error(conn))
return NULL;
xcb_screen_t *root_screen = xcb_aux_get_screen(conn, screen);
xcb_window_t root = root_screen->root;
xcb_intern_atom_cookie_t atom_cookie;
xcb_intern_atom_reply_t *atom_reply;
atom_cookie = xcb_intern_atom(conn, 0, strlen("I3_SOCKET_PATH"), "I3_SOCKET_PATH");
atom_reply = xcb_intern_atom_reply(conn, atom_cookie, NULL);
if (atom_reply == NULL)
return NULL;
xcb_get_property_cookie_t prop_cookie;
xcb_get_property_reply_t *prop_reply;
prop_cookie = xcb_get_property_unchecked(conn, false, root, atom_reply->atom,
XCB_GET_PROPERTY_TYPE_ANY, 0, PATH_MAX);
prop_reply = xcb_get_property_reply(conn, prop_cookie, NULL);
if (prop_reply == NULL || xcb_get_property_value_length(prop_reply) == 0)
return NULL;
if (asprintf(&socket_path, "%.*s", xcb_get_property_value_length(prop_reply),
(char*)xcb_get_property_value(prop_reply)) == -1)
return NULL;
return socket_path;
}
/*
* Handles expose events, that is, draws the window contents.
*
*/
static int handle_expose() {
/* re-draw the background */
xcb_rectangle_t border = {0, 0, 300, (15*font_height) + 8};
xcb_change_gc_single(conn, pixmap_gc, XCB_GC_FOREGROUND, get_colorpixel(conn, "#000000"));
xcb_rectangle_t border = {0, 0, 300, (15 * font.height) + 8};
xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND, (uint32_t[]){ get_colorpixel("#000000") });
xcb_poly_fill_rectangle(conn, pixmap, pixmap_gc, 1, &border);
xcb_change_gc_single(conn, pixmap_gc, XCB_GC_FONT, font_id);
xcb_change_gc(conn, pixmap_gc, XCB_GC_FONT, (uint32_t[]){ font.id });
#define txt(x, row, text) xcb_image_text_8(conn, strlen(text), pixmap, pixmap_gc, x, (row * font_height) + 2, text)
#define txt(x, row, text) xcb_image_text_8(conn, strlen(text), pixmap, pixmap_gc, x, (row * font.height) + 2, text)
if (current_step == STEP_WELCOME) {
/* restore font color */
xcb_change_gc_single(conn, pixmap_gc, XCB_GC_FOREGROUND, get_colorpixel(conn, "#FFFFFF"));
xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND, (uint32_t[]){ get_colorpixel("#FFFFFF") });
txt(10, 2, "You have not configured i3 yet.");
txt(10, 3, "Do you want me to generate ~/.i3/config?");
@ -190,16 +126,16 @@ static int handle_expose() {
txt(85, 7, "No, I will use the defaults");
/* green */
xcb_change_gc_single(conn, pixmap_gc, XCB_GC_FOREGROUND, get_colorpixel(conn, "#00FF00"));
xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND, (uint32_t[]){ get_colorpixel("#00FF00") });
txt(25, 5, "<Enter>");
/* red */
xcb_change_gc_single(conn, pixmap_gc, XCB_GC_FOREGROUND, get_colorpixel(conn, "#FF0000"));
xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND, (uint32_t[]){ get_colorpixel("#FF0000") });
txt(31, 7, "<ESC>");
}
if (current_step == STEP_GENERATE) {
xcb_change_gc_single(conn, pixmap_gc, XCB_GC_FOREGROUND, get_colorpixel(conn, "#FFFFFF"));
xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND, (uint32_t[]){ get_colorpixel("#FFFFFF") });
txt(10, 2, "Please choose either:");
txt(85, 4, "Win as default modifier");
@ -214,20 +150,19 @@ static int handle_expose() {
else txt(31, 4, "<Win>");
/* the selected modifier */
xcb_change_gc_single(conn, pixmap_gc, XCB_GC_FONT, font_bold_id);
xcb_change_gc(conn, pixmap_gc, XCB_GC_FONT, (uint32_t[]){ bold_font.id });
if (modifier == MOD_Mod4)
txt(31, 4, "<Win>");
else txt(31, 5, "<Alt>");
/* green */
uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_FONT;
uint32_t values[] = { get_colorpixel(conn, "#00FF00"), font_id };
xcb_change_gc(conn, pixmap_gc, mask, values);
xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND | XCB_GC_FONT,
(uint32_t[]) { get_colorpixel("#00FF00"), font.id });
txt(25, 9, "<Enter>");
/* red */
xcb_change_gc_single(conn, pixmap_gc, XCB_GC_FOREGROUND, get_colorpixel(conn, "#FF0000"));
xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND, (uint32_t[]){ get_colorpixel("#FF0000") });
txt(31, 10, "<ESC>");
}
@ -406,7 +341,7 @@ static void finish() {
fclose(ks_config);
/* tell i3 to reload the config file */
int sockfd = connect_ipc(socket_path);
int sockfd = ipc_connect(socket_path);
ipc_send_message(sockfd, strlen("reload"), 0, (uint8_t*)"reload");
close(sockfd);
@ -485,6 +420,7 @@ int main(int argc, char *argv[]) {
xcb_get_modifier_mapping_cookie_t modmap_cookie;
modmap_cookie = xcb_get_modifier_mapping(conn);
symbols = xcb_key_symbols_alloc(conn);
/* Place requests for the atoms we need as soon as possible */
#define xmacro(atom) \
@ -498,17 +434,31 @@ int main(int argc, char *argv[]) {
if (!(modmap_reply = xcb_get_modifier_mapping_reply(conn, modmap_cookie, NULL)))
errx(EXIT_FAILURE, "Could not get modifier mapping\n");
/* XXX: we should refactor xcb_get_numlock_mask so that it uses the
* modifier mapping we already have */
xcb_get_numlock_mask(conn);
xcb_numlock_mask = get_mod_mask_for(XCB_NUM_LOCK, symbols, modmap_reply);
symbols = xcb_key_symbols_alloc(conn);
font_id = get_font_id(conn, pattern, &font_height);
font_bold_id = get_font_id(conn, patternbold, &font_bold_height);
font = load_font(pattern, true);
bold_font = load_font(patternbold, true);
/* Open an input window */
win = open_input_window(conn, 300, 205);
win = xcb_generate_id(conn);
xcb_create_window(
conn,
XCB_COPY_FROM_PARENT,
win, /* the window id */
root, /* parent == root */
490, 297, 300, 205, /* dimensions */
0, /* X11 border = 0, we draw our own */
XCB_WINDOW_CLASS_INPUT_OUTPUT,
XCB_WINDOW_CLASS_COPY_FROM_PARENT, /* copy visual from parent */
XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK,
(uint32_t[]){
0, /* back pixel: black */
XCB_EVENT_MASK_EXPOSURE |
XCB_EVENT_MASK_BUTTON_PRESS
});
/* Map the window (make it visible) */
xcb_map_window(conn, win);
/* Setup NetWM atoms */
#define xmacro(name) \

View File

@ -1,222 +0,0 @@
/*
* vim:ts=8:expandtab
*
* i3 - an improved dynamic tiling window manager
*
* © 2009 Michael Stapelberg and contributors
*
* See file LICENSE for license information.
*
*/
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <err.h>
#include <xcb/xcb.h>
#include <xcb/xcb_keysyms.h>
#include <X11/keysym.h>
#include "xcb.h"
extern xcb_window_t root;
unsigned int xcb_numlock_mask;
/*
* Convenience-wrapper around xcb_change_gc which saves us declaring a variable
*
*/
void xcb_change_gc_single(xcb_connection_t *conn, xcb_gcontext_t gc, uint32_t mask, uint32_t value) {
xcb_change_gc(conn, gc, mask, &value);
}
/*
* Returns the colorpixel to use for the given hex color (think of HTML).
*
* The hex_color has to start with #, for example #FF00FF.
*
* NOTE that get_colorpixel() does _NOT_ check the given color code for validity.
* This has to be done by the caller.
*
*/
uint32_t get_colorpixel(xcb_connection_t *conn, char *hex) {
char strgroups[3][3] = {{hex[1], hex[2], '\0'},
{hex[3], hex[4], '\0'},
{hex[5], hex[6], '\0'}};
uint32_t rgb16[3] = {(strtol(strgroups[0], NULL, 16)),
(strtol(strgroups[1], NULL, 16)),
(strtol(strgroups[2], NULL, 16))};
return (rgb16[0] << 16) + (rgb16[1] << 8) + rgb16[2];
}
/*
* Returns the mask for Mode_switch (to be used for looking up keysymbols by
* keycode).
*
*/
uint32_t get_mod_mask(xcb_connection_t *conn, uint32_t keycode) {
xcb_key_symbols_t *symbols = xcb_key_symbols_alloc(conn);
xcb_get_modifier_mapping_reply_t *modmap_r;
xcb_keycode_t *modmap, kc;
xcb_keycode_t *modeswitchcodes = xcb_key_symbols_get_keycode(symbols, keycode);
if (modeswitchcodes == NULL)
return 0;
modmap_r = xcb_get_modifier_mapping_reply(conn, xcb_get_modifier_mapping(conn), NULL);
modmap = xcb_get_modifier_mapping_keycodes(modmap_r);
for (int i = 0; i < 8; i++)
for (int j = 0; j < modmap_r->keycodes_per_modifier; j++) {
kc = modmap[i * modmap_r->keycodes_per_modifier + j];
for (xcb_keycode_t *ktest = modeswitchcodes; *ktest; ktest++) {
if (*ktest != kc)
continue;
free(modeswitchcodes);
free(modmap_r);
return (1 << i);
}
}
return 0;
}
/*
* Opens the window we use for input/output and maps it
*
*/
xcb_window_t open_input_window(xcb_connection_t *conn, uint32_t width, uint32_t height) {
xcb_window_t win = xcb_generate_id(conn);
//xcb_cursor_t cursor_id = xcb_generate_id(conn);
#if 0
/* Use the default cursor (left pointer) */
if (cursor > -1) {
i3Font *cursor_font = load_font(conn, "cursor");
xcb_create_glyph_cursor(conn, cursor_id, cursor_font->id, cursor_font->id,
XCB_CURSOR_LEFT_PTR, XCB_CURSOR_LEFT_PTR + 1,
0, 0, 0, 65535, 65535, 65535);
}
#endif
uint32_t mask = 0;
uint32_t values[3];
mask |= XCB_CW_BACK_PIXEL;
values[0] = 0;
mask |= XCB_CW_EVENT_MASK;
values[1] = XCB_EVENT_MASK_EXPOSURE |
XCB_EVENT_MASK_BUTTON_PRESS;
xcb_create_window(conn,
XCB_COPY_FROM_PARENT,
win, /* the window id */
root, /* parent == root */
490, 297, width, height, /* dimensions */
0, /* border = 0, we draw our own */
XCB_WINDOW_CLASS_INPUT_OUTPUT,
XCB_WINDOW_CLASS_COPY_FROM_PARENT, /* copy visual from parent */
mask,
values);
#if 0
if (cursor > -1)
xcb_change_window_attributes(conn, result, XCB_CW_CURSOR, &cursor_id);
#endif
/* Map the window (= make it visible) */
xcb_map_window(conn, win);
return win;
}
/*
* Returns the ID of the font matching the given pattern and stores the height
* of the font (in pixels) in *font_height. die()s if no font matches.
*
*/
int get_font_id(xcb_connection_t *conn, char *pattern, int *font_height) {
xcb_void_cookie_t font_cookie;
xcb_list_fonts_with_info_cookie_t info_cookie;
/* Send all our requests first */
int result;
result = xcb_generate_id(conn);
font_cookie = xcb_open_font_checked(conn, result, strlen(pattern), pattern);
info_cookie = xcb_list_fonts_with_info(conn, 1, strlen(pattern), pattern);
xcb_generic_error_t *error = xcb_request_check(conn, font_cookie);
if (error != NULL) {
fprintf(stderr, "ERROR: Could not open font: %d\n", error->error_code);
exit(1);
}
/* Get information (height/name) for this font */
xcb_list_fonts_with_info_reply_t *reply = xcb_list_fonts_with_info_reply(conn, info_cookie, NULL);
if (reply == NULL)
errx(1, "Could not load font \"%s\"\n", pattern);
*font_height = reply->font_ascent + reply->font_descent;
return result;
}
/*
* Finds out which modifier mask is the one for numlock, as the user may change this.
*
*/
void xcb_get_numlock_mask(xcb_connection_t *conn) {
xcb_key_symbols_t *keysyms;
xcb_get_modifier_mapping_cookie_t cookie;
xcb_get_modifier_mapping_reply_t *reply;
xcb_keycode_t *modmap;
int mask, i;
const int masks[8] = { XCB_MOD_MASK_SHIFT,
XCB_MOD_MASK_LOCK,
XCB_MOD_MASK_CONTROL,
XCB_MOD_MASK_1,
XCB_MOD_MASK_2,
XCB_MOD_MASK_3,
XCB_MOD_MASK_4,
XCB_MOD_MASK_5 };
/* Request the modifier map */
cookie = xcb_get_modifier_mapping_unchecked(conn);
/* Get the keysymbols */
keysyms = xcb_key_symbols_alloc(conn);
if ((reply = xcb_get_modifier_mapping_reply(conn, cookie, NULL)) == NULL) {
xcb_key_symbols_free(keysyms);
return;
}
modmap = xcb_get_modifier_mapping_keycodes(reply);
/* Get the keycode for numlock */
#ifdef OLD_XCB_KEYSYMS_API
xcb_keycode_t numlock = xcb_key_symbols_get_keycode(keysyms, XCB_NUM_LOCK);
#else
/* For now, we only use the first keysymbol. */
xcb_keycode_t *numlock_syms = xcb_key_symbols_get_keycode(keysyms, XCB_NUM_LOCK);
if (numlock_syms == NULL)
return;
xcb_keycode_t numlock = *numlock_syms;
free(numlock_syms);
#endif
/* Check all modifiers (Mod1-Mod5, Shift, Control, Lock) */
for (mask = 0; mask < 8; mask++)
for (i = 0; i < reply->keycodes_per_modifier; i++)
if (modmap[(mask * reply->keycodes_per_modifier) + i] == numlock)
xcb_numlock_mask = masks[mask];
xcb_key_symbols_free(keysyms);
free(reply);
}

View File

@ -8,17 +8,4 @@
#include "atoms.xmacro"
#undef xmacro
extern unsigned int xcb_numlock_mask;
void xcb_change_gc_single(xcb_connection_t *conn, xcb_gcontext_t gc, uint32_t mask, uint32_t value);
uint32_t get_colorpixel(xcb_connection_t *conn, char *hex);
uint32_t get_mod_mask(xcb_connection_t *conn, uint32_t keycode);
xcb_window_t open_input_window(xcb_connection_t *conn, uint32_t width, uint32_t height);
int get_font_id(xcb_connection_t *conn, char *pattern, int *font_height);
/**
* Finds out which modifier mask is the one for numlock, as the user may change this.
*
*/
void xcb_get_numlock_mask(xcb_connection_t *conn);
#endif

View File

@ -3,23 +3,28 @@ TOPDIR=..
include $(TOPDIR)/common.mk
CPPFLAGS += -I$(TOPDIR)/include
# Depend on the object files of all source-files in src/*.c and on all header files
FILES=$(patsubst %.c,%.o,$(wildcard *.c))
HEADERS=$(wildcard *.h)
# Depend on the specific file (.c for each .o) and on all headers
%.o: %.c ${HEADERS}
echo "CC $<"
echo "[i3-input] CC $<"
$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
all: i3-input
i3-input: ${FILES}
echo "LINK i3-input"
$(CC) $(LDFLAGS) -o $@ ${FILES} $(LIBS)
i3-input: $(TOPDIR)/libi3/libi3.a ${FILES}
echo "[i3-input] LINK i3-input"
$(CC) $(LDFLAGS) -o $@ $(filter-out libi3/libi3.a,$^) $(LIBS)
$(TOPDIR)/libi3/%.a: $(TOPDIR)/libi3/*.c
$(MAKE) -C $(TOPDIR)/libi3
install: all
echo "INSTALL"
echo "[i3-input] INSTALL"
$(INSTALL) -d -m 0755 $(DESTDIR)$(PREFIX)/bin
$(INSTALL) -m 0755 i3-input $(DESTDIR)$(PREFIX)/bin/

View File

@ -16,13 +16,5 @@ extern xcb_window_t root;
char *convert_ucs_to_utf8(char *input);
char *convert_utf8_to_ucs2(char *input, int *real_strlen);
uint32_t get_colorpixel(xcb_connection_t *conn, char *hex);
uint32_t get_mod_mask(xcb_connection_t *conn, uint32_t keycode);
int connect_ipc(char *socket_path);
void ipc_send_message(int sockfd, uint32_t message_size,
uint32_t message_type, uint8_t *payload);
xcb_window_t open_input_window(xcb_connection_t *conn, uint32_t width, uint32_t height);
int get_font_id(xcb_connection_t *conn, char *pattern, int *font_height);
void xcb_change_gc_single(xcb_connection_t *conn, xcb_gcontext_t gc, uint32_t mask, uint32_t value);
#endif

View File

@ -1,68 +0,0 @@
/*
* vim:ts=8:expandtab
*
* i3 - an improved dynamic tiling window manager
*
* © 2009 Michael Stapelberg and contributors
*
* See file LICENSE for license information.
*
*/
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
#include <err.h>
/*
* Formats a message (payload) of the given size and type and sends it to i3 via
* the given socket file descriptor.
*
*/
void ipc_send_message(int sockfd, uint32_t message_size,
uint32_t message_type, uint8_t *payload) {
int buffer_size = strlen("i3-ipc") + sizeof(uint32_t) + sizeof(uint32_t) + message_size;
char msg[buffer_size];
char *walk = msg;
strcpy(walk, "i3-ipc");
walk += strlen("i3-ipc");
memcpy(walk, &message_size, sizeof(uint32_t));
walk += sizeof(uint32_t);
memcpy(walk, &message_type, sizeof(uint32_t));
walk += sizeof(uint32_t);
memcpy(walk, payload, message_size);
int sent_bytes = 0;
int bytes_to_go = buffer_size;
while (sent_bytes < bytes_to_go) {
int n = write(sockfd, msg + sent_bytes, bytes_to_go);
if (n == -1)
err(EXIT_FAILURE, "write() failed");
sent_bytes += n;
bytes_to_go -= n;
}
}
/*
* Connects to the i3 IPC socket and returns the file descriptor for the
* socket. die()s if anything goes wrong.
*
*/
int connect_ipc(char *socket_path) {
int sockfd = socket(AF_LOCAL, SOCK_STREAM, 0);
if (sockfd == -1)
err(EXIT_FAILURE, "Could not create socket");
struct sockaddr_un addr;
memset(&addr, 0, sizeof(struct sockaddr_un));
addr.sun_family = AF_LOCAL;
strncpy(addr.sun_path, socket_path, sizeof(addr.sun_path) - 1);
if (connect(sockfd, (const struct sockaddr*)&addr, sizeof(struct sockaddr_un)) < 0)
err(EXIT_FAILURE, "Could not connect to i3");
return sockfd;
}

View File

@ -1,11 +1,8 @@
/*
* vim:ts=8:expandtab
* vim:ts=4:sw=4:expandtab
*
* i3 - an improved dynamic tiling window manager
*
* © 2009 Michael Stapelberg and contributors
*
* See file LICENSE for license information.
* © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
*
* i3-input/main.c: Utility which lets the user input commands and sends them
* to i3.
@ -35,11 +32,15 @@
#include "i3-input.h"
#include "libi3.h"
/* IPC format string. %s will be replaced with what the user entered, then
* the command will be sent to i3 */
static char *format;
static char *socket_path;
static int sockfd;
static xcb_key_symbols_t *symbols;
static int modeswitchmask;
static int numlockmask;
static bool modeswitch_active = false;
static xcb_window_t win;
static xcb_pixmap_t pixmap;
@ -47,48 +48,12 @@ static xcb_gcontext_t pixmap_gc;
static char *glyphs_ucs[512];
static char *glyphs_utf8[512];
static int input_position;
static int font_height;
static char *command_prefix;
static i3Font font;
static char *prompt;
static int prompt_len;
static int limit;
xcb_window_t root;
/*
* Try to get the socket path from X11 and return NULL if it doesnt work.
* As i3-msg is a short-running tool, we dont bother with cleaning up the
* connection and leave it up to the operating system on exit.
*
*/
static char *socket_path_from_x11() {
xcb_connection_t *conn;
int screen;
if ((conn = xcb_connect(NULL, &screen)) == NULL ||
xcb_connection_has_error(conn))
return NULL;
xcb_screen_t *root_screen = xcb_aux_get_screen(conn, screen);
xcb_window_t root = root_screen->root;
xcb_intern_atom_cookie_t atom_cookie;
xcb_intern_atom_reply_t *atom_reply;
atom_cookie = xcb_intern_atom(conn, 0, strlen("I3_SOCKET_PATH"), "I3_SOCKET_PATH");
atom_reply = xcb_intern_atom_reply(conn, atom_cookie, NULL);
if (atom_reply == NULL)
return NULL;
xcb_get_property_cookie_t prop_cookie;
xcb_get_property_reply_t *prop_reply;
prop_cookie = xcb_get_property_unchecked(conn, false, root, atom_reply->atom,
XCB_GET_PROPERTY_TYPE_ANY, 0, PATH_MAX);
prop_reply = xcb_get_property_reply(conn, prop_cookie, NULL);
if (prop_reply == NULL || xcb_get_property_value_length(prop_reply) == 0)
return NULL;
if (asprintf(&socket_path, "%.*s", xcb_get_property_value_length(prop_reply),
(char*)xcb_get_property_value(prop_reply)) == -1)
return NULL;
return socket_path;
}
/*
* Concats the glyphs (either UCS-2 or UTF-8) to a single string, suitable for
@ -122,14 +87,14 @@ static int handle_expose(void *data, xcb_connection_t *conn, xcb_expose_event_t
printf("expose!\n");
/* re-draw the background */
xcb_rectangle_t border = {0, 0, 500, font_height + 8}, inner = {2, 2, 496, font_height + 8 - 4};
xcb_change_gc_single(conn, pixmap_gc, XCB_GC_FOREGROUND, get_colorpixel(conn, "#FF0000"));
xcb_rectangle_t border = {0, 0, 500, font.height + 8}, inner = {2, 2, 496, font.height + 8 - 4};
xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND, (uint32_t[]){ get_colorpixel("#FF0000") });
xcb_poly_fill_rectangle(conn, pixmap, pixmap_gc, 1, &border);
xcb_change_gc_single(conn, pixmap_gc, XCB_GC_FOREGROUND, get_colorpixel(conn, "#000000"));
xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND, (uint32_t[]){ get_colorpixel("#000000") });
xcb_poly_fill_rectangle(conn, pixmap, pixmap_gc, 1, &inner);
/* restore font color */
xcb_change_gc_single(conn, pixmap_gc, XCB_GC_FOREGROUND, get_colorpixel(conn, "#FFFFFF"));
xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND, (uint32_t[]){ get_colorpixel("#FFFFFF") });
uint8_t *con = concat_strings(glyphs_ucs, input_position);
char *full_text = (char*)con;
if (prompt != NULL) {
@ -140,10 +105,10 @@ static int handle_expose(void *data, xcb_connection_t *conn, xcb_expose_event_t
memcpy(full_text + (prompt_len * 2), con, input_position * 2);
}
xcb_image_text_16(conn, input_position + prompt_len, pixmap, pixmap_gc, 4 /* X */,
font_height + 2 /* Y = baseline of font */, (xcb_char2b_t*)full_text);
font.height + 2 /* Y = baseline of font */, (xcb_char2b_t*)full_text);
/* Copy the contents of the pixmap to the real window */
xcb_copy_area(conn, pixmap, win, pixmap_gc, 0, 0, 0, 0, /* */ 500, font_height + 8);
xcb_copy_area(conn, pixmap, win, pixmap_gc, 0, 0, 0, 0, /* */ 500, font.height + 8);
xcb_flush(conn);
free(con);
if (prompt != NULL)
@ -159,8 +124,15 @@ static int handle_expose(void *data, xcb_connection_t *conn, xcb_expose_event_t
static int handle_key_release(void *ignored, xcb_connection_t *conn, xcb_key_release_event_t *event) {
printf("releasing %d, state raw = %d\n", event->detail, event->state);
/* fix state */
event->state &= ~numlockmask;
/* See the documentation of xcb_key_symbols_get_keysym for this one.
* Basically: We get either col 0 or col 1, depending on whether shift is
* pressed. */
int col = (event->state & XCB_MOD_MASK_SHIFT);
/* If modeswitch is currently active, we need to look in group 2 or 3,
* respectively. */
if (modeswitch_active)
col += 2;
xcb_keysym_t sym = xcb_key_press_lookup_keysym(symbols, event, event->state);
if (sym == XK_Mode_switch) {
@ -172,16 +144,41 @@ static int handle_key_release(void *ignored, xcb_connection_t *conn, xcb_key_rel
}
static void finish_input() {
uint8_t *command = concat_strings(glyphs_utf8, input_position);
char *full_command = (char*)command;
/* prefix the command if a prefix was specified on commandline */
if (command_prefix != NULL) {
if (asprintf(&full_command, "%s%s", command_prefix, command) == -1)
err(EXIT_FAILURE, "asprintf() failed\n");
}
printf("command = %s\n", full_command);
char *command = (char*)concat_strings(glyphs_utf8, input_position);
ipc_send_message(sockfd, strlen(full_command), 0, (uint8_t*)full_command);
/* count the occurences of %s in the string */
int c;
int len = strlen(format);
int cnt = 0;
for (c = 0; c < (len-1); c++)
if (format[c] == '%' && format[c+1] == 's')
cnt++;
printf("occurences = %d\n", cnt);
/* allocate space for the output */
int inputlen = strlen(command);
char *full = calloc(1,
strlen(format) - (2 * cnt) /* format without all %s */
+ (inputlen * cnt) /* replaced %s */
+ 1); /* trailing NUL */
char *dest = full;
for (c = 0; c < len; c++) {
/* if this is not % or it is % but without a following 's',
* just copy the character */
if (format[c] != '%' || (c == (len-1)) || format[c+1] != 's')
*(dest++) = format[c];
else {
strncat(dest, command, inputlen);
dest += inputlen;
/* skip the following 's' of '%s' */
c++;
}
}
/* prefix the command if a prefix was specified on commandline */
printf("command = %s\n", full);
ipc_send_message(sockfd, strlen(full), 0, (uint8_t*)full);
#if 0
free(command);
@ -202,16 +199,17 @@ static void finish_input() {
static int handle_key_press(void *ignored, xcb_connection_t *conn, xcb_key_press_event_t *event) {
printf("Keypress %d, state raw = %d\n", event->detail, event->state);
/* fix state */
/* See the documentation of xcb_key_symbols_get_keysym for this one.
* Basically: We get either col 0 or col 1, depending on whether shift is
* pressed. */
int col = (event->state & XCB_MOD_MASK_SHIFT);
/* If modeswitch is currently active, we need to look in group 2 or 3,
* respectively. */
if (modeswitch_active)
event->state |= modeswitchmask;
col += 2;
/* Apparantly, after activating numlock once, the numlock modifier
* stays turned on (use xev(1) to verify). So, to resolve useful
* keysyms, we remove the numlock flag from the event state */
event->state &= ~numlockmask;
xcb_keysym_t sym = xcb_key_press_lookup_keysym(symbols, event, event->state);
xcb_keysym_t sym = xcb_key_press_lookup_keysym(symbols, event, col);
if (sym == XK_Mode_switch) {
printf("Mode switch enabled\n");
modeswitch_active = true;
@ -280,8 +278,9 @@ static int handle_key_press(void *ignored, xcb_connection_t *conn, xcb_key_press
}
int main(int argc, char *argv[]) {
format = strdup("%s");
socket_path = getenv("I3SOCK");
char *pattern = "-misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1";
char *pattern = sstrdup("-misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1");
int o, option_index = 0;
static struct option long_options[] = {
@ -290,12 +289,13 @@ int main(int argc, char *argv[]) {
{"limit", required_argument, 0, 'l'},
{"prompt", required_argument, 0, 'P'},
{"prefix", required_argument, 0, 'p'},
{"format", required_argument, 0, 'F'},
{"font", required_argument, 0, 'f'},
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
};
char *options_string = "s:p:P:f:l:vh";
char *options_string = "s:p:P:f:l:F:vh";
while ((o = getopt_long(argc, argv, options_string, long_options, &option_index)) != -1) {
switch (o) {
@ -307,8 +307,10 @@ int main(int argc, char *argv[]) {
printf("i3-input " I3_VERSION);
return 0;
case 'p':
FREE(command_prefix);
command_prefix = strdup(optarg);
/* This option is deprecated, but will still work in i3 v4.1, 4.2 and 4.3 */
fprintf(stderr, "i3-input: WARNING: the -p option is DEPRECATED in favor of the -F (format) option\n");
FREE(format);
sasprintf(&format, "%s%%s", optarg);
break;
case 'l':
limit = atoi(optarg);
@ -321,45 +323,70 @@ int main(int argc, char *argv[]) {
FREE(pattern);
pattern = strdup(optarg);
break;
case 'F':
FREE(format);
format = strdup(optarg);
break;
case 'h':
printf("i3-input " I3_VERSION);
printf("i3-input [-s <socket>] [-p <prefix>] [-l <limit>] [-P <prompt>] [-f <font>] [-v]\n");
printf("i3-input " I3_VERSION "\n");
printf("i3-input [-s <socket>] [-F <format>] [-l <limit>] [-P <prompt>] [-f <font>] [-v]\n");
printf("\n");
printf("Example:\n");
printf(" i3-input -F 'workspace \"%%s\"' -P 'Switch to workspace: '\n");
return 0;
}
}
printf("using format \"%s\"\n", format);
if (socket_path == NULL)
socket_path = socket_path_from_x11();
if (socket_path == NULL)
socket_path = "/tmp/i3-ipc.sock";
sockfd = connect_ipc(socket_path);
sockfd = ipc_connect(socket_path);
if (prompt != NULL)
prompt = convert_utf8_to_ucs2(prompt, &prompt_len);
int screens;
xcb_connection_t *conn = xcb_connect(NULL, &screens);
if (xcb_connection_has_error(conn))
conn = xcb_connect(NULL, &screens);
if (!conn || xcb_connection_has_error(conn))
die("Cannot open display\n");
xcb_screen_t *root_screen = xcb_aux_get_screen(conn, screens);
root = root_screen->root;
modeswitchmask = get_mod_mask(conn, XK_Mode_switch);
numlockmask = get_mod_mask(conn, XK_Num_Lock);
symbols = xcb_key_symbols_alloc(conn);
uint32_t font_id = get_font_id(conn, pattern, &font_height);
font = load_font(pattern, true);
/* Open an input window */
win = open_input_window(conn, 500, font_height + 8);
win = xcb_generate_id(conn);
xcb_create_window(
conn,
XCB_COPY_FROM_PARENT,
win, /* the window id */
root, /* parent == root */
50, 50, 500, font.height + 8, /* dimensions */
0, /* X11 border = 0, we draw our own */
XCB_WINDOW_CLASS_INPUT_OUTPUT,
XCB_WINDOW_CLASS_COPY_FROM_PARENT, /* copy visual from parent */
XCB_CW_BACK_PIXEL | XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK,
(uint32_t[]){
0, /* back pixel: black */
1, /* override redirect: dont manage this window */
XCB_EVENT_MASK_EXPOSURE
});
/* Map the window (make it visible) */
xcb_map_window(conn, win);
/* Create pixmap */
pixmap = xcb_generate_id(conn);
pixmap_gc = xcb_generate_id(conn);
xcb_create_pixmap(conn, root_screen->root_depth, pixmap, win, 500, font_height + 8);
xcb_create_pixmap(conn, root_screen->root_depth, pixmap, win, 500, font.height + 8);
xcb_create_gc(conn, pixmap_gc, pixmap, 0, 0);
/* Set input focus (we have override_redirect=1, so the wm will not do
@ -367,7 +394,7 @@ int main(int argc, char *argv[]) {
xcb_set_input_focus(conn, XCB_INPUT_FOCUS_POINTER_ROOT, win, XCB_CURRENT_TIME);
/* Create graphics context */
xcb_change_gc_single(conn, pixmap_gc, XCB_GC_FONT, font_id);
xcb_change_gc(conn, pixmap_gc, XCB_GC_FONT, (uint32_t[]){ font.id });
/* Grab the keyboard to get all input */
xcb_flush(conn);

View File

@ -1,11 +1,11 @@
/*
* vim:ts=8:expandtab
* vim:ts=4:sw=4:expandtab
*
* i3 - an improved dynamic tiling window manager
* © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
*
* © 2009 Michael Stapelberg and contributors
*
* See file LICENSE for license information.
* ucs2_to_utf8.c: Converts between UCS-2 and UTF-8, both of which are used in
* different contexts in X11.
*
*/
#include <stdlib.h>
@ -14,6 +14,8 @@
#include <err.h>
#include <iconv.h>
#include "libi3.h"
static iconv_t conversion_descriptor = 0;
static iconv_t conversion_descriptor2 = 0;
@ -27,9 +29,7 @@ char *convert_ucs_to_utf8(char *input) {
/* UTF-8 may consume up to 4 byte */
int buffer_size = 8;
char *buffer = calloc(buffer_size, 1);
if (buffer == NULL)
err(EXIT_FAILURE, "malloc() failed\n");
char *buffer = scalloc(buffer_size);
size_t output_size = buffer_size;
/* We need to use an additional pointer, because iconv() modifies it */
char *output = buffer;
@ -37,10 +37,8 @@ char *convert_ucs_to_utf8(char *input) {
/* We convert the input into UCS-2 big endian */
if (conversion_descriptor == 0) {
conversion_descriptor = iconv_open("UTF-8", "UCS-2BE");
if (conversion_descriptor == 0) {
fprintf(stderr, "error opening the conversion context\n");
exit(1);
}
if (conversion_descriptor == 0)
errx(EXIT_FAILURE, "Error opening the conversion context");
}
/* Get the conversion descriptor back to original state */
@ -49,6 +47,7 @@ char *convert_ucs_to_utf8(char *input) {
/* Convert our text */
int rc = iconv(conversion_descriptor, (void*)&input, &input_size, &output, &output_size);
if (rc == (size_t)-1) {
free(buffer);
perror("Converting to UCS-2 failed");
return NULL;
}
@ -68,9 +67,7 @@ char *convert_utf8_to_ucs2(char *input, int *real_strlen) {
/* UCS-2 consumes exactly two bytes for each glyph */
int buffer_size = input_size * 2;
char *buffer = malloc(buffer_size);
if (buffer == NULL)
err(EXIT_FAILURE, "malloc() failed\n");
char *buffer = smalloc(buffer_size);
size_t output_size = buffer_size;
/* We need to use an additional pointer, because iconv() modifies it */
char *output = buffer;
@ -78,10 +75,8 @@ char *convert_utf8_to_ucs2(char *input, int *real_strlen) {
/* We convert the input into UCS-2 big endian */
if (conversion_descriptor2 == 0) {
conversion_descriptor2 = iconv_open("UCS-2BE", "UTF-8");
if (conversion_descriptor2 == 0) {
fprintf(stderr, "error opening the conversion context\n");
exit(1);
}
if (conversion_descriptor2 == 0)
errx(EXIT_FAILURE, "Error opening the conversion context");
}
/* Get the conversion descriptor back to original state */
@ -91,6 +86,7 @@ char *convert_utf8_to_ucs2(char *input, int *real_strlen) {
int rc = iconv(conversion_descriptor2, (void*)&input, &input_size, &output, &output_size);
if (rc == (size_t)-1) {
perror("Converting to UCS-2 failed");
free(buffer);
if (real_strlen != NULL)
*real_strlen = 0;
return NULL;

View File

@ -1,165 +0,0 @@
/*
* vim:ts=8:expandtab
*
* i3 - an improved dynamic tiling window manager
*
* © 2009 Michael Stapelberg and contributors
*
* See file LICENSE for license information.
*
*/
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <xcb/xcb.h>
#include <xcb/xcb_keysyms.h>
#include <X11/keysym.h>
#include "i3-input.h"
/*
* Convenience-wrapper around xcb_change_gc which saves us declaring a variable
*
*/
void xcb_change_gc_single(xcb_connection_t *conn, xcb_gcontext_t gc, uint32_t mask, uint32_t value) {
xcb_change_gc(conn, gc, mask, &value);
}
/*
* Returns the colorpixel to use for the given hex color (think of HTML).
*
* The hex_color has to start with #, for example #FF00FF.
*
* NOTE that get_colorpixel() does _NOT_ check the given color code for validity.
* This has to be done by the caller.
*
*/
uint32_t get_colorpixel(xcb_connection_t *conn, char *hex) {
char strgroups[3][3] = {{hex[1], hex[2], '\0'},
{hex[3], hex[4], '\0'},
{hex[5], hex[6], '\0'}};
uint32_t rgb16[3] = {(strtol(strgroups[0], NULL, 16)),
(strtol(strgroups[1], NULL, 16)),
(strtol(strgroups[2], NULL, 16))};
return (rgb16[0] << 16) + (rgb16[1] << 8) + rgb16[2];
}
/*
* Returns the mask for Mode_switch (to be used for looking up keysymbols by
* keycode).
*
*/
uint32_t get_mod_mask(xcb_connection_t *conn, uint32_t keycode) {
xcb_key_symbols_t *symbols = xcb_key_symbols_alloc(conn);
xcb_get_modifier_mapping_reply_t *modmap_r;
xcb_keycode_t *modmap, kc;
xcb_keycode_t *modeswitchcodes = xcb_key_symbols_get_keycode(symbols, keycode);
if (modeswitchcodes == NULL)
return 0;
modmap_r = xcb_get_modifier_mapping_reply(conn, xcb_get_modifier_mapping(conn), NULL);
modmap = xcb_get_modifier_mapping_keycodes(modmap_r);
for (int i = 0; i < 8; i++)
for (int j = 0; j < modmap_r->keycodes_per_modifier; j++) {
kc = modmap[i * modmap_r->keycodes_per_modifier + j];
for (xcb_keycode_t *ktest = modeswitchcodes; *ktest; ktest++) {
if (*ktest != kc)
continue;
free(modeswitchcodes);
free(modmap_r);
return (1 << i);
}
}
return 0;
}
/*
* Opens the window we use for input/output and maps it
*
*/
xcb_window_t open_input_window(xcb_connection_t *conn, uint32_t width, uint32_t height) {
xcb_window_t win = xcb_generate_id(conn);
//xcb_cursor_t cursor_id = xcb_generate_id(conn);
#if 0
/* Use the default cursor (left pointer) */
if (cursor > -1) {
i3Font *cursor_font = load_font(conn, "cursor");
xcb_create_glyph_cursor(conn, cursor_id, cursor_font->id, cursor_font->id,
XCB_CURSOR_LEFT_PTR, XCB_CURSOR_LEFT_PTR + 1,
0, 0, 0, 65535, 65535, 65535);
}
#endif
uint32_t mask = 0;
uint32_t values[3];
mask |= XCB_CW_BACK_PIXEL;
values[0] = 0;
mask |= XCB_CW_OVERRIDE_REDIRECT;
values[1] = 1;
mask |= XCB_CW_EVENT_MASK;
values[2] = XCB_EVENT_MASK_EXPOSURE;
xcb_create_window(conn,
XCB_COPY_FROM_PARENT,
win, /* the window id */
root, /* parent == root */
50, 50, width, height, /* dimensions */
0, /* border = 0, we draw our own */
XCB_WINDOW_CLASS_INPUT_OUTPUT,
XCB_WINDOW_CLASS_COPY_FROM_PARENT, /* copy visual from parent */
mask,
values);
#if 0
if (cursor > -1)
xcb_change_window_attributes(conn, result, XCB_CW_CURSOR, &cursor_id);
#endif
/* Map the window (= make it visible) */
xcb_map_window(conn, win);
return win;
}
/*
* Returns the ID of the font matching the given pattern and stores the height
* of the font (in pixels) in *font_height. die()s if no font matches.
*
*/
int get_font_id(xcb_connection_t *conn, char *pattern, int *font_height) {
xcb_void_cookie_t font_cookie;
xcb_list_fonts_with_info_cookie_t info_cookie;
/* Send all our requests first */
int result;
result = xcb_generate_id(conn);
font_cookie = xcb_open_font_checked(conn, result, strlen(pattern), pattern);
info_cookie = xcb_list_fonts_with_info(conn, 1, strlen(pattern), pattern);
xcb_generic_error_t *error = xcb_request_check(conn, font_cookie);
if (error != NULL) {
fprintf(stderr, "ERROR: Could not open font: %d\n", error->error_code);
exit(1);
}
/* Get information (height/name) for this font */
xcb_list_fonts_with_info_reply_t *reply = xcb_list_fonts_with_info_reply(conn, info_cookie, NULL);
if (reply == NULL)
die("Could not load font \"%s\"\n", pattern);
*font_height = reply->font_ascent + reply->font_descent;
return result;
}

View File

@ -358,6 +358,8 @@ sub convert_command {
# add an i3bar invocation automatically if no 'workspace_bar no' was found
if ($workspace_bar) {
print "\n";
print "# XXX: Automatically added a call to i3bar to provide a workspace bar\n";
print "exec i3status | i3bar -d\n";
print "# XXX: Automatically added a bar configuration\n";
print "bar {\n";
print " status_command i3status\n";
print "}\n";
}

View File

@ -11,17 +11,17 @@ HEADERS=$(wildcard *.h)
# Depend on the specific file (.c for each .o) and on all headers
%.o: %.c ${HEADERS}
echo "CC $<"
echo "[i3-msg] CC $<"
$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
all: i3-msg
i3-msg: ${FILES}
echo "LINK i3-msg"
echo "[i3-msg] LINK i3-msg"
$(CC) $(LDFLAGS) -o i3-msg ${FILES} $(LIBS)
install: all
echo "INSTALL"
echo "[i3-msg] INSTALL"
$(INSTALL) -d -m 0755 $(DESTDIR)$(PREFIX)/bin
$(INSTALL) -m 0755 i3-msg $(DESTDIR)$(PREFIX)/bin/

View File

@ -2,15 +2,15 @@
* vim:ts=4:sw=4:expandtab
*
* i3 - an improved dynamic tiling window manager
*
* © 2009-2010 Michael Stapelberg and contributors
*
* See file LICENSE for license information.
* © 2009-2010 Michael Stapelberg and contributors (see also: LICENSE)
*
* i3-msg/main.c: Utility which sends messages to a running i3-instance using
* IPC via UNIX domain sockets.
*
* This serves as an example for how to send your own messages to i3.
* This (in combination with libi3/ipc_send_message.c and
* libi3/ipc_recv_message.c) serves as an example for how to send your own
* messages to i3.
*
* Additionally, its even useful sometimes :-).
*
*/
@ -32,122 +32,11 @@
#include <xcb/xcb.h>
#include <xcb/xcb_aux.h>
#include "libi3.h"
#include <i3/ipc.h>
static char *socket_path;
/*
* Try to get the socket path from X11 and return NULL if it doesnt work.
* As i3-msg is a short-running tool, we dont bother with cleaning up the
* connection and leave it up to the operating system on exit.
*
*/
static char *socket_path_from_x11() {
xcb_connection_t *conn;
int screen;
if ((conn = xcb_connect(NULL, &screen)) == NULL ||
xcb_connection_has_error(conn))
return NULL;
xcb_screen_t *root_screen = xcb_aux_get_screen(conn, screen);
xcb_window_t root = root_screen->root;
xcb_intern_atom_cookie_t atom_cookie;
xcb_intern_atom_reply_t *atom_reply;
atom_cookie = xcb_intern_atom(conn, 0, strlen("I3_SOCKET_PATH"), "I3_SOCKET_PATH");
atom_reply = xcb_intern_atom_reply(conn, atom_cookie, NULL);
if (atom_reply == NULL)
return NULL;
xcb_get_property_cookie_t prop_cookie;
xcb_get_property_reply_t *prop_reply;
prop_cookie = xcb_get_property_unchecked(conn, false, root, atom_reply->atom,
XCB_GET_PROPERTY_TYPE_ANY, 0, PATH_MAX);
prop_reply = xcb_get_property_reply(conn, prop_cookie, NULL);
if (prop_reply == NULL || xcb_get_property_value_length(prop_reply) == 0)
return NULL;
if (asprintf(&socket_path, "%.*s", xcb_get_property_value_length(prop_reply),
(char*)xcb_get_property_value(prop_reply)) == -1)
return NULL;
return socket_path;
}
/*
* Formats a message (payload) of the given size and type and sends it to i3 via
* the given socket file descriptor.
*
*/
static void ipc_send_message(int sockfd, uint32_t message_size,
uint32_t message_type, uint8_t *payload) {
int buffer_size = strlen(I3_IPC_MAGIC) + sizeof(uint32_t) + sizeof(uint32_t) + message_size;
char msg[buffer_size];
char *walk = msg;
strcpy(walk, I3_IPC_MAGIC);
walk += strlen(I3_IPC_MAGIC);
memcpy(walk, &message_size, sizeof(uint32_t));
walk += sizeof(uint32_t);
memcpy(walk, &message_type, sizeof(uint32_t));
walk += sizeof(uint32_t);
memcpy(walk, payload, message_size);
int sent_bytes = 0;
int bytes_to_go = buffer_size;
while (sent_bytes < bytes_to_go) {
int n = write(sockfd, msg + sent_bytes, bytes_to_go);
if (n == -1)
err(EXIT_FAILURE, "write() failed");
sent_bytes += n;
bytes_to_go -= n;
}
}
static void ipc_recv_message(int sockfd, uint32_t message_type,
uint32_t *reply_length, uint8_t **reply) {
/* Read the message header first */
uint32_t to_read = strlen(I3_IPC_MAGIC) + sizeof(uint32_t) + sizeof(uint32_t);
char msg[to_read];
char *walk = msg;
uint32_t read_bytes = 0;
while (read_bytes < to_read) {
int n = read(sockfd, msg + read_bytes, to_read);
if (n == -1)
err(EXIT_FAILURE, "read() failed");
if (n == 0)
errx(EXIT_FAILURE, "received EOF instead of reply");
read_bytes += n;
to_read -= n;
}
if (memcmp(walk, I3_IPC_MAGIC, strlen(I3_IPC_MAGIC)) != 0)
errx(EXIT_FAILURE, "invalid magic in reply");
walk += strlen(I3_IPC_MAGIC);
*reply_length = *((uint32_t*)walk);
walk += sizeof(uint32_t);
if (*((uint32_t*)walk) != message_type)
errx(EXIT_FAILURE, "unexpected reply type (got %d, expected %d)", *((uint32_t*)walk), message_type);
walk += sizeof(uint32_t);
*reply = malloc(*reply_length);
if ((*reply) == NULL)
err(EXIT_FAILURE, "malloc() failed");
to_read = *reply_length;
read_bytes = 0;
while (read_bytes < to_read) {
int n = read(sockfd, *reply + read_bytes, to_read);
if (n == -1)
err(EXIT_FAILURE, "read() failed");
read_bytes += n;
to_read -= n;
}
}
int main(int argc, char *argv[]) {
socket_path = getenv("I3SOCK");
int o, option_index = 0;
@ -170,7 +59,7 @@ int main(int argc, char *argv[]) {
if (o == 's') {
if (socket_path != NULL)
free(socket_path);
socket_path = strdup(optarg);
socket_path = sstrdup(optarg);
} else if (o == 't') {
if (strcasecmp(optarg, "command") == 0)
message_type = I3_IPC_MESSAGE_TYPE_COMMAND;
@ -180,9 +69,13 @@ int main(int argc, char *argv[]) {
message_type = I3_IPC_MESSAGE_TYPE_GET_OUTPUTS;
else if (strcasecmp(optarg, "get_tree") == 0)
message_type = I3_IPC_MESSAGE_TYPE_GET_TREE;
else if (strcasecmp(optarg, "get_marks") == 0)
message_type = I3_IPC_MESSAGE_TYPE_GET_MARKS;
else if (strcasecmp(optarg, "get_bar_config") == 0)
message_type = I3_IPC_MESSAGE_TYPE_GET_BAR_CONFIG;
else {
printf("Unknown message type\n");
printf("Known types: command, get_workspaces, get_outputs, get_tree\n");
printf("Known types: command, get_workspaces, get_outputs, get_tree, get_marks, get_bar_config\n");
exit(EXIT_FAILURE);
}
} else if (o == 'q') {
@ -202,15 +95,14 @@ int main(int argc, char *argv[]) {
/* Fall back to the default socket path */
if (socket_path == NULL)
socket_path = strdup("/tmp/i3-ipc.sock");
socket_path = sstrdup("/tmp/i3-ipc.sock");
/* Use all arguments, separated by whitespace, as payload.
* This way, you dont have to do i3-msg 'mark foo', you can use
* i3-msg mark foo */
while (optind < argc) {
if (!payload) {
if (!(payload = strdup(argv[optind])))
err(EXIT_FAILURE, "strdup(argv[optind])");
payload = sstrdup(argv[optind]);
} else {
char *both;
if (asprintf(&both, "%s %s", payload, argv[optind]) == -1)
@ -235,15 +127,21 @@ int main(int argc, char *argv[]) {
if (connect(sockfd, (const struct sockaddr*)&addr, sizeof(struct sockaddr_un)) < 0)
err(EXIT_FAILURE, "Could not connect to i3");
ipc_send_message(sockfd, strlen(payload), message_type, (uint8_t*)payload);
if (ipc_send_message(sockfd, strlen(payload), message_type, (uint8_t*)payload) == -1)
err(EXIT_FAILURE, "IPC: write()");
if (quiet)
return 0;
uint32_t reply_length;
uint8_t *reply;
ipc_recv_message(sockfd, message_type, &reply_length, &reply);
printf("%.*s", reply_length, reply);
int ret;
if ((ret = ipc_recv_message(sockfd, message_type, &reply_length, &reply)) != 0) {
if (ret == -1)
err(EXIT_FAILURE, "IPC: read()");
exit(1);
}
printf("%.*s\n", reply_length, reply);
free(reply);
close(sockfd);

View File

@ -3,23 +3,28 @@ TOPDIR=..
include $(TOPDIR)/common.mk
CPPFLAGS += -I$(TOPDIR)/include
# Depend on the object files of all source-files in src/*.c and on all header files
FILES=$(patsubst %.c,%.o,$(wildcard *.c))
HEADERS=$(wildcard *.h)
# Depend on the specific file (.c for each .o) and on all headers
%.o: %.c ${HEADERS}
echo "CC $<"
echo "[i3-nagbar] CC $<"
$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
all: i3-nagbar
i3-nagbar: ${FILES}
echo "LINK i3-nagbar"
$(CC) $(LDFLAGS) -o $@ ${FILES} $(LIBS)
i3-nagbar: $(TOPDIR)/libi3/libi3.a ${FILES}
echo "[i3-nagbar] LINK i3-nagbar"
$(CC) $(LDFLAGS) -o $@ $(filter-out libi3/libi3.a,$^) $(LIBS)
$(TOPDIR)/libi3/%.a: $(TOPDIR)/libi3/*.c
$(MAKE) -C $(TOPDIR)/libi3
install: all
echo "INSTALL"
echo "[i3-nagbar] INSTALL"
$(INSTALL) -d -m 0755 $(DESTDIR)$(PREFIX)/bin
$(INSTALL) -m 0755 i3-nagbar $(DESTDIR)$(PREFIX)/bin/

View File

@ -18,9 +18,4 @@ while (0)
extern xcb_window_t root;
uint32_t get_colorpixel(xcb_connection_t *conn, char *hex);
xcb_window_t open_input_window(xcb_connection_t *conn, uint32_t width, uint32_t height);
int get_font_id(xcb_connection_t *conn, char *pattern, int *font_height);
void xcb_change_gc_single(xcb_connection_t *conn, xcb_gcontext_t gc, uint32_t mask, uint32_t value);
#endif

View File

@ -2,12 +2,10 @@
* vim:ts=4:sw=4:expandtab
*
* i3 - an improved dynamic tiling window manager
* © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
*
* © 2009-2011 Michael Stapelberg and contributors
*
* See file LICENSE for license information.
*
* i3-nagbar is a utility which displays a nag message.
* i3-nagbar is a utility which displays a nag message, for example in the case
* when the user has an error in his configuration file.
*
*/
#include <ev.h>
@ -28,6 +26,7 @@
#include <xcb/xcb_aux.h>
#include <xcb/xcb_event.h>
#include "libi3.h"
#include "i3-nagbar.h"
typedef struct {
@ -41,11 +40,20 @@ static xcb_window_t win;
static xcb_pixmap_t pixmap;
static xcb_gcontext_t pixmap_gc;
static xcb_rectangle_t rect = { 0, 0, 600, 20 };
static int font_height;
static char *prompt = "Please do not run this program.";
static i3Font font;
static char *prompt;
static button_t *buttons;
static int buttoncnt;
/* Result of get_colorpixel() for the various colors. */
static uint32_t color_background; /* background of the bar */
static uint32_t color_button_background; /* background for buttons */
static uint32_t color_border; /* color of the button border */
static uint32_t color_border_bottom; /* color of the bottom border */
static uint32_t color_text; /* color of the text */
xcb_window_t root;
xcb_connection_t *conn;
/*
* Starts the given application by passing it through a shell. We use double fork
@ -118,32 +126,30 @@ static void handle_button_release(xcb_connection_t *conn, xcb_button_release_eve
*
*/
static int handle_expose(xcb_connection_t *conn, xcb_expose_event_t *event) {
printf("expose!\n");
/* re-draw the background */
xcb_change_gc_single(conn, pixmap_gc, XCB_GC_FOREGROUND, get_colorpixel(conn, "#900000"));
xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND, (uint32_t[]){ color_background });
xcb_poly_fill_rectangle(conn, pixmap, pixmap_gc, 1, &rect);
/* restore font color */
uint32_t values[3];
values[0] = get_colorpixel(conn, "#FFFFFF");
values[1] = get_colorpixel(conn, "#900000");
values[0] = color_text;
values[1] = color_background;
xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND | XCB_GC_BACKGROUND, values);
xcb_image_text_8(conn, strlen(prompt), pixmap, pixmap_gc, 4 + 4/* X */,
font_height + 2 + 4 /* Y = baseline of font */, prompt);
font.height + 2 + 4 /* Y = baseline of font */, prompt);
/* render close button */
int line_width = 4;
int w = 20;
int y = rect.width;
values[0] = get_colorpixel(conn, "#680a0a");
values[0] = color_button_background;
values[1] = line_width;
xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND | XCB_GC_LINE_WIDTH, values);
xcb_rectangle_t close = { y - w - (2 * line_width), 0, w + (2 * line_width), rect.height };
xcb_poly_fill_rectangle(conn, pixmap, pixmap_gc, 1, &close);
xcb_change_gc_single(conn, pixmap_gc, XCB_GC_FOREGROUND, get_colorpixel(conn, "#d92424"));
xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND, (uint32_t[]){ color_border });
xcb_point_t points[] = {
{ y - w - (2 * line_width), line_width / 2 },
{ y - (line_width / 2), line_width / 2 },
@ -153,12 +159,12 @@ static int handle_expose(xcb_connection_t *conn, xcb_expose_event_t *event) {
};
xcb_poly_line(conn, XCB_COORD_MODE_ORIGIN, pixmap, pixmap_gc, 5, points);
values[0] = get_colorpixel(conn, "#ffffff");
values[1] = get_colorpixel(conn, "#680a0a");
values[0] = color_text;
values[1] = color_button_background;
values[2] = 1;
xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND | XCB_GC_BACKGROUND | XCB_GC_LINE_WIDTH, values);
xcb_image_text_8(conn, strlen("x"), pixmap, pixmap_gc, y - w - line_width + (w / 2) - 4/* X */,
font_height + 2 + 4 - 1/* Y = baseline of font */, "X");
font.height + 2 + 4 - 1/* Y = baseline of font */, "X");
y -= w;
y -= 20;
@ -167,13 +173,13 @@ static int handle_expose(xcb_connection_t *conn, xcb_expose_event_t *event) {
line_width = 1;
for (int c = 0; c < buttoncnt; c++) {
/* TODO: make w = text extents of the label */
w = 90;
w = 100;
y -= 30;
xcb_change_gc_single(conn, pixmap_gc, XCB_GC_FOREGROUND, get_colorpixel(conn, "#680a0a"));
xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND, (uint32_t[]){ color_button_background });
close = (xcb_rectangle_t){ y - w - (2 * line_width), 2, w + (2 * line_width), rect.height - 6 };
xcb_poly_fill_rectangle(conn, pixmap, pixmap_gc, 1, &close);
xcb_change_gc_single(conn, pixmap_gc, XCB_GC_FOREGROUND, get_colorpixel(conn, "#d92424"));
xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND, (uint32_t[]){ color_border });
buttons[c].x = y - w - (2 * line_width);
buttons[c].width = w;
xcb_point_t points2[] = {
@ -185,18 +191,18 @@ static int handle_expose(xcb_connection_t *conn, xcb_expose_event_t *event) {
};
xcb_poly_line(conn, XCB_COORD_MODE_ORIGIN, pixmap, pixmap_gc, 5, points2);
values[0] = get_colorpixel(conn, "#ffffff");
values[1] = get_colorpixel(conn, "#680a0a");
values[0] = color_text;
values[1] = color_button_background;
xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND | XCB_GC_BACKGROUND, values);
xcb_image_text_8(conn, strlen(buttons[c].label), pixmap, pixmap_gc, y - w - line_width + 6/* X */,
font_height + 2 + 3/* Y = baseline of font */, buttons[c].label);
font.height + 2 + 3/* Y = baseline of font */, buttons[c].label);
y -= w;
}
/* border line at the bottom */
line_width = 2;
values[0] = get_colorpixel(conn, "#470909");
values[0] = color_border_bottom;
values[1] = line_width;
xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND | XCB_GC_LINE_WIDTH, values);
xcb_point_t bottom[] = {
@ -214,8 +220,9 @@ static int handle_expose(xcb_connection_t *conn, xcb_expose_event_t *event) {
}
int main(int argc, char *argv[]) {
char *pattern = "-misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1";
char *pattern = strdup("-misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1");
int o, option_index = 0;
enum { TYPE_ERROR = 0, TYPE_WARNING = 1 } bar_type = TYPE_ERROR;
static struct option long_options[] = {
{"version", no_argument, 0, 'v'},
@ -223,10 +230,13 @@ int main(int argc, char *argv[]) {
{"button", required_argument, 0, 'b'},
{"help", no_argument, 0, 'h'},
{"message", no_argument, 0, 'm'},
{"type", required_argument, 0, 't'},
{0, 0, 0, 0}
};
char *options_string = "b:f:m:vh";
char *options_string = "b:f:m:t:vh";
prompt = strdup("Please do not run this program.");
while ((o = getopt_long(argc, argv, options_string, long_options, &option_index)) != -1) {
switch (o) {
@ -238,8 +248,12 @@ int main(int argc, char *argv[]) {
pattern = strdup(optarg);
break;
case 'm':
FREE(prompt);
prompt = strdup(optarg);
break;
case 't':
bar_type = (strcasecmp(optarg, "warning") == 0 ? TYPE_WARNING : TYPE_ERROR);
break;
case 'h':
printf("i3-nagbar " I3_VERSION "\n");
printf("i3-nagbar [-m <message>] [-b <button> <action>] [-f <font>] [-v]\n");
@ -260,7 +274,6 @@ int main(int argc, char *argv[]) {
}
int screens;
xcb_connection_t *conn;
if ((conn = xcb_connect(NULL, &screens)) == NULL ||
xcb_connection_has_error(conn))
die("Cannot open display\n");
@ -274,10 +287,47 @@ int main(int argc, char *argv[]) {
xcb_screen_t *root_screen = xcb_aux_get_screen(conn, screens);
root = root_screen->root;
uint32_t font_id = get_font_id(conn, pattern, &font_height);
if (bar_type == TYPE_ERROR) {
/* Red theme for error messages */
color_button_background = get_colorpixel("#680a0a");
color_background = get_colorpixel("#900000");
color_text = get_colorpixel("#ffffff");
color_border = get_colorpixel("#d92424");
color_border_bottom = get_colorpixel("#470909");
} else {
/* Yellowish theme for warnings */
color_button_background = get_colorpixel("#ffc100");
color_background = get_colorpixel("#ffa8000");
color_text = get_colorpixel("#000000");
color_border = get_colorpixel("#ab7100");
color_border_bottom = get_colorpixel("#ab7100");
}
font = load_font(pattern, true);
/* Open an input window */
win = open_input_window(conn, 500, font_height + 8 + 8 /* 8px padding */);
win = xcb_generate_id(conn);
xcb_create_window(
conn,
XCB_COPY_FROM_PARENT,
win, /* the window id */
root, /* parent == root */
50, 50, 500, font.height + 8 + 8 /* 8 px padding */, /* dimensions */
0, /* x11 border = 0, we draw our own */
XCB_WINDOW_CLASS_INPUT_OUTPUT,
XCB_WINDOW_CLASS_COPY_FROM_PARENT, /* copy visual from parent */
XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK,
(uint32_t[]){
0, /* back pixel: black */
XCB_EVENT_MASK_EXPOSURE |
XCB_EVENT_MASK_STRUCTURE_NOTIFY |
XCB_EVENT_MASK_BUTTON_PRESS |
XCB_EVENT_MASK_BUTTON_RELEASE
});
/* Map the window (make it visible) */
xcb_map_window(conn, win);
/* Setup NetWM atoms */
#define xmacro(name) \
@ -318,7 +368,7 @@ int main(int argc, char *argv[]) {
uint32_t bottom_end_x;
} __attribute__((__packed__)) strut_partial = {0,};
strut_partial.top = font_height + 6;
strut_partial.top = font.height + 6;
strut_partial.top_start_x = 0;
strut_partial.top_end_x = 800;
@ -334,11 +384,11 @@ int main(int argc, char *argv[]) {
/* Create pixmap */
pixmap = xcb_generate_id(conn);
pixmap_gc = xcb_generate_id(conn);
xcb_create_pixmap(conn, root_screen->root_depth, pixmap, win, 500, font_height + 8);
xcb_create_pixmap(conn, root_screen->root_depth, pixmap, win, 500, font.height + 8);
xcb_create_gc(conn, pixmap_gc, pixmap, 0, 0);
/* Create graphics context */
xcb_change_gc_single(conn, pixmap_gc, XCB_GC_FONT, font_id);
xcb_change_gc(conn, pixmap_gc, XCB_GC_FONT, (uint32_t[]){ font.id });
/* Grab the keyboard to get all input */
xcb_flush(conn);
@ -383,7 +433,7 @@ int main(int argc, char *argv[]) {
xcb_create_gc(conn, pixmap_gc, pixmap, 0, 0);
/* Create graphics context */
xcb_change_gc_single(conn, pixmap_gc, XCB_GC_FONT, font_id);
xcb_change_gc(conn, pixmap_gc, XCB_GC_FONT, (uint32_t[]){ font.id });
break;
}
}

View File

@ -1,132 +0,0 @@
/*
* vim:ts=8:expandtab
*
* i3 - an improved dynamic tiling window manager
*
* © 2009 Michael Stapelberg and contributors
*
* See file LICENSE for license information.
*
*/
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <xcb/xcb.h>
#include <xcb/xcb_keysyms.h>
#include <X11/keysym.h>
#include "i3-nagbar.h"
/*
* Convenience-wrapper around xcb_change_gc which saves us declaring a variable
*
*/
void xcb_change_gc_single(xcb_connection_t *conn, xcb_gcontext_t gc, uint32_t mask, uint32_t value) {
xcb_change_gc(conn, gc, mask, &value);
}
/*
* Returns the colorpixel to use for the given hex color (think of HTML).
*
* The hex_color has to start with #, for example #FF00FF.
*
* NOTE that get_colorpixel() does _NOT_ check the given color code for validity.
* This has to be done by the caller.
*
*/
uint32_t get_colorpixel(xcb_connection_t *conn, char *hex) {
char strgroups[3][3] = {{hex[1], hex[2], '\0'},
{hex[3], hex[4], '\0'},
{hex[5], hex[6], '\0'}};
uint32_t rgb16[3] = {(strtol(strgroups[0], NULL, 16)),
(strtol(strgroups[1], NULL, 16)),
(strtol(strgroups[2], NULL, 16))};
return (rgb16[0] << 16) + (rgb16[1] << 8) + rgb16[2];
}
/*
* Opens the window we use for input/output and maps it
*
*/
xcb_window_t open_input_window(xcb_connection_t *conn, uint32_t width, uint32_t height) {
xcb_window_t win = xcb_generate_id(conn);
//xcb_cursor_t cursor_id = xcb_generate_id(conn);
#if 0
/* Use the default cursor (left pointer) */
if (cursor > -1) {
i3Font *cursor_font = load_font(conn, "cursor");
xcb_create_glyph_cursor(conn, cursor_id, cursor_font->id, cursor_font->id,
XCB_CURSOR_LEFT_PTR, XCB_CURSOR_LEFT_PTR + 1,
0, 0, 0, 65535, 65535, 65535);
}
#endif
uint32_t mask = 0;
uint32_t values[3];
mask |= XCB_CW_BACK_PIXEL;
values[0] = 0;
mask |= XCB_CW_EVENT_MASK;
values[1] = XCB_EVENT_MASK_EXPOSURE |
XCB_EVENT_MASK_STRUCTURE_NOTIFY |
XCB_EVENT_MASK_BUTTON_PRESS |
XCB_EVENT_MASK_BUTTON_RELEASE;
xcb_create_window(conn,
XCB_COPY_FROM_PARENT,
win, /* the window id */
root, /* parent == root */
50, 50, width, height, /* dimensions */
0, /* border = 0, we draw our own */
XCB_WINDOW_CLASS_INPUT_OUTPUT,
XCB_WINDOW_CLASS_COPY_FROM_PARENT, /* copy visual from parent */
mask,
values);
#if 0
if (cursor > -1)
xcb_change_window_attributes(conn, result, XCB_CW_CURSOR, &cursor_id);
#endif
/* Map the window (= make it visible) */
xcb_map_window(conn, win);
return win;
}
/*
* Returns the ID of the font matching the given pattern and stores the height
* of the font (in pixels) in *font_height. die()s if no font matches.
*
*/
int get_font_id(xcb_connection_t *conn, char *pattern, int *font_height) {
xcb_void_cookie_t font_cookie;
xcb_list_fonts_with_info_cookie_t info_cookie;
/* Send all our requests first */
int result;
result = xcb_generate_id(conn);
font_cookie = xcb_open_font_checked(conn, result, strlen(pattern), pattern);
info_cookie = xcb_list_fonts_with_info(conn, 1, strlen(pattern), pattern);
xcb_generic_error_t *error = xcb_request_check(conn, font_cookie);
if (error != NULL) {
fprintf(stderr, "ERROR: Could not open font: %d\n", error->error_code);
exit(1);
}
/* Get information (height/name) for this font */
xcb_list_fonts_with_info_reply_t *reply = xcb_list_fonts_with_info_reply(conn, info_cookie, NULL);
if (reply == NULL)
die("Could not load font \"%s\"\n", pattern);
*font_height = reply->font_ascent + reply->font_descent;
return result;
}

14
i3-sensible-editor Executable file
View File

@ -0,0 +1,14 @@
#!/bin/sh
# This script tries to exec an editor by trying some known editors if $EDITOR is
# not set.
#
# Distributions/packagers can enhance this script with a
# distribution-specific mechanism to find the preferred pager.
which $VISUAL >/dev/null && exec $VISUAL "$@"
which $EDITOR >/dev/null && exec $EDITOR "$@"
# Hopefully one of these is installed (no flamewars about preference please!):
which nano >/dev/null && exec nano "$@"
which vim >/dev/null && exec vim "$@"
which vi >/dev/null && exec vi "$@"
which emacs >/dev/null && exec emacs "$@"

15
i3-sensible-pager Executable file
View File

@ -0,0 +1,15 @@
#!/bin/sh
# This script tries to exec a pager by trying some known pagers if $PAGER is
# not set.
#
# Distributions/packagers can enhance this script with a
# distribution-specific mechanism to find the preferred pager.
which $PAGER >/dev/null && exec $PAGER "$@"
# Hopefully one of these is installed:
which most >/dev/null && exec most "$@"
which less >/dev/null && exec less "$@"
# we don't use 'more' because it will exit if the file is 'too short'
# If no pager is installed, try an editor
exec i3-sensible-editor "$@"

15
i3-sensible-terminal Executable file
View File

@ -0,0 +1,15 @@
#!/bin/sh
# This script tries to exec a terminal emulator by trying some known terminal
# emulators.
#
# Distributions/packagers should enhance this script with a
# distribution-specific mechanism to find the preferred terminal emulator. On
# Debian, there is the x-terminal-emulator symlink for example.
# Please don't touch the first line, though:
which $TERMINAL >/dev/null && exec $TERMINAL "$@"
# Hopefully one of these is installed:
which xterm >/dev/null && exec xterm "$@"
which urxvt >/dev/null && exec urxvt "$@"
which rxvt >/dev/null && exec rxvt "$@"
which roxterm >/dev/null && exec roxterm "$@"

View File

@ -16,7 +16,7 @@ font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
floating_modifier Mod1
# start a terminal
bindsym Mod1+Return exec urxvt
bindsym Mod1+Return exec i3-sensible-terminal
# kill focused window
bindsym Mod1+Shift+q kill
@ -147,7 +147,9 @@ bindsym Mod1+r mode "resize"
# Start i3bar to display a workspace bar (plus the system information i3status
# finds out, if available)
exec i3status | i3bar -d
bar {
status_command i3status
}
#######################################################################
# automatically start i3-config-wizard to offer the user to create a

View File

@ -17,7 +17,7 @@ font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
floating_modifier $mod
# start a terminal
bindcode $mod+36 exec urxvt
bindcode $mod+36 exec i3-sensible-terminal
# kill focused window
bindcode $mod+Shift+24 kill
@ -148,4 +148,6 @@ bindcode $mod+27 mode "resize"
# Start i3bar to display a workspace bar (plus the system information i3status
# finds out, if available)
exec i3status | i3bar -d
bar {
status_command i3status
}

View File

@ -10,30 +10,33 @@ CPPFLAGS += -I$(TOPDIR)/include
all: i3bar doc
i3bar: ${FILES}
echo "LINK"
$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
i3bar: $(TOPDIR)/libi3/libi3.a ${FILES}
echo "[i3bar] LINK"
$(CC) $(LDFLAGS) -o $@ $(filter-out libi3/libi3.a,$^) $(LIBS)
$(TOPDIR)/libi3/%.a: $(TOPDIR)/libi3/*.c
$(MAKE) -C $(TOPDIR)/libi3
doc:
echo ""
echo "SUBDIR doc"
echo "[i3bar] SUBDIR doc"
$(MAKE) -C doc
src/%.o: src/%.c ${HEADERS}
echo "CC $<"
echo "[i3bar] CC $<"
$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
install: all
echo "INSTALL"
echo "[i3bar] INSTALL"
$(INSTALL) -d -m 0755 $(DESTDIR)$(PREFIX)/bin
$(INSTALL) -m 0755 i3bar $(DESTDIR)$(PREFIX)/bin
clean:
rm -f src/*.o
make -C doc clean
$(MAKE) -C doc clean
distclean: clean
rm -f i3bar
make -C doc distclean
$(MAKE) -C doc distclean
.PHONY: install clean distclean doc

View File

@ -1,7 +1,7 @@
i3bar(1)
========
Axel Wagner <mail+i3bar@merovius.de>
v0.7, July 2011
v4.1, October 2011
== NAME
@ -9,81 +9,59 @@ i3bar - xcb-based status- and workspace-bar
== SYNOPSIS
*i3bar* [*-s* 'sock_path'] [*-c* 'command'] [*-m*|*-d*['pos']] [*-f* 'font'] [*-V*] [*-h*]
*i3bar* [*-s* 'sock_path'] [*-b* 'bar_id'] [*-v*] [*-h*]
== WARNING
i3bar will automatically be invoked by i3 for every 'bar' configuration block.
Starting it manually is usually not what you want to do.
You have been warned!
== OPTIONS
*-s, --socket* 'sock_path'::
Specifies the 'socketpath', via which *i3bar* connects to *i3*(1). If *i3bar* can not connect to *i3*, it will exit. Defaults to '/tmp/i3-ipc.sock'
Overwrites the path to the i3 IPC socket.
*-c, --command* 'command'::
Execute '<command>' to get 'stdin'. You can also simply pipe into 'stdin', but starting the coomand for itself, *i3bar* is able to send 'SIGCONT' and 'SIGSTOP', when combined with *-m*
*-b, --bar_id* 'bar_id'::
Specifies the bar ID for which to get the configuration from i3.
*-m, --hide*::
Hide the bar, when 'mod4' is not pressed. With this, dockmode will not be set, and the bar is out of the way most of the time so you have more room.
If *-c* is specified, the childprocess is sent a 'SIGSTOP' on hiding and a 'SIGCONT' on unhiding of the bars.
This is the default behavior of i3bar.
*-d*['pos']*, --dock*[*=*'pos']::
Put i3bar in dockmode. This will reserve some space for it, so it does not overlap other clients.
You can specify either *bottom* (default) or *top* as 'pos'.
*-f, --font* 'font'::
Specifies a 'X-core-font' to use. You can choose one with *xfontsel*(1). Defaults to '+++-misc-fixed-medium-r-semicondensed--12-110-75-75-c-60-iso10646-1+++'.
*-V, --verbose*::
Be (very) verbose with the debug-output. If not set, only errors are reported to 'stderr'
*-v, --version*::
Display version number and exit.
*-h, --help*::
Display a short help-message and exit
== DESCRIPTION
*i3bar* is an xcb- and libev-based status- and ws-bar. It is best thought of as an replacement for the *i3-wsbar*(1) + *dzen2*(1)-combination. It creates a workspace-bar for every active output ("screen") and displays a piped in statusline rightaligned on every bar.
*i3bar* displays a bar at the bottom (or top) of your monitor(s) containing
workspace switching buttons and a statusline generated by i3status(1) or
similar. It is automatically invoked (and configured through) i3.
It does not sample any status-information itself, so you still need a program like *i3status*(1) or *conky*(1) for that.
i3bar does not support any color or other markups, so stdin should be plain utf8, one line at a time. If you use *i3status*(1), you therefore should specify 'output_format = none' in the general section of its config file.
Also, you should disable the internal workspace bar of *i3*(1), when using *i3bar* by specifying 'workspace_bar no' in your *i3*-configfile.
== COLORS
*i3bar* does not yet support formatting in the displayed statusline. However it does support setting colors for the bar, the workspace-buttons and the statusline.
For now this happens with the following command-line-options:
*--color-bar-fg, --color-bar-bg, --color-active-ws-fg, --color-active-ws-bg, --color-inactive-ws-fg, --color-inactive-ws-bg, --color-urgent-ws-bg, --color-urgent-ws-fg, --color-focus-ws-fg, --color-focus-ws-bg*
For each specified option you need to give a HEX-colorcode.
Be advised that this command-line-options are only temporary and are very likely to be removed, when we finally have a config-file.
i3bar does not support any color or other markups, so stdin should be plain
utf8, one line at a time. If you use *i3status*(1), you therefore should
specify 'output_format = none' in the general section of its config file.
== ENVIRONMENT
=== I3SOCK
If no ipc-socket is specified on the commandline, this variable is used
to determine the path, at wich the unix domain socket is expected, on which
to connect to i3.
Used as a fallback for the i3 IPC socket path if neither the commandline
contains an argument nor the I3_SOCKET_PATH property is set on the X11 root
window.
== EXAMPLES
To get a docked bar with some statusinformation, you use
Nothing to see here, move along. As stated above, you should not run i3bar manually.
*i3status | i3bar --dock*
If you rather have it displayed at the top of the screen, you use
*i3status | i3bar --dock=top*
If you want it to hide when not needed, you should instead simply use
*i3bar -c i3status*
Instead, see the i3 documentation, especially the Users Guide.
== SEE ALSO
+i3(1)+, +i3-wsbar(1)+, +dzen2(1)+, +i3status(1)+
+i3status(1)+ or +conky(1)+ for programs generating a statusline.
+dzen2(1)+ or +xmobar(1)+ for similar programs to i3bar.
== AUTHORS

View File

@ -1,9 +1,10 @@
/*
* vim:ts=4:sw=4:expandtab
*
* i3bar - an xcb-based status- and ws-bar for i3
* © 2010-2011 Axel Wagner and contributors (see also: LICENSE)
*
* © 2010-2011 Axel Wagner and contributors
*
* See file LICNSE for license information
* child.c: Getting Input for the statusline
*
*/
#ifndef CHILD_H_

View File

@ -1,16 +1,16 @@
/*
* vim:ts=4:sw=4:expandtab
*
* i3bar - an xcb-based status- and ws-bar for i3
*
* © 2010-2011 Axel Wagner and contributors
*
* See file LICNSE for license information
* © 2010-2011 Axel Wagner and contributors (see also: LICENSE)
*
*/
#ifndef COMMON_H_
#define COMMON_H_
#include <stdbool.h>
typedef struct rect_t rect;
typedef int bool;
struct ev_loop* main_loop;
char *statusline;
@ -29,8 +29,10 @@ struct rect_t {
#include "outputs.h"
#include "util.h"
#include "workspaces.h"
#include "trayclients.h"
#include "xcb.h"
#include "ucs2_to_utf8.h"
#include "config.h"
#include "libi3.h"
#endif

View File

@ -1,22 +1,49 @@
/*
* vim:ts=4:sw=4:expandtab
*
* i3bar - an xcb-based status- and ws-bar for i3
* © 2010-2011 Axel Wagner and contributors (see also: LICENSE)
*
* config.c: Parses the configuration (received from i3).
*
*/
#ifndef CONFIG_H_
#define CONFIG_H_
#include "common.h"
typedef enum {
DOCKPOS_NONE = 0,
DOCKPOS_TOP,
DOCKPOS_BOT
} dockpos_t;
POS_NONE = 0,
POS_TOP,
POS_BOT
} position_t;
typedef struct config_t {
int hide_on_modifier;
dockpos_t dockpos;
position_t position;
int verbose;
xcb_colors_t *colors;
struct xcb_color_strings_t colors;
int disable_ws;
char *bar_id;
char *command;
char *fontname;
char *tray_output;
int num_outputs;
char **outputs;
} config_t;
config_t config;
/**
* Start parsing the received bar configuration json-string
*
*/
void parse_config_json(char *json);
/**
* free()s the color strings as soon as they are not needed anymore.
*
*/
void free_colors(struct xcb_color_strings_t *colors);
#endif

View File

@ -1,9 +1,10 @@
/*
* vim:ts=4:sw=4:expandtab
*
* i3bar - an xcb-based status- and ws-bar for i3
* © 2010-2011 Axel Wagner and contributors (see also: LICENSE)
*
* © 2010-2011 Axel Wagner and contributors
*
* See file LICNSE for license information
* ipc.c: Communicating with i3
*
*/
#ifndef IPC_H_

View File

@ -1,9 +1,10 @@
/*
* vim:ts=4:sw=4:expandtab
*
* i3bar - an xcb-based status- and ws-bar for i3
* © 2010-2011 Axel Wagner and contributors (see also: LICENSE)
*
* © 2010-2011 Axel Wagner and contributors
*
* See file LICNSE for license information
* outputs.c: Maintaining the output-list
*
*/
#ifndef OUTPUTS_H_
@ -47,6 +48,7 @@ struct i3_output {
xcb_gcontext_t bargc; /* The graphical context of the bar */
struct ws_head *workspaces; /* The workspaces on this output */
struct tc_head *trayclients; /* The tray clients on this output */
SLIST_ENTRY(i3_output) slist; /* Pointer for the SLIST-Macro */
};

View File

@ -1,527 +0,0 @@
/* $OpenBSD: queue.h,v 1.1 2007/10/26 03:14:08 niallo Exp $ */
/* $NetBSD: queue.h,v 1.11 1996/05/16 05:17:14 mycroft Exp $ */
/*
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)queue.h 8.5 (Berkeley) 8/20/94
*/
#ifndef _SYS_QUEUE_H_
#define _SYS_QUEUE_H_
/*
* This file defines five types of data structures: singly-linked lists,
* lists, simple queues, tail queues, and circular queues.
*
*
* A singly-linked list is headed by a single forward pointer. The elements
* are singly linked for minimum space and pointer manipulation overhead at
* the expense of O(n) removal for arbitrary elements. New elements can be
* added to the list after an existing element or at the head of the list.
* Elements being removed from the head of the list should use the explicit
* macro for this purpose for optimum efficiency. A singly-linked list may
* only be traversed in the forward direction. Singly-linked lists are ideal
* for applications with large datasets and few or no removals or for
* implementing a LIFO queue.
*
* A list is headed by a single forward pointer (or an array of forward
* pointers for a hash table header). The elements are doubly linked
* so that an arbitrary element can be removed without a need to
* traverse the list. New elements can be added to the list before
* or after an existing element or at the head of the list. A list
* may only be traversed in the forward direction.
*
* A simple queue is headed by a pair of pointers, one the head of the
* list and the other to the tail of the list. The elements are singly
* linked to save space, so elements can only be removed from the
* head of the list. New elements can be added to the list before or after
* an existing element, at the head of the list, or at the end of the
* list. A simple queue may only be traversed in the forward direction.
*
* A tail queue is headed by a pair of pointers, one to the head of the
* list and the other to the tail of the list. The elements are doubly
* linked so that an arbitrary element can be removed without a need to
* traverse the list. New elements can be added to the list before or
* after an existing element, at the head of the list, or at the end of
* the list. A tail queue may be traversed in either direction.
*
* A circle queue is headed by a pair of pointers, one to the head of the
* list and the other to the tail of the list. The elements are doubly
* linked so that an arbitrary element can be removed without a need to
* traverse the list. New elements can be added to the list before or after
* an existing element, at the head of the list, or at the end of the list.
* A circle queue may be traversed in either direction, but has a more
* complex end of list detection.
*
* For details on the use of these macros, see the queue(3) manual page.
*/
#if defined(QUEUE_MACRO_DEBUG) || (defined(_KERNEL) && defined(DIAGNOSTIC))
#define _Q_INVALIDATE(a) (a) = ((void *)-1)
#else
#define _Q_INVALIDATE(a)
#endif
/*
* Singly-linked List definitions.
*/
#define SLIST_HEAD(name, type) \
struct name { \
struct type *slh_first; /* first element */ \
}
#define SLIST_HEAD_INITIALIZER(head) \
{ NULL }
#define SLIST_ENTRY(type) \
struct { \
struct type *sle_next; /* next element */ \
}
/*
* Singly-linked List access methods.
*/
#define SLIST_FIRST(head) ((head)->slh_first)
#define SLIST_END(head) NULL
#define SLIST_EMPTY(head) (SLIST_FIRST(head) == SLIST_END(head))
#define SLIST_NEXT(elm, field) ((elm)->field.sle_next)
#define SLIST_FOREACH(var, head, field) \
for((var) = SLIST_FIRST(head); \
(var) != SLIST_END(head); \
(var) = SLIST_NEXT(var, field))
#define SLIST_FOREACH_PREVPTR(var, varp, head, field) \
for ((varp) = &SLIST_FIRST((head)); \
((var) = *(varp)) != SLIST_END(head); \
(varp) = &SLIST_NEXT((var), field))
/*
* Singly-linked List functions.
*/
#define SLIST_INIT(head) { \
SLIST_FIRST(head) = SLIST_END(head); \
}
#define SLIST_INSERT_AFTER(slistelm, elm, field) do { \
(elm)->field.sle_next = (slistelm)->field.sle_next; \
(slistelm)->field.sle_next = (elm); \
} while (0)
#define SLIST_INSERT_HEAD(head, elm, field) do { \
(elm)->field.sle_next = (head)->slh_first; \
(head)->slh_first = (elm); \
} while (0)
#define SLIST_REMOVE_NEXT(head, elm, field) do { \
(elm)->field.sle_next = (elm)->field.sle_next->field.sle_next; \
} while (0)
#define SLIST_REMOVE_HEAD(head, field) do { \
(head)->slh_first = (head)->slh_first->field.sle_next; \
} while (0)
#define SLIST_REMOVE(head, elm, type, field) do { \
if ((head)->slh_first == (elm)) { \
SLIST_REMOVE_HEAD((head), field); \
} else { \
struct type *curelm = (head)->slh_first; \
\
while (curelm->field.sle_next != (elm)) \
curelm = curelm->field.sle_next; \
curelm->field.sle_next = \
curelm->field.sle_next->field.sle_next; \
_Q_INVALIDATE((elm)->field.sle_next); \
} \
} while (0)
/*
* List definitions.
*/
#define LIST_HEAD(name, type) \
struct name { \
struct type *lh_first; /* first element */ \
}
#define LIST_HEAD_INITIALIZER(head) \
{ NULL }
#define LIST_ENTRY(type) \
struct { \
struct type *le_next; /* next element */ \
struct type **le_prev; /* address of previous next element */ \
}
/*
* List access methods
*/
#define LIST_FIRST(head) ((head)->lh_first)
#define LIST_END(head) NULL
#define LIST_EMPTY(head) (LIST_FIRST(head) == LIST_END(head))
#define LIST_NEXT(elm, field) ((elm)->field.le_next)
#define LIST_FOREACH(var, head, field) \
for((var) = LIST_FIRST(head); \
(var)!= LIST_END(head); \
(var) = LIST_NEXT(var, field))
/*
* List functions.
*/
#define LIST_INIT(head) do { \
LIST_FIRST(head) = LIST_END(head); \
} while (0)
#define LIST_INSERT_AFTER(listelm, elm, field) do { \
if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \
(listelm)->field.le_next->field.le_prev = \
&(elm)->field.le_next; \
(listelm)->field.le_next = (elm); \
(elm)->field.le_prev = &(listelm)->field.le_next; \
} while (0)
#define LIST_INSERT_BEFORE(listelm, elm, field) do { \
(elm)->field.le_prev = (listelm)->field.le_prev; \
(elm)->field.le_next = (listelm); \
*(listelm)->field.le_prev = (elm); \
(listelm)->field.le_prev = &(elm)->field.le_next; \
} while (0)
#define LIST_INSERT_HEAD(head, elm, field) do { \
if (((elm)->field.le_next = (head)->lh_first) != NULL) \
(head)->lh_first->field.le_prev = &(elm)->field.le_next;\
(head)->lh_first = (elm); \
(elm)->field.le_prev = &(head)->lh_first; \
} while (0)
#define LIST_REMOVE(elm, field) do { \
if ((elm)->field.le_next != NULL) \
(elm)->field.le_next->field.le_prev = \
(elm)->field.le_prev; \
*(elm)->field.le_prev = (elm)->field.le_next; \
_Q_INVALIDATE((elm)->field.le_prev); \
_Q_INVALIDATE((elm)->field.le_next); \
} while (0)
#define LIST_REPLACE(elm, elm2, field) do { \
if (((elm2)->field.le_next = (elm)->field.le_next) != NULL) \
(elm2)->field.le_next->field.le_prev = \
&(elm2)->field.le_next; \
(elm2)->field.le_prev = (elm)->field.le_prev; \
*(elm2)->field.le_prev = (elm2); \
_Q_INVALIDATE((elm)->field.le_prev); \
_Q_INVALIDATE((elm)->field.le_next); \
} while (0)
/*
* Simple queue definitions.
*/
#define SIMPLEQ_HEAD(name, type) \
struct name { \
struct type *sqh_first; /* first element */ \
struct type **sqh_last; /* addr of last next element */ \
}
#define SIMPLEQ_HEAD_INITIALIZER(head) \
{ NULL, &(head).sqh_first }
#define SIMPLEQ_ENTRY(type) \
struct { \
struct type *sqe_next; /* next element */ \
}
/*
* Simple queue access methods.
*/
#define SIMPLEQ_FIRST(head) ((head)->sqh_first)
#define SIMPLEQ_END(head) NULL
#define SIMPLEQ_EMPTY(head) (SIMPLEQ_FIRST(head) == SIMPLEQ_END(head))
#define SIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next)
#define SIMPLEQ_FOREACH(var, head, field) \
for((var) = SIMPLEQ_FIRST(head); \
(var) != SIMPLEQ_END(head); \
(var) = SIMPLEQ_NEXT(var, field))
/*
* Simple queue functions.
*/
#define SIMPLEQ_INIT(head) do { \
(head)->sqh_first = NULL; \
(head)->sqh_last = &(head)->sqh_first; \
} while (0)
#define SIMPLEQ_INSERT_HEAD(head, elm, field) do { \
if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \
(head)->sqh_last = &(elm)->field.sqe_next; \
(head)->sqh_first = (elm); \
} while (0)
#define SIMPLEQ_INSERT_TAIL(head, elm, field) do { \
(elm)->field.sqe_next = NULL; \
*(head)->sqh_last = (elm); \
(head)->sqh_last = &(elm)->field.sqe_next; \
} while (0)
#define SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\
(head)->sqh_last = &(elm)->field.sqe_next; \
(listelm)->field.sqe_next = (elm); \
} while (0)
#define SIMPLEQ_REMOVE_HEAD(head, field) do { \
if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL) \
(head)->sqh_last = &(head)->sqh_first; \
} while (0)
/*
* Tail queue definitions.
*/
#define TAILQ_HEAD(name, type) \
struct name { \
struct type *tqh_first; /* first element */ \
struct type **tqh_last; /* addr of last next element */ \
}
#define TAILQ_HEAD_INITIALIZER(head) \
{ NULL, &(head).tqh_first }
#define TAILQ_ENTRY(type) \
struct { \
struct type *tqe_next; /* next element */ \
struct type **tqe_prev; /* address of previous next element */ \
}
/*
* tail queue access methods
*/
#define TAILQ_FIRST(head) ((head)->tqh_first)
#define TAILQ_END(head) NULL
#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
#define TAILQ_LAST(head, headname) \
(*(((struct headname *)((head)->tqh_last))->tqh_last))
/* XXX */
#define TAILQ_PREV(elm, headname, field) \
(*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
#define TAILQ_EMPTY(head) \
(TAILQ_FIRST(head) == TAILQ_END(head))
#define TAILQ_FOREACH(var, head, field) \
for((var) = TAILQ_FIRST(head); \
(var) != TAILQ_END(head); \
(var) = TAILQ_NEXT(var, field))
#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \
for((var) = TAILQ_LAST(head, headname); \
(var) != TAILQ_END(head); \
(var) = TAILQ_PREV(var, headname, field))
/*
* Tail queue functions.
*/
#define TAILQ_INIT(head) do { \
(head)->tqh_first = NULL; \
(head)->tqh_last = &(head)->tqh_first; \
} while (0)
#define TAILQ_INSERT_HEAD(head, elm, field) do { \
if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \
(head)->tqh_first->field.tqe_prev = \
&(elm)->field.tqe_next; \
else \
(head)->tqh_last = &(elm)->field.tqe_next; \
(head)->tqh_first = (elm); \
(elm)->field.tqe_prev = &(head)->tqh_first; \
} while (0)
#define TAILQ_INSERT_TAIL(head, elm, field) do { \
(elm)->field.tqe_next = NULL; \
(elm)->field.tqe_prev = (head)->tqh_last; \
*(head)->tqh_last = (elm); \
(head)->tqh_last = &(elm)->field.tqe_next; \
} while (0)
#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
(elm)->field.tqe_next->field.tqe_prev = \
&(elm)->field.tqe_next; \
else \
(head)->tqh_last = &(elm)->field.tqe_next; \
(listelm)->field.tqe_next = (elm); \
(elm)->field.tqe_prev = &(listelm)->field.tqe_next; \
} while (0)
#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
(elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
(elm)->field.tqe_next = (listelm); \
*(listelm)->field.tqe_prev = (elm); \
(listelm)->field.tqe_prev = &(elm)->field.tqe_next; \
} while (0)
#define TAILQ_REMOVE(head, elm, field) do { \
if (((elm)->field.tqe_next) != NULL) \
(elm)->field.tqe_next->field.tqe_prev = \
(elm)->field.tqe_prev; \
else \
(head)->tqh_last = (elm)->field.tqe_prev; \
*(elm)->field.tqe_prev = (elm)->field.tqe_next; \
_Q_INVALIDATE((elm)->field.tqe_prev); \
_Q_INVALIDATE((elm)->field.tqe_next); \
} while (0)
#define TAILQ_REPLACE(head, elm, elm2, field) do { \
if (((elm2)->field.tqe_next = (elm)->field.tqe_next) != NULL) \
(elm2)->field.tqe_next->field.tqe_prev = \
&(elm2)->field.tqe_next; \
else \
(head)->tqh_last = &(elm2)->field.tqe_next; \
(elm2)->field.tqe_prev = (elm)->field.tqe_prev; \
*(elm2)->field.tqe_prev = (elm2); \
_Q_INVALIDATE((elm)->field.tqe_prev); \
_Q_INVALIDATE((elm)->field.tqe_next); \
} while (0)
/*
* Circular queue definitions.
*/
#define CIRCLEQ_HEAD(name, type) \
struct name { \
struct type *cqh_first; /* first element */ \
struct type *cqh_last; /* last element */ \
}
#define CIRCLEQ_HEAD_INITIALIZER(head) \
{ CIRCLEQ_END(&head), CIRCLEQ_END(&head) }
#define CIRCLEQ_ENTRY(type) \
struct { \
struct type *cqe_next; /* next element */ \
struct type *cqe_prev; /* previous element */ \
}
/*
* Circular queue access methods
*/
#define CIRCLEQ_FIRST(head) ((head)->cqh_first)
#define CIRCLEQ_LAST(head) ((head)->cqh_last)
#define CIRCLEQ_END(head) ((void *)(head))
#define CIRCLEQ_NEXT(elm, field) ((elm)->field.cqe_next)
#define CIRCLEQ_PREV(elm, field) ((elm)->field.cqe_prev)
#define CIRCLEQ_EMPTY(head) \
(CIRCLEQ_FIRST(head) == CIRCLEQ_END(head))
#define CIRCLEQ_FOREACH(var, head, field) \
for((var) = CIRCLEQ_FIRST(head); \
(var) != CIRCLEQ_END(head); \
(var) = CIRCLEQ_NEXT(var, field))
#define CIRCLEQ_FOREACH_REVERSE(var, head, field) \
for((var) = CIRCLEQ_LAST(head); \
(var) != CIRCLEQ_END(head); \
(var) = CIRCLEQ_PREV(var, field))
/*
* Circular queue functions.
*/
#define CIRCLEQ_INIT(head) do { \
(head)->cqh_first = CIRCLEQ_END(head); \
(head)->cqh_last = CIRCLEQ_END(head); \
} while (0)
#define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
(elm)->field.cqe_next = (listelm)->field.cqe_next; \
(elm)->field.cqe_prev = (listelm); \
if ((listelm)->field.cqe_next == CIRCLEQ_END(head)) \
(head)->cqh_last = (elm); \
else \
(listelm)->field.cqe_next->field.cqe_prev = (elm); \
(listelm)->field.cqe_next = (elm); \
} while (0)
#define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \
(elm)->field.cqe_next = (listelm); \
(elm)->field.cqe_prev = (listelm)->field.cqe_prev; \
if ((listelm)->field.cqe_prev == CIRCLEQ_END(head)) \
(head)->cqh_first = (elm); \
else \
(listelm)->field.cqe_prev->field.cqe_next = (elm); \
(listelm)->field.cqe_prev = (elm); \
} while (0)
#define CIRCLEQ_INSERT_HEAD(head, elm, field) do { \
(elm)->field.cqe_next = (head)->cqh_first; \
(elm)->field.cqe_prev = CIRCLEQ_END(head); \
if ((head)->cqh_last == CIRCLEQ_END(head)) \
(head)->cqh_last = (elm); \
else \
(head)->cqh_first->field.cqe_prev = (elm); \
(head)->cqh_first = (elm); \
} while (0)
#define CIRCLEQ_INSERT_TAIL(head, elm, field) do { \
(elm)->field.cqe_next = CIRCLEQ_END(head); \
(elm)->field.cqe_prev = (head)->cqh_last; \
if ((head)->cqh_first == CIRCLEQ_END(head)) \
(head)->cqh_first = (elm); \
else \
(head)->cqh_last->field.cqe_next = (elm); \
(head)->cqh_last = (elm); \
} while (0)
#define CIRCLEQ_REMOVE(head, elm, field) do { \
if ((elm)->field.cqe_next == CIRCLEQ_END(head)) \
(head)->cqh_last = (elm)->field.cqe_prev; \
else \
(elm)->field.cqe_next->field.cqe_prev = \
(elm)->field.cqe_prev; \
if ((elm)->field.cqe_prev == CIRCLEQ_END(head)) \
(head)->cqh_first = (elm)->field.cqe_next; \
else \
(elm)->field.cqe_prev->field.cqe_next = \
(elm)->field.cqe_next; \
_Q_INVALIDATE((elm)->field.cqe_prev); \
_Q_INVALIDATE((elm)->field.cqe_next); \
} while (0)
#define CIRCLEQ_REPLACE(head, elm, elm2, field) do { \
if (((elm2)->field.cqe_next = (elm)->field.cqe_next) == \
CIRCLEQ_END(head)) \
(head)->cqh_last = (elm2); \
else \
(elm2)->field.cqe_next->field.cqe_prev = (elm2); \
if (((elm2)->field.cqe_prev = (elm)->field.cqe_prev) == \
CIRCLEQ_END(head)) \
(head)->cqh_first = (elm2); \
else \
(elm2)->field.cqe_prev->field.cqe_next = (elm2); \
_Q_INVALIDATE((elm)->field.cqe_prev); \
_Q_INVALIDATE((elm)->field.cqe_next); \
} while (0)
#endif /* !_SYS_QUEUE_H_ */

View File

@ -0,0 +1,25 @@
/*
* vim:ts=4:sw=4:expandtab
*
* i3bar - an xcb-based status- and ws-bar for i3
* © 2010-2011 Axel Wagner and contributors (see also: LICENSE)
*
*/
#ifndef TRAYCLIENT_H_
#define TRAYCLIENT_H_
#include "common.h"
typedef struct trayclient trayclient;
TAILQ_HEAD(tc_head, trayclient);
struct trayclient {
xcb_window_t win; /* The window ID of the tray client */
bool mapped; /* Whether this window is mapped */
int xe_version; /* The XEMBED version supported by the client */
TAILQ_ENTRY(trayclient) tailq; /* Pointer for the TAILQ-Macro */
};
#endif

View File

@ -1 +1,15 @@
/*
* vim:ts=4:sw=4:expandtab
*
* i3 - an improved dynamic tiling window manager
* © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
*
* ucs2_to_utf8.c: Converts between UCS-2 and UTF-8, both of which are used in
* different contexts in X11.
*/
#ifndef _UCS2_TO_UTF8
#define _UCS2_TO_UTF8
char *convert_utf8_to_ucs2(char *input, int *real_strlen);
#endif

View File

@ -1,9 +1,8 @@
/*
* i3bar - an xcb-based status- and ws-bar for i3
* vim:ts=4:sw=4:expandtab
*
* © 2010-2011 Axel Wagner and contributors
*
* See file LICNSE for license information
* i3 - an improved dynamic tiling window manager
* © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
*
*/
#ifndef UTIL_H_

View File

@ -1,9 +1,10 @@
/*
* vim:ts=4:sw=4:expandtab
*
* i3bar - an xcb-based status- and ws-bar for i3
* © 2010-2011 Axel Wagner and contributors (see also: LICENSE)
*
* © 2010-2011 Axel Wagner and contributors
*
* See file LICNSE for license information
* workspaces.c: Maintaining the workspace-lists
*
*/
#ifndef WORKSPACES_H_

View File

@ -1,9 +1,10 @@
/*
* vim:ts=4:sw=4:expandtab
*
* i3bar - an xcb-based status- and ws-bar for i3
* © 2010-2011 Axel Wagner and contributors (see also: LICENSE)
*
* © 2010-2011 Axel Wagner and contributors
*
* See file LICNSE for license information
* xcb.c: Communicating with X
*
*/
#ifndef XCB_H_
@ -12,6 +13,18 @@
#include <stdint.h>
//#include "outputs.h"
#ifdef XCB_COMPAT
#define XCB_ATOM_CARDINAL CARDINAL
#endif
#define _NET_SYSTEM_TRAY_ORIENTATION_HORZ 0
#define _NET_SYSTEM_TRAY_ORIENTATION_VERT 1
#define SYSTEM_TRAY_REQUEST_DOCK 0
#define SYSTEM_TRAY_BEGIN_MESSAGE 1
#define SYSTEM_TRAY_CANCEL_MESSAGE 2
#define XEMBED_MAPPED (1 << 0)
#define XEMBED_EMBEDDED_NOTIFY 0
struct xcb_color_strings_t {
char *bar_fg;
char *bar_bg;
@ -28,10 +41,18 @@ struct xcb_color_strings_t {
typedef struct xcb_colors_t xcb_colors_t;
/*
* Initialize xcb and use the specified fontname for text-rendering
* Early initialization of the connection to X11: Everything which does not
* depend on 'config'.
*
*/
char *init_xcb(char *fontname);
char *init_xcb_early();
/**
* Initialization which depends on 'config' being usable. Called after the
* configuration has arrived.
*
*/
void init_xcb_late(char *fontname);
/*
* Initialize the colors

View File

@ -2,4 +2,10 @@ ATOM_DO(_NET_WM_WINDOW_TYPE)
ATOM_DO(_NET_WM_WINDOW_TYPE_DOCK)
ATOM_DO(_NET_WM_STRUT_PARTIAL)
ATOM_DO(I3_SOCKET_PATH)
ATOM_DO(MANAGER)
ATOM_DO(_NET_SYSTEM_TRAY_ORIENTATION)
ATOM_DO(_NET_SYSTEM_TRAY_VISUAL)
ATOM_DO(_NET_SYSTEM_TRAY_OPCODE)
ATOM_DO(_XEMBED_INFO)
ATOM_DO(_XEMBED)
#undef ATOM_DO

View File

@ -1,11 +1,10 @@
/*
* vim:ts=4:sw=4:expandtab
*
* i3bar - an xcb-based status- and ws-bar for i3
* © 2010-2011 Axel Wagner and contributors (see also: LICENSE)
*
* © 2010-2011 Axel Wagner and contributors
*
* See file LICNSE for license information
*
* src/child.c: Getting Input for the statusline
* child.c: Getting Input for the statusline
*
*/
#include <stdlib.h>
@ -17,6 +16,7 @@
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <err.h>
#include <ev.h>
#include "common.h"
@ -60,7 +60,7 @@ void stdin_io_cb(struct ev_loop *loop, ev_io *watcher, int revents) {
int n = 0;
int rec = 0;
int buffer_len = STDIN_CHUNK_SIZE;
char *buffer = malloc(buffer_len);
char *buffer = smalloc(buffer_len);
buffer[0] = '\0';
while(1) {
n = read(fd, buffer + rec, buffer_len - rec);
@ -89,7 +89,7 @@ void stdin_io_cb(struct ev_loop *loop, ev_io *watcher, int revents) {
if (rec == buffer_len) {
buffer_len += STDIN_CHUNK_SIZE;
buffer = realloc(buffer, buffer_len);
buffer = srealloc(buffer, buffer_len);
}
}
if (*buffer == '\0') {
@ -129,7 +129,9 @@ void start_child(char *command) {
child_pid = 0;
if (command != NULL) {
int fd[2];
pipe(fd);
if (pipe(fd) == -1)
err(EXIT_FAILURE, "pipe(fd)");
child_pid = fork();
switch (child_pid) {
case -1:
@ -167,12 +169,12 @@ void start_child(char *command) {
/* We set O_NONBLOCK because blocking is evil in event-driven software */
fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK);
stdin_io = malloc(sizeof(ev_io));
stdin_io = smalloc(sizeof(ev_io));
ev_io_init(stdin_io, &stdin_io_cb, STDIN_FILENO, EV_READ);
ev_io_start(main_loop, stdin_io);
/* We must cleanup, if the child unexpectedly terminates */
child_sig = malloc(sizeof(ev_child));
child_sig = smalloc(sizeof(ev_child));
ev_child_init(child_sig, &child_sig_cb, child_pid, 0);
ev_child_start(main_loop, child_sig);

232
i3bar/src/config.c Normal file
View File

@ -0,0 +1,232 @@
/*
* vim:ts=4:sw=4:expandtab
*
* i3bar - an xcb-based status- and ws-bar for i3
* © 2010-2011 Axel Wagner and contributors (see also: LICENSE)
*
* config.c: Parses the configuration (received from i3).
*
*/
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <i3/ipc.h>
#include <yajl/yajl_parse.h>
#include <yajl/yajl_version.h>
#include "common.h"
static char *cur_key;
/*
* Parse a key.
*
* Essentially we just save it in cur_key.
*
*/
#if YAJL_MAJOR >= 2
static int config_map_key_cb(void *params_, const unsigned char *keyVal, size_t keyLen) {
#else
static int config_map_key_cb(void *params_, const unsigned char *keyVal, unsigned keyLen) {
#endif
FREE(cur_key);
cur_key = smalloc(sizeof(unsigned char) * (keyLen + 1));
strncpy(cur_key, (const char*) keyVal, keyLen);
cur_key[keyLen] = '\0';
return 1;
}
/*
* Parse a null-value (current_workspace)
*
*/
static int config_null_cb(void *params_) {
if (!strcmp(cur_key, "id")) {
/* If 'id' is NULL, the bar config was not found. Error out. */
ELOG("No such bar config. Use 'i3-msg -t get_bar_config' to get the available configs.\n");
ELOG("Are you starting i3bar by hand? You should not:\n");
ELOG("Configure a 'bar' block in your i3 config and i3 will launch i3bar automatically.\n");
exit(EXIT_FAILURE);
}
return 1;
}
/*
* Parse a string
*
*/
#if YAJL_MAJOR >= 2
static int config_string_cb(void *params_, const unsigned char *val, size_t _len) {
#else
static int config_string_cb(void *params_, const unsigned char *val, unsigned int _len) {
#endif
int len = (int)_len;
/* The id is ignored, we already have it in config.bar_id */
if (!strcmp(cur_key, "id"))
return 1;
if (!strcmp(cur_key, "mode")) {
DLOG("mode = %.*s, len = %d\n", len, val, len);
config.hide_on_modifier = (len == 4 && !strncmp((const char*)val, "hide", strlen("hide")));
return 1;
}
if (!strcmp(cur_key, "position")) {
DLOG("position = %.*s\n", len, val);
config.position = (len == 3 && !strncmp((const char*)val, "top", strlen("top")) ? POS_TOP : POS_BOT);
return 1;
}
if (!strcmp(cur_key, "status_command")) {
/* We cannot directly start the child here, because start_child() also
* needs to be run when no command was specified (to setup stdin).
* Therefore we save the command in 'config' and access it later in
* got_bar_config() */
DLOG("command = %.*s\n", len, val);
sasprintf(&config.command, "%.*s", len, val);
return 1;
}
if (!strcmp(cur_key, "font")) {
DLOG("font = %.*s\n", len, val);
sasprintf(&config.fontname, "%.*s", len, val);
return 1;
}
if (!strcmp(cur_key, "outputs")) {
DLOG("+output %.*s\n", len, val);
int new_num_outputs = config.num_outputs + 1;
config.outputs = srealloc(config.outputs, sizeof(char*) * new_num_outputs);
sasprintf(&config.outputs[config.num_outputs], "%.*s", len, val);
config.num_outputs = new_num_outputs;
return 1;
}
if (!strcmp(cur_key, "tray_output")) {
DLOG("tray_output %.*s\n", len, val);
FREE(config.tray_output);
sasprintf(&config.tray_output, "%.*s", len, val);
return 1;
}
#define COLOR(json_name, struct_name) \
do { \
if (!strcmp(cur_key, #json_name)) { \
DLOG(#json_name " = " #struct_name " = %.*s\n", len, val); \
sasprintf(&(config.colors.struct_name), "%.*s", len, val); \
return 1; \
} \
} while (0)
COLOR(statusline, bar_fg);
COLOR(background, bar_bg);
COLOR(focused_workspace_text, focus_ws_fg);
COLOR(focused_workspace_bg, focus_ws_bg);
COLOR(active_workspace_text, active_ws_fg);
COLOR(active_workspace_bg, active_ws_bg);
COLOR(inactive_workspace_text, inactive_ws_fg);
COLOR(inactive_workspace_bg, inactive_ws_bg);
COLOR(urgent_workspace_text, urgent_ws_fg);
COLOR(urgent_workspace_bg, urgent_ws_bg);
printf("got unexpected string %.*s for cur_key = %s\n", len, val, cur_key);
return 0;
}
/*
* Parse a boolean value
*
*/
static int config_boolean_cb(void *params_, int val) {
if (!strcmp(cur_key, "workspace_buttons")) {
DLOG("workspace_buttons = %d\n", val);
config.disable_ws = !val;
return 1;
}
if (!strcmp(cur_key, "verbose")) {
DLOG("verbose = %d\n", val);
config.verbose = val;
return 1;
}
return 0;
}
/* A datastructure to pass all these callbacks to yajl */
static yajl_callbacks outputs_callbacks = {
&config_null_cb,
&config_boolean_cb,
NULL,
NULL,
NULL,
&config_string_cb,
NULL,
&config_map_key_cb,
NULL,
NULL,
NULL
};
/*
* Start parsing the received bar configuration json-string
*
*/
void parse_config_json(char *json) {
yajl_handle handle;
yajl_status state;
#if YAJL_MAJOR < 2
yajl_parser_config parse_conf = { 0, 0 };
handle = yajl_alloc(&outputs_callbacks, &parse_conf, NULL, NULL);
#else
handle = yajl_alloc(&outputs_callbacks, NULL, NULL);
#endif
state = yajl_parse(handle, (const unsigned char*) json, strlen(json));
/* FIXME: Proper errorhandling for JSON-parsing */
switch (state) {
case yajl_status_ok:
break;
case yajl_status_client_canceled:
#if YAJL_MAJOR < 2
case yajl_status_insufficient_data:
#endif
case yajl_status_error:
ELOG("Could not parse config-reply!\n");
exit(EXIT_FAILURE);
break;
}
yajl_free(handle);
}
/*
* free()s the color strings as soon as they are not needed anymore.
*
*/
void free_colors(struct xcb_color_strings_t *colors) {
#define FREE_COLOR(x) \
do { \
if (colors->x) \
free(colors->x); \
} while (0)
FREE_COLOR(bar_fg);
FREE_COLOR(bar_bg);
FREE_COLOR(active_ws_fg);
FREE_COLOR(active_ws_bg);
FREE_COLOR(inactive_ws_fg);
FREE_COLOR(inactive_ws_bg);
FREE_COLOR(urgent_ws_fg);
FREE_COLOR(urgent_ws_bg);
FREE_COLOR(focus_ws_fg);
FREE_COLOR(focus_ws_bg);
#undef FREE_COLOR
}

View File

@ -1,11 +1,10 @@
/*
* vim:ts=4:sw=4:expandtab
*
* i3bar - an xcb-based status- and ws-bar for i3
* © 2010-2011 Axel Wagner and contributors (see also: LICENSE)
*
* © 2010-2011 Axel Wagner and contributors
*
* See file LICNSE for license information
*
* src/ipc.c: Communicating with i3
* ipc.c: Communicating with i3
*
*/
#include <stdlib.h>
@ -22,55 +21,11 @@
#include "common.h"
ev_io *i3_connection;
ev_timer *reconn = NULL;
const char *sock_path;
typedef void(*handler_t)(char*);
/*
* Retry to connect.
*
*/
void retry_connection(struct ev_loop *loop, ev_timer *w, int events) {
static int retries = 8;
if (init_connection(sock_path) == 0) {
if (retries == 0) {
ELOG("Retried 8 times - connection failed!\n");
exit(EXIT_FAILURE);
}
retries--;
return;
}
retries = 8;
ev_timer_stop(loop, w);
subscribe_events();
/* We get the current outputs and workspaces, to
* reconfigure all bars with the current configuration */
i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_OUTPUTS, NULL);
if (!config.disable_ws) {
i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_WORKSPACES, NULL);
}
}
/*
* Schedule a reconnect
*
*/
void reconnect() {
if (reconn == NULL) {
if ((reconn = malloc(sizeof(ev_timer))) == NULL) {
ELOG("malloc() failed: %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
} else {
ev_timer_stop(main_loop, reconn);
}
ev_timer_init(reconn, retry_connection, 0.25, 0.25);
ev_timer_start(main_loop, reconn);
}
/*
* Called, when we get a reply to a command from i3.
* Since i3 does not give us much feedback on commands, we do not much
@ -112,12 +67,47 @@ void got_output_reply(char *reply) {
reconfig_windows();
}
/*
* Called when we get the configuration for our bar instance
*
*/
void got_bar_config(char *reply) {
DLOG("Received bar config \"%s\"\n", reply);
/* We initiate the main-function by requesting infos about the outputs and
* workspaces. Everything else (creating the bars, showing the right workspace-
* buttons and more) is taken care of by the event-drivenness of the code */
i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_OUTPUTS, NULL);
parse_config_json(reply);
/* Now we can actually use 'config', so let's subscribe to the appropriate
* events and request the workspaces if necessary. */
subscribe_events();
if (!config.disable_ws)
i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_WORKSPACES, NULL);
/* Initialize the rest of XCB */
init_xcb_late(config.fontname);
/* Resolve color strings to colorpixels and save them, then free the strings. */
init_colors(&(config.colors));
free_colors(&(config.colors));
/* The name of this function is actually misleading. Even if no command is
* specified, this function initiates the watchers to listen on stdin and
* react accordingly */
start_child(config.command);
FREE(config.command);
}
/* Data-structure to easily call the reply-handlers later */
handler_t reply_handlers[] = {
&got_command_reply,
&got_workspace_reply,
&got_subscribe_reply,
&got_output_reply,
NULL,
NULL,
&got_bar_config,
};
/*
@ -157,11 +147,7 @@ void got_data(struct ev_loop *loop, ev_io *watcher, int events) {
/* First we only read the header, because we know its length */
uint32_t header_len = strlen(I3_IPC_MAGIC) + sizeof(uint32_t)*2;
char *header = malloc(header_len);
if (header == NULL) {
ELOG("Could not allocate memory: %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
char *header = smalloc(header_len);
/* We first parse the fixed-length IPC-header, to know, how much data
* we have to expect */
@ -173,12 +159,11 @@ void got_data(struct ev_loop *loop, ev_io *watcher, int events) {
exit(EXIT_FAILURE);
}
if (n == 0) {
/* EOF received. We try to recover a few times, because most likely
* i3 just restarted */
ELOG("EOF received, try to recover...\n");
destroy_connection();
reconnect();
return;
/* EOF received. Since i3 will restart i3bar instances as appropriate,
* we exit here. */
DLOG("EOF received, exiting...\n");
clean_xcb();
exit(EXIT_SUCCESS);
}
rec += n;
}
@ -200,15 +185,7 @@ void got_data(struct ev_loop *loop, ev_io *watcher, int events) {
/* Now that we know, what to expect, we can start read()ing the rest
* of the message */
char *buffer = malloc(size + 1);
if (buffer == NULL) {
/* EOF received. We try to recover a few times, because most likely
* i3 just restarted */
ELOG("EOF received, try to recover...\n");
destroy_connection();
reconnect();
return;
}
char *buffer = smalloc(size + 1);
rec = 0;
while (rec < size) {
@ -230,6 +207,7 @@ void got_data(struct ev_loop *loop, ev_io *watcher, int events) {
type ^= 1 << 31;
event_handlers[type](buffer);
} else {
if (reply_handlers[type])
reply_handlers[type](buffer);
}
@ -253,12 +231,7 @@ int i3_send_msg(uint32_t type, const char *payload) {
/* TODO: I'm not entirely sure if this buffer really has to contain more
* than the pure header (why not just write() the payload from *payload?),
* but we leave it for now */
char *buffer = malloc(to_write);
if (buffer == NULL) {
ELOG("Could not allocate memory: %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
char *buffer = smalloc(to_write);
char *walk = buffer;
strncpy(buffer, I3_IPC_MAGIC, strlen(I3_IPC_MAGIC));
@ -296,27 +269,8 @@ int i3_send_msg(uint32_t type, const char *payload) {
*/
int init_connection(const char *socket_path) {
sock_path = socket_path;
int sockfd = socket(AF_LOCAL, SOCK_STREAM, 0);
if (sockfd == -1) {
ELOG("Could not create Socket: %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
struct sockaddr_un addr;
memset(&addr, 0, sizeof(struct sockaddr_un));
addr.sun_family = AF_LOCAL;
strcpy(addr.sun_path, sock_path);
if (connect(sockfd, (const struct sockaddr*) &addr, sizeof(struct sockaddr_un)) < 0) {
ELOG("Could not connect to i3! %s: %s\n", sock_path, strerror(errno));
reconnect();
return 0;
}
i3_connection = malloc(sizeof(ev_io));
if (i3_connection == NULL) {
ELOG("malloc() failed: %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
int sockfd = ipc_connect(socket_path);
i3_connection = smalloc(sizeof(ev_io));
ev_io_init(i3_connection, &got_data, sockfd, EV_READ);
ev_io_start(main_loop, i3_connection);
return 1;

View File

@ -1,9 +1,8 @@
/*
* vim:ts=4:sw=4:expandtab
*
* i3bar - an xcb-based status- and ws-bar for i3
*
* © 2010-2011 Axel Wagner and contributors
*
* See file LICNSE for license information
* © 2010-2011 Axel Wagner and contributors (see also: LICENSE)
*
*/
#include <stdio.h>
@ -28,70 +27,23 @@ char *expand_path(char *path) {
ELOG("glob() failed\n");
exit(EXIT_FAILURE);
}
char *result = strdup(globbuf.gl_pathc > 0 ? globbuf.gl_pathv[0] : path);
if (result == NULL) {
ELOG("malloc() failed: %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
char *result = sstrdup(globbuf.gl_pathc > 0 ? globbuf.gl_pathv[0] : path);
globfree(&globbuf);
return result;
}
static void read_color(char **color) {
int len = strlen(optarg);
if (len == 6 || (len == 7 && optarg[0] == '#')) {
int offset = len - 6;
int good = 1, i;
for (i = offset; good && i < 6 + offset; ++i) {
char c = optarg[i];
if (!(c >= 'a' && c <= 'f')
&& !(c >= 'A' && c <= 'F')
&& !(c >= '0' && c <= '9')) {
good = 0;
break;
}
}
if (good) {
*color = strdup(optarg + offset);
return;
}
}
fprintf(stderr, "Bad color value \"%s\"\n", optarg);
exit(EXIT_FAILURE);
}
static void free_colors(struct xcb_color_strings_t *colors) {
#define FREE_COLOR(x) \
do { \
if (colors->x) \
free(colors->x); \
} while (0)
FREE_COLOR(bar_fg);
FREE_COLOR(bar_bg);
FREE_COLOR(active_ws_fg);
FREE_COLOR(active_ws_bg);
FREE_COLOR(inactive_ws_fg);
FREE_COLOR(inactive_ws_bg);
FREE_COLOR(urgent_ws_fg);
FREE_COLOR(urgent_ws_bg);
FREE_COLOR(focus_ws_fg);
FREE_COLOR(focus_ws_bg);
#undef FREE_COLOR
}
void print_usage(char *elf_name) {
printf("Usage: %s [-s sock_path] [-c command] [-m|-d[pos]] [-f font] [-V] [-h]\n", elf_name);
printf("Usage: %s [-b bar_id] [-s sock_path] [-h] [-v]\n", elf_name);
printf("\n");
printf("--bar_id <bar_id>\tBar ID for which to get the configuration\n");
printf("-s <sock_path>\tConnect to i3 via <sock_path>\n");
printf("-c <command>\tExecute <command> to get stdin\n");
printf("-m\t\tHide the bars, when mod4 is not pressed.\n");
printf("-d[<pos>]\tEnable dockmode. <pos> is \"top\" or \"bottom\". Default is bottom\n");
printf("\t\tIf -c is specified, the childprocess is sent a SIGSTOP on hiding,\n");
printf("\t\tand a SIGCONT on unhiding of the bars\n");
printf("-f <font>\tUse X-Core-Font <font> for display\n");
printf("-w\t\tDisable workspace-buttons\n");
printf("-V\t\tBe (very) verbose with the debug-output\n");
printf("-h\t\tDisplay this help-message and exit\n");
printf("-v\t\tDisplay version number and exit\n");
printf("\n");
printf(" PLEASE NOTE that i3bar will be automatically started by i3\n"
" as soon as there is a 'bar' configuration block in your\n"
" config file. You should never need to start it manually.\n");
printf("\n");
}
/*
@ -118,107 +70,33 @@ int main(int argc, char **argv) {
int opt;
int option_index = 0;
char *socket_path = getenv("I3SOCK");
char *command = NULL;
char *fontname = NULL;
char *i3_default_sock_path = "/tmp/i3-ipc.sock";
struct xcb_color_strings_t colors = { NULL, };
/* Definition of the standard-config */
config.hide_on_modifier = 0;
config.dockpos = DOCKPOS_NONE;
config.disable_ws = 0;
/* Initialize the standard config to use 0 as default */
memset(&config, '\0', sizeof(config_t));
static struct option long_opt[] = {
{ "socket", required_argument, 0, 's' },
{ "command", required_argument, 0, 'c' },
{ "hide", no_argument, 0, 'm' },
{ "dock", optional_argument, 0, 'd' },
{ "font", required_argument, 0, 'f' },
{ "nows", no_argument, 0, 'w' },
{ "bar_id", required_argument, 0, 0 },
{ "help", no_argument, 0, 'h' },
{ "version", no_argument, 0, 'v' },
{ "verbose", no_argument, 0, 'V' },
{ "color-bar-fg", required_argument, 0, 'A' },
{ "color-bar-bg", required_argument, 0, 'B' },
{ "color-active-ws-fg", required_argument, 0, 'C' },
{ "color-active-ws-bg", required_argument, 0, 'D' },
{ "color-inactive-ws-fg", required_argument, 0, 'E' },
{ "color-inactive-ws-bg", required_argument, 0, 'F' },
{ "color-urgent-ws-bg", required_argument, 0, 'G' },
{ "color-urgent-ws-fg", required_argument, 0, 'H' },
{ "color-focus-ws-bg", required_argument, 0, 'I' },
{ "color-focus-ws-fg", required_argument, 0, 'J' },
{ NULL, 0, 0, 0}
};
while ((opt = getopt_long(argc, argv, "s:c:d::mf:whvVA:B:C:D:E:F:G:H:I:J:", long_opt, &option_index)) != -1) {
while ((opt = getopt_long(argc, argv, "s:hv", long_opt, &option_index)) != -1) {
switch (opt) {
case 's':
socket_path = expand_path(optarg);
break;
case 'c':
command = strdup(optarg);
break;
case 'm':
config.hide_on_modifier = 1;
break;
case 'd':
config.hide_on_modifier = 0;
if (optarg == NULL) {
config.dockpos = DOCKPOS_BOT;
break;
}
if (!strcmp(optarg, "top")) {
config.dockpos = DOCKPOS_TOP;
} else if (!strcmp(optarg, "bottom")) {
config.dockpos = DOCKPOS_BOT;
} else {
print_usage(argv[0]);
exit(EXIT_FAILURE);
}
break;
case 'f':
fontname = strdup(optarg);
break;
case 'w':
config.disable_ws = 1;
break;
case 'v':
printf("i3bar version " I3_VERSION " © 2010-2011 Axel Wagner and contributors\n");
exit(EXIT_SUCCESS);
break;
case 'V':
config.verbose = 1;
break;
case 'A':
read_color(&colors.bar_fg);
break;
case 'B':
read_color(&colors.bar_bg);
break;
case 'C':
read_color(&colors.active_ws_fg);
break;
case 'D':
read_color(&colors.active_ws_bg);
break;
case 'E':
read_color(&colors.inactive_ws_fg);
break;
case 'F':
read_color(&colors.inactive_ws_bg);
break;
case 'G':
read_color(&colors.urgent_ws_bg);
break;
case 'H':
read_color(&colors.urgent_ws_fg);
break;
case 'I':
read_color(&colors.focus_ws_bg);
break;
case 'J':
read_color(&colors.focus_ws_fg);
case 0:
if (!strcmp(long_opt[option_index].name, "bar_id")) {
FREE(config.bar_id);
config.bar_id = sstrdup(optarg);
}
break;
default:
print_usage(argv[0]);
@ -227,26 +105,16 @@ int main(int argc, char **argv) {
}
}
if (fontname == NULL) {
/* This is a very restrictive default. More sensefull would be something like
* "-misc-*-*-*-*--*-*-*-*-*-*-*-*". But since that produces very ugly results
* on my machine, let's stick with this until we have a configfile */
fontname = "-misc-fixed-medium-r-semicondensed--12-110-75-75-c-60-iso10646-1";
}
if (config.dockpos != DOCKPOS_NONE) {
if (config.hide_on_modifier) {
ELOG("--dock and --hide are mutually exclusive!\n");
if (!config.bar_id) {
/* TODO: maybe we want -f which will automatically ask i3 for the first
* configured bar (and error out if there are too many)? */
ELOG("No bar_id passed. Please let i3 start i3bar or specify --bar_id\n");
exit(EXIT_FAILURE);
}
} else {
config.hide_on_modifier = 1;
}
main_loop = ev_default_loop(0);
init_colors(&colors);
char *atom_sock_path = init_xcb(fontname);
char *atom_sock_path = init_xcb_early();
if (socket_path == NULL) {
socket_path = atom_sock_path;
@ -257,38 +125,18 @@ int main(int argc, char **argv) {
socket_path = expand_path(i3_default_sock_path);
}
free_colors(&colors);
init_outputs();
if (init_connection(socket_path)) {
/* We subscribe to the i3-events we need */
subscribe_events();
/* We initiate the main-function by requesting infos about the outputs and
* workspaces. Everything else (creating the bars, showing the right workspace-
* buttons and more) is taken care of by the event-driveniness of the code */
i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_OUTPUTS, NULL);
if (!config.disable_ws) {
i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_WORKSPACES, NULL);
/* Request the bar configuration. When it arrives, we fill the config array. */
i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_BAR_CONFIG, config.bar_id);
}
}
/* The name of this function is actually misleading. Even if no -c is specified,
* this function initiates the watchers to listen on stdin and react accordingly */
start_child(command);
FREE(command);
/* We listen to SIGTERM/QUIT/INT and try to exit cleanly, by stopping the main-loop.
* We only need those watchers on the stack, so putting them on the stack saves us
* some calls to free() */
ev_signal *sig_term = malloc(sizeof(ev_signal));
ev_signal *sig_int = malloc(sizeof(ev_signal));
ev_signal *sig_hup = malloc(sizeof(ev_signal));
if (sig_term == NULL || sig_int == NULL || sig_hup == NULL) {
ELOG("malloc() failed: %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
ev_signal *sig_term = smalloc(sizeof(ev_signal));
ev_signal *sig_int = smalloc(sizeof(ev_signal));
ev_signal *sig_hup = smalloc(sizeof(ev_signal));
ev_signal_init(sig_term, &sig_cb, SIGTERM);
ev_signal_init(sig_int, &sig_cb, SIGINT);

View File

@ -1,11 +1,10 @@
/*
* vim:ts=4:sw=4:expandtab
*
* i3bar - an xcb-based status- and ws-bar for i3
* © 2010-2011 Axel Wagner and contributors (see also: LICENSE)
*
* © 2010-2011 Axel Wagner and contributors
*
* See file LICNSE for license information
*
* src/outputs.c: Maintaining the output-list
* outputs.c: Maintaining the output-list
*
*/
#include <string.h>
@ -24,7 +23,7 @@ struct outputs_json_params {
i3_output *outputs_walk;
char *cur_key;
char *json;
bool init;
bool in_rect;
};
/*
@ -43,7 +42,7 @@ static int outputs_null_cb(void *params_) {
* Parse a boolean value (active)
*
*/
static int outputs_boolean_cb(void *params_, bool val) {
static int outputs_boolean_cb(void *params_, int val) {
struct outputs_json_params *params = (struct outputs_json_params*) params_;
if (strcmp(params->cur_key, "active")) {
@ -113,7 +112,7 @@ static int outputs_string_cb(void *params_, const unsigned char *val, unsigned i
struct outputs_json_params *params = (struct outputs_json_params*) params_;
if (!strcmp(params->cur_key, "current_workspace")) {
char *copy = malloc(sizeof(const unsigned char) * (len + 1));
char *copy = smalloc(sizeof(const unsigned char) * (len + 1));
strncpy(copy, (const char*) val, len);
copy[len] = '\0';
@ -132,7 +131,7 @@ static int outputs_string_cb(void *params_, const unsigned char *val, unsigned i
return 0;
}
char *name = malloc(sizeof(const unsigned char) * (len + 1));
char *name = smalloc(sizeof(const unsigned char) * (len + 1));
strncpy(name, (const char*) val, len);
name[len] = '\0';
@ -152,20 +151,27 @@ static int outputs_start_map_cb(void *params_) {
i3_output *new_output = NULL;
if (params->cur_key == NULL) {
new_output = malloc(sizeof(i3_output));
new_output = smalloc(sizeof(i3_output));
new_output->name = NULL;
new_output->ws = 0,
memset(&new_output->rect, 0, sizeof(rect));
new_output->bar = XCB_NONE;
new_output->workspaces = malloc(sizeof(struct ws_head));
new_output->workspaces = smalloc(sizeof(struct ws_head));
TAILQ_INIT(new_output->workspaces);
new_output->trayclients = smalloc(sizeof(struct tc_head));
TAILQ_INIT(new_output->trayclients);
params->outputs_walk = new_output;
return 1;
}
if (!strcmp(params->cur_key, "rect")) {
params->in_rect = true;
}
return 1;
}
@ -175,7 +181,33 @@ static int outputs_start_map_cb(void *params_) {
*/
static int outputs_end_map_cb(void *params_) {
struct outputs_json_params *params = (struct outputs_json_params*) params_;
/* FIXME: What is at the end of a rect? */
if (params->in_rect) {
params->in_rect = false;
/* Ignore the end of a rect */
return 1;
}
/* See if we actually handle that output */
if (config.num_outputs > 0) {
bool handle_output = false;
for (int c = 0; c < config.num_outputs; c++) {
if (strcasecmp(params->outputs_walk->name, config.outputs[c]) != 0)
continue;
handle_output = true;
break;
}
if (!handle_output) {
DLOG("Ignoring output \"%s\", not configured to handle it.\n",
params->outputs_walk->name);
FREE(params->outputs_walk->name);
FREE(params->outputs_walk->workspaces);
FREE(params->outputs_walk->trayclients);
FREE(params->outputs_walk);
FREE(params->cur_key);
return 1;
}
}
i3_output *target = get_output_by_name(params->outputs_walk->name);
@ -203,7 +235,7 @@ static int outputs_map_key_cb(void *params_, const unsigned char *keyVal, unsign
struct outputs_json_params *params = (struct outputs_json_params*) params_;
FREE(params->cur_key);
params->cur_key = malloc(sizeof(unsigned char) * (keyLen + 1));
params->cur_key = smalloc(sizeof(unsigned char) * (keyLen + 1));
strncpy(params->cur_key, (const char*) keyVal, keyLen);
params->cur_key[keyLen] = '\0';
@ -230,7 +262,7 @@ yajl_callbacks outputs_callbacks = {
*
*/
void init_outputs() {
outputs = malloc(sizeof(struct outputs_head));
outputs = smalloc(sizeof(struct outputs_head));
SLIST_INIT(outputs);
}
@ -244,6 +276,7 @@ void parse_outputs_json(char *json) {
params.outputs_walk = NULL;
params.cur_key = NULL;
params.json = json;
params.in_rect = false;
yajl_handle handle;
yajl_status state;

View File

@ -1,12 +1,11 @@
/*
* vim:ts=8:expandtab
* vim:ts=4:sw=4:expandtab
*
* i3 - an improved dynamic tiling window manager
* © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
*
* © 2009 Michael Stapelberg and contributors
*
* See file LICENSE for license information.
*
* ucs2_to_utf8.c: Converts between UCS-2 and UTF-8, both of which are used in
* different contexts in X11.
*/
#include <stdlib.h>
#include <stdio.h>
@ -14,6 +13,8 @@
#include <err.h>
#include <iconv.h>
#include "libi3.h"
static iconv_t conversion_descriptor = 0;
static iconv_t conversion_descriptor2 = 0;
@ -27,9 +28,7 @@ char *convert_ucs_to_utf8(char *input) {
/* UTF-8 may consume up to 4 byte */
int buffer_size = 8;
char *buffer = calloc(buffer_size, 1);
if (buffer == NULL)
err(EXIT_FAILURE, "malloc() failed\n");
char *buffer = scalloc(buffer_size);
size_t output_size = buffer_size;
/* We need to use an additional pointer, because iconv() modifies it */
char *output = buffer;
@ -50,6 +49,7 @@ char *convert_ucs_to_utf8(char *input) {
int rc = iconv(conversion_descriptor, (void*)&input, &input_size, &output, &output_size);
if (rc == (size_t)-1) {
perror("Converting to UCS-2 failed");
free(buffer);
return NULL;
}
@ -68,9 +68,7 @@ char *convert_utf8_to_ucs2(char *input, int *real_strlen) {
/* UCS-2 consumes exactly two bytes for each glyph */
int buffer_size = input_size * 2;
char *buffer = malloc(buffer_size);
if (buffer == NULL)
err(EXIT_FAILURE, "malloc() failed\n");
char *buffer = smalloc(buffer_size);
size_t output_size = buffer_size;
/* We need to use an additional pointer, because iconv() modifies it */
char *output = buffer;
@ -91,6 +89,7 @@ char *convert_utf8_to_ucs2(char *input, int *real_strlen) {
int rc = iconv(conversion_descriptor2, (void*)&input, &input_size, &output, &output_size);
if (rc == (size_t)-1) {
perror("Converting to UCS-2 failed");
free(buffer);
if (real_strlen != NULL)
*real_strlen = 0;
return NULL;

View File

@ -1,11 +1,10 @@
/*
* vim:ts=4:sw=4:expandtab
*
* i3bar - an xcb-based status- and ws-bar for i3
* © 2010-2011 Axel Wagner and contributors (see also: LICENSE)
*
* © 2010-2011 Axel Wagner and contributors
*
* See file LICNSE for license information
*
* src/workspaces.c: Maintaining the workspace-lists
* workspaces.c: Maintaining the workspace-lists
*
*/
#include <string.h>
@ -29,7 +28,7 @@ struct workspaces_json_params {
* Parse a boolean value (visible, focused, urgent)
*
*/
static int workspaces_boolean_cb(void *params_, bool val) {
static int workspaces_boolean_cb(void *params_, int val) {
struct workspaces_json_params *params = (struct workspaces_json_params*) params_;
if (!strcmp(params->cur_key, "visible")) {
@ -115,7 +114,7 @@ static int workspaces_string_cb(void *params_, const unsigned char *val, unsigne
if (!strcmp(params->cur_key, "name")) {
/* Save the name */
params->workspaces_walk->name = malloc(sizeof(const unsigned char) * (len + 1));
params->workspaces_walk->name = smalloc(sizeof(const unsigned char) * (len + 1));
strncpy(params->workspaces_walk->name, (const char*) val, len);
params->workspaces_walk->name[len] = '\0';
@ -139,14 +138,17 @@ static int workspaces_string_cb(void *params_, const unsigned char *val, unsigne
if (!strcmp(params->cur_key, "output")) {
/* We add the ws to the TAILQ of the output, it belongs to */
output_name = malloc(sizeof(const unsigned char) * (len + 1));
output_name = smalloc(sizeof(const unsigned char) * (len + 1));
strncpy(output_name, (const char*) val, len);
output_name[len] = '\0';
params->workspaces_walk->output = get_output_by_name(output_name);
i3_output *target = get_output_by_name(output_name);
if (target) {
params->workspaces_walk->output = target;
TAILQ_INSERT_TAIL(params->workspaces_walk->output->workspaces,
params->workspaces_walk,
tailq);
}
FREE(output_name);
return 1;
@ -165,7 +167,7 @@ static int workspaces_start_map_cb(void *params_) {
i3_ws *new_workspace = NULL;
if (params->cur_key == NULL) {
new_workspace = malloc(sizeof(i3_ws));
new_workspace = smalloc(sizeof(i3_ws));
new_workspace->num = -1;
new_workspace->name = NULL;
new_workspace->visible = 0;
@ -195,11 +197,7 @@ static int workspaces_map_key_cb(void *params_, const unsigned char *keyVal, uns
struct workspaces_json_params *params = (struct workspaces_json_params*) params_;
FREE(params->cur_key);
params->cur_key = malloc(sizeof(unsigned char) * (keyLen + 1));
if (params->cur_key == NULL) {
ELOG("Could not allocate memory: %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
params->cur_key = smalloc(sizeof(unsigned char) * (keyLen + 1));
strncpy(params->cur_key, (const char*) keyVal, keyLen);
params->cur_key[keyLen] = '\0';

View File

@ -1,16 +1,20 @@
/*
* vim:ts=4:sw=4:expandtab
*
* i3bar - an xcb-based status- and ws-bar for i3
* © 2010-2011 Axel Wagner and contributors (see also: LICENSE)
*
* © 2010-2011 Axel Wagner and contributors
*
* See file LICNSE for license information
*
* src/xcb.c: Communicating with X
* xcb.c: Communicating with X
*
*/
#include <xcb/xcb.h>
#include <xcb/xproto.h>
#include <xcb/xcb_atom.h>
#ifdef XCB_COMPAT
#include "xcb_compat.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@ -20,36 +24,14 @@
#include <ev.h>
#include <errno.h>
#include <limits.h>
#include <err.h>
#include <X11/Xlib.h>
#include <X11/XKBlib.h>
#include <X11/extensions/XKB.h>
#include "common.h"
#if defined(__APPLE__)
/*
* Taken from FreeBSD
* Returns a pointer to a new string which is a duplicate of the
* string, but only copies at most n characters.
*
*/
char *strndup(const char *str, size_t n) {
size_t len;
char *copy;
for (len = 0; len < n && str[len]; len++)
continue;
if ((copy = malloc(len + 1)) == NULL)
return (NULL);
memcpy(copy, str, len);
copy[len] = '\0';
return (copy);
}
#endif
#include "libi3.h"
/* We save the Atoms in an easy to access array, indexed by an enum */
enum {
@ -63,6 +45,7 @@ xcb_atom_t atoms[NUM_ATOMS];
/* Variables, that are the same for all functions at all times */
xcb_connection_t *xcb_connection;
int screen;
xcb_screen_t *xcb_screen;
xcb_window_t xcb_root;
xcb_font_t xcb_font;
@ -185,21 +168,6 @@ void draw_text(xcb_drawable_t drawable, xcb_gcontext_t ctx, int16_t x, int16_t y
}
}
/*
* Converts a colorstring to a colorpixel as expected from xcb_change_gc.
* s is assumed to be in the format "rrggbb"
*
*/
uint32_t get_colorpixel(const char *s) {
char strings[3][3] = { { s[0], s[1], '\0'} ,
{ s[2], s[3], '\0'} ,
{ s[4], s[5], '\0'} };
uint8_t r = strtol(strings[0], NULL, 16);
uint8_t g = strtol(strings[1], NULL, 16);
uint8_t b = strtol(strings[2], NULL, 16);
return (r << 16 | g << 8 | b);
}
/*
* Redraws the statusline to the buffer
*
@ -272,7 +240,9 @@ void unhide_bars() {
XCB_CONFIG_WINDOW_HEIGHT |
XCB_CONFIG_WINDOW_STACK_MODE;
values[0] = walk->rect.x;
values[1] = walk->rect.y + walk->rect.h - font_height - 6;
if (config.position == POS_TOP)
values[1] = walk->rect.y;
else values[1] = walk->rect.y + walk->rect.h - font_height - 6;
values[2] = walk->rect.w;
values[3] = font_height + 6;
values[4] = XCB_STACK_MODE_ABOVE;
@ -298,16 +268,16 @@ void init_colors(const struct xcb_color_strings_t *new_colors) {
do { \
colors.name = get_colorpixel(new_colors->name ? new_colors->name : def); \
} while (0)
PARSE_COLOR(bar_fg, "FFFFFF");
PARSE_COLOR(bar_bg, "000000");
PARSE_COLOR(active_ws_fg, "FFFFFF");
PARSE_COLOR(active_ws_bg, "480000");
PARSE_COLOR(inactive_ws_fg, "FFFFFF");
PARSE_COLOR(inactive_ws_bg, "240000");
PARSE_COLOR(urgent_ws_fg, "FFFFFF");
PARSE_COLOR(urgent_ws_bg, "002400");
PARSE_COLOR(focus_ws_fg, "FFFFFF");
PARSE_COLOR(focus_ws_bg, "480000");
PARSE_COLOR(bar_fg, "#FFFFFF");
PARSE_COLOR(bar_bg, "#000000");
PARSE_COLOR(active_ws_fg, "#FFFFFF");
PARSE_COLOR(active_ws_bg, "#333333");
PARSE_COLOR(inactive_ws_fg, "#888888");
PARSE_COLOR(inactive_ws_bg, "#222222");
PARSE_COLOR(urgent_ws_fg, "#FFFFFF");
PARSE_COLOR(urgent_ws_bg, "#900000");
PARSE_COLOR(focus_ws_fg, "#FFFFFF");
PARSE_COLOR(focus_ws_bg, "#285577");
#undef PARSE_COLOR
}
@ -389,6 +359,310 @@ void handle_button(xcb_button_press_event_t *event) {
i3_send_msg(I3_IPC_MESSAGE_TYPE_COMMAND, buffer);
}
/*
* Configures the x coordinate of all trayclients. To be called after adding a
* new tray client or removing an old one.
*
*/
static void configure_trayclients() {
trayclient *trayclient;
i3_output *output;
SLIST_FOREACH(output, outputs, slist) {
if (!output->active)
continue;
int clients = 0;
TAILQ_FOREACH_REVERSE(trayclient, output->trayclients, tc_head, tailq) {
if (!trayclient->mapped)
continue;
clients++;
DLOG("Configuring tray window %08x to x=%d\n",
trayclient->win, output->rect.w - (clients * (font_height + 2)));
uint32_t x = output->rect.w - (clients * (font_height + 2));
xcb_configure_window(xcb_connection,
trayclient->win,
XCB_CONFIG_WINDOW_X,
&x);
}
}
}
/*
* Handles ClientMessages (messages sent from another client directly to us).
*
* At the moment, only the tray window will receive client messages. All
* supported client messages currently are _NET_SYSTEM_TRAY_OPCODE.
*
*/
static void handle_client_message(xcb_client_message_event_t* event) {
if (event->type == atoms[_NET_SYSTEM_TRAY_OPCODE] &&
event->format == 32) {
DLOG("_NET_SYSTEM_TRAY_OPCODE received\n");
/* event->data.data32[0] is the timestamp */
uint32_t op = event->data.data32[1];
uint32_t mask;
uint32_t values[2];
if (op == SYSTEM_TRAY_REQUEST_DOCK) {
xcb_window_t client = event->data.data32[2];
/* Listen for PropertyNotify events to get the most recent value of
* the XEMBED_MAPPED atom, also listen for UnmapNotify events */
mask = XCB_CW_EVENT_MASK;
values[0] = XCB_EVENT_MASK_PROPERTY_CHANGE |
XCB_EVENT_MASK_STRUCTURE_NOTIFY;
xcb_change_window_attributes(xcb_connection,
client,
mask,
values);
/* Request the _XEMBED_INFO property. The XEMBED specification
* (which is referred by the tray specification) says this *has* to
* be set, but VLC does not set it */
bool map_it = true;
int xe_version = 1;
xcb_get_property_cookie_t xembedc;
xembedc = xcb_get_property_unchecked(xcb_connection,
0,
client,
atoms[_XEMBED_INFO],
XCB_GET_PROPERTY_TYPE_ANY,
0,
2 * 32);
xcb_get_property_reply_t *xembedr = xcb_get_property_reply(xcb_connection,
xembedc,
NULL);
if (xembedr != NULL && xembedr->length != 0) {
DLOG("xembed format = %d, len = %d\n", xembedr->format, xembedr->length);
uint32_t *xembed = xcb_get_property_value(xembedr);
DLOG("xembed version = %d\n", xembed[0]);
DLOG("xembed flags = %d\n", xembed[1]);
map_it = ((xembed[1] & XEMBED_MAPPED) == XEMBED_MAPPED);
xe_version = xembed[0];
if (xe_version > 1)
xe_version = 1;
free(xembedr);
} else {
ELOG("Window %08x violates the XEMBED protocol, _XEMBED_INFO not set\n", client);
}
DLOG("X window %08x requested docking\n", client);
i3_output *walk, *output = NULL;
SLIST_FOREACH(walk, outputs, slist) {
if (!walk->active)
continue;
if (config.tray_output &&
strcasecmp(walk->name, config.tray_output) != 0)
continue;
DLOG("using output %s\n", walk->name);
output = walk;
}
if (output == NULL) {
ELOG("No output found\n");
return;
}
xcb_reparent_window(xcb_connection,
client,
output->bar,
output->rect.w - font_height - 2,
2);
/* We reconfigure the window to use a reasonable size. The systray
* specification explicitly says:
* Tray icons may be assigned any size by the system tray, and
* should do their best to cope with any size effectively
*/
mask = XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT;
values[0] = font_height;
values[1] = font_height;
xcb_configure_window(xcb_connection,
client,
mask,
values);
/* send the XEMBED_EMBEDDED_NOTIFY message */
void *event = scalloc(32);
xcb_client_message_event_t *ev = event;
ev->response_type = XCB_CLIENT_MESSAGE;
ev->window = client;
ev->type = atoms[_XEMBED];
ev->format = 32;
ev->data.data32[0] = XCB_CURRENT_TIME;
ev->data.data32[1] = atoms[XEMBED_EMBEDDED_NOTIFY];
ev->data.data32[2] = output->bar;
ev->data.data32[3] = xe_version;
xcb_send_event(xcb_connection,
0,
client,
XCB_EVENT_MASK_NO_EVENT,
(char*)ev);
free(event);
/* Put the client inside the save set. Upon termination (whether
* killed or normal exit does not matter) of i3bar, these clients
* will be correctly reparented to their most closest living
* ancestor. Without this, tray icons might die when i3bar
* exits/crashes. */
xcb_change_save_set(xcb_connection, XCB_SET_MODE_INSERT, client);
if (map_it) {
DLOG("Mapping dock client\n");
xcb_map_window(xcb_connection, client);
} else {
DLOG("Not mapping dock client yet\n");
}
trayclient *tc = smalloc(sizeof(trayclient));
tc->win = client;
tc->mapped = map_it;
tc->xe_version = xe_version;
TAILQ_INSERT_TAIL(output->trayclients, tc, tailq);
/* Trigger an update to copy the statusline text to the appropriate
* position */
configure_trayclients();
draw_bars();
}
}
}
/*
* Handles UnmapNotify events. These events happen when a tray window unmaps
* itself. We then update our data structure
*
*/
static void handle_unmap_notify(xcb_unmap_notify_event_t* event) {
DLOG("UnmapNotify for window = %08x, event = %08x\n", event->window, event->event);
i3_output *walk;
SLIST_FOREACH(walk, outputs, slist) {
if (!walk->active)
continue;
DLOG("checking output %s\n", walk->name);
trayclient *trayclient;
TAILQ_FOREACH(trayclient, walk->trayclients, tailq) {
if (trayclient->win != event->window)
continue;
DLOG("Removing tray client with window ID %08x\n", event->window);
TAILQ_REMOVE(walk->trayclients, trayclient, tailq);
/* Trigger an update, we now have more space for the statusline */
configure_trayclients();
draw_bars();
return;
}
}
}
/*
* Handle PropertyNotify messages. Currently only the _XEMBED_INFO property is
* handled, which tells us whether a dock client should be mapped or unmapped.
*
*/
static void handle_property_notify(xcb_property_notify_event_t *event) {
DLOG("PropertyNotify\n");
if (event->atom == atoms[_XEMBED_INFO] &&
event->state == XCB_PROPERTY_NEW_VALUE) {
DLOG("xembed_info updated\n");
trayclient *trayclient = NULL, *walk;
i3_output *o_walk;
SLIST_FOREACH(o_walk, outputs, slist) {
if (!o_walk->active)
continue;
TAILQ_FOREACH(walk, o_walk->trayclients, tailq) {
if (walk->win != event->window)
continue;
trayclient = walk;
break;
}
if (trayclient)
break;
}
if (!trayclient) {
ELOG("PropertyNotify received for unknown window %08x\n",
event->window);
return;
}
xcb_get_property_cookie_t xembedc;
xembedc = xcb_get_property_unchecked(xcb_connection,
0,
trayclient->win,
atoms[_XEMBED_INFO],
XCB_GET_PROPERTY_TYPE_ANY,
0,
2 * 32);
xcb_get_property_reply_t *xembedr = xcb_get_property_reply(xcb_connection,
xembedc,
NULL);
if (xembedr == NULL || xembedr->length == 0) {
DLOG("xembed_info unset\n");
return;
}
DLOG("xembed format = %d, len = %d\n", xembedr->format, xembedr->length);
uint32_t *xembed = xcb_get_property_value(xembedr);
DLOG("xembed version = %d\n", xembed[0]);
DLOG("xembed flags = %d\n", xembed[1]);
bool map_it = ((xembed[1] & XEMBED_MAPPED) == XEMBED_MAPPED);
DLOG("map-state now %d\n", map_it);
if (trayclient->mapped && !map_it) {
/* need to unmap the window */
xcb_unmap_window(xcb_connection, trayclient->win);
trayclient->mapped = map_it;
configure_trayclients();
draw_bars();
} else if (!trayclient->mapped && map_it) {
/* need to map the window */
xcb_map_window(xcb_connection, trayclient->win);
trayclient->mapped = map_it;
configure_trayclients();
draw_bars();
}
free(xembedr);
}
}
/*
* Handle ConfigureRequests by denying them and sending the client a
* ConfigureNotify with its actual size.
*
*/
static void handle_configure_request(xcb_configure_request_event_t *event) {
DLOG("ConfigureRequest for window = %08x\n", event->window);
trayclient *trayclient;
i3_output *output;
SLIST_FOREACH(output, outputs, slist) {
if (!output->active)
continue;
int clients = 0;
TAILQ_FOREACH_REVERSE(trayclient, output->trayclients, tc_head, tailq) {
if (!trayclient->mapped)
continue;
clients++;
if (trayclient->win != event->window)
continue;
xcb_rectangle_t rect;
rect.x = output->rect.w - (clients * (font_height + 2));
rect.y = 2;
rect.width = font_height;
rect.height = font_height;
DLOG("This is a tray window. x = %d\n", rect.x);
fake_configure_notify(xcb_connection, rect, event->window, 0);
return;
}
}
DLOG("WARNING: Could not find corresponding tray window.\n");
}
/*
* This function is called immediately before the main loop locks. We flush xcb
* then (and only then)
@ -412,10 +686,7 @@ void xcb_chk_cb(struct ev_loop *loop, ev_check *watcher, int revents) {
exit(1);
}
while ((event = xcb_poll_for_event(xcb_connection)) == NULL) {
return;
}
while ((event = xcb_poll_for_event(xcb_connection)) != NULL) {
switch (event->response_type & ~0x80) {
case XCB_EXPOSE:
/* Expose-events happen, when the window needs to be redrawn */
@ -425,8 +696,27 @@ void xcb_chk_cb(struct ev_loop *loop, ev_check *watcher, int revents) {
/* Button-press-events are mouse-buttons clicked on one of our bars */
handle_button((xcb_button_press_event_t*) event);
break;
case XCB_CLIENT_MESSAGE:
/* Client messages are used for client-to-client communication, for
* example system tray widgets talk to us directly via client messages. */
handle_client_message((xcb_client_message_event_t*) event);
break;
case XCB_UNMAP_NOTIFY:
case XCB_DESTROY_NOTIFY:
/* UnmapNotifies are received when a tray window unmaps itself */
handle_unmap_notify((xcb_unmap_notify_event_t*) event);
break;
case XCB_PROPERTY_NOTIFY:
/* PropertyNotify */
handle_property_notify((xcb_property_notify_event_t*) event);
break;
case XCB_CONFIGURE_REQUEST:
/* ConfigureRequest, sent by a tray child */
handle_configure_request((xcb_configure_request_event_t*) event);
break;
}
free(event);
}
FREE(event);
}
/*
@ -477,12 +767,13 @@ void xkb_io_cb(struct ev_loop *loop, ev_io *watcher, int revents) {
}
/*
* Initialize xcb and use the specified fontname for text-rendering
* Early initialization of the connection to X11: Everything which does not
* depend on 'config'.
*
*/
char *init_xcb(char *fontname) {
char *init_xcb_early() {
/* FIXME: xcb_connect leaks Memory */
xcb_connection = xcb_connect(NULL, NULL);
xcb_connection = xcb_connect(NULL, &screen);
if (xcb_connection_has_error(xcb_connection)) {
ELOG("Cannot open display\n");
exit(EXIT_FAILURE);
@ -496,6 +787,93 @@ char *init_xcb(char *fontname) {
xcb_screen = xcb_setup_roots_iterator(xcb_get_setup(xcb_connection)).data;
xcb_root = xcb_screen->root;
/* We draw the statusline to a seperate pixmap, because it looks the same on all bars and
* this way, we can choose to crop it */
uint32_t mask = XCB_GC_FOREGROUND;
uint32_t vals[] = { colors.bar_bg, colors.bar_bg };
statusline_clear = xcb_generate_id(xcb_connection);
xcb_void_cookie_t clear_ctx_cookie = xcb_create_gc_checked(xcb_connection,
statusline_clear,
xcb_root,
mask,
vals);
mask |= XCB_GC_BACKGROUND;
vals[0] = colors.bar_fg;
statusline_ctx = xcb_generate_id(xcb_connection);
xcb_void_cookie_t sl_ctx_cookie = xcb_create_gc_checked(xcb_connection,
statusline_ctx,
xcb_root,
mask,
vals);
statusline_pm = xcb_generate_id(xcb_connection);
xcb_void_cookie_t sl_pm_cookie = xcb_create_pixmap_checked(xcb_connection,
xcb_screen->root_depth,
statusline_pm,
xcb_root,
xcb_screen->width_in_pixels,
xcb_screen->height_in_pixels);
/* The various Watchers to communicate with xcb */
xcb_io = smalloc(sizeof(ev_io));
xcb_prep = smalloc(sizeof(ev_prepare));
xcb_chk = smalloc(sizeof(ev_check));
ev_io_init(xcb_io, &xcb_io_cb, xcb_get_file_descriptor(xcb_connection), EV_READ);
ev_prepare_init(xcb_prep, &xcb_prep_cb);
ev_check_init(xcb_chk, &xcb_chk_cb);
ev_io_start(main_loop, xcb_io);
ev_prepare_start(main_loop, xcb_prep);
ev_check_start(main_loop, xcb_chk);
/* Now we get the atoms and save them in a nice data structure */
get_atoms();
xcb_get_property_cookie_t path_cookie;
path_cookie = xcb_get_property_unchecked(xcb_connection,
0,
xcb_root,
atoms[I3_SOCKET_PATH],
XCB_GET_PROPERTY_TYPE_ANY,
0, PATH_MAX);
/* We check, if i3 set its socket-path */
xcb_get_property_reply_t *path_reply = xcb_get_property_reply(xcb_connection,
path_cookie,
NULL);
char *path = NULL;
if (path_reply) {
int len = xcb_get_property_value_length(path_reply);
if (len != 0) {
path = strndup(xcb_get_property_value(path_reply), len);
}
}
if (xcb_request_failed(sl_pm_cookie, "Could not allocate statusline-buffer") ||
xcb_request_failed(clear_ctx_cookie, "Could not allocate statusline-buffer-clearcontext") ||
xcb_request_failed(sl_ctx_cookie, "Could not allocate statusline-buffer-context")) {
exit(EXIT_FAILURE);
}
return path;
}
/*
* Initialization which depends on 'config' being usable. Called after the
* configuration has arrived.
*
*/
void init_xcb_late(char *fontname) {
if (fontname == NULL) {
/* XXX: font fallback to 'misc' like i3 does it would be good. */
fontname = "-misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1";
}
/* We load and allocate the font */
xcb_font = xcb_generate_id(xcb_connection);
xcb_void_cookie_t open_font_cookie;
@ -510,6 +888,13 @@ char *init_xcb(char *fontname) {
query_font_cookie = xcb_query_font(xcb_connection,
xcb_font);
xcb_change_gc(xcb_connection,
statusline_ctx,
XCB_GC_FONT,
(uint32_t[]){ xcb_font });
xcb_flush(xcb_connection);
/* To grab modifiers without blocking other applications from receiving key-events
* involving that modifier, we sadly have to use xkb which is not yet fully supported
* in xcb */
@ -546,78 +931,12 @@ char *init_xcb(char *fontname) {
exit(EXIT_FAILURE);
}
xkb_io = malloc(sizeof(ev_io));
xkb_io = smalloc(sizeof(ev_io));
ev_io_init(xkb_io, &xkb_io_cb, ConnectionNumber(xkb_dpy), EV_READ);
ev_io_start(main_loop, xkb_io);
XFlush(xkb_dpy);
}
/* We draw the statusline to a seperate pixmap, because it looks the same on all bars and
* this way, we can choose to crop it */
uint32_t mask = XCB_GC_FOREGROUND;
uint32_t vals[3] = { colors.bar_bg, colors.bar_bg, xcb_font };
statusline_clear = xcb_generate_id(xcb_connection);
xcb_void_cookie_t clear_ctx_cookie = xcb_create_gc_checked(xcb_connection,
statusline_clear,
xcb_root,
mask,
vals);
mask |= XCB_GC_BACKGROUND | XCB_GC_FONT;
vals[0] = colors.bar_fg;
statusline_ctx = xcb_generate_id(xcb_connection);
xcb_void_cookie_t sl_ctx_cookie = xcb_create_gc_checked(xcb_connection,
statusline_ctx,
xcb_root,
mask,
vals);
statusline_pm = xcb_generate_id(xcb_connection);
xcb_void_cookie_t sl_pm_cookie = xcb_create_pixmap_checked(xcb_connection,
xcb_screen->root_depth,
statusline_pm,
xcb_root,
xcb_screen->width_in_pixels,
xcb_screen->height_in_pixels);
/* The various Watchers to communicate with xcb */
xcb_io = malloc(sizeof(ev_io));
xcb_prep = malloc(sizeof(ev_prepare));
xcb_chk = malloc(sizeof(ev_check));
ev_io_init(xcb_io, &xcb_io_cb, xcb_get_file_descriptor(xcb_connection), EV_READ);
ev_prepare_init(xcb_prep, &xcb_prep_cb);
ev_check_init(xcb_chk, &xcb_chk_cb);
ev_io_start(main_loop, xcb_io);
ev_prepare_start(main_loop, xcb_prep);
ev_check_start(main_loop, xcb_chk);
/* Now we get the atoms and save them in a nice data structure */
get_atoms();
xcb_get_property_cookie_t path_cookie;
path_cookie = xcb_get_property_unchecked(xcb_connection,
0,
xcb_root,
atoms[I3_SOCKET_PATH],
XCB_GET_PROPERTY_TYPE_ANY,
0, PATH_MAX);
/* We check, if i3 set its socket-path */
xcb_get_property_reply_t *path_reply = xcb_get_property_reply(xcb_connection,
path_cookie,
NULL);
char *path = NULL;
if (path_reply) {
int len = xcb_get_property_value_length(path_reply);
if (len != 0) {
path = strndup(xcb_get_property_value(path_reply), len);
}
}
/* Now we save the font-infos */
font_info = xcb_query_font_reply(xcb_connection,
query_font_cookie,
@ -636,14 +955,96 @@ char *init_xcb(char *fontname) {
}
DLOG("Calculated Font-height: %d\n", font_height);
}
if (xcb_request_failed(sl_pm_cookie, "Could not allocate statusline-buffer") ||
xcb_request_failed(clear_ctx_cookie, "Could not allocate statusline-buffer-clearcontext") ||
xcb_request_failed(sl_ctx_cookie, "Could not allocate statusline-buffer-context")) {
/*
* Initializes tray support by requesting the appropriate _NET_SYSTEM_TRAY atom
* for the X11 display we are running on, then acquiring the selection for this
* atom. Afterwards, tray clients will send ClientMessages to our window.
*
*/
void init_tray() {
DLOG("Initializing system tray functionality\n");
/* request the tray manager atom for the X11 display we are running on */
char atomname[strlen("_NET_SYSTEM_TRAY_S") + 11];
snprintf(atomname, strlen("_NET_SYSTEM_TRAY_S") + 11, "_NET_SYSTEM_TRAY_S%d", screen);
xcb_intern_atom_cookie_t tray_cookie;
xcb_intern_atom_reply_t *tray_reply;
tray_cookie = xcb_intern_atom(xcb_connection, 0, strlen(atomname), atomname);
/* tray support: we need a window to own the selection */
xcb_window_t selwin = xcb_generate_id(xcb_connection);
uint32_t selmask = XCB_CW_OVERRIDE_REDIRECT;
uint32_t selval[] = { 1 };
xcb_create_window(xcb_connection,
xcb_screen->root_depth,
selwin,
xcb_root,
-1, -1,
1, 1,
1,
XCB_WINDOW_CLASS_INPUT_OUTPUT,
xcb_screen->root_visual,
selmask,
selval);
uint32_t orientation = _NET_SYSTEM_TRAY_ORIENTATION_HORZ;
/* set the atoms */
xcb_change_property(xcb_connection,
XCB_PROP_MODE_REPLACE,
selwin,
atoms[_NET_SYSTEM_TRAY_ORIENTATION],
XCB_ATOM_CARDINAL,
32,
1,
&orientation);
if (!(tray_reply = xcb_intern_atom_reply(xcb_connection, tray_cookie, NULL))) {
ELOG("Could not get atom %s\n", atomname);
exit(EXIT_FAILURE);
}
return path;
xcb_set_selection_owner(xcb_connection,
selwin,
tray_reply->atom,
XCB_CURRENT_TIME);
/* Verify that we have the selection */
xcb_get_selection_owner_cookie_t selcookie;
xcb_get_selection_owner_reply_t *selreply;
selcookie = xcb_get_selection_owner(xcb_connection, tray_reply->atom);
if (!(selreply = xcb_get_selection_owner_reply(xcb_connection, selcookie, NULL))) {
ELOG("Could not get selection owner for %s\n", atomname);
exit(EXIT_FAILURE);
}
if (selreply->owner != selwin) {
ELOG("Could not set the %s selection. " \
"Maybe another tray is already running?\n", atomname);
/* NOTE that this error is not fatal. We just cant provide tray
* functionality */
free(selreply);
return;
}
/* Inform clients waiting for a new _NET_SYSTEM_TRAY that we are here */
void *event = scalloc(32);
xcb_client_message_event_t *ev = event;
ev->response_type = XCB_CLIENT_MESSAGE;
ev->window = xcb_root;
ev->type = atoms[MANAGER];
ev->format = 32;
ev->data.data32[0] = XCB_CURRENT_TIME;
ev->data.data32[1] = tray_reply->atom;
ev->data.data32[2] = selwin;
xcb_send_event(xcb_connection,
0,
xcb_root,
XCB_EVENT_MASK_STRUCTURE_NOTIFY,
(char*)ev);
free(event);
free(tray_reply);
}
/*
@ -653,15 +1054,27 @@ char *init_xcb(char *fontname) {
*/
void clean_xcb() {
i3_output *o_walk;
trayclient *trayclient;
free_workspaces();
SLIST_FOREACH(o_walk, outputs, slist) {
TAILQ_FOREACH(trayclient, o_walk->trayclients, tailq) {
/* Unmap, then reparent (to root) the tray client windows */
xcb_unmap_window(xcb_connection, trayclient->win);
xcb_reparent_window(xcb_connection,
trayclient->win,
xcb_root,
0,
0);
}
destroy_window(o_walk);
FREE(o_walk->trayclients);
FREE(o_walk->workspaces);
FREE(o_walk->name);
}
FREE_SLIST(outputs, i3_output);
FREE(outputs);
xcb_flush(xcb_connection);
xcb_disconnect(xcb_connection);
ev_check_stop(main_loop, xcb_chk);
@ -758,6 +1171,7 @@ void realloc_sl_buffer() {
void reconfig_windows() {
uint32_t mask;
uint32_t values[5];
static bool tray_configured = false;
i3_output *walk;
SLIST_FOREACH(walk, outputs, slist) {
@ -778,8 +1192,14 @@ void reconfig_windows() {
values[0] = colors.bar_bg;
/* If hide_on_modifier is set, i3 is not supposed to manage our bar-windows */
values[1] = config.hide_on_modifier;
/* The events we want to receive */
values[2] = XCB_EVENT_MASK_EXPOSURE;
/* We enable the following EventMask fields:
* EXPOSURE, to get expose events (we have to re-draw then)
* SUBSTRUCTURE_REDIRECT, to get ConfigureRequests when the tray
* child windows use ConfigureWindow
* BUTTON_PRESS, to handle clicks on the workspace buttons
* */
values[2] = XCB_EVENT_MASK_EXPOSURE |
XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT;
if (!config.disable_ws) {
values[2] |= XCB_EVENT_MASK_BUTTON_PRESS;
}
@ -803,6 +1223,31 @@ void reconfig_windows() {
walk->rect.w,
walk->rect.h);
/* Set the WM_CLASS and WM_NAME (we don't need UTF-8) atoms */
xcb_void_cookie_t class_cookie;
class_cookie = xcb_change_property(xcb_connection,
XCB_PROP_MODE_REPLACE,
walk->bar,
XCB_ATOM_WM_CLASS,
XCB_ATOM_STRING,
8,
(strlen("i3bar") + 1) * 2,
"i3bar\0i3bar\0");
char *name;
if (asprintf(&name, "i3bar for output %s", walk->name) == -1)
err(EXIT_FAILURE, "asprintf()");
xcb_void_cookie_t name_cookie;
name_cookie = xcb_change_property(xcb_connection,
XCB_PROP_MODE_REPLACE,
walk->bar,
XCB_ATOM_WM_NAME,
XCB_ATOM_STRING,
8,
strlen(name),
name);
free(name);
/* We want dock-windows (for now). When override_redirect is set, i3 is ignoring
* this one */
xcb_void_cookie_t dock_cookie = xcb_change_property(xcb_connection,
@ -833,15 +1278,15 @@ void reconfig_windows() {
uint32_t bottom_start_x;
uint32_t bottom_end_x;
} __attribute__((__packed__)) strut_partial = {0,};
switch (config.dockpos) {
case DOCKPOS_NONE:
switch (config.position) {
case POS_NONE:
break;
case DOCKPOS_TOP:
case POS_TOP:
strut_partial.top = font_height + 6;
strut_partial.top_start_x = walk->rect.x;
strut_partial.top_end_x = walk->rect.x + walk->rect.w;
break;
case DOCKPOS_BOT:
case POS_BOT:
strut_partial.bottom = font_height + 6;
strut_partial.bottom_start_x = walk->rect.x;
strut_partial.bottom_end_x = walk->rect.x + walk->rect.w;
@ -876,11 +1321,20 @@ void reconfig_windows() {
if (xcb_request_failed(win_cookie, "Could not create window") ||
xcb_request_failed(pm_cookie, "Could not create pixmap") ||
xcb_request_failed(dock_cookie, "Could not set dock mode") ||
xcb_request_failed(class_cookie, "Could not set WM_CLASS") ||
xcb_request_failed(name_cookie, "Could not set WM_NAME") ||
xcb_request_failed(strut_cookie, "Could not set strut") ||
xcb_request_failed(gc_cookie, "Could not create graphical context") ||
(!config.hide_on_modifier && xcb_request_failed(map_cookie, "Could not map window"))) {
exit(EXIT_FAILURE);
}
if (!tray_configured &&
(!config.tray_output ||
strcasecmp("none", config.tray_output) != 0)) {
init_tray();
tray_configured = true;
}
} else {
/* We already have a bar, so we just reconfigure it */
mask = XCB_CONFIG_WINDOW_X |
@ -960,13 +1414,26 @@ void draw_bars() {
/* Luckily we already prepared a seperate pixmap containing the rendered
* statusline, we just have to copy the relevant parts to the relevant
* position */
trayclient *trayclient;
int traypx = 0;
TAILQ_FOREACH(trayclient, outputs_walk->trayclients, tailq) {
if (!trayclient->mapped)
continue;
/* We assume the tray icons are quadratic (we use the font
* *height* as *width* of the icons) because we configured them
* like this. */
traypx += font_height + 2;
}
/* Add 2px of padding if there are any tray icons */
if (traypx > 0)
traypx += 2;
xcb_copy_area(xcb_connection,
statusline_pm,
outputs_walk->buffer,
outputs_walk->bargc,
MAX(0, (int16_t)(statusline_width - outputs_walk->rect.w + 4)), 0,
MAX(0, (int16_t)(outputs_walk->rect.w - statusline_width - 4)), 3,
MIN(outputs_walk->rect.w - 4, statusline_width), font_height);
MAX(0, (int16_t)(outputs_walk->rect.w - statusline_width - traypx - 4)), 3,
MIN(outputs_walk->rect.w - traypx - 4, statusline_width), font_height);
}
if (config.disable_ws) {

View File

@ -1,4 +1,9 @@
/*
* vim:ts=4:sw=4:expandtab
*
* i3 - an improved dynamic tiling window manager
* © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
*
* This header file includes all relevant files of i3 and the most often used
* system header files. This reduces boilerplate (the amount of code duplicated
* at the beginning of each source file) and is not significantly slower at
@ -64,5 +69,8 @@
#include "output.h"
#include "ewmh.h"
#include "assignments.h"
#include "regex.h"
#include "libi3.h"
#include "startup.h"
#endif

View File

@ -1,6 +1,11 @@
/*
* vim:ts=4:sw=4:expandtab
*
* i3 - an improved dynamic tiling window manager
* © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
*
* assignments.c: Assignments for specific windows (for_window).
*
*/
#ifndef _ASSIGNMENTS_H
#define _ASSIGNMENTS_H

View File

@ -15,11 +15,14 @@ xmacro(_NET_CLIENT_LIST_STACKING)
xmacro(_NET_CURRENT_DESKTOP)
xmacro(_NET_ACTIVE_WINDOW)
xmacro(_NET_WORKAREA)
xmacro(_NET_STARTUP_ID)
xmacro(WM_PROTOCOLS)
xmacro(WM_DELETE_WINDOW)
xmacro(UTF8_STRING)
xmacro(WM_STATE)
xmacro(WM_CLIENT_LEADER)
xmacro(WM_TAKE_FOCUS)
xmacro(WM_WINDOW_ROLE)
xmacro(I3_SOCKET_PATH)
xmacro(I3_CONFIG_PATH)
xmacro(I3_SYNC)

View File

@ -2,10 +2,9 @@
* vim:ts=4:sw=4:expandtab
*
* i3 - an improved dynamic tiling window manager
* © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
*
* © 2009-2011 Michael Stapelberg and contributors
*
* See file LICENSE for license information.
* click.c: Button press (mouse click) events.
*
*/
#ifndef _CLICK_H

View File

@ -1,3 +1,12 @@
/*
* vim:ts=4:sw=4:expandtab
*
* i3 - an improved dynamic tiling window manager
* © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
*
* cmdparse.y: the parser for commands you send to i3 (or bind on keys)
*
*/
#ifndef _CMDPARSE_H
#define _CMDPARSE_H

View File

@ -1,3 +1,14 @@
/*
* vim:ts=4:sw=4:expandtab
*
* i3 - an improved dynamic tiling window manager
* © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
*
* con.c: Functions which deal with containers directly (creating containers,
* searching containers, getting specific properties from containers,
* ).
*
*/
#ifndef _CON_H
#define _CON_H

View File

@ -1,11 +1,8 @@
/*
* vim:ts=8:expandtab
* vim:ts=4:sw=4:expandtab
*
* i3 - an improved dynamic tiling window manager
*
* © 2009-2010 Michael Stapelberg and contributors
*
* See file LICENSE for license information.
* © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
*
* include/config.h: Contains all structs/variables for the configurable
* part of i3 as well as functions handling the configuration file (calling
@ -13,18 +10,20 @@
* mode).
*
*/
#ifndef _CONFIG_H
#define _CONFIG_H
#include <stdbool.h>
#include "queue.h"
#include "i3.h"
#include "libi3.h"
typedef struct Config Config;
typedef struct Barconfig Barconfig;
extern char *current_configpath;
extern Config config;
extern SLIST_HEAD(modes_head, Mode) modes;
extern TAILQ_HEAD(barconfig_head, Barconfig) barconfigs;
/**
* Used during the config file lexing/parsing to keep the state of the lexer
@ -33,6 +32,7 @@ extern SLIST_HEAD(modes_head, Mode) modes;
*/
struct context {
bool has_errors;
bool has_warnings;
int line_number;
char *line_copy;
@ -123,9 +123,28 @@ struct Config {
* more often. */
bool force_focus_wrapping;
/** By default, use the RandR API for multi-monitor setups.
* Unfortunately, the nVidia binary graphics driver doesn't support
* this API. Instead, it only support the less powerful Xinerama API,
* which can be enabled by this option.
*
* Note: this option takes only effect on the initial startup (eg.
* reconfiguration is not possible). On startup, the list of screens
* is fetched once and never updated. */
bool force_xinerama;
/** Automatic workspace back and forth switching. If this is set, a
* switch to the currently active workspace will switch to the
* previously focused one instead, making it possible to fast toggle
* between two workspaces. */
bool workspace_auto_back_and_forth;
/** The default border style for new windows. */
border_style_t default_border;
/** The default border style for new floating windows. */
border_style_t default_floating_border;
/** The modifier which needs to be pressed in combination with your mouse
* buttons to do things with floating windows (move, resize) */
uint32_t floating_modifier;
@ -151,6 +170,72 @@ struct Config {
} popup_during_fullscreen;
};
/**
* Holds the status bar configuration (i3bar). One of these structures is
* created for each 'bar' block in the config.
*
*/
struct Barconfig {
/** Automatically generated ID for this bar config. Used by the bar process
* to request a specific configuration. */
char *id;
/** Number of outputs in the outputs array */
int num_outputs;
/** Outputs on which this bar should show up on. We use an array for
* simplicity (since we store just strings). */
char **outputs;
/** Output on which the tray should be shown. The special value of 'no'
* disables the tray (its enabled by default). */
char *tray_output;
/** Path to the i3 IPC socket. This option is discouraged since programs
* can find out the path by looking for the I3_SOCKET_PATH property on the
* root window! */
char *socket_path;
/** Bar display mode (hide unless modifier is pressed or show in dock mode) */
enum { M_DOCK = 0, M_HIDE = 1 } mode;
/** Bar position (bottom by default). */
enum { P_BOTTOM = 0, P_TOP = 1 } position;
/** Command that should be run to get a statusline, for example 'i3status'.
* Will be passed to the shell. */
char *status_command;
/** Font specification for all text rendered on the bar. */
char *font;
/** Hide workspace buttons? Configuration option is 'workspace_buttons no'
* but we invert the bool to get the correct default when initializing with
* zero. */
bool hide_workspace_buttons;
/** Enable verbose mode? Useful for debugging purposes. */
bool verbose;
struct bar_colors {
char *background;
char *statusline;
char *focused_workspace_text;
char *focused_workspace_bg;
char *active_workspace_text;
char *active_workspace_bg;
char *inactive_workspace_text;
char *inactive_workspace_bg;
char *urgent_workspace_text;
char *urgent_workspace_bg;
} colors;
TAILQ_ENTRY(Barconfig) configs;
};
/**
* Reads the configuration from ~/.i3/config or /etc/i3/config if not found.
*

View File

@ -7,12 +7,17 @@
* include/data.h: This file defines all data structures used by i3
*
*/
#ifndef _DATA_H
#define _DATA_H
#define SN_API_NOT_YET_FROZEN 1
#include <libsn/sn-launcher.h>
#include <xcb/randr.h>
#include <xcb/xcb_atom.h>
#include <stdbool.h>
#include <pcre.h>
#ifndef _DATA_H
#define _DATA_H
#include "queue.h"
/*
@ -27,7 +32,6 @@
*/
/* Forward definitions */
typedef struct Font i3Font;
typedef struct Binding Binding;
typedef struct Rect Rect;
typedef struct xoutput Output;
@ -137,6 +141,37 @@ struct Ignore_Event {
SLIST_ENTRY(Ignore_Event) ignore_events;
};
/**
* Stores internal information about a startup sequence, like the workspace it
* was initiated on.
*
*/
struct Startup_Sequence {
/** startup ID for this sequence, generated by libstartup-notification */
char *id;
/** workspace on which this startup was initiated */
char *workspace;
/** libstartup-notification context for this launch */
SnLauncherContext *context;
TAILQ_ENTRY(Startup_Sequence) sequences;
};
/**
* Regular expression wrapper. It contains the pattern itself as a string (like
* ^foo[0-9]$) as well as a pointer to the compiled PCRE expression and the
* pcre_extra data returned by pcre_study().
*
* This makes it easier to have a useful logfile, including the matching or
* non-matching pattern.
*
*/
struct regex {
char *pattern;
pcre *regex;
pcre_extra *extra;
};
/******************************************************************************
* Major types
*****************************************************************************/
@ -183,24 +218,13 @@ struct Binding {
struct Autostart {
/** Command, like in command mode */
char *command;
/** no_startup_id flag for start_application(). Determines whether a
* startup notification context/ID should be created. */
bool no_startup_id;
TAILQ_ENTRY(Autostart) autostarts;
TAILQ_ENTRY(Autostart) autostarts_always;
};
/**
* Data structure for cached font information:
* - font id in X11 (load it once)
* - font height (multiple calls needed to get it)
*
*/
struct Font {
/** The height of the font, built from font_ascent + font_descent */
int height;
/** The xcb-id for the font */
xcb_font_t id;
};
/**
* An Output is a physical output on your graphics driver. Outputs which
* are currently in use have (output->active == true). Each output has a
@ -248,6 +272,11 @@ struct Window {
* application supports _NET_WM_NAME, in COMPOUND_TEXT otherwise). */
char *name_x;
/** The WM_WINDOW_ROLE of this window (for example, the pidgin buddy window
* sets "buddy list"). Useful to match specific windows in assignments or
* for_window. */
char *role;
/** Flag to force re-rendering the decoration upon changes */
bool name_x_changed;
@ -277,12 +306,12 @@ struct Window {
};
struct Match {
char *title;
int title_len;
char *application;
char *class;
char *instance;
char *mark;
struct regex *title;
struct regex *application;
struct regex *class;
struct regex *instance;
struct regex *mark;
struct regex *role;
enum {
M_DONTCHECK = -1,
M_NODOCK = 0,

View File

@ -1,11 +1,11 @@
/*
* vim:ts=8:expandtab
* vim:ts=4:sw=4:expandtab
*
* i3 - an improved dynamic tiling window manager
* © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
*
* (c) 2009 Michael Stapelberg and contributors
*
* See file LICENSE for license information.
* debug.c: Debugging functions, especially FormatEvent, which prints unhandled
* events. This code is from xcb-util.
*
*/
#ifndef _DEBUG_H

View File

@ -2,10 +2,9 @@
* vim:ts=4:sw=4:expandtab
*
* i3 - an improved dynamic tiling window manager
* © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
*
* © 2009 Michael Stapelberg and contributors
*
* See file LICENSE for license information.
* ewmh.c: Get/set certain EWMH properties easily.
*
*/
#ifndef _EWMH_C

View File

@ -1,11 +1,10 @@
/*
* vim:ts=8:expandtab
* vim:ts=4:sw=4:expandtab
*
* i3 - an improved dynamic tiling window manager
* © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
*
* © 2009-2010 Michael Stapelberg and contributors
*
* See file LICENSE for license information.
* floating.c: Floating windows.
*
*/
#ifndef _FLOATING_H
@ -14,12 +13,12 @@
#include "tree.h"
/** Callback for dragging */
typedef void(*callback_t)(Con*, Rect*, uint32_t, uint32_t, void*);
typedef void(*callback_t)(Con*, Rect*, uint32_t, uint32_t, const void*);
/** Macro to create a callback function for dragging */
#define DRAGGING_CB(name) \
static void name(Con *con, Rect *old_rect, uint32_t new_x, \
uint32_t new_y, void *extra)
uint32_t new_y, const void *extra)
/** On which border was the dragging initiated? */
typedef enum { BORDER_LEFT = (1 << 0),
@ -90,7 +89,7 @@ int floating_border_click(xcb_connection_t *conn, Client *client,
* Calls the drag_pointer function with the drag_window callback
*
*/
void floating_drag_window(Con *con, xcb_button_press_event_t *event);
void floating_drag_window(Con *con, const xcb_button_press_event_t *event);
/**
* Called when the user clicked on a floating window while holding the
@ -98,7 +97,7 @@ void floating_drag_window(Con *con, xcb_button_press_event_t *event);
* Calls the drag_pointer function with the resize_window callback
*
*/
void floating_resize_window(Con *con, bool proportional, xcb_button_press_event_t *event);
void floating_resize_window(Con *con, const bool proportional, const xcb_button_press_event_t *event);
#if 0
/**
@ -134,8 +133,8 @@ void floating_toggle_hide(xcb_connection_t *conn, Workspace *workspace);
* the event and the new coordinates (x, y).
*
*/
void drag_pointer(Con *con, xcb_button_press_event_t *event,
void drag_pointer(Con *con, const xcb_button_press_event_t *event,
xcb_window_t confine_to, border_t border, callback_t callback,
void *extra);
const void *extra);
#endif

View File

@ -1,11 +1,11 @@
/*
* vim:ts=8:expandtab
* vim:ts=4:sw=4:expandtab
*
* i3 - an improved dynamic tiling window manager
* © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
*
* © 2009-2010 Michael Stapelberg and contributors
*
* See file LICENSE for license information.
* handlers.c: Small handlers for various events (keypresses, focus changes,
* ).
*
*/
#ifndef _HANDLERS_H

View File

@ -2,24 +2,39 @@
* vim:ts=4:sw=4:expandtab
*
* i3 - an improved dynamic tiling window manager
* © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
*
* © 2009 Michael Stapelberg and contributors
*
* See file LICENSE for license information.
* i3.h: global variables that are used all over i3.
*
*/
#ifndef _I3_H
#define _I3_H
#include <sys/time.h>
#include <sys/resource.h>
#include <xcb/xcb_keysyms.h>
#include <X11/XKBlib.h>
#define SN_API_NOT_YET_FROZEN 1
#include <libsn/sn-launcher.h>
#include "queue.h"
#include "data.h"
#include "xcb.h"
#ifndef _I3_H
#define _I3_H
/** The original value of RLIMIT_CORE when i3 was started. We need to restore
* this before starting any other process, since we set RLIMIT_CORE to
* RLIM_INFINITY for i3 debugging versions. */
extern struct rlimit original_rlimit_core;
extern xcb_connection_t *conn;
extern int conn_screen;
/** The last timestamp we got from X11 (timestamps are included in some events
* and are used for some things, like determining a unique ID in startup
* notification). */
extern xcb_timestamp_t last_timestamp;
extern SnDisplay *sndisplay;
extern xcb_key_symbols_t *keysyms;
extern char **start_argv;
extern Display *xlibdpy, *xkbdpy;
@ -35,5 +50,6 @@ extern uint8_t root_depth;
extern bool xcursor_supported, xkb_supported;
extern xcb_window_t root;
extern struct ev_loop *main_loop;
extern bool only_check_config;
#endif

View File

@ -1,17 +1,13 @@
/*
* vim:ts=8:expandtab
* vim:ts=4:sw=4:expandtab
*
* i3 - an improved dynamic tiling window manager
*
* © 2009-2010 Michael Stapelberg and contributors
*
* See file LICENSE for license information.
* © 2009-2010 Michael Stapelberg and contributors (see also: LICENSE)
*
* This public header defines the different constants and message types to use
* for the IPC interface to i3 (see docs/ipc for more information).
*
*/
#ifndef _I3_IPC_H
#define _I3_IPC_H
@ -38,6 +34,11 @@
/** Requests the tree layout from i3 */
#define I3_IPC_MESSAGE_TYPE_GET_TREE 4
/** Request the current defined marks from i3 */
#define I3_IPC_MESSAGE_TYPE_GET_MARKS 5
/** Request the configuration for a specific 'bar' */
#define I3_IPC_MESSAGE_TYPE_GET_BAR_CONFIG 6
/*
* Messages from i3 to clients
@ -59,6 +60,11 @@
/** Tree reply type */
#define I3_IPC_REPLY_TYPE_TREE 4
/** Marks reply type */
#define I3_IPC_REPLY_TYPE_MARKS 5
/** Bar config reply type */
#define I3_IPC_REPLY_TYPE_BAR_CONFIG 6
/*
* Events from i3 to clients. Events have the first bit set high.

View File

@ -1,14 +1,12 @@
/*
* vim:ts=8:expandtab
* vim:ts=4:sw=4:expandtab
*
* i3 - an improved dynamic tiling window manager
* © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
*
* © 2009-2010 Michael Stapelberg and contributors
*
* See file LICENSE for license information.
* ipc.c: UNIX domain socket IPC (initialization, client handling, protocol).
*
*/
#ifndef _IPC_H
#define _IPC_H

182
include/libi3.h Normal file
View File

@ -0,0 +1,182 @@
/*
* vim:ts=4:sw=4:expandtab
*
* i3 - an improved dynamic tiling window manager
* © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
*
* libi3: contains functions which are used by i3 *and* accompanying tools such
* as i3-msg, i3-config-wizard,
*
*/
#ifndef _LIBI3_H
#define _LIBI3_H
#include <stdbool.h>
#include <stdarg.h>
#include <stdio.h>
#include <xcb/xcb.h>
#include <xcb/xproto.h>
#include <xcb/xcb_keysyms.h>
typedef struct Font i3Font;
/**
* Data structure for cached font information:
* - font id in X11 (load it once)
* - font height (multiple calls needed to get it)
*
*/
struct Font {
/** The height of the font, built from font_ascent + font_descent */
int height;
/** The xcb-id for the font */
xcb_font_t id;
};
/* Since this file also gets included by utilities which dont use the i3 log
* infrastructure, we define a fallback. */
#if !defined(ELOG)
#define ELOG(fmt, ...) fprintf(stderr, "ERROR: " fmt, ##__VA_ARGS__)
#endif
/**
* Try to get the socket path from X11 and return NULL if it doesnt work.
*
* The memory for the socket path is dynamically allocated and has to be
* free()d by the caller.
*
*/
char *socket_path_from_x11();
/**
* Safe-wrapper around malloc which exits if malloc returns NULL (meaning that
* there is no more memory available)
*
*/
void *smalloc(size_t size);
/**
* Safe-wrapper around calloc which exits if malloc returns NULL (meaning that
* there is no more memory available)
*
*/
void *scalloc(size_t size);
/**
* Safe-wrapper around realloc which exits if realloc returns NULL (meaning
* that there is no more memory available).
*
*/
void *srealloc(void *ptr, size_t size);
/**
* Safe-wrapper around strdup which exits if malloc returns NULL (meaning that
* there is no more memory available)
*
*/
char *sstrdup(const char *str);
/**
* Safe-wrapper around asprintf which exits if it returns -1 (meaning that
* there is no more memory available)
*
*/
int sasprintf(char **strp, const char *fmt, ...);
/**
* Connects to the i3 IPC socket and returns the file descriptor for the
* socket. die()s if anything goes wrong.
*
*/
int ipc_connect(const char *socket_path);
/**
* Formats a message (payload) of the given size and type and sends it to i3 via
* the given socket file descriptor.
*
* Returns -1 when write() fails, errno will remain.
* Returns 0 on success.
*
*/
int ipc_send_message(int sockfd, uint32_t message_size,
uint32_t message_type, const uint8_t *payload);
/**
* Reads a message from the given socket file descriptor and stores its length
* (reply_length) as well as a pointer to its contents (reply).
*
* Returns -1 when read() fails, errno will remain.
* Returns -2 when the IPC protocol is violated (invalid magic, unexpected
* message type, EOF instead of a message). Additionally, the error will be
* printed to stderr.
* Returns 0 on success.
*
*/
int ipc_recv_message(int sockfd, uint32_t message_type,
uint32_t *reply_length, uint8_t **reply);
/**
* Generates a configure_notify event and sends it to the given window
* Applications need this to think theyve configured themselves correctly.
* The truth is, however, that we will manage them.
*
*/
void fake_configure_notify(xcb_connection_t *conn, xcb_rectangle_t r, xcb_window_t window, int border_width);
/**
* Returns the colorpixel to use for the given hex color (think of HTML). Only
* works for true-color (vast majority of cases) at the moment, avoiding a
* roundtrip to X11.
*
* The hex_color has to start with #, for example #FF00FF.
*
* NOTE that get_colorpixel() does _NOT_ check the given color code for validity.
* This has to be done by the caller.
*
* NOTE that this function may in the future rely on a global xcb_connection_t
* variable called 'conn' to be present.
*
*/
uint32_t get_colorpixel(const char *hex) __attribute__((const));
#if defined(__APPLE__)
/*
* Taken from FreeBSD
* Returns a pointer to a new string which is a duplicate of the
* string, but only copies at most n characters.
*
*/
char *strndup(const char *str, size_t n);
#endif
/**
* All-in-one function which returns the modifier mask (XCB_MOD_MASK_*) for the
* given keysymbol, for example for XCB_NUM_LOCK (usually configured to mod2).
*
* This function initiates one round-trip. Use get_mod_mask_for() directly if
* you already have the modifier mapping and key symbols.
*
*/
uint32_t aio_get_mod_mask_for(uint32_t keysym, xcb_key_symbols_t *symbols);
/**
* Returns the modifier mask (XCB_MOD_MASK_*) for the given keysymbol, for
* example for XCB_NUM_LOCK (usually configured to mod2).
*
* This function does not initiate any round-trips.
*
*/
uint32_t get_mod_mask_for(uint32_t keysym,
xcb_key_symbols_t *symbols,
xcb_get_modifier_mapping_reply_t *modmap_reply);
/**
* Loads a font for usage, also getting its height. If fallback is true,
* the fonts 'fixed' or '-misc-*' will be loaded instead of exiting.
*
*/
i3Font load_font(const char *pattern, bool fallback);
#endif

View File

@ -1,3 +1,13 @@
/*
* vim:ts=4:sw=4:expandtab
*
* i3 - an improved dynamic tiling window manager
* © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
*
* load_layout.c: Restore (parts of) the layout, for example after an inplace
* restart.
*
*/
#ifndef _LOAD_LAYOUT_H
#define _LOAD_LAYOUT_H

View File

@ -2,10 +2,9 @@
* vim:ts=4:sw=4:expandtab
*
* i3 - an improved dynamic tiling window manager
* © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
*
* © 2009-2011 Michael Stapelberg and contributors
*
* See file LICENSE for license information.
* log.c: Setting of loglevels, logging functions.
*
*/
#ifndef _LOG_H

View File

@ -1,19 +1,17 @@
/*
* vim:ts=8:expandtab
* vim:ts=4:sw=4:expandtab
*
* i3 - an improved dynamic tiling window manager
* © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
*
* © 2009 Michael Stapelberg and contributors
*
* See file LICENSE for license information.
* manage.c: Initially managing new windows (or existing ones on restart).
*
*/
#include "data.h"
#ifndef _MANAGE_H
#define _MANAGE_H
#include "data.h"
/**
* Go through all existing windows (if the window manager is restarted) and
* manage them

View File

@ -1,3 +1,16 @@
/*
* vim:ts=4:sw=4:expandtab
*
* i3 - an improved dynamic tiling window manager
* © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
*
* A "match" is a data structure which acts like a mask or expression to match
* certain windows or not. For example, when using commands, you can specify a
* command like this: [title="*Firefox*"] kill. The title member of the match
* data structure will then be filled and i3 will check each window using
* match_matches_window() to find the windows affected by this command.
*
*/
#ifndef _MATCH_H
#define _MATCH_H
@ -28,4 +41,10 @@ void match_copy(Match *dest, Match *src);
*/
bool match_matches_window(Match *match, i3Window *window);
/**
* Frees the given match. It must not be used afterwards!
*
*/
void match_free(Match *match);
#endif

View File

@ -1,7 +1,12 @@
/*
* vim:ts=4:sw=4:expandtab
*
* i3 - an improved dynamic tiling window manager
* © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
*
* move.c: Moving containers into some direction.
*
*/
#ifndef _MOVE_H
#define _MOVE_H

View File

@ -1,7 +1,12 @@
/*
* vim:ts=4:sw=4:expandtab
*
* i3 - an improved dynamic tiling window manager
* © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
*
* output.c: Output (monitor) related functions.
*
*/
#ifndef _OUTPUT_H
#define _OUTPUT_H

View File

@ -1,19 +1,20 @@
/*
* vim:ts=8:expandtab
* vim:ts=4:sw=4:expandtab
*
* i3 - an improved dynamic tiling window manager
* © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
*
* © 2009-2010 Michael Stapelberg and contributors
*
* See file LICENSE for license information.
* For more information on RandR, please see the X.org RandR specification at
* http://cgit.freedesktop.org/xorg/proto/randrproto/tree/randrproto.txt
* (take your time to read it completely, it answers all questions).
*
*/
#include "data.h"
#include <xcb/randr.h>
#ifndef _RANDR_H
#define _RANDR_H
#include "data.h"
#include <xcb/randr.h>
TAILQ_HEAD(outputs_head, xoutput);
extern struct outputs_head outputs;

39
include/regex.h Normal file
View File

@ -0,0 +1,39 @@
/*
* vim:ts=4:sw=4:expandtab
*
* i3 - an improved dynamic tiling window manager
* © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
*
* regex.c: Interface to libPCRE (perl compatible regular expressions).
*
*/
#ifndef _REGEX_H
#define _REGEX_H
/**
* Creates a new 'regex' struct containing the given pattern and a PCRE
* compiled regular expression. Also, calls pcre_study because this regex will
* most likely be used often (like for every new window and on every relevant
* property change of existing windows).
*
* Returns NULL if the pattern could not be compiled into a regular expression
* (and ELOGs an appropriate error message).
*
*/
struct regex *regex_new(const char *pattern);
/**
* Frees the given regular expression. It must not be used afterwards!
*
*/
void regex_free(struct regex *regex);
/**
* Checks if the given regular expression matches the given input and returns
* true if it does. In either case, it logs the outcome using LOG(), so it will
* be visible without any debug loglevel.
*
*/
bool regex_matches(struct regex *regex, const char *input);
#endif

View File

@ -1,7 +1,13 @@
/*
* vim:ts=4:sw=4:expandtab
*
* i3 - an improved dynamic tiling window manager
* © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
*
* render.c: Renders (determines position/sizes) the layout tree, updating the
* various rects. Needs to be pushed to X11 (see x.c) to be visible.
*
*/
#ifndef _RENDER_H
#define _RENDER_H

Some files were not shown because too many files have changed in this diff Show More