From: Michael Stapelberg Date: Fri, 11 Nov 2011 22:49:20 +0000 (+0000) Subject: Merge branch 'next' X-Git-Tag: 4.1.1~36 X-Git-Url: https://git.sur5r.net/?p=i3%2Fi3;a=commitdiff_plain;h=0adbffb38621192c416ac52aa6b82ac57fb6394d;hp=f4877773c39c5d254ba8efedfe3c39641ee8bb95 Merge branch 'next' --- diff --git a/.gitignore b/.gitignore index 454b2e3a..cad6ad9a 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/CMDMODE b/CMDMODE deleted file mode 100644 index 95cb5bc1..00000000 --- a/CMDMODE +++ /dev/null @@ -1,47 +0,0 @@ ---------------------- -- Command mode ---------------------- - -This is the grammar for the 'command mode' (your configuration file -uses these commands, too). - -left := | -right := | -up := | -down := | - -where := | -move := -snap := - -cmd := [ ] [ | ] -with := { [ ] }+ -jump := [ "[/]" | [ ] ] -focus := focus [ | floating | tiling | ft ] - (travels the focus stack backwards, 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 | kill | exit | restart ] - -input := [ | | | | ] - -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 diff --git a/DEPENDS b/DEPENDS index ea7133a5..61fb9586 100644 --- a/DEPENDS +++ b/DEPENDS @@ -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 distribution’s 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. diff --git a/LICENSE b/LICENSE index 5771597b..05f078e2 100644 --- a/LICENSE +++ b/LICENSE @@ -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 diff --git a/Makefile b/Makefile index 15ccf0e6..c0797839 100644 --- a/Makefile +++ b/Makefile @@ -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 \ diff --git a/PACKAGE-MAINTAINER b/PACKAGE-MAINTAINER index 3d9a8e18..269ce0fd 100644 --- a/PACKAGE-MAINTAINER +++ b/PACKAGE-MAINTAINER @@ -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 diff --git a/RELEASE-NOTES-4.1 b/RELEASE-NOTES-4.1 new file mode 100644 index 00000000..de06c3ab --- /dev/null +++ b/RELEASE-NOTES-4.1 @@ -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 don’t 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: Don’t 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: Don’t leak the error logfile file descriptor + • Bugfix: Don’t 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: Don’t 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 diff --git a/TODO b/TODO deleted file mode 100644 index 40b56ce3..00000000 --- a/TODO +++ /dev/null @@ -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 diff --git a/common.mk b/common.mk index ce41f287..a9d16618 100644 --- a/common.mk +++ b/common.mk @@ -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,27 +56,35 @@ 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 += $(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) -LIBS += $(call ldflags_for_lib, xcb-atom, xcb-atom) -LIBS += $(call ldflags_for_lib, xcb-aux, xcb-aux) +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 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 LIBS += $(call ldflags_for_lib, xcb-util) endif -LIBS += $(call ldflags_for_lib, xcb-icccm, xcb-icccm) -LIBS += $(call ldflags_for_lib, xcb-xinerama, xcb-xinerama) -LIBS += $(call ldflags_for_lib, xcb-randr, xcb-randr) -LIBS += $(call ldflags_for_lib, xcb, xcb) -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, xcb-icccm,xcb-icccm) +LIBS += $(call ldflags_for_lib, xcb-xinerama,xcb-xinerama) +LIBS += $(call ldflags_for_lib, xcb-randr,xcb-randr) +LIBS += $(call ldflags_for_lib, xcb,xcb) +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) diff --git a/debian/changelog b/debian/changelog index 990badb2..be459af5 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,8 +1,60 @@ -i3-wm (4.0.3-0) unstable; urgency=low - - * NOT YET RELEASED! - - -- Michael Stapelberg Sun, 28 Aug 2011 20:17:31 +0200 +i3-wm (4.1-1) unstable; urgency=low + + * 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: Don’t 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: Don’t leak the error logfile file descriptor + * Bugfix: Don’t 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: Don’t 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 Fri, 11 Nov 2011 21:28:15 +0000 i3-wm (4.0.2-1) unstable; urgency=low diff --git a/debian/compat b/debian/compat index 1e8b3149..7f8f011e 100644 --- a/debian/compat +++ b/debian/compat @@ -1 +1 @@ -6 +7 diff --git a/debian/control b/debian/control index b546e650..e3786cfb 100644 --- a/debian/control +++ b/debian/control @@ -3,7 +3,7 @@ Section: utils Priority: extra Maintainer: Michael Stapelberg 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. diff --git a/debian/i3-wm.docs b/debian/i3-wm.docs index d59c5736..e5896855 100644 --- a/debian/i3-wm.docs +++ b/debian/i3-wm.docs @@ -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 diff --git a/debian/i3-wm.manpages b/debian/i3-wm.manpages new file mode 100644 index 00000000..2de3a995 --- /dev/null +++ b/debian/i3-wm.manpages @@ -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 diff --git a/debian/patches/manpage-x-terminal-emulator.patch b/debian/patches/manpage-x-terminal-emulator.patch new file mode 100644 index 00000000..61ff0160 --- /dev/null +++ b/debian/patches/manpage-x-terminal-emulator.patch @@ -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 diff --git a/debian/patches/series b/debian/patches/series new file mode 100644 index 00000000..08d60ae0 --- /dev/null +++ b/debian/patches/series @@ -0,0 +1,2 @@ +use-x-terminal-emulator.patch +manpage-x-terminal-emulator.patch diff --git a/debian/patches/use-x-terminal-emulator.patch b/debian/patches/use-x-terminal-emulator.patch new file mode 100644 index 00000000..fd515c16 --- /dev/null +++ b/debian/patches/use-x-terminal-emulator.patch @@ -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 "$@" diff --git a/debian/rules b/debian/rules index e62dd5ee..a488469d 100755 --- a/debian/rules +++ b/debian/rules @@ -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 - $(MAKE) -C man - $(MAKE) -C docs +clean: + dh clean - touch $@ +install: build install-stamp +install-stamp: + dh install + touch install-stamp -clean: - dh_testdir - dh_testroot - rm -f build-stamp +binary-arch: install + dh binary-arch - # Add here commands to clean up after the build process. - [ ! -f Makefile ] || $(MAKE) distclean +binary-indep: install + dh binary-indep - dh_clean +binary: binary-arch binary-indep -install: build - dh_testdir - dh_testroot - dh_clean -k - dh_installdirs +override_dh_auto_build: + $(MAKE) + $(MAKE) -C man + $(MAKE) -C docs - # 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 diff --git a/docs/Makefile b/docs/Makefile index 9d70243d..d1e0768a 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -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 diff --git a/docs/asciidoc-git.conf b/docs/asciidoc-git.conf new file mode 100644 index 00000000..24dcb596 --- /dev/null +++ b/docs/asciidoc-git.conf @@ -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
+ +[replacements] +ifdef::asciidoc7compatible[] +# Superscripts. +\^(.+?)\^=\1 +# Subscripts. +~(.+?)~=\1 +endif::asciidoc7compatible[] + +[ruler-blockmacro] +
+ +[pagebreak-blockmacro] +
+ +[blockdef-pass] +asciimath-style=template="asciimathblock",subs=[] +latexmath-style=template="latexmathblock",subs=[] + +[macros] +# math macros. +# Special characters are escaped in HTML math markup. +(?su)[\\]?(?Pasciimath|latexmath):(?P\S*?)\[(?P.*?)(?asciimath|latexmath)::(?P\S*?)(\[(?P.*?)\])$=#[specialcharacters] + +[asciimath-inlinemacro] +`{passtext}` + +[asciimath-blockmacro] +
+
+
{title}
+`{passtext}` +
+ +[asciimathblock] +
+
+
{title}
+`|` +
+ +[latexmath-inlinemacro] +{passtext} + +[latexmath-blockmacro] +
+
+
{title}
+{passtext} +
+ +[latexmathblock] +
+
+
{title}
+| +
+ +[image-inlinemacro] + + +{data-uri%}{alt={target}} +{data-uri#}{alt={target}} +{link#} + + +[image-blockmacro] +
+ +
{caption={figure-caption} {counter:figure-number}. }{title}
+
+ +[unfloat-blockmacro] +
+ +[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:[]. +
[{0}]
+ +[footnoteref-inlinemacro] +# footnoteref:[], create reference to footnote. +{2%}
[{1}]
+# footnoteref:[,], create footnote with ID. +{2#}
[{2}]
+ +[callout-inlinemacro] +ifndef::icons[] +<{index}> +endif::icons[] +ifdef::icons[] +ifndef::data-uri[] +{index} +endif::data-uri[] +ifdef::data-uri[] +{index} +endif::data-uri[] +endif::icons[] + +# Comment line macros. +[comment-inlinemacro] +{showcomments#}
{passtext}
+ +[comment-blockmacro] +{showcomments#}

{passtext}

+ +[literal-inlinemacro] +# Inline literal. +{passtext} + +# List tags. +[listtags-bulleted] +list=
{title?
{title}
}
    |
+item=
  • |
  • +text=

    |

    + +[listtags-numbered] +# The start attribute is not valid XHTML 1.1 but all browsers support it. +list=
    {title?
    {title}
    }
      |
    +item=
  • |
  • +text=

    |

    + +[listtags-labeled] +list=
    {title?
    {title}
    }
    |
    +entry= +label= +term=
    |
    +item=
    |
    +text=

    |

    + +[listtags-horizontal] +list=
    {title?
    {title}
    }{labelwidth?}{itemwidth?}|
    +label=| +term=|
    +entry=| +item=| +text=

    |

    + +[listtags-qanda] +list=
    {title?
    {title}
    }
      |
    +entry=
  • |
  • +label= +term=

    |

    +item= +text=

    |

    + +[listtags-callout] +ifndef::icons[] +list=
    {title?
    {title}
    }
      |
    +item=
  • |
  • +text=

    |

    +endif::icons[] +ifdef::icons[] +list=
    {title?
    {title}
    }|
    +ifndef::data-uri[] +item={listindex}| +endif::data-uri[] +ifdef::data-uri[] +item={listindex}| +endif::data-uri[] +text=| +endif::icons[] + +[listtags-glossary] +list=
    {title?
    {title}
    }
    |
    +label= +entry= +term=
    |
    +item=
    |
    +text=

    |

    + +[listtags-bibliography] +list=
    {title?
    {title}
    }
      |
    +item=
  • |
  • +text=

    |

    + +[tags] +# Quoted text. +emphasis={1?}|{1?} +strong={1?}|{1?} +monospaced={1?}|{1?} +singlequoted={lsquo}{1?}|{1?}{rsquo} +doublequoted={ldquo}{1?}|{1?}{rdquo} +unquoted={1?}|{1?} +superscript={1?}|{1?} +subscript={1?}|{1?} + +ifdef::deprecated-quotes[] +# Override with deprecated quote attributes. +emphasis={role?}|{role?} +strong={role?}|{role?} +monospaced={role?}|{role?} +singlequoted={role?}{1,2,3?}{amp}#8216;|{amp}#8217;{1,2,3?}{role?} +doublequoted={role?}{1,2,3?}{amp}#8220;|{amp}#8221;{1,2,3?}{role?} +unquoted={role?}{1,2,3?}|{1,2,3?}{role?} +superscript={role?}|{role?} +subscript={role?}|{role?} +endif::deprecated-quotes[] + +# Inline macros +[http-inlinemacro] +{0={name}:{target}} +[https-inlinemacro] +{0={name}:{target}} +[ftp-inlinemacro] +{0={name}:{target}} +[file-inlinemacro] +{0={name}:{target}} +[irc-inlinemacro] +{0={name}:{target}} +[mailto-inlinemacro] +{0={target}} +[link-inlinemacro] +{0={target}} +[callto-inlinemacro] +{0={target}} +# anchor:id[text] +[anchor-inlinemacro] + +# [[id,text]] +[anchor2-inlinemacro] + +# [[[id]]] +[anchor3-inlinemacro] +[{1}] +# xref:id[text] +[xref-inlinemacro] +{0=[{target}]} +# <> +[xref2-inlinemacro] +{2=[{1}]} + +# Special word substitution. +[emphasizedwords] +{words} +[monospacedwords] +{words} +[strongwords] +{words} + +# Paragraph substitution. +[paragraph] +
    {title?
    {title}
    }

    +| +

    + +[admonitionparagraph] +template::[admonitionblock] + +# Delimited blocks. +[listingblock] +
    +
    {caption=}{title}
    +
    +
    
    +|
    +
    +
    + +[literalblock] +
    +
    {title}
    +
    +
    
    +|
    +
    +
    + +[sidebarblock] +
    +
    +
    {title}
    +| +
    + +[openblock] +
    +
    {title}
    +
    +| +
    + +[partintroblock] +template::[openblock] + +[abstractblock] +template::[quoteblock] + +[quoteblock] +
    +
    {title}
    +
    +| +
    +
    +{citetitle}{attribution?
    } +— {attribution} +
    + +[verseblock] +
    +
    {title}
    +
    +|
    +
    +
    +{citetitle}{attribution?
    } +— {attribution} +
    + +[exampleblock] +
    +
    {caption={example-caption} {counter:example-number}. }{title}
    +
    +| +
    + +[admonitionblock] +
    + + + +
    +{data-uri%}{icons#}{caption} +{data-uri#}{icons#}{caption} +{icons%}
    {caption}
    +
    +
    {title}
    +| +
    +
    + +# Tables. +[tabletags-default] +colspec= +bodyrow=| +headdata=| +bodydata=| +paragraph=

    |

    + +[tabletags-header] +paragraph=

    |

    + +[tabletags-emphasis] +paragraph=

    |

    + +[tabletags-strong] +paragraph=

    |

    + +[tabletags-monospaced] +paragraph=

    |

    + +[tabletags-verse] +bodydata=
    |
    +paragraph= + +[tabletags-literal] +bodydata=
    |
    +paragraph= + +[tabletags-asciidoc] +bodydata=
    |
    +paragraph= + +[table] +
    + + +{colspecs} +{headrows#} +{headrows} +{headrows#} +{footrows#} +{footrows} +{footrows#} + +{bodyrows} + +
    {caption={table-caption} {counter:table-number}. }{title}
    +
    + +#-------------------------------------------------------------------- +# Deprecated old table definitions. +# + +[miscellaneous] +# Screen width in pixels. +pagewidth=800 +pageunits= + +[old_tabledef-default] +template=old_table +colspec= +bodyrow=| +headdata=| +footdata=| +bodydata=| + +[old_table] +
    + + +{colspecs} +{headrows#} +{headrows} +{headrows#} +{footrows#} +{footrows} +{footrows#} + +{bodyrows} + +
    {caption={table-caption}}{title}
    +
    + +# End of deprecated old table definitions. +#-------------------------------------------------------------------- + +[floatingtitle] +{title} + +[preamble] +# Untitled elements between header and first section title. +
    +
    +| +
    +
    + +# Document sections. +[sect0] +{title} +| + +[sect1] +
    +{numbered?{sectnum} }{title} +
    +| +
    +
    + +[sect2] +
    +{numbered?{sectnum} }{title} +| +
    + +[sect3] +
    +{numbered?{sectnum} }{title} +| +
    + +[sect4] +
    +{title} +| +
    + +[appendix] +
    +{numbered?{sectnum} }{appendix-caption} {counter:appendix-number:A}: {title} +
    +| +
    +
    + +[toc] +
    +
    {toc-title}
    + +
    + +[header] + + + + + + + + +i3: {title} +{title%}i3: {doctitle=} + +ifdef::linkcss[] + +{doctype-manpage} +ifdef::quirks[] + +endif::quirks[] + +ifdef::pygments[] +endif::linkcss[] +ifndef::linkcss[] + +endif::linkcss[] +ifndef::disable-javascript[] +ifdef::linkcss[] + + +endif::linkcss[] +ifndef::linkcss[] + +endif::linkcss[] +endif::disable-javascript[] +ifdef::asciimath[] +ifdef::linkcss[] + +endif::linkcss[] +ifndef::linkcss[] + +endif::linkcss[] +endif::asciimath[] +ifdef::latexmath[] +ifdef::linkcss[] + +endif::linkcss[] +ifndef::linkcss[] + +endif::linkcss[] +endif::latexmath[] +{docinfo1,docinfo2#}{include:{docdir}/docinfo.html} +{docinfo,docinfo2#}{include:{docdir}/{docname}-docinfo.html} + + + +
    +

    i3 - improved tiling WM

    + +
    +
    +# Article, book header. +ifndef::doctype-manpage[] + +endif::doctype-manpage[] +# Man page header. +ifdef::doctype-manpage[] + +endif::doctype-manpage[] + +[footer] +
    +{disable-javascript%

    } + + + + +ifdef::doctype-manpage[] +[synopsis] +template::[sect1] +endif::doctype-manpage[] + +ifdef::quirks[] +include::{backend}-quirks.conf[] +endif::quirks[] diff --git a/docs/i3-sync-working.dia b/docs/i3-sync-working.dia new file mode 100644 index 00000000..9f1c3bc8 Binary files /dev/null and b/docs/i3-sync-working.dia differ diff --git a/docs/i3-sync-working.png b/docs/i3-sync-working.png new file mode 100644 index 00000000..dce44ac5 Binary files /dev/null and b/docs/i3-sync-working.png differ diff --git a/docs/i3-sync.dia b/docs/i3-sync.dia new file mode 100644 index 00000000..0945ae26 Binary files /dev/null and b/docs/i3-sync.dia differ diff --git a/docs/i3-sync.png b/docs/i3-sync.png new file mode 100644 index 00000000..b64cce25 Binary files /dev/null and b/docs/i3-sync.png differ diff --git a/docs/ipc b/docs/ipc index 7e713260..fc46590e 100644 --- a/docs/ipc +++ b/docs/ipc @@ -1,7 +1,7 @@ IPC interface (interprocess communication) ========================================== Michael Stapelberg -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 diff --git a/docs/multi-monitor b/docs/multi-monitor index ec0256c0..a1fd6dc0 100644 --- a/docs/multi-monitor +++ b/docs/multi-monitor @@ -1,7 +1,7 @@ The multi-monitor situation =========================== Michael Stapelberg -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 diff --git a/docs/testsuite b/docs/testsuite new file mode 100644 index 00000000..720ff394 --- /dev/null +++ b/docs/testsuite @@ -0,0 +1,540 @@ +i3 testsuite +============ +Michael Stapelberg +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 <> 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 User’s 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 let’s 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? Let’s 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 can’t + 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 parent’s 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. diff --git a/docs/userguide b/docs/userguide index a8317d04..3d78d16f 100644 --- a/docs/userguide +++ b/docs/userguide @@ -1,7 +1,7 @@ i3 User’s Guide =============== Michael Stapelberg -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 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 <>. 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), you’d 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 [→] 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 window’s 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 <>. + [[workspace_screen]] === Automatically putting workspaces on specific screens @@ -541,17 +569,20 @@ the second screen and so on). *Syntax*: ---------------------------------- -workspace output +workspace 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 force_focus_wrapping yes ------------------------ +=== Forcing Xinerama + +As explained in-depth in , 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 don’t provide support for +reconfiguring your screens on the fly (they are read only once on startup and +that’s it). + +For people who do cannot modify their +~/.xsession+ to add the ++--force-xinerama+ commandline parameter, a configuration option is provided: + +*Syntax*: +----------------------- +force_xinerama +----------------------- + +*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 +<>) 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 don’t 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 +-------------------------------------- + +*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 don’t 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 + don’t 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 +---------------- + +*Example*: +---------------- +mode hide +---------------- + +=== Position + +This option determines in which edge of the screen i3bar should show up. + +The default is bottom. + +*Syntax*: +--------------------- +position +--------------------- + +*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 +--------------- + +*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 +------------------------- + +*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 +--------------------- + +*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 +-------------------------- + +*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 + statusline + + colorclass +} +---------------------------------------- + +*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 can’t 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 +focus +move [ 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 [ px] [or 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+: diff --git a/i3-config-wizard/Makefile b/i3-config-wizard/Makefile index 43c3a1ff..27d5bf54 100644 --- a/i3-config-wizard/Makefile +++ b/i3-config-wizard/Makefile @@ -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/ diff --git a/i3-config-wizard/cfgparse.y b/i3-config-wizard/cfgparse.y index 018b37b2..bbe11937 100644 --- a/i3-config-wizard/cfgparse.y +++ b/i3-config-wizard/cfgparse.y @@ -14,6 +14,8 @@ #include +#include "libi3.h" + extern Display *dpy; struct context { @@ -141,7 +143,7 @@ bindcode: char *str = XKeysymToString(sym); char *modifiers = modifier_to_string($3); // TODO: modifier to string - asprintf(&(context->result), "bindsym %s%s %s\n", modifiers, str, $6); + sasprintf(&(context->result), "bindsym %s%s %s\n", modifiers, str, $6); free(modifiers); } ; diff --git a/i3-config-wizard/ipc.c b/i3-config-wizard/ipc.c deleted file mode 100644 index 597a86ef..00000000 --- a/i3-config-wizard/ipc.c +++ /dev/null @@ -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 -#include -#include -#include -#include -#include -#include - -/* - * 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; -} diff --git a/i3-config-wizard/ipc.h b/i3-config-wizard/ipc.h deleted file mode 100644 index c40c909d..00000000 --- a/i3-config-wizard/ipc.h +++ /dev/null @@ -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 diff --git a/i3-config-wizard/main.c b/i3-config-wizard/main.c index da1f76a3..cdce0653 100644 --- a/i3-config-wizard/main.c +++ b/i3-config-wizard/main.c @@ -2,13 +2,10 @@ * 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. + * keysyms. * */ #include @@ -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 doesn’t work. - * As i3-msg is a short-running tool, we don’t 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, ""); /* 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, ""); } 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, ""); /* 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, ""); else txt(31, 5, ""); /* 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, ""); /* 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, ""); } @@ -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); - - symbols = xcb_key_symbols_alloc(conn); + xcb_numlock_mask = get_mod_mask_for(XCB_NUM_LOCK, symbols, modmap_reply); - 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) \ diff --git a/i3-config-wizard/xcb.c b/i3-config-wizard/xcb.c deleted file mode 100644 index 461dfd52..00000000 --- a/i3-config-wizard/xcb.c +++ /dev/null @@ -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 -#include -#include -#include -#include - -#include -#include - -#include - -#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); -} - diff --git a/i3-config-wizard/xcb.h b/i3-config-wizard/xcb.h index 40aeec88..4ed182c4 100644 --- a/i3-config-wizard/xcb.h +++ b/i3-config-wizard/xcb.h @@ -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 diff --git a/i3-input/Makefile b/i3-input/Makefile index 45653dad..493df784 100644 --- a/i3-input/Makefile +++ b/i3-input/Makefile @@ -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/ diff --git a/i3-input/i3-input.h b/i3-input/i3-input.h index 581203d4..d97807d1 100644 --- a/i3-input/i3-input.h +++ b/i3-input/i3-input.h @@ -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 diff --git a/i3-input/ipc.c b/i3-input/ipc.c deleted file mode 100644 index 2d11f0e0..00000000 --- a/i3-input/ipc.c +++ /dev/null @@ -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 -#include -#include -#include -#include -#include -#include - -/* - * 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; -} diff --git a/i3-input/main.c b/i3-input/main.c index fb2635a2..def68481 100644 --- a/i3-input/main.c +++ b/i3-input/main.c @@ -1,14 +1,11 @@ /* - * 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. + * to i3. * */ #include @@ -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 doesn’t work. - * As i3-msg is a short-running tool, we don’t 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; -} +xcb_connection_t *conn; /* * Concats the glyphs (either UCS-2 or UTF-8) to a single string, suitable for @@ -96,21 +61,21 @@ static char *socket_path_from_x11() { * */ static uint8_t *concat_strings(char **glyphs, int max) { - uint8_t *output = calloc(max+1, 4); - uint8_t *walk = output; - for (int c = 0; c < max; c++) { - printf("at %c\n", glyphs[c][0]); - /* if the first byte is 0, this has to be UCS2 */ - if (glyphs[c][0] == '\0') { - memcpy(walk, glyphs[c], 2); - walk += 2; - } else { - strcpy((char*)walk, glyphs[c]); - walk += strlen(glyphs[c]); - } + uint8_t *output = calloc(max+1, 4); + uint8_t *walk = output; + for (int c = 0; c < max; c++) { + printf("at %c\n", glyphs[c][0]); + /* if the first byte is 0, this has to be UCS2 */ + if (glyphs[c][0] == '\0') { + memcpy(walk, glyphs[c], 2); + walk += 2; + } else { + strcpy((char*)walk, glyphs[c]); + walk += strlen(glyphs[c]); } - printf("output = %s\n", output); - return output; + } + printf("output = %s\n", output); + return output; } /* @@ -119,37 +84,37 @@ static uint8_t *concat_strings(char **glyphs, int max) { * */ static int handle_expose(void *data, xcb_connection_t *conn, xcb_expose_event_t *event) { - 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_poly_fill_rectangle(conn, pixmap, pixmap_gc, 1, &border); - xcb_change_gc_single(conn, pixmap_gc, XCB_GC_FOREGROUND, get_colorpixel(conn, "#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")); - uint8_t *con = concat_strings(glyphs_ucs, input_position); - char *full_text = (char*)con; - if (prompt != NULL) { - full_text = malloc((prompt_len + input_position) * 2 + 1); - if (full_text == NULL) - err(EXIT_FAILURE, "malloc() failed\n"); - memcpy(full_text, prompt, prompt_len * 2); - 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); - - /* 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_flush(conn); - free(con); - if (prompt != NULL) - free(full_text); - - return 1; + 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(conn, pixmap_gc, XCB_GC_FOREGROUND, (uint32_t[]){ get_colorpixel("#FF0000") }); + xcb_poly_fill_rectangle(conn, pixmap, pixmap_gc, 1, &border); + 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(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) { + full_text = malloc((prompt_len + input_position) * 2 + 1); + if (full_text == NULL) + err(EXIT_FAILURE, "malloc() failed\n"); + memcpy(full_text, prompt, prompt_len * 2); + 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); + + /* 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_flush(conn); + free(con); + if (prompt != NULL) + free(full_text); + + return 1; } /* @@ -157,37 +122,69 @@ 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); + 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); - xcb_keysym_t sym = xcb_key_press_lookup_keysym(symbols, event, event->state); - if (sym == XK_Mode_switch) { - printf("Mode switch disabled\n"); - modeswitch_active = false; - } + /* If modeswitch is currently active, we need to look in group 2 or 3, + * respectively. */ + if (modeswitch_active) + col += 2; - return 1; + xcb_keysym_t sym = xcb_key_press_lookup_keysym(symbols, event, event->state); + if (sym == XK_Mode_switch) { + printf("Mode switch disabled\n"); + modeswitch_active = false; + } + + return 1; } 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"); + char *command = (char*)concat_strings(glyphs_utf8, input_position); + + /* 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++; } - printf("command = %s\n", full_command); + } + + /* prefix the command if a prefix was specified on commandline */ + printf("command = %s\n", full); - ipc_send_message(sockfd, strlen(full_command), 0, (uint8_t*)full_command); + ipc_send_message(sockfd, strlen(full), 0, (uint8_t*)full); #if 0 - free(command); - return 1; + free(command); + return 1; #endif - exit(0); + exit(0); } /* @@ -200,224 +197,254 @@ 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 */ - if (modeswitch_active) - event->state |= modeswitchmask; - - /* 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); - if (sym == XK_Mode_switch) { - printf("Mode switch enabled\n"); - modeswitch_active = true; - return 1; - } - - if (sym == XK_Return) - finish_input(); - - if (sym == XK_BackSpace) { - if (input_position == 0) - return 1; - - input_position--; - free(glyphs_ucs[input_position]); - free(glyphs_utf8[input_position]); - - handle_expose(NULL, conn, NULL); - return 1; - } - if (sym == XK_Escape) { - exit(0); - } - - /* TODO: handle all of these? */ - printf("is_keypad_key = %d\n", xcb_is_keypad_key(sym)); - printf("is_private_keypad_key = %d\n", xcb_is_private_keypad_key(sym)); - printf("xcb_is_cursor_key = %d\n", xcb_is_cursor_key(sym)); - printf("xcb_is_pf_key = %d\n", xcb_is_pf_key(sym)); - printf("xcb_is_function_key = %d\n", xcb_is_function_key(sym)); - printf("xcb_is_misc_function_key = %d\n", xcb_is_misc_function_key(sym)); - printf("xcb_is_modifier_key = %d\n", xcb_is_modifier_key(sym)); - - if (xcb_is_modifier_key(sym) || xcb_is_cursor_key(sym)) - return 1; - - printf("sym = %c (%d)\n", sym, sym); - - /* convert the keysym to UCS */ - uint16_t ucs = keysym2ucs(sym); - if ((int16_t)ucs == -1) { - fprintf(stderr, "Keysym could not be converted to UCS, skipping\n"); - return 1; - } - - /* store the UCS into a string */ - uint8_t inp[3] = {(ucs & 0xFF00) >> 8, (ucs & 0xFF), 0}; + printf("Keypress %d, state raw = %d\n", event->detail, event->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) + col += 2; + + 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; + return 1; + } - printf("inp[0] = %02x, inp[1] = %02x, inp[2] = %02x\n", inp[0], inp[1], inp[2]); - /* convert it to UTF-8 */ - char *out = convert_ucs_to_utf8((char*)inp); - printf("converted to %s\n", out); + if (sym == XK_Return) + finish_input(); - glyphs_ucs[input_position] = malloc(3 * sizeof(uint8_t)); - if (glyphs_ucs[input_position] == NULL) - err(EXIT_FAILURE, "malloc() failed\n"); - memcpy(glyphs_ucs[input_position], inp, 3); - glyphs_utf8[input_position] = strdup(out); - input_position++; + if (sym == XK_BackSpace) { + if (input_position == 0) + return 1; - if (input_position == limit) - finish_input(); + input_position--; + free(glyphs_ucs[input_position]); + free(glyphs_utf8[input_position]); handle_expose(NULL, conn, NULL); return 1; -} - -int main(int argc, char *argv[]) { - socket_path = getenv("I3SOCK"); - char *pattern = "-misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1"; - int o, option_index = 0; - - static struct option long_options[] = { - {"socket", required_argument, 0, 's'}, - {"version", no_argument, 0, 'v'}, - {"limit", required_argument, 0, 'l'}, - {"prompt", required_argument, 0, 'P'}, - {"prefix", required_argument, 0, 'p'}, - {"font", required_argument, 0, 'f'}, - {"help", no_argument, 0, 'h'}, - {0, 0, 0, 0} - }; - - char *options_string = "s:p:P:f:l:vh"; - - while ((o = getopt_long(argc, argv, options_string, long_options, &option_index)) != -1) { - switch (o) { - case 's': - FREE(socket_path); - socket_path = strdup(optarg); - break; - case 'v': - printf("i3-input " I3_VERSION); - return 0; - case 'p': - FREE(command_prefix); - command_prefix = strdup(optarg); - break; - case 'l': - limit = atoi(optarg); - break; - case 'P': - FREE(prompt); - prompt = strdup(optarg); - break; - case 'f': - FREE(pattern); - pattern = strdup(optarg); - break; - case 'h': - printf("i3-input " I3_VERSION); - printf("i3-input [-s ] [-p ] [-l ] [-P ] [-f ] [-v]\n"); - return 0; - } - } - - 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); - - 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)) - 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); + } + if (sym == XK_Escape) { + exit(0); + } + + /* TODO: handle all of these? */ + printf("is_keypad_key = %d\n", xcb_is_keypad_key(sym)); + printf("is_private_keypad_key = %d\n", xcb_is_private_keypad_key(sym)); + printf("xcb_is_cursor_key = %d\n", xcb_is_cursor_key(sym)); + printf("xcb_is_pf_key = %d\n", xcb_is_pf_key(sym)); + printf("xcb_is_function_key = %d\n", xcb_is_function_key(sym)); + printf("xcb_is_misc_function_key = %d\n", xcb_is_misc_function_key(sym)); + printf("xcb_is_modifier_key = %d\n", xcb_is_modifier_key(sym)); + + if (xcb_is_modifier_key(sym) || xcb_is_cursor_key(sym)) + return 1; - uint32_t font_id = get_font_id(conn, pattern, &font_height); + printf("sym = %c (%d)\n", sym, sym); - /* Open an input window */ - win = open_input_window(conn, 500, font_height + 8); + /* convert the keysym to UCS */ + uint16_t ucs = keysym2ucs(sym); + if ((int16_t)ucs == -1) { + fprintf(stderr, "Keysym could not be converted to UCS, skipping\n"); + return 1; + } - /* 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_gc(conn, pixmap_gc, pixmap, 0, 0); + /* store the UCS into a string */ + uint8_t inp[3] = {(ucs & 0xFF00) >> 8, (ucs & 0xFF), 0}; - /* Set input focus (we have override_redirect=1, so the wm will not do - * this for us) */ - xcb_set_input_focus(conn, XCB_INPUT_FOCUS_POINTER_ROOT, win, XCB_CURRENT_TIME); + printf("inp[0] = %02x, inp[1] = %02x, inp[2] = %02x\n", inp[0], inp[1], inp[2]); + /* convert it to UTF-8 */ + char *out = convert_ucs_to_utf8((char*)inp); + printf("converted to %s\n", out); - /* Create graphics context */ - xcb_change_gc_single(conn, pixmap_gc, XCB_GC_FONT, font_id); + glyphs_ucs[input_position] = malloc(3 * sizeof(uint8_t)); + if (glyphs_ucs[input_position] == NULL) + err(EXIT_FAILURE, "malloc() failed\n"); + memcpy(glyphs_ucs[input_position], inp, 3); + glyphs_utf8[input_position] = strdup(out); + input_position++; - /* Grab the keyboard to get all input */ - xcb_flush(conn); + if (input_position == limit) + finish_input(); - /* Try (repeatedly, if necessary) to grab the keyboard. We might not - * get the keyboard at the first attempt because of the keybinding - * still being active when started via a wm’s keybinding. */ - xcb_grab_keyboard_cookie_t cookie; - xcb_grab_keyboard_reply_t *reply = NULL; + handle_expose(NULL, conn, NULL); + return 1; +} - int count = 0; - while ((reply == NULL || reply->status != XCB_GRAB_STATUS_SUCCESS) && (count++ < 500)) { - cookie = xcb_grab_keyboard(conn, false, win, XCB_CURRENT_TIME, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC); - reply = xcb_grab_keyboard_reply(conn, cookie, NULL); - usleep(1000); +int main(int argc, char *argv[]) { + format = strdup("%s"); + socket_path = getenv("I3SOCK"); + 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[] = { + {"socket", required_argument, 0, 's'}, + {"version", no_argument, 0, 'v'}, + {"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:F:vh"; + + while ((o = getopt_long(argc, argv, options_string, long_options, &option_index)) != -1) { + switch (o) { + case 's': + FREE(socket_path); + socket_path = strdup(optarg); + break; + case 'v': + printf("i3-input " I3_VERSION); + return 0; + case 'p': + /* 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); + break; + case 'P': + FREE(prompt); + prompt = strdup(optarg); + break; + case 'f': + FREE(pattern); + pattern = strdup(optarg); + break; + case 'F': + FREE(format); + format = strdup(optarg); + break; + case 'h': + printf("i3-input " I3_VERSION "\n"); + printf("i3-input [-s ] [-F ] [-l ] [-P ] [-f ] [-v]\n"); + printf("\n"); + printf("Example:\n"); + printf(" i3-input -F 'workspace \"%%s\"' -P 'Switch to workspace: '\n"); + return 0; } - - if (reply->status != XCB_GRAB_STATUS_SUCCESS) { - fprintf(stderr, "Could not grab keyboard, status = %d\n", reply->status); - exit(-1); + } + + 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 = ipc_connect(socket_path); + + if (prompt != NULL) + prompt = convert_utf8_to_ucs2(prompt, &prompt_len); + + int screens; + 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; + + symbols = xcb_key_symbols_alloc(conn); + + font = load_font(pattern, true); + + /* Open an input window */ + 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: don’t 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_gc(conn, pixmap_gc, pixmap, 0, 0); + + /* Set input focus (we have override_redirect=1, so the wm will not do + * this for us) */ + xcb_set_input_focus(conn, XCB_INPUT_FOCUS_POINTER_ROOT, win, XCB_CURRENT_TIME); + + /* Create graphics context */ + xcb_change_gc(conn, pixmap_gc, XCB_GC_FONT, (uint32_t[]){ font.id }); + + /* Grab the keyboard to get all input */ + xcb_flush(conn); + + /* Try (repeatedly, if necessary) to grab the keyboard. We might not + * get the keyboard at the first attempt because of the keybinding + * still being active when started via a wm’s keybinding. */ + xcb_grab_keyboard_cookie_t cookie; + xcb_grab_keyboard_reply_t *reply = NULL; + + int count = 0; + while ((reply == NULL || reply->status != XCB_GRAB_STATUS_SUCCESS) && (count++ < 500)) { + cookie = xcb_grab_keyboard(conn, false, win, XCB_CURRENT_TIME, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC); + reply = xcb_grab_keyboard_reply(conn, cookie, NULL); + usleep(1000); + } + + if (reply->status != XCB_GRAB_STATUS_SUCCESS) { + fprintf(stderr, "Could not grab keyboard, status = %d\n", reply->status); + exit(-1); + } + + xcb_flush(conn); + + xcb_generic_event_t *event; + while ((event = xcb_wait_for_event(conn)) != NULL) { + if (event->response_type == 0) { + fprintf(stderr, "X11 Error received! sequence %x\n", event->sequence); + continue; } - xcb_flush(conn); - - xcb_generic_event_t *event; - while ((event = xcb_wait_for_event(conn)) != NULL) { - if (event->response_type == 0) { - fprintf(stderr, "X11 Error received! sequence %x\n", event->sequence); - continue; - } + /* Strip off the highest bit (set if the event is generated) */ + int type = (event->response_type & 0x7F); - /* Strip off the highest bit (set if the event is generated) */ - int type = (event->response_type & 0x7F); + switch (type) { + case XCB_KEY_PRESS: + handle_key_press(NULL, conn, (xcb_key_press_event_t*)event); + break; - switch (type) { - case XCB_KEY_PRESS: - handle_key_press(NULL, conn, (xcb_key_press_event_t*)event); - break; + case XCB_KEY_RELEASE: + handle_key_release(NULL, conn, (xcb_key_release_event_t*)event); + break; - case XCB_KEY_RELEASE: - handle_key_release(NULL, conn, (xcb_key_release_event_t*)event); - break; - - case XCB_EXPOSE: - handle_expose(NULL, conn, (xcb_expose_event_t*)event); - break; - } - - free(event); + case XCB_EXPOSE: + handle_expose(NULL, conn, (xcb_expose_event_t*)event); + break; } - return 0; + free(event); + } + + return 0; } diff --git a/i3-input/ucs2_to_utf8.c b/i3-input/ucs2_to_utf8.c index 4557c9da..df112eef 100644 --- a/i3-input/ucs2_to_utf8.c +++ b/i3-input/ucs2_to_utf8.c @@ -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 @@ -14,6 +14,8 @@ #include #include +#include "libi3.h" + static iconv_t conversion_descriptor = 0; static iconv_t conversion_descriptor2 = 0; @@ -23,37 +25,34 @@ static iconv_t conversion_descriptor2 = 0; * */ char *convert_ucs_to_utf8(char *input) { - size_t input_size = 2; - /* 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"); - size_t output_size = buffer_size; - /* We need to use an additional pointer, because iconv() modifies it */ - char *output = buffer; - - /* 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); - } - } - - /* Get the conversion descriptor back to original state */ - iconv(conversion_descriptor, NULL, NULL, NULL, NULL); - - /* Convert our text */ - int rc = iconv(conversion_descriptor, (void*)&input, &input_size, &output, &output_size); - if (rc == (size_t)-1) { - perror("Converting to UCS-2 failed"); - return NULL; - } - - return buffer; + size_t input_size = 2; + /* UTF-8 may consume up to 4 byte */ + int buffer_size = 8; + + 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; + + /* 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) + errx(EXIT_FAILURE, "Error opening the conversion context"); + } + + /* Get the conversion descriptor back to original state */ + iconv(conversion_descriptor, NULL, NULL, NULL, NULL); + + /* 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; + } + + return buffer; } /* @@ -64,41 +63,38 @@ char *convert_ucs_to_utf8(char *input) { * */ char *convert_utf8_to_ucs2(char *input, int *real_strlen) { - size_t input_size = strlen(input) + 1; - /* 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"); - size_t output_size = buffer_size; - /* We need to use an additional pointer, because iconv() modifies it */ - char *output = buffer; - - /* 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); - } - } - - /* Get the conversion descriptor back to original state */ - iconv(conversion_descriptor2, NULL, NULL, NULL, NULL); - - /* Convert our text */ - int rc = iconv(conversion_descriptor2, (void*)&input, &input_size, &output, &output_size); - if (rc == (size_t)-1) { - perror("Converting to UCS-2 failed"); - if (real_strlen != NULL) - *real_strlen = 0; - return NULL; - } + size_t input_size = strlen(input) + 1; + /* UCS-2 consumes exactly two bytes for each glyph */ + int buffer_size = input_size * 2; + + 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; + + /* 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) + errx(EXIT_FAILURE, "Error opening the conversion context"); + } + /* Get the conversion descriptor back to original state */ + iconv(conversion_descriptor2, NULL, NULL, NULL, NULL); + + /* Convert our text */ + 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 = ((buffer_size - output_size) / 2) - 1; + *real_strlen = 0; + return NULL; + } + + if (real_strlen != NULL) + *real_strlen = ((buffer_size - output_size) / 2) - 1; - return buffer; + return buffer; } diff --git a/i3-input/xcb.c b/i3-input/xcb.c deleted file mode 100644 index 3c1d99e1..00000000 --- a/i3-input/xcb.c +++ /dev/null @@ -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 -#include -#include -#include - -#include -#include - -#include - -#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; -} diff --git a/i3-migrate-config-to-v4 b/i3-migrate-config-to-v4 index 4dd4418f..4f4d0134 100755 --- a/i3-migrate-config-to-v4 +++ b/i3-migrate-config-to-v4 @@ -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"; } diff --git a/i3-msg/Makefile b/i3-msg/Makefile index 1b7c1c04..617df932 100644 --- a/i3-msg/Makefile +++ b/i3-msg/Makefile @@ -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/ diff --git a/i3-msg/main.c b/i3-msg/main.c index 630a345d..6a3b29d3 100644 --- a/i3-msg/main.c +++ b/i3-msg/main.c @@ -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, it’s even useful sometimes :-). * */ @@ -32,122 +32,11 @@ #include #include +#include "libi3.h" #include static char *socket_path; -/* - * Try to get the socket path from X11 and return NULL if it doesn’t work. - * As i3-msg is a short-running tool, we don’t 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 don’t 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); diff --git a/i3-nagbar/Makefile b/i3-nagbar/Makefile index 933ae76c..05a5b911 100644 --- a/i3-nagbar/Makefile +++ b/i3-nagbar/Makefile @@ -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/ diff --git a/i3-nagbar/i3-nagbar.h b/i3-nagbar/i3-nagbar.h index 2fbe3cbb..5a21226b 100644 --- a/i3-nagbar/i3-nagbar.h +++ b/i3-nagbar/i3-nagbar.h @@ -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 diff --git a/i3-nagbar/main.c b/i3-nagbar/main.c index d0d7e77a..4d4e253a 100644 --- a/i3-nagbar/main.c +++ b/i3-nagbar/main.c @@ -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 @@ -28,6 +26,7 @@ #include #include +#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 ] [-b