diff options
author | Jasper St. Pierre <jstpierre@mecheye.net> | 2013-07-17 23:15:02 -0400 |
---|---|---|
committer | Jasper St. Pierre <jstpierre@mecheye.net> | 2013-08-13 09:39:02 -0400 |
commit | 8c1c77482db263a7dcc04051a9694f30a852b702 (patch) | |
tree | ff1ba7bb3b2a362a488f5b9cbad1c7f89376305b | |
parent | e633606ca951bd73164b289b899aff283fd72a96 (diff) | |
download | mutter-8c1c77482db263a7dcc04051a9694f30a852b702.tar.gz |
Remove old, deprecated utilities that nobody has used in a million years
https://bugzilla.gnome.org/show_bug.cgi?id=704437
30 files changed, 10 insertions, 5172 deletions
diff --git a/configure.ac b/configure.ac index dbb3acae2..9baf35bf1 100644 --- a/configure.ac +++ b/configure.ac @@ -118,9 +118,6 @@ AM_GLIB_GNU_GETTEXT ## here we get the flags we'll actually use # GRegex requires Glib-2.14.0 PKG_CHECK_MODULES(ALL, glib-2.0 >= 2.14.0) -# gtk_window_set_icon_name requires gtk2+-2.6.0 -PKG_CHECK_MODULES(MUTTER_MESSAGE, gtk+-3.0) -PKG_CHECK_MODULES(MUTTER_WINDOW_DEMO, gtk+-3.0) # Unconditionally use this dir to avoid a circular dep with gnomecc GNOME_KEYBINDINGS_KEYSDIR="${datadir}/gnome-control-center/keybindings" @@ -307,9 +304,6 @@ if test "x$found_xsync" = "xyes"; then fi MUTTER_LIBS="$MUTTER_LIBS $XSYNC_LIBS $RANDR_LIBS $SHAPE_LIBS $X_LIBS $X_PRE_LIBS -lX11 $X_EXTRA_LIBS -lm" -MUTTER_MESSAGE_LIBS="$MUTTER_MESSAGE_LIBS $X_LIBS $X_PRE_LIBS -lX11 $X_EXTRA_LIBS" -MUTTER_WINDOW_DEMO_LIBS="$MUTTER_WINDOW_DEMO_LIBS $X_LIBS $X_PRE_LIBS -lX11 $X_EXTRA_LIBS -lm" -MUTTER_PROPS_LIBS="$MUTTER_PROPS_LIBS $X_LIBS $X_PRE_LIBS -lX11 $X_EXTRA_LIBS" found_sm=no case "$MUTTER_LIBS" in @@ -439,10 +433,8 @@ doc/man/Makefile doc/reference/Makefile doc/reference/meta-docs.sgml src/Makefile -src/wm-tester/Makefile src/libmutter.pc src/mutter-plugins.pc -src/tools/Makefile src/compositor/plugins/Makefile po/Makefile.in ]) diff --git a/src/Makefile.am b/src/Makefile.am index 22cce625a..c936a7290 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -3,7 +3,7 @@ lib_LTLIBRARIES = libmutter.la -SUBDIRS=wm-tester tools compositor/plugins +SUBDIRS=compositor/plugins INCLUDES= \ -DCLUTTER_ENABLE_EXPERIMENTAL_API \ @@ -156,8 +156,6 @@ libmutter_la_SOURCES = \ meta/theme.h \ ui/theme-private.h \ ui/ui.c \ - meta/preview-widget.h \ - ui/preview-widget.c \ $(mutter_built_sources) libmutter_la_LDFLAGS = -no-undefined @@ -195,7 +193,6 @@ libmutterinclude_base_headers = \ # Excluded from scanning for introspection but installed # atomnames.h: macros cause problems for scanning process libmutterinclude_extra_headers = \ - meta/preview-widget.h \ meta/atomnames.h libmutterincludedir = $(includedir)/mutter/meta @@ -204,11 +201,6 @@ libmutterinclude_HEADERS = \ $(libmutterinclude_base_headers) \ $(libmutterinclude_extra_headers) -mutter_theme_viewer_SOURCES= \ - ui/theme-viewer.c - -bin_PROGRAMS=mutter mutter-theme-viewer - mutter_SOURCES = core/mutter.c mutter_LDADD = $(MUTTER_LIBS) libmutter.la @@ -245,8 +237,6 @@ Meta-$(api_version).gir: libmutter.la endif -mutter_theme_viewer_LDADD= $(MUTTER_LIBS) libmutter.la - testboxes_SOURCES = core/testboxes.c testgradient_SOURCES = ui/testgradient.c testasyncgetprop_SOURCES = core/testasyncgetprop.c diff --git a/src/core/display.c b/src/core/display.c index 9d5a87cb0..e39361e83 100644 --- a/src/core/display.c +++ b/src/core/display.c @@ -3043,27 +3043,6 @@ event_callback (XEvent *event, } } else if (event->xclient.message_type == - display->atom__MUTTER_RELOAD_THEME_MESSAGE) - { - meta_verbose ("Received reload theme request\n"); - meta_ui_set_current_theme (meta_prefs_get_theme (), - TRUE); - meta_display_retheme_all (); - } - else if (event->xclient.message_type == - display->atom__MUTTER_SET_KEYBINDINGS_MESSAGE) - { - meta_verbose ("Received set keybindings request = %d\n", - (int) event->xclient.data.l[0]); - meta_set_keybindings_disabled (!event->xclient.data.l[0]); - } - else if (event->xclient.message_type == - display->atom__MUTTER_TOGGLE_VERBOSE) - { - meta_verbose ("Received toggle verbose message\n"); - meta_set_verbose (!meta_is_verbose ()); - } - else if (event->xclient.message_type == display->atom_WM_PROTOCOLS) { meta_verbose ("Received WM_PROTOCOLS message\n"); diff --git a/src/core/keybindings-private.h b/src/core/keybindings-private.h index c8a12b1ef..c47aacdc4 100644 --- a/src/core/keybindings-private.h +++ b/src/core/keybindings-private.h @@ -69,7 +69,6 @@ void meta_window_ungrab_all_keys (MetaWindow *window, gboolean meta_display_process_key_event (MetaDisplay *display, MetaWindow *window, XIDeviceEvent *event); -void meta_set_keybindings_disabled (gboolean setting); void meta_display_process_mapping_event (MetaDisplay *display, XEvent *event); diff --git a/src/core/keybindings.c b/src/core/keybindings.c index 135dac5ad..8439ea830 100644 --- a/src/core/keybindings.c +++ b/src/core/keybindings.c @@ -56,8 +56,6 @@ #define SCHEMA_COMMON_KEYBINDINGS "org.gnome.desktop.wm.keybindings" #define SCHEMA_MUTTER_KEYBINDINGS "org.gnome.mutter.keybindings" -static gboolean all_bindings_disabled = FALSE; - static gboolean add_builtin_keybinding (MetaDisplay *display, const char *name, GSettings *settings, @@ -2046,21 +2044,6 @@ meta_display_process_key_event (MetaDisplay *display, const char *str; MetaScreen *screen; - if (all_bindings_disabled) - { - /* In this mode, we try to pretend we don't have grabs, so we - * immediately replay events and drop the grab. (This still - * messes up global passive grabs from other clients.) The - * FALSE return here is a little suspect, but we don't really - * know if we'll see the event again or not, and it's pretty - * poorly defined how this mode is supposed to interact with - * plugins. - */ - XIAllowEvents (display->xdisplay, event->deviceid, - XIReplayDevice, event->time); - return FALSE; - } - /* if key event was on root window, we have a shortcut */ screen = meta_display_screen_for_root (display, event->event); @@ -4098,14 +4081,6 @@ handle_set_spew_mark (MetaDisplay *display, meta_verbose ("-- MARK MARK MARK MARK --\n"); } -void -meta_set_keybindings_disabled (gboolean setting) -{ - all_bindings_disabled = setting; - meta_topic (META_DEBUG_KEYBINDINGS, - "Keybindings %s\n", all_bindings_disabled ? "disabled" : "enabled"); -} - /** * meta_keybindings_set_custom_handler: * @name: The name of the keybinding to set diff --git a/src/core/main.c b/src/core/main.c index 4bec3d260..767a8b843 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -514,14 +514,14 @@ meta_run (void) if (g_getenv ("MUTTER_G_FATAL_WARNINGS") != NULL) g_log_set_always_fatal (G_LOG_LEVEL_MASK); - meta_ui_set_current_theme (meta_prefs_get_theme (), FALSE); + meta_ui_set_current_theme (meta_prefs_get_theme ()); /* Try to find some theme that'll work if the theme preference * doesn't exist. First try Simple (the default theme) then just * try anything in the themes directory. */ if (!meta_ui_have_a_theme ()) - meta_ui_set_current_theme ("Simple", FALSE); + meta_ui_set_current_theme ("Simple"); if (!meta_ui_have_a_theme ()) { @@ -539,7 +539,7 @@ meta_run (void) while (((dir_entry = g_dir_read_name (themes_dir)) != NULL) && (!meta_ui_have_a_theme ())) { - meta_ui_set_current_theme (dir_entry, FALSE); + meta_ui_set_current_theme (dir_entry); } g_dir_close (themes_dir); @@ -598,7 +598,7 @@ prefs_changed_callback (MetaPreference pref, { case META_PREF_THEME: case META_PREF_DRAGGABLE_BORDER_WIDTH: - meta_ui_set_current_theme (meta_prefs_get_theme (), FALSE); + meta_ui_set_current_theme (meta_prefs_get_theme ()); meta_display_retheme_all (); break; diff --git a/src/meta/atomnames.h b/src/meta/atomnames.h index 122315153..2a62873be 100644 --- a/src/meta/atomnames.h +++ b/src/meta/atomnames.h @@ -54,9 +54,6 @@ item(WM_WINDOW_ROLE) item(UTF8_STRING) item(WM_ICON_SIZE) item(_KWM_WIN_ICON) -item(_MUTTER_RELOAD_THEME_MESSAGE) -item(_MUTTER_SET_KEYBINDINGS_MESSAGE) -item(_MUTTER_TOGGLE_VERBOSE) item(_MUTTER_HINTS) item(_GTK_THEME_VARIANT) item(_GTK_HIDE_TITLEBAR_WHEN_MAXIMIZED) diff --git a/src/meta/preview-widget.h b/src/meta/preview-widget.h deleted file mode 100644 index 2a7919485..000000000 --- a/src/meta/preview-widget.h +++ /dev/null @@ -1,87 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ - -/* Metacity theme preview widget */ - -/* - * Copyright (C) 2002 Havoc Pennington - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#include <config.h> - -#include <meta/common.h> -#include <meta/theme.h> -#include <gtk/gtk.h> - -#ifndef META_PREVIEW_WIDGET_H -#define META_PREVIEW_WIDGET_H - -#define META_TYPE_PREVIEW (meta_preview_get_type ()) -#define META_PREVIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), META_TYPE_PREVIEW, MetaPreview)) -#define META_PREVIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), META_TYPE_PREVIEW, MetaPreviewClass)) -#define META_IS_PREVIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), META_TYPE_PREVIEW)) -#define META_IS_PREVIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), META_TYPE_PREVIEW)) -#define META_PREVIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), META_TYPE_PREVIEW, MetaPreviewClass)) - -typedef struct _MetaPreview MetaPreview; -typedef struct _MetaPreviewClass MetaPreviewClass; - -struct _MetaPreview -{ - GtkBin bin; - - GtkStyleContext *style_context; - - MetaTheme *theme; - char *title; - MetaFrameType type; - MetaFrameFlags flags; - - PangoLayout *layout; - int text_height; - - MetaFrameBorders borders; - guint borders_cached : 1; - - MetaButtonLayout button_layout; -}; - -struct _MetaPreviewClass -{ - /*< private >*/ - GtkBinClass parent_class; -}; - - -GType meta_preview_get_type (void) G_GNUC_CONST; -GtkWidget* meta_preview_new (void); - -void meta_preview_set_theme (MetaPreview *preview, - MetaTheme *theme); -void meta_preview_set_title (MetaPreview *preview, - const char *title); -void meta_preview_set_frame_type (MetaPreview *preview, - MetaFrameType type); -void meta_preview_set_frame_flags (MetaPreview *preview, - MetaFrameFlags flags); -void meta_preview_set_button_layout (MetaPreview *preview, - const MetaButtonLayout *button_layout); - -GdkPixbuf* meta_preview_get_icon (void); -GdkPixbuf* meta_preview_get_mini_icon (void); - -#endif diff --git a/src/meta/theme.h b/src/meta/theme.h index a6aa5d835..5ecb76c3f 100644 --- a/src/meta/theme.h +++ b/src/meta/theme.h @@ -33,8 +33,7 @@ typedef struct _MetaTheme MetaTheme; MetaTheme* meta_theme_get_current (void); -void meta_theme_set_current (const char *name, - gboolean force_reload); +void meta_theme_set_current (const char *name); MetaTheme* meta_theme_new (void); void meta_theme_free (MetaTheme *theme); diff --git a/src/tools/.cvsignore b/src/tools/.cvsignore deleted file mode 100644 index 8ecc6b5e3..000000000 --- a/src/tools/.cvsignore +++ /dev/null @@ -1,8 +0,0 @@ -Makefile -Makefile.in -metacity-grayscale -metacity-message -metacity-mag -metacity-properties -metacity-properties.desktop -metacity-window-demo diff --git a/src/tools/Makefile.am b/src/tools/Makefile.am deleted file mode 100644 index c9a47a7f0..000000000 --- a/src/tools/Makefile.am +++ /dev/null @@ -1,34 +0,0 @@ -@INTLTOOL_DESKTOP_RULE@ - -icondir=$(pkgdatadir)/icons -icon_DATA=mutter-window-demo.png - -INCLUDES=@MUTTER_WINDOW_DEMO_CFLAGS@ @MUTTER_MESSAGE_CFLAGS@ \ - -I$(top_srcdir)/src \ - -DMUTTER_ICON_DIR=\"$(pkgdatadir)/icons\" \ - -DMUTTER_LOCALEDIR=\"$(prefix)/@DATADIRNAME@/locale\" - -mutter_message_SOURCES= \ - mutter-message.c - -mutter_window_demo_SOURCES= \ - mutter-window-demo.c - -mutter_mag_SOURCES= \ - mutter-mag.c - -mutter_grayscale_SOURCES= \ - mutter-grayscale.c - -bin_PROGRAMS=mutter-message mutter-window-demo - -## cheesy hacks I use, don't really have any business existing. ;-) -noinst_PROGRAMS=mutter-mag mutter-grayscale - -mutter_message_LDADD= @MUTTER_MESSAGE_LIBS@ -mutter_window_demo_LDADD= @MUTTER_WINDOW_DEMO_LIBS@ -mutter_mag_LDADD= @MUTTER_WINDOW_DEMO_LIBS@ -mutter_grayscale_LDADD = @MUTTER_WINDOW_DEMO_LIBS@ - -EXTRA_DIST=$(icon_DATA) - diff --git a/src/tools/mutter-grayscale.c b/src/tools/mutter-grayscale.c deleted file mode 100644 index ce73f45b5..000000000 --- a/src/tools/mutter-grayscale.c +++ /dev/null @@ -1,107 +0,0 @@ -/* Hack for grayscaling an image */ - -/* - * Copyright (C) 2002 Red Hat Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#include <gdk-pixbuf/gdk-pixbuf.h> -#include <unistd.h> -#include <stdlib.h> -#include <math.h> - -#define INTENSITY(r, g, b) ((r) * 0.30 + (g) * 0.59 + (b) * 0.11) - -static GdkPixbuf* -grayscale_pixbuf (GdkPixbuf *pixbuf) -{ - GdkPixbuf *gray; - guchar *pixels; - int rowstride; - int pixstride; - int row; - int n_rows; - int width; - - gray = gdk_pixbuf_copy (pixbuf); - rowstride = gdk_pixbuf_get_rowstride (gray); - pixstride = gdk_pixbuf_get_has_alpha (gray) ? 4 : 3; - - pixels = gdk_pixbuf_get_pixels (gray); - n_rows = gdk_pixbuf_get_height (gray); - width = gdk_pixbuf_get_width (gray); - - row = 0; - while (row < n_rows) - { - guchar *p = pixels + row * rowstride; - guchar *end = p + (pixstride * width); - - while (p != end) - { - double v = INTENSITY (p[0], p[1], p[2]); - - p[0] = (guchar) v; - p[1] = (guchar) v; - p[2] = (guchar) v; - - p += pixstride; - } - - ++row; - } - - return gray; -} - -int -main (int argc, char **argv) -{ - GdkPixbuf *pixbuf; - GdkPixbuf *gray; - GError *err; - - if (argc != 2) - { - g_printerr ("specify a single image on the command line\n"); - return 1; - } - - err = NULL; - pixbuf = gdk_pixbuf_new_from_file (argv[1], &err); - if (err != NULL) - { - g_printerr ("failed to load image: %s\n", err->message); - g_error_free (err); - return 1; - } - - gray = grayscale_pixbuf (pixbuf); - - err = NULL; - gdk_pixbuf_save (gray, "grayscale.png", "png", &err, NULL); - if (err != NULL) - { - g_printerr ("failed to save image: %s\n", err->message); - g_error_free (err); - return 1; - } - - g_print ("wrote grayscale.png\n"); - - return 0; -} diff --git a/src/tools/mutter-mag.c b/src/tools/mutter-mag.c deleted file mode 100644 index b85fc5698..000000000 --- a/src/tools/mutter-mag.c +++ /dev/null @@ -1,299 +0,0 @@ -/* Hack for use instead of xmag */ - -/* - * Copyright (C) 2002 Red Hat Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#define _GNU_SOURCE -#define _XOPEN_SOURCE 600 /* C99 -- for rint() */ - -#include <gtk/gtk.h> -#include <gdk/gdkx.h> -#include <gdk/gdkkeysyms.h> -#include <unistd.h> -#include <stdlib.h> -#include <math.h> - -static GtkWidget *grab_widget = NULL; -static GtkWidget *display_window = NULL; -static int last_grab_x = 0; -static int last_grab_y = 0; -static int last_grab_width = 150; -static int last_grab_height = 150; -static GtkAllocation last_grab_allocation; -static double width_factor = 4.0; -static double height_factor = 4.0; -static GdkInterpType interp_mode = GDK_INTERP_NEAREST; -static guint regrab_idle_id = 0; - -static GdkPixbuf* -get_pixbuf (void) -{ - GdkPixbuf *screenshot; - GdkPixbuf *magnified; - -#if 0 - g_print ("Size %d x %d\n", - last_grab_width, last_grab_height); -#endif - - screenshot = gdk_pixbuf_get_from_window (gdk_get_default_root_window (), - last_grab_x, last_grab_y, - last_grab_width, last_grab_height); - - if (screenshot == NULL) - { - g_printerr ("Screenshot failed\n"); - exit (1); - } - - magnified = gdk_pixbuf_scale_simple (screenshot, last_grab_width * width_factor, - last_grab_height * height_factor, - interp_mode); - - - g_object_unref (G_OBJECT (screenshot)); - - return magnified; -} - -static gboolean -regrab_idle (GtkWidget *image) -{ - GtkAllocation allocation; - GdkPixbuf *magnified; - - gtk_widget_get_allocation (image, &allocation); - - if (allocation.width != last_grab_allocation.width || - allocation.height != last_grab_allocation.height) - { - last_grab_width = rint (allocation.width / width_factor); - last_grab_height = rint (allocation.height / height_factor); - last_grab_allocation = allocation; - - magnified = get_pixbuf (); - - gtk_image_set_from_pixbuf (GTK_IMAGE (image), magnified); - - g_object_unref (G_OBJECT (magnified)); - } - - regrab_idle_id = 0; - - return FALSE; -} - -static void -image_resized (GtkWidget *image) -{ - if (regrab_idle_id == 0) - regrab_idle_id = g_idle_add_full (G_PRIORITY_LOW + 100, (GSourceFunc) regrab_idle, - image, NULL); -} - -static void -grab_area_at_mouse (GtkWidget *invisible, - int x_root, - int y_root) -{ - GdkPixbuf *magnified; - int width, height; - GtkWidget *widget; - - width = last_grab_width; - height = last_grab_height; - - last_grab_x = x_root; - last_grab_y = y_root; - last_grab_width = width; - last_grab_height = height; - - magnified = get_pixbuf (); - - display_window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_window_set_default_size (GTK_WINDOW (display_window), - last_grab_width, last_grab_height); - widget = gtk_image_new_from_pixbuf (magnified); - gtk_widget_set_size_request (widget, 40, 40); - gtk_container_add (GTK_CONTAINER (display_window), widget); - g_object_unref (G_OBJECT (magnified)); - - g_object_add_weak_pointer (G_OBJECT (display_window), - (gpointer) &display_window); - - g_signal_connect (G_OBJECT (display_window), "destroy", - G_CALLBACK (gtk_main_quit), NULL); - - g_signal_connect_after (G_OBJECT (widget), "size_allocate", G_CALLBACK (image_resized), NULL); - - gtk_widget_show_all (display_window); -} - -static void -shutdown_grab (void) -{ - GdkDeviceManager *manager; - GdkDevice *device; - - manager = gdk_display_get_device_manager (gdk_display_get_default ()); - device = gdk_device_manager_get_client_pointer (manager); - - gdk_device_ungrab (device, gtk_get_current_event_time ()); - gdk_device_ungrab (gdk_device_get_associated_device (device), - gtk_get_current_event_time ()); - gtk_grab_remove (grab_widget); -} - -static void -mouse_motion (GtkWidget *invisible, - GdkEventMotion *event, - gpointer data) -{ - -} - -static gboolean -mouse_release (GtkWidget *invisible, - GdkEventButton *event, - gpointer data) -{ - if (event->button != 1) - return FALSE; - - grab_area_at_mouse (invisible, event->x_root, event->y_root); - - shutdown_grab (); - - g_signal_handlers_disconnect_by_func (invisible, mouse_motion, NULL); - g_signal_handlers_disconnect_by_func (invisible, mouse_release, NULL); - - return TRUE; -} - -/* Helper Functions */ - -static gboolean mouse_press (GtkWidget *invisible, - GdkEventButton *event, - gpointer data); - -static gboolean -key_press (GtkWidget *invisible, - GdkEventKey *event, - gpointer data) -{ - if (event->keyval == GDK_KEY_Escape) - { - shutdown_grab (); - - g_signal_handlers_disconnect_by_func (invisible, mouse_press, NULL); - g_signal_handlers_disconnect_by_func (invisible, key_press, NULL); - - gtk_main_quit (); - - return TRUE; - } - - return FALSE; -} - -static gboolean -mouse_press (GtkWidget *invisible, - GdkEventButton *event, - gpointer data) -{ - if (event->type == GDK_BUTTON_PRESS && - event->button == 1) - { - g_signal_connect (invisible, "motion_notify_event", - G_CALLBACK (mouse_motion), NULL); - g_signal_connect (invisible, "button_release_event", - G_CALLBACK (mouse_release), NULL); - g_signal_handlers_disconnect_by_func (invisible, mouse_press, NULL); - g_signal_handlers_disconnect_by_func (invisible, key_press, NULL); - return TRUE; - } - - return FALSE; -} - -static void -begin_area_grab (void) -{ - GdkWindow *window; - GdkDeviceManager *manager; - GdkDevice *device; - - if (grab_widget == NULL) - { - grab_widget = gtk_invisible_new (); - - gtk_widget_add_events (grab_widget, - GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK); - - gtk_widget_show (grab_widget); - } - - window = gtk_widget_get_window (grab_widget); - manager = gdk_display_get_device_manager (gdk_display_get_default ()); - device = gdk_device_manager_get_client_pointer (manager); - - if (gdk_device_grab (device, - window, - GDK_OWNERSHIP_NONE, - FALSE, - GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK, - NULL, - gtk_get_current_event_time ()) != GDK_GRAB_SUCCESS) - { - g_warning ("Failed to grab pointer to do eyedropper"); - return; - } - - if (gdk_device_grab (gdk_device_get_associated_device (device), - window, - GDK_OWNERSHIP_NONE, - FALSE, - GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK, - NULL, - gtk_get_current_event_time ()) != GDK_GRAB_SUCCESS) - { - gdk_device_ungrab (device, gtk_get_current_event_time ()); - g_warning ("Failed to grab keyboard to do eyedropper"); - return; - } - - gtk_grab_add (grab_widget); - - g_signal_connect (grab_widget, "button_press_event", - G_CALLBACK (mouse_press), NULL); - g_signal_connect (grab_widget, "key_press_event", - G_CALLBACK (key_press), NULL); -} - -int -main (int argc, char **argv) -{ - gtk_init (&argc, &argv); - - begin_area_grab (); - - gtk_main (); - - return 0; -} diff --git a/src/tools/mutter-message.c b/src/tools/mutter-message.c deleted file mode 100644 index 5b93597bc..000000000 --- a/src/tools/mutter-message.c +++ /dev/null @@ -1,160 +0,0 @@ -/* Mutter send-magic-messages app */ - -/* - * Copyright (C) 2002 Havoc Pennington - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#include <config.h> -#include <gtk/gtk.h> -#include <gdk/gdkx.h> -#include <stdlib.h> -#include <string.h> - -#include <libintl.h> -#define _(x) dgettext (GETTEXT_PACKAGE, x) -#define N_(x) x - -static Display *display; - -static void -send_reload_theme (void) -{ - XEvent xev; - - xev.xclient.type = ClientMessage; - xev.xclient.serial = 0; - xev.xclient.send_event = True; - xev.xclient.display = display; - xev.xclient.window = gdk_x11_get_default_root_xwindow (); - xev.xclient.message_type = XInternAtom (display, - "_MUTTER_RELOAD_THEME_MESSAGE", - False); - xev.xclient.format = 32; - xev.xclient.data.l[0] = 0; - xev.xclient.data.l[1] = 0; - xev.xclient.data.l[2] = 0; - - XSendEvent (display, - gdk_x11_get_default_root_xwindow (), - False, - SubstructureRedirectMask | SubstructureNotifyMask, - &xev); - - XFlush (display); - XSync (display, False); -} - -static void -send_set_keybindings (gboolean enabled) -{ - XEvent xev; - - xev.xclient.type = ClientMessage; - xev.xclient.serial = 0; - xev.xclient.send_event = True; - xev.xclient.display = display; - xev.xclient.window = gdk_x11_get_default_root_xwindow (); - xev.xclient.message_type = XInternAtom (display, - "_MUTTER_SET_KEYBINDINGS_MESSAGE", - False); - xev.xclient.format = 32; - xev.xclient.data.l[0] = enabled; - xev.xclient.data.l[1] = 0; - xev.xclient.data.l[2] = 0; - - XSendEvent (display, - gdk_x11_get_default_root_xwindow (), - False, - SubstructureRedirectMask | SubstructureNotifyMask, - &xev); - - XFlush (display); - XSync (display, False); -} - -#ifdef WITH_VERBOSE_MODE -static void -send_toggle_verbose (void) -{ - XEvent xev; - - xev.xclient.type = ClientMessage; - xev.xclient.serial = 0; - xev.xclient.send_event = True; - xev.xclient.display = display; - xev.xclient.window = gdk_x11_get_default_root_xwindow (); - xev.xclient.message_type = XInternAtom (display, - "_MUTTER_TOGGLE_VERBOSE", - False); - xev.xclient.format = 32; - xev.xclient.data.l[0] = 0; - xev.xclient.data.l[1] = 0; - xev.xclient.data.l[2] = 0; - - XSendEvent (display, - gdk_x11_get_default_root_xwindow (), - False, - SubstructureRedirectMask | SubstructureNotifyMask, - &xev); - - XFlush (display); - XSync (display, False); -} -#endif - -static void -usage (void) -{ - g_printerr (_("Usage: %s\n"), - "mutter-message (reload-theme|enable-keybindings|disable-keybindings|toggle-verbose)"); - exit (1); -} - -int -main (int argc, char **argv) -{ - bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); - - gtk_init (&argc, &argv); - - if (argc < 2) - usage (); - - display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); - - if (strcmp (argv[1], "reload-theme") == 0) - send_reload_theme (); - else if (strcmp (argv[1], "enable-keybindings") == 0) - send_set_keybindings (TRUE); - else if (strcmp (argv[1], "disable-keybindings") == 0) - send_set_keybindings (FALSE); - else if (strcmp (argv[1], "toggle-verbose") == 0) - { -#ifndef WITH_VERBOSE_MODE - g_printerr (_("Mutter was compiled without support for verbose mode\n")); - return 1; -#else - send_toggle_verbose (); -#endif - } - else - usage (); - - return 0; -} - diff --git a/src/tools/mutter-window-demo.c b/src/tools/mutter-window-demo.c deleted file mode 100644 index 2a3247724..000000000 --- a/src/tools/mutter-window-demo.c +++ /dev/null @@ -1,1049 +0,0 @@ -/* Mutter window types/properties demo app */ - -/* - * Copyright (C) 2002 Havoc Pennington - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#include <gtk/gtk.h> -#include <gdk/gdkx.h> -#include <X11/Xatom.h> -#include <unistd.h> - -static GtkWidget* do_appwindow (void); - -static gboolean aspect_on; - -static void -set_gdk_window_struts (GdkWindow *window, - int left, - int right, - int top, - int bottom) -{ - long vals[12]; - - vals[0] = left; - vals[1] = right; - vals[2] = top; - vals[3] = bottom; - vals[4] = 000; - vals[5] = 400; - vals[6] = 200; - vals[7] = 600; - vals[8] = 76; - vals[9] = 676; - vals[10] = 200; - vals[11] = 800; - - XChangeProperty (GDK_WINDOW_XDISPLAY (window), - GDK_WINDOW_XID (window), - XInternAtom (GDK_WINDOW_XDISPLAY (window), - "_NET_WM_STRUT_PARTIAL", False), - XA_CARDINAL, 32, PropModeReplace, - (guchar *)vals, 12); -} - -static void -on_realize_set_struts (GtkWindow *window, - gpointer data) -{ - GtkWidget *widget; - int left; - int right; - int top; - int bottom; - - widget = GTK_WIDGET (window); - - g_return_if_fail (gtk_widget_get_realized (widget)); - - left = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (window), "meta-strut-left")); - right = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (window), "meta-strut-right")); - top = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (window), "meta-strut-top")); - bottom = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (window), "meta-strut-bottom")); - - set_gdk_window_struts (gtk_widget_get_window (widget), - left, right, top, bottom); -} - -static void -set_gtk_window_struts (GtkWidget *window, - int left, - int right, - int top, - int bottom) -{ - GtkWidget *widget; - - widget = GTK_WIDGET (window); - - g_object_set_data (G_OBJECT (window), "meta-strut-left", - GINT_TO_POINTER (left)); - g_object_set_data (G_OBJECT (window), "meta-strut-right", - GINT_TO_POINTER (right)); - g_object_set_data (G_OBJECT (window), "meta-strut-top", - GINT_TO_POINTER (top)); - g_object_set_data (G_OBJECT (window), "meta-strut-bottom", - GINT_TO_POINTER (bottom)); - - g_signal_handlers_disconnect_by_func (G_OBJECT (window), - on_realize_set_struts, - NULL); - - g_signal_connect_after (G_OBJECT (window), - "realize", - G_CALLBACK (on_realize_set_struts), - NULL); - - if (gtk_widget_get_realized (widget)) - set_gdk_window_struts (gtk_widget_get_window (widget), - left, right, top, bottom); -} - -static void -set_gdk_window_type (GdkWindow *window, - const char *type) -{ - Atom atoms[2] = { None, None }; - - atoms[0] = XInternAtom (GDK_WINDOW_XDISPLAY (window), - type, False); - - XChangeProperty (GDK_WINDOW_XDISPLAY (window), - GDK_WINDOW_XID (window), - XInternAtom (GDK_WINDOW_XDISPLAY (window), "_NET_WM_WINDOW_TYPE", False), - XA_ATOM, 32, PropModeReplace, - (guchar *)atoms, - 1); -} - -static void -on_realize_set_type (GtkWindow *window, - gpointer data) -{ - GtkWidget *widget; - const char *type; - - widget = GTK_WIDGET (window); - - g_return_if_fail (gtk_widget_get_realized (widget)); - - type = g_object_get_data (G_OBJECT (window), "meta-window-type"); - - g_return_if_fail (type != NULL); - - set_gdk_window_type (gtk_widget_get_window (widget), - type); -} - -static void -set_gtk_window_type (GtkWindow *window, - const char *type) -{ - GtkWidget *widget; - - widget = GTK_WIDGET (window); - - g_object_set_data (G_OBJECT (window), "meta-window-type", (char*) type); - - g_signal_handlers_disconnect_by_func (G_OBJECT (window), - on_realize_set_type, - NULL); - - g_signal_connect_after (G_OBJECT (window), - "realize", - G_CALLBACK (on_realize_set_type), - NULL); - - if (gtk_widget_get_realized (widget)) - set_gdk_window_type (gtk_widget_get_window (widget), - type); -} - -static void -set_gdk_window_border_only (GdkWindow *window) -{ - gdk_window_set_decorations (window, GDK_DECOR_BORDER); -} - -static void -on_realize_set_border_only (GtkWindow *window, - gpointer data) -{ - GtkWidget *widget; - - widget = GTK_WIDGET (window); - - g_return_if_fail (gtk_widget_get_realized (widget)); - - set_gdk_window_border_only (gtk_widget_get_window (widget)); -} - -static void -set_gtk_window_border_only (GtkWindow *window) -{ - GtkWidget *widget; - - widget = GTK_WIDGET (window); - - g_signal_handlers_disconnect_by_func (G_OBJECT (window), - on_realize_set_border_only, - NULL); - - g_signal_connect_after (G_OBJECT (window), - "realize", - G_CALLBACK (on_realize_set_border_only), - NULL); - - if (gtk_widget_get_realized (widget)) - set_gdk_window_border_only (gtk_widget_get_window (widget)); -} - -int -main (int argc, char **argv) -{ - GList *list; - GdkPixbuf *pixbuf; - GError *err; - - gtk_init (&argc, &argv); - - err = NULL; - pixbuf = gdk_pixbuf_new_from_file (MUTTER_ICON_DIR"/mutter-window-demo.png", - &err); - if (pixbuf) - { - list = g_list_prepend (NULL, pixbuf); - - gtk_window_set_default_icon_list (list); - g_list_free (list); - g_object_unref (G_OBJECT (pixbuf)); - } - else - { - g_printerr ("Could not load icon: %s\n", err->message); - g_error_free (err); - } - - do_appwindow (); - - gtk_main (); - - return 0; -} - -static void -response_cb (GtkDialog *dialog, - int response_id, - void *data); - -static void -make_dialog (GtkWidget *parent, - int depth) -{ - GtkWidget *dialog; - char *str; - - dialog = gtk_message_dialog_new (parent ? GTK_WINDOW (parent) : NULL, - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_INFO, - GTK_BUTTONS_CLOSE, - parent ? "Here is a dialog %d" : - "Here is a dialog %d with no transient parent", - depth); - - str = g_strdup_printf ("%d dialog", depth); - gtk_window_set_title (GTK_WINDOW (dialog), str); - g_free (str); - - gtk_dialog_add_button (GTK_DIALOG (dialog), - "Open child dialog", - GTK_RESPONSE_ACCEPT); - - /* Close dialog on user response */ - g_signal_connect (G_OBJECT (dialog), - "response", - G_CALLBACK (response_cb), - NULL); - - g_object_set_data (G_OBJECT (dialog), "depth", - GINT_TO_POINTER (depth)); - - gtk_widget_show (dialog); -} - -static void -response_cb (GtkDialog *dialog, - int response_id, - void *data) -{ - switch (response_id) - { - case GTK_RESPONSE_ACCEPT: - make_dialog (GTK_WIDGET (dialog), - GPOINTER_TO_INT (g_object_get_data (G_OBJECT (dialog), - "depth")) + 1); - break; - - default: - gtk_widget_destroy (GTK_WIDGET (dialog)); - break; - } -} - -static void -dialog_cb (GtkAction *action, - gpointer callback_data) -{ - make_dialog (GTK_WIDGET (callback_data), 1); -} - -static void -modal_dialog_cb (GtkAction *action, - gpointer callback_data) -{ - GtkWidget *dialog; - - dialog = gtk_message_dialog_new (GTK_WINDOW (callback_data), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_INFO, - GTK_BUTTONS_CLOSE, - "Here is a MODAL dialog"); - - set_gtk_window_type (GTK_WINDOW (dialog), "_NET_WM_WINDOW_TYPE_MODAL_DIALOG"); - - gtk_dialog_run (GTK_DIALOG (dialog)); - - gtk_widget_destroy (dialog); -} - -static void -no_parent_dialog_cb (GtkAction *action, - gpointer callback_data) -{ - make_dialog (NULL, 1); -} - -static void -utility_cb (GtkAction *action, - gpointer callback_data) -{ - GtkWidget *window; - GtkWidget *vbox; - GtkWidget *button; - - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - set_gtk_window_type (GTK_WINDOW (window), "_NET_WM_WINDOW_TYPE_UTILITY"); - gtk_window_set_title (GTK_WINDOW (window), "Utility"); - - gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (callback_data)); - - vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); - - gtk_container_add (GTK_CONTAINER (window), vbox); - - button = gtk_button_new_with_mnemonic ("_A button"); - gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); - - button = gtk_button_new_with_mnemonic ("_B button"); - gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); - - button = gtk_button_new_with_mnemonic ("_C button"); - gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); - - button = gtk_button_new_with_mnemonic ("_D button"); - gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); - - gtk_widget_show_all (window); -} - -static void -toolbar_cb (GtkAction *action, - gpointer callback_data) -{ - GtkWidget *window; - GtkWidget *vbox; - GtkWidget *label; - - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - set_gtk_window_type (GTK_WINDOW (window), "_NET_WM_WINDOW_TYPE_TOOLBAR"); - gtk_window_set_title (GTK_WINDOW (window), "Toolbar"); - - gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (callback_data)); - - vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); - - gtk_container_add (GTK_CONTAINER (window), vbox); - - label = gtk_label_new ("FIXME this needs a resize grip, etc."); - gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); - - gtk_widget_show_all (window); -} - -static void -menu_cb (GtkAction *action, - gpointer callback_data) -{ - GtkWidget *window; - GtkWidget *vbox; - GtkWidget *label; - - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - set_gtk_window_type (GTK_WINDOW (window), "_NET_WM_WINDOW_TYPE_MENU"); - gtk_window_set_title (GTK_WINDOW (window), "Menu"); - - gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (callback_data)); - - vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); - - gtk_container_add (GTK_CONTAINER (window), vbox); - - label = gtk_label_new ("FIXME this isn't a menu."); - gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); - - gtk_widget_show_all (window); -} - -static void -override_redirect_cb (GtkAction *action, - gpointer callback_data) -{ - GtkWidget *window; - GtkWidget *vbox; - GtkWidget *label; - - window = gtk_window_new (GTK_WINDOW_POPUP); - gtk_window_set_title (GTK_WINDOW (window), "Override Redirect"); - - vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); - - gtk_container_add (GTK_CONTAINER (window), vbox); - - label = gtk_label_new ("This is an override\nredirect window\nand should not be managed"); - gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); - - gtk_widget_show_all (window); -} - -static void -border_only_cb (GtkAction *action, - gpointer callback_data) -{ - GtkWidget *window; - GtkWidget *vbox; - GtkWidget *label; - - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - set_gtk_window_border_only (GTK_WINDOW (window)); - gtk_window_set_title (GTK_WINDOW (window), "Border only"); - - gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (callback_data)); - - vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); - - gtk_container_add (GTK_CONTAINER (window), vbox); - - label = gtk_label_new ("This window is supposed to have a border but no titlebar."); - gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); - - gtk_widget_show_all (window); -} - -#if 0 -static void -changing_icon_cb (GtkAction *action, - gpointer callback_data) -{ - GtkWidget *window; - GtkWidget *vbox; - GtkWidget *label; - - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_window_set_title (GTK_WINDOW (window), "Changing Icon"); - - vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); - - gtk_container_add (GTK_CONTAINER (window), vbox); - - label = gtk_label_new ("This window has an icon that changes over time"); - gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); - - gtk_widget_show_all (window); -} -#endif - -static gboolean -focus_in_event_cb (GtkWidget *window, - GdkEvent *event, - gpointer data) -{ - GtkWidget *widget; - - widget = GTK_WIDGET (data); - - gtk_label_set_text (GTK_LABEL (widget), "Has focus"); - - return TRUE; -} - - -static gboolean -focus_out_event_cb (GtkWidget *window, - GdkEvent *event, - gpointer data) -{ - GtkWidget *widget; - - widget = GTK_WIDGET (data); - - gtk_label_set_text (GTK_LABEL (widget), "Not focused"); - - return TRUE; -} - -static GtkWidget* -focus_label (GtkWidget *window) -{ - GtkWidget *label; - - label = gtk_label_new ("Not focused"); - - g_signal_connect (G_OBJECT (window), "focus_in_event", - G_CALLBACK (focus_in_event_cb), label); - - g_signal_connect (G_OBJECT (window), "focus_out_event", - G_CALLBACK (focus_out_event_cb), label); - - return label; -} - -static void -splashscreen_cb (GtkAction *action, - gpointer callback_data) -{ - GtkWidget *window; - GtkWidget *image; - GtkWidget *vbox; - - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - set_gtk_window_type (GTK_WINDOW (window), "_NET_WM_WINDOW_TYPE_SPLASHSCREEN"); - gtk_window_set_title (GTK_WINDOW (window), "Splashscreen"); - - vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); - - image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_INFO, GTK_ICON_SIZE_DIALOG); - gtk_box_pack_start (GTK_BOX (vbox), image, FALSE, FALSE, 0); - - gtk_box_pack_start (GTK_BOX (vbox), focus_label (window), FALSE, FALSE, 0); - - gtk_container_add (GTK_CONTAINER (window), vbox); - - gtk_widget_show_all (window); -} - -enum -{ - DOCK_TOP = 1, - DOCK_BOTTOM = 2, - DOCK_LEFT = 3, - DOCK_RIGHT = 4, - DOCK_ALL = 5 -}; - -static void -make_dock (int type) -{ - GtkWidget *window; - GtkWidget *image; - GtkWidget *box; - GtkWidget *button; - - g_return_if_fail (type != DOCK_ALL); - - box = NULL; - switch (type) - { - case DOCK_LEFT: - case DOCK_RIGHT: - box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); - break; - case DOCK_TOP: - case DOCK_BOTTOM: - box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); - break; - case DOCK_ALL: - break; - } - - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - set_gtk_window_type (GTK_WINDOW (window), "_NET_WM_WINDOW_TYPE_DOCK"); - - image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_INFO, GTK_ICON_SIZE_DIALOG); - gtk_box_pack_start (GTK_BOX (box), image, FALSE, FALSE, 0); - - gtk_box_pack_start (GTK_BOX (box), focus_label (window), FALSE, FALSE, 0); - - button = gtk_button_new_with_label ("Close"); - gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0); - - g_signal_connect_swapped (G_OBJECT (button), "clicked", - G_CALLBACK (gtk_widget_destroy), window); - - gtk_container_add (GTK_CONTAINER (window), box); - -#define DOCK_SIZE 48 - switch (type) - { - case DOCK_LEFT: - gtk_widget_set_size_request (window, DOCK_SIZE, 400); - gtk_window_move (GTK_WINDOW (window), 0, 000); - set_gtk_window_struts (window, DOCK_SIZE, 0, 0, 0); - gtk_window_set_title (GTK_WINDOW (window), "LeftDock"); - break; - case DOCK_RIGHT: - gtk_widget_set_size_request (window, DOCK_SIZE, 400); - gtk_window_move (GTK_WINDOW (window), gdk_screen_width () - DOCK_SIZE, 200); - set_gtk_window_struts (window, 0, DOCK_SIZE, 0, 0); - gtk_window_set_title (GTK_WINDOW (window), "RightDock"); - break; - case DOCK_TOP: - gtk_widget_set_size_request (window, 600, DOCK_SIZE); - gtk_window_move (GTK_WINDOW (window), 76, 0); - set_gtk_window_struts (window, 0, 0, DOCK_SIZE, 0); - gtk_window_set_title (GTK_WINDOW (window), "TopDock"); - break; - case DOCK_BOTTOM: - gtk_widget_set_size_request (window, 600, DOCK_SIZE); - gtk_window_move (GTK_WINDOW (window), 200, gdk_screen_height () - DOCK_SIZE); - set_gtk_window_struts (window, 0, 0, 0, DOCK_SIZE); - gtk_window_set_title (GTK_WINDOW (window), "BottomDock"); - break; - case DOCK_ALL: - break; - } - - gtk_widget_show_all (window); -} - -static void -dock_cb (GtkAction *action, - gpointer callback_data) -{ - guint callback_action; - const gchar *name; - - name = gtk_action_get_name (action); - - if (!g_strcmp0 (name, "Top dock")) - callback_action = DOCK_TOP; - else if (!g_strcmp0 (name, "Bottom dock")) - callback_action = DOCK_BOTTOM; - else if (!g_strcmp0 (name, "Left dock")) - callback_action = DOCK_LEFT; - else if (!g_strcmp0 (name, "Right dock")) - callback_action = DOCK_RIGHT; - else if (!g_strcmp0 (name, "All docks")) - callback_action = DOCK_ALL; - else - return; - - if (callback_action == DOCK_ALL) - { - make_dock (DOCK_TOP); - make_dock (DOCK_BOTTOM); - make_dock (DOCK_LEFT); - make_dock (DOCK_RIGHT); - } - else - { - make_dock (callback_action); - } -} - -static void -desktop_cb (GtkAction *action, - gpointer callback_data) -{ - GtkWidget *window; - GtkWidget *label; - GdkRGBA desktop_color; - - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - set_gtk_window_type (GTK_WINDOW (window), "_NET_WM_WINDOW_TYPE_DESKTOP"); - gtk_window_set_title (GTK_WINDOW (window), "Desktop"); - gtk_widget_set_size_request (window, - gdk_screen_width (), gdk_screen_height ()); - gtk_window_move (GTK_WINDOW (window), 0, 0); - - desktop_color.red = 0.32; - desktop_color.green = 0.46; - desktop_color.blue = 0.65; - desktop_color.alpha = 1.0; - - gtk_widget_override_background_color (window, 0, &desktop_color); - - label = focus_label (window); - - gtk_container_add (GTK_CONTAINER (window), label); - - gtk_widget_show_all (window); -} - -static void -sleep_cb (GtkAction *action, - gpointer data) -{ - sleep (1000); -} - -static void -toggle_aspect_ratio (GtkAction *action, - gpointer data) -{ - GtkWidget *window; - GdkGeometry geom; - GtkWidget *widget = GTK_WIDGET (data); - - if (aspect_on) - { - geom.min_aspect = 0; - geom.max_aspect = 65535; - } - else - { - geom.min_aspect = 1.777778; - geom.max_aspect = 1.777778; - } - - aspect_on = !aspect_on; - - window = gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW); - if (window) - gtk_window_set_geometry_hints (GTK_WINDOW (window), - widget, - &geom, - GDK_HINT_ASPECT); - -} - -static void -toggle_decorated_cb (GtkWidget *button, - gpointer data) -{ - GtkWidget *window; - window = gtk_widget_get_ancestor (data, GTK_TYPE_WINDOW); - if (window) - gtk_window_set_decorated (GTK_WINDOW (window), - !gtk_window_get_decorated (GTK_WINDOW (window))); -} - -static void -clicked_toolbar_cb (GtkWidget *button, - gpointer data) -{ - GtkWidget *dialog; - - dialog = gtk_message_dialog_new (GTK_WINDOW (data), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_INFO, - GTK_BUTTONS_CLOSE, - "Clicking the toolbar buttons doesn't do anything"); - - /* Close dialog on user response */ - g_signal_connect (G_OBJECT (dialog), - "response", - G_CALLBACK (gtk_widget_destroy), - NULL); - - gtk_widget_show (dialog); -} - -static void -update_statusbar (GtkTextBuffer *buffer, - GtkStatusbar *statusbar) -{ - gchar *msg; - gint row, col; - gint count; - GtkTextIter iter; - - gtk_statusbar_pop (statusbar, 0); /* clear any previous message, underflow is allowed */ - - count = gtk_text_buffer_get_char_count (buffer); - - gtk_text_buffer_get_iter_at_mark (buffer, - &iter, - gtk_text_buffer_get_insert (buffer)); - - row = gtk_text_iter_get_line (&iter); - col = gtk_text_iter_get_line_offset (&iter); - - msg = g_strdup_printf ("Cursor at row %d column %d - %d chars in document", - row, col, count); - - gtk_statusbar_push (statusbar, 0, msg); - - g_free (msg); -} - -static void -mark_set_callback (GtkTextBuffer *buffer, - const GtkTextIter *new_location, - GtkTextMark *mark, - gpointer data) -{ - update_statusbar (buffer, GTK_STATUSBAR (data)); -} - -static int window_count = 0; - -static void -destroy_cb (GtkWidget *w, gpointer data) -{ - --window_count; - if (window_count == 0) - gtk_main_quit (); -} - -static const gchar *menu_item_string = - "<ui>\n" - "<menubar>\n" - "<menu name='Windows' action='Windows'>\n" - "<menuitem name='Dialog' action='Dialog'/>\n" - "<menuitem name='Modal dialog' action='Modal dialog'/>\n" - "<menuitem name='Parentless dialog' action='Parentless dialog'/>\n" - "<menuitem name='Utility' action='Utility'/>\n" - "<menuitem name='Splashscreen' action='Splashscreen'/>\n" - "<menuitem name='Top dock' action='Top dock'/>\n" - "<menuitem name='Bottom dock' action='Bottom dock'/>\n" - "<menuitem name='Left dock' action='Left dock'/>\n" - "<menuitem name='Right dock' action='Right dock'/>\n" - "<menuitem name='All docks' action='All docks'/>\n" - "<menuitem name='Desktop' action='Desktop'/>\n" - "<menuitem name='Menu' action='Menu'/>\n" - "<menuitem name='Toolbar' action='Toolbar'/>\n" - "<menuitem name='Override Redirect' action='Override Redirect'/>\n" - "<menuitem name='Border Only' action='Border Only'/>\n" - "</menu>\n" - "</menubar>\n" - "<toolbar>\n" - "<toolitem name='New' action='New'/>\n" - "<toolitem name='Lock' action='Lock'/>\n" - "<toolitem name='Decorations' action='Decorations'/>\n" - "<toolitem name='Ratio' action='Ratio'/>\n" - "<toolitem name='Quit' action='Quit'/>\n" - "</toolbar>\n" - "</ui>\n"; - -static const GtkActionEntry menu_items[] = -{ - { "Windows", NULL, "_Windows", NULL, - NULL, NULL }, - { "Dialog", NULL, "_Dialog", "<control>d", - NULL, G_CALLBACK (dialog_cb) }, - { "Modal dialog", NULL, "_Modal dialog", NULL, - NULL, G_CALLBACK (modal_dialog_cb) }, - { "Parentless dialog", NULL, "_Parentless dialog", NULL, - NULL, G_CALLBACK (no_parent_dialog_cb) }, - { "Utility", NULL, "_Utility", "<control>u", - NULL, G_CALLBACK (utility_cb) }, - { "Splashscreen", NULL, "_Splashscreen", "<control>s", - NULL, G_CALLBACK (splashscreen_cb) }, - { "Top dock", NULL, "_Top dock", NULL, - NULL, G_CALLBACK (dock_cb) }, - { "Bottom dock", NULL, "_Bottom dock", NULL, - NULL, G_CALLBACK (dock_cb) }, - { "Left dock", NULL, "_Left dock", NULL, - NULL, G_CALLBACK (dock_cb) }, - { "Right dock", NULL, "_Right dock", NULL, - NULL, G_CALLBACK (dock_cb) }, - { "All docks", NULL, "_All docks", NULL, - NULL, G_CALLBACK (dock_cb) }, - { "Desktop", NULL, "Des_ktop", NULL, - NULL, G_CALLBACK (desktop_cb) }, - { "Menu", NULL, "Me_nu", NULL, - NULL, G_CALLBACK (menu_cb) }, - { "Toolbar", NULL, "Tool_bar", NULL, - NULL, G_CALLBACK (toolbar_cb) }, - { "Override Redirect", NULL, "Override Redirect", NULL, - NULL, G_CALLBACK (override_redirect_cb) }, - { "Border Only", NULL, "Border Only", NULL, - NULL, G_CALLBACK (border_only_cb) } -}; - -static const GtkActionEntry tool_items[] = -{ - { "New", GTK_STOCK_NEW, NULL, NULL, - "Open another one of these windows", G_CALLBACK (do_appwindow) }, - { "Lock", GTK_STOCK_OPEN, NULL, NULL, - "This is a demo button that" - " locks up the demo", G_CALLBACK (sleep_cb) }, - { "Decorations", GTK_STOCK_OPEN, NULL, NULL, - "This is a demo button that " - "toggles window decorations", G_CALLBACK (toggle_decorated_cb) }, - { "Quit", GTK_STOCK_QUIT, NULL, NULL, - "This is a demo button with " - " a 'quit' icon", G_CALLBACK (clicked_toolbar_cb) }, - { "Ratio", GTK_STOCK_OPEN, NULL, NULL, - "This is a demo button that locks the aspect ratio " - "using a hint", G_CALLBACK (toggle_aspect_ratio) } -}; - -static GtkWidget * -do_appwindow (void) -{ - GtkWidget *window; - GtkWidget *grid; - GtkWidget *statusbar; - GtkWidget *contents; - GtkWidget *sw; - GtkTextBuffer *buffer; - GtkActionGroup *action_group; - GtkUIManager *ui_manager; - - /* Create the toplevel window - */ - - ++window_count; - - aspect_on = FALSE; - - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_window_set_title (GTK_WINDOW (window), "Application Window"); - - g_signal_connect (G_OBJECT (window), "destroy", - G_CALLBACK (destroy_cb), NULL); - - grid = gtk_grid_new (); - - gtk_widget_set_vexpand (grid, TRUE); - gtk_widget_set_hexpand (grid, TRUE); - - gtk_container_add (GTK_CONTAINER (window), grid); - - /* Create the menubar - */ - - contents = gtk_text_view_new (); - - action_group = gtk_action_group_new ("mainmenu"); - gtk_action_group_add_actions (action_group, - menu_items, - G_N_ELEMENTS (menu_items), - window); - gtk_action_group_add_actions (action_group, - tool_items, - G_N_ELEMENTS (tool_items), - window); - - ui_manager = gtk_ui_manager_new (); - - gtk_ui_manager_insert_action_group (ui_manager, action_group, 0); - - /* create menu items */ - - gtk_ui_manager_add_ui_from_string (ui_manager, menu_item_string, -1, NULL); - - gtk_grid_attach (GTK_GRID (grid), - gtk_ui_manager_get_widget (ui_manager, "/ui/menubar"), - 0, 0, 1, 1); - - gtk_widget_set_hexpand (gtk_ui_manager_get_widget (ui_manager, "/ui/menubar"), - TRUE); - - /* Create document - */ - - sw = gtk_scrolled_window_new (NULL, NULL); - - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); - - gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), - GTK_SHADOW_IN); - - gtk_grid_attach (GTK_GRID (grid), - sw, - 0, 2, 1, 1); - - gtk_widget_set_hexpand (sw, TRUE); - gtk_widget_set_vexpand (sw, TRUE); - - gtk_window_set_default_size (GTK_WINDOW (window), - 200, 200); - - gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (contents), - PANGO_WRAP_WORD); - - gtk_container_add (GTK_CONTAINER (sw), - contents); - - /* Create the toolbar - */ - - gtk_grid_attach (GTK_GRID (grid), - gtk_ui_manager_get_widget (ui_manager, "/ui/toolbar"), - 0, 1, 1, 1); - - gtk_widget_set_hexpand (gtk_ui_manager_get_widget (ui_manager, "/ui/toolbar"), - TRUE); - - /* Create statusbar */ - - statusbar = gtk_statusbar_new (); - gtk_grid_attach (GTK_GRID (grid), - statusbar, - 0, 3, 1, 1); - - gtk_widget_set_hexpand (statusbar, - TRUE); - - /* Show text widget info in the statusbar */ - buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (contents)); - - gtk_text_buffer_set_text (buffer, - "This demo demonstrates various kinds of windows that " - "window managers and window manager themes should handle. " - "Be sure to tear off the menu and toolbar, those are also " - "a special kind of window.", - -1); - - g_signal_connect_object (buffer, - "changed", - G_CALLBACK (update_statusbar), - statusbar, - 0); - - g_signal_connect_object (buffer, - "mark_set", /* cursor moved */ - G_CALLBACK (mark_set_callback), - statusbar, - 0); - - update_statusbar (buffer, GTK_STATUSBAR (statusbar)); - - gtk_widget_show_all (window); - - g_object_unref (ui_manager); - - return window; -} - - diff --git a/src/tools/mutter-window-demo.png b/src/tools/mutter-window-demo.png Binary files differdeleted file mode 100644 index d87f8296e..000000000 --- a/src/tools/mutter-window-demo.png +++ /dev/null diff --git a/src/ui/preview-widget.c b/src/ui/preview-widget.c deleted file mode 100644 index 1aa64a251..000000000 --- a/src/ui/preview-widget.c +++ /dev/null @@ -1,496 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ - -/* - * Copyright (C) 2002 Havoc Pennington - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -/* - * SECTION:preview-widget - * @title: MetaPreview - * @short_description: Mutter theme preview widget - */ - -#define _GNU_SOURCE -#define _XOPEN_SOURCE 600 /* for the maths routines over floats */ - -#include <math.h> -#include <gtk/gtk.h> -#include <meta/preview-widget.h> -#include "theme-private.h" - -static void meta_preview_get_preferred_width (GtkWidget *widget, - gint *minimum, - gint *natural); -static void meta_preview_get_preferred_height (GtkWidget *widget, - gint *minimum, - gint *natural); -static void meta_preview_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); -static gboolean meta_preview_draw (GtkWidget *widget, - cairo_t *cr); -static void meta_preview_realize (GtkWidget *widget); -static void meta_preview_dispose (GObject *object); -static void meta_preview_finalize (GObject *object); - -G_DEFINE_TYPE (MetaPreview, meta_preview, GTK_TYPE_BIN); - -static void -meta_preview_class_init (MetaPreviewClass *class) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (class); - GtkWidgetClass *widget_class; - - widget_class = (GtkWidgetClass*) class; - - gobject_class->dispose = meta_preview_dispose; - gobject_class->finalize = meta_preview_finalize; - - widget_class->realize = meta_preview_realize; - widget_class->draw = meta_preview_draw; - widget_class->get_preferred_width = meta_preview_get_preferred_width; - widget_class->get_preferred_height = meta_preview_get_preferred_height; - widget_class->size_allocate = meta_preview_size_allocate; - - gtk_container_class_handle_border_width (GTK_CONTAINER_CLASS (class)); -} - -static void -meta_preview_init (MetaPreview *preview) -{ - int i; - - gtk_widget_set_has_window (GTK_WIDGET (preview), FALSE); - - i = 0; - while (i < MAX_BUTTONS_PER_CORNER) - { - preview->button_layout.left_buttons[i] = META_BUTTON_FUNCTION_LAST; - preview->button_layout.right_buttons[i] = META_BUTTON_FUNCTION_LAST; - ++i; - } - - preview->button_layout.left_buttons[0] = META_BUTTON_FUNCTION_MENU; - - preview->button_layout.right_buttons[0] = META_BUTTON_FUNCTION_MINIMIZE; - preview->button_layout.right_buttons[1] = META_BUTTON_FUNCTION_MAXIMIZE; - preview->button_layout.right_buttons[2] = META_BUTTON_FUNCTION_CLOSE; - - preview->type = META_FRAME_TYPE_NORMAL; - preview->flags = - META_FRAME_ALLOWS_DELETE | - META_FRAME_ALLOWS_MENU | - META_FRAME_ALLOWS_MINIMIZE | - META_FRAME_ALLOWS_MAXIMIZE | - META_FRAME_ALLOWS_VERTICAL_RESIZE | - META_FRAME_ALLOWS_HORIZONTAL_RESIZE | - META_FRAME_HAS_FOCUS | - META_FRAME_ALLOWS_SHADE | - META_FRAME_ALLOWS_MOVE; - - preview->borders_cached = FALSE; -} - -GtkWidget* -meta_preview_new (void) -{ - MetaPreview *preview; - - preview = g_object_new (META_TYPE_PREVIEW, NULL); - - return GTK_WIDGET (preview); -} - -static void -meta_preview_dispose (GObject *object) -{ - MetaPreview *preview = META_PREVIEW (object); - - g_clear_object (&preview->style_context); - - G_OBJECT_CLASS (meta_preview_parent_class)->dispose (object); -} - -static void -meta_preview_finalize (GObject *object) -{ - MetaPreview *preview; - - preview = META_PREVIEW (object); - - g_free (preview->title); - preview->title = NULL; - - G_OBJECT_CLASS (meta_preview_parent_class)->finalize (object); -} - -static void -ensure_info (MetaPreview *preview) -{ - GtkWidget *widget; - - widget = GTK_WIDGET (preview); - - if (preview->layout == NULL) - { - PangoFontDescription *font_desc; - double scale; - PangoAttrList *attrs; - PangoAttribute *attr; - - if (preview->theme) - scale = meta_theme_get_title_scale (preview->theme, - preview->type, - preview->flags); - else - scale = 1.0; - - preview->layout = gtk_widget_create_pango_layout (widget, - preview->title); - - font_desc = meta_gtk_widget_get_font_desc (widget, scale, NULL); - - preview->text_height = - meta_pango_font_desc_get_text_height (font_desc, - gtk_widget_get_pango_context (widget)); - - attrs = pango_attr_list_new (); - - attr = pango_attr_size_new (pango_font_description_get_size (font_desc)); - attr->start_index = 0; - attr->end_index = G_MAXINT; - - pango_attr_list_insert (attrs, attr); - - pango_layout_set_attributes (preview->layout, attrs); - - pango_attr_list_unref (attrs); - - pango_font_description_free (font_desc); - } - - if (!preview->borders_cached) - { - if (preview->theme) - meta_theme_get_frame_borders (preview->theme, - preview->type, - preview->text_height, - preview->flags, - &preview->borders); - else - meta_frame_borders_clear (&preview->borders); - preview->borders_cached = TRUE; - } -} - -static gboolean -meta_preview_draw (GtkWidget *widget, - cairo_t *cr) -{ - MetaPreview *preview = META_PREVIEW (widget); - GtkAllocation allocation; - - gtk_widget_get_allocation (widget, &allocation); - - if (preview->theme) - { - int client_width; - int client_height; - MetaButtonState button_states[META_BUTTON_TYPE_LAST] = - { - META_BUTTON_STATE_NORMAL, - META_BUTTON_STATE_NORMAL, - META_BUTTON_STATE_NORMAL, - META_BUTTON_STATE_NORMAL - }; - - ensure_info (preview); - cairo_save (cr); - - client_width = allocation.width - preview->borders.total.left - preview->borders.total.right; - client_height = allocation.height - preview->borders.total.top - preview->borders.total.bottom; - - if (client_width < 0) - client_width = 1; - if (client_height < 0) - client_height = 1; - - meta_theme_draw_frame (preview->theme, - preview->style_context, - cr, - preview->type, - preview->flags, - client_width, client_height, - preview->layout, - preview->text_height, - &preview->button_layout, - button_states, - meta_preview_get_mini_icon (), - meta_preview_get_icon ()); - - cairo_restore (cr); - } - - /* draw child */ - return GTK_WIDGET_CLASS (meta_preview_parent_class)->draw (widget, cr); -} - -static void -meta_preview_realize (GtkWidget *widget) -{ - MetaPreview *preview = META_PREVIEW (widget); - - GTK_WIDGET_CLASS (meta_preview_parent_class)->realize (widget); - - preview->style_context = meta_theme_create_style_context (gtk_widget_get_screen (widget), - NULL); -} - -#define NO_CHILD_WIDTH 80 -#define NO_CHILD_HEIGHT 20 - -static void -meta_preview_get_preferred_width (GtkWidget *widget, - gint *minimum, - gint *natural) -{ - MetaPreview *preview; - GtkWidget *child; - - preview = META_PREVIEW (widget); - - ensure_info (preview); - - *minimum = *natural = preview->borders.total.left + preview->borders.total.right; - - child = gtk_bin_get_child (GTK_BIN (preview)); - if (child && gtk_widget_get_visible (child)) - { - gint child_min, child_nat; - - gtk_widget_get_preferred_width (child, &child_min, &child_nat); - - *minimum += child_min; - *natural += child_nat; - } - else - { - *minimum += NO_CHILD_WIDTH; - *natural += NO_CHILD_WIDTH; - } -} - -static void -meta_preview_get_preferred_height (GtkWidget *widget, - gint *minimum, - gint *natural) -{ - MetaPreview *preview; - GtkWidget *child; - - preview = META_PREVIEW (widget); - - ensure_info (preview); - - *minimum = *natural = preview->borders.total.top + preview->borders.total.bottom; - - child = gtk_bin_get_child (GTK_BIN (preview)); - if (child && gtk_widget_get_visible (child)) - { - gint child_min, child_nat; - - gtk_widget_get_preferred_height (child, &child_min, &child_nat); - - *minimum += child_min; - *natural += child_nat; - } - else - { - *minimum += NO_CHILD_HEIGHT; - *natural += NO_CHILD_HEIGHT; - } -} - -static void -meta_preview_size_allocate (GtkWidget *widget, - GtkAllocation *allocation) -{ - MetaPreview *preview; - GtkAllocation widget_allocation, child_allocation; - GtkWidget *child; - - preview = META_PREVIEW (widget); - - ensure_info (preview); - - gtk_widget_set_allocation (widget, allocation); - - child = gtk_bin_get_child (GTK_BIN (widget)); - if (child && gtk_widget_get_visible (child)) - { - gtk_widget_get_allocation (widget, &widget_allocation); - child_allocation.x = widget_allocation.x + preview->borders.total.left; - child_allocation.y = widget_allocation.y + preview->borders.total.top; - - child_allocation.width = MAX (1, widget_allocation.width - preview->borders.total.left - preview->borders.total.right); - child_allocation.height = MAX (1, widget_allocation.height - preview->borders.total.top - preview->borders.total.bottom); - - gtk_widget_size_allocate (child, &child_allocation); - } -} - -static void -clear_cache (MetaPreview *preview) -{ - if (preview->layout) - { - g_object_unref (G_OBJECT (preview->layout)); - preview->layout = NULL; - } - - preview->borders_cached = FALSE; -} - -void -meta_preview_set_theme (MetaPreview *preview, - MetaTheme *theme) -{ - g_return_if_fail (META_IS_PREVIEW (preview)); - - preview->theme = theme; - - clear_cache (preview); - - gtk_widget_queue_resize (GTK_WIDGET (preview)); -} - -void -meta_preview_set_title (MetaPreview *preview, - const char *title) -{ - g_return_if_fail (META_IS_PREVIEW (preview)); - - g_free (preview->title); - preview->title = g_strdup (title); - - clear_cache (preview); - - gtk_widget_queue_resize (GTK_WIDGET (preview)); -} - -void -meta_preview_set_frame_type (MetaPreview *preview, - MetaFrameType type) -{ - g_return_if_fail (META_IS_PREVIEW (preview)); - - preview->type = type; - - clear_cache (preview); - - gtk_widget_queue_resize (GTK_WIDGET (preview)); -} - -void -meta_preview_set_frame_flags (MetaPreview *preview, - MetaFrameFlags flags) -{ - g_return_if_fail (META_IS_PREVIEW (preview)); - - preview->flags = flags; - - clear_cache (preview); - - gtk_widget_queue_resize (GTK_WIDGET (preview)); -} - -void -meta_preview_set_button_layout (MetaPreview *preview, - const MetaButtonLayout *button_layout) -{ - g_return_if_fail (META_IS_PREVIEW (preview)); - - preview->button_layout = *button_layout; - - gtk_widget_queue_draw (GTK_WIDGET (preview)); -} - -GdkPixbuf* -meta_preview_get_icon (void) -{ - static GdkPixbuf *default_icon = NULL; - - if (default_icon == NULL) - { - GtkIconTheme *theme; - gboolean icon_exists; - - theme = gtk_icon_theme_get_default (); - - icon_exists = gtk_icon_theme_has_icon (theme, META_DEFAULT_ICON_NAME); - - if (icon_exists) - default_icon = gtk_icon_theme_load_icon (theme, - META_DEFAULT_ICON_NAME, - META_ICON_WIDTH, - 0, - NULL); - else - default_icon = gtk_icon_theme_load_icon (theme, - "gtk-missing-image", - META_ICON_WIDTH, - 0, - NULL); - - g_assert (default_icon); - } - - return default_icon; -} - -GdkPixbuf* -meta_preview_get_mini_icon (void) -{ - static GdkPixbuf *default_icon = NULL; - - if (default_icon == NULL) - { - GtkIconTheme *theme; - gboolean icon_exists; - - theme = gtk_icon_theme_get_default (); - - icon_exists = gtk_icon_theme_has_icon (theme, META_DEFAULT_ICON_NAME); - - if (icon_exists) - default_icon = gtk_icon_theme_load_icon (theme, - META_DEFAULT_ICON_NAME, - META_MINI_ICON_WIDTH, - 0, - NULL); - else - default_icon = gtk_icon_theme_load_icon (theme, - "gtk-missing-image", - META_MINI_ICON_WIDTH, - 0, - NULL); - - g_assert (default_icon); - } - - return default_icon; -} diff --git a/src/ui/theme-viewer.c b/src/ui/theme-viewer.c deleted file mode 100644 index 8d2808152..000000000 --- a/src/ui/theme-viewer.c +++ /dev/null @@ -1,1365 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ - -/* Metacity theme viewer and test app main() */ - -/* - * Copyright (C) 2002 Havoc Pennington - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#include <config.h> -#include <meta/util.h> -#include <meta/theme.h> -#include "theme-private.h" -#include <meta/preview-widget.h> -#include <gtk/gtk.h> -#include <time.h> -#include <stdlib.h> -#include <string.h> - -#include <libintl.h> -#define _(x) dgettext (GETTEXT_PACKAGE, x) -#define N_(x) x - -/* We need to compute all different button arrangements - * in terms of button location. We don't care about - * different arrangements in terms of button function. - * - * So if dups are allowed, from 0-4 buttons on the left, from 0-4 on - * the right, 5x5=25 combinations. - * - * If no dups, 0-4 on left determines the number on the right plus - * we have a special case for the "no buttons on either side" case. - */ -#ifndef ALLOW_DUPLICATE_BUTTONS -#define BUTTON_LAYOUT_COMBINATIONS (MAX_BUTTONS_PER_CORNER + 1 + 1) -#else -#define BUTTON_LAYOUT_COMBINATIONS ((MAX_BUTTONS_PER_CORNER+1)*(MAX_BUTTONS_PER_CORNER+1)) -#endif - -enum -{ - FONT_SIZE_SMALL, - FONT_SIZE_NORMAL, - FONT_SIZE_LARGE, - FONT_SIZE_LAST -}; - -static MetaTheme *global_theme = NULL; -static GtkWidget *previews[META_FRAME_TYPE_LAST*FONT_SIZE_LAST + BUTTON_LAYOUT_COMBINATIONS] = { NULL, }; -static double milliseconds_to_draw_frame = 0.0; - -static void run_position_expression_tests (void); -#if 0 -static void run_position_expression_timings (void); -#endif -static void run_theme_benchmark (void); - - -static const gchar *menu_item_string = - "<ui>\n" - "<menubar>\n" - "<menu name='Windows' action='Windows'>\n" - "<menuitem name='Dialog' action='Dialog'/>\n" - "<menuitem name='Modal dialog' action='Modal dialog'/>\n" - "<menuitem name='Utility' action='Utility'/>\n" - "<menuitem name='Splashscreen' action='Splashscreen'/>\n" - "<menuitem name='Top dock' action='Top dock'/>\n" - "<menuitem name='Bottom dock' action='Bottom dock'/>\n" - "<menuitem name='Left dock' action='Left dock'/>\n" - "<menuitem name='Right dock' action='Right dock'/>\n" - "<menuitem name='Desktop' action='Desktop'/>\n" - "</menu>\n" - "</menubar>\n" - "<toolbar>\n" - "<separator/>\n" - "<toolitem name='New' action='New'/>\n" - "<toolitem name='Open' action='Open'/>\n" - "<toolitem name='Quit' action='Quit'/>\n" - "<separator/>\n" - "</toolbar>\n" - "</ui>\n"; - -static GtkActionEntry menu_items[] = -{ - { "Windows", NULL, N_("_Windows"), NULL, NULL, NULL }, - { "Dialog", NULL, N_("_Dialog"), "<control>d", NULL, NULL }, - { "Modal dialog", NULL, N_("_Modal dialog"), NULL, NULL, NULL }, - { "Utility", NULL, N_("_Utility"), "<control>u", NULL, NULL }, - { "Splashscreen", NULL, N_("_Splashscreen"), "<control>s", NULL, NULL }, - { "Top dock", NULL, N_("_Top dock"), NULL, NULL, NULL }, - { "Bottom dock", NULL, N_("_Bottom dock"), NULL, NULL, NULL }, - { "Left dock", NULL, N_("_Left dock"), NULL, NULL, NULL }, - { "Right dock", NULL, N_("_Right dock"), NULL, NULL, NULL }, - { "All docks", NULL, N_("_All docks"), NULL, NULL, NULL }, - { "Desktop", NULL, N_("Des_ktop"), NULL, NULL, NULL } -}; - -static GtkActionEntry tool_items[] = -{ - { "New", GTK_STOCK_NEW, NULL, NULL, - N_("Open another one of these windows"), NULL }, - { "Open", GTK_STOCK_OPEN, NULL, NULL, - N_("This is a demo button with an 'open' icon"), NULL }, - { "Quit", GTK_STOCK_QUIT, NULL, NULL, - N_("This is a demo button with a 'quit' icon"), NULL } -}; - -static GtkWidget * -normal_contents (void) -{ - GtkWidget *grid; - GtkWidget *statusbar; - GtkWidget *contents; - GtkWidget *sw; - GtkActionGroup *action_group; - GtkUIManager *ui_manager; - - grid = gtk_grid_new (); - - /* Create the menubar - */ - - action_group = gtk_action_group_new ("mainmenu"); - gtk_action_group_add_actions (action_group, - menu_items, - G_N_ELEMENTS (menu_items), - NULL); - gtk_action_group_add_actions (action_group, - tool_items, - G_N_ELEMENTS (tool_items), - NULL); - - ui_manager = gtk_ui_manager_new (); - - gtk_ui_manager_insert_action_group (ui_manager, action_group, 0); - - /* create menu items */ - gtk_ui_manager_add_ui_from_string (ui_manager, menu_item_string, -1, NULL); - - gtk_grid_attach (GTK_GRID (grid), - gtk_ui_manager_get_widget (ui_manager, "/ui/menubar"), - 0, 0, 1, 1); - - gtk_widget_set_hexpand (gtk_ui_manager_get_widget (ui_manager, "/ui/menubar"), - TRUE); - - /* Create the toolbar - */ - gtk_grid_attach (GTK_GRID (grid), - gtk_ui_manager_get_widget (ui_manager, "/ui/toolbar"), - 0, 1, 1, 1); - - gtk_widget_set_hexpand (gtk_ui_manager_get_widget (ui_manager, "/ui/toolbar"), - TRUE); - - /* Create document - */ - - sw = gtk_scrolled_window_new (NULL, NULL); - - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); - - gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), - GTK_SHADOW_IN); - - gtk_grid_attach (GTK_GRID (grid), - sw, - 0, 2, 1, 1); - - gtk_widget_set_hexpand (sw, TRUE); - gtk_widget_set_vexpand (sw, TRUE); - - contents = gtk_text_view_new (); - gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (contents), - PANGO_WRAP_WORD); - - gtk_container_add (GTK_CONTAINER (sw), - contents); - - /* Create statusbar */ - - statusbar = gtk_statusbar_new (); - gtk_grid_attach (GTK_GRID (grid), - statusbar, - 0, 3, 1, 1); - - gtk_widget_set_hexpand (statusbar, TRUE); - - gtk_widget_show_all (grid); - - g_object_unref (ui_manager); - - return grid; -} - -static void -update_spacings (GtkWidget *vbox, - GtkWidget *action_area) -{ - gtk_container_set_border_width (GTK_CONTAINER (vbox), 2); - gtk_box_set_spacing (GTK_BOX (action_area), 10); - gtk_container_set_border_width (GTK_CONTAINER (action_area), 5); -} - -static GtkWidget* -dialog_contents (void) -{ - GtkWidget *vbox; - GtkWidget *hbox; - GtkWidget *action_area; - GtkWidget *label; - GtkWidget *image; - GtkWidget *button; - - vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); - - action_area = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL); - - gtk_button_box_set_layout (GTK_BUTTON_BOX (action_area), - GTK_BUTTONBOX_END); - - button = gtk_button_new_from_stock (GTK_STOCK_OK); - gtk_box_pack_end (GTK_BOX (action_area), - button, - FALSE, TRUE, 0); - - gtk_box_pack_end (GTK_BOX (vbox), action_area, - FALSE, TRUE, 0); - - update_spacings (vbox, action_area); - - label = gtk_label_new (_("This is a sample message in a sample dialog")); - image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_INFO, - GTK_ICON_SIZE_DIALOG); - gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.0); - - gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); - gtk_label_set_selectable (GTK_LABEL (label), TRUE); - - hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); - - gtk_box_pack_start (GTK_BOX (hbox), image, - FALSE, FALSE, 0); - - gtk_box_pack_start (GTK_BOX (hbox), label, - TRUE, TRUE, 0); - - gtk_box_pack_start (GTK_BOX (vbox), - hbox, - FALSE, FALSE, 0); - - gtk_widget_show_all (vbox); - - return vbox; -} - -static GtkWidget* -utility_contents (void) -{ - GtkWidget *grid; - GtkWidget *button; - int i, j; - - grid = gtk_grid_new (); - - i = 0; - while (i < 3) - { - j = 0; - while (j < 4) - { - char *str; - - str = g_strdup_printf ("_%c", (char) ('A' + 4*i + j)); - - button = gtk_button_new_with_mnemonic (str); - - g_free (str); - - gtk_grid_attach (GTK_GRID (grid), - button, - i, j, 1, 1); - - ++j; - } - - ++i; - } - - gtk_widget_show_all (grid); - - return grid; -} - -static GtkWidget* -menu_contents (void) -{ - GtkWidget *vbox; - GtkWidget *mi; - int i; - GtkWidget *frame; - - frame = gtk_frame_new (NULL); - gtk_frame_set_shadow_type (GTK_FRAME (frame), - GTK_SHADOW_OUT); - - vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); - - i = 0; - while (i < 10) - { - char *str = g_strdup_printf (_("Fake menu item %d\n"), i + 1); - mi = gtk_label_new (str); - gtk_misc_set_alignment (GTK_MISC (mi), 0.0, 0.5); - g_free (str); - gtk_box_pack_start (GTK_BOX (vbox), mi, FALSE, FALSE, 0); - - ++i; - } - - gtk_container_add (GTK_CONTAINER (frame), vbox); - - gtk_widget_show_all (frame); - - return frame; -} - -static GtkWidget* -border_only_contents (void) -{ - GtkWidget *event_box; - GtkWidget *vbox; - GtkWidget *w; - GdkRGBA color; - - event_box = gtk_event_box_new (); - - color.red = 0.6; - color.green = 0; - color.blue = 0.6; - color.alpha = 1.0; - gtk_widget_override_background_color (event_box, 0, &color); - - vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); - gtk_container_set_border_width (GTK_CONTAINER (vbox), 3); - - w = gtk_label_new (_("Border-only window")); - gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 0); - w = gtk_button_new_with_label (_("Bar")); - gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 0); - - gtk_container_add (GTK_CONTAINER (event_box), vbox); - - gtk_widget_show_all (event_box); - - return event_box; -} - -static GtkWidget* -get_window_contents (MetaFrameType type, - const char **title) -{ - switch (type) - { - case META_FRAME_TYPE_NORMAL: - *title = _("Normal Application Window"); - return normal_contents (); - - case META_FRAME_TYPE_DIALOG: - *title = _("Dialog Box"); - return dialog_contents (); - - case META_FRAME_TYPE_MODAL_DIALOG: - *title = _("Modal Dialog Box"); - return dialog_contents (); - - case META_FRAME_TYPE_UTILITY: - *title = _("Utility Palette"); - return utility_contents (); - - case META_FRAME_TYPE_MENU: - *title = _("Torn-off Menu"); - return menu_contents (); - - case META_FRAME_TYPE_BORDER: - *title = _("Border"); - return border_only_contents (); - - case META_FRAME_TYPE_ATTACHED: - *title = _("Attached Modal Dialog"); - return dialog_contents (); - - case META_FRAME_TYPE_LAST: - g_assert_not_reached (); - break; - } - - return NULL; -} - -static MetaFrameFlags -get_window_flags (MetaFrameType type) -{ - MetaFrameFlags flags; - - flags = META_FRAME_ALLOWS_DELETE | - META_FRAME_ALLOWS_MENU | - META_FRAME_ALLOWS_MINIMIZE | - META_FRAME_ALLOWS_MAXIMIZE | - META_FRAME_ALLOWS_VERTICAL_RESIZE | - META_FRAME_ALLOWS_HORIZONTAL_RESIZE | - META_FRAME_HAS_FOCUS | - META_FRAME_ALLOWS_SHADE | - META_FRAME_ALLOWS_MOVE; - - switch (type) - { - case META_FRAME_TYPE_NORMAL: - break; - - case META_FRAME_TYPE_DIALOG: - case META_FRAME_TYPE_MODAL_DIALOG: - flags &= ~(META_FRAME_ALLOWS_MINIMIZE | - META_FRAME_ALLOWS_MAXIMIZE); - break; - - case META_FRAME_TYPE_UTILITY: - flags &= ~(META_FRAME_ALLOWS_MINIMIZE | - META_FRAME_ALLOWS_MAXIMIZE); - break; - - case META_FRAME_TYPE_MENU: - flags &= ~(META_FRAME_ALLOWS_MINIMIZE | - META_FRAME_ALLOWS_MAXIMIZE); - break; - - case META_FRAME_TYPE_BORDER: - break; - - case META_FRAME_TYPE_ATTACHED: - break; - - case META_FRAME_TYPE_LAST: - g_assert_not_reached (); - break; - } - - return flags; -} - -static GtkWidget* -preview_collection (int font_size, - const PangoFontDescription *base_desc) -{ - GtkWidget *box; - GtkWidget *sw; - GdkRGBA desktop_color; - int i; - GtkWidget *eventbox; - - sw = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); - - box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); - gtk_box_set_spacing (GTK_BOX (box), 20); - gtk_container_set_border_width (GTK_CONTAINER (box), 20); - - eventbox = gtk_event_box_new (); - gtk_container_add (GTK_CONTAINER (eventbox), box); - gtk_container_add (GTK_CONTAINER (sw), eventbox); - - desktop_color.red = 0.32; - desktop_color.green = 0.46; - desktop_color.blue = 0.65; - desktop_color.alpha = 1.0; - - gtk_widget_override_background_color (eventbox, 0, &desktop_color); - - i = 0; - while (i < META_FRAME_TYPE_LAST) - { - const char *title = NULL; - GtkWidget *contents; - GtkWidget *align; - double xalign, yalign; - GtkWidget *eventbox2; - GtkWidget *preview; - PangoFontDescription *font_desc; - double scale; - - eventbox2 = gtk_event_box_new (); - - preview = meta_preview_new (); - - gtk_container_add (GTK_CONTAINER (eventbox2), preview); - - meta_preview_set_frame_type (META_PREVIEW (preview), i); - meta_preview_set_frame_flags (META_PREVIEW (preview), - get_window_flags (i)); - - meta_preview_set_theme (META_PREVIEW (preview), global_theme); - - contents = get_window_contents (i, &title); - - meta_preview_set_title (META_PREVIEW (preview), title); - - gtk_container_add (GTK_CONTAINER (preview), contents); - - if (i == META_FRAME_TYPE_MENU) - { - xalign = 0.0; - yalign = 0.0; - } - else - { - xalign = 0.5; - yalign = 0.5; - } - - align = gtk_alignment_new (0.0, 0.0, xalign, yalign); - gtk_container_add (GTK_CONTAINER (align), eventbox2); - - gtk_box_pack_start (GTK_BOX (box), align, TRUE, TRUE, 0); - - switch (font_size) - { - case FONT_SIZE_SMALL: - scale = PANGO_SCALE_XX_SMALL; - break; - case FONT_SIZE_LARGE: - scale = PANGO_SCALE_XX_LARGE; - break; - default: - scale = 1.0; - break; - } - - if (scale != 1.0) - { - font_desc = pango_font_description_new (); - - pango_font_description_set_size (font_desc, - MAX (pango_font_description_get_size (base_desc) * scale, 1)); - - gtk_widget_modify_font (preview, font_desc); - - pango_font_description_free (font_desc); - } - - previews[font_size*META_FRAME_TYPE_LAST + i] = preview; - - ++i; - } - - return sw; -} - -static MetaButtonLayout different_layouts[BUTTON_LAYOUT_COMBINATIONS]; - -static void -init_layouts (void) -{ - int i; - - /* Blank out all the layouts */ - i = 0; - while (i < (int) G_N_ELEMENTS (different_layouts)) - { - int j; - - j = 0; - while (j < MAX_BUTTONS_PER_CORNER) - { - different_layouts[i].left_buttons[j] = META_BUTTON_FUNCTION_LAST; - different_layouts[i].right_buttons[j] = META_BUTTON_FUNCTION_LAST; - ++j; - } - ++i; - } - -#ifndef ALLOW_DUPLICATE_BUTTONS - i = 0; - while (i <= MAX_BUTTONS_PER_CORNER) - { - int j; - - j = 0; - while (j < i) - { - different_layouts[i].right_buttons[j] = (MetaButtonFunction) j; - ++j; - } - while (j < MAX_BUTTONS_PER_CORNER) - { - different_layouts[i].left_buttons[j-i] = (MetaButtonFunction) j; - ++j; - } - - ++i; - } - - /* Special extra case for no buttons on either side */ - different_layouts[i].left_buttons[0] = META_BUTTON_FUNCTION_LAST; - different_layouts[i].right_buttons[0] = META_BUTTON_FUNCTION_LAST; - -#else - /* FIXME this code is if we allow duplicate buttons, - * which we currently do not - */ - int left; - int i; - - left = 0; - i = 0; - - while (left < MAX_BUTTONS_PER_CORNER) - { - int right; - - right = 0; - - while (right < MAX_BUTTONS_PER_CORNER) - { - int j; - - static MetaButtonFunction left_functions[MAX_BUTTONS_PER_CORNER] = { - META_BUTTON_FUNCTION_MENU, - META_BUTTON_FUNCTION_MINIMIZE, - META_BUTTON_FUNCTION_MAXIMIZE, - META_BUTTON_FUNCTION_CLOSE - }; - static MetaButtonFunction right_functions[MAX_BUTTONS_PER_CORNER] = { - META_BUTTON_FUNCTION_MINIMIZE, - META_BUTTON_FUNCTION_MAXIMIZE, - META_BUTTON_FUNCTION_CLOSE, - META_BUTTON_FUNCTION_MENU - }; - - g_assert (i < BUTTON_LAYOUT_COMBINATIONS); - - j = 0; - while (j <= left) - { - different_layouts[i].left_buttons[j] = left_functions[j]; - ++j; - } - - j = 0; - while (j <= right) - { - different_layouts[i].right_buttons[j] = right_functions[j]; - ++j; - } - - ++i; - - ++right; - } - - ++left; - } -#endif -} - - -static GtkWidget* -previews_of_button_layouts (void) -{ - static gboolean initted = FALSE; - GtkWidget *box; - GtkWidget *sw; - GdkRGBA desktop_color; - int i; - GtkWidget *eventbox; - - if (!initted) - { - init_layouts (); - initted = TRUE; - } - - sw = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); - - box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); - gtk_box_set_spacing (GTK_BOX (box), 20); - gtk_container_set_border_width (GTK_CONTAINER (box), 20); - - eventbox = gtk_event_box_new (); - gtk_container_add (GTK_CONTAINER (eventbox), box); - gtk_container_add (GTK_CONTAINER (sw), eventbox); - - desktop_color.red = 0.32; - desktop_color.green = 0.46; - desktop_color.blue = 0.65; - desktop_color.alpha = 1.0; - - gtk_widget_override_background_color (eventbox, 0, &desktop_color); - - i = 0; - while (i < BUTTON_LAYOUT_COMBINATIONS) - { - GtkWidget *align; - double xalign, yalign; - GtkWidget *eventbox2; - GtkWidget *preview; - char *title; - - eventbox2 = gtk_event_box_new (); - - preview = meta_preview_new (); - - gtk_container_add (GTK_CONTAINER (eventbox2), preview); - - meta_preview_set_theme (META_PREVIEW (preview), global_theme); - - title = g_strdup_printf (_("Button layout test %d"), i+1); - meta_preview_set_title (META_PREVIEW (preview), title); - g_free (title); - - meta_preview_set_button_layout (META_PREVIEW (preview), - &different_layouts[i]); - - xalign = 0.5; - yalign = 0.5; - - align = gtk_alignment_new (0.0, 0.0, xalign, yalign); - gtk_container_add (GTK_CONTAINER (align), eventbox2); - - gtk_box_pack_start (GTK_BOX (box), align, TRUE, TRUE, 0); - - previews[META_FRAME_TYPE_LAST*FONT_SIZE_LAST + i] = preview; - - ++i; - } - - return sw; -} - -static GtkWidget* -benchmark_summary (void) -{ - char *msg; - GtkWidget *label; - - msg = g_strdup_printf (_("%g milliseconds to draw one window frame"), - milliseconds_to_draw_frame); - label = gtk_label_new (msg); - g_free (msg); - - return label; -} - -int -main (int argc, char **argv) -{ - GtkStyleContext *style; - PangoFontDescription *font_desc; - GtkWidget *window; - GtkWidget *collection; - GError *err; - clock_t start, end; - GtkWidget *notebook; - int i; - - bindtextdomain (GETTEXT_PACKAGE, MUTTER_LOCALEDIR); - textdomain(GETTEXT_PACKAGE); - bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); - - run_position_expression_tests (); -#if 0 - run_position_expression_timings (); -#endif - - gtk_init (&argc, &argv); - - if (g_getenv ("MUTTER_DEBUG") != NULL) - { - meta_set_debugging (TRUE); - meta_set_verbose (TRUE); - } - - start = clock (); - err = NULL; - if (argc == 1) - global_theme = meta_theme_load ("Atlanta", &err); - else if (argc == 2) - global_theme = meta_theme_load (argv[1], &err); - else - { - g_printerr (_("Usage: metacity-theme-viewer [THEMENAME]\n")); - exit (1); - } - end = clock (); - - if (global_theme == NULL) - { - g_printerr (_("Error loading theme: %s\n"), - err->message); - g_error_free (err); - exit (1); - } - - g_print (_("Loaded theme \"%s\" in %g seconds\n"), - global_theme->name, - (end - start) / (double) CLOCKS_PER_SEC); - - run_theme_benchmark (); - - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_window_set_default_size (GTK_WINDOW (window), 350, 350); - - if (strcmp (global_theme->name, global_theme->readable_name)==0) - gtk_window_set_title (GTK_WINDOW (window), - global_theme->readable_name); - else - { - /* The theme directory name is different from the name the theme - * gives itself within its file. Display both, directory name first. - */ - gchar *title = g_strconcat (global_theme->name, " - ", - global_theme->readable_name, - NULL); - - gtk_window_set_title (GTK_WINDOW (window), - title); - - g_free (title); - } - - g_signal_connect (G_OBJECT (window), "destroy", - G_CALLBACK (gtk_main_quit), NULL); - - gtk_widget_realize (window); - - style = meta_theme_create_style_context (gtk_widget_get_screen (window), NULL); - gtk_style_context_get (style, GTK_STATE_FLAG_NORMAL, "font", &font_desc, NULL); - - g_assert (style); - g_assert (font_desc); - - notebook = gtk_notebook_new (); - gtk_container_add (GTK_CONTAINER (window), notebook); - - collection = preview_collection (FONT_SIZE_NORMAL, - font_desc); - gtk_notebook_append_page (GTK_NOTEBOOK (notebook), - collection, - gtk_label_new (_("Normal Title Font"))); - - collection = preview_collection (FONT_SIZE_SMALL, - font_desc); - gtk_notebook_append_page (GTK_NOTEBOOK (notebook), - collection, - gtk_label_new (_("Small Title Font"))); - - collection = preview_collection (FONT_SIZE_LARGE, - font_desc); - gtk_notebook_append_page (GTK_NOTEBOOK (notebook), - collection, - gtk_label_new (_("Large Title Font"))); - - collection = previews_of_button_layouts (); - gtk_notebook_append_page (GTK_NOTEBOOK (notebook), - collection, - gtk_label_new (_("Button Layouts"))); - - collection = benchmark_summary (); - gtk_notebook_append_page (GTK_NOTEBOOK (notebook), - collection, - gtk_label_new (_("Benchmark"))); - - pango_font_description_free (font_desc); - - i = 0; - while (i < (int) G_N_ELEMENTS (previews)) - { - /* preview widget likes to be realized before its size request. - * it's lame that way. - */ - gtk_widget_realize (previews[i]); - - ++i; - } - - gtk_widget_show_all (window); - - gtk_main (); - - return 0; -} - - -static MetaFrameFlags -get_flags (GtkWidget *widget) -{ - return META_FRAME_ALLOWS_DELETE | - META_FRAME_ALLOWS_MENU | - META_FRAME_ALLOWS_MINIMIZE | - META_FRAME_ALLOWS_MAXIMIZE | - META_FRAME_ALLOWS_VERTICAL_RESIZE | - META_FRAME_ALLOWS_HORIZONTAL_RESIZE | - META_FRAME_HAS_FOCUS | - META_FRAME_ALLOWS_SHADE | - META_FRAME_ALLOWS_MOVE; -} - -static int -get_text_height (GtkWidget *widget, - GtkStyleContext *style) -{ - PangoFontDescription *font_desc; - int text_height; - - gtk_style_context_get (style, GTK_STATE_FLAG_NORMAL, "font", &font_desc, NULL); - text_height = meta_pango_font_desc_get_text_height (font_desc, - gtk_widget_get_pango_context (widget)); - pango_font_description_free (font_desc); - return text_height; -} - -static PangoLayout* -create_title_layout (GtkWidget *widget) -{ - PangoLayout *layout; - - layout = gtk_widget_create_pango_layout (widget, _("Window Title Goes Here")); - - return layout; -} - -static void -run_theme_benchmark (void) -{ - GtkWidget* widget; - GtkStyleContext *style_context; - cairo_surface_t *pixmap; - MetaFrameBorders borders; - MetaButtonState button_states[META_BUTTON_TYPE_LAST] = - { - META_BUTTON_STATE_NORMAL, - META_BUTTON_STATE_NORMAL, - META_BUTTON_STATE_NORMAL, - META_BUTTON_STATE_NORMAL - }; - PangoLayout *layout; - clock_t start; - clock_t end; - GTimer *timer; - int i; - MetaButtonLayout button_layout; -#define ITERATIONS 100 - int client_width; - int client_height; - cairo_t *cr; - int inc; - - widget = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_widget_realize (widget); - - style_context = meta_theme_create_style_context (gtk_widget_get_screen (widget), NULL); - - meta_theme_get_frame_borders (global_theme, - META_FRAME_TYPE_NORMAL, - get_text_height (widget, style_context), - get_flags (widget), - &borders); - - layout = create_title_layout (widget); - - i = 0; - while (i < MAX_BUTTONS_PER_CORNER) - { - button_layout.left_buttons[i] = META_BUTTON_FUNCTION_LAST; - button_layout.right_buttons[i] = META_BUTTON_FUNCTION_LAST; - ++i; - } - - button_layout.left_buttons[0] = META_BUTTON_FUNCTION_MENU; - - button_layout.right_buttons[0] = META_BUTTON_FUNCTION_MINIMIZE; - button_layout.right_buttons[1] = META_BUTTON_FUNCTION_MAXIMIZE; - button_layout.right_buttons[2] = META_BUTTON_FUNCTION_CLOSE; - - timer = g_timer_new (); - start = clock (); - - client_width = 50; - client_height = 50; - inc = 1000 / ITERATIONS; /* Increment to grow width/height, - * eliminates caching effects. - */ - - i = 0; - while (i < ITERATIONS) - { - /* Creating the pixmap in the loop is right, since - * GDK does the same with its double buffering. - */ - pixmap = gdk_window_create_similar_surface (gtk_widget_get_window (widget), - CAIRO_CONTENT_COLOR, - client_width + borders.total.left + borders.total.right, - client_height + borders.total.top + borders.total.bottom); - - cr = cairo_create (pixmap); - - meta_theme_draw_frame (global_theme, - style_context, - cr, - META_FRAME_TYPE_NORMAL, - get_flags (widget), - client_width, client_height, - layout, - get_text_height (widget, style_context), - &button_layout, - button_states, - meta_preview_get_mini_icon (), - meta_preview_get_icon ()); - - cairo_destroy (cr); - cairo_surface_destroy (pixmap); - - ++i; - client_width += inc; - client_height += inc; - } - - end = clock (); - g_timer_stop (timer); - - milliseconds_to_draw_frame = (g_timer_elapsed (timer, NULL) / (double) ITERATIONS) * 1000; - - g_print (_("Drew %d frames in %g client-side seconds (%g milliseconds per frame) and %g seconds wall clock time including X server resources (%g milliseconds per frame)\n"), - ITERATIONS, - ((double)end - (double)start) / CLOCKS_PER_SEC, - (((double)end - (double)start) / CLOCKS_PER_SEC / (double) ITERATIONS) * 1000, - g_timer_elapsed (timer, NULL), - milliseconds_to_draw_frame); - - g_timer_destroy (timer); - g_object_unref (G_OBJECT (layout)); - g_object_unref (style_context); - gtk_widget_destroy (widget); - -#undef ITERATIONS -} - -typedef struct -{ - GdkRectangle rect; - const char *expr; - int expected_x; - int expected_y; - MetaThemeError expected_error; -} PositionExpressionTest; - -#define NO_ERROR -1 - -static const PositionExpressionTest position_expression_tests[] = { - /* Just numbers */ - { { 10, 20, 40, 50 }, - "10", 20, 30, NO_ERROR }, - { { 10, 20, 40, 50 }, - "14.37", 24, 34, NO_ERROR }, - /* Binary expressions with 2 ints */ - { { 10, 20, 40, 50 }, - "14 * 10", 150, 160, NO_ERROR }, - { { 10, 20, 40, 50 }, - "14 + 10", 34, 44, NO_ERROR }, - { { 10, 20, 40, 50 }, - "14 - 10", 14, 24, NO_ERROR }, - { { 10, 20, 40, 50 }, - "8 / 2", 14, 24, NO_ERROR }, - { { 10, 20, 40, 50 }, - "8 % 3", 12, 22, NO_ERROR }, - /* Binary expressions with floats and mixed float/ints */ - { { 10, 20, 40, 50 }, - "7.0 / 3.5", 12, 22, NO_ERROR }, - { { 10, 20, 40, 50 }, - "12.1 / 3", 14, 24, NO_ERROR }, - { { 10, 20, 40, 50 }, - "12 / 2.95", 14, 24, NO_ERROR }, - /* Binary expressions without whitespace after first number */ - { { 10, 20, 40, 50 }, - "14* 10", 150, 160, NO_ERROR }, - { { 10, 20, 40, 50 }, - "14+ 10", 34, 44, NO_ERROR }, - { { 10, 20, 40, 50 }, - "14- 10", 14, 24, NO_ERROR }, - { { 10, 20, 40, 50 }, - "8/ 2", 14, 24, NO_ERROR }, - { { 10, 20, 40, 50 }, - "7.0/ 3.5", 12, 22, NO_ERROR }, - { { 10, 20, 40, 50 }, - "12.1/ 3", 14, 24, NO_ERROR }, - { { 10, 20, 40, 50 }, - "12/ 2.95", 14, 24, NO_ERROR }, - /* Binary expressions without whitespace before second number */ - { { 10, 20, 40, 50 }, - "14 *10", 150, 160, NO_ERROR }, - { { 10, 20, 40, 50 }, - "14 +10", 34, 44, NO_ERROR }, - { { 10, 20, 40, 50 }, - "14 -10", 14, 24, NO_ERROR }, - { { 10, 20, 40, 50 }, - "8 /2", 14, 24, NO_ERROR }, - { { 10, 20, 40, 50 }, - "7.0 /3.5", 12, 22, NO_ERROR }, - { { 10, 20, 40, 50 }, - "12.1 /3", 14, 24, NO_ERROR }, - { { 10, 20, 40, 50 }, - "12 /2.95", 14, 24, NO_ERROR }, - /* Binary expressions without any whitespace */ - { { 10, 20, 40, 50 }, - "14*10", 150, 160, NO_ERROR }, - { { 10, 20, 40, 50 }, - "14+10", 34, 44, NO_ERROR }, - { { 10, 20, 40, 50 }, - "14-10", 14, 24, NO_ERROR }, - { { 10, 20, 40, 50 }, - "8/2", 14, 24, NO_ERROR }, - { { 10, 20, 40, 50 }, - "7.0/3.5", 12, 22, NO_ERROR }, - { { 10, 20, 40, 50 }, - "12.1/3", 14, 24, NO_ERROR }, - { { 10, 20, 40, 50 }, - "12/2.95", 14, 24, NO_ERROR }, - /* Binary expressions with parentheses */ - { { 10, 20, 40, 50 }, - "(14) * (10)", 150, 160, NO_ERROR }, - { { 10, 20, 40, 50 }, - "(14) + (10)", 34, 44, NO_ERROR }, - { { 10, 20, 40, 50 }, - "(14) - (10)", 14, 24, NO_ERROR }, - { { 10, 20, 40, 50 }, - "(8) / (2)", 14, 24, NO_ERROR }, - { { 10, 20, 40, 50 }, - "(7.0) / (3.5)", 12, 22, NO_ERROR }, - { { 10, 20, 40, 50 }, - "(12.1) / (3)", 14, 24, NO_ERROR }, - { { 10, 20, 40, 50 }, - "(12) / (2.95)", 14, 24, NO_ERROR }, - /* Lots of extra parentheses */ - { { 10, 20, 40, 50 }, - "(((14)) * ((10)))", 150, 160, NO_ERROR }, - { { 10, 20, 40, 50 }, - "((((14)))) + ((((((((10))))))))", 34, 44, NO_ERROR }, - { { 10, 20, 40, 50 }, - "((((((((((14 - 10))))))))))", 14, 24, NO_ERROR }, - /* Binary expressions with variables */ - { { 10, 20, 40, 50 }, - "2 * width", 90, 100, NO_ERROR }, - { { 10, 20, 40, 50 }, - "2 * height", 110, 120, NO_ERROR }, - { { 10, 20, 40, 50 }, - "width - 10", 40, 50, NO_ERROR }, - { { 10, 20, 40, 50 }, - "height / 2", 35, 45, NO_ERROR }, - /* More than two operands */ - { { 10, 20, 40, 50 }, - "8 / 2 + 5", 19, 29, NO_ERROR }, - { { 10, 20, 40, 50 }, - "8 * 2 + 5", 31, 41, NO_ERROR }, - { { 10, 20, 40, 50 }, - "8 + 2 * 5", 28, 38, NO_ERROR }, - { { 10, 20, 40, 50 }, - "8 + 8 / 2", 22, 32, NO_ERROR }, - { { 10, 20, 40, 50 }, - "14 / (2 + 5)", 12, 22, NO_ERROR }, - { { 10, 20, 40, 50 }, - "8 * (2 + 5)", 66, 76, NO_ERROR }, - { { 10, 20, 40, 50 }, - "(8 + 2) * 5", 60, 70, NO_ERROR }, - { { 10, 20, 40, 50 }, - "(8 + 8) / 2", 18, 28, NO_ERROR }, - /* Errors */ - { { 10, 20, 40, 50 }, - "2 * foo", 0, 0, META_THEME_ERROR_UNKNOWN_VARIABLE }, - { { 10, 20, 40, 50 }, - "2 *", 0, 0, META_THEME_ERROR_FAILED }, - { { 10, 20, 40, 50 }, - "- width", 0, 0, META_THEME_ERROR_FAILED }, - { { 10, 20, 40, 50 }, - "5 % 1.0", 0, 0, META_THEME_ERROR_MOD_ON_FLOAT }, - { { 10, 20, 40, 50 }, - "1.0 % 5", 0, 0, META_THEME_ERROR_MOD_ON_FLOAT }, - { { 10, 20, 40, 50 }, - "! * 2", 0, 0, META_THEME_ERROR_BAD_CHARACTER }, - { { 10, 20, 40, 50 }, - " ", 0, 0, META_THEME_ERROR_FAILED }, - { { 10, 20, 40, 50 }, - "() () (( ) ()) ((()))", 0, 0, META_THEME_ERROR_FAILED }, - { { 10, 20, 40, 50 }, - "(*) () ((/) ()) ((()))", 0, 0, META_THEME_ERROR_FAILED }, - { { 10, 20, 40, 50 }, - "2 * 5 /", 0, 0, META_THEME_ERROR_FAILED }, - { { 10, 20, 40, 50 }, - "+ 2 * 5", 0, 0, META_THEME_ERROR_FAILED }, - { { 10, 20, 40, 50 }, - "+ 2 * 5", 0, 0, META_THEME_ERROR_FAILED } -}; - -static void -run_position_expression_tests (void) -{ -#if 0 - int i; - MetaPositionExprEnv env; - - i = 0; - while (i < (int) G_N_ELEMENTS (position_expression_tests)) - { - GError *err; - gboolean retval; - const PositionExpressionTest *test; - PosToken *tokens; - int n_tokens; - int x, y; - - test = &position_expression_tests[i]; - - if (g_getenv ("META_PRINT_TESTS") != NULL) - g_print ("Test expression: \"%s\" expecting x = %d y = %d", - test->expr, test->expected_x, test->expected_y); - - err = NULL; - - env.rect = meta_rect (test->rect.x, test->rect.y, - test->rect.width, test->rect.height); - env.object_width = -1; - env.object_height = -1; - env.left_width = 0; - env.right_width = 0; - env.top_height = 0; - env.bottom_height = 0; - env.title_width = 5; - env.title_height = 5; - env.icon_width = 32; - env.icon_height = 32; - env.mini_icon_width = 16; - env.mini_icon_height = 16; - env.theme = NULL; - - if (err == NULL) - { - retval = meta_parse_position_expression (tokens, n_tokens, - &env, - &x, &y, - &err); - } - - if (retval && err) - g_error (_("position expression test returned TRUE but set error")); - if (!retval && err == NULL) - g_error (_("position expression test returned FALSE but didn't set error")); - if (((int) test->expected_error) != NO_ERROR) - { - if (err == NULL) - g_error (_("Error was expected but none given")); - if (err->code != (int) test->expected_error) - g_error (_("Error %d was expected but %d given"), - test->expected_error, err->code); - } - else - { - if (err) - g_error (_("Error not expected but one was returned: %s"), - err->message); - - if (x != test->expected_x) - g_error (_("x value was %d, %d was expected"), x, test->expected_x); - - if (y != test->expected_y) - g_error (_("y value was %d, %d was expected"), y, test->expected_y); - } - - if (err) - g_error_free (err); - - meta_pos_tokens_free (tokens, n_tokens); - ++i; - } -#endif -} - -#if 0 -static void -run_position_expression_timings (void) -{ - int i; - int iters; - clock_t start; - clock_t end; - MetaPositionExprEnv env; - -#define ITERATIONS 100000 - - start = clock (); - - iters = 0; - i = 0; - while (iters < ITERATIONS) - { - const PositionExpressionTest *test; - int x, y; - - test = &position_expression_tests[i]; - - env.x = test->rect.x; - env.y = test->rect.y; - env.width = test->rect.width; - env.height = test->rect.height; - env.object_width = -1; - env.object_height = -1; - env.left_width = 0; - env.right_width = 0; - env.top_height = 0; - env.bottom_height = 0; - env.title_width = 5; - env.title_height = 5; - env.icon_width = 32; - env.icon_height = 32; - env.mini_icon_width = 16; - env.mini_icon_height = 16; - env.theme = NULL; - - meta_parse_position_expression (test->expr, - &env, - &x, &y, NULL); - - ++iters; - ++i; - if (i == G_N_ELEMENTS (position_expression_tests)) - i = 0; - } - - end = clock (); - - g_print (_("%d coordinate expressions parsed in %g seconds (%g seconds average)\n"), - ITERATIONS, - ((double)end - (double)start) / CLOCKS_PER_SEC, - ((double)end - (double)start) / CLOCKS_PER_SEC / (double) ITERATIONS); - -} -#endif diff --git a/src/ui/theme.c b/src/ui/theme.c index c841a0c35..fb11f0d54 100644 --- a/src/ui/theme.c +++ b/src/ui/theme.c @@ -5071,8 +5071,7 @@ meta_theme_set_current (const char *name, meta_topic (META_DEBUG_THEMES, "Setting current theme to \"%s\"\n", name); - if (!force_reload && - meta_current_theme && + if (meta_current_theme && strcmp (name, meta_current_theme->name) == 0) return; diff --git a/src/ui/ui.c b/src/ui/ui.c index 265ecfcca..fc6fb4dc2 100644 --- a/src/ui/ui.c +++ b/src/ui/ui.c @@ -769,10 +769,9 @@ meta_ui_theme_get_frame_borders (MetaUI *ui, } void -meta_ui_set_current_theme (const char *name, - gboolean force_reload) +meta_ui_set_current_theme (const char *name) { - meta_theme_set_current (name, force_reload); + meta_theme_set_current (name); meta_invalidate_default_icons (); } diff --git a/src/ui/ui.h b/src/ui/ui.h index 2ea3ca12c..e397c43d0 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -154,8 +154,7 @@ gboolean meta_ui_window_should_not_cause_focus (Display *xdisplay, char* meta_text_property_to_utf8 (Display *xdisplay, const XTextProperty *prop); -void meta_ui_set_current_theme (const char *name, - gboolean force_reload); +void meta_ui_set_current_theme (const char *name); gboolean meta_ui_have_a_theme (void); /* Not a real key symbol but means "key above the tab key"; this is diff --git a/src/wm-tester/.cvsignore b/src/wm-tester/.cvsignore deleted file mode 100644 index 0bca29e86..000000000 --- a/src/wm-tester/.cvsignore +++ /dev/null @@ -1,7 +0,0 @@ -Makefile -Makefile.in -focus-window -test-gravity -test-resizing -wm-tester -test-size-hints diff --git a/src/wm-tester/Makefile.am b/src/wm-tester/Makefile.am deleted file mode 100644 index 2bb29d96e..000000000 --- a/src/wm-tester/Makefile.am +++ /dev/null @@ -1,33 +0,0 @@ - -INCLUDES=@MUTTER_CFLAGS@ - -wm_tester_SOURCES= \ - main.c - -test_gravity_SOURCES= \ - test-gravity.c - -focus_window_SOURCES= \ - focus-window.c - -test_resizing_SOURCES= \ - test-resizing.c - -test_size_hints_SOURCES= \ - test-size-hints.c - -test_attached_SOURCES= \ - test-attached.c - -test_focus_SOURCES= \ - test-focus.c - -noinst_PROGRAMS=wm-tester test-gravity test-resizing focus-window test-size-hints test-attached test-focus - -wm_tester_LDADD= @MUTTER_LIBS@ -test_gravity_LDADD= @MUTTER_LIBS@ -test_resizing_LDADD= @MUTTER_LIBS@ -test_size_hints_LDADD= @MUTTER_LIBS@ -focus_window_LDADD= @MUTTER_LIBS@ -test_attached_LDADD= @MUTTER_LIBS@ -test_focus_LDADD= @MUTTER_LIBS@ diff --git a/src/wm-tester/focus-window.c b/src/wm-tester/focus-window.c deleted file mode 100644 index dc33bd25d..000000000 --- a/src/wm-tester/focus-window.c +++ /dev/null @@ -1,37 +0,0 @@ -#include <X11/Xlib.h> -#include <X11/Xutil.h> -#include <stdio.h> -#include <stdlib.h> - -int main (int argc, char **argv) -{ - Display *d; - Window w; - const char *w_str; - char *end; - - if (argc != 2) - { - fprintf (stderr, "Usage: focus-window WINDOWID\n"); - exit (1); - } - - d = XOpenDisplay (NULL); - - w_str = argv[1]; - end = NULL; - - w = strtoul (w_str, &end, 16); - if (end == w_str) - { - fprintf (stderr, "Usage: focus-window WINDOWID\n"); - exit (1); - } - - printf ("Setting input focus to 0x%lx\n", w); - XSetInputFocus (d, w, RevertToPointerRoot, CurrentTime); - XFlush (d); - - return 0; -} - diff --git a/src/wm-tester/main.c b/src/wm-tester/main.c deleted file mode 100644 index d9b27b4d3..000000000 --- a/src/wm-tester/main.c +++ /dev/null @@ -1,245 +0,0 @@ -/* WM tester main() */ - -/* - * Copyright (C) 2001 Havoc Pennington - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#include <gtk/gtk.h> - -#include <stdlib.h> -#include <sys/types.h> -#include <stdio.h> -#include <string.h> -#include <unistd.h> - -static void set_up_the_evil (void); -static void set_up_icon_windows (void); - -static void -usage (void) -{ - g_print ("wm-tester [--evil] [--icon-windows]\n"); - exit (0); -} - -int -main (int argc, char **argv) -{ - int i; - gboolean do_evil; - gboolean do_icon_windows; - - gtk_init (&argc, &argv); - - do_evil = FALSE; - do_icon_windows = FALSE; - - i = 1; - while (i < argc) - { - const char *arg = argv[i]; - - if (strcmp (arg, "--help") == 0 || - strcmp (arg, "-h") == 0 || - strcmp (arg, "-?") == 0) - usage (); - else if (strcmp (arg, "--evil") == 0) - do_evil = TRUE; - else if (strcmp (arg, "--icon-windows") == 0) - do_icon_windows = TRUE; - else - usage (); - - ++i; - } - - /* Be sure some option was provided */ - if (! (do_evil || do_icon_windows)) - return 1; - - if (do_evil) - set_up_the_evil (); - - if (do_icon_windows) - set_up_icon_windows (); - - gtk_main (); - - return 0; -} - -static GSList *evil_windows = NULL; - -static gint -evil_timeout (gpointer data) -{ - int i; - int n_windows; - int len; - int create_count; - int destroy_count; - - len = g_slist_length (evil_windows); - - if (len > 35) - { - create_count = 2; - destroy_count = 5; - } - else - { - create_count = 5; - destroy_count = 5; - } - - /* Create some windows */ - n_windows = g_random_int_range (0, create_count); - - i = 0; - while (i < n_windows) - { - GtkWidget *w; - GtkWidget *c; - int t; - GtkWidget *parent; - - w = gtk_window_new (GTK_WINDOW_TOPLEVEL); - - gtk_window_move (GTK_WINDOW (w), - g_random_int_range (0, - gdk_screen_width ()), - g_random_int_range (0, - gdk_screen_height ())); - - parent = NULL; - - /* set transient for random window (may create all kinds of weird cycles) */ - if (len > 0) - { - t = g_random_int_range (- (len / 3), len); - if (t >= 0) - { - parent = g_slist_nth_data (evil_windows, t); - - if (parent != NULL) - gtk_window_set_transient_for (GTK_WINDOW (w), GTK_WINDOW (parent)); - } - } - - if (parent != NULL) - c = gtk_button_new_with_label ("Evil Transient!"); - else - c = gtk_button_new_with_label ("Evil Window!"); - gtk_container_add (GTK_CONTAINER (w), c); - - gtk_widget_show_all (w); - - evil_windows = g_slist_prepend (evil_windows, w); - - ++i; - } - - /* Destroy some windows */ - if (len > destroy_count) - { - n_windows = g_random_int_range (0, destroy_count); - i = 0; - while (i < n_windows) - { - GtkWidget *w; - - w = g_slist_nth_data (evil_windows, - g_random_int_range (0, len)); - if (w) - { - --len; - evil_windows = g_slist_remove (evil_windows, w); - gtk_widget_destroy (w); - } - - ++i; - } - } - - return TRUE; -} - -static void -set_up_the_evil (void) -{ - g_timeout_add (400, evil_timeout, NULL); -} - -static void -set_up_icon_windows (void) -{ - int i; - int n_windows; - - /* Create some windows */ - n_windows = 9; - - i = 0; - while (i < n_windows) - { - GtkWidget *w; - GtkWidget *c; - GList *icons; - GdkPixbuf *pix; - - w = gtk_window_new (GTK_WINDOW_TOPLEVEL); - c = gtk_button_new_with_label ("Icon window"); - gtk_container_add (GTK_CONTAINER (w), c); - - icons = NULL; - - pix = gtk_widget_render_icon (w, - GTK_STOCK_SAVE, - GTK_ICON_SIZE_LARGE_TOOLBAR, - NULL); - - icons = g_list_append (icons, pix); - - if (i % 2) - { - pix = gtk_widget_render_icon (w, - GTK_STOCK_SAVE, - GTK_ICON_SIZE_DIALOG, - NULL); - icons = g_list_append (icons, pix); - } - - if (i % 3) - { - pix = gtk_widget_render_icon (w, - GTK_STOCK_SAVE, - GTK_ICON_SIZE_MENU, - NULL); - icons = g_list_append (icons, pix); - } - - gtk_window_set_icon_list (GTK_WINDOW (w), icons); - - g_list_foreach (icons, (GFunc) g_object_unref, NULL); - g_list_free (icons); - - gtk_widget_show_all (w); - - ++i; - } -} diff --git a/src/wm-tester/test-attached.c b/src/wm-tester/test-attached.c deleted file mode 100644 index c27036b55..000000000 --- a/src/wm-tester/test-attached.c +++ /dev/null @@ -1,100 +0,0 @@ -#include <gtk/gtk.h> - -enum { - DESTROY_PARENT, - DETACH, - ATTACH_1, - ATTACH_2 -}; - -GtkWidget *window1, *window2; - -static void -dialog_response (GtkDialog *dialog, int response, gpointer user_data) -{ - if (response == DESTROY_PARENT) - { - GtkWidget *window = GTK_WIDGET (gtk_window_get_transient_for (GTK_WINDOW (dialog))); - - if (window == window1) - { - gtk_dialog_set_response_sensitive (dialog, ATTACH_1, FALSE); - window1 = NULL; - } - else - { - gtk_dialog_set_response_sensitive (dialog, ATTACH_2, FALSE); - window2 = NULL; - } - - gtk_dialog_set_response_sensitive (dialog, DESTROY_PARENT, FALSE); - gtk_dialog_set_response_sensitive (dialog, DETACH, FALSE); - gtk_widget_destroy (window); - } - else if (response == DETACH) - { - gtk_window_set_transient_for (GTK_WINDOW (dialog), NULL); - gtk_dialog_set_response_sensitive (dialog, DESTROY_PARENT, FALSE); - gtk_dialog_set_response_sensitive (dialog, DETACH, FALSE); - gtk_dialog_set_response_sensitive (dialog, ATTACH_1, window1 != NULL); - gtk_dialog_set_response_sensitive (dialog, ATTACH_2, window2 != NULL); - } - else if (response == ATTACH_1) - { - gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (window1)); - gtk_dialog_set_response_sensitive (dialog, DESTROY_PARENT, TRUE); - gtk_dialog_set_response_sensitive (dialog, DETACH, TRUE); - gtk_dialog_set_response_sensitive (dialog, ATTACH_1, FALSE); - gtk_dialog_set_response_sensitive (dialog, ATTACH_2, window2 != NULL); - } - else if (response == ATTACH_2) - { - gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (window2)); - gtk_dialog_set_response_sensitive (dialog, DESTROY_PARENT, TRUE); - gtk_dialog_set_response_sensitive (dialog, DETACH, TRUE); - gtk_dialog_set_response_sensitive (dialog, ATTACH_1, window1 != NULL); - gtk_dialog_set_response_sensitive (dialog, ATTACH_2, FALSE); - } - else if (response == GTK_RESPONSE_CLOSE) - gtk_main_quit (); -} - -int -main (int argc, char **argv) -{ - GtkWidget *dialog; - - gtk_init (&argc, &argv); - - window1 = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_window_set_title (GTK_WINDOW (window1), "Parent 1"); - gtk_widget_show (window1); - - window2 = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_window_set_title (GTK_WINDOW (window2), "Parent 2"); - gtk_widget_show (window2); - - dialog = gtk_dialog_new_with_buttons ("Child", - NULL, - GTK_DIALOG_MODAL, - "Destroy Parent", - DESTROY_PARENT, - "Detach", - DETACH, - "Attach to 1", - ATTACH_1, - "Attach to 2", - ATTACH_2, - GTK_STOCK_QUIT, - GTK_RESPONSE_CLOSE, - NULL); - gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), DESTROY_PARENT, FALSE); - gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), DETACH, FALSE); - - g_signal_connect (dialog, "response", G_CALLBACK (dialog_response), NULL); - gtk_widget_show (dialog); - - gtk_main (); - - return 0; -} diff --git a/src/wm-tester/test-focus.c b/src/wm-tester/test-focus.c deleted file mode 100644 index 2ff59c5a5..000000000 --- a/src/wm-tester/test-focus.c +++ /dev/null @@ -1,362 +0,0 @@ -#include <gtk/gtk.h> -#include <gdk/gdkx.h> -#include <X11/Xatom.h> - -GtkWidget *main_window; -GtkWidget *noinput_window, *passive_window, *local_window; -GtkWidget *global_window, *lame_window, *grabby_window, *dying_window; - -static void -clear_on_destroy (GtkWidget *widget, gpointer user_data) -{ - GtkWidget **widget_pointer = user_data; - - *widget_pointer = NULL; -} - -static void -disable_take_focus (GtkWidget *window) -{ - GdkDisplay *display; - GdkWindow *gdkwindow; - Atom *protocols, wm_take_focus; - int n_protocols, i; - - gtk_widget_realize (window); - gdkwindow = gtk_widget_get_window (window); - display = gdk_window_get_display (gdkwindow); - - wm_take_focus = gdk_x11_get_xatom_by_name_for_display (display, "WM_TAKE_FOCUS"); - XGetWMProtocols (GDK_DISPLAY_XDISPLAY (display), - GDK_WINDOW_XID (gdkwindow), - &protocols, &n_protocols); - for (i = 0; i < n_protocols; i++) - { - if (protocols[i] == wm_take_focus) - { - protocols[i] = protocols[n_protocols - 1]; - n_protocols--; - break; - } - } - XSetWMProtocols (GDK_DISPLAY_XDISPLAY (display), - GDK_WINDOW_XID (gdkwindow), - protocols, n_protocols); - XFree (protocols); -} - -static void -clear_input_hint (GtkWidget *window) -{ - /* This needs to be called after gtk_widget_show, otherwise - * GTK+ will overwrite it. */ - GdkWindow *gdkwindow = gtk_widget_get_window (window); - XWMHints *wm_hints; - - wm_hints = XGetWMHints (GDK_DISPLAY_XDISPLAY (gdk_window_get_display (gdkwindow)), - GDK_WINDOW_XID (gdkwindow)); - - wm_hints->flags |= InputHint; - wm_hints->input = False; - - XSetWMHints (GDK_DISPLAY_XDISPLAY (gdk_window_get_display (gdkwindow)), - GDK_WINDOW_XID (gdkwindow), - wm_hints); - - XFree (wm_hints); -} - -static void -active_notify (GObject *obj, - GParamSpec *pspec, - gpointer user_data) -{ - GtkLabel *label = user_data; - - if (gtk_window_is_active (GTK_WINDOW (obj))) - gtk_label_set_text (label, "Focused"); - else - gtk_label_set_text (label, "Not focused"); -} - -static void -make_focused_label (GtkWidget *toplevel, - GtkWidget *parent) -{ - GtkWidget *label; - - label = gtk_label_new (""); - gtk_widget_show (label); - - gtk_container_add (GTK_CONTAINER (parent), label); - - g_signal_connect (toplevel, "notify::is-active", - G_CALLBACK (active_notify), label); - active_notify (G_OBJECT (toplevel), NULL, label); -} - -static void -setup_test_dialog (GtkWidget *toplevel) -{ - make_focused_label (toplevel, toplevel); - gtk_widget_set_size_request (toplevel, 200, 200); -} - -static void -noinput_clicked (GtkButton *button, gpointer user_data) -{ - if (noinput_window) - gtk_window_present_with_time (GTK_WINDOW (noinput_window), gtk_get_current_event_time ()); - else - { - noinput_window = g_object_new (GTK_TYPE_WINDOW, - "type", GTK_WINDOW_TOPLEVEL, - "title", "No Input", - "accept-focus", FALSE, - NULL); - setup_test_dialog (noinput_window); - g_signal_connect (noinput_window, "destroy", - G_CALLBACK (clear_on_destroy), &noinput_window); - disable_take_focus (noinput_window); - gtk_widget_show (noinput_window); - } -} - -static void -passive_clicked (GtkButton *button, gpointer user_data) -{ - if (passive_window) - gtk_window_present_with_time (GTK_WINDOW (passive_window), gtk_get_current_event_time ()); - else - { - passive_window = g_object_new (GTK_TYPE_WINDOW, - "type", GTK_WINDOW_TOPLEVEL, - "title", "Passive Input", - "accept-focus", TRUE, - NULL); - setup_test_dialog (passive_window); - g_signal_connect (passive_window, "destroy", - G_CALLBACK (clear_on_destroy), &passive_window); - disable_take_focus (passive_window); - gtk_widget_show (passive_window); - } -} - -static void -local_clicked (GtkButton *button, gpointer user_data) -{ - if (local_window) - gtk_window_present_with_time (GTK_WINDOW (local_window), gtk_get_current_event_time ()); - else - { - local_window = g_object_new (GTK_TYPE_WINDOW, - "type", GTK_WINDOW_TOPLEVEL, - "title", "Locally Active Input", - "accept-focus", TRUE, - NULL); - setup_test_dialog (local_window); - g_signal_connect (local_window, "destroy", - G_CALLBACK (clear_on_destroy), &local_window); - gtk_widget_show (local_window); - } -} - -static void -global_clicked (GtkButton *button, gpointer user_data) -{ - if (global_window) - gtk_window_present_with_time (GTK_WINDOW (global_window), gtk_get_current_event_time ()); - else - { - /* gtk will only process WM_TAKE_FOCUS messages if accept-focus - * is TRUE. So we set that property and then manually clear the - * Input WMHint. - */ - global_window = g_object_new (GTK_TYPE_WINDOW, - "type", GTK_WINDOW_TOPLEVEL, - "title", "Globally Active Input", - "accept-focus", TRUE, - NULL); - setup_test_dialog (global_window); - g_signal_connect (global_window, "destroy", - G_CALLBACK (clear_on_destroy), &global_window); - gtk_widget_show (global_window); - clear_input_hint (global_window); - } -} - -static void -lame_clicked (GtkButton *button, gpointer user_data) -{ - if (lame_window) - gtk_window_present_with_time (GTK_WINDOW (lame_window), gtk_get_current_event_time ()); - else - { - lame_window = g_object_new (GTK_TYPE_WINDOW, - "type", GTK_WINDOW_TOPLEVEL, - "title", "Lame Globally Active Input", - "accept-focus", FALSE, - NULL); - setup_test_dialog (lame_window); - g_signal_connect (lame_window, "destroy", - G_CALLBACK (clear_on_destroy), &lame_window); - gtk_widget_show (lame_window); - } -} - -static void -grabby_active_changed (GObject *object, GParamSpec *param, gpointer user_data) -{ - if (gtk_window_is_active (GTK_WINDOW (grabby_window))) - { - GdkWindow *gdkwindow = gtk_widget_get_window (grabby_window); - guint32 now = gdk_x11_get_server_time (gdkwindow); - - gtk_window_present_with_time (GTK_WINDOW (main_window), now - 1); - XSetInputFocus (GDK_DISPLAY_XDISPLAY (gdk_window_get_display (gdkwindow)), - GDK_WINDOW_XID (gdkwindow), - RevertToParent, - now); - } -} - -static void -grabby_clicked (GtkButton *button, gpointer user_data) -{ - if (grabby_window) - gtk_window_present_with_time (GTK_WINDOW (grabby_window), gtk_get_current_event_time ()); - else - { - grabby_window = g_object_new (GTK_TYPE_WINDOW, - "type", GTK_WINDOW_TOPLEVEL, - "title", "Focus-grabbing Window", - "accept-focus", TRUE, - /* Because mutter maps windows - * asynchronously, our trick won't - * work if we try to do it when the - * window is first mapped. - */ - "focus-on-map", FALSE, - NULL); - setup_test_dialog (grabby_window); - g_signal_connect (grabby_window, "destroy", - G_CALLBACK (clear_on_destroy), &grabby_window); - g_signal_connect (grabby_window, "notify::is-active", - G_CALLBACK (grabby_active_changed), NULL); - gtk_widget_show (grabby_window); - } -} - -static void -dying_clicked (GtkButton *button, gpointer user_data) -{ - if (dying_window) - { - gtk_window_present_with_time (GTK_WINDOW (dying_window), gtk_get_current_event_time ()); - gtk_widget_destroy (dying_window); - } - else - { - GtkWidget *label; - - dying_window = g_object_new (GTK_TYPE_WINDOW, - "type", GTK_WINDOW_TOPLEVEL, - "title", "Dying Window", - "accept-focus", TRUE, - /* As with grabby window */ - "focus-on-map", FALSE, - NULL); - setup_test_dialog (dying_window); - g_signal_connect (dying_window, "destroy", - G_CALLBACK (clear_on_destroy), &dying_window); - - label = gtk_label_new ("Click button again to test"); - gtk_container_add (GTK_CONTAINER (dying_window), label); - gtk_widget_set_size_request (dying_window, 200, 200); - - gtk_widget_show_all (dying_window); - } -} - -static void -main_window_destroyed (GtkWidget *widget, gpointer user_data) -{ - gtk_main_quit (); -} - -int -main (int argc, char **argv) -{ - GtkWidget *vbox, *button; - - gtk_init (&argc, &argv); - - main_window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_window_set_title (GTK_WINDOW (main_window), "Focus Tester"); - - vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8); - gtk_box_set_homogeneous (GTK_BOX (vbox), 8); - gtk_container_set_border_width (GTK_CONTAINER (vbox), 8); - gtk_container_add (GTK_CONTAINER (main_window), vbox); - - make_focused_label (main_window, vbox); - - /* ICCCM "No Input" mode; Input hint False, WM_TAKE_FOCUS absent */ - button = gtk_button_new_with_label ("No Input Window"); - g_signal_connect (button, "clicked", G_CALLBACK (noinput_clicked), NULL); - gtk_container_add (GTK_CONTAINER (vbox), button); - - /* ICCCM "Passive" mode; Input hint True, WM_TAKE_FOCUS absent */ - button = gtk_button_new_with_label ("Passive Input Window"); - g_signal_connect (button, "clicked", G_CALLBACK (passive_clicked), NULL); - gtk_container_add (GTK_CONTAINER (vbox), button); - - /* ICCCM "Locally Active" mode; Input hint True, WM_TAKE_FOCUS present. - * This is the behavior of GtkWindows with accept_focus==TRUE. - */ - button = gtk_button_new_with_label ("Locally Active Window"); - g_signal_connect (button, "clicked", G_CALLBACK (local_clicked), NULL); - gtk_container_add (GTK_CONTAINER (vbox), button); - - /* ICCCM "Globally Active" mode; Input hint False, WM_TAKE_FOCUS present, - * and the window responds to WM_TAKE_FOCUS by calling XSetInputFocus. - */ - button = gtk_button_new_with_label ("Globally Active Window"); - g_signal_connect (button, "clicked", G_CALLBACK (global_clicked), NULL); - gtk_container_add (GTK_CONTAINER (vbox), button); - - /* "Lame" Globally Active mode; like "Globally Active", except that - * the window does not respond to WM_TAKE_FOCUS. This is the - * behavior of GtkWindows with accept_focus==FALSE. - */ - button = gtk_button_new_with_label ("Globally Lame Window"); - g_signal_connect (button, "clicked", G_CALLBACK (lame_clicked), NULL); - gtk_container_add (GTK_CONTAINER (vbox), button); - - /* "Grabby" window; when you activate the window, it asks the wm to - * focus the main window, but then forcibly grabs focus back with - * a newer timestamp, causing the wm to be temporarily confused - * about what window is focused and triggering the "Earlier attempt - * to focus ... failed" codepath. - */ - button = gtk_button_new_with_label ("Grabby Window"); - g_signal_connect (button, "clicked", G_CALLBACK (grabby_clicked), NULL); - gtk_container_add (GTK_CONTAINER (vbox), button); - - /* "Dying" window; we create the window on the first click, then - * activate it and destroy it on the second click, causing mutter to - * do an XSetInputFocus but not receive the corresponding FocusIn. - */ - button = gtk_button_new_with_label ("Dying Window"); - g_signal_connect (button, "clicked", G_CALLBACK (dying_clicked), NULL); - gtk_container_add (GTK_CONTAINER (vbox), button); - - gtk_widget_show_all (main_window); - - g_signal_connect (main_window, "destroy", - G_CALLBACK (main_window_destroyed), NULL); - - gtk_main (); - - return 0; -} diff --git a/src/wm-tester/test-gravity.c b/src/wm-tester/test-gravity.c deleted file mode 100644 index 8e5b581c7..000000000 --- a/src/wm-tester/test-gravity.c +++ /dev/null @@ -1,308 +0,0 @@ -#include <X11/Xlib.h> -#include <X11/Xutil.h> -#include <stdio.h> -#include <string.h> - -static int gravities[10] = { - NorthWestGravity, - NorthGravity, - NorthEastGravity, - WestGravity, - CenterGravity, - EastGravity, - SouthWestGravity, - SouthGravity, - SouthEastGravity, - StaticGravity -}; - -typedef struct -{ - int x, y, width, height; -} Rectangle; - -static Window windows[10]; -static int doubled[10] = { 0, }; -static Rectangle window_rects[10]; - -#define WINDOW_WIDTH 100 -#define WINDOW_HEIGHT 100 - -static int x_offset[3] = { 0, - WINDOW_WIDTH/2, -WINDOW_WIDTH }; -static int y_offset[3] = { 0, - WINDOW_HEIGHT/2, -WINDOW_HEIGHT }; -static double screen_x_fraction[3] = { 0, 0.5, 1.0 }; -static double screen_y_fraction[3] = { 0, 0.5, 1.0 }; -static int screen_width; -static int screen_height; - -static const char* -window_gravity_to_string (int gravity) -{ - switch (gravity) - { - case NorthWestGravity: - return "NorthWestGravity"; - case NorthGravity: - return "NorthGravity"; - case NorthEastGravity: - return "NorthEastGravity"; - case WestGravity: - return "WestGravity"; - case CenterGravity: - return "CenterGravity"; - case EastGravity: - return "EastGravity"; - case SouthWestGravity: - return "SouthWestGravity"; - case SouthGravity: - return "SouthGravity"; - case SouthEastGravity: - return "SouthEastGravity"; - case StaticGravity: - return "StaticGravity"; - default: - return "NorthWestGravity"; - } -} - -static void -calculate_position (int i, int doubled, int *x, int *y) -{ - if (i == 9) - { - *x = 150; - *y = 150; - } - else - { - int xoff = x_offset[i % 3]; - int yoff = y_offset[i / 3]; - if (doubled) - { - xoff *= 2; - yoff *= 2; - } - - *x = screen_x_fraction[i % 3] * screen_width + xoff; - *y = screen_y_fraction[i / 3] * screen_height + yoff; - } -} - -static int -find_window (Window window) -{ - int i; - for (i=0; i<10; i++) - { - if (windows[i] == window) - return i; - } - - return -1; -} - -typedef struct { - unsigned long flags; - unsigned long functions; - unsigned long decorations; - long input_mode; - unsigned long status; -} MotifWmHints, MwmHints; - -#define MWM_HINTS_FUNCTIONS (1L << 0) -#define MWM_HINTS_DECORATIONS (1L << 1) -#define MWM_HINTS_INPUT_MODE (1L << 2) -#define MWM_HINTS_STATUS (1L << 3) - -int main (int argc, char **argv) -{ - Display *d; - Window w; - XSizeHints hints; - int i; - int screen; - XEvent ev; - int noframes; - - if (argc > 1 && strcmp (argv[1], "--noframes") == 0) - noframes = 1; - else - noframes = 0; - - d = XOpenDisplay (NULL); - - screen = DefaultScreen (d); - screen_width = DisplayWidth (d, screen); - screen_height = DisplayHeight (d, screen); - - for (i=0; i<10; i++) - { - int x, y; - - calculate_position (i, doubled[i], &x, &y); - - w = XCreateSimpleWindow (d, RootWindow (d, screen), - x, y, WINDOW_WIDTH, WINDOW_HEIGHT, 0, - WhitePixel (d, screen), WhitePixel (d, screen)); - - windows[i] = w; - window_rects[i].x = x; - window_rects[i].y = y; - window_rects[i].width = WINDOW_WIDTH; - window_rects[i].height = WINDOW_HEIGHT; - - XSelectInput (d, w, ButtonPressMask | ExposureMask | StructureNotifyMask); - - hints.flags = USPosition | PMinSize | PMaxSize | PWinGravity; - - hints.min_width = WINDOW_WIDTH / 2; - hints.min_height = WINDOW_HEIGHT / 2; - -#if 1 - /* we constrain max size below the "doubled" size so that - * the WM will have to deal with constraints - * at the same time it's dealing with configure request - */ - hints.max_width = WINDOW_WIDTH * 2 - WINDOW_WIDTH / 2; - hints.max_height = WINDOW_HEIGHT * 2 - WINDOW_HEIGHT / 2; -#else - hints.max_width = WINDOW_WIDTH * 2 + WINDOW_WIDTH / 2; - hints.max_height = WINDOW_HEIGHT * 2 + WINDOW_HEIGHT / 2; -#endif - hints.win_gravity = gravities[i]; - - XSetWMNormalHints (d, w, &hints); - - XStoreName (d, w, window_gravity_to_string (hints.win_gravity)); - - if (noframes) - { - MotifWmHints mwm; - Atom mwm_atom; - - mwm.decorations = 0; - mwm.flags = MWM_HINTS_DECORATIONS; - - mwm_atom = XInternAtom (d, "_MOTIF_WM_HINTS", False); - - XChangeProperty (d, w, mwm_atom, mwm_atom, - 32, PropModeReplace, - (unsigned char *)&mwm, - sizeof (MotifWmHints)/sizeof (long)); - } - - XMapWindow (d, w); - } - - while (1) - { - XNextEvent (d, &ev); - - if (ev.xany.type == ConfigureNotify) - { - i = find_window (ev.xconfigure.window); - - if (i >= 0) - { - Window ignored; - - window_rects[i].width = ev.xconfigure.width; - window_rects[i].height = ev.xconfigure.height; - - XClearArea (d, windows[i], 0, 0, - ev.xconfigure.width, - ev.xconfigure.height, - True); - - if (!ev.xconfigure.send_event) - XTranslateCoordinates (d, windows[i], DefaultRootWindow (d), - 0, 0, - &window_rects[i].x, &window_rects[i].y, - &ignored); - else - { - window_rects[i].x = ev.xconfigure.x; - window_rects[i].y = ev.xconfigure.y; - } - } - } - else if (ev.xany.type == Expose) - { - i = find_window (ev.xexpose.window); - - if (i >= 0) - { - GC gc; - XGCValues values; - char buf[256]; - - values.foreground = BlackPixel (d, screen); - - gc = XCreateGC (d, windows[i], - GCForeground, &values); - - sprintf (buf, - "%d,%d", - window_rects[i].x, - window_rects[i].y); - - XDrawString (d, windows[i], gc, 10, 15, - buf, strlen (buf)); - - sprintf (buf, - "%dx%d", - window_rects[i].width, - window_rects[i].height); - - XDrawString (d, windows[i], gc, 10, 35, - buf, strlen (buf)); - - XFreeGC (d, gc); - } - } - else if (ev.xany.type == ButtonPress) - { - i = find_window (ev.xbutton.window); - - if (i >= 0) - { - /* Button 1 = move, 2 = resize, 3 = both at once */ - - if (ev.xbutton.button == Button1) - { - int x, y; - - calculate_position (i, doubled[i], &x, &y); - XMoveWindow (d, windows[i], x, y); - } - else if (ev.xbutton.button == Button2) - { - if (doubled[i]) - XResizeWindow (d, windows[i], WINDOW_WIDTH, WINDOW_HEIGHT); - else - XResizeWindow (d, windows[i], WINDOW_WIDTH*2, WINDOW_HEIGHT*2); - - doubled[i] = !doubled[i]; - } - else if (ev.xbutton.button == Button3) - { - int x, y; - - calculate_position (i, !doubled[i], &x, &y); - - if (doubled[i]) - XMoveResizeWindow (d, windows[i], x, y, WINDOW_WIDTH, WINDOW_HEIGHT); - else - XMoveResizeWindow (d, windows[i], x, y, WINDOW_WIDTH*2, WINDOW_HEIGHT*2); - - doubled[i] = !doubled[i]; - } - } - } - } - - /* This program has an infinite loop above so a return statement would - * just cause compiler warnings. - */ -} - diff --git a/src/wm-tester/test-resizing.c b/src/wm-tester/test-resizing.c deleted file mode 100644 index 616786fea..000000000 --- a/src/wm-tester/test-resizing.c +++ /dev/null @@ -1,257 +0,0 @@ -#include <X11/Xlib.h> -#include <X11/Xutil.h> -#include <stdlib.h> -#include <glib.h> - -static void -calc_rects (XRectangle *rects, int width, int height) -{ - int w = (width - 21) / 3; - int h = (height - 21) / 3; - int i; - - i = 0; - while (i < 9) - { - rects[i].width = w; - rects[i].height = h; - ++i; - } - - /* NW */ - rects[0].x = 0; - rects[0].y = 0; - - /* N */ - rects[1].x = width / 2 - w / 2; - rects[1].y = 0; - - /* NE */ - rects[2].x = width - w; - rects[2].y = 0; - - /* E */ - rects[3].x = width - w; - rects[3].y = height / 2 - h / 2; - - /* SE */ - rects[4].x = width - w; - rects[4].y = height - h; - - /* S */ - rects[5].x = width / 2 - w / 2; - rects[5].y = height - h; - - /* SW */ - rects[6].x = 0; - rects[6].y = height - h; - - /* W */ - rects[7].x = 0; - rects[7].y = height / 2 - h / 2; - - /* Center */ - rects[8].x = width / 2 - w / 2; - rects[8].y = height / 2 - h / 2; -} - -static Bool -all_events (Display *display, - XEvent *event, - XPointer arg) -{ - return True; -} - -static void -get_size (Display *d, Drawable draw, - int *xp, int *yp, int *widthp, int *heightp) -{ - int x, y; - unsigned int width=0, height=0, border=0, depth=0; - Window root; - - XGetGeometry (d, draw, &root, &x, &y, &width, &height, &border, &depth); - - if (xp) - *xp = x; - if (yp) - *yp = y; - if (widthp) - *widthp = width; - if (heightp) - *heightp = height; -} - -int -main (int argc, char **argv) -{ - Display *d; - Window w, cw; - XSizeHints hints; - int screen; - XEvent ev; - int x, y, width, height; - Pixmap pix; - GC gc; - XGCValues gc_vals; - XSetWindowAttributes set_attrs; - XWindowChanges changes; - XRectangle rects[9]; - gboolean redraw_pending; - unsigned int mask; - - d = XOpenDisplay (NULL); - - screen = DefaultScreen (d); - - /* Print some debug spew to show how StaticGravity works */ - w = XCreateSimpleWindow (d, RootWindow (d, screen), - 0, 0, 100, 100, 0, - WhitePixel (d, screen), - WhitePixel (d, screen)); - cw = XCreateSimpleWindow (d, w, - 0, 0, 100, 100, 0, - WhitePixel (d, screen), - WhitePixel (d, screen)); - set_attrs.win_gravity = StaticGravity; - - XChangeWindowAttributes (d, cw, - CWWinGravity, - &set_attrs); - - get_size (d, w, &x, &y, &width, &height); - - g_print ("Parent is %d,%d %d x %d before configuring parent\n", - x, y, width, height); - - get_size (d, cw, &x, &y, &width, &height); - - g_print ("Child is %d,%d %d x %d before configuring parent\n", - x, y, width, height); - - changes.x = 10; - changes.y = 10; - changes.width = 110; - changes.height = 110; - /* last mask wins */ - mask = CWX | CWY; - mask = CWWidth | CWHeight; - mask = CWX | CWY | CWWidth | CWHeight; - - XConfigureWindow (d, w, mask, &changes); - XSync (d, False); - - get_size (d, w, &x, &y, &width, &height); - - g_print ("Parent is %d,%d %d x %d after configuring parent\n", - x, y, width, height); - - get_size (d, cw, &x, &y, &width, &height); - - g_print ("Child is %d,%d %d x %d after configuring parent\n", - x, y, width, height); - - XDestroyWindow (d, w); - - /* The window that gets displayed */ - - x = 20; - y = 20; - width = 100; - height = 100; - - calc_rects (rects, width, height); - - w = XCreateSimpleWindow (d, RootWindow (d, screen), - x, y, width, height, 0, - WhitePixel (d, screen), - WhitePixel (d, screen)); - - set_attrs.bit_gravity = StaticGravity; - - XChangeWindowAttributes (d, w, - CWBitGravity, - &set_attrs); - - XSelectInput (d, w, - ButtonPressMask | ExposureMask | StructureNotifyMask); - - hints.flags = PMinSize; - - hints.min_width = 100; - hints.min_height = 100; - - XSetWMNormalHints (d, w, &hints); - XMapWindow (d, w); - - redraw_pending = FALSE; - while (1) - { - XNextEvent (d, &ev); - - switch (ev.xany.type) - { - case ButtonPress: - if (ev.xbutton.button == 3) - { - g_print ("Exiting on button 3 press\n"); - exit (0); - } - break; - - case ConfigureNotify: - x = ev.xconfigure.x; - y = ev.xconfigure.y; - width = ev.xconfigure.width; - height = ev.xconfigure.height; - - redraw_pending = TRUE; - break; - - case Expose: - redraw_pending = TRUE; - break; - - default: - break; - } - - /* Primitive event compression */ - if (XCheckIfEvent (d, &ev, all_events, NULL)) - { - XPutBackEvent (d, &ev); - } - else if (redraw_pending) - { - calc_rects (rects, width, height); - - pix = XCreatePixmap (d, w, width, height, - DefaultDepth (d, screen)); - - gc_vals.foreground = WhitePixel (d, screen); - - gc = XCreateGC (d, pix, GCForeground, &gc_vals); - - XFillRectangle (d, pix, gc, 0, 0, width, height); - - /* Draw rectangles at each gravity point */ - gc_vals.foreground = BlackPixel (d, screen); - XChangeGC (d, gc, GCForeground, &gc_vals); - - XFillRectangles (d, pix, gc, rects, G_N_ELEMENTS (rects)); - - XCopyArea (d, pix, w, gc, 0, 0, width, height, 0, 0); - - XFreePixmap (d, pix); - XFreeGC (d, gc); - - redraw_pending = FALSE; - } - } - - /* This program has an infinite loop above so a return statement would - * just cause compiler warnings. - */ -} - diff --git a/src/wm-tester/test-size-hints.c b/src/wm-tester/test-size-hints.c deleted file mode 100644 index 72f1b4868..000000000 --- a/src/wm-tester/test-size-hints.c +++ /dev/null @@ -1,136 +0,0 @@ -#include <X11/Xlib.h> -#include <X11/Xutil.h> -#include <stdlib.h> -#include <glib.h> - -static Bool -all_events (Display *display, - XEvent *event, - XPointer arg) -{ - return True; -} - -#if 0 -static void -get_size (Display *d, Drawable draw, - int *xp, int *yp, int *widthp, int *heightp) -{ - int x, y; - unsigned int width, height, border, depth; - Window root; - - XGetGeometry (d, draw, &root, &x, &y, &width, &height, &border, &depth); - - if (xp) - *xp = x; - if (yp) - *yp = y; - if (widthp) - *widthp = width; - if (*heightp) - *heightp = height; -} -#endif - -int -main (int argc, char **argv) -{ - Display *d; - Window zero_min_size; - XSizeHints hints; - int screen; - XEvent ev; - int x, y, width, height; - Pixmap pix; - GC gc; - XGCValues gc_vals; - gboolean redraw_pending; - - d = XOpenDisplay (NULL); - - screen = DefaultScreen (d); - - x = 0; - y = 0; - width = 100; - height = 100; - - zero_min_size = XCreateSimpleWindow (d, RootWindow (d, screen), - x, y, width, height, 0, - WhitePixel (d, screen), - WhitePixel (d, screen)); - - XSelectInput (d, zero_min_size, - ButtonPressMask | ExposureMask | StructureNotifyMask); - - hints.flags = PMinSize; - - hints.min_width = 0; - hints.min_height = 0; - - XSetWMNormalHints (d, zero_min_size, &hints); - XMapWindow (d, zero_min_size); - - redraw_pending = FALSE; - while (1) - { - XNextEvent (d, &ev); - - switch (ev.xany.type) - { - case ButtonPress: - if (ev.xbutton.button == 1) - { - g_print ("Exiting on button 1 press\n"); - exit (0); - } - break; - - case ConfigureNotify: - x = ev.xconfigure.x; - y = ev.xconfigure.y; - width = ev.xconfigure.width; - height = ev.xconfigure.height; - - redraw_pending = TRUE; - break; - - case Expose: - redraw_pending = TRUE; - break; - - default: - break; - } - - /* Primitive event compression */ - if (XCheckIfEvent (d, &ev, all_events, NULL)) - { - XPutBackEvent (d, &ev); - } - else if (redraw_pending) - { - pix = XCreatePixmap (d, zero_min_size, width, height, - DefaultDepth (d, screen)); - - gc_vals.foreground = WhitePixel (d, screen); - - gc = XCreateGC (d, pix, GCForeground, &gc_vals); - - XFillRectangle (d, pix, gc, 0, 0, width, height); - - XCopyArea (d, pix, zero_min_size, gc, 0, 0, width, height, 0, 0); - - XFreePixmap (d, pix); - XFreeGC (d, gc); - - redraw_pending = FALSE; - } - } - - /* This program has an infinite loop above so a return statement would - * just cause compiler warnings. - */ -} - |