summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSam Spilsbury <sam.spilsbury@canonical.com>2010-12-07 00:41:58 +0800
committerSam Spilsbury <sam.spilsbury@canonical.com>2010-12-07 00:41:58 +0800
commit0cb1fc6a0a8d9f42df21bd804d701c836c41155c (patch)
treed987e508cc86825c8258533d208e7eeb8f20aa37 /src
parent096e343ae70adc96ffe4351182cbcf89aa181579 (diff)
downloadunity-window-decorator-0cb1fc6a0a8d9f42df21bd804d701c836c41155c.tar.gz
unity-window-decorator-0cb1fc6a0a8d9f42df21bd804d701c836c41155c.tar.bz2
Added sources
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt210
-rw-r--r--src/TODO6
-rw-r--r--src/actionmenu.c109
-rw-r--r--src/blurprops.c68
-rw-r--r--src/cairo.c876
-rw-r--r--src/config.h.gtk.in25
-rw-r--r--src/decorator.c872
-rw-r--r--src/decorprops.c134
-rw-r--r--src/events.c1133
-rw-r--r--src/forcequit.c176
-rw-r--r--src/gdk.c87
-rw-r--r--src/gtk-window-decorator.c407
-rw-r--r--src/gtk-window-decorator.h949
-rw-r--r--src/gwd.schemas.in81
-rw-r--r--src/metacity.c1591
-rw-r--r--src/settings.c560
-rw-r--r--src/style.c42
-rw-r--r--src/switcher.c427
-rw-r--r--src/tooltip.c184
-rw-r--r--src/util.c278
-rw-r--r--src/wnck.c601
21 files changed, 8670 insertions, 146 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index afd7551..9cd5c96 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,162 +1,80 @@
-function (compiz_install_gconf_schema _src _dst)
- pkg_check_modules (GCONF gconf-2.0)
- find_program (GCONFTOOL_EXECUTABLE gconftool-2)
- mark_as_advanced (FORCE GCONFTOOL_EXECUTABLE)
-
- if (GCONFTOOL_EXECUTABLE AND NOT COMPIZ_DISABLE_SCHEMAS_INSTALL)
- install (CODE "
- if (\"\$ENV{USER}\" STREQUAL \"root\")
- exec_program (${GCONFTOOL_EXECUTABLE}
- ARGS \"--get-default-source\"
- OUTPUT_VARIABLE ENV{GCONF_CONFIG_SOURCE})
- exec_program (${GCONFTOOL_EXECUTABLE}
- ARGS \"--makefile-install-rule ${_src} > /dev/null\")
- else (\"\$ENV{USER}\" STREQUAL \"root\")
- exec_program (${GCONFTOOL_EXECUTABLE}
- ARGS \"--install-schema-file=${_src} > /dev/null\")
- endif (\"\$ENV{USER}\" STREQUAL \"root\")
- ")
- endif ()
- install (
- FILES "${_src}"
- DESTINATION "${COMPIZ_DESTDIR}${_dst}"
+if (USE_GTK)
+
+ if (COMPIZ_BUILD_WITH_RPATH)
+ set (CMAKE_INSTALL_RPATH ${libdir})
+ endif (COMPIZ_BUILD_WITH_RPATH)
+
+ include_directories (
+ ${compiz_SOURCE_DIR}/include
+ ${CMAKE_BINARY_DIR}/gtk
+ ${GTK_WINDOW_DECORATOR_INCLUDE_DIRS}
+ ${METACITY_INCLUDE_DIRS}
+ ${GCONF_INCLUDE_DIRS}
+ ${DBUS_GLIB_INCLUDE_DIRS}
)
-endfunction ()
-
-set (USE_GCONF_GTK_WINDOW_DECORATOR 1 CACHE BOOL "Install GConf schemas for GTK Window Decorator")
-if (BUILD_GTK)
-
- pkg_check_modules (GTK_WINDOW_DECORATOR
- libdecoration
- gconf-2.0
- xrender>=0.8.4
- gtk+-2.0>=2.18.0
- libwnck-1.0
- pangocairo
+ add_definitions (
+ -DHAVE_CONFIG_H
+ -DALL_LINGUAS=\"${ALL_LINGUAS}\"
+ -DLOCALEDIR=\\\"${datadir}/locale\\\"
)
- if (GTK_WINDOW_DECORATOR_FOUND)
- include (CheckFunctionExists)
- set (CMAKE_REQUIRED_FLAGS ${GTK_WINDOW_DECORATOR_CFLAGS})
- set (CMAKE_REQUIRED_LIBRARIES ${GTK_WINDOW_DECORATOR_LIBRARIES})
- list (FIND CMAKE_REQUIRED_FLAGS "-D_REENTRANT" REENTRANT_INDEX)
- if (REENTRANT_INDEX)
- list (REMOVE_AT CMAKE_REQUIRED_FLAGS REENTRANT_INDEX)
- list (APPEND CMAKE_REQUIRED_FLAGS "-D_REENTRANT=1")
- endif (REENTRANT_INDEX)
- check_function_exists (wnck_window_has_name HAVE_WNCK_WINDOW_HAS_NAME)
- set (CMAKE_REQUIRED_FLAGS "")
- set (CMAKE_REQUIRED_LIBRARIES "")
-
- compiz_pkg_check_modules (HAVE_LIBWNCK_2_18_1 libwnck-1.0>=2.18.1)
- compiz_pkg_check_modules (HAVE_LIBWNCK_2_19_4 libwnck-1.0>=2.19.4)
-
- if (BUILD_METACITY)
- pkg_check_modules (METACITY libmetacity-private)
- if (METACITY_FOUND)
- compiz_pkg_check_modules (HAVE_METACITY_2_15_21 libmetacity-private>=2.15.21)
- compiz_pkg_check_modules (HAVE_METACITY_2_17_0 libmetacity-private>=2.17.0)
- compiz_pkg_check_modules (HAVE_METACITY_2_23_2 libmetacity-private>=2.23.2)
- else (METACITY_FOUND)
- compiz_set (USE_METACITY 0)
- endif (METACITY_FOUND)
- endif (BUILD_METACITY)
-
- if (COMPIZ_BUILD_WITH_RPATH)
- set (CMAKE_INSTALL_RPATH ${libdir})
- endif (COMPIZ_BUILD_WITH_RPATH)
-
- configure_file (
- ${CMAKE_CURRENT_SOURCE_DIR}/config.h.gtk.in
- ${CMAKE_CURRENT_BINARY_DIR}/config.h
- )
- include_directories (
- ${CMAKE_CURRENT_BINARY_DIR}
- ${GTK_WINDOW_DECORATOR_INCLUDE_DIRS}
- ${METACITY_INCLUDE_DIRS}
- ${GCONF_INCLUDE_DIRS}
- ${DBUS_GLIB_INCLUDE_DIRS}
- )
-
- add_definitions (
- -DHAVE_CONFIG_H
- -DALL_LINGUAS=\"${ALL_LINGUAS}\"
- -DLOCALEDIR=\\\"${datadir}/locale\\\"
- )
+ link_directories (
+ ${COMPIZ_LINK_DIRS}
+ )
- link_directories (
- ${GTK_WINDOW_DECORATOR_LIBRARY_DIRS}
- ${COMPIZ_LINK_DIRS}
+ if (USE_GCONF)
+ set (gwd_schema ${CMAKE_CURRENT_BINARY_DIR}/gwd.schemas)
+ compiz_translate_xml (
+ ${CMAKE_CURRENT_SOURCE_DIR}/gwd.schemas.in
+ ${gwd_schema}
)
+ compiz_install_gconf_schema (${CMAKE_CURRENT_BINARY_DIR}/gwd.schemas ${SCHEMADIR})
+ endif (USE_GCONF)
+
+ add_executable (gtk-window-decorator
+ gtk-window-decorator.c
+ blurprops.c
+ decorprops.c
+ cairo.c
+ gdk.c
+ switcher.c
+ metacity.c
+ events.c
+ forcequit.c
+ tooltip.c
+ actionmenu.c
+ settings.c
+ util.c
+ style.c
+ wnck.c
+ decorator.c
+ ${gwd_schema}
+ )
- if (USE_GCONF_GTK_WINDOW_DECORATOR)
-
- if (NOT COMPIZ_INSTALL_GCONF_SCHEMA_DIR)
- set (SCHEMADIR "${CMAKE_INSTALL_PREFIX}/share/gconf/schemas")
- else (NOT COMPIZ_INSTALL_GCONF_SCHEMA_DIR)
- set (SCHEMADIR "${COMPIZ_INSTALL_GCONF_SCHEMA_DIR}")
- endif (NOT COMPIZ_INSTALL_GCONF_SCHEMA_DIR)
-
- set (gwd_schema ${CMAKE_CURRENT_BINARY_DIR}/gwd.schemas)
-
- compiz_translate_xml (
- ${CMAKE_CURRENT_SOURCE_DIR}/gwd.schemas.in
- ${gwd_schema}
- )
-
- compiz_install_gconf_schema (${CMAKE_CURRENT_BINARY_DIR}/gwd.schemas ${SCHEMADIR})
-
- endif (USE_GCONF_GTK_WINDOW_DECORATOR)
-
- add_executable (gtk-window-decorator
- gtk-window-decorator.c
- blurprops.c
- decorprops.c
- cairo.c
- gdk.c
- switcher.c
- metacity.c
- events.c
- forcequit.c
- tooltip.c
- actionmenu.c
- settings.c
- util.c
- style.c
- wnck.c
- decorator.c
- ${gwd_schema}
- )
+ add_dependencies (gtk-window-decorator decoration)
- if (USE_METACITY)
- set (metacitylibs ${METACITY_LIBRARIES})
- endif (USE_METACITY)
+ if (USE_METACITY)
+ set (metacitylibs ${METACITY_LIBRARIES})
+ endif (USE_METACITY)
- set_target_properties (
- gtk-window-decorator PROPERTIES
- INSTALL_RPATH_USE_LINK_PATH 0
- COMPILE_FLAGS ${GTK_WINDOW_DECORATOR_CFLAGS}
- )
- target_link_libraries (gtk-window-decorator
- ${GTK_WINDOW_DECORATOR_LIBRARIES}
- ${GCONF_LIBRARIES}
- ${DBUS_GLIB_LIBRARIES}
- ${metacitylibs}
- )
+ target_link_libraries (
+ gtk-window-decorator
+ decoration
+ ${GTK_WINDOW_DECORATOR_LIBRARIES}
+ ${GCONF_LIBRARIES}
+ ${DBUS_GLIB_LIBRARIES}
+ ${metacitylibs}
+ )
- install (
- TARGETS gtk-window-decorator
- DESTINATION ${COMPIZ_DESTDIR}${exec_prefix}
- RUNTIME DESTINATION bin
- )
+ install (
+ TARGETS gtk-window-decorator
+ DESTINATION ${COMPIZ_DESTDIR}${exec_prefix}
+ )
- else (GTK_WINDOW_DECORATOR_FOUND)
- set (USE_GTK 0)
- endif (GTK_WINDOW_DECORATOR_FOUND)
-endif (BUILD_GTK)
+endif (USE_GTK)
diff --git a/src/TODO b/src/TODO
new file mode 100644
index 0000000..d1b8e93
--- /dev/null
+++ b/src/TODO
@@ -0,0 +1,6 @@
+
+* Plugin interface
+
+* Plugin with SVG-based theme support
+
+* Plugin that supports old metacity themes \ No newline at end of file
diff --git a/src/actionmenu.c b/src/actionmenu.c
new file mode 100644
index 0000000..27c9821
--- /dev/null
+++ b/src/actionmenu.c
@@ -0,0 +1,109 @@
+#include "gtk-window-decorator.h"
+
+static void
+action_menu_unmap (GObject *object)
+{
+ action_menu_mapped = FALSE;
+}
+
+static void
+position_action_menu (GtkMenu *menu,
+ gint *x,
+ gint *y,
+ gboolean *push_in,
+ gpointer user_data)
+{
+ WnckWindow *win = (WnckWindow *) user_data;
+ decor_t *d = g_object_get_data (G_OBJECT (win), "decor");
+ gint bx, by, width, height;
+
+ wnck_window_get_client_window_geometry (win, x, y, &width, &height);
+
+ if ((*theme_get_button_position) (d, BUTTON_MENU, width, height,
+ &bx, &by, &width, &height))
+ *x = *x - _win_extents.left + bx;
+
+ if (gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL)
+ {
+ GtkRequisition req;
+
+ gtk_widget_size_request (GTK_WIDGET (menu), &req);
+ *x = MAX (0, *x - req.width + width);
+ }
+
+ *push_in = TRUE;
+}
+
+void
+action_menu_map (WnckWindow *win,
+ long button,
+ Time time)
+{
+ GdkDisplay *gdkdisplay;
+ GdkScreen *screen;
+
+ gdkdisplay = gdk_display_get_default ();
+ screen = gdk_display_get_default_screen (gdkdisplay);
+
+ if (action_menu)
+ {
+ if (action_menu_mapped)
+ {
+ gtk_widget_destroy (action_menu);
+ action_menu_mapped = FALSE;
+ action_menu = NULL;
+ return;
+ }
+ else
+ gtk_widget_destroy (action_menu);
+ }
+
+ switch (wnck_window_get_window_type (win)) {
+ case WNCK_WINDOW_DESKTOP:
+ case WNCK_WINDOW_DOCK:
+ /* don't allow window action */
+ return;
+ case WNCK_WINDOW_NORMAL:
+ case WNCK_WINDOW_DIALOG:
+
+#ifndef HAVE_LIBWNCK_2_19_4
+ case WNCK_WINDOW_MODAL_DIALOG:
+#endif
+
+ case WNCK_WINDOW_TOOLBAR:
+ case WNCK_WINDOW_MENU:
+ case WNCK_WINDOW_UTILITY:
+ case WNCK_WINDOW_SPLASHSCREEN:
+ /* allow window action menu */
+ break;
+ }
+
+ action_menu = wnck_create_window_action_menu (win);
+
+ gtk_menu_set_screen (GTK_MENU (action_menu), screen);
+
+ g_signal_connect_object (G_OBJECT (action_menu), "unmap",
+ G_CALLBACK (action_menu_unmap),
+ 0, 0);
+
+ gtk_widget_show (action_menu);
+
+ if (!button || button == 1)
+ {
+ gtk_menu_popup (GTK_MENU (action_menu),
+ NULL, NULL,
+ position_action_menu, (gpointer) win,
+ button,
+ time);
+ }
+ else
+ {
+ gtk_menu_popup (GTK_MENU (action_menu),
+ NULL, NULL,
+ NULL, NULL,
+ button,
+ time);
+ }
+
+ action_menu_mapped = TRUE;
+}
diff --git a/src/blurprops.c b/src/blurprops.c
new file mode 100644
index 0000000..d30979b
--- /dev/null
+++ b/src/blurprops.c
@@ -0,0 +1,68 @@
+#include "gtk-window-decorator.h"
+
+void
+decor_update_blur_property (decor_t *d,
+ int width,
+ int height,
+ Region top_region,
+ int top_offset,
+ Region bottom_region,
+ int bottom_offset,
+ Region left_region,
+ int left_offset,
+ Region right_region,
+ int right_offset)
+{
+ Display *xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
+ long *data = NULL;
+ int size = 0;
+
+ if (blur_type != BLUR_TYPE_ALL)
+ {
+ bottom_region = NULL;
+ left_region = NULL;
+ right_region = NULL;
+
+ if (blur_type != BLUR_TYPE_TITLEBAR)
+ top_region = NULL;
+ }
+
+ if (top_region)
+ size += top_region->numRects;
+ if (bottom_region)
+ size += bottom_region->numRects;
+ if (left_region)
+ size += left_region->numRects;
+ if (right_region)
+ size += right_region->numRects;
+
+ if (size)
+ data = (long *) malloc (sizeof (long) * (2 + size * 6));
+
+ if (data)
+ {
+ decor_region_to_blur_property (data, 4, 0, width, height,
+ top_region, top_offset,
+ bottom_region, bottom_offset,
+ left_region, left_offset,
+ right_region, right_offset);
+
+ gdk_error_trap_push ();
+ XChangeProperty (xdisplay, d->prop_xid,
+ win_blur_decor_atom,
+ XA_INTEGER,
+ 32, PropModeReplace, (guchar *) data,
+ 2 + size * 6);
+ gdk_display_sync (gdk_display_get_default ());
+ gdk_error_trap_pop ();
+
+ free (data);
+ }
+ else
+ {
+ gdk_error_trap_push ();
+ XDeleteProperty (xdisplay, d->prop_xid, win_blur_decor_atom);
+ gdk_display_sync (gdk_display_get_default ());
+ gdk_error_trap_pop ();
+ }
+} \ No newline at end of file
diff --git a/src/cairo.c b/src/cairo.c
new file mode 100644
index 0000000..a9b8f42
--- /dev/null
+++ b/src/cairo.c
@@ -0,0 +1,876 @@
+#include "gtk-window-decorator.h"
+
+void
+rounded_rectangle (cairo_t *cr,
+ double x,
+ double y,
+ double w,
+ double h,
+ double radius,
+ int corner)
+{
+ if (corner & CORNER_TOPLEFT)
+ cairo_move_to (cr, x + radius, y);
+ else
+ cairo_move_to (cr, x, y);
+
+ if (corner & CORNER_TOPRIGHT)
+ cairo_arc (cr, x + w - radius, y + radius, radius,
+ M_PI * 1.5, M_PI * 2.0);
+ else
+ cairo_line_to (cr, x + w, y);
+
+ if (corner & CORNER_BOTTOMRIGHT)
+ cairo_arc (cr, x + w - radius, y + h - radius, radius,
+ 0.0, M_PI * 0.5);
+ else
+ cairo_line_to (cr, x + w, y + h);
+
+ if (corner & CORNER_BOTTOMLEFT)
+ cairo_arc (cr, x + radius, y + h - radius, radius,
+ M_PI * 0.5, M_PI);
+ else
+ cairo_line_to (cr, x, y + h);
+
+ if (corner & CORNER_TOPLEFT)
+ cairo_arc (cr, x + radius, y + radius, radius, M_PI, M_PI * 1.5);
+ else
+ cairo_line_to (cr, x, y);
+}
+
+void
+fill_rounded_rectangle (cairo_t *cr,
+ double x,
+ double y,
+ double w,
+ double h,
+ double radius,
+ int corner,
+ decor_color_t *c0,
+ double alpha0,
+ decor_color_t *c1,
+ double alpha1,
+ int gravity)
+{
+ cairo_pattern_t *pattern;
+
+ rounded_rectangle (cr, x, y, w, h, radius, corner);
+
+ if (gravity & SHADE_RIGHT)
+ {
+ x = x + w;
+ w = -w;
+ }
+ else if (!(gravity & SHADE_LEFT))
+ {
+ x = w = 0;
+ }
+
+ if (gravity & SHADE_BOTTOM)
+ {
+ y = y + h;
+ h = -h;
+ }
+ else if (!(gravity & SHADE_TOP))
+ {
+ y = h = 0;
+ }
+
+ if (w && h)
+ {
+ cairo_matrix_t matrix;
+
+ pattern = cairo_pattern_create_radial (0.0, 0.0, 0.0, 0.0, 0.0, w);
+
+ cairo_matrix_init_scale (&matrix, 1.0, w / h);
+ cairo_matrix_translate (&matrix, -(x + w), -(y + h));
+
+ cairo_pattern_set_matrix (pattern, &matrix);
+ }
+ else
+ {
+ pattern = cairo_pattern_create_linear (x + w, y + h, x, y);
+ }
+
+ cairo_pattern_add_color_stop_rgba (pattern, 0.0, c0->r, c0->g, c0->b,
+ alpha0);
+
+ cairo_pattern_add_color_stop_rgba (pattern, 1.0, c1->r, c1->g, c1->b,
+ alpha1);
+
+ cairo_pattern_set_extend (pattern, CAIRO_EXTEND_PAD);
+
+ cairo_set_source (cr, pattern);
+ cairo_fill (cr);
+ cairo_pattern_destroy (pattern);
+}
+
+void
+draw_shadow_background (decor_t *d,
+ cairo_t *cr,
+ decor_shadow_t *s,
+ decor_context_t *c)
+{
+ Display *xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
+
+ if (!s || !s->picture ||!d->picture)
+ {
+ cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.0);
+ cairo_paint (cr);
+ }
+ else
+ {
+ decor_fill_picture_extents_with_shadow (xdisplay,
+ s, c,
+ d->picture,
+ &d->border_layout);
+ }
+}
+
+static void
+draw_close_button (decor_t *d,
+ cairo_t *cr,
+ double s)
+{
+ cairo_rel_move_to (cr, 0.0, s);
+
+ cairo_rel_line_to (cr, s, -s);
+ cairo_rel_line_to (cr, s, s);
+ cairo_rel_line_to (cr, s, -s);
+ cairo_rel_line_to (cr, s, s);
+
+ cairo_rel_line_to (cr, -s, s);
+ cairo_rel_line_to (cr, s, s);
+ cairo_rel_line_to (cr, -s, s);
+ cairo_rel_line_to (cr, -s, -s);
+
+ cairo_rel_line_to (cr, -s, s);
+ cairo_rel_line_to (cr, -s, -s);
+ cairo_rel_line_to (cr, s, -s);
+
+ cairo_close_path (cr);
+}
+
+static void
+draw_max_button (decor_t *d,
+ cairo_t *cr,
+ double s)
+{
+ cairo_rel_line_to (cr, 12.0, 0.0);
+ cairo_rel_line_to (cr, 0.0, 12.0);
+ cairo_rel_line_to (cr, -12.0, 0.0);
+
+ cairo_close_path (cr);
+
+ cairo_rel_move_to (cr, 2.0, s);
+
+ cairo_rel_line_to (cr, 12.0 - 4.0, 0.0);
+ cairo_rel_line_to (cr, 0.0, 12.0 - s - 2.0);
+ cairo_rel_line_to (cr, -(12.0 - 4.0), 0.0);
+
+ cairo_close_path (cr);
+}
+
+static void
+draw_unmax_button (decor_t *d,
+ cairo_t *cr,
+ double s)
+{
+ cairo_rel_move_to (cr, 1.0, 1.0);
+
+ cairo_rel_line_to (cr, 10.0, 0.0);
+ cairo_rel_line_to (cr, 0.0, 10.0);
+ cairo_rel_line_to (cr, -10.0, 0.0);
+
+ cairo_close_path (cr);
+
+ cairo_rel_move_to (cr, 2.0, s);
+
+ cairo_rel_line_to (cr, 10.0 - 4.0, 0.0);
+ cairo_rel_line_to (cr, 0.0, 10.0 - s - 2.0);
+ cairo_rel_line_to (cr, -(10.0 - 4.0), 0.0);
+
+ cairo_close_path (cr);
+}
+
+static void
+draw_min_button (decor_t *d,
+ cairo_t *cr,
+ double s)
+{
+ cairo_rel_move_to (cr, 0.0, 8.0);
+
+ cairo_rel_line_to (cr, 12.0, 0.0);
+ cairo_rel_line_to (cr, 0.0, s);
+ cairo_rel_line_to (cr, -12.0, 0.0);
+
+ cairo_close_path (cr);
+}
+
+typedef void (*draw_proc) (cairo_t *cr);
+
+static void
+button_state_offsets (gdouble x,
+ gdouble y,
+ guint state,
+ gdouble *return_x,
+ gdouble *return_y)
+{
+ static double off[] = { 0.0, 0.0, 0.0, 0.5 };
+
+ *return_x = x + off[state];
+ *return_y = y + off[state];
+}
+
+static void
+button_state_paint (cairo_t *cr,
+ GtkStyle *style,
+ decor_color_t *color,
+ guint state)
+{
+
+#define IN_STATE (PRESSED_EVENT_WINDOW | IN_EVENT_WINDOW)
+
+ if ((state & IN_STATE) == IN_STATE)
+ {
+ if (state & IN_EVENT_WINDOW)
+ cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
+ else
+ cairo_set_source_rgba (cr, color->r, color->g, color->b, 0.95);
+
+ cairo_fill_preserve (cr);
+
+ gdk_cairo_set_source_color_alpha (cr,
+ &style->fg[GTK_STATE_NORMAL],
+ STROKE_ALPHA);
+
+ cairo_set_line_width (cr, 1.0);
+ cairo_stroke (cr);
+ cairo_set_line_width (cr, 2.0);
+ }
+ else
+ {
+ gdk_cairo_set_source_color_alpha (cr,
+ &style->fg[GTK_STATE_NORMAL],
+ STROKE_ALPHA);
+ cairo_stroke_preserve (cr);
+
+ if (state & IN_EVENT_WINDOW)
+ cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
+ else
+ cairo_set_source_rgba (cr, color->r, color->g, color->b, 0.95);
+
+ cairo_fill (cr);
+ }
+}
+
+void
+draw_window_decoration (decor_t *d)
+{
+ cairo_t *cr;
+ GtkStyle *style;
+ GdkDrawable *drawable;
+ decor_color_t color;
+ double alpha;
+ double x1, y1, x2, y2, x, y, h;
+ int corners = SHADE_LEFT | SHADE_RIGHT | SHADE_TOP | SHADE_BOTTOM;
+ int top;
+ int button_x;
+
+ if (!d->pixmap)
+ return;
+
+ style = gtk_widget_get_style (style_window_rgba);
+
+ if (d->state & (WNCK_WINDOW_STATE_MAXIMIZED_HORIZONTALLY |
+ WNCK_WINDOW_STATE_MAXIMIZED_VERTICALLY))
+ corners = 0;
+
+ color.r = style->bg[GTK_STATE_NORMAL].red / 65535.0;
+ color.g = style->bg[GTK_STATE_NORMAL].green / 65535.0;
+ color.b = style->bg[GTK_STATE_NORMAL].blue / 65535.0;
+
+ if (d->frame_window)
+ {
+ GdkColormap *cmap;
+
+ cmap = get_colormap_for_drawable (GDK_DRAWABLE (d->pixmap));
+ gdk_drawable_set_colormap (GDK_DRAWABLE (d->pixmap), cmap);
+ gdk_drawable_set_colormap (GDK_DRAWABLE (d->buffer_pixmap), cmap);
+ drawable = GDK_DRAWABLE (d->buffer_pixmap);
+ }
+ else if (d->buffer_pixmap)
+ drawable = GDK_DRAWABLE (d->buffer_pixmap);
+ else
+ drawable = GDK_DRAWABLE (d->pixmap);
+
+ cr = gdk_cairo_create (GDK_DRAWABLE (drawable));
+ if (!cr)
+ return;
+
+ cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
+
+ top = _win_extents.top + titlebar_height;
+
+ x1 = d->context->left_space - _win_extents.left;
+ y1 = d->context->top_space - _win_extents.top - titlebar_height;
+ x2 = d->width - d->context->right_space + _win_extents.right;
+ y2 = d->height - d->context->bottom_space + _win_extents.bottom;
+
+ h = d->height - d->context->top_space - d->context->bottom_space;
+
+ cairo_set_line_width (cr, 1.0);
+
+ if (!d->frame_window)
+ draw_shadow_background (d, cr, d->shadow, d->context);
+
+ if (d->active)
+ {
+ decor_color_t *title_color = _title_color;
+
+ alpha = decoration_alpha + 0.3;
+
+ fill_rounded_rectangle (cr,
+ x1 + 0.5,
+ y1 + 0.5,
+ _win_extents.left - 0.5,
+ top - 0.5,
+ 5.0, CORNER_TOPLEFT & corners,
+ &title_color[0], 1.0, &title_color[1], alpha,
+ SHADE_TOP | SHADE_LEFT);
+
+ fill_rounded_rectangle (cr,
+ x1 + _win_extents.left,
+ y1 + 0.5,
+ x2 - x1 - _win_extents.left -
+ _win_extents.right,
+ top - 0.5,
+ 5.0, 0,
+ &title_color[0], 1.0, &title_color[1], alpha,
+ SHADE_TOP);
+
+ fill_rounded_rectangle (cr,
+ x2 - _win_extents.right,
+ y1 + 0.5,
+ _win_extents.right - 0.5,
+ top - 0.5,
+ 5.0, CORNER_TOPRIGHT & corners,
+ &title_color[0], 1.0, &title_color[1], alpha,
+ SHADE_TOP | SHADE_RIGHT);
+ }
+ else
+ {
+ alpha = decoration_alpha;
+
+ fill_rounded_rectangle (cr,
+ x1 + 0.5,
+ y1 + 0.5,
+ _win_extents.left - 0.5,
+ top - 0.5,
+ 5.0, CORNER_TOPLEFT & corners,
+ &color, 1.0, &color, alpha,
+ SHADE_TOP | SHADE_LEFT);
+
+ fill_rounded_rectangle (cr,
+ x1 + _win_extents.left,
+ y1 + 0.5,
+ x2 - x1 - _win_extents.left -
+ _win_extents.right,
+ top - 0.5,
+ 5.0, 0,
+ &color, 1.0, &color, alpha,
+ SHADE_TOP);
+
+ fill_rounded_rectangle (cr,
+ x2 - _win_extents.right,
+ y1 + 0.5,
+ _win_extents.right - 0.5,
+ top - 0.5,
+ 5.0, CORNER_TOPRIGHT & corners,
+ &color, 1.0, &color, alpha,
+ SHADE_TOP | SHADE_RIGHT);
+ }
+
+ fill_rounded_rectangle (cr,
+ x1 + 0.5,
+ y1 + top,
+ _win_extents.left - 0.5,
+ h,
+ 5.0, 0,
+ &color, 1.0, &color, alpha,
+ SHADE_LEFT);
+
+ fill_rounded_rectangle (cr,
+ x2 - _win_extents.right,
+ y1 + top,
+ _win_extents.right - 0.5,
+ h,
+ 5.0, 0,
+ &color, 1.0, &color, alpha,
+ SHADE_RIGHT);
+
+
+ fill_rounded_rectangle (cr,
+ x1 + 0.5,
+ y2 - _win_extents.bottom,
+ _win_extents.left - 0.5,
+ _win_extents.bottom - 0.5,
+ 5.0, CORNER_BOTTOMLEFT & corners,
+ &color, 1.0, &color, alpha,
+ SHADE_BOTTOM | SHADE_LEFT);
+
+ fill_rounded_rectangle (cr,
+ x1 + _win_extents.left,
+ y2 - _win_extents.bottom,
+ x2 - x1 - _win_extents.left -
+ _win_extents.right,
+ _win_extents.bottom - 0.5,
+ 5.0, 0,
+ &color, 1.0, &color, alpha,
+ SHADE_BOTTOM);
+
+ fill_rounded_rectangle (cr,
+ x2 - _win_extents.right,
+ y2 - _win_extents.bottom,
+ _win_extents.right - 0.5,
+ _win_extents.bottom - 0.5,
+ 5.0, CORNER_BOTTOMRIGHT & corners,
+ &color, 1.0, &color, alpha,
+ SHADE_BOTTOM | SHADE_RIGHT);
+
+ cairo_rectangle (cr,
+ d->context->left_space,
+ d->context->top_space,
+ d->width - d->context->left_space -
+ d->context->right_space,
+ h);
+ gdk_cairo_set_source_color (cr, &style->bg[GTK_STATE_NORMAL]);
+ cairo_fill (cr);
+
+ cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
+
+ if (d->active)
+ {
+ gdk_cairo_set_source_color_alpha (cr,
+ &style->fg[GTK_STATE_NORMAL],
+ 0.7);
+
+ cairo_move_to (cr, x1 + 0.5, y1 + top - 0.5);
+ cairo_rel_line_to (cr, x2 - x1 - 1.0, 0.0);
+
+ cairo_stroke (cr);
+ }
+
+ rounded_rectangle (cr,
+ x1 + 0.5, y1 + 0.5,
+ x2 - x1 - 1.0, y2 - y1 - 1.0,
+ 5.0,
+ (CORNER_TOPLEFT | CORNER_TOPRIGHT | CORNER_BOTTOMLEFT |
+ CORNER_BOTTOMRIGHT) & corners);
+
+ cairo_clip (cr);
+
+ cairo_translate (cr, 1.0, 1.0);
+
+ rounded_rectangle (cr,
+ x1 + 0.5, y1 + 0.5,
+ x2 - x1 - 1.0, y2 - y1 - 1.0,
+ 5.0,
+ (CORNER_TOPLEFT | CORNER_TOPRIGHT | CORNER_BOTTOMLEFT |
+ CORNER_BOTTOMRIGHT) & corners);
+
+ cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.4);
+
+ cairo_stroke (cr);
+
+ cairo_translate (cr, -2.0, -2.0);
+
+ rounded_rectangle (cr,
+ x1 + 0.5, y1 + 0.5,
+ x2 - x1 - 1.0, y2 - y1 - 1.0,
+ 5.0,
+ (CORNER_TOPLEFT | CORNER_TOPRIGHT | CORNER_BOTTOMLEFT |
+ CORNER_BOTTOMRIGHT) & corners);
+
+ cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.1);
+
+ cairo_stroke (cr);
+
+ cairo_translate (cr, 1.0, 1.0);
+
+ cairo_reset_clip (cr);
+
+ rounded_rectangle (cr,
+ x1 + 0.5, y1 + 0.5,
+ x2 - x1 - 1.0, y2 - y1 - 1.0,
+ 5.0,
+ (CORNER_TOPLEFT | CORNER_TOPRIGHT | CORNER_BOTTOMLEFT |
+ CORNER_BOTTOMRIGHT) & corners);
+
+ gdk_cairo_set_source_color_alpha (cr,
+ &style->fg[GTK_STATE_NORMAL],
+ alpha);
+
+ cairo_stroke (cr);
+
+ cairo_set_line_width (cr, 2.0);
+
+ button_x = d->width - d->context->right_space - 13;
+
+ if (d->actions & WNCK_WINDOW_ACTION_CLOSE)
+ {
+ button_state_offsets (button_x,
+ y1 - 3.0 + titlebar_height / 2,
+ d->button_states[BUTTON_CLOSE], &x, &y);
+
+ button_x -= 17;
+
+ if (d->active)
+ {
+ cairo_move_to (cr, x, y);
+ draw_close_button (d, cr, 3.0);
+ button_state_paint (cr, style, &color,
+ d->button_states[BUTTON_CLOSE]);
+ }
+ else
+ {
+ gdk_cairo_set_source_color_alpha (cr,
+ &style->fg[GTK_STATE_NORMAL],
+ alpha * 0.75);
+
+ cairo_move_to (cr, x, y);
+ draw_close_button (d, cr, 3.0);
+ cairo_fill (cr);
+ }
+ }
+
+ if (d->actions & WNCK_WINDOW_ACTION_MAXIMIZE)
+ {
+ button_state_offsets (button_x,
+ y1 - 3.0 + titlebar_height / 2,
+ d->button_states[BUTTON_MAX], &x, &y);
+
+ button_x -= 17;
+
+ cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
+
+ if (d->active)
+ {
+ gdk_cairo_set_source_color_alpha (cr,
+ &style->fg[GTK_STATE_NORMAL],
+ STROKE_ALPHA);
+
+ cairo_move_to (cr, x, y);
+
+ if (d->state & (WNCK_WINDOW_STATE_MAXIMIZED_HORIZONTALLY |
+ WNCK_WINDOW_STATE_MAXIMIZED_VERTICALLY))
+ draw_unmax_button (d, cr, 4.0);
+ else
+ draw_max_button (d, cr, 4.0);
+
+ button_state_paint (cr, style, &color,
+ d->button_states[BUTTON_MAX]);
+ }
+ else
+ {
+ gdk_cairo_set_source_color_alpha (cr,
+ &style->fg[GTK_STATE_NORMAL],
+ alpha * 0.75);
+
+ cairo_move_to (cr, x, y);
+
+ if (d->state & (WNCK_WINDOW_STATE_MAXIMIZED_HORIZONTALLY |
+ WNCK_WINDOW_STATE_MAXIMIZED_VERTICALLY))
+ draw_unmax_button (d, cr, 4.0);
+ else
+ draw_max_button (d, cr, 4.0);
+
+ cairo_fill (cr);
+ }
+ }
+
+ if (d->actions & WNCK_WINDOW_ACTION_MINIMIZE)
+ {
+ button_state_offsets (button_x,
+ y1 - 3.0 + titlebar_height / 2,
+ d->button_states[BUTTON_MIN], &x, &y);
+
+ button_x -= 17;
+
+ if (d->active)
+ {
+ gdk_cairo_set_source_color_alpha (cr,
+ &style->fg[GTK_STATE_NORMAL],
+ STROKE_ALPHA);
+
+
+ cairo_move_to (cr, x, y);
+ draw_min_button (d, cr, 4.0);
+ button_state_paint (cr, style, &color,
+ d->button_states[BUTTON_MIN]);
+ }
+ else
+ {
+ gdk_cairo_set_source_color_alpha (cr,
+ &style->fg[GTK_STATE_NORMAL],
+ alpha * 0.75);
+
+ cairo_move_to (cr, x, y);
+ draw_min_button (d, cr, 4.0);
+ cairo_fill (cr);
+ }
+ }
+
+ if (d->layout)
+ {
+ if (d->active)
+ {
+ cairo_move_to (cr,
+ d->context->left_space + 21.0,
+ y1 + 2.0 + (titlebar_height - text_height) / 2.0);
+
+ gdk_cairo_set_source_color_alpha (cr,
+ &style->fg[GTK_STATE_NORMAL],
+ STROKE_ALPHA);
+
+ pango_cairo_layout_path (cr, d->layout);
+ cairo_stroke (cr);
+
+ cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
+ }
+ else
+ {
+ gdk_cairo_set_source_color_alpha (cr,
+ &style->fg[GTK_STATE_NORMAL],
+ alpha);
+ }
+
+ cairo_move_to (cr,
+ d->context->left_space + 21.0,
+ y1 + 2.0 + (titlebar_height - text_height) / 2.0);
+
+ pango_cairo_show_layout (cr, d->layout);
+ }
+
+ if (d->icon)
+ {
+ cairo_translate (cr, d->context->left_space + 1,
+ y1 - 5.0 + titlebar_height / 2);
+ cairo_set_source (cr, d->icon);
+ cairo_rectangle (cr, 0.0, 0.0, 16.0, 16.0);
+ cairo_clip (cr);
+
+ if (d->active)
+ cairo_paint (cr);
+ else
+ cairo_paint_with_alpha (cr, alpha);
+ }
+
+ cairo_destroy (cr);
+
+ copy_to_front_buffer (d);
+
+ if (d->frame_window)
+ {
+ GdkWindow *gdk_frame_window = gtk_widget_get_window (d->decor_window);
+
+ gtk_image_set_from_pixmap (GTK_IMAGE (d->decor_image), d->pixmap, NULL);
+ gtk_window_resize (GTK_WINDOW (d->decor_window), d->width, d->height);
+ gdk_window_move (gdk_frame_window, 0, 0);
+ gdk_window_lower (gdk_frame_window);
+ }
+
+ if (d->prop_xid)
+ {
+ decor_update_window_property (d);
+ d->prop_xid = 0;
+ }
+}
+
+static void
+calc_button_size (decor_t *d)
+{
+ gint button_width;
+
+ button_width = 0;
+
+ if (d->actions & WNCK_WINDOW_ACTION_CLOSE)
+ button_width += 17;
+
+ if (d->actions & (WNCK_WINDOW_ACTION_MAXIMIZE_HORIZONTALLY |
+ WNCK_WINDOW_ACTION_MAXIMIZE_VERTICALLY |
+ WNCK_WINDOW_ACTION_UNMAXIMIZE_HORIZONTALLY |
+ WNCK_WINDOW_ACTION_UNMAXIMIZE_VERTICALLY))
+ button_width += 17;
+
+ if (d->actions & (WNCK_WINDOW_ACTION_MINIMIZE |
+ WNCK_WINDOW_ACTION_MINIMIZE))
+ button_width += 17;
+
+ if (button_width)
+ button_width++;
+
+ d->button_width = button_width;
+}
+
+gboolean
+calc_decoration_size (decor_t *d,
+ gint w,
+ gint h,
+ gint name_width,
+ gint *width,
+ gint *height)
+{
+ decor_layout_t layout;
+ int top_width;
+
+ /* To avoid wasting texture memory, we only calculate the minimal
+ * required decoration size then clip and stretch the texture where
+ * appropriate
+ */
+
+ if (!d->frame_window)
+ {
+ calc_button_size (d);
+
+ if (w < ICON_SPACE + d->button_width)
+ return FALSE;
+
+ top_width = name_width + d->button_width + ICON_SPACE;
+ if (w < top_width)
+ top_width = MAX (ICON_SPACE + d->button_width, w);
+
+ decor_get_default_layout (&window_context, top_width, 1, &layout);
+
+ if (!d->context || memcmp (&layout, &d->border_layout, sizeof (layout)))
+ {
+ *width = layout.width;
+ *height = layout.height;
+
+ d->border_layout = layout;
+ d->context = &window_context;
+ d->shadow = border_shadow;
+
+ return TRUE;
+ }
+ }
+ else
+ {
+ calc_button_size (d);
+
+ /* _default_win_extents + top height */
+
+ top_width = name_width + d->button_width + ICON_SPACE;
+ if (w < top_width)
+ top_width = MAX (ICON_SPACE + d->button_width, w);
+
+ decor_get_default_layout (&window_context_no_shadow,
+ d->client_width, d->client_height, &layout);
+
+ *width = layout.width;
+ *height = layout.height;
+
+ d->border_layout = layout;
+ d->context = &window_context_no_shadow;
+ d->shadow = border_no_shadow;
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+gboolean
+get_button_position (decor_t *d,
+ gint i,
+ gint width,
+ gint height,
+ gint *x,
+ gint *y,
+ gint *w,
+ gint *h)
+{
+ if (i > BUTTON_MENU)
+ return FALSE;
+
+ if (d->frame_window)
+ {
+ *x = bpos[i].x + bpos[i].xw * width + _win_extents.left + 4;
+ *y = bpos[i].y + bpos[i].yh * height + bpos[i].yth *
+ (titlebar_height - 17) + _win_extents.top + 2;
+ }
+ else
+ {
+ *x = bpos[i].x + bpos[i].xw * width;
+ *y = bpos[i].y + bpos[i].yh * height + bpos[i].yth *
+ (titlebar_height - 17);
+ }
+
+ *w = bpos[i].w + bpos[i].ww * width;
+ *h = bpos[i].h + bpos[i].hh * height + bpos[i].hth +
+ (titlebar_height - 17);
+
+ /* hack to position multiple buttons on the right */
+ if (i != BUTTON_MENU)
+ *x -= 10 + 16 * i;
+
+ return TRUE;
+}
+
+void
+get_event_window_position (decor_t *d,
+ gint i,
+ gint j,
+ gint width,
+ gint height,
+ gint *x,
+ gint *y,
+ gint *w,
+ gint *h)
+{
+ if (d->frame_window)
+ {
+ *x = pos[i][j].x + pos[i][j].xw * width + _win_extents.left;
+ *y = pos[i][j].y + _win_extents.top +
+ pos[i][j].yh * height + pos[i][j].yth * (titlebar_height - 17);
+
+ if (i == 0 && (j == 0 || j == 2))
+ *y -= titlebar_height;
+ }
+ else
+ {
+ *x = pos[i][j].x + pos[i][j].xw * width;
+ *y = pos[i][j].y +
+ pos[i][j].yh * height + pos[i][j].yth * (titlebar_height - 17);
+ }
+
+ if ((d->state & WNCK_WINDOW_STATE_MAXIMIZED_HORIZONTALLY) &&
+ (j == 0 || j == 2))
+ {
+ *w = 0;
+ }
+ else
+ {
+ *w = pos[i][j].w + pos[i][j].ww * width;
+ }
+
+ if ((d->state & WNCK_WINDOW_STATE_MAXIMIZED_VERTICALLY) &&
+ (i == 0 || i == 2))
+ {
+ *h = 0;
+ }
+ else
+ {
+ *h = pos[i][j].h +
+ pos[i][j].hh * height + pos[i][j].hth * (titlebar_height - 17);
+ }
+}
+
+void
+update_border_extents (gint text_height)
+{
+ _win_extents = _default_win_extents;
+ _max_win_extents = _default_win_extents;
+ max_titlebar_height = titlebar_height =
+ (text_height < 17) ? 17 : text_height;
+}
diff --git a/src/config.h.gtk.in b/src/config.h.gtk.in
new file mode 100644
index 0000000..a9f34aa
--- /dev/null
+++ b/src/config.h.gtk.in
@@ -0,0 +1,25 @@
+/* Define to 1 if Metacity support is enabled */
+#cmakedefine USE_METACITY 1
+
+/* Define to 1 if Gconf support is enabled */
+#cmakedefine USE_GCONF_GTK_WINDOW_DECORATOR 1
+
+/* Define to 1 if you have the `wnck_window_has_name' function. */
+#cmakedefine HAVE_WNCK_WINDOW_HAS_NAME 1
+
+/* Define to 1 if libwnck version >= 2_18_1 */
+#cmakedefine HAVE_LIBWNCK_2_18_1 1
+
+/* Define to 1 if libwnck version >= 2_19_4 */
+#cmakedefine HAVE_LIBWNCK_2_19_4 1
+
+/* Define to 1 if metacity version >= 2.15.21 */
+#cmakedefine HAVE_METACITY_2_15_21 1
+
+/* Define to 1 if metacity version >= 2.17.0 */
+#cmakedefine HAVE_METACITY_2_17_0 1
+
+/* Define to 1 if metacity version >= 2.23.2 */
+#cmakedefine HAVE_METACITY_2_23_2 1
+
+#define GETTEXT_PACKAGE "${GETTEXT_PACKAGE}"
diff --git a/src/decorator.c b/src/decorator.c
new file mode 100644
index 0000000..68eb22f
--- /dev/null
+++ b/src/decorator.c
@@ -0,0 +1,872 @@
+#include "gtk-window-decorator.h"
+
+static const PangoFontDescription *
+get_titlebar_font (void)
+{
+ if (use_system_font)
+ {
+ return NULL;
+ }
+ else
+ return titlebar_font;
+}
+
+void
+update_titlebar_font (void)
+{
+ const PangoFontDescription *font_desc;
+ PangoFontMetrics *metrics;
+ PangoLanguage *lang;
+
+ font_desc = get_titlebar_font ();
+ if (!font_desc)
+ {
+ GtkStyle *default_style;
+
+ default_style = gtk_widget_get_default_style ();
+ font_desc = default_style->font_desc;
+ }
+
+ pango_context_set_font_description (pango_context, font_desc);
+
+ lang = pango_context_get_language (pango_context);
+ metrics = pango_context_get_metrics (pango_context, font_desc, lang);
+
+ text_height = PANGO_PIXELS (pango_font_metrics_get_ascent (metrics) +
+ pango_font_metrics_get_descent (metrics));
+
+ pango_font_metrics_unref (metrics);
+}
+
+void
+update_event_windows (WnckWindow *win)
+{
+ Display *xdisplay;
+ decor_t *d = g_object_get_data (G_OBJECT (win), "decor");
+ gint x0, y0, width, height, x, y, w, h;
+ gint i, j, k, l;
+ gint actions = d->actions;
+
+ xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
+
+ wnck_window_get_client_window_geometry (win, &x0, &y0, &width, &height);
+
+ if (d->state & WNCK_WINDOW_STATE_SHADED)
+ {
+ height = 0;
+ k = l = 1;
+ }
+ else
+ {
+ k = 0;
+ l = 2;
+ }
+
+ gdk_error_trap_push ();
+
+ for (i = 0; i < 3; i++)
+ {
+ static guint event_window_actions[3][3] = {
+ {
+ WNCK_WINDOW_ACTION_RESIZE,
+ WNCK_WINDOW_ACTION_RESIZE,
+ WNCK_WINDOW_ACTION_RESIZE
+ }, {
+ WNCK_WINDOW_ACTION_RESIZE,
+ WNCK_WINDOW_ACTION_MOVE,
+ WNCK_WINDOW_ACTION_RESIZE
+ }, {
+ WNCK_WINDOW_ACTION_RESIZE,
+ WNCK_WINDOW_ACTION_RESIZE,
+ WNCK_WINDOW_ACTION_RESIZE
+ }
+ };
+
+ for (j = 0; j < 3; j++)
+ {
+ w = 0;
+ h = 0;
+
+ if (actions & event_window_actions[i][j] && i >= k && i <= l)
+ (*theme_get_event_window_position) (d, i, j, width, height,
+ &x, &y, &w, &h);
+
+ if (d->frame_window)
+ {
+ BoxPtr box = &d->event_windows[i][j].pos;
+ box->x1 = x;
+ box->x2 = x + w;
+ box->y1 = y;
+ box->y2 = y + h;
+ }
+ else if (!d->frame_window && w != 0 && h != 0)
+ {
+ XMapWindow (xdisplay, d->event_windows[i][j].window);
+ XMoveResizeWindow (xdisplay, d->event_windows[i][j].window,
+ x, y, w, h);
+ }
+ else if (!d->frame_window)
+ {
+ XUnmapWindow (xdisplay, d->event_windows[i][j].window);
+ }
+ }
+ }
+
+ /* no button event windows if width is less than minimum width */
+ if (width < ICON_SPACE + d->button_width)
+ actions = 0;
+
+ for (i = 0; i < BUTTON_NUM; i++)
+ {
+ static guint button_actions[BUTTON_NUM] = {
+ WNCK_WINDOW_ACTION_CLOSE,
+ WNCK_WINDOW_ACTION_MAXIMIZE,
+ WNCK_WINDOW_ACTION_MINIMIZE,
+ 0,
+ WNCK_WINDOW_ACTION_SHADE,
+
+#ifdef HAVE_LIBWNCK_2_18_1
+ WNCK_WINDOW_ACTION_ABOVE,
+ WNCK_WINDOW_ACTION_STICK,
+ WNCK_WINDOW_ACTION_UNSHADE,
+ WNCK_WINDOW_ACTION_ABOVE,
+ WNCK_WINDOW_ACTION_UNSTICK
+#else
+ 0,
+ 0,
+ 0,
+ 0,
+ 0
+#endif
+
+ };
+
+ if (d->frame_window &&
+ button_actions[i] && !(actions & button_actions[i]))
+ {
+ memset (&d->button_windows[i].pos, 0, sizeof (Box));
+ }
+ else if (!d->frame_window &&
+ button_actions[i] && !(actions & button_actions[i]))
+ {
+ XUnmapWindow (xdisplay, d->button_windows[i].window);
+ continue;
+ }
+
+ if (d->frame_window &&
+ (*theme_get_button_position) (d, i, width, height, &x, &y, &w, &h))
+ {
+ BoxPtr box = &d->button_windows[i].pos;
+ box->x1 = x;
+ box->y1 = y;
+ box->x2 = x + w;
+ box->y2 = y + h;
+ }
+ else if (!d->frame_window &&
+ (*theme_get_button_position) (d, i, width, height,
+ &x, &y, &w, &h))
+ {
+ Window win = d->button_windows[i].window;
+ XMapWindow (xdisplay, win);
+ XMoveResizeWindow (xdisplay, win, x, y, w, h);
+ }
+ else if (!d->frame_window)
+ {
+ XUnmapWindow (xdisplay, d->button_windows[i].window);
+ }
+ }
+
+ gdk_display_sync (gdk_display_get_default ());
+ gdk_error_trap_pop ();
+}
+
+#ifdef HAVE_WNCK_WINDOW_HAS_NAME
+static const char *
+wnck_window_get_real_name (WnckWindow *win)
+{
+ return wnck_window_has_name (win) ? wnck_window_get_name (win) : NULL;
+}
+#define wnck_window_get_name wnck_window_get_real_name
+#endif
+
+gint
+max_window_name_width (WnckWindow *win)
+{
+ decor_t *d = g_object_get_data (G_OBJECT (win), "decor");
+ const gchar *name;
+ gint w;
+
+ if (!d->layout)
+ {
+ d->layout = pango_layout_new (pango_context);
+ if (!d->layout)
+ return 0;
+
+ pango_layout_set_wrap (d->layout, PANGO_WRAP_CHAR);
+ }
+
+ name = wnck_window_get_name (win);
+ if (!name)
+ return 0;
+
+ pango_layout_set_auto_dir (d->layout, FALSE);
+ pango_layout_set_width (d->layout, -1);
+ pango_layout_set_text (d->layout, name, strlen (name));
+ pango_layout_get_pixel_size (d->layout, &w, NULL);
+
+ if (d->name)
+ pango_layout_set_text (d->layout, d->name, strlen (d->name));
+
+ return w + 6;
+}
+
+void
+update_window_decoration_name (WnckWindow *win)
+{
+ decor_t *d = g_object_get_data (G_OBJECT (win), "decor");
+ const gchar *name;
+ glong name_length;
+ PangoLayoutLine *line;
+
+ if (d->name)
+ {
+ g_free (d->name);
+ d->name = NULL;
+ }
+
+ name = wnck_window_get_name (win);
+ if (name && (name_length = strlen (name)))
+ {
+ gint w;
+
+ if (theme_draw_window_decoration != draw_window_decoration)
+ {
+ w = SHRT_MAX;
+ }
+ else
+ {
+ gint width;
+
+ wnck_window_get_client_window_geometry (win, NULL, NULL,
+ &width, NULL);
+
+ w = width - ICON_SPACE - 2 - d->button_width;
+ if (w < 1)
+ w = 1;
+ }
+
+ pango_layout_set_auto_dir (d->layout, FALSE);
+ pango_layout_set_width (d->layout, w * PANGO_SCALE);
+ pango_layout_set_text (d->layout, name, name_length);
+
+ line = pango_layout_get_line (d->layout, 0);
+
+ name_length = line->length;
+ if (pango_layout_get_line_count (d->layout) > 1)
+ {
+ if (name_length < 4)
+ {
+ pango_layout_set_text (d->layout, NULL, 0);
+ return;
+ }
+
+ d->name = g_strndup (name, name_length);
+ strcpy (d->name + name_length - 3, "...");
+ }
+ else
+ d->name = g_strndup (name, name_length);
+
+ pango_layout_set_text (d->layout, d->name, name_length);
+ }
+}
+
+void
+update_window_decoration_icon (WnckWindow *win)
+{
+ decor_t *d = g_object_get_data (G_OBJECT (win), "decor");
+
+ if (d->icon)
+ {
+ cairo_pattern_destroy (d->icon);
+ d->icon = NULL;
+ }
+
+ if (d->icon_pixmap)
+ {
+ g_object_unref (G_OBJECT (d->icon_pixmap));
+ d->icon_pixmap = NULL;
+ }
+
+ if (d->icon_pixbuf)
+ g_object_unref (G_OBJECT (d->icon_pixbuf));
+
+ d->icon_pixbuf = wnck_window_get_mini_icon (win);
+ if (d->icon_pixbuf)
+ {
+ cairo_t *cr;
+
+ g_object_ref (G_OBJECT (d->icon_pixbuf));
+
+ if (d->frame_window)
+ d->icon_pixmap = pixmap_new_from_pixbuf (d->icon_pixbuf,
+ 24);
+ else
+ d->icon_pixmap = pixmap_new_from_pixbuf (d->icon_pixbuf,
+ 32);
+ cr = gdk_cairo_create (GDK_DRAWABLE (d->icon_pixmap));
+ d->icon = cairo_pattern_create_for_surface (cairo_get_target (cr));
+ cairo_destroy (cr);
+ }
+}
+
+
+
+gboolean
+update_window_decoration_size (WnckWindow *win)
+{
+ decor_t *d = g_object_get_data (G_OBJECT (win), "decor");
+ GdkPixmap *pixmap, *buffer_pixmap = NULL;
+ Picture picture;
+ gint width, height;
+ gint x, y, w, h, name_width;
+ Display *xdisplay;
+ XRenderPictFormat *format;
+ int depth;
+
+ xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
+
+ wnck_window_get_client_window_geometry (win, &x, &y, &w, &h);
+
+ name_width = max_window_name_width (win);
+
+ if (!(*theme_calc_decoration_size) (d, w, h, name_width, &width, &height))
+ {
+ update_window_decoration_name (win);
+ return FALSE;
+ }
+
+ gdk_error_trap_push ();
+
+ if (d->frame_window)
+ depth = gdk_drawable_get_depth (GDK_DRAWABLE (d->frame_window));
+ else
+ depth = 32;
+
+ pixmap = create_pixmap (width, height, depth);
+
+ gdk_flush ();
+
+ if (!pixmap || gdk_error_trap_pop ())
+ {
+ memset (pixmap, 0, sizeof (pixmap));
+ return FALSE;
+ }
+
+ gdk_error_trap_push ();
+
+ buffer_pixmap = create_pixmap (width, height, depth);
+
+ gdk_flush ();
+
+ if (!buffer_pixmap || gdk_error_trap_pop ())
+ {
+ memset (buffer_pixmap, 0, sizeof (buffer_pixmap));
+ g_object_unref (G_OBJECT (pixmap));
+ return FALSE;
+ }
+
+ format = get_format_for_drawable (d, GDK_DRAWABLE (buffer_pixmap));
+ picture = XRenderCreatePicture (xdisplay, GDK_PIXMAP_XID (buffer_pixmap),
+ format, 0, NULL);
+
+ if (d->pixmap)
+ g_object_unref (G_OBJECT (d->pixmap));
+
+ if (d->buffer_pixmap)
+ g_object_unref (G_OBJECT (d->buffer_pixmap));
+
+ if (d->picture)
+ XRenderFreePicture (xdisplay, d->picture);
+
+ if (d->cr)
+ cairo_destroy (d->cr);
+
+ d->pixmap = pixmap;
+ d->buffer_pixmap = buffer_pixmap;
+ d->cr = gdk_cairo_create (pixmap);
+
+ d->picture = picture;
+
+ d->width = width;
+ d->height = height;
+
+ d->prop_xid = wnck_window_get_xid (win);
+
+ update_window_decoration_name (win);
+
+ queue_decor_draw (d);
+
+ return TRUE;
+}
+
+/* to save some memory, value is specific to current decorations */
+#define TRANSLUCENT_CORNER_SIZE 3
+
+static void
+draw_border_shape (Display *xdisplay,
+ Pixmap pixmap,
+ Picture picture,
+ int width,
+ int height,
+ decor_context_t *c,
+ void *closure)
+{
+ static XRenderColor white = { 0xffff, 0xffff, 0xffff, 0xffff };
+ GdkColormap *colormap;
+ decor_t d;
+ double save_decoration_alpha;
+
+ memset (&d, 0, sizeof (d));
+
+ d.pixmap = gdk_pixmap_foreign_new_for_display (gdk_display_get_default (),
+ pixmap);
+ d.width = width;
+ d.height = height;
+ d.active = TRUE;
+ d.draw = theme_draw_window_decoration;
+ d.picture = picture;
+ d.context = c;
+
+ /* we use closure argument if maximized */
+ if (closure)
+ d.state |=
+ WNCK_WINDOW_STATE_MAXIMIZED_HORIZONTALLY |
+ WNCK_WINDOW_STATE_MAXIMIZED_VERTICALLY;
+
+ decor_get_default_layout (c, 1, 1, &d.border_layout);
+
+ colormap = get_colormap_for_drawable (GDK_DRAWABLE (d.pixmap));
+ gdk_drawable_set_colormap (d.pixmap, colormap);
+
+ /* create shadow from opaque decoration */
+ save_decoration_alpha = decoration_alpha;
+ decoration_alpha = 1.0;
+
+ (*d.draw) (&d);
+
+ decoration_alpha = save_decoration_alpha;
+
+ XRenderFillRectangle (xdisplay, PictOpSrc, picture, &white,
+ c->left_space,
+ c->top_space,
+ width - c->left_space - c->right_space,
+ height - c->top_space - c->bottom_space);
+
+ g_object_unref (G_OBJECT (d.pixmap));
+}
+
+int
+update_shadow (void)
+{
+ decor_shadow_options_t opt_shadow;
+ decor_shadow_options_t opt_no_shadow;
+ Display *xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
+ GdkDisplay *display = gdk_display_get_default ();
+ GdkScreen *screen = gdk_display_get_default_screen (display);
+
+ opt_shadow.shadow_radius = shadow_radius;
+ opt_shadow.shadow_opacity = shadow_opacity;
+
+ memcpy (opt_shadow.shadow_color, shadow_color, sizeof (shadow_color));
+
+ opt_shadow.shadow_offset_x = shadow_offset_x;
+ opt_shadow.shadow_offset_y = shadow_offset_y;
+
+ opt_no_shadow.shadow_radius = 0;
+ opt_no_shadow.shadow_opacity = 0;
+
+ opt_no_shadow.shadow_offset_x = 0;
+ opt_no_shadow.shadow_offset_y = 0;
+
+ if (no_border_shadow)
+ {
+ decor_shadow_destroy (xdisplay, no_border_shadow);
+ no_border_shadow = NULL;
+ }
+
+ no_border_shadow = decor_shadow_create (xdisplay,
+ gdk_x11_screen_get_xscreen (screen),
+ 1, 1,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0, 0, 0, 0,
+ &opt_shadow,
+ &shadow_context,
+ decor_draw_simple,
+ 0);
+
+ if (border_shadow)
+ {
+ decor_shadow_destroy (xdisplay, border_shadow);
+ border_shadow = NULL;
+ }
+
+ border_shadow = decor_shadow_create (xdisplay,
+ gdk_x11_screen_get_xscreen (screen),
+ 1, 1,
+ _win_extents.left,
+ _win_extents.right,
+ _win_extents.top + titlebar_height,
+ _win_extents.bottom,
+ _win_extents.left -
+ TRANSLUCENT_CORNER_SIZE,
+ _win_extents.right -
+ TRANSLUCENT_CORNER_SIZE,
+ _win_extents.top + titlebar_height -
+ TRANSLUCENT_CORNER_SIZE,
+ _win_extents.bottom -
+ TRANSLUCENT_CORNER_SIZE,
+ &opt_shadow,
+ &window_context,
+ draw_border_shape,
+ 0);
+
+ if (border_no_shadow)
+ {
+ decor_shadow_destroy (xdisplay, border_no_shadow);
+ border_no_shadow = NULL;
+ }
+
+ border_no_shadow = decor_shadow_create (xdisplay,
+ gdk_x11_screen_get_xscreen (screen),
+ 1, 1,
+ _win_extents.left,
+ _win_extents.right,
+ _win_extents.top + titlebar_height,
+ _win_extents.bottom,
+ _win_extents.left -
+ TRANSLUCENT_CORNER_SIZE,
+ _win_extents.right -
+ TRANSLUCENT_CORNER_SIZE,
+ _win_extents.top + titlebar_height -
+ TRANSLUCENT_CORNER_SIZE,
+ _win_extents.bottom -
+ TRANSLUCENT_CORNER_SIZE,
+ &opt_no_shadow,
+ &window_context_no_shadow,
+ draw_border_shape,
+ 0);
+
+ decor_context_t *context = &window_context_no_shadow;
+
+
+ if (max_border_shadow)
+ {
+ decor_shadow_destroy (xdisplay, max_border_shadow);
+ max_border_shadow = NULL;
+ }
+
+ max_border_shadow =
+ decor_shadow_create (xdisplay,
+ gdk_x11_screen_get_xscreen (screen),
+ 1, 1,
+ _max_win_extents.left,
+ _max_win_extents.right,
+ _max_win_extents.top + max_titlebar_height,
+ _max_win_extents.bottom,
+ _max_win_extents.left - TRANSLUCENT_CORNER_SIZE,
+ _max_win_extents.right - TRANSLUCENT_CORNER_SIZE,
+ _max_win_extents.top + max_titlebar_height -
+ TRANSLUCENT_CORNER_SIZE,
+ _max_win_extents.bottom - TRANSLUCENT_CORNER_SIZE,
+ &opt_shadow,
+ &max_window_context,
+ draw_border_shape,
+ (void *) 1);
+
+ if (max_border_no_shadow)
+ {
+ decor_shadow_destroy (xdisplay, max_border_shadow);
+ max_border_shadow = NULL;
+ }
+
+ max_border_no_shadow =
+ decor_shadow_create (xdisplay,
+ gdk_x11_screen_get_xscreen (screen),
+ 1, 1,
+ _max_win_extents.left,
+ _max_win_extents.right,
+ _max_win_extents.top + max_titlebar_height,
+ _max_win_extents.bottom,
+ _max_win_extents.left - TRANSLUCENT_CORNER_SIZE,
+ _max_win_extents.right - TRANSLUCENT_CORNER_SIZE,
+ _max_win_extents.top + max_titlebar_height -
+ TRANSLUCENT_CORNER_SIZE,
+ _max_win_extents.bottom - TRANSLUCENT_CORNER_SIZE,
+ &opt_no_shadow,
+ &max_window_context_no_shadow,
+ draw_border_shape,
+ (void *) 1);
+
+ if (switcher_shadow)
+ {
+ decor_shadow_destroy (xdisplay, switcher_shadow);
+ switcher_shadow = NULL;
+ }
+
+ switcher_shadow = decor_shadow_create (xdisplay,
+ gdk_x11_screen_get_xscreen (screen),
+ 1, 1,
+ _switcher_extents.left,
+ _switcher_extents.right,
+ _switcher_extents.top,
+ _switcher_extents.bottom,
+ _switcher_extents.left -
+ TRANSLUCENT_CORNER_SIZE,
+ _switcher_extents.right -
+ TRANSLUCENT_CORNER_SIZE,
+ _switcher_extents.top -
+ TRANSLUCENT_CORNER_SIZE,
+ _switcher_extents.bottom -
+ TRANSLUCENT_CORNER_SIZE,
+ &opt_shadow,
+ &switcher_context,
+ decor_draw_simple,
+ 0);
+
+ return 1;
+}
+
+void
+update_window_decoration (WnckWindow *win)
+{
+ decor_t *d = g_object_get_data (G_OBJECT (win), "decor");
+
+ if (d->decorated)
+ {
+ /* force size update */
+ d->context = NULL;
+ d->width = d->height = 0;
+
+ update_window_decoration_size (win);
+ update_event_windows (win);
+ }
+ else
+ {
+ Window xid = wnck_window_get_xid (win);
+ Window select;
+
+ if (get_window_prop (xid, select_window_atom, &select))
+ {
+ /* force size update */
+ d->context = NULL;
+ d->width = d->height = 0;
+ switcher_width = switcher_height = 0;
+
+ update_switcher_window (win, select);
+ }
+ }
+}
+
+void
+update_window_decoration_state (WnckWindow *win)
+{
+ decor_t *d = g_object_get_data (G_OBJECT (win), "decor");
+
+ d->state = wnck_window_get_state (win);
+}
+
+void
+update_window_decoration_actions (WnckWindow *win)
+{
+ decor_t *d = g_object_get_data (G_OBJECT (win), "decor");
+
+ d->actions = wnck_window_get_actions (win);
+}
+
+static gboolean
+draw_decor_list (void *data)
+{
+ GSList *list;
+ decor_t *d;
+
+ draw_idle_id = 0;
+
+ for (list = draw_list; list; list = list->next)
+ {
+ d = (decor_t *) list->data;
+ (*d->draw) (d);
+ }
+
+ g_slist_free (draw_list);
+ draw_list = NULL;
+
+ return FALSE;
+}
+
+void
+queue_decor_draw (decor_t *d)
+{
+ if (g_slist_find (draw_list, d))
+ return;
+
+ draw_list = g_slist_append (draw_list, d);
+
+ if (!draw_idle_id)
+ draw_idle_id = g_idle_add (draw_decor_list, NULL);
+}
+
+void
+update_default_decorations (GdkScreen *screen)
+{
+ long data[256];
+ Window xroot;
+ GdkDisplay *gdkdisplay = gdk_display_get_default ();
+ Display *xdisplay = gdk_x11_display_get_xdisplay (gdkdisplay);
+ Atom bareAtom, normalAtom, activeAtom;
+ decor_t d;
+ gint nQuad;
+ decor_quad_t quads[N_QUADS_MAX];
+ decor_extents_t extents = _win_extents;
+
+ xroot = RootWindowOfScreen (gdk_x11_screen_get_xscreen (screen));
+
+ bareAtom = XInternAtom (xdisplay, DECOR_BARE_ATOM_NAME, FALSE);
+ normalAtom = XInternAtom (xdisplay, DECOR_NORMAL_ATOM_NAME, FALSE);
+ activeAtom = XInternAtom (xdisplay, DECOR_ACTIVE_ATOM_NAME, FALSE);
+
+ if (no_border_shadow)
+ {
+ decor_layout_t layout;
+
+ decor_get_default_layout (&shadow_context, 1, 1, &layout);
+
+ nQuad = decor_set_lSrStSbS_window_quads (quads, &shadow_context,
+ &layout);
+
+ decor_quads_to_property (data, no_border_shadow->pixmap,
+ &_shadow_extents, &_shadow_extents,
+ 0, 0, quads, nQuad);
+
+ XChangeProperty (xdisplay, xroot,
+ bareAtom,
+ XA_INTEGER,
+ 32, PropModeReplace, (guchar *) data,
+ BASE_PROP_SIZE + QUAD_PROP_SIZE * nQuad);
+
+ if (minimal)
+ {
+ XChangeProperty (xdisplay, xroot,
+ normalAtom,
+ XA_INTEGER,
+ 32, PropModeReplace, (guchar *) data,
+ BASE_PROP_SIZE + QUAD_PROP_SIZE * nQuad);
+ XChangeProperty (xdisplay, xroot,
+ activeAtom,
+ XA_INTEGER,
+ 32, PropModeReplace, (guchar *) data,
+ BASE_PROP_SIZE + QUAD_PROP_SIZE * nQuad);
+ }
+ }
+ else
+ {
+ XDeleteProperty (xdisplay, xroot, bareAtom);
+
+ if (minimal)
+ {
+ XDeleteProperty (xdisplay, xroot, normalAtom);
+ XDeleteProperty (xdisplay, xroot, activeAtom);
+ }
+ }
+
+ if (minimal)
+ return;
+
+ memset (&d, 0, sizeof (d));
+
+ d.context = &window_context;
+ d.shadow = border_shadow;
+ d.layout = pango_layout_new (pango_context);
+
+ decor_get_default_layout (d.context, 1, 1, &d.border_layout);
+
+ d.width = d.border_layout.width;
+ d.height = d.border_layout.height;
+
+ extents.top += titlebar_height;
+
+ d.draw = theme_draw_window_decoration;
+
+ if (decor_normal_pixmap)
+ g_object_unref (G_OBJECT (decor_normal_pixmap));
+
+ nQuad = decor_set_lSrStSbS_window_quads (quads, d.context,
+ &d.border_layout);
+
+ decor_normal_pixmap = create_pixmap (d.width, d.height, 32);
+
+ if (decor_normal_pixmap)
+ {
+ d.pixmap = decor_normal_pixmap;
+ d.active = FALSE;
+ d.picture = XRenderCreatePicture (xdisplay,
+ GDK_PIXMAP_XID (d.pixmap),
+ xformat_rgba, 0, NULL);
+
+ (*d.draw) (&d);
+
+ XRenderFreePicture (xdisplay, d.picture);
+
+ decor_quads_to_property (data, GDK_PIXMAP_XID (d.pixmap),
+ &extents, &extents, 0, 0, quads, nQuad);
+
+ XChangeProperty (xdisplay, xroot,
+ normalAtom,
+ XA_INTEGER,
+ 32, PropModeReplace, (guchar *) data,
+ BASE_PROP_SIZE + QUAD_PROP_SIZE * nQuad);
+ }
+
+ if (decor_active_pixmap)
+ g_object_unref (G_OBJECT (decor_active_pixmap));
+
+ decor_active_pixmap = create_pixmap (d.width, d.height, 32);
+
+ if (decor_active_pixmap)
+ {
+ d.pixmap = decor_active_pixmap;
+ d.active = TRUE;
+ d.picture = XRenderCreatePicture (xdisplay,
+ GDK_PIXMAP_XID (d.pixmap),
+ xformat_rgba, 0, NULL);
+
+ (*d.draw) (&d);
+
+ XRenderFreePicture (xdisplay, d.picture);
+
+ decor_quads_to_property (data, GDK_PIXMAP_XID (d.pixmap),
+ &extents, &extents, 0, 0, quads, nQuad);
+
+ XChangeProperty (xdisplay, xroot,
+ activeAtom,
+ XA_INTEGER,
+ 32, PropModeReplace, (guchar *) data,
+ BASE_PROP_SIZE + QUAD_PROP_SIZE * nQuad);
+ }
+
+ if (d.layout)
+ g_object_unref (G_OBJECT (d.layout));
+}
+
+void
+copy_to_front_buffer (decor_t *d)
+{
+ if (!d->buffer_pixmap)
+ return;
+
+ cairo_set_operator (d->cr, CAIRO_OPERATOR_SOURCE);
+ gdk_cairo_set_source_pixmap (d->cr, d->buffer_pixmap, 0, 0);
+ cairo_paint (d->cr);
+}
diff --git a/src/decorprops.c b/src/decorprops.c
new file mode 100644
index 0000000..68b6ed5
--- /dev/null
+++ b/src/decorprops.c
@@ -0,0 +1,134 @@
+#include "gtk-window-decorator.h"
+
+void
+decor_update_window_property (decor_t *d)
+{
+ long data[256];
+ Display *xdisplay =
+ GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
+ decor_extents_t extents = _win_extents;
+ gint nQuad;
+ decor_quad_t quads[N_QUADS_MAX];
+ int w, h;
+ gint stretch_offset;
+ REGION top, bottom, left, right;
+
+ w = d->border_layout.top.x2 - d->border_layout.top.x1 -
+ d->context->left_space - d->context->right_space;
+
+ if (d->border_layout.rotation)
+ h = d->border_layout.left.x2 - d->border_layout.left.x1;
+ else
+ h = d->border_layout.left.y2 - d->border_layout.left.y1;
+
+ stretch_offset = w - d->button_width - 1;
+
+ nQuad = decor_set_lSrStXbS_window_quads (quads, d->context,
+ &d->border_layout,
+ stretch_offset);
+
+ extents.top += titlebar_height;
+
+ if (d->frame_window)
+ {
+ decor_gen_window_property (data, &extents, &extents, 20, 20);
+ }
+ else
+ {
+ decor_quads_to_property (data, GDK_PIXMAP_XID (d->pixmap),
+ &extents, &extents,
+ ICON_SPACE + d->button_width,
+ 0,
+ quads, nQuad);
+ }
+
+ gdk_error_trap_push ();
+ XChangeProperty (xdisplay, d->prop_xid,
+ win_decor_atom,
+ XA_INTEGER,
+ 32, PropModeReplace, (guchar *) data,
+ BASE_PROP_SIZE + QUAD_PROP_SIZE * nQuad);
+ gdk_display_sync (gdk_display_get_default ());
+ gdk_error_trap_pop ();
+
+ top.rects = &top.extents;
+ top.numRects = top.size = 1;
+
+ top.extents.x1 = -extents.left;
+ top.extents.y1 = -extents.top;
+ top.extents.x2 = w + extents.right;
+ top.extents.y2 = 0;
+
+ bottom.rects = &bottom.extents;
+ bottom.numRects = bottom.size = 1;
+
+ bottom.extents.x1 = -extents.left;
+ bottom.extents.y1 = 0;
+ bottom.extents.x2 = w + extents.right;
+ bottom.extents.y2 = extents.bottom;
+
+ left.rects = &left.extents;
+ left.numRects = left.size = 1;
+
+ left.extents.x1 = -extents.left;
+ left.extents.y1 = 0;
+ left.extents.x2 = 0;
+ left.extents.y2 = h;
+
+ right.rects = &right.extents;
+ right.numRects = right.size = 1;
+
+ right.extents.x1 = 0;
+ right.extents.y1 = 0;
+ right.extents.x2 = extents.right;
+ right.extents.y2 = h;
+
+ decor_update_blur_property (d,
+ w, h,
+ &top, stretch_offset,
+ &bottom, w / 2,
+ &left, h / 2,
+ &right, h / 2);
+}
+
+void
+decor_update_switcher_property (decor_t *d)
+{
+ long data[256];
+ Display *xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
+ gint nQuad;
+ decor_quad_t quads[N_QUADS_MAX];
+ GtkStyle *style;
+ long fgColor[4];
+
+ nQuad = decor_set_lSrStSbX_window_quads (quads, &switcher_context,
+ &d->border_layout,
+ d->border_layout.top.x2 -
+ d->border_layout.top.x1 -
+ switcher_context.extents.left -
+ switcher_context.extents.right -
+ 32);
+
+ decor_quads_to_property (data, GDK_PIXMAP_XID (d->pixmap),
+ &_switcher_extents, &_switcher_extents,
+ 0, 0, quads, nQuad);
+
+ style = gtk_widget_get_style (style_window_rgba);
+
+ fgColor[0] = style->fg[GTK_STATE_NORMAL].red;
+ fgColor[1] = style->fg[GTK_STATE_NORMAL].green;
+ fgColor[2] = style->fg[GTK_STATE_NORMAL].blue;
+ fgColor[3] = SWITCHER_ALPHA;
+
+ gdk_error_trap_push ();
+ XChangeProperty (xdisplay, d->prop_xid,
+ win_decor_atom,
+ XA_INTEGER,
+ 32, PropModeReplace, (guchar *) data,
+ BASE_PROP_SIZE + QUAD_PROP_SIZE * nQuad);
+ XChangeProperty (xdisplay, d->prop_xid, switcher_fg_atom,
+ XA_INTEGER, 32, PropModeReplace, (guchar *) fgColor, 4);
+ gdk_display_sync (gdk_display_get_default ());
+ gdk_error_trap_pop ();
+
+}
diff --git a/src/events.c b/src/events.c
new file mode 100644
index 0000000..6c3af32
--- /dev/null
+++ b/src/events.c
@@ -0,0 +1,1133 @@
+#include "gtk-window-decorator.h"
+
+void
+move_resize_window (WnckWindow *win,
+ int direction,
+ decor_event *gtkwd_event)
+{
+ Display *xdisplay;
+ GdkDisplay *gdkdisplay;
+ GdkScreen *screen;
+ Window xroot;
+ XEvent ev;
+
+ gdkdisplay = gdk_display_get_default ();
+ xdisplay = GDK_DISPLAY_XDISPLAY (gdkdisplay);
+ screen = gdk_display_get_default_screen (gdkdisplay);
+ xroot = RootWindowOfScreen (gdk_x11_screen_get_xscreen (screen));
+
+ if (action_menu_mapped)
+ {
+ gtk_object_destroy (GTK_OBJECT (action_menu));
+ action_menu_mapped = FALSE;
+ action_menu = NULL;
+ return;
+ }
+
+ ev.xclient.type = ClientMessage;
+ ev.xclient.display = xdisplay;
+
+ ev.xclient.serial = 0;
+ ev.xclient.send_event = TRUE;
+
+ ev.xclient.window = wnck_window_get_xid (win);
+ ev.xclient.message_type = wm_move_resize_atom;
+ ev.xclient.format = 32;
+
+ ev.xclient.data.l[0] = gtkwd_event->x_root;
+ ev.xclient.data.l[1] = gtkwd_event->y_root;
+ ev.xclient.data.l[2] = direction;
+ ev.xclient.data.l[3] = gtkwd_event->button;
+ ev.xclient.data.l[4] = 1;
+
+ XUngrabPointer (xdisplay, gtkwd_event->time);
+ XUngrabKeyboard (xdisplay, gtkwd_event->time);
+
+ XSendEvent (xdisplay, xroot, FALSE,
+ SubstructureRedirectMask | SubstructureNotifyMask,
+ &ev);
+
+ XSync (xdisplay, FALSE);
+}
+
+void
+common_button_event (WnckWindow *win,
+ decor_event *gtkwd_event,
+ decor_event_type gtkwd_type,
+ int button,
+ int max,
+ char *tooltip)
+{
+ decor_t *d = g_object_get_data (G_OBJECT (win), "decor");
+ guint state = d->button_states[button];
+
+ handle_tooltip_event (win, gtkwd_event, gtkwd_type, state, tooltip);
+
+ if (d->frame_window && gtkwd_type == GEnterNotify)
+ {
+ GdkCursor* cursor;
+ cursor = gdk_cursor_new (GDK_LEFT_PTR);
+ gdk_window_set_cursor (d->frame_window, cursor);
+ gdk_cursor_unref (cursor);
+ }
+
+ switch (gtkwd_type) {
+ case GButtonPress:
+ if (gtkwd_event->button <= max)
+ d->button_states[button] |= PRESSED_EVENT_WINDOW;
+ break;
+ case GButtonRelease:
+ if (gtkwd_event->button <= max)
+ d->button_states[button] &= ~PRESSED_EVENT_WINDOW;
+ break;
+ case GEnterNotify:
+ d->button_states[button] |= IN_EVENT_WINDOW;
+ break;
+ case GLeaveNotify:
+ d->button_states[button] &= ~IN_EVENT_WINDOW;
+ break;
+ default:
+ break;
+ }
+
+ if (state != d->button_states[button])
+ queue_decor_draw (d);
+}
+
+#define BUTTON_EVENT_ACTION_STATE (PRESSED_EVENT_WINDOW | IN_EVENT_WINDOW)
+
+void
+close_button_event (WnckWindow *win,
+ decor_event *gtkwd_event,
+ decor_event_type gtkwd_type)
+{
+ decor_t *d = g_object_get_data (G_OBJECT (win), "decor");
+ guint state = d->button_states[BUTTON_CLOSE];
+
+ common_button_event (win, gtkwd_event, gtkwd_type,
+ BUTTON_CLOSE, 1, _("Close Window"));
+
+ switch (gtkwd_type) {
+ case GButtonRelease:
+ if (gtkwd_event->button == 1)
+ if (state == BUTTON_EVENT_ACTION_STATE)
+ wnck_window_close (win, gtkwd_event->time);
+ break;
+ default:
+ break;
+ }
+}
+
+void
+max_button_event (WnckWindow *win,
+ decor_event *gtkwd_event,
+ decor_event_type gtkwd_type)
+{
+ decor_t *d = g_object_get_data (G_OBJECT (win), "decor");
+ guint state = d->button_states[BUTTON_MAX];
+
+ if (wnck_window_is_maximized (win))
+ common_button_event (win, gtkwd_event, gtkwd_type, BUTTON_MAX,
+ 3, _("Unmaximize Window"));
+ else
+ common_button_event (win, gtkwd_event, gtkwd_type, BUTTON_MAX,
+ 3, _("Maximize Window"));
+
+ switch (gtkwd_type) {
+ case GButtonRelease:
+ if (gtkwd_event->button <= 3)
+ {
+ if (state == BUTTON_EVENT_ACTION_STATE)
+ {
+ if (gtkwd_event->button == 2)
+ {
+ if (wnck_window_is_maximized_vertically (win))
+ wnck_window_unmaximize_vertically (win);
+ else
+ wnck_window_maximize_vertically (win);
+ }
+ else if (gtkwd_event->button == 3)
+ {
+ if (wnck_window_is_maximized_horizontally (win))
+ wnck_window_unmaximize_horizontally (win);
+ else
+ wnck_window_maximize_horizontally (win);
+ }
+ else
+ {
+ if (wnck_window_is_maximized (win))
+ wnck_window_unmaximize (win);
+ else
+ wnck_window_maximize (win);
+ }
+ }
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+void
+min_button_event (WnckWindow *win,
+ decor_event *gtkwd_event,
+ decor_event_type gtkwd_type)
+{
+ decor_t *d = g_object_get_data (G_OBJECT (win), "decor");
+ guint state = d->button_states[BUTTON_MIN];
+
+ common_button_event (win, gtkwd_event, gtkwd_type,
+ BUTTON_MIN, 1, _("Minimize Window"));
+
+ switch (gtkwd_type) {
+ case GButtonRelease:
+ if (gtkwd_event->button == 1)
+ if (state == BUTTON_EVENT_ACTION_STATE)
+ wnck_window_minimize (win);
+ break;
+ default:
+ break;
+ }
+}
+
+void
+menu_button_event (WnckWindow *win,
+ decor_event *gtkwd_event,
+ decor_event_type gtkwd_type)
+{
+
+ common_button_event (win, gtkwd_event, gtkwd_type,
+ BUTTON_MENU, 1, _("Window Menu"));
+
+ switch (gtkwd_type) {
+ case GButtonPress:
+ if (gtkwd_event->button == 1)
+ action_menu_map (win,
+ gtkwd_event->button,
+ gtkwd_event->time);
+ break;
+ default:
+ break;
+ }
+}
+
+void
+shade_button_event (WnckWindow *win,
+ decor_event *gtkwd_event,
+ decor_event_type gtkwd_type)
+{
+ decor_t *d = g_object_get_data (G_OBJECT (win), "decor");
+ guint state = d->button_states[BUTTON_SHADE];
+
+ common_button_event (win, gtkwd_event, gtkwd_type,
+ BUTTON_SHADE, 1, _("Shade"));
+
+ switch (gtkwd_type) {
+ case GButtonRelease:
+ if (gtkwd_event->button == 1)
+ {
+ if (state == BUTTON_EVENT_ACTION_STATE)
+ wnck_window_shade (win);
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+void
+above_button_event (WnckWindow *win,
+ decor_event *gtkwd_event,
+ decor_event_type gtkwd_type)
+{
+ decor_t *d = g_object_get_data (G_OBJECT (win), "decor");
+ guint state = d->button_states[BUTTON_ABOVE];
+
+ common_button_event (win, gtkwd_event, gtkwd_type,
+ BUTTON_ABOVE, 1, _("Make Above"));
+
+ switch (gtkwd_type) {
+ case GButtonRelease:
+ if (gtkwd_event->button == 1)
+ if (state == BUTTON_EVENT_ACTION_STATE)
+#ifdef HAVE_LIBWNCK_2_18_1
+ wnck_window_make_above (win);
+#endif
+ break;
+ default:
+ break;
+ }
+}
+
+void
+stick_button_event (WnckWindow *win,
+ decor_event *gtkwd_event,
+ decor_event_type gtkwd_type)
+{
+ decor_t *d = g_object_get_data (G_OBJECT (win), "decor");
+ guint state = d->button_states[BUTTON_STICK];
+
+ common_button_event (win, gtkwd_event, gtkwd_type,
+ BUTTON_STICK, 1, _("Stick"));
+
+ switch (gtkwd_type) {
+ case GButtonRelease:
+ if (gtkwd_event->button == 1)
+ if (state == BUTTON_EVENT_ACTION_STATE)
+ wnck_window_stick (win);
+ break;
+ default:
+ break;
+ }
+}
+
+void
+unshade_button_event (WnckWindow *win,
+ decor_event *gtkwd_event,
+ decor_event_type gtkwd_type)
+{
+ decor_t *d = g_object_get_data (G_OBJECT (win), "decor");
+ guint state = d->button_states[BUTTON_UNSHADE];
+
+ common_button_event (win, gtkwd_event, gtkwd_type,
+ BUTTON_UNSHADE, 1, _("Unshade"));
+
+ switch (gtkwd_type) {
+ case GButtonRelease:
+ if (gtkwd_event->button == 1)
+ if (state == BUTTON_EVENT_ACTION_STATE)
+ wnck_window_unshade (win);
+ break;
+ default:
+ break;
+ }
+}
+
+void
+unabove_button_event (WnckWindow *win,
+ decor_event *gtkwd_event,
+ decor_event_type gtkwd_type)
+{
+ decor_t *d = g_object_get_data (G_OBJECT (win), "decor");
+ guint state = d->button_states[BUTTON_UNABOVE];
+
+ common_button_event (win, gtkwd_event, gtkwd_type,
+ BUTTON_UNABOVE, 1, _("Unmake Above"));
+
+ switch (gtkwd_type) {
+ case GButtonRelease:
+ if (gtkwd_event->button == 1)
+ if (state == BUTTON_EVENT_ACTION_STATE)
+#ifdef HAVE_LIBWNCK_2_18_1
+ wnck_window_unmake_above (win);
+#endif
+ break;
+ default:
+ break;
+ }
+}
+
+void
+unstick_button_event (WnckWindow *win,
+ decor_event *gtkwd_event,
+ decor_event_type gtkwd_type)
+{
+ decor_t *d = g_object_get_data (G_OBJECT (win), "decor");
+ guint state = d->button_states[BUTTON_UNSTICK];
+
+ common_button_event (win, gtkwd_event, gtkwd_type,
+ BUTTON_UNSTICK, 1, _("Unstick"));
+
+ switch (gtkwd_type) {
+ case GButtonRelease:
+ if (gtkwd_event->button == 1)
+ if (state == BUTTON_EVENT_ACTION_STATE)
+ wnck_window_unstick (win);
+ break;
+ default:
+ break;
+ }
+}
+
+void
+handle_title_button_event (WnckWindow *win,
+ int action,
+ decor_event *gtkwd_event)
+{
+ switch (action) {
+ case CLICK_ACTION_SHADE:
+ if (wnck_window_is_shaded (win))
+ wnck_window_unshade (win);
+ else
+ wnck_window_shade (win);
+ break;
+ case CLICK_ACTION_MAXIMIZE:
+ if (wnck_window_is_maximized (win))
+ wnck_window_unmaximize (win);
+ else
+ wnck_window_maximize (win);
+ break;
+ case CLICK_ACTION_MINIMIZE:
+ if (!wnck_window_is_minimized (win))
+ wnck_window_minimize (win);
+ break;
+ case CLICK_ACTION_RAISE:
+ restack_window (win, Above);
+ break;
+ case CLICK_ACTION_LOWER:
+ restack_window (win, Below);
+ break;
+ case CLICK_ACTION_MENU:
+ action_menu_map (win, gtkwd_event->button, gtkwd_event->time);
+ break;
+ }
+}
+
+void
+handle_mouse_wheel_title_event (WnckWindow *win,
+ unsigned int button)
+{
+ switch (wheel_action) {
+ case WHEEL_ACTION_SHADE:
+ if (button == 4)
+ {
+ if (!wnck_window_is_shaded (win))
+ wnck_window_shade (win);
+ }
+ else if (button == 5)
+ {
+ if (wnck_window_is_shaded (win))
+ wnck_window_unshade (win);
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+void
+title_event (WnckWindow *win,
+ decor_event *gtkwd_event,
+ decor_event_type gtkwd_type)
+{
+ static int last_button_num = 0;
+ static Window last_button_xwindow = None;
+ static Time last_button_time = 0;
+ static int last_button_x = 0;
+ static int last_button_y = 0;
+
+ decor_t *d = g_object_get_data (G_OBJECT (win), "decor");
+
+ if (d->frame_window && gtkwd_type == GEnterNotify)
+ {
+ GdkCursor* cursor = gdk_cursor_new (GDK_LEFT_PTR);
+ gdk_window_set_cursor (d->frame_window, cursor);
+ gdk_cursor_unref (cursor);
+ }
+
+ if (gtkwd_type != GButtonPress)
+ return;
+
+ if (gtkwd_event->button == 1)
+ {
+ if (gtkwd_event->button == last_button_num &&
+ gtkwd_event->window == last_button_xwindow &&
+ gtkwd_event->time < last_button_time + double_click_timeout &&
+ dist (gtkwd_event->x, gtkwd_event->y,
+ last_button_x, last_button_y) < DOUBLE_CLICK_DISTANCE)
+ {
+ handle_title_button_event (win, double_click_action,
+ gtkwd_event);
+
+ last_button_num = 0;
+ last_button_xwindow = None;
+ last_button_time = 0;
+ last_button_x = 0;
+ last_button_y = 0;
+ }
+ else
+ {
+ last_button_num = gtkwd_event->button;
+ last_button_xwindow = gtkwd_event->window;
+ last_button_time = gtkwd_event->time;
+ last_button_x = gtkwd_event->x;
+ last_button_y = gtkwd_event->y;
+
+ restack_window (win, Above);
+
+ move_resize_window (win, WM_MOVERESIZE_MOVE, gtkwd_event);
+ }
+ }
+ else if (gtkwd_event->button == 2)
+ {
+ handle_title_button_event (win, middle_click_action,
+ gtkwd_event);
+ }
+ else if (gtkwd_event->button == 3)
+ {
+ handle_title_button_event (win, right_click_action,
+ gtkwd_event);
+ }
+ else if (gtkwd_event->button == 4 ||
+ gtkwd_event->button == 5)
+ {
+ handle_mouse_wheel_title_event (win, gtkwd_event->button);
+ }
+}
+
+void
+frame_common_event (WnckWindow *win,
+ int direction,
+ decor_event *gtkwd_event,
+ decor_event_type gtkwd_type)
+{
+
+ decor_t *d = g_object_get_data (G_OBJECT (win), "decor");
+
+ if (d->frame_window && gtkwd_type == GEnterNotify)
+ {
+ GdkCursor *cursor = NULL;
+
+ switch (direction)
+ {
+ case WM_MOVERESIZE_SIZE_TOPLEFT:
+ cursor = gdk_cursor_new (GDK_TOP_LEFT_CORNER);
+ break;
+ case WM_MOVERESIZE_SIZE_LEFT:
+ cursor = gdk_cursor_new (GDK_LEFT_SIDE);
+ break;
+ case WM_MOVERESIZE_SIZE_BOTTOMLEFT:
+ cursor = gdk_cursor_new (GDK_BOTTOM_LEFT_CORNER);
+ break;
+ case WM_MOVERESIZE_SIZE_BOTTOM:
+ cursor = gdk_cursor_new (GDK_BOTTOM_SIDE);
+ break;
+ case WM_MOVERESIZE_SIZE_BOTTOMRIGHT:
+ cursor = gdk_cursor_new (GDK_BOTTOM_RIGHT_CORNER);
+ break;
+ case WM_MOVERESIZE_SIZE_RIGHT:
+ cursor = gdk_cursor_new (GDK_RIGHT_SIDE);
+ break;
+ case WM_MOVERESIZE_SIZE_TOPRIGHT:
+ cursor = gdk_cursor_new (GDK_TOP_RIGHT_CORNER);
+ break;
+ case WM_MOVERESIZE_SIZE_TOP:
+ cursor = gdk_cursor_new (GDK_TOP_SIDE);
+ break;
+ default:
+ break;
+ }
+
+ if (cursor)
+ {
+ gdk_window_set_cursor (d->frame_window, cursor);
+ gdk_cursor_unref (cursor);
+ }
+ }
+
+ if (gtkwd_type != GButtonPress)
+ return;
+
+ switch (gtkwd_event->button) {
+ case 1:
+ move_resize_window (win, direction, gtkwd_event);
+ restack_window (win, Above);
+ break;
+ case 2:
+ handle_title_button_event (win, middle_click_action,
+ gtkwd_event);
+ break;
+ case 3:
+ handle_title_button_event (win, right_click_action,
+ gtkwd_event);
+ break;
+ }
+}
+
+void
+top_left_event (WnckWindow *win,
+ decor_event *gtkwd_event,
+ decor_event_type gtkwd_type)
+{
+ frame_common_event (win, WM_MOVERESIZE_SIZE_TOPLEFT,
+ gtkwd_event, gtkwd_type);
+}
+
+void
+top_event (WnckWindow *win,
+ decor_event *gtkwd_event,
+ decor_event_type gtkwd_type)
+{
+ frame_common_event (win, WM_MOVERESIZE_SIZE_TOP,
+ gtkwd_event, gtkwd_type);
+}
+
+void
+top_right_event (WnckWindow *win,
+ decor_event *gtkwd_event,
+ decor_event_type gtkwd_type)
+{
+ frame_common_event (win, WM_MOVERESIZE_SIZE_TOPRIGHT,
+ gtkwd_event, gtkwd_type);
+}
+
+void
+left_event (WnckWindow *win,
+ decor_event *gtkwd_event,
+ decor_event_type gtkwd_type)
+{
+ frame_common_event (win, WM_MOVERESIZE_SIZE_LEFT,
+ gtkwd_event, gtkwd_type);
+}
+
+void
+right_event (WnckWindow *win,
+ decor_event *gtkwd_event,
+ decor_event_type gtkwd_type)
+{
+ frame_common_event (win, WM_MOVERESIZE_SIZE_RIGHT,
+ gtkwd_event, gtkwd_type);
+}
+
+void
+bottom_left_event (WnckWindow *win,
+ decor_event *gtkwd_event,
+ decor_event_type gtkwd_type)
+{
+ frame_common_event (win, WM_MOVERESIZE_SIZE_BOTTOMLEFT,
+ gtkwd_event, gtkwd_type);
+}
+
+void
+bottom_event (WnckWindow *win,
+ decor_event *gtkwd_event,
+ decor_event_type gtkwd_type)
+{
+ frame_common_event (win, WM_MOVERESIZE_SIZE_BOTTOM,
+ gtkwd_event, gtkwd_type);
+}
+
+void
+bottom_right_event (WnckWindow *win,
+ decor_event *gtkwd_event,
+ decor_event_type gtkwd_type)
+{
+ frame_common_event (win, WM_MOVERESIZE_SIZE_BOTTOMRIGHT,
+ gtkwd_event, gtkwd_type);
+}
+
+void
+frame_window_realized (GtkWidget *widget,
+ gpointer data)
+{
+ decor_t *d = (decor_t *) data;
+
+ if (d)
+ {
+ GdkWindow *gdk_frame_window = gtk_widget_get_window (d->decor_window);
+ gdk_window_reparent (gdk_frame_window, d->frame_window, 0, 0);
+ gdk_window_lower (gdk_frame_window);
+
+ }
+}
+
+event_callback
+find_event_callback_for_point (decor_t *d,
+ int x,
+ int y,
+ Bool *enter,
+ Bool *leave,
+ BoxPtr *entered_box)
+{
+ int i, j;
+ BoxPtr box;
+
+ for (i = 0; i < BUTTON_NUM; i++)
+ {
+ box = &d->button_windows[i].pos;
+ if (x >= box->x1 && x <= box->x2 &&
+ y >= box->y1 && y <= box->y2)
+ {
+ if (d->last_pos_entered != box)
+ {
+ if (enter)
+ *enter = TRUE;
+ if (leave && d->last_pos_entered)
+ *leave = TRUE;
+ if (entered_box)
+ *entered_box = box;
+ }
+ return d->button_windows[i].callback;
+ }
+ }
+
+ for (i = 0; i < 3; i++)
+ {
+ for (j = 0; j < 3; j++)
+ {
+ box = &d->event_windows[i][j].pos;
+ if (x >= box->x1 && x <= box->x2 &&
+ y >= box->y1 && y <= box->y2)
+ {
+ if (d->last_pos_entered != box)
+ {
+ if (enter)
+ *enter = TRUE;
+ if (leave && d->last_pos_entered)
+ *leave = TRUE;
+ if (entered_box)
+ *entered_box = box;
+ }
+ return d->event_windows[i][j].callback;
+ }
+ }
+ }
+
+ return NULL;
+}
+
+event_callback
+find_leave_event_callback (decor_t *d)
+{
+ int i, j;
+
+ for (i = 0; i < BUTTON_NUM; i++)
+ {
+ if (d->last_pos_entered == &d->button_windows[i].pos)
+ return d->button_windows[i].callback;
+ }
+
+ for (i = 0; i < 3; i++)
+ {
+ for (j = 0; j < 3; j++)
+ {
+ if (d->last_pos_entered == &d->event_windows[i][j].pos)
+ return d->event_windows[i][j].callback;
+ }
+ }
+
+ return NULL;
+}
+
+void
+frame_handle_button_press (GtkWidget *widget,
+ GdkEventButton *event,
+ gpointer user_data)
+{
+ decor_t *d = (decor_t *) user_data;
+
+ if (d)
+ {
+ /* Check to see where the event happened and fill out an appropriate
+ * struct
+ */
+ event_callback cb;
+
+ cb = find_event_callback_for_point (d, event->x, event->y,
+ NULL, NULL, NULL);
+
+ if (cb && d->decorated)
+ {
+ decor_event gtkwd_event;
+
+ gtkwd_event.window = GDK_WINDOW_XID (d->frame_window);
+ gtkwd_event.button = event->button;
+ gtkwd_event.x = event->x;
+ gtkwd_event.y = event->y;
+ gtkwd_event.x_root = event->x_root;
+ gtkwd_event.y_root = event->y_root;
+ gtkwd_event.time = event->time;
+
+ (*cb) (d->win, &gtkwd_event, GButtonPress);
+ }
+ }
+}
+
+void
+frame_handle_button_release (GtkWidget *widget,
+ GdkEventButton *event,
+ gpointer user_data)
+{
+ decor_t *d = (decor_t *) user_data;
+
+ if (d)
+ {
+ event_callback cb;
+
+ cb = find_event_callback_for_point (d, event->x, event->y,
+ NULL, NULL, NULL);
+
+ if (cb && d->decorated)
+ {
+ decor_event gtkwd_event;
+
+ gtkwd_event.window = GDK_WINDOW_XID (d->frame_window);
+ gtkwd_event.button = event->button;
+ gtkwd_event.x = event->x;
+ gtkwd_event.y = event->y;
+ gtkwd_event.x_root = event->x_root;
+ gtkwd_event.y_root = event->y_root;
+ gtkwd_event.time = event->time;
+
+ (*cb) (d->win, &gtkwd_event, GButtonRelease);
+ }
+ }
+}
+
+void
+frame_handle_motion (GtkWidget *widget,
+ GdkEventMotion *event,
+ gpointer user_data)
+{
+ decor_t *d = (decor_t *) user_data;
+
+ if (d)
+ {
+ event_callback cb = NULL;
+ Bool send_enter = FALSE;
+ Bool send_leave = FALSE;
+ BoxPtr entered_box;
+
+ cb = find_event_callback_for_point (d, event->x, event->y,
+ &send_enter, &send_leave,
+ &entered_box);
+
+ if (cb && d->decorated)
+ {
+ decor_event gtkwd_event;
+
+ gtkwd_event.window = GDK_WINDOW_XID (d->frame_window);
+ gtkwd_event.x = event->x;
+ gtkwd_event.y = event->y;
+ gtkwd_event.x_root = event->x_root;
+ gtkwd_event.y_root = event->y_root;
+ gtkwd_event.time = event->time;
+
+ if (send_enter)
+ (*cb) (d->win, &gtkwd_event, GEnterNotify);
+
+ if (send_leave)
+ {
+ event_callback leave_cb;
+
+ leave_cb = find_leave_event_callback (d);
+
+ if (leave_cb)
+ (*leave_cb) (d->win, &gtkwd_event, GLeaveNotify);
+
+ }
+
+ if (send_enter)
+ d->last_pos_entered = entered_box;
+ }
+ else if (d->last_pos_entered && d->decorated)
+ {
+ /* We are not in an event / button window but last_pos_entered
+ * is still set, so send a GLeaveNotify to last_pos_entered
+ * and set it to NULL
+ */
+
+ event_callback leave_cb;
+
+ leave_cb = find_leave_event_callback (d);
+
+ if (leave_cb)
+ {
+ decor_event gtkwd_event;
+
+ gtkwd_event.window = GDK_WINDOW_XID (d->frame_window);
+ gtkwd_event.x = event->x;
+ gtkwd_event.y = event->y;
+ gtkwd_event.x_root = event->x_root;
+ gtkwd_event.y_root = event->y_root;
+ gtkwd_event.time = event->time;
+
+ (*leave_cb) (d->win, &gtkwd_event, GLeaveNotify);
+ }
+
+ d->last_pos_entered = NULL;
+ }
+ }
+}
+
+GdkFilterReturn
+event_filter_func (GdkXEvent *gdkxevent,
+ GdkEvent *event,
+ gpointer data)
+{
+ Display *xdisplay;
+ GdkDisplay *gdkdisplay;
+ XEvent *xevent = gdkxevent;
+ gulong xid = 0;
+
+ gdkdisplay = gdk_display_get_default ();
+ xdisplay = GDK_DISPLAY_XDISPLAY (gdkdisplay);
+
+ switch (xevent->type) {
+ case ButtonPress:
+ case ButtonRelease:
+ xid = (gulong)
+ g_hash_table_lookup (frame_table,
+ GINT_TO_POINTER (xevent->xbutton.window));
+ break;
+ case EnterNotify:
+ case LeaveNotify:
+ xid = (gulong)
+ g_hash_table_lookup (frame_table,
+ GINT_TO_POINTER (xevent->xcrossing.window));
+ break;
+ case MotionNotify:
+ xid = (gulong)
+ g_hash_table_lookup (frame_table,
+ GINT_TO_POINTER (xevent->xmotion.window));
+ break;
+ case PropertyNotify:
+ if (xevent->xproperty.atom == frame_input_window_atom)
+ {
+ WnckWindow *win;
+
+ xid = xevent->xproperty.window;
+
+ win = wnck_window_get (xid);
+ if (win)
+ {
+ Window frame, window;
+
+ if (!get_window_prop (xid, select_window_atom, &window))
+ {
+ if (get_window_prop (xid, frame_input_window_atom, &frame))
+ add_frame_window (win, frame, FALSE);
+ else
+ remove_frame_window (win);
+ }
+ }
+ }
+ if (xevent->xproperty.atom == frame_output_window_atom)
+ {
+ WnckWindow *win;
+
+ xid = xevent->xproperty.window;
+
+ win = wnck_window_get (xid);
+ if (win)
+ {
+ Window frame, window;
+
+ if (!get_window_prop (xid, select_window_atom, &window))
+ {
+ if (get_window_prop (xid, frame_output_window_atom, &frame))
+ add_frame_window (win, frame, TRUE);
+ else
+ remove_frame_window (win);
+ }
+ }
+ }
+ else if (xevent->xproperty.atom == compiz_shadow_info_atom ||
+ xevent->xproperty.atom == compiz_shadow_color_atom)
+ {
+ GdkScreen *g_screen = gdk_display_get_default_screen (gdkdisplay);
+ Window root = GDK_WINDOW_XWINDOW (gdk_screen_get_root_window (g_screen));
+ WnckScreen *screen;
+
+ screen = wnck_screen_get_for_root (root);
+
+ if (screen)
+ {
+ shadow_property_changed (screen);
+ }
+ }
+ else if (xevent->xproperty.atom == mwm_hints_atom)
+ {
+ WnckWindow *win;
+
+ xid = xevent->xproperty.window;
+
+ win = wnck_window_get (xid);
+ if (win)
+ {
+ decor_t *d = g_object_get_data (G_OBJECT (win), "decor");
+ gboolean decorated = FALSE;
+
+ if (get_mwm_prop (xid) & (MWM_DECOR_ALL | MWM_DECOR_TITLE))
+ decorated = TRUE;
+
+ if (decorated != d->decorated)
+ {
+ d->decorated = decorated;
+ if (decorated)
+ {
+ d->context = NULL;
+ d->width = d->height = 0;
+
+ update_window_decoration_size (win);
+ update_event_windows (win);
+ }
+ else
+ {
+ gdk_error_trap_push ();
+ XDeleteProperty (xdisplay, xid, win_decor_atom);
+ gdk_display_sync (gdk_display_get_default ());
+ gdk_error_trap_pop ();
+ }
+ }
+ }
+ }
+ else if (xevent->xproperty.atom == select_window_atom)
+ {
+ WnckWindow *win;
+
+ xid = xevent->xproperty.window;
+
+ win = wnck_window_get (xid);
+ if (win)
+ {
+ Window select;
+
+ if (get_window_prop (xid, select_window_atom, &select))
+ update_switcher_window (win, select);
+ }
+ }
+ break;
+ case DestroyNotify:
+ g_hash_table_remove (frame_table,
+ GINT_TO_POINTER (xevent->xproperty.window));
+ break;
+ case ClientMessage:
+ if (xevent->xclient.message_type == toolkit_action_atom)
+ {
+ long action;
+
+ action = xevent->xclient.data.l[0];
+ if (action == toolkit_action_window_menu_atom)
+ {
+ WnckWindow *win;
+
+ win = wnck_window_get (xevent->xclient.window);
+ if (win)
+ {
+ action_menu_map (win,
+ xevent->xclient.data.l[2],
+ xevent->xclient.data.l[1]);
+ }
+ }
+ else if (action == toolkit_action_force_quit_dialog_atom)
+ {
+ WnckWindow *win;
+
+ win = wnck_window_get (xevent->xclient.window);
+ if (win)
+ {
+ if (xevent->xclient.data.l[2])
+ show_force_quit_dialog (win,
+ xevent->xclient.data.l[1]);
+ else
+ hide_force_quit_dialog (win);
+ }
+ }
+ }
+ default:
+ break;
+ }
+
+ if (xid)
+ {
+ WnckWindow *win;
+
+ win = wnck_window_get (xid);
+ if (win)
+ {
+ decor_t *d = g_object_get_data (G_OBJECT (win), "decor");
+
+ if (d->decorated)
+ {
+ gint i, j;
+ event_callback cb = NULL;
+ Window w = xevent->xany.window;
+
+ for (i = 0; i < 3; i++)
+ for (j = 0; j < 3; j++)
+ if (d->event_windows[i][j].window == w)
+ cb = d->event_windows[i][j].callback;
+
+ if (!cb)
+ {
+ for (i = 0; i < BUTTON_NUM; i++)
+ if (d->button_windows[i].window == w)
+ cb = d->button_windows[i].callback;
+ }
+
+ if (cb)
+ {
+ decor_event gtkwd_event;
+ decor_event_type gtkwd_type;
+
+ gtkwd_event.window = w;
+
+ switch (xevent->type)
+ {
+ case ButtonPress:
+ case ButtonRelease:
+ if (xevent->type == ButtonPress)
+ gtkwd_type = GButtonPress;
+ else
+ gtkwd_type = GButtonRelease;
+ gtkwd_event.button = xevent->xbutton.button;
+ gtkwd_event.x = xevent->xbutton.x;
+ gtkwd_event.y = xevent->xbutton.y;
+ gtkwd_event.x_root = xevent->xbutton.x_root;
+ gtkwd_event.y_root = xevent->xbutton.y_root;
+ gtkwd_event.time = xevent->xbutton.time;
+ break;
+ case EnterNotify:
+ case LeaveNotify:
+ if (xevent->type == EnterNotify)
+ gtkwd_type = GEnterNotify;
+ else
+ gtkwd_type = GLeaveNotify;
+ gtkwd_event.x = xevent->xcrossing.x;
+ gtkwd_event.y = xevent->xcrossing.y;
+ gtkwd_event.x_root = xevent->xcrossing.x_root;
+ gtkwd_event.y_root = xevent->xcrossing.y_root;
+ gtkwd_event.time = xevent->xcrossing.time;
+ break;
+ default:
+ cb = NULL;
+ break;
+ }
+ if (cb)
+ (*cb) (win, &gtkwd_event, gtkwd_type);
+ }
+ }
+ }
+ }
+
+ return GDK_FILTER_CONTINUE;
+}
+
+GdkFilterReturn
+selection_event_filter_func (GdkXEvent *gdkxevent,
+ GdkEvent *event,
+ gpointer data)
+{
+ Display *xdisplay;
+ GdkDisplay *gdkdisplay;
+ XEvent *xevent = gdkxevent;
+ int status;
+
+ gdkdisplay = gdk_display_get_default ();
+ xdisplay = GDK_DISPLAY_XDISPLAY (gdkdisplay);
+
+ switch (xevent->type) {
+ case SelectionRequest:
+ decor_handle_selection_request (xdisplay, xevent, dm_sn_timestamp);
+ break;
+ case SelectionClear:
+ status = decor_handle_selection_clear (xdisplay, xevent, 0);
+ if (status == DECOR_SELECTION_GIVE_UP)
+ exit (0);
+ default:
+ break;
+ }
+
+ return GDK_FILTER_CONTINUE;
+}
diff --git a/src/forcequit.c b/src/forcequit.c
new file mode 100644
index 0000000..93ed2f0
--- /dev/null
+++ b/src/forcequit.c
@@ -0,0 +1,176 @@
+#include "gtk-window-decorator.h"
+
+static char *
+get_client_machine (Window xwindow)
+{
+ Atom atom, type;
+ gulong nitems, bytes_after;
+ guchar *str = NULL;
+ int format, result;
+ char *retval;
+
+ atom = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "WM_CLIENT_MACHINE", FALSE);
+
+ gdk_error_trap_push ();
+
+ result = XGetWindowProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
+ xwindow, atom,
+ 0, G_MAXLONG,
+ FALSE, XA_STRING, &type, &format, &nitems,
+ &bytes_after, &str);
+
+ gdk_error_trap_pop ();
+
+ if (result != Success)
+ return NULL;
+
+ if (type != XA_STRING)
+ {
+ XFree (str);
+ return NULL;
+ }
+
+ retval = g_strdup ((gchar *) str);
+
+ XFree (str);
+
+ return retval;
+}
+
+static void
+kill_window (WnckWindow *win)
+{
+ WnckApplication *app;
+
+ app = wnck_window_get_application (win);
+ if (app)
+ {
+ gchar buf[257], *client_machine;
+ int pid;
+
+ pid = wnck_application_get_pid (app);
+ client_machine = get_client_machine (wnck_application_get_xid (app));
+
+ if (client_machine && pid > 0)
+ {
+ if (gethostname (buf, sizeof (buf) - 1) == 0)
+ {
+ if (strcmp (buf, client_machine) == 0)
+ kill (pid, 9);
+ }
+ }
+
+ if (client_machine)
+ g_free (client_machine);
+ }
+
+ gdk_error_trap_push ();
+ XKillClient (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), wnck_window_get_xid (win));
+ gdk_display_sync (gdk_display_get_default ());
+ gdk_error_trap_pop ();
+}
+
+static void
+force_quit_dialog_realize (GtkWidget *dialog,
+ void *data)
+{
+ WnckWindow *win = data;
+
+ gdk_error_trap_push ();
+ XSetTransientForHint (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
+ GDK_WINDOW_XID (dialog->window),
+ wnck_window_get_xid (win));
+ gdk_display_sync (gdk_display_get_default ());
+ gdk_error_trap_pop ();
+}
+
+static void
+force_quit_dialog_response (GtkWidget *dialog,
+ gint response,
+ void *data)
+{
+ WnckWindow *win = data;
+ decor_t *d = g_object_get_data (G_OBJECT (win), "decor");
+
+ if (response == GTK_RESPONSE_ACCEPT)
+ kill_window (win);
+
+ if (d->force_quit_dialog)
+ {
+ d->force_quit_dialog = NULL;
+ gtk_widget_destroy (dialog);
+ }
+}
+
+void
+show_force_quit_dialog (WnckWindow *win,
+ Time timestamp)
+{
+ decor_t *d = g_object_get_data (G_OBJECT (win), "decor");
+ GtkWidget *dialog;
+ gchar *str, *tmp;
+
+ if (d->force_quit_dialog)
+ return;
+
+ tmp = g_markup_escape_text (wnck_window_get_name (win), -1);
+ str = g_strdup_printf (_("The window \"%s\" is not responding."), tmp);
+
+ g_free (tmp);
+
+ dialog = gtk_message_dialog_new (NULL, 0,
+ GTK_MESSAGE_WARNING,
+ GTK_BUTTONS_NONE,
+ "<b>%s</b>\n\n%s",
+ str,
+ _("Forcing this application to "
+ "quit will cause you to lose any "
+ "unsaved changes."));
+ g_free (str);
+
+ gtk_window_set_icon_name (GTK_WINDOW (dialog), "force-quit");
+
+ gtk_label_set_use_markup (GTK_LABEL (GTK_MESSAGE_DIALOG (dialog)->label),
+ TRUE);
+ gtk_label_set_line_wrap (GTK_LABEL (GTK_MESSAGE_DIALOG (dialog)->label),
+ TRUE);
+
+ gtk_dialog_add_buttons (GTK_DIALOG (dialog),
+ GTK_STOCK_CANCEL,
+ GTK_RESPONSE_REJECT,
+ _("_Force Quit"),
+ GTK_RESPONSE_ACCEPT,
+ NULL);
+
+ gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_REJECT);
+
+ g_signal_connect (G_OBJECT (dialog), "realize",
+ G_CALLBACK (force_quit_dialog_realize),
+ win);
+
+ g_signal_connect (G_OBJECT (dialog), "response",
+ G_CALLBACK (force_quit_dialog_response),
+ win);
+
+ gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
+
+ gtk_widget_realize (dialog);
+
+ gdk_x11_window_set_user_time (dialog->window, timestamp);
+
+ gtk_widget_show (dialog);
+
+ d->force_quit_dialog = dialog;
+}
+
+void
+hide_force_quit_dialog (WnckWindow *win)
+{
+ decor_t *d = g_object_get_data (G_OBJECT (win), "decor");
+
+ if (d->force_quit_dialog)
+ {
+ gtk_widget_destroy (d->force_quit_dialog);
+ d->force_quit_dialog = NULL;
+ }
+}
diff --git a/src/gdk.c b/src/gdk.c
new file mode 100644
index 0000000..fe7d63a
--- /dev/null
+++ b/src/gdk.c
@@ -0,0 +1,87 @@
+#include "gtk-window-decorator.h"
+
+GdkPixmap *
+pixmap_new_from_pixbuf (GdkPixbuf *pixbuf, int depth)
+{
+ GdkPixmap *pixmap;
+ guint width, height;
+ cairo_t *cr;
+
+ width = gdk_pixbuf_get_width (pixbuf);
+ height = gdk_pixbuf_get_height (pixbuf);
+
+ pixmap = create_pixmap (width, height, depth);
+ if (!pixmap)
+ return NULL;
+
+ cr = (cairo_t *) gdk_cairo_create (GDK_DRAWABLE (pixmap));
+ gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
+ cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
+ cairo_paint (cr);
+ cairo_destroy (cr);
+
+ return pixmap;
+}
+
+
+void
+gdk_cairo_set_source_color_alpha (cairo_t *cr,
+ GdkColor *color,
+ double alpha)
+{
+ cairo_set_source_rgba (cr,
+ color->red / 65535.0,
+ color->green / 65535.0,
+ color->blue / 65535.0,
+ alpha);
+}
+
+inline GdkWindow *
+create_gdk_window (Window xframe)
+{
+ GdkDisplay *display = gdk_display_get_default ();
+ GdkScreen *screen = gdk_display_get_default_screen (display);
+ GdkWindow *window = gdk_window_foreign_new (xframe);
+ GdkColormap *cmap = gdk_screen_get_rgb_colormap (screen);
+
+ gdk_drawable_set_colormap (GDK_DRAWABLE (window), cmap);
+
+ return window;
+}
+
+GdkColormap *
+get_colormap_for_drawable (GdkDrawable *d)
+{
+ GdkDisplay *display = gdk_display_get_default ();
+ GdkScreen *screen = gdk_display_get_default_screen (display);
+
+ if (gdk_drawable_get_depth (d) == 32)
+ return gdk_screen_get_rgba_colormap (screen);
+
+ return gdk_screen_get_rgb_colormap (screen);
+}
+
+XRenderPictFormat *
+get_format_for_drawable (decor_t *d, GdkDrawable *drawable)
+{
+ if (!d->frame_window || gdk_drawable_get_depth (drawable) == 32)
+ return xformat_rgba;
+
+ return xformat_rgb;
+}
+
+GdkPixmap *
+create_pixmap (int w,
+ int h,
+ int depth)
+{
+ GtkWidget *widget;
+ GdkWindow *window;
+
+ if (w == 0 || h == 0)
+ abort ();
+
+ widget = (depth > 24) ? style_window_rgba : style_window_rgb;
+ window = gtk_widget_get_window (widget);
+ return gdk_pixmap_new (GDK_DRAWABLE (window), w, h, depth);
+} \ No newline at end of file
diff --git a/src/gtk-window-decorator.c b/src/gtk-window-decorator.c
new file mode 100644
index 0000000..bde881a
--- /dev/null
+++ b/src/gtk-window-decorator.c
@@ -0,0 +1,407 @@
+/*
+ * Copyright © 2006 Novell, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: David Reveman <davidr@novell.com>
+ */
+
+#include "gtk-window-decorator.h"
+
+gboolean minimal = FALSE;
+
+double decoration_alpha = 0.5;
+
+#define SWITCHER_SPACE 40
+
+decor_extents_t _shadow_extents = { 0, 0, 0, 0 };
+decor_extents_t _win_extents = { 6, 6, 6, 6 };
+decor_extents_t _max_win_extents = { 6, 6, 4, 6 };
+decor_extents_t _default_win_extents = { 6, 6, 6, 6 };
+decor_extents_t _switcher_extents = { 6, 6, 6, 6 + SWITCHER_SPACE };
+
+int titlebar_height = 17;
+int max_titlebar_height = 17;
+
+decor_context_t window_context = {
+ { 0, 0, 0, 0 },
+ 6, 6, 4, 6,
+ 0, 0, 0, 0
+};
+
+decor_context_t max_window_context = {
+ { 0, 0, 0, 0 },
+ 6, 6, 4, 6,
+ 0, 0, 0, 0
+};
+
+decor_context_t window_context_no_shadow = {
+ { 0, 0, 0, 0 },
+ 6, 6, 4, 6,
+ 0, 0, 0, 0
+};
+
+decor_context_t max_window_context_no_shadow = {
+ { 0, 0, 0, 0 },
+ 6, 6, 4, 6,
+ 0, 0, 0, 0
+};
+
+decor_context_t switcher_context = {
+ { 0, 0, 0, 0 },
+ 6, 6, 6, 6 + SWITCHER_SPACE,
+ 0, 0, 0, 0
+};
+
+decor_context_t shadow_context = {
+ { 0, 0, 0, 0 },
+ 0, 0, 0, 0,
+ 0, 0, 0, 0,
+};
+
+gdouble shadow_radius = SHADOW_RADIUS;
+gdouble shadow_opacity = SHADOW_OPACITY;
+gushort shadow_color[3] = {
+ SHADOW_COLOR_RED,
+ SHADOW_COLOR_GREEN,
+ SHADOW_COLOR_BLUE
+};
+gint shadow_offset_x = SHADOW_OFFSET_X;
+gint shadow_offset_y = SHADOW_OFFSET_Y;
+
+guint cmdline_options = 0;
+
+decor_shadow_t *no_border_shadow = NULL;
+decor_shadow_t *border_shadow = NULL;
+decor_shadow_t *max_border_shadow = NULL;
+decor_shadow_t *border_no_shadow = NULL;
+decor_shadow_t *max_border_no_shadow = NULL;
+decor_shadow_t *switcher_shadow = NULL;
+
+GdkPixmap *decor_normal_pixmap = NULL;
+GdkPixmap *decor_active_pixmap = NULL;
+
+Atom frame_input_window_atom;
+Atom frame_output_window_atom;
+Atom win_decor_atom;
+Atom win_blur_decor_atom;
+Atom wm_move_resize_atom;
+Atom restack_window_atom;
+Atom select_window_atom;
+Atom mwm_hints_atom;
+Atom switcher_fg_atom;
+
+Atom compiz_shadow_info_atom;
+Atom compiz_shadow_color_atom;
+
+Atom toolkit_action_atom;
+Atom toolkit_action_window_menu_atom;
+Atom toolkit_action_force_quit_dialog_atom;
+
+Time dm_sn_timestamp;
+
+struct _cursor cursor[3][3] = {
+ { C (top_left_corner), C (top_side), C (top_right_corner) },
+ { C (left_side), C (left_ptr), C (right_side) },
+ { C (bottom_left_corner), C (bottom_side), C (bottom_right_corner) }
+};
+
+struct _pos pos[3][3] = {
+ {
+ { 0, 0, 10, 21, 0, 0, 0, 0, 0, 1 },
+ { 10, 0, -8, 6, 0, 0, 1, 0, 0, 1 },
+ { 2, 0, 10, 21, 1, 0, 0, 0, 0, 1 }
+ }, {
+ { 0, 10, 6, 11, 0, 0, 0, 1, 1, 0 },
+ { 6, 6, 0, 15, 0, 0, 1, 0, 0, 1 },
+ { 6, 10, 6, 11, 1, 0, 0, 1, 1, 0 }
+ }, {
+ { 0, 17, 10, 10, 0, 1, 0, 0, 1, 0 },
+ { 10, 21, -8, 6, 0, 1, 1, 0, 1, 0 },
+ { 2, 17, 10, 10, 1, 1, 0, 0, 1, 0 }
+ }
+}, bpos[] = {
+ { 0, 6, 16, 16, 1, 0, 0, 0, 0, 0 },
+ { 0, 6, 16, 16, 1, 0, 0, 0, 0, 0 },
+ { 0, 6, 16, 16, 1, 0, 0, 0, 0, 0 },
+ { 6, 2, 16, 16, 0, 0, 0, 0, 0, 0 }
+};
+
+char *program_name;
+
+GtkWidget *style_window_rgba;
+GtkWidget *style_window_rgb;
+GtkWidget *switcher_label;
+
+GHashTable *frame_table;
+GtkWidget *action_menu = NULL;
+gboolean action_menu_mapped = FALSE;
+decor_color_t _title_color[2];
+PangoContext *pango_context;
+gint double_click_timeout = 250;
+
+GtkWidget *tip_window;
+GtkWidget *tip_label;
+GTimeVal tooltip_last_popdown = { 0, 0 };
+gint tooltip_timer_tag = 0;
+
+GSList *draw_list = NULL;
+guint draw_idle_id = 0;
+
+PangoFontDescription *titlebar_font = NULL;
+gboolean use_system_font = FALSE;
+gint text_height;
+
+gint blur_type = BLUR_TYPE_NONE;
+
+GdkPixmap *switcher_pixmap = NULL;
+GdkPixmap *switcher_buffer_pixmap = NULL;
+gint switcher_width;
+gint switcher_height;
+Window switcher_selected_window = None;
+
+XRenderPictFormat *xformat_rgba;
+XRenderPictFormat *xformat_rgb;
+
+int
+main (int argc, char *argv[])
+{
+ GdkDisplay *gdkdisplay;
+ Display *xdisplay;
+ GdkScreen *gdkscreen;
+ WnckScreen *screen;
+ gint i, j, status;
+ gboolean replace = FALSE;
+
+#ifdef USE_METACITY
+ char *meta_theme = NULL;
+#endif
+
+ program_name = argv[0];
+
+ gtk_init (&argc, &argv);
+
+ bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
+ bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+ textdomain (GETTEXT_PACKAGE);
+
+ for (i = 0; i < argc; i++)
+ {
+ if (strcmp (argv[i], "--minimal") == 0)
+ {
+ minimal = TRUE;
+ }
+ else if (strcmp (argv[i], "--replace") == 0)
+ {
+ replace = TRUE;
+ }
+ else if (strcmp (argv[i], "--blur") == 0)
+ {
+ if (argc > ++i)
+ {
+ if (strcmp (argv[i], "titlebar") == 0)
+ blur_type = BLUR_TYPE_TITLEBAR;
+ else if (strcmp (argv[i], "all") == 0)
+ blur_type = BLUR_TYPE_ALL;
+ }
+ cmdline_options |= CMDLINE_BLUR;
+ }
+
+#ifdef USE_METACITY
+ else if (strcmp (argv[i], "--opacity") == 0)
+ {
+ if (argc > ++i)
+ meta_opacity = atof (argv[i]);
+ cmdline_options |= CMDLINE_OPACITY;
+ }
+ else if (strcmp (argv[i], "--no-opacity-shade") == 0)
+ {
+ meta_shade_opacity = FALSE;
+ cmdline_options |= CMDLINE_OPACITY_SHADE;
+ }
+ else if (strcmp (argv[i], "--active-opacity") == 0)
+ {
+ if (argc > ++i)
+ meta_active_opacity = atof (argv[i]);
+ cmdline_options |= CMDLINE_ACTIVE_OPACITY;
+ }
+ else if (strcmp (argv[i], "--no-active-opacity-shade") == 0)
+ {
+ meta_active_shade_opacity = FALSE;
+ cmdline_options |= CMDLINE_ACTIVE_OPACITY_SHADE;
+ }
+ else if (strcmp (argv[i], "--metacity-theme") == 0)
+ {
+ if (argc > ++i)
+ meta_theme = argv[i];
+ cmdline_options |= CMDLINE_THEME;
+ }
+#endif
+
+ else if (strcmp (argv[i], "--help") == 0)
+ {
+ fprintf (stderr, "%s "
+ "[--minimal] "
+ "[--replace] "
+ "[--blur none|titlebar|all] "
+
+#ifdef USE_METACITY
+ "[--opacity OPACITY] "
+ "[--no-opacity-shade] "
+ "[--active-opacity OPACITY] "
+ "[--no-active-opacity-shade] "
+ "[--metacity-theme THEME] "
+#endif
+
+ "[--help]"
+
+ "\n", program_name);
+ return 0;
+ }
+ }
+
+ theme_draw_window_decoration = draw_window_decoration;
+ theme_calc_decoration_size = calc_decoration_size;
+ theme_update_border_extents = update_border_extents;
+ theme_get_event_window_position = get_event_window_position;
+ theme_get_button_position = get_button_position;
+
+#ifdef USE_METACITY
+ if (meta_theme)
+ {
+ meta_theme_set_current (meta_theme, TRUE);
+ if (meta_theme_get_current ())
+ {
+ theme_draw_window_decoration = meta_draw_window_decoration;
+ theme_calc_decoration_size = meta_calc_decoration_size;
+ theme_update_border_extents = meta_update_border_extents;
+ theme_get_event_window_position = meta_get_event_window_position;
+ theme_get_button_position = meta_get_button_position;
+ }
+ }
+#endif
+
+ gdkdisplay = gdk_display_get_default ();
+ xdisplay = gdk_x11_display_get_xdisplay (gdkdisplay);
+ gdkscreen = gdk_display_get_default_screen (gdkdisplay);
+
+ frame_input_window_atom = XInternAtom (xdisplay,
+ DECOR_INPUT_FRAME_ATOM_NAME, FALSE);
+ frame_output_window_atom = XInternAtom (xdisplay,
+ DECOR_OUTPUT_FRAME_ATOM_NAME, FALSE);
+
+ win_decor_atom = XInternAtom (xdisplay, DECOR_WINDOW_ATOM_NAME, FALSE);
+ win_blur_decor_atom = XInternAtom (xdisplay, DECOR_BLUR_ATOM_NAME, FALSE);
+ wm_move_resize_atom = XInternAtom (xdisplay, "_NET_WM_MOVERESIZE", FALSE);
+ restack_window_atom = XInternAtom (xdisplay, "_NET_RESTACK_WINDOW", FALSE);
+ select_window_atom = XInternAtom (xdisplay, DECOR_SWITCH_WINDOW_ATOM_NAME,
+ FALSE);
+ mwm_hints_atom = XInternAtom (xdisplay, "_MOTIF_WM_HINTS", FALSE);
+ switcher_fg_atom = XInternAtom (xdisplay,
+ DECOR_SWITCH_FOREGROUND_COLOR_ATOM_NAME,
+ FALSE);
+
+ compiz_shadow_info_atom = XInternAtom (xdisplay, "_COMPIZ_NET_CM_SHADOW_PROPERTIES", FALSE);
+ compiz_shadow_color_atom = XInternAtom (xdisplay, "_COMPIZ_NET_CM_SHADOW_COLOR", FALSE);
+
+ toolkit_action_atom =
+ XInternAtom (xdisplay, "_COMPIZ_TOOLKIT_ACTION", FALSE);
+ toolkit_action_window_menu_atom =
+ XInternAtom (xdisplay, "_COMPIZ_TOOLKIT_ACTION_WINDOW_MENU", FALSE);
+ toolkit_action_force_quit_dialog_atom =
+ XInternAtom (xdisplay, "_COMPIZ_TOOLKIT_ACTION_FORCE_QUIT_DIALOG",
+ FALSE);
+
+ status = decor_acquire_dm_session (xdisplay,
+ gdk_screen_get_number (gdkscreen),
+ "gwd", replace, &dm_sn_timestamp);
+ if (status != DECOR_ACQUIRE_STATUS_SUCCESS)
+ {
+ if (status == DECOR_ACQUIRE_STATUS_FAILED)
+ {
+ fprintf (stderr,
+ "%s: Could not acquire decoration manager "
+ "selection on screen %d display \"%s\"\n",
+ program_name, gdk_screen_get_number (gdkscreen),
+ DisplayString (xdisplay));
+ }
+ else if (status == DECOR_ACQUIRE_STATUS_OTHER_DM_RUNNING)
+ {
+ fprintf (stderr,
+ "%s: Screen %d on display \"%s\" already "
+ "has a decoration manager; try using the "
+ "--replace option to replace the current "
+ "decoration manager.\n",
+ program_name, gdk_screen_get_number (gdkscreen),
+ DisplayString (xdisplay));
+ }
+
+ return 1;
+ }
+
+ for (i = 0; i < 3; i++)
+ {
+ for (j = 0; j < 3; j++)
+ {
+ if (cursor[i][j].shape != XC_left_ptr)
+ cursor[i][j].cursor =
+ XCreateFontCursor (xdisplay, cursor[i][j].shape);
+ }
+ }
+
+ xformat_rgba = XRenderFindStandardFormat (xdisplay, PictStandardARGB32);
+ xformat_rgb = XRenderFindStandardFormat (xdisplay, PictStandardRGB24);
+
+ frame_table = g_hash_table_new (NULL, NULL);
+
+ if (!create_tooltip_window ())
+ {
+ fprintf (stderr, "%s, Couldn't create tooltip window\n", argv[0]);
+ return 1;
+ }
+
+ screen = wnck_screen_get_default ();
+ wnck_set_client_type (WNCK_CLIENT_TYPE_PAGER);
+
+ gdk_window_add_filter (NULL,
+ selection_event_filter_func,
+ NULL);
+
+ if (!minimal)
+ {
+ gdk_window_add_filter (NULL,
+ event_filter_func,
+ NULL);
+
+ connect_screen (screen);
+ }
+
+ if (!init_settings (screen))
+ {
+ fprintf (stderr, "%s: Failed to get necessary gtk settings\n", argv[0]);
+ return 1;
+ }
+
+ decor_set_dm_check_hint (xdisplay, gdk_screen_get_number (gdkscreen),
+ WINDOW_DECORATION_TYPE_PIXMAP |
+ WINDOW_DECORATION_TYPE_WINDOW);
+
+ update_default_decorations (gdkscreen);
+
+ gtk_main ();
+
+ return 0;
+}
diff --git a/src/gtk-window-decorator.h b/src/gtk-window-decorator.h
new file mode 100644
index 0000000..37fe299
--- /dev/null
+++ b/src/gtk-window-decorator.h
@@ -0,0 +1,949 @@
+#ifndef _GTK_WINDOW_DECORATOR_H
+#define _GTK_WINDOW_DECORATOR_H
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "decoration.h"
+
+#include <X11/Xlib.h>
+#include <X11/Xatom.h>
+#include <X11/cursorfont.h>
+#include <X11/extensions/Xrender.h>
+#include <X11/Xregion.h>
+
+#ifndef GDK_DISABLE_DEPRECATED
+#define GDK_DISABLE_DEPRECATED
+#endif
+
+#ifndef GTK_DISABLE_DEPRECATED
+#define GTK_DISABLE_DEPRECATED
+#endif
+
+#include <gtk/gtk.h>
+#include <gdk/gdkx.h>
+
+#ifdef USE_GCONF
+#include <gconf/gconf-client.h>
+#endif
+
+#ifdef USE_DBUS_GLIB
+#define DBUS_API_SUBJECT_TO_CHANGE
+#include <dbus/dbus.h>
+#include <dbus/dbus-glib-lowlevel.h>
+#endif
+
+#define WNCK_I_KNOW_THIS_IS_UNSTABLE
+#include <libwnck/libwnck.h>
+#include <libwnck/window-action-menu.h>
+
+#ifndef HAVE_LIBWNCK_2_19_4
+#define wnck_window_get_client_window_geometry wnck_window_get_geometry
+#endif
+
+#include <cairo.h>
+#include <cairo-xlib.h>
+
+#if CAIRO_VERSION < CAIRO_VERSION_ENCODE(1, 1, 0)
+#define CAIRO_EXTEND_PAD CAIRO_EXTEND_NONE
+#endif
+
+#include <pango/pango-context.h>
+#include <pango/pangocairo.h>
+
+#include <string.h>
+#include <stdlib.h>
+#include <math.h>
+#include <limits.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <signal.h>
+
+#include <libintl.h>
+#define _(x) gettext (x)
+#define N_(x) x
+
+#ifdef USE_METACITY
+#include <metacity-private/theme.h>
+#endif
+
+#define METACITY_GCONF_DIR "/apps/metacity/general"
+
+#define COMPIZ_USE_SYSTEM_FONT_KEY \
+METACITY_GCONF_DIR "/titlebar_uses_system_font"
+
+#define COMPIZ_TITLEBAR_FONT_KEY \
+METACITY_GCONF_DIR "/titlebar_font"
+
+#define COMPIZ_DOUBLE_CLICK_TITLEBAR_KEY \
+METACITY_GCONF_DIR "/action_double_click_titlebar"
+
+#define COMPIZ_MIDDLE_CLICK_TITLEBAR_KEY \
+METACITY_GCONF_DIR "/action_middle_click_titlebar"
+
+#define COMPIZ_RIGHT_CLICK_TITLEBAR_KEY \
+METACITY_GCONF_DIR "/action_right_click_titlebar"
+
+#define COMPIZ_GCONF_DIR1 "/apps/compiz/plugins/decoration/allscreens/options"
+
+#define COMPIZ_SHADOW_RADIUS_KEY \
+COMPIZ_GCONF_DIR1 "/shadow_radius"
+
+#define COMPIZ_SHADOW_OPACITY_KEY \
+COMPIZ_GCONF_DIR1 "/shadow_opacity"
+
+#define COMPIZ_SHADOW_COLOR_KEY \
+COMPIZ_GCONF_DIR1 "/shadow_color"
+
+#define COMPIZ_SHADOW_OFFSET_X_KEY \
+COMPIZ_GCONF_DIR1 "/shadow_x_offset"
+
+#define COMPIZ_SHADOW_OFFSET_Y_KEY \
+COMPIZ_GCONF_DIR1 "/shadow_y_offset"
+
+#define META_THEME_KEY \
+METACITY_GCONF_DIR "/theme"
+
+#define META_BUTTON_LAYOUT_KEY \
+METACITY_GCONF_DIR "/button_layout"
+
+#define GCONF_DIR "/apps/gwd"
+
+#define USE_META_THEME_KEY \
+GCONF_DIR "/use_metacity_theme"
+
+#define META_THEME_OPACITY_KEY \
+GCONF_DIR "/metacity_theme_opacity"
+
+#define META_THEME_SHADE_OPACITY_KEY \
+GCONF_DIR "/metacity_theme_shade_opacity"
+
+#define META_THEME_ACTIVE_OPACITY_KEY \
+GCONF_DIR "/metacity_theme_active_opacity"
+
+#define META_THEME_ACTIVE_SHADE_OPACITY_KEY \
+GCONF_DIR "/metacity_theme_active_shade_opacity"
+
+#define BLUR_TYPE_KEY \
+GCONF_DIR "/blur_type"
+
+#define WHEEL_ACTION_KEY \
+GCONF_DIR "/mouse_wheel_action"
+
+#define DBUS_DEST "org.freedesktop.compiz"
+#define DBUS_PATH "/org/freedesktop/compiz/decor/screen0"
+#define DBUS_INTERFACE "org.freedesktop.compiz"
+#define DBUS_METHOD_GET "get"
+
+#define STROKE_ALPHA 0.6
+
+#define ICON_SPACE 20
+
+#define DOUBLE_CLICK_DISTANCE 8.0
+
+#define WM_MOVERESIZE_SIZE_TOPLEFT 0
+#define WM_MOVERESIZE_SIZE_TOP 1
+#define WM_MOVERESIZE_SIZE_TOPRIGHT 2
+#define WM_MOVERESIZE_SIZE_RIGHT 3
+#define WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
+#define WM_MOVERESIZE_SIZE_BOTTOM 5
+#define WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
+#define WM_MOVERESIZE_SIZE_LEFT 7
+#define WM_MOVERESIZE_MOVE 8
+#define WM_MOVERESIZE_SIZE_KEYBOARD 9
+#define WM_MOVERESIZE_MOVE_KEYBOARD 10
+
+#define SHADOW_RADIUS 8.0
+#define SHADOW_OPACITY 0.5
+#define SHADOW_OFFSET_X 1
+#define SHADOW_OFFSET_Y 1
+#define SHADOW_COLOR_RED 0x0000
+#define SHADOW_COLOR_GREEN 0x0000
+#define SHADOW_COLOR_BLUE 0x0000
+
+#define META_OPACITY 0.75
+#define META_SHADE_OPACITY TRUE
+#define META_ACTIVE_OPACITY 1.0
+#define META_ACTIVE_SHADE_OPACITY TRUE
+
+#define META_MAXIMIZED (WNCK_WINDOW_STATE_MAXIMIZED_HORIZONTALLY | \
+WNCK_WINDOW_STATE_MAXIMIZED_VERTICALLY)
+
+#define CMDLINE_OPACITY (1 << 0)
+#define CMDLINE_OPACITY_SHADE (1 << 1)
+#define CMDLINE_ACTIVE_OPACITY (1 << 2)
+#define CMDLINE_ACTIVE_OPACITY_SHADE (1 << 3)
+#define CMDLINE_BLUR (1 << 4)
+#define CMDLINE_THEME (1 << 5)
+
+#define MWM_HINTS_DECORATIONS (1L << 1)
+
+#define MWM_DECOR_ALL (1L << 0)
+#define MWM_DECOR_BORDER (1L << 1)
+#define MWM_DECOR_HANDLE (1L << 2)
+#define MWM_DECOR_TITLE (1L << 3)
+#define MWM_DECOR_MENU (1L << 4)
+#define MWM_DECOR_MINIMIZE (1L << 5)
+#define MWM_DECOR_MAXIMIZE (1L << 6)
+
+#define PROP_MOTIF_WM_HINT_ELEMENTS 3
+
+typedef struct {
+unsigned long flags;
+unsigned long functions;
+unsigned long decorations;
+} MwmHints;
+
+enum {
+ CLICK_ACTION_NONE,
+ CLICK_ACTION_SHADE,
+ CLICK_ACTION_MAXIMIZE,
+ CLICK_ACTION_MINIMIZE,
+ CLICK_ACTION_RAISE,
+ CLICK_ACTION_LOWER,
+ CLICK_ACTION_MENU
+};
+
+enum {
+ WHEEL_ACTION_NONE,
+ WHEEL_ACTION_SHADE
+};
+
+#define DOUBLE_CLICK_ACTION_DEFAULT CLICK_ACTION_MAXIMIZE
+#define MIDDLE_CLICK_ACTION_DEFAULT CLICK_ACTION_LOWER
+#define RIGHT_CLICK_ACTION_DEFAULT CLICK_ACTION_MENU
+#define WHEEL_ACTION_DEFAULT WHEEL_ACTION_NONE
+
+int double_click_action;
+int middle_click_action;
+int right_click_action;
+int wheel_action;
+
+extern gboolean minimal;
+extern double decoration_alpha;
+
+#define SWITCHER_SPACE 40
+
+extern decor_extents_t _shadow_extents;
+extern decor_extents_t _win_extents;
+extern decor_extents_t _max_win_extents;
+extern decor_extents_t _default_win_extents;
+extern decor_extents_t _switcher_extents;
+
+extern int titlebar_height;
+extern int max_titlebar_height;
+
+extern decor_context_t window_context;
+extern decor_context_t window_context_no_shadow;
+extern decor_context_t max_window_context;
+extern decor_context_t max_window_context_no_shadow;
+extern decor_context_t switcher_context;
+extern decor_context_t shadow_context;
+
+extern gdouble shadow_radius;
+extern gdouble shadow_opacity;
+extern gushort shadow_color[3];
+extern gint shadow_offset_x;
+extern gint shadow_offset_y;
+
+#ifdef USE_METACITY
+extern double meta_opacity;
+extern gboolean meta_shade_opacity;
+extern double meta_active_opacity;
+extern gboolean meta_active_shade_opacity;
+
+extern gboolean meta_button_layout_set;
+extern MetaButtonLayout meta_button_layout;
+#endif
+
+extern guint cmdline_options;
+
+extern decor_shadow_t *no_border_shadow;
+extern decor_shadow_t *border_shadow;
+extern decor_shadow_t *border_no_shadow;
+extern decor_shadow_t *max_border_shadow;
+extern decor_shadow_t *max_border_no_shadow;
+extern decor_shadow_t *switcher_shadow;
+
+extern GdkPixmap *decor_normal_pixmap;
+extern GdkPixmap *decor_active_pixmap;
+
+extern Atom frame_input_window_atom;
+extern Atom frame_output_window_atom;
+extern Atom win_decor_atom;
+extern Atom win_blur_decor_atom;
+extern Atom wm_move_resize_atom;
+extern Atom restack_window_atom;
+extern Atom select_window_atom;
+extern Atom mwm_hints_atom;
+extern Atom switcher_fg_atom;
+
+extern Atom toolkit_action_atom;
+extern Atom toolkit_action_window_menu_atom;
+extern Atom toolkit_action_force_quit_dialog_atom;
+
+extern Time dm_sn_timestamp;
+
+#define C(name) { 0, XC_ ## name }
+
+struct _cursor {
+ Cursor cursor;
+ unsigned int shape;
+};
+
+extern struct _cursor cursor[3][3];
+
+#define BUTTON_CLOSE 0
+#define BUTTON_MAX 1
+#define BUTTON_MIN 2
+#define BUTTON_MENU 3
+#define BUTTON_SHADE 4
+#define BUTTON_ABOVE 5
+#define BUTTON_STICK 6
+#define BUTTON_UNSHADE 7
+#define BUTTON_UNABOVE 8
+#define BUTTON_UNSTICK 9
+#define BUTTON_NUM 10
+
+struct _pos {
+ int x, y, w, h;
+ int xw, yh, ww, hh, yth, hth;
+};
+
+extern struct _pos pos[3][3], bpos[];
+
+typedef struct _decor_color {
+ double r;
+ double g;
+ double b;
+} decor_color_t;
+
+
+#define IN_EVENT_WINDOW (1 << 0)
+#define PRESSED_EVENT_WINDOW (1 << 1)
+
+typedef struct _decor_event {
+ guint time;
+ guint window;
+ guint x;
+ guint y;
+ guint x_root;
+ guint y_root;
+ guint button;
+} decor_event;
+
+typedef enum _decor_event_type {
+ GButtonPress = 1,
+ GButtonRelease,
+ GEnterNotify,
+ GLeaveNotify,
+ GMotionNotify
+} decor_event_type;
+
+typedef void (*event_callback) (WnckWindow *win,
+ decor_event *gtkwd_event,
+ decor_event_type gtkwd_type);
+
+typedef struct {
+ Window window;
+ Box pos;
+ event_callback callback;
+} event_window;
+
+typedef struct _decor {
+ WnckWindow *win;
+ event_window event_windows[3][3];
+ event_window button_windows[BUTTON_NUM];
+ Box *last_pos_entered;
+ guint button_states[BUTTON_NUM];
+ GdkPixmap *pixmap;
+ GdkPixmap *buffer_pixmap;
+ GdkWindow *frame_window;
+ GtkWidget *decor_window;
+ GtkWidget *decor_event_box;
+ GtkWidget *decor_image;
+ cairo_t *cr;
+ decor_layout_t border_layout;
+ decor_context_t *context;
+ decor_shadow_t *shadow;
+ Picture picture;
+ gint button_width;
+ gint width;
+ gint height;
+ gint client_width;
+ gint client_height;
+ gboolean decorated;
+ gboolean active;
+ PangoLayout *layout;
+ gchar *name;
+ cairo_pattern_t *icon;
+ GdkPixmap *icon_pixmap;
+ GdkPixbuf *icon_pixbuf;
+ WnckWindowState state;
+ WnckWindowActions actions;
+ XID prop_xid;
+ GtkWidget *force_quit_dialog;
+ Bool created;
+ void (*draw) (struct _decor *d);
+} decor_t;
+
+void (*theme_draw_window_decoration) (decor_t *d);
+gboolean (*theme_calc_decoration_size) (decor_t *d,
+ int client_width,
+ int client_height,
+ int text_width,
+ int *width,
+ int *height);
+void (*theme_update_border_extents) (gint text_height);
+void (*theme_get_event_window_position) (decor_t *d,
+ gint i,
+ gint j,
+ gint width,
+ gint height,
+ gint *x,
+ gint *y,
+ gint *w,
+ gint *h);
+gboolean (*theme_get_button_position) (decor_t *d,
+ gint i,
+ gint width,
+ gint height,
+ gint *x,
+ gint *y,
+ gint *w,
+ gint *h);
+
+extern char *program_name;
+
+extern GtkWidget *style_window_rgba;
+extern GtkWidget *style_window_rgb;
+extern GtkWidget *switcher_label;
+
+extern GHashTable *frame_table;
+extern GtkWidget *action_menu;
+extern gboolean action_menu_mapped;
+extern decor_color_t _title_color[2];
+extern PangoContext *pango_context;
+extern gint double_click_timeout;
+
+extern GtkWidget *tip_window;
+extern GtkWidget *tip_label;
+extern GTimeVal tooltip_last_popdown;
+extern gint tooltip_timer_tag;
+
+extern GSList *draw_list;
+extern guint draw_idle_id;
+
+extern PangoFontDescription *titlebar_font;
+extern gboolean use_system_font;
+extern gint text_height;
+
+#define BLUR_TYPE_NONE 0
+#define BLUR_TYPE_TITLEBAR 1
+#define BLUR_TYPE_ALL 2
+
+extern gint blur_type;
+
+extern GdkPixmap *switcher_pixmap;
+extern GdkPixmap *switcher_buffer_pixmap;
+extern gint switcher_width;
+extern gint switcher_height;
+extern Window switcher_selected_window;
+
+extern XRenderPictFormat *xformat_rgba;
+extern XRenderPictFormat *xformat_rgb;
+
+extern Atom compiz_shadow_info_atom;
+extern Atom compiz_shadow_color_atom;
+
+/* gtk-window-decorator.c */
+
+double
+dist (double x1, double y1,
+ double x2, double y2);
+
+/* decorator.c */
+
+gboolean
+update_window_decoration_size (WnckWindow *win);
+
+void
+update_window_decoration_name (WnckWindow *win);
+
+gint
+max_window_name_width (WnckWindow *win);
+
+void
+update_default_decorations (GdkScreen *screen);
+
+void
+update_window_decoration_state (WnckWindow *win);
+
+void
+update_window_decoration_actions (WnckWindow *win);
+
+void
+update_window_decoration_icon (WnckWindow *win);
+
+void
+update_event_windows (WnckWindow *win);
+
+int
+update_shadow (void);
+
+void
+shadow_property_changed (WnckScreen *screen);
+
+void
+update_titlebar_font (void);
+
+void
+update_window_decoration_name (WnckWindow *win);
+
+void
+update_window_decoration (WnckWindow *win);
+
+void
+queue_decor_draw (decor_t *d);
+
+void
+copy_to_front_buffer (decor_t *d);
+
+
+
+/* wnck.c*/
+
+void
+decorations_changed (WnckScreen *screen);
+
+void
+connect_screen (WnckScreen *screen);
+
+void
+add_frame_window (WnckWindow *win,
+ Window frame,
+ Bool mode);
+
+void
+remove_frame_window (WnckWindow *win);
+
+void
+restack_window (WnckWindow *win,
+ int stack_mode);
+
+
+/* blur.c */
+
+void
+decor_update_blur_property (decor_t *d,
+ int width,
+ int height,
+ Region top_region,
+ int top_offset,
+ Region bottom_region,
+ int bottom_offset,
+ Region left_region,
+ int left_offset,
+ Region right_region,
+ int right_offset);
+
+/* decorprops.c */
+
+void
+decor_update_window_property (decor_t *d);
+
+void
+decor_update_switcher_property (decor_t *d);
+
+/* cairo.c */
+
+#define CORNER_TOPLEFT (1 << 0)
+#define CORNER_TOPRIGHT (1 << 1)
+#define CORNER_BOTTOMRIGHT (1 << 2)
+#define CORNER_BOTTOMLEFT (1 << 3)
+
+#define SHADE_LEFT (1 << 0)
+#define SHADE_RIGHT (1 << 1)
+#define SHADE_TOP (1 << 2)
+#define SHADE_BOTTOM (1 << 3)
+
+void
+draw_shadow_background (decor_t *d,
+ cairo_t *cr,
+ decor_shadow_t *s,
+ decor_context_t *c);
+
+void
+draw_window_decoration (decor_t *d);
+
+void
+fill_rounded_rectangle (cairo_t *cr,
+ double x,
+ double y,
+ double w,
+ double h,
+ double radius,
+ int corner,
+ decor_color_t *c0,
+ double alpha0,
+ decor_color_t *c1,
+ double alpha1,
+ int gravity);
+
+void
+rounded_rectangle (cairo_t *cr,
+ double x,
+ double y,
+ double w,
+ double h,
+ double radius,
+ int corner);
+
+gboolean
+calc_decoration_size (decor_t *d,
+ gint w,
+ gint h,
+ gint name_width,
+ gint *width,
+ gint *height);
+
+void
+update_border_extents (gint text_height);
+
+gboolean
+get_button_position (decor_t *d,
+ gint i,
+ gint width,
+ gint height,
+ gint *x,
+ gint *y,
+ gint *w,
+ gint *h);
+
+void
+get_event_window_position (decor_t *d,
+ gint i,
+ gint j,
+ gint width,
+ gint height,
+ gint *x,
+ gint *y,
+ gint *w,
+ gint *h);
+
+/* gdk.c */
+
+void
+gdk_cairo_set_source_color_alpha (cairo_t *cr,
+ GdkColor *color,
+ double alpha);
+
+inline GdkWindow *
+create_gdk_window (Window xframe);
+
+GdkColormap *
+get_colormap_for_drawable (GdkDrawable *d);
+
+XRenderPictFormat *
+get_format_for_drawable (decor_t *d, GdkDrawable *drawable);
+
+GdkPixmap *
+create_pixmap (int w,
+ int h,
+ int depth);
+
+GdkPixmap *
+pixmap_new_from_pixbuf (GdkPixbuf *pixbuf, int depth);
+
+/* metacity.c */
+#ifdef USE_METACITY
+void
+meta_draw_window_decoration (decor_t *d);
+
+void
+meta_get_decoration_geometry (decor_t *d,
+ MetaTheme *theme,
+ MetaFrameFlags *flags,
+ MetaFrameGeometry *fgeom,
+ MetaButtonLayout *button_layout,
+ GdkRectangle *clip);
+
+void
+meta_calc_button_size (decor_t *d);
+
+gboolean
+meta_calc_decoration_size (decor_t *d,
+ gint w,
+ gint h,
+ gint name_width,
+ gint *width,
+ gint *height);
+
+gboolean
+meta_get_button_position (decor_t *d,
+ gint i,
+ gint width,
+ gint height,
+ gint *x,
+ gint *y,
+ gint *w,
+ gint *h);
+
+gboolean
+meta_button_present (MetaButtonLayout *button_layout,
+ MetaButtonFunction function);
+
+void
+meta_get_event_window_position (decor_t *d,
+ gint i,
+ gint j,
+ gint width,
+ gint height,
+ gint *x,
+ gint *y,
+ gint *w,
+ gint *h);
+void
+meta_update_border_extents (gint text_height);
+
+void
+meta_update_button_layout (const char *value);
+#endif
+/* switcher.c */
+
+#define SWITCHER_ALPHA 0xa0a0
+
+void
+draw_switcher_decoration (decor_t *d);
+
+gboolean
+update_switcher_window (WnckWindow *win,
+ Window selected);
+
+/* events.c */
+
+void
+move_resize_window (WnckWindow *win,
+ int direction,
+ decor_event *gtkwd_event);
+
+void
+common_button_event (WnckWindow *win,
+ decor_event *gtkwd_event,
+ decor_event_type gtkwd_type,
+ int button,
+ int max,
+ char *tooltip);
+
+void
+close_button_event (WnckWindow *win,
+ decor_event *gtkwd_event,
+ decor_event_type gtkwd_type);
+
+void
+max_button_event (WnckWindow *win,
+ decor_event *gtkwd_event,
+ decor_event_type gtkwd_type);
+
+void
+min_button_event (WnckWindow *win,
+ decor_event *gtkwd_event,
+ decor_event_type gtkwd_type);
+
+void
+menu_button_event (WnckWindow *win,
+ decor_event *gtkwd_event,
+ decor_event_type gtkwd_type);
+
+void
+shade_button_event (WnckWindow *win,
+ decor_event *gtkwd_event,
+ decor_event_type gtkwd_type);
+
+void
+above_button_event (WnckWindow *win,
+ decor_event *gtkwd_event,
+ decor_event_type gtkwd_type);
+
+void
+stick_button_event (WnckWindow *win,
+ decor_event *gtkwd_event,
+ decor_event_type gtkwd_type);
+void
+unshade_button_event (WnckWindow *win,
+ decor_event *gtkwd_event,
+ decor_event_type gtkwd_type);
+
+void
+unabove_button_event (WnckWindow *win,
+ decor_event *gtkwd_event,
+ decor_event_type gtkwd_type);
+
+void
+unstick_button_event (WnckWindow *win,
+ decor_event *gtkwd_event,
+ decor_event_type gtkwd_type);
+
+void
+handle_title_button_event (WnckWindow *win,
+ int action,
+ decor_event *gtkwd_event);
+
+void
+handle_mouse_wheel_title_event (WnckWindow *win,
+ unsigned int button);
+
+void
+title_event (WnckWindow *win,
+ decor_event *gtkwd_event,
+ decor_event_type gtkwd_type);
+
+void
+frame_common_event (WnckWindow *win,
+ int direction,
+ decor_event *gtkwd_event,
+ decor_event_type gtkwd_type);
+
+void
+top_left_event (WnckWindow *win,
+ decor_event *gtkwd_event,
+ decor_event_type gtkwd_type);
+
+void
+top_event (WnckWindow *win,
+ decor_event *gtkwd_event,
+ decor_event_type gtkwd_type);
+
+void
+top_right_event (WnckWindow *win,
+ decor_event *gtkwd_event,
+ decor_event_type gtkwd_type);
+
+void
+left_event (WnckWindow *win,
+ decor_event *gtkwd_event,
+ decor_event_type gtkwd_type);
+void
+right_event (WnckWindow *win,
+ decor_event *gtkwd_event,
+ decor_event_type gtkwd_type);
+
+void
+bottom_left_event (WnckWindow *win,
+ decor_event *gtkwd_event,
+ decor_event_type gtkwd_type);
+
+void
+bottom_event (WnckWindow *win,
+ decor_event *gtkwd_event,
+ decor_event_type gtkwd_type);
+void
+bottom_right_event (WnckWindow *win,
+ decor_event *gtkwd_event,
+ decor_event_type gtkwd_type);
+
+void
+frame_window_realized (GtkWidget *widget,
+ gpointer data);
+
+event_callback
+find_event_callback_for_point (decor_t *d,
+ int x,
+ int y,
+ Bool *enter,
+ Bool *leave,
+ BoxPtr *entered_box);
+
+event_callback
+find_leave_event_callback (decor_t *d);
+
+void
+frame_handle_button_press (GtkWidget *widget,
+ GdkEventButton *event,
+ gpointer user_data);
+
+void
+frame_handle_button_release (GtkWidget *widget,
+ GdkEventButton *event,
+ gpointer user_data);
+
+void
+frame_handle_motion (GtkWidget *widget,
+ GdkEventMotion *event,
+ gpointer user_data);
+
+GdkFilterReturn
+selection_event_filter_func (GdkXEvent *gdkxevent,
+ GdkEvent *event,
+ gpointer data);
+
+GdkFilterReturn
+event_filter_func (GdkXEvent *gdkxevent,
+ GdkEvent *event,
+ gpointer data);
+
+/* tooltip.c */
+
+gboolean
+create_tooltip_window (void);
+
+void
+handle_tooltip_event (WnckWindow *win,
+ decor_event *gtkwd_event,
+ decor_event_type gtkwd_type,
+ guint state,
+ const char *tip);
+
+/* forcequit.c */
+
+void
+show_force_quit_dialog (WnckWindow *win,
+ Time timestamp);
+
+void
+hide_force_quit_dialog (WnckWindow *win);
+
+/* actionmenu.c */
+
+void
+action_menu_map (WnckWindow *win,
+ long button,
+ Time time);
+
+/* util.c */
+
+double
+square (double x);
+
+double
+dist (double x1, double y1,
+ double x2, double y2);
+
+void
+shade (const decor_color_t *a,
+ decor_color_t *b,
+ float k);
+
+gboolean
+get_window_prop (Window xwindow,
+ Atom atom,
+ Window *val);
+
+unsigned int
+get_mwm_prop (Window xwindow);
+
+
+/* style.c */
+
+void
+update_style (GtkWidget *widget);
+
+void
+style_changed (GtkWidget *widget);
+
+/* settings.c */
+
+gboolean
+init_settings (WnckScreen *screen);
+
+#endif
diff --git a/src/gwd.schemas.in b/src/gwd.schemas.in
new file mode 100644
index 0000000..89b8c9c
--- /dev/null
+++ b/src/gwd.schemas.in
@@ -0,0 +1,81 @@
+<gconfschemafile>
+ <schemalist>
+ <schema>
+ <key>/schemas/apps/gwd/blur_type</key>
+ <applyto>/apps/gwd/blur_type</applyto>
+ <owner>gwd</owner>
+ <type>string</type>
+ <default>none</default>
+ <locale name="C">
+ <short>Blur type</short>
+ <long>Type of blur used for window decorations</long>
+ </locale>
+ </schema>
+ <schema>
+ <key>/schemas/apps/gwd/use_metacity_theme</key>
+ <applyto>/apps/gwd/use_metacity_theme</applyto>
+ <owner>gwd</owner>
+ <type>bool</type>
+ <default>true</default>
+ <locale name="C">
+ <short>Use metacity theme</short>
+ <long>Use metacity theme when drawing window decorations</long>
+ </locale>
+ </schema>
+ <schema>
+ <key>/schemas/apps/gwd/mouse_wheel_action</key>
+ <applyto>/apps/gwd/mouse_wheel_action</applyto>
+ <owner>gwd</owner>
+ <type>string</type>
+ <default>none</default>
+ <locale name="C">
+ <short>Title bar mouse wheel action</short>
+ <long>Action to take when scrolling the mouse wheel on a window title bar.</long>
+ </locale>
+ </schema>
+ <schema>
+ <key>/schemas/apps/gwd/metacity_theme_opacity</key>
+ <applyto>/apps/gwd/metacity_theme_opacity</applyto>
+ <owner>gwd</owner>
+ <type>float</type>
+ <default>0.75</default>
+ <locale name="C">
+ <short>Metacity theme opacity</short>
+ <long>Opacity to use for metacity theme decorations</long>
+ </locale>
+ </schema>
+ <schema>
+ <key>/schemas/apps/gwd/metacity_theme_shade_opacity</key>
+ <applyto>/apps/gwd/metacity_theme_shade_opacity</applyto>
+ <owner>gwd</owner>
+ <type>bool</type>
+ <default>true</default>
+ <locale name="C">
+ <short>Metacity theme opacity shade</short>
+ <long>Shade windows with metacity theme decorations from opaque to translucent</long>
+ </locale>
+ </schema>
+ <schema>
+ <key>/schemas/apps/gwd/metacity_theme_active_opacity</key>
+ <applyto>/apps/gwd/metacity_theme_active_opacity</applyto>
+ <owner>gwd</owner>
+ <type>float</type>
+ <default>1.0</default>
+ <locale name="C">
+ <short>Metacity theme active window opacity</short>
+ <long>Opacity to use for active windows with metacity theme decorations</long>
+ </locale>
+ </schema>
+ <schema>
+ <key>/schemas/apps/gwd/metacity_theme_active_shade_opacity</key>
+ <applyto>/apps/gwd/metacity_theme_active_shade_opacity</applyto>
+ <owner>gwd</owner>
+ <type>bool</type>
+ <default>true</default>
+ <locale name="C">
+ <short>Metacity theme active window opacity shade</short>
+ <long>Shade active windows with metacity theme decorations from opaque to translucent</long>
+ </locale>
+ </schema>
+ </schemalist>
+</gconfschemafile>
diff --git a/src/metacity.c b/src/metacity.c
new file mode 100644
index 0000000..bbef354
--- /dev/null
+++ b/src/metacity.c
@@ -0,0 +1,1591 @@
+#include "gtk-window-decorator.h"
+
+#ifdef USE_METACITY
+
+double meta_opacity = META_OPACITY;
+gboolean meta_shade_opacity = META_SHADE_OPACITY;
+double meta_active_opacity = META_ACTIVE_OPACITY;
+gboolean meta_active_shade_opacity = META_ACTIVE_SHADE_OPACITY;
+
+gboolean meta_button_layout_set = FALSE;
+MetaButtonLayout meta_button_layout;
+
+static void
+decor_update_meta_window_property (decor_t *d,
+ MetaTheme *theme,
+ MetaFrameFlags flags,
+ Region top,
+ Region bottom,
+ Region left,
+ Region right)
+{
+ long data[256];
+ Display *xdisplay =
+ GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
+ gint nQuad;
+ decor_extents_t extents, max_extents;
+ decor_quad_t quads[N_QUADS_MAX];
+ gint w, lh, rh;
+ gint top_stretch_offset;
+ gint bottom_stretch_offset;
+ gint left_stretch_offset;
+ gint right_stretch_offset;
+
+ w = d->border_layout.top.x2 - d->border_layout.top.x1 -
+ d->context->left_space - d->context->right_space;
+
+ if (d->border_layout.rotation)
+ lh = d->border_layout.left.x2 - d->border_layout.left.x1;
+ else
+ lh = d->border_layout.left.y2 - d->border_layout.left.y1;
+
+ if (d->border_layout.rotation)
+ rh = d->border_layout.right.x2 - d->border_layout.right.x1;
+ else
+ rh = d->border_layout.right.y2 - d->border_layout.right.y1;
+
+ left_stretch_offset = lh / 2;
+ right_stretch_offset = rh / 2;
+ top_stretch_offset = w - d->button_width - 1;
+ bottom_stretch_offset = (d->border_layout.bottom.x2 -
+ d->border_layout.bottom.x1 -
+ d->context->left_space -
+ d->context->right_space) / 2;
+
+ nQuad = decor_set_lXrXtXbX_window_quads (quads, d->context,
+ &d->border_layout,
+ left_stretch_offset,
+ right_stretch_offset,
+ top_stretch_offset,
+ bottom_stretch_offset);
+
+ extents = _win_extents;
+ max_extents = _max_win_extents;
+
+ extents.top += titlebar_height;
+ max_extents.top += max_titlebar_height;
+
+ if (d->frame_window)
+ decor_gen_window_property (data, &extents, &max_extents, 20, 20);
+ else
+ decor_quads_to_property (data, GDK_PIXMAP_XID (d->pixmap),
+ &extents, &max_extents,
+ ICON_SPACE + d->button_width,
+ 0,
+ quads, nQuad);
+
+ gdk_error_trap_push ();
+ XChangeProperty (xdisplay, d->prop_xid,
+ win_decor_atom,
+ XA_INTEGER,
+ 32, PropModeReplace, (guchar *) data,
+ BASE_PROP_SIZE + QUAD_PROP_SIZE * nQuad);
+ gdk_display_sync (gdk_display_get_default ());
+ gdk_error_trap_pop ();
+
+ decor_update_blur_property (d,
+ w, lh,
+ top, top_stretch_offset,
+ bottom, bottom_stretch_offset,
+ left, left_stretch_offset,
+ right, right_stretch_offset);
+}
+
+static void
+meta_get_corner_radius (const MetaFrameGeometry *fgeom,
+ int *top_left_radius,
+ int *top_right_radius,
+ int *bottom_left_radius,
+ int *bottom_right_radius)
+{
+
+#ifdef HAVE_METACITY_2_17_0
+ *top_left_radius = fgeom->top_left_corner_rounded_radius;
+ *top_right_radius = fgeom->top_right_corner_rounded_radius;
+ *bottom_left_radius = fgeom->bottom_left_corner_rounded_radius;
+ *bottom_right_radius = fgeom->bottom_right_corner_rounded_radius;
+#else
+ *top_left_radius = fgeom->top_left_corner_rounded ? 5 : 0;
+ *top_right_radius = fgeom->top_right_corner_rounded ? 5 : 0;
+ *bottom_left_radius = fgeom->bottom_left_corner_rounded ? 5 : 0;
+ *bottom_right_radius = fgeom->bottom_right_corner_rounded ? 5 : 0;
+#endif
+
+}
+
+static int
+radius_to_width (int radius,
+ int i)
+{
+ float r1 = sqrt (radius) + radius;
+ float r2 = r1 * r1 - (r1 - (i + 0.5)) * (r1 - (i + 0.5));
+
+ return floor (0.5f + r1 - sqrt (r2));
+}
+
+static Region
+meta_get_top_border_region (const MetaFrameGeometry *fgeom,
+ int width)
+{
+ Region corners_xregion, border_xregion;
+ XRectangle xrect;
+ int top_left_radius;
+ int top_right_radius;
+ int bottom_left_radius;
+ int bottom_right_radius;
+ int w, i;
+
+ corners_xregion = XCreateRegion ();
+
+ meta_get_corner_radius (fgeom,
+ &top_left_radius,
+ &top_right_radius,
+ &bottom_left_radius,
+ &bottom_right_radius);
+
+ if (top_left_radius)
+ {
+ for (i = 0; i < top_left_radius; i++)
+ {
+ w = radius_to_width (top_left_radius, i);
+
+ xrect.x = 0;
+ xrect.y = i;
+ xrect.width = w;
+ xrect.height = 1;
+
+ XUnionRectWithRegion (&xrect, corners_xregion, corners_xregion);
+ }
+ }
+
+ if (top_right_radius)
+ {
+ for (i = 0; i < top_right_radius; i++)
+ {
+ w = radius_to_width (top_right_radius, i);
+
+ xrect.x = width - w;
+ xrect.y = i;
+ xrect.width = w;
+ xrect.height = 1;
+
+ XUnionRectWithRegion (&xrect, corners_xregion, corners_xregion);
+ }
+ }
+
+ border_xregion = XCreateRegion ();
+
+ xrect.x = 0;
+ xrect.y = 0;
+ xrect.width = width;
+ xrect.height = fgeom->top_height;
+
+ XUnionRectWithRegion (&xrect, border_xregion, border_xregion);
+
+ XSubtractRegion (border_xregion, corners_xregion, border_xregion);
+
+ XDestroyRegion (corners_xregion);
+
+ return border_xregion;
+}
+
+static Region
+meta_get_bottom_border_region (const MetaFrameGeometry *fgeom,
+ int width)
+{
+ Region corners_xregion, border_xregion;
+ XRectangle xrect;
+ int top_left_radius;
+ int top_right_radius;
+ int bottom_left_radius;
+ int bottom_right_radius;
+ int w, i;
+
+ corners_xregion = XCreateRegion ();
+
+ meta_get_corner_radius (fgeom,
+ &top_left_radius,
+ &top_right_radius,
+ &bottom_left_radius,
+ &bottom_right_radius);
+
+ if (bottom_left_radius)
+ {
+ for (i = 0; i < bottom_left_radius; i++)
+ {
+ w = radius_to_width (bottom_left_radius, i);
+
+ xrect.x = 0;
+ xrect.y = fgeom->bottom_height - i - 1;
+ xrect.width = w;
+ xrect.height = 1;
+
+ XUnionRectWithRegion (&xrect, corners_xregion, corners_xregion);
+ }
+ }
+
+ if (bottom_right_radius)
+ {
+ for (i = 0; i < bottom_right_radius; i++)
+ {
+ w = radius_to_width (bottom_right_radius, i);
+
+ xrect.x = width - w;
+ xrect.y = fgeom->bottom_height - i - 1;
+ xrect.width = w;
+ xrect.height = 1;
+
+ XUnionRectWithRegion (&xrect, corners_xregion, corners_xregion);
+ }
+ }
+
+ border_xregion = XCreateRegion ();
+
+ xrect.x = 0;
+ xrect.y = 0;
+ xrect.width = width;
+ xrect.height = fgeom->bottom_height;
+
+ XUnionRectWithRegion (&xrect, border_xregion, border_xregion);
+
+ XSubtractRegion (border_xregion, corners_xregion, border_xregion);
+
+ XDestroyRegion (corners_xregion);
+
+ return border_xregion;
+}
+
+static Region
+meta_get_left_border_region (const MetaFrameGeometry *fgeom,
+ int height)
+{
+ Region border_xregion;
+ XRectangle xrect;
+
+ border_xregion = XCreateRegion ();
+
+ xrect.x = 0;
+ xrect.y = 0;
+ xrect.width = fgeom->left_width;
+ xrect.height = height - fgeom->top_height - fgeom->bottom_height;
+
+ XUnionRectWithRegion (&xrect, border_xregion, border_xregion);
+
+ return border_xregion;
+}
+
+static Region
+meta_get_right_border_region (const MetaFrameGeometry *fgeom,
+ int height)
+{
+ Region border_xregion;
+ XRectangle xrect;
+
+ border_xregion = XCreateRegion ();
+
+ xrect.x = 0;
+ xrect.y = 0;
+ xrect.width = fgeom->right_width;
+ xrect.height = height - fgeom->top_height - fgeom->bottom_height;
+
+ XUnionRectWithRegion (&xrect, border_xregion, border_xregion);
+
+ return border_xregion;
+}
+
+static MetaButtonState
+meta_button_state (int state)
+{
+