From: Mikael Magnusson Date: Sun, 2 Mar 2008 18:41:32 +0000 (+0100) Subject: Merge branch 'backport' into work X-Git-Tag: mikabox-3.4.7.2~70 X-Git-Url: http://git.openbox.org/?p=mikachu%2Fopenbox.git;a=commitdiff_plain;h=9676757a08b3e2e508c47f7795326bda8e54dc53;hp=e4691468cd291a6bd2b489e90eca2be78b8d0c51 Merge branch 'backport' into work Conflicts: openbox/actions/desktop.c openbox/actions/if.c --- diff --git a/.gitignore b/.gitignore index 8397f12..3f68a41 100644 --- a/.gitignore +++ b/.gitignore @@ -32,7 +32,7 @@ m4/*.m4 missing .dirstamp openbox/openbox -parser/obparser-3.0.pc +parser/obparser-4.0.pc po/Makefile.in.in po/Makevars.template po/POTFILES @@ -48,7 +48,8 @@ po/en@boldquot.insert-header po/en@quot.insert-header po/remove-potcdate.sed *.gmo -render/obrender-3.0.pc +render/obrender-4.0.pc +obt/obt-4.0.pc tools/gnome-panel-control/gnome-panel-control version.h .libs diff --git a/Makefile.am b/Makefile.am index 6a6f175..00d7998 100644 --- a/Makefile.am +++ b/Makefile.am @@ -8,7 +8,8 @@ rcdir = $(configdir)/openbox xsessionsdir = $(datadir)/xsessions gnomewmfilesdir = $(datadir)/gnome/wm-properties pkgconfigdir = $(libdir)/pkgconfig -pubincludedir = $(includedir)/openbox/@OB_VERSION@/openbox +obtpubincludedir= $(includedir)/openbox/@OBT_VERSION@/obt +rrpubincludedir = $(includedir)/openbox/@RR_VERSION@/render pixmapdir = $(datadir)/pixmaps xsddir = $(datadir)/openbox secretbindir = $(libdir)/openbox @@ -25,7 +26,7 @@ check_PROGRAMS = \ render/rendertest lib_LTLIBRARIES = \ - parser/libobparser.la \ + obt/libobt.la \ render/libobrender.la bin_PROGRAMS = \ @@ -49,7 +50,7 @@ render_rendertest_CPPFLAGS = \ $(GLIB_CFLAGS) \ -DG_LOG_DOMAIN=\"RenderTest\" render_rendertest_LDADD = \ - parser/libobparser.la \ + obt/libobt.la \ render/libobrender.la \ $(GLIB_LIBS) \ $(PANGO_LIBS) \ @@ -67,9 +68,9 @@ render_libobrender_la_CPPFLAGS = \ -DG_LOG_DOMAIN=\"ObRender\" \ -DDEFAULT_THEME=\"$(theme)\" render_libobrender_la_LDFLAGS = \ - -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) + -version-info $(RR_CURRENT):$(RR_REVISION):$(RR_AGE) render_libobrender_la_LIBADD = \ - parser/libobparser.la \ + obt/libobt.la \ $(X_LIBS) \ $(PANGO_LIBS) \ $(XFT_LIBS) \ @@ -98,33 +99,52 @@ render_libobrender_la_SOURCES = \ render/theme.h \ render/theme.c -## parser ## +## obt ## -parser_libobparser_la_CPPFLAGS = \ +obt_libobt_la_CPPFLAGS = \ + $(XINERAMA_CFLAGS) \ + $(XKB_CFLAGS) \ + $(XRANDR_CFLAGS) \ + $(XSHAPE_CFLAGS) \ + $(XSYNC_CFLAGS) \ $(GLIB_CFLAGS) \ $(XML_CFLAGS) \ - -DG_LOG_DOMAIN=\"ObParser\" \ + -DG_LOG_DOMAIN=\"Obt\" \ -DLOCALEDIR=\"$(localedir)\" \ -DDATADIR=\"$(datadir)\" \ -DCONFIGDIR=\"$(configdir)\" -parser_libobparser_la_LDFLAGS = \ - -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) -parser_libobparser_la_LIBADD = \ +obt_libobt_la_LDFLAGS = \ + -version-info $(OBT_CURRENT):$(OBT_REVISION):$(OBT_AGE) +obt_libobt_la_LIBADD = \ + $(XINERAMA_LIBS) \ + $(XKB_LIBS) \ + $(XRANDR_LIBS) \ + $(XSHAPE_LIBS) \ + $(XSYNC_LIBS) \ $(GLIB_LIBS) \ - $(XML_LIBS) -parser_libobparser_la_SOURCES = \ - parser/parse.h \ - parser/parse.c + $(XML_LIBS) +obt_libobt_la_SOURCES = \ + obt/display.h \ + obt/display.c \ + obt/internal.h \ + obt/keyboard.h \ + obt/keyboard.c \ + obt/mainloop.h \ + obt/mainloop.c \ + obt/parse.h \ + obt/parse.c \ + obt/paths.h \ + obt/paths.c \ + obt/prop.h \ + obt/prop.c \ + obt/util.h \ + obt/xevent.h \ + obt/xevent.c ## openbox ## openbox_openbox_CPPFLAGS = \ $(SM_CFLAGS) \ - $(XINERAMA_CFLAGS) \ - $(XKB_CFLAGS) \ - $(XRANDR_CFLAGS) \ - $(XSHAPE_CFLAGS) \ - $(XSYNC_CFLAGS) \ $(X_CFLAGS) \ $(XCURSOR_CFLAGS) \ $(SM_CFLAGS) \ @@ -138,11 +158,6 @@ openbox_openbox_CPPFLAGS = \ -DG_LOG_DOMAIN=\"Openbox\" openbox_openbox_LDADD = \ $(SM_LIBS) \ - $(XINERAMA_LIBS) \ - $(XKB_LIBS) \ - $(XRANDR_LIBS) \ - $(XSHAPE_LIBS) \ - $(XSYNC_LIBS) \ $(GLIB_LIBS) \ $(X_LIBS) \ $(XCURSOR_LIBS) \ @@ -151,7 +166,7 @@ openbox_openbox_LDADD = \ $(EFENCE_LIBS) \ $(LIBINTL) \ render/libobrender.la \ - parser/libobparser.la + obt/libobt.la openbox_openbox_LDFLAGS = -export-dynamic openbox_openbox_SOURCES = \ gettext.h \ @@ -212,8 +227,6 @@ openbox_openbox_SOURCES = \ openbox/dock.h \ openbox/event.c \ openbox/event.h \ - openbox/extensions.c \ - openbox/extensions.h \ openbox/focus.c \ openbox/focus.h \ openbox/focus_cycle.c \ @@ -231,19 +244,17 @@ openbox_openbox_SOURCES = \ openbox/grab.h \ openbox/group.c \ openbox/group.h \ + openbox/hooks.c \ + openbox/hooks.h \ openbox/keyboard.c \ openbox/keyboard.h \ openbox/keytree.c \ openbox/keytree.h \ - openbox/mainloop.c \ - openbox/mainloop.h \ openbox/menuframe.c \ openbox/menuframe.h \ openbox/menu.c \ openbox/menu.h \ openbox/misc.h \ - openbox/modkeys.c \ - openbox/modkeys.h \ openbox/mouse.c \ openbox/mouse.h \ openbox/moveresize.c \ @@ -259,8 +270,6 @@ openbox_openbox_SOURCES = \ openbox/prompt.h \ openbox/popup.c \ openbox/popup.h \ - openbox/prop.c \ - openbox/prop.h \ openbox/resist.c \ openbox/resist.h \ openbox/screen.c \ @@ -274,10 +283,7 @@ openbox_openbox_SOURCES = \ openbox/translate.c \ openbox/translate.h \ openbox/window.c \ - openbox/window.h \ - openbox/xerror.c \ - openbox/xerror.h - + openbox/window.h ## gnome-panel-control ## @@ -394,7 +400,7 @@ dist_syscrash_theme_DATA= \ ## public headers ## -pubinclude_HEADERS = \ +rrpubinclude_HEADERS = \ render/color.h \ render/font.h \ render/geom.h \ @@ -404,14 +410,22 @@ pubinclude_HEADERS = \ render/mask.h \ render/render.h \ render/theme.h \ - parser/parse.h - -nodist_pubinclude_HEADERS = \ - version.h + render/version.h + +obtpubinclude_HEADERS = \ + obt/display.h \ + obt/keyboard.h \ + obt/mainloop.h \ + obt/parse.h \ + obt/paths.h \ + obt/prop.h \ + obt/util.h \ + obt/version.h \ + obt/xevent.h nodist_pkgconfig_DATA = \ - render/obrender-3.0.pc \ - parser/obparser-3.0.pc + render/obrender-4.0.pc \ + obt/obt-4.0.pc ## data ## @@ -460,7 +474,6 @@ nodist_xsessions_DATA = \ data/xsession/openbox-kde.desktop dist_noinst_DATA = \ - version.h.in \ data/autostart.sh.in \ data/rc.xsd \ data/menu.xsd \ @@ -478,8 +491,10 @@ dist_noinst_DATA = \ doc/openbox-gnome-session.1.in \ doc/openbox-kde-session.1.sgml \ doc/openbox-kde-session.1.in \ - render/obrender-3.0.pc.in \ - parser/obparser-3.0.pc.in \ + render/version.h.in \ + render/obrender-4.0.pc.in \ + obt/obt-4.0.pc.in \ + obt/version.h.in \ tools/themeupdate/themeupdate.py \ tests/hideshow.py \ tests/Makefile \ @@ -535,7 +550,7 @@ CLEANFILES = \ # $(MAKE) -$(MAKEFLAGS) -C doc/doxygen doc distclean-local: - for d in . m4 po render; do \ + for d in . m4 po render parser obt openbox; do \ for p in core core.* gmon.out *\~ *.orig *.rej .\#*; do \ rm -f "$$d/$$p"; \ done \ diff --git a/README.GIT b/README.GIT index c50118e..b4b0557 100644 --- a/README.GIT +++ b/README.GIT @@ -3,7 +3,7 @@ To build Openbox from git you need: A C Compiler (GNU GCC 3.2+ suggested) GNU Gettext 0.14.4 GNU Autoconf 2.50+ -GNU Automake 1.9+ +GNU Automake 1.9 (no more, no less) GNU Libtool Xlib library/headers (devel package) Pkg-Config diff --git a/configure.ac b/configure.ac index 53e5001..463e7fb 100644 --- a/configure.ac +++ b/configure.ac @@ -4,41 +4,65 @@ AM_INIT_AUTOMAKE AC_CONFIG_SRCDIR([openbox/openbox.c]) dnl Making releases: -dnl OB_MICRO_VERSION += 1; -dnl OB_INTERFACE_AGE += 1; -dnl OB_BINARY_AGE += 1; -dnl if any functions have been added, set OB_INTERFACE_AGE to 0. +dnl RR_MICRO_VERSION += 1; +dnl RR_INTERFACE_AGE += 1; +dnl R_BINARY_AGE += 1; +dnl if any functions have been added, set RR_INTERFACE_AGE to 0. dnl if backwards compatibility has been broken, -dnl set OB_BINARY_AGE and OB_INTERFACE_AGE to 0. +dnl set RR_BINARY_AGE and RR_INTERFACE_AGE to 0. dnl dnl if MAJOR or MINOR version changes, be sure to change AC_INIT above to match dnl -OB_MAJOR_VERSION=3 -OB_MINOR_VERSION=4 -OB_MICRO_VERSION=16 -OB_INTERFACE_AGE=0 -OB_BINARY_AGE=0 -OB_VERSION=$OB_MAJOR_VERSION.$OB_MINOR_VERSION - -AC_SUBST(OB_MAJOR_VERSION) -AC_SUBST(OB_MINOR_VERSION) -AC_SUBST(OB_MICRO_VERSION) -AC_SUBST(OB_INTERFACE_AGE) -AC_SUBST(OB_BINARY_AGE) -AC_SUBST(OB_VERSION) +RR_MAJOR_VERSION=4 +RR_MINOR_VERSION=0 +RR_MICRO_VERSION=17 +RR_INTERFACE_AGE=0 +RR_BINARY_AGE=0 +RR_VERSION=$RR_MAJOR_VERSION.$RR_MINOR_VERSION + +OBT_MAJOR_VERSION=4 +OBT_MINOR_VERSION=0 +OBT_MICRO_VERSION=0 +OBT_INTERFACE_AGE=0 +OBT_BINARY_AGE=0 +OBT_VERSION=$OBT_MAJOR_VERSION.$OBT_MINOR_VERSION + +AC_SUBST(RR_MAJOR_VERSION) +AC_SUBST(RR_MINOR_VERSION) +AC_SUBST(RR_MICRO_VERSION) +AC_SUBST(RR_INTERFACE_AGE) +AC_SUBST(RR_BINARY_AGE) +AC_SUBST(RR_VERSION) +AC_SUBST(OBT_MAJOR_VERSION) +AC_SUBST(OBT_MINOR_VERSION) +AC_SUBST(OBT_MICRO_VERSION) +AC_SUBST(OBT_INTERFACE_AGE) +AC_SUBST(OBT_BINARY_AGE) +AC_SUBST(OBT_VERSION) dnl Libtool versioning -LT_RELEASE=$OB_MAJOR_VERSION.$OB_MINOR_VERSION -LT_CURRENT=`expr $OB_MICRO_VERSION - $OB_INTERFACE_AGE` -LT_REVISION=$OB_INTERFACE_AGE -LT_AGE=`expr $OB_BINARY_AGE - $OB_INTERFACE_AGE` -LT_CURRENT_MINUS_AGE=`expr $LT_CURRENT - $LT_AGE` - -AC_SUBST(LT_RELEASE) -AC_SUBST(LT_CURRENT) -AC_SUBST(LT_REVISION) -AC_SUBST(LT_AGE) -AC_SUBST(LT_CURRENT_MINUS_AGE) +RR_RELEASE=$RR_MAJOR_VERSION.$RR_MINOR_VERSION +RR_CURRENT=`expr $RR_MICRO_VERSION - $RR_INTERFACE_AGE` +RR_REVISION=$RR_INTERFACE_AGE +RR_AGE=`expr $RR_BINARY_AGE - $RR_INTERFACE_AGE` +RR_CURRENT_MINUS_AGE=`expr $RR_CURRENT - $RR_AGE` + +OBT_RELEASE=$OBT_MAJOR_VERSION.$OBT_MINOR_VERSION +OBT_CURRENT=`expr $OBT_MICRO_VERSION - $OBT_INTERFACE_AGE` +OBT_REVISION=$OBT_INTERFACE_AGE +OBT_AGE=`expr $OBT_BINARY_AGE - $OBT_INTERFACE_AGE` +OBT_CURRENT_MINUS_AGE=`expr $OBT_CURRENT - $OBT_AGE` + +AC_SUBST(RR_RELEASE) +AC_SUBST(RR_CURRENT) +AC_SUBST(RR_REVISION) +AC_SUBST(RR_AGE) +AC_SUBST(RR_CURRENT_MINUS_AGE) +AC_SUBST(OBT_RELEASE) +AC_SUBST(OBT_CURRENT) +AC_SUBST(OBT_REVISION) +AC_SUBST(OBT_AGE) +AC_SUBST(OBT_CURRENT_MINUS_AGE) AC_PREFIX_DEFAULT([/usr/local]) test "$prefix" = "NONE" && prefix=$ac_default_prefix @@ -154,9 +178,10 @@ AC_CONFIG_FILES([ Makefile m4/Makefile po/Makefile.in - render/obrender-3.0.pc - parser/obparser-3.0.pc - version.h + render/obrender-4.0.pc + obt/obt-4.0.pc + render/version.h + obt/version.h ]) AC_CONFIG_COMMANDS([doc], [test -d doc || mkdir doc]) diff --git a/data/rc.xml b/data/rc.xml index ebe2f31..f223f67 100644 --- a/data/rc.xml +++ b/data/rc.xml @@ -348,14 +348,24 @@ - - - - + + no + + + + + + + - - + + yes + + + + + @@ -559,23 +569,23 @@ - + previous - + next - + previous - + next - + previous - + next @@ -600,16 +610,16 @@ - + previous - + next - + previous - + next diff --git a/m4/openbox.m4 b/m4/openbox.m4 index 5c3aeec..5a95e84 100644 --- a/m4/openbox.m4 +++ b/m4/openbox.m4 @@ -74,7 +74,7 @@ AC_DEFUN([OB_COMPILER_FLAGS], if test "$GCC" = "yes"; then AC_MSG_RESULT([yes]) if test "$DEBUG" = "yes"; then - FLAGS="$FLAGS -O0 -g3 -fno-inline -Wwrite-strings" + FLAGS="$FLAGS -O0 -ggdb -fno-inline -Wwrite-strings" FLAGS="$FLAGS -Wall -Wsign-compare -Waggregate-return" FLAGS="$FLAGS -Wcast-qual -Wbad-function-cast -Wpointer-arith" # for Python.h diff --git a/parser/Makefile b/obt/Makefile similarity index 100% rename from parser/Makefile rename to obt/Makefile diff --git a/obt/display.c b/obt/display.c new file mode 100644 index 0000000..72c1b4d --- /dev/null +++ b/obt/display.c @@ -0,0 +1,152 @@ +/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- + + obt/display.c for the Openbox window manager + Copyright (c) 2007 Dana Jansens + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + See the COPYING file for a copy of the GNU General Public License. +*/ + +#include "obt/display.h" +#include "obt/prop.h" +#include "obt/internal.h" +#include "obt/keyboard.h" + +#ifdef HAVE_STRING_H +# include +#endif +#ifdef HAVE_FCNTL_H +# include +#endif +#ifdef HAVE_UNISTD_H +# include +#endif + +Display* obt_display = NULL; + +gboolean obt_display_error_occured = FALSE; + +gboolean obt_display_extension_xkb = FALSE; +gint obt_display_extension_xkb_basep; +gboolean obt_display_extension_shape = FALSE; +gint obt_display_extension_shape_basep; +gboolean obt_display_extension_xinerama = FALSE; +gint obt_display_extension_xinerama_basep; +gboolean obt_display_extension_randr = FALSE; +gint obt_display_extension_randr_basep; +gboolean obt_display_extension_sync = FALSE; +gint obt_display_extension_sync_basep; + +static gint xerror_handler(Display *d, XErrorEvent *e); + +static gboolean xerror_ignore = FALSE; + +gboolean obt_display_open(const char *display_name) +{ + gchar *n; + Display *d = NULL; + + n = display_name ? g_strdup(display_name) : NULL; + obt_display = d = XOpenDisplay(n); + if (d) { + gint junk; + (void)junk; + + if (fcntl(ConnectionNumber(d), F_SETFD, 1) == -1) + g_message("Failed to set display as close-on-exec"); + XSetErrorHandler(xerror_handler); + + /* read what extensions are present */ +#ifdef XKB + obt_display_extension_xkb = + XkbQueryExtension(d, &junk, + &obt_display_extension_xkb_basep, &junk, + NULL, NULL); + if (!obt_display_extension_xkb) + g_message("XKB extension is not present on the server"); +#endif + +#ifdef SHAPE + obt_display_extension_shape = + XShapeQueryExtension(d, &obt_display_extension_shape_basep, + &junk); + if (!obt_display_extension_shape) + g_message("X Shape extension is not present on the server"); +#endif + +#ifdef XINERAMA + obt_display_extension_xinerama = + XineramaQueryExtension(d, + &obt_display_extension_xinerama_basep, + &junk) && XineramaIsActive(d); + if (!obt_display_extension_xinerama) + g_message("Xinerama extension is not present on the server"); +#endif + +#ifdef XRANDR + obt_display_extension_randr = + XRRQueryExtension(d, &obt_display_extension_randr_basep, + &junk); + if (!obt_display_extension_randr) + g_message("XRandR extension is not present on the server"); +#endif + +#ifdef SYNC + obt_display_extension_sync = + XSyncQueryExtension(d, &obt_display_extension_sync_basep, + &junk) && XSyncInitialize(d, &junk, &junk); + if (!obt_display_extension_sync) + g_message("X Sync extension is not present on the server or is an " + "incompatible version"); +#endif + + obt_prop_startup(); + obt_keyboard_reload(); + } + g_free(n); + + return obt_display != NULL; +} + +void obt_display_close(void) +{ + obt_keyboard_shutdown(); + if (obt_display) XCloseDisplay(obt_display); +} + +static gint xerror_handler(Display *d, XErrorEvent *e) +{ +#ifdef DEBUG + gchar errtxt[128]; + + XGetErrorText(d, e->error_code, errtxt, 127); + if (!xerror_ignore) { + if (e->error_code == BadWindow) + /*g_message(_("X Error: %s\n"), errtxt)*/; + else + g_error("X Error: %s", errtxt); + } else + g_message("Ignoring XError code %d '%s'", e->error_code, errtxt); +#else + (void)d; (void)e; +#endif + + obt_display_error_occured = TRUE; + return 0; +} + +void obt_display_ignore_errors(gboolean ignore) +{ + XSync(obt_display, FALSE); + xerror_ignore = ignore; + if (ignore) obt_display_error_occured = FALSE; +} diff --git a/obt/display.h b/obt/display.h new file mode 100644 index 0000000..ff20f9c --- /dev/null +++ b/obt/display.h @@ -0,0 +1,68 @@ +/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- + + obt/display.h for the Openbox window manager + Copyright (c) 2007 Dana Jansens + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + See the COPYING file for a copy of the GNU General Public License. +*/ + +#ifndef __obt_display_h +#define __obt_display_h + +#include +#include + +#include /* shape.h uses Region which is in here */ +#ifdef XKB +#include +#endif +#ifdef SHAPE +#include +#endif +#ifdef XINERAMA +#include +#endif +#ifdef XRANDR +#include +#endif +#ifdef SYNC +#include +#endif + +G_BEGIN_DECLS + +extern gboolean obt_display_error_occured; + +extern gboolean obt_display_extension_xkb; +extern gint obt_display_extension_xkb_basep; +extern gboolean obt_display_extension_shape; +extern gint obt_display_extension_shape_basep; +extern gboolean obt_display_extension_xinerama; +extern gint obt_display_extension_xinerama_basep; +extern gboolean obt_display_extension_randr; +extern gint obt_display_extension_randr_basep; +extern gboolean obt_display_extension_sync; +extern gint obt_display_extension_sync_basep; + +extern Display* obt_display; + +gboolean obt_display_open(const char *display_name); +void obt_display_close(void); + +void obt_display_ignore_errors(gboolean ignore); + +#define obt_root(screen) (RootWindow(obt_display, screen)) + +G_END_DECLS + +#endif /*__obt_display_h*/ diff --git a/openbox/xerror.h b/obt/internal.h similarity index 70% rename from openbox/xerror.h rename to obt/internal.h index de1aa5a..818107d 100644 --- a/openbox/xerror.h +++ b/obt/internal.h @@ -1,6 +1,7 @@ /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- - xerror.h for the Openbox window manager + obt/internal.h for the Openbox window manager + Copyright (c) 2006 Mikael Magnusson Copyright (c) 2003-2007 Dana Jansens This program is free software; you can redistribute it and/or modify @@ -16,17 +17,11 @@ See the COPYING file for a copy of the GNU General Public License. */ -#ifndef __xerror_h -#define __xerror_h +#ifndef __obt_internal_h +#define __obt_internal_h -#include -#include +void obt_prop_startup(void); -/* can be used to track errors */ -extern gboolean xerror_occured; +void obt_keyboard_shutdown(void); -gint xerror_handler(Display *, XErrorEvent *); - -void xerror_set_ignore(gboolean ignore); - -#endif +#endif /* __obt_internal_h */ diff --git a/openbox/modkeys.c b/obt/keyboard.c similarity index 64% rename from openbox/modkeys.c rename to obt/keyboard.c index 9e8da32..699fa8b 100644 --- a/openbox/modkeys.c +++ b/obt/keyboard.c @@ -1,6 +1,6 @@ /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- - modkeys.c for the Openbox window manager + obt/keyboard.c for the Openbox window manager Copyright (c) 2007 Dana Jansens This program is free software; you can redistribute it and/or modify @@ -16,8 +16,8 @@ See the COPYING file for a copy of the GNU General Public License. */ -#include "modkeys.h" -#include "openbox.h" +#include "obt/display.h" +#include "obt/keyboard.h" #include #include @@ -34,31 +34,37 @@ #define nth_mask(n) (1 << n) static void set_modkey_mask(guchar mask, KeySym sym); +void obt_keyboard_shutdown(); static XModifierKeymap *modmap; static KeySym *keymap; static gint min_keycode, max_keycode, keysyms_per_keycode; /* This is a bitmask of the different masks for each modifier key */ -static guchar modkeys_keys[OB_MODKEY_NUM_KEYS]; +static guchar modkeys_keys[OBT_KEYBOARD_NUM_MODKEYS]; static gboolean alt_l = FALSE; static gboolean meta_l = FALSE; static gboolean super_l = FALSE; static gboolean hyper_l = FALSE; -void modkeys_startup(gboolean reconfigure) +static gboolean started = FALSE; + +void obt_keyboard_reload(void) { gint i, j, k; + if (started) obt_keyboard_shutdown(); /* free stuff */ + started = TRUE; + /* reset the keys to not be bound to any masks */ - for (i = 0; i < OB_MODKEY_NUM_KEYS; ++i) + for (i = 0; i < OBT_KEYBOARD_NUM_MODKEYS; ++i) modkeys_keys[i] = 0; - modmap = XGetModifierMapping(ob_display); + modmap = XGetModifierMapping(obt_display); g_assert(modmap->max_keypermod > 0); - XDisplayKeycodes(ob_display, &min_keycode, &max_keycode); - keymap = XGetKeyboardMapping(ob_display, min_keycode, + XDisplayKeycodes(obt_display, &min_keycode, &max_keycode); + keymap = XGetKeyboardMapping(obt_display, min_keycode, max_keycode - min_keycode + 1, &keysyms_per_keycode); @@ -86,18 +92,21 @@ void modkeys_startup(gboolean reconfigure) } /* CapsLock, Shift, and Control are special and hard-coded */ - modkeys_keys[OB_MODKEY_KEY_CAPSLOCK] = LockMask; - modkeys_keys[OB_MODKEY_KEY_SHIFT] = ShiftMask; - modkeys_keys[OB_MODKEY_KEY_CONTROL] = ControlMask; + modkeys_keys[OBT_KEYBOARD_MODKEY_CAPSLOCK] = LockMask; + modkeys_keys[OBT_KEYBOARD_MODKEY_SHIFT] = ShiftMask; + modkeys_keys[OBT_KEYBOARD_MODKEY_CONTROL] = ControlMask; } -void modkeys_shutdown(gboolean reconfigure) +void obt_keyboard_shutdown(void) { XFreeModifiermap(modmap); + modmap = NULL; XFree(keymap); + keymap = NULL; + started = FALSE; } -guint modkeys_keycode_to_mask(guint keycode) +guint obt_keyboard_keycode_to_modmask(guint keycode) { gint i, j; guint mask = 0; @@ -116,7 +125,7 @@ guint modkeys_keycode_to_mask(guint keycode) return mask; } -guint modkeys_only_modifier_masks(guint mask) +guint obt_keyboard_only_modmasks(guint mask) { mask &= ALL_MASKS; /* strip off these lock keys. they shouldn't affect key bindings */ @@ -124,12 +133,12 @@ guint modkeys_only_modifier_masks(guint mask) because you could bind it to something else and it should work as that modifier then. i think capslock is weird in xkb. */ - mask &= ~modkeys_key_to_mask(OB_MODKEY_KEY_NUMLOCK); - mask &= ~modkeys_key_to_mask(OB_MODKEY_KEY_SCROLLLOCK); + mask &= ~obt_keyboard_modkey_to_modmask(OBT_KEYBOARD_MODKEY_NUMLOCK); + mask &= ~obt_keyboard_modkey_to_modmask(OBT_KEYBOARD_MODKEY_SCROLLLOCK); return mask; } -guint modkeys_key_to_mask(ObModkeysKey key) +guint obt_keyboard_modkey_to_modmask(ObtModkeysKey key) { return modkeys_keys[key]; } @@ -139,44 +148,44 @@ static void set_modkey_mask(guchar mask, KeySym sym) /* find what key this is, and bind it to the mask */ if (sym == XK_Num_Lock) - modkeys_keys[OB_MODKEY_KEY_NUMLOCK] |= mask; + modkeys_keys[OBT_KEYBOARD_MODKEY_NUMLOCK] |= mask; else if (sym == XK_Scroll_Lock) - modkeys_keys[OB_MODKEY_KEY_SCROLLLOCK] |= mask; + modkeys_keys[OBT_KEYBOARD_MODKEY_SCROLLLOCK] |= mask; else if (sym == XK_Super_L && super_l) - modkeys_keys[OB_MODKEY_KEY_SUPER] |= mask; + modkeys_keys[OBT_KEYBOARD_MODKEY_SUPER] |= mask; else if (sym == XK_Super_L && !super_l) /* left takes precident over right, so erase any masks the right key may have set */ - modkeys_keys[OB_MODKEY_KEY_SUPER] = mask, super_l = TRUE; + modkeys_keys[OBT_KEYBOARD_MODKEY_SUPER] = mask, super_l = TRUE; else if (sym == XK_Super_R && !super_l) - modkeys_keys[OB_MODKEY_KEY_SUPER] |= mask; + modkeys_keys[OBT_KEYBOARD_MODKEY_SUPER] |= mask; else if (sym == XK_Hyper_L && hyper_l) - modkeys_keys[OB_MODKEY_KEY_HYPER] |= mask; + modkeys_keys[OBT_KEYBOARD_MODKEY_HYPER] |= mask; else if (sym == XK_Hyper_L && !hyper_l) - modkeys_keys[OB_MODKEY_KEY_HYPER] = mask, hyper_l = TRUE; + modkeys_keys[OBT_KEYBOARD_MODKEY_HYPER] = mask, hyper_l = TRUE; else if (sym == XK_Hyper_R && !hyper_l) - modkeys_keys[OB_MODKEY_KEY_HYPER] |= mask; + modkeys_keys[OBT_KEYBOARD_MODKEY_HYPER] |= mask; else if (sym == XK_Alt_L && alt_l) - modkeys_keys[OB_MODKEY_KEY_ALT] |= mask; + modkeys_keys[OBT_KEYBOARD_MODKEY_ALT] |= mask; else if (sym == XK_Alt_L && !alt_l) - modkeys_keys[OB_MODKEY_KEY_ALT] = mask, alt_l = TRUE; + modkeys_keys[OBT_KEYBOARD_MODKEY_ALT] = mask, alt_l = TRUE; else if (sym == XK_Alt_R && !alt_l) - modkeys_keys[OB_MODKEY_KEY_ALT] |= mask; + modkeys_keys[OBT_KEYBOARD_MODKEY_ALT] |= mask; else if (sym == XK_Meta_L && meta_l) - modkeys_keys[OB_MODKEY_KEY_META] |= mask; + modkeys_keys[OBT_KEYBOARD_MODKEY_META] |= mask; else if (sym == XK_Meta_L && !meta_l) - modkeys_keys[OB_MODKEY_KEY_META] = mask, meta_l = TRUE; + modkeys_keys[OBT_KEYBOARD_MODKEY_META] = mask, meta_l = TRUE; else if (sym == XK_Meta_R && !meta_l) - modkeys_keys[OB_MODKEY_KEY_META] |= mask; + modkeys_keys[OBT_KEYBOARD_MODKEY_META] |= mask; /* CapsLock, Shift, and Control are special and hard-coded */ } -KeyCode modkeys_sym_to_code(KeySym sym) +KeyCode obt_keyboard_keysym_to_keycode(KeySym sym) { gint i, j; @@ -188,3 +197,28 @@ KeyCode modkeys_sym_to_code(KeySym sym) return 0; } +gchar *obt_keyboard_keycode_to_string(guint keycode) +{ + KeySym sym; + + if ((sym = XKeycodeToKeysym(obt_display, keycode, 0)) != NoSymbol) + return g_locale_to_utf8(XKeysymToString(sym), -1, NULL, NULL, NULL); + return NULL; +} + +gunichar obt_keyboard_keycode_to_unichar(guint keycode) +{ + gunichar unikey = 0; + char *key; + + if ((key = obt_keyboard_keycode_to_string(keycode)) != NULL && + /* don't accept keys that aren't a single letter, like "space" */ + key[1] == '\0') + { + unikey = g_utf8_get_char_validated(key, -1); + if (unikey == (gunichar)-1 || unikey == (gunichar)-2 || unikey == 0) + unikey = 0; + } + g_free(key); + return unikey; +} diff --git a/openbox/modkeys.h b/obt/keyboard.h similarity index 52% rename from openbox/modkeys.h rename to obt/keyboard.h index dc72f28..dd28cb8 100644 --- a/openbox/modkeys.h +++ b/obt/keyboard.h @@ -1,6 +1,6 @@ /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- - masks.h for the Openbox window manager + obt/keyboard.h for the Openbox window manager Copyright (c) 2007 Dana Jansens This program is free software; you can redistribute it and/or modify @@ -16,45 +16,55 @@ See the COPYING file for a copy of the GNU General Public License. */ -#ifndef ob__modkeys_h -#define ob__modkeys_h +#ifndef __obt_keyboard_h +#define __obt_keyboard_h #include #include +G_BEGIN_DECLS + /*! These keys are bound to the modifier masks in any fashion, except for CapsLock, Shift, and Control. */ typedef enum { - OB_MODKEY_KEY_CAPSLOCK, - OB_MODKEY_KEY_NUMLOCK, - OB_MODKEY_KEY_SCROLLLOCK, - OB_MODKEY_KEY_SHIFT, - OB_MODKEY_KEY_CONTROL, - OB_MODKEY_KEY_SUPER, - OB_MODKEY_KEY_HYPER, - OB_MODKEY_KEY_META, - OB_MODKEY_KEY_ALT, - - OB_MODKEY_NUM_KEYS -} ObModkeysKey; - -void modkeys_startup(gboolean reconfigure); -void modkeys_shutdown(gboolean reconfigure); - -/*! Get the modifier masks for a keycode. (eg. a keycode bound to Alt_L could + OBT_KEYBOARD_MODKEY_CAPSLOCK, + OBT_KEYBOARD_MODKEY_NUMLOCK, + OBT_KEYBOARD_MODKEY_SCROLLLOCK, + OBT_KEYBOARD_MODKEY_SHIFT, + OBT_KEYBOARD_MODKEY_CONTROL, + OBT_KEYBOARD_MODKEY_SUPER, + OBT_KEYBOARD_MODKEY_HYPER, + OBT_KEYBOARD_MODKEY_META, + OBT_KEYBOARD_MODKEY_ALT, + + OBT_KEYBOARD_NUM_MODKEYS +} ObtModkeysKey; + +void obt_keyboard_reload(void); + +/*! Get the modifier mask(s) for a KeyCode. (eg. a keycode bound to Alt_L could return a mask of (Mod1Mask | Mask3Mask)) */ -guint modkeys_keycode_to_mask(guint keycode); +guint obt_keyboard_keycode_to_modmask(guint keycode); /*! Strip off all modifiers except for the modifier keys. This strips stuff - like Button1Mask, and also LockMask, NumLockMask, and ScrollLockMask */ -guint modkeys_only_modifier_masks(guint mask); + like Button1Mask, and also LockMask, NumlockMask, and ScrolllockMask */ +guint obt_keyboard_only_modmasks(guint mask); /*! Get the modifier masks for a modifier key. This includes both the left and right keys when there are both. */ -guint modkeys_key_to_mask(ObModkeysKey key); +guint obt_keyboard_modkey_to_modmask(ObtModkeysKey key); /*! Convert a KeySym to a KeyCode, because the X function is terrible - says valgrind. */ -KeyCode modkeys_sym_to_code(KeySym sym); +KeyCode obt_keyboard_keysym_to_keycode(KeySym sym); + +/*! Give the string form of a KeyCode */ +gchar *obt_keyboard_keycode_to_string(guint keycode); + +/*! Translate a KeyCode to the unicode character it represents */ +gunichar obt_keyboard_keycode_to_unichar(guint keycode); + + +G_END_DECLS -#endif +#endif /* __obt_keyboard_h */ diff --git a/openbox/mainloop.c b/obt/mainloop.c similarity index 75% rename from openbox/mainloop.c rename to obt/mainloop.c index b292120..691c687 100644 --- a/openbox/mainloop.c +++ b/obt/mainloop.c @@ -1,6 +1,6 @@ /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- - mainloop.c for the Openbox window manager + obt/mainloop.c for the Openbox window manager Copyright (c) 2006 Mikael Magnusson Copyright (c) 2003-2007 Dana Jansens @@ -17,25 +17,27 @@ See the COPYING file for a copy of the GNU General Public License. */ -#include "mainloop.h" -#include "event.h" +#include "obt/mainloop.h" +#include "obt/display.h" +#include "obt/util.h" #include #include #include #include -typedef struct _ObMainLoopTimer ObMainLoopTimer; -typedef struct _ObMainLoopSignal ObMainLoopSignal; -typedef struct _ObMainLoopSignalHandlerType ObMainLoopSignalHandlerType; -typedef struct _ObMainLoopXHandlerType ObMainLoopXHandlerType; -typedef struct _ObMainLoopFdHandlerType ObMainLoopFdHandlerType; +typedef struct _ObtMainLoopTimer ObtMainLoopTimer; +typedef struct _ObtMainLoopSignal ObtMainLoopSignal; +typedef struct _ObtMainLoopSignalHandlerType ObtMainLoopSignalHandlerType; +typedef struct _ObtMainLoopXHandlerType ObtMainLoopXHandlerType; +typedef struct _ObtMainLoopFdHandlerType ObtMainLoopFdHandlerType; /* this should be more than the number of possible signals on any architecture... */ #define NUM_SIGNALS 99 -/* all created ObMainLoops. Used by the signal handler to pass along signals */ +/* all created ObtMainLoops. Used by the signal handler to pass along + signals */ static GSList *all_loops; /* signals are global to all loops */ @@ -64,11 +66,13 @@ static gint core_signals[] = #define NUM_CORE_SIGNALS (sizeof(core_signals) / sizeof(core_signals[0])) static void sighandler(gint sig); -static void timer_dispatch(ObMainLoop *loop, GTimeVal **wait); +static void timer_dispatch(ObtMainLoop *loop, GTimeVal **wait); static void fd_handler_destroy(gpointer data); +static void calc_max_fd(ObtMainLoop *loop); -struct _ObMainLoop +struct _ObtMainLoop { + gint ref; Display *display; gboolean run; /* do keep running */ @@ -90,7 +94,7 @@ struct _ObMainLoop GSList *signal_handlers[NUM_SIGNALS]; }; -struct _ObMainLoopTimer +struct _ObtMainLoopTimer { gulong delay; GSourceFunc func; @@ -110,42 +114,41 @@ struct _ObMainLoopTimer gboolean fired; }; -struct _ObMainLoopSignalHandlerType +struct _ObtMainLoopSignalHandlerType { - ObMainLoop *loop; + ObtMainLoop *loop; gint signal; gpointer data; - ObMainLoopSignalHandler func; + ObtMainLoopSignalHandler func; GDestroyNotify destroy; }; -struct _ObMainLoopXHandlerType +struct _ObtMainLoopXHandlerType { - ObMainLoop *loop; + ObtMainLoop *loop; gpointer data; - ObMainLoopXHandler func; + ObtMainLoopXHandler func; GDestroyNotify destroy; }; -struct _ObMainLoopFdHandlerType +struct _ObtMainLoopFdHandlerType { - ObMainLoop *loop; + ObtMainLoop *loop; gint fd; gpointer data; - ObMainLoopFdHandler func; + ObtMainLoopFdHandler func; GDestroyNotify destroy; }; -ObMainLoop *ob_main_loop_new(Display *display) +ObtMainLoop *obt_main_loop_new(void) { - ObMainLoop *loop; + ObtMainLoop *loop; - loop = g_new0(ObMainLoop, 1); - loop->display = display; - loop->fd_x = ConnectionNumber(display); + loop = g_new0(ObtMainLoop, 1); + loop->ref = 1; FD_ZERO(&loop->fd_set); - FD_SET(loop->fd_x, &loop->fd_set); - loop->fd_max = loop->fd_x; + loop->fd_x = -1; + loop->fd_max = -1; loop->fd_handlers = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, fd_handler_destroy); @@ -185,24 +188,29 @@ ObMainLoop *ob_main_loop_new(Display *display) return loop; } -void ob_main_loop_destroy(ObMainLoop *loop) +void obt_main_loop_ref(ObtMainLoop *loop) +{ + ++loop->ref; +} + +void obt_main_loop_unref(ObtMainLoop *loop) { guint i; GSList *it, *next; - if (loop) { + if (loop && --loop->ref == 0) { g_assert(loop->running == FALSE); for (it = loop->x_handlers; it; it = next) { - ObMainLoopXHandlerType *h = it->data; + ObtMainLoopXHandlerType *h = it->data; next = g_slist_next(it); - ob_main_loop_x_remove(loop, h->func); + obt_main_loop_x_remove(loop, h->func); } g_hash_table_destroy(loop->fd_handlers); for (it = loop->timers; it; it = g_slist_next(it)) { - ObMainLoopTimer *t = it->data; + ObtMainLoopTimer *t = it->data; if (t->destroy) t->destroy(t->data); g_free(t); } @@ -211,9 +219,9 @@ void ob_main_loop_destroy(ObMainLoop *loop) for (i = 0; i < NUM_SIGNALS; ++i) for (it = loop->signal_handlers[i]; it; it = next) { - ObMainLoopSignalHandlerType *h = it->data; + ObtMainLoopSignalHandlerType *h = it->data; next = g_slist_next(it); - ob_main_loop_signal_remove(loop, h->func); + obt_main_loop_signal_remove(loop, h->func); } all_loops = g_slist_remove(all_loops, loop); @@ -230,7 +238,7 @@ void ob_main_loop_destroy(ObMainLoop *loop) } } - g_free(loop); + obt_free0(loop, ObtMainLoop, 1); } } @@ -238,14 +246,14 @@ static void fd_handle_foreach(gpointer key, gpointer value, gpointer data) { - ObMainLoopFdHandlerType *h = value; + ObtMainLoopFdHandlerType *h = value; fd_set *set = data; if (FD_ISSET(h->fd, set)) h->func(h->fd, h->data); } -void ob_main_loop_run(ObMainLoop *loop) +void obt_main_loop_run(ObtMainLoop *loop) { XEvent e; struct timeval *wait; @@ -268,7 +276,7 @@ void ob_main_loop_run(ObMainLoop *loop) while (loop->signals_fired[i]) { for (it = loop->signal_handlers[i]; it; it = g_slist_next(it)) { - ObMainLoopSignalHandlerType *h = it->data; + ObtMainLoopSignalHandlerType *h = it->data; h->func(i, h->data); } loop->signals_fired[i]--; @@ -277,12 +285,12 @@ void ob_main_loop_run(ObMainLoop *loop) loop->signal_fired = FALSE; sigprocmask(SIG_SETMASK, &oldset, NULL); - } else if (XPending(loop->display)) { + } else if (loop->display && XPending(loop->display)) { do { XNextEvent(loop->display, &e); for (it = loop->x_handlers; it; it = g_slist_next(it)) { - ObMainLoopXHandlerType *h = it->data; + ObtMainLoopXHandlerType *h = it->data; h->func(&e, h->data); } } while (XPending(loop->display) && loop->run); @@ -312,35 +320,45 @@ void ob_main_loop_run(ObMainLoop *loop) loop->running = FALSE; } -void ob_main_loop_exit(ObMainLoop *loop) +void obt_main_loop_exit(ObtMainLoop *loop) { loop->run = FALSE; } /*** XEVENT WATCHERS ***/ -void ob_main_loop_x_add(ObMainLoop *loop, - ObMainLoopXHandler handler, - gpointer data, - GDestroyNotify notify) +void obt_main_loop_x_add(ObtMainLoop *loop, + ObtMainLoopXHandler handler, + gpointer data, + GDestroyNotify notify) { - ObMainLoopXHandlerType *h; + ObtMainLoopXHandlerType *h; - h = g_new(ObMainLoopXHandlerType, 1); + h = g_new(ObtMainLoopXHandlerType, 1); h->loop = loop; h->func = handler; h->data = data; h->destroy = notify; + + if (!loop->x_handlers) { + g_assert(obt_display); /* is the display open? */ + + loop->display = obt_display; + loop->fd_x = ConnectionNumber(loop->display); + FD_SET(loop->fd_x, &loop->fd_set); + calc_max_fd(loop); + } + loop->x_handlers = g_slist_prepend(loop->x_handlers, h); } -void ob_main_loop_x_remove(ObMainLoop *loop, - ObMainLoopXHandler handler) +void obt_main_loop_x_remove(ObtMainLoop *loop, + ObtMainLoopXHandler handler) { GSList *it, *next; for (it = loop->x_handlers; it; it = next) { - ObMainLoopXHandlerType *h = it->data; + ObtMainLoopXHandlerType *h = it->data; next = g_slist_next(it); if (h->func == handler) { loop->x_handlers = g_slist_delete_link(loop->x_handlers, it); @@ -348,6 +366,11 @@ void ob_main_loop_x_remove(ObMainLoop *loop, g_free(h); } } + + if (!loop->x_handlers) { + FD_CLR(loop->fd_x, &loop->fd_set); + calc_max_fd(loop); + } } /*** SIGNAL WATCHERS ***/ @@ -372,23 +395,23 @@ static void sighandler(gint sig) } for (it = all_loops; it; it = g_slist_next(it)) { - ObMainLoop *loop = it->data; + ObtMainLoop *loop = it->data; loop->signal_fired = TRUE; loop->signals_fired[sig]++; } } -void ob_main_loop_signal_add(ObMainLoop *loop, - gint signal, - ObMainLoopSignalHandler handler, - gpointer data, - GDestroyNotify notify) +void obt_main_loop_signal_add(ObtMainLoop *loop, + gint signal, + ObtMainLoopSignalHandler handler, + gpointer data, + GDestroyNotify notify) { - ObMainLoopSignalHandlerType *h; + ObtMainLoopSignalHandlerType *h; g_return_if_fail(signal < NUM_SIGNALS); - h = g_new(ObMainLoopSignalHandlerType, 1); + h = g_new(ObtMainLoopSignalHandlerType, 1); h->loop = loop; h->signal = signal; h->func = handler; @@ -412,15 +435,15 @@ void ob_main_loop_signal_add(ObMainLoop *loop, all_signals[signal].installed++; } -void ob_main_loop_signal_remove(ObMainLoop *loop, - ObMainLoopSignalHandler handler) +void obt_main_loop_signal_remove(ObtMainLoop *loop, + ObtMainLoopSignalHandler handler) { guint i; GSList *it, *next; for (i = 0; i < NUM_SIGNALS; ++i) { for (it = loop->signal_handlers[i]; it; it = next) { - ObMainLoopSignalHandlerType *h = it->data; + ObtMainLoopSignalHandlerType *h = it->data; next = g_slist_next(it); @@ -447,28 +470,28 @@ void ob_main_loop_signal_remove(ObMainLoop *loop, static void max_fd_func(gpointer key, gpointer value, gpointer data) { - ObMainLoop *loop = data; + ObtMainLoop *loop = data; /* key is the fd */ loop->fd_max = MAX(loop->fd_max, *(gint*)key); } -static void calc_max_fd(ObMainLoop *loop) +static void calc_max_fd(ObtMainLoop *loop) { loop->fd_max = loop->fd_x; g_hash_table_foreach(loop->fd_handlers, max_fd_func, loop); } -void ob_main_loop_fd_add(ObMainLoop *loop, - gint fd, - ObMainLoopFdHandler handler, - gpointer data, - GDestroyNotify notify) +void obt_main_loop_fd_add(ObtMainLoop *loop, + gint fd, + ObtMainLoopFdHandler handler, + gpointer data, + GDestroyNotify notify) { - ObMainLoopFdHandlerType *h; + ObtMainLoopFdHandlerType *h; - h = g_new(ObMainLoopFdHandlerType, 1); + h = g_new(ObtMainLoopFdHandlerType, 1); h->loop = loop; h->fd = fd; h->func = handler; @@ -482,7 +505,7 @@ void ob_main_loop_fd_add(ObMainLoop *loop, static void fd_handler_destroy(gpointer data) { - ObMainLoopFdHandlerType *h = data; + ObtMainLoopFdHandlerType *h = data; FD_CLR(h->fd, &h->loop->fd_set); @@ -490,16 +513,17 @@ static void fd_handler_destroy(gpointer data) h->destroy(h->data); } -void ob_main_loop_fd_remove(ObMainLoop *loop, - gint fd) +void obt_main_loop_fd_remove(ObtMainLoop *loop, + gint fd) { g_hash_table_remove(loop->fd_handlers, &fd); + calc_max_fd(loop); } /*** TIMEOUTS ***/ #define NEAREST_TIMEOUT(loop) \ - (((ObMainLoopTimer*)(loop)->timers->data)->timeout) + (((ObtMainLoopTimer*)(loop)->timers->data)->timeout) static glong timecompare(GTimeVal *a, GTimeVal *b) { @@ -508,11 +532,11 @@ static glong timecompare(GTimeVal *a, GTimeVal *b) return a->tv_usec - b->tv_usec; } -static void insert_timer(ObMainLoop *loop, ObMainLoopTimer *ins) +static void insert_timer(ObtMainLoop *loop, ObtMainLoopTimer *ins) { GSList *it; for (it = loop->timers; it; it = g_slist_next(it)) { - ObMainLoopTimer *t = it->data; + ObtMainLoopTimer *t = it->data; if (timecompare(&ins->timeout, &t->timeout) <= 0) { loop->timers = g_slist_insert_before(loop->timers, it, ins); break; @@ -522,14 +546,14 @@ static void insert_timer(ObMainLoop *loop, ObMainLoopTimer *ins) loop->timers = g_slist_append(loop->timers, ins); } -void ob_main_loop_timeout_add(ObMainLoop *loop, - gulong microseconds, - GSourceFunc handler, - gpointer data, - GEqualFunc cmp, - GDestroyNotify notify) +void obt_main_loop_timeout_add(ObtMainLoop *loop, + gulong microseconds, + GSourceFunc handler, + gpointer data, + GEqualFunc cmp, + GDestroyNotify notify) { - ObMainLoopTimer *t = g_new(ObMainLoopTimer, 1); + ObtMainLoopTimer *t = g_new(ObtMainLoopTimer, 1); g_assert(microseconds > 0); /* if it's 0 it'll cause an infinite loop */ @@ -546,25 +570,25 @@ void ob_main_loop_timeout_add(ObMainLoop *loop, insert_timer(loop, t); } -void ob_main_loop_timeout_remove(ObMainLoop *loop, - GSourceFunc handler) +void obt_main_loop_timeout_remove(ObtMainLoop *loop, + GSourceFunc handler) { GSList *it; for (it = loop->timers; it; it = g_slist_next(it)) { - ObMainLoopTimer *t = it->data; + ObtMainLoopTimer *t = it->data; if (t->func == handler) t->del_me = TRUE; } } -void ob_main_loop_timeout_remove_data(ObMainLoop *loop, GSourceFunc handler, - gpointer data, gboolean cancel_dest) +void obt_main_loop_timeout_remove_data(ObtMainLoop *loop, GSourceFunc handler, + gpointer data, gboolean cancel_dest) { GSList *it; for (it = loop->timers; it; it = g_slist_next(it)) { - ObMainLoopTimer *t = it->data; + ObtMainLoopTimer *t = it->data; if (t->func == handler && t->equal(t->data, data)) { t->del_me = TRUE; if (cancel_dest) @@ -574,7 +598,7 @@ void ob_main_loop_timeout_remove_data(ObMainLoop *loop, GSourceFunc handler, } /* find the time to wait for the nearest timeout */ -static gboolean nearest_timeout_wait(ObMainLoop *loop, GTimeVal *tm) +static gboolean nearest_timeout_wait(ObtMainLoop *loop, GTimeVal *tm) { if (loop->timers == NULL) return FALSE; @@ -594,7 +618,7 @@ static gboolean nearest_timeout_wait(ObMainLoop *loop, GTimeVal *tm) return TRUE; } -static void timer_dispatch(ObMainLoop *loop, GTimeVal **wait) +static void timer_dispatch(ObtMainLoop *loop, GTimeVal **wait) { GSList *it, *next; @@ -603,7 +627,7 @@ static void timer_dispatch(ObMainLoop *loop, GTimeVal **wait) g_get_current_time(&loop->now); for (it = loop->timers; it; it = next) { - ObMainLoopTimer *curr; + ObtMainLoopTimer *curr; next = g_slist_next(it); diff --git a/obt/mainloop.h b/obt/mainloop.h new file mode 100644 index 0000000..f455d62 --- /dev/null +++ b/obt/mainloop.h @@ -0,0 +1,81 @@ +/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- + + obt/mainloop.h for the Openbox window manager + Copyright (c) 2006 Mikael Magnusson + Copyright (c) 2003-2007 Dana Jansens + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + See the COPYING file for a copy of the GNU General Public License. +*/ + +#ifndef __obt_mainloop_h +#define __obt_mainloop_h + +#include +#include + +G_BEGIN_DECLS + +typedef struct _ObtMainLoop ObtMainLoop; + +ObtMainLoop *obt_main_loop_new(void); +void obt_main_loop_ref(ObtMainLoop *loop); +void obt_main_loop_unref(ObtMainLoop *loop); + +typedef void (*ObtMainLoopXHandler) (const XEvent *e, gpointer data); + +void obt_main_loop_x_add(ObtMainLoop *loop, + ObtMainLoopXHandler handler, + gpointer data, + GDestroyNotify notify); +void obt_main_loop_x_remove(ObtMainLoop *loop, + ObtMainLoopXHandler handler); + +typedef void (*ObtMainLoopFdHandler) (gint fd, gpointer data); + +void obt_main_loop_fd_add(ObtMainLoop *loop, + gint fd, + ObtMainLoopFdHandler handler, + gpointer data, + GDestroyNotify notify); +void obt_main_loop_fd_remove(ObtMainLoop *loop, + gint fd); + +typedef void (*ObtMainLoopSignalHandler) (gint signal, gpointer data); + +void obt_main_loop_signal_add(ObtMainLoop *loop, + gint signal, + ObtMainLoopSignalHandler handler, + gpointer data, + GDestroyNotify notify); +void obt_main_loop_signal_remove(ObtMainLoop *loop, + ObtMainLoopSignalHandler handler); + +void obt_main_loop_timeout_add(ObtMainLoop *loop, + gulong microseconds, + GSourceFunc handler, + gpointer data, + GEqualFunc cmp, + GDestroyNotify notify); +void obt_main_loop_timeout_remove(ObtMainLoop *loop, + GSourceFunc handler); +void obt_main_loop_timeout_remove_data(ObtMainLoop *loop, + GSourceFunc handler, + gpointer data, + gboolean cancel_dest); + +void obt_main_loop_run(ObtMainLoop *loop); +void obt_main_loop_exit(ObtMainLoop *loop); + +G_END_DECLS + +#endif diff --git a/obt/obt-4.0.pc.in b/obt/obt-4.0.pc.in new file mode 100644 index 0000000..840de16 --- /dev/null +++ b/obt/obt-4.0.pc.in @@ -0,0 +1,14 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +xcflags=@X_CFLAGS@ +xlibs=@X_LIBS@ + +Name: Obt +Description: Openbox Toolkit Library +Version: @OBT_VERSION@ +Requires: glib-2.0 +Libs: -L${libdir} -lobrender ${xlibs} +Cflags: -I${includedir}/openbox/@OBT_VERSION@ ${xcflags} diff --git a/obt/parse.c b/obt/parse.c new file mode 100644 index 0000000..d181b67 --- /dev/null +++ b/obt/parse.c @@ -0,0 +1,413 @@ +/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- + + obt/parse.c for the Openbox window manager + Copyright (c) 2003-2007 Dana Jansens + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + See the COPYING file for a copy of the GNU General Public License. +*/ + +#include "obt/parse.h" +#include "obt/paths.h" + +#include + +#ifdef HAVE_STDLIB_H +# include +#endif +#ifdef HAVE_SYS_STAT_H +# include +#endif +#ifdef HAVE_SYS_TYPES_H +# include +#endif +#ifdef HAVE_UNISTD_H +# include +#endif + +struct Callback { + gchar *tag; + ObtParseCallback func; + gpointer data; +}; + +struct _ObtParseInst { + gint ref; + ObtPaths *xdg_paths; + GHashTable *callbacks; + xmlDocPtr doc; + xmlNodePtr root; + gchar *path; +}; + +static void destfunc(struct Callback *c) +{ + g_free(c->tag); + g_free(c); +} + +ObtParseInst* obt_parse_instance_new(void) +{ + ObtParseInst *i = g_new(ObtParseInst, 1); + i->ref = 1; + i->xdg_paths = obt_paths_new(); + i->callbacks = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, + (GDestroyNotify)destfunc); + i->doc = NULL; + i->root = NULL; + i->path = NULL; + return i; +} + +void obt_parse_instance_ref(ObtParseInst *i) +{ + ++i->ref; +} + +void obt_parse_instance_unref(ObtParseInst *i) +{ + if (i && --i->ref == 0) { + obt_paths_unref(i->xdg_paths); + g_hash_table_destroy(i->callbacks); + g_free(i); + } +} + +xmlDocPtr obt_parse_doc(ObtParseInst *i) +{ + g_assert(i->doc); /* a doc is open? */ + return i->doc; +} + +xmlNodePtr obt_parse_root(ObtParseInst *i) +{ + g_assert(i->doc); /* a doc is open? */ + return i->root; +} + +void obt_parse_register(ObtParseInst *i, const gchar *tag, + ObtParseCallback func, gpointer data) +{ + struct Callback *c; + + if ((c = g_hash_table_lookup(i->callbacks, tag))) { + g_error("Tag '%s' already registered", tag); + return; + } + + c = g_new(struct Callback, 1); + c->tag = g_strdup(tag); + c->func = func; + c->data = data; + g_hash_table_insert(i->callbacks, c->tag, c); +} + +static gboolean load_file(ObtParseInst *i, + const gchar *domain, + const gchar *filename, + const gchar *root_node, + GSList *paths) +{ + GSList *it; + gboolean r = FALSE; + + g_assert(i->doc == NULL); /* another doc isn't open already? */ + + for (it = paths; !r && it; it = g_slist_next(it)) { + gchar *path; + struct stat s; + + if (!domain && !filename) /* given a full path to the file */ + path = g_strdup(it->data); + else + path = g_build_filename(it->data, domain, filename, NULL); + + if (stat(path, &s) >= 0) { + /* XML_PARSE_BLANKS is needed apparently, or the tree can end up + with extra nodes in it. */ + i->doc = xmlReadFile(path, NULL, (XML_PARSE_NOBLANKS | + XML_PARSE_RECOVER)); + if (i->doc) { + i->root = xmlDocGetRootElement(i->doc); + if (!i->root) { + xmlFreeDoc(i->doc); + i->doc = NULL; + g_message("%s is an empty XML document", path); + } + else if (xmlStrcmp(i->root->name, + (const xmlChar*)root_node)) { + xmlFreeDoc(i->doc); + i->doc = NULL; + i->root = NULL; + g_message("XML document %s is of wrong type. Root " + "node is not '%s'", path, root_node); + } + else { + i->path = g_strdup(path); + r = TRUE; /* ok! */ + } + } + } + + g_free(path); + } + + return r; +} + +gboolean obt_parse_load_file(ObtParseInst *i, + const gchar *path, + const gchar *root_node) +{ + GSList *paths; + gboolean r; + + paths = g_slist_append(NULL, g_strdup(path)); + + r = load_file(i, NULL, NULL, root_node, paths); + + while (paths) { + g_free(paths->data); + paths = g_slist_delete_link(paths, paths); + } + return r; +} + +gboolean obt_parse_load_config_file(ObtParseInst *i, + const gchar *domain, + const gchar *filename, + const gchar *root_node) +{ + GSList *it, *paths = NULL; + gboolean r; + + for (it = obt_paths_config_dirs(i->xdg_paths); it; it = g_slist_next(it)) + paths = g_slist_append(paths, g_strdup(it->data)); + + r = load_file(i, domain, filename, root_node, paths); + + while (paths) { + g_free(paths->data); + paths = g_slist_delete_link(paths, paths); + } + return r; +} + +gboolean obt_parse_load_data_file(ObtParseInst *i, + const gchar *domain, + const gchar *filename, + const gchar *root_node) +{ + GSList *it, *paths = NULL; + gboolean r; + + for (it = obt_paths_data_dirs(i->xdg_paths); it; it = g_slist_next(it)) + paths = g_slist_append(paths, g_strdup(it->data)); + + r = load_file(i, domain, filename, root_node, paths); + + while (paths) { + g_free(paths->data); + paths = g_slist_delete_link(paths, paths); + } + return r; +} + +gboolean obt_parse_load_theme_file(ObtParseInst *i, + const gchar *theme, + const gchar *domain, + const gchar *filename, + const gchar *root_node) +{ + GSList *it, *paths = NULL; + gboolean r; + + /* use ~/.themes for backwards compatibility */ + paths = g_slist_append + (paths, g_build_filename(g_get_home_dir(), ".themes", theme, NULL)); + + for (it = obt_paths_data_dirs(i->xdg_paths); it; it = g_slist_next(it)) + paths = g_slist_append + (paths, g_build_filename(it->data, "themes", theme, NULL)); + + r = load_file(i, domain, filename, root_node, paths); + + while (paths) { + g_free(paths->data); + paths = g_slist_delete_link(paths, paths); + } + return r; +} + + +gboolean obt_parse_load_mem(ObtParseInst *i, + gpointer data, guint len, const gchar *root_node) +{ + gboolean r = FALSE; + + g_assert(i->doc == NULL); /* another doc isn't open already? */ + + i->doc = xmlParseMemory(data, len); + if (i) { + i->root = xmlDocGetRootElement(i->doc); + if (!i->root) { + xmlFreeDoc(i->doc); + i->doc = NULL; + g_message("Given memory is an empty document"); + } + else if (xmlStrcmp(i->root->name, (const xmlChar*)root_node)) { + xmlFreeDoc(i->doc); + i->doc = NULL; + i->root = NULL; + g_message("XML Document in given memory is of wrong " + "type. Root node is not '%s'\n", root_node); + } + else + r = TRUE; /* ok ! */ + } + return r; +} + +void obt_parse_close(ObtParseInst *i) +{ + if (i && i->doc) { + xmlFreeDoc(i->doc); + g_free(i->path); + i->doc = NULL; + i->root = NULL; + i->path = NULL; + } +} + +void obt_parse_tree(ObtParseInst *i, xmlNodePtr node) +{ + g_assert(i->doc); /* a doc is open? */ + + while (node) { + struct Callback *c = g_hash_table_lookup(i->callbacks, node->name); + if (c) c->func(node, c->data); + node = node->next; + } +} + +void obt_parse_tree_from_root(ObtParseInst *i) +{ + obt_parse_tree(i, i->root->children); +} + +gchar *obt_parse_node_string(xmlNodePtr node) +{ + xmlChar *c = xmlNodeGetContent(node); + gchar *s = g_strdup(c ? (gchar*)c : ""); + xmlFree(c); + return s; +} + +gint obt_parse_node_int(xmlNodePtr node) +{ + xmlChar *c = xmlNodeGetContent(node); + gint i = c ? atoi((gchar*)c) : 0; + xmlFree(c); + return i; +} + +gboolean obt_parse_node_bool(xmlNodePtr node) +{ + xmlChar *c = xmlNodeGetContent(node); + gboolean b = FALSE; + if (c && !xmlStrcasecmp(c, (const xmlChar*) "true")) + b = TRUE; + else if (c && !xmlStrcasecmp(c, (const xmlChar*) "yes")) + b = TRUE; + else if (c && !xmlStrcasecmp(c, (const xmlChar*) "on")) + b = TRUE; + xmlFree(c); + return b; +} + +gboolean obt_parse_node_contains(xmlNodePtr node, const gchar *val) +{ + xmlChar *c = xmlNodeGetContent(node); + gboolean r; + r = !xmlStrcasecmp(c, (const xmlChar*) val); + xmlFree(c); + return r; +} + +xmlNodePtr obt_parse_find_node(xmlNodePtr node, const gchar *tag) +{ + while (node) { + if (!xmlStrcmp(node->name, (const xmlChar*) tag)) + return node; + node = node->next; + } + return NULL; +} + +gboolean obt_parse_attr_bool(xmlNodePtr node, const gchar *name, + gboolean *value) +{ + xmlChar *c = xmlGetProp(node, (const xmlChar*) name); + gboolean r = FALSE; + if (c) { + if (!xmlStrcasecmp(c, (const xmlChar*) "true")) + *value = TRUE, r = TRUE; + else if (!xmlStrcasecmp(c, (const xmlChar*) "yes")) + *value = TRUE, r = TRUE; + else if (!xmlStrcasecmp(c, (const xmlChar*) "on")) + *value = TRUE, r = TRUE; + else if (!xmlStrcasecmp(c, (const xmlChar*) "false")) + *value = FALSE, r = TRUE; + else if (!xmlStrcasecmp(c, (const xmlChar*) "no")) + *value = FALSE, r = TRUE; + else if (!xmlStrcasecmp(c, (const xmlChar*) "off")) + *value = FALSE, r = TRUE; + } + xmlFree(c); + return r; +} + +gboolean obt_parse_attr_int(xmlNodePtr node, const gchar *name, gint *value) +{ + xmlChar *c = xmlGetProp(node, (const xmlChar*) name); + gboolean r = FALSE; + if (c) { + *value = atoi((gchar*)c); + r = TRUE; + } + xmlFree(c); + return r; +} + +gboolean obt_parse_attr_string(xmlNodePtr node, const gchar *name, + gchar **value) +{ + xmlChar *c = xmlGetProp(node, (const xmlChar*) name); + gboolean r = FALSE; + if (c) { + *value = g_strdup((gchar*)c); + r = TRUE; + } + xmlFree(c); + return r; +} + +gboolean obt_parse_attr_contains(xmlNodePtr node, const gchar *name, + const gchar *val) +{ + xmlChar *c = xmlGetProp(node, (const xmlChar*) name); + gboolean r = FALSE; + if (c) + r = !xmlStrcasecmp(c, (const xmlChar*) val); + xmlFree(c); + return r; +} diff --git a/obt/parse.h b/obt/parse.h new file mode 100644 index 0000000..acc3f5c --- /dev/null +++ b/obt/parse.h @@ -0,0 +1,85 @@ +/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- + + obt/parse.h for the Openbox window manager + Copyright (c) 2003-2007 Dana Jansens + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + See the COPYING file for a copy of the GNU General Public License. +*/ + +#ifndef __obt_parse_h +#define __obt_parse_h + +#include +#include + +G_BEGIN_DECLS + +typedef struct _ObtParseInst ObtParseInst; + +typedef void (*ObtParseCallback)(xmlNodePtr node, gpointer data); + +ObtParseInst* obt_parse_instance_new(void); +void obt_parse_instance_ref(ObtParseInst *inst); +void obt_parse_instance_unref(ObtParseInst *inst); + +gboolean obt_parse_load_file(ObtParseInst *inst, + const gchar *path, + const gchar *root_node); +gboolean obt_parse_load_config_file(ObtParseInst *inst, + const gchar *domain, + const gchar *filename, + const gchar *root_node); +gboolean obt_parse_load_data_file(ObtParseInst *inst, + const gchar *domain, + const gchar *filename, + const gchar *root_node); +gboolean obt_parse_load_theme_file(ObtParseInst *inst, + const gchar *theme, + const gchar *domain, + const gchar *filename, + const gchar *root_node); +gboolean obt_parse_load_mem(ObtParseInst *inst, + gpointer data, guint len, const gchar *root_node); + +xmlDocPtr obt_parse_doc(ObtParseInst *inst); +xmlNodePtr obt_parse_root(ObtParseInst *inst); + +void obt_parse_close(ObtParseInst *inst); + +void obt_parse_register(ObtParseInst *inst, const gchar *tag, + ObtParseCallback func, gpointer data); +void obt_parse_tree(ObtParseInst *i, xmlNodePtr node); +void obt_parse_tree_from_root(ObtParseInst *i); + + +/* helpers */ + +xmlNodePtr obt_parse_find_node(xmlNodePtr node, const gchar *name); + +gboolean obt_parse_node_contains (xmlNodePtr node, const gchar *val); +gchar *obt_parse_node_string (xmlNodePtr node); +gint obt_parse_node_int (xmlNodePtr node); +gboolean obt_parse_node_bool (xmlNodePtr node); + +gboolean obt_parse_attr_contains (xmlNodePtr node, const gchar *name, + const gchar *val); +gboolean obt_parse_attr_string (xmlNodePtr node, const gchar *name, + gchar **value); +gboolean obt_parse_attr_int (xmlNodePtr node, const gchar *name, + gint *value); +gboolean obt_parse_attr_bool (xmlNodePtr node, const gchar *name, + gboolean *value); + +G_END_DECLS + +#endif diff --git a/obt/paths.c b/obt/paths.c new file mode 100644 index 0000000..6100499 --- /dev/null +++ b/obt/paths.c @@ -0,0 +1,247 @@ +/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- + + obt/paths.c for the Openbox window manager + Copyright (c) 2003-2007 Dana Jansens + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + See the COPYING file for a copy of the GNU General Public License. +*/ + +#include "obt/paths.h" +#include "obt/util.h" + +#ifdef HAVE_SYS_STAT_H +# include +#endif +#ifdef HAVE_SYS_TYPES_H +# include +#endif +#ifdef HAVE_STRING_H +# include +#endif + +struct _ObtPaths +{ + gint ref; + gchar *config_home; + gchar *data_home; + gchar *cache_home; + GSList *config_dirs; + GSList *data_dirs; +}; + +static gint slist_path_cmp(const gchar *a, const gchar *b) +{ + return strcmp(a, b); +} + +typedef GSList* (*GSListFunc) (gpointer list, gconstpointer data); + +static GSList* slist_path_add(GSList *list, gpointer data, GSListFunc func) +{ + g_assert(func); + + if (!data) + return list; + + if (!g_slist_find_custom(list, data, (GCompareFunc) slist_path_cmp)) + list = func(list, data); + else + g_free(data); + + return list; +} + +static GSList* split_paths(const gchar *paths) +{ + GSList *list = NULL; + gchar **spl, **it; + + if (!paths) + return NULL; + spl = g_strsplit(paths, ":", -1); + for (it = spl; *it; ++it) + list = slist_path_add(list, *it, (GSListFunc) g_slist_append); + g_free(spl); + return list; +} + +ObtPaths* obt_paths_new(void) +{ + ObtPaths *p; + const gchar *path; + + p = g_new0(ObtPaths, 1); + p->ref = 1; + + path = g_getenv("XDG_CONFIG_HOME"); + if (path && path[0] != '\0') /* not unset or empty */ + p->config_home = g_build_filename(path, NULL); + else + p->config_home = g_build_filename(g_get_home_dir(), ".config", NULL); + + path = g_getenv("XDG_DATA_HOME"); + if (path && path[0] != '\0') /* not unset or empty */ + p->data_home = g_build_filename(path, NULL); + else + p->data_home = g_build_filename(g_get_home_dir(), ".local", + "share", NULL); + + path = g_getenv("XDG_CACHE_HOME"); + if (path && path[0] != '\0') /* not unset or empty */ + p->cache_home = g_build_filename(path, NULL); + else + p->cache_home = g_build_filename(g_get_home_dir(), ".cache", NULL); + + path = g_getenv("XDG_CONFIG_DIRS"); + if (path && path[0] != '\0') /* not unset or empty */ + p->config_dirs = split_paths(path); + else { + p->config_dirs = slist_path_add(p->config_dirs, + g_strdup(CONFIGDIR), + (GSListFunc) g_slist_append); + p->config_dirs = slist_path_add(p->config_dirs, + g_build_filename + (G_DIR_SEPARATOR_S, + "etc", "xdg", NULL), + (GSListFunc) g_slist_append); + } + p->config_dirs = slist_path_add(p->config_dirs, + g_strdup(p->config_home), + (GSListFunc) g_slist_prepend); + + path = g_getenv("XDG_DATA_DIRS"); + if (path && path[0] != '\0') /* not unset or empty */ + p->data_dirs = split_paths(path); + else { + p->data_dirs = slist_path_add(p->data_dirs, + g_strdup(DATADIR), + (GSListFunc) g_slist_append); + p->data_dirs = slist_path_add(p->data_dirs, + g_build_filename + (G_DIR_SEPARATOR_S, + "usr", "local", "share", NULL), + (GSListFunc) g_slist_append); + p->data_dirs = slist_path_add(p->data_dirs, + g_build_filename + (G_DIR_SEPARATOR_S, + "usr", "share", NULL), + (GSListFunc) g_slist_append); + } + p->data_dirs = slist_path_add(p->data_dirs, + g_strdup(p->data_home), + (GSListFunc) g_slist_prepend); + return p; +} + +void obt_paths_ref(ObtPaths *p) +{ + ++p->ref; +} + +void obt_paths_unref(ObtPaths *p) +{ + if (p && --p->ref == 0) { + GSList *it; + + for (it = p->config_dirs; it; it = g_slist_next(it)) + g_free(it->data); + g_slist_free(p->config_dirs); + for (it = p->data_dirs; it; it = g_slist_next(it)) + g_free(it->data); + g_slist_free(p->data_dirs); + g_free(p->config_home); + g_free(p->data_home); + g_free(p->cache_home); + + obt_free0(p, ObtPaths, 1); + } +} + +gchar *obt_paths_expand_tilde(const gchar *f) +{ + gchar **spl; + gchar *ret; + + if (!f) + return NULL; + spl = g_strsplit(f, "~", 0); + ret = g_strjoinv(g_get_home_dir(), spl); + g_strfreev(spl); + return ret; +} + +gboolean obt_paths_mkdir(const gchar *path, gint mode) +{ + gboolean ret = TRUE; + + g_return_val_if_fail(path != NULL, FALSE); + g_return_val_if_fail(path[0] != '\0', FALSE); + + if (!g_file_test(path, G_FILE_TEST_IS_DIR)) + if (mkdir(path, mode) == -1) + ret = FALSE; + + return ret; +} + +gboolean obt_paths_mkdir_path(const gchar *path, gint mode) +{ + gboolean ret = TRUE; + + g_return_val_if_fail(path != NULL, FALSE); + g_return_val_if_fail(path[0] == '/', FALSE); + + if (!g_file_test(path, G_FILE_TEST_IS_DIR)) { + gchar *c, *e; + + c = g_strdup(path); + e = c; + while ((e = strchr(e + 1, '/'))) { + *e = '\0'; + if (!(ret = obt_paths_mkdir(c, mode))) + goto parse_mkdir_path_end; + *e = '/'; + } + ret = obt_paths_mkdir(c, mode); + + parse_mkdir_path_end: + g_free(c); + } + + return ret; +} + +const gchar* obt_paths_config_home(ObtPaths *p) +{ + return p->config_home; +} + +const gchar* obt_paths_data_home(ObtPaths *p) +{ + return p->data_home; +} + +const gchar* obt_paths_cache_home(ObtPaths *p) +{ + return p->cache_home; +} + +GSList* obt_paths_config_dirs(ObtPaths *p) +{ + return p->config_dirs; +} + +GSList* obt_paths_data_dirs(ObtPaths *p) +{ + return p->data_dirs; +} diff --git a/obt/paths.h b/obt/paths.h new file mode 100644 index 0000000..8753d4f --- /dev/null +++ b/obt/paths.h @@ -0,0 +1,44 @@ +/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- + + obt/paths.h for the Openbox window manager + Copyright (c) 2003-2007 Dana Jansens + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + See the COPYING file for a copy of the GNU General Public License. +*/ + +#ifndef __obt_paths_h +#define __obt_paths_h + +#include + +G_BEGIN_DECLS + +typedef struct _ObtPaths ObtPaths; + +ObtPaths* obt_paths_new(void); +void obt_paths_ref(ObtPaths *p); +void obt_paths_unref(ObtPaths *p); + +const gchar* obt_paths_config_home(ObtPaths *p); +const gchar* obt_paths_data_home(ObtPaths *p); +const gchar* obt_paths_cache_home(ObtPaths *p); +GSList* obt_paths_config_dirs(ObtPaths *p); +GSList* obt_paths_data_dirs(ObtPaths *p); + +gchar *obt_paths_expand_tilde(const gchar *f); +gboolean obt_paths_mkdir(const gchar *path, gint mode); +gboolean obt_paths_mkdir_path(const gchar *path, gint mode); + +G_END_DECLS + +#endif diff --git a/obt/prop.c b/obt/prop.c new file mode 100644 index 0000000..1e324b9 --- /dev/null +++ b/obt/prop.c @@ -0,0 +1,497 @@ +/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- + + obt/prop.c for the Openbox window manager + Copyright (c) 2006 Mikael Magnusson + Copyright (c) 2003-2007 Dana Jansens + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + See the COPYING file for a copy of the GNU General Public License. +*/ + +#include "obt/prop.h" +#include "obt/display.h" + +#include +#ifdef HAVE_STRING_H +# include +#endif + +Atom prop_atoms[OBT_PROP_NUM_ATOMS]; +gboolean prop_started = FALSE; + +#define CREATE_NAME(var, name) (prop_atoms[OBT_PROP_##var] = \ + XInternAtom((obt_display), (name), FALSE)) +#define CREATE(var) CREATE_NAME(var, #var) +#define CREATE_(var) CREATE_NAME(var, "_" #var) + +void obt_prop_startup(void) +{ + if (prop_started) return; + prop_started = TRUE; + + g_assert(obt_display); + + CREATE(CARDINAL); + CREATE(WINDOW); + CREATE(PIXMAP); + CREATE(ATOM); + CREATE(STRING); + CREATE_NAME(UTF8, "UTF8_STRING"); + + CREATE(MANAGER); + + CREATE(WM_COLORMAP_WINDOWS); + CREATE(WM_PROTOCOLS); + CREATE(WM_STATE); + CREATE(WM_CHANGE_STATE); + CREATE(WM_DELETE_WINDOW); + CREATE(WM_TAKE_FOCUS); + CREATE(WM_NAME); + CREATE(WM_ICON_NAME); + CREATE(WM_CLASS); + CREATE(WM_WINDOW_ROLE); + CREATE(WM_CLIENT_MACHINE); + CREATE(WM_COMMAND); + CREATE(WM_CLIENT_LEADER); + CREATE(WM_TRANSIENT_FOR); + CREATE_(MOTIF_WM_HINTS); + + CREATE(SM_CLIENT_ID); + + CREATE_(NET_WM_FULL_PLACEMENT); + + CREATE_(NET_SUPPORTED); + CREATE_(NET_CLIENT_LIST); + CREATE_(NET_CLIENT_LIST_STACKING); + CREATE_(NET_NUMBER_OF_DESKTOPS); + CREATE_(NET_DESKTOP_GEOMETRY); + CREATE_(NET_DESKTOP_VIEWPORT); + CREATE_(NET_CURRENT_DESKTOP); + CREATE_(NET_DESKTOP_NAMES); + CREATE_(NET_ACTIVE_WINDOW); +/* CREATE_(NET_RESTACK_WINDOW);*/ + CREATE_(NET_WORKAREA); + CREATE_(NET_SUPPORTING_WM_CHECK); + CREATE_(NET_DESKTOP_LAYOUT); + CREATE_(NET_SHOWING_DESKTOP); + + CREATE_(NET_CLOSE_WINDOW); + CREATE_(NET_WM_MOVERESIZE); + CREATE_(NET_MOVERESIZE_WINDOW); + CREATE_(NET_REQUEST_FRAME_EXTENTS); + CREATE_(NET_RESTACK_WINDOW); + + CREATE_(NET_STARTUP_ID); + + CREATE_(NET_WM_NAME); + CREATE_(NET_WM_VISIBLE_NAME); + CREATE_(NET_WM_ICON_NAME); + CREATE_(NET_WM_VISIBLE_ICON_NAME); + CREATE_(NET_WM_DESKTOP); + CREATE_(NET_WM_WINDOW_TYPE); + CREATE_(NET_WM_STATE); + CREATE_(NET_WM_STRUT); + CREATE_(NET_WM_STRUT_PARTIAL); + CREATE_(NET_WM_ICON); + CREATE_(NET_WM_ICON_GEOMETRY); + CREATE_(NET_WM_PID); + CREATE_(NET_WM_ALLOWED_ACTIONS); + CREATE_(NET_WM_USER_TIME); +/* CREATE_(NET_WM_USER_TIME_WINDOW); */ + CREATE_(KDE_NET_WM_FRAME_STRUT); + CREATE_(NET_FRAME_EXTENTS); + + CREATE_(NET_WM_PING); +#ifdef SYNC + CREATE_(NET_WM_SYNC_REQUEST); + CREATE_(NET_WM_SYNC_REQUEST_COUNTER); +#endif + + CREATE_(NET_WM_WINDOW_TYPE_DESKTOP); + CREATE_(NET_WM_WINDOW_TYPE_DOCK); + CREATE_(NET_WM_WINDOW_TYPE_TOOLBAR); + CREATE_(NET_WM_WINDOW_TYPE_MENU); + CREATE_(NET_WM_WINDOW_TYPE_UTILITY); + CREATE_(NET_WM_WINDOW_TYPE_SPLASH); + CREATE_(NET_WM_WINDOW_TYPE_DIALOG); + CREATE_(NET_WM_WINDOW_TYPE_NORMAL); + CREATE_(NET_WM_WINDOW_TYPE_POPUP_MENU); + + prop_atoms[OBT_PROP_NET_WM_MOVERESIZE_SIZE_TOPLEFT] = 0; + prop_atoms[OBT_PROP_NET_WM_MOVERESIZE_SIZE_TOP] = 1; + prop_atoms[OBT_PROP_NET_WM_MOVERESIZE_SIZE_TOPRIGHT] = 2; + prop_atoms[OBT_PROP_NET_WM_MOVERESIZE_SIZE_RIGHT] = 3; + prop_atoms[OBT_PROP_NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT] = 4; + prop_atoms[OBT_PROP_NET_WM_MOVERESIZE_SIZE_BOTTOM] = 5; + prop_atoms[OBT_PROP_NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT] = 6; + prop_atoms[OBT_PROP_NET_WM_MOVERESIZE_SIZE_LEFT] = 7; + prop_atoms[OBT_PROP_NET_WM_MOVERESIZE_MOVE] = 8; + prop_atoms[OBT_PROP_NET_WM_MOVERESIZE_SIZE_KEYBOARD] = 9; + prop_atoms[OBT_PROP_NET_WM_MOVERESIZE_MOVE_KEYBOARD] = 10; + prop_atoms[OBT_PROP_NET_WM_MOVERESIZE_CANCEL] = 11; + + CREATE_(NET_WM_ACTION_MOVE); + CREATE_(NET_WM_ACTION_RESIZE); + CREATE_(NET_WM_ACTION_MINIMIZE); + CREATE_(NET_WM_ACTION_SHADE); + CREATE_(NET_WM_ACTION_MAXIMIZE_HORZ); + CREATE_(NET_WM_ACTION_MAXIMIZE_VERT); + CREATE_(NET_WM_ACTION_FULLSCREEN); + CREATE_(NET_WM_ACTION_CHANGE_DESKTOP); + CREATE_(NET_WM_ACTION_CLOSE); + CREATE_(NET_WM_ACTION_ABOVE); + CREATE_(NET_WM_ACTION_BELOW); + + CREATE_(NET_WM_STATE_MODAL); +/* CREATE_(NET_WM_STATE_STICKY);*/ + CREATE_(NET_WM_STATE_MAXIMIZED_VERT); + CREATE_(NET_WM_STATE_MAXIMIZED_HORZ); + CREATE_(NET_WM_STATE_SHADED); + CREATE_(NET_WM_STATE_SKIP_TASKBAR); + CREATE_(NET_WM_STATE_SKIP_PAGER); + CREATE_(NET_WM_STATE_HIDDEN); + CREATE_(NET_WM_STATE_FULLSCREEN); + CREATE_(NET_WM_STATE_ABOVE); + CREATE_(NET_WM_STATE_BELOW); + CREATE_(NET_WM_STATE_DEMANDS_ATTENTION); + + prop_atoms[OBT_PROP_NET_WM_STATE_ADD] = 1; + prop_atoms[OBT_PROP_NET_WM_STATE_REMOVE] = 0; + prop_atoms[OBT_PROP_NET_WM_STATE_TOGGLE] = 2; + + prop_atoms[OBT_PROP_NET_WM_ORIENTATION_HORZ] = 0; + prop_atoms[OBT_PROP_NET_WM_ORIENTATION_VERT] = 1; + prop_atoms[OBT_PROP_NET_WM_TOPLEFT] = 0; + prop_atoms[OBT_PROP_NET_WM_TOPRIGHT] = 1; + prop_atoms[OBT_PROP_NET_WM_BOTTOMRIGHT] = 2; + prop_atoms[OBT_PROP_NET_WM_BOTTOMLEFT] = 3; + + CREATE_(KDE_WM_CHANGE_STATE); + CREATE_(KDE_NET_WM_WINDOW_TYPE_OVERRIDE); + +/* + CREATE_NAME(ROOTPMAPId, "_XROOTPMAP_ID"); + CREATE_NAME(ESETROOTId, "ESETROOT_PMAP_ID"); +*/ + + CREATE_(OPENBOX_PID); + CREATE_(OB_THEME); + CREATE_(OB_CONFIG_FILE); + CREATE_(OB_WM_ACTION_UNDECORATE); + CREATE_(OB_WM_STATE_UNDECORATED); + CREATE_(OB_CONTROL); +} + +Atom obt_prop_atom(ObtPropAtom a) +{ + g_assert(prop_started); + g_assert(a < OBT_PROP_NUM_ATOMS); + return prop_atoms[a]; +} + +static gboolean get_prealloc(Window win, Atom prop, Atom type, gint size, + guchar *data, gulong num) +{ + gboolean ret = FALSE; + gint res; + guchar *xdata = NULL; + Atom ret_type; + gint ret_size; + gulong ret_items, bytes_left; + glong num32 = 32 / size * num; /* num in 32-bit elements */ + + res = XGetWindowProperty(obt_display, win, prop, 0l, num32, + FALSE, type, &ret_type, &ret_size, + &ret_items, &bytes_left, &xdata); + if (res == Success && ret_items && xdata) { + if (ret_size == size && ret_items >= num) { + guint i; + for (i = 0; i < num; ++i) + switch (size) { + case 8: + data[i] = xdata[i]; + break; + case 16: + ((guint16*)data)[i] = ((gushort*)xdata)[i]; + break; + case 32: + ((guint32*)data)[i] = ((gulong*)xdata)[i]; + break; + default: + g_assert_not_reached(); /* unhandled size */ + } + ret = TRUE; + } + XFree(xdata); + } + return ret; +} + +static gboolean get_all(Window win, Atom prop, Atom type, gint size, + guchar **data, guint *num) +{ + gboolean ret = FALSE; + gint res; + guchar *xdata = NULL; + Atom ret_type; + gint ret_size; + gulong ret_items, bytes_left; + + res = XGetWindowProperty(obt_display, win, prop, 0l, G_MAXLONG, + FALSE, type, &ret_type, &ret_size, + &ret_items, &bytes_left, &xdata); + if (res == Success) { + if (ret_size == size && ret_items > 0) { + guint i; + + *data = g_malloc(ret_items * (size / 8)); + for (i = 0; i < ret_items; ++i) + switch (size) { + case 8: + (*data)[i] = xdata[i]; + break; + case 16: + ((guint16*)*data)[i] = ((gushort*)xdata)[i]; + break; + case 32: + ((guint32*)*data)[i] = ((gulong*)xdata)[i]; + break; + default: + g_assert_not_reached(); /* unhandled size */ + } + *num = ret_items; + ret = TRUE; + } + XFree(xdata); + } + return ret; +} + +static gboolean get_stringlist(Window win, Atom prop, gchar ***list, gint *nstr) +{ + XTextProperty tprop; + gboolean ret = FALSE; + + if (XGetTextProperty(obt_display, win, &tprop, prop) && tprop.nitems) { + if (XTextPropertyToStringList(&tprop, list, nstr)) + ret = TRUE; + XFree(tprop.value); + } + return ret; +} + +gboolean obt_prop_get32(Window win, Atom prop, Atom type, guint32 *ret) +{ + return get_prealloc(win, prop, type, 32, (guchar*)ret, 1); +} + +gboolean obt_prop_get_array32(Window win, Atom prop, Atom type, guint32 **ret, + guint *nret) +{ + return get_all(win, prop, type, 32, (guchar**)ret, nret); +} + +gboolean obt_prop_get_string_locale(Window win, Atom prop, gchar **ret) +{ + gchar **list; + gint nstr; + gchar *s; + + if (get_stringlist(win, prop, &list, &nstr) && nstr) { + s = g_locale_to_utf8(list[0], -1, NULL, NULL, NULL); + XFreeStringList(list); + if (s) { + *ret = s; + return TRUE; + } + } + return FALSE; +} + +gboolean obt_prop_get_strings_locale(Window win, Atom prop, gchar ***ret) +{ + GSList *strs = NULL, *it; + gchar *raw, *p; + guint num, i, count = 0; + + if (get_all(win, prop, OBT_PROP_ATOM(STRING), 8, + (guchar**)&raw, &num)) + { + p = raw; + while (p < raw + num) { + ++count; + strs = g_slist_append(strs, p); + p += strlen(p) + 1; /* next string */ + } + + *ret = g_new0(gchar*, count + 1); + (*ret)[count] = NULL; /* null terminated list */ + + for (i = 0, it = strs; it; ++i, it = g_slist_next(it)) { + (*ret)[i] = g_locale_to_utf8(it->data, -1, NULL, NULL, NULL); + /* make sure translation did not fail */ + if (!(*ret)[i]) + (*ret)[i] = g_strdup(""); + } + g_free(raw); + g_slist_free(strs); + return TRUE; + } + return FALSE; +} + +gboolean obt_prop_get_string_utf8(Window win, Atom prop, gchar **ret) +{ + gchar *raw; + gchar *str; + guint num; + + if (get_all(win, prop, OBT_PROP_ATOM(UTF8), 8, + (guchar**)&raw, &num)) + { + str = g_strndup(raw, num); /* grab the first string from the list */ + g_free(raw); + if (g_utf8_validate(str, -1, NULL)) { + *ret = str; + return TRUE; + } + g_free(str); + } + return FALSE; +} + +gboolean obt_prop_get_strings_utf8(Window win, Atom prop, gchar ***ret) +{ + GSList *strs = NULL, *it; + gchar *raw, *p; + guint num, i, count = 0; + + if (get_all(win, prop, OBT_PROP_ATOM(UTF8), 8, + (guchar**)&raw, &num)) + { + p = raw; + while (p < raw + num) { + ++count; + strs = g_slist_append(strs, p); + p += strlen(p) + 1; /* next string */ + } + + *ret = g_new0(gchar*, count + 1); + + for (i = 0, it = strs; it; ++i, it = g_slist_next(it)) { + if (g_utf8_validate(it->data, -1, NULL)) + (*ret)[i] = g_strdup(it->data); + else + (*ret)[i] = g_strdup(""); + } + g_free(raw); + g_slist_free(strs); + return TRUE; + } + return FALSE; +} + +void obt_prop_set32(Window win, Atom prop, Atom type, gulong val) +{ + XChangeProperty(obt_display, win, prop, type, 32, PropModeReplace, + (guchar*)&val, 1); +} + +void obt_prop_set_array32(Window win, Atom prop, Atom type, gulong *val, + guint num) +{ + XChangeProperty(obt_display, win, prop, type, 32, PropModeReplace, + (guchar*)val, num); +} + +void obt_prop_set_string_locale(Window win, Atom prop, const gchar *val) +{ + gchar const *s[2] = { val, NULL }; + obt_prop_set_strings_locale(win, prop, s); +} + +void obt_prop_set_strings_locale(Window win, Atom prop, const gchar **strs) +{ + gint i, count; + gchar **lstrs; + XTextProperty tprop; + + /* count the strings in strs, and convert them to the locale format */ + for (count = 0; strs[count]; ++count); + lstrs = g_new0(char*, count); + for (i = 0; i < count; ++i) { + lstrs[i] = g_locale_from_utf8(strs[i], -1, NULL, NULL, NULL); + if (!lstrs[i]) { + lstrs[i] = g_strdup(""); /* make it an empty string */ + g_warning("Unable to translate string '%s' from UTF8 to locale " + "format", strs[i]); + } + } + + + XStringListToTextProperty(lstrs, count, &tprop); + XSetTextProperty(obt_display, win, &tprop, prop); + XFree(tprop.value); +} + +void obt_prop_set_string_utf8(Window win, Atom prop, const gchar *val) +{ + XChangeProperty(obt_display, win, prop, OBT_PROP_ATOM(UTF8), 8, + PropModeReplace, (const guchar*)val, strlen(val)); +} + +void obt_prop_set_strings_utf8(Window win, Atom prop, const gchar **strs) +{ + GString *str; + gchar const **s; + + str = g_string_sized_new(0); + for (s = strs; *s; ++s) { + str = g_string_append(str, *s); + str = g_string_append_c(str, '\0'); + } + XChangeProperty(obt_display, win, prop, obt_prop_atom(OBT_PROP_UTF8), 8, + PropModeReplace, (guchar*)str->str, str->len); + g_string_free(str, TRUE); +} + +void obt_prop_erase(Window win, Atom prop) +{ + XDeleteProperty(obt_display, win, prop); +} + +void obt_prop_message(gint screen, Window about, Atom messagetype, + glong data0, glong data1, glong data2, glong data3, + glong data4, glong mask) +{ + obt_prop_message_to(obt_root(screen), about, messagetype, + data0, data1, data2, data3, data4, mask); +} + +void obt_prop_message_to(Window to, Window about, + Atom messagetype, + glong data0, glong data1, glong data2, glong data3, + glong data4, glong mask) +{ + XEvent ce; + ce.xclient.type = ClientMessage; + ce.xclient.message_type = messagetype; + ce.xclient.display = obt_display; + ce.xclient.window = about; + ce.xclient.format = 32; + ce.xclient.data.l[0] = data0; + ce.xclient.data.l[1] = data1; + ce.xclient.data.l[2] = data2; + ce.xclient.data.l[3] = data3; + ce.xclient.data.l[4] = data4; + XSendEvent(obt_display, to, FALSE, mask, &ce); +} diff --git a/obt/prop.h b/obt/prop.h new file mode 100644 index 0000000..22a1ab4 --- /dev/null +++ b/obt/prop.h @@ -0,0 +1,281 @@ +/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- + + obt/prop.h for the Openbox window manager + Copyright (c) 2006 Mikael Magnusson + Copyright (c) 2003-2007 Dana Jansens + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + See the COPYING file for a copy of the GNU General Public License. +*/ + +#ifndef __obt_prop_h +#define __obt_prop_h + +#include +#include + +G_BEGIN_DECLS + +typedef enum { + /* types */ + OBT_PROP_CARDINAL, /*!< The atom which represents the Cardinal data type */ + OBT_PROP_WINDOW, /*!< The atom which represents window ids */ + OBT_PROP_PIXMAP, /*!< The atom which represents pixmap ids */ + OBT_PROP_ATOM, /*!< The atom which represents atom values */ + OBT_PROP_STRING, /*!< The atom which represents ascii strings */ + OBT_PROP_UTF8, /*!< The atom which represents utf8-encoded strings */ + + /* selection stuff */ + OBT_PROP_MANAGER, + + /* window hints */ + OBT_PROP_WM_COLORMAP_WINDOWS, + OBT_PROP_WM_PROTOCOLS, + OBT_PROP_WM_STATE, + OBT_PROP_WM_DELETE_WINDOW, + OBT_PROP_WM_TAKE_FOCUS, + OBT_PROP_WM_CHANGE_STATE, + OBT_PROP_WM_NAME, + OBT_PROP_WM_ICON_NAME, + OBT_PROP_WM_CLASS, + OBT_PROP_WM_WINDOW_ROLE, + OBT_PROP_WM_CLIENT_MACHINE, + OBT_PROP_WM_COMMAND, + OBT_PROP_WM_CLIENT_LEADER, + OBT_PROP_WM_TRANSIENT_FOR, + OBT_PROP_MOTIF_WM_HINTS, + + /* SM atoms */ + OBT_PROP_SM_CLIENT_ID, + + /* NETWM atoms */ + + /* Atoms that are used inside messages - these don't go in net_supported */ + + OBT_PROP_NET_WM_MOVERESIZE_SIZE_TOPLEFT, + OBT_PROP_NET_WM_MOVERESIZE_SIZE_TOP, + OBT_PROP_NET_WM_MOVERESIZE_SIZE_TOPRIGHT, + OBT_PROP_NET_WM_MOVERESIZE_SIZE_RIGHT, + OBT_PROP_NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT, + OBT_PROP_NET_WM_MOVERESIZE_SIZE_BOTTOM, + OBT_PROP_NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT, + OBT_PROP_NET_WM_MOVERESIZE_SIZE_LEFT, + OBT_PROP_NET_WM_MOVERESIZE_MOVE, + OBT_PROP_NET_WM_MOVERESIZE_SIZE_KEYBOARD, + OBT_PROP_NET_WM_MOVERESIZE_MOVE_KEYBOARD, + OBT_PROP_NET_WM_MOVERESIZE_CANCEL, + + OBT_PROP_NET_WM_STATE_ADD, + OBT_PROP_NET_WM_STATE_REMOVE, + OBT_PROP_NET_WM_STATE_TOGGLE, + + OBT_PROP_NET_WM_ORIENTATION_HORZ, + OBT_PROP_NET_WM_ORIENTATION_VERT, + OBT_PROP_NET_WM_TOPLEFT, + OBT_PROP_NET_WM_TOPRIGHT, + OBT_PROP_NET_WM_BOTTOMRIGHT, + OBT_PROP_NET_WM_BOTTOMLEFT, + + OBT_PROP_NET_WM_WINDOW_TYPE_POPUP_MENU, + + OBT_PROP_PRIVATE_PADDING1, + OBT_PROP_PRIVATE_PADDING2, + OBT_PROP_PRIVATE_PADDING3, + OBT_PROP_PRIVATE_PADDING4, + OBT_PROP_PRIVATE_PADDING5, + OBT_PROP_PRIVATE_PADDING6, + OBT_PROP_PRIVATE_PADDING7, + OBT_PROP_PRIVATE_PADDING8, + OBT_PROP_PRIVATE_PADDING9, + OBT_PROP_PRIVATE_PADDING10, + OBT_PROP_PRIVATE_PADDING11, + OBT_PROP_PRIVATE_PADDING12, + + /* Everything below here must go in net_supported on the root window */ + + /* root window properties */ + OBT_PROP_NET_SUPPORTED, + OBT_PROP_NET_CLIENT_LIST, + OBT_PROP_NET_CLIENT_LIST_STACKING, + OBT_PROP_NET_NUMBER_OF_DESKTOPS, + OBT_PROP_NET_DESKTOP_GEOMETRY, + OBT_PROP_NET_DESKTOP_VIEWPORT, + OBT_PROP_NET_CURRENT_DESKTOP, + OBT_PROP_NET_DESKTOP_NAMES, + OBT_PROP_NET_ACTIVE_WINDOW, +/* Atom net_restack_window;*/ + OBT_PROP_NET_WORKAREA, + OBT_PROP_NET_SUPPORTING_WM_CHECK, + OBT_PROP_NET_DESKTOP_LAYOUT, + OBT_PROP_NET_SHOWING_DESKTOP, + + /* root window messages */ + OBT_PROP_NET_CLOSE_WINDOW, + OBT_PROP_NET_WM_MOVERESIZE, + OBT_PROP_NET_MOVERESIZE_WINDOW, + OBT_PROP_NET_REQUEST_FRAME_EXTENTS, + OBT_PROP_NET_RESTACK_WINDOW, + + /* helpful hints to apps that aren't used for anything */ + OBT_PROP_NET_WM_FULL_PLACEMENT, + + /* startup-notification extension */ + OBT_PROP_NET_STARTUP_ID, + + /* application window properties */ + OBT_PROP_NET_WM_NAME, + OBT_PROP_NET_WM_VISIBLE_NAME, + OBT_PROP_NET_WM_ICON_NAME, + OBT_PROP_NET_WM_VISIBLE_ICON_NAME, + OBT_PROP_NET_WM_DESKTOP, + OBT_PROP_NET_WM_WINDOW_TYPE, + OBT_PROP_NET_WM_STATE, + OBT_PROP_NET_WM_STRUT, + OBT_PROP_NET_WM_STRUT_PARTIAL, + OBT_PROP_NET_WM_ICON, + OBT_PROP_NET_WM_ICON_GEOMETRY, + OBT_PROP_NET_WM_PID, + OBT_PROP_NET_WM_ALLOWED_ACTIONS, + OBT_PROP_NET_WM_USER_TIME, +/* OBT_PROP_NET_WM_USER_TIME_WINDOW, */ + OBT_PROP_NET_FRAME_EXTENTS, + + /* application protocols */ + OBT_PROP_NET_WM_PING, +#ifdef SYNC + OBT_PROP_NET_WM_SYNC_REQUEST, + OBT_PROP_NET_WM_SYNC_REQUEST_COUNTER, +#endif + + OBT_PROP_NET_WM_WINDOW_TYPE_DESKTOP, + OBT_PROP_NET_WM_WINDOW_TYPE_DOCK, + OBT_PROP_NET_WM_WINDOW_TYPE_TOOLBAR, + OBT_PROP_NET_WM_WINDOW_TYPE_MENU, + OBT_PROP_NET_WM_WINDOW_TYPE_UTILITY, + OBT_PROP_NET_WM_WINDOW_TYPE_SPLASH, + OBT_PROP_NET_WM_WINDOW_TYPE_DIALOG, + OBT_PROP_NET_WM_WINDOW_TYPE_NORMAL, + + OBT_PROP_NET_WM_ACTION_MOVE, + OBT_PROP_NET_WM_ACTION_RESIZE, + OBT_PROP_NET_WM_ACTION_MINIMIZE, + OBT_PROP_NET_WM_ACTION_SHADE, +/* OBT_PROP_NET_WM_ACTION_STICK,*/ + OBT_PROP_NET_WM_ACTION_MAXIMIZE_HORZ, + OBT_PROP_NET_WM_ACTION_MAXIMIZE_VERT, + OBT_PROP_NET_WM_ACTION_FULLSCREEN, + OBT_PROP_NET_WM_ACTION_CHANGE_DESKTOP, + OBT_PROP_NET_WM_ACTION_CLOSE, + OBT_PROP_NET_WM_ACTION_ABOVE, + OBT_PROP_NET_WM_ACTION_BELOW, + + OBT_PROP_NET_WM_STATE_MODAL, +/* OBT_PROP_NET_WM_STATE_STICKY,*/ + OBT_PROP_NET_WM_STATE_MAXIMIZED_VERT, + OBT_PROP_NET_WM_STATE_MAXIMIZED_HORZ, + OBT_PROP_NET_WM_STATE_SHADED, + OBT_PROP_NET_WM_STATE_SKIP_TASKBAR, + OBT_PROP_NET_WM_STATE_SKIP_PAGER, + OBT_PROP_NET_WM_STATE_HIDDEN, + OBT_PROP_NET_WM_STATE_FULLSCREEN, + OBT_PROP_NET_WM_STATE_ABOVE, + OBT_PROP_NET_WM_STATE_BELOW, + OBT_PROP_NET_WM_STATE_DEMANDS_ATTENTION, + + /* KDE atoms */ + + OBT_PROP_KDE_WM_CHANGE_STATE, + OBT_PROP_KDE_NET_WM_FRAME_STRUT, + OBT_PROP_KDE_NET_WM_WINDOW_TYPE_OVERRIDE, + +/* + OBT_PROP_ROOTPMAPID, + OBT_PROP_ESETROOTID, +*/ + + /* Openbox specific atoms */ + + OBT_PROP_OB_WM_ACTION_UNDECORATE, + OBT_PROP_OB_WM_STATE_UNDECORATED, + OBT_PROP_OPENBOX_PID, /* this is depreecated in favour of ob_control */ + OBT_PROP_OB_THEME, + OBT_PROP_OB_CONFIG_FILE, + OBT_PROP_OB_CONTROL, + + OBT_PROP_NUM_ATOMS +} ObtPropAtom; + +Atom obt_prop_atom(ObtPropAtom a); + +gboolean obt_prop_get32(Window win, Atom prop, Atom type, guint32 *ret); +gboolean obt_prop_get_array32(Window win, Atom prop, Atom type, guint32 **ret, + guint *nret); +gboolean obt_prop_get_string_locale(Window win, Atom prop, gchar **ret); +gboolean obt_prop_get_string_utf8(Window win, Atom prop, gchar **ret); +gboolean obt_prop_get_strings_locale(Window win, Atom prop, gchar ***ret); +gboolean obt_prop_get_strings_utf8(Window win, Atom prop, gchar ***ret); + +void obt_prop_set32(Window win, Atom prop, Atom type, gulong val); +void obt_prop_set_array32(Window win, Atom prop, Atom type, gulong *val, + guint num); +void obt_prop_set_string_locale(Window win, Atom prop, const gchar *val); +void obt_prop_set_string_utf8(Window win, Atom prop, const gchar *val); +void obt_prop_set_strings_locale(Window win, Atom prop, const gchar **strs); +void obt_prop_set_strings_utf8(Window win, Atom prop, const gchar **strs); + +void obt_prop_erase(Window win, Atom prop); + +void obt_prop_message(gint screen, Window about, Atom messagetype, + glong data0, glong data1, glong data2, glong data3, + glong data4, glong mask); +void obt_prop_message_to(Window to, Window about, Atom messagetype, + glong data0, glong data1, glong data2, glong data3, + glong data4, glong mask); + +#define OBT_PROP_ATOM(prop) obt_prop_atom(OBT_PROP_##prop) + +#define OBT_PROP_GET32(win, prop, type, ret) \ + (obt_prop_get32(win, OBT_PROP_ATOM(prop), OBT_PROP_ATOM(type), ret)) +#define OBT_PROP_GETA32(win, prop, type, ret, nret) \ + (obt_prop_get_array32(win, OBT_PROP_ATOM(prop), OBT_PROP_ATOM(type), \ + ret, nret)) +#define OBT_PROP_GETS(win, prop, type, ret) \ + (obt_prop_get_string_##type(win, OBT_PROP_ATOM(prop), ret)) +#define OBT_PROP_GETSS(win, prop, type, ret) \ + (obt_prop_get_strings_##type(win, OBT_PROP_ATOM(prop), ret)) + +#define OBT_PROP_SET32(win, prop, type, val) \ + (obt_prop_set32(win, OBT_PROP_ATOM(prop), OBT_PROP_ATOM(type), val)) +#define OBT_PROP_SETA32(win, prop, type, val, num) \ + (obt_prop_set_array32(win, OBT_PROP_ATOM(prop), OBT_PROP_ATOM(type), \ + val, num)) +#define OBT_PROP_SETS(win, prop, type, val) \ + (obt_prop_set_string_##type(win, OBT_PROP_ATOM(prop), val)) +#define OBT_PROP_SETSS(win, prop, type, strs) \ + (obt_prop_set_strings_##type(win, OBT_PROP_ATOM(prop), strs)) + +#define OBT_PROP_ERASE(win, prop) (obt_prop_erase(win, OBT_PROP_ATOM(prop))) + +#define OBT_PROP_MSG(screen, about, msgtype, data0, data1, data2, data3, \ + data4) \ + (obt_prop_message(screen, about, OBT_PROP_ATOM(msgtype), \ + data0, data1, data2, data3, data4, \ + SubstructureNotifyMask | SubstructureRedirectMask)) + +#define OBT_PROP_MSG_TO(to, about, msgtype, data0, data1, data2, data3, \ + data4, mask) \ + (obt_prop_message_to(to, about, OBT_PROP_ATOM(msgtype), \ + data0, data1, data2, data3, data4, mask)) + +G_END_DECLS + +#endif /* __obt_prop_h */ diff --git a/obt/util.h b/obt/util.h new file mode 100644 index 0000000..ff44d36 --- /dev/null +++ b/obt/util.h @@ -0,0 +1,37 @@ +/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- + + obt/util.h for the Openbox window manager + Copyright (c) 2007 Dana Jansens + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + See the COPYING file for a copy of the GNU General Public License. +*/ + +#ifndef __obt_util_h +#define __obt_util_h + +#include + +#ifdef HAVE_STRING_H +# include /* for memset() */ +#endif + +G_BEGIN_DECLS + +/* Util funcs */ +#define obt_free g_free +#define obt_free0(p, type, num) memset((p), 0, sizeof(type) * (num)), g_free(p) + +G_END_DECLS + + +#endif /*__obt_util_h*/ diff --git a/obt/version.h.in b/obt/version.h.in new file mode 100644 index 0000000..8adfcf8 --- /dev/null +++ b/obt/version.h.in @@ -0,0 +1,15 @@ +#ifndef obt__version_h +#define obt__version_h + +#define OBT_MAJOR_VERSION @OBT_MAJOR_VERSION@ +#define OBT_MINOR_VERSION @OBT_MINOR_VERSION@ +#define OBT_MICRO_VERSION @OBT_MICRO_VERSION@ +#define OBT_VERSION OBT_MAJOR_VERSION.OBT_MINOR_VERSION.OBT_MICRO_VERSION + +#define OBT_CHECK_VERSION(major,minor,micro) \ + (OBT_MAJOR_VERSION > (major) || \ + (OBT_MAJOR_VERSION == (major) && OBT_MINOR_VERSION > (minor)) || \ + (OBT_MAJOR_VERSION == (major) && OBT_MINOR_VERSION == (minor) && \ + OBT_MICRO_VERSION >= (micro))) + +#endif diff --git a/obt/xevent.c b/obt/xevent.c new file mode 100644 index 0000000..1cc32a9 --- /dev/null +++ b/obt/xevent.c @@ -0,0 +1,134 @@ +/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- + + obt/xevent.c for the Openbox window manager + Copyright (c) 2007 Dana Jansens + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + See the COPYING file for a copy of the GNU General Public License. +*/ + +#include "obt/xevent.h" +#include "obt/mainloop.h" +#include "obt/util.h" + +typedef struct _ObtXEventBinding ObtXEventBinding; + +struct _ObtXEventHandler +{ + gint ref; + ObtMainLoop *loop; + + /* An array of hash tables where the key is the window, and the value is + the ObtXEventBinding */ + GHashTable **bindings; + gint num_event_types; /* the length of the bindings array */ +}; + +struct _ObtXEventBinding +{ + Window win; + ObtXEventCallback func; + gpointer data; +}; + +static void xevent_handler(const XEvent *e, gpointer data); +static guint window_hash(Window *w) { return *w; } +static gboolean window_comp(Window *w1, Window *w2) { return *w1 == *w2; } + +ObtXEventHandler* xevent_new(void) +{ + ObtXEventHandler *h; + + h = g_new0(ObtXEventHandler, 1); + h->ref = 1; + + return h; +} + +void xevent_ref(ObtXEventHandler *h) +{ + ++h->ref; +} + +void xevent_unref(ObtXEventHandler *h) +{ + if (h && --h->ref == 0) { + gint i; + + if (h->loop) + obt_main_loop_x_remove(h->loop, xevent_handler); + for (i = 0; i < h->num_event_types; ++i) + g_hash_table_destroy(h->bindings[i]); + g_free(h->bindings); + + obt_free0(h, ObtXEventHandler, 1); + } +} + +void xevent_register(ObtXEventHandler *h, ObtMainLoop *loop) +{ + h->loop = loop; + obt_main_loop_x_add(loop, xevent_handler, h, NULL); +} + +void xevent_set_handler(ObtXEventHandler *h, gint type, Window win, + ObtXEventCallback func, gpointer data) +{ + ObtXEventBinding *b; + + g_assert(func); + + /* make sure we have a spot for the event */ + if (type + 1 < h->num_event_types) { + gint i; + h->bindings = g_renew(GHashTable*, h->bindings, type + 1); + for (i = h->num_event_types; i < type + 1; ++i) + h->bindings[i] = g_hash_table_new_full((GHashFunc)window_hash, + (GEqualFunc)window_comp, + NULL, g_free); + h->num_event_types = type + 1; + } + + b = g_new(ObtXEventBinding, 1); + b->win = win; + b->func = func; + b->data = data; + g_hash_table_replace(h->bindings[type], &b->win, b); +} + +void xevent_remove_handler(ObtXEventHandler *h, gint type, Window win) +{ + g_assert(type < h->num_event_types); + g_assert(win); + + g_hash_table_remove(h->bindings[type], &win); +} + +static void xevent_handler(const XEvent *e, gpointer data) +{ + ObtXEventHandler *h; + ObtXEventBinding *b; + + h = data; + + if (e->type < h->num_event_types) { + const gint all = OBT_XEVENT_ALL_WINDOWS; + /* run the all_windows handler first */ + b = g_hash_table_lookup(h->bindings[e->xany.type], &all); + if (b) b->func(e, b->data); + /* then run the per-window handler */ + b = g_hash_table_lookup(h->bindings[e->xany.type], &e->xany.window); + if (b) b->func(e, b->data); + } + else + g_message("Unhandled X Event type %d", e->xany.type); +} diff --git a/obt/xevent.h b/obt/xevent.h new file mode 100644 index 0000000..ec0b66e --- /dev/null +++ b/obt/xevent.h @@ -0,0 +1,48 @@ +/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- + + obt/xevent.h for the Openbox window manager + Copyright (c) 2007 Dana Jansens + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + See the COPYING file for a copy of the GNU General Public License. +*/ + +#ifndef __obt_xevent_h +#define __obt_xevent_h + +#include +#include + +G_BEGIN_DECLS + +struct _ObtMainLoop; + +typedef struct _ObtXEventHandler ObtXEventHandler; + +typedef void (*ObtXEventCallback) (const XEvent *e, gpointer data); + +ObtXEventHandler* xevent_new(void); +void xevent_ref(ObtXEventHandler *h); +void xevent_unref(ObtXEventHandler *h); + +void xevent_register(ObtXEventHandler *h, + struct _ObtMainLoop *loop); + +#define OBT_XEVENT_ALL_WINDOWS None + +void xevent_set_handler(ObtXEventHandler *h, gint type, Window win, + ObtXEventCallback func, gpointer data); +void xevent_remove_handler(ObtXEventHandler *h, gint type, Window win); + +G_END_DECLS + +#endif /*__obt_xevent_h*/ diff --git a/openbox/actions.c b/openbox/actions.c index d43896d..8f72714 100644 --- a/openbox/actions.c +++ b/openbox/actions.c @@ -159,23 +159,21 @@ ObActionsAct* actions_parse_string(const gchar *name) if ((act = actions_build_act_from_string(name))) if (act->def->setup) - act->options = act->def->setup(NULL, NULL, NULL); + act->options = act->def->setup(NULL); return act; } -ObActionsAct* actions_parse(ObParseInst *i, - xmlDocPtr doc, - xmlNodePtr node) +ObActionsAct* actions_parse(xmlNodePtr node) { gchar *name; ObActionsAct *act = NULL; - if (parse_attr_string("name", node, &name)) { + if (obt_parse_attr_string(node, "name", &name)) { if ((act = actions_build_act_from_string(name))) /* there is more stuff to parse here */ if (act->def->setup) - act->options = act->def->setup(i, doc, node->xmlChildrenNode); + act->options = act->def->setup(node->children); g_free(name); } diff --git a/openbox/actions.h b/openbox/actions.h index 6db6f8d..7a09a66 100644 --- a/openbox/actions.h +++ b/openbox/actions.h @@ -18,7 +18,8 @@ #include "misc.h" #include "frame.h" -#include "parser/parse.h" +#include "obt/parse.h" + #include #include @@ -30,8 +31,7 @@ typedef struct _ObActionsGlobalData ObActionsGlobalData; typedef struct _ObActionsClientData ObActionsClientData; typedef struct _ObActionsSelectorData ObActionsSelectorData; -typedef gpointer (*ObActionsDataSetupFunc)(ObParseInst *i, - xmlDocPtr doc, xmlNodePtr node); +typedef gpointer (*ObActionsDataSetupFunc)(xmlNodePtr node); typedef void (*ObActionsDataFreeFunc)(gpointer options); typedef gboolean (*ObActionsRunFunc)(ObActionsData *data, gpointer options); @@ -64,9 +64,7 @@ gboolean actions_register(const gchar *name, ObActionsInteractiveInputFunc i_input, ObActionsInteractiveCancelFunc i_cancel); -ObActionsAct* actions_parse(ObParseInst *i, - xmlDocPtr doc, - xmlNodePtr node); +ObActionsAct* actions_parse(xmlNodePtr node); ObActionsAct* actions_parse_string(const gchar *name); gboolean actions_act_is_interactive(ObActionsAct *act); @@ -81,7 +79,7 @@ void actions_act_unref(ObActionsAct *act); void actions_set_need_pointer_replay_before_move(gboolean replay); /*! Returns if a ReplayPointer is still needed. If it was called while running actions then this will be false */ -gboolean actions_get_need_pointer_replay_before_move(); +gboolean actions_get_need_pointer_replay_before_move(void); /*! Pass in a GSList of ObActionsAct's to be run. */ void actions_run_acts(GSList *acts, @@ -93,8 +91,8 @@ void actions_run_acts(GSList *acts, ObFrameContext con, struct _ObClient *client); -gboolean actions_interactive_act_running(); -void actions_interactive_cancel_act(); +gboolean actions_interactive_act_running(void); +void actions_interactive_cancel_act(void); gboolean actions_interactive_input_event(XEvent *e); diff --git a/openbox/actions/addremovedesktop.c b/openbox/actions/addremovedesktop.c index 8125b9b..b6e621a 100644 --- a/openbox/actions/addremovedesktop.c +++ b/openbox/actions/addremovedesktop.c @@ -7,36 +7,28 @@ typedef struct { gboolean add; } Options; -static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node); -static gpointer setup_add_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node); -static gpointer setup_remove_func(ObParseInst *i, - xmlDocPtr doc, xmlNodePtr node); -static void free_func(gpointer options); +static gpointer setup_func(xmlNodePtr node); +static gpointer setup_add_func(xmlNodePtr node); +static gpointer setup_remove_func(xmlNodePtr node); static gboolean run_func(ObActionsData *data, gpointer options); void action_addremovedesktop_startup(void) { - actions_register("AddDesktop", - setup_add_func, - free_func, - run_func, + actions_register("AddDesktop", setup_add_func, g_free, run_func, NULL, NULL); - actions_register("RemoveDesktop", - setup_remove_func, - free_func, - run_func, + actions_register("RemoveDesktop", setup_remove_func, g_free, run_func, NULL, NULL); } -static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node) +static gpointer setup_func(xmlNodePtr node) { xmlNodePtr n; Options *o; o = g_new0(Options, 1); - if ((n = parse_find_node("where", node))) { - gchar *s = parse_string(doc, n); + if ((n = obt_parse_find_node(node, "where"))) { + gchar *s = obt_parse_node_string(n); if (!g_ascii_strcasecmp(s, "last")) o->current = FALSE; else if (!g_ascii_strcasecmp(s, "current")) @@ -47,28 +39,20 @@ static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node) return o; } -static gpointer setup_add_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node) +static gpointer setup_add_func(xmlNodePtr node) { - Options *o = setup_func(i, doc, node); + Options *o = setup_func(node); o->add = TRUE; return o; } -static gpointer setup_remove_func(ObParseInst *i, - xmlDocPtr doc, xmlNodePtr node) +static gpointer setup_remove_func(xmlNodePtr node) { - Options *o = setup_func(i, doc, node); + Options *o = setup_func(node); o->add = FALSE; return o; } -static void free_func(gpointer options) -{ - Options *o = options; - - g_free(o); -} - /* Always return FALSE because its not interactive */ static gboolean run_func(ObActionsData *data, gpointer options) { diff --git a/openbox/actions/all.h b/openbox/actions/all.h index 4fbd6ff..909836a 100644 --- a/openbox/actions/all.h +++ b/openbox/actions/all.h @@ -1,44 +1,44 @@ #ifndef __actions_all_h #define __actions_all_h -void action_all_startup(); +void action_all_startup(void); -void action_execute_startup(); -void action_debug_startup(); -void action_showmenu_startup(); -void action_showdesktop_startup(); -void action_reconfigure_startup(); -void action_exit_startup(); -void action_restart_startup(); -void action_session_startup(); -void action_cyclewindows_startup(); -void action_breakchroot_startup(); -void action_close_startup(); -void action_move_startup(); -void action_focus_startup(); -void action_raise_startup(); -void action_lower_startup(); -void action_raiselower_startup(); -void action_unfocus_startup(); -void action_iconify_startup(); -void action_fullscreen_startup(); -void action_maximize_startup(); -void action_moveresizeto_startup(); -void action_moverelative_startup(); -void action_shade_startup(); -void action_kill_startup(); -void action_omnipresent_startup(); -void action_directionalwindows_startup(); -void action_resize_startup(); -void action_decorations_startup(); -void action_desktop_startup(); -void action_resizerelative_startup(); -void action_addremovedesktop_startup(); -void action_dockautohide_startup(); -void action_layer_startup(); -void action_movetoedge_startup(); -void action_growtoedge_startup(); -void action_if_startup(); -void action_focustobottom_startup(); +void action_execute_startup(void); +void action_debug_startup(void); +void action_showmenu_startup(void); +void action_showdesktop_startup(void); +void action_reconfigure_startup(void); +void action_exit_startup(void); +void action_restart_startup(void); +void action_session_startup(void); +void action_cyclewindows_startup(void); +void action_breakchroot_startup(void); +void action_close_startup(void); +void action_move_startup(void); +void action_focus_startup(void); +void action_raise_startup(void); +void action_lower_startup(void); +void action_raiselower_startup(void); +void action_unfocus_startup(void); +void action_iconify_startup(void); +void action_fullscreen_startup(void); +void action_maximize_startup(void); +void action_moveresizeto_startup(void); +void action_moverelative_startup(void); +void action_shade_startup(void); +void action_kill_startup(void); +void action_omnipresent_startup(void); +void action_directionalwindows_startup(void); +void action_resize_startup(void); +void action_decorations_startup(void); +void action_desktop_startup(void); +void action_resizerelative_startup(void); +void action_addremovedesktop_startup(void); +void action_dockautohide_startup(void); +void action_layer_startup(void); +void action_movetoedge_startup(void); +void action_growtoedge_startup(void); +void action_if_startup(void); +void action_focustobottom_startup(void); #endif diff --git a/openbox/actions/cyclewindows.c b/openbox/actions/cyclewindows.c index cb341af..44d87cf 100644 --- a/openbox/actions/cyclewindows.c +++ b/openbox/actions/cyclewindows.c @@ -8,23 +8,21 @@ typedef struct { gboolean linear; - gboolean dialog; gboolean dock_windows; gboolean desktop_windows; gboolean all_desktops; gboolean forward; gboolean bar; gboolean raise; + ObFocusCyclePopupMode dialog_mode; GSList *actions; } Options; static gboolean cycling = FALSE; -static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node); -static gpointer setup_forward_func(ObParseInst *i, xmlDocPtr doc, - xmlNodePtr node); -static gpointer setup_backward_func(ObParseInst *i, xmlDocPtr doc, - xmlNodePtr node); +static gpointer setup_func(xmlNodePtr node); +static gpointer setup_forward_func(xmlNodePtr node); +static gpointer setup_backward_func(xmlNodePtr node); static void free_func(gpointer options); static gboolean run_func(ObActionsData *data, gpointer options); static gboolean i_input_func(guint initial_state, @@ -43,38 +41,42 @@ void action_cyclewindows_startup(void) run_func, i_input_func, i_cancel_func); } -static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node) +static gpointer setup_func(xmlNodePtr node) { xmlNodePtr n; Options *o; o = g_new0(Options, 1); - o->dialog = TRUE; o->bar = TRUE; - - if ((n = parse_find_node("linear", node))) - o->linear = parse_bool(doc, n); - if ((n = parse_find_node("dialog", node))) - o->dialog = parse_bool(doc, n); - if ((n = parse_find_node("bar", node))) - o->bar = parse_bool(doc, n); - if ((n = parse_find_node("raise", node))) - o->raise = parse_bool(doc, n); - if ((n = parse_find_node("panels", node))) - o->dock_windows = parse_bool(doc, n); - if ((n = parse_find_node("desktop", node))) - o->desktop_windows = parse_bool(doc, n); - if ((n = parse_find_node("allDesktops", node))) - o->all_desktops = parse_bool(doc, n); - - if ((n = parse_find_node("finalactions", node))) { + o->dialog_mode = OB_FOCUS_CYCLE_POPUP_MODE_LIST; + + if ((n = obt_parse_find_node(node, "linear"))) + o->linear = obt_parse_node_bool(n); + if ((n = obt_parse_find_node(node, "dialog"))) { + if (obt_parse_node_contains(n, "none")) + o->dialog_mode = OB_FOCUS_CYCLE_POPUP_MODE_NONE; + else if (obt_parse_node_contains(n, "icons")) + o->dialog_mode = OB_FOCUS_CYCLE_POPUP_MODE_ICONS; + } + if ((n = obt_parse_find_node(node, "bar"))) + o->bar = obt_parse_node_bool(n); + if ((n = obt_parse_find_node(node, "raise"))) + o->raise = obt_parse_node_bool(n); + if ((n = obt_parse_find_node(node, "panels"))) + o->dock_windows = obt_parse_node_bool(n); + if ((n = obt_parse_find_node(node, "desktop"))) + o->desktop_windows = obt_parse_node_bool(n); + if ((n = obt_parse_find_node(node, "allDesktops"))) + o->all_desktops = obt_parse_node_bool(n); + + if ((n = obt_parse_find_node(node, "finalactions"))) { xmlNodePtr m; - m = parse_find_node("action", n->xmlChildrenNode); + m = obt_parse_find_node(n->children, "action"); while (m) { - ObActionsAct *action = actions_parse(i, doc, m); + ObActionsAct *action = actions_parse(m); if (action) o->actions = g_slist_prepend(o->actions, action); - m = parse_find_node("action", m->next); + m = obt_parse_find_node(m->next, "action"); } } else { @@ -89,18 +91,16 @@ static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node) return o; } -static gpointer setup_forward_func(ObParseInst *i, xmlDocPtr doc, - xmlNodePtr node) +static gpointer setup_forward_func(xmlNodePtr node) { - Options *o = setup_func(i, doc, node); + Options *o = setup_func(node); o->forward = TRUE; return o; } -static gpointer setup_backward_func(ObParseInst *i, xmlDocPtr doc, - xmlNodePtr node) +static gpointer setup_backward_func(xmlNodePtr node) { - Options *o = setup_func(i, doc, node); + Options *o = setup_func(node); o->forward = FALSE; return o; } @@ -129,7 +129,7 @@ static gboolean run_func(ObActionsData *data, gpointer options) o->linear, TRUE, o->bar, - o->dialog, + o->dialog_mode, FALSE, FALSE); cycling = TRUE; @@ -189,7 +189,7 @@ static void end_cycle(gboolean cancel, guint state, Options *o) o->linear, TRUE, o->bar, - o->dialog, + o->dialog_mode, TRUE, cancel); cycling = FALSE; diff --git a/openbox/actions/debug.c b/openbox/actions/debug.c index f71b685..99e838a 100644 --- a/openbox/actions/debug.c +++ b/openbox/actions/debug.c @@ -5,39 +5,32 @@ typedef struct { gchar *str; } Options; -static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node); +static gpointer setup_func(xmlNodePtr node); static void free_func(gpointer options); static gboolean run_func(ObActionsData *data, gpointer options); void action_debug_startup(void) { - actions_register("Debug", - setup_func, - free_func, - run_func, - NULL, NULL); + actions_register("Debug", setup_func, free_func, run_func, NULL, NULL); } -static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node) +static gpointer setup_func(xmlNodePtr node) { xmlNodePtr n; Options *o; o = g_new0(Options, 1); - if ((n = parse_find_node("string", node))) - o->str = parse_string(doc, n); + if ((n = obt_parse_find_node(node, "string"))) + o->str = obt_parse_node_string(n); return o; } static void free_func(gpointer options) { Options *o = options; - - if (o) { - g_free(o->str); - g_free(o); - } + g_free(o->str); + g_free(o); } /* Always return FALSE because its not interactive */ diff --git a/openbox/actions/desktop.c b/openbox/actions/desktop.c index 142fec5..d5535f6 100644 --- a/openbox/actions/desktop.c +++ b/openbox/actions/desktop.c @@ -26,10 +26,8 @@ typedef struct { gboolean follow; } Options; -static gpointer setup_go_func(ObParseInst *i, xmlDocPtr doc, - xmlNodePtr node); -static gpointer setup_send_func(ObParseInst *i, xmlDocPtr doc, - xmlNodePtr node); +static gpointer setup_go_func(xmlNodePtr node); +static gpointer setup_send_func(xmlNodePtr node); static gboolean run_func(ObActionsData *data, gpointer options); void action_desktop_startup(void) @@ -40,8 +38,7 @@ void action_desktop_startup(void) NULL, NULL); } -static gpointer setup_go_func(ObParseInst *i, xmlDocPtr doc, - xmlNodePtr node) +static gpointer setup_go_func(xmlNodePtr node) { xmlNodePtr n; Options *o; @@ -53,8 +50,8 @@ static gpointer setup_go_func(ObParseInst *i, xmlDocPtr doc, /* wrap by default - it's handy! */ o->rel.wrap = TRUE; - if ((n = parse_find_node("to", node))) { - gchar *s = parse_string(doc, n); + if ((n = obt_parse_find_node(node, "to"))) { + gchar *s = obt_parse_node_string(n); if (!g_ascii_strcasecmp(s, "last")) o->type = LAST; else if (!g_ascii_strcasecmp(s, "next")) { @@ -94,24 +91,23 @@ static gpointer setup_go_func(ObParseInst *i, xmlDocPtr doc, g_free(s); } - if ((n = parse_find_node("wrap", node))) - o->rel.wrap = parse_bool(doc, n); + if ((n = obt_parse_find_node(node, "wrap"))) + o->rel.wrap = obt_parse_node_bool(n); return o; } -static gpointer setup_send_func(ObParseInst *i, xmlDocPtr doc, - xmlNodePtr node) +static gpointer setup_send_func(xmlNodePtr node) { xmlNodePtr n; Options *o; - o = setup_go_func(i, doc, node); + o = setup_go_func(node); o->send = TRUE; o->follow = TRUE; - if ((n = parse_find_node("follow", node))) - o->follow = parse_bool(doc, n); + if ((n = obt_parse_find_node(node, "follow"))) + o->follow = obt_parse_node_bool(n); return o; } diff --git a/openbox/actions/directionalwindows.c b/openbox/actions/directionalwindows.c index 55c9e60..c5c25c1 100644 --- a/openbox/actions/directionalwindows.c +++ b/openbox/actions/directionalwindows.c @@ -20,11 +20,9 @@ typedef struct { static gboolean cycling = FALSE; -static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node); -static gpointer setup_cycle_func(ObParseInst *i, xmlDocPtr doc, - xmlNodePtr node); -static gpointer setup_target_func(ObParseInst *i, xmlDocPtr doc, - xmlNodePtr node); +static gpointer setup_func(xmlNodePtr node); +static gpointer setup_cycle_func(xmlNodePtr node); +static gpointer setup_target_func(xmlNodePtr node); static void free_func(gpointer options); static gboolean run_func(ObActionsData *data, gpointer options); static gboolean i_input_func(guint initial_state, @@ -43,7 +41,7 @@ void action_directionalwindows_startup(void) run_func, NULL, NULL); } -static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node) +static gpointer setup_func(xmlNodePtr node) { xmlNodePtr n; Options *o; @@ -52,18 +50,18 @@ static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node) o->dialog = TRUE; o->bar = TRUE; - if ((n = parse_find_node("dialog", node))) - o->dialog = parse_bool(doc, n); - if ((n = parse_find_node("bar", node))) - o->bar = parse_bool(doc, n); - if ((n = parse_find_node("raise", node))) - o->raise = parse_bool(doc, n); - if ((n = parse_find_node("panels", node))) - o->dock_windows = parse_bool(doc, n); - if ((n = parse_find_node("desktop", node))) - o->desktop_windows = parse_bool(doc, n); - if ((n = parse_find_node("direction", node))) { - gchar *s = parse_string(doc, n); + if ((n = obt_parse_find_node(node, "dialog"))) + o->dialog = obt_parse_node_bool(n); + if ((n = obt_parse_find_node(node, "bar"))) + o->bar = obt_parse_node_bool(n); + if ((n = obt_parse_find_node(node, "raise"))) + o->raise = obt_parse_node_bool(n); + if ((n = obt_parse_find_node(node, "panels"))) + o->dock_windows = obt_parse_node_bool(n); + if ((n = obt_parse_find_node(node, "desktop"))) + o->desktop_windows = obt_parse_node_bool(n); + if ((n = obt_parse_find_node(node, "direction"))) { + gchar *s = obt_parse_node_string(n); if (!g_ascii_strcasecmp(s, "north") || !g_ascii_strcasecmp(s, "up")) o->direction = OB_DIRECTION_NORTH; @@ -87,14 +85,14 @@ static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node) g_free(s); } - if ((n = parse_find_node("finalactions", node))) { + if ((n = obt_parse_find_node(node, "finalactions"))) { xmlNodePtr m; - m = parse_find_node("action", n->xmlChildrenNode); + m = obt_parse_find_node(n->children, "action"); while (m) { - ObActionsAct *action = actions_parse(i, doc, m); + ObActionsAct *action = actions_parse(m); if (action) o->actions = g_slist_prepend(o->actions, action); - m = parse_find_node("action", m->next); + m = obt_parse_find_node(m->next, "action"); } } else { @@ -109,18 +107,16 @@ static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node) return o; } -static gpointer setup_cycle_func(ObParseInst *i, xmlDocPtr doc, - xmlNodePtr node) +static gpointer setup_cycle_func(xmlNodePtr node) { - Options *o = setup_func(i, doc, node); + Options *o = setup_func(node); o->interactive = TRUE; return o; } -static gpointer setup_target_func(ObParseInst *i, xmlDocPtr doc, - xmlNodePtr node) +static gpointer setup_target_func(xmlNodePtr node) { - Options *o = setup_func(i, doc, node); + Options *o = setup_func(node); o->interactive = FALSE; return o; } diff --git a/openbox/actions/execute.c b/openbox/actions/execute.c index eb1b461..81aa6d2 100644 --- a/openbox/actions/execute.c +++ b/openbox/actions/execute.c @@ -1,8 +1,10 @@ #include "openbox/actions.h" #include "openbox/event.h" #include "openbox/startupnotify.h" +#include "openbox/client.h" #include "openbox/prompt.h" #include "openbox/screen.h" +#include "obt/paths.h" #include "gettext.h" #ifdef HAVE_STDLIB_H @@ -18,7 +20,7 @@ typedef struct { gchar *prompt; } Options; -static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node); +static gpointer setup_func(xmlNodePtr node); static void free_func(gpointer options); static gboolean run_func(ObActionsData *data, gpointer options); /* @@ -31,41 +33,37 @@ static void i_cancel_func(gpointer options); void action_execute_startup(void) { - actions_register("Execute", - setup_func, - free_func, - run_func, - NULL, NULL); + actions_register("Execute", setup_func, free_func, run_func, NULL, NULL); } -static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node) +static gpointer setup_func(xmlNodePtr node) { xmlNodePtr n; Options *o; o = g_new0(Options, 1); - if ((n = parse_find_node("command", node)) || - (n = parse_find_node("execute", node))) + if ((n = obt_parse_find_node(node, "command")) || + (n = obt_parse_find_node(node, "execute"))) { - gchar *s = parse_string(doc, n); - o->cmd = parse_expand_tilde(s); + gchar *s = obt_parse_node_string(n); + o->cmd = obt_paths_expand_tilde(s); g_free(s); } - if ((n = parse_find_node("prompt", node))) - o->prompt = parse_string(doc, n); + if ((n = obt_parse_find_node(node, "prompt"))) + o->prompt = obt_parse_node_string(n); - if ((n = parse_find_node("startupnotify", node))) { + if ((n = obt_parse_find_node(node, "startupnotify"))) { xmlNodePtr m; - if ((m = parse_find_node("enabled", n->xmlChildrenNode))) - o->sn = parse_bool(doc, m); - if ((m = parse_find_node("name", n->xmlChildrenNode))) - o->sn_name = parse_string(doc, m); - if ((m = parse_find_node("icon", n->xmlChildrenNode))) - o->sn_icon = parse_string(doc, m); - if ((m = parse_find_node("wmclass", n->xmlChildrenNode))) - o->sn_wmclass = parse_string(doc, m); + if ((m = obt_parse_find_node(n->children, "enabled"))) + o->sn = obt_parse_node_bool(m); + if ((m = obt_parse_find_node(n->children, "name"))) + o->sn_name = obt_parse_node_string(m); + if ((m = obt_parse_find_node(n->children, "icon"))) + o->sn_icon = obt_parse_node_string(m); + if ((m = obt_parse_find_node(n->children, "wmclass"))) + o->sn_wmclass = obt_parse_node_string(m); } return o; } @@ -110,7 +108,7 @@ static void prompt_cb(ObPrompt *p, gint result, gpointer options) /* Always return FALSE because its not interactive */ static gboolean run_func(ObActionsData *data, gpointer options) { - GError *e = NULL; + GError *e; gchar **argv = NULL; gchar *cmd; Options *o = options; @@ -138,16 +136,80 @@ static gboolean run_func(ObActionsData *data, gpointer options) return FALSE; } + if (data->client) { + gchar *c, *before, *expand; + + /* replace occurances of $pid and $window */ + + expand = NULL; + before = cmd; + + while ((c = strchr(before, '$'))) { + if ((c[1] == 'p' || c[1] == 'P') && + (c[2] == 'i' || c[2] == 'I') && + (c[3] == 'd' || c[3] == 'D') && + !g_ascii_isalnum(c[4])) + { + /* found $pid */ + gchar *tmp; + + *c = '\0'; + tmp = expand; + expand = g_strdup_printf("%s%s%u", + (expand ? expand : ""), + before, + data->client->pid); + g_free(tmp); + + before = c + 4; /* 4 = strlen("$pid") */ + } + + if ((c[1] == 'w' || c[1] == 'W') && + (c[2] == 'i' || c[2] == 'I') && + (c[3] == 'd' || c[3] == 'D') && + !g_ascii_isalnum(c[7])) + { + /* found $window */ + gchar *tmp; + + *c = '\0'; + tmp = expand; + expand = g_strdup_printf("%s%s%lu", + (expand ? expand : ""), + before, + data->client->window); + g_free(tmp); + + before = c + 7; /* 4 = strlen("$window") */ + } + } + + if (expand) { + gchar *tmp; + + /* add on the end of the string after the last replacement */ + tmp = expand; + expand = g_strconcat(expand, before, NULL); + g_free(tmp); + + /* replace the command with the expanded one */ + g_free(cmd); + cmd = expand; + } + } + /* If there is a keyboard grab going on then we need to cancel it so the application can grab things */ event_cancel_all_key_grabs(); + e = NULL; if (!g_shell_parse_argv(cmd, NULL, &argv, &e)) { g_message(_("Failed to execute \"%s\": %s"), o->cmd, e->message); g_error_free(e); } else { gchar *program = NULL; + gboolean ok; if (o->sn) { program = g_path_get_basename(argv[0]); @@ -158,18 +220,21 @@ static gboolean run_func(ObActionsData *data, gpointer options) screen_desktop); } - if (!g_spawn_async(NULL, argv, NULL, - G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, - NULL, NULL, NULL, &e)) - { - g_message(_("Failed to execute \"%s\": %s"), o->cmd, e->message); + e = NULL; + ok = g_spawn_async(NULL, argv, NULL, + G_SPAWN_SEARCH_PATH | + G_SPAWN_DO_NOT_REAP_CHILD, + NULL, NULL, NULL, &e); + if (!ok) { + g_message(_("Failed to execute \"%s\": %s"), + o->cmd, e->message); g_error_free(e); - - if (o->sn) - sn_spawn_cancel(); } - if (o->sn) + + if (o->sn) { + if (!ok) sn_spawn_cancel(); unsetenv("DESKTOP_STARTUP_ID"); + } g_free(program); g_strfreev(argv); diff --git a/openbox/actions/exit.c b/openbox/actions/exit.c index 747514f..25fc08b 100644 --- a/openbox/actions/exit.c +++ b/openbox/actions/exit.c @@ -7,7 +7,7 @@ typedef struct { gboolean prompt; } Options; -static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node); +static gpointer setup_func(xmlNodePtr node); static gboolean run_func(ObActionsData *data, gpointer options); void action_exit_startup(void) @@ -15,7 +15,7 @@ void action_exit_startup(void) actions_register("Exit", setup_func, NULL, run_func, NULL, NULL); } -static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node) +static gpointer setup_func(xmlNodePtr node) { xmlNodePtr n; Options *o; @@ -23,8 +23,8 @@ static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node) o = g_new0(Options, 1); o->prompt = TRUE; - if ((n = parse_find_node("prompt", node))) - o->prompt = parse_bool(doc, n); + if ((n = obt_parse_find_node(node, "prompt"))) + o->prompt = obt_parse_node_bool(n); return o; } diff --git a/openbox/actions/focus.c b/openbox/actions/focus.c index 0ef9d26..4d0f220 100644 --- a/openbox/actions/focus.c +++ b/openbox/actions/focus.c @@ -7,38 +7,26 @@ typedef struct { gboolean here; } Options; -static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node); -static void free_func(gpointer options); +static gpointer setup_func(xmlNodePtr node); static gboolean run_func(ObActionsData *data, gpointer options); void action_focus_startup(void) { - actions_register("Focus", - setup_func, - free_func, - run_func, - NULL, NULL); + actions_register("Focus", setup_func, g_free, run_func, NULL, NULL); } -static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node) +static gpointer setup_func(xmlNodePtr node) { xmlNodePtr n; Options *o; o = g_new0(Options, 1); - if ((n = parse_find_node("here", node))) - o->here = parse_bool(doc, n); + if ((n = obt_parse_find_node(node, "here"))) + o->here = obt_parse_node_bool(n); return o; } -static void free_func(gpointer options) -{ - Options *o = options; - - g_free(o); -} - /* Always return FALSE because its not interactive */ static gboolean run_func(ObActionsData *data, gpointer options) { diff --git a/openbox/actions/growtoedge.c b/openbox/actions/growtoedge.c index 69b8ef7..a37e3a2 100644 --- a/openbox/actions/growtoedge.c +++ b/openbox/actions/growtoedge.c @@ -7,31 +7,32 @@ typedef struct { ObDirection dir; + gboolean shrink; } Options; -static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node); -static void free_func(gpointer options); +static gpointer setup_func(xmlNodePtr node); +static gpointer setup_shrink_func(xmlNodePtr node); static gboolean run_func(ObActionsData *data, gpointer options); void action_growtoedge_startup(void) { - actions_register("GrowToEdge", - setup_func, - free_func, - run_func, - NULL, NULL); + actions_register("GrowToEdge", setup_func, + g_free, run_func, NULL, NULL); + actions_register("ShrinkToEdge", setup_shrink_func, + g_free, run_func, NULL, NULL); } -static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node) +static gpointer setup_func(xmlNodePtr node) { xmlNodePtr n; Options *o; o = g_new0(Options, 1); o->dir = OB_DIRECTION_NORTH; + o->shrink = FALSE; - if ((n = parse_find_node("direction", node))) { - gchar *s = parse_string(doc, n); + if ((n = obt_parse_find_node(node, "direction"))) { + gchar *s = obt_parse_node_string(n); if (!g_ascii_strcasecmp(s, "north") || !g_ascii_strcasecmp(s, "up")) o->dir = OB_DIRECTION_NORTH; @@ -50,11 +51,14 @@ static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node) return o; } -static void free_func(gpointer options) +static gpointer setup_shrink_func(xmlNodePtr node) { - Options *o = options; + Options *o; - g_free(o); + o = setup_func(node); + o->shrink = TRUE; + + return o; } static gboolean do_grow(ObActionsData *data, gint x, gint y, gint w, gint h) @@ -98,11 +102,13 @@ static gboolean run_func(ObActionsData *data, gpointer options) return FALSE; } - /* try grow */ - client_find_resize_directional(data->client, o->dir, TRUE, - &x, &y, &w, &h); - if (do_grow(data, x, y, w, h)) - return FALSE; + if (!o->shrink) { + /* try grow */ + client_find_resize_directional(data->client, o->dir, TRUE, + &x, &y, &w, &h); + if (do_grow(data, x, y, w, h)) + return FALSE; + } /* we couldn't grow, so try shrink! */ opp = (o->dir == OB_DIRECTION_NORTH ? OB_DIRECTION_SOUTH : diff --git a/openbox/actions/if.c b/openbox/actions/if.c index 4c98966..833bdd3 100644 --- a/openbox/actions/if.c +++ b/openbox/actions/if.c @@ -23,81 +23,77 @@ typedef struct { GSList *elseacts; } Options; -static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node); +static gpointer setup_func(xmlNodePtr node); static void free_func(gpointer options); static gboolean run_func(ObActionsData *data, gpointer options); void action_if_startup(void) { - actions_register("If", - setup_func, - free_func, - run_func, - NULL, NULL); + actions_register("If", setup_func, free_func, run_func, NULL, NULL); } -static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node) +static gpointer setup_func(xmlNodePtr node) { xmlNodePtr n; Options *o; o = g_new0(Options, 1); - if ((n = parse_find_node("shaded", node))) { - if (parse_bool(doc, n)) + if ((n = obt_parse_find_node(node, "shaded"))) { + if (obt_parse_node_bool(n)) o->shaded_on = TRUE; else o->shaded_off = TRUE; } - if ((n = parse_find_node("maximized", node))) { - if (parse_bool(doc, n)) + if ((n = obt_parse_find_node(node, "maximized"))) { + if (obt_parse_node_bool(n)) o->maxfull_on = TRUE; else o->maxfull_off = TRUE; } - if ((n = parse_find_node("maximizedhorizontal", node))) { - if (parse_bool(doc, n)) + if ((n = obt_parse_find_node(node, "maximizedhorizontal"))) { + if (obt_parse_node_bool(n)) o->maxhorz_on = TRUE; else o->maxhorz_off = TRUE; } - if ((n = parse_find_node("maximizedvertical", node))) { - if (parse_bool(doc, n)) + if ((n = obt_parse_find_node(node, "maximizedvertical"))) { + if (obt_parse_node_bool(n)) o->maxvert_on = TRUE; else o->maxvert_off = TRUE; } - if ((n = parse_find_node("iconified", node))) { - if (parse_bool(doc, n)) + if ((n = obt_parse_find_node(node, "iconified"))) { + if (obt_parse_node_bool(n)) o->iconic_on = TRUE; else o->iconic_off = TRUE; } - if ((n = parse_find_node("focused", node))) { - if (parse_bool(doc, n)) + if ((n = obt_parse_find_node(node, "focused"))) { + if (obt_parse_node_bool(n)) o->focused = TRUE; else o->unfocused = TRUE; } - if ((n = parse_find_node("then", node))) { + if ((n = obt_parse_find_node(node, "then"))) { xmlNodePtr m; - m = parse_find_node("action", n->xmlChildrenNode); + m = obt_parse_find_node(n->children, "action"); while (m) { - ObActionsAct *action = actions_parse(i, doc, m); + ObActionsAct *action = actions_parse(m); if (action) o->thenacts = g_slist_append(o->thenacts, action); - m = parse_find_node("action", m->next); + m = obt_parse_find_node(m->next, "action"); } } - if ((n = parse_find_node("else", node))) { + if ((n = obt_parse_find_node(node, "else"))) { xmlNodePtr m; - m = parse_find_node("action", n->xmlChildrenNode); + m = obt_parse_find_node(n->children, "action"); while (m) { - ObActionsAct *action = actions_parse(i, doc, m); + ObActionsAct *action = actions_parse(m); if (action) o->elseacts = g_slist_append(o->elseacts, action); - m = parse_find_node("action", m->next); + m = obt_parse_find_node(m->next, "action"); } } @@ -108,6 +104,15 @@ static void free_func(gpointer options) { Options *o = options; + while (o->thenacts) { + actions_act_unref(o->thenacts->data); + o->thenacts = g_slist_delete_link(o->thenacts, o->thenacts); + } + while (o->elseacts) { + actions_act_unref(o->elseacts->data); + o->elseacts = g_slist_delete_link(o->elseacts, o->elseacts); + } + g_free(o); } diff --git a/openbox/actions/layer.c b/openbox/actions/layer.c index 92fa480..bbfda57 100644 --- a/openbox/actions/layer.c +++ b/openbox/actions/layer.c @@ -6,11 +6,9 @@ typedef struct { gboolean toggle; } Options; -static gpointer setup_func_top(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node); -static gpointer setup_func_bottom(ObParseInst *i, xmlDocPtr doc, - xmlNodePtr node); -static gpointer setup_func_send(ObParseInst *i, xmlDocPtr doc, - xmlNodePtr node); +static gpointer setup_func_top(xmlNodePtr node); +static gpointer setup_func_bottom(xmlNodePtr node); +static gpointer setup_func_send(xmlNodePtr node); static gboolean run_func(ObActionsData *data, gpointer options); void action_layer_startup(void) @@ -23,7 +21,7 @@ void action_layer_startup(void) run_func, NULL, NULL); } -static gpointer setup_func_top(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node) +static gpointer setup_func_top(xmlNodePtr node) { Options *o = g_new0(Options, 1); o->layer = 1; @@ -31,8 +29,7 @@ static gpointer setup_func_top(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node) return o; } -static gpointer setup_func_bottom(ObParseInst *i, xmlDocPtr doc, - xmlNodePtr node) +static gpointer setup_func_bottom(xmlNodePtr node) { Options *o = g_new0(Options, 1); o->layer = -1; @@ -40,16 +37,15 @@ static gpointer setup_func_bottom(ObParseInst *i, xmlDocPtr doc, return o; } -static gpointer setup_func_send(ObParseInst *i, xmlDocPtr doc, - xmlNodePtr node) +static gpointer setup_func_send(xmlNodePtr node) { xmlNodePtr n; Options *o; o = g_new0(Options, 1); - if ((n = parse_find_node("layer", node))) { - gchar *s = parse_string(doc, n); + if ((n = obt_parse_find_node(node, "layer"))) { + gchar *s = obt_parse_node_string(n); if (!g_ascii_strcasecmp(s, "above") || !g_ascii_strcasecmp(s, "top")) o->layer = 1; diff --git a/openbox/actions/maximize.c b/openbox/actions/maximize.c index bb6f470..45e8b38 100644 --- a/openbox/actions/maximize.c +++ b/openbox/actions/maximize.c @@ -12,7 +12,7 @@ typedef struct { MaxDirection dir; } Options; -static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node); +static gpointer setup_func(xmlNodePtr node); static gboolean run_func_on(ObActionsData *data, gpointer options); static gboolean run_func_off(ObActionsData *data, gpointer options); static gboolean run_func_toggle(ObActionsData *data, gpointer options); @@ -27,7 +27,7 @@ void action_maximize_startup(void) NULL, NULL); } -static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node) +static gpointer setup_func(xmlNodePtr node) { xmlNodePtr n; Options *o; @@ -35,8 +35,8 @@ static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node) o = g_new0(Options, 1); o->dir = BOTH; - if ((n = parse_find_node("direction", node))) { - gchar *s = parse_string(doc, n); + if ((n = obt_parse_find_node(node, "direction"))) { + gchar *s = obt_parse_node_string(n); if (!g_ascii_strcasecmp(s, "vertical") || !g_ascii_strcasecmp(s, "vert")) o->dir = VERT; diff --git a/openbox/actions/move.c b/openbox/actions/move.c index 1a8ea20..ddd3f59 100644 --- a/openbox/actions/move.c +++ b/openbox/actions/move.c @@ -1,6 +1,6 @@ #include "openbox/actions.h" -#include "openbox/prop.h" #include "openbox/moveresize.h" +#include "obt/prop.h" static gboolean run_func(ObActionsData *data, gpointer options); @@ -19,8 +19,8 @@ static gboolean run_func(ObActionsData *data, gpointer options) guint32 corner; corner = data->button != 0 ? - prop_atoms.net_wm_moveresize_move : - prop_atoms.net_wm_moveresize_move_keyboard; + OBT_PROP_ATOM(NET_WM_MOVERESIZE_MOVE) : + OBT_PROP_ATOM(NET_WM_MOVERESIZE_MOVE_KEYBOARD); moveresize_start(data->client, data->x, data->y, data->button, corner); } diff --git a/openbox/actions/moverelative.c b/openbox/actions/moverelative.c index 1d1189c..ccdff54 100644 --- a/openbox/actions/moverelative.c +++ b/openbox/actions/moverelative.c @@ -9,41 +9,29 @@ typedef struct { gint y; } Options; -static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node); -static void free_func(gpointer options); +static gpointer setup_func(xmlNodePtr node); static gboolean run_func(ObActionsData *data, gpointer options); void action_moverelative_startup(void) { - actions_register("MoveRelative", - setup_func, - free_func, - run_func, - NULL, NULL); + actions_register("MoveRelative", setup_func, g_free, run_func, NULL, NULL); } -static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node) +static gpointer setup_func(xmlNodePtr node) { xmlNodePtr n; Options *o; o = g_new0(Options, 1); - if ((n = parse_find_node("x", node))) - o->x = parse_int(doc, n); - if ((n = parse_find_node("y", node))) - o->y = parse_int(doc, n); + if ((n = obt_parse_find_node(node, "x"))) + o->x = obt_parse_node_int(n); + if ((n = obt_parse_find_node(node, "y"))) + o->y = obt_parse_node_int(n); return o; } -static void free_func(gpointer options) -{ - Options *o = options; - - g_free(o); -} - /* Always return FALSE because its not interactive */ static gboolean run_func(ObActionsData *data, gpointer options) { diff --git a/openbox/actions/moveresizeto.c b/openbox/actions/moveresizeto.c index cdd772a..357c731 100644 --- a/openbox/actions/moveresizeto.c +++ b/openbox/actions/moveresizeto.c @@ -21,23 +21,18 @@ typedef struct { gint monitor; } Options; -static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node); -static void free_func(gpointer options); +static gpointer setup_func(xmlNodePtr node); static gboolean run_func(ObActionsData *data, gpointer options); void action_moveresizeto_startup(void) { - actions_register("MoveResizeTo", - setup_func, - free_func, - run_func, - NULL, NULL); + actions_register("MoveResizeTo", setup_func, g_free, run_func, NULL, NULL); } -static void parse_coord(xmlDocPtr doc, xmlNodePtr n, gint *pos, +static void parse_coord(xmlNodePtr n, gint *pos, gboolean *opposite, gboolean *center) { - gchar *s = parse_string(doc, n); + gchar *s = obt_parse_node_string(n); if (g_ascii_strcasecmp(s, "current") != 0) { if (!g_ascii_strcasecmp(s, "center")) *center = TRUE; @@ -53,7 +48,7 @@ static void parse_coord(xmlDocPtr doc, xmlNodePtr n, gint *pos, g_free(s); } -static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node) +static gpointer setup_func(xmlNodePtr node) { xmlNodePtr n; Options *o; @@ -65,32 +60,32 @@ static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node) o->h = G_MININT; o->monitor = CURRENT_MONITOR; - if ((n = parse_find_node("x", node))) - parse_coord(doc, n, &o->x, &o->xopposite, &o->xcenter); + if ((n = obt_parse_find_node(node, "x"))) + parse_coord(n, &o->x, &o->xopposite, &o->xcenter); - if ((n = parse_find_node("y", node))) - parse_coord(doc, n, &o->y, &o->yopposite, &o->ycenter); + if ((n = obt_parse_find_node(node, "y"))) + parse_coord(n, &o->y, &o->yopposite, &o->ycenter); - if ((n = parse_find_node("width", node))) { - gchar *s = parse_string(doc, n); + if ((n = obt_parse_find_node(node, "width"))) { + gchar *s = obt_parse_node_string(n); if (g_ascii_strcasecmp(s, "current") != 0) - o->w = parse_int(doc, n); + o->w = obt_parse_node_int(n); g_free(s); } - if ((n = parse_find_node("height", node))) { - gchar *s = parse_string(doc, n); + if ((n = obt_parse_find_node(node, "height"))) { + gchar *s = obt_parse_node_string(n); if (g_ascii_strcasecmp(s, "current") != 0) - o->h = parse_int(doc, n); + o->h = obt_parse_node_int(n); g_free(s); } - if ((n = parse_find_node("monitor", node))) { - gchar *s = parse_string(doc, n); + if ((n = obt_parse_find_node(node, "monitor"))) { + gchar *s = obt_parse_node_string(n); if (g_ascii_strcasecmp(s, "current") != 0) { if (!g_ascii_strcasecmp(s, "all")) o->monitor = ALL_MONITORS; else - o->monitor = parse_int(doc, n) - 1; + o->monitor = obt_parse_node_int(n) - 1; } g_free(s); } @@ -98,13 +93,6 @@ static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node) return o; } -static void free_func(gpointer options) -{ - Options *o = options; - - g_free(o); -} - /* Always return FALSE because its not interactive */ static gboolean run_func(ObActionsData *data, gpointer options) { diff --git a/openbox/actions/movetoedge.c b/openbox/actions/movetoedge.c index 5941bde..f360ddd 100644 --- a/openbox/actions/movetoedge.c +++ b/openbox/actions/movetoedge.c @@ -9,20 +9,15 @@ typedef struct { ObDirection dir; } Options; -static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node); -static void free_func(gpointer options); +static gpointer setup_func(xmlNodePtr node); static gboolean run_func(ObActionsData *data, gpointer options); void action_movetoedge_startup(void) { - actions_register("MoveToEdge", - setup_func, - free_func, - run_func, - NULL, NULL); + actions_register("MoveToEdge", setup_func, g_free, run_func, NULL, NULL); } -static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node) +static gpointer setup_func(xmlNodePtr node) { xmlNodePtr n; Options *o; @@ -30,8 +25,8 @@ static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node) o = g_new0(Options, 1); o->dir = OB_DIRECTION_NORTH; - if ((n = parse_find_node("direction", node))) { - gchar *s = parse_string(doc, n); + if ((n = obt_parse_find_node(node, "direction"))) { + gchar *s = obt_parse_node_string(n); if (!g_ascii_strcasecmp(s, "north") || !g_ascii_strcasecmp(s, "up")) o->dir = OB_DIRECTION_NORTH; @@ -50,13 +45,6 @@ static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node) return o; } -static void free_func(gpointer options) -{ - Options *o = options; - - g_free(o); -} - /* Always return FALSE because its not interactive */ static gboolean run_func(ObActionsData *data, gpointer options) { diff --git a/openbox/actions/resize.c b/openbox/actions/resize.c index 3714e38..47f45f5 100644 --- a/openbox/actions/resize.c +++ b/openbox/actions/resize.c @@ -1,16 +1,15 @@ #include "openbox/actions.h" -#include "openbox/prop.h" #include "openbox/moveresize.h" #include "openbox/client.h" #include "openbox/frame.h" +#include "obt/prop.h" typedef struct { gboolean corner_specified; guint32 corner; } Options; -static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node); -static void free_func(gpointer options); +static gpointer setup_func(xmlNodePtr node); static gboolean run_func(ObActionsData *data, gpointer options); static guint32 pick_corner(gint x, gint y, gint cx, gint cy, gint cw, gint ch, @@ -18,40 +17,36 @@ static guint32 pick_corner(gint x, gint y, gint cx, gint cy, gint cw, gint ch, void action_resize_startup(void) { - actions_register("Resize", - setup_func, - free_func, - run_func, - NULL, NULL); + actions_register("Resize", setup_func, g_free, run_func, NULL, NULL); } -static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node) +static gpointer setup_func(xmlNodePtr node) { xmlNodePtr n; Options *o; o = g_new0(Options, 1); - if ((n = parse_find_node("edge", node))) { - gchar *s = parse_string(doc, n); + if ((n = obt_parse_find_node(node, "edge"))) { + gchar *s = obt_parse_node_string(n); o->corner_specified = TRUE; if (!g_ascii_strcasecmp(s, "top")) - o->corner = prop_atoms.net_wm_moveresize_size_top; + o->corner = OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOP); else if (!g_ascii_strcasecmp(s, "bottom")) - o->corner = prop_atoms.net_wm_moveresize_size_bottom; + o->corner = OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOM); else if (!g_ascii_strcasecmp(s, "left")) - o->corner = prop_atoms.net_wm_moveresize_size_left; + o->corner = OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_LEFT); else if (!g_ascii_strcasecmp(s, "right")) - o->corner = prop_atoms.net_wm_moveresize_size_right; + o->corner = OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_RIGHT); else if (!g_ascii_strcasecmp(s, "topleft")) - o->corner = prop_atoms.net_wm_moveresize_size_topleft; + o->corner = OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOPLEFT); else if (!g_ascii_strcasecmp(s, "topright")) - o->corner = prop_atoms.net_wm_moveresize_size_topright; + o->corner = OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOPRIGHT); else if (!g_ascii_strcasecmp(s, "bottomleft")) - o->corner = prop_atoms.net_wm_moveresize_size_bottomleft; + o->corner = OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT); else if (!g_ascii_strcasecmp(s, "bottomright")) - o->corner = prop_atoms.net_wm_moveresize_size_bottomright; + o->corner = OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT); else o->corner_specified = FALSE; @@ -60,13 +55,6 @@ static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node) return o; } -static void free_func(gpointer options) -{ - Options *o = options; - - g_free(o); -} - /* Always return FALSE because its not interactive */ static gboolean run_func(ObActionsData *data, gpointer options) { @@ -77,7 +65,7 @@ static gboolean run_func(ObActionsData *data, gpointer options) guint32 corner; if (!data->button) - corner = prop_atoms.net_wm_moveresize_size_keyboard; + corner = OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_KEYBOARD); else if (o->corner_specified) corner = o->corner; /* it was specified in the binding */ else @@ -163,30 +151,30 @@ static guint32 pick_corner(gint x, gint y, gint cx, gint cy, gint cw, gint ch, if (shaded) { /* for shaded windows, you can only resize west/east and move */ if (b) - return prop_atoms.net_wm_moveresize_size_left; + return OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_LEFT); if (c) - return prop_atoms.net_wm_moveresize_size_right; - return prop_atoms.net_wm_moveresize_move; + return OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_RIGHT); + return OBT_PROP_ATOM(NET_WM_MOVERESIZE_MOVE); } if (y < A && y >= C) - return prop_atoms.net_wm_moveresize_size_topleft; + return OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOPLEFT); else if (y >= A && y >= B && a) - return prop_atoms.net_wm_moveresize_size_top; + return OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOP); else if (y < B && y >= D) - return prop_atoms.net_wm_moveresize_size_topright; + return OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOPRIGHT); else if (y < C && y >= E && b) - return prop_atoms.net_wm_moveresize_size_left; + return OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_LEFT); else if (y < D && y >= F && c) - return prop_atoms.net_wm_moveresize_size_right; + return OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_RIGHT); else if (y < E && y >= G) - return prop_atoms.net_wm_moveresize_size_bottomleft; + return OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT); else if (y < G && y < H && d) - return prop_atoms.net_wm_moveresize_size_bottom; + return OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOM); else if (y >= H && y < F) - return prop_atoms.net_wm_moveresize_size_bottomright; + return OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT); else - return prop_atoms.net_wm_moveresize_move; + return OBT_PROP_ATOM(NET_WM_MOVERESIZE_MOVE); #undef X #undef A diff --git a/openbox/actions/resizerelative.c b/openbox/actions/resizerelative.c index f705c29..5742e1f 100644 --- a/openbox/actions/resizerelative.c +++ b/openbox/actions/resizerelative.c @@ -11,47 +11,36 @@ typedef struct { gint bottom; } Options; -static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node); -static void free_func(gpointer options); +static gpointer setup_func(xmlNodePtr node); static gboolean run_func(ObActionsData *data, gpointer options); void action_resizerelative_startup(void) { - actions_register("ResizeRelative", - setup_func, - free_func, - run_func, + actions_register("ResizeRelative", setup_func, g_free, run_func, NULL, NULL); } -static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node) +static gpointer setup_func(xmlNodePtr node) { xmlNodePtr n; Options *o; o = g_new0(Options, 1); - if ((n = parse_find_node("left", node))) - o->left = parse_int(doc, n); - if ((n = parse_find_node("right", node))) - o->right = parse_int(doc, n); - if ((n = parse_find_node("top", node)) || - (n = parse_find_node("up", node))) - o->top = parse_int(doc, n); - if ((n = parse_find_node("bottom", node)) || - (n = parse_find_node("down", node))) - o->bottom = parse_int(doc, n); + if ((n = obt_parse_find_node(node, "left"))) + o->left = obt_parse_node_int(n); + if ((n = obt_parse_find_node(node, "right"))) + o->right = obt_parse_node_int(n); + if ((n = obt_parse_find_node(node, "top")) || + (n = obt_parse_find_node(node, "up"))) + o->top = obt_parse_node_int(n); + if ((n = obt_parse_find_node(node, "bottom")) || + (n = obt_parse_find_node(node, "down"))) + o->bottom = obt_parse_node_int(n); return o; } -static void free_func(gpointer options) -{ - Options *o = options; - - g_free(o); -} - /* Always return FALSE because its not interactive */ static gboolean run_func(ObActionsData *data, gpointer options) { diff --git a/openbox/actions/restart.c b/openbox/actions/restart.c index 4b52f9d..47f332b 100644 --- a/openbox/actions/restart.c +++ b/openbox/actions/restart.c @@ -1,35 +1,32 @@ #include "openbox/actions.h" #include "openbox/openbox.h" +#include "obt/paths.h" typedef struct { gchar *cmd; } Options; -static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node); +static gpointer setup_func(xmlNodePtr node); static void free_func(gpointer options); static gboolean run_func(ObActionsData *data, gpointer options); void action_restart_startup(void) { - actions_register("Restart", - setup_func, - free_func, - run_func, - NULL, NULL); + actions_register("Restart", setup_func, free_func, run_func, NULL, NULL); } -static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node) +static gpointer setup_func(xmlNodePtr node) { xmlNodePtr n; Options *o; o = g_new0(Options, 1); - if ((n = parse_find_node("command", node)) || - (n = parse_find_node("execute", node))) + if ((n = obt_parse_find_node(node, "command")) || + (n = obt_parse_find_node(node, "execute"))) { - gchar *s = parse_string(doc, n); - o->cmd = parse_expand_tilde(s); + gchar *s = obt_parse_node_string(n); + o->cmd = obt_paths_expand_tilde(s); g_free(s); } return o; @@ -38,11 +35,8 @@ static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node) static void free_func(gpointer options) { Options *o = options; - - if (o) { - g_free(o->cmd); - g_free(o); - } + g_free(o->cmd); + g_free(o); } /* Always return FALSE because its not interactive */ diff --git a/openbox/actions/session.c b/openbox/actions/session.c index 0117e07..cfc5e37 100644 --- a/openbox/actions/session.c +++ b/openbox/actions/session.c @@ -12,7 +12,7 @@ typedef struct { gboolean silent; } Options; -static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node); +static gpointer setup_func(xmlNodePtr node); static gboolean logout_func(ObActionsData *data, gpointer options); void action_session_startup(void) @@ -21,7 +21,7 @@ void action_session_startup(void) NULL, NULL); } -static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node) +static gpointer setup_func(xmlNodePtr node) { xmlNodePtr n; Options *o; @@ -29,8 +29,8 @@ static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node) o = g_new0(Options, 1); o->prompt = TRUE; - if ((n = parse_find_node("prompt", node))) - o->prompt = parse_bool(doc, n); + if ((n = obt_parse_find_node(node, "prompt"))) + o->prompt = obt_parse_node_bool(n); return o; } diff --git a/openbox/actions/showmenu.c b/openbox/actions/showmenu.c index c1d53e4..9590bd1 100644 --- a/openbox/actions/showmenu.c +++ b/openbox/actions/showmenu.c @@ -6,7 +6,7 @@ typedef struct { gchar *name; } Options; -static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node); +static gpointer setup_func(xmlNodePtr node); static void free_func(gpointer options); static gboolean run_func(ObActionsData *data, gpointer options); @@ -16,15 +16,15 @@ void action_showmenu_startup(void) NULL, NULL); } -static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node) +static gpointer setup_func(xmlNodePtr node) { xmlNodePtr n; Options *o; o = g_new0(Options, 1); - if ((n = parse_find_node("menu", node))) - o->name = parse_string(doc, n); + if ((n = obt_parse_find_node(node, "menu"))) + o->name = obt_parse_node_string(n); return o; } diff --git a/openbox/client.c b/openbox/client.c index 816fa92..c0864bc 100644 --- a/openbox/client.c +++ b/openbox/client.c @@ -21,13 +21,10 @@ #include "debug.h" #include "startupnotify.h" #include "dock.h" -#include "xerror.h" #include "screen.h" #include "moveresize.h" #include "ping.h" #include "place.h" -#include "prop.h" -#include "extensions.h" #include "frame.h" #include "session.h" #include "event.h" @@ -36,6 +33,7 @@ #include "focus.h" #include "stacking.h" #include "openbox.h" +#include "hooks.h" #include "group.h" #include "config.h" #include "menuframe.h" @@ -43,6 +41,8 @@ #include "mouse.h" #include "render/render.h" #include "gettext.h" +#include "obt/display.h" +#include "obt/prop.h" #ifdef HAVE_UNISTD_H # include @@ -185,8 +185,8 @@ void client_set_list(void) } else windows = NULL; - PROP_SETA32(RootWindow(ob_display, ob_screen), - net_client_list, window, (gulong*)windows, size); + OBT_PROP_SETA32(obt_root(ob_screen), NET_CLIENT_LIST, WINDOW, + (gulong*)windows, size); if (windows) g_free(windows); @@ -194,97 +194,17 @@ void client_set_list(void) stacking_set_list(); } -void client_manage_all(void) -{ - guint i, j, nchild; - Window w, *children; - XWMHints *wmhints; - XWindowAttributes attrib; - - XQueryTree(ob_display, RootWindow(ob_display, ob_screen), - &w, &w, &children, &nchild); - - /* remove all icon windows from the list */ - for (i = 0; i < nchild; i++) { - if (children[i] == None) continue; - wmhints = XGetWMHints(ob_display, children[i]); - if (wmhints) { - if ((wmhints->flags & IconWindowHint) && - (wmhints->icon_window != children[i])) - for (j = 0; j < nchild; j++) - if (children[j] == wmhints->icon_window) { - children[j] = None; - break; - } - XFree(wmhints); - } - } - - /* manage windows in reverse order from how they were originally mapped. - this is an attempt to manage children windows before their parents, so - that when the parent is mapped, it can find the child */ - for (i = 0; i < nchild; ++i) { - if (children[i] == None) - continue; - if (XGetWindowAttributes(ob_display, children[i], &attrib)) { - if (attrib.override_redirect) continue; - - if (attrib.map_state != IsUnmapped) - client_manage(children[i], NULL); - } - } - XFree(children); -} - void client_manage(Window window, ObPrompt *prompt) { ObClient *self; - XEvent e; - XWindowAttributes attrib; XSetWindowAttributes attrib_set; - XWMHints *wmhint; gboolean activate = FALSE; ObAppSettings *settings; gboolean transient = FALSE; Rect place, *monitor; Time launch_time, map_time; - grab_server(TRUE); - - /* check if it has already been unmapped by the time we started - mapping. the grab does a sync so we don't have to here */ - if (XCheckTypedWindowEvent(ob_display, window, DestroyNotify, &e) || - XCheckTypedWindowEvent(ob_display, window, UnmapNotify, &e)) - { - XPutBackEvent(ob_display, &e); - - ob_debug("Trying to manage unmapped window. Aborting that.\n"); - grab_server(FALSE); - return; /* don't manage it */ - } - - /* make sure it isn't an override-redirect window */ - if (!XGetWindowAttributes(ob_display, window, &attrib) || - attrib.override_redirect) - { - grab_server(FALSE); - return; /* don't manage it */ - } - - /* is the window a docking app */ - if ((wmhint = XGetWMHints(ob_display, window))) { - if ((wmhint->flags & StateHint) && - wmhint->initial_state == WithdrawnState) - { - dock_add(window, wmhint); - grab_server(FALSE); - XFree(wmhint); - return; - } - XFree(wmhint); - } - - ob_debug("Managing window: 0x%lx\n", window); + ob_debug("Managing window: 0x%lx", window); map_time = event_get_server_time(); @@ -293,13 +213,13 @@ void client_manage(Window window, ObPrompt *prompt) attrib_set.event_mask = CLIENT_EVENTMASK | (prompt ? prompt->event_mask : 0); attrib_set.do_not_propagate_mask = CLIENT_NOPROPAGATEMASK; - XChangeWindowAttributes(ob_display, window, + XChangeWindowAttributes(obt_display, window, CWEventMask|CWDontPropagate, &attrib_set); /* create the ObClient struct, and populate it from the hints on the window */ self = g_new0(ObClient, 1); - self->obwin.type = Window_Client; + self->obwin.type = OB_WINDOW_CLASS_CLIENT; self->window = window; self->prompt = prompt; @@ -311,8 +231,8 @@ void client_manage(Window window, ObPrompt *prompt) /* get all the stuff off the window */ client_get_all(self, TRUE); - ob_debug("Window type: %d\n", self->type); - ob_debug("Window group: 0x%x\n", self->group?self->group->leader:0); + ob_debug("Window type: %d", self->type); + ob_debug("Window group: 0x%x", self->group?self->group->leader:0); /* now we have all of the window's information so we can set this up. do this before creating the frame, so it can tell that we are still @@ -323,7 +243,7 @@ void client_manage(Window window, ObPrompt *prompt) should be reparented back to root automatically, unless we are managing an internal ObPrompt window */ if (!self->prompt) - XChangeSaveSet(ob_display, window, SetModeInsert); + XChangeSaveSet(obt_display, window, SetModeInsert); /* create the decoration frame for the client window */ self->frame = frame_new(self); @@ -368,7 +288,7 @@ void client_manage(Window window, ObPrompt *prompt) } /* remove the client's border */ - XSetWindowBorderWidth(ob_display, self->window, 0); + XSetWindowBorderWidth(obt_display, self->window, 0); /* adjust the frame to the client's size before showing or placing the window */ @@ -381,7 +301,7 @@ void client_manage(Window window, ObPrompt *prompt) /* figure out placement for the window if the window is new */ if (ob_state() == OB_STATE_RUNNING) { - ob_debug("Positioned: %s @ %d %d\n", + ob_debug("Positioned: %s @ %d %d", (!self->positioned ? "no" : (self->positioned == PPosition ? "program specified" : (self->positioned == USPosition ? "user specified" : @@ -389,7 +309,7 @@ void client_manage(Window window, ObPrompt *prompt) "program + user specified" : "BADNESS !?")))), place.x, place.y); - ob_debug("Sized: %s @ %d %d\n", + ob_debug("Sized: %s @ %d %d", (!self->sized ? "no" : (self->sized == PSize ? "program specified" : (self->sized == USSize ? "user specified" : @@ -461,7 +381,7 @@ void client_manage(Window window, ObPrompt *prompt) place.width = MIN(place.width, a->width); place.height = MIN(place.height, a->height); - ob_debug("setting window size to %dx%d\n", place.width, place.height); + ob_debug("setting window size to %dx%d", place.width, place.height); /* get the size of the client back */ place.width -= self->frame->size.left + self->frame->size.right; @@ -471,11 +391,11 @@ void client_manage(Window window, ObPrompt *prompt) } ob_debug("placing window 0x%x at %d, %d with size %d x %d. " - "some restrictions may apply\n", + "some restrictions may apply", self->window, place.x, place.y, place.width, place.height); if (self->session) ob_debug(" but session requested %d, %d %d x %d instead, " - "overriding\n", + "overriding", self->session->x, self->session->y, self->session->w, self->session->h); @@ -490,7 +410,7 @@ void client_manage(Window window, ObPrompt *prompt) g_free(monitor); monitor = NULL; - ob_debug_type(OB_DEBUG_FOCUS, "Going to try activate new window? %s\n", + ob_debug_type(OB_DEBUG_FOCUS, "Going to try activate new window? %s", activate ? "yes" : "no"); if (activate) { gboolean raise = FALSE; @@ -498,7 +418,7 @@ void client_manage(Window window, ObPrompt *prompt) /* This is focus stealing prevention */ ob_debug_type(OB_DEBUG_FOCUS, "Want to focus new window 0x%x at time %u " - "launched at %u (last user interaction time %u)\n", + "launched at %u (last user interaction time %u)", self->window, map_time, launch_time, event_last_user_time); @@ -508,7 +428,7 @@ void client_manage(Window window, ObPrompt *prompt) ob_debug_type(OB_DEBUG_FOCUS, "Not focusing the window because the user is inside " "an Openbox menu or is move/resizing a window and " - "we don't want to interrupt them\n"); + "we don't want to interrupt them"); } /* if it's on another desktop */ @@ -522,7 +442,7 @@ void client_manage(Window window, ObPrompt *prompt) raise = TRUE; ob_debug_type(OB_DEBUG_FOCUS, "Not focusing the window because its on another " - "desktop\n"); + "desktop"); } /* If something is focused, and it's not our relative... */ else if (focus_client && client_search_focus_tree_full(self) == NULL && @@ -539,14 +459,14 @@ void client_manage(Window window, ObPrompt *prompt) activate = FALSE; ob_debug_type(OB_DEBUG_FOCUS, "Not focusing the window because the user is " - "working in another window\n"); + "working in another window"); } /* If it's a transient (and its parents aren't focused) */ else if (client_has_parent(self)) { activate = FALSE; ob_debug_type(OB_DEBUG_FOCUS, "Not focusing the window because it is a " - "transient, and its relatives aren't focused\n"); + "transient, and its relatives aren't focused"); } /* Don't steal focus from globally active clients. I stole this idea from KWin. It seems nice. @@ -557,7 +477,7 @@ void client_manage(Window window, ObPrompt *prompt) activate = FALSE; ob_debug_type(OB_DEBUG_FOCUS, "Not focusing the window because a globally " - "active client has focus\n"); + "active client has focus"); } /* Don't move focus if it's not going to go to this window anyway */ @@ -566,7 +486,7 @@ void client_manage(Window window, ObPrompt *prompt) raise = TRUE; ob_debug_type(OB_DEBUG_FOCUS, "Not focusing the window because another window " - "would get the focus anyway\n"); + "would get the focus anyway"); } else if (!(self->desktop == screen_desktop || self->desktop == DESKTOP_ALL)) @@ -582,7 +502,7 @@ void client_manage(Window window, ObPrompt *prompt) if (!activate) { ob_debug_type(OB_DEBUG_FOCUS, "Focus stealing prevention activated for %s at " - "time %u (last user interaction time %u)\n", + "time %u (last user interaction time %u)", self->title, map_time, event_last_user_time); /* if the client isn't focused, then hilite it so the user knows it is there */ @@ -627,7 +547,7 @@ void client_manage(Window window, ObPrompt *prompt) /* add to client list/map */ client_list = g_list_append(client_list, self); - g_hash_table_insert(window_map, &self->window, self); + window_add(&self->window, CLIENT_AS_WINDOW(self)); /* this has to happen after we're in the client_list */ if (STRUT_EXISTS(self->strut)) @@ -639,10 +559,10 @@ void client_manage(Window window, ObPrompt *prompt) /* free the ObAppSettings shallow copy */ g_free(settings); - ob_debug("Managed window 0x%lx plate 0x%x (%s)\n", + ob_debug("Managed window 0x%lx plate 0x%x (%s)", window, self->frame->window, self->class); - return; + hooks_queue(OB_HOOK_WIN_NEW, self); } @@ -651,7 +571,7 @@ ObClient *client_fake_manage(Window window) ObClient *self; ObAppSettings *settings; - ob_debug("Pretend-managing window: %lx\n", window); + ob_debug("Pretend-managing window: %lx", window); /* do this minimal stuff to figure out the client's decorations */ @@ -669,7 +589,7 @@ ObClient *client_fake_manage(Window window) self->frame = frame_new(self); frame_adjust_area(self->frame, FALSE, TRUE, TRUE); - ob_debug("gave extents left %d right %d top %d bottom %d\n", + ob_debug("gave extents left %d right %d top %d bottom %d", self->frame->size.left, self->frame->size.right, self->frame->size.top, self->frame->size.bottom); @@ -690,7 +610,7 @@ void client_unmanage(ObClient *self) GSList *it; gulong ignore_start; - ob_debug("Unmanaging window: 0x%x plate 0x%x (%s) (%s)\n", + ob_debug("Unmanaging window: 0x%x plate 0x%x (%s) (%s)", self->window, self->frame->window, self->class, self->title ? self->title : ""); @@ -698,7 +618,7 @@ void client_unmanage(ObClient *self) /* we dont want events no more. do this before hiding the frame so we don't generate more events */ - XSelectInput(ob_display, self->window, NoEventMask); + XSelectInput(obt_display, self->window, NoEventMask); /* ignore enter events from the unmap so it doesnt mess with the focus */ if (!config_focus_under_mouse) @@ -706,7 +626,7 @@ void client_unmanage(ObClient *self) frame_hide(self->frame); /* flush to send the hide to the server quickly */ - XFlush(ob_display); + XFlush(obt_display); if (!config_focus_under_mouse) event_end_ignore_all_enters(ignore_start); @@ -716,7 +636,10 @@ void client_unmanage(ObClient *self) /* remove the window from our save set, unless we are managing an internal ObPrompt window */ if (!self->prompt) - XChangeSaveSet(ob_display, self->window, SetModeDelete); + XChangeSaveSet(obt_display, self->window, SetModeDelete); + + /* this can't be queued to run later */ + hooks_run(OB_HOOK_WIN_CLOSE, self); /* update the focus lists */ focus_order_remove(self); @@ -731,7 +654,7 @@ void client_unmanage(ObClient *self) client_list = g_list_remove(client_list, self); stacking_remove(self); - g_hash_table_remove(window_map, &self->window); + window_remove(self->window); /* once the client is out of the list, update the struts to remove its influence */ @@ -784,7 +707,7 @@ void client_unmanage(ObClient *self) self->decorations = 0; /* unmanaged windows have no decor */ /* give the client its border back */ - XSetWindowBorderWidth(ob_display, self->window, self->border_width); + XSetWindowBorderWidth(obt_display, self->window, self->border_width); client_move_resize(self, a.x, a.y, a.width, a.height); } @@ -797,25 +720,25 @@ void client_unmanage(ObClient *self) if (ob_state() != OB_STATE_EXITING) { /* these values should not be persisted across a window unmapping/mapping */ - PROP_ERASE(self->window, net_wm_desktop); - PROP_ERASE(self->window, net_wm_state); - PROP_ERASE(self->window, wm_state); + OBT_PROP_ERASE(self->window, NET_WM_DESKTOP); + OBT_PROP_ERASE(self->window, NET_WM_STATE); + OBT_PROP_ERASE(self->window, WM_STATE); } else { /* if we're left in an unmapped state, the client wont be mapped. this is bad, since we will no longer be managing the window on restart */ - XMapWindow(ob_display, self->window); + XMapWindow(obt_display, self->window); } /* these should not be left on the window ever. other window managers don't necessarily use them and it will mess them up (like compiz) */ - PROP_ERASE(self->window, net_wm_visible_name); - PROP_ERASE(self->window, net_wm_visible_icon_name); + OBT_PROP_ERASE(self->window, NET_WM_VISIBLE_NAME); + OBT_PROP_ERASE(self->window, NET_WM_VISIBLE_ICON_NAME); /* update the list hints */ client_set_list(); - ob_debug("Unmanaged window 0x%lx\n", self->window); + ob_debug("Unmanaged window 0x%lx", self->window); /* free all data allocated in the client struct */ RrImageUnref(self->icon_set); @@ -873,7 +796,7 @@ static ObAppSettings *client_get_settings_state(ObClient *self) match = FALSE; if (match) { - ob_debug("Window matching: %s\n", app->name); + ob_debug("Window matching: %s", app->name); /* copy the settings to our struct, overriding the existing settings if they are not defaults */ @@ -928,17 +851,17 @@ static void client_restore_session_state(ObClient *self) GList *it; ob_debug_type(OB_DEBUG_SM, - "Restore session for client %s\n", self->title); + "Restore session for client %s", self->title); if (!(it = session_state_find(self))) { ob_debug_type(OB_DEBUG_SM, - "Session data not found for client %s\n", self->title); + "Session data not found for client %s", self->title); return; } self->session = it->data; - ob_debug_type(OB_DEBUG_SM, "Session data loaded for client %s\n", + ob_debug_type(OB_DEBUG_SM, "Session data loaded for client %s", self->title); RECT_SET_POINT(self->area, self->session->x, self->session->y); @@ -948,13 +871,13 @@ static void client_restore_session_state(ObClient *self) self->area.width = self->session->w; if (self->session->h > 0) self->area.height = self->session->h; - XResizeWindow(ob_display, self->window, + XResizeWindow(obt_display, self->window, self->area.width, self->area.height); self->desktop = (self->session->desktop == DESKTOP_ALL ? self->session->desktop : MIN(screen_num_desktops - 1, self->session->desktop)); - PROP_SET32(self->window, net_wm_desktop, cardinal, self->desktop); + OBT_PROP_SET32(self->window, NET_WM_DESKTOP, CARDINAL, self->desktop); self->shaded = self->session->shaded; self->iconic = self->session->iconic; @@ -1181,10 +1104,11 @@ static void client_get_all(ObClient *self, gboolean real) static void client_get_startup_id(ObClient *self) { - if (!(PROP_GETS(self->window, net_startup_id, utf8, &self->startup_id))) + if (!(OBT_PROP_GETS(self->window, NET_STARTUP_ID, utf8, + &self->startup_id))) if (self->group) - PROP_GETS(self->group->leader, - net_startup_id, utf8, &self->startup_id); + OBT_PROP_GETS(self->group->leader, + NET_STARTUP_ID, utf8, &self->startup_id); } static void client_get_area(ObClient *self) @@ -1192,14 +1116,14 @@ static void client_get_area(ObClient *self) XWindowAttributes wattrib; Status ret; - ret = XGetWindowAttributes(ob_display, self->window, &wattrib); + ret = XGetWindowAttributes(obt_display, self->window, &wattrib); g_assert(ret != BadWindow); RECT_SET(self->area, wattrib.x, wattrib.y, wattrib.width, wattrib.height); POINT_SET(self->root_pos, wattrib.x, wattrib.y); self->border_width = wattrib.border_width; - ob_debug("client area: %d %d %d %d bw %d\n", wattrib.x, wattrib.y, + ob_debug("client area: %d %d %d %d bw %d", wattrib.x, wattrib.y, wattrib.width, wattrib.height, wattrib.border_width); } @@ -1207,12 +1131,12 @@ static void client_get_desktop(ObClient *self) { guint32 d = screen_num_desktops; /* an always-invalid value */ - if (PROP_GET32(self->window, net_wm_desktop, cardinal, &d)) { + if (OBT_PROP_GET32(self->window, NET_WM_DESKTOP, CARDINAL, &d)) { if (d >= screen_num_desktops && d != DESKTOP_ALL) self->desktop = screen_num_desktops - 1; else self->desktop = d; - ob_debug("client requested desktop 0x%x\n", self->desktop); + ob_debug("client requested desktop 0x%x", self->desktop); } else { GSList *it; gboolean first = TRUE; @@ -1235,7 +1159,7 @@ static void client_get_desktop(ObClient *self) if (all != screen_num_desktops) { self->desktop = all; - ob_debug("client desktop set from parents: 0x%x\n", + ob_debug("client desktop set from parents: 0x%x", self->desktop); } /* try get from the startup-notification protocol */ @@ -1243,13 +1167,13 @@ static void client_get_desktop(ObClient *self) if (self->desktop >= screen_num_desktops && self->desktop != DESKTOP_ALL) self->desktop = screen_num_desktops - 1; - ob_debug("client desktop set from startup-notification: 0x%x\n", + ob_debug("client desktop set from startup-notification: 0x%x", self->desktop); } /* defaults to the current desktop */ else { self->desktop = screen_desktop; - ob_debug("client desktop set to the current desktop: %d\n", + ob_debug("client desktop set to the current desktop: %d", self->desktop); } } @@ -1260,32 +1184,32 @@ static void client_get_state(ObClient *self) guint32 *state; guint num; - if (PROP_GETA32(self->window, net_wm_state, atom, &state, &num)) { + if (OBT_PROP_GETA32(self->window, NET_WM_STATE, ATOM, &state, &num)) { gulong i; for (i = 0; i < num; ++i) { - if (state[i] == prop_atoms.net_wm_state_modal) + if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_MODAL)) self->modal = TRUE; - else if (state[i] == prop_atoms.net_wm_state_shaded) + else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_SHADED)) self->shaded = TRUE; - else if (state[i] == prop_atoms.net_wm_state_hidden) + else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_HIDDEN)) self->iconic = TRUE; - else if (state[i] == prop_atoms.net_wm_state_skip_taskbar) + else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR)) self->skip_taskbar = TRUE; - else if (state[i] == prop_atoms.net_wm_state_skip_pager) + else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER)) self->skip_pager = TRUE; - else if (state[i] == prop_atoms.net_wm_state_fullscreen) + else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN)) self->fullscreen = TRUE; - else if (state[i] == prop_atoms.net_wm_state_maximized_vert) + else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT)) self->max_vert = TRUE; - else if (state[i] == prop_atoms.net_wm_state_maximized_horz) + else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ)) self->max_horz = TRUE; - else if (state[i] == prop_atoms.net_wm_state_above) + else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_ABOVE)) self->above = TRUE; - else if (state[i] == prop_atoms.net_wm_state_below) + else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_BELOW)) self->below = TRUE; - else if (state[i] == prop_atoms.net_wm_state_demands_attention) + else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION)) self->demands_attention = TRUE; - else if (state[i] == prop_atoms.ob_wm_state_undecorated) + else if (state[i] == OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED)) self->undecorated = TRUE; } @@ -1297,14 +1221,14 @@ static void client_get_shaped(ObClient *self) { self->shaped = FALSE; #ifdef SHAPE - if (extensions_shape) { + if (obt_display_extension_shape) { gint foo; guint ufoo; gint s; - XShapeSelectInput(ob_display, self->window, ShapeNotifyMask); + XShapeSelectInput(obt_display, self->window, ShapeNotifyMask); - XShapeQueryExtents(ob_display, self->window, &s, &foo, + XShapeQueryExtents(obt_display, self->window, &s, &foo, &foo, &ufoo, &ufoo, &foo, &foo, &foo, &ufoo, &ufoo); self->shaped = !!s; @@ -1318,22 +1242,22 @@ void client_update_transient_for(ObClient *self) ObClient *target = NULL; gboolean trangroup = FALSE; - if (XGetTransientForHint(ob_display, self->window, &t)) { + if (XGetTransientForHint(obt_display, self->window, &t)) { if (t != self->window) { /* can't be transient to itself! */ - target = g_hash_table_lookup(window_map, &t); + ObWindow *tw = window_find(t); /* if this happens then we need to check for it */ - g_assert(target != self); - if (target && !WINDOW_IS_CLIENT(target)) { + g_assert(tw != CLIENT_AS_WINDOW(self)); + if (tw && WINDOW_IS_CLIENT(tw)) { /* watch out for windows with a parent that is something different, like a dockapp for example */ - target = NULL; + target = WINDOW_AS_CLIENT(tw); } } /* Setting the transient_for to Root is actually illegal, however applications from time have done this to specify transient for their group */ - if (!target && self->group && t == RootWindow(ob_display, ob_screen)) + if (!target && self->group && t == obt_root(ob_screen)) trangroup = TRUE; } else if (self->group && self->transient) trangroup = TRUE; @@ -1469,8 +1393,8 @@ static void client_get_mwm_hints(ObClient *self) self->mwmhints.flags = 0; /* default to none */ - if (PROP_GETA32(self->window, motif_wm_hints, motif_wm_hints, - &hints, &num)) { + if (OBT_PROP_GETA32(self->window, MOTIF_WM_HINTS, MOTIF_WM_HINTS, + &hints, &num)) { if (num >= OB_MWM_ELEMENTS) { self->mwmhints.flags = hints[0]; self->mwmhints.functions = hints[1]; @@ -1489,26 +1413,27 @@ void client_get_type_and_transientness(ObClient *self) self->type = -1; self->transient = FALSE; - if (PROP_GETA32(self->window, net_wm_window_type, atom, &val, &num)) { + if (OBT_PROP_GETA32(self->window, NET_WM_WINDOW_TYPE, ATOM, &val, &num)) { /* use the first value that we know about in the array */ for (i = 0; i < num; ++i) { - if (val[i] == prop_atoms.net_wm_window_type_desktop) + if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DESKTOP)) self->type = OB_CLIENT_TYPE_DESKTOP; - else if (val[i] == prop_atoms.net_wm_window_type_dock) + else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DOCK)) self->type = OB_CLIENT_TYPE_DOCK; - else if (val[i] == prop_atoms.net_wm_window_type_toolbar) + else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_TOOLBAR)) self->type = OB_CLIENT_TYPE_TOOLBAR; - else if (val[i] == prop_atoms.net_wm_window_type_menu) + else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_MENU)) self->type = OB_CLIENT_TYPE_MENU; - else if (val[i] == prop_atoms.net_wm_window_type_utility) + else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_UTILITY)) self->type = OB_CLIENT_TYPE_UTILITY; - else if (val[i] == prop_atoms.net_wm_window_type_splash) + else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_SPLASH)) self->type = OB_CLIENT_TYPE_SPLASH; - else if (val[i] == prop_atoms.net_wm_window_type_dialog) + else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DIALOG)) self->type = OB_CLIENT_TYPE_DIALOG; - else if (val[i] == prop_atoms.net_wm_window_type_normal) + else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_NORMAL)) self->type = OB_CLIENT_TYPE_NORMAL; - else if (val[i] == prop_atoms.kde_net_wm_window_type_override) { + else if (val[i] == OBT_PROP_ATOM(KDE_NET_WM_WINDOW_TYPE_OVERRIDE)) + { /* prevent this window from getting any decor or functionality */ self->mwmhints.flags &= (OB_MWM_FLAG_FUNCTIONS | @@ -1522,7 +1447,7 @@ void client_get_type_and_transientness(ObClient *self) g_free(val); } - if (XGetTransientForHint(ob_display, self->window, &t)) + if (XGetTransientForHint(obt_display, self->window, &t)) self->transient = TRUE; if (self->type == (ObClientType) -1) { @@ -1548,26 +1473,26 @@ void client_get_type_and_transientness(ObClient *self) void client_update_protocols(ObClient *self) { guint32 *proto; - guint num_return, i; + guint num_ret, i; self->focus_notify = FALSE; self->delete_window = FALSE; - if (PROP_GETA32(self->window, wm_protocols, atom, &proto, &num_return)) { - for (i = 0; i < num_return; ++i) { - if (proto[i] == prop_atoms.wm_delete_window) + if (OBT_PROP_GETA32(self->window, WM_PROTOCOLS, ATOM, &proto, &num_ret)) { + for (i = 0; i < num_ret; ++i) { + if (proto[i] == OBT_PROP_ATOM(WM_DELETE_WINDOW)) /* this means we can request the window to close */ self->delete_window = TRUE; - else if (proto[i] == prop_atoms.wm_take_focus) + else if (proto[i] == OBT_PROP_ATOM(WM_TAKE_FOCUS)) /* if this protocol is requested, then the window will be notified whenever we want it to receive focus */ self->focus_notify = TRUE; - else if (proto[i] == prop_atoms.net_wm_ping) + else if (proto[i] == OBT_PROP_ATOM(NET_WM_PING)) /* if this protocol is requested, then the window will allow pings to determine if it is still alive */ self->ping = TRUE; #ifdef SYNC - else if (proto[i] == prop_atoms.net_wm_sync_request) + else if (proto[i] == OBT_PROP_ATOM(NET_WM_SYNC_REQUEST)) /* if this protocol is requested, then resizing the window will be synchronized between the frame and the client */ @@ -1583,7 +1508,8 @@ void client_update_sync_request_counter(ObClient *self) { guint32 i; - if (PROP_GET32(self->window, net_wm_sync_request_counter, cardinal, &i)) { + if (OBT_PROP_GET32(self->window, NET_WM_SYNC_REQUEST_COUNTER, CARDINAL,&i)) + { self->sync_counter = i; } else self->sync_counter = None; @@ -1594,7 +1520,7 @@ static void client_get_colormap(ObClient *self) { XWindowAttributes wa; - if (XGetWindowAttributes(ob_display, self->window, &wa)) + if (XGetWindowAttributes(obt_display, self->window, &wa)) client_update_colormap(self, wa.colormap); } @@ -1602,7 +1528,7 @@ void client_update_colormap(ObClient *self, Colormap colormap) { if (colormap == self->colormap) return; - ob_debug("Setting client %s colormap: 0x%x\n", self->title, colormap); + ob_debug("Setting client %s colormap: 0x%x", self->title, colormap); if (client_focused(self)) { screen_install_colormap(self, FALSE); /* uninstall old one */ @@ -1626,7 +1552,7 @@ void client_update_normal_hints(ObClient *self) SIZE_SET(self->max_size, G_MAXINT, G_MAXINT); /* get the hints from the window */ - if (XGetWMNormalHints(ob_display, self->window, &size, &ret)) { + if (XGetWMNormalHints(obt_display, self->window, &size, &ret)) { /* normal windows can't request placement! har har if (!client_normal(self)) */ @@ -1657,15 +1583,15 @@ void client_update_normal_hints(ObClient *self) if (size.flags & PResizeInc && size.width_inc && size.height_inc) SIZE_SET(self->size_inc, size.width_inc, size.height_inc); - ob_debug("Normal hints: min size (%d %d) max size (%d %d)\n " - "size inc (%d %d) base size (%d %d)\n", + ob_debug("Normal hints: min size (%d %d) max size (%d %d)", self->min_size.width, self->min_size.height, - self->max_size.width, self->max_size.height, + self->max_size.width, self->max_size.height); + ob_debug("size inc (%d %d) base size (%d %d)", self->size_inc.width, self->size_inc.height, self->base_size.width, self->base_size.height); } else - ob_debug("Normal hints: not set\n"); + ob_debug("Normal hints: not set"); } void client_setup_decor_and_functions(ObClient *self, gboolean reconfig) @@ -1838,38 +1764,38 @@ static void client_change_allowed_actions(ObClient *self) /* desktop windows are kept on all desktops */ if (self->type != OB_CLIENT_TYPE_DESKTOP) - actions[num++] = prop_atoms.net_wm_action_change_desktop; + actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_CHANGE_DESKTOP); if (self->functions & OB_CLIENT_FUNC_SHADE) - actions[num++] = prop_atoms.net_wm_action_shade; + actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_SHADE); if (self->functions & OB_CLIENT_FUNC_CLOSE) - actions[num++] = prop_atoms.net_wm_action_close; + actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_CLOSE); if (self->functions & OB_CLIENT_FUNC_MOVE) - actions[num++] = prop_atoms.net_wm_action_move; + actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_MOVE); if (self->functions & OB_CLIENT_FUNC_ICONIFY) - actions[num++] = prop_atoms.net_wm_action_minimize; + actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_MINIMIZE); if (self->functions & OB_CLIENT_FUNC_RESIZE) - actions[num++] = prop_atoms.net_wm_action_resize; + actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_RESIZE); if (self->functions & OB_CLIENT_FUNC_FULLSCREEN) - actions[num++] = prop_atoms.net_wm_action_fullscreen; + actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_FULLSCREEN); if (self->functions & OB_CLIENT_FUNC_MAXIMIZE) { - actions[num++] = prop_atoms.net_wm_action_maximize_horz; - actions[num++] = prop_atoms.net_wm_action_maximize_vert; + actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_MAXIMIZE_HORZ); + actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_MAXIMIZE_VERT); } if (self->functions & OB_CLIENT_FUNC_ABOVE) - actions[num++] = prop_atoms.net_wm_action_above; + actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_ABOVE); if (self->functions & OB_CLIENT_FUNC_BELOW) - actions[num++] = prop_atoms.net_wm_action_below; + actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_BELOW); if (self->functions & OB_CLIENT_FUNC_UNDECORATE) - actions[num++] = prop_atoms.ob_wm_action_undecorate; + actions[num++] = OBT_PROP_ATOM(OB_WM_ACTION_UNDECORATE); - PROP_SETA32(self->window, net_wm_allowed_actions, atom, actions, num); + OBT_PROP_SETA32(self->window, NET_WM_ALLOWED_ACTIONS, ATOM, actions, num); - /* make sure the window isn't breaking any rules now + /* make sure the window isn't breaking any rules now - don't check ICONIFY here. just cuz a window can't iconify doesnt mean - it can't be iconified with its parent - */ + don't check ICONIFY here. just cuz a window can't iconify doesnt mean + it can't be iconified with its parent + */ if (!(self->functions & OB_CLIENT_FUNC_SHADE) && self->shaded) { if (self->frame) client_shade(self, FALSE); @@ -1893,7 +1819,7 @@ void client_update_wmhints(ObClient *self) /* assume a window takes input if it doesn't specify */ self->can_focus = TRUE; - if ((hints = XGetWMHints(ob_display, self->window)) != NULL) { + if ((hints = XGetWMHints(obt_display, self->window)) != NULL) { gboolean ur; if (hints->flags & InputHint) @@ -1982,10 +1908,10 @@ void client_update_title(ObClient *self) g_free(self->original_title); /* try netwm */ - if (!PROP_GETS(self->window, net_wm_name, utf8, &data)) { + if (!OBT_PROP_GETS(self->window, NET_WM_NAME, utf8, &data)) { /* try old x stuff */ - if (!(PROP_GETS(self->window, wm_name, locale, &data) - || PROP_GETS(self->window, wm_name, utf8, &data))) { + if (!(OBT_PROP_GETS(self->window, WM_NAME, locale, &data) + || OBT_PROP_GETS(self->window, WM_NAME, utf8, &data))) { if (self->transient) { /* GNOME alert windows are not given titles: @@ -2013,7 +1939,7 @@ void client_update_title(ObClient *self) g_free(data); } - PROP_SETS(self->window, net_wm_visible_name, visible); + OBT_PROP_SETS(self->window, NET_WM_VISIBLE_NAME, utf8, visible); self->title = visible; if (self->frame) @@ -2024,10 +1950,10 @@ void client_update_title(ObClient *self) g_free(self->icon_title); /* try netwm */ - if (!PROP_GETS(self->window, net_wm_icon_name, utf8, &data)) + if (!OBT_PROP_GETS(self->window, NET_WM_ICON_NAME, utf8, &data)) /* try old x stuff */ - if (!(PROP_GETS(self->window, wm_icon_name, locale, &data) || - PROP_GETS(self->window, wm_icon_name, utf8, &data))) + if (!(OBT_PROP_GETS(self->window, WM_ICON_NAME, locale, &data) || + OBT_PROP_GETS(self->window, WM_ICON_NAME, utf8, &data))) data = g_strdup(self->title); if (self->client_machine) { @@ -2045,7 +1971,7 @@ void client_update_title(ObClient *self) g_free(data); } - PROP_SETS(self->window, net_wm_visible_icon_name, visible); + OBT_PROP_SETS(self->window, NET_WM_VISIBLE_ICON_NAME, utf8, visible); self->icon_title = visible; } @@ -2056,8 +1982,9 @@ void client_update_strut(ObClient *self) gboolean got = FALSE; StrutPartial strut; - if (PROP_GETA32(self->window, net_wm_strut_partial, cardinal, - &data, &num)) { + if (OBT_PROP_GETA32(self->window, NET_WM_STRUT_PARTIAL, CARDINAL, + &data, &num)) + { if (num == 12) { got = TRUE; STRUT_PARTIAL_SET(strut, @@ -2069,7 +1996,7 @@ void client_update_strut(ObClient *self) } if (!got && - PROP_GETA32(self->window, net_wm_strut, cardinal, &data, &num)) { + OBT_PROP_GETA32(self->window, NET_WM_STRUT, CARDINAL, &data, &num)) { if (num == 4) { Rect *a; @@ -2118,7 +2045,7 @@ void client_update_icons(ObClient *self) icon */ grab_server(TRUE); - if (PROP_GETA32(self->window, net_wm_icon, cardinal, &data, &num)) { + if (OBT_PROP_GETA32(self->window, NET_WM_ICON, CARDINAL, &data, &num)) { /* figure out how many valid icons are in here */ i = 0; num_seen = 0; @@ -2170,16 +2097,16 @@ void client_update_icons(ObClient *self) if (!img) { XWMHints *hints; - if ((hints = XGetWMHints(ob_display, self->window))) { + if ((hints = XGetWMHints(obt_display, self->window))) { if (hints->flags & IconPixmapHint) { gboolean xicon; - xerror_set_ignore(TRUE); + obt_display_ignore_errors(TRUE); xicon = RrPixmapToRGBA(ob_rr_inst, hints->icon_pixmap, (hints->flags & IconMaskHint ? hints->icon_mask : None), (gint*)&w, (gint*)&h, &data); - xerror_set_ignore(FALSE); + obt_display_ignore_errors(FALSE); if (xicon) { @@ -2223,7 +2150,7 @@ void client_update_icons(ObClient *self) (((icon[i] >> RrDefaultRedOffset) & 0xff) << 16) + (((icon[i] >> RrDefaultGreenOffset) & 0xff) << 8) + (((icon[i] >> RrDefaultBlueOffset) & 0xff) << 0); - PROP_SETA32(self->window, net_wm_icon, cardinal, ldata, w*h+2); + OBT_PROP_SETA32(self->window, NET_WM_ICON, CARDINAL, ldata, w*h+2); g_free(ldata); } else if (self->frame) /* don't draw the icon empty if we're just setting one now anyways, @@ -2240,7 +2167,8 @@ void client_update_icon_geometry(ObClient *self) RECT_SET(self->icon_geometry, 0, 0, 0, 0); - if (PROP_GETA32(self->window, net_wm_icon_geometry, cardinal, &data, &num)) + if (OBT_PROP_GETA32(self->window, NET_WM_ICON_GEOMETRY, CARDINAL, + &data, &num)) { if (num == 4) /* don't let them set it with an area < 0 */ @@ -2257,23 +2185,23 @@ static void client_get_session_ids(ObClient *self) gchar *s; gchar **ss; - if (!PROP_GET32(self->window, wm_client_leader, window, &leader)) + if (!OBT_PROP_GET32(self->window, WM_CLIENT_LEADER, WINDOW, &leader)) leader = None; /* get the SM_CLIENT_ID */ got = FALSE; if (leader) - got = PROP_GETS(leader, sm_client_id, locale, &self->sm_client_id); + got = OBT_PROP_GETS(leader, SM_CLIENT_ID, locale, &self->sm_client_id); if (!got) - PROP_GETS(self->window, sm_client_id, locale, &self->sm_client_id); + OBT_PROP_GETS(self->window, SM_CLIENT_ID, locale, &self->sm_client_id); /* get the WM_CLASS (name and class). make them "" if they are not provided */ got = FALSE; if (leader) - got = PROP_GETSS(leader, wm_class, locale, &ss); + got = OBT_PROP_GETSS(leader, WM_CLASS, locale, &ss); if (!got) - got = PROP_GETSS(self->window, wm_class, locale, &ss); + got = OBT_PROP_GETSS(self->window, WM_CLASS, locale, &ss); if (got) { if (ss[0]) { @@ -2290,9 +2218,9 @@ static void client_get_session_ids(ObClient *self) /* get the WM_WINDOW_ROLE. make it "" if it is not provided */ got = FALSE; if (leader) - got = PROP_GETS(leader, wm_window_role, locale, &s); + got = OBT_PROP_GETS(leader, WM_WINDOW_ROLE, locale, &s); if (!got) - got = PROP_GETS(self->window, wm_window_role, locale, &s); + got = OBT_PROP_GETS(self->window, WM_WINDOW_ROLE, locale, &s); if (got) self->role = s; @@ -2303,9 +2231,9 @@ static void client_get_session_ids(ObClient *self) got = FALSE; if (leader) - got = PROP_GETSS(leader, wm_command, locale, &ss); + got = OBT_PROP_GETSS(leader, WM_COMMAND, locale, &ss); if (!got) - got = PROP_GETSS(self->window, wm_command, locale, &ss); + got = OBT_PROP_GETSS(self->window, WM_COMMAND, locale, &ss); if (got) { /* merge/mash them all together */ @@ -2328,9 +2256,9 @@ static void client_get_session_ids(ObClient *self) /* get the WM_CLIENT_MACHINE */ got = FALSE; if (leader) - got = PROP_GETS(leader, wm_client_machine, locale, &s); + got = OBT_PROP_GETS(leader, WM_CLIENT_MACHINE, locale, &s); if (!got) - got = PROP_GETS(self->window, wm_client_machine, locale, &s); + got = OBT_PROP_GETS(self->window, WM_CLIENT_MACHINE, locale, &s); if (got) { gchar localhost[128]; @@ -2345,7 +2273,7 @@ static void client_get_session_ids(ObClient *self) /* see if it has the PID set too (the PID requires that the WM_CLIENT_MACHINE be set) */ - if (PROP_GET32(self->window, net_wm_pid, cardinal, &pid)) + if (OBT_PROP_GET32(self->window, NET_WM_PID, CARDINAL, &pid)) self->pid = pid; } } @@ -2365,12 +2293,12 @@ static void client_change_wm_state(ObClient *self) self->wmstate = NormalState; if (old != self->wmstate) { - PROP_MSG(self->window, kde_wm_change_state, - self->wmstate, 1, 0, 0); + OBT_PROP_MSG(ob_screen, self->window, KDE_WM_CHANGE_STATE, + self->wmstate, 1, 0, 0, 0); state[0] = self->wmstate; state[1] = None; - PROP_SETA32(self->window, wm_state, wm_state, state, 2); + OBT_PROP_SETA32(self->window, WM_STATE, WM_STATE, state, 2); } } @@ -2381,30 +2309,30 @@ static void client_change_state(ObClient *self) num = 0; if (self->modal) - netstate[num++] = prop_atoms.net_wm_state_modal; + netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_MODAL); if (self->shaded) - netstate[num++] = prop_atoms.net_wm_state_shaded; + netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_SHADED); if (self->iconic) - netstate[num++] = prop_atoms.net_wm_state_hidden; + netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_HIDDEN); if (self->skip_taskbar) - netstate[num++] = prop_atoms.net_wm_state_skip_taskbar; + netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR); if (self->skip_pager) - netstate[num++] = prop_atoms.net_wm_state_skip_pager; + netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER); if (self->fullscreen) - netstate[num++] = prop_atoms.net_wm_state_fullscreen; + netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN); if (self->max_vert) - netstate[num++] = prop_atoms.net_wm_state_maximized_vert; + netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT); if (self->max_horz) - netstate[num++] = prop_atoms.net_wm_state_maximized_horz; + netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ); if (self->above) - netstate[num++] = prop_atoms.net_wm_state_above; + netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_ABOVE); if (self->below) - netstate[num++] = prop_atoms.net_wm_state_below; + netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_BELOW); if (self->demands_attention) - netstate[num++] = prop_atoms.net_wm_state_demands_attention; + netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION); if (self->undecorated) - netstate[num++] = prop_atoms.ob_wm_state_undecorated; - PROP_SETA32(self->window, net_wm_state, atom, netstate, num); + netstate[num++] = OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED); + OBT_PROP_SETA32(self->window, NET_WM_STATE, ATOM, netstate, num); if (self->frame) frame_adjust_state(self->frame); @@ -2597,6 +2525,8 @@ gboolean client_show(ObClient *self) desktop! */ client_change_wm_state(self); + + hooks_queue(OB_HOOK_WIN_VISIBLE, self); } return show; } @@ -2635,6 +2565,8 @@ gboolean client_hide(ObClient *self) desktop! */ client_change_wm_state(self); + + hooks_queue(OB_HOOK_WIN_INVISIBLE, self); } return hide; } @@ -2703,7 +2635,7 @@ static void client_apply_startup_state(ObClient *self, pre-max/pre-fullscreen values */ client_try_configure(self, &x, &y, &w, &h, &l, &l, FALSE); - ob_debug("placed window 0x%x at %d, %d with size %d x %d\n", + ob_debug("placed window 0x%x at %d, %d with size %d x %d", self->window, x, y, w, h); /* save the area, and make it where it should be for the premax stuff */ oldarea = self->area; @@ -2743,7 +2675,7 @@ static void client_apply_startup_state(ObClient *self, client_configure(self, x, y, w, h, FALSE, TRUE, FALSE); /* set the desktop hint, to make sure that it always exists */ - PROP_SET32(self->window, net_wm_desktop, cardinal, self->desktop); + OBT_PROP_SET32(self->window, NET_WM_DESKTOP, CARDINAL, self->desktop); /* nothing to do for the other states: skip_taskbar @@ -3022,7 +2954,7 @@ void client_configure(ObClient *self, gint x, gint y, gint w, gint h, /* if the client is enlarging, then resize the client before the frame */ if (send_resize_client && (w > oldw || h > oldh)) { - XMoveResizeWindow(ob_display, self->window, + XMoveResizeWindow(obt_display, self->window, self->frame->size.left, self->frame->size.top, MAX(w, oldw), MAX(h, oldh)); frame_adjust_client_area(self->frame); @@ -3088,11 +3020,11 @@ void client_configure(ObClient *self, gint x, gint y, gint w, gint h, XEvent event; event.type = ConfigureNotify; - event.xconfigure.display = ob_display; + event.xconfigure.display = obt_display; event.xconfigure.event = self->window; event.xconfigure.window = self->window; - ob_debug("Sending ConfigureNotify to %s for %d,%d %dx%d\n", + ob_debug("Sending ConfigureNotify to %s for %d,%d %dx%d", self->title, self->root_pos.x, self->root_pos.y, w, h); /* root window real coords */ @@ -3114,11 +3046,11 @@ void client_configure(ObClient *self, gint x, gint y, gint w, gint h, */ if (send_resize_client && (w <= oldw || h <= oldh)) { frame_adjust_client_area(self->frame); - XMoveResizeWindow(ob_display, self->window, + XMoveResizeWindow(obt_display, self->window, self->frame->size.left, self->frame->size.top, w, h); } - XFlush(ob_display); + XFlush(obt_display); /* if it moved between monitors, then this can affect the stacking layer of this window or others - for fullscreen windows */ @@ -3169,7 +3101,7 @@ void client_fullscreen(ObClient *self, gboolean fs) RECT_SET(self->pre_fullscreen_area, 0, 0, 0, 0); } - ob_debug("Window %s going fullscreen (%d)\n", + ob_debug("Window %s going fullscreen (%d)", self->title, self->fullscreen); client_setup_decor_and_functions(self, FALSE); @@ -3194,7 +3126,7 @@ static void client_iconify_recursive(ObClient *self, gboolean changed = FALSE; if (self->iconic != iconic) { - ob_debug("%sconifying window: 0x%lx\n", (iconic ? "I" : "Uni"), + ob_debug("%sconifying window: 0x%lx", (iconic ? "I" : "Uni"), self->window); if (iconic) { @@ -3230,6 +3162,9 @@ static void client_iconify_recursive(ObClient *self, frame_begin_iconify_animation(self->frame, iconic); /* do this after starting the animation so it doesn't flash */ client_showhide(self); + + hooks_queue((iconic ? OB_HOOK_WIN_ICONIC : OB_HOOK_WIN_UNICONIC), + self); } /* iconify all direct transients, and deiconify all transients @@ -3317,6 +3252,8 @@ void client_maximize(ObClient *self, gboolean max, gint dir) client_setup_decor_and_functions(self, FALSE); client_move_resize(self, x, y, w, h); + + hooks_queue((max ? OB_HOOK_WIN_MAX : OB_HOOK_WIN_UNMAX), self); } void client_shade(ObClient *self, gboolean shade) @@ -3330,6 +3267,8 @@ void client_shade(ObClient *self, gboolean shade) client_change_wm_state(self); /* the window is being hidden/shown */ /* resize the frame to just the titlebar */ frame_adjust_area(self->frame, FALSE, TRUE, FALSE); + + hooks_queue((shade ? OB_HOOK_WIN_SHADE : OB_HOOK_WIN_UNSHADE), self); } static void client_ping_event(ObClient *self, gboolean dead) @@ -3369,12 +3308,12 @@ void client_close(ObClient *self) if (!self->delete_window) /* don't use client_kill(), we should only kill based on PID in response to a lack of PING replies */ - XKillClient(ob_display, self->window); + XKillClient(obt_display, self->window); else { /* request the client to close with WM_DELETE_WINDOW */ - PROP_MSG_TO(self->window, self->window, wm_protocols, - prop_atoms.wm_delete_window, event_curtime, 0, 0, 0, - NoEventMask); + OBT_PROP_MSG_TO(self->window, self->window, WM_PROTOCOLS, + OBT_PROP_ATOM(WM_DELETE_WINDOW), event_curtime, + 0, 0, 0, NoEventMask); /* we're trying to close the window, so see if it is responding. if it is not, then we will let them kill the window */ @@ -3472,14 +3411,14 @@ void client_kill(ObClient *self) client_update_title(self); } else { - ob_debug("killing window 0x%x with pid %lu, with SIGKILL\n", + ob_debug("killing window 0x%x with pid %lu, with SIGKILL", self->window, self->pid); kill(self->pid, SIGKILL); /* kill -9 */ } } else { /* running on a remote host */ - XKillClient(ob_display, self->window); + XKillClient(obt_display, self->window); } } @@ -3509,13 +3448,13 @@ static void client_set_desktop_recursive(ObClient *self, if (target != self->desktop && self->type != OB_CLIENT_TYPE_DESKTOP) { - ob_debug("Setting desktop %u\n", target+1); + ob_debug("Setting desktop %u", target+1); g_assert(target < screen_num_desktops || target == DESKTOP_ALL); old = self->desktop; self->desktop = target; - PROP_SET32(self->window, net_wm_desktop, cardinal, target); + OBT_PROP_SET32(self->window, NET_WM_DESKTOP, CARDINAL, target); /* the frame can display the current desktop state */ frame_adjust_state(self->frame); /* 'move' the window to the new desktop */ @@ -3531,6 +3470,9 @@ static void client_set_desktop_recursive(ObClient *self, /* the new desktop's geometry may be different, so we may need to resize, for example if we are maximized */ client_reconfigure(self, FALSE); + + if (old != self->desktop) + hooks_queue(OB_HOOK_WIN_DESK_CHANGE, self); } /* move all transients */ @@ -3571,11 +3513,12 @@ gboolean client_validate(ObClient *self) { XEvent e; - XSync(ob_display, FALSE); /* get all events on the server */ + XSync(obt_display, FALSE); /* get all events on the server */ - if (XCheckTypedWindowEvent(ob_display, self->window, DestroyNotify, &e) || - XCheckTypedWindowEvent(ob_display, self->window, UnmapNotify, &e)) { - XPutBackEvent(ob_display, &e); + if (XCheckTypedWindowEvent(obt_display, self->window, DestroyNotify, &e) || + XCheckTypedWindowEvent(obt_display, self->window, UnmapNotify, &e)) + { + XPutBackEvent(obt_display, &e); return FALSE; } @@ -3609,10 +3552,11 @@ void client_set_state(ObClient *self, Atom action, glong data1, glong data2) gboolean above = self->above; gboolean below = self->below; gint i; + gboolean value; - if (!(action == prop_atoms.net_wm_state_add || - action == prop_atoms.net_wm_state_remove || - action == prop_atoms.net_wm_state_toggle)) + if (!(action == OBT_PROP_ATOM(NET_WM_STATE_ADD) || + action == OBT_PROP_ATOM(NET_WM_STATE_REMOVE) || + action == OBT_PROP_ATOM(NET_WM_STATE_TOGGLE))) /* an invalid action was passed to the client message, ignore it */ return; @@ -3622,105 +3566,67 @@ void client_set_state(ObClient *self, Atom action, glong data1, glong data2) if (!state) continue; /* if toggling, then pick whether we're adding or removing */ - if (action == prop_atoms.net_wm_state_toggle) { - if (state == prop_atoms.net_wm_state_modal) - action = modal ? prop_atoms.net_wm_state_remove : - prop_atoms.net_wm_state_add; - else if (state == prop_atoms.net_wm_state_maximized_vert) - action = self->max_vert ? prop_atoms.net_wm_state_remove : - prop_atoms.net_wm_state_add; - else if (state == prop_atoms.net_wm_state_maximized_horz) - action = self->max_horz ? prop_atoms.net_wm_state_remove : - prop_atoms.net_wm_state_add; - else if (state == prop_atoms.net_wm_state_shaded) - action = shaded ? prop_atoms.net_wm_state_remove : - prop_atoms.net_wm_state_add; - else if (state == prop_atoms.net_wm_state_skip_taskbar) - action = self->skip_taskbar ? - prop_atoms.net_wm_state_remove : - prop_atoms.net_wm_state_add; - else if (state == prop_atoms.net_wm_state_skip_pager) - action = self->skip_pager ? - prop_atoms.net_wm_state_remove : - prop_atoms.net_wm_state_add; - else if (state == prop_atoms.net_wm_state_hidden) - action = self->iconic ? - prop_atoms.net_wm_state_remove : - prop_atoms.net_wm_state_add; - else if (state == prop_atoms.net_wm_state_fullscreen) - action = fullscreen ? - prop_atoms.net_wm_state_remove : - prop_atoms.net_wm_state_add; - else if (state == prop_atoms.net_wm_state_above) - action = self->above ? prop_atoms.net_wm_state_remove : - prop_atoms.net_wm_state_add; - else if (state == prop_atoms.net_wm_state_below) - action = self->below ? prop_atoms.net_wm_state_remove : - prop_atoms.net_wm_state_add; - else if (state == prop_atoms.net_wm_state_demands_attention) - action = self->demands_attention ? - prop_atoms.net_wm_state_remove : - prop_atoms.net_wm_state_add; - else if (state == prop_atoms.ob_wm_state_undecorated) - action = undecorated ? prop_atoms.net_wm_state_remove : - prop_atoms.net_wm_state_add; + if (action == OBT_PROP_ATOM(NET_WM_STATE_TOGGLE)) { + if (state == OBT_PROP_ATOM(NET_WM_STATE_MODAL)) + value = modal; + else if (state == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT)) + value = self->max_vert; + else if (state == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ)) + value = self->max_horz; + else if (state == OBT_PROP_ATOM(NET_WM_STATE_SHADED)) + value = shaded; + else if (state == OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR)) + value = self->skip_taskbar; + else if (state == OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER)) + value = self->skip_pager; + else if (state == OBT_PROP_ATOM(NET_WM_STATE_HIDDEN)) + value = self->iconic; + else if (state == OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN)) + value = fullscreen; + else if (state == OBT_PROP_ATOM(NET_WM_STATE_ABOVE)) + value = self->above; + else if (state == OBT_PROP_ATOM(NET_WM_STATE_BELOW)) + value = self->below; + else if (state == OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION)) + value = self->demands_attention; + else if (state == OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED)) + value = undecorated; + action = value ? OBT_PROP_ATOM(NET_WM_STATE_REMOVE) : + OBT_PROP_ATOM(NET_WM_STATE_ADD); } - if (action == prop_atoms.net_wm_state_add) { - if (state == prop_atoms.net_wm_state_modal) { - modal = TRUE; - } else if (state == prop_atoms.net_wm_state_maximized_vert) { - max_vert = TRUE; - } else if (state == prop_atoms.net_wm_state_maximized_horz) { - max_horz = TRUE; - } else if (state == prop_atoms.net_wm_state_shaded) { - shaded = TRUE; - } else if (state == prop_atoms.net_wm_state_skip_taskbar) { - self->skip_taskbar = TRUE; - } else if (state == prop_atoms.net_wm_state_skip_pager) { - self->skip_pager = TRUE; - } else if (state == prop_atoms.net_wm_state_hidden) { - iconic = TRUE; - } else if (state == prop_atoms.net_wm_state_fullscreen) { - fullscreen = TRUE; - } else if (state == prop_atoms.net_wm_state_above) { - above = TRUE; + value = action == OBT_PROP_ATOM(NET_WM_STATE_ADD); + if (state == OBT_PROP_ATOM(NET_WM_STATE_MODAL)) { + modal = value; + } else if (state == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT)) { + max_vert = value; + } else if (state == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ)) { + max_horz = value; + } else if (state == OBT_PROP_ATOM(NET_WM_STATE_SHADED)) { + shaded = value; + } else if (state == OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR)) { + self->skip_taskbar = value; + } else if (state == OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER)) { + self->skip_pager = value; + } else if (state == OBT_PROP_ATOM(NET_WM_STATE_HIDDEN)) { + iconic = value; + } else if (state == OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN)) { + fullscreen = value; + } else if (state == OBT_PROP_ATOM(NET_WM_STATE_ABOVE)) { + above = value; + /* only unset below when setting above, otherwise you can't get to + the normal layer */ + if (value) below = FALSE; - } else if (state == prop_atoms.net_wm_state_below) { + } else if (state == OBT_PROP_ATOM(NET_WM_STATE_BELOW)) { + /* and vice versa */ + if (value) above = FALSE; - below = TRUE; - } else if (state == prop_atoms.net_wm_state_demands_attention) { - demands_attention = TRUE; - } else if (state == prop_atoms.ob_wm_state_undecorated) { - undecorated = TRUE; - } - - } else { /* action == prop_atoms.net_wm_state_remove */ - if (state == prop_atoms.net_wm_state_modal) { - modal = FALSE; - } else if (state == prop_atoms.net_wm_state_maximized_vert) { - max_vert = FALSE; - } else if (state == prop_atoms.net_wm_state_maximized_horz) { - max_horz = FALSE; - } else if (state == prop_atoms.net_wm_state_shaded) { - shaded = FALSE; - } else if (state == prop_atoms.net_wm_state_skip_taskbar) { - self->skip_taskbar = FALSE; - } else if (state == prop_atoms.net_wm_state_skip_pager) { - self->skip_pager = FALSE; - } else if (state == prop_atoms.net_wm_state_hidden) { - iconic = FALSE; - } else if (state == prop_atoms.net_wm_state_fullscreen) { - fullscreen = FALSE; - } else if (state == prop_atoms.net_wm_state_above) { - above = FALSE; - } else if (state == prop_atoms.net_wm_state_below) { - below = FALSE; - } else if (state == prop_atoms.net_wm_state_demands_attention) { - demands_attention = FALSE; - } else if (state == prop_atoms.ob_wm_state_undecorated) { - undecorated = FALSE; - } + below = value; + } else if (state == OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION)){ + demands_attention = value; + } else if (state == OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED)) { + undecorated = value; } } @@ -3810,12 +3716,12 @@ gboolean client_focus(ObClient *self) if (!client_can_focus(self)) { ob_debug_type(OB_DEBUG_FOCUS, - "Client %s can't be focused\n", self->title); + "Client %s can't be focused", self->title); return FALSE; } ob_debug_type(OB_DEBUG_FOCUS, - "Focusing client \"%s\" (0x%x) at time %u\n", + "Focusing client \"%s\" (0x%x) at time %u", self->title, self->window, event_curtime); /* if using focus_delay, stop the timer now so that focus doesn't @@ -3824,35 +3730,35 @@ gboolean client_focus(ObClient *self) event_cancel_all_key_grabs(); - xerror_set_ignore(TRUE); - xerror_occured = FALSE; + obt_display_ignore_errors(TRUE); if (self->can_focus) { /* This can cause a BadMatch error with CurrentTime, or if an app passed in a bad time for _NET_WM_ACTIVE_WINDOW. */ - XSetInputFocus(ob_display, self->window, RevertToPointerRoot, + XSetInputFocus(obt_display, self->window, RevertToPointerRoot, event_curtime); } if (self->focus_notify) { XEvent ce; ce.xclient.type = ClientMessage; - ce.xclient.message_type = prop_atoms.wm_protocols; - ce.xclient.display = ob_display; + ce.xclient.message_type = OBT_PROP_ATOM(WM_PROTOCOLS); + ce.xclient.display = obt_display; ce.xclient.window = self->window; ce.xclient.format = 32; - ce.xclient.data.l[0] = prop_atoms.wm_take_focus; + ce.xclient.data.l[0] = OBT_PROP_ATOM(WM_TAKE_FOCUS); ce.xclient.data.l[1] = event_curtime; ce.xclient.data.l[2] = 0l; ce.xclient.data.l[3] = 0l; ce.xclient.data.l[4] = 0l; - XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce); + XSendEvent(obt_display, self->window, FALSE, NoEventMask, &ce); } - xerror_set_ignore(FALSE); + obt_display_ignore_errors(FALSE); - ob_debug_type(OB_DEBUG_FOCUS, "Error focusing? %d\n", xerror_occured); - return !xerror_occured; + ob_debug_type(OB_DEBUG_FOCUS, "Error focusing? %d", + obt_display_error_occured); + return !obt_display_error_occured; } static void client_present(ObClient *self, gboolean here, gboolean raise, @@ -3969,6 +3875,9 @@ void client_set_undecorated(ObClient *self, gboolean undecorated) self->undecorated = undecorated; client_setup_decor_and_functions(self, TRUE); client_change_state(self); /* reflect this in the state hints */ + + hooks_queue((undecorated ? + OB_HOOK_WIN_UNDECORATED : OB_HOOK_WIN_DECORATED), self); } } @@ -4145,15 +4054,15 @@ static void detect_edge(Rect area, ObDirection dir, g_assert_not_reached(); } - ob_debug("my head %d size %d\n", my_head, my_size); - ob_debug("head %d tail %d dest %d\n", head, tail, *dest); + ob_debug("my head %d size %d", my_head, my_size); + ob_debug("head %d tail %d dest %d", head, tail, *dest); if (!skip_head) { - ob_debug("using near edge %d\n", head); + ob_debug("using near edge %d", head); *dest = head; *near_edge = TRUE; } else if (!skip_tail) { - ob_debug("using far edge %d\n", tail); + ob_debug("using far edge %d", tail); *dest = tail; *near_edge = FALSE; } @@ -4218,7 +4127,7 @@ void client_find_edge_directional(ObClient *self, ObDirection dir, cur->desktop != screen_desktop) continue; - ob_debug("trying window %s\n", cur->title); + ob_debug("trying window %s", cur->title); detect_edge(cur->frame->area, dir, my_head, my_size, my_edge_start, my_edge_size, dest, near_edge); @@ -4339,10 +4248,10 @@ void client_find_resize_directional(ObClient *self, ObDirection side, g_assert_not_reached(); } - ob_debug("head %d dir %d\n", head, dir); + ob_debug("head %d dir %d", head, dir); client_find_edge_directional(self, dir, head, 1, e_start, e_size, &e, &near); - ob_debug("edge %d\n", e); + ob_debug("edge %d", e); *x = self->frame->area.x; *y = self->frame->area.y; *w = self->frame->area.width; diff --git a/openbox/client.h b/openbox/client.h index c2461cb..6a396cf 100644 --- a/openbox/client.h +++ b/openbox/client.h @@ -321,15 +321,13 @@ typedef void (*ObClientCallback)(ObClient *client, gpointer data); void client_add_destroy_notify(ObClientCallback func, gpointer data); void client_remove_destroy_notify(ObClientCallback func); -/*! Manages all existing windows */ -void client_manage_all(); /*! Manages a given window @param prompt This specifies an ObPrompt which is being managed. It is possible to manage Openbox-owned windows through this. */ void client_manage(Window win, struct _ObPrompt *prompt); /*! Unmanages all managed windows */ -void client_unmanage_all(); +void client_unmanage_all(void); /*! Unmanages a given client */ void client_unmanage(ObClient *client); @@ -342,7 +340,7 @@ ObClient *client_fake_manage(Window win); void client_fake_unmanage(ObClient *self); /*! Sets the client list on the root window from the client_list */ -void client_set_list(); +void client_set_list(void); /*! Determines if the client should be shown or hidden currently. @return TRUE if it should be visible; otherwise, FALSE. @@ -717,7 +715,7 @@ void client_set_layer(ObClient *self, gint layer); guint client_monitor(ObClient *self); -ObClient* client_under_pointer(); +ObClient* client_under_pointer(void); gboolean client_has_group_siblings(ObClient *self); diff --git a/openbox/client_menu.c b/openbox/client_menu.c index 6c3147a..18f847e 100644 --- a/openbox/client_menu.c +++ b/openbox/client_menu.c @@ -27,8 +27,8 @@ #include "frame.h" #include "moveresize.h" #include "event.h" -#include "prop.h" #include "gettext.h" +#include "obt/prop.h" #include @@ -150,7 +150,7 @@ static void client_menu_execute(ObMenuEntry *e, ObMenuFrame *f, screen_pointer_pos(&x, &y); moveresize_start(c, x, y, 0, - prop_atoms.net_wm_moveresize_move_keyboard); + OBT_PROP_ATOM(NET_WM_MOVERESIZE_MOVE_KEYBOARD)); break; case CLIENT_RESIZE: /* this needs to grab the keyboard so hide the menu */ @@ -159,7 +159,7 @@ static void client_menu_execute(ObMenuEntry *e, ObMenuFrame *f, screen_pointer_pos(&x, &y); moveresize_start(c, x, y, 0, - prop_atoms.net_wm_moveresize_size_keyboard); + OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_KEYBOARD)); break; case CLIENT_CLOSE: client_close(c); diff --git a/openbox/client_menu.h b/openbox/client_menu.h index fe14502..5c55516 100644 --- a/openbox/client_menu.h +++ b/openbox/client_menu.h @@ -19,6 +19,6 @@ #ifndef ob__client_menu_h #define ob__client_menu_h -void client_menu_startup(); +void client_menu_startup(void); #endif diff --git a/openbox/config.c b/openbox/config.c index 00efd5e..cc86ce7 100644 --- a/openbox/config.c +++ b/openbox/config.c @@ -21,13 +21,13 @@ #include "keyboard.h" #include "mouse.h" #include "actions.h" -#include "prop.h" #include "translate.h" +#include "hooks.h" #include "client.h" #include "screen.h" -#include "parser/parse.h" #include "openbox.h" #include "gettext.h" +#include "obt/paths.h" gboolean config_focus_new; gboolean config_focus_follow; @@ -146,10 +146,9 @@ void config_app_settings_copy_non_defaults(const ObAppSettings *src, } } -static void config_parse_gravity_coord(xmlDocPtr doc, xmlNodePtr node, - GravityCoord *c) +static void config_parse_gravity_coord(xmlNodePtr node, GravityCoord *c) { - gchar *s = parse_string(doc, node); + gchar *s = obt_parse_node_string(node); if (!g_ascii_strcasecmp(s, "center")) c->center = TRUE; else { @@ -191,10 +190,9 @@ static void config_parse_gravity_coord(xmlDocPtr doc, xmlNodePtr node, the monitor, so center2 will center the window on the second monitor. */ -static void parse_per_app_settings(ObParseInst *inst, xmlDocPtr doc, - xmlNodePtr node, gpointer data) +static void parse_per_app_settings(xmlNodePtr node, gpointer d) { - xmlNodePtr app = parse_find_node("application", node->children); + xmlNodePtr app = obt_parse_find_node(node->children, "application"); gchar *name = NULL, *class = NULL, *role = NULL, *type = NULL; gboolean name_set, class_set, type_set; gboolean x_pos_given; @@ -202,9 +200,9 @@ static void parse_per_app_settings(ObParseInst *inst, xmlDocPtr doc, while (app) { name_set = class_set = type_set = x_pos_given = FALSE; - class_set = parse_attr_string("class", app, &class); - name_set = parse_attr_string("name", app, &name); - type_set = parse_attr_string("type", app, &type); + class_set = obt_parse_attr_string(app, "class", &class); + name_set = obt_parse_attr_string(app, "name", &name); + type_set = obt_parse_attr_string(app, "type", &type); if (class_set || name_set) { xmlNodePtr n, c; ObAppSettings *settings = config_create_app_settings();; @@ -234,57 +232,55 @@ static void parse_per_app_settings(ObParseInst *inst, xmlDocPtr doc, settings->type = OB_CLIENT_TYPE_DESKTOP; } - if (parse_attr_string("role", app, &role)) + if (obt_parse_attr_string(app, "role", &role)) settings->role = g_pattern_spec_new(role); - if ((n = parse_find_node("decor", app->children))) - if (!parse_contains("default", doc, n)) - settings->decor = parse_bool(doc, n); + if ((n = obt_parse_find_node(app->children, "decor"))) + if (!obt_parse_node_contains(n, "default")) + settings->decor = obt_parse_node_bool(n); - if ((n = parse_find_node("shade", app->children))) - if (!parse_contains("default", doc, n)) - settings->shade = parse_bool(doc, n); + if ((n = obt_parse_find_node(app->children, "shade"))) + if (!obt_parse_node_contains(n, "default")) + settings->shade = obt_parse_node_bool(n); - if ((n = parse_find_node("position", app->children))) { - if ((c = parse_find_node("x", n->children))) - if (!parse_contains("default", doc, c)) { - config_parse_gravity_coord(doc, c, - &settings->position.x); + if ((n = obt_parse_find_node(app->children, "position"))) { + if ((c = obt_parse_find_node(n->children, "x"))) + if (!obt_parse_node_contains(c, "default")) { + config_parse_gravity_coord(c, &settings->position.x); x_pos_given = TRUE; } - if (x_pos_given && (c = parse_find_node("y", n->children))) - if (!parse_contains("default", doc, c)) { - config_parse_gravity_coord(doc, c, - &settings->position.y); + if (x_pos_given && (c = obt_parse_find_node(n->children, "y"))) + if (!obt_parse_node_contains(c, "default")) { + config_parse_gravity_coord(c, &settings->position.y); settings->pos_given = TRUE; } if (settings->pos_given && - (c = parse_find_node("monitor", n->children))) - if (!parse_contains("default", doc, c)) { - gchar *s = parse_string(doc, c); + (c = obt_parse_find_node(n->children, "monitor"))) + if (!obt_parse_node_contains(c, "default")) { + gchar *s = obt_parse_node_string(c); if (!g_ascii_strcasecmp(s, "mouse")) settings->monitor = 0; else - settings->monitor = parse_int(doc, c) + 1; + settings->monitor = obt_parse_node_int(c) + 1; g_free(s); } - parse_attr_bool("force", n, &settings->pos_force); + obt_parse_attr_bool(n, "force", &settings->pos_force); } - if ((n = parse_find_node("focus", app->children))) - if (!parse_contains("default", doc, n)) - settings->focus = parse_bool(doc, n); + if ((n = obt_parse_find_node(app->children, "focus"))) + if (!obt_parse_node_contains(n, "default")) + settings->focus = obt_parse_node_bool(n); - if ((n = parse_find_node("desktop", app->children))) { - if (!parse_contains("default", doc, n)) { - gchar *s = parse_string(doc, n); + if ((n = obt_parse_find_node(app->children, "desktop"))) { + if (!obt_parse_node_contains(n, "default")) { + gchar *s = obt_parse_node_string(n); if (!g_ascii_strcasecmp(s, "all")) settings->desktop = DESKTOP_ALL; else { - gint i = parse_int(doc, n); + gint i = obt_parse_node_int(n); if (i > 0) settings->desktop = i; } @@ -292,9 +288,9 @@ static void parse_per_app_settings(ObParseInst *inst, xmlDocPtr doc, } } - if ((n = parse_find_node("layer", app->children))) - if (!parse_contains("default", doc, n)) { - gchar *s = parse_string(doc, n); + if ((n = obt_parse_find_node(app->children, "layer"))) + if (!obt_parse_node_contains(n, "default")) { + gchar *s = obt_parse_node_string(n); if (!g_ascii_strcasecmp(s, "above")) settings->layer = 1; else if (!g_ascii_strcasecmp(s, "below")) @@ -304,25 +300,25 @@ static void parse_per_app_settings(ObParseInst *inst, xmlDocPtr doc, g_free(s); } - if ((n = parse_find_node("iconic", app->children))) - if (!parse_contains("default", doc, n)) - settings->iconic = parse_bool(doc, n); + if ((n = obt_parse_find_node(app->children, "iconic"))) + if (!obt_parse_node_contains(n, "default")) + settings->iconic = obt_parse_node_bool(n); - if ((n = parse_find_node("skip_pager", app->children))) - if (!parse_contains("default", doc, n)) - settings->skip_pager = parse_bool(doc, n); + if ((n = obt_parse_find_node(app->children, "skip_pager"))) + if (!obt_parse_node_contains(n, "default")) + settings->skip_pager = obt_parse_node_bool(n); - if ((n = parse_find_node("skip_taskbar", app->children))) - if (!parse_contains("default", doc, n)) - settings->skip_taskbar = parse_bool(doc, n); + if ((n = obt_parse_find_node(app->children, "skip_taskbar"))) + if (!obt_parse_node_contains(n, "default")) + settings->skip_taskbar = obt_parse_node_bool(n); - if ((n = parse_find_node("fullscreen", app->children))) - if (!parse_contains("default", doc, n)) - settings->fullscreen = parse_bool(doc, n); + if ((n = obt_parse_find_node(app->children, "fullscreen"))) + if (!obt_parse_node_contains(n, "default")) + settings->fullscreen = obt_parse_node_bool(n); - if ((n = parse_find_node("maximized", app->children))) - if (!parse_contains("default", doc, n)) { - gchar *s = parse_string(doc, n); + if ((n = obt_parse_find_node(app->children, "maximized"))) + if (!obt_parse_node_contains(n, "default")) { + gchar *s = obt_parse_node_string(n); if (!g_ascii_strcasecmp(s, "horizontal")) { settings->max_horz = TRUE; settings->max_vert = FALSE; @@ -331,7 +327,7 @@ static void parse_per_app_settings(ObParseInst *inst, xmlDocPtr doc, settings->max_vert = TRUE; } else settings->max_horz = settings->max_vert = - parse_bool(doc, n); + obt_parse_node_bool(n); g_free(s); } @@ -343,10 +339,51 @@ static void parse_per_app_settings(ObParseInst *inst, xmlDocPtr doc, name = class = role = NULL; } - app = parse_find_node("application", app->next); + app = obt_parse_find_node(app->next, "application"); } } +static void parse_hook(xmlNodePtr node, gpointer d) +{ + gchar *name; + ObHook hook; + xmlNodePtr n; + + + if (!obt_parse_attr_string(node, "name", &name)) { + g_message(_("Hook in config file is missing a name")); + return; + } + + hook = hooks_hook_from_name(name); + if (!hook) + g_message(_("Unknown hook \"%s\" in config file"), name); + else { + if ((n = obt_parse_find_node(node->children, "action"))) + while (n) { + ObActionsAct *action; + + action = actions_parse(n); + if (action) + hooks_add(hook, action); + n = obt_parse_find_node(n->next, "action"); + } + } + + g_free(name); +} + +static void parse_hooks(xmlNodePtr node, gpointer d) +{ + xmlNodePtr n; + + if ((n = obt_parse_find_node(node->children, "hook"))) + while (n) { + parse_hook(n, NULL); + n = obt_parse_find_node(n->next, "hook"); + } +} + /* @@ -357,34 +394,33 @@ static void parse_per_app_settings(ObParseInst *inst, xmlDocPtr doc, */ -static void parse_key(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, - GList *keylist) +static void parse_key(xmlNodePtr node, GList *keylist) { gchar *key; xmlNodePtr n; gboolean is_chroot = FALSE; - if (!parse_attr_string("key", node, &key)) + if (!obt_parse_attr_string(node, "key", &key)) return; - parse_attr_bool("chroot", node, &is_chroot); + obt_parse_attr_bool(node, "chroot", &is_chroot); keylist = g_list_append(keylist, key); - if ((n = parse_find_node("keybind", node->children))) { + if ((n = obt_parse_find_node(node->children, "keybind"))) { while (n) { - parse_key(i, doc, n, keylist); - n = parse_find_node("keybind", n->next); + parse_key(n, keylist); + n = obt_parse_find_node(n->next, "keybind"); } } - else if ((n = parse_find_node("action", node->children))) { + else if ((n = obt_parse_find_node(node->children, "action"))) { while (n) { ObActionsAct *action; - action = actions_parse(i, doc, n); + action = actions_parse(n); if (action) keyboard_bind(keylist, action); - n = parse_find_node("action", n->next); + n = obt_parse_find_node(n->next, "action"); } } @@ -395,25 +431,24 @@ static void parse_key(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, keylist = g_list_delete_link(keylist, g_list_last(keylist)); } -static void parse_keyboard(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, - gpointer data) +static void parse_keyboard(xmlNodePtr node, gpointer d) { xmlNodePtr n; gchar *key; keyboard_unbind_all(); - if ((n = parse_find_node("chainQuitKey", node->children))) { - key = parse_string(doc, n); + if ((n = obt_parse_find_node(node->children, "chainQuitKey"))) { + key = obt_parse_node_string(n); translate_key(key, &config_keyboard_reset_state, &config_keyboard_reset_keycode); g_free(key); } - if ((n = parse_find_node("keybind", node->children))) + if ((n = obt_parse_find_node(node->children, "keybind"))) while (n) { - parse_key(i, doc, n, NULL); - n = parse_find_node("keybind", n->next); + parse_key(n, NULL); + n = obt_parse_find_node(n->next, "keybind"); } } @@ -427,8 +462,7 @@ static void parse_keyboard(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, */ -static void parse_mouse(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, - gpointer data) +static void parse_mouse(xmlNodePtr node, gpointer d) { xmlNodePtr n, nbut, nact; gchar *buttonstr; @@ -439,141 +473,137 @@ static void parse_mouse(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, node = node->children; - if ((n = parse_find_node("dragThreshold", node))) - config_mouse_threshold = parse_int(doc, n); - if ((n = parse_find_node("doubleClickTime", node))) - config_mouse_dclicktime = parse_int(doc, n); - if ((n = parse_find_node("screenEdgeWarpTime", node))) - config_mouse_screenedgetime = parse_int(doc, n); + if ((n = obt_parse_find_node(node, "dragThreshold"))) + config_mouse_threshold = obt_parse_node_int(n); + if ((n = obt_parse_find_node(node, "doubleClickTime"))) + config_mouse_dclicktime = obt_parse_node_int(n); + if ((n = obt_parse_find_node(node, "screenEdgeWarpTime"))) + config_mouse_screenedgetime = obt_parse_node_int(n); - n = parse_find_node("context", node); + n = obt_parse_find_node(node, "context"); while (n) { - if (!parse_attr_string("name", n, &contextstr)) + if (!obt_parse_attr_string(n, "name", &contextstr)) goto next_n; - nbut = parse_find_node("mousebind", n->children); + nbut = obt_parse_find_node(n->children, "mousebind"); while (nbut) { - if (!parse_attr_string("button", nbut, &buttonstr)) + if (!obt_parse_attr_string(nbut, "button", &buttonstr)) goto next_nbut; - if (parse_attr_contains("press", nbut, "action")) { + if (obt_parse_attr_contains(nbut, "action", "press")) { mact = OB_MOUSE_ACTION_PRESS; - } else if (parse_attr_contains("release", nbut, "action")) { + } else if (obt_parse_attr_contains(nbut, "action", "release")) { mact = OB_MOUSE_ACTION_RELEASE; - } else if (parse_attr_contains("click", nbut, "action")) { + } else if (obt_parse_attr_contains(nbut, "action", "click")) { mact = OB_MOUSE_ACTION_CLICK; - } else if (parse_attr_contains("doubleclick", nbut,"action")) { + } else if (obt_parse_attr_contains(nbut, "action","doubleclick")) { mact = OB_MOUSE_ACTION_DOUBLE_CLICK; - } else if (parse_attr_contains("drag", nbut, "action")) { + } else if (obt_parse_attr_contains(nbut, "action", "drag")) { mact = OB_MOUSE_ACTION_MOTION; } else goto next_nbut; - nact = parse_find_node("action", nbut->children); + nact = obt_parse_find_node(nbut->children, "action"); while (nact) { ObActionsAct *action; - if ((action = actions_parse(i, doc, nact))) + if ((action = actions_parse(nact))) mouse_bind(buttonstr, contextstr, mact, action); - nact = parse_find_node("action", nact->next); + nact = obt_parse_find_node(nact->next, "action"); } g_free(buttonstr); next_nbut: - nbut = parse_find_node("mousebind", nbut->next); + nbut = obt_parse_find_node(nbut->next, "mousebind"); } g_free(contextstr); next_n: - n = parse_find_node("context", n->next); + n = obt_parse_find_node(n->next, "context"); } } -static void parse_focus(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, - gpointer data) +static void parse_focus(xmlNodePtr node, gpointer d) { xmlNodePtr n; node = node->children; - if ((n = parse_find_node("focusNew", node))) - config_focus_new = parse_bool(doc, n); - if ((n = parse_find_node("followMouse", node))) - config_focus_follow = parse_bool(doc, n); - if ((n = parse_find_node("focusDelay", node))) - config_focus_delay = parse_int(doc, n); - if ((n = parse_find_node("raiseOnFocus", node))) - config_focus_raise = parse_bool(doc, n); - if ((n = parse_find_node("focusLast", node))) - config_focus_last = parse_bool(doc, n); - if ((n = parse_find_node("underMouse", node))) - config_focus_under_mouse = parse_bool(doc, n); + if ((n = obt_parse_find_node(node, "focusNew"))) + config_focus_new = obt_parse_node_bool(n); + if ((n = obt_parse_find_node(node, "followMouse"))) + config_focus_follow = obt_parse_node_bool(n); + if ((n = obt_parse_find_node(node, "focusDelay"))) + config_focus_delay = obt_parse_node_int(n); + if ((n = obt_parse_find_node(node, "raiseOnFocus"))) + config_focus_raise = obt_parse_node_bool(n); + if ((n = obt_parse_find_node(node, "focusLast"))) + config_focus_last = obt_parse_node_bool(n); + if ((n = obt_parse_find_node(node, "underMouse"))) + config_focus_under_mouse = obt_parse_node_bool(n); } -static void parse_placement(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, - gpointer data) +static void parse_placement(xmlNodePtr node, gpointer d) { xmlNodePtr n; node = node->children; - if ((n = parse_find_node("policy", node))) - if (parse_contains("UnderMouse", doc, n)) + if ((n = obt_parse_find_node(node, "policy"))) + if (obt_parse_node_contains(n, "UnderMouse")) config_place_policy = OB_PLACE_POLICY_MOUSE; - if ((n = parse_find_node("center", node))) - config_place_center = parse_bool(doc, n); - if ((n = parse_find_node("monitor", node))) { - if (parse_contains("active", doc, n)) + if ((n = obt_parse_find_node(node, "center"))) + config_place_center = obt_parse_node_bool(n); + if ((n = obt_parse_find_node(node, "monitor"))) { + if (obt_parse_node_contains(n, "active")) config_place_monitor = OB_PLACE_MONITOR_ACTIVE; - else if (parse_contains("mouse", doc, n)) + else if (obt_parse_node_contains(n, "mouse")) config_place_monitor = OB_PLACE_MONITOR_MOUSE; } } -static void parse_margins(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, - gpointer data) +static void parse_margins(xmlNodePtr node, gpointer d) { xmlNodePtr n; node = node->children; - if ((n = parse_find_node("top", node))) - config_margins.top = MAX(0, parse_int(doc, n)); - if ((n = parse_find_node("left", node))) - config_margins.left = MAX(0, parse_int(doc, n)); - if ((n = parse_find_node("right", node))) - config_margins.right = MAX(0, parse_int(doc, n)); - if ((n = parse_find_node("bottom", node))) - config_margins.bottom = MAX(0, parse_int(doc, n)); + if ((n = obt_parse_find_node(node, "top"))) + config_margins.top = MAX(0, obt_parse_node_int(n)); + if ((n = obt_parse_find_node(node, "left"))) + config_margins.left = MAX(0, obt_parse_node_int(n)); + if ((n = obt_parse_find_node(node, "right"))) + config_margins.right = MAX(0, obt_parse_node_int(n)); + if ((n = obt_parse_find_node(node, "bottom"))) + config_margins.bottom = MAX(0, obt_parse_node_int(n)); } -static void parse_theme(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, - gpointer data) +static void parse_theme(xmlNodePtr node, gpointer d) { xmlNodePtr n; node = node->children; - if ((n = parse_find_node("name", node))) { + if ((n = obt_parse_find_node(node, "name"))) { gchar *c; g_free(config_theme); - c = parse_string(doc, n); - config_theme = parse_expand_tilde(c); + c = obt_parse_node_string(n); + config_theme = obt_paths_expand_tilde(c); g_free(c); } - if ((n = parse_find_node("titleLayout", node))) { + if ((n = obt_parse_find_node(node, "titleLayout"))) { gchar *c, *d; g_free(config_title_layout); - config_title_layout = parse_string(doc, n); + config_title_layout = obt_parse_node_string(n); /* replace duplicates with spaces */ for (c = config_title_layout; *c != '\0'; ++c) for (d = c+1; *d != '\0'; ++d) if (*c == *d) *d = ' '; } - if ((n = parse_find_node("keepBorder", node))) - config_theme_keepborder = parse_bool(doc, n); - if ((n = parse_find_node("animateIconify", node))) - config_animate_iconify = parse_bool(doc, n); + if ((n = obt_parse_find_node(node, "keepBorder"))) + config_theme_keepborder = obt_parse_node_bool(n); + if ((n = obt_parse_find_node(node, "animateIconify"))) + config_animate_iconify = obt_parse_node_bool(n); - n = parse_find_node("font", node); + n = obt_parse_find_node(node, "font"); while (n) { xmlNodePtr fnode; RrFont **font; @@ -582,35 +612,35 @@ static void parse_theme(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, RrFontWeight weight = RrDefaultFontWeight; RrFontSlant slant = RrDefaultFontSlant; - if (parse_attr_contains("ActiveWindow", n, "place")) + if (obt_parse_attr_contains(n, "place", "ActiveWindow")) font = &config_font_activewindow; - else if (parse_attr_contains("InactiveWindow", n, "place")) + else if (obt_parse_attr_contains(n, "place", "InactiveWindow")) font = &config_font_inactivewindow; - else if (parse_attr_contains("MenuHeader", n, "place")) + else if (obt_parse_attr_contains(n, "place", "MenuHeader")) font = &config_font_menutitle; - else if (parse_attr_contains("MenuItem", n, "place")) + else if (obt_parse_attr_contains(n, "place", "MenuItem")) font = &config_font_menuitem; - else if (parse_attr_contains("OnScreenDisplay", n, "place")) + else if (obt_parse_attr_contains(n, "place", "OnScreenDisplay")) font = &config_font_osd; else goto next_font; - if ((fnode = parse_find_node("name", n->children))) { + if ((fnode = obt_parse_find_node(n->children, "name"))) { g_free(name); - name = parse_string(doc, fnode); + name = obt_parse_node_string(fnode); } - if ((fnode = parse_find_node("size", n->children))) { - int s = parse_int(doc, fnode); + if ((fnode = obt_parse_find_node(n->children, "size"))) { + int s = obt_parse_node_int(fnode); if (s > 0) size = s; } - if ((fnode = parse_find_node("weight", n->children))) { - gchar *w = parse_string(doc, fnode); + if ((fnode = obt_parse_find_node(n->children, "weight"))) { + gchar *w = obt_parse_node_string(fnode); if (!g_ascii_strcasecmp(w, "Bold")) weight = RR_FONTWEIGHT_BOLD; g_free(w); } - if ((fnode = parse_find_node("slant", n->children))) { - gchar *s = parse_string(doc, fnode); + if ((fnode = obt_parse_find_node(n->children, "slant"))) { + gchar *s = obt_parse_node_string(fnode); if (!g_ascii_strcasecmp(s, "Italic")) slant = RR_FONTSLANT_ITALIC; if (!g_ascii_strcasecmp(s, "Oblique")) @@ -621,28 +651,27 @@ static void parse_theme(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, *font = RrFontOpen(ob_rr_inst, name, size, weight, slant); g_free(name); next_font: - n = parse_find_node("font", n->next); + n = obt_parse_find_node(n->next, "font"); } } -static void parse_desktops(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, - gpointer data) +static void parse_desktops(xmlNodePtr node, gpointer d) { xmlNodePtr n; node = node->children; - if ((n = parse_find_node("number", node))) { - gint d = parse_int(doc, n); + if ((n = obt_parse_find_node(node, "number"))) { + gint d = obt_parse_node_int(n); if (d > 0) config_desktops_num = (unsigned) d; } - if ((n = parse_find_node("firstdesk", node))) { - gint d = parse_int(doc, n); + if ((n = obt_parse_find_node(node, "firstdesk"))) { + gint d = obt_parse_node_int(n); if (d > 0) config_screen_firstdesk = (unsigned) d; } - if ((n = parse_find_node("names", node))) { + if ((n = obt_parse_find_node(node, "names"))) { GSList *it; xmlNodePtr nname; @@ -651,51 +680,51 @@ static void parse_desktops(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, g_slist_free(config_desktops_names); config_desktops_names = NULL; - nname = parse_find_node("name", n->children); + nname = obt_parse_find_node(n->children, "name"); while (nname) { - config_desktops_names = g_slist_append(config_desktops_names, - parse_string(doc, nname)); - nname = parse_find_node("name", nname->next); + config_desktops_names = + g_slist_append(config_desktops_names, + obt_parse_node_string(nname)); + nname = obt_parse_find_node(nname->next, "name"); } } - if ((n = parse_find_node("popupTime", node))) - config_desktop_popup_time = parse_int(doc, n); + if ((n = obt_parse_find_node(node, "popupTime"))) + config_desktop_popup_time = obt_parse_node_int(n); } -static void parse_resize(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, - gpointer data) +static void parse_resize(xmlNodePtr node, gpointer d) { xmlNodePtr n; node = node->children; - if ((n = parse_find_node("drawContents", node))) - config_resize_redraw = parse_bool(doc, n); - if ((n = parse_find_node("popupShow", node))) { - config_resize_popup_show = parse_int(doc, n); - if (parse_contains("Always", doc, n)) + if ((n = obt_parse_find_node(node, "drawContents"))) + config_resize_redraw = obt_parse_node_bool(n); + if ((n = obt_parse_find_node(node, "popupShow"))) { + config_resize_popup_show = obt_parse_node_int(n); + if (obt_parse_node_contains(n, "Always")) config_resize_popup_show = 2; - else if (parse_contains("Never", doc, n)) + else if (obt_parse_node_contains(n, "Never")) config_resize_popup_show = 0; - else if (parse_contains("Nonpixel", doc, n)) + else if (obt_parse_node_contains(n, "Nonpixel")) config_resize_popup_show = 1; } - if ((n = parse_find_node("popupPosition", node))) { - if (parse_contains("Top", doc, n)) + if ((n = obt_parse_find_node(node, "popupPosition"))) { + if (obt_parse_node_contains(n, "Top")) config_resize_popup_pos = OB_RESIZE_POS_TOP; - else if (parse_contains("Center", doc, n)) + else if (obt_parse_node_contains(n, "Center")) config_resize_popup_pos = OB_RESIZE_POS_CENTER; - else if (parse_contains("Fixed", doc, n)) { + else if (obt_parse_node_contains(n, "Fixed")) { config_resize_popup_pos = OB_RESIZE_POS_FIXED; - if ((n = parse_find_node("popupFixedPosition", node))) { + if ((n = obt_parse_find_node(node, "popupFixedPosition"))) { xmlNodePtr n2; - if ((n2 = parse_find_node("x", n->children))) - config_parse_gravity_coord(doc, n2, + if ((n2 = obt_parse_find_node(n->children, "x"))) + config_parse_gravity_coord(n2, &config_resize_popup_fixed.x); - if ((n2 = parse_find_node("y", n->children))) - config_parse_gravity_coord(doc, n2, + if ((n2 = obt_parse_find_node(n->children, "y"))) + config_parse_gravity_coord(n2, &config_resize_popup_fixed.y); config_resize_popup_fixed.x.pos = @@ -707,72 +736,71 @@ static void parse_resize(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, } } -static void parse_dock(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, - gpointer data) +static void parse_dock(xmlNodePtr node, gpointer d) { xmlNodePtr n; node = node->children; - if ((n = parse_find_node("position", node))) { - if (parse_contains("TopLeft", doc, n)) + if ((n = obt_parse_find_node(node, "position"))) { + if (obt_parse_node_contains(n, "TopLeft")) config_dock_floating = FALSE, config_dock_pos = OB_DIRECTION_NORTHWEST; - else if (parse_contains("Top", doc, n)) + else if (obt_parse_node_contains(n, "Top")) config_dock_floating = FALSE, config_dock_pos = OB_DIRECTION_NORTH; - else if (parse_contains("TopRight", doc, n)) + else if (obt_parse_node_contains(n, "TopRight")) config_dock_floating = FALSE, config_dock_pos = OB_DIRECTION_NORTHEAST; - else if (parse_contains("Right", doc, n)) + else if (obt_parse_node_contains(n, "Right")) config_dock_floating = FALSE, config_dock_pos = OB_DIRECTION_EAST; - else if (parse_contains("BottomRight", doc, n)) + else if (obt_parse_node_contains(n, "BottomRight")) config_dock_floating = FALSE, config_dock_pos = OB_DIRECTION_SOUTHEAST; - else if (parse_contains("Bottom", doc, n)) + else if (obt_parse_node_contains(n, "Bottom")) config_dock_floating = FALSE, config_dock_pos = OB_DIRECTION_SOUTH; - else if (parse_contains("BottomLeft", doc, n)) + else if (obt_parse_node_contains(n, "BottomLeft")) config_dock_floating = FALSE, config_dock_pos = OB_DIRECTION_SOUTHWEST; - else if (parse_contains("Left", doc, n)) + else if (obt_parse_node_contains(n, "Left")) config_dock_floating = FALSE, config_dock_pos = OB_DIRECTION_WEST; - else if (parse_contains("Floating", doc, n)) + else if (obt_parse_node_contains(n, "Floating")) config_dock_floating = TRUE; } if (config_dock_floating) { - if ((n = parse_find_node("floatingX", node))) - config_dock_x = parse_int(doc, n); - if ((n = parse_find_node("floatingY", node))) - config_dock_y = parse_int(doc, n); + if ((n = obt_parse_find_node(node, "floatingX"))) + config_dock_x = obt_parse_node_int(n); + if ((n = obt_parse_find_node(node, "floatingY"))) + config_dock_y = obt_parse_node_int(n); } else { - if ((n = parse_find_node("noStrut", node))) - config_dock_nostrut = parse_bool(doc, n); + if ((n = obt_parse_find_node(node, "noStrut"))) + config_dock_nostrut = obt_parse_node_bool(n); } - if ((n = parse_find_node("stacking", node))) { - if (parse_contains("above", doc, n)) - config_dock_layer = OB_STACKING_LAYER_ABOVE; - else if (parse_contains("normal", doc, n)) + if ((n = obt_parse_find_node(node, "stacking"))) { + if (obt_parse_node_contains(n, "normal")) config_dock_layer = OB_STACKING_LAYER_NORMAL; - else if (parse_contains("below", doc, n)) + else if (obt_parse_node_contains(n, "below")) config_dock_layer = OB_STACKING_LAYER_BELOW; + else if (obt_parse_node_contains(n, "above")) + config_dock_layer = OB_STACKING_LAYER_ABOVE; } - if ((n = parse_find_node("direction", node))) { - if (parse_contains("horizontal", doc, n)) + if ((n = obt_parse_find_node(node, "direction"))) { + if (obt_parse_node_contains(n, "horizontal")) config_dock_orient = OB_ORIENTATION_HORZ; - else if (parse_contains("vertical", doc, n)) + else if (obt_parse_node_contains(n, "vertical")) config_dock_orient = OB_ORIENTATION_VERT; } - if ((n = parse_find_node("autoHide", node))) - config_dock_hide = parse_bool(doc, n); - if ((n = parse_find_node("hideDelay", node))) - config_dock_hide_delay = parse_int(doc, n); - if ((n = parse_find_node("showDelay", node))) - config_dock_show_delay = parse_int(doc, n); - if ((n = parse_find_node("moveButton", node))) { - gchar *str = parse_string(doc, n); + if ((n = obt_parse_find_node(node, "autoHide"))) + config_dock_hide = obt_parse_node_bool(n); + if ((n = obt_parse_find_node(node, "hideDelay"))) + config_dock_hide_delay = obt_parse_node_int(n); + if ((n = obt_parse_find_node(node, "showDelay"))) + config_dock_show_delay = obt_parse_node_int(n); + if ((n = obt_parse_find_node(node, "moveButton"))) { + gchar *str = obt_parse_node_string(n); guint b, s; if (translate_button(str, &s, &b)) { config_dock_app_move_button = b; @@ -784,42 +812,40 @@ static void parse_dock(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, } } -static void parse_menu(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, - gpointer data) +static void parse_menu(xmlNodePtr node, gpointer d) { xmlNodePtr n; for (node = node->children; node; node = node->next) { if (!xmlStrcasecmp(node->name, (const xmlChar*) "file")) { gchar *c; - c = parse_string(doc, node); + c = obt_parse_node_string(node); config_menu_files = g_slist_append(config_menu_files, - parse_expand_tilde(c)); + obt_paths_expand_tilde(c)); g_free(c); } - if ((n = parse_find_node("hideDelay", node))) - config_menu_hide_delay = parse_int(doc, n); - if ((n = parse_find_node("middle", node))) - config_menu_middle = parse_bool(doc, n); - if ((n = parse_find_node("submenuShowDelay", node))) - config_submenu_show_delay = parse_int(doc, n); - if ((n = parse_find_node("applicationIcons", node))) - config_menu_client_list_icons = parse_bool(doc, n); - if ((n = parse_find_node("manageDesktops", node))) - config_menu_manage_desktops = parse_bool(doc, n); + if ((n = obt_parse_find_node(node, "hideDelay"))) + config_menu_hide_delay = obt_parse_node_int(n); + if ((n = obt_parse_find_node(node, "middle"))) + config_menu_middle = obt_parse_node_bool(n); + if ((n = obt_parse_find_node(node, "submenuShowDelay"))) + config_submenu_show_delay = obt_parse_node_int(n); + if ((n = obt_parse_find_node(node, "applicationIcons"))) + config_menu_client_list_icons = obt_parse_node_bool(n); + if ((n = obt_parse_find_node(node, "manageDesktops"))) + config_menu_manage_desktops = obt_parse_node_bool(n); } } -static void parse_resistance(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, - gpointer data) +static void parse_resistance(xmlNodePtr node, gpointer d) { xmlNodePtr n; node = node->children; - if ((n = parse_find_node("strength", node))) - config_resist_win = parse_int(doc, n); - if ((n = parse_find_node("screen_edge_strength", node))) - config_resist_edge = parse_int(doc, n); + if ((n = obt_parse_find_node(node, "strength"))) + config_resist_win = obt_parse_node_int(n); + if ((n = obt_parse_find_node(node, "screen_edge_strength"))) + config_resist_edge = obt_parse_node_int(n); } typedef struct @@ -910,7 +936,7 @@ static void bind_default_mouse(void) actions_parse_string(it->actname)); } -void config_startup(ObParseInst *i) +void config_startup(ObtParseInst *i) { config_focus_new = TRUE; config_focus_follow = FALSE; @@ -919,17 +945,17 @@ void config_startup(ObParseInst *i) config_focus_last = TRUE; config_focus_under_mouse = FALSE; - parse_register(i, "focus", parse_focus, NULL); + obt_parse_register(i, "focus", parse_focus, NULL); config_place_policy = OB_PLACE_POLICY_SMART; config_place_center = TRUE; config_place_monitor = OB_PLACE_MONITOR_ANY; - parse_register(i, "placement", parse_placement, NULL); + obt_parse_register(i, "placement", parse_placement, NULL); STRUT_PARTIAL_SET(config_margins, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); - parse_register(i, "margins", parse_margins, NULL); + obt_parse_register(i, "margins", parse_margins, NULL); config_theme = NULL; @@ -942,14 +968,14 @@ void config_startup(ObParseInst *i) config_font_menuitem = NULL; config_font_menutitle = NULL; - parse_register(i, "theme", parse_theme, NULL); + obt_parse_register(i, "theme", parse_theme, NULL); config_desktops_num = 4; config_screen_firstdesk = 1; config_desktops_names = NULL; config_desktop_popup_time = 875; - parse_register(i, "desktops", parse_desktops, NULL); + obt_parse_register(i, "desktops", parse_desktops, NULL); config_resize_redraw = TRUE; config_resize_popup_show = 1; /* nonpixel increments */ @@ -957,7 +983,7 @@ void config_startup(ObParseInst *i) GRAVITY_COORD_SET(config_resize_popup_fixed.x, 0, FALSE, FALSE); GRAVITY_COORD_SET(config_resize_popup_fixed.y, 0, FALSE, FALSE); - parse_register(i, "resize", parse_resize, NULL); + obt_parse_register(i, "resize", parse_resize, NULL); config_dock_layer = OB_STACKING_LAYER_ABOVE; config_dock_pos = OB_DIRECTION_NORTHEAST; @@ -972,14 +998,14 @@ void config_startup(ObParseInst *i) config_dock_app_move_button = 2; /* middle */ config_dock_app_move_modifiers = 0; - parse_register(i, "dock", parse_dock, NULL); + obt_parse_register(i, "dock", parse_dock, NULL); translate_key("C-g", &config_keyboard_reset_state, &config_keyboard_reset_keycode); bind_default_keyboard(); - parse_register(i, "keyboard", parse_keyboard, NULL); + obt_parse_register(i, "keyboard", parse_keyboard, NULL); config_mouse_threshold = 8; config_mouse_dclicktime = 200; @@ -987,12 +1013,12 @@ void config_startup(ObParseInst *i) bind_default_mouse(); - parse_register(i, "mouse", parse_mouse, NULL); + obt_parse_register(i, "mouse", parse_mouse, NULL); config_resist_win = 10; config_resist_edge = 20; - parse_register(i, "resistance", parse_resistance, NULL); + obt_parse_register(i, "resistance", parse_resistance, NULL); config_menu_hide_delay = 250; config_menu_middle = FALSE; @@ -1001,11 +1027,13 @@ void config_startup(ObParseInst *i) config_menu_manage_desktops = TRUE; config_menu_files = NULL; - parse_register(i, "menu", parse_menu, NULL); + obt_parse_register(i, "menu", parse_menu, NULL); + + obt_parse_register(i, "hooks", parse_hooks, NULL); config_per_app_settings = NULL; - parse_register(i, "applications", parse_per_app_settings, NULL); + obt_parse_register(i, "applications", parse_per_app_settings, NULL); } void config_shutdown(void) diff --git a/openbox/config.h b/openbox/config.h index 62b9247..8a01ee1 100644 --- a/openbox/config.h +++ b/openbox/config.h @@ -27,11 +27,10 @@ #include "geom.h" #include "moveresize.h" #include "render/render.h" +#include "obt/parse.h" #include -struct _ObParseInst; - typedef struct _ObAppSettings ObAppSettings; struct _ObAppSettings @@ -188,11 +187,11 @@ extern GSList *config_menu_files; /*! Per app settings */ extern GSList *config_per_app_settings; -void config_startup(struct _ObParseInst *i); -void config_shutdown(); +void config_startup(ObtParseInst *i); +void config_shutdown(void); /*! Create an ObAppSettings structure with the default values */ -ObAppSettings* config_create_app_settings(); +ObAppSettings* config_create_app_settings(void); /*! Copies any settings in src to dest, if they are their default value in src. */ void config_app_settings_copy_non_defaults(const ObAppSettings *src, diff --git a/openbox/debug.c b/openbox/debug.c index 0fceba4..4264486 100644 --- a/openbox/debug.c +++ b/openbox/debug.c @@ -17,62 +17,152 @@ */ #include "debug.h" +#include "gettext.h" +#include "obt/paths.h" #include #include #include #include +#include -static gboolean show; +#ifdef HAVE_UNISTD_H +# include +#endif -void ob_debug_show_output(gboolean enable) +static gboolean enabled_types[OB_DEBUG_TYPE_NUM] = {FALSE}; +static FILE *log_file = NULL; +static guint rr_handler_id = 0; +static guint obt_handler_id = 0; +static guint ob_handler_id = 0; + +static void log_handler(const gchar *log_domain, GLogLevelFlags log_level, + const gchar *message, gpointer user_data); + +void ob_debug_startup(void) { - show = enable; + ObtPaths *p = obt_paths_new(); + gchar *dir = g_build_filename(obt_paths_cache_home(p), + "openbox", NULL); + + /* log messages to a log file! fancy, no? */ + if (!obt_paths_mkdir_path(dir, 0777)) + g_message(_("Unable to make directory '%s': %s"), + dir, g_strerror(errno)); + else { + gchar *name = g_build_filename(obt_paths_cache_home(p), + "openbox", "openbox.log", NULL); + /* unlink it before opening to remove competition */ + unlink(name); + log_file = fopen(name, "w"); + g_free(name); + } + + rr_handler_id = + g_log_set_handler("ObRender", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | + G_LOG_FLAG_RECURSION, log_handler, NULL); + obt_handler_id = + g_log_set_handler("Obt", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | + G_LOG_FLAG_RECURSION, log_handler, NULL); + ob_handler_id = + g_log_set_handler("Openbox", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | + G_LOG_FLAG_RECURSION, log_handler, NULL); + + obt_paths_unref(p); + g_free(dir); } -void ob_debug(const gchar *a, ...) +void ob_debug_shutdown(void) { - va_list vl; + g_log_remove_handler("ObRender", rr_handler_id); + g_log_remove_handler("Obt", obt_handler_id); + g_log_remove_handler("Openbox", ob_handler_id); - if (show) { - fprintf(stderr, "DEBUG: "); - va_start(vl, a); - vfprintf(stderr, a, vl); - va_end(vl); + if (log_file) { + fclose(log_file); + log_file = NULL; } } -static gboolean enabled_types[OB_DEBUG_TYPE_NUM] = {FALSE}; - void ob_debug_enable(ObDebugType type, gboolean enable) { g_assert(type < OB_DEBUG_TYPE_NUM); enabled_types[type] = enable; } -void ob_debug_type(ObDebugType type, const gchar *a, ...) +static inline void log_print(FILE *out, const gchar* log_domain, + const gchar *level, const gchar *message) { - va_list vl; + fprintf(out, log_domain); + fprintf(out, "-"); + fprintf(out, level); + fprintf(out, ": "); + fprintf(out, message); + fprintf(out, "\n"); + fflush(out); +} + +static void log_handler(const gchar *log_domain, GLogLevelFlags log_level, + const gchar *message, gpointer data) +{ + FILE *out; + const gchar *level; + + switch (log_level & G_LOG_LEVEL_MASK) { + case G_LOG_LEVEL_DEBUG: level = "Debug"; out = stdout; break; + case G_LOG_LEVEL_INFO: level = "Info"; out = stdout; break; + case G_LOG_LEVEL_MESSAGE: level = "Message"; out = stdout; break; + case G_LOG_LEVEL_WARNING: level = "Warning"; out = stderr; break; + case G_LOG_LEVEL_CRITICAL: level = "Critical"; out = stderr; break; + case G_LOG_LEVEL_ERROR: level = "Error"; out = stderr; break; + default: g_assert_not_reached(); /* invalid level.. */ + } + + log_print(out, log_domain, level, message); + if (log_file) log_print(log_file, log_domain, level, message); +} + +static inline void log_argv(ObDebugType type, + const gchar *format, va_list args) +{ + const gchar *prefix; + gchar *message; g_assert(type < OB_DEBUG_TYPE_NUM); + if (!enabled_types[type]) return; + + switch (type) { + case OB_DEBUG_FOCUS: prefix = "(FOCUS) "; break; + case OB_DEBUG_APP_BUGS: prefix = "(APPLICATION BUG) "; break; + case OB_DEBUG_SM: prefix = "(SESSION) "; break; + default: prefix = NULL; break; + } - if (show && enabled_types[type]) { - switch (type) { - case OB_DEBUG_FOCUS: - fprintf(stderr, "FOCUS: "); - break; - case OB_DEBUG_APP_BUGS: - fprintf(stderr, "APPLICATION BUG: "); - break; - case OB_DEBUG_SM: - fprintf(stderr, "SESSION: "); - break; - default: - g_assert_not_reached(); - } - - va_start(vl, a); - vfprintf(stderr, a, vl); - va_end(vl); + message = g_strdup_vprintf(format, args); + if (prefix) { + gchar *a = message; + message = g_strconcat(prefix, message, NULL); + g_free(a); } + + g_debug(message); + g_free(message); +} + +void ob_debug(const gchar *a, ...) +{ + va_list vl; + + va_start(vl, a); + log_argv(OB_DEBUG_NORMAL, a, vl); + va_end(vl); +} + +void ob_debug_type(ObDebugType type, const gchar *a, ...) +{ + va_list vl; + + va_start(vl, a); + log_argv(type, a, vl); + va_end(vl); } diff --git a/openbox/debug.h b/openbox/debug.h index 3c6bedf..a24e66e 100644 --- a/openbox/debug.h +++ b/openbox/debug.h @@ -21,11 +21,13 @@ #include -void ob_debug_show_output(gboolean enable); +void ob_debug_startup(void); +void ob_debug_shutdown(void); void ob_debug(const gchar *a, ...); typedef enum { + OB_DEBUG_NORMAL, OB_DEBUG_FOCUS, OB_DEBUG_APP_BUGS, OB_DEBUG_SM, diff --git a/openbox/dock.c b/openbox/dock.c index 4c183e2..ee1202c 100644 --- a/openbox/dock.c +++ b/openbox/dock.c @@ -19,13 +19,12 @@ #include "debug.h" #include "dock.h" -#include "mainloop.h" #include "screen.h" -#include "prop.h" #include "config.h" #include "grab.h" #include "openbox.h" #include "render/theme.h" +#include "obt/prop.h" #define DOCK_EVENT_MASK (ButtonPressMask | ButtonReleaseMask | \ EnterWindowMask | LeaveWindowMask) @@ -51,6 +50,9 @@ static void dock_app_grab_button(ObDockApp *app, gboolean grab) } } +static guint window_hash(Window *w) { return *w; } +static gboolean window_comp(Window *w1, Window *w2) { return *w1 == *w2; } + void dock_startup(gboolean reconfig) { XSetWindowAttributes attrib; @@ -58,9 +60,9 @@ void dock_startup(gboolean reconfig) if (reconfig) { GList *it; - XSetWindowBorder(ob_display, dock->frame, + XSetWindowBorder(obt_display, dock->frame, RrColorPixel(ob_rr_theme->osd_border_color)); - XSetWindowBorderWidth(ob_display, dock->frame, ob_rr_theme->obwidth); + XSetWindowBorderWidth(obt_display, dock->frame, ob_rr_theme->obwidth); RrAppearanceFree(dock->a_frame); dock->a_frame = RrAppearanceCopy(ob_rr_theme->osd_hilite_bg); @@ -79,14 +81,17 @@ void dock_startup(gboolean reconfig) 0, 0, 0, 0, 0, 0, 0, 0); dock = g_new0(ObDock, 1); - dock->obwin.type = Window_Dock; + dock->obwin.type = OB_WINDOW_CLASS_DOCK; dock->hidden = TRUE; + dock->dock_map = g_hash_table_new((GHashFunc)window_hash, + (GEqualFunc)window_comp); + attrib.event_mask = DOCK_EVENT_MASK; attrib.override_redirect = True; attrib.do_not_propagate_mask = DOCK_NOPROPAGATEMASK; - dock->frame = XCreateWindow(ob_display, RootWindow(ob_display, ob_screen), + dock->frame = XCreateWindow(obt_display, obt_root(ob_screen), 0, 0, 1, 1, 0, RrDepth(ob_rr_inst), InputOutput, RrVisual(ob_rr_inst), @@ -94,15 +99,15 @@ void dock_startup(gboolean reconfig) CWDontPropagate, &attrib); dock->a_frame = RrAppearanceCopy(ob_rr_theme->osd_hilite_bg); - XSetWindowBorder(ob_display, dock->frame, + XSetWindowBorder(obt_display, dock->frame, RrColorPixel(ob_rr_theme->osd_border_color)); - XSetWindowBorderWidth(ob_display, dock->frame, ob_rr_theme->obwidth); + XSetWindowBorderWidth(obt_display, dock->frame, ob_rr_theme->obwidth); /* Setting the window type so xcompmgr can tell what it is */ - PROP_SET32(dock->frame, net_wm_window_type, atom, - prop_atoms.net_wm_window_type_dock); + OBT_PROP_SET32(dock->frame, NET_WM_WINDOW_TYPE, ATOM, + OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DOCK)); - g_hash_table_insert(window_map, &dock->frame, dock); + window_add(&dock->frame, DOCK_AS_WINDOW(dock)); stacking_add(DOCK_AS_WINDOW(dock)); } @@ -118,25 +123,25 @@ void dock_shutdown(gboolean reconfig) return; } - XDestroyWindow(ob_display, dock->frame); + g_hash_table_destroy(dock->dock_map); + + XDestroyWindow(obt_display, dock->frame); RrAppearanceFree(dock->a_frame); - g_hash_table_remove(window_map, &dock->frame); + window_remove(dock->frame); stacking_remove(dock); } -void dock_add(Window win, XWMHints *wmhints) +void dock_manage(Window icon_win, Window name_win) { ObDockApp *app; XWindowAttributes attrib; gchar **data; app = g_new0(ObDockApp, 1); - app->obwin.type = Window_DockApp; - app->win = win; - app->icon_win = (wmhints->flags & IconWindowHint) ? - wmhints->icon_window : win; + app->name_win = name_win; + app->icon_win = icon_win; - if (PROP_GETSS(app->win, wm_class, locale, &data)) { + if (OBT_PROP_GETSS(app->name_win, WM_CLASS, locale, &data)) { if (data[0]) { app->name = g_strdup(data[0]); if (data[1]) @@ -148,7 +153,7 @@ void dock_add(Window win, XWMHints *wmhints) if (app->name == NULL) app->name = g_strdup(""); if (app->class == NULL) app->class = g_strdup(""); - if (XGetWindowAttributes(ob_display, app->icon_win, &attrib)) { + if (XGetWindowAttributes(obt_display, app->icon_win, &attrib)) { app->w = attrib.width; app->h = attrib.height; } else { @@ -156,9 +161,10 @@ void dock_add(Window win, XWMHints *wmhints) } dock->dock_apps = g_list_append(dock->dock_apps, app); + g_hash_table_insert(dock->dock_map, &app->icon_win, app); dock_configure(); - XReparentWindow(ob_display, app->icon_win, dock->frame, app->x, app->y); + XReparentWindow(obt_display, app->icon_win, dock->frame, app->x, app->y); /* This is the same case as in frame.c for client windows. When Openbox is starting, the window is already mapped so we see unmap events occur for @@ -168,51 +174,53 @@ void dock_add(Window win, XWMHints *wmhints) */ if (ob_state() == OB_STATE_STARTING) app->ignore_unmaps += 2; + XChangeSaveSet(obt_display, app->icon_win, SetModeInsert); + XMapWindow(obt_display, app->icon_win); - if (app->win != app->icon_win) { - /* have to map it so that it can be re-managed on a restart */ - XMoveWindow(ob_display, app->win, -1000, -1000); - XMapWindow(ob_display, app->win); + if (app->name_win != app->icon_win) { + XReparentWindow(obt_display, app->name_win, dock->frame, -1000, -1000); + XChangeSaveSet(obt_display, app->name_win, SetModeInsert); + XMapWindow(obt_display, app->name_win); } - XMapWindow(ob_display, app->icon_win); - XSync(ob_display, False); - /* specify that if we exit, the window should not be destroyed and should - be reparented back to root automatically */ - XChangeSaveSet(ob_display, app->icon_win, SetModeInsert); - XSelectInput(ob_display, app->icon_win, DOCKAPP_EVENT_MASK); + XSync(obt_display, False); + + XSelectInput(obt_display, app->icon_win, DOCKAPP_EVENT_MASK); dock_app_grab_button(app, TRUE); - g_hash_table_insert(window_map, &app->icon_win, app); + ob_debug("Managed Dock App: 0x%lx 0x%lx (%s)", + app->icon_win, app->name_win, app->class); - ob_debug("Managed Dock App: 0x%lx (%s)\n", app->icon_win, app->class); + grab_server(FALSE); } -void dock_remove_all(void) +void dock_unmanage_all(void) { while (dock->dock_apps) - dock_remove(dock->dock_apps->data, TRUE); + dock_unmanage(dock->dock_apps->data, TRUE); } -void dock_remove(ObDockApp *app, gboolean reparent) +void dock_unmanage(ObDockApp *app, gboolean reparent) { dock_app_grab_button(app, FALSE); - XSelectInput(ob_display, app->icon_win, NoEventMask); + XSelectInput(obt_display, app->icon_win, NoEventMask); /* remove the window from our save set */ - XChangeSaveSet(ob_display, app->icon_win, SetModeDelete); - XSync(ob_display, False); - - g_hash_table_remove(window_map, &app->icon_win); - - if (reparent) - XReparentWindow(ob_display, app->icon_win, - RootWindow(ob_display, ob_screen), app->x, app->y); + XChangeSaveSet(obt_display, app->icon_win, SetModeDelete); + XSync(obt_display, False); + + if (reparent) { + XReparentWindow(obt_display, app->icon_win, obt_root(ob_screen), 0, 0); + if (app->name_win != app->icon_win) + XReparentWindow(obt_display, app->name_win, + obt_root(ob_screen), 0, 0); + } dock->dock_apps = g_list_remove(dock->dock_apps, app); + g_hash_table_remove(dock->dock_map, &app->icon_win); dock_configure(); - ob_debug("Unmanaged Dock App: 0x%lx (%s)\n", app->icon_win, app->class); + ob_debug("Unmanaged Dock App: 0x%lx (%s)", app->icon_win, app->class); g_free(app->name); g_free(app->class); @@ -273,7 +281,7 @@ void dock_configure(void) break; } - XMoveWindow(ob_display, app->icon_win, app->x, app->y); + XMoveWindow(obt_display, app->icon_win, app->x, app->y); } /* used for calculating offsets */ @@ -523,14 +531,14 @@ void dock_configure(void) g_assert(dock->area.width > 0); g_assert(dock->area.height > 0); - XMoveResizeWindow(ob_display, dock->frame, dock->area.x, dock->area.y, + XMoveResizeWindow(obt_display, dock->frame, dock->area.x, dock->area.y, dock->area.width, dock->area.height); RrPaint(dock->a_frame, dock->frame, dock->area.width, dock->area.height); - XMapWindow(ob_display, dock->frame); + XMapWindow(obt_display, dock->frame); } else - XUnmapWindow(ob_display, dock->frame); + XUnmapWindow(obt_display, dock->frame); /* but they are useful outside of this function! but don't add it if the dock is actually not visible */ @@ -636,19 +644,21 @@ void dock_hide(gboolean hide) { if (!hide) { if (dock->hidden && config_dock_hide) { - ob_main_loop_timeout_add(ob_main_loop, - config_dock_show_delay * 1000, - show_timeout, NULL, g_direct_equal, NULL); + obt_main_loop_timeout_add(ob_main_loop, + config_dock_show_delay * 1000, + show_timeout, NULL, + g_direct_equal, NULL); } else if (!dock->hidden && config_dock_hide) { - ob_main_loop_timeout_remove(ob_main_loop, hide_timeout); + obt_main_loop_timeout_remove(ob_main_loop, hide_timeout); } } else { if (!dock->hidden && config_dock_hide) { - ob_main_loop_timeout_add(ob_main_loop, - config_dock_hide_delay * 1000, - hide_timeout, NULL, g_direct_equal, NULL); + obt_main_loop_timeout_add(ob_main_loop, + config_dock_hide_delay * 1000, + hide_timeout, NULL, + g_direct_equal, NULL); } else if (dock->hidden && config_dock_hide) { - ob_main_loop_timeout_remove(ob_main_loop, show_timeout); + obt_main_loop_timeout_remove(ob_main_loop, show_timeout); } } } @@ -658,3 +668,8 @@ void dock_get_area(Rect *a) RECT_SET(*a, dock->area.x, dock->area.y, dock->area.width, dock->area.height); } + +ObDockApp* dock_find_dockapp(Window xwin) +{ + return g_hash_table_lookup(dock->dock_map, &xwin); +} diff --git a/openbox/dock.h b/openbox/dock.h index 57c1f39..3463f27 100644 --- a/openbox/dock.h +++ b/openbox/dock.h @@ -44,15 +44,14 @@ struct _ObDock gboolean hidden; GList *dock_apps; + GHashTable *dock_map; }; struct _ObDockApp { - ObWindow obwin; - gint ignore_unmaps; Window icon_win; - Window win; + Window name_win; gchar *name; gchar *class; @@ -68,17 +67,19 @@ extern StrutPartial dock_strut; void dock_startup(gboolean reconfig); void dock_shutdown(gboolean reconfig); -void dock_configure(); +void dock_configure(void); void dock_hide(gboolean hide); -void dock_add(Window win, XWMHints *wmhints); +void dock_manage(Window icon_win, Window name_win); -void dock_remove_all(); -void dock_remove(ObDockApp *app, gboolean reparent); +void dock_unmanage_all(void); +void dock_unmanage(ObDockApp *app, gboolean reparent); void dock_app_drag(ObDockApp *app, XMotionEvent *e); void dock_app_configure(ObDockApp *app, gint w, gint h); void dock_get_area(Rect *a); +ObDockApp* dock_find_dockapp(Window xwin); + #endif diff --git a/openbox/event.c b/openbox/event.c index 5c4700a..9705fb6 100644 --- a/openbox/event.c +++ b/openbox/event.c @@ -24,8 +24,6 @@ #include "dock.h" #include "actions.h" #include "client.h" -#include "xerror.h" -#include "prop.h" #include "config.h" #include "screen.h" #include "frame.h" @@ -34,17 +32,17 @@ #include "prompt.h" #include "menuframe.h" #include "keyboard.h" -#include "modkeys.h" #include "mouse.h" -#include "mainloop.h" +#include "hooks.h" #include "focus.h" #include "focus_cycle.h" #include "moveresize.h" #include "group.h" #include "stacking.h" -#include "extensions.h" -#include "translate.h" #include "ping.h" +#include "obt/display.h" +#include "obt/prop.h" +#include "obt/keyboard.h" #include #include @@ -87,8 +85,8 @@ typedef struct static void event_process(const XEvent *e, gpointer data); static void event_handle_root(XEvent *e); -static gboolean event_handle_menu_keyboard(XEvent *e); -static gboolean event_handle_menu(XEvent *e); +static gboolean event_handle_menu_input(XEvent *e); +static void event_handle_menu(ObMenuFrame *frame, XEvent *e); static gboolean event_handle_prompt(ObPrompt *p, XEvent *e); static void event_handle_dock(ObDock *s, XEvent *e); static void event_handle_dockapp(ObDockApp *app, XEvent *e); @@ -125,9 +123,9 @@ static void ice_watch(IceConn conn, IcePointer data, Bool opening, if (opening) { fd = IceConnectionNumber(conn); - ob_main_loop_fd_add(ob_main_loop, fd, ice_handler, conn, NULL); + obt_main_loop_fd_add(ob_main_loop, fd, ice_handler, conn, NULL); } else { - ob_main_loop_fd_remove(ob_main_loop, fd); + obt_main_loop_fd_remove(ob_main_loop, fd); fd = -1; } } @@ -137,7 +135,7 @@ void event_startup(gboolean reconfig) { if (reconfig) return; - ob_main_loop_x_add(ob_main_loop, event_process, NULL, NULL); + obt_main_loop_x_add(ob_main_loop, event_process, NULL, NULL); #ifdef USE_SM IceAddConnectionWatch(ice_watch, NULL); @@ -164,9 +162,15 @@ static Window event_get_window(XEvent *e) /* pick a window */ switch (e->type) { case SelectionClear: - window = RootWindow(ob_display, ob_screen); + window = obt_root(ob_screen); + break; + case CreateNotify: + window = e->xcreatewindow.window; break; case MapRequest: + window = e->xmaprequest.window; + break; + case MapNotify: window = e->xmap.window; break; case UnmapNotify: @@ -183,7 +187,9 @@ static Window event_get_window(XEvent *e) break; default: #ifdef XKB - if (extensions_xkb && e->type == extensions_xkb_event_basep) { + if (obt_display_extension_xkb && + e->type == obt_display_extension_xkb_basep) + { switch (((XkbAnyEvent*)e)->xkb_type) { case XkbBellNotify: window = ((XkbBellNotifyEvent*)e)->window; @@ -193,8 +199,8 @@ static Window event_get_window(XEvent *e) } else #endif #ifdef SYNC - if (extensions_sync && - e->type == extensions_sync_event_basep + XSyncAlarmNotify) + if (obt_display_extension_sync && + e->type == obt_display_extension_sync_basep + XSyncAlarmNotify) { window = None; } else @@ -232,8 +238,8 @@ static void event_set_curtime(XEvent *e) break; default: #ifdef SYNC - if (extensions_sync && - e->type == extensions_sync_event_basep + XSyncAlarmNotify) + if (obt_display_extension_sync && + e->type == obt_display_extension_sync_basep + XSyncAlarmNotify) { t = ((XSyncAlarmNotifyEvent*)e)->time; } @@ -261,34 +267,34 @@ static void event_hack_mods(XEvent *e) switch (e->type) { case ButtonPress: case ButtonRelease: - e->xbutton.state = modkeys_only_modifier_masks(e->xbutton.state); + e->xbutton.state = obt_keyboard_only_modmasks(e->xbutton.state); break; case KeyPress: - e->xkey.state = modkeys_only_modifier_masks(e->xkey.state); + e->xkey.state = obt_keyboard_only_modmasks(e->xkey.state); break; case KeyRelease: #ifdef XKB /* If XKB is present, then the modifiers are all strange from its magic. Our X core protocol stuff won't work, so we use this to find what the modifier state is instead. */ - if (XkbGetState(ob_display, XkbUseCoreKbd, &xkb_state) == Success) + if (XkbGetState(obt_display, XkbUseCoreKbd, &xkb_state) == Success) e->xkey.state = - modkeys_only_modifier_masks(xkb_state.compat_state); + obt_keyboard_only_modmasks(xkb_state.compat_state); else #endif { - e->xkey.state = modkeys_only_modifier_masks(e->xkey.state); + e->xkey.state = obt_keyboard_only_modmasks(e->xkey.state); /* remove from the state the mask of the modifier key being released, if it is a modifier key being released that is */ - e->xkey.state &= ~modkeys_keycode_to_mask(e->xkey.keycode); + e->xkey.state &= ~obt_keyboard_keycode_to_modmask(e->xkey.keycode); } break; case MotionNotify: - e->xmotion.state = modkeys_only_modifier_masks(e->xmotion.state); + e->xmotion.state = obt_keyboard_only_modmasks(e->xmotion.state); /* compress events */ { XEvent ce; - while (XCheckTypedWindowEvent(ob_display, e->xmotion.window, + while (XCheckTypedWindowEvent(obt_display, e->xmotion.window, e->type, &ce)) { e->xmotion.x = ce.xmotion.x; e->xmotion.y = ce.xmotion.y; @@ -318,7 +324,7 @@ static gboolean wanted_focusevent(XEvent *e, gboolean in_client_only) /* These are the ones we want.. */ - if (win == RootWindow(ob_display, ob_screen)) { + if (win == obt_root(ob_screen)) { /* If looking for a focus in on a client, then always return FALSE for focus in's to the root window */ if (in_client_only) @@ -339,7 +345,7 @@ static gboolean wanted_focusevent(XEvent *e, gboolean in_client_only) but has disappeared. */ if (in_client_only) { - ObWindow *w = g_hash_table_lookup(window_map, &e->xfocus.window); + ObWindow *w = window_find(e->xfocus.window); if (!w || !WINDOW_IS_CLIENT(w)) return FALSE; } @@ -372,7 +378,7 @@ static gboolean wanted_focusevent(XEvent *e, gboolean in_client_only) return FALSE; /* Focus left the root window revertedto state */ - if (win == RootWindow(ob_display, ob_screen)) + if (win == obt_root(ob_screen)) return FALSE; /* These are the ones we want.. */ @@ -428,7 +434,7 @@ static void print_focusevent(XEvent *e) g_assert(modestr); g_assert(detailstr); - ob_debug_type(OB_DEBUG_FOCUS, "Focus%s 0x%x mode=%s detail=%s\n", + ob_debug_type(OB_DEBUG_FOCUS, "Focus%s 0x%x mode=%s detail=%s", (e->xfocus.type == FocusIn ? "In" : "Out"), win, modestr, detailstr); @@ -454,13 +460,15 @@ static gboolean event_ignore(XEvent *e, ObClient *client) static void event_process(const XEvent *ec, gpointer data) { + XEvent ee, *e; + ObEventData *ed = data; + Window window; ObClient *client = NULL; ObDock *dock = NULL; ObDockApp *dockapp = NULL; ObWindow *obwin = NULL; - XEvent ee, *e; - ObEventData *ed = data; + ObMenuFrame *menu = NULL; ObPrompt *prompt = NULL; /* make a copy we can mangle */ @@ -468,31 +476,31 @@ static void event_process(const XEvent *ec, gpointer data) e = ⅇ window = event_get_window(e); - if ((obwin = g_hash_table_lookup(window_map, &window))) { + if (window == obt_root(ob_screen)) + /* don't do any lookups, waste of cpu */; + else if ((obwin = window_find(window))) { switch (obwin->type) { - case Window_Dock: + case OB_WINDOW_CLASS_DOCK: dock = WINDOW_AS_DOCK(obwin); break; - case Window_DockApp: - dockapp = WINDOW_AS_DOCKAPP(obwin); - break; - case Window_Client: + case OB_WINDOW_CLASS_CLIENT: client = WINDOW_AS_CLIENT(obwin); /* events on clients can be events on prompt windows too */ prompt = client->prompt; break; - case Window_Menu: - /* not to be used for events */ - g_assert_not_reached(); + case OB_WINDOW_CLASS_MENUFRAME: + menu = WINDOW_AS_MENUFRAME(obwin); break; - case Window_Internal: + case OB_WINDOW_CLASS_INTERNAL: /* we don't do anything with events directly on these windows */ break; - case Window_Prompt: + case OB_WINDOW_CLASS_PROMPT: prompt = WINDOW_AS_PROMPT(obwin); break; } } + else + dockapp = dock_find_dockapp(window); event_set_curtime(e); event_curserial = e->xany.serial; @@ -506,12 +514,7 @@ static void event_process(const XEvent *ec, gpointer data) /* deal with it in the kernel */ - if (menu_frame_visible && - (e->type == EnterNotify || e->type == LeaveNotify)) - { - /* crossing events for menu */ - event_handle_menu(e); - } else if (e->type == FocusIn) { + if (e->type == FocusIn) { if (client && e->xfocus.detail == NotifyInferior) { @@ -536,7 +539,7 @@ static void event_process(const XEvent *ec, gpointer data) XEvent ce; ob_debug_type(OB_DEBUG_FOCUS, - "Focus went to root or pointer root/none\n"); + "Focus went to root or pointer root/none"); if (e->xfocus.detail == NotifyInferior || e->xfocus.detail == NotifyNonlinear) @@ -557,12 +560,12 @@ static void event_process(const XEvent *ec, gpointer data) But if the other focus in is something like PointerRoot then we still want to fall back. */ - if (XCheckIfEvent(ob_display, &ce, event_look_for_focusin_client, + if (XCheckIfEvent(obt_display, &ce, event_look_for_focusin_client, NULL)) { - XPutBackEvent(ob_display, &ce); + XPutBackEvent(obt_display, &ce); ob_debug_type(OB_DEBUG_FOCUS, - " but another FocusIn is coming\n"); + " but another FocusIn is coming"); } else { /* Focus has been reverted. @@ -578,7 +581,7 @@ static void event_process(const XEvent *ec, gpointer data) else if (!client) { ob_debug_type(OB_DEBUG_FOCUS, - "Focus went to a window that is already gone\n"); + "Focus went to a window that is already gone"); /* If you send focus to a window and then it disappears, you can get the FocusIn for it, after it is unmanaged. @@ -597,25 +600,25 @@ static void event_process(const XEvent *ec, gpointer data) XEvent ce; /* Look for the followup FocusIn */ - if (!XCheckIfEvent(ob_display, &ce, event_look_for_focusin, NULL)) { + if (!XCheckIfEvent(obt_display, &ce, event_look_for_focusin, NULL)) { /* There is no FocusIn, this means focus went to a window that is not being managed, or a window on another screen. */ Window win, root; gint i; guint u; - xerror_set_ignore(TRUE); - if (XGetInputFocus(ob_display, &win, &i) != 0 && - XGetGeometry(ob_display, win, &root, &i,&i,&u,&u,&u,&u) != 0 && - root != RootWindow(ob_display, ob_screen)) + obt_display_ignore_errors(TRUE); + if (XGetInputFocus(obt_display, &win, &i) && + XGetGeometry(obt_display, win, &root, &i,&i,&u,&u,&u,&u) && + root != obt_root(ob_screen)) { ob_debug_type(OB_DEBUG_FOCUS, - "Focus went to another screen !\n"); + "Focus went to another screen !"); focus_left_screen = TRUE; } else ob_debug_type(OB_DEBUG_FOCUS, - "Focus went to a black hole !\n"); - xerror_set_ignore(FALSE); + "Focus went to a black hole !"); + obt_display_ignore_errors(FALSE); /* nothing is focused */ focus_set_client(NULL); } else { @@ -626,7 +629,7 @@ static void event_process(const XEvent *ec, gpointer data) /* The FocusIn was ignored, this means it was on a window that isn't a client. */ ob_debug_type(OB_DEBUG_FOCUS, - "Focus went to an unmanaged window 0x%x !\n", + "Focus went to an unmanaged window 0x%x !", ce.xfocus.window); focus_fallback(TRUE, config_focus_under_mouse, TRUE, TRUE); } @@ -644,22 +647,25 @@ static void event_process(const XEvent *ec, gpointer data) event_handle_dockapp(dockapp, e); else if (dock) event_handle_dock(dock, e); - else if (window == RootWindow(ob_display, ob_screen)) + else if (menu) + event_handle_menu(menu, e); + else if (window == obt_root(ob_screen)) event_handle_root(e); else if (e->type == MapRequest) - client_manage(window, NULL); + window_manage(window); else if (e->type == MappingNotify) { /* keyboard layout changes for modifier mapping changes. reload the modifier map, and rebind all the key bindings as appropriate */ - ob_debug("Kepboard map changed. Reloading keyboard bindings.\n"); - modkeys_shutdown(TRUE); - modkeys_startup(TRUE); + ob_debug("Kepboard map changed. Reloading keyboard bindings."); + obt_keyboard_reload(); keyboard_rebind(); } else if (e->type == ClientMessage) { /* This is for _NET_WM_REQUEST_FRAME_EXTENTS messages. They come for windows that are not managed yet. */ - if (e->xclient.message_type == prop_atoms.net_request_frame_extents) { + if (e->xclient.message_type == + OBT_PROP_ATOM(NET_REQUEST_FRAME_EXTENTS)) + { /* Pretend to manage the client, getting information used to determine its decorations */ ObClient *c = client_fake_manage(e->xclient.window); @@ -670,8 +676,8 @@ static void event_process(const XEvent *ec, gpointer data) vals[1] = c->frame->size.right; vals[2] = c->frame->size.top; vals[3] = c->frame->size.bottom; - PROP_SETA32(e->xclient.window, net_frame_extents, - cardinal, vals, 4); + OBT_PROP_SETA32(e->xclient.window, NET_FRAME_EXTENTS, + CARDINAL, vals, 4); /* Free the pretend client */ client_fake_unmanage(c); @@ -692,14 +698,14 @@ static void event_process(const XEvent *ec, gpointer data) /* we are not to be held responsible if someone sends us an invalid request! */ - xerror_set_ignore(TRUE); - XConfigureWindow(ob_display, window, + obt_display_ignore_errors(TRUE); + XConfigureWindow(obt_display, window, e->xconfigurerequest.value_mask, &xwc); - xerror_set_ignore(FALSE); + obt_display_ignore_errors(FALSE); } #ifdef SYNC - else if (extensions_sync && - e->type == extensions_sync_event_basep + XSyncAlarmNotify) + else if (obt_display_extension_sync && + e->type == obt_display_extension_sync_basep + XSyncAlarmNotify) { XSyncAlarmNotifyEvent *se = (XSyncAlarmNotifyEvent*)e; if (se->alarm == moveresize_alarm && moveresize_in_progress) @@ -712,7 +718,7 @@ static void event_process(const XEvent *ec, gpointer data) else if (e->type == ButtonPress || e->type == ButtonRelease) { /* If the button press was on some non-root window, or was physically on the root window, then process it */ - if (window != RootWindow(ob_display, ob_screen) || + if (window != obt_root(ob_screen) || e->xbutton.subwindow == None) { event_handle_user_input(client, e); @@ -722,7 +728,7 @@ static void event_process(const XEvent *ec, gpointer data) else { ObWindow *w; - if ((w = g_hash_table_lookup(window_map, &e->xbutton.subwindow)) && + if ((w = window_find(e->xbutton.subwindow)) && WINDOW_IS_INTERNAL(w)) { event_handle_user_input(client, e); @@ -733,6 +739,11 @@ static void event_process(const XEvent *ec, gpointer data) e->type == MotionNotify) event_handle_user_input(client, e); + XFlush(obt_display); + + /* run all the hooks at once */ + hooks_run_queue(); + /* if something happens and it's not from an XEvent, then we don't know the time */ event_curtime = CurrentTime; @@ -745,7 +756,7 @@ static void event_handle_root(XEvent *e) switch(e->type) { case SelectionClear: - ob_debug("Another WM has requested to replace us. Exiting.\n"); + ob_debug("Another WM has requested to replace us. Exiting."); ob_exit_replace(); break; @@ -753,41 +764,41 @@ static void event_handle_root(XEvent *e) if (e->xclient.format != 32) break; msgtype = e->xclient.message_type; - if (msgtype == prop_atoms.net_current_desktop) { + if (msgtype == OBT_PROP_ATOM(NET_CURRENT_DESKTOP)) { guint d = e->xclient.data.l[0]; if (d < screen_num_desktops) { event_curtime = e->xclient.data.l[1]; if (event_curtime == 0) ob_debug_type(OB_DEBUG_APP_BUGS, "_NET_CURRENT_DESKTOP message is missing " - "a timestamp\n"); + "a timestamp"); screen_set_desktop(d, TRUE); } - } else if (msgtype == prop_atoms.net_number_of_desktops) { + } else if (msgtype == OBT_PROP_ATOM(NET_NUMBER_OF_DESKTOPS)) { guint d = e->xclient.data.l[0]; if (d > 0 && d <= 1000) screen_set_num_desktops(d); - } else if (msgtype == prop_atoms.net_showing_desktop) { + } else if (msgtype == OBT_PROP_ATOM(NET_SHOWING_DESKTOP)) { screen_show_desktop(e->xclient.data.l[0] != 0, NULL); - } else if (msgtype == prop_atoms.ob_control) { - ob_debug("OB_CONTROL: %d\n", e->xclient.data.l[0]); + } else if (msgtype == OBT_PROP_ATOM(OB_CONTROL)) { + ob_debug("OB_CONTROL: %d", e->xclient.data.l[0]); if (e->xclient.data.l[0] == 1) ob_reconfigure(); else if (e->xclient.data.l[0] == 2) ob_restart(); else if (e->xclient.data.l[0] == 3) ob_exit(0); - } else if (msgtype == prop_atoms.wm_protocols) { - if ((Atom)e->xclient.data.l[0] == prop_atoms.net_wm_ping) + } else if (msgtype == OBT_PROP_ATOM(WM_PROTOCOLS)) { + if ((Atom)e->xclient.data.l[0] == OBT_PROP_ATOM(NET_WM_PING)) ping_got_pong(e->xclient.data.l[1]); } break; case PropertyNotify: - if (e->xproperty.atom == prop_atoms.net_desktop_names) { - ob_debug("UPDATE DESKTOP NAMES\n"); + if (e->xproperty.atom == OBT_PROP_ATOM(NET_DESKTOP_NAMES)) { + ob_debug("UPDATE DESKTOP NAMES"); screen_update_desktop_names(); } - else if (e->xproperty.atom == prop_atoms.net_desktop_layout) + else if (e->xproperty.atom == OBT_PROP_ATOM(NET_DESKTOP_LAYOUT)) screen_update_layout(); break; case ConfigureNotify: @@ -815,17 +826,17 @@ void event_enter_client(ObClient *client) if (config_focus_delay) { ObFocusDelayData *data; - ob_main_loop_timeout_remove(ob_main_loop, focus_delay_func); + obt_main_loop_timeout_remove(ob_main_loop, focus_delay_func); data = g_new(ObFocusDelayData, 1); data->client = client; data->time = event_curtime; data->serial = event_curserial; - ob_main_loop_timeout_add(ob_main_loop, - config_focus_delay * 1000, - focus_delay_func, - data, focus_delay_cmp, focus_delay_dest); + obt_main_loop_timeout_add(ob_main_loop, + config_focus_delay * 1000, + focus_delay_func, + data, focus_delay_cmp, focus_delay_dest); } else { ObFocusDelayData data; data.client = client; @@ -875,12 +886,12 @@ static void compress_client_message_event(XEvent *e, XEvent *ce, Window window, Atom msgtype) { /* compress changes into a single change */ - while (XCheckTypedWindowEvent(ob_display, window, e->type, ce)) { + while (XCheckTypedWindowEvent(obt_display, window, e->type, ce)) { /* XXX: it would be nice to compress ALL messages of a type, not just messages in a row without other message types between. */ if (ce->xclient.message_type != msgtype) { - XPutBackEvent(ob_display, ce); + XPutBackEvent(obt_display, ce); break; } e->xclient = ce->xclient; @@ -999,7 +1010,7 @@ static void event_handle_client(ObClient *client, XEvent *e) event_end_ignore_all_enters(event_start_ignore_all_enters()); ob_debug_type(OB_DEBUG_FOCUS, - "%sNotify mode %d detail %d on %lx\n", + "%sNotify mode %d detail %d on %lx", (e->type == EnterNotify ? "Enter" : "Leave"), e->xcrossing.mode, e->xcrossing.detail, (client?client->window:0)); @@ -1011,9 +1022,9 @@ static void event_handle_client(ObClient *client, XEvent *e) delay is up */ e->xcrossing.detail != NotifyInferior) { - ob_main_loop_timeout_remove_data(ob_main_loop, - focus_delay_func, - client, FALSE); + obt_main_loop_timeout_remove_data(ob_main_loop, + focus_delay_func, + client, FALSE); } break; default: @@ -1044,7 +1055,7 @@ static void event_handle_client(ObClient *client, XEvent *e) { ob_debug_type(OB_DEBUG_FOCUS, "%sNotify mode %d detail %d serial %lu on %lx " - "IGNORED\n", + "IGNORED", (e->type == EnterNotify ? "Enter" : "Leave"), e->xcrossing.mode, e->xcrossing.detail, @@ -1054,7 +1065,7 @@ static void event_handle_client(ObClient *client, XEvent *e) else { ob_debug_type(OB_DEBUG_FOCUS, "%sNotify mode %d detail %d serial %lu on %lx, " - "focusing window\n", + "focusing window", (e->type == EnterNotify ? "Enter" : "Leave"), e->xcrossing.mode, e->xcrossing.detail, @@ -1094,10 +1105,10 @@ static void event_handle_client(ObClient *client, XEvent *e) RECT_TO_DIMS(client->area, x, y, w, h); ob_debug("ConfigureRequest for \"%s\" desktop %d wmstate %d " - "visible %d\n" - " x %d y %d w %d h %d b %d\n", + "visible %d", client->title, - screen_desktop, client->wmstate, client->frame->visible, + screen_desktop, client->wmstate, client->frame->visible); + ob_debug(" x %d y %d w %d h %d b %d", x, y, w, h, client->border_width); if (e->xconfigurerequest.value_mask & CWBorderWidth) @@ -1121,8 +1132,7 @@ static void event_handle_client(ObClient *client, XEvent *e) /* get the sibling */ if (e->xconfigurerequest.value_mask & CWSibling) { ObWindow *win; - win = g_hash_table_lookup(window_map, - &e->xconfigurerequest.above); + win = window_find(e->xconfigurerequest.above); if (win && WINDOW_IS_CLIENT(win) && WINDOW_AS_CLIENT(win) != client) { @@ -1176,7 +1186,7 @@ static void event_handle_client(ObClient *client, XEvent *e) } ob_debug("ConfigureRequest x(%d) %d y(%d) %d w(%d) %d h(%d) %d " - "move %d resize %d\n", + "move %d resize %d", e->xconfigurerequest.value_mask & CWX, x, e->xconfigurerequest.value_mask & CWY, y, e->xconfigurerequest.value_mask & CWWidth, w, @@ -1202,7 +1212,7 @@ static void event_handle_client(ObClient *client, XEvent *e) ob_debug_type(OB_DEBUG_APP_BUGS, "Application %s is trying to move via " "ConfigureRequest to it's root window position " - "but it is not using StaticGravity\n", + "but it is not using StaticGravity", client->title); /* don't move it */ x = client->area.x; @@ -1229,25 +1239,25 @@ static void event_handle_client(ObClient *client, XEvent *e) client_find_onscreen(client, &x, &y, w, h, FALSE); - ob_debug("Granting ConfigureRequest x %d y %d w %d h %d\n", + ob_debug("Granting ConfigureRequest x %d y %d w %d h %d", x, y, w, h); client_configure(client, x, y, w, h, FALSE, TRUE, TRUE); } break; } case UnmapNotify: + ob_debug("UnmapNotify for window 0x%x eventwin 0x%x sendevent %d " + "ignores left %d", + client->window, e->xunmap.event, e->xunmap.from_configure, + client->ignore_unmaps); if (client->ignore_unmaps) { client->ignore_unmaps--; break; } - ob_debug("UnmapNotify for window 0x%x eventwin 0x%x sendevent %d " - "ignores left %d\n", - client->window, e->xunmap.event, e->xunmap.from_configure, - client->ignore_unmaps); client_unmanage(client); break; case DestroyNotify: - ob_debug("DestroyNotify for window 0x%x\n", client->window); + ob_debug("DestroyNotify for window 0x%x", client->window); client_unmanage(client); break; case ReparentNotify: @@ -1263,13 +1273,13 @@ static void event_handle_client(ObClient *client, XEvent *e) /* we don't want the reparent event, put it back on the stack for the X server to deal with after we unmanage the window */ - XPutBackEvent(ob_display, e); + XPutBackEvent(obt_display, e); - ob_debug("ReparentNotify for window 0x%x\n", client->window); + ob_debug("ReparentNotify for window 0x%x", client->window); client_unmanage(client); break; case MapRequest: - ob_debug("MapRequest for 0x%lx\n", client->window); + ob_debug("MapRequest for 0x%lx", client->window); if (!client->iconic) break; /* this normally doesn't happen, but if it does, we don't want it! it can happen now when the window is on @@ -1284,20 +1294,20 @@ static void event_handle_client(ObClient *client, XEvent *e) if (e->xclient.format != 32) return; msgtype = e->xclient.message_type; - if (msgtype == prop_atoms.wm_change_state) { + if (msgtype == OBT_PROP_ATOM(WM_CHANGE_STATE)) { compress_client_message_event(e, &ce, client->window, msgtype); client_set_wm_state(client, e->xclient.data.l[0]); - } else if (msgtype == prop_atoms.net_wm_desktop) { + } else if (msgtype == OBT_PROP_ATOM(NET_WM_DESKTOP)) { compress_client_message_event(e, &ce, client->window, msgtype); if ((unsigned)e->xclient.data.l[0] < screen_num_desktops || (unsigned)e->xclient.data.l[0] == DESKTOP_ALL) client_set_desktop(client, (unsigned)e->xclient.data.l[0], FALSE, FALSE); - } else if (msgtype == prop_atoms.net_wm_state) { + } else if (msgtype == OBT_PROP_ATOM(NET_WM_STATE)) { gulong ignore_start; /* can't compress these */ - ob_debug("net_wm_state %s %ld %ld for 0x%lx\n", + ob_debug("net_wm_state %s %ld %ld for 0x%lx", (e->xclient.data.l[0] == 0 ? "Remove" : e->xclient.data.l[0] == 1 ? "Add" : e->xclient.data.l[0] == 2 ? "Toggle" : "INVALID"), @@ -1311,11 +1321,11 @@ static void event_handle_client(ObClient *client, XEvent *e) e->xclient.data.l[1], e->xclient.data.l[2]); if (!config_focus_under_mouse) event_end_ignore_all_enters(ignore_start); - } else if (msgtype == prop_atoms.net_close_window) { - ob_debug("net_close_window for 0x%lx\n", client->window); + } else if (msgtype == OBT_PROP_ATOM(NET_CLOSE_WINDOW)) { + ob_debug("net_close_window for 0x%lx", client->window); client_close(client); - } else if (msgtype == prop_atoms.net_active_window) { - ob_debug("net_active_window for 0x%lx source=%s\n", + } else if (msgtype == OBT_PROP_ATOM(NET_ACTIVE_WINDOW)) { + ob_debug("net_active_window for 0x%lx source=%s", client->window, (e->xclient.data.l[0] == 0 ? "unknown" : (e->xclient.data.l[0] == 1 ? "application" : @@ -1329,50 +1339,50 @@ static void event_handle_client(ObClient *client, XEvent *e) if (e->xclient.data.l[1] == 0) ob_debug_type(OB_DEBUG_APP_BUGS, "_NET_ACTIVE_WINDOW message for window %s is" - " missing a timestamp\n", client->title); + " missing a timestamp", client->title); } else ob_debug_type(OB_DEBUG_APP_BUGS, "_NET_ACTIVE_WINDOW message for window %s is " - "missing source indication\n"); + "missing source indication"); client_activate(client, TRUE, TRUE, TRUE, (e->xclient.data.l[0] == 0 || e->xclient.data.l[0] == 2)); - } else if (msgtype == prop_atoms.net_wm_moveresize) { - ob_debug("net_wm_moveresize for 0x%lx direction %d\n", + } else if (msgtype == OBT_PROP_ATOM(NET_WM_MOVERESIZE)) { + ob_debug("net_wm_moveresize for 0x%lx direction %d", client->window, e->xclient.data.l[2]); if ((Atom)e->xclient.data.l[2] == - prop_atoms.net_wm_moveresize_size_topleft || + OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOPLEFT) || (Atom)e->xclient.data.l[2] == - prop_atoms.net_wm_moveresize_size_top || + OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOP) || (Atom)e->xclient.data.l[2] == - prop_atoms.net_wm_moveresize_size_topright || + OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOPRIGHT) || (Atom)e->xclient.data.l[2] == - prop_atoms.net_wm_moveresize_size_right || + OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_RIGHT) || (Atom)e->xclient.data.l[2] == - prop_atoms.net_wm_moveresize_size_right || + OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_RIGHT) || (Atom)e->xclient.data.l[2] == - prop_atoms.net_wm_moveresize_size_bottomright || + OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT) || (Atom)e->xclient.data.l[2] == - prop_atoms.net_wm_moveresize_size_bottom || + OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOM) || (Atom)e->xclient.data.l[2] == - prop_atoms.net_wm_moveresize_size_bottomleft || + OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT) || (Atom)e->xclient.data.l[2] == - prop_atoms.net_wm_moveresize_size_left || + OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_LEFT) || (Atom)e->xclient.data.l[2] == - prop_atoms.net_wm_moveresize_move || + OBT_PROP_ATOM(NET_WM_MOVERESIZE_MOVE) || (Atom)e->xclient.data.l[2] == - prop_atoms.net_wm_moveresize_size_keyboard || + OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_KEYBOARD) || (Atom)e->xclient.data.l[2] == - prop_atoms.net_wm_moveresize_move_keyboard) { - + OBT_PROP_ATOM(NET_WM_MOVERESIZE_MOVE_KEYBOARD)) + { moveresize_start(client, e->xclient.data.l[0], e->xclient.data.l[1], e->xclient.data.l[3], e->xclient.data.l[2]); } else if ((Atom)e->xclient.data.l[2] == - prop_atoms.net_wm_moveresize_cancel) + OBT_PROP_ATOM(NET_WM_MOVERESIZE_CANCEL)) moveresize_end(TRUE); - } else if (msgtype == prop_atoms.net_moveresize_window) { + } else if (msgtype == OBT_PROP_ATOM(NET_MOVERESIZE_WINDOW)) { gint ograv, x, y, w, h; ograv = client->gravity; @@ -1410,7 +1420,7 @@ static void event_handle_client(ObClient *client, XEvent *e) else h = client->area.height; - ob_debug("MOVERESIZE x %d %d y %d %d (gravity %d)\n", + ob_debug("MOVERESIZE x %d %d y %d %d (gravity %d)", e->xclient.data.l[0] & 1 << 8, x, e->xclient.data.l[0] & 1 << 9, y, client->gravity); @@ -1420,17 +1430,16 @@ static void event_handle_client(ObClient *client, XEvent *e) client_configure(client, x, y, w, h, FALSE, TRUE, FALSE); client->gravity = ograv; - } else if (msgtype == prop_atoms.net_restack_window) { + } else if (msgtype == OBT_PROP_ATOM(NET_RESTACK_WINDOW)) { if (e->xclient.data.l[0] != 2) { ob_debug_type(OB_DEBUG_APP_BUGS, "_NET_RESTACK_WINDOW sent for window %s with " - "invalid source indication %ld\n", + "invalid source indication %ld", client->title, e->xclient.data.l[0]); } else { ObClient *sibling = NULL; if (e->xclient.data.l[1]) { - ObWindow *win = g_hash_table_lookup - (window_map, &e->xclient.data.l[1]); + ObWindow *win = window_find(e->xclient.data.l[1]); if (WINDOW_IS_CLIENT(win) && WINDOW_AS_CLIENT(win) != client) { @@ -1439,7 +1448,7 @@ static void event_handle_client(ObClient *client, XEvent *e) if (sibling == NULL) ob_debug_type(OB_DEBUG_APP_BUGS, "_NET_RESTACK_WINDOW sent for window %s " - "with invalid sibling 0x%x\n", + "with invalid sibling 0x%x", client->title, e->xclient.data.l[1]); } if (e->xclient.data.l[2] == Below || @@ -1464,7 +1473,7 @@ static void event_handle_client(ObClient *client, XEvent *e) } else ob_debug_type(OB_DEBUG_APP_BUGS, "_NET_RESTACK_WINDOW sent for window %s " - "with invalid detail %d\n", + "with invalid detail %d", client->title, e->xclient.data.l[2]); } } @@ -1474,7 +1483,7 @@ static void event_handle_client(ObClient *client, XEvent *e) if (!client_validate(client)) break; /* compress changes to a single property into a single change */ - while (XCheckTypedWindowEvent(ob_display, client->window, + while (XCheckTypedWindowEvent(obt_display, client->window, e->type, &ce)) { Atom a, b; @@ -1486,28 +1495,28 @@ static void event_handle_client(ObClient *client, XEvent *e) if (a == b) continue; - if ((a == prop_atoms.net_wm_name || - a == prop_atoms.wm_name || - a == prop_atoms.net_wm_icon_name || - a == prop_atoms.wm_icon_name) + if ((a == OBT_PROP_ATOM(NET_WM_NAME) || + a == OBT_PROP_ATOM(WM_NAME) || + a == OBT_PROP_ATOM(NET_WM_ICON_NAME) || + a == OBT_PROP_ATOM(WM_ICON_NAME)) && - (b == prop_atoms.net_wm_name || - b == prop_atoms.wm_name || - b == prop_atoms.net_wm_icon_name || - b == prop_atoms.wm_icon_name)) { + (b == OBT_PROP_ATOM(NET_WM_NAME) || + b == OBT_PROP_ATOM(WM_NAME) || + b == OBT_PROP_ATOM(NET_WM_ICON_NAME) || + b == OBT_PROP_ATOM(WM_ICON_NAME))) { continue; } - if (a == prop_atoms.net_wm_icon && - b == prop_atoms.net_wm_icon) + if (a == OBT_PROP_ATOM(NET_WM_ICON) && + b == OBT_PROP_ATOM(NET_WM_ICON)) continue; - XPutBackEvent(ob_display, &ce); + XPutBackEvent(obt_display, &ce); break; } msgtype = e->xproperty.atom; if (msgtype == XA_WM_NORMAL_HINTS) { - ob_debug("Update NORMAL hints\n"); + ob_debug("Update NORMAL hints"); client_update_normal_hints(client); /* normal hints can make a window non-resizable */ client_setup_decor_and_functions(client, FALSE); @@ -1524,30 +1533,30 @@ static void event_handle_client(ObClient *client, XEvent *e) /* type may have changed, so update the layer */ client_calc_layer(client); client_setup_decor_and_functions(client, TRUE); - } else if (msgtype == prop_atoms.net_wm_name || - msgtype == prop_atoms.wm_name || - msgtype == prop_atoms.net_wm_icon_name || - msgtype == prop_atoms.wm_icon_name) { + } else if (msgtype == OBT_PROP_ATOM(NET_WM_NAME) || + msgtype == OBT_PROP_ATOM(WM_NAME) || + msgtype == OBT_PROP_ATOM(NET_WM_ICON_NAME) || + msgtype == OBT_PROP_ATOM(WM_ICON_NAME)) { client_update_title(client); - } else if (msgtype == prop_atoms.wm_protocols) { + } else if (msgtype == OBT_PROP_ATOM(WM_PROTOCOLS)) { client_update_protocols(client); client_setup_decor_and_functions(client, TRUE); } - else if (msgtype == prop_atoms.net_wm_strut || - msgtype == prop_atoms.net_wm_strut_partial) { + else if (msgtype == OBT_PROP_ATOM(NET_WM_STRUT) || + msgtype == OBT_PROP_ATOM(NET_WM_STRUT_PARTIAL)) { client_update_strut(client); } - else if (msgtype == prop_atoms.net_wm_icon) { + else if (msgtype == OBT_PROP_ATOM(NET_WM_ICON)) { client_update_icons(client); } - else if (msgtype == prop_atoms.net_wm_icon_geometry) { + else if (msgtype == OBT_PROP_ATOM(NET_WM_ICON_GEOMETRY)) { client_update_icon_geometry(client); } - else if (msgtype == prop_atoms.net_wm_user_time) { + else if (msgtype == OBT_PROP_ATOM(NET_WM_USER_TIME)) { guint32 t; if (client == focus_client && - PROP_GET32(client->window, net_wm_user_time, cardinal, &t) && - t && !event_time_after(t, e->xproperty.time) && + OBT_PROP_GET32(client->window, NET_WM_USER_TIME, CARDINAL, &t) + && t && !event_time_after(t, e->xproperty.time) && (!event_last_user_time || event_time_after(t, event_last_user_time))) { @@ -1555,7 +1564,7 @@ static void event_handle_client(ObClient *client, XEvent *e) } } #ifdef SYNC - else if (msgtype == prop_atoms.net_wm_sync_request_counter) { + else if (msgtype == OBT_PROP_ATOM(NET_WM_SYNC_REQUEST_COUNTER)) { client_update_sync_request_counter(client); } #endif @@ -1566,7 +1575,9 @@ static void event_handle_client(ObClient *client, XEvent *e) default: ; #ifdef SHAPE - if (extensions_shape && e->type == extensions_shape_event_basep) { + if (obt_display_extension_shape && + e->type == obt_display_extension_shape_basep) + { client->shaped = ((XShapeEvent*)e)->shaped; frame_adjust_shape(client->frame); } @@ -1605,11 +1616,11 @@ static void event_handle_dockapp(ObDockApp *app, XEvent *e) app->ignore_unmaps--; break; } - dock_remove(app, TRUE); + dock_unmanage(app, TRUE); break; case DestroyNotify: case ReparentNotify: - dock_remove(app, FALSE); + dock_unmanage(app, FALSE); break; case ConfigureNotify: dock_app_configure(app, e->xconfigure.width, e->xconfigure.height); @@ -1656,125 +1667,160 @@ static gboolean event_handle_prompt(ObPrompt *p, XEvent *e) return FALSE; } -static gboolean event_handle_menu_keyboard(XEvent *ev) +static gboolean event_handle_menu_input(XEvent *ev) { - guint keycode, state; - gunichar unikey; - ObMenuFrame *frame; gboolean ret = FALSE; - keycode = ev->xkey.keycode; - state = ev->xkey.state; - unikey = translate_unichar(keycode); + if (ev->type == ButtonRelease || ev->type == ButtonPress) { + ObMenuEntryFrame *e; - frame = find_active_or_last_menu(); - if (frame == NULL) - g_assert_not_reached(); /* there is no active menu */ + if (menu_hide_delay_reached() && + (ev->xbutton.button < 4 || ev->xbutton.button > 5)) + { + if ((e = menu_entry_frame_under(ev->xbutton.x_root, + ev->xbutton.y_root))) + { + if (ev->type == ButtonPress && e->frame->child) + menu_frame_select(e->frame->child, NULL, TRUE); + menu_frame_select(e->frame, e, TRUE); + if (ev->type == ButtonRelease) + menu_entry_frame_execute(e, ev->xbutton.state); + } + else if (ev->type == ButtonRelease) + menu_frame_hide_all(); + } + ret = TRUE; + } + else if (ev->type == MotionNotify) { + ObMenuFrame *f; + ObMenuEntryFrame *e; - /* Allow control while going thru the menu */ - else if (ev->type == KeyPress && (state & ~ControlMask) == 0) { - frame->got_press = TRUE; + if ((e = menu_entry_frame_under(ev->xmotion.x_root, + ev->xmotion.y_root))) + if (!(f = find_active_menu()) || + f == e->frame || + f->parent == e->frame || + f->child == e->frame) + menu_frame_select(e->frame, e, FALSE); + } + else if (ev->type == KeyPress || ev->type == KeyRelease) { + guint keycode, state; + gunichar unikey; + ObMenuFrame *frame; - if (keycode == ob_keycode(OB_KEY_ESCAPE)) { - menu_frame_hide_all(); - ret = TRUE; - } + keycode = ev->xkey.keycode; + state = ev->xkey.state; + unikey = obt_keyboard_keycode_to_unichar(keycode); - else if (keycode == ob_keycode(OB_KEY_LEFT)) { - /* Left goes to the parent menu */ - if (frame->parent) - menu_frame_select(frame, NULL, TRUE); - ret = TRUE; - } + frame = find_active_or_last_menu(); + if (frame == NULL) + g_assert_not_reached(); /* there is no active menu */ - else if (keycode == ob_keycode(OB_KEY_RIGHT)) { - /* Right goes to the selected submenu */ - if (frame->child) menu_frame_select_next(frame->child); - ret = TRUE; - } + /* Allow control while going thru the menu */ + else if (ev->type == KeyPress && (state & ~ControlMask) == 0) { + frame->got_press = TRUE; - else if (keycode == ob_keycode(OB_KEY_UP)) { - menu_frame_select_previous(frame); - ret = TRUE; - } + if (keycode == ob_keycode(OB_KEY_ESCAPE)) { + menu_frame_hide_all(); + ret = TRUE; + } - else if (keycode == ob_keycode(OB_KEY_DOWN)) { - menu_frame_select_next(frame); - ret = TRUE; - } - } + else if (keycode == ob_keycode(OB_KEY_LEFT)) { + /* Left goes to the parent menu */ + if (frame->parent) + menu_frame_select(frame, NULL, TRUE); + ret = TRUE; + } - /* Use KeyRelease events for running things so that the key release doesn't - get sent to the focused application. + else if (keycode == ob_keycode(OB_KEY_RIGHT)) { + /* Right goes to the selected submenu */ + if (frame->child) menu_frame_select_next(frame->child); + ret = TRUE; + } - Allow ControlMask only, and don't bother if the menu is empty */ - else if (ev->type == KeyRelease && (state & ~ControlMask) == 0 && - frame->entries && frame->got_press) - { - if (keycode == ob_keycode(OB_KEY_RETURN)) { - /* Enter runs the active item or goes into the submenu. - Control-Enter runs it without closing the menu. */ - if (frame->child) - menu_frame_select_next(frame->child); - else if (frame->selected) - menu_entry_frame_execute(frame->selected, state); - - ret = TRUE; - } + else if (keycode == ob_keycode(OB_KEY_UP)) { + menu_frame_select_previous(frame); + ret = TRUE; + } - /* keyboard accelerator shortcuts. (if it was a valid key) */ - else if (unikey != 0) { - GList *start; - GList *it; - ObMenuEntryFrame *found = NULL; - guint num_found = 0; - - /* start after the selected one */ - start = frame->entries; - if (frame->selected) { - for (it = start; frame->selected != it->data; - it = g_list_next(it)) - g_assert(it != NULL); /* nothing was selected? */ - /* next with wraparound */ - start = g_list_next(it); - if (start == NULL) start = frame->entries; + else if (keycode == ob_keycode(OB_KEY_DOWN)) { + menu_frame_select_next(frame); + ret = TRUE; } + } + + /* Use KeyRelease events for running things so that the key release + doesn't get sent to the focused application. - it = start; - do { - ObMenuEntryFrame *e = it->data; - gunichar entrykey = 0; + Allow ControlMask only, and don't bother if the menu is empty */ + else if (ev->type == KeyRelease && (state & ~ControlMask) == 0 && + frame->entries && frame->got_press) + { + if (keycode == ob_keycode(OB_KEY_RETURN)) { + /* Enter runs the active item or goes into the submenu. + Control-Enter runs it without closing the menu. */ + if (frame->child) + menu_frame_select_next(frame->child); + else if (frame->selected) + menu_entry_frame_execute(frame->selected, state); - if (e->entry->type == OB_MENU_ENTRY_TYPE_NORMAL) - entrykey = e->entry->data.normal.shortcut; - else if (e->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU) - entrykey = e->entry->data.submenu.submenu->shortcut; + ret = TRUE; + } - if (unikey == entrykey) { - if (found == NULL) found = e; - ++num_found; + /* keyboard accelerator shortcuts. (if it was a valid key) */ + else if (unikey != 0) { + GList *start; + GList *it; + ObMenuEntryFrame *found = NULL; + guint num_found = 0; + + /* start after the selected one */ + start = frame->entries; + if (frame->selected) { + for (it = start; frame->selected != it->data; + it = g_list_next(it)) + g_assert(it != NULL); /* nothing was selected? */ + /* next with wraparound */ + start = g_list_next(it); + if (start == NULL) start = frame->entries; } - /* next with wraparound */ - it = g_list_next(it); - if (it == NULL) it = frame->entries; - } while (it != start); + it = start; + do { + ObMenuEntryFrame *e = it->data; + gunichar entrykey = 0; - if (found) { - if (found->entry->type == OB_MENU_ENTRY_TYPE_NORMAL && - num_found == 1) - { - menu_frame_select(frame, found, TRUE); - usleep(50000); /* highlight the item for a short bit so the - user can see what happened */ - menu_entry_frame_execute(found, state); - } else { - menu_frame_select(frame, found, TRUE); - if (num_found == 1) - menu_frame_select_next(frame->child); - } + if (e->entry->type == OB_MENU_ENTRY_TYPE_NORMAL) + entrykey = e->entry->data.normal.shortcut; + else if (e->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU) + entrykey = e->entry->data.submenu.submenu->shortcut; - ret = TRUE; + if (unikey == entrykey) { + if (found == NULL) found = e; + ++num_found; + } + + /* next with wraparound */ + it = g_list_next(it); + if (it == NULL) it = frame->entries; + } while (it != start); + + if (found) { + if (found->entry->type == OB_MENU_ENTRY_TYPE_NORMAL && + num_found == 1) + { + menu_frame_select(frame, found, TRUE); + usleep(50000); /* highlight the item for a short bit so + the user can see what happened */ + menu_entry_frame_execute(found, state); + } else { + menu_frame_select(frame, found, TRUE); + if (num_found == 1) + menu_frame_select_next(frame->child); + } + + ret = TRUE; + } } } } @@ -1782,27 +1828,12 @@ static gboolean event_handle_menu_keyboard(XEvent *ev) return ret; } -static gboolean event_handle_menu(XEvent *ev) +static void event_handle_menu(ObMenuFrame *frame, XEvent *ev) { ObMenuFrame *f; ObMenuEntryFrame *e; - gboolean ret = TRUE; switch (ev->type) { - case ButtonRelease: - if (menu_hide_delay_reached() && - (ev->xbutton.button < 4 || ev->xbutton.button > 5)) - { - if ((e = menu_entry_frame_under(ev->xbutton.x_root, - ev->xbutton.y_root))) - { - menu_frame_select(e->frame, e, TRUE); - menu_entry_frame_execute(e, ev->xbutton.state); - } - else - menu_frame_hide_all(); - } - break; case EnterNotify: if ((e = g_hash_table_lookup(menu_frame_map, &ev->xcrossing.window))) { if (e->ignore_enters) @@ -1826,21 +1857,7 @@ static gboolean event_handle_menu(XEvent *ev) menu_frame_select(e->frame, NULL, FALSE); } break; - case MotionNotify: - if ((e = menu_entry_frame_under(ev->xmotion.x_root, - ev->xmotion.y_root))) - if (!(f = find_active_menu()) || - f == e->frame || - f->parent == e->frame || - f->child == e->frame) - menu_frame_select(e->frame, e, FALSE); - break; - case KeyPress: - case KeyRelease: - ret = event_handle_menu_keyboard(ev); - break; } - return ret; } static void event_handle_user_input(ObClient *client, XEvent *e) @@ -1850,7 +1867,7 @@ static void event_handle_user_input(ObClient *client, XEvent *e) e->type == KeyRelease); if (menu_frame_visible) { - if (event_handle_menu(e)) + if (event_handle_menu_input(e)) /* don't use the event if the menu used it, but if the menu didn't use it and it's a keypress that is bound, it will close the menu and be used */ @@ -1874,11 +1891,16 @@ static void event_handle_user_input(ObClient *client, XEvent *e) if (!client || !frame_iconify_animating(client->frame)) mouse_event(client, e); } else - keyboard_event((focus_cycle_target ? focus_cycle_target : - (client ? client : focus_client)), e); + keyboard_event(event_target_client(client), e); } } +ObClient* event_target_client(ObClient *client) +{ + return (focus_cycle_target ? focus_cycle_target : + (client ? client : focus_client)); +} + static void focus_delay_dest(gpointer data) { g_free(data); @@ -1908,20 +1930,20 @@ static gboolean focus_delay_func(gpointer data) static void focus_delay_client_dest(ObClient *client, gpointer data) { - ob_main_loop_timeout_remove_data(ob_main_loop, focus_delay_func, - client, FALSE); + obt_main_loop_timeout_remove_data(ob_main_loop, focus_delay_func, + client, FALSE); } void event_halt_focus_delay(void) { /* ignore all enter events up till the event which caused this to occur */ if (event_curserial) event_ignore_enter_range(1, event_curserial); - ob_main_loop_timeout_remove(ob_main_loop, focus_delay_func); + obt_main_loop_timeout_remove(ob_main_loop, focus_delay_func); } gulong event_start_ignore_all_enters(void) { - return NextRequest(ob_display); + return NextRequest(obt_display); } static void event_ignore_enter_range(gulong start, gulong end) @@ -1936,11 +1958,11 @@ static void event_ignore_enter_range(gulong start, gulong end) r->end = end; ignore_serials = g_slist_prepend(ignore_serials, r); - ob_debug_type(OB_DEBUG_FOCUS, "ignoring enters from %lu until %lu\n", + ob_debug_type(OB_DEBUG_FOCUS, "ignoring enters from %lu until %lu", r->start, r->end); /* increment the serial so we don't ignore events we weren't meant to */ - PROP_ERASE(screen_support_win, motif_wm_hints); + OBT_PROP_ERASE(screen_support_win, MOTIF_WM_HINTS); } void event_end_ignore_all_enters(gulong start) @@ -1951,7 +1973,7 @@ void event_end_ignore_all_enters(gulong start) movement will be ignored until we create some further network traffic. Instead ignore up to NextRequest-1, then when we increment the serial, we will be *past* the range of ignored serials */ - event_ignore_enter_range(start, NextRequest(ob_display)-1); + event_ignore_enter_range(start, NextRequest(obt_display)-1); } static gboolean is_enter_focus_event_ignored(gulong serial) @@ -1978,24 +2000,24 @@ void event_cancel_all_key_grabs(void) { if (actions_interactive_act_running()) { actions_interactive_cancel_act(); - ob_debug("KILLED interactive action\n"); + ob_debug("KILLED interactive action"); } else if (menu_frame_visible) { menu_frame_hide_all(); - ob_debug("KILLED open menus\n"); + ob_debug("KILLED open menus"); } else if (moveresize_in_progress) { moveresize_end(TRUE); - ob_debug("KILLED interactive moveresize\n"); + ob_debug("KILLED interactive moveresize"); } else if (grab_on_keyboard()) { ungrab_keyboard(); - ob_debug("KILLED active grab on keyboard\n"); + ob_debug("KILLED active grab on keyboard"); } else ungrab_passive_key(); - XSync(ob_display, FALSE); + XSync(obt_display, FALSE); } gboolean event_time_after(Time t1, Time t2) @@ -2028,9 +2050,9 @@ Time event_get_server_time(void) /* Generate a timestamp */ XEvent event; - XChangeProperty(ob_display, screen_support_win, - prop_atoms.wm_class, prop_atoms.string, + XChangeProperty(obt_display, screen_support_win, + OBT_PROP_ATOM(WM_CLASS), OBT_PROP_ATOM(STRING), 8, PropModeAppend, NULL, 0); - XWindowEvent(ob_display, screen_support_win, PropertyChangeMask, &event); + XWindowEvent(obt_display, screen_support_win, PropertyChangeMask, &event); return event.xproperty.time; } diff --git a/openbox/event.h b/openbox/event.h index 93af6b4..ba5a03e 100644 --- a/openbox/event.h +++ b/openbox/event.h @@ -33,11 +33,6 @@ extern Time event_curtime; /*! The last user-interaction time, as given by the clients */ extern Time event_last_user_time; -/*! The value of the mask for the NumLock modifier */ -extern guint NumLockMask; -/*! The value of the mask for the ScrollLock modifier */ -extern guint ScrollLockMask; - void event_startup(gboolean reconfig); void event_shutdown(gboolean reconfig); @@ -47,7 +42,7 @@ void event_enter_client(struct _ObClient *client); /*! Make mouse focus not move at all from the stuff that happens between these two function calls. */ -gulong event_start_ignore_all_enters(); +gulong event_start_ignore_all_enters(void); void event_end_ignore_all_enters(gulong start); /*! End *all* active and passive grabs on the keyboard @@ -57,16 +52,20 @@ void event_end_ignore_all_enters(gulong start); Actions should not rely on being able to move focus during an interactive grab. */ -void event_cancel_all_key_grabs(); +void event_cancel_all_key_grabs(void); /* Halts any focus delay in progress, use this when the user is selecting a window for focus */ -void event_halt_focus_delay(); +void event_halt_focus_delay(void); /*! Compare t1 and t2, taking into account wraparound. True if t1 comes at the same time or later than t2. */ gboolean event_time_after(Time t1, Time t2); -Time event_get_server_time(); +Time event_get_server_time(void); + +/*! Given a possible target client, returns what the target client really + should be for actions */ +struct _ObClient* event_target_client(struct _ObClient *client); #endif diff --git a/openbox/extensions.c b/openbox/extensions.c deleted file mode 100644 index cd188dd..0000000 --- a/openbox/extensions.c +++ /dev/null @@ -1,132 +0,0 @@ -/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- - - extensions.c for the Openbox window manager - Copyright (c) 2006 Mikael Magnusson - Copyright (c) 2003-2007 Dana Jansens - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - See the COPYING file for a copy of the GNU General Public License. -*/ - -#include "openbox.h" -#include "geom.h" -#include "extensions.h" -#include "screen.h" -#include "debug.h" - -gboolean extensions_xkb = FALSE; -gint extensions_xkb_event_basep; -gboolean extensions_shape = FALSE; -gint extensions_shape_event_basep; -gboolean extensions_xinerama = FALSE; -gint extensions_xinerama_event_basep; -gboolean extensions_randr = FALSE; -gint extensions_randr_event_basep; -gboolean extensions_sync = FALSE; -gint extensions_sync_event_basep; - -void extensions_query_all(void) -{ - gint junk; - (void)junk; - -#ifdef XKB - extensions_xkb = - XkbQueryExtension(ob_display, &junk, &extensions_xkb_event_basep, - &junk, NULL, NULL); - if (!extensions_xkb) - ob_debug("XKB extension is not present on the server\n"); -#endif - -#ifdef SHAPE - extensions_shape = - XShapeQueryExtension(ob_display, &extensions_shape_event_basep, - &junk); - if (!extensions_shape) - ob_debug("X Shape extension is not present on the server\n"); -#endif - -#ifdef XINERAMA - extensions_xinerama = - XineramaQueryExtension(ob_display, &extensions_xinerama_event_basep, - &junk) && XineramaIsActive(ob_display); - if (!extensions_xinerama) - ob_debug("Xinerama extension is not present on the server\n"); -#endif - -#ifdef XRANDR - extensions_randr = - XRRQueryExtension(ob_display, &extensions_randr_event_basep, - &junk); - if (!extensions_randr) - ob_debug("XRandR extension is not present on the server\n"); -#endif - -#ifdef SYNC - extensions_sync = - XSyncQueryExtension(ob_display, &extensions_sync_event_basep, - &junk) && - XSyncInitialize(ob_display, &junk, &junk); - if (!extensions_sync) - ob_debug("X Sync extension is not present on the server or is an " - "incompatible version\n"); -#endif -} - -void extensions_xinerama_screens(Rect **xin_areas, guint *nxin) -{ - guint i; - gint l, r, t, b; - if (ob_debug_xinerama) { - gint w = WidthOfScreen(ScreenOfDisplay(ob_display, ob_screen)); - gint h = HeightOfScreen(ScreenOfDisplay(ob_display, ob_screen)); - *nxin = 2; - *xin_areas = g_new(Rect, *nxin + 1); - RECT_SET((*xin_areas)[0], 0, 0, w/2, h); - RECT_SET((*xin_areas)[1], w/2, 0, w-(w/2), h); - } - else -#ifdef XINERAMA - if (extensions_xinerama) { - guint i; - gint n; - XineramaScreenInfo *info = XineramaQueryScreens(ob_display, &n); - *nxin = n; - *xin_areas = g_new(Rect, *nxin + 1); - for (i = 0; i < *nxin; ++i) - RECT_SET((*xin_areas)[i], info[i].x_org, info[i].y_org, - info[i].width, info[i].height); - XFree(info); - } - else -#endif - { - *nxin = 1; - *xin_areas = g_new(Rect, *nxin + 1); - RECT_SET((*xin_areas)[0], 0, 0, - WidthOfScreen(ScreenOfDisplay(ob_display, ob_screen)), - HeightOfScreen(ScreenOfDisplay(ob_display, ob_screen))); - } - - /* returns one extra with the total area in it */ - l = (*xin_areas)[0].x; - t = (*xin_areas)[0].y; - r = (*xin_areas)[0].x + (*xin_areas)[0].width - 1; - b = (*xin_areas)[0].y + (*xin_areas)[0].height - 1; - for (i = 1; i < *nxin; ++i) { - l = MIN(l, (*xin_areas)[i].x); - t = MIN(l, (*xin_areas)[i].y); - r = MAX(r, (*xin_areas)[i].x + (*xin_areas)[i].width - 1); - b = MAX(b, (*xin_areas)[i].y + (*xin_areas)[i].height - 1); - } - RECT_SET((*xin_areas)[*nxin], l, t, r - l + 1, b - t + 1); -} diff --git a/openbox/extensions.h b/openbox/extensions.h deleted file mode 100644 index 3155874..0000000 --- a/openbox/extensions.h +++ /dev/null @@ -1,74 +0,0 @@ -/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- - - extensions.h for the Openbox window manager - Copyright (c) 2006 Mikael Magnusson - Copyright (c) 2003-2007 Dana Jansens - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - See the COPYING file for a copy of the GNU General Public License. -*/ - -#ifndef __extensions_h -#define __extensions_h - -#include "geom.h" - -#include -#include /* shape.h uses Region which is in here */ -#ifdef XKB -#include -#endif -#ifdef SHAPE -#include -#endif -#ifdef XINERAMA -#include -#endif -#ifdef XRANDR -#include -#endif -#ifdef SYNC -#include -#endif - -#include - -/*! Does the display have the XKB extension? */ -extern gboolean extensions_xkb; -/*! Base for events for the XKB extension */ -extern gint extensions_xkb_event_basep; - -/*! Does the display have the Shape extension? */ -extern gboolean extensions_shape; -/*! Base for events for the Shape extension */ -extern gint extensions_shape_event_basep; - -/*! Does the display have the Xinerama extension? */ -extern gboolean extensions_xinerama; -/*! Base for events for the Xinerama extension */ -extern gint extensions_xinerama_event_basep; - -/*! Does the display have the RandR extension? */ -extern gboolean extensions_randr; -/*! Base for events for the Randr extension */ -extern gint extensions_randr_event_basep; - -/*! Does the display have the Sync extension? */ -extern gboolean extensions_sync; -/*! Base for events for the Sync extension */ -extern gint extensions_sync_event_basep; - -void extensions_query_all(); - -void extensions_xinerama_screens(Rect **areas, guint *nxin); - -#endif diff --git a/openbox/focus.c b/openbox/focus.c index 12625fd..23cf910 100644 --- a/openbox/focus.c +++ b/openbox/focus.c @@ -26,10 +26,11 @@ #include "group.h" #include "focus_cycle.h" #include "screen.h" -#include "prop.h" #include "keyboard.h" +#include "hooks.h" #include "focus.h" #include "stacking.h" +#include "obt/prop.h" #include #include @@ -52,7 +53,7 @@ void focus_shutdown(gboolean reconfig) if (reconfig) return; /* reset focus to root */ - XSetInputFocus(ob_display, PointerRoot, RevertToNone, CurrentTime); + XSetInputFocus(obt_display, PointerRoot, RevertToNone, CurrentTime); } static void push_to_top(ObClient *client) @@ -72,9 +73,10 @@ static void push_to_top(ObClient *client) void focus_set_client(ObClient *client) { Window active; + ObClient *old; ob_debug_type(OB_DEBUG_FOCUS, - "focus_set_client 0x%lx\n", client ? client->window : 0); + "focus_set_client 0x%lx", client ? client->window : 0); if (focus_client == client) return; @@ -87,6 +89,7 @@ void focus_set_client(ObClient *client) focus_cycle_stop(focus_client); focus_cycle_stop(client); + old = focus_client; focus_client = client; if (client != NULL) { @@ -99,9 +102,11 @@ void focus_set_client(ObClient *client) /* set the NET_ACTIVE_WINDOW hint, but preserve it on shutdown */ if (ob_state() != OB_STATE_EXITING) { active = client ? client->window : None; - PROP_SET32(RootWindow(ob_display, ob_screen), - net_active_window, window, active); + OBT_PROP_SET32(obt_root(ob_screen), NET_ACTIVE_WINDOW, WINDOW, active); } + + hooks_queue(OB_HOOK_WIN_UNFOCUS, old); + hooks_queue(OB_HOOK_WIN_FOCUS, client); } static ObClient* focus_fallback_target(gboolean allow_refocus, @@ -112,18 +117,18 @@ static ObClient* focus_fallback_target(gboolean allow_refocus, GList *it; ObClient *c; - ob_debug_type(OB_DEBUG_FOCUS, "trying pointer stuff\n"); + ob_debug_type(OB_DEBUG_FOCUS, "trying pointer stuff"); if (allow_pointer && config_focus_follow) if ((c = client_under_pointer()) && (allow_refocus || client_focus_target(c) != old) && (client_normal(c) && client_focus(c))) { - ob_debug_type(OB_DEBUG_FOCUS, "found in pointer stuff\n"); + ob_debug_type(OB_DEBUG_FOCUS, "found in pointer stuff"); return c; } - ob_debug_type(OB_DEBUG_FOCUS, "trying the focus order\n"); + ob_debug_type(OB_DEBUG_FOCUS, "trying the focus order"); for (it = focus_order; it; it = g_list_next(it)) { c = it->data; /* fallback focus to a window if: @@ -139,12 +144,12 @@ static ObClient* focus_fallback_target(gboolean allow_refocus, (allow_refocus || client_focus_target(c) != old) && client_focus(c)) { - ob_debug_type(OB_DEBUG_FOCUS, "found in focus order\n"); + ob_debug_type(OB_DEBUG_FOCUS, "found in focus order"); return c; } } - ob_debug_type(OB_DEBUG_FOCUS, "trying a desktop window\n"); + ob_debug_type(OB_DEBUG_FOCUS, "trying a desktop window"); for (it = focus_order; it; it = g_list_next(it)) { c = it->data; /* fallback focus to a window if: @@ -158,7 +163,7 @@ static ObClient* focus_fallback_target(gboolean allow_refocus, (allow_refocus || client_focus_target(c) != old) && client_focus(c)) { - ob_debug_type(OB_DEBUG_FOCUS, "found a desktop window\n"); + ob_debug_type(OB_DEBUG_FOCUS, "found a desktop window"); return c; } } @@ -200,7 +205,7 @@ void focus_nothing(void) event_cancel_all_key_grabs(); /* when nothing will be focused, send focus to the backup target */ - XSetInputFocus(ob_display, screen_support_win, RevertToPointerRoot, + XSetInputFocus(obt_display, screen_support_win, RevertToPointerRoot, event_curtime); } diff --git a/openbox/focus.h b/openbox/focus.h index b8f8999..4f37b72 100644 --- a/openbox/focus.h +++ b/openbox/focus.h @@ -41,7 +41,7 @@ void focus_shutdown(gboolean reconfig); void focus_set_client(struct _ObClient *client); /*! Focus nothing, but let keyboard events be caught. */ -void focus_nothing(); +void focus_nothing(void); /*! Call this when you need to focus something! */ struct _ObClient* focus_fallback(gboolean allow_refocus, diff --git a/openbox/focus_cycle.c b/openbox/focus_cycle.c index c7fc42e..4d79377 100644 --- a/openbox/focus_cycle.c +++ b/openbox/focus_cycle.c @@ -19,7 +19,6 @@ #include "focus_cycle.h" #include "focus_cycle_indicator.h" -#include "focus_cycle_popup.h" #include "client.h" #include "frame.h" #include "focus.h" @@ -70,7 +69,7 @@ void focus_cycle_stop(ObClient *ifclient) ObClient* focus_cycle(gboolean forward, gboolean all_desktops, gboolean dock_windows, gboolean desktop_windows, gboolean linear, gboolean interactive, - gboolean showbar, gboolean dialog, + gboolean showbar, ObFocusCyclePopupMode mode, gboolean done, gboolean cancel) { static GList *order = NULL; @@ -130,13 +129,13 @@ ObClient* focus_cycle(gboolean forward, gboolean all_desktops, focus_cycle_target = ft; focus_cycle_draw_indicator(showbar ? ft : NULL); } - if (dialog) - /* same arguments as focus_target_valid */ - focus_cycle_popup_show(ft, - focus_cycle_iconic_windows, - focus_cycle_all_desktops, - focus_cycle_dock_windows, - focus_cycle_desktop_windows); + /* same arguments as focus_target_valid */ + focus_cycle_popup_show(ft, + focus_cycle_iconic_windows, + focus_cycle_all_desktops, + focus_cycle_dock_windows, + focus_cycle_desktop_windows, + mode); return focus_cycle_target; } else if (ft != focus_cycle_target) { focus_cycle_target = ft; diff --git a/openbox/focus_cycle.h b/openbox/focus_cycle.h index 6e1c2c9..c31abc8 100644 --- a/openbox/focus_cycle.h +++ b/openbox/focus_cycle.h @@ -21,6 +21,7 @@ #define __focus_cycle_h #include "misc.h" +#include "focus_cycle_popup.h" #include #include @@ -37,7 +38,7 @@ void focus_cycle_shutdown(gboolean reconfig); struct _ObClient* focus_cycle(gboolean forward, gboolean all_desktops, gboolean dock_windows, gboolean desktop_windows, gboolean linear, gboolean interactive, - gboolean showbar, gboolean dialog, + gboolean showbar, ObFocusCyclePopupMode mode, gboolean done, gboolean cancel); struct _ObClient* focus_directional_cycle(ObDirection dir, gboolean dock_windows, diff --git a/openbox/focus_cycle_indicator.c b/openbox/focus_cycle_indicator.c index 79de673..495a723 100644 --- a/openbox/focus_cycle_indicator.c +++ b/openbox/focus_cycle_indicator.c @@ -32,10 +32,10 @@ static struct { - InternalWindow top; - InternalWindow left; - InternalWindow right; - InternalWindow bottom; + ObInternalWindow top; + ObInternalWindow left; + ObInternalWindow right; + ObInternalWindow bottom; } focus_indicator; static RrAppearance *a_focus_indicator; @@ -45,7 +45,7 @@ static gboolean visible; static Window create_window(Window parent, gulong mask, XSetWindowAttributes *attrib) { - return XCreateWindow(ob_display, parent, 0, 0, 1, 1, 0, + return XCreateWindow(obt_display, parent, 0, 0, 1, 1, 0, RrDepth(ob_rr_inst), InputOutput, RrVisual(ob_rr_inst), mask, attrib); @@ -59,38 +59,38 @@ void focus_cycle_indicator_startup(gboolean reconfig) if (reconfig) return; - focus_indicator.top.type = Window_Internal; - focus_indicator.left.type = Window_Internal; - focus_indicator.right.type = Window_Internal; - focus_indicator.bottom.type = Window_Internal; + focus_indicator.top.type = OB_WINDOW_CLASS_INTERNAL; + focus_indicator.left.type = OB_WINDOW_CLASS_INTERNAL; + focus_indicator.right.type = OB_WINDOW_CLASS_INTERNAL; + focus_indicator.bottom.type = OB_WINDOW_CLASS_INTERNAL; attr.override_redirect = True; - attr.background_pixel = BlackPixel(ob_display, ob_screen); + attr.background_pixel = BlackPixel(obt_display, ob_screen); focus_indicator.top.window = - create_window(RootWindow(ob_display, ob_screen), + create_window(obt_root(ob_screen), CWOverrideRedirect | CWBackPixel, &attr); focus_indicator.left.window = - create_window(RootWindow(ob_display, ob_screen), + create_window(obt_root(ob_screen), CWOverrideRedirect | CWBackPixel, &attr); focus_indicator.right.window = - create_window(RootWindow(ob_display, ob_screen), + create_window(obt_root(ob_screen), CWOverrideRedirect | CWBackPixel, &attr); focus_indicator.bottom.window = - create_window(RootWindow(ob_display, ob_screen), + create_window(obt_root(ob_screen), CWOverrideRedirect | CWBackPixel, &attr); stacking_add(INTERNAL_AS_WINDOW(&focus_indicator.top)); stacking_add(INTERNAL_AS_WINDOW(&focus_indicator.left)); stacking_add(INTERNAL_AS_WINDOW(&focus_indicator.right)); stacking_add(INTERNAL_AS_WINDOW(&focus_indicator.bottom)); - g_hash_table_insert(window_map, &focus_indicator.top.window, - &focus_indicator.top); - g_hash_table_insert(window_map, &focus_indicator.left.window, - &focus_indicator.left); - g_hash_table_insert(window_map, &focus_indicator.right.window, - &focus_indicator.right); - g_hash_table_insert(window_map, &focus_indicator.bottom.window, - &focus_indicator.bottom); + window_add(&focus_indicator.top.window, + INTERNAL_AS_WINDOW(&focus_indicator.top)); + window_add(&focus_indicator.left.window, + INTERNAL_AS_WINDOW(&focus_indicator.left)); + window_add(&focus_indicator.right.window, + INTERNAL_AS_WINDOW(&focus_indicator.right)); + window_add(&focus_indicator.bottom.window, + INTERNAL_AS_WINDOW(&focus_indicator.bottom)); color_white = RrColorNew(ob_rr_inst, 0xff, 0xff, 0xff); @@ -117,20 +117,20 @@ void focus_cycle_indicator_shutdown(gboolean reconfig) RrAppearanceFree(a_focus_indicator); - g_hash_table_remove(window_map, &focus_indicator.top.window); - g_hash_table_remove(window_map, &focus_indicator.left.window); - g_hash_table_remove(window_map, &focus_indicator.right.window); - g_hash_table_remove(window_map, &focus_indicator.bottom.window); + window_remove(focus_indicator.top.window); + window_remove(focus_indicator.left.window); + window_remove(focus_indicator.right.window); + window_remove(focus_indicator.bottom.window); stacking_remove(INTERNAL_AS_WINDOW(&focus_indicator.top)); stacking_remove(INTERNAL_AS_WINDOW(&focus_indicator.left)); stacking_remove(INTERNAL_AS_WINDOW(&focus_indicator.right)); stacking_remove(INTERNAL_AS_WINDOW(&focus_indicator.bottom)); - XDestroyWindow(ob_display, focus_indicator.top.window); - XDestroyWindow(ob_display, focus_indicator.left.window); - XDestroyWindow(ob_display, focus_indicator.right.window); - XDestroyWindow(ob_display, focus_indicator.bottom.window); + XDestroyWindow(obt_display, focus_indicator.top.window); + XDestroyWindow(obt_display, focus_indicator.left.window); + XDestroyWindow(obt_display, focus_indicator.right.window); + XDestroyWindow(obt_display, focus_indicator.bottom.window); } void focus_cycle_draw_indicator(ObClient *c) @@ -141,10 +141,10 @@ void focus_cycle_draw_indicator(ObClient *c) /* kill enter events cause by this unmapping */ ignore_start = event_start_ignore_all_enters(); - XUnmapWindow(ob_display, focus_indicator.top.window); - XUnmapWindow(ob_display, focus_indicator.left.window); - XUnmapWindow(ob_display, focus_indicator.right.window); - XUnmapWindow(ob_display, focus_indicator.bottom.window); + XUnmapWindow(obt_display, focus_indicator.top.window); + XUnmapWindow(obt_display, focus_indicator.left.window); + XUnmapWindow(obt_display, focus_indicator.right.window); + XUnmapWindow(obt_display, focus_indicator.bottom.window); event_end_ignore_all_enters(ignore_start); @@ -170,7 +170,7 @@ void focus_cycle_draw_indicator(ObClient *c) /* kill enter events cause by this moving */ ignore_start = event_start_ignore_all_enters(); - XMoveResizeWindow(ob_display, focus_indicator.top.window, + XMoveResizeWindow(obt_display, focus_indicator.top.window, x, y, w, h); a_focus_indicator->texture[0].data.lineart.x1 = 0; a_focus_indicator->texture[0].data.lineart.y1 = h-1; @@ -196,7 +196,7 @@ void focus_cycle_draw_indicator(ObClient *c) w = wl; h = c->frame->area.height; - XMoveResizeWindow(ob_display, focus_indicator.left.window, + XMoveResizeWindow(obt_display, focus_indicator.left.window, x, y, w, h); a_focus_indicator->texture[0].data.lineart.x1 = w-1; a_focus_indicator->texture[0].data.lineart.y1 = 0; @@ -222,7 +222,7 @@ void focus_cycle_draw_indicator(ObClient *c) w = wr; h = c->frame->area.height ; - XMoveResizeWindow(ob_display, focus_indicator.right.window, + XMoveResizeWindow(obt_display, focus_indicator.right.window, x, y, w, h); a_focus_indicator->texture[0].data.lineart.x1 = 0; a_focus_indicator->texture[0].data.lineart.y1 = 0; @@ -248,7 +248,7 @@ void focus_cycle_draw_indicator(ObClient *c) w = c->frame->area.width; h = wb; - XMoveResizeWindow(ob_display, focus_indicator.bottom.window, + XMoveResizeWindow(obt_display, focus_indicator.bottom.window, x, y, w, h); a_focus_indicator->texture[0].data.lineart.x1 = 0; a_focus_indicator->texture[0].data.lineart.y1 = 0; @@ -269,10 +269,10 @@ void focus_cycle_draw_indicator(ObClient *c) RrPaint(a_focus_indicator, focus_indicator.bottom.window, w, h); - XMapWindow(ob_display, focus_indicator.top.window); - XMapWindow(ob_display, focus_indicator.left.window); - XMapWindow(ob_display, focus_indicator.right.window); - XMapWindow(ob_display, focus_indicator.bottom.window); + XMapWindow(obt_display, focus_indicator.top.window); + XMapWindow(obt_display, focus_indicator.left.window); + XMapWindow(obt_display, focus_indicator.right.window); + XMapWindow(obt_display, focus_indicator.bottom.window); event_end_ignore_all_enters(ignore_start); diff --git a/openbox/focus_cycle_popup.c b/openbox/focus_cycle_popup.c index df3558d..3feac6a 100644 --- a/openbox/focus_cycle_popup.c +++ b/openbox/focus_cycle_popup.c @@ -30,11 +30,23 @@ #include #include -#define ICON_SIZE 40 -#define ICON_HILITE_WIDTH 2 -#define ICON_HILITE_MARGIN 1 +/* Size of the hilite box around a window's icon */ +#define HILITE_SIZE 40 +/* Width of the outer ring around the hilite box */ +#define HILITE_WIDTH 2 +/* Space between the outer ring around the hilite box and the icon inside it */ +#define HILITE_MARGIN 1 +/* Total distance from the edge of the hilite box to the icon inside it */ +#define HILITE_OFFSET (HILITE_WIDTH + HILITE_MARGIN) +/* Size of the icons, which can appear inside or outside of a hilite box */ +#define ICON_SIZE (HILITE_SIZE - 2*HILITE_OFFSET) +/* Margin area around the outside of the dialog */ #define OUTSIDE_BORDER 3 +/* Margin area around the text */ #define TEXT_BORDER 2 +/* Scroll the list-mode list when the cursor gets within this many rows of the + top or bottom */ +#define SCROLL_MARGIN 4 typedef struct _ObFocusCyclePopup ObFocusCyclePopup; typedef struct _ObFocusCyclePopupTarget ObFocusCyclePopupTarget; @@ -44,7 +56,9 @@ struct _ObFocusCyclePopupTarget ObClient *client; RrImage *icon; gchar *text; - Window win; + Window iconwin; + /* This is used when the popup is in list mode */ + Window textwin; }; struct _ObFocusCyclePopup @@ -52,7 +66,11 @@ struct _ObFocusCyclePopup ObWindow obwin; Window bg; - Window text; + /* This is used when the popup is in icon mode */ + Window icon_mode_text; + + Window list_mode_up; + Window list_mode_down; GList *targets; gint n_targets; @@ -61,13 +79,17 @@ struct _ObFocusCyclePopup gint maxtextw; + /* How are the list is scrolled, in scroll mode */ + gint scroll; + RrAppearance *a_bg; RrAppearance *a_text; + RrAppearance *a_hilite_text; RrAppearance *a_icon; - - RrPixel32 *hilite_rgba; + RrAppearance *a_arrow; gboolean mapped; + ObFocusCyclePopupMode mode; }; /*! This popup shows all possible windows */ @@ -88,7 +110,7 @@ static void popup_render (ObFocusCyclePopup *p, static Window create_window(Window parent, guint bwidth, gulong mask, XSetWindowAttributes *attr) { - return XCreateWindow(ob_display, parent, 0, 0, 1, 1, bwidth, + return XCreateWindow(obt_display, parent, 0, 0, 1, 1, bwidth, RrDepth(ob_rr_inst), InputOutput, RrVisual(ob_rr_inst), mask, attr); } @@ -96,48 +118,98 @@ static Window create_window(Window parent, guint bwidth, gulong mask, void focus_cycle_popup_startup(gboolean reconfig) { XSetWindowAttributes attrib; + RrPixel32 *p; single_popup = icon_popup_new(); - popup.obwin.type = Window_Internal; + popup.obwin.type = OB_WINDOW_CLASS_INTERNAL; popup.a_bg = RrAppearanceCopy(ob_rr_theme->osd_hilite_bg); - popup.a_text = RrAppearanceCopy(ob_rr_theme->osd_hilite_label); - popup.a_icon = RrAppearanceCopy(ob_rr_theme->a_clear_tex); + popup.a_hilite_text = RrAppearanceCopy(ob_rr_theme->osd_hilite_label); + popup.a_text = RrAppearanceCopy(ob_rr_theme->a_unfocused_label); + popup.a_icon = RrAppearanceCopy(ob_rr_theme->a_clear); + popup.a_arrow = RrAppearanceCopy(ob_rr_theme->a_clear_tex); + popup.a_hilite_text->surface.parent = popup.a_bg; popup.a_text->surface.parent = popup.a_bg; popup.a_icon->surface.parent = popup.a_bg; + popup.a_text->texture[0].data.text.justify = RR_JUSTIFY_LEFT; + popup.a_hilite_text->texture[0].data.text.justify = RR_JUSTIFY_LEFT; + + /* 2 textures. texture[0] is the icon. texture[1] is the hilight, and + may or may not be used */ + RrAppearanceAddTextures(popup.a_icon, 2); + RrAppearanceClearTextures(popup.a_icon); popup.a_icon->texture[0].type = RR_TEXTURE_IMAGE; - RrAppearanceAddTextures(popup.a_bg, 1); - popup.a_bg->texture[0].type = RR_TEXTURE_RGBA; + RrAppearanceClearTextures(popup.a_arrow); + popup.a_arrow->texture[0].type = RR_TEXTURE_MASK; + popup.a_arrow->texture[0].data.mask.color = + ob_rr_theme->osd_color; attrib.override_redirect = True; attrib.border_pixel=RrColorPixel(ob_rr_theme->osd_border_color); - popup.bg = create_window(RootWindow(ob_display, ob_screen), - ob_rr_theme->obwidth, + popup.bg = create_window(obt_root(ob_screen), ob_rr_theme->obwidth, CWOverrideRedirect | CWBorderPixel, &attrib); - popup.text = create_window(popup.bg, 0, 0, NULL); + /* create the text window used for the icon-mode popup */ + popup.icon_mode_text = create_window(popup.bg, 0, 0, NULL); + + /* create the windows for the up and down arrows */ + popup.list_mode_up = create_window(popup.bg, 0, 0, NULL); + popup.list_mode_down = create_window(popup.bg, 0, 0, NULL); popup.targets = NULL; popup.n_targets = 0; popup.last_target = NULL; - popup.hilite_rgba = NULL; + /* set up the hilite texture for the icon */ + popup.a_icon->texture[1].data.rgba.width = HILITE_SIZE; + popup.a_icon->texture[1].data.rgba.height = HILITE_SIZE; + popup.a_icon->texture[1].data.rgba.alpha = 0xff; + p = g_new(RrPixel32, HILITE_SIZE * HILITE_SIZE); + popup.a_icon->texture[1].data.rgba.data = p; - XMapWindow(ob_display, popup.text); + /* create the hilite under the target icon */ + { + RrPixel32 color; + gint x, y, o; + + color = ((ob_rr_theme->osd_color->r & 0xff) << RrDefaultRedOffset) + + ((ob_rr_theme->osd_color->g & 0xff) << RrDefaultGreenOffset) + + ((ob_rr_theme->osd_color->b & 0xff) << RrDefaultBlueOffset); + + o = 0; + for (x = 0; x < HILITE_SIZE; x++) + for (y = 0; y < HILITE_SIZE; y++) { + guchar a; + + if (x < HILITE_WIDTH || + x >= HILITE_SIZE - HILITE_WIDTH || + y < HILITE_WIDTH || + y >= HILITE_SIZE - HILITE_WIDTH) + { + /* the border of the target */ + a = 0x88; + } else { + /* the background of the target */ + a = 0x22; + } + + p[o++] = color + (a << RrDefaultAlphaOffset); + } + } stacking_add(INTERNAL_AS_WINDOW(&popup)); - g_hash_table_insert(window_map, &popup.bg, &popup); + window_add(&popup.bg, INTERNAL_AS_WINDOW(&popup)); } void focus_cycle_popup_shutdown(gboolean reconfig) { icon_popup_free(single_popup); - g_hash_table_remove(window_map, &popup.bg); + window_remove(popup.bg); stacking_remove(INTERNAL_AS_WINDOW(&popup)); while(popup.targets) { @@ -145,19 +217,24 @@ void focus_cycle_popup_shutdown(gboolean reconfig) RrImageUnref(t->icon); g_free(t->text); - XDestroyWindow(ob_display, t->win); + XDestroyWindow(obt_display, t->iconwin); + XDestroyWindow(obt_display, t->textwin); g_free(t); popup.targets = g_list_delete_link(popup.targets, popup.targets); } - g_free(popup.hilite_rgba); - popup.hilite_rgba = NULL; + g_free(popup.a_icon->texture[1].data.rgba.data); + popup.a_icon->texture[1].data.rgba.data = NULL; - XDestroyWindow(ob_display, popup.text); - XDestroyWindow(ob_display, popup.bg); + XDestroyWindow(obt_display, popup.list_mode_up); + XDestroyWindow(obt_display, popup.list_mode_down); + XDestroyWindow(obt_display, popup.icon_mode_text); + XDestroyWindow(obt_display, popup.bg); + RrAppearanceFree(popup.a_arrow); RrAppearanceFree(popup.a_icon); + RrAppearanceFree(popup.a_hilite_text); RrAppearanceFree(popup.a_text); RrAppearanceFree(popup.a_bg); } @@ -193,18 +270,17 @@ static void popup_setup(ObFocusCyclePopup *p, gboolean create_targets, p->a_text->texture[0].data.text.string = text; maxwidth = MAX(maxwidth, RrMinWidth(p->a_text)); - if (!create_targets) + if (!create_targets) { g_free(text); - else { + } else { ObFocusCyclePopupTarget *t = g_new(ObFocusCyclePopupTarget, 1); t->client = ft; t->text = text; t->icon = client_icon(t->client); RrImageRef(t->icon); /* own the icon so it won't go away */ - t->win = create_window(p->bg, 0, 0, NULL); - - XMapWindow(ob_display, t->win); + t->iconwin = create_window(p->bg, 0, 0, NULL); + t->textwin = create_window(p->bg, 0, 0, NULL); p->targets = g_list_prepend(p->targets, t); ++n; @@ -249,16 +325,29 @@ static void popup_render(ObFocusCyclePopup *p, const ObClient *c) gint l, t, r, b; gint x, y, w, h; Rect *screen_area = NULL; - gint icons_per_row; - gint icon_rows; - gint textx, texty, textw, texth; gint rgbax, rgbay, rgbaw, rgbah; - gint icons_center_x; - gint innerw, innerh; gint i; GList *it; const ObFocusCyclePopupTarget *newtarget; - gint newtargetx, newtargety; + gint icons_per_row; + gint icon_rows; + gint textw, texth; + gint selected_pos; + gint last_scroll; + + /* vars for icon mode */ + gint icon_mode_textx; + gint icon_mode_texty; + gint icons_center_x; + + /* vars for list mode */ + gint list_mode_icon_column_w = HILITE_SIZE + OUTSIDE_BORDER; + gint up_arrow_x, down_arrow_x; + gint up_arrow_y, down_arrow_y; + gboolean showing_arrows = FALSE; + + g_assert(p->mode == OB_FOCUS_CYCLE_POPUP_MODE_ICONS || + p->mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST); screen_area = screen_physical_area_active(); @@ -271,195 +360,313 @@ static void popup_render(ObFocusCyclePopup *p, const ObClient *c) t = mt + OUTSIDE_BORDER; b = mb + OUTSIDE_BORDER; - /* get the icon pictures' sizes */ - innerw = ICON_SIZE - (ICON_HILITE_WIDTH + ICON_HILITE_MARGIN) * 2; - innerh = ICON_SIZE - (ICON_HILITE_WIDTH + ICON_HILITE_MARGIN) * 2; - /* get the width from the text and keep it within limits */ w = l + r + p->maxtextw; + if (p->mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST) + /* when in list mode, there are icons down the side */ + w += list_mode_icon_column_w; w = MIN(w, MAX(screen_area->width/3, POPUP_WIDTH)); /* max width */ w = MAX(w, POPUP_WIDTH); /* min width */ - /* how many icons will fit in that row? make the width fit that */ - w -= l + r; - icons_per_row = (w + ICON_SIZE - 1) / ICON_SIZE; - w = icons_per_row * ICON_SIZE + l + r; - - /* how many rows do we need? */ - icon_rows = (p->n_targets-1) / icons_per_row + 1; + /* get the text height */ + texth = RrMinHeight(p->a_hilite_text); + if (p->mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST) + texth = MAX(MAX(texth, RrMinHeight(p->a_text)), HILITE_SIZE); + else + texth += TEXT_BORDER * 2; + + if (p->mode == OB_FOCUS_CYCLE_POPUP_MODE_ICONS) { + /* how many icons will fit in that row? make the width fit that */ + w -= l + r; + icons_per_row = (w + HILITE_SIZE - 1) / HILITE_SIZE; + w = icons_per_row * HILITE_SIZE + l + r; + + /* how many rows do we need? */ + icon_rows = (p->n_targets-1) / icons_per_row + 1; + } else { + /* in list mode, there is one column of icons.. */ + icons_per_row = 1; + /* maximum is 80% of the screen height */ + icon_rows = MIN(p->n_targets, + (4*screen_area->height/5) /* 80% of the screen */ + / + MAX(HILITE_SIZE, texth)); /* height of each row */ + /* but make sure there is always one */ + icon_rows = MAX(icon_rows, 1); + } - /* get the text dimensions */ + /* get the text width */ textw = w - l - r; - texth = RrMinHeight(p->a_text) + TEXT_BORDER * 2; + if (p->mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST) + /* leave space on the side for the icons */ + textw -= list_mode_icon_column_w; - /* find the height of the dialog */ - h = t + b + (icon_rows * ICON_SIZE) + (OUTSIDE_BORDER + texth); - - /* get the position of the text */ - textx = l; - texty = h - texth - b; - - /* find the position for the popup (include the outer borders) */ - x = screen_area->x + (screen_area->width - - (w + ob_rr_theme->obwidth * 2)) / 2; - y = screen_area->y + (screen_area->height - - (h + ob_rr_theme->obwidth * 2)) / 2; - - /* get the dimensions of the target hilite texture */ - rgbax = ml; - rgbay = mt; - rgbaw = w - ml - mr; - rgbah = h - mt - mb; - - /* center the icons if there is less than one row */ - if (icon_rows == 1) - icons_center_x = (w - p->n_targets * ICON_SIZE) / 2; - else - icons_center_x = 0; + if (!p->mapped) + /* reset the scrolling when the dialog is first shown */ + p->scroll = 0; - if (!p->mapped) { - /* position the background but don't draw it*/ - XMoveResizeWindow(ob_display, p->bg, x, y, w, h); - - /* set up the hilite texture for the background */ - p->a_bg->texture[0].data.rgba.width = rgbaw; - p->a_bg->texture[0].data.rgba.height = rgbah; - p->a_bg->texture[0].data.rgba.alpha = 0xff; - p->hilite_rgba = g_new(RrPixel32, rgbaw * rgbah); - p->a_bg->texture[0].data.rgba.data = p->hilite_rgba; - - /* position the text, but don't draw it */ - XMoveResizeWindow(ob_display, p->text, textx, texty, textw, texth); - p->a_text->surface.parentx = textx; - p->a_text->surface.parenty = texty; - } + /* find the height of the dialog */ + h = t + b + (icon_rows * MAX(HILITE_SIZE, texth)); + if (p->mode == OB_FOCUS_CYCLE_POPUP_MODE_ICONS) + /* in icon mode the text sits below the icons, so make some space */ + h += OUTSIDE_BORDER + texth; /* find the focused target */ + newtarget = NULL; for (i = 0, it = p->targets; it; ++i, it = g_list_next(it)) { const ObFocusCyclePopupTarget *target = it->data; - const gint row = i / icons_per_row; /* starting from 0 */ - const gint col = i % icons_per_row; /* starting from 0 */ - if (target->client == c) { /* save the target */ newtarget = target; - newtargetx = icons_center_x + l + (col * ICON_SIZE); - newtargety = t + (row * ICON_SIZE); + break; + } + } + selected_pos = i; + g_assert(newtarget != NULL); - if (!p->mapped) - break; /* if we're not dimensioning, then we're done */ + /* scroll the list if needed */ + last_scroll = p->scroll; + if (p->mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST) { + const gint top = p->scroll + SCROLL_MARGIN; + const gint bottom = p->scroll + icon_rows - SCROLL_MARGIN; + const gint min_scroll = 0; + const gint max_scroll = p->n_targets - icon_rows; + + if (top - selected_pos >= 0) { + p->scroll -= top - selected_pos + 1; + p->scroll = MAX(p->scroll, min_scroll); + } else if (selected_pos - bottom >= 0) { + p->scroll += selected_pos - bottom + 1; + p->scroll = MIN(p->scroll, max_scroll); } } - g_assert(newtarget != NULL); + /* show the scroll arrows when appropriate */ + if (p->scroll && p->mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST) { + XMapWindow(obt_display, p->list_mode_up); + showing_arrows = TRUE; + } else + XUnmapWindow(obt_display, p->list_mode_up); - /* create the hilite under the target icon */ + if (p->scroll < p->n_targets - icon_rows && + p->mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST) { - RrPixel32 color; - gint i, j, o; + XMapWindow(obt_display, p->list_mode_down); + showing_arrows = TRUE; + } else + XUnmapWindow(obt_display, p->list_mode_down); - color = ((ob_rr_theme->osd_color->r & 0xff) << RrDefaultRedOffset) + - ((ob_rr_theme->osd_color->g & 0xff) << RrDefaultGreenOffset) + - ((ob_rr_theme->osd_color->b & 0xff) << RrDefaultBlueOffset); + /* make space for the arrows */ + if (showing_arrows) + h += ob_rr_theme->up_arrow_mask->height + OUTSIDE_BORDER + + ob_rr_theme->down_arrow_mask->height + OUTSIDE_BORDER; - o = 0; - for (i = 0; i < rgbah; ++i) - for (j = 0; j < rgbaw; ++j) { - guchar a; - const gint x = j + rgbax - newtargetx; - const gint y = i + rgbay - newtargety; + /* center the icons if there is less than one row */ + if (p->mode == OB_FOCUS_CYCLE_POPUP_MODE_ICONS && icon_rows == 1) + icons_center_x = (w - p->n_targets * HILITE_SIZE) / 2; + else + icons_center_x = 0; - if (x < 0 || x >= ICON_SIZE || - y < 0 || y >= ICON_SIZE) - { - /* outside the target */ - a = 0x00; - } - else if (x < ICON_HILITE_WIDTH || - x >= ICON_SIZE - ICON_HILITE_WIDTH || - y < ICON_HILITE_WIDTH || - y >= ICON_SIZE - ICON_HILITE_WIDTH) - { - /* the border of the target */ - a = 0x88; - } - else { - /* the background of the target */ - a = 0x22; - } + if (p->mode == OB_FOCUS_CYCLE_POPUP_MODE_ICONS) { + /* get the position of the text */ + icon_mode_textx = l; + icon_mode_texty = h - texth - b; + } - p->hilite_rgba[o++] = - color + (a << RrDefaultAlphaOffset); - } + /* find the position for the popup (include the outer borders) */ + x = screen_area->x + (screen_area->width - + (w + ob_rr_theme->obwidth * 2)) / 2; + y = screen_area->y + (screen_area->height - + (h + ob_rr_theme->obwidth * 2)) / 2; + + /* get the dimensions of the target hilite texture */ + rgbax = ml; + rgbay = mt; + rgbaw = w - ml - mr; + rgbah = h - mt - mb; + + if (!p->mapped) { + /* position the background but don't draw it */ + XMoveResizeWindow(obt_display, p->bg, x, y, w, h); + + if (p->mode == OB_FOCUS_CYCLE_POPUP_MODE_ICONS) { + /* position the text */ + XMoveResizeWindow(obt_display, p->icon_mode_text, + icon_mode_textx, icon_mode_texty, textw, texth); + XMapWindow(obt_display, popup.icon_mode_text); + } else { + XUnmapWindow(obt_display, popup.icon_mode_text); + + up_arrow_x = (w - ob_rr_theme->up_arrow_mask->width) / 2; + up_arrow_y = t; + + down_arrow_x = (w - ob_rr_theme->down_arrow_mask->width) / 2; + down_arrow_y = h - b - ob_rr_theme->down_arrow_mask->height; + + /* position the arrows */ + XMoveResizeWindow(obt_display, p->list_mode_up, + up_arrow_x, up_arrow_y, + ob_rr_theme->up_arrow_mask->width, + ob_rr_theme->up_arrow_mask->height); + XMoveResizeWindow(obt_display, p->list_mode_down, + down_arrow_x, down_arrow_y, + ob_rr_theme->down_arrow_mask->width, + ob_rr_theme->down_arrow_mask->height); + } } /* * * draw everything * * */ /* draw the background */ - RrPaint(p->a_bg, p->bg, w, h); + if (!p->mapped) + RrPaint(p->a_bg, p->bg, w, h); + + /* draw the scroll arrows */ + if (!p->mapped && p->mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST) { + p->a_arrow->texture[0].data.mask.mask = + ob_rr_theme->up_arrow_mask; + p->a_arrow->surface.parent = p->a_bg; + p->a_arrow->surface.parentx = up_arrow_x; + p->a_arrow->surface.parenty = up_arrow_y; + RrPaint(p->a_arrow, p->list_mode_up, + ob_rr_theme->up_arrow_mask->width, + ob_rr_theme->up_arrow_mask->height); + + p->a_arrow->texture[0].data.mask.mask = + ob_rr_theme->down_arrow_mask; + p->a_arrow->surface.parent = p->a_bg; + p->a_arrow->surface.parentx = down_arrow_x; + p->a_arrow->surface.parenty = down_arrow_y; + RrPaint(p->a_arrow, p->list_mode_down, + ob_rr_theme->down_arrow_mask->width, + ob_rr_theme->down_arrow_mask->height); + } - /* draw the icons */ + /* draw the icons and text */ for (i = 0, it = p->targets; it; ++i, it = g_list_next(it)) { const ObFocusCyclePopupTarget *target = it->data; - /* have to redraw the targetted icon and last targetted icon, - they can pick up the hilite changes in the backgroud */ - if (!p->mapped || newtarget == target || p->last_target == target) { - const gint row = i / icons_per_row; /* starting from 0 */ - const gint col = i % icons_per_row; /* starting from 0 */ - gint innerx, innery; - - /* find the dimensions of the icon inside it */ - innerx = icons_center_x + l + (col * ICON_SIZE); - innerx += ICON_HILITE_WIDTH + ICON_HILITE_MARGIN; - innery = t + (row * ICON_SIZE); - innery += ICON_HILITE_WIDTH + ICON_HILITE_MARGIN; - - /* move the icon */ - XMoveResizeWindow(ob_display, target->win, - innerx, innery, innerw, innerh); + /* have to redraw the targetted icon and last targetted icon + * to update the hilite */ + if (!p->mapped || newtarget == target || p->last_target == target || + last_scroll != p->scroll) + { + /* row and column start from 0 */ + const gint row = i / icons_per_row - p->scroll; + const gint col = i % icons_per_row; + gint iconx, icony; + gint list_mode_textx, list_mode_texty; + RrAppearance *text; + + /* find the coordinates for the icon */ + iconx = icons_center_x + l + (col * HILITE_SIZE); + icony = t + (showing_arrows ? ob_rr_theme->up_arrow_mask->height + + OUTSIDE_BORDER + : 0) + + (row * MAX(texth, HILITE_SIZE)) + + MAX(texth - HILITE_SIZE, 0) / 2; + + /* find the dimensions of the text box */ + list_mode_textx = iconx + HILITE_SIZE + TEXT_BORDER; + list_mode_texty = icony; + + /* position the icon */ + XMoveResizeWindow(obt_display, target->iconwin, + iconx, icony, HILITE_SIZE, HILITE_SIZE); + + /* position the text */ + if (p->mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST) + XMoveResizeWindow(obt_display, target->textwin, + list_mode_textx, list_mode_texty, + textw, texth); + + /* show/hide the right windows */ + if (row >= 0 && row < icon_rows) { + XMapWindow(obt_display, target->iconwin); + if (p->mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST) + XMapWindow(obt_display, target->textwin); + else + XUnmapWindow(obt_display, target->textwin); + } else { + XUnmapWindow(obt_display, target->textwin); + if (p->mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST) + XUnmapWindow(obt_display, target->iconwin); + else + XMapWindow(obt_display, target->iconwin); + } /* get the icon from the client */ + p->a_icon->texture[0].data.image.twidth = ICON_SIZE; + p->a_icon->texture[0].data.image.theight = ICON_SIZE; + p->a_icon->texture[0].data.image.tx = HILITE_OFFSET; + p->a_icon->texture[0].data.image.ty = HILITE_OFFSET; p->a_icon->texture[0].data.image.alpha = target->client->iconic ? OB_ICONIC_ALPHA : 0xff; p->a_icon->texture[0].data.image.image = target->icon; + /* Draw the hilite? */ + p->a_icon->texture[1].type = (target == newtarget) ? + RR_TEXTURE_RGBA : RR_TEXTURE_NONE; + /* draw the icon */ - p->a_icon->surface.parentx = innerx; - p->a_icon->surface.parenty = innery; - RrPaint(p->a_icon, target->win, innerw, innerh); + p->a_icon->surface.parentx = iconx; + p->a_icon->surface.parenty = icony; + RrPaint(p->a_icon, target->iconwin, HILITE_SIZE, HILITE_SIZE); + + /* draw the text */ + if (p->mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST || + target == newtarget) + { + text = (target == newtarget) ? p->a_hilite_text : p->a_text; + text->texture[0].data.text.string = target->text; + text->surface.parentx = + p->mode == OB_FOCUS_CYCLE_POPUP_MODE_ICONS ? + icon_mode_textx : list_mode_textx; + text->surface.parenty = + p->mode == OB_FOCUS_CYCLE_POPUP_MODE_ICONS ? + icon_mode_texty : list_mode_texty; + RrPaint(text, + (p->mode == OB_FOCUS_CYCLE_POPUP_MODE_ICONS ? + p->icon_mode_text : target->textwin), + textw, texth); + } } } - /* draw the text */ - p->a_text->texture[0].data.text.string = newtarget->text; - p->a_text->surface.parentx = textx; - p->a_text->surface.parenty = texty; - RrPaint(p->a_text, p->text, textw, texth); - p->last_target = newtarget; g_free(screen_area); + + XFlush(obt_display); } void focus_cycle_popup_show(ObClient *c, gboolean iconic_windows, gboolean all_desktops, gboolean dock_windows, - gboolean desktop_windows) + gboolean desktop_windows, + ObFocusCyclePopupMode mode) { g_assert(c != NULL); + if (mode == OB_FOCUS_CYCLE_POPUP_MODE_NONE) { + focus_cycle_popup_hide(); + return; + } + /* do this stuff only when the dialog is first showing */ - if (!popup.mapped) - popup_setup(&popup, TRUE, iconic_windows, all_desktops, + if (!popup.mapped) { + popup_setup(&popup, TRUE, iconic_windows, all_desktops, dock_windows, desktop_windows); + /* this is fixed once the dialog is shown */ + popup.mode = mode; + } g_assert(popup.targets != NULL); popup_render(&popup, c); if (!popup.mapped) { /* show the dialog */ - XMapWindow(ob_display, popup.bg); - XFlush(ob_display); + XMapWindow(obt_display, popup.bg); + XFlush(obt_display); popup.mapped = TRUE; screen_hide_desktop_popup(); } @@ -471,8 +678,8 @@ void focus_cycle_popup_hide(void) ignore_start = event_start_ignore_all_enters(); - XUnmapWindow(ob_display, popup.bg); - XFlush(ob_display); + XUnmapWindow(obt_display, popup.bg); + XFlush(obt_display); event_end_ignore_all_enters(ignore_start); @@ -483,16 +690,14 @@ void focus_cycle_popup_hide(void) RrImageUnref(t->icon); g_free(t->text); - XDestroyWindow(ob_display, t->win); + XDestroyWindow(obt_display, t->iconwin); + XDestroyWindow(obt_display, t->textwin); g_free(t); popup.targets = g_list_delete_link(popup.targets, popup.targets); } popup.n_targets = 0; popup.last_target = NULL; - - g_free(popup.hilite_rgba); - popup.hilite_rgba = NULL; } void focus_cycle_popup_single_show(struct _ObClient *c, diff --git a/openbox/focus_cycle_popup.h b/openbox/focus_cycle_popup.h index ded39e2..c289be3 100644 --- a/openbox/focus_cycle_popup.h +++ b/openbox/focus_cycle_popup.h @@ -24,19 +24,26 @@ struct _ObClient; #include +typedef enum { + OB_FOCUS_CYCLE_POPUP_MODE_NONE, + OB_FOCUS_CYCLE_POPUP_MODE_ICONS, + OB_FOCUS_CYCLE_POPUP_MODE_LIST +} ObFocusCyclePopupMode; + void focus_cycle_popup_startup(gboolean reconfig); void focus_cycle_popup_shutdown(gboolean reconfig); void focus_cycle_popup_show(struct _ObClient *c, gboolean iconic_windows, gboolean all_desktops, gboolean dock_windows, - gboolean desktop_windows); -void focus_cycle_popup_hide(); + gboolean desktop_windows, + ObFocusCyclePopupMode mode); +void focus_cycle_popup_hide(void); void focus_cycle_popup_single_show(struct _ObClient *c, gboolean iconic_windows, gboolean all_desktops, gboolean dock_windows, gboolean desktop_windows); -void focus_cycle_popup_single_hide(); +void focus_cycle_popup_single_hide(void); #endif diff --git a/openbox/frame.c b/openbox/frame.c index 0b764a4..25c4704 100644 --- a/openbox/frame.c +++ b/openbox/frame.c @@ -20,17 +20,16 @@ #include "frame.h" #include "client.h" #include "openbox.h" -#include "extensions.h" -#include "prop.h" #include "grab.h" #include "config.h" #include "framerender.h" -#include "mainloop.h" #include "focus_cycle.h" #include "focus_cycle_indicator.h" #include "moveresize.h" #include "screen.h" #include "render/theme.h" +#include "obt/display.h" +#include "obt/prop.h" #define FRAME_EVENTMASK (EnterWindowMask | LeaveWindowMask | \ ButtonPressMask | ButtonReleaseMask | \ @@ -56,7 +55,7 @@ static void frame_adjust_cursors(ObFrame *self); static Window createWindow(Window parent, Visual *visual, gulong mask, XSetWindowAttributes *attrib) { - return XCreateWindow(ob_display, parent, 0, 0, 1, 1, 0, + return XCreateWindow(obt_display, parent, 0, 0, 1, 1, 0, (visual ? 32 : RrDepth(ob_rr_inst)), InputOutput, (visual ? visual : RrVisual(ob_rr_inst)), mask, attrib); @@ -73,7 +72,7 @@ static Visual *check_32bit_client(ObClient *c) if (RrDepth(ob_rr_inst) == 32) return NULL; - ret = XGetWindowAttributes(ob_display, c->window, &wattrib); + ret = XGetWindowAttributes(obt_display, c->window, &wattrib); g_assert(ret != BadDrawable); g_assert(ret != BadWindow); @@ -102,13 +101,12 @@ ObFrame *frame_new(ObClient *client) mask = CWColormap | CWBackPixel | CWBorderPixel; /* create a colormap with the visual */ self->colormap = attrib.colormap = - XCreateColormap(ob_display, - RootWindow(ob_display, ob_screen), + XCreateColormap(obt_display, obt_root(ob_screen), visual, AllocNone); - attrib.background_pixel = BlackPixel(ob_display, ob_screen); - attrib.border_pixel = BlackPixel(ob_display, ob_screen); + attrib.background_pixel = BlackPixel(obt_display, ob_screen); + attrib.border_pixel = BlackPixel(obt_display, ob_screen); } - self->window = createWindow(RootWindow(ob_display, ob_screen), visual, + self->window = createWindow(obt_root(ob_screen), visual, mask, &attrib); /* create the visible decor windows */ @@ -179,9 +177,9 @@ ObFrame *frame_new(ObClient *client) self->focused = FALSE; /* the other stuff is shown based on decor settings */ - XMapWindow(ob_display, self->label); - XMapWindow(ob_display, self->backback); - XMapWindow(ob_display, self->backfront); + XMapWindow(obt_display, self->label); + XMapWindow(obt_display, self->backback); + XMapWindow(obt_display, self->backfront); self->max_press = self->close_press = self->desk_press = self->iconify_press = self->shade_press = FALSE; @@ -196,25 +194,25 @@ ObFrame *frame_new(ObClient *client) static void set_theme_statics(ObFrame *self) { /* set colors/appearance/sizes for stuff that doesn't change */ - XResizeWindow(ob_display, self->max, + XResizeWindow(obt_display, self->max, ob_rr_theme->button_size, ob_rr_theme->button_size); - XResizeWindow(ob_display, self->iconify, + XResizeWindow(obt_display, self->iconify, ob_rr_theme->button_size, ob_rr_theme->button_size); - XResizeWindow(ob_display, self->icon, + XResizeWindow(obt_display, self->icon, ob_rr_theme->button_size + 2, ob_rr_theme->button_size + 2); - XResizeWindow(ob_display, self->close, + XResizeWindow(obt_display, self->close, ob_rr_theme->button_size, ob_rr_theme->button_size); - XResizeWindow(ob_display, self->desk, + XResizeWindow(obt_display, self->desk, ob_rr_theme->button_size, ob_rr_theme->button_size); - XResizeWindow(ob_display, self->shade, + XResizeWindow(obt_display, self->shade, ob_rr_theme->button_size, ob_rr_theme->button_size); - XResizeWindow(ob_display, self->tltresize, + XResizeWindow(obt_display, self->tltresize, ob_rr_theme->grip_width, ob_rr_theme->paddingy + 1); - XResizeWindow(ob_display, self->trtresize, + XResizeWindow(obt_display, self->trtresize, ob_rr_theme->grip_width, ob_rr_theme->paddingy + 1); - XResizeWindow(ob_display, self->tllresize, + XResizeWindow(obt_display, self->tllresize, ob_rr_theme->paddingx + 1, ob_rr_theme->title_height); - XResizeWindow(ob_display, self->trrresize, + XResizeWindow(obt_display, self->trrresize, ob_rr_theme->paddingx + 1, ob_rr_theme->title_height); } @@ -226,9 +224,9 @@ void frame_free(ObFrame *self) { free_theme_statics(self); - XDestroyWindow(ob_display, self->window); + XDestroyWindow(obt_display, self->window); if (self->colormap) - XFreeColormap(ob_display, self->colormap); + XFreeColormap(obt_display, self->colormap); g_free(self); } @@ -242,8 +240,8 @@ void frame_show(ObFrame *self) the client gets its MapNotify, i.e. to make sure the client is _visible_ when it gets MapNotify. */ grab_server(TRUE); - XMapWindow(ob_display, self->client->window); - XMapWindow(ob_display, self->window); + XMapWindow(obt_display, self->client->window); + XMapWindow(obt_display, self->window); grab_server(FALSE); } } @@ -253,10 +251,10 @@ void frame_hide(ObFrame *self) if (self->visible) { self->visible = FALSE; if (!frame_iconify_animating(self)) - XUnmapWindow(ob_display, self->window); + XUnmapWindow(obt_display, self->window); /* we unmap the client itself so that we can get MapRequest events, and because the ICCCM tells us to! */ - XUnmapWindow(ob_display, self->client->window); + XUnmapWindow(obt_display, self->client->window); self->client->ignore_unmaps += 1; } } @@ -275,13 +273,13 @@ void frame_adjust_shape(ObFrame *self) if (!self->client->shaped) { /* clear the shape on the frame window */ - XShapeCombineMask(ob_display, self->window, ShapeBounding, + XShapeCombineMask(obt_display, self->window, ShapeBounding, self->size.left, self->size.top, None, ShapeSet); } else { /* make the frame's shape match the clients */ - XShapeCombineShape(ob_display, self->window, ShapeBounding, + XShapeCombineShape(obt_display, self->window, ShapeBounding, self->size.left, self->size.top, self->client->window, @@ -307,7 +305,7 @@ void frame_adjust_shape(ObFrame *self) ++num; } - XShapeCombineRectangles(ob_display, self->window, + XShapeCombineRectangles(obt_display, self->window, ShapeBounding, 0, 0, xrect, num, ShapeUnion, Unsorted); } @@ -382,17 +380,17 @@ void frame_adjust_area(ObFrame *self, gboolean moved, ob_rr_theme->grip_width - self->size.bottom; if (self->cbwidth_l) { - XMoveResizeWindow(ob_display, self->innerleft, + XMoveResizeWindow(obt_display, self->innerleft, self->size.left - self->cbwidth_l, self->size.top, self->cbwidth_l, self->client->area.height); - XMapWindow(ob_display, self->innerleft); + XMapWindow(obt_display, self->innerleft); } else - XUnmapWindow(ob_display, self->innerleft); + XUnmapWindow(obt_display, self->innerleft); if (self->cbwidth_l && innercornerheight > 0) { - XMoveResizeWindow(ob_display, self->innerbll, + XMoveResizeWindow(obt_display, self->innerbll, 0, self->client->area.height - (ob_rr_theme->grip_width - @@ -400,22 +398,22 @@ void frame_adjust_area(ObFrame *self, gboolean moved, self->cbwidth_l, ob_rr_theme->grip_width - self->size.bottom); - XMapWindow(ob_display, self->innerbll); + XMapWindow(obt_display, self->innerbll); } else - XUnmapWindow(ob_display, self->innerbll); + XUnmapWindow(obt_display, self->innerbll); if (self->cbwidth_r) { - XMoveResizeWindow(ob_display, self->innerright, + XMoveResizeWindow(obt_display, self->innerright, self->size.left + self->client->area.width, self->size.top, self->cbwidth_r, self->client->area.height); - XMapWindow(ob_display, self->innerright); + XMapWindow(obt_display, self->innerright); } else - XUnmapWindow(ob_display, self->innerright); + XUnmapWindow(obt_display, self->innerright); if (self->cbwidth_r && innercornerheight > 0) { - XMoveResizeWindow(ob_display, self->innerbrr, + XMoveResizeWindow(obt_display, self->innerbrr, 0, self->client->area.height - (ob_rr_theme->grip_width - @@ -423,35 +421,35 @@ void frame_adjust_area(ObFrame *self, gboolean moved, self->cbwidth_r, ob_rr_theme->grip_width - self->size.bottom); - XMapWindow(ob_display, self->innerbrr); + XMapWindow(obt_display, self->innerbrr); } else - XUnmapWindow(ob_display, self->innerbrr); + XUnmapWindow(obt_display, self->innerbrr); if (self->cbwidth_t) { - XMoveResizeWindow(ob_display, self->innertop, + XMoveResizeWindow(obt_display, self->innertop, self->size.left - self->cbwidth_l, self->size.top - self->cbwidth_t, self->client->area.width + self->cbwidth_l + self->cbwidth_r, self->cbwidth_t); - XMapWindow(ob_display, self->innertop); + XMapWindow(obt_display, self->innertop); } else - XUnmapWindow(ob_display, self->innertop); + XUnmapWindow(obt_display, self->innertop); if (self->cbwidth_b) { - XMoveResizeWindow(ob_display, self->innerbottom, + XMoveResizeWindow(obt_display, self->innerbottom, self->size.left - self->cbwidth_l, self->size.top + self->client->area.height, self->client->area.width + self->cbwidth_l + self->cbwidth_r, self->cbwidth_b); - XMoveResizeWindow(ob_display, self->innerblb, + XMoveResizeWindow(obt_display, self->innerblb, 0, 0, ob_rr_theme->grip_width + self->bwidth, self->cbwidth_b); - XMoveResizeWindow(ob_display, self->innerbrb, + XMoveResizeWindow(obt_display, self->innerbrb, self->client->area.width + self->cbwidth_l + self->cbwidth_r - (ob_rr_theme->grip_width + self->bwidth), @@ -459,13 +457,13 @@ void frame_adjust_area(ObFrame *self, gboolean moved, ob_rr_theme->grip_width + self->bwidth, self->cbwidth_b); - XMapWindow(ob_display, self->innerbottom); - XMapWindow(ob_display, self->innerblb); - XMapWindow(ob_display, self->innerbrb); + XMapWindow(obt_display, self->innerbottom); + XMapWindow(obt_display, self->innerblb); + XMapWindow(obt_display, self->innerbrb); } else { - XUnmapWindow(ob_display, self->innerbottom); - XUnmapWindow(ob_display, self->innerblb); - XUnmapWindow(ob_display, self->innerbrb); + XUnmapWindow(obt_display, self->innerbottom); + XUnmapWindow(obt_display, self->innerblb); + XUnmapWindow(obt_display, self->innerbrb); } if (self->bwidth) { @@ -474,16 +472,16 @@ void frame_adjust_area(ObFrame *self, gboolean moved, /* height of titleleft and titleright */ titlesides = (!self->max_horz ? ob_rr_theme->grip_width : 0); - XMoveResizeWindow(ob_display, self->titletop, + XMoveResizeWindow(obt_display, self->titletop, ob_rr_theme->grip_width + self->bwidth, 0, /* width + bwidth*2 - bwidth*2 - grips*2 */ self->width - ob_rr_theme->grip_width * 2, self->bwidth); - XMoveResizeWindow(ob_display, self->titletopleft, + XMoveResizeWindow(obt_display, self->titletopleft, 0, 0, ob_rr_theme->grip_width + self->bwidth, self->bwidth); - XMoveResizeWindow(ob_display, self->titletopright, + XMoveResizeWindow(obt_display, self->titletopright, self->client->area.width + self->size.left + self->size.right - ob_rr_theme->grip_width - self->bwidth, @@ -492,11 +490,11 @@ void frame_adjust_area(ObFrame *self, gboolean moved, self->bwidth); if (titlesides > 0) { - XMoveResizeWindow(ob_display, self->titleleft, + XMoveResizeWindow(obt_display, self->titleleft, 0, self->bwidth, self->bwidth, titlesides); - XMoveResizeWindow(ob_display, self->titleright, + XMoveResizeWindow(obt_display, self->titleright, self->client->area.width + self->size.left + self->size.right - self->bwidth, @@ -504,73 +502,73 @@ void frame_adjust_area(ObFrame *self, gboolean moved, self->bwidth, titlesides); - XMapWindow(ob_display, self->titleleft); - XMapWindow(ob_display, self->titleright); + XMapWindow(obt_display, self->titleleft); + XMapWindow(obt_display, self->titleright); } else { - XUnmapWindow(ob_display, self->titleleft); - XUnmapWindow(ob_display, self->titleright); + XUnmapWindow(obt_display, self->titleleft); + XUnmapWindow(obt_display, self->titleright); } - XMapWindow(ob_display, self->titletop); - XMapWindow(ob_display, self->titletopleft); - XMapWindow(ob_display, self->titletopright); + XMapWindow(obt_display, self->titletop); + XMapWindow(obt_display, self->titletopleft); + XMapWindow(obt_display, self->titletopright); if (self->decorations & OB_FRAME_DECOR_TITLEBAR) { - XMoveResizeWindow(ob_display, self->titlebottom, + XMoveResizeWindow(obt_display, self->titlebottom, (self->max_horz ? 0 : self->bwidth), ob_rr_theme->title_height + self->bwidth, self->width, self->bwidth); - XMapWindow(ob_display, self->titlebottom); + XMapWindow(obt_display, self->titlebottom); } else - XUnmapWindow(ob_display, self->titlebottom); + XUnmapWindow(obt_display, self->titlebottom); } else { - XUnmapWindow(ob_display, self->titlebottom); + XUnmapWindow(obt_display, self->titlebottom); - XUnmapWindow(ob_display, self->titletop); - XUnmapWindow(ob_display, self->titletopleft); - XUnmapWindow(ob_display, self->titletopright); - XUnmapWindow(ob_display, self->titleleft); - XUnmapWindow(ob_display, self->titleright); + XUnmapWindow(obt_display, self->titletop); + XUnmapWindow(obt_display, self->titletopleft); + XUnmapWindow(obt_display, self->titletopright); + XUnmapWindow(obt_display, self->titleleft); + XUnmapWindow(obt_display, self->titleright); } if (self->decorations & OB_FRAME_DECOR_TITLEBAR) { - XMoveResizeWindow(ob_display, self->title, + XMoveResizeWindow(obt_display, self->title, (self->max_horz ? 0 : self->bwidth), self->bwidth, self->width, ob_rr_theme->title_height); - XMapWindow(ob_display, self->title); + XMapWindow(obt_display, self->title); if (self->decorations & OB_FRAME_DECOR_GRIPS) { - XMoveResizeWindow(ob_display, self->topresize, + XMoveResizeWindow(obt_display, self->topresize, ob_rr_theme->grip_width, 0, self->width - ob_rr_theme->grip_width *2, ob_rr_theme->paddingy + 1); - XMoveWindow(ob_display, self->tltresize, 0, 0); - XMoveWindow(ob_display, self->tllresize, 0, 0); - XMoveWindow(ob_display, self->trtresize, + XMoveWindow(obt_display, self->tltresize, 0, 0); + XMoveWindow(obt_display, self->tllresize, 0, 0); + XMoveWindow(obt_display, self->trtresize, self->width - ob_rr_theme->grip_width, 0); - XMoveWindow(ob_display, self->trrresize, + XMoveWindow(obt_display, self->trrresize, self->width - ob_rr_theme->paddingx - 1, 0); - XMapWindow(ob_display, self->topresize); - XMapWindow(ob_display, self->tltresize); - XMapWindow(ob_display, self->tllresize); - XMapWindow(ob_display, self->trtresize); - XMapWindow(ob_display, self->trrresize); + XMapWindow(obt_display, self->topresize); + XMapWindow(obt_display, self->tltresize); + XMapWindow(obt_display, self->tllresize); + XMapWindow(obt_display, self->trtresize); + XMapWindow(obt_display, self->trrresize); } else { - XUnmapWindow(ob_display, self->topresize); - XUnmapWindow(ob_display, self->tltresize); - XUnmapWindow(ob_display, self->tllresize); - XUnmapWindow(ob_display, self->trtresize); - XUnmapWindow(ob_display, self->trrresize); + XUnmapWindow(obt_display, self->topresize); + XUnmapWindow(obt_display, self->tltresize); + XUnmapWindow(obt_display, self->tllresize); + XUnmapWindow(obt_display, self->trtresize); + XUnmapWindow(obt_display, self->trrresize); } } else - XUnmapWindow(ob_display, self->title); + XUnmapWindow(obt_display, self->title); } if ((self->decorations & OB_FRAME_DECOR_TITLEBAR)) @@ -581,7 +579,7 @@ void frame_adjust_area(ObFrame *self, gboolean moved, gint sidebwidth = self->max_horz ? 0 : self->bwidth; if (self->bwidth && self->size.bottom) { - XMoveResizeWindow(ob_display, self->handlebottom, + XMoveResizeWindow(obt_display, self->handlebottom, ob_rr_theme->grip_width + self->bwidth + sidebwidth, self->size.top + self->client->area.height + @@ -592,7 +590,7 @@ void frame_adjust_area(ObFrame *self, gboolean moved, if (sidebwidth) { - XMoveResizeWindow(ob_display, self->lgripleft, + XMoveResizeWindow(obt_display, self->lgripleft, 0, self->size.top + self->client->area.height + @@ -604,7 +602,7 @@ void frame_adjust_area(ObFrame *self, gboolean moved, (!self->max_horz ? ob_rr_theme->grip_width : self->size.bottom - self->cbwidth_b)); - XMoveResizeWindow(ob_display, self->rgripright, + XMoveResizeWindow(obt_display, self->rgripright, self->size.left + self->client->area.width + self->size.right - self->bwidth, @@ -619,20 +617,20 @@ void frame_adjust_area(ObFrame *self, gboolean moved, ob_rr_theme->grip_width : self->size.bottom - self->cbwidth_b)); - XMapWindow(ob_display, self->lgripleft); - XMapWindow(ob_display, self->rgripright); + XMapWindow(obt_display, self->lgripleft); + XMapWindow(obt_display, self->rgripright); } else { - XUnmapWindow(ob_display, self->lgripleft); - XUnmapWindow(ob_display, self->rgripright); + XUnmapWindow(obt_display, self->lgripleft); + XUnmapWindow(obt_display, self->rgripright); } - XMoveResizeWindow(ob_display, self->lgripbottom, + XMoveResizeWindow(obt_display, self->lgripbottom, sidebwidth, self->size.top + self->client->area.height + self->size.bottom - self->bwidth, ob_rr_theme->grip_width + self->bwidth, self->bwidth); - XMoveResizeWindow(ob_display, self->rgripbottom, + XMoveResizeWindow(obt_display, self->rgripbottom, self->size.left + self->client->area.width + self->size.right - self->bwidth - sidebwidth- ob_rr_theme->grip_width, @@ -641,29 +639,29 @@ void frame_adjust_area(ObFrame *self, gboolean moved, ob_rr_theme->grip_width + self->bwidth, self->bwidth); - XMapWindow(ob_display, self->handlebottom); - XMapWindow(ob_display, self->lgripbottom); - XMapWindow(ob_display, self->rgripbottom); + XMapWindow(obt_display, self->handlebottom); + XMapWindow(obt_display, self->lgripbottom); + XMapWindow(obt_display, self->rgripbottom); if (self->decorations & OB_FRAME_DECOR_HANDLE && ob_rr_theme->handle_height > 0) { - XMoveResizeWindow(ob_display, self->handletop, + XMoveResizeWindow(obt_display, self->handletop, ob_rr_theme->grip_width + self->bwidth + sidebwidth, FRAME_HANDLE_Y(self), self->width - (ob_rr_theme->grip_width + sidebwidth) * 2, self->bwidth); - XMapWindow(ob_display, self->handletop); + XMapWindow(obt_display, self->handletop); if (self->decorations & OB_FRAME_DECOR_GRIPS) { - XMoveResizeWindow(ob_display, self->handleleft, + XMoveResizeWindow(obt_display, self->handleleft, ob_rr_theme->grip_width, 0, self->bwidth, ob_rr_theme->handle_height); - XMoveResizeWindow(ob_display, self->handleright, + XMoveResizeWindow(obt_display, self->handleright, self->width - ob_rr_theme->grip_width - self->bwidth, @@ -671,13 +669,13 @@ void frame_adjust_area(ObFrame *self, gboolean moved, self->bwidth, ob_rr_theme->handle_height); - XMoveResizeWindow(ob_display, self->lgriptop, + XMoveResizeWindow(obt_display, self->lgriptop, sidebwidth, FRAME_HANDLE_Y(self), ob_rr_theme->grip_width + self->bwidth, self->bwidth); - XMoveResizeWindow(ob_display, self->rgriptop, + XMoveResizeWindow(obt_display, self->rgriptop, self->size.left + self->client->area.width + self->size.right - self->bwidth - @@ -687,77 +685,77 @@ void frame_adjust_area(ObFrame *self, gboolean moved, self->bwidth, self->bwidth); - XMapWindow(ob_display, self->handleleft); - XMapWindow(ob_display, self->handleright); - XMapWindow(ob_display, self->lgriptop); - XMapWindow(ob_display, self->rgriptop); + XMapWindow(obt_display, self->handleleft); + XMapWindow(obt_display, self->handleright); + XMapWindow(obt_display, self->lgriptop); + XMapWindow(obt_display, self->rgriptop); } else { - XUnmapWindow(ob_display, self->handleleft); - XUnmapWindow(ob_display, self->handleright); - XUnmapWindow(ob_display, self->lgriptop); - XUnmapWindow(ob_display, self->rgriptop); + XUnmapWindow(obt_display, self->handleleft); + XUnmapWindow(obt_display, self->handleright); + XUnmapWindow(obt_display, self->lgriptop); + XUnmapWindow(obt_display, self->rgriptop); } } else { - XUnmapWindow(ob_display, self->handleleft); - XUnmapWindow(ob_display, self->handleright); - XUnmapWindow(ob_display, self->lgriptop); - XUnmapWindow(ob_display, self->rgriptop); + XUnmapWindow(obt_display, self->handleleft); + XUnmapWindow(obt_display, self->handleright); + XUnmapWindow(obt_display, self->lgriptop); + XUnmapWindow(obt_display, self->rgriptop); - XUnmapWindow(ob_display, self->handletop); + XUnmapWindow(obt_display, self->handletop); } } else { - XUnmapWindow(ob_display, self->handleleft); - XUnmapWindow(ob_display, self->handleright); - XUnmapWindow(ob_display, self->lgriptop); - XUnmapWindow(ob_display, self->rgriptop); - - XUnmapWindow(ob_display, self->handletop); - - XUnmapWindow(ob_display, self->handlebottom); - XUnmapWindow(ob_display, self->lgripleft); - XUnmapWindow(ob_display, self->rgripright); - XUnmapWindow(ob_display, self->lgripbottom); - XUnmapWindow(ob_display, self->rgripbottom); + XUnmapWindow(obt_display, self->handleleft); + XUnmapWindow(obt_display, self->handleright); + XUnmapWindow(obt_display, self->lgriptop); + XUnmapWindow(obt_display, self->rgriptop); + + XUnmapWindow(obt_display, self->handletop); + + XUnmapWindow(obt_display, self->handlebottom); + XUnmapWindow(obt_display, self->lgripleft); + XUnmapWindow(obt_display, self->rgripright); + XUnmapWindow(obt_display, self->lgripbottom); + XUnmapWindow(obt_display, self->rgripbottom); } if (self->decorations & OB_FRAME_DECOR_HANDLE && ob_rr_theme->handle_height > 0) { - XMoveResizeWindow(ob_display, self->handle, + XMoveResizeWindow(obt_display, self->handle, sidebwidth, FRAME_HANDLE_Y(self) + self->bwidth, self->width, ob_rr_theme->handle_height); - XMapWindow(ob_display, self->handle); + XMapWindow(obt_display, self->handle); if (self->decorations & OB_FRAME_DECOR_GRIPS) { - XMoveResizeWindow(ob_display, self->lgrip, + XMoveResizeWindow(obt_display, self->lgrip, 0, 0, ob_rr_theme->grip_width, ob_rr_theme->handle_height); - XMoveResizeWindow(ob_display, self->rgrip, + XMoveResizeWindow(obt_display, self->rgrip, self->width - ob_rr_theme->grip_width, 0, ob_rr_theme->grip_width, ob_rr_theme->handle_height); - XMapWindow(ob_display, self->lgrip); - XMapWindow(ob_display, self->rgrip); + XMapWindow(obt_display, self->lgrip); + XMapWindow(obt_display, self->rgrip); } else { - XUnmapWindow(ob_display, self->lgrip); - XUnmapWindow(ob_display, self->rgrip); + XUnmapWindow(obt_display, self->lgrip); + XUnmapWindow(obt_display, self->rgrip); } } else { - XUnmapWindow(ob_display, self->lgrip); - XUnmapWindow(ob_display, self->rgrip); + XUnmapWindow(obt_display, self->lgrip); + XUnmapWindow(obt_display, self->rgrip); - XUnmapWindow(ob_display, self->handle); + XUnmapWindow(obt_display, self->handle); } if (self->bwidth && !self->max_horz && (self->client->area.height + self->size.top + self->size.bottom) > ob_rr_theme->grip_width * 2) { - XMoveResizeWindow(ob_display, self->left, + XMoveResizeWindow(obt_display, self->left, 0, self->bwidth + ob_rr_theme->grip_width, self->bwidth, @@ -765,15 +763,15 @@ void frame_adjust_area(ObFrame *self, gboolean moved, self->size.top + self->size.bottom - ob_rr_theme->grip_width * 2); - XMapWindow(ob_display, self->left); + XMapWindow(obt_display, self->left); } else - XUnmapWindow(ob_display, self->left); + XUnmapWindow(obt_display, self->left); if (self->bwidth && !self->max_horz && (self->client->area.height + self->size.top + self->size.bottom) > ob_rr_theme->grip_width * 2) { - XMoveResizeWindow(ob_display, self->right, + XMoveResizeWindow(obt_display, self->right, self->client->area.width + self->cbwidth_l + self->cbwidth_r + self->bwidth, self->bwidth + ob_rr_theme->grip_width, @@ -782,11 +780,11 @@ void frame_adjust_area(ObFrame *self, gboolean moved, self->size.top + self->size.bottom - ob_rr_theme->grip_width * 2); - XMapWindow(ob_display, self->right); + XMapWindow(obt_display, self->right); } else - XUnmapWindow(ob_display, self->right); + XUnmapWindow(obt_display, self->right); - XMoveResizeWindow(ob_display, self->backback, + XMoveResizeWindow(obt_display, self->backback, self->size.left, self->size.top, self->client->area.width, self->client->area.height); @@ -818,7 +816,7 @@ void frame_adjust_area(ObFrame *self, gboolean moved, but don't do this during an iconify animation. it will be reflected afterwards. */ - XMoveResizeWindow(ob_display, self->window, + XMoveResizeWindow(obt_display, self->window, self->area.x, self->area.y, self->area.width, @@ -828,7 +826,7 @@ void frame_adjust_area(ObFrame *self, gboolean moved, also this correctly positions the client when it maps. this also needs to be run when the frame's decorations sizes change! */ - XMoveWindow(ob_display, self->client->window, + XMoveWindow(obt_display, self->client->window, self->size.left, self->size.top); if (resized) { @@ -843,10 +841,10 @@ void frame_adjust_area(ObFrame *self, gboolean moved, vals[1] = self->size.right; vals[2] = self->size.top; vals[3] = self->size.bottom; - PROP_SETA32(self->client->window, net_frame_extents, - cardinal, vals, 4); - PROP_SETA32(self->client->window, kde_net_wm_frame_strut, - cardinal, vals, 4); + OBT_PROP_SETA32(self->client->window, NET_FRAME_EXTENTS, + CARDINAL, vals, 4); + OBT_PROP_SETA32(self->client->window, KDE_NET_WM_FRAME_STRUT, + CARDINAL, vals, 4); } /* if this occurs while we are focus cycling, the indicator needs to @@ -855,7 +853,7 @@ void frame_adjust_area(ObFrame *self, gboolean moved, focus_cycle_draw_indicator(self->client); } if (resized && (self->decorations & OB_FRAME_DECOR_TITLEBAR)) - XResizeWindow(ob_display, self->label, self->label_width, + XResizeWindow(obt_display, self->label, self->label_width, ob_rr_theme->label_height); } @@ -877,58 +875,58 @@ static void frame_adjust_cursors(ObFrame *self) /* these ones turn off when max vert, and some when shaded */ a.cursor = ob_cursor(r && topbot && !sh ? OB_CURSOR_NORTH : OB_CURSOR_NONE); - XChangeWindowAttributes(ob_display, self->topresize, CWCursor, &a); - XChangeWindowAttributes(ob_display, self->titletop, CWCursor, &a); + XChangeWindowAttributes(obt_display, self->topresize, CWCursor, &a); + XChangeWindowAttributes(obt_display, self->titletop, CWCursor, &a); a.cursor = ob_cursor(r && topbot ? OB_CURSOR_SOUTH : OB_CURSOR_NONE); - XChangeWindowAttributes(ob_display, self->handle, CWCursor, &a); - XChangeWindowAttributes(ob_display, self->handletop, CWCursor, &a); - XChangeWindowAttributes(ob_display, self->handlebottom, CWCursor, &a); - XChangeWindowAttributes(ob_display, self->innerbottom, CWCursor, &a); + XChangeWindowAttributes(obt_display, self->handle, CWCursor, &a); + XChangeWindowAttributes(obt_display, self->handletop, CWCursor, &a); + XChangeWindowAttributes(obt_display, self->handlebottom, CWCursor, &a); + XChangeWindowAttributes(obt_display, self->innerbottom, CWCursor, &a); /* these ones change when shaded */ a.cursor = ob_cursor(r ? (sh ? OB_CURSOR_WEST : OB_CURSOR_NORTHWEST) : OB_CURSOR_NONE); - XChangeWindowAttributes(ob_display, self->titleleft, CWCursor, &a); - XChangeWindowAttributes(ob_display, self->tltresize, CWCursor, &a); - XChangeWindowAttributes(ob_display, self->tllresize, CWCursor, &a); - XChangeWindowAttributes(ob_display, self->titletopleft, CWCursor, &a); + XChangeWindowAttributes(obt_display, self->titleleft, CWCursor, &a); + XChangeWindowAttributes(obt_display, self->tltresize, CWCursor, &a); + XChangeWindowAttributes(obt_display, self->tllresize, CWCursor, &a); + XChangeWindowAttributes(obt_display, self->titletopleft, CWCursor, &a); a.cursor = ob_cursor(r ? (sh ? OB_CURSOR_EAST : OB_CURSOR_NORTHEAST) : OB_CURSOR_NONE); - XChangeWindowAttributes(ob_display, self->titleright, CWCursor, &a); - XChangeWindowAttributes(ob_display, self->trtresize, CWCursor, &a); - XChangeWindowAttributes(ob_display, self->trrresize, CWCursor, &a); - XChangeWindowAttributes(ob_display, self->titletopright, CWCursor, &a); + XChangeWindowAttributes(obt_display, self->titleright, CWCursor, &a); + XChangeWindowAttributes(obt_display, self->trtresize, CWCursor, &a); + XChangeWindowAttributes(obt_display, self->trrresize, CWCursor, &a); + XChangeWindowAttributes(obt_display, self->titletopright, CWCursor,&a); /* these ones are pretty static */ a.cursor = ob_cursor(r ? OB_CURSOR_WEST : OB_CURSOR_NONE); - XChangeWindowAttributes(ob_display, self->left, CWCursor, &a); - XChangeWindowAttributes(ob_display, self->innerleft, CWCursor, &a); + XChangeWindowAttributes(obt_display, self->left, CWCursor, &a); + XChangeWindowAttributes(obt_display, self->innerleft, CWCursor, &a); a.cursor = ob_cursor(r ? OB_CURSOR_EAST : OB_CURSOR_NONE); - XChangeWindowAttributes(ob_display, self->right, CWCursor, &a); - XChangeWindowAttributes(ob_display, self->innerright, CWCursor, &a); + XChangeWindowAttributes(obt_display, self->right, CWCursor, &a); + XChangeWindowAttributes(obt_display, self->innerright, CWCursor, &a); a.cursor = ob_cursor(r ? OB_CURSOR_SOUTHWEST : OB_CURSOR_NONE); - XChangeWindowAttributes(ob_display, self->lgrip, CWCursor, &a); - XChangeWindowAttributes(ob_display, self->handleleft, CWCursor, &a); - XChangeWindowAttributes(ob_display, self->lgripleft, CWCursor, &a); - XChangeWindowAttributes(ob_display, self->lgriptop, CWCursor, &a); - XChangeWindowAttributes(ob_display, self->lgripbottom, CWCursor, &a); - XChangeWindowAttributes(ob_display, self->innerbll, CWCursor, &a); - XChangeWindowAttributes(ob_display, self->innerblb, CWCursor, &a); + XChangeWindowAttributes(obt_display, self->lgrip, CWCursor, &a); + XChangeWindowAttributes(obt_display, self->handleleft, CWCursor, &a); + XChangeWindowAttributes(obt_display, self->lgripleft, CWCursor, &a); + XChangeWindowAttributes(obt_display, self->lgriptop, CWCursor, &a); + XChangeWindowAttributes(obt_display, self->lgripbottom, CWCursor, &a); + XChangeWindowAttributes(obt_display, self->innerbll, CWCursor, &a); + XChangeWindowAttributes(obt_display, self->innerblb, CWCursor, &a); a.cursor = ob_cursor(r ? OB_CURSOR_SOUTHEAST : OB_CURSOR_NONE); - XChangeWindowAttributes(ob_display, self->rgrip, CWCursor, &a); - XChangeWindowAttributes(ob_display, self->handleright, CWCursor, &a); - XChangeWindowAttributes(ob_display, self->rgripright, CWCursor, &a); - XChangeWindowAttributes(ob_display, self->rgriptop, CWCursor, &a); - XChangeWindowAttributes(ob_display, self->rgripbottom, CWCursor, &a); - XChangeWindowAttributes(ob_display, self->innerbrr, CWCursor, &a); - XChangeWindowAttributes(ob_display, self->innerbrb, CWCursor, &a); + XChangeWindowAttributes(obt_display, self->rgrip, CWCursor, &a); + XChangeWindowAttributes(obt_display, self->handleright, CWCursor, &a); + XChangeWindowAttributes(obt_display, self->rgripright, CWCursor, &a); + XChangeWindowAttributes(obt_display, self->rgriptop, CWCursor, &a); + XChangeWindowAttributes(obt_display, self->rgripbottom, CWCursor, &a); + XChangeWindowAttributes(obt_display, self->innerbrr, CWCursor, &a); + XChangeWindowAttributes(obt_display, self->innerbrb, CWCursor, &a); } } void frame_adjust_client_area(ObFrame *self) { /* adjust the window which is there to prevent flashing on unmap */ - XMoveResizeWindow(ob_display, self->backfront, 0, 0, + XMoveResizeWindow(obt_display, self->backfront, 0, 0, self->client->area.width, self->client->area.height); } @@ -944,7 +942,7 @@ void frame_adjust_focus(ObFrame *self, gboolean hilite) self->focused = hilite; self->need_render = TRUE; framerender_frame(self); - XFlush(ob_display); + XFlush(obt_display); } void frame_adjust_title(ObFrame *self) @@ -967,7 +965,7 @@ void frame_grab_client(ObFrame *self) */ /* reparent the client to the frame */ - XReparentWindow(ob_display, self->client->window, self->window, 0, 0); + XReparentWindow(obt_display, self->client->window, self->window, 0, 0); /* When reparenting the client window, it is usually not mapped yet, since @@ -980,54 +978,54 @@ void frame_grab_client(ObFrame *self) /* select the event mask on the client's parent (to receive config/map req's) the ButtonPress is to catch clicks on the client border */ - XSelectInput(ob_display, self->window, FRAME_EVENTMASK); + XSelectInput(obt_display, self->window, FRAME_EVENTMASK); /* set all the windows for the frame in the window_map */ - g_hash_table_insert(window_map, &self->window, self->client); - g_hash_table_insert(window_map, &self->backback, self->client); - g_hash_table_insert(window_map, &self->backfront, self->client); - g_hash_table_insert(window_map, &self->innerleft, self->client); - g_hash_table_insert(window_map, &self->innertop, self->client); - g_hash_table_insert(window_map, &self->innerright, self->client); - g_hash_table_insert(window_map, &self->innerbottom, self->client); - g_hash_table_insert(window_map, &self->innerblb, self->client); - g_hash_table_insert(window_map, &self->innerbll, self->client); - g_hash_table_insert(window_map, &self->innerbrb, self->client); - g_hash_table_insert(window_map, &self->innerbrr, self->client); - g_hash_table_insert(window_map, &self->title, self->client); - g_hash_table_insert(window_map, &self->label, self->client); - g_hash_table_insert(window_map, &self->max, self->client); - g_hash_table_insert(window_map, &self->close, self->client); - g_hash_table_insert(window_map, &self->desk, self->client); - g_hash_table_insert(window_map, &self->shade, self->client); - g_hash_table_insert(window_map, &self->icon, self->client); - g_hash_table_insert(window_map, &self->iconify, self->client); - g_hash_table_insert(window_map, &self->handle, self->client); - g_hash_table_insert(window_map, &self->lgrip, self->client); - g_hash_table_insert(window_map, &self->rgrip, self->client); - g_hash_table_insert(window_map, &self->topresize, self->client); - g_hash_table_insert(window_map, &self->tltresize, self->client); - g_hash_table_insert(window_map, &self->tllresize, self->client); - g_hash_table_insert(window_map, &self->trtresize, self->client); - g_hash_table_insert(window_map, &self->trrresize, self->client); - g_hash_table_insert(window_map, &self->left, self->client); - g_hash_table_insert(window_map, &self->right, self->client); - g_hash_table_insert(window_map, &self->titleleft, self->client); - g_hash_table_insert(window_map, &self->titletop, self->client); - g_hash_table_insert(window_map, &self->titletopleft, self->client); - g_hash_table_insert(window_map, &self->titletopright, self->client); - g_hash_table_insert(window_map, &self->titleright, self->client); - g_hash_table_insert(window_map, &self->titlebottom, self->client); - g_hash_table_insert(window_map, &self->handleleft, self->client); - g_hash_table_insert(window_map, &self->handletop, self->client); - g_hash_table_insert(window_map, &self->handleright, self->client); - g_hash_table_insert(window_map, &self->handlebottom, self->client); - g_hash_table_insert(window_map, &self->lgripleft, self->client); - g_hash_table_insert(window_map, &self->lgriptop, self->client); - g_hash_table_insert(window_map, &self->lgripbottom, self->client); - g_hash_table_insert(window_map, &self->rgripright, self->client); - g_hash_table_insert(window_map, &self->rgriptop, self->client); - g_hash_table_insert(window_map, &self->rgripbottom, self->client); + window_add(&self->window, CLIENT_AS_WINDOW(self->client)); + window_add(&self->backback, CLIENT_AS_WINDOW(self->client)); + window_add(&self->backfront, CLIENT_AS_WINDOW(self->client)); + window_add(&self->innerleft, CLIENT_AS_WINDOW(self->client)); + window_add(&self->innertop, CLIENT_AS_WINDOW(self->client)); + window_add(&self->innerright, CLIENT_AS_WINDOW(self->client)); + window_add(&self->innerbottom, CLIENT_AS_WINDOW(self->client)); + window_add(&self->innerblb, CLIENT_AS_WINDOW(self->client)); + window_add(&self->innerbll, CLIENT_AS_WINDOW(self->client)); + window_add(&self->innerbrb, CLIENT_AS_WINDOW(self->client)); + window_add(&self->innerbrr, CLIENT_AS_WINDOW(self->client)); + window_add(&self->title, CLIENT_AS_WINDOW(self->client)); + window_add(&self->label, CLIENT_AS_WINDOW(self->client)); + window_add(&self->max, CLIENT_AS_WINDOW(self->client)); + window_add(&self->close, CLIENT_AS_WINDOW(self->client)); + window_add(&self->desk, CLIENT_AS_WINDOW(self->client)); + window_add(&self->shade, CLIENT_AS_WINDOW(self->client)); + window_add(&self->icon, CLIENT_AS_WINDOW(self->client)); + window_add(&self->iconify, CLIENT_AS_WINDOW(self->client)); + window_add(&self->handle, CLIENT_AS_WINDOW(self->client)); + window_add(&self->lgrip, CLIENT_AS_WINDOW(self->client)); + window_add(&self->rgrip, CLIENT_AS_WINDOW(self->client)); + window_add(&self->topresize, CLIENT_AS_WINDOW(self->client)); + window_add(&self->tltresize, CLIENT_AS_WINDOW(self->client)); + window_add(&self->tllresize, CLIENT_AS_WINDOW(self->client)); + window_add(&self->trtresize, CLIENT_AS_WINDOW(self->client)); + window_add(&self->trrresize, CLIENT_AS_WINDOW(self->client)); + window_add(&self->left, CLIENT_AS_WINDOW(self->client)); + window_add(&self->right, CLIENT_AS_WINDOW(self->client)); + window_add(&self->titleleft, CLIENT_AS_WINDOW(self->client)); + window_add(&self->titletop, CLIENT_AS_WINDOW(self->client)); + window_add(&self->titletopleft, CLIENT_AS_WINDOW(self->client)); + window_add(&self->titletopright, CLIENT_AS_WINDOW(self->client)); + window_add(&self->titleright, CLIENT_AS_WINDOW(self->client)); + window_add(&self->titlebottom, CLIENT_AS_WINDOW(self->client)); + window_add(&self->handleleft, CLIENT_AS_WINDOW(self->client)); + window_add(&self->handletop, CLIENT_AS_WINDOW(self->client)); + window_add(&self->handleright, CLIENT_AS_WINDOW(self->client)); + window_add(&self->handlebottom, CLIENT_AS_WINDOW(self->client)); + window_add(&self->lgripleft, CLIENT_AS_WINDOW(self->client)); + window_add(&self->lgriptop, CLIENT_AS_WINDOW(self->client)); + window_add(&self->lgripbottom, CLIENT_AS_WINDOW(self->client)); + window_add(&self->rgripright, CLIENT_AS_WINDOW(self->client)); + window_add(&self->rgriptop, CLIENT_AS_WINDOW(self->client)); + window_add(&self->rgripbottom, CLIENT_AS_WINDOW(self->client)); } void frame_release_client(ObFrame *self) @@ -1036,11 +1034,11 @@ void frame_release_client(ObFrame *self) gboolean reparent = TRUE; /* if there was any animation going on, kill it */ - ob_main_loop_timeout_remove_data(ob_main_loop, frame_animate_iconify, - self, FALSE); + obt_main_loop_timeout_remove_data(ob_main_loop, frame_animate_iconify, + self, FALSE); /* check if the app has already reparented its window away */ - while (XCheckTypedWindowEvent(ob_display, self->client->window, + while (XCheckTypedWindowEvent(obt_display, self->client->window, ReparentNotify, &ev)) { /* This check makes sure we don't catch our own reparent action to @@ -1052,7 +1050,7 @@ void frame_release_client(ObFrame *self) */ if (ev.xreparent.parent != self->window) { reparent = FALSE; - XPutBackEvent(ob_display, &ev); + XPutBackEvent(obt_display, &ev); break; } } @@ -1060,60 +1058,58 @@ void frame_release_client(ObFrame *self) if (reparent) { /* according to the ICCCM - if the client doesn't reparent itself, then we will reparent the window to root for them */ - XReparentWindow(ob_display, self->client->window, - RootWindow(ob_display, ob_screen), - self->client->area.x, - self->client->area.y); + XReparentWindow(obt_display, self->client->window, obt_root(ob_screen), + self->client->area.x, self->client->area.y); } /* remove all the windows for the frame from the window_map */ - g_hash_table_remove(window_map, &self->window); - g_hash_table_remove(window_map, &self->backback); - g_hash_table_remove(window_map, &self->backfront); - g_hash_table_remove(window_map, &self->innerleft); - g_hash_table_remove(window_map, &self->innertop); - g_hash_table_remove(window_map, &self->innerright); - g_hash_table_remove(window_map, &self->innerbottom); - g_hash_table_remove(window_map, &self->innerblb); - g_hash_table_remove(window_map, &self->innerbll); - g_hash_table_remove(window_map, &self->innerbrb); - g_hash_table_remove(window_map, &self->innerbrr); - g_hash_table_remove(window_map, &self->title); - g_hash_table_remove(window_map, &self->label); - g_hash_table_remove(window_map, &self->max); - g_hash_table_remove(window_map, &self->close); - g_hash_table_remove(window_map, &self->desk); - g_hash_table_remove(window_map, &self->shade); - g_hash_table_remove(window_map, &self->icon); - g_hash_table_remove(window_map, &self->iconify); - g_hash_table_remove(window_map, &self->handle); - g_hash_table_remove(window_map, &self->lgrip); - g_hash_table_remove(window_map, &self->rgrip); - g_hash_table_remove(window_map, &self->topresize); - g_hash_table_remove(window_map, &self->tltresize); - g_hash_table_remove(window_map, &self->tllresize); - g_hash_table_remove(window_map, &self->trtresize); - g_hash_table_remove(window_map, &self->trrresize); - g_hash_table_remove(window_map, &self->left); - g_hash_table_remove(window_map, &self->right); - g_hash_table_remove(window_map, &self->titleleft); - g_hash_table_remove(window_map, &self->titletop); - g_hash_table_remove(window_map, &self->titletopleft); - g_hash_table_remove(window_map, &self->titletopright); - g_hash_table_remove(window_map, &self->titleright); - g_hash_table_remove(window_map, &self->titlebottom); - g_hash_table_remove(window_map, &self->handleleft); - g_hash_table_remove(window_map, &self->handletop); - g_hash_table_remove(window_map, &self->handleright); - g_hash_table_remove(window_map, &self->handlebottom); - g_hash_table_remove(window_map, &self->lgripleft); - g_hash_table_remove(window_map, &self->lgriptop); - g_hash_table_remove(window_map, &self->lgripbottom); - g_hash_table_remove(window_map, &self->rgripright); - g_hash_table_remove(window_map, &self->rgriptop); - g_hash_table_remove(window_map, &self->rgripbottom); - - ob_main_loop_timeout_remove_data(ob_main_loop, flash_timeout, self, TRUE); + window_remove(self->window); + window_remove(self->backback); + window_remove(self->backfront); + window_remove(self->innerleft); + window_remove(self->innertop); + window_remove(self->innerright); + window_remove(self->innerbottom); + window_remove(self->innerblb); + window_remove(self->innerbll); + window_remove(self->innerbrb); + window_remove(self->innerbrr); + window_remove(self->title); + window_remove(self->label); + window_remove(self->max); + window_remove(self->close); + window_remove(self->desk); + window_remove(self->shade); + window_remove(self->icon); + window_remove(self->iconify); + window_remove(self->handle); + window_remove(self->lgrip); + window_remove(self->rgrip); + window_remove(self->topresize); + window_remove(self->tltresize); + window_remove(self->tllresize); + window_remove(self->trtresize); + window_remove(self->trrresize); + window_remove(self->left); + window_remove(self->right); + window_remove(self->titleleft); + window_remove(self->titletop); + window_remove(self->titletopleft); + window_remove(self->titletopright); + window_remove(self->titleright); + window_remove(self->titlebottom); + window_remove(self->handleleft); + window_remove(self->handletop); + window_remove(self->handleright); + window_remove(self->handlebottom); + window_remove(self->lgripleft); + window_remove(self->lgriptop); + window_remove(self->lgripbottom); + window_remove(self->rgripright); + window_remove(self->rgriptop); + window_remove(self->rgripbottom); + + obt_main_loop_timeout_remove_data(ob_main_loop, flash_timeout, self, TRUE); } /* is there anything present between us and the label? */ @@ -1239,54 +1235,54 @@ static void layout_title(ObFrame *self) /* position and map the elements */ if (self->icon_on) { - XMapWindow(ob_display, self->icon); - XMoveWindow(ob_display, self->icon, self->icon_x, + XMapWindow(obt_display, self->icon); + XMoveWindow(obt_display, self->icon, self->icon_x, ob_rr_theme->paddingy); } else - XUnmapWindow(ob_display, self->icon); + XUnmapWindow(obt_display, self->icon); if (self->desk_on) { - XMapWindow(ob_display, self->desk); - XMoveWindow(ob_display, self->desk, self->desk_x, + XMapWindow(obt_display, self->desk); + XMoveWindow(obt_display, self->desk, self->desk_x, ob_rr_theme->paddingy + 1); } else - XUnmapWindow(ob_display, self->desk); + XUnmapWindow(obt_display, self->desk); if (self->shade_on) { - XMapWindow(ob_display, self->shade); - XMoveWindow(ob_display, self->shade, self->shade_x, + XMapWindow(obt_display, self->shade); + XMoveWindow(obt_display, self->shade, self->shade_x, ob_rr_theme->paddingy + 1); } else - XUnmapWindow(ob_display, self->shade); + XUnmapWindow(obt_display, self->shade); if (self->iconify_on) { - XMapWindow(ob_display, self->iconify); - XMoveWindow(ob_display, self->iconify, self->iconify_x, + XMapWindow(obt_display, self->iconify); + XMoveWindow(obt_display, self->iconify, self->iconify_x, ob_rr_theme->paddingy + 1); } else - XUnmapWindow(ob_display, self->iconify); + XUnmapWindow(obt_display, self->iconify); if (self->max_on) { - XMapWindow(ob_display, self->max); - XMoveWindow(ob_display, self->max, self->max_x, + XMapWindow(obt_display, self->max); + XMoveWindow(obt_display, self->max, self->max_x, ob_rr_theme->paddingy + 1); } else - XUnmapWindow(ob_display, self->max); + XUnmapWindow(obt_display, self->max); if (self->close_on) { - XMapWindow(ob_display, self->close); - XMoveWindow(ob_display, self->close, self->close_x, + XMapWindow(obt_display, self->close); + XMoveWindow(obt_display, self->close, self->close_x, ob_rr_theme->paddingy + 1); } else - XUnmapWindow(ob_display, self->close); + XUnmapWindow(obt_display, self->close); if (self->label_on) { self->label_width = MAX(1, self->label_width); /* no lower than 1 */ - XMapWindow(ob_display, self->label); - XMoveWindow(ob_display, self->label, self->label_x, + XMapWindow(obt_display, self->label); + XMoveWindow(obt_display, self->label, self->label_x, ob_rr_theme->paddingy); } else - XUnmapWindow(ob_display, self->label); + XUnmapWindow(obt_display, self->label); } ObFrameContext frame_context_from_string(const gchar *name) @@ -1341,7 +1337,7 @@ ObFrameContext frame_context(ObClient *client, Window win, gint x, gint y) if (moveresize_in_progress) return OB_FRAME_CONTEXT_MOVE_RESIZE; - if (win == RootWindow(ob_display, ob_screen)) + if (win == obt_root(ob_screen)) return OB_FRAME_CONTEXT_ROOT ; if (client == NULL) return OB_FRAME_CONTEXT_NONE; if (win == client->window) { @@ -1634,12 +1630,12 @@ void frame_flash_start(ObFrame *self) self->flash_on = self->focused; if (!self->flashing) - ob_main_loop_timeout_add(ob_main_loop, - G_USEC_PER_SEC * 0.6, - flash_timeout, - self, - g_direct_equal, - flash_done); + obt_main_loop_timeout_add(ob_main_loop, + G_USEC_PER_SEC * 0.6, + flash_timeout, + self, + g_direct_equal, + flash_done); g_get_current_time(&self->flash_end); g_time_val_add(&self->flash_end, G_USEC_PER_SEC * 5); @@ -1725,8 +1721,8 @@ static gboolean frame_animate_iconify(gpointer p) h = self->size.top; /* just the titlebar */ } - XMoveResizeWindow(ob_display, self->window, x, y, w, h); - XFlush(ob_display); + XMoveResizeWindow(obt_display, self->window, x, y, w, h); + XFlush(obt_display); if (time == 0) frame_end_iconify_animation(self); @@ -1740,7 +1736,7 @@ void frame_end_iconify_animation(ObFrame *self) if (self->iconify_animation_going == 0) return; if (!self->visible) - XUnmapWindow(ob_display, self->window); + XUnmapWindow(obt_display, self->window); else { /* Send a ConfigureNotify when the animation is done, this fixes KDE's pager showing the window in the wrong place. since the @@ -1753,12 +1749,12 @@ void frame_end_iconify_animation(ObFrame *self) /* we're not animating any more ! */ self->iconify_animation_going = 0; - XMoveResizeWindow(ob_display, self->window, + XMoveResizeWindow(obt_display, self->window, self->area.x, self->area.y, self->area.width, self->area.height); /* we delay re-rendering until after we're done animating */ framerender_frame(self); - XFlush(ob_display); + XFlush(obt_display); } void frame_begin_iconify_animation(ObFrame *self, gboolean iconifying) @@ -1797,18 +1793,18 @@ void frame_begin_iconify_animation(ObFrame *self, gboolean iconifying) } if (new_anim) { - ob_main_loop_timeout_remove_data(ob_main_loop, frame_animate_iconify, - self, FALSE); - ob_main_loop_timeout_add(ob_main_loop, - FRAME_ANIMATE_ICONIFY_STEP_TIME, - frame_animate_iconify, self, - g_direct_equal, NULL); + obt_main_loop_timeout_remove_data(ob_main_loop, frame_animate_iconify, + self, FALSE); + obt_main_loop_timeout_add(ob_main_loop, + FRAME_ANIMATE_ICONIFY_STEP_TIME, + frame_animate_iconify, self, + g_direct_equal, NULL); /* do the first step */ frame_animate_iconify(self); /* show it during the animation even if it is not "visible" */ if (!self->visible) - XMapWindow(ob_display, self->window); + XMapWindow(obt_display, self->window); } } diff --git a/openbox/framerender.c b/openbox/framerender.c index 4720d76..bf71d2c 100644 --- a/openbox/framerender.c +++ b/openbox/framerender.c @@ -49,67 +49,67 @@ void framerender_frame(ObFrame *self) RrColorPixel(ob_rr_theme->cb_focused_color) : RrColorPixel(ob_rr_theme->cb_unfocused_color)); - XSetWindowBackground(ob_display, self->backback, px); - XClearWindow(ob_display, self->backback); - XSetWindowBackground(ob_display, self->innerleft, px); - XClearWindow(ob_display, self->innerleft); - XSetWindowBackground(ob_display, self->innertop, px); - XClearWindow(ob_display, self->innertop); - XSetWindowBackground(ob_display, self->innerright, px); - XClearWindow(ob_display, self->innerright); - XSetWindowBackground(ob_display, self->innerbottom, px); - XClearWindow(ob_display, self->innerbottom); - XSetWindowBackground(ob_display, self->innerbll, px); - XClearWindow(ob_display, self->innerbll); - XSetWindowBackground(ob_display, self->innerbrr, px); - XClearWindow(ob_display, self->innerbrr); - XSetWindowBackground(ob_display, self->innerblb, px); - XClearWindow(ob_display, self->innerblb); - XSetWindowBackground(ob_display, self->innerbrb, px); - XClearWindow(ob_display, self->innerbrb); + XSetWindowBackground(obt_display, self->backback, px); + XClearWindow(obt_display, self->backback); + XSetWindowBackground(obt_display, self->innerleft, px); + XClearWindow(obt_display, self->innerleft); + XSetWindowBackground(obt_display, self->innertop, px); + XClearWindow(obt_display, self->innertop); + XSetWindowBackground(obt_display, self->innerright, px); + XClearWindow(obt_display, self->innerright); + XSetWindowBackground(obt_display, self->innerbottom, px); + XClearWindow(obt_display, self->innerbottom); + XSetWindowBackground(obt_display, self->innerbll, px); + XClearWindow(obt_display, self->innerbll); + XSetWindowBackground(obt_display, self->innerbrr, px); + XClearWindow(obt_display, self->innerbrr); + XSetWindowBackground(obt_display, self->innerblb, px); + XClearWindow(obt_display, self->innerblb); + XSetWindowBackground(obt_display, self->innerbrb, px); + XClearWindow(obt_display, self->innerbrb); px = (self->focused ? RrColorPixel(ob_rr_theme->frame_focused_border_color) : RrColorPixel(ob_rr_theme->frame_unfocused_border_color)); - XSetWindowBackground(ob_display, self->left, px); - XClearWindow(ob_display, self->left); - XSetWindowBackground(ob_display, self->right, px); - XClearWindow(ob_display, self->right); - - XSetWindowBackground(ob_display, self->titleleft, px); - XClearWindow(ob_display, self->titleleft); - XSetWindowBackground(ob_display, self->titletop, px); - XClearWindow(ob_display, self->titletop); - XSetWindowBackground(ob_display, self->titletopleft, px); - XClearWindow(ob_display, self->titletopleft); - XSetWindowBackground(ob_display, self->titletopright, px); - XClearWindow(ob_display, self->titletopright); - XSetWindowBackground(ob_display, self->titleright, px); - XClearWindow(ob_display, self->titleright); - - XSetWindowBackground(ob_display, self->handleleft, px); - XClearWindow(ob_display, self->handleleft); - XSetWindowBackground(ob_display, self->handletop, px); - XClearWindow(ob_display, self->handletop); - XSetWindowBackground(ob_display, self->handleright, px); - XClearWindow(ob_display, self->handleright); - XSetWindowBackground(ob_display, self->handlebottom, px); - XClearWindow(ob_display, self->handlebottom); - - XSetWindowBackground(ob_display, self->lgripleft, px); - XClearWindow(ob_display, self->lgripleft); - XSetWindowBackground(ob_display, self->lgriptop, px); - XClearWindow(ob_display, self->lgriptop); - XSetWindowBackground(ob_display, self->lgripbottom, px); - XClearWindow(ob_display, self->lgripbottom); - - XSetWindowBackground(ob_display, self->rgripright, px); - XClearWindow(ob_display, self->rgripright); - XSetWindowBackground(ob_display, self->rgriptop, px); - XClearWindow(ob_display, self->rgriptop); - XSetWindowBackground(ob_display, self->rgripbottom, px); - XClearWindow(ob_display, self->rgripbottom); + XSetWindowBackground(obt_display, self->left, px); + XClearWindow(obt_display, self->left); + XSetWindowBackground(obt_display, self->right, px); + XClearWindow(obt_display, self->right); + + XSetWindowBackground(obt_display, self->titleleft, px); + XClearWindow(obt_display, self->titleleft); + XSetWindowBackground(obt_display, self->titletop, px); + XClearWindow(obt_display, self->titletop); + XSetWindowBackground(obt_display, self->titletopleft, px); + XClearWindow(obt_display, self->titletopleft); + XSetWindowBackground(obt_display, self->titletopright, px); + XClearWindow(obt_display, self->titletopright); + XSetWindowBackground(obt_display, self->titleright, px); + XClearWindow(obt_display, self->titleright); + + XSetWindowBackground(obt_display, self->handleleft, px); + XClearWindow(obt_display, self->handleleft); + XSetWindowBackground(obt_display, self->handletop, px); + XClearWindow(obt_display, self->handletop); + XSetWindowBackground(obt_display, self->handleright, px); + XClearWindow(obt_display, self->handleright); + XSetWindowBackground(obt_display, self->handlebottom, px); + XClearWindow(obt_display, self->handlebottom); + + XSetWindowBackground(obt_display, self->lgripleft, px); + XClearWindow(obt_display, self->lgripleft); + XSetWindowBackground(obt_display, self->lgriptop, px); + XClearWindow(obt_display, self->lgriptop); + XSetWindowBackground(obt_display, self->lgripbottom, px); + XClearWindow(obt_display, self->lgripbottom); + + XSetWindowBackground(obt_display, self->rgripright, px); + XClearWindow(obt_display, self->rgripright); + XSetWindowBackground(obt_display, self->rgriptop, px); + XClearWindow(obt_display, self->rgriptop); + XSetWindowBackground(obt_display, self->rgripbottom, px); + XClearWindow(obt_display, self->rgripbottom); /* don't use the separator color for shaded windows */ if (!self->client->shaded) @@ -117,8 +117,8 @@ void framerender_frame(ObFrame *self) RrColorPixel(ob_rr_theme->title_separator_focused_color) : RrColorPixel(ob_rr_theme->title_separator_unfocused_color)); - XSetWindowBackground(ob_display, self->titlebottom, px); - XClearWindow(ob_display, self->titlebottom); + XSetWindowBackground(obt_display, self->titlebottom, px); + XClearWindow(obt_display, self->titlebottom); } if (self->decorations & OB_FRAME_DECOR_TITLEBAR) { @@ -341,7 +341,7 @@ void framerender_frame(ObFrame *self) } } - XFlush(ob_display); + XFlush(obt_display); } static void framerender_label(ObFrame *self, RrAppearance *a) diff --git a/openbox/grab.c b/openbox/grab.c index 214666e..e797e44 100644 --- a/openbox/grab.c +++ b/openbox/grab.c @@ -18,12 +18,12 @@ */ #include "grab.h" -#include "modkeys.h" #include "openbox.h" #include "event.h" -#include "xerror.h" #include "screen.h" #include "debug.h" +#include "obt/display.h" +#include "obt/keyboard.h" #include #include @@ -74,7 +74,7 @@ gboolean grab_keyboard_full(gboolean grab) if (grab) { if (kgrabs++ == 0) { - ret = XGrabKeyboard(ob_display, RootWindow(ob_display, ob_screen), + ret = XGrabKeyboard(obt_display, obt_root(ob_screen), False, GrabModeAsync, GrabModeAsync, event_curtime) == Success; if (!ret) @@ -87,7 +87,7 @@ gboolean grab_keyboard_full(gboolean grab) ret = TRUE; } else if (kgrabs > 0) { if (--kgrabs == 0) { - XUngrabKeyboard(ob_display, ungrab_time()); + XUngrabKeyboard(obt_display, ungrab_time()); } ret = TRUE; } @@ -102,11 +102,10 @@ gboolean grab_pointer_full(gboolean grab, gboolean owner_events, if (grab) { if (pgrabs++ == 0) { - ret = XGrabPointer(ob_display, screen_support_win, owner_events, + ret = XGrabPointer(obt_display, screen_support_win, owner_events, GRAB_PTR_MASK, GrabModeAsync, GrabModeAsync, - (confine ? RootWindow(ob_display, ob_screen) : - None), + (confine ? obt_root(ob_screen) : None), ob_cursor(cur), event_curtime) == Success; if (!ret) --pgrabs; @@ -116,7 +115,7 @@ gboolean grab_pointer_full(gboolean grab, gboolean owner_events, ret = TRUE; } else if (pgrabs > 0) { if (--pgrabs == 0) { - XUngrabPointer(ob_display, ungrab_time()); + XUngrabPointer(obt_display, ungrab_time()); } ret = TRUE; } @@ -128,13 +127,13 @@ gint grab_server(gboolean grab) static guint sgrabs = 0; if (grab) { if (sgrabs++ == 0) { - XGrabServer(ob_display); - XSync(ob_display, FALSE); + XGrabServer(obt_display); + XSync(obt_display, FALSE); } } else if (sgrabs > 0) { if (--sgrabs == 0) { - XUngrabServer(ob_display); - XFlush(ob_display); + XUngrabServer(obt_display); + XFlush(obt_display); } } return sgrabs; @@ -145,9 +144,9 @@ void grab_startup(gboolean reconfig) guint i = 0; guint num, caps, scroll; - num = modkeys_key_to_mask(OB_MODKEY_KEY_NUMLOCK); - caps = modkeys_key_to_mask(OB_MODKEY_KEY_CAPSLOCK); - scroll = modkeys_key_to_mask(OB_MODKEY_KEY_SCROLLLOCK); + num = obt_keyboard_modkey_to_modmask(OBT_KEYBOARD_MODKEY_NUMLOCK); + caps = obt_keyboard_modkey_to_modmask(OBT_KEYBOARD_MODKEY_CAPSLOCK); + scroll = obt_keyboard_modkey_to_modmask(OBT_KEYBOARD_MODKEY_SCROLLLOCK); mask_list[i++] = 0; mask_list[i++] = num; @@ -174,13 +173,13 @@ void grab_button_full(guint button, guint state, Window win, guint mask, { guint i; - xerror_set_ignore(TRUE); /* can get BadAccess from these */ - xerror_occured = FALSE; + /* can get BadAccess from these */ + obt_display_ignore_errors(TRUE); for (i = 0; i < MASK_LIST_SIZE; ++i) - XGrabButton(ob_display, button, state | mask_list[i], win, False, mask, - pointer_mode, GrabModeAsync, None, ob_cursor(cur)); - xerror_set_ignore(FALSE); - if (xerror_occured) + XGrabButton(obt_display, button, state | mask_list[i], win, False, + mask, pointer_mode, GrabModeAsync, None, ob_cursor(cur)); + obt_display_ignore_errors(FALSE); + if (obt_display_error_occured) ob_debug("Failed to grab button %d modifiers %d", button, state); } @@ -189,26 +188,26 @@ void ungrab_button(guint button, guint state, Window win) guint i; for (i = 0; i < MASK_LIST_SIZE; ++i) - XUngrabButton(ob_display, button, state | mask_list[i], win); + XUngrabButton(obt_display, button, state | mask_list[i], win); } void grab_key(guint keycode, guint state, Window win, gint keyboard_mode) { guint i; - xerror_set_ignore(TRUE); /* can get BadAccess' from these */ - xerror_occured = FALSE; + /* can get BadAccess' from these */ + obt_display_ignore_errors(TRUE); for (i = 0; i < MASK_LIST_SIZE; ++i) - XGrabKey(ob_display, keycode, state | mask_list[i], win, FALSE, + XGrabKey(obt_display, keycode, state | mask_list[i], win, FALSE, GrabModeAsync, keyboard_mode); - xerror_set_ignore(FALSE); - if (xerror_occured) + obt_display_ignore_errors(FALSE); + if (obt_display_error_occured) ob_debug("Failed to grab keycode %d modifiers %d", keycode, state); } void ungrab_all_keys(Window win) { - XUngrabKey(ob_display, AnyKey, AnyModifier, win); + XUngrabKey(obt_display, AnyKey, AnyModifier, win); } void grab_key_passive_count(int change) @@ -223,7 +222,7 @@ void ungrab_passive_key(void) /*ob_debug("ungrabbing %d passive grabs\n", passive_count);*/ if (passive_count) { /* kill our passive grab */ - XUngrabKeyboard(ob_display, event_curtime); + XUngrabKeyboard(obt_display, event_curtime); passive_count = 0; } } diff --git a/openbox/grab.h b/openbox/grab.h index 30c4b70..8253637 100644 --- a/openbox/grab.h +++ b/openbox/grab.h @@ -38,8 +38,8 @@ gint grab_server(gboolean grab); #define grab_pointer(o,c,u) grab_pointer_full(TRUE, (o), (c), (u)) #define ungrab_pointer() grab_pointer_full(FALSE, FALSE, FALSE, OB_CURSOR_NONE) -gboolean grab_on_keyboard(); -gboolean grab_on_pointer(); +gboolean grab_on_keyboard(void); +gboolean grab_on_pointer(void); void grab_button_full(guint button, guint state, Window win, guint mask, gint pointer_mode, ObCursor cursor); @@ -50,6 +50,6 @@ void grab_key(guint keycode, guint state, Window win, gint keyboard_mode); void ungrab_all_keys(Window win); void grab_key_passive_count(int change); -void ungrab_passive_key(); +void ungrab_passive_key(void); #endif diff --git a/openbox/hooks.c b/openbox/hooks.c new file mode 100644 index 0000000..ad57fdb --- /dev/null +++ b/openbox/hooks.c @@ -0,0 +1,118 @@ +#include "hooks.h" +#include "actions.h" +#include "client.h" +#include "focus.h" +#include "debug.h" +#include "obt/display.h" + +#include + +static GSList *hooks[OB_NUM_HOOKS]; +static const gchar *names[OB_NUM_HOOKS]; + +typedef struct { + ObHook hook; + struct _ObClient *client; +} ObHookQueue; + +#define QUEUE_SIZE 20 +ObHookQueue run_queue[QUEUE_SIZE]; +gint queue_size; + +void hooks_startup(gboolean reconfig) +{ + gint i; + + for (i = 0; i < OB_NUM_HOOKS; ++i) + hooks[i] = NULL; + + queue_size = 0; + + names[OB_HOOK_WIN_NEW] = "WindowNew"; + names[OB_HOOK_WIN_CLOSE] = "WindowClosed"; + names[OB_HOOK_WIN_VISIBLE] = "WindowVisible"; + names[OB_HOOK_WIN_INVISIBLE] = "WindowInvisible"; + names[OB_HOOK_WIN_ICONIC] = "WindowIconified"; + names[OB_HOOK_WIN_UNICONIC] = "WindowUniconified"; + names[OB_HOOK_WIN_MAX] = "WindowMaximized"; + names[OB_HOOK_WIN_UNMAX] = "WindowUnmaximized"; + names[OB_HOOK_WIN_SHADE] = "WindowShaded"; + names[OB_HOOK_WIN_UNSHADE] = "WindowUnshaded"; + names[OB_HOOK_WIN_FOCUS] = "WindowFocused"; + names[OB_HOOK_WIN_UNFOCUS] = "WindowUnfocused"; + names[OB_HOOK_WIN_DESK_CHANGE] = "WindowOnNewDesktop"; + names[OB_HOOK_WIN_DECORATED] = "WindowDecorated"; + names[OB_HOOK_WIN_UNDECORATED] = "WindowUndecorated"; + names[OB_HOOK_SCREEN_DESK_CHANGE] = "DesktopChanged"; +} + +void hooks_shutdown(gboolean reconfig) +{ + gint i; + + for (i = 0; i < OB_NUM_HOOKS; ++i) + while (hooks[i]) { + actions_act_unref(hooks[i]->data); + hooks[i] = g_slist_delete_link(hooks[i], hooks[i]); + } +} + +ObHook hooks_hook_from_name(const gchar *n) +{ + gint i; + + for (i = 1; i < OB_NUM_HOOKS; ++i) + if (!g_ascii_strcasecmp(n, names[i])) + return (ObHook)i; + return OB_HOOK_INVALID; +} + +void hooks_queue(ObHook hook, struct _ObClient *client) +{ + ObHookQueue *q; + + g_assert(hook < OB_NUM_HOOKS && hook > OB_HOOK_INVALID); + + ob_debug("Queing hook %s for client 0x%x", names[hook], + (client ? client->window : 0)); + q = &run_queue[queue_size++]; + q->hook = hook; + q->client = client; + + if (queue_size == QUEUE_SIZE) + /* queue is full */ + hooks_run_queue(); +} + +void hooks_run(ObHook hook, struct _ObClient *c) +{ + hooks_queue(hook, c); + hooks_run_queue(); +} + +void hooks_add(ObHook hook, struct _ObActionsAct *act) +{ + g_assert(hook < OB_NUM_HOOKS && hook > OB_HOOK_INVALID); + + /* append so they are executed in the same order as they appear in the + config file */ + hooks[hook] = g_slist_append(hooks[hook], act); +} + +void hooks_run_queue(void) +{ + gint i; + + for (i = 0; i < queue_size; ++i) { + const ObHookQueue *q = &run_queue[i]; + + ob_debug("Running hook %s for client 0x%x", names[q->hook], + (q->client ? q->client->window : 0)); + actions_run_acts(hooks[q->hook], + OB_USER_ACTION_HOOK, + 0, -1, -1, 0, + OB_FRAME_CONTEXT_NONE, + q->client); + } + queue_size = 0; +} diff --git a/openbox/hooks.h b/openbox/hooks.h new file mode 100644 index 0000000..322f952 --- /dev/null +++ b/openbox/hooks.h @@ -0,0 +1,42 @@ +#ifndef ob__hooks_h +#define ob__hooks_h + +#include + +struct _ObActionsAct; +struct _ObClient; + +typedef enum { + OB_HOOK_INVALID, + OB_HOOK_WIN_NEW, + OB_HOOK_WIN_CLOSE, + OB_HOOK_WIN_VISIBLE, + OB_HOOK_WIN_INVISIBLE, + OB_HOOK_WIN_ICONIC, + OB_HOOK_WIN_UNICONIC, + OB_HOOK_WIN_MAX, + OB_HOOK_WIN_UNMAX, + OB_HOOK_WIN_SHADE, + OB_HOOK_WIN_UNSHADE, + OB_HOOK_WIN_FOCUS, + OB_HOOK_WIN_UNFOCUS, + OB_HOOK_WIN_DESK_CHANGE, + OB_HOOK_WIN_DECORATED, + OB_HOOK_WIN_UNDECORATED, + OB_HOOK_SCREEN_DESK_CHANGE, + OB_NUM_HOOKS +} ObHook; + +void hooks_startup(gboolean reconfig); +void hooks_shutdown(gboolean reconfig); + +ObHook hooks_hook_from_name(const gchar *n); + +void hooks_queue(ObHook hook, struct _ObClient *c); +void hooks_run(ObHook hook, struct _ObClient *c); + +void hooks_add(ObHook hook, struct _ObActionsAct *act); + +void hooks_run_queue(void); + +#endif diff --git a/openbox/keyboard.c b/openbox/keyboard.c index c318a4c..5ac4236 100644 --- a/openbox/keyboard.c +++ b/openbox/keyboard.c @@ -17,7 +17,6 @@ See the COPYING file for a copy of the GNU General Public License. */ -#include "mainloop.h" #include "focus.h" #include "screen.h" #include "frame.h" @@ -26,7 +25,6 @@ #include "grab.h" #include "client.h" #include "actions.h" -#include "prop.h" #include "menuframe.h" #include "config.h" #include "keytree.h" @@ -46,20 +44,20 @@ static void grab_keys(gboolean grab) { KeyBindingTree *p; - ungrab_all_keys(RootWindow(ob_display, ob_screen)); + ungrab_all_keys(obt_root(ob_screen)); if (grab) { p = curpos ? curpos->first_child : keyboard_firstnode; while (p) { if (p->key) - grab_key(p->key, p->state, RootWindow(ob_display, ob_screen), + grab_key(p->key, p->state, obt_root(ob_screen), GrabModeSync); p = p->next_sibling; } if (curpos) grab_key(config_keyboard_reset_keycode, config_keyboard_reset_state, - RootWindow(ob_display, ob_screen), GrabModeSync); + obt_root(ob_screen), GrabModeSync); } } @@ -221,7 +219,7 @@ void keyboard_event(ObClient *client, const XEvent *e) if (e->xkey.keycode == config_keyboard_reset_keycode && e->xkey.state == config_keyboard_reset_state) { - ob_main_loop_timeout_remove(ob_main_loop, chain_timeout); + obt_main_loop_timeout_remove(ob_main_loop, chain_timeout); keyboard_reset_chains(-1); return; } @@ -239,11 +237,11 @@ void keyboard_event(ObClient *client, const XEvent *e) menu_frame_hide_all(); if (p->first_child != NULL) { /* part of a chain */ - ob_main_loop_timeout_remove(ob_main_loop, chain_timeout); + obt_main_loop_timeout_remove(ob_main_loop, chain_timeout); /* 3 second timeout for chains */ - ob_main_loop_timeout_add(ob_main_loop, 3 * G_USEC_PER_SEC, - chain_timeout, NULL, - g_direct_equal, NULL); + obt_main_loop_timeout_add(ob_main_loop, 3 * G_USEC_PER_SEC, + chain_timeout, NULL, + g_direct_equal, NULL); set_curpos(p); } else if (p->chroot) /* an empty chroot */ set_curpos(p); @@ -264,7 +262,7 @@ void keyboard_event(ObClient *client, const XEvent *e) p = p->next_sibling; } - XAllowEvents(ob_display, AsyncKeyboard, event_curtime); + XAllowEvents(obt_display, AsyncKeyboard, event_curtime); } static void node_rebind(KeyBindingTree *node) @@ -318,7 +316,7 @@ void keyboard_startup(gboolean reconfig) void keyboard_shutdown(gboolean reconfig) { - ob_main_loop_timeout_remove(ob_main_loop, chain_timeout); + obt_main_loop_timeout_remove(ob_main_loop, chain_timeout); keyboard_unbind_all(); set_curpos(NULL); diff --git a/openbox/keyboard.h b/openbox/keyboard.h index 995cdbc..1674cf9 100644 --- a/openbox/keyboard.h +++ b/openbox/keyboard.h @@ -34,11 +34,11 @@ extern KeyBindingTree *keyboard_firstnode; void keyboard_startup(gboolean reconfig); void keyboard_shutdown(gboolean reconfig); -void keyboard_rebind(); +void keyboard_rebind(void); void keyboard_chroot(GList *keylist); gboolean keyboard_bind(GList *keylist, struct _ObActionsAct *action); -void keyboard_unbind_all(); +void keyboard_unbind_all(void); void keyboard_event(struct _ObClient *client, const XEvent *e); /*! @param break_chroots how many chroots to break. -1 means to break them ALL! diff --git a/openbox/mainloop.h b/openbox/mainloop.h deleted file mode 100644 index 373528e..0000000 --- a/openbox/mainloop.h +++ /dev/null @@ -1,76 +0,0 @@ -/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- - - mainloop.h for the Openbox window manager - Copyright (c) 2006 Mikael Magnusson - Copyright (c) 2003-2007 Dana Jansens - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - See the COPYING file for a copy of the GNU General Public License. -*/ - -#ifndef __ob__mainloop_h -#define __ob__mainloop_h - -#include -#include - -typedef struct _ObMainLoop ObMainLoop; - -ObMainLoop *ob_main_loop_new(Display *display); -void ob_main_loop_destroy(ObMainLoop *loop); - -typedef void (*ObMainLoopXHandler) (const XEvent *e, gpointer data); - -void ob_main_loop_x_add(ObMainLoop *loop, - ObMainLoopXHandler handler, - gpointer data, - GDestroyNotify notify); -void ob_main_loop_x_remove(ObMainLoop *loop, - ObMainLoopXHandler handler); - -typedef void (*ObMainLoopFdHandler) (gint fd, gpointer data); - -void ob_main_loop_fd_add(ObMainLoop *loop, - gint fd, - ObMainLoopFdHandler handler, - gpointer data, - GDestroyNotify notify); -void ob_main_loop_fd_remove(ObMainLoop *loop, - gint fd); - -typedef void (*ObMainLoopSignalHandler) (gint signal, gpointer data); - -void ob_main_loop_signal_add(ObMainLoop *loop, - gint signal, - ObMainLoopSignalHandler handler, - gpointer data, - GDestroyNotify notify); -void ob_main_loop_signal_remove(ObMainLoop *loop, - ObMainLoopSignalHandler handler); - -void ob_main_loop_timeout_add(ObMainLoop *loop, - gulong microseconds, - GSourceFunc handler, - gpointer data, - GEqualFunc cmp, - GDestroyNotify notify); -void ob_main_loop_timeout_remove(ObMainLoop *loop, - GSourceFunc handler); -void ob_main_loop_timeout_remove_data(ObMainLoop *loop, - GSourceFunc handler, - gpointer data, - gboolean cancel_dest); - -void ob_main_loop_run(ObMainLoop *loop); -void ob_main_loop_exit(ObMainLoop *loop); - -#endif diff --git a/openbox/menu.c b/openbox/menu.c index 0c10b75..432aa2b 100644 --- a/openbox/menu.c +++ b/openbox/menu.c @@ -20,7 +20,6 @@ #include "debug.h" #include "menu.h" #include "openbox.h" -#include "mainloop.h" #include "stacking.h" #include "grab.h" #include "client.h" @@ -35,7 +34,8 @@ #include "client_list_menu.h" #include "client_list_combined_menu.h" #include "gettext.h" -#include "parser/parse.h" +#include "obt/parse.h" +#include "obt/paths.h" typedef struct _ObMenuParseState ObMenuParseState; @@ -46,18 +46,14 @@ struct _ObMenuParseState }; static GHashTable *menu_hash = NULL; -static ObParseInst *menu_parse_inst; +static ObtParseInst *menu_parse_inst; static ObMenuParseState menu_parse_state; static gboolean menu_can_hide = FALSE; static void menu_destroy_hash_value(ObMenu *self); -static void parse_menu_item(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, - gpointer data); -static void parse_menu_separator(ObParseInst *i, - xmlDocPtr doc, xmlNodePtr node, - gpointer data); -static void parse_menu(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, - gpointer data); +static void parse_menu_item(xmlNodePtr node, gpointer data); +static void parse_menu_separator(xmlNodePtr node, gpointer data); +static void parse_menu(xmlNodePtr node, gpointer data); static gunichar parse_shortcut(const gchar *label, gboolean allow_shortcut, gchar **strippedlabel, guint *position, gboolean *always_show); @@ -72,8 +68,6 @@ static void client_dest(ObClient *client, gpointer data) void menu_startup(gboolean reconfig) { - xmlDocPtr doc; - xmlNodePtr node; gboolean loaded = FALSE; GSList *it; @@ -84,29 +78,37 @@ void menu_startup(gboolean reconfig) client_list_combined_menu_startup(reconfig); client_menu_startup(); - menu_parse_inst = parse_startup(); + menu_parse_inst = obt_parse_instance_new(); menu_parse_state.parent = NULL; menu_parse_state.pipe_creator = NULL; - parse_register(menu_parse_inst, "menu", parse_menu, &menu_parse_state); - parse_register(menu_parse_inst, "item", parse_menu_item, - &menu_parse_state); - parse_register(menu_parse_inst, "separator", - parse_menu_separator, &menu_parse_state); + obt_parse_register(menu_parse_inst, "menu", parse_menu, &menu_parse_state); + obt_parse_register(menu_parse_inst, "item", parse_menu_item, + &menu_parse_state); + obt_parse_register(menu_parse_inst, "separator", + parse_menu_separator, &menu_parse_state); for (it = config_menu_files; it; it = g_slist_next(it)) { - if (parse_load_menu(it->data, &doc, &node)) { + if (obt_parse_load_config_file(menu_parse_inst, + "openbox", + it->data, + "openbox_menu")) + { loaded = TRUE; - parse_tree(menu_parse_inst, doc, node->children); - xmlFreeDoc(doc); + obt_parse_tree_from_root(menu_parse_inst); + obt_parse_close(menu_parse_inst); } else g_message(_("Unable to find a valid menu file \"%s\""), (const gchar*)it->data); } if (!loaded) { - if (parse_load_menu("menu.xml", &doc, &node)) { - parse_tree(menu_parse_inst, doc, node->children); - xmlFreeDoc(doc); + if (obt_parse_load_config_file(menu_parse_inst, + "openbox", + "menu.xml", + "openbox_menu")) + { + obt_parse_tree_from_root(menu_parse_inst); + obt_parse_close(menu_parse_inst); } else g_message(_("Unable to find a valid menu file \"%s\""), "menu.xml"); @@ -123,7 +125,7 @@ void menu_shutdown(gboolean reconfig) if (!reconfig) client_remove_destroy_notify(client_dest); - parse_shutdown(menu_parse_inst); + obt_parse_instance_unref(menu_parse_inst); menu_parse_inst = NULL; client_list_menu_shutdown(reconfig); @@ -157,8 +159,6 @@ void menu_clear_pipe_caches(void) void menu_pipe_execute(ObMenu *self) { - xmlDocPtr doc; - xmlNodePtr node; gchar *output; GError *err = NULL; @@ -174,13 +174,13 @@ void menu_pipe_execute(ObMenu *self) return; } - if (parse_load_mem(output, strlen(output), - "openbox_pipe_menu", &doc, &node)) + if (obt_parse_load_mem(menu_parse_inst, output, strlen(output), + "openbox_pipe_menu")) { menu_parse_state.pipe_creator = self; menu_parse_state.parent = self; - parse_tree(menu_parse_inst, doc, node->children); - xmlFreeDoc(doc); + obt_parse_tree_from_root(menu_parse_inst); + obt_parse_close(menu_parse_inst); } else { g_message(_("Invalid output from pipe-menu \"%s\""), self->execute); } @@ -263,19 +263,18 @@ static gunichar parse_shortcut(const gchar *label, gboolean allow_shortcut, return shortcut; } -static void parse_menu_item(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, - gpointer data) +static void parse_menu_item(xmlNodePtr node, gpointer data) { ObMenuParseState *state = data; gchar *label; if (state->parent) { - if (parse_attr_string("label", node, &label)) { + if (obt_parse_attr_string(node, "label", &label)) { GSList *acts = NULL; for (node = node->children; node; node = node->next) if (!xmlStrcasecmp(node->name, (const xmlChar*) "action")) { - ObActionsAct *a = actions_parse(i, doc, node); + ObActionsAct *a = actions_parse(node); if (a) acts = g_slist_append(acts, a); } @@ -285,16 +284,14 @@ static void parse_menu_item(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, } } -static void parse_menu_separator(ObParseInst *i, - xmlDocPtr doc, xmlNodePtr node, - gpointer data) +static void parse_menu_separator(xmlNodePtr node, gpointer data) { ObMenuParseState *state = data; if (state->parent) { gchar *label; - if (!parse_attr_string("label", node, &label)) + if (!obt_parse_attr_string(node, "label", &label)) label = NULL; menu_add_separator(state->parent, -1, label); @@ -302,30 +299,29 @@ static void parse_menu_separator(ObParseInst *i, } } -static void parse_menu(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, - gpointer data) +static void parse_menu(xmlNodePtr node, gpointer data) { ObMenuParseState *state = data; gchar *name = NULL, *title = NULL, *script = NULL; ObMenu *menu; - if (!parse_attr_string("id", node, &name)) + if (!obt_parse_attr_string(node, "id", &name)) goto parse_menu_fail; if (!g_hash_table_lookup(menu_hash, name)) { - if (!parse_attr_string("label", node, &title)) + if (!obt_parse_attr_string(node, "label", &title)) goto parse_menu_fail; if ((menu = menu_new(name, title, TRUE, NULL))) { menu->pipe_creator = state->pipe_creator; - if (parse_attr_string("execute", node, &script)) { - menu->execute = parse_expand_tilde(script); + if (obt_parse_attr_string(node, "execute", &script)) { + menu->execute = obt_paths_expand_tilde(script); } else { ObMenu *old; old = state->parent; state->parent = menu; - parse_tree(i, doc, node->children); + obt_parse_tree(menu_parse_inst, node->children); state->parent = old; } } @@ -457,10 +453,10 @@ void menu_show(gchar *name, gint x, gint y, gboolean mouse, ObClient *client) menu_can_hide = TRUE; else { menu_can_hide = FALSE; - ob_main_loop_timeout_add(ob_main_loop, - config_menu_hide_delay * 1000, - menu_hide_delay_func, - NULL, g_direct_equal, NULL); + obt_main_loop_timeout_add(ob_main_loop, + config_menu_hide_delay * 1000, + menu_hide_delay_func, + NULL, g_direct_equal, NULL); } } } diff --git a/openbox/menu.h b/openbox/menu.h index 7e11545..43efd41 100644 --- a/openbox/menu.h +++ b/openbox/menu.h @@ -22,7 +22,6 @@ #include "window.h" #include "geom.h" #include "render/render.h" -#include "parser/parse.h" #include @@ -169,13 +168,13 @@ void menu_free(ObMenu *menu); /*! Repopulate a pipe-menu by running its command */ void menu_pipe_execute(ObMenu *self); /*! Clear a pipe-menu's entries */ -void menu_clear_pipe_caches(); +void menu_clear_pipe_caches(void); void menu_show_all_shortcuts(ObMenu *self, gboolean show); void menu_show(gchar *name, gint x, gint y, gboolean mouse, struct _ObClient *client); -gboolean menu_hide_delay_reached(); +gboolean menu_hide_delay_reached(void); void menu_set_show_func(ObMenu *menu, ObMenuShowFunc func); void menu_set_hide_func(ObMenu *menu, ObMenuHideFunc func); diff --git a/openbox/menuframe.c b/openbox/menuframe.c index ac1d88d..7b4c872 100644 --- a/openbox/menuframe.c +++ b/openbox/menuframe.c @@ -21,12 +21,11 @@ #include "client.h" #include "menu.h" #include "screen.h" -#include "prop.h" #include "actions.h" #include "grab.h" #include "openbox.h" -#include "mainloop.h" #include "config.h" +#include "obt/prop.h" #include "render/theme.h" #define PADDING 2 @@ -54,7 +53,7 @@ static void menu_frame_hide(ObMenuFrame *self); static Window createWindow(Window parent, gulong mask, XSetWindowAttributes *attrib) { - return XCreateWindow(ob_display, parent, 0, 0, 1, 1, 0, + return XCreateWindow(obt_display, parent, 0, 0, 1, 1, 0, RrDepth(ob_rr_inst), InputOutput, RrVisual(ob_rr_inst), mask, attrib); } @@ -91,7 +90,7 @@ ObMenuFrame* menu_frame_new(ObMenu *menu, guint show_from, ObClient *client) XSetWindowAttributes attr; self = g_new0(ObMenuFrame, 1); - self->type = Window_Menu; + self->obwin.type = OB_WINDOW_CLASS_MENUFRAME; self->menu = menu; self->selected = NULL; self->client = client; @@ -99,20 +98,21 @@ ObMenuFrame* menu_frame_new(ObMenu *menu, guint show_from, ObClient *client) self->show_from = show_from; attr.event_mask = FRAME_EVENTMASK; - self->window = createWindow(RootWindow(ob_display, ob_screen), + self->window = createWindow(obt_root(ob_screen), CWEventMask, &attr); /* make it a popup menu type window */ - PROP_SET32(self->window, net_wm_window_type, atom, - prop_atoms.net_wm_window_type_popup_menu); + OBT_PROP_SET32(self->window, NET_WM_WINDOW_TYPE, ATOM, + OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_POPUP_MENU)); - XSetWindowBorderWidth(ob_display, self->window, ob_rr_theme->mbwidth); - XSetWindowBorder(ob_display, self->window, + XSetWindowBorderWidth(obt_display, self->window, ob_rr_theme->mbwidth); + XSetWindowBorder(obt_display, self->window, RrColorPixel(ob_rr_theme->menu_border_color)); self->a_items = RrAppearanceCopy(ob_rr_theme->a_menu); - stacking_add(MENU_AS_WINDOW(self)); + window_add(&self->window, MENUFRAME_AS_WINDOW(self)); + stacking_add(MENUFRAME_AS_WINDOW(self)); return self; } @@ -125,11 +125,12 @@ void menu_frame_free(ObMenuFrame *self) self->entries = g_list_delete_link(self->entries, self->entries); } - stacking_remove(MENU_AS_WINDOW(self)); + stacking_remove(MENUFRAME_AS_WINDOW(self)); + window_remove(self->window); RrAppearanceFree(self->a_items); - XDestroyWindow(ob_display, self->window); + XDestroyWindow(obt_display, self->window); g_free(self); } @@ -161,8 +162,10 @@ static ObMenuEntryFrame* menu_entry_frame_new(ObMenuEntry *entry, g_hash_table_insert(menu_frame_map, &self->bullet, self); } - XMapWindow(ob_display, self->window); - XMapWindow(ob_display, self->text); + XMapWindow(obt_display, self->window); + XMapWindow(obt_display, self->text); + + window_add(&self->window, MENUFRAME_AS_WINDOW(self->frame)); return self; } @@ -172,16 +175,18 @@ static void menu_entry_frame_free(ObMenuEntryFrame *self) if (self) { menu_entry_unref(self->entry); - XDestroyWindow(ob_display, self->text); - XDestroyWindow(ob_display, self->window); + window_remove(self->window); + + XDestroyWindow(obt_display, self->text); + XDestroyWindow(obt_display, self->window); g_hash_table_remove(menu_frame_map, &self->text); g_hash_table_remove(menu_frame_map, &self->window); if (self->entry->type == OB_MENU_ENTRY_TYPE_NORMAL) { - XDestroyWindow(ob_display, self->icon); + XDestroyWindow(obt_display, self->icon); g_hash_table_remove(menu_frame_map, &self->icon); } if (self->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU) { - XDestroyWindow(ob_display, self->bullet); + XDestroyWindow(obt_display, self->bullet); g_hash_table_remove(menu_frame_map, &self->bullet); } @@ -192,7 +197,7 @@ static void menu_entry_frame_free(ObMenuEntryFrame *self) void menu_frame_move(ObMenuFrame *self, gint x, gint y) { RECT_SET_POINT(self->area, x, y); - XMoveWindow(ob_display, self->window, self->area.x, self->area.y); + XMoveWindow(obt_display, self->window, self->area.x, self->area.y); } static void menu_frame_place_topmenu(ObMenuFrame *self, gint *x, gint *y) @@ -354,7 +359,7 @@ static void menu_entry_frame_render(ObMenuEntryFrame *self) } RECT_SET_SIZE(self->area, self->frame->inner_w, th); - XResizeWindow(ob_display, self->window, + XResizeWindow(obt_display, self->window, self->area.width, self->area.height); item_a->surface.parent = self->frame->a_items; item_a->surface.parentx = self->area.x; @@ -413,7 +418,7 @@ static void menu_entry_frame_render(ObMenuEntryFrame *self) switch (self->entry->type) { case OB_MENU_ENTRY_TYPE_NORMAL: - XMoveResizeWindow(ob_display, self->text, + XMoveResizeWindow(obt_display, self->text, self->frame->text_x, PADDING, self->frame->text_w, ITEM_HEIGHT - 2*PADDING); @@ -424,7 +429,7 @@ static void menu_entry_frame_render(ObMenuEntryFrame *self) ITEM_HEIGHT - 2*PADDING); break; case OB_MENU_ENTRY_TYPE_SUBMENU: - XMoveResizeWindow(ob_display, self->text, + XMoveResizeWindow(obt_display, self->text, self->frame->text_x, PADDING, self->frame->text_w - ITEM_HEIGHT, ITEM_HEIGHT - 2*PADDING); @@ -437,7 +442,7 @@ static void menu_entry_frame_render(ObMenuEntryFrame *self) case OB_MENU_ENTRY_TYPE_SEPARATOR: if (self->entry->data.separator.label != NULL) { /* labeled separator */ - XMoveResizeWindow(ob_display, self->text, + XMoveResizeWindow(obt_display, self->text, ob_rr_theme->paddingx, ob_rr_theme->paddingy, self->area.width - 2*ob_rr_theme->paddingx, ob_rr_theme->menu_title_height - @@ -453,7 +458,7 @@ static void menu_entry_frame_render(ObMenuEntryFrame *self) gint i; /* unlabeled separator */ - XMoveResizeWindow(ob_display, self->text, 0, 0, + XMoveResizeWindow(obt_display, self->text, 0, 0, self->area.width, ob_rr_theme->menu_sep_width + 2*ob_rr_theme->menu_sep_paddingy); @@ -484,7 +489,7 @@ static void menu_entry_frame_render(ObMenuEntryFrame *self) { RrAppearance *clear; - XMoveResizeWindow(ob_display, self->icon, + XMoveResizeWindow(obt_display, self->icon, PADDING, frame->item_margin.top, ITEM_HEIGHT - frame->item_margin.top - frame->item_margin.bottom, @@ -506,14 +511,14 @@ static void menu_entry_frame_render(ObMenuEntryFrame *self) - frame->item_margin.bottom, ITEM_HEIGHT - frame->item_margin.top - frame->item_margin.bottom); - XMapWindow(ob_display, self->icon); + XMapWindow(obt_display, self->icon); } else if (self->entry->type == OB_MENU_ENTRY_TYPE_NORMAL && self->entry->data.normal.mask) { RrColor *c; RrAppearance *clear; - XMoveResizeWindow(ob_display, self->icon, + XMoveResizeWindow(obt_display, self->icon, PADDING, frame->item_margin.top, ITEM_HEIGHT - frame->item_margin.top - frame->item_margin.bottom, @@ -546,13 +551,13 @@ static void menu_entry_frame_render(ObMenuEntryFrame *self) - frame->item_margin.bottom, ITEM_HEIGHT - frame->item_margin.top - frame->item_margin.bottom); - XMapWindow(ob_display, self->icon); + XMapWindow(obt_display, self->icon); } else - XUnmapWindow(ob_display, self->icon); + XUnmapWindow(obt_display, self->icon); if (self->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU) { RrAppearance *bullet_a; - XMoveResizeWindow(ob_display, self->bullet, + XMoveResizeWindow(obt_display, self->bullet, self->frame->text_x + self->frame->text_w - ITEM_HEIGHT + PADDING, PADDING, ITEM_HEIGHT - 2*PADDING, @@ -567,11 +572,11 @@ static void menu_entry_frame_render(ObMenuEntryFrame *self) RrPaint(bullet_a, self->bullet, ITEM_HEIGHT - 2*PADDING, ITEM_HEIGHT - 2*PADDING); - XMapWindow(ob_display, self->bullet); + XMapWindow(obt_display, self->bullet); } else - XUnmapWindow(ob_display, self->bullet); + XUnmapWindow(obt_display, self->bullet); - XFlush(ob_display); + XFlush(obt_display); } /*! this code is taken from the menu_frame_render. if that changes, this won't @@ -690,10 +695,10 @@ void menu_frame_render(ObMenuFrame *self) } RECT_SET_POINT(e->area, 0, h+e->border); - XMoveWindow(ob_display, e->window, + XMoveWindow(obt_display, e->window, e->area.x-e->border, e->area.y-e->border); - XSetWindowBorderWidth(ob_display, e->window, e->border); - XSetWindowBorder(ob_display, e->window, + XSetWindowBorderWidth(obt_display, e->window, e->border); + XSetWindowBorder(obt_display, e->window, RrColorPixel(ob_rr_theme->menu_border_color)); @@ -776,7 +781,7 @@ void menu_frame_render(ObMenuFrame *self) if (!w) w = 10; if (!h) h = 3; - XResizeWindow(ob_display, self->window, w, h); + XResizeWindow(obt_display, self->window, w, h); self->inner_w = w; @@ -790,7 +795,7 @@ void menu_frame_render(ObMenuFrame *self) RECT_SET_SIZE(self->area, w, h); - XFlush(ob_display); + XFlush(obt_display); } static void menu_frame_update(ObMenuFrame *self) @@ -972,7 +977,7 @@ gboolean menu_frame_show_topmenu(ObMenuFrame *self, gint x, gint y, menu_frame_move(self, x, y); - XMapWindow(ob_display, self->window); + XMapWindow(obt_display, self->window); if (screen_pointer_pos(&px, &py)) { ObMenuEntryFrame *e = menu_entry_frame_under(px, py); @@ -1015,7 +1020,7 @@ gboolean menu_frame_show_submenu(ObMenuFrame *self, ObMenuFrame *parent, } menu_frame_move(self, x + dx, y + dy); - XMapWindow(ob_display, self->window); + XMapWindow(obt_display, self->window); if (screen_pointer_pos(&px, &py)) { ObMenuEntryFrame *e = menu_entry_frame_under(px, py); @@ -1052,7 +1057,7 @@ static void menu_frame_hide(ObMenuFrame *self) ungrab_keyboard(); } - XUnmapWindow(ob_display, self->window); + XUnmapWindow(obt_display, self->window); menu_frame_free(self); } @@ -1063,8 +1068,8 @@ void menu_frame_hide_all(void) if (config_submenu_show_delay) { /* remove any submenu open requests */ - ob_main_loop_timeout_remove(ob_main_loop, - menu_entry_frame_submenu_timeout); + obt_main_loop_timeout_remove(ob_main_loop, + menu_entry_frame_submenu_timeout); } if ((it = g_list_last(menu_frame_visible))) menu_frame_hide(it->data); @@ -1078,8 +1083,8 @@ void menu_frame_hide_all_client(ObClient *client) if (f->client == client) { if (config_submenu_show_delay) { /* remove any submenu open requests */ - ob_main_loop_timeout_remove(ob_main_loop, - menu_entry_frame_submenu_timeout); + obt_main_loop_timeout_remove(ob_main_loop, + menu_entry_frame_submenu_timeout); } menu_frame_hide(f); } @@ -1145,8 +1150,8 @@ void menu_frame_select(ObMenuFrame *self, ObMenuEntryFrame *entry, if (config_submenu_show_delay) { /* remove any submenu open requests */ - ob_main_loop_timeout_remove(ob_main_loop, - menu_entry_frame_submenu_timeout); + obt_main_loop_timeout_remove(ob_main_loop, + menu_entry_frame_submenu_timeout); } self->selected = entry; @@ -1162,11 +1167,11 @@ void menu_frame_select(ObMenuFrame *self, ObMenuEntryFrame *entry, if (self->selected->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU) { if (config_submenu_show_delay && !immediate) { /* initiate a new submenu open request */ - ob_main_loop_timeout_add(ob_main_loop, - config_submenu_show_delay * 1000, - menu_entry_frame_submenu_timeout, - self->selected, g_direct_equal, - NULL); + obt_main_loop_timeout_add(ob_main_loop, + config_submenu_show_delay * 1000, + menu_entry_frame_submenu_timeout, + self->selected, g_direct_equal, + NULL); } else { menu_entry_frame_show_submenu(self->selected); } diff --git a/openbox/menuframe.h b/openbox/menuframe.h index 1b1dcc7..1d5dd0c 100644 --- a/openbox/menuframe.h +++ b/openbox/menuframe.h @@ -38,7 +38,7 @@ extern GList *menu_frame_visible; struct _ObMenuFrame { /* stuff to be an ObWindow */ - Window_InternalType type; + ObWindow obwin; Window window; struct _ObMenu *menu; @@ -117,7 +117,7 @@ gboolean menu_frame_show_topmenu(ObMenuFrame *self, gint x, gint y, gboolean menu_frame_show_submenu(ObMenuFrame *self, ObMenuFrame *parent, ObMenuEntryFrame *parent_entry); -void menu_frame_hide_all(); +void menu_frame_hide_all(void); void menu_frame_hide_all_client(struct _ObClient *client); void menu_frame_render(ObMenuFrame *self); diff --git a/openbox/misc.h b/openbox/misc.h index c73c926..13530ed 100644 --- a/openbox/misc.h +++ b/openbox/misc.h @@ -107,6 +107,7 @@ typedef enum { OB_USER_ACTION_MOUSE_DOUBLE_CLICK, OB_USER_ACTION_MOUSE_MOTION, OB_USER_ACTION_MENU_SELECTION, + OB_USER_ACTION_HOOK, OB_NUM_USER_ACTIONS } ObUserAction; diff --git a/openbox/mouse.c b/openbox/mouse.c index f63d266..cd8490f 100644 --- a/openbox/mouse.c +++ b/openbox/mouse.c @@ -19,16 +19,15 @@ #include "openbox.h" #include "config.h" -#include "xerror.h" #include "actions.h" #include "event.h" #include "client.h" -#include "prop.h" #include "grab.h" #include "frame.h" #include "translate.h" #include "mouse.h" #include "gettext.h" +#include "obt/display.h" #include @@ -197,11 +196,11 @@ static gboolean fire_binding(ObMouseAction a, ObFrameContext context, return TRUE; } -void mouse_replay_pointer() +void mouse_replay_pointer(void) { if (replay_pointer_needed) { /* replay the pointer event before any windows move */ - XAllowEvents(ob_display, ReplayPointer, event_curtime); + XAllowEvents(obt_display, ReplayPointer, event_curtime); replay_pointer_needed = FALSE; } } @@ -281,10 +280,10 @@ void mouse_event(ObClient *client, XEvent *e) Window wjunk; guint ujunk, b, w, h; /* this can cause errors to occur when the window closes */ - xerror_set_ignore(TRUE); - junk1 = XGetGeometry(ob_display, e->xbutton.window, + obt_display_ignore_errors(TRUE); + junk1 = XGetGeometry(obt_display, e->xbutton.window, &wjunk, &junk1, &junk2, &w, &h, &b, &ujunk); - xerror_set_ignore(FALSE); + obt_display_ignore_errors(FALSE); if (junk1) { if (e->xbutton.x >= (signed)-b && e->xbutton.y >= (signed)-b && diff --git a/openbox/mouse.h b/openbox/mouse.h index a862fe5..2bd5d57 100644 --- a/openbox/mouse.h +++ b/openbox/mouse.h @@ -31,7 +31,7 @@ void mouse_shutdown(gboolean reconfig); gboolean mouse_bind(const gchar *buttonstr, const gchar *contextstr, ObMouseAction mact, struct _ObActionsAct *action); -void mouse_unbind_all(); +void mouse_unbind_all(void); void mouse_event(struct _ObClient *client, XEvent *e); @@ -43,6 +43,6 @@ ObFrameContext mouse_button_frame_context(ObFrameContext context, /*! If a replay pointer is needed, then do it. Call this when windows are going to be moving/appearing/disappearing, so that you know the mouse click will go to the right window */ -void mouse_replay_pointer(); +void mouse_replay_pointer(void); #endif diff --git a/openbox/moveresize.c b/openbox/moveresize.c index 9374f8b..ddc518a 100644 --- a/openbox/moveresize.c +++ b/openbox/moveresize.c @@ -20,21 +20,20 @@ #include "grab.h" #include "framerender.h" #include "screen.h" -#include "prop.h" #include "client.h" #include "frame.h" #include "openbox.h" #include "resist.h" -#include "mainloop.h" -#include "modkeys.h" #include "popup.h" #include "moveresize.h" #include "config.h" #include "event.h" #include "debug.h" -#include "extensions.h" #include "render/render.h" #include "render/theme.h" +#include "obt/display.h" +#include "obt/prop.h" +#include "obt/keyboard.h" #include #include @@ -168,8 +167,8 @@ static void popup_coords(ObClient *c, const gchar *format, gint a, gint b) void moveresize_start(ObClient *c, gint x, gint y, guint b, guint32 cnr) { ObCursor cur; - gboolean mv = (cnr == prop_atoms.net_wm_moveresize_move || - cnr == prop_atoms.net_wm_moveresize_move_keyboard); + gboolean mv = (cnr == OBT_PROP_ATOM(NET_WM_MOVERESIZE_MOVE) || + cnr == OBT_PROP_ATOM(NET_WM_MOVERESIZE_MOVE_KEYBOARD)); gint up = 1; gint left = 1; @@ -179,32 +178,37 @@ void moveresize_start(ObClient *c, gint x, gint y, guint b, guint32 cnr) (c->functions & OB_CLIENT_FUNC_RESIZE))) return; - if (cnr == prop_atoms.net_wm_moveresize_size_topleft) { + if (cnr == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOPLEFT)) { cur = OB_CURSOR_NORTHWEST; up = left = -1; - } else if (cnr == prop_atoms.net_wm_moveresize_size_top) { + } + else if (cnr == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOP)) { cur = OB_CURSOR_NORTH; up = -1; - } else if (cnr == prop_atoms.net_wm_moveresize_size_topright) { + } + else if (cnr == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOPRIGHT)) { cur = OB_CURSOR_NORTHEAST; up = -1; - } else if (cnr == prop_atoms.net_wm_moveresize_size_right) + } + else if (cnr == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_RIGHT)) cur = OB_CURSOR_EAST; - else if (cnr == prop_atoms.net_wm_moveresize_size_bottomright) + else if (cnr == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT)) cur = OB_CURSOR_SOUTHEAST; - else if (cnr == prop_atoms.net_wm_moveresize_size_bottom) + else if (cnr == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOM)) cur = OB_CURSOR_SOUTH; - else if (cnr == prop_atoms.net_wm_moveresize_size_bottomleft) { + else if (cnr == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT)) { cur = OB_CURSOR_SOUTHWEST; left = -1; - } else if (cnr == prop_atoms.net_wm_moveresize_size_left) { + } + else if (cnr == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_LEFT)) { cur = OB_CURSOR_WEST; left = -1; - } else if (cnr == prop_atoms.net_wm_moveresize_size_keyboard) + } + else if (cnr == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_KEYBOARD)) cur = OB_CURSOR_SOUTHEAST; - else if (cnr == prop_atoms.net_wm_moveresize_move) + else if (cnr == OBT_PROP_ATOM(NET_WM_MOVERESIZE_MOVE)) cur = OB_CURSOR_MOVE; - else if (cnr == prop_atoms.net_wm_moveresize_move_keyboard) + else if (cnr == OBT_PROP_ATOM(NET_WM_MOVERESIZE_MOVE_KEYBOARD)) cur = OB_CURSOR_MOVE; else g_assert_not_reached(); @@ -251,7 +255,7 @@ void moveresize_start(ObClient *c, gint x, gint y, guint b, guint32 cnr) moveresize_in_progress = TRUE; #ifdef SYNC - if (config_resize_redraw && !moving && extensions_sync && + if (config_resize_redraw && !moving && obt_display_extension_sync && moveresize_client->sync_request && moveresize_client->sync_counter && !moveresize_client->not_responding) { @@ -263,7 +267,7 @@ void moveresize_start(ObClient *c, gint x, gint y, guint b, guint32 cnr) /* set the counter to an initial value */ XSyncIntToValue(&val, 0); - XSyncSetCounter(ob_display, moveresize_client->sync_counter, val); + XSyncSetCounter(obt_display, moveresize_client->sync_counter, val); /* this will be incremented when we tell the client what we're looking for */ @@ -279,7 +283,7 @@ void moveresize_start(ObClient *c, gint x, gint y, guint b, guint32 cnr) aa.trigger.test_type = XSyncPositiveTransition; aa.events = True; XSyncIntToValue(&aa.delta, 1); - moveresize_alarm = XSyncCreateAlarm(ob_display, + moveresize_alarm = XSyncCreateAlarm(obt_display, XSyncCACounter | XSyncCAValue | XSyncCAValueType | @@ -308,11 +312,11 @@ void moveresize_end(gboolean cancel) #ifdef SYNC /* turn off the alarm */ if (moveresize_alarm != None) { - XSyncDestroyAlarm(ob_display, moveresize_alarm); + XSyncDestroyAlarm(obt_display, moveresize_alarm); moveresize_alarm = None; } - ob_main_loop_timeout_remove(ob_main_loop, sync_timeout_func); + obt_main_loop_timeout_remove(ob_main_loop, sync_timeout_func); #endif client_configure(moveresize_client, @@ -367,7 +371,7 @@ static void do_resize(void) } #ifdef SYNC - if (config_resize_redraw && extensions_sync && + if (config_resize_redraw && obt_display_extension_sync && moveresize_client->sync_request && moveresize_client->sync_counter && !moveresize_client->not_responding) { @@ -384,24 +388,24 @@ static void do_resize(void) /* tell the client what we're waiting for */ ce.xclient.type = ClientMessage; - ce.xclient.message_type = prop_atoms.wm_protocols; - ce.xclient.display = ob_display; + ce.xclient.message_type = OBT_PROP_ATOM(WM_PROTOCOLS); + ce.xclient.display = obt_display; ce.xclient.window = moveresize_client->window; ce.xclient.format = 32; - ce.xclient.data.l[0] = prop_atoms.net_wm_sync_request; + ce.xclient.data.l[0] = OBT_PROP_ATOM(NET_WM_SYNC_REQUEST); ce.xclient.data.l[1] = event_curtime; ce.xclient.data.l[2] = XSyncValueLow32(val); ce.xclient.data.l[3] = XSyncValueHigh32(val); ce.xclient.data.l[4] = 0l; - XSendEvent(ob_display, moveresize_client->window, FALSE, + XSendEvent(obt_display, moveresize_client->window, FALSE, NoEventMask, &ce); waiting_for_sync = TRUE; - ob_main_loop_timeout_remove(ob_main_loop, sync_timeout_func); - ob_main_loop_timeout_add(ob_main_loop, G_USEC_PER_SEC * 2, - sync_timeout_func, - NULL, NULL, NULL); + obt_main_loop_timeout_remove(ob_main_loop, sync_timeout_func); + obt_main_loop_timeout_add(ob_main_loop, G_USEC_PER_SEC * 2, + sync_timeout_func, + NULL, NULL, NULL); } #endif @@ -580,10 +584,10 @@ static void do_edge_warp(gint x, gint y) cancel_edge_warp(); if (dir != (ObDirection)-1) { edge_warp_odd = TRUE; /* switch on the first timeout */ - ob_main_loop_timeout_add(ob_main_loop, - config_mouse_screenedgetime * 1000, - edge_warp_delay_func, - NULL, NULL, NULL); + obt_main_loop_timeout_add(ob_main_loop, + config_mouse_screenedgetime * 1000, + edge_warp_delay_func, + NULL, NULL, NULL); } edge_warp_dir = dir; } @@ -591,7 +595,7 @@ static void do_edge_warp(gint x, gint y) static void cancel_edge_warp(void) { - ob_main_loop_timeout_remove(ob_main_loop, edge_warp_delay_func); + obt_main_loop_timeout_remove(ob_main_loop, edge_warp_delay_func); } static void move_with_keys(gint keycode, gint state) @@ -601,7 +605,7 @@ static void move_with_keys(gint keycode, gint state) gint dist = 0; /* shift means jump to edge */ - if (state & modkeys_key_to_mask(OB_MODKEY_KEY_SHIFT)) { + if (state & obt_keyboard_modkey_to_modmask(OBT_KEYBOARD_MODKEY_SHIFT)) { gint x, y; ObDirection dir; @@ -619,8 +623,11 @@ static void move_with_keys(gint keycode, gint state) dy = y - moveresize_client->area.y; } else { /* control means fine grained */ - if (state & modkeys_key_to_mask(OB_MODKEY_KEY_CONTROL)) + if (state & + obt_keyboard_modkey_to_modmask(OBT_KEYBOARD_MODKEY_CONTROL)) + { dist = 1; + } else dist = KEY_DIST; @@ -635,12 +642,12 @@ static void move_with_keys(gint keycode, gint state) } screen_pointer_pos(&opx, &opy); - XWarpPointer(ob_display, None, None, 0, 0, 0, 0, dx, dy); + XWarpPointer(obt_display, None, None, 0, 0, 0, 0, dx, dy); /* steal the motion events this causes */ - XSync(ob_display, FALSE); + XSync(obt_display, FALSE); { XEvent ce; - while (XCheckTypedEvent(ob_display, MotionNotify, &ce)); + while (XCheckTypedEvent(obt_display, MotionNotify, &ce)); } screen_pointer_pos(&px, &py); @@ -701,7 +708,7 @@ static void resize_with_keys(gint keycode, gint state) } /* shift means jump to edge */ - if (state & modkeys_key_to_mask(OB_MODKEY_KEY_SHIFT)) { + if (state & obt_keyboard_modkey_to_modmask(OBT_KEYBOARD_MODKEY_SHIFT)) { gint x, y, w, h; if (keycode == ob_keycode(OB_KEY_RIGHT)) @@ -726,7 +733,9 @@ static void resize_with_keys(gint keycode, gint state) distw = moveresize_client->size_inc.width; resist = 1; } - else if (state & modkeys_key_to_mask(OB_MODKEY_KEY_CONTROL)) { + else if (state & + obt_keyboard_modkey_to_modmask(OBT_KEYBOARD_MODKEY_CONTROL)) + { distw = 1; resist = 1; } @@ -738,7 +747,9 @@ static void resize_with_keys(gint keycode, gint state) disth = moveresize_client->size_inc.height; resist = 1; } - else if (state & modkeys_key_to_mask(OB_MODKEY_KEY_CONTROL)) { + else if (state & + obt_keyboard_modkey_to_modmask(OBT_KEYBOARD_MODKEY_CONTROL)) + { disth = 1; resist = 1; } @@ -792,12 +803,12 @@ static void resize_with_keys(gint keycode, gint state) pdy = dh; screen_pointer_pos(&opx, &opy); - XWarpPointer(ob_display, None, None, 0, 0, 0, 0, pdx, pdy); + XWarpPointer(obt_display, None, None, 0, 0, 0, 0, pdx, pdy); /* steal the motion events this causes */ - XSync(ob_display, FALSE); + XSync(obt_display, FALSE); { XEvent ce; - while (XCheckTypedEvent(ob_display, MotionNotify, &ce)); + while (XCheckTypedEvent(obt_display, MotionNotify, &ce)); } screen_pointer_pos(&px, &py); @@ -840,41 +851,44 @@ gboolean moveresize_event(XEvent *e) gint dw, dh; ObDirection dir; - if (corner == prop_atoms.net_wm_moveresize_size_topleft) { + if (corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOPLEFT)) { dw = -(e->xmotion.x_root - start_x); dh = -(e->xmotion.y_root - start_y); dir = OB_DIRECTION_NORTHWEST; - } else if (corner == prop_atoms.net_wm_moveresize_size_top) { + } else if (corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOP)) { dw = 0; dh = -(e->xmotion.y_root - start_y); dir = OB_DIRECTION_NORTH; - } else if (corner == prop_atoms.net_wm_moveresize_size_topright) { + } else if (corner == + OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOPRIGHT)) { dw = (e->xmotion.x_root - start_x); dh = -(e->xmotion.y_root - start_y); dir = OB_DIRECTION_NORTHEAST; - } else if (corner == prop_atoms.net_wm_moveresize_size_right) { + } else if (corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_RIGHT)) { dw = (e->xmotion.x_root - start_x); dh = 0; dir = OB_DIRECTION_EAST; } else if (corner == - prop_atoms.net_wm_moveresize_size_bottomright) { + OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT)) { dw = (e->xmotion.x_root - start_x); dh = (e->xmotion.y_root - start_y); dir = OB_DIRECTION_SOUTHEAST; - } else if (corner == prop_atoms.net_wm_moveresize_size_bottom) { + } else if (corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOM)) + { dw = 0; dh = (e->xmotion.y_root - start_y); dir = OB_DIRECTION_SOUTH; } else if (corner == - prop_atoms.net_wm_moveresize_size_bottomleft) { + OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT)) { dw = -(e->xmotion.x_root - start_x); dh = (e->xmotion.y_root - start_y); dir = OB_DIRECTION_SOUTHWEST; - } else if (corner == prop_atoms.net_wm_moveresize_size_left) { + } else if (corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_LEFT)) { dw = -(e->xmotion.x_root - start_x); dh = 0; dir = OB_DIRECTION_WEST; - } else if (corner == prop_atoms.net_wm_moveresize_size_keyboard) { + } else if (corner == + OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_KEYBOARD)) { dw = (e->xmotion.x_root - start_x); dh = (e->xmotion.y_root - start_y); dir = OB_DIRECTION_SOUTHEAST; @@ -888,15 +902,15 @@ gboolean moveresize_event(XEvent *e) cur_w += dw; cur_h += dh; - if (corner == prop_atoms.net_wm_moveresize_size_topleft || - corner == prop_atoms.net_wm_moveresize_size_left || - corner == prop_atoms.net_wm_moveresize_size_bottomleft) + if (corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOPLEFT) || + corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_LEFT) || + corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT)) { cur_x -= dw; } - if (corner == prop_atoms.net_wm_moveresize_size_topleft || - corner == prop_atoms.net_wm_moveresize_size_top || - corner == prop_atoms.net_wm_moveresize_size_topright) + if (corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOPLEFT) || + corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOP) || + corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOPRIGHT)) { cur_y -= dh; } @@ -916,17 +930,19 @@ gboolean moveresize_event(XEvent *e) e->xkey.keycode == ob_keycode(OB_KEY_DOWN) || e->xkey.keycode == ob_keycode(OB_KEY_UP)) { - if (corner == prop_atoms.net_wm_moveresize_size_keyboard) { + if (corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_KEYBOARD)) { resize_with_keys(e->xkey.keycode, e->xkey.state); used = TRUE; - } else if (corner == prop_atoms.net_wm_moveresize_move_keyboard) { + } else if (corner == + OBT_PROP_ATOM(NET_WM_MOVERESIZE_MOVE_KEYBOARD)) + { move_with_keys(e->xkey.keycode, e->xkey.state); used = TRUE; } } } #ifdef SYNC - else if (e->type == extensions_sync_event_basep + XSyncAlarmNotify) + else if (e->type == obt_display_extension_sync_basep + XSyncAlarmNotify) { waiting_for_sync = FALSE; /* we got our sync... */ do_resize(); /* ...so try resize if there is more change pending */ diff --git a/openbox/openbox.c b/openbox/openbox.c index fb1e75d..01aa58a 100644 --- a/openbox/openbox.c +++ b/openbox/openbox.c @@ -21,12 +21,9 @@ #include "openbox.h" #include "session.h" #include "dock.h" -#include "modkeys.h" #include "event.h" #include "menu.h" #include "client.h" -#include "xerror.h" -#include "prop.h" #include "screen.h" #include "actions.h" #include "startupnotify.h" @@ -39,18 +36,20 @@ #include "framerender.h" #include "keyboard.h" #include "mouse.h" -#include "extensions.h" #include "menuframe.h" #include "grab.h" #include "group.h" #include "config.h" #include "ping.h" -#include "mainloop.h" #include "prompt.h" +#include "hooks.h" #include "gettext.h" -#include "parser/parse.h" #include "render/render.h" #include "render/theme.h" +#include "obt/display.h" +#include "obt/prop.h" +#include "obt/keyboard.h" +#include "obt/parse.h" #ifdef HAVE_FCNTL_H # include @@ -85,12 +84,10 @@ #include #include - RrInstance *ob_rr_inst; RrImageCache *ob_rr_icons; RrTheme *ob_rr_theme; -ObMainLoop *ob_main_loop; -Display *ob_display; +ObtMainLoop *ob_main_loop; gint ob_screen; gboolean ob_replace_wm = FALSE; gboolean ob_sm_use = TRUE; @@ -123,6 +120,8 @@ gint main(gint argc, gchar **argv) state = OB_STATE_STARTING; + ob_debug_startup(); + /* initialize the locale */ if (!setlocale(LC_ALL, "")) g_message("Couldn't set locale from environment."); @@ -142,45 +141,36 @@ gint main(gint argc, gchar **argv) program_name = g_path_get_basename(argv[0]); g_set_prgname(program_name); - if (!remote_control) { - parse_paths_startup(); - + if (!remote_control) session_startup(argc, argv); - } - - ob_display = XOpenDisplay(NULL); - if (ob_display == NULL) + if (!obt_display_open(NULL)) ob_exit_with_error(_("Failed to open the display from the DISPLAY environment variable.")); - if (fcntl(ConnectionNumber(ob_display), F_SETFD, 1) == -1) - ob_exit_with_error("Failed to set display as close-on-exec"); if (remote_control) { - prop_startup(); - /* Send client message telling the OB process to: * remote_control = 1 -> reconfigure * remote_control = 2 -> restart */ - PROP_MSG(RootWindow(ob_display, ob_screen), - ob_control, remote_control, 0, 0, 0); - XCloseDisplay(ob_display); + OBT_PROP_MSG(ob_screen, obt_root(ob_screen), + OB_CONTROL, remote_control, 0, 0, 0, 0); + obt_display_close(); exit(EXIT_SUCCESS); } - ob_main_loop = ob_main_loop_new(ob_display); + ob_main_loop = obt_main_loop_new(); /* set up signal handler */ - ob_main_loop_signal_add(ob_main_loop, SIGUSR1, signal_handler, NULL, NULL); - ob_main_loop_signal_add(ob_main_loop, SIGUSR2, signal_handler, NULL, NULL); - ob_main_loop_signal_add(ob_main_loop, SIGTERM, signal_handler, NULL, NULL); - ob_main_loop_signal_add(ob_main_loop, SIGINT, signal_handler, NULL, NULL); - ob_main_loop_signal_add(ob_main_loop, SIGHUP, signal_handler, NULL, NULL); - ob_main_loop_signal_add(ob_main_loop, SIGPIPE, signal_handler, NULL, NULL); - ob_main_loop_signal_add(ob_main_loop, SIGCHLD, signal_handler, NULL, NULL); + obt_main_loop_signal_add(ob_main_loop, SIGUSR1, signal_handler, NULL,NULL); + obt_main_loop_signal_add(ob_main_loop, SIGUSR2, signal_handler, NULL,NULL); + obt_main_loop_signal_add(ob_main_loop, SIGTERM, signal_handler, NULL,NULL); + obt_main_loop_signal_add(ob_main_loop, SIGINT, signal_handler, NULL,NULL); + obt_main_loop_signal_add(ob_main_loop, SIGHUP, signal_handler, NULL,NULL); + obt_main_loop_signal_add(ob_main_loop, SIGPIPE, signal_handler, NULL,NULL); + obt_main_loop_signal_add(ob_main_loop, SIGCHLD, signal_handler, NULL,NULL); - ob_screen = DefaultScreen(ob_display); + ob_screen = DefaultScreen(obt_display); - ob_rr_inst = RrInstanceNew(ob_display, ob_screen); + ob_rr_inst = RrInstanceNew(obt_display, ob_screen); if (ob_rr_inst == NULL) ob_exit_with_error(_("Failed to initialize the obrender library.")); /* Saving 3 resizes of an RrImage makes a lot of sense for icons, as there @@ -189,7 +179,7 @@ gint main(gint argc, gchar **argv) */ ob_rr_icons = RrImageCacheNew(3); - XSynchronize(ob_display, xsync); + XSynchronize(obt_display, xsync); /* check for locale support */ if (!XSupportsLocale()) @@ -197,12 +187,9 @@ gint main(gint argc, gchar **argv) if (!XSetLocaleModifiers("")) g_message(_("Cannot set locale modifiers for the X server.")); - /* set our error handler */ - XSetErrorHandler(xerror_handler); - /* set the DISPLAY environment variable for any lauched children, to the display we're using, so they open in the right place. */ - setenv("DISPLAY", DisplayString(ob_display), TRUE); + setenv("DISPLAY", DisplayString(obt_display), TRUE); /* create available cursors */ cursors[OB_CURSOR_NONE] = None; @@ -223,42 +210,41 @@ gint main(gint argc, gchar **argv) cursors[OB_CURSOR_NORTHWEST] = load_cursor("top_left_corner", XC_top_left_corner); - - prop_startup(); /* get atoms values for the display */ - extensions_query_all(); /* find which extensions are present */ - if (screen_annex()) { /* it will be ours! */ do { - modkeys_startup(reconfigure); + if (reconfigure) obt_keyboard_reload(); /* get the keycodes for keys we use */ - keys[OB_KEY_RETURN] = modkeys_sym_to_code(XK_Return); - keys[OB_KEY_ESCAPE] = modkeys_sym_to_code(XK_Escape); - keys[OB_KEY_LEFT] = modkeys_sym_to_code(XK_Left); - keys[OB_KEY_RIGHT] = modkeys_sym_to_code(XK_Right); - keys[OB_KEY_UP] = modkeys_sym_to_code(XK_Up); - keys[OB_KEY_DOWN] = modkeys_sym_to_code(XK_Down); - keys[OB_KEY_TAB] = modkeys_sym_to_code(XK_Tab); - keys[OB_KEY_SPACE] = modkeys_sym_to_code(XK_space); + keys[OB_KEY_RETURN] = obt_keyboard_keysym_to_keycode(XK_Return); + keys[OB_KEY_ESCAPE] = obt_keyboard_keysym_to_keycode(XK_Escape); + keys[OB_KEY_LEFT] = obt_keyboard_keysym_to_keycode(XK_Left); + keys[OB_KEY_RIGHT] = obt_keyboard_keysym_to_keycode(XK_Right); + keys[OB_KEY_UP] = obt_keyboard_keysym_to_keycode(XK_Up); + keys[OB_KEY_DOWN] = obt_keyboard_keysym_to_keycode(XK_Down); + keys[OB_KEY_TAB] = obt_keyboard_keysym_to_keycode(XK_Tab); + keys[OB_KEY_SPACE] = obt_keyboard_keysym_to_keycode(XK_space); { - ObParseInst *i; - xmlDocPtr doc; - xmlNodePtr node; + ObtParseInst *i; /* startup the parsing so everything can register sections of the rc */ - i = parse_startup(); + i = obt_parse_instance_new(); /* register all the available actions */ actions_startup(reconfigure); + hooks_startup(reconfigure); /* start up config which sets up with the parser */ config_startup(i); /* parse/load user options */ - if (parse_load_rc(config_file, &doc, &node)) { - parse_tree(i, doc, node->xmlChildrenNode); - parse_close(doc); + if ((config_file && + obt_parse_load_file(i, config_file, "openbox_config")) || + obt_parse_load_config_file(i, "openbox", "rc.xml", + "openbox_config")) + { + obt_parse_tree_from_root(i); + obt_parse_close(i); } else { g_message(_("Unable to find a valid config file, using some simple defaults")); @@ -269,16 +255,15 @@ gint main(gint argc, gchar **argv) gchar *p = g_filename_to_utf8(config_file, -1, NULL, NULL, NULL); if (p) - PROP_SETS(RootWindow(ob_display, ob_screen), - ob_config_file, p); + OBT_PROP_SETS(obt_root(ob_screen), OB_CONFIG_FILE, + utf8, p); g_free(p); } else - PROP_ERASE(RootWindow(ob_display, ob_screen), - ob_config_file); + OBT_PROP_ERASE(obt_root(ob_screen), OB_CONFIG_FILE); /* we're done with parsing now, kill it */ - parse_shutdown(i); + obt_parse_instance_unref(i); } /* load the theme specified in the rc file */ @@ -297,8 +282,8 @@ gint main(gint argc, gchar **argv) if (ob_rr_theme == NULL) ob_exit_with_error(_("Unable to load a theme.")); - PROP_SETS(RootWindow(ob_display, ob_screen), - ob_theme, ob_rr_theme->name); + OBT_PROP_SETS(obt_root(ob_screen), + OB_THEME, utf8, ob_rr_theme->name); } if (reconfigure) { @@ -337,14 +322,13 @@ gint main(gint argc, gchar **argv) ObWindow *w; /* get all the existing windows */ - client_manage_all(); + window_manage_all(); focus_nothing(); /* focus what was focused if a wm was already running */ - if (PROP_GET32(RootWindow(ob_display, ob_screen), - net_active_window, window, &xid) && - (w = g_hash_table_lookup(window_map, &xid)) && - WINDOW_IS_CLIENT(w)) + if (OBT_PROP_GET32(obt_root(ob_screen), + NET_ACTIVE_WINDOW, WINDOW, &xid) && + (w = window_find(xid)) && WINDOW_IS_CLIENT(w)) { client_focus(WINDOW_AS_CLIENT(w)); } @@ -368,13 +352,11 @@ gint main(gint argc, gchar **argv) reconfigure = FALSE; state = OB_STATE_RUNNING; - ob_main_loop_run(ob_main_loop); + obt_main_loop_run(ob_main_loop); state = OB_STATE_EXITING; - if (!reconfigure) { - dock_remove_all(); - client_unmanage_all(); - } + if (!reconfigure) + window_unmanage_all(); menu_shutdown(reconfigure); menu_frame_shutdown(reconfigure); @@ -396,12 +378,12 @@ gint main(gint argc, gchar **argv) sn_shutdown(reconfigure); event_shutdown(reconfigure); config_shutdown(); + hooks_shutdown(reconfigure); actions_shutdown(reconfigure); - modkeys_shutdown(reconfigure); } while (reconfigure); } - XSync(ob_display, FALSE); + XSync(obt_display, FALSE); RrThemeFree(ob_rr_theme); RrImageCacheUnref(ob_rr_icons); @@ -409,9 +391,7 @@ gint main(gint argc, gchar **argv) session_shutdown(being_replaced); - XCloseDisplay(ob_display); - - parse_paths_shutdown(); + obt_display_close(); if (restart) { if (restart_path != NULL) { @@ -467,6 +447,8 @@ gint main(gint argc, gchar **argv) g_free(ob_sm_id); g_free(program_name); + ob_debug_shutdown(); + return exitcode; } @@ -474,11 +456,11 @@ static void signal_handler(gint signal, gpointer data) { switch (signal) { case SIGUSR1: - ob_debug("Caught signal %d. Restarting.\n", signal); + ob_debug("Caught signal %d. Restarting.", signal); ob_restart(); break; case SIGUSR2: - ob_debug("Caught signal %d. Reconfiguring.\n", signal); + ob_debug("Caught signal %d. Reconfiguring.", signal); ob_reconfigure(); break; case SIGCHLD: @@ -486,13 +468,13 @@ static void signal_handler(gint signal, gpointer data) while (waitpid(-1, NULL, WNOHANG) > 0); break; default: - ob_debug("Caught signal %d. Exiting.\n", signal); + ob_debug("Caught signal %d. Exiting.", signal); /* TERM and INT return a 0 code */ ob_exit(!(signal == SIGTERM || signal == SIGINT)); } } -static void print_version() +static void print_version(void) { g_print("Openbox %s\n", PACKAGE_VERSION); g_print(_("Copyright (c)")); @@ -504,7 +486,7 @@ static void print_version() g_print("under certain conditions. See the file COPYING for details.\n\n"); } -static void print_help() +static void print_help(void) { g_print(_("Syntax: openbox [options]\n")); g_print(_("\nOptions:\n")); @@ -524,6 +506,7 @@ static void print_help() g_print(_(" --sync Run in synchronous mode\n")); g_print(_(" --debug Display debugging output\n")); g_print(_(" --debug-focus Display debugging output for focus handling\n")); + g_print(_(" --debug-session Display debugging output for session managment\n")); g_print(_(" --debug-xinerama Split the display into fake xinerama screens\n")); g_print(_("\nPlease report bugs at %s\n"), PACKAGE_BUGREPORT); } @@ -539,7 +522,7 @@ static void remove_args(gint *argc, gchar **argv, gint index, gint num) *argc -= num; } -static void parse_env() +static void parse_env(void) { /* unset this so we don't pass it on unknowingly */ unsetenv("DESKTOP_STARTUP_ID"); @@ -570,16 +553,19 @@ static void parse_args(gint *argc, gchar **argv) xsync = TRUE; } else if (!strcmp(argv[i], "--debug")) { - ob_debug_show_output(TRUE); - ob_debug_enable(OB_DEBUG_SM, TRUE); + ob_debug_enable(OB_DEBUG_NORMAL, TRUE); ob_debug_enable(OB_DEBUG_APP_BUGS, TRUE); } else if (!strcmp(argv[i], "--debug-focus")) { - ob_debug_show_output(TRUE); - ob_debug_enable(OB_DEBUG_SM, TRUE); + ob_debug_enable(OB_DEBUG_NORMAL, TRUE); ob_debug_enable(OB_DEBUG_APP_BUGS, TRUE); ob_debug_enable(OB_DEBUG_FOCUS, TRUE); } + else if (!strcmp(argv[i], "--debug-session")) { + ob_debug_enable(OB_DEBUG_NORMAL, TRUE); + ob_debug_enable(OB_DEBUG_APP_BUGS, TRUE); + ob_debug_enable(OB_DEBUG_SM, TRUE); + } else if (!strcmp(argv[i], "--debug-xinerama")) { ob_debug_xinerama = TRUE; } @@ -611,7 +597,7 @@ static void parse_args(gint *argc, gchar **argv) ob_sm_save_file = g_strdup(argv[i+1]); remove_args(argc, argv, i, 2); --i; /* this arg was removed so go back */ - ob_debug_type(OB_DEBUG_SM, "--sm-save-file %s\n", + ob_debug_type(OB_DEBUG_SM, "--sm-save-file %s", ob_sm_save_file); } } @@ -623,7 +609,7 @@ static void parse_args(gint *argc, gchar **argv) ob_sm_id = g_strdup(argv[i+1]); remove_args(argc, argv, i, 2); --i; /* this arg was removed so go back */ - ob_debug_type(OB_DEBUG_SM, "--sm-client-id %s\n", ob_sm_id); + ob_debug_type(OB_DEBUG_SM, "--sm-client-id %s", ob_sm_id); } } else if (!strcmp(argv[i], "--sm-disable")) { @@ -648,10 +634,10 @@ static Cursor load_cursor(const gchar *name, guint fontval) Cursor c = None; #if USE_XCURSOR - c = XcursorLibraryLoadCursor(ob_display, name); + c = XcursorLibraryLoadCursor(obt_display, name); #endif if (c == None) - c = XCreateFontCursor(ob_display, fontval); + c = XCreateFontCursor(obt_display, fontval); return c; } @@ -668,13 +654,13 @@ void ob_restart_other(const gchar *path) ob_restart(); } -void ob_restart() +void ob_restart(void) { restart = TRUE; ob_exit(0); } -void ob_reconfigure() +void ob_reconfigure(void) { reconfigure = TRUE; ob_exit(0); @@ -683,14 +669,14 @@ void ob_reconfigure() void ob_exit(gint code) { exitcode = code; - ob_main_loop_exit(ob_main_loop); + obt_main_loop_exit(ob_main_loop); } -void ob_exit_replace() +void ob_exit_replace(void) { exitcode = 0; being_replaced = TRUE; - ob_main_loop_exit(ob_main_loop); + obt_main_loop_exit(ob_main_loop); } Cursor ob_cursor(ObCursor cursor) @@ -705,7 +691,7 @@ KeyCode ob_keycode(ObKey key) return keys[key]; } -ObState ob_state() +ObState ob_state(void) { return state; } diff --git a/openbox/openbox.h b/openbox/openbox.h index 4f2310f..ba22183 100644 --- a/openbox/openbox.h +++ b/openbox/openbox.h @@ -23,20 +23,17 @@ #include "render/render.h" #include "render/theme.h" +#include "obt/mainloop.h" +#include "obt/display.h" #include #include -struct _ObMainLoop; - extern RrInstance *ob_rr_inst; extern RrImageCache *ob_rr_icons; extern RrTheme *ob_rr_theme; -extern struct _ObMainLoop *ob_main_loop; - -/*! The X display */ -extern Display *ob_display; +extern ObtMainLoop *ob_main_loop; /*! The number of the screen on which we're running */ extern gint ob_screen; @@ -51,14 +48,14 @@ extern gboolean ob_replace_wm; extern gboolean ob_debug_xinerama; /* The state of execution of the window manager */ -ObState ob_state(); +ObState ob_state(void); void ob_restart_other(const gchar *path); -void ob_restart(); +void ob_restart(void); void ob_exit(gint code); -void ob_exit_replace(); +void ob_exit_replace(void); -void ob_reconfigure(); +void ob_reconfigure(void); void ob_exit_with_error(const gchar *msg); diff --git a/openbox/ping.c b/openbox/ping.c index 748c0c8..8320249 100644 --- a/openbox/ping.c +++ b/openbox/ping.c @@ -19,11 +19,11 @@ #include "ping.h" #include "client.h" -#include "prop.h" #include "event.h" #include "debug.h" -#include "mainloop.h" #include "openbox.h" +#include "obt/mainloop.h" +#include "obt/prop.h" typedef struct _ObPingTarget { @@ -79,8 +79,8 @@ void ping_start(struct _ObClient *client, ObPingEventHandler h) t->client = client; t->h = h; - ob_main_loop_timeout_add(ob_main_loop, PING_TIMEOUT, ping_timeout, - t, g_direct_equal, NULL); + obt_main_loop_timeout_add(ob_main_loop, PING_TIMEOUT, ping_timeout, + t, g_direct_equal, NULL); /* act like we just timed out immediately, to start the pinging process now instead of after the first delay. this makes sure the client ends up in the ping_ids hash table now. */ @@ -95,7 +95,7 @@ void ping_got_pong(guint32 id) ObPingTarget *t; if ((t = g_hash_table_lookup(ping_ids, &id))) { - /*ob_debug("-PONG: '%s' (id %u)\n", t->client->title, t->id);*/ + /*ob_debug("-PONG: '%s' (id %u)", t->client->title, t->id);*/ if (t->waiting > PING_TIMEOUT_WARN) { /* we had notified that they weren't responding, so now we need to notify that they are again */ @@ -107,7 +107,7 @@ void ping_got_pong(guint32 id) ping_end(t->client, NULL); } else - ob_debug("Got PONG with id %u but not waiting for one\n", id); + ob_debug("Got PONG with id %u but not waiting for one", id); } static gboolean find_client(gpointer key, gpointer value, gpointer client) @@ -130,10 +130,10 @@ static void ping_send(ObPingTarget *t) g_hash_table_insert(ping_ids, &t->id, t); } - /*ob_debug("+PING: '%s' (id %u)\n", t->client->title, t->id);*/ - PROP_MSG_TO(t->client->window, t->client->window, wm_protocols, - prop_atoms.net_wm_ping, t->id, t->client->window, 0, 0, - NoEventMask); + /*ob_debug("+PING: '%s' (id %u)", t->client->title, t->id);*/ + OBT_PROP_MSG_TO(t->client->window, t->client->window, WM_PROTOCOLS, + OBT_PROP_ATOM(NET_WM_PING), t->id, t->client->window, 0, 0, + NoEventMask); } static gboolean ping_timeout(gpointer data) @@ -158,7 +158,8 @@ static void ping_end(ObClient *client, gpointer data) if ((t = g_hash_table_find(ping_ids, find_client, client))) { g_hash_table_remove(ping_ids, &t->id); - ob_main_loop_timeout_remove_data(ob_main_loop, ping_timeout, t, FALSE); + obt_main_loop_timeout_remove_data(ob_main_loop, ping_timeout, + t, FALSE); g_free(t); } diff --git a/openbox/place.c b/openbox/place.c index 45d7f07..aac40e8 100644 --- a/openbox/place.c +++ b/openbox/place.c @@ -76,7 +76,7 @@ static Rect **pick_head(ObClient *c) /* try direct parent first */ if ((p = client_direct_parent(c))) { add_choice(choice, client_monitor(p)); - ob_debug("placement adding choice %d for parent\n", + ob_debug("placement adding choice %d for parent", client_monitor(p)); } @@ -92,7 +92,7 @@ static Rect **pick_head(ObClient *c) itc->desktop == DESKTOP_ALL || c->desktop == DESKTOP_ALL)) { add_choice(choice, client_monitor(it->data)); - ob_debug("placement adding choice %d for group sibling\n", + ob_debug("placement adding choice %d for group sibling", client_monitor(it->data)); } } @@ -103,7 +103,7 @@ static Rect **pick_head(ObClient *c) if (itc != c) { add_choice(choice, client_monitor(it->data)); ob_debug("placement adding choice %d for group sibling on " - "another desktop\n", client_monitor(it->data)); + "another desktop", client_monitor(it->data)); } } } @@ -113,7 +113,7 @@ static Rect **pick_head(ObClient *c) config_place_monitor != OB_PLACE_MONITOR_MOUSE) { add_choice(choice, client_monitor(focus_client)); - ob_debug("placement adding choice %d for normal focused window\n", + ob_debug("placement adding choice %d for normal focused window", client_monitor(focus_client)); } @@ -125,7 +125,7 @@ static Rect **pick_head(ObClient *c) g_free(monitor); if (contain) { add_choice(choice, i); - ob_debug("placement adding choice %d for mouse pointer\n", i); + ob_debug("placement adding choice %d for mouse pointer", i); break; } } diff --git a/openbox/popup.c b/openbox/popup.c index 770f33d..fd31846 100644 --- a/openbox/popup.c +++ b/openbox/popup.c @@ -25,7 +25,6 @@ #include "stacking.h" #include "event.h" #include "screen.h" -#include "mainloop.h" #include "render/render.h" #include "render/theme.h" @@ -34,7 +33,7 @@ ObPopup *popup_new(void) XSetWindowAttributes attrib; ObPopup *self = g_new0(ObPopup, 1); - self->obwin.type = Window_Internal; + self->obwin.type = OB_WINDOW_CLASS_INTERNAL; self->gravity = NorthWestGravity; self->x = self->y = self->textw = self->h = 0; self->a_bg = RrAppearanceCopy(ob_rr_theme->osd_hilite_bg); @@ -42,34 +41,34 @@ ObPopup *popup_new(void) self->iconwm = self->iconhm = 1; attrib.override_redirect = True; - self->bg = XCreateWindow(ob_display, RootWindow(ob_display, ob_screen), + self->bg = XCreateWindow(obt_display, obt_root(ob_screen), 0, 0, 1, 1, 0, RrDepth(ob_rr_inst), InputOutput, RrVisual(ob_rr_inst), CWOverrideRedirect, &attrib); - self->text = XCreateWindow(ob_display, self->bg, + self->text = XCreateWindow(obt_display, self->bg, 0, 0, 1, 1, 0, RrDepth(ob_rr_inst), InputOutput, RrVisual(ob_rr_inst), 0, NULL); - XSetWindowBorderWidth(ob_display, self->bg, ob_rr_theme->obwidth); - XSetWindowBorder(ob_display, self->bg, + XSetWindowBorderWidth(obt_display, self->bg, ob_rr_theme->obwidth); + XSetWindowBorder(obt_display, self->bg, RrColorPixel(ob_rr_theme->osd_border_color)); - XMapWindow(ob_display, self->text); + XMapWindow(obt_display, self->text); stacking_add(INTERNAL_AS_WINDOW(self)); - g_hash_table_insert(window_map, &self->bg, self); + window_add(&self->bg, INTERNAL_AS_WINDOW(self)); return self; } void popup_free(ObPopup *self) { if (self) { - XDestroyWindow(ob_display, self->bg); - XDestroyWindow(ob_display, self->text); + XDestroyWindow(obt_display, self->bg); + XDestroyWindow(obt_display, self->text); RrAppearanceFree(self->a_bg); RrAppearanceFree(self->a_text); - g_hash_table_remove(window_map, &self->bg); + window_remove(self->bg); stacking_remove(self); g_free(self); } @@ -141,7 +140,7 @@ static gboolean popup_show_timeout(gpointer data) { ObPopup *self = data; - XMapWindow(ob_display, self->bg); + XMapWindow(obt_display, self->bg); stacking_raise(INTERNAL_AS_WINDOW(self)); self->mapped = TRUE; self->delay_mapped = FALSE; @@ -273,7 +272,7 @@ void popup_delay_show(ObPopup *self, gulong usec, gchar *text) } /* set the windows/appearances up */ - XMoveResizeWindow(ob_display, self->bg, x, y, w, h); + XMoveResizeWindow(obt_display, self->bg, x, y, w, h); /* when there is no icon and the text is not parent relative, then fill the whole dialog with the text appearance, don't use the bg at all */ @@ -284,7 +283,7 @@ void popup_delay_show(ObPopup *self, gulong usec, gchar *text) self->a_text->surface.parent = self->a_bg; self->a_text->surface.parentx = textx; self->a_text->surface.parenty = texty; - XMoveResizeWindow(ob_display, self->text, textx, texty, textw, texth); + XMoveResizeWindow(obt_display, self->text, textx, texty, textw, texth); RrPaint(self->a_text, self->text, textw, texth); } @@ -296,9 +295,9 @@ void popup_delay_show(ObPopup *self, gulong usec, gchar *text) if (usec) { /* don't kill previous show timers */ if (!self->delay_mapped) { - ob_main_loop_timeout_add(ob_main_loop, usec, - popup_show_timeout, self, - g_direct_equal, NULL); + obt_main_loop_timeout_add(ob_main_loop, usec, + popup_show_timeout, self, + g_direct_equal, NULL); self->delay_mapped = TRUE; } } else { @@ -315,12 +314,12 @@ void popup_hide(ObPopup *self) /* kill enter events cause by this unmapping */ ignore_start = event_start_ignore_all_enters(); - XUnmapWindow(ob_display, self->bg); + XUnmapWindow(obt_display, self->bg); self->mapped = FALSE; event_end_ignore_all_enters(ignore_start); } else if (self->delay_mapped) { - ob_main_loop_timeout_remove(ob_main_loop, popup_show_timeout); + obt_main_loop_timeout_remove(ob_main_loop, popup_show_timeout); self->delay_mapped = FALSE; } } @@ -332,7 +331,7 @@ static void icon_popup_draw_icon(gint x, gint y, gint w, gint h, gpointer data) self->a_icon->surface.parent = self->popup->a_bg; self->a_icon->surface.parentx = x; self->a_icon->surface.parenty = y; - XMoveResizeWindow(ob_display, self->icon, x, y, w, h); + XMoveResizeWindow(obt_display, self->icon, x, y, w, h); RrPaint(self->a_icon, self->icon, w, h); } @@ -343,11 +342,11 @@ ObIconPopup *icon_popup_new(void) self = g_new0(ObIconPopup, 1); self->popup = popup_new(); self->a_icon = RrAppearanceCopy(ob_rr_theme->a_clear_tex); - self->icon = XCreateWindow(ob_display, self->popup->bg, + self->icon = XCreateWindow(obt_display, self->popup->bg, 0, 0, 1, 1, 0, RrDepth(ob_rr_inst), InputOutput, RrVisual(ob_rr_inst), 0, NULL); - XMapWindow(ob_display, self->icon); + XMapWindow(obt_display, self->icon); self->popup->hasicon = TRUE; self->popup->draw_icon = icon_popup_draw_icon; @@ -359,7 +358,7 @@ ObIconPopup *icon_popup_new(void) void icon_popup_free(ObIconPopup *self) { if (self) { - XDestroyWindow(ob_display, self->icon); + XDestroyWindow(obt_display, self->icon); RrAppearanceFree(self->a_icon); popup_free(self->popup); g_free(self); @@ -485,7 +484,7 @@ static void pager_popup_draw_icon(gint px, gint py, gint w, gint h, a->surface.parent = self->popup->a_bg; a->surface.parentx = x + px; a->surface.parenty = y + py; - XMoveResizeWindow(ob_display, self->wins[n], + XMoveResizeWindow(obt_display, self->wins[n], x + px, y + py, eachw, eachh); RrPaint(a, self->wins[n], eachw, eachh); } @@ -520,7 +519,7 @@ void pager_popup_free(ObPagerPopup *self) guint i; for (i = 0; i < self->desks; ++i) - XDestroyWindow(ob_display, self->wins[i]); + XDestroyWindow(obt_display, self->wins[i]); g_free(self->wins); RrAppearanceFree(self->hilight); RrAppearanceFree(self->unhilight); @@ -536,7 +535,7 @@ void pager_popup_delay_show(ObPagerPopup *self, gulong usec, if (screen_num_desktops < self->desks) for (i = screen_num_desktops; i < self->desks; ++i) - XDestroyWindow(ob_display, self->wins[i]); + XDestroyWindow(obt_display, self->wins[i]); if (screen_num_desktops != self->desks) self->wins = g_renew(Window, self->wins, screen_num_desktops); @@ -547,12 +546,12 @@ void pager_popup_delay_show(ObPagerPopup *self, gulong usec, attr.border_pixel = RrColorPixel(ob_rr_theme->osd_border_color); - self->wins[i] = XCreateWindow(ob_display, self->popup->bg, + self->wins[i] = XCreateWindow(obt_display, self->popup->bg, 0, 0, 1, 1, ob_rr_theme->obwidth, RrDepth(ob_rr_inst), InputOutput, RrVisual(ob_rr_inst), CWBorderPixel, &attr); - XMapWindow(ob_display, self->wins[i]); + XMapWindow(obt_display, self->wins[i]); } self->desks = screen_num_desktops; diff --git a/openbox/popup.h b/openbox/popup.h index 2b01ce2..503e277 100644 --- a/openbox/popup.h +++ b/openbox/popup.h @@ -77,7 +77,7 @@ struct _ObPagerPopup RrAppearance *unhilight; }; -ObPopup *popup_new(); +ObPopup *popup_new(void); void popup_free(ObPopup *self); /*! Position the popup. The gravity rules are not the same X uses for windows, @@ -105,7 +105,7 @@ void popup_hide(ObPopup *self); RrAppearance *popup_icon_appearance(ObPopup *self); -ObIconPopup *icon_popup_new(); +ObIconPopup *icon_popup_new(void); void icon_popup_free(ObIconPopup *self); #define icon_popup_show(s, t, i) icon_popup_delay_show((s),0,(t),(i)) @@ -124,7 +124,7 @@ void icon_popup_delay_show(ObIconPopup *self, gulong usec, #define icon_popup_set_text_align(p, j) popup_set_text_align((p)->popup,(j)) void icon_popup_icon_size_multiplier(ObIconPopup *self, guint wm, guint hm); -ObPagerPopup *pager_popup_new(); +ObPagerPopup *pager_popup_new(void); void pager_popup_free(ObPagerPopup *self); #define pager_popup_show(s, t, d) pager_popup_delay_show((s),0,(t),(d)) diff --git a/openbox/prompt.c b/openbox/prompt.c index 0278757..7c19bcb 100644 --- a/openbox/prompt.c +++ b/openbox/prompt.c @@ -19,12 +19,12 @@ #include "prompt.h" #include "openbox.h" #include "screen.h" -#include "openbox.h" #include "client.h" #include "group.h" -#include "prop.h" -#include "modkeys.h" #include "event.h" +#include "obt/display.h" +#include "obt/keyboard.h" +#include "obt/prop.h" #include "gettext.h" static GList *prompt_list = NULL; @@ -145,9 +145,8 @@ ObPrompt* prompt_new(const gchar *msg, self->data = data; self->default_result = default_result; self->cancel_result = cancel_result; - self->super.type = Window_Prompt; - self->super.window = XCreateWindow(ob_display, - RootWindow(ob_display, ob_screen), + self->super.type = OB_WINDOW_CLASS_PROMPT; + self->super.window = XCreateWindow(obt_display, obt_root(ob_screen), 0, 0, 1, 1, 0, CopyFromParent, InputOutput, CopyFromParent, @@ -155,19 +154,19 @@ ObPrompt* prompt_new(const gchar *msg, &attrib); /* make it a dialog type window */ - PROP_SET32(self->super.window, net_wm_window_type, atom, - prop_atoms.net_wm_window_type_dialog); + OBT_PROP_SET32(self->super.window, NET_WM_WINDOW_TYPE, ATOM, + OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DIALOG)); /* listen for key presses on the window */ self->event_mask = KeyPressMask; /* set up the text message widow */ self->msg.text = g_strdup(msg); - self->msg.window = XCreateWindow(ob_display, self->super.window, + self->msg.window = XCreateWindow(obt_display, self->super.window, 0, 0, 1, 1, 0, CopyFromParent, InputOutput, CopyFromParent, 0, NULL); - XMapWindow(ob_display, self->msg.window); + XMapWindow(obt_display, self->msg.window); /* set up the buttons from the answers */ @@ -190,16 +189,15 @@ ObPrompt* prompt_new(const gchar *msg, } for (i = 0; i < self->n_buttons; ++i) { - self->button[i].window = XCreateWindow(ob_display, self->super.window, + self->button[i].window = XCreateWindow(obt_display, self->super.window, 0, 0, 1, 1, 0, CopyFromParent, InputOutput, CopyFromParent, 0, NULL); - XMapWindow(ob_display, self->button[i].window); - g_hash_table_insert(window_map, &self->button[i].window, - PROMPT_AS_WINDOW(self)); + XMapWindow(obt_display, self->button[i].window); + window_add(&self->button[i].window, PROMPT_AS_WINDOW(self)); /* listen for button presses on the buttons */ - XSelectInput(ob_display, self->button[i].window, + XSelectInput(obt_display, self->button[i].window, ButtonPressMask | ButtonReleaseMask | ButtonMotionMask); } @@ -221,12 +219,12 @@ void prompt_unref(ObPrompt *self) prompt_list = g_list_remove(prompt_list, self); for (i = 0; i < self->n_buttons; ++i) { - g_hash_table_remove(window_map, &self->button[i].window); - XDestroyWindow(ob_display, self->button[i].window); + window_remove(self->button[i].window); + XDestroyWindow(obt_display, self->button[i].window); } - XDestroyWindow(ob_display, self->msg.window); - XDestroyWindow(ob_display, self->super.window); + XDestroyWindow(obt_display, self->msg.window); + XDestroyWindow(obt_display, self->super.window); g_free(self); } } @@ -309,11 +307,11 @@ static void prompt_layout(ObPrompt *self) prompt_resize(self, w + l + r, h + t + b); /* move and resize the internal windows */ - XMoveResizeWindow(ob_display, self->msg.window, + XMoveResizeWindow(obt_display, self->msg.window, self->msg.x, self->msg.y, self->msg.width, self->msg.height); for (i = 0; i < self->n_buttons; ++i) - XMoveResizeWindow(ob_display, self->button[i].window, + XMoveResizeWindow(obt_display, self->button[i].window, self->button[i].x, self->button[i].y, self->button[i].width, self->button[i].height); } @@ -330,13 +328,13 @@ static void prompt_resize(ObPrompt *self, gint w, gint h) hints.flags = PMinSize | PMaxSize; hints.min_width = hints.max_width = w; hints.min_height = hints.max_height = h; - XSetWMNormalHints(ob_display, self->super.window, &hints); + XSetWMNormalHints(obt_display, self->super.window, &hints); if (self->mapped) { /* send a configure request like a normal client would */ req.type = ConfigureRequest; - req.display = ob_display; - req.parent = RootWindow(ob_display, ob_screen); + req.display = obt_display; + req.parent = obt_root(ob_screen); req.window = self->super.window; req.width = w; req.height = h; @@ -345,7 +343,7 @@ static void prompt_resize(ObPrompt *self, gint w, gint h) (XEvent*)&req); } else - XResizeWindow(ob_display, self->super.window, w, h); + XResizeWindow(obt_display, self->super.window, w, h); } static void setup_button_focus_tex(ObPromptElement *e, RrAppearance *a, @@ -439,11 +437,11 @@ void prompt_show(ObPrompt *self, ObClient *parent, gboolean modal) if (self->mapped) { /* activate the prompt */ - PROP_MSG(self->super.window, net_active_window, - 1, /* from an application.. */ - event_curtime, - 0, - 0); + OBT_PROP_MSG(ob_screen, self->super.window, NET_ACTIVE_WINDOW, + 1, /* from an application.. */ + event_curtime, + 0, + 0, 0); return; } @@ -465,7 +463,7 @@ void prompt_show(ObPrompt *self, ObClient *parent, gboolean modal) /* make it transient for the window's group */ h.flags = WindowGroupHint; h.window_group = parent->group->leader; - p = RootWindow(ob_display, ob_screen); + p = obt_root(ob_screen); } else { /* make it transient for the window directly */ @@ -473,15 +471,16 @@ void prompt_show(ObPrompt *self, ObClient *parent, gboolean modal) p = parent->window; } - XSetWMHints(ob_display, self->super.window, &h); - PROP_SET32(self->super.window, wm_transient_for, window, p); + XSetWMHints(obt_display, self->super.window, &h); + OBT_PROP_SET32(self->super.window, WM_TRANSIENT_FOR, WINDOW, p); - states[0] = prop_atoms.net_wm_state_modal; + states[0] = OBT_PROP_ATOM(NET_WM_STATE_MODAL); nstates = (modal ? 1 : 0); - PROP_SETA32(self->super.window, net_wm_state, atom, states, nstates); + OBT_PROP_SETA32(self->super.window, NET_WM_STATE, ATOM, + states, nstates); } else - PROP_ERASE(self->super.window, wm_transient_for); + OBT_PROP_ERASE(self->super.window, WM_TRANSIENT_FOR); /* set up the dialog and render it */ prompt_layout(self); @@ -494,7 +493,7 @@ void prompt_show(ObPrompt *self, ObClient *parent, gboolean modal) void prompt_hide(ObPrompt *self) { - XUnmapWindow(ob_display, self->super.window); + XUnmapWindow(obt_display, self->super.window); self->mapped = FALSE; } @@ -505,7 +504,7 @@ gboolean prompt_key_event(ObPrompt *self, XEvent *e) if (e->type != KeyPress) return FALSE; - shift_mask = modkeys_key_to_mask(OB_MODKEY_KEY_SHIFT); + shift_mask = obt_keyboard_modkey_to_modmask(OBT_KEYBOARD_MODKEY_SHIFT); shift = !!(e->xkey.state & shift_mask); /* only accept shift */ diff --git a/openbox/prompt.h b/openbox/prompt.h index 89d3d59..107aafd 100644 --- a/openbox/prompt.h +++ b/openbox/prompt.h @@ -42,7 +42,7 @@ struct _ObPromptElement { struct _ObPrompt { - InternalWindow super; + ObInternalWindow super; gint ref; guint event_mask; diff --git a/openbox/prop.c b/openbox/prop.c deleted file mode 100644 index 5dc4a2f..0000000 --- a/openbox/prop.c +++ /dev/null @@ -1,473 +0,0 @@ -/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- - - prop.c for the Openbox window manager - Copyright (c) 2006 Mikael Magnusson - Copyright (c) 2003-2007 Dana Jansens - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - See the COPYING file for a copy of the GNU General Public License. -*/ - -#include "prop.h" -#include "openbox.h" - -#include - -Atoms prop_atoms; - -#define CREATE(var, name) (prop_atoms.var = \ - XInternAtom(ob_display, name, FALSE)) - -void prop_startup(void) -{ - CREATE(cardinal, "CARDINAL"); - CREATE(window, "WINDOW"); - CREATE(pixmap, "PIXMAP"); - CREATE(atom, "ATOM"); - CREATE(string, "STRING"); - CREATE(utf8, "UTF8_STRING"); - - CREATE(manager, "MANAGER"); - - CREATE(wm_colormap_windows, "WM_COLORMAP_WINDOWS"); - CREATE(wm_protocols, "WM_PROTOCOLS"); - CREATE(wm_state, "WM_STATE"); - CREATE(wm_change_state, "WM_CHANGE_STATE"); - CREATE(wm_delete_window, "WM_DELETE_WINDOW"); - CREATE(wm_take_focus, "WM_TAKE_FOCUS"); - CREATE(wm_name, "WM_NAME"); - CREATE(wm_icon_name, "WM_ICON_NAME"); - CREATE(wm_class, "WM_CLASS"); - CREATE(wm_window_role, "WM_WINDOW_ROLE"); - CREATE(wm_client_machine, "WM_CLIENT_MACHINE"); - CREATE(wm_command, "WM_COMMAND"); - CREATE(wm_client_leader, "WM_CLIENT_LEADER"); - CREATE(wm_transient_for, "WM_TRANSIENT_FOR"); - CREATE(motif_wm_hints, "_MOTIF_WM_HINTS"); - - CREATE(sm_client_id, "SM_CLIENT_ID"); - - CREATE(net_wm_full_placement, "_NET_WM_FULL_PLACEMENT"); - - CREATE(net_supported, "_NET_SUPPORTED"); - CREATE(net_client_list, "_NET_CLIENT_LIST"); - CREATE(net_client_list_stacking, "_NET_CLIENT_LIST_STACKING"); - CREATE(net_number_of_desktops, "_NET_NUMBER_OF_DESKTOPS"); - CREATE(net_desktop_geometry, "_NET_DESKTOP_GEOMETRY"); - CREATE(net_desktop_viewport, "_NET_DESKTOP_VIEWPORT"); - CREATE(net_current_desktop, "_NET_CURRENT_DESKTOP"); - CREATE(net_desktop_names, "_NET_DESKTOP_NAMES"); - CREATE(net_active_window, "_NET_ACTIVE_WINDOW"); -/* CREATE(net_restack_window, "_NET_RESTACK_WINDOW");*/ - CREATE(net_workarea, "_NET_WORKAREA"); - CREATE(net_supporting_wm_check, "_NET_SUPPORTING_WM_CHECK"); - CREATE(net_desktop_layout, "_NET_DESKTOP_LAYOUT"); - CREATE(net_showing_desktop, "_NET_SHOWING_DESKTOP"); - - CREATE(net_close_window, "_NET_CLOSE_WINDOW"); - CREATE(net_wm_moveresize, "_NET_WM_MOVERESIZE"); - CREATE(net_moveresize_window, "_NET_MOVERESIZE_WINDOW"); - CREATE(net_request_frame_extents, "_NET_REQUEST_FRAME_EXTENTS"); - CREATE(net_restack_window, "_NET_RESTACK_WINDOW"); - - CREATE(net_startup_id, "_NET_STARTUP_ID"); - - CREATE(net_wm_name, "_NET_WM_NAME"); - CREATE(net_wm_visible_name, "_NET_WM_VISIBLE_NAME"); - CREATE(net_wm_icon_name, "_NET_WM_ICON_NAME"); - CREATE(net_wm_visible_icon_name, "_NET_WM_VISIBLE_ICON_NAME"); - CREATE(net_wm_desktop, "_NET_WM_DESKTOP"); - CREATE(net_wm_window_type, "_NET_WM_WINDOW_TYPE"); - CREATE(net_wm_state, "_NET_WM_STATE"); - CREATE(net_wm_strut, "_NET_WM_STRUT"); - CREATE(net_wm_strut_partial, "_NET_WM_STRUT_PARTIAL"); - CREATE(net_wm_icon, "_NET_WM_ICON"); - CREATE(net_wm_icon_geometry, "_NET_WM_ICON_GEOMETRY"); - CREATE(net_wm_pid, "_NET_WM_PID"); - CREATE(net_wm_allowed_actions, "_NET_WM_ALLOWED_ACTIONS"); - CREATE(net_wm_user_time, "_NET_WM_USER_TIME"); -/* CREATE(net_wm_user_time_window, "_NET_WM_USER_TIME_WINDOW"); */ - CREATE(kde_net_wm_frame_strut, "_KDE_NET_WM_FRAME_STRUT"); - CREATE(net_frame_extents, "_NET_FRAME_EXTENTS"); - - CREATE(net_wm_ping, "_NET_WM_PING"); -#ifdef SYNC - CREATE(net_wm_sync_request, "_NET_WM_SYNC_REQUEST"); - CREATE(net_wm_sync_request_counter, "_NET_WM_SYNC_REQUEST_COUNTER"); -#endif - - CREATE(net_wm_window_type_desktop, "_NET_WM_WINDOW_TYPE_DESKTOP"); - CREATE(net_wm_window_type_dock, "_NET_WM_WINDOW_TYPE_DOCK"); - CREATE(net_wm_window_type_toolbar, "_NET_WM_WINDOW_TYPE_TOOLBAR"); - CREATE(net_wm_window_type_menu, "_NET_WM_WINDOW_TYPE_MENU"); - CREATE(net_wm_window_type_utility, "_NET_WM_WINDOW_TYPE_UTILITY"); - CREATE(net_wm_window_type_splash, "_NET_WM_WINDOW_TYPE_SPLASH"); - CREATE(net_wm_window_type_dialog, "_NET_WM_WINDOW_TYPE_DIALOG"); - CREATE(net_wm_window_type_normal, "_NET_WM_WINDOW_TYPE_NORMAL"); - CREATE(net_wm_window_type_popup_menu, "_NET_WM_WINDOW_TYPE_POPUP_MENU"); - - prop_atoms.net_wm_moveresize_size_topleft = 0; - prop_atoms.net_wm_moveresize_size_top = 1; - prop_atoms.net_wm_moveresize_size_topright = 2; - prop_atoms.net_wm_moveresize_size_right = 3; - prop_atoms.net_wm_moveresize_size_bottomright = 4; - prop_atoms.net_wm_moveresize_size_bottom = 5; - prop_atoms.net_wm_moveresize_size_bottomleft = 6; - prop_atoms.net_wm_moveresize_size_left = 7; - prop_atoms.net_wm_moveresize_move = 8; - prop_atoms.net_wm_moveresize_size_keyboard = 9; - prop_atoms.net_wm_moveresize_move_keyboard = 10; - prop_atoms.net_wm_moveresize_cancel = 11; - - CREATE(net_wm_action_move, "_NET_WM_ACTION_MOVE"); - CREATE(net_wm_action_resize, "_NET_WM_ACTION_RESIZE"); - CREATE(net_wm_action_minimize, "_NET_WM_ACTION_MINIMIZE"); - CREATE(net_wm_action_shade, "_NET_WM_ACTION_SHADE"); - CREATE(net_wm_action_maximize_horz, "_NET_WM_ACTION_MAXIMIZE_HORZ"); - CREATE(net_wm_action_maximize_vert, "_NET_WM_ACTION_MAXIMIZE_VERT"); - CREATE(net_wm_action_fullscreen, "_NET_WM_ACTION_FULLSCREEN"); - CREATE(net_wm_action_change_desktop, "_NET_WM_ACTION_CHANGE_DESKTOP"); - CREATE(net_wm_action_close, "_NET_WM_ACTION_CLOSE"); - CREATE(net_wm_action_above, "_NET_WM_ACTION_ABOVE"); - CREATE(net_wm_action_below, "_NET_WM_ACTION_BELOW"); - - CREATE(net_wm_state_modal, "_NET_WM_STATE_MODAL"); -/* CREATE(net_wm_state_sticky, "_NET_WM_STATE_STICKY");*/ - CREATE(net_wm_state_maximized_vert, "_NET_WM_STATE_MAXIMIZED_VERT"); - CREATE(net_wm_state_maximized_horz, "_NET_WM_STATE_MAXIMIZED_HORZ"); - CREATE(net_wm_state_shaded, "_NET_WM_STATE_SHADED"); - CREATE(net_wm_state_skip_taskbar, "_NET_WM_STATE_SKIP_TASKBAR"); - CREATE(net_wm_state_skip_pager, "_NET_WM_STATE_SKIP_PAGER"); - CREATE(net_wm_state_hidden, "_NET_WM_STATE_HIDDEN"); - CREATE(net_wm_state_fullscreen, "_NET_WM_STATE_FULLSCREEN"); - CREATE(net_wm_state_above, "_NET_WM_STATE_ABOVE"); - CREATE(net_wm_state_below, "_NET_WM_STATE_BELOW"); - CREATE(net_wm_state_demands_attention, "_NET_WM_STATE_DEMANDS_ATTENTION"); - - prop_atoms.net_wm_state_add = 1; - prop_atoms.net_wm_state_remove = 0; - prop_atoms.net_wm_state_toggle = 2; - - prop_atoms.net_wm_orientation_horz = 0; - prop_atoms.net_wm_orientation_vert = 1; - prop_atoms.net_wm_topleft = 0; - prop_atoms.net_wm_topright = 1; - prop_atoms.net_wm_bottomright = 2; - prop_atoms.net_wm_bottomleft = 3; - - CREATE(kde_wm_change_state, "_KDE_WM_CHANGE_STATE"); - CREATE(kde_net_wm_window_type_override,"_KDE_NET_WM_WINDOW_TYPE_OVERRIDE"); - -/* - CREATE(rootpmapid, "_XROOTPMAP_ID"); - CREATE(esetrootid, "ESETROOT_PMAP_ID"); -*/ - - CREATE(openbox_pid, "_OPENBOX_PID"); - CREATE(ob_theme, "_OB_THEME"); - CREATE(ob_config_file, "_OB_CONFIG_FILE"); - CREATE(ob_wm_action_undecorate, "_OB_WM_ACTION_UNDECORATE"); - CREATE(ob_wm_state_undecorated, "_OB_WM_STATE_UNDECORATED"); - CREATE(ob_control, "_OB_CONTROL"); -} - -#include -#include -#include - -/* this just isn't used... and it also breaks on 64bit, watch out -static gboolean get(Window win, Atom prop, Atom type, gint size, - guchar **data, gulong num) -{ - gboolean ret = FALSE; - gint res; - guchar *xdata = NULL; - Atom ret_type; - gint ret_size; - gulong ret_items, bytes_left; - glong num32 = 32 / size * num; /\* num in 32-bit elements *\/ - - res = XGetWindowProperty(display, win, prop, 0l, num32, - FALSE, type, &ret_type, &ret_size, - &ret_items, &bytes_left, &xdata); - if (res == Success && ret_items && xdata) { - if (ret_size == size && ret_items >= num) { - *data = g_memdup(xdata, num * (size / 8)); - ret = TRUE; - } - XFree(xdata); - } - return ret; -} -*/ - -static gboolean get_prealloc(Window win, Atom prop, Atom type, gint size, - guchar *data, gulong num) -{ - gboolean ret = FALSE; - gint res; - guchar *xdata = NULL; - Atom ret_type; - gint ret_size; - gulong ret_items, bytes_left; - glong num32 = 32 / size * num; /* num in 32-bit elements */ - - res = XGetWindowProperty(ob_display, win, prop, 0l, num32, - FALSE, type, &ret_type, &ret_size, - &ret_items, &bytes_left, &xdata); - if (res == Success && ret_items && xdata) { - if (ret_size == size && ret_items >= num) { - guint i; - for (i = 0; i < num; ++i) - switch (size) { - case 8: - data[i] = xdata[i]; - break; - case 16: - ((guint16*)data)[i] = ((gushort*)xdata)[i]; - break; - case 32: - ((guint32*)data)[i] = ((gulong*)xdata)[i]; - break; - default: - g_assert_not_reached(); /* unhandled size */ - } - ret = TRUE; - } - XFree(xdata); - } - return ret; -} - -static gboolean get_all(Window win, Atom prop, Atom type, gint size, - guchar **data, guint *num) -{ - gboolean ret = FALSE; - gint res; - guchar *xdata = NULL; - Atom ret_type; - gint ret_size; - gulong ret_items, bytes_left; - - res = XGetWindowProperty(ob_display, win, prop, 0l, G_MAXLONG, - FALSE, type, &ret_type, &ret_size, - &ret_items, &bytes_left, &xdata); - if (res == Success) { - if (ret_size == size && ret_items > 0) { - guint i; - - *data = g_malloc(ret_items * (size / 8)); - for (i = 0; i < ret_items; ++i) - switch (size) { - case 8: - (*data)[i] = xdata[i]; - break; - case 16: - ((guint16*)*data)[i] = ((gushort*)xdata)[i]; - break; - case 32: - ((guint32*)*data)[i] = ((gulong*)xdata)[i]; - break; - default: - g_assert_not_reached(); /* unhandled size */ - } - *num = ret_items; - ret = TRUE; - } - XFree(xdata); - } - return ret; -} - -static gboolean get_stringlist(Window win, Atom prop, gchar ***list, gint *nstr) -{ - XTextProperty tprop; - gboolean ret = FALSE; - - if (XGetTextProperty(ob_display, win, &tprop, prop) && tprop.nitems) { - if (XTextPropertyToStringList(&tprop, list, nstr)) - ret = TRUE; - XFree(tprop.value); - } - return ret; -} - -gboolean prop_get32(Window win, Atom prop, Atom type, guint32 *ret) -{ - return get_prealloc(win, prop, type, 32, (guchar*)ret, 1); -} - -gboolean prop_get_array32(Window win, Atom prop, Atom type, guint32 **ret, - guint *nret) -{ - return get_all(win, prop, type, 32, (guchar**)ret, nret); -} - -gboolean prop_get_string_locale(Window win, Atom prop, gchar **ret) -{ - gchar **list; - gint nstr; - gchar *s; - - if (get_stringlist(win, prop, &list, &nstr) && nstr) { - s = g_locale_to_utf8(list[0], -1, NULL, NULL, NULL); - XFreeStringList(list); - if (s) { - *ret = s; - return TRUE; - } - } - return FALSE; -} - -gboolean prop_get_strings_locale(Window win, Atom prop, gchar ***ret) -{ - GSList *strs = NULL, *it; - gchar *raw, *p; - guint num, i, count = 0; - - if (get_all(win, prop, prop_atoms.string, 8, (guchar**)&raw, &num)) { - - p = raw; - while (p < raw + num) { - ++count; - strs = g_slist_append(strs, p); - p += strlen(p) + 1; /* next string */ - } - - *ret = g_new0(gchar*, count + 1); - (*ret)[count] = NULL; /* null terminated list */ - - for (i = 0, it = strs; it; ++i, it = g_slist_next(it)) { - (*ret)[i] = g_locale_to_utf8(it->data, -1, NULL, NULL, NULL); - /* make sure translation did not fail */ - if (!(*ret)[i]) - (*ret)[i] = g_strdup(""); - } - g_free(raw); - g_slist_free(strs); - return TRUE; - } - return FALSE; -} - -gboolean prop_get_string_utf8(Window win, Atom prop, gchar **ret) -{ - gchar *raw; - gchar *str; - guint num; - - if (get_all(win, prop, prop_atoms.utf8, 8, (guchar**)&raw, &num)) { - str = g_strndup(raw, num); /* grab the first string from the list */ - g_free(raw); - if (g_utf8_validate(str, -1, NULL)) { - *ret = str; - return TRUE; - } - g_free(str); - } - return FALSE; -} - -gboolean prop_get_strings_utf8(Window win, Atom prop, gchar ***ret) -{ - GSList *strs = NULL, *it; - gchar *raw, *p; - guint num, i, count = 0; - - if (get_all(win, prop, prop_atoms.utf8, 8, (guchar**)&raw, &num)) { - - p = raw; - while (p < raw + num) { - ++count; - strs = g_slist_append(strs, p); - p += strlen(p) + 1; /* next string */ - } - - *ret = g_new0(gchar*, count + 1); - - for (i = 0, it = strs; it; ++i, it = g_slist_next(it)) { - if (g_utf8_validate(it->data, -1, NULL)) - (*ret)[i] = g_strdup(it->data); - else - (*ret)[i] = g_strdup(""); - } - g_free(raw); - g_slist_free(strs); - return TRUE; - } - return FALSE; -} - -void prop_set32(Window win, Atom prop, Atom type, gulong val) -{ - XChangeProperty(ob_display, win, prop, type, 32, PropModeReplace, - (guchar*)&val, 1); -} - -void prop_set_array32(Window win, Atom prop, Atom type, gulong *val, - guint num) -{ - XChangeProperty(ob_display, win, prop, type, 32, PropModeReplace, - (guchar*)val, num); -} - -void prop_set_string_utf8(Window win, Atom prop, const gchar *val) -{ - XChangeProperty(ob_display, win, prop, prop_atoms.utf8, 8, - PropModeReplace, (const guchar*)val, strlen(val)); -} - -void prop_set_strings_utf8(Window win, Atom prop, gchar **strs) -{ - GString *str; - gchar **s; - - str = g_string_sized_new(0); - for (s = strs; *s; ++s) { - str = g_string_append(str, *s); - str = g_string_append_c(str, '\0'); - } - XChangeProperty(ob_display, win, prop, prop_atoms.utf8, 8, - PropModeReplace, (guchar*)str->str, str->len); - g_string_free(str, TRUE); -} - -void prop_erase(Window win, Atom prop) -{ - XDeleteProperty(ob_display, win, prop); -} - -void prop_message(Window about, Atom messagetype, glong data0, glong data1, - glong data2, glong data3, glong mask) -{ - prop_message_to(RootWindow(ob_display, ob_screen), about, messagetype, - data0, data1, data2, data3, 0, mask); -} - -void prop_message_to(Window to, Window about, Atom messagetype, - glong data0, glong data1, glong data2, - glong data3, glong data4, glong mask) -{ - XEvent ce; - ce.xclient.type = ClientMessage; - ce.xclient.message_type = messagetype; - ce.xclient.display = ob_display; - ce.xclient.window = about; - ce.xclient.format = 32; - ce.xclient.data.l[0] = data0; - ce.xclient.data.l[1] = data1; - ce.xclient.data.l[2] = data2; - ce.xclient.data.l[3] = data3; - ce.xclient.data.l[4] = data4; - XSendEvent(ob_display, to, FALSE, mask, &ce); -} diff --git a/openbox/prop.h b/openbox/prop.h deleted file mode 100644 index 46c9301..0000000 --- a/openbox/prop.h +++ /dev/null @@ -1,261 +0,0 @@ -/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- - - prop.h for the Openbox window manager - Copyright (c) 2006 Mikael Magnusson - Copyright (c) 2003-2007 Dana Jansens - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - See the COPYING file for a copy of the GNU General Public License. -*/ - -#ifndef __atoms_h -#define __atoms_h - -#include -#include -#ifdef HAVE_STRING_H -# include -#endif - -/*! The atoms on the X server which this class will cache */ -typedef struct Atoms { - /* types */ - Atom cardinal; /*!< The atom which represents the Cardinal data type */ - Atom window; /*!< The atom which represents window ids */ - Atom pixmap; /*!< The atom which represents pixmap ids */ - Atom atom; /*!< The atom which represents atom values */ - Atom string; /*!< The atom which represents ascii strings */ - Atom utf8; /*!< The atom which represents utf8-encoded strings */ - - /* selection stuff */ - Atom manager; - - /* window hints */ - Atom wm_colormap_windows; - Atom wm_protocols; - Atom wm_state; - Atom wm_delete_window; - Atom wm_take_focus; - Atom wm_change_state; - Atom wm_name; - Atom wm_icon_name; - Atom wm_class; - Atom wm_window_role; - Atom wm_client_machine; - Atom wm_command; - Atom wm_client_leader; - Atom wm_transient_for; - Atom motif_wm_hints; - - /* SM atoms */ - Atom sm_client_id; - - /* NETWM atoms */ - - /* Atoms that are used inside messages - these don't go in net_supported */ - - Atom net_wm_moveresize_size_topleft; - Atom net_wm_moveresize_size_top; - Atom net_wm_moveresize_size_topright; - Atom net_wm_moveresize_size_right; - Atom net_wm_moveresize_size_bottomright; - Atom net_wm_moveresize_size_bottom; - Atom net_wm_moveresize_size_bottomleft; - Atom net_wm_moveresize_size_left; - Atom net_wm_moveresize_move; - Atom net_wm_moveresize_size_keyboard; - Atom net_wm_moveresize_move_keyboard; - Atom net_wm_moveresize_cancel; - - Atom net_wm_state_add; - Atom net_wm_state_remove; - Atom net_wm_state_toggle; - - Atom net_wm_orientation_horz; - Atom net_wm_orientation_vert; - Atom net_wm_topleft; - Atom net_wm_topright; - Atom net_wm_bottomright; - Atom net_wm_bottomleft; - - /* types that we use but don't support */ - - Atom net_wm_window_type_popup_menu; - - /* Everything below here must go in net_supported on the root window */ - - /* root window properties */ - Atom net_supported; - Atom net_client_list; - Atom net_client_list_stacking; - Atom net_number_of_desktops; - Atom net_desktop_geometry; - Atom net_desktop_viewport; - Atom net_current_desktop; - Atom net_desktop_names; - Atom net_active_window; -/* Atom net_restack_window;*/ - Atom net_workarea; - Atom net_supporting_wm_check; - Atom net_desktop_layout; - Atom net_showing_desktop; - - /* root window messages */ - Atom net_close_window; - Atom net_wm_moveresize; - Atom net_moveresize_window; - Atom net_request_frame_extents; - Atom net_restack_window; - - /* helpful hints to apps that aren't used for anything */ - Atom net_wm_full_placement; - - /* startup-notification extension */ - Atom net_startup_id; - - /* application window properties */ - Atom net_wm_name; - Atom net_wm_visible_name; - Atom net_wm_icon_name; - Atom net_wm_visible_icon_name; - Atom net_wm_desktop; - Atom net_wm_window_type; - Atom net_wm_state; - Atom net_wm_strut; - Atom net_wm_strut_partial; - Atom net_wm_icon; - Atom net_wm_icon_geometry; - Atom net_wm_pid; - Atom net_wm_allowed_actions; - Atom net_wm_user_time; -/* Atom net_wm_user_time_window; */ - Atom net_frame_extents; - - /* application protocols */ - Atom net_wm_ping; -#ifdef SYNC - Atom net_wm_sync_request; - Atom net_wm_sync_request_counter; -#endif - - Atom net_wm_window_type_desktop; - Atom net_wm_window_type_dock; - Atom net_wm_window_type_toolbar; - Atom net_wm_window_type_menu; - Atom net_wm_window_type_utility; - Atom net_wm_window_type_splash; - Atom net_wm_window_type_dialog; - Atom net_wm_window_type_normal; - - Atom net_wm_action_move; - Atom net_wm_action_resize; - Atom net_wm_action_minimize; - Atom net_wm_action_shade; -/* Atom net_wm_action_stick;*/ - Atom net_wm_action_maximize_horz; - Atom net_wm_action_maximize_vert; - Atom net_wm_action_fullscreen; - Atom net_wm_action_change_desktop; - Atom net_wm_action_close; - Atom net_wm_action_above; - Atom net_wm_action_below; - - Atom net_wm_state_modal; -/* Atom net_wm_state_sticky;*/ - Atom net_wm_state_maximized_vert; - Atom net_wm_state_maximized_horz; - Atom net_wm_state_shaded; - Atom net_wm_state_skip_taskbar; - Atom net_wm_state_skip_pager; - Atom net_wm_state_hidden; - Atom net_wm_state_fullscreen; - Atom net_wm_state_above; - Atom net_wm_state_below; - Atom net_wm_state_demands_attention; - - /* KDE atoms */ - - Atom kde_wm_change_state; - Atom kde_net_wm_frame_strut; - Atom kde_net_wm_window_type_override; - -/* - Atom rootpmapid; - Atom esetrootid; -*/ - - /* Openbox specific atoms */ - - Atom ob_wm_action_undecorate; - Atom ob_wm_state_undecorated; - Atom openbox_pid; /* this is depreecated in favour of ob_control */ - Atom ob_theme; - Atom ob_config_file; - Atom ob_control; -} Atoms; -extern Atoms prop_atoms; - -void prop_startup(); - -gboolean prop_get32(Window win, Atom prop, Atom type, guint32 *ret); -gboolean prop_get_array32(Window win, Atom prop, Atom type, guint32 **ret, - guint *nret); -gboolean prop_get_string_locale(Window win, Atom prop, gchar **ret); -gboolean prop_get_string_utf8(Window win, Atom prop, gchar **ret); -gboolean prop_get_strings_locale(Window win, Atom prop, gchar ***ret); -gboolean prop_get_strings_utf8(Window win, Atom prop, gchar ***ret); - -void prop_set32(Window win, Atom prop, Atom type, gulong val); -void prop_set_array32(Window win, Atom prop, Atom type, gulong *val, - guint num); -void prop_set_string_utf8(Window win, Atom prop, const gchar *val); -void prop_set_strings_utf8(Window win, Atom prop, gchar **strs); - -void prop_erase(Window win, Atom prop); - -void prop_message(Window about, Atom messagetype, glong data0, glong data1, - glong data2, glong data3, glong mask); -void prop_message_to(Window to, Window about, Atom messagetype, - glong data0, glong data1, glong data2, - glong data3, glong data4, glong mask); - -#define PROP_GET32(win, prop, type, ret) \ - (prop_get32(win, prop_atoms.prop, prop_atoms.type, ret)) -#define PROP_GETA32(win, prop, type, ret, nret) \ - (prop_get_array32(win, prop_atoms.prop, prop_atoms.type, ret, \ - nret)) -#define PROP_GETS(win, prop, type, ret) \ - (prop_get_string_##type(win, prop_atoms.prop, ret)) -#define PROP_GETSS(win, prop, type, ret) \ - (prop_get_strings_##type(win, prop_atoms.prop, ret)) - -#define PROP_SET32(win, prop, type, val) \ - prop_set32(win, prop_atoms.prop, prop_atoms.type, val) -#define PROP_SETA32(win, prop, type, val, num) \ - prop_set_array32(win, prop_atoms.prop, prop_atoms.type, val, num) -#define PROP_SETS(win, prop, val) \ - prop_set_string_utf8(win, prop_atoms.prop, val) -#define PROP_SETSS(win, prop, strs) \ - prop_set_strings_utf8(win, prop_atoms.prop, strs) - -#define PROP_ERASE(win, prop) prop_erase(win, prop_atoms.prop) - -#define PROP_MSG(about, msgtype, data0, data1, data2, data3) \ - (prop_message(about, prop_atoms.msgtype, data0, data1, data2, data3, \ - SubstructureNotifyMask | SubstructureRedirectMask)) - -#define PROP_MSG_TO(to, about, msgtype, data0, data1, data2, data3, data4, \ - mask) \ - (prop_message_to(to, about, prop_atoms.msgtype, \ - data0, data1, data2, data3, data4, mask)) - -#endif diff --git a/openbox/resist.c b/openbox/resist.c index f21eb8e..3bcb95f 100644 --- a/openbox/resist.c +++ b/openbox/resist.c @@ -17,14 +17,13 @@ See the COPYING file for a copy of the GNU General Public License. */ +#include "resist.h" #include "client.h" #include "frame.h" #include "stacking.h" #include "screen.h" #include "dock.h" #include "config.h" -#include "resist.h" -#include "parser/parse.h" #include diff --git a/openbox/resist.h b/openbox/resist.h index a2b3f16..31cc717 100644 --- a/openbox/resist.h +++ b/openbox/resist.h @@ -19,10 +19,12 @@ #ifndef ob__resist_h #define ob__resist_h -struct _ObClient; +#include "misc.h" #include +struct _ObClient; + /*! @x The client's x destination (in the client's coordinates, not the frame's @y The client's y destination (in the client's coordinates, not the frame's */ diff --git a/openbox/screen.c b/openbox/screen.c index 2e48f85..cd46c53 100644 --- a/openbox/screen.c +++ b/openbox/screen.c @@ -20,13 +20,10 @@ #include "debug.h" #include "openbox.h" #include "dock.h" -#include "xerror.h" -#include "prop.h" #include "grab.h" #include "startupnotify.h" #include "moveresize.h" #include "config.h" -#include "mainloop.h" #include "screen.h" #include "client.h" #include "session.h" @@ -34,9 +31,12 @@ #include "event.h" #include "focus.h" #include "popup.h" -#include "extensions.h" +#include "hooks.h" #include "render/render.h" #include "gettext.h" +#include "obt/display.h" +#include "obt/prop.h" +#include "obt/mainloop.h" #include #ifdef HAVE_UNISTD_H @@ -91,10 +91,10 @@ static gboolean replace_wm(void) Time timestamp; wm_sn = g_strdup_printf("WM_S%d", ob_screen); - wm_sn_atom = XInternAtom(ob_display, wm_sn, FALSE); + wm_sn_atom = XInternAtom(obt_display, wm_sn, FALSE); g_free(wm_sn); - current_wm_sn_owner = XGetSelectionOwner(ob_display, wm_sn_atom); + current_wm_sn_owner = XGetSelectionOwner(obt_display, wm_sn_atom); if (current_wm_sn_owner == screen_support_win) current_wm_sn_owner = None; if (current_wm_sn_owner) { @@ -103,24 +103,23 @@ static gboolean replace_wm(void) ob_screen); return FALSE; } - xerror_set_ignore(TRUE); - xerror_occured = FALSE; + obt_display_ignore_errors(TRUE); /* We want to find out when the current selection owner dies */ - XSelectInput(ob_display, current_wm_sn_owner, StructureNotifyMask); - XSync(ob_display, FALSE); + XSelectInput(obt_display, current_wm_sn_owner, StructureNotifyMask); + XSync(obt_display, FALSE); - xerror_set_ignore(FALSE); - if (xerror_occured) + obt_display_ignore_errors(FALSE); + if (obt_display_error_occured) current_wm_sn_owner = None; } timestamp = event_get_server_time(); - XSetSelectionOwner(ob_display, wm_sn_atom, screen_support_win, + XSetSelectionOwner(obt_display, wm_sn_atom, screen_support_win, timestamp); - if (XGetSelectionOwner(ob_display, wm_sn_atom) != screen_support_win) { + if (XGetSelectionOwner(obt_display, wm_sn_atom) != screen_support_win) { g_message(_("Could not acquire window manager selection on screen %d"), ob_screen); return FALSE; @@ -133,7 +132,7 @@ static gboolean replace_wm(void) const gulong timeout = G_USEC_PER_SEC * 15; /* wait for 15s max */ while (wait < timeout) { - if (XCheckWindowEvent(ob_display, current_wm_sn_owner, + if (XCheckWindowEvent(obt_display, current_wm_sn_owner, StructureNotifyMask, &event) && event.type == DestroyNotify) break; @@ -148,9 +147,9 @@ static gboolean replace_wm(void) } /* Send client message indicating that we are now the WM */ - prop_message(RootWindow(ob_display, ob_screen), prop_atoms.manager, - timestamp, wm_sn_atom, screen_support_win, 0, - SubstructureNotifyMask); + obt_prop_message(ob_screen, obt_root(ob_screen), OBT_PROP_ATOM(MANAGER), + timestamp, wm_sn_atom, screen_support_win, 0, 0, + SubstructureNotifyMask); return TRUE; } @@ -160,37 +159,33 @@ gboolean screen_annex(void) XSetWindowAttributes attrib; pid_t pid; gint i, num_support; - Atom *prop_atoms_start, *wm_supported_pos; gulong *supported; /* create the netwm support window */ attrib.override_redirect = TRUE; attrib.event_mask = PropertyChangeMask; - screen_support_win = XCreateWindow(ob_display, - RootWindow(ob_display, ob_screen), + screen_support_win = XCreateWindow(obt_display, obt_root(ob_screen), -100, -100, 1, 1, 0, CopyFromParent, InputOutput, CopyFromParent, CWEventMask | CWOverrideRedirect, &attrib); - XMapWindow(ob_display, screen_support_win); - XLowerWindow(ob_display, screen_support_win); + XMapWindow(obt_display, screen_support_win); + XLowerWindow(obt_display, screen_support_win); if (!replace_wm()) { - XDestroyWindow(ob_display, screen_support_win); + XDestroyWindow(obt_display, screen_support_win); return FALSE; } - xerror_set_ignore(TRUE); - xerror_occured = FALSE; - XSelectInput(ob_display, RootWindow(ob_display, ob_screen), - ROOT_EVENTMASK); - xerror_set_ignore(FALSE); - if (xerror_occured) { + obt_display_ignore_errors(TRUE); + XSelectInput(obt_display, obt_root(ob_screen), ROOT_EVENTMASK); + obt_display_ignore_errors(FALSE); + if (obt_display_error_occured) { g_message(_("A window manager is already running on screen %d"), ob_screen); - XDestroyWindow(ob_display, screen_support_win); + XDestroyWindow(obt_display, screen_support_win); return FALSE; } @@ -198,114 +193,110 @@ gboolean screen_annex(void) /* set the OPENBOX_PID hint */ pid = getpid(); - PROP_SET32(RootWindow(ob_display, ob_screen), - openbox_pid, cardinal, pid); + OBT_PROP_SET32(obt_root(ob_screen), OPENBOX_PID, CARDINAL, pid); /* set supporting window */ - PROP_SET32(RootWindow(ob_display, ob_screen), - net_supporting_wm_check, window, screen_support_win); + OBT_PROP_SET32(obt_root(ob_screen), + NET_SUPPORTING_WM_CHECK, WINDOW, screen_support_win); /* set properties on the supporting window */ - PROP_SETS(screen_support_win, net_wm_name, "Openbox"); - PROP_SET32(screen_support_win, net_supporting_wm_check, - window, screen_support_win); + OBT_PROP_SETS(screen_support_win, NET_WM_NAME, utf8, "Openbox"); + OBT_PROP_SET32(screen_support_win, NET_SUPPORTING_WM_CHECK, + WINDOW, screen_support_win); /* set the _NET_SUPPORTED_ATOMS hint */ - /* this is all the atoms after net_supported in the prop_atoms struct */ - prop_atoms_start = (Atom*)&prop_atoms; - wm_supported_pos = (Atom*)&(prop_atoms.net_supported); - num_support = sizeof(prop_atoms) / sizeof(Atom) - - (wm_supported_pos - prop_atoms_start) - 1; + /* this is all the atoms after NET_SUPPORTED in the ObtPropAtoms enum */ + num_support = OBT_PROP_NUM_ATOMS - OBT_PROP_NET_SUPPORTED - 1; i = 0; supported = g_new(gulong, num_support); - supported[i++] = prop_atoms.net_supporting_wm_check; - supported[i++] = prop_atoms.net_wm_full_placement; - supported[i++] = prop_atoms.net_current_desktop; - supported[i++] = prop_atoms.net_number_of_desktops; - supported[i++] = prop_atoms.net_desktop_geometry; - supported[i++] = prop_atoms.net_desktop_viewport; - supported[i++] = prop_atoms.net_active_window; - supported[i++] = prop_atoms.net_workarea; - supported[i++] = prop_atoms.net_client_list; - supported[i++] = prop_atoms.net_client_list_stacking; - supported[i++] = prop_atoms.net_desktop_names; - supported[i++] = prop_atoms.net_close_window; - supported[i++] = prop_atoms.net_desktop_layout; - supported[i++] = prop_atoms.net_showing_desktop; - supported[i++] = prop_atoms.net_wm_name; - supported[i++] = prop_atoms.net_wm_visible_name; - supported[i++] = prop_atoms.net_wm_icon_name; - supported[i++] = prop_atoms.net_wm_visible_icon_name; - supported[i++] = prop_atoms.net_wm_desktop; - supported[i++] = prop_atoms.net_wm_strut; - supported[i++] = prop_atoms.net_wm_strut_partial; - supported[i++] = prop_atoms.net_wm_icon; - supported[i++] = prop_atoms.net_wm_icon_geometry; - supported[i++] = prop_atoms.net_wm_window_type; - supported[i++] = prop_atoms.net_wm_window_type_desktop; - supported[i++] = prop_atoms.net_wm_window_type_dock; - supported[i++] = prop_atoms.net_wm_window_type_toolbar; - supported[i++] = prop_atoms.net_wm_window_type_menu; - supported[i++] = prop_atoms.net_wm_window_type_utility; - supported[i++] = prop_atoms.net_wm_window_type_splash; - supported[i++] = prop_atoms.net_wm_window_type_dialog; - supported[i++] = prop_atoms.net_wm_window_type_normal; - supported[i++] = prop_atoms.net_wm_allowed_actions; - supported[i++] = prop_atoms.net_wm_action_move; - supported[i++] = prop_atoms.net_wm_action_resize; - supported[i++] = prop_atoms.net_wm_action_minimize; - supported[i++] = prop_atoms.net_wm_action_shade; - supported[i++] = prop_atoms.net_wm_action_maximize_horz; - supported[i++] = prop_atoms.net_wm_action_maximize_vert; - supported[i++] = prop_atoms.net_wm_action_fullscreen; - supported[i++] = prop_atoms.net_wm_action_change_desktop; - supported[i++] = prop_atoms.net_wm_action_close; - supported[i++] = prop_atoms.net_wm_action_above; - supported[i++] = prop_atoms.net_wm_action_below; - supported[i++] = prop_atoms.net_wm_state; - supported[i++] = prop_atoms.net_wm_state_modal; - supported[i++] = prop_atoms.net_wm_state_maximized_vert; - supported[i++] = prop_atoms.net_wm_state_maximized_horz; - supported[i++] = prop_atoms.net_wm_state_shaded; - supported[i++] = prop_atoms.net_wm_state_skip_taskbar; - supported[i++] = prop_atoms.net_wm_state_skip_pager; - supported[i++] = prop_atoms.net_wm_state_hidden; - supported[i++] = prop_atoms.net_wm_state_fullscreen; - supported[i++] = prop_atoms.net_wm_state_above; - supported[i++] = prop_atoms.net_wm_state_below; - supported[i++] = prop_atoms.net_wm_state_demands_attention; - supported[i++] = prop_atoms.net_moveresize_window; - supported[i++] = prop_atoms.net_wm_moveresize; - supported[i++] = prop_atoms.net_wm_user_time; + supported[i++] = OBT_PROP_ATOM(NET_SUPPORTING_WM_CHECK); + supported[i++] = OBT_PROP_ATOM(NET_WM_FULL_PLACEMENT); + supported[i++] = OBT_PROP_ATOM(NET_CURRENT_DESKTOP); + supported[i++] = OBT_PROP_ATOM(NET_NUMBER_OF_DESKTOPS); + supported[i++] = OBT_PROP_ATOM(NET_DESKTOP_GEOMETRY); + supported[i++] = OBT_PROP_ATOM(NET_DESKTOP_VIEWPORT); + supported[i++] = OBT_PROP_ATOM(NET_ACTIVE_WINDOW); + supported[i++] = OBT_PROP_ATOM(NET_WORKAREA); + supported[i++] = OBT_PROP_ATOM(NET_CLIENT_LIST); + supported[i++] = OBT_PROP_ATOM(NET_CLIENT_LIST_STACKING); + supported[i++] = OBT_PROP_ATOM(NET_DESKTOP_NAMES); + supported[i++] = OBT_PROP_ATOM(NET_CLOSE_WINDOW); + supported[i++] = OBT_PROP_ATOM(NET_DESKTOP_LAYOUT); + supported[i++] = OBT_PROP_ATOM(NET_SHOWING_DESKTOP); + supported[i++] = OBT_PROP_ATOM(NET_WM_NAME); + supported[i++] = OBT_PROP_ATOM(NET_WM_VISIBLE_NAME); + supported[i++] = OBT_PROP_ATOM(NET_WM_ICON_NAME); + supported[i++] = OBT_PROP_ATOM(NET_WM_VISIBLE_ICON_NAME); + supported[i++] = OBT_PROP_ATOM(NET_WM_DESKTOP); + supported[i++] = OBT_PROP_ATOM(NET_WM_STRUT); + supported[i++] = OBT_PROP_ATOM(NET_WM_STRUT_PARTIAL); + supported[i++] = OBT_PROP_ATOM(NET_WM_ICON); + supported[i++] = OBT_PROP_ATOM(NET_WM_ICON_GEOMETRY); + supported[i++] = OBT_PROP_ATOM(NET_WM_WINDOW_TYPE); + supported[i++] = OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DESKTOP); + supported[i++] = OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DOCK); + supported[i++] = OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_TOOLBAR); + supported[i++] = OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_MENU); + supported[i++] = OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_UTILITY); + supported[i++] = OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_SPLASH); + supported[i++] = OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DIALOG); + supported[i++] = OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_NORMAL); + supported[i++] = OBT_PROP_ATOM(NET_WM_ALLOWED_ACTIONS); + supported[i++] = OBT_PROP_ATOM(NET_WM_ACTION_MOVE); + supported[i++] = OBT_PROP_ATOM(NET_WM_ACTION_RESIZE); + supported[i++] = OBT_PROP_ATOM(NET_WM_ACTION_MINIMIZE); + supported[i++] = OBT_PROP_ATOM(NET_WM_ACTION_SHADE); + supported[i++] = OBT_PROP_ATOM(NET_WM_ACTION_MAXIMIZE_HORZ); + supported[i++] = OBT_PROP_ATOM(NET_WM_ACTION_MAXIMIZE_VERT); + supported[i++] = OBT_PROP_ATOM(NET_WM_ACTION_FULLSCREEN); + supported[i++] = OBT_PROP_ATOM(NET_WM_ACTION_CHANGE_DESKTOP); + supported[i++] = OBT_PROP_ATOM(NET_WM_ACTION_CLOSE); + supported[i++] = OBT_PROP_ATOM(NET_WM_ACTION_ABOVE); + supported[i++] = OBT_PROP_ATOM(NET_WM_ACTION_BELOW); + supported[i++] = OBT_PROP_ATOM(NET_WM_STATE); + supported[i++] = OBT_PROP_ATOM(NET_WM_STATE_MODAL); + supported[i++] = OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT); + supported[i++] = OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ); + supported[i++] = OBT_PROP_ATOM(NET_WM_STATE_SHADED); + supported[i++] = OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR); + supported[i++] = OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER); + supported[i++] = OBT_PROP_ATOM(NET_WM_STATE_HIDDEN); + supported[i++] = OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN); + supported[i++] = OBT_PROP_ATOM(NET_WM_STATE_ABOVE); + supported[i++] = OBT_PROP_ATOM(NET_WM_STATE_BELOW); + supported[i++] = OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION); + supported[i++] = OBT_PROP_ATOM(NET_MOVERESIZE_WINDOW); + supported[i++] = OBT_PROP_ATOM(NET_WM_MOVERESIZE); + supported[i++] = OBT_PROP_ATOM(NET_WM_USER_TIME); /* - supported[i++] = prop_atoms.net_wm_user_time_window; + supported[i++] = OBT_PROP_ATOM(NET_WM_USER_TIME_WINDOW); */ - supported[i++] = prop_atoms.net_frame_extents; - supported[i++] = prop_atoms.net_request_frame_extents; - supported[i++] = prop_atoms.net_restack_window; - supported[i++] = prop_atoms.net_startup_id; + supported[i++] = OBT_PROP_ATOM(NET_FRAME_EXTENTS); + supported[i++] = OBT_PROP_ATOM(NET_REQUEST_FRAME_EXTENTS); + supported[i++] = OBT_PROP_ATOM(NET_RESTACK_WINDOW); + supported[i++] = OBT_PROP_ATOM(NET_STARTUP_ID); #ifdef SYNC - supported[i++] = prop_atoms.net_wm_sync_request; - supported[i++] = prop_atoms.net_wm_sync_request_counter; + supported[i++] = OBT_PROP_ATOM(NET_WM_SYNC_REQUEST); + supported[i++] = OBT_PROP_ATOM(NET_WM_SYNC_REQUEST_COUNTER); #endif - supported[i++] = prop_atoms.net_wm_pid; - supported[i++] = prop_atoms.net_wm_ping; - - supported[i++] = prop_atoms.kde_wm_change_state; - supported[i++] = prop_atoms.kde_net_wm_frame_strut; - supported[i++] = prop_atoms.kde_net_wm_window_type_override; - - supported[i++] = prop_atoms.ob_wm_action_undecorate; - supported[i++] = prop_atoms.ob_wm_state_undecorated; - supported[i++] = prop_atoms.openbox_pid; - supported[i++] = prop_atoms.ob_theme; - supported[i++] = prop_atoms.ob_config_file; - supported[i++] = prop_atoms.ob_control; + supported[i++] = OBT_PROP_ATOM(NET_WM_PID); + supported[i++] = OBT_PROP_ATOM(NET_WM_PING); + + supported[i++] = OBT_PROP_ATOM(KDE_WM_CHANGE_STATE); + supported[i++] = OBT_PROP_ATOM(KDE_NET_WM_FRAME_STRUT); + supported[i++] = OBT_PROP_ATOM(KDE_NET_WM_WINDOW_TYPE_OVERRIDE); + + supported[i++] = OBT_PROP_ATOM(OB_WM_ACTION_UNDECORATE); + supported[i++] = OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED); + supported[i++] = OBT_PROP_ATOM(OPENBOX_PID); + supported[i++] = OBT_PROP_ATOM(OB_THEME); + supported[i++] = OBT_PROP_ATOM(OB_CONFIG_FILE); + supported[i++] = OBT_PROP_ATOM(OB_CONTROL); g_assert(i == num_support); - PROP_SETA32(RootWindow(ob_display, ob_screen), - net_supported, atom, supported, num_support); + OBT_PROP_SETA32(obt_root(ob_screen), + NET_SUPPORTED, ATOM, supported, num_support); g_free(supported); screen_tell_ksplash(); @@ -337,14 +328,14 @@ static void screen_tell_ksplash(void) hear it anyways. perhaps it is for old ksplash. or new ksplash. or something. oh well. */ e.xclient.type = ClientMessage; - e.xclient.display = ob_display; - e.xclient.window = RootWindow(ob_display, ob_screen); + e.xclient.display = obt_display; + e.xclient.window = obt_root(ob_screen); e.xclient.message_type = - XInternAtom(ob_display, "_KDE_SPLASH_PROGRESS", False); + XInternAtom(obt_display, "_KDE_SPLASH_PROGRESS", False); e.xclient.format = 8; strcpy(e.xclient.data.b, "wm started"); - XSendEvent(ob_display, RootWindow(ob_display, ob_screen), - False, SubstructureNotifyMask, &e ); + XSendEvent(obt_display, obt_root(ob_screen), + False, SubstructureNotifyMask, &e); } void screen_startup(gboolean reconfig) @@ -368,9 +359,7 @@ void screen_startup(gboolean reconfig) screen_resize(); /* have names already been set for the desktops? */ - if (PROP_GETSS(RootWindow(ob_display, ob_screen), - net_desktop_names, utf8, &names)) - { + if (OBT_PROP_GETSS(obt_root(ob_screen), NET_DESKTOP_NAMES, utf8, &names)) { g_strfreev(names); namesexist = TRUE; } @@ -391,7 +380,8 @@ void screen_startup(gboolean reconfig) names[i] = g_strdup(it->data); /* set the root window property */ - PROP_SETSS(RootWindow(ob_display, ob_screen), net_desktop_names,names); + OBT_PROP_SETSS(obt_root(ob_screen), + NET_DESKTOP_NAMES, utf8, (const gchar**)names); g_strfreev(names); } @@ -401,8 +391,8 @@ void screen_startup(gboolean reconfig) this will also set the default names from the config file up for desktops that don't have names yet */ screen_num_desktops = 0; - if (PROP_GET32(RootWindow(ob_display, ob_screen), - net_number_of_desktops, cardinal, &d)) + if (OBT_PROP_GET32(obt_root(ob_screen), + NET_NUMBER_OF_DESKTOPS, CARDINAL, &d)) { if (d != config_desktops_num) { /* TRANSLATORS: If you need to specify a different order of the @@ -422,8 +412,8 @@ void screen_startup(gboolean reconfig) screen_desktop = screen_num_desktops; /* something invalid */ /* start on the current desktop when a wm was already running */ - if (PROP_GET32(RootWindow(ob_display, ob_screen), - net_current_desktop, cardinal, &d) && + if (OBT_PROP_GET32(obt_root(ob_screen), + NET_CURRENT_DESKTOP, CARDINAL, &d) && d < screen_num_desktops) { screen_set_desktop(d, FALSE); @@ -437,8 +427,8 @@ void screen_startup(gboolean reconfig) /* don't start in showing-desktop mode */ screen_showing_desktop = FALSE; - PROP_SET32(RootWindow(ob_display, ob_screen), - net_showing_desktop, cardinal, screen_showing_desktop); + OBT_PROP_SET32(obt_root(ob_screen), + NET_SHOWING_DESKTOP, CARDINAL, screen_showing_desktop); if (session_desktop_layout_present && screen_validate_layout(&session_desktop_layout)) @@ -456,17 +446,16 @@ void screen_shutdown(gboolean reconfig) if (reconfig) return; - XSelectInput(ob_display, RootWindow(ob_display, ob_screen), - NoEventMask); + XSelectInput(obt_display, obt_root(ob_screen), NoEventMask); /* we're not running here no more! */ - PROP_ERASE(RootWindow(ob_display, ob_screen), openbox_pid); + OBT_PROP_ERASE(obt_root(ob_screen), OPENBOX_PID); /* not without us */ - PROP_ERASE(RootWindow(ob_display, ob_screen), net_supported); + OBT_PROP_ERASE(obt_root(ob_screen), NET_SUPPORTED); /* don't keep this mode */ - PROP_ERASE(RootWindow(ob_display, ob_screen), net_showing_desktop); + OBT_PROP_ERASE(obt_root(ob_screen), NET_SHOWING_DESKTOP); - XDestroyWindow(ob_display, screen_support_win); + XDestroyWindow(obt_display, screen_support_win); g_strfreev(screen_desktop_names); screen_desktop_names = NULL; @@ -479,8 +468,8 @@ void screen_resize(void) GList *it; gulong geometry[2]; - w = WidthOfScreen(ScreenOfDisplay(ob_display, ob_screen)); - h = HeightOfScreen(ScreenOfDisplay(ob_display, ob_screen)); + w = WidthOfScreen(ScreenOfDisplay(obt_display, ob_screen)); + h = HeightOfScreen(ScreenOfDisplay(obt_display, ob_screen)); if (w == oldw && h == oldh) return; @@ -489,8 +478,8 @@ void screen_resize(void) /* Set the _NET_DESKTOP_GEOMETRY hint */ screen_physical_size.width = geometry[0] = w; screen_physical_size.height = geometry[1] = h; - PROP_SETA32(RootWindow(ob_display, ob_screen), - net_desktop_geometry, cardinal, geometry, 2); + OBT_PROP_SETA32(obt_root(ob_screen), + NET_DESKTOP_GEOMETRY, CARDINAL, geometry, 2); if (ob_state() == OB_STATE_STARTING) return; @@ -514,13 +503,12 @@ void screen_set_num_desktops(guint num) old = screen_num_desktops; screen_num_desktops = num; - PROP_SET32(RootWindow(ob_display, ob_screen), - net_number_of_desktops, cardinal, num); + OBT_PROP_SET32(obt_root(ob_screen), NET_NUMBER_OF_DESKTOPS, CARDINAL, num); /* set the viewport hint */ viewport = g_new0(gulong, num * 2); - PROP_SETA32(RootWindow(ob_display, ob_screen), - net_desktop_viewport, cardinal, viewport, num * 2); + OBT_PROP_SETA32(obt_root(ob_screen), + NET_DESKTOP_VIEWPORT, CARDINAL, viewport, num * 2); g_free(viewport); /* the number of rows/columns will differ */ @@ -616,8 +604,7 @@ void screen_set_desktop(guint num, gboolean dofocus) if (previous == num) return; - PROP_SET32(RootWindow(ob_display, ob_screen), - net_current_desktop, cardinal, num); + OBT_PROP_SET32(obt_root(ob_screen), NET_CURRENT_DESKTOP, CARDINAL, num); /* This whole thing decides when/how to save the screen_last_desktop so that it can be restored later if you want */ @@ -683,11 +670,11 @@ void screen_set_desktop(guint num, gboolean dofocus) } } screen_desktop_timeout = FALSE; - ob_main_loop_timeout_remove(ob_main_loop, last_desktop_func); - ob_main_loop_timeout_add(ob_main_loop, REMEMBER_LAST_DESKTOP_TIME, - last_desktop_func, NULL, NULL, NULL); + obt_main_loop_timeout_remove(ob_main_loop, last_desktop_func); + obt_main_loop_timeout_add(ob_main_loop, REMEMBER_LAST_DESKTOP_TIME, + last_desktop_func, NULL, NULL, NULL); - ob_debug("Moving to desktop %d\n", num+1); + ob_debug("Moving to desktop %d", num+1); if (ob_state() == OB_STATE_RUNNING) screen_show_desktop_popup(screen_desktop); @@ -722,6 +709,8 @@ void screen_set_desktop(guint num, gboolean dofocus) if (event_curtime != CurrentTime) screen_desktop_user_time = event_curtime; + + hooks_queue(OB_HOOK_SCREEN_DESK_CHANGE, NULL); } void screen_add_desktop(gboolean current) @@ -744,7 +733,7 @@ void screen_add_desktop(gboolean current) parent - which will have to be on the same desktop */ !client_direct_parent(c)) { - ob_debug("moving window %s\n", c->title); + ob_debug("moving window %s", c->title); client_set_desktop(c, c->desktop+1, FALSE, TRUE); } } @@ -785,7 +774,7 @@ void screen_remove_desktop(gboolean current) parent - which will have to be on the same desktop */ !client_direct_parent(c)) { - ob_debug("moving window %s\n", c->title); + ob_debug("moving window %s", c->title); client_set_desktop(c, c->desktop - 1, TRUE, TRUE); } /* raise all the windows that are on the current desktop which @@ -795,7 +784,7 @@ void screen_remove_desktop(gboolean current) (d == DESKTOP_ALL || d == screen_desktop)) { stacking_raise(CLIENT_AS_WINDOW(c)); - ob_debug("raising window %s\n", c->title); + ob_debug("raising window %s", c->title); } } } @@ -804,7 +793,7 @@ void screen_remove_desktop(gboolean current) /* fallback focus like we're changing desktops */ if (screen_desktop < screen_num_desktops - 1) { screen_fallback_focus(); - ob_debug("fake desktop change\n"); + ob_debug("fake desktop change"); } screen_set_num_desktops(screen_num_desktops-1); @@ -945,15 +934,15 @@ void screen_show_desktop_popup(guint d) MAX(a->width/3, POPUP_WIDTH)); pager_popup_show(desktop_popup, screen_desktop_names[d], d); - ob_main_loop_timeout_remove(ob_main_loop, hide_desktop_popup_func); - ob_main_loop_timeout_add(ob_main_loop, config_desktop_popup_time * 1000, - hide_desktop_popup_func, NULL, NULL, NULL); + obt_main_loop_timeout_remove(ob_main_loop, hide_desktop_popup_func); + obt_main_loop_timeout_add(ob_main_loop, config_desktop_popup_time * 1000, + hide_desktop_popup_func, NULL, NULL, NULL); g_free(a); } void screen_hide_desktop_popup(void) { - ob_main_loop_timeout_remove(ob_main_loop, hide_desktop_popup_func); + obt_main_loop_timeout_remove(ob_main_loop, hide_desktop_popup_func); pager_popup_hide(desktop_popup); } @@ -1112,13 +1101,13 @@ void screen_update_layout(void) screen_desktop_layout.rows = 1; screen_desktop_layout.columns = screen_num_desktops; - if (PROP_GETA32(RootWindow(ob_display, ob_screen), - net_desktop_layout, cardinal, &data, &num)) { + if (OBT_PROP_GETA32(obt_root(ob_screen), + NET_DESKTOP_LAYOUT, CARDINAL, &data, &num)) { if (num == 3 || num == 4) { - if (data[0] == prop_atoms.net_wm_orientation_vert) + if (data[0] == OBT_PROP_ATOM(NET_WM_ORIENTATION_VERT)) l.orientation = OB_ORIENTATION_VERT; - else if (data[0] == prop_atoms.net_wm_orientation_horz) + else if (data[0] == OBT_PROP_ATOM(NET_WM_ORIENTATION_HORZ)) l.orientation = OB_ORIENTATION_HORZ; else return; @@ -1126,13 +1115,13 @@ void screen_update_layout(void) if (num < 4) l.start_corner = OB_CORNER_TOPLEFT; else { - if (data[3] == prop_atoms.net_wm_topleft) + if (data[3] == OBT_PROP_ATOM(NET_WM_TOPLEFT)) l.start_corner = OB_CORNER_TOPLEFT; - else if (data[3] == prop_atoms.net_wm_topright) + else if (data[3] == OBT_PROP_ATOM(NET_WM_TOPRIGHT)) l.start_corner = OB_CORNER_TOPRIGHT; - else if (data[3] == prop_atoms.net_wm_bottomright) + else if (data[3] == OBT_PROP_ATOM(NET_WM_BOTTOMRIGHT)) l.start_corner = OB_CORNER_BOTTOMRIGHT; - else if (data[3] == prop_atoms.net_wm_bottomleft) + else if (data[3] == OBT_PROP_ATOM(NET_WM_BOTTOMLEFT)) l.start_corner = OB_CORNER_BOTTOMLEFT; else return; @@ -1157,8 +1146,8 @@ void screen_update_desktop_names(void) g_strfreev(screen_desktop_names); screen_desktop_names = NULL; - if (PROP_GETSS(RootWindow(ob_display, ob_screen), - net_desktop_names, utf8, &screen_desktop_names)) + if (OBT_PROP_GETSS(obt_root(ob_screen), + NET_DESKTOP_NAMES, utf8, &screen_desktop_names)) for (i = 0; screen_desktop_names[i] && i < screen_num_desktops; ++i); else i = 0; @@ -1184,8 +1173,8 @@ void screen_update_desktop_names(void) /* if we changed any names, then set the root property so we can all agree on the names */ - PROP_SETSS(RootWindow(ob_display, ob_screen), net_desktop_names, - screen_desktop_names); + OBT_PROP_SETSS(obt_root(ob_screen), NET_DESKTOP_NAMES, + utf8, (const gchar**)screen_desktop_names); } /* resize the pager for these names */ @@ -1252,24 +1241,23 @@ void screen_show_desktop(gboolean show, ObClient *show_only) } show = !!show; /* make it boolean */ - PROP_SET32(RootWindow(ob_display, ob_screen), - net_showing_desktop, cardinal, show); + OBT_PROP_SET32(obt_root(ob_screen), NET_SHOWING_DESKTOP, CARDINAL, show); } void screen_install_colormap(ObClient *client, gboolean install) { if (client == NULL || client->colormap == None) { if (install) - XInstallColormap(RrDisplay(ob_rr_inst), RrColormap(ob_rr_inst)); + XInstallColormap(obt_display, RrColormap(ob_rr_inst)); else - XUninstallColormap(RrDisplay(ob_rr_inst), RrColormap(ob_rr_inst)); + XUninstallColormap(obt_display, RrColormap(ob_rr_inst)); } else { - xerror_set_ignore(TRUE); + obt_display_ignore_errors(TRUE); if (install) - XInstallColormap(RrDisplay(ob_rr_inst), client->colormap); + XInstallColormap(obt_display, client->colormap); else - XUninstallColormap(RrDisplay(ob_rr_inst), client->colormap); - xerror_set_ignore(FALSE); + XUninstallColormap(obt_display, client->colormap); + obt_display_ignore_errors(FALSE); } } @@ -1311,6 +1299,54 @@ typedef struct { } \ } +static void get_xinerama_screens(Rect **xin_areas, guint *nxin) +{ + guint i; + gint l, r, t, b; + + if (ob_debug_xinerama) { + gint w = WidthOfScreen(ScreenOfDisplay(obt_display, ob_screen)); + gint h = HeightOfScreen(ScreenOfDisplay(obt_display, ob_screen)); + *nxin = 2; + *xin_areas = g_new(Rect, *nxin + 1); + RECT_SET((*xin_areas)[0], 0, 0, w/2, h); + RECT_SET((*xin_areas)[1], w/2, 0, w-(w/2), h); + } +#ifdef XINERAMA + else if (obt_display_extension_xinerama) { + guint i; + gint n; + XineramaScreenInfo *info = XineramaQueryScreens(obt_display, &n); + *nxin = n; + *xin_areas = g_new(Rect, *nxin + 1); + for (i = 0; i < *nxin; ++i) + RECT_SET((*xin_areas)[i], info[i].x_org, info[i].y_org, + info[i].width, info[i].height); + XFree(info); + } +#endif + else { + *nxin = 1; + *xin_areas = g_new(Rect, *nxin + 1); + RECT_SET((*xin_areas)[0], 0, 0, + WidthOfScreen(ScreenOfDisplay(obt_display, ob_screen)), + HeightOfScreen(ScreenOfDisplay(obt_display, ob_screen))); + } + + /* returns one extra with the total area in it */ + l = (*xin_areas)[0].x; + t = (*xin_areas)[0].y; + r = (*xin_areas)[0].x + (*xin_areas)[0].width - 1; + b = (*xin_areas)[0].y + (*xin_areas)[0].height - 1; + for (i = 1; i < *nxin; ++i) { + l = MIN(l, (*xin_areas)[i].x); + t = MIN(l, (*xin_areas)[i].y); + r = MAX(r, (*xin_areas)[i].x + (*xin_areas)[i].width - 1); + b = MAX(b, (*xin_areas)[i].y + (*xin_areas)[i].height - 1); + } + RECT_SET((*xin_areas)[*nxin], l, t, r - l + 1, b - t + 1); +} + void screen_update_areas(void) { guint i, j; @@ -1319,7 +1355,7 @@ void screen_update_areas(void) GSList *sit; g_free(monitor_area); - extensions_xinerama_screens(&monitor_area, &screen_num_monitors); + get_xinerama_screens(&monitor_area, &screen_num_monitors); /* set up the user-specified margins */ config_margins.top_start = RECT_LEFT(monitor_area[screen_num_monitors]); @@ -1428,8 +1464,8 @@ void screen_update_areas(void) /* all the work areas are not used here, only the ones for the first monitor are */ - PROP_SETA32(RootWindow(ob_display, ob_screen), net_workarea, cardinal, - dims, 4 * screen_num_desktops); + OBT_PROP_SETA32(obt_root(ob_screen), NET_WORKAREA, CARDINAL, + dims, 4 * screen_num_desktops); /* the area has changed, adjust all the windows if they need it */ for (it = client_list; it; it = g_list_next(it)) @@ -1670,10 +1706,10 @@ Rect* screen_physical_area_active(void) void screen_set_root_cursor(void) { if (sn_app_starting()) - XDefineCursor(ob_display, RootWindow(ob_display, ob_screen), + XDefineCursor(obt_display, obt_root(ob_screen), ob_cursor(OB_CURSOR_BUSYPOINTER)); else - XDefineCursor(ob_display, RootWindow(ob_display, ob_screen), + XDefineCursor(obt_display, obt_root(ob_screen), ob_cursor(OB_CURSOR_POINTER)); } @@ -1684,12 +1720,12 @@ gboolean screen_pointer_pos(gint *x, gint *y) guint u; gboolean ret; - ret = !!XQueryPointer(ob_display, RootWindow(ob_display, ob_screen), + ret = !!XQueryPointer(obt_display, obt_root(ob_screen), &w, &w, x, y, &i, &i, &u); if (!ret) { - for (i = 0; i < ScreenCount(ob_display); ++i) + for (i = 0; i < ScreenCount(obt_display); ++i) if (i != ob_screen) - if (XQueryPointer(ob_display, RootWindow(ob_display, i), + if (XQueryPointer(obt_display, obt_root(i), &w, &w, x, y, &i, &i, &u)) break; } diff --git a/openbox/screen.h b/openbox/screen.h index 39871e3..11915f1 100644 --- a/openbox/screen.h +++ b/openbox/screen.h @@ -53,7 +53,7 @@ extern ObDesktopLayout screen_desktop_layout; extern gchar **screen_desktop_names; /*! Take over the screen, set the basic hints on it claming it as ours */ -gboolean screen_annex(); +gboolean screen_annex(void); /*! Once the screen is ours, set up its initial state */ void screen_startup(gboolean reconfig); @@ -61,7 +61,7 @@ void screen_startup(gboolean reconfig); void screen_shutdown(gboolean reconfig); /*! Figure out the new size of the screen and adjust stuff for it */ -void screen_resize(); +void screen_resize(void); /*! Change the number of available desktops */ void screen_set_num_desktops(guint num); @@ -78,7 +78,7 @@ guint screen_find_desktop(guint from, ObDirection dir, /*! Show the desktop popup/notification */ void screen_show_desktop_popup(guint d); /*! Hide it */ -void screen_hide_desktop_popup(); +void screen_hide_desktop_popup(void); /*! Shows and focuses the desktop and hides all the client windows, or returns to the normal state, showing client windows. @@ -89,22 +89,22 @@ void screen_hide_desktop_popup(); void screen_show_desktop(gboolean show, struct _ObClient *show_only); /*! Updates the desktop layout from the root property if available */ -void screen_update_layout(); +void screen_update_layout(void); /*! Get desktop names from the root window property */ -void screen_update_desktop_names(); +void screen_update_desktop_names(void); /*! Installs or uninstalls a colormap for a client. If client is NULL, then it handles the root colormap. */ void screen_install_colormap(struct _ObClient *client, gboolean install); -void screen_update_areas(); +void screen_update_areas(void); -Rect *screen_physical_area_all_monitors(); +Rect *screen_physical_area_all_monitors(void); Rect *screen_physical_area_monitor(guint head); -Rect *screen_physical_area_active(); +Rect *screen_physical_area_active(void); /* doesn't include struts which the search area is already outside of when 'search' is not NULL */ @@ -127,7 +127,7 @@ guint screen_find_monitor(Rect *search); /*! Sets the root cursor. This function decides which cursor to use, but you gotta call it to let it know it should change. */ -void screen_set_root_cursor(); +void screen_set_root_cursor(void); /*! Gives back the pointer's position in x and y. Returns TRUE if the pointer is on this screen and FALSE if it is on another screen. */ diff --git a/openbox/session.c b/openbox/session.c index 4483c05..3cf8fbe 100644 --- a/openbox/session.c +++ b/openbox/session.c @@ -39,10 +39,10 @@ void session_request_logout(gboolean silent) {} #include "debug.h" #include "openbox.h" #include "client.h" -#include "prop.h" #include "focus.h" #include "gettext.h" -#include "parser/parse.h" +#include "obt/parse.h" +#include "obt/paths.h" #include #include @@ -92,22 +92,26 @@ static void session_state_free(ObSessionState *state); void session_startup(gint argc, gchar **argv) { gchar *dir; + ObtPaths *p; if (!ob_sm_use) return; sm_argc = argc; sm_argv = argv; - dir = g_build_filename(parse_xdg_data_home_path(), + p = obt_paths_new(); + dir = g_build_filename(obt_paths_cache_home(p), "openbox", "sessions", NULL); - if (!parse_mkdir_path(dir, 0700)) { + obt_paths_unref(p), p = NULL; + + if (!obt_paths_mkdir_path(dir, 0700)) { g_message(_("Unable to make directory \"%s\": %s"), dir, g_strerror(errno)); } if (ob_sm_save_file != NULL) { if (ob_sm_restore) { - ob_debug_type(OB_DEBUG_SM, "Loading from session file %s\n", + ob_debug_type(OB_DEBUG_SM, "Loading from session file %s", ob_sm_save_file); session_load_file(ob_sm_save_file); } @@ -156,7 +160,7 @@ void session_shutdown(gboolean permanent) } /*! Connect to the session manager and set up our callback functions */ -static gboolean session_connect() +static gboolean session_connect(void) { SmcCallbacks cb; gchar *oldid; @@ -174,7 +178,7 @@ static gboolean session_connect() /* connect to the server */ oldid = ob_sm_id; - ob_debug_type(OB_DEBUG_SM, "Connecting to SM with id: %s\n", + ob_debug_type(OB_DEBUG_SM, "Connecting to SM with id: %s", oldid ? oldid : "(null)"); sm_conn = SmcOpenConnection(NULL, NULL, 1, 0, SmcSaveYourselfProcMask | @@ -184,13 +188,13 @@ static gboolean session_connect() &cb, oldid, &ob_sm_id, SM_ERR_LEN-1, sm_err); g_free(oldid); - ob_debug_type(OB_DEBUG_SM, "Connected to SM with id: %s\n", ob_sm_id); + ob_debug_type(OB_DEBUG_SM, "Connected to SM with id: %s", ob_sm_id); if (sm_conn == NULL) - ob_debug("Failed to connect to session manager: %s\n", sm_err); + ob_debug("Failed to connect to session manager: %s", sm_err); return sm_conn != NULL; } -static void session_setup_program() +static void session_setup_program(void) { SmPropValue vals = { .value = sm_argv[0], @@ -203,13 +207,13 @@ static void session_setup_program() .vals = &vals }; SmProp *list = ∝ - ob_debug_type(OB_DEBUG_SM, "Setting program: %s\n", sm_argv[0]); + ob_debug_type(OB_DEBUG_SM, "Setting program: %s", sm_argv[0]); SmcSetProperties(sm_conn, 1, &list); g_free(prop.name); g_free(prop.type); } -static void session_setup_user() +static void session_setup_user(void) { char *user = g_strdup(g_get_user_name()); @@ -224,7 +228,7 @@ static void session_setup_user() .vals = &vals }; SmProp *list = ∝ - ob_debug_type(OB_DEBUG_SM, "Setting user: %s\n", user); + ob_debug_type(OB_DEBUG_SM, "Setting user: %s", user); SmcSetProperties(sm_conn, 1, &list); g_free(prop.name); g_free(prop.type); @@ -246,13 +250,13 @@ static void session_setup_restart_style(gboolean restart) .vals = &vals }; SmProp *list = ∝ - ob_debug_type(OB_DEBUG_SM, "Setting restart: %d\n", restart); + ob_debug_type(OB_DEBUG_SM, "Setting restart: %d", restart); SmcSetProperties(sm_conn, 1, &list); g_free(prop.name); g_free(prop.type); } -static void session_setup_pid() +static void session_setup_pid(void) { gchar *pid = g_strdup_printf("%ld", (glong) getpid()); @@ -267,7 +271,7 @@ static void session_setup_pid() .vals = &vals }; SmProp *list = ∝ - ob_debug_type(OB_DEBUG_SM, "Setting pid: %s\n", pid); + ob_debug_type(OB_DEBUG_SM, "Setting pid: %s", pid); SmcSetProperties(sm_conn, 1, &list); g_free(prop.name); g_free(prop.type); @@ -275,7 +279,7 @@ static void session_setup_pid() } /*! This is a gnome-session-manager extension */ -static void session_setup_priority() +static void session_setup_priority(void) { gchar priority = 20; /* 20 is a lower prioity to run before other apps */ @@ -290,13 +294,13 @@ static void session_setup_priority() .vals = &vals }; SmProp *list = ∝ - ob_debug_type(OB_DEBUG_SM, "Setting priority: %d\n", priority); + ob_debug_type(OB_DEBUG_SM, "Setting priority: %d", priority); SmcSetProperties(sm_conn, 1, &list); g_free(prop.name); g_free(prop.type); } -static void session_setup_clone_command() +static void session_setup_clone_command(void) { gint i; @@ -309,11 +313,11 @@ static void session_setup_clone_command() }; SmProp *list = ∝ - ob_debug_type(OB_DEBUG_SM, "Setting clone command: (%d)\n", sm_argc); + ob_debug_type(OB_DEBUG_SM, "Setting clone command: (%d)", sm_argc); for (i = 0; i < sm_argc; ++i) { vals[i].value = sm_argv[i]; vals[i].length = strlen(sm_argv[i]) + 1; - ob_debug_type(OB_DEBUG_SM, " %s\n", vals[i].value); + ob_debug_type(OB_DEBUG_SM, " %s", vals[i].value); } SmcSetProperties(sm_conn, 1, &list); @@ -322,7 +326,7 @@ static void session_setup_clone_command() g_free(vals); } -static void session_setup_restart_command() +static void session_setup_restart_command(void) { gint i; @@ -335,26 +339,26 @@ static void session_setup_restart_command() }; SmProp *list = ∝ - ob_debug_type(OB_DEBUG_SM, "Setting restart command: (%d)\n", sm_argc+4); + ob_debug_type(OB_DEBUG_SM, "Setting restart command: (%d)", sm_argc+4); for (i = 0; i < sm_argc; ++i) { vals[i].value = sm_argv[i]; vals[i].length = strlen(sm_argv[i]) + 1; - ob_debug_type(OB_DEBUG_SM, " %s\n", vals[i].value); + ob_debug_type(OB_DEBUG_SM, " %s", vals[i].value); } vals[i].value = g_strdup("--sm-client-id"); vals[i].length = strlen("--sm-client-id") + 1; vals[i+1].value = ob_sm_id; vals[i+1].length = strlen(ob_sm_id) + 1; - ob_debug_type(OB_DEBUG_SM, " %s\n", vals[i].value); - ob_debug_type(OB_DEBUG_SM, " %s\n", vals[i+1].value); + ob_debug_type(OB_DEBUG_SM, " %s", vals[i].value); + ob_debug_type(OB_DEBUG_SM, " %s", vals[i+1].value); vals[i+2].value = g_strdup("--sm-save-file"); vals[i+2].length = strlen("--sm-save-file") + 1; vals[i+3].value = ob_sm_save_file; vals[i+3].length = strlen(ob_sm_save_file) + 1; - ob_debug_type(OB_DEBUG_SM, " %s\n", vals[i+2].value); - ob_debug_type(OB_DEBUG_SM, " %s\n", vals[i+3].value); + ob_debug_type(OB_DEBUG_SM, " %s", vals[i+2].value); + ob_debug_type(OB_DEBUG_SM, " %s", vals[i+3].value); SmcSetProperties(sm_conn, 1, &list); g_free(prop.name); @@ -364,7 +368,7 @@ static void session_setup_restart_command() g_free(vals); } -static ObSMSaveData *sm_save_get_data() +static ObSMSaveData *sm_save_get_data(void) { ObSMSaveData *savedata = g_new0(ObSMSaveData, 1); /* save the active desktop and client. @@ -382,9 +386,9 @@ static void sm_save_yourself_2(SmcConn conn, SmPointer data) ObSMSaveData *savedata = data; /* save the current state */ - ob_debug_type(OB_DEBUG_SM, "Session save phase 2 requested\n"); + ob_debug_type(OB_DEBUG_SM, "Session save phase 2 requested"); ob_debug_type(OB_DEBUG_SM, - " Saving session to file '%s'\n", ob_sm_save_file); + " Saving session to file '%s'", ob_sm_save_file); if (savedata == NULL) savedata = sm_save_get_data(); success = session_save_to_file(savedata); @@ -393,7 +397,7 @@ static void sm_save_yourself_2(SmcConn conn, SmPointer data) /* tell the session manager how to restore this state */ if (success) session_setup_restart_command(); - ob_debug_type(OB_DEBUG_SM, "Saving is done (success = %d)\n", success); + ob_debug_type(OB_DEBUG_SM, "Saving is done (success = %d)", success); SmcSaveYourselfDone(conn, success); } @@ -404,10 +408,10 @@ static void sm_save_yourself(SmcConn conn, SmPointer data, gint save_type, ObSMSaveData *savedata = NULL; gchar *vendor; - ob_debug_type(OB_DEBUG_SM, "Session save requested\n"); + ob_debug_type(OB_DEBUG_SM, "Session save requested"); vendor = SmcVendor(sm_conn); - ob_debug_type(OB_DEBUG_SM, "Session manager's vendor: %s\n", vendor); + ob_debug_type(OB_DEBUG_SM, "Session manager's vendor: %s", vendor); if (!strcmp(vendor, "KDE")) { /* ksmserver guarantees that phase 1 will complete before allowing any @@ -418,7 +422,7 @@ static void sm_save_yourself(SmcConn conn, SmPointer data, gint save_type, free(vendor); if (!SmcRequestSaveYourselfPhase2(conn, sm_save_yourself_2, savedata)) { - ob_debug_type(OB_DEBUG_SM, "Requst for phase 2 failed\n"); + ob_debug_type(OB_DEBUG_SM, "Requst for phase 2 failed"); g_free(savedata); SmcSaveYourselfDone(conn, FALSE); } @@ -426,18 +430,18 @@ static void sm_save_yourself(SmcConn conn, SmPointer data, gint save_type, static void sm_die(SmcConn conn, SmPointer data) { - ob_debug_type(OB_DEBUG_SM, "Die requested\n"); + ob_debug_type(OB_DEBUG_SM, "Die requested"); ob_exit(0); } static void sm_save_complete(SmcConn conn, SmPointer data) { - ob_debug_type(OB_DEBUG_SM, "Save complete\n"); + ob_debug_type(OB_DEBUG_SM, "Save complete"); } static void sm_shutdown_cancelled(SmcConn conn, SmPointer data) { - ob_debug_type(OB_DEBUG_SM, "Shutdown cancelled\n"); + ob_debug_type(OB_DEBUG_SM, "Shutdown cancelled"); } static gboolean session_save_to_file(const ObSMSaveData *savedata) @@ -495,18 +499,18 @@ static gboolean session_save_to_file(const ObSMSaveData *savedata) if (!c->sm_client_id) { ob_debug_type(OB_DEBUG_SM, "Client %s does not have a " - "session id set\n", + "session id set", c->title); if (!c->wm_command) { ob_debug_type(OB_DEBUG_SM, "Client %s does not have an " "oldskool wm_command set either. We won't " - "be saving its data\n", + "be saving its data", c->title); continue; } } - ob_debug_type(OB_DEBUG_SM, "Saving state for client %s\n", + ob_debug_type(OB_DEBUG_SM, "Saving state for client %s", c->title); prex = c->area.x; @@ -605,20 +609,20 @@ static void session_state_free(ObSessionState *state) static gboolean session_state_cmp(ObSessionState *s, ObClient *c) { - ob_debug_type(OB_DEBUG_SM, "Comparing client against saved state: \n"); - ob_debug_type(OB_DEBUG_SM, " client id: %s \n", c->sm_client_id); - ob_debug_type(OB_DEBUG_SM, " client name: %s \n", c->name); - ob_debug_type(OB_DEBUG_SM, " client class: %s \n", c->class); - ob_debug_type(OB_DEBUG_SM, " client role: %s \n", c->role); - ob_debug_type(OB_DEBUG_SM, " client type: %d \n", c->type); - ob_debug_type(OB_DEBUG_SM, " client command: %s \n", + ob_debug_type(OB_DEBUG_SM, "Comparing client against saved state: "); + ob_debug_type(OB_DEBUG_SM, " client id: %s ", c->sm_client_id); + ob_debug_type(OB_DEBUG_SM, " client name: %s ", c->name); + ob_debug_type(OB_DEBUG_SM, " client class: %s ", c->class); + ob_debug_type(OB_DEBUG_SM, " client role: %s ", c->role); + ob_debug_type(OB_DEBUG_SM, " client type: %d ", c->type); + ob_debug_type(OB_DEBUG_SM, " client command: %s ", c->wm_command ? c->wm_command : "(null)"); - ob_debug_type(OB_DEBUG_SM, " state id: %s \n", s->id); - ob_debug_type(OB_DEBUG_SM, " state name: %s \n", s->name); - ob_debug_type(OB_DEBUG_SM, " state class: %s \n", s->class); - ob_debug_type(OB_DEBUG_SM, " state role: %s \n", s->role); - ob_debug_type(OB_DEBUG_SM, " state type: %d \n", s->type); - ob_debug_type(OB_DEBUG_SM, " state command: %s \n", + ob_debug_type(OB_DEBUG_SM, " state id: %s ", s->id); + ob_debug_type(OB_DEBUG_SM, " state name: %s ", s->name); + ob_debug_type(OB_DEBUG_SM, " state class: %s ", s->class); + ob_debug_type(OB_DEBUG_SM, " state role: %s ", s->role); + ob_debug_type(OB_DEBUG_SM, " state type: %d ", s->type); + ob_debug_type(OB_DEBUG_SM, " state command: %s ", s->command ? s->command : "(null)"); if ((c->sm_client_id && s->id && !strcmp(c->sm_client_id, s->id)) || @@ -653,101 +657,106 @@ GList* session_state_find(ObClient *c) static void session_load_file(const gchar *path) { - xmlDocPtr doc; + ObtParseInst *i; xmlNodePtr node, n, m; GList *it, *inext; - if (!parse_load(path, "openbox_session", &doc, &node)) + i = obt_parse_instance_new(); + + if (!obt_parse_load_file(i, path, "openbox_session")) { + obt_parse_instance_unref(i); return; + } + node = obt_parse_root(i); - if ((n = parse_find_node("desktop", node->children))) - session_desktop = parse_int(doc, n); + if ((n = obt_parse_find_node(node->children, "desktop"))) + session_desktop = obt_parse_node_int(n); - if ((n = parse_find_node("numdesktops", node->children))) - session_num_desktops = parse_int(doc, n); + if ((n = obt_parse_find_node(node->children, "numdesktops"))) + session_num_desktops = obt_parse_node_int(n); - if ((n = parse_find_node("desktoplayout", node->children))) { + if ((n = obt_parse_find_node(node->children, "desktoplayout"))) { /* make sure they are all there for it to be valid */ - if ((m = parse_find_node("orientation", n->children))) - session_desktop_layout.orientation = parse_int(doc, m); - if (m && (m = parse_find_node("startcorner", n->children))) - session_desktop_layout.start_corner = parse_int(doc, m); - if (m && (m = parse_find_node("columns", n->children))) - session_desktop_layout.columns = parse_int(doc, m); - if (m && (m = parse_find_node("rows", n->children))) - session_desktop_layout.rows = parse_int(doc, m); + if ((m = obt_parse_find_node(n->children, "orientation"))) + session_desktop_layout.orientation = obt_parse_node_int(m); + if (m && (m = obt_parse_find_node(n->children, "startcorner"))) + session_desktop_layout.start_corner = obt_parse_node_int(m); + if (m && (m = obt_parse_find_node(n->children, "columns"))) + session_desktop_layout.columns = obt_parse_node_int(m); + if (m && (m = obt_parse_find_node(n->children, "rows"))) + session_desktop_layout.rows = obt_parse_node_int(m); session_desktop_layout_present = m != NULL; } - if ((n = parse_find_node("desktopnames", node->children))) { - for (m = parse_find_node("name", n->children); m; - m = parse_find_node("name", m->next)) + if ((n = obt_parse_find_node(node->children, "desktopnames"))) { + for (m = obt_parse_find_node(n->children, "name"); m; + m = obt_parse_find_node(m->next, "name")) { session_desktop_names = g_slist_append(session_desktop_names, - parse_string(doc, m)); + obt_parse_node_string(m)); } } - for (node = parse_find_node("window", node->children); node != NULL; - node = parse_find_node("window", node->next)) + for (node = obt_parse_find_node(node->children, "window"); node != NULL; + node = obt_parse_find_node(node->next, "window")) { ObSessionState *state; state = g_new0(ObSessionState, 1); - if (!parse_attr_string("id", node, &state->id)) - if (!parse_attr_string("command", node, &state->command)) + if (!obt_parse_attr_string(node, "id", &state->id)) + if (!obt_parse_attr_string(node, "command", &state->command)) goto session_load_bail; - if (!(n = parse_find_node("name", node->children))) + if (!(n = obt_parse_find_node(node->children, "name"))) goto session_load_bail; - state->name = parse_string(doc, n); - if (!(n = parse_find_node("class", node->children))) + state->name = obt_parse_node_string(n); + if (!(n = obt_parse_find_node(node->children, "class"))) goto session_load_bail; - state->class = parse_string(doc, n); - if (!(n = parse_find_node("role", node->children))) + state->class = obt_parse_node_string(n); + if (!(n = obt_parse_find_node(node->children, "role"))) goto session_load_bail; - state->role = parse_string(doc, n); - if (!(n = parse_find_node("windowtype", node->children))) + state->role = obt_parse_node_string(n); + if (!(n = obt_parse_find_node(node->children, "windowtype"))) goto session_load_bail; - state->type = parse_int(doc, n); - if (!(n = parse_find_node("desktop", node->children))) + state->type = obt_parse_node_int(n); + if (!(n = obt_parse_find_node(node->children, "desktop"))) goto session_load_bail; - state->desktop = parse_int(doc, n); - if (!(n = parse_find_node("x", node->children))) + state->desktop = obt_parse_node_int(n); + if (!(n = obt_parse_find_node(node->children, "x"))) goto session_load_bail; - state->x = parse_int(doc, n); - if (!(n = parse_find_node("y", node->children))) + state->x = obt_parse_node_int(n); + if (!(n = obt_parse_find_node(node->children, "y"))) goto session_load_bail; - state->y = parse_int(doc, n); - if (!(n = parse_find_node("width", node->children))) + state->y = obt_parse_node_int(n); + if (!(n = obt_parse_find_node(node->children, "width"))) goto session_load_bail; - state->w = parse_int(doc, n); - if (!(n = parse_find_node("height", node->children))) + state->w = obt_parse_node_int(n); + if (!(n = obt_parse_find_node(node->children, "height"))) goto session_load_bail; - state->h = parse_int(doc, n); + state->h = obt_parse_node_int(n); state->shaded = - parse_find_node("shaded", node->children) != NULL; + obt_parse_find_node(node->children, "shaded") != NULL; state->iconic = - parse_find_node("iconic", node->children) != NULL; + obt_parse_find_node(node->children, "iconic") != NULL; state->skip_pager = - parse_find_node("skip_pager", node->children) != NULL; + obt_parse_find_node(node->children, "skip_pager") != NULL; state->skip_taskbar = - parse_find_node("skip_taskbar", node->children) != NULL; + obt_parse_find_node(node->children, "skip_taskbar") != NULL; state->fullscreen = - parse_find_node("fullscreen", node->children) != NULL; + obt_parse_find_node(node->children, "fullscreen") != NULL; state->above = - parse_find_node("above", node->children) != NULL; + obt_parse_find_node(node->children, "above") != NULL; state->below = - parse_find_node("below", node->children) != NULL; + obt_parse_find_node(node->children, "below") != NULL; state->max_horz = - parse_find_node("max_horz", node->children) != NULL; + obt_parse_find_node(node->children, "max_horz") != NULL; state->max_vert = - parse_find_node("max_vert", node->children) != NULL; + obt_parse_find_node(node->children, "max_vert") != NULL; state->undecorated = - parse_find_node("undecorated", node->children) != NULL; + obt_parse_find_node(node->children, "undecorated") != NULL; state->focused = - parse_find_node("focused", node->children) != NULL; + obt_parse_find_node(node->children, "focused") != NULL; /* save this. they are in the file in stacking order, so preserve that order here */ @@ -802,7 +811,7 @@ static void session_load_file(const gchar *path) } } - xmlFreeDoc(doc); + obt_parse_instance_unref(i); } void session_request_logout(gboolean silent) diff --git a/openbox/stacking.c b/openbox/stacking.c index 4c24e3e..3c05df4 100644 --- a/openbox/stacking.c +++ b/openbox/stacking.c @@ -18,7 +18,6 @@ */ #include "openbox.h" -#include "prop.h" #include "screen.h" #include "focus.h" #include "client.h" @@ -27,6 +26,7 @@ #include "window.h" #include "event.h" #include "debug.h" +#include "obt/prop.h" GList *stacking_list = NULL; /*! When true, stacking changes will not be reflected on the screen. This is @@ -55,8 +55,8 @@ void stacking_set_list(void) } } - PROP_SETA32(RootWindow(ob_display, ob_screen), - net_client_list_stacking, window, (gulong*)windows, i); + OBT_PROP_SETA32(obt_root(ob_screen), NET_CLIENT_LIST_STACKING, WINDOW, + (gulong*)windows, i); g_free(windows); } @@ -105,7 +105,7 @@ static void do_restack(GList *wins, GList *before) #endif if (!pause_changes) - XRestackWindows(ob_display, win, i); + XRestackWindows(obt_display, win, i); g_free(win); stacking_set_list(); @@ -132,7 +132,7 @@ void stacking_temp_raise(ObWindow *window) win[1] = window_top(window); start = event_start_ignore_all_enters(); - XRestackWindows(ob_display, win, 2); + XRestackWindows(obt_display, win, 2); event_end_ignore_all_enters(start); pause_changes = TRUE; @@ -150,7 +150,7 @@ void stacking_restore(void) for (i = 1, it = stacking_list; it; ++i, it = g_list_next(it)) win[i] = window_top(it->data); start = event_start_ignore_all_enters(); - XRestackWindows(ob_display, win, i); + XRestackWindows(obt_display, win, i); event_end_ignore_all_enters(start); g_free(win); @@ -633,21 +633,20 @@ gboolean stacking_restack_request(ObClient *client, ObClient *sibling, sibling->iconic)) { ob_debug("Setting restack sibling to NULL, they are not on the same " - "desktop or it is iconified\n"); + "desktop or it is iconified"); sibling = NULL; } switch (detail) { case Below: - ob_debug("Restack request Below for client %s sibling %s\n", + ob_debug("Restack request Below for client %s sibling %s", client->title, sibling ? sibling->title : "(all)"); /* just lower it */ stacking_lower(CLIENT_AS_WINDOW(client)); ret = TRUE; break; case BottomIf: - ob_debug("Restack request BottomIf for client %s sibling " - "%s\n", + ob_debug("Restack request BottomIf for client %s sibling %s", client->title, sibling ? sibling->title : "(all)"); /* if this client occludes sibling (or anything if NULL), then lower it to the bottom */ @@ -657,13 +656,13 @@ gboolean stacking_restack_request(ObClient *client, ObClient *sibling, } break; case Above: - ob_debug("Restack request Above for client %s sibling %s\n", + ob_debug("Restack request Above for client %s sibling %s", client->title, sibling ? sibling->title : "(all)"); stacking_raise(CLIENT_AS_WINDOW(client)); ret = TRUE; break; case TopIf: - ob_debug("Restack request TopIf for client %s sibling %s\n", + ob_debug("Restack request TopIf for client %s sibling %s", client->title, sibling ? sibling->title : "(all)"); if (stacking_occluded(client, sibling)) { stacking_raise(CLIENT_AS_WINDOW(client)); @@ -671,8 +670,7 @@ gboolean stacking_restack_request(ObClient *client, ObClient *sibling, } break; case Opposite: - ob_debug("Restack request Opposite for client %s sibling " - "%s\n", + ob_debug("Restack request Opposite for client %s sibling %s", client->title, sibling ? sibling->title : "(all)"); if (stacking_occluded(client, sibling)) { stacking_raise(CLIENT_AS_WINDOW(client)); diff --git a/openbox/stacking.h b/openbox/stacking.h index e226f36..773f658 100644 --- a/openbox/stacking.h +++ b/openbox/stacking.h @@ -43,7 +43,7 @@ extern GList *stacking_list; /*! Sets the window stacking list on the root window from the stacking_list */ -void stacking_set_list(); +void stacking_set_list(void); void stacking_add(struct _ObWindow *win); void stacking_add_nonintrusive(struct _ObWindow *win); @@ -56,7 +56,7 @@ void stacking_raise(struct _ObWindow *window); void stacking_temp_raise(struct _ObWindow *window); /*! Restores any temporarily raised windows to their correct place */ -void stacking_restore(); +void stacking_restore(void); /*! Lowers a window below all others in its stacking layer */ void stacking_lower(struct _ObWindow *window); diff --git a/openbox/startupnotify.c b/openbox/startupnotify.c index e13aa55..3e8799f 100644 --- a/openbox/startupnotify.c +++ b/openbox/startupnotify.c @@ -43,7 +43,6 @@ void sn_spawn_cancel() {} #else #include "openbox.h" -#include "mainloop.h" #include "screen.h" #define SN_API_NOT_YET_FROZEN @@ -63,12 +62,12 @@ void sn_startup(gboolean reconfig) { if (reconfig) return; - sn_display = sn_display_new(ob_display, NULL, NULL); + sn_display = sn_display_new(obt_display, NULL, NULL); sn_context = sn_monitor_context_new(sn_display, ob_screen, sn_event_func, NULL, NULL); sn_launcher = sn_launcher_context_new(sn_display, ob_screen); - ob_main_loop_x_add(ob_main_loop, sn_handler, NULL, NULL); + obt_main_loop_x_add(ob_main_loop, sn_handler, NULL, NULL); } void sn_shutdown(gboolean reconfig) @@ -77,7 +76,7 @@ void sn_shutdown(gboolean reconfig) if (reconfig) return; - ob_main_loop_x_remove(ob_main_loop, sn_handler); + obt_main_loop_x_remove(ob_main_loop, sn_handler); for (it = sn_waits; it; it = g_slist_next(it)) sn_startup_sequence_unref((SnStartupSequence*)it->data); @@ -140,10 +139,10 @@ static void sn_event_func(SnMonitorEvent *ev, gpointer data) sn_waits = g_slist_prepend(sn_waits, seq); /* 20 second timeout for apps to start if the launcher doesn't have a timeout */ - ob_main_loop_timeout_add(ob_main_loop, 20 * G_USEC_PER_SEC, - sn_wait_timeout, seq, - g_direct_equal, - (GDestroyNotify)sn_startup_sequence_unref); + obt_main_loop_timeout_add(ob_main_loop, 20 * G_USEC_PER_SEC, + sn_wait_timeout, seq, + g_direct_equal, + (GDestroyNotify)sn_startup_sequence_unref); change = TRUE; break; case SN_MONITOR_EVENT_CHANGED: @@ -154,8 +153,8 @@ static void sn_event_func(SnMonitorEvent *ev, gpointer data) case SN_MONITOR_EVENT_CANCELED: if ((seq = sequence_find(sn_startup_sequence_get_id(seq)))) { sn_waits = g_slist_remove(sn_waits, seq); - ob_main_loop_timeout_remove_data(ob_main_loop, sn_wait_timeout, - seq, FALSE); + obt_main_loop_timeout_remove_data(ob_main_loop, sn_wait_timeout, + seq, FALSE); change = TRUE; } break; @@ -261,10 +260,10 @@ void sn_setup_spawn_environment(const gchar *program, const gchar *name, /* 20 second timeout for apps to start */ sn_launcher_context_ref(sn_launcher); - ob_main_loop_timeout_add(ob_main_loop, 20 * G_USEC_PER_SEC, - sn_launch_wait_timeout, sn_launcher, - g_direct_equal, - (GDestroyNotify)sn_launcher_context_unref); + obt_main_loop_timeout_add(ob_main_loop, 20 * G_USEC_PER_SEC, + sn_launch_wait_timeout, sn_launcher, + g_direct_equal, + (GDestroyNotify)sn_launcher_context_unref); setenv("DESKTOP_STARTUP_ID", id, TRUE); diff --git a/openbox/startupnotify.h b/openbox/startupnotify.h index 758beee..d524bca 100644 --- a/openbox/startupnotify.h +++ b/openbox/startupnotify.h @@ -25,7 +25,7 @@ void sn_startup(gboolean reconfig); void sn_shutdown(gboolean reconfig); -gboolean sn_app_starting(); +gboolean sn_app_starting(void); /*! Notify that an app has started @param wmclass the WM_CLASS[1] hint @@ -45,6 +45,6 @@ void sn_setup_spawn_environment(const gchar *program, const gchar *name, /* Tell startup notification we're not actually running the program we told it we were */ -void sn_spawn_cancel(); +void sn_spawn_cancel(void); #endif diff --git a/openbox/translate.c b/openbox/translate.c index bd8b88f..50d5000 100644 --- a/openbox/translate.c +++ b/openbox/translate.c @@ -19,9 +19,9 @@ #include "openbox.h" #include "mouse.h" -#include "modkeys.h" -#include "translate.h" #include "gettext.h" +#include "obt/keyboard.h" + #include #include #include @@ -38,23 +38,23 @@ static guint translate_modifier(gchar *str) else if (!g_ascii_strcasecmp("Control", str) || !g_ascii_strcasecmp("C", str)) - mask = modkeys_key_to_mask(OB_MODKEY_KEY_CONTROL); + mask = obt_keyboard_modkey_to_modmask(OBT_KEYBOARD_MODKEY_CONTROL); else if (!g_ascii_strcasecmp("Alt", str) || !g_ascii_strcasecmp("A", str)) - mask = modkeys_key_to_mask(OB_MODKEY_KEY_ALT); + mask = obt_keyboard_modkey_to_modmask(OBT_KEYBOARD_MODKEY_ALT); else if (!g_ascii_strcasecmp("Meta", str) || !g_ascii_strcasecmp("M", str)) - mask = modkeys_key_to_mask(OB_MODKEY_KEY_META); + mask = obt_keyboard_modkey_to_modmask(OBT_KEYBOARD_MODKEY_META); /* W = windows key, is linked to the Super_L/R buttons */ else if (!g_ascii_strcasecmp("Super", str) || !g_ascii_strcasecmp("W", str)) - mask = modkeys_key_to_mask(OB_MODKEY_KEY_SUPER); + mask = obt_keyboard_modkey_to_modmask(OBT_KEYBOARD_MODKEY_SUPER); else if (!g_ascii_strcasecmp("Shift", str) || !g_ascii_strcasecmp("S", str)) - mask = modkeys_key_to_mask(OB_MODKEY_KEY_SHIFT); + mask = obt_keyboard_modkey_to_modmask(OBT_KEYBOARD_MODKEY_SHIFT); else if (!g_ascii_strcasecmp("Hyper", str) || !g_ascii_strcasecmp("H", str)) - mask = modkeys_key_to_mask(OB_MODKEY_KEY_HYPER); + mask = obt_keyboard_modkey_to_modmask(OBT_KEYBOARD_MODKEY_HYPER); else g_message(_("Invalid modifier key \"%s\" in key/mouse binding"), str); @@ -145,7 +145,7 @@ gboolean translate_key(const gchar *str, guint *state, guint *keycode) g_message(_("Invalid key name \"%s\" in key binding"), l); goto translation_fail; } - *keycode = XKeysymToKeycode(ob_display, sym); + *keycode = XKeysymToKeycode(obt_display, sym); } if (!*keycode) { g_message(_("Requested key \"%s\" does not exist on the display"), l); @@ -158,30 +158,3 @@ translation_fail: g_strfreev(parsed); return ret; } - -gchar *translate_keycode(guint keycode) -{ - KeySym sym; - const gchar *ret = NULL; - - if ((sym = XKeycodeToKeysym(ob_display, keycode, 0)) != NoSymbol) - ret = XKeysymToString(sym); - return g_locale_to_utf8(ret, -1, NULL, NULL, NULL); -} - -gunichar translate_unichar(guint keycode) -{ - gunichar unikey = 0; - - char *key; - if ((key = translate_keycode(keycode)) != NULL && - /* don't accept keys that aren't a single letter, like "space" */ - key[1] == '\0') - { - unikey = g_utf8_get_char_validated(key, -1); - if (unikey == (gunichar)-1 || unikey == (gunichar)-2 || unikey == 0) - unikey = 0; - } - g_free(key); - return unikey; -} diff --git a/openbox/translate.h b/openbox/translate.h index 6d9e23b..8249514 100644 --- a/openbox/translate.h +++ b/openbox/translate.h @@ -24,10 +24,4 @@ gboolean translate_button(const gchar *str, guint *state, guint *keycode); gboolean translate_key(const gchar *str, guint *state, guint *keycode); -/*! Give the string form of a keycode */ -gchar *translate_keycode(guint keycode); - -/*! Translate a keycode to the unicode character it represents */ -gunichar translate_unichar(guint keycode); - #endif diff --git a/openbox/window.c b/openbox/window.c index d312fc3..b90dc50 100644 --- a/openbox/window.c +++ b/openbox/window.c @@ -22,9 +22,12 @@ #include "dock.h" #include "client.h" #include "frame.h" +#include "openbox.h" #include "prompt.h" +#include "debug.h" +#include "grab.h" -GHashTable *window_map; +static GHashTable *window_map; static guint window_hash(Window *w) { return *w; } static gboolean window_comp(Window *w1, Window *w2) { return *w1 == *w2; } @@ -47,20 +50,16 @@ void window_shutdown(gboolean reconfig) Window window_top(ObWindow *self) { switch (self->type) { - case Window_Menu: - return ((ObMenuFrame*)self)->window; - case Window_Dock: - return ((ObDock*)self)->frame; - case Window_DockApp: - /* not to be used for stacking */ - g_assert_not_reached(); - break; - case Window_Client: - return ((ObClient*)self)->frame->window; - case Window_Internal: - return ((InternalWindow*)self)->window; - case Window_Prompt: - return ((ObPrompt*)self)->super.window; + case OB_WINDOW_CLASS_MENUFRAME: + return WINDOW_AS_MENUFRAME(self)->window; + case OB_WINDOW_CLASS_DOCK: + return WINDOW_AS_DOCK(self)->frame; + case OB_WINDOW_CLASS_CLIENT: + return WINDOW_AS_CLIENT(self)->frame->window; + case OB_WINDOW_CLASS_INTERNAL: + return WINDOW_AS_INTERNAL(self)->window; + case OB_WINDOW_CLASS_PROMPT: + return WINDOW_AS_PROMPT(self)->super.window; } g_assert_not_reached(); return None; @@ -69,19 +68,14 @@ Window window_top(ObWindow *self) ObStackingLayer window_layer(ObWindow *self) { switch (self->type) { - case Window_Menu: - return OB_STACKING_LAYER_INTERNAL; - case Window_Dock: + case OB_WINDOW_CLASS_DOCK: return config_dock_layer; - case Window_DockApp: - /* not to be used for stacking */ - g_assert_not_reached(); - break; - case Window_Client: + case OB_WINDOW_CLASS_CLIENT: return ((ObClient*)self)->layer; - case Window_Internal: + case OB_WINDOW_CLASS_MENUFRAME: + case OB_WINDOW_CLASS_INTERNAL: return OB_STACKING_LAYER_INTERNAL; - case Window_Prompt: + case OB_WINDOW_CLASS_PROMPT: /* not used directly for stacking, prompts are managed as clients */ g_assert_not_reached(); break; @@ -89,3 +83,129 @@ ObStackingLayer window_layer(ObWindow *self) g_assert_not_reached(); return None; } + +ObWindow* window_find(Window xwin) +{ + return g_hash_table_lookup(window_map, &xwin); +} + +void window_add(Window *xwin, ObWindow *win) +{ + g_assert(xwin != NULL); + g_assert(win != NULL); + g_hash_table_insert(window_map, xwin, win); +} + +void window_remove(Window xwin) +{ + g_assert(xwin != None); + g_hash_table_remove(window_map, &xwin); +} + +void window_manage_all(void) +{ + guint i, j, nchild; + Window w, *children; + XWMHints *wmhints; + XWindowAttributes attrib; + + if (!XQueryTree(obt_display, RootWindow(obt_display, ob_screen), + &w, &w, &children, &nchild)) { + ob_debug("XQueryTree failed in window_manage_all"); + nchild = 0; + } + + /* remove all icon windows from the list */ + for (i = 0; i < nchild; i++) { + if (children[i] == None) continue; + wmhints = XGetWMHints(obt_display, children[i]); + if (wmhints) { + if ((wmhints->flags & IconWindowHint) && + (wmhints->icon_window != children[i])) + for (j = 0; j < nchild; j++) + if (children[j] == wmhints->icon_window) { + /* XXX watch the window though */ + children[j] = None; + break; + } + XFree(wmhints); + } + } + + for (i = 0; i < nchild; ++i) { + if (children[i] == None) continue; + if (window_find(children[i])) continue; /* skip our own windows */ + if (XGetWindowAttributes(obt_display, children[i], &attrib)) { + if (attrib.map_state == IsUnmapped) + ; + else + window_manage(children[i]); + } + } + + if (children) XFree(children); +} + +void window_manage(Window win) +{ + XEvent e; + XWindowAttributes attrib; + gboolean no_manage = FALSE; + gboolean is_dockapp = FALSE; + Window icon_win = None; + + grab_server(TRUE); + + /* check if it has already been unmapped by the time we started + mapping. the grab does a sync so we don't have to here */ + if (XCheckTypedWindowEvent(obt_display, win, DestroyNotify, &e) || + XCheckTypedWindowEvent(obt_display, win, UnmapNotify, &e)) + { + XPutBackEvent(obt_display, &e); + ob_debug("Trying to manage unmapped window. Aborting that.\n"); + no_manage = TRUE; + } + + if (!XGetWindowAttributes(obt_display, win, &attrib)) + no_manage = TRUE; + else { + XWMHints *wmhints; + + /* is the window a docking app */ + is_dockapp = FALSE; + if ((wmhints = XGetWMHints(obt_display, win))) { + if ((wmhints->flags & StateHint) && + wmhints->initial_state == WithdrawnState) + { + if (wmhints->flags & IconWindowHint) + icon_win = wmhints->icon_window; + is_dockapp = TRUE; + } + XFree(wmhints); + } + } + + if (!no_manage) { + if (attrib.override_redirect) { + ob_debug("not managing override redirect window 0x%x\n", win); + grab_server(FALSE); + } + else if (is_dockapp) { + if (!icon_win) + icon_win = win; + dock_manage(icon_win, win); + } + else + client_manage(win, NULL); + } + else { + grab_server(FALSE); + ob_debug("FAILED to manage window 0x%x\n", win); + } +} + +void window_unmanage_all(void) +{ + dock_unmanage_all(); + client_unmanage_all(); +} diff --git a/openbox/window.h b/openbox/window.h index 76615c0..24a7d07 100644 --- a/openbox/window.h +++ b/openbox/window.h @@ -28,33 +28,29 @@ typedef struct _ObWindow ObWindow; typedef struct _ObInternalWindow ObInternalWindow; typedef enum { - Window_Menu, - Window_Dock, - Window_DockApp, /* used for events but not stacking */ - Window_Client, - Window_Internal,/* used for stacking but not events (except to filter - events on the root window) */ - Window_Prompt, -} Window_InternalType; - -struct _ObWindow -{ - Window_InternalType type; + OB_WINDOW_CLASS_MENUFRAME, + OB_WINDOW_CLASS_DOCK, + OB_WINDOW_CLASS_CLIENT, + OB_WINDOW_CLASS_INTERNAL, + OB_WINDOW_CLASS_PROMPT +} ObWindowClass; + +/* In order to be an ObWindow, you need to make this struct the top of your + struct */ +struct _ObWindow { + ObWindowClass type; }; -/* Wrapper for internal stuff. If its struct matches this then it can be used - as an ObWindow */ -typedef struct InternalWindow { - Window_InternalType type; - Window window; -} InternalWindow; - -#define WINDOW_IS_MENU(win) (((ObWindow*)win)->type == Window_Menu) -#define WINDOW_IS_DOCK(win) (((ObWindow*)win)->type == Window_Dock) -#define WINDOW_IS_DOCKAPP(win) (((ObWindow*)win)->type == Window_DockApp) -#define WINDOW_IS_CLIENT(win) (((ObWindow*)win)->type == Window_Client) -#define WINDOW_IS_INTERNAL(win) (((ObWindow*)win)->type == Window_Internal) -#define WINDOW_IS_PROMPT(win) (((ObWindow*)win)->type == Window_Prompt) +#define WINDOW_IS_MENUFRAME(win) \ + (((ObWindow*)win)->type == OB_WINDOW_CLASS_MENUFRAME) +#define WINDOW_IS_DOCK(win) \ + (((ObWindow*)win)->type == OB_WINDOW_CLASS_DOCK) +#define WINDOW_IS_CLIENT(win) \ + (((ObWindow*)win)->type == OB_WINDOW_CLASS_CLIENT) +#define WINDOW_IS_INTERNAL(win) \ + (((ObWindow*)win)->type == OB_WINDOW_CLASS_INTERNAL) +#define WINDOW_IS_PROMPT(win) \ + (((ObWindow*)win)->type == OB_WINDOW_CLASS_PROMPT) struct _ObMenu; struct _ObDock; @@ -62,26 +58,36 @@ struct _ObDockApp; struct _ObClient; struct _ObPrompt; -#define WINDOW_AS_MENU(win) ((struct _ObMenuFrame*)win) +#define WINDOW_AS_MENUFRAME(win) ((struct _ObMenuFrame*)win) #define WINDOW_AS_DOCK(win) ((struct _ObDock*)win) -#define WINDOW_AS_DOCKAPP(win) ((struct _ObDockApp*)win) #define WINDOW_AS_CLIENT(win) ((struct _ObClient*)win) -#define WINDOW_AS_INTERNAL(win) ((struct InternalWindow*)win) +#define WINDOW_AS_INTERNAL(win) ((struct _ObInternalWindow*)win) #define WINDOW_AS_PROMPT(win) ((struct _ObPrompt*)win) -#define MENU_AS_WINDOW(menu) ((ObWindow*)menu) +#define MENUFRAME_AS_WINDOW(menu) ((ObWindow*)menu) #define DOCK_AS_WINDOW(dock) ((ObWindow*)dock) -#define DOCKAPP_AS_WINDOW(dockapp) ((ObWindow*)dockapp) #define CLIENT_AS_WINDOW(client) ((ObWindow*)client) #define INTERNAL_AS_WINDOW(intern) ((ObWindow*)intern) #define PROMPT_AS_WINDOW(prompt) ((ObWindow*)prompt) -extern GHashTable *window_map; - -void window_startup(gboolean reconfig); +void window_startup (gboolean reconfig); void window_shutdown(gboolean reconfig); -Window window_top(ObWindow *self); +Window window_top (ObWindow *self); ObStackingLayer window_layer(ObWindow *self); +ObWindow* window_find (Window xwin); +void window_add (Window *xwin, ObWindow *win); +void window_remove(Window xwin); + +/* Internal openbox-owned windows like the alt-tab popup */ +struct _ObInternalWindow { + ObWindowClass type; + Window window; +}; + +void window_manage_all(void); +void window_manage(Window win); +void window_unmanage_all(void); + #endif diff --git a/openbox/xerror.c b/openbox/xerror.c deleted file mode 100644 index 2657b8e..0000000 --- a/openbox/xerror.c +++ /dev/null @@ -1,55 +0,0 @@ -/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- - - xerror.c for the Openbox window manager - Copyright (c) 2006 Mikael Magnusson - Copyright (c) 2003-2007 Dana Jansens - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - See the COPYING file for a copy of the GNU General Public License. -*/ - -#include "openbox.h" -#include "gettext.h" -#include "debug.h" -#include "xerror.h" -#include -#include - -static gboolean xerror_ignore = FALSE; -gboolean xerror_occured = FALSE; - -gint xerror_handler(Display *d, XErrorEvent *e) -{ -#ifdef DEBUG - gchar errtxt[128]; - - XGetErrorText(d, e->error_code, errtxt, 127); - if (!xerror_ignore) { - if (e->error_code == BadWindow) - /*g_message(_("X Error: %s\n"), errtxt)*/; - else - g_error(_("X Error: %s"), errtxt); - } else - ob_debug("XError code %d '%s'\n", e->error_code, errtxt); -#else - (void)d; (void)e; -#endif - - xerror_occured = TRUE; - return 0; -} - -void xerror_set_ignore(gboolean ignore) -{ - XSync(ob_display, FALSE); - xerror_ignore = ignore; -} diff --git a/parser/obparser-3.0.pc.in b/parser/obparser-3.0.pc.in deleted file mode 100644 index 75d04c9..0000000 --- a/parser/obparser-3.0.pc.in +++ /dev/null @@ -1,11 +0,0 @@ -prefix=@prefix@ -exec_prefix=@exec_prefix@ -libdir=@libdir@ -includedir=@includedir@ - -Name: ObParser -Description: Openbox config file parsing library -Version: @VERSION@ -Requires: libxml-2.0 glib-2.0 -Libs: -L${libdir} -lobparser -Cflags: -I${includedir}/openbox/@OB_VERSION@ diff --git a/parser/parse.c b/parser/parse.c deleted file mode 100644 index 636b451..0000000 --- a/parser/parse.c +++ /dev/null @@ -1,529 +0,0 @@ -/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- - - parse.c for the Openbox window manager - Copyright (c) 2003-2007 Dana Jansens - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - See the COPYING file for a copy of the GNU General Public License. -*/ - -#include "parse.h" -#include -#include -#include -#include -#include -#include - -static gboolean xdg_start; -static gchar *xdg_config_home_path; -static gchar *xdg_data_home_path; -static GSList *xdg_config_dir_paths; -static GSList *xdg_data_dir_paths; - -struct Callback { - gchar *tag; - ParseCallback func; - gpointer data; -}; - -struct _ObParseInst { - GHashTable *callbacks; -}; - -static void destfunc(struct Callback *c) -{ - g_free(c->tag); - g_free(c); -} - -ObParseInst* parse_startup(void) -{ - ObParseInst *i = g_new(ObParseInst, 1); - i->callbacks = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, - (GDestroyNotify)destfunc); - return i; -} - -void parse_shutdown(ObParseInst *i) -{ - if (i) { - g_hash_table_destroy(i->callbacks); - g_free(i); - } -} - -void parse_register(ObParseInst *i, const gchar *tag, - ParseCallback func, gpointer data) -{ - struct Callback *c; - - if ((c = g_hash_table_lookup(i->callbacks, tag))) { - g_error("Tag '%s' already registered", tag); - return; - } - - c = g_new(struct Callback, 1); - c->tag = g_strdup(tag); - c->func = func; - c->data = data; - g_hash_table_insert(i->callbacks, c->tag, c); -} - -gboolean parse_load_rc(const gchar *file, xmlDocPtr *doc, xmlNodePtr *root) -{ - GSList *it; - gboolean r = FALSE; - - if (file && parse_load(file, "openbox_config", doc, root)) - return TRUE; - - for (it = xdg_config_dir_paths; !r && it; it = g_slist_next(it)) { - gchar *path; - - path = g_build_filename(it->data, "openbox", "rc.xml", NULL); - r = parse_load(path, "openbox_config", doc, root); - g_free(path); - } - - return r; -} - -gboolean parse_load_theme(const gchar *name, xmlDocPtr *doc, xmlNodePtr *root, - gchar **retpath) -{ - GSList *it; - gchar *path; - gboolean r = FALSE; - gchar *eng; - - /* backward compatibility.. */ - path = g_build_filename(g_get_home_dir(), ".themes", name, - "openbox-3", "themerc.xml", NULL); - if (parse_load(path, "openbox_theme", doc, root) && - parse_attr_string("engine", *root, &eng)) - { - if (!strcmp(eng, "box")) { - *retpath = g_path_get_dirname(path); - r = TRUE; - } - g_free(eng); - } - g_free(path); - - if (!r) { - for (it = xdg_data_dir_paths; !r && it; it = g_slist_next(it)) { - path = g_build_filename(it->data, "themes", name, "openbox-3", - "themerc.xml", NULL); - if (parse_load(path, "openbox_theme", doc, root) && - parse_attr_string("engine", *root, &eng)) - { - if (!strcmp(eng, "box")) { - *retpath = g_path_get_dirname(path); - r = TRUE; - } - g_free(eng); - } - g_free(path); - } - } - return r; -} - -gboolean parse_load_menu(const gchar *file, xmlDocPtr *doc, xmlNodePtr *root) -{ - GSList *it; - gchar *path; - gboolean r = FALSE; - - if (file[0] == '/') { - r = parse_load(file, "openbox_menu", doc, root); - } else { - for (it = xdg_config_dir_paths; !r && it; it = g_slist_next(it)) { - path = g_build_filename(it->data, "openbox", file, NULL); - r = parse_load(path, "openbox_menu", doc, root); - g_free(path); - } - } - return r; -} - -gboolean parse_load(const gchar *path, const gchar *rootname, - xmlDocPtr *doc, xmlNodePtr *root) -{ - struct stat s; - - if (stat(path, &s) < 0) - return FALSE; - - /* XML_PARSE_BLANKS is needed apparently. When it loads a theme file, - without this option, the tree is weird and has extra nodes in it. */ - if ((*doc = xmlReadFile(path, NULL, - XML_PARSE_NOBLANKS | XML_PARSE_RECOVER))) { - *root = xmlDocGetRootElement(*doc); - if (!*root) { - xmlFreeDoc(*doc); - *doc = NULL; - g_message("%s is an empty document", path); - } else { - if (xmlStrcmp((*root)->name, (const xmlChar*)rootname)) { - xmlFreeDoc(*doc); - *doc = NULL; - g_message("XML Document %s is of wrong type. Root " - "node is not '%s'", path, rootname); - } - } - } - if (!*doc) - return FALSE; - return TRUE; -} - -gboolean parse_load_mem(gpointer data, guint len, const gchar *rootname, - xmlDocPtr *doc, xmlNodePtr *root) -{ - if ((*doc = xmlParseMemory(data, len))) { - *root = xmlDocGetRootElement(*doc); - if (!*root) { - xmlFreeDoc(*doc); - *doc = NULL; - g_message("Given memory is an empty document"); - } else { - if (xmlStrcmp((*root)->name, (const xmlChar*)rootname)) { - xmlFreeDoc(*doc); - *doc = NULL; - g_message("XML Document in given memory is of wrong " - "type. Root node is not '%s'\n", rootname); - } - } - } - if (!*doc) - return FALSE; - return TRUE; -} - -void parse_close(xmlDocPtr doc) -{ - xmlFreeDoc(doc); -} - -void parse_tree(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node) -{ - while (node) { - struct Callback *c = g_hash_table_lookup(i->callbacks, node->name); - - if (c) - c->func(i, doc, node, c->data); - - node = node->next; - } -} - -gchar *parse_string(xmlDocPtr doc, xmlNodePtr node) -{ - xmlChar *c = xmlNodeListGetString(doc, node->children, TRUE); - gchar *s = g_strdup(c ? (gchar*)c : ""); - xmlFree(c); - return s; -} - -gint parse_int(xmlDocPtr doc, xmlNodePtr node) -{ - xmlChar *c = xmlNodeListGetString(doc, node->children, TRUE); - gint i = c ? atoi((gchar*)c) : 0; - xmlFree(c); - return i; -} - -gboolean parse_bool(xmlDocPtr doc, xmlNodePtr node) -{ - xmlChar *c = xmlNodeListGetString(doc, node->children, TRUE); - gboolean b = FALSE; - if (c && !xmlStrcasecmp(c, (const xmlChar*) "true")) - b = TRUE; - else if (c && !xmlStrcasecmp(c, (const xmlChar*) "yes")) - b = TRUE; - else if (c && !xmlStrcasecmp(c, (const xmlChar*) "on")) - b = TRUE; - xmlFree(c); - return b; -} - -gboolean parse_contains(const gchar *val, xmlDocPtr doc, xmlNodePtr node) -{ - xmlChar *c = xmlNodeListGetString(doc, node->children, TRUE); - gboolean r; - r = !xmlStrcasecmp(c, (const xmlChar*) val); - xmlFree(c); - return r; -} - -xmlNodePtr parse_find_node(const gchar *tag, xmlNodePtr node) -{ - while (node) { - if (!xmlStrcmp(node->name, (const xmlChar*) tag)) - return node; - node = node->next; - } - return NULL; -} - -gboolean parse_attr_bool(const gchar *name, xmlNodePtr node, gboolean *value) -{ - xmlChar *c = xmlGetProp(node, (const xmlChar*) name); - gboolean r = FALSE; - if (c) { - if (!xmlStrcasecmp(c, (const xmlChar*) "true")) - *value = TRUE, r = TRUE; - else if (!xmlStrcasecmp(c, (const xmlChar*) "yes")) - *value = TRUE, r = TRUE; - else if (!xmlStrcasecmp(c, (const xmlChar*) "on")) - *value = TRUE, r = TRUE; - else if (!xmlStrcasecmp(c, (const xmlChar*) "false")) - *value = FALSE, r = TRUE; - else if (!xmlStrcasecmp(c, (const xmlChar*) "no")) - *value = FALSE, r = TRUE; - else if (!xmlStrcasecmp(c, (const xmlChar*) "off")) - *value = FALSE, r = TRUE; - } - xmlFree(c); - return r; -} - -gboolean parse_attr_int(const gchar *name, xmlNodePtr node, gint *value) -{ - xmlChar *c = xmlGetProp(node, (const xmlChar*) name); - gboolean r = FALSE; - if (c) { - *value = atoi((gchar*)c); - r = TRUE; - } - xmlFree(c); - return r; -} - -gboolean parse_attr_string(const gchar *name, xmlNodePtr node, gchar **value) -{ - xmlChar *c = xmlGetProp(node, (const xmlChar*) name); - gboolean r = FALSE; - if (c) { - *value = g_strdup((gchar*)c); - r = TRUE; - } - xmlFree(c); - return r; -} - -gboolean parse_attr_contains(const gchar *val, xmlNodePtr node, - const gchar *name) -{ - xmlChar *c = xmlGetProp(node, (const xmlChar*) name); - gboolean r = FALSE; - if (c) - r = !xmlStrcasecmp(c, (const xmlChar*) val); - xmlFree(c); - return r; -} - -static gint slist_path_cmp(const gchar *a, const gchar *b) -{ - return strcmp(a, b); -} - -typedef GSList* (*GSListFunc) (gpointer list, gconstpointer data); - -static GSList* slist_path_add(GSList *list, gpointer data, GSListFunc func) -{ - g_assert(func); - - if (!data) - return list; - - if (!g_slist_find_custom(list, data, (GCompareFunc) slist_path_cmp)) - list = func(list, data); - else - g_free(data); - - return list; -} - -static GSList* split_paths(const gchar *paths) -{ - GSList *list = NULL; - gchar **spl, **it; - - if (!paths) - return NULL; - spl = g_strsplit(paths, ":", -1); - for (it = spl; *it; ++it) - list = slist_path_add(list, *it, (GSListFunc) g_slist_append); - g_free(spl); - return list; -} - -void parse_paths_startup(void) -{ - const gchar *path; - - if (xdg_start) - return; - xdg_start = TRUE; - - path = g_getenv("XDG_CONFIG_HOME"); - if (path && path[0] != '\0') /* not unset or empty */ - xdg_config_home_path = g_build_filename(path, NULL); - else - xdg_config_home_path = g_build_filename(g_get_home_dir(), ".config", - NULL); - - path = g_getenv("XDG_DATA_HOME"); - if (path && path[0] != '\0') /* not unset or empty */ - xdg_data_home_path = g_build_filename(path, NULL); - else - xdg_data_home_path = g_build_filename(g_get_home_dir(), ".local", - "share", NULL); - - path = g_getenv("XDG_CONFIG_DIRS"); - if (path && path[0] != '\0') /* not unset or empty */ - xdg_config_dir_paths = split_paths(path); - else { - xdg_config_dir_paths = slist_path_add(xdg_config_dir_paths, - g_strdup(CONFIGDIR), - (GSListFunc) g_slist_append); - xdg_config_dir_paths = slist_path_add(xdg_config_dir_paths, - g_build_filename - (G_DIR_SEPARATOR_S, - "etc", "xdg", NULL), - (GSListFunc) g_slist_append); - } - xdg_config_dir_paths = slist_path_add(xdg_config_dir_paths, - g_strdup(xdg_config_home_path), - (GSListFunc) g_slist_prepend); - - path = g_getenv("XDG_DATA_DIRS"); - if (path && path[0] != '\0') /* not unset or empty */ - xdg_data_dir_paths = split_paths(path); - else { - xdg_data_dir_paths = slist_path_add(xdg_data_dir_paths, - g_strdup(DATADIR), - (GSListFunc) g_slist_append); - xdg_data_dir_paths = slist_path_add(xdg_data_dir_paths, - g_build_filename - (G_DIR_SEPARATOR_S, - "usr", "local", "share", NULL), - (GSListFunc) g_slist_append); - xdg_data_dir_paths = slist_path_add(xdg_data_dir_paths, - g_build_filename - (G_DIR_SEPARATOR_S, - "usr", "share", NULL), - (GSListFunc) g_slist_append); - } - xdg_data_dir_paths = slist_path_add(xdg_data_dir_paths, - g_strdup(xdg_data_home_path), - (GSListFunc) g_slist_prepend); -} - -void parse_paths_shutdown(void) -{ - GSList *it; - - if (!xdg_start) - return; - xdg_start = FALSE; - - for (it = xdg_config_dir_paths; it; it = g_slist_next(it)) - g_free(it->data); - g_slist_free(xdg_config_dir_paths); - xdg_config_dir_paths = NULL; - for (it = xdg_data_dir_paths; it; it = g_slist_next(it)) - g_free(it->data); - g_slist_free(xdg_data_dir_paths); - xdg_data_dir_paths = NULL; - g_free(xdg_config_home_path); - xdg_config_home_path = NULL; - g_free(xdg_data_home_path); - xdg_data_home_path = NULL; -} - -gchar *parse_expand_tilde(const gchar *f) -{ - gchar **spl; - gchar *ret; - - if (!f) - return NULL; - spl = g_strsplit(f, "~", 0); - ret = g_strjoinv(g_get_home_dir(), spl); - g_strfreev(spl); - return ret; -} - -gboolean parse_mkdir(const gchar *path, gint mode) -{ - gboolean ret = TRUE; - - g_return_val_if_fail(path != NULL, FALSE); - g_return_val_if_fail(path[0] != '\0', FALSE); - - if (!g_file_test(path, G_FILE_TEST_IS_DIR)) - if (mkdir(path, mode) == -1) - ret = FALSE; - - return ret; -} - -gboolean parse_mkdir_path(const gchar *path, gint mode) -{ - gboolean ret = TRUE; - - g_return_val_if_fail(path != NULL, FALSE); - g_return_val_if_fail(path[0] == '/', FALSE); - - if (!g_file_test(path, G_FILE_TEST_IS_DIR)) { - gchar *c, *e; - - c = g_strdup(path); - e = c; - while ((e = strchr(e + 1, '/'))) { - *e = '\0'; - if (!(ret = parse_mkdir(c, mode))) - goto parse_mkdir_path_end; - *e = '/'; - } - ret = parse_mkdir(c, mode); - - parse_mkdir_path_end: - g_free(c); - } - - return ret; -} - -const gchar* parse_xdg_config_home_path(void) -{ - return xdg_config_home_path; -} - -const gchar* parse_xdg_data_home_path(void) -{ - return xdg_data_home_path; -} - -GSList* parse_xdg_config_dir_paths(void) -{ - return xdg_config_dir_paths; -} - -GSList* parse_xdg_data_dir_paths(void) -{ - return xdg_data_dir_paths; -} diff --git a/parser/parse.h b/parser/parse.h deleted file mode 100644 index 28af64b..0000000 --- a/parser/parse.h +++ /dev/null @@ -1,98 +0,0 @@ -/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- - - parse.h for the Openbox window manager - Copyright (c) 2003-2007 Dana Jansens - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - See the COPYING file for a copy of the GNU General Public License. -*/ - -#ifndef __parse_h -#define __parse_h - -#include "version.h" - -#include -#include - -G_BEGIN_DECLS - -typedef struct _ObParseInst ObParseInst; - -typedef void (*ParseCallback)(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, - gpointer data); - -ObParseInst* parse_startup(); -void parse_shutdown(ObParseInst *inst); - -/*! Loads Openbox's rc, from the normal paths - @param file The path of the config to try load. NULL to load from the - default path - */ -gboolean parse_load_rc(const gchar *file, xmlDocPtr *doc, xmlNodePtr *root); -/* Loads an Openbox menu, from the normal paths */ -gboolean parse_load_menu(const gchar *file, xmlDocPtr *doc, xmlNodePtr *root); -/* Loads an Openbox theme, from the normal paths */ -gboolean parse_load_theme(const gchar *name, xmlDocPtr *doc, xmlNodePtr *root, - gchar **path); - -void parse_register(ObParseInst *inst, const gchar *tag, - ParseCallback func, gpointer data); -void parse_tree(ObParseInst *inst, xmlDocPtr doc, xmlNodePtr node); - - -/* open/close */ - -gboolean parse_load(const gchar *path, const gchar *rootname, - xmlDocPtr *doc, xmlNodePtr *root); -gboolean parse_load_mem(gpointer data, guint len, const gchar *rootname, - xmlDocPtr *doc, xmlNodePtr *root); -void parse_close(xmlDocPtr doc); - - -/* helpers */ - -xmlNodePtr parse_find_node(const gchar *tag, xmlNodePtr node); - -gchar *parse_string(xmlDocPtr doc, xmlNodePtr node); -gint parse_int(xmlDocPtr doc, xmlNodePtr node); -gboolean parse_bool(xmlDocPtr doc, xmlNodePtr node); - -gboolean parse_contains(const gchar *val, xmlDocPtr doc, xmlNodePtr node); -gboolean parse_attr_contains(const gchar *val, xmlNodePtr node, - const gchar *name); - -gboolean parse_attr_string(const gchar *name, xmlNodePtr node, gchar **value); -gboolean parse_attr_int(const gchar *name, xmlNodePtr node, gint *value); -gboolean parse_attr_bool(const gchar *name, xmlNodePtr node, gboolean *value); - -/* paths */ - -void parse_paths_startup(); -void parse_paths_shutdown(); - -const gchar* parse_xdg_config_home_path(); -const gchar* parse_xdg_data_home_path(); -GSList* parse_xdg_config_dir_paths(); -GSList* parse_xdg_data_dir_paths(); - -/*! Expands the ~ character to the home directory throughout the given - string */ -gchar *parse_expand_tilde(const gchar *f); -/*! Makes a directory */ -gboolean parse_mkdir(const gchar *path, gint mode); -/*! Makes a directory and all its parents */ -gboolean parse_mkdir_path(const gchar *path, gint mode); - -G_END_DECLS - -#endif diff --git a/po/POTFILES.in b/po/POTFILES.in index 85938de..200e9ca 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -7,6 +7,7 @@ openbox/client_list_combined_menu.c openbox/client_list_menu.c openbox/client_menu.c openbox/config.c +openbox/debug.c openbox/keyboard.c openbox/menu.c openbox/mouse.c @@ -15,5 +16,4 @@ openbox/screen.c openbox/session.c openbox/startupnotify.c openbox/translate.c -openbox/xerror.c openbox/prompt.c diff --git a/render/obrender-3.0.pc.in b/render/obrender-4.0.pc.in similarity index 63% rename from render/obrender-3.0.pc.in rename to render/obrender-4.0.pc.in index ebb17ef..539606a 100644 --- a/render/obrender-3.0.pc.in +++ b/render/obrender-4.0.pc.in @@ -8,7 +8,7 @@ xlibs=@X_LIBS@ Name: ObRender Description: Openbox Render Library -Version: @VERSION@ -Requires: obparser-3.0 glib-2.0 xft pangoxft +Version: @RR_VERSION@ +Requires: obt-4.0 glib-2.0 xft pangoxft Libs: -L${libdir} -lobrender ${xlibs} -Cflags: -I${includedir}/openbox/@OB_VERSION@ ${xcflags} +Cflags: -I${includedir}/openbox/@RR_VERSION@ ${xcflags} diff --git a/render/render.h b/render/render.h index f7bc504..706843e 100644 --- a/render/render.h +++ b/render/render.h @@ -22,7 +22,7 @@ #define __render_h #include "geom.h" -#include "version.h" +#include "render/version.h" #include /* some platforms dont include this as needed for Xft */ #include diff --git a/render/theme.c b/render/theme.c index 8c7393b..ece4037 100644 --- a/render/theme.c +++ b/render/theme.c @@ -23,7 +23,7 @@ #include "mask.h" #include "theme.h" #include "icon.h" -#include "parser/parse.h" +#include "obt/paths.h" #include #include @@ -560,6 +560,16 @@ RrTheme* RrThemeNew(const RrInstance *inst, const gchar *name, theme->menu_bullet_mask = RrPixmapMaskNew(inst, 4, 7, (gchar*)data); } + /* up and down arrows */ + { + guchar data[] = { 0xfe, 0x00, 0x7c, 0x00, 0x38, 0x00, 0x10, 0x00 }; + theme->down_arrow_mask = RrPixmapMaskNew(inst, 9, 4, (gchar*)data); + } + { + guchar data[] = { 0x10, 0x00, 0x38, 0x00, 0x7c, 0x00, 0xfe, 0x00 }; + theme->up_arrow_mask = RrPixmapMaskNew(inst, 9, 4, (gchar*)data); + } + /* setup the default window icon */ theme->def_win_icon = read_c_image(OB_DEFAULT_ICON_WIDTH, OB_DEFAULT_ICON_HEIGHT, @@ -1472,6 +1482,8 @@ void RrThemeFree(RrTheme *theme) RrPixmapMaskFree(theme->close_hover_mask); RrPixmapMaskFree(theme->close_pressed_mask); RrPixmapMaskFree(theme->menu_bullet_mask); + RrPixmapMaskFree(theme->down_arrow_mask); + RrPixmapMaskFree(theme->up_arrow_mask); RrFontClose(theme->win_font_focused); RrFontClose(theme->win_font_unfocused); @@ -1582,6 +1594,10 @@ static XrmDatabase loaddb(const gchar *name, gchar **path) *path = g_path_get_dirname(s); g_free(s); } else { + ObtPaths *p; + + p = obt_paths_new(); + /* XXX backwards compatibility, remove me sometime later */ s = g_build_filename(g_get_home_dir(), ".themes", name, "openbox-3", "themerc", NULL); @@ -1589,8 +1605,7 @@ static XrmDatabase loaddb(const gchar *name, gchar **path) *path = g_path_get_dirname(s); g_free(s); - for (it = parse_xdg_data_dir_paths(); !db && it; - it = g_slist_next(it)) + for (it = obt_paths_data_dirs(p); !db && it; it = g_slist_next(it)) { s = g_build_filename(it->data, "themes", name, "openbox-3", "themerc", NULL); @@ -1598,6 +1613,8 @@ static XrmDatabase loaddb(const gchar *name, gchar **path) *path = g_path_get_dirname(s); g_free(s); } + + obt_paths_unref(p); } if (db == NULL) { diff --git a/render/theme.h b/render/theme.h index a14dac2..da8e80d 100644 --- a/render/theme.h +++ b/render/theme.h @@ -151,6 +151,9 @@ struct _RrTheme { RrPixmapMask *menu_toggle_mask; /* menu boolean */ #endif + RrPixmapMask *down_arrow_mask; + RrPixmapMask *up_arrow_mask; + /* global appearances */ RrAppearance *a_disabled_focused_max; RrAppearance *a_disabled_unfocused_max; diff --git a/render/version.h.in b/render/version.h.in new file mode 100644 index 0000000..0ff30b5 --- /dev/null +++ b/render/version.h.in @@ -0,0 +1,15 @@ +#ifndef rr__version_h +#define rr__version_h + +#define RR_MAJOR_VERSION @RR_MAJOR_VERSION@ +#define RR_MINOR_VERSION @RR_MINOR_VERSION@ +#define RR_MICRO_VERSION @RR_MICRO_VERSION@ +#define RR_VERSION RR_MAJOR_VERSION.RR_MINOR_VERSION.RR_MICRO_VERSION + +#define RR_CHECK_VERSION(major,minor,micro) \ + (RR_MAJOR_VERSION > (major) || \ + (RR_MAJOR_VERSION == (major) && RR_MINOR_VERSION > (minor)) || \ + (RR_MAJOR_VERSION == (major) && RR_MINOR_VERSION == (minor) && \ + RR_MICRO_VERSION >= (micro))) + +#endif diff --git a/tests/overrideinputonly.c b/tests/overrideinputonly.c new file mode 100644 index 0000000..0c13ac3 --- /dev/null +++ b/tests/overrideinputonly.c @@ -0,0 +1,58 @@ +/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- + + override.c for the Openbox window manager + Copyright (c) 2003-2007 Dana Jansens + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + See the COPYING file for a copy of the GNU General Public License. +*/ + +#include +#include + +int main (int argc, char *argv[]) { + XSetWindowAttributes xswa; + unsigned long xswamask; + Display *display; + Window win; + XEvent report; + int i,x=0,y=0,h=1,w=1; + + for (i=0; i < argc; i++) { + if (!strcmp(argv[i], "-g") || !strcmp(argv[i], "-geometry")) { + XParseGeometry(argv[++i], &x, &y, &w, &h); + } + } + + display = XOpenDisplay(NULL); + + if (display == NULL) { + fprintf(stderr, "couldn't connect to X server :0\n"); + return 0; + } + + xswa.override_redirect = True; + xswamask = CWOverrideRedirect; + + win = XCreateWindow(display, RootWindow(display, 0), + x, y, w, h, 0, 0, InputOnly, + CopyFromParent, xswamask, &xswa); + + XMapWindow(display, win); + XFlush(display); + + while (1) { + XNextEvent(display, &report); + } + + return 1; +} diff --git a/version.h.in b/version.h.in deleted file mode 100644 index da3f02e..0000000 --- a/version.h.in +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef ob__version_h -#define ob__version_h - -#define OB_MAJOR_VERSION @OB_MAJOR_VERSION@ -#define OB_MINOR_VERSION @OB_MINOR_VERSION@ -#define OB_MICRO_VERSION @OB_MICRO_VERSION@ -#define OB_VERSION OB_MAJOR_VERSION.OB_MINOR_VERSION.OB_MICRO_VERSION - -#define OB_CHECK_VERSION(major,minor,micro) \ - (OB_MAJOR_VERSION > (major) || \ - (OB_MAJOR_VERSION == (major) && OB_MINOR_VERSION > (minor)) || \ - (OB_MAJOR_VERSION == (major) && OB_MINOR_VERSION == (minor) && \ - OB_MICRO_VERSION >= (micro))) - -#endif