From ddaceb232c8b537a7d29a9708928d3a3671b98e5 Mon Sep 17 00:00:00 2001 From: haxar Date: Tue, 21 Feb 2012 20:13:04 -0800 Subject: gsd to msd complete rename patch by NiceandGently; code changes commit --- plugins/common/Makefile.am | 10 ++-- plugins/common/gsd-keygrab.c | 24 ++++---- plugins/common/gsd-keygrab.h | 6 +- plugins/common/gsd-osd-window.c | 128 ++++++++++++++++++++-------------------- plugins/common/gsd-osd-window.h | 50 ++++++++-------- 5 files changed, 109 insertions(+), 109 deletions(-) (limited to 'plugins/common') diff --git a/plugins/common/Makefile.am b/plugins/common/Makefile.am index 447d02d..3733a90 100644 --- a/plugins/common/Makefile.am +++ b/plugins/common/Makefile.am @@ -4,10 +4,10 @@ noinst_LTLIBRARIES = libcommon.la libcommon_la_SOURCES = \ eggaccelerators.c \ eggaccelerators.h \ - gsd-keygrab.c \ - gsd-keygrab.h \ - gsd-osd-window.c \ - gsd-osd-window.h + msd-keygrab.c \ + msd-keygrab.h \ + msd-osd-window.c \ + msd-osd-window.h libcommon_la_CPPFLAGS = \ $(AM_CPPFLAGS) @@ -17,7 +17,7 @@ libcommon_la_CFLAGS = \ $(AM_CFLAGS) libcommon_la_LDFLAGS = \ - $(GSD_PLUGIN_LDFLAGS) $(X11_LIBS) + $(MSD_PLUGIN_LDFLAGS) $(X11_LIBS) libcommon_la_LIBADD = \ $(SETTINGS_PLUGIN_LIBS) diff --git a/plugins/common/gsd-keygrab.c b/plugins/common/gsd-keygrab.c index d94fd29..7a16f4e 100644 --- a/plugins/common/gsd-keygrab.c +++ b/plugins/common/gsd-keygrab.c @@ -32,25 +32,25 @@ #include "eggaccelerators.h" -#include "gsd-keygrab.h" +#include "msd-keygrab.h" /* these are the mods whose combinations are ignored by the keygrabbing code */ -static GdkModifierType gsd_ignored_mods = 0; +static GdkModifierType msd_ignored_mods = 0; /* these are the ones we actually use for global keys, we always only check * for these set */ -static GdkModifierType gsd_used_mods = 0; +static GdkModifierType msd_used_mods = 0; static void setup_modifiers (void) { - if (gsd_used_mods == 0 || gsd_ignored_mods == 0) { + if (msd_used_mods == 0 || msd_ignored_mods == 0) { GdkModifierType dynmods; /* default modifiers */ - gsd_ignored_mods = \ + msd_ignored_mods = \ 0x2000 /*Xkb modifier*/ | GDK_LOCK_MASK | GDK_HYPER_MASK; - gsd_used_mods = \ + msd_used_mods = \ GDK_SHIFT_MASK | GDK_CONTROL_MASK |\ GDK_MOD1_MASK | GDK_MOD2_MASK | GDK_MOD3_MASK | GDK_MOD4_MASK |\ GDK_MOD5_MASK | GDK_SUPER_MASK | GDK_META_MASK; @@ -62,8 +62,8 @@ setup_modifiers (void) EGG_VIRTUAL_NUM_LOCK_MASK, &dynmods); - gsd_ignored_mods |= dynmods; - gsd_used_mods &= ~dynmods; + msd_ignored_mods |= dynmods; + msd_used_mods &= ~dynmods; } } @@ -89,7 +89,7 @@ grab_key_real (guint keycode, } } -/* Grab the key. In order to ignore GSD_IGNORED_MODS we need to grab +/* Grab the key. In order to ignore MSD_IGNORED_MODS we need to grab * all combinations of the ignored modifiers and those actually used * for the binding (if any). * @@ -124,7 +124,7 @@ grab_key_unsafe (Key *key, setup_modifiers (); - mask = gsd_ignored_mods & ~key->state & GDK_MODIFIER_MASK; + mask = msd_ignored_mods & ~key->state & GDK_MODIFIER_MASK; bit = 0; /* store the indexes of all set bits in mask in the array */ @@ -236,11 +236,11 @@ match_key (Key *key, XEvent *event) consumed &= ~GDK_SHIFT_MASK; return ((lower == key->keysym || upper == key->keysym) - && (event->xkey.state & ~consumed & gsd_used_mods) == key->state); + && (event->xkey.state & ~consumed & msd_used_mods) == key->state); } /* The key we passed doesn't have a keysym, so try with just the keycode */ return (key != NULL - && key->state == (event->xkey.state & gsd_used_mods) + && key->state == (event->xkey.state & msd_used_mods) && key_uses_keycode (key, event->xkey.keycode)); } diff --git a/plugins/common/gsd-keygrab.h b/plugins/common/gsd-keygrab.h index a157ab4..8ebef21 100644 --- a/plugins/common/gsd-keygrab.h +++ b/plugins/common/gsd-keygrab.h @@ -17,8 +17,8 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifndef __GSD_COMMON_KEYGRAB_H -#define __GSD_COMMON_KEYGRAB_H +#ifndef __MSD_COMMON_KEYGRAB_H +#define __MSD_COMMON_KEYGRAB_H #ifdef __cplusplus extern "C" { @@ -48,4 +48,4 @@ gboolean key_uses_keycode (const Key *key, } #endif -#endif /* __GSD_COMMON_KEYGRAB_H */ +#endif /* __MSD_COMMON_KEYGRAB_H */ diff --git a/plugins/common/gsd-osd-window.c b/plugins/common/gsd-osd-window.c index 03ca316..123313c 100644 --- a/plugins/common/gsd-osd-window.c +++ b/plugins/common/gsd-osd-window.c @@ -36,7 +36,7 @@ #include #include -#include "gsd-osd-window.h" +#include "msd-osd-window.h" #define DIALOG_TIMEOUT 2000 /* dialog timeout in ms */ #define DIALOG_FADE_TIMEOUT 1500 /* timeout before fade starts */ @@ -44,9 +44,9 @@ #define BG_ALPHA 0.75 -#define GSD_OSD_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_OSD_WINDOW, GsdOsdWindowPrivate)) +#define MSD_OSD_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_OSD_WINDOW, MsdOsdWindowPrivate)) -struct GsdOsdWindowPrivate +struct MsdOsdWindowPrivate { guint is_composited : 1; guint hide_timeout_id; @@ -61,10 +61,10 @@ enum { static guint signals[LAST_SIGNAL] = { 0 }; -G_DEFINE_TYPE (GsdOsdWindow, gsd_osd_window, GTK_TYPE_WINDOW) +G_DEFINE_TYPE (MsdOsdWindow, msd_osd_window, GTK_TYPE_WINDOW) static gboolean -fade_timeout (GsdOsdWindow *window) +fade_timeout (MsdOsdWindow *window) { if (window->priv->fade_out_alpha <= 0.0) { gtk_widget_hide (GTK_WIDGET (window)); @@ -95,7 +95,7 @@ fade_timeout (GsdOsdWindow *window) } static gboolean -hide_timeout (GsdOsdWindow *window) +hide_timeout (MsdOsdWindow *window) { if (window->priv->is_composited) { window->priv->hide_timeout_id = 0; @@ -110,7 +110,7 @@ hide_timeout (GsdOsdWindow *window) } static void -remove_hide_timeout (GsdOsdWindow *window) +remove_hide_timeout (MsdOsdWindow *window) { if (window->priv->hide_timeout_id != 0) { g_source_remove (window->priv->hide_timeout_id); @@ -125,7 +125,7 @@ remove_hide_timeout (GsdOsdWindow *window) } static void -add_hide_timeout (GsdOsdWindow *window) +add_hide_timeout (MsdOsdWindow *window) { int timeout; @@ -140,7 +140,7 @@ add_hide_timeout (GsdOsdWindow *window) } void -gsd_osd_window_draw_rounded_rectangle (cairo_t* cr, +msd_osd_window_draw_rounded_rectangle (cairo_t* cr, gdouble aspect, gdouble x, gdouble y, @@ -192,7 +192,7 @@ gsd_osd_window_draw_rounded_rectangle (cairo_t* cr, } void -gsd_osd_window_color_reverse (const GdkColor *a, +msd_osd_window_color_reverse (const GdkColor *a, GdkColor *b) { gdouble red; @@ -228,7 +228,7 @@ gsd_osd_window_color_reverse (const GdkColor *a, static void expose_when_composited (GtkWidget *widget, GdkEventExpose *event) { - GsdOsdWindow *window; + MsdOsdWindow *window; cairo_t *context; cairo_t *cr; cairo_surface_t *surface; @@ -238,7 +238,7 @@ expose_when_composited (GtkWidget *widget, GdkEventExpose *event) GdkColor color; double r, g, b; - window = GSD_OSD_WINDOW (widget); + window = MSD_OSD_WINDOW (widget); context = gdk_cairo_create (gtk_widget_get_window (widget)); @@ -264,15 +264,15 @@ expose_when_composited (GtkWidget *widget, GdkEventExpose *event) cairo_paint (cr); /* draw a box */ - gsd_osd_window_draw_rounded_rectangle (cr, 1.0, 0.5, 0.5, height / 10, width-1, height-1); - gsd_osd_window_color_reverse (&style->bg[GTK_STATE_NORMAL], &color); + msd_osd_window_draw_rounded_rectangle (cr, 1.0, 0.5, 0.5, height / 10, width-1, height-1); + msd_osd_window_color_reverse (&style->bg[GTK_STATE_NORMAL], &color); r = (float)color.red / 65535.0; g = (float)color.green / 65535.0; b = (float)color.blue / 65535.0; cairo_set_source_rgba (cr, r, g, b, BG_ALPHA); cairo_fill_preserve (cr); - gsd_osd_window_color_reverse (&style->text_aa[GTK_STATE_NORMAL], &color); + msd_osd_window_color_reverse (&style->text_aa[GTK_STATE_NORMAL], &color); r = (float)color.red / 65535.0; g = (float)color.green / 65535.0; b = (float)color.blue / 65535.0; @@ -308,10 +308,10 @@ expose_when_composited (GtkWidget *widget, GdkEventExpose *event) static void expose_when_not_composited (GtkWidget *widget, GdkEventExpose *event) { - GsdOsdWindow *window; + MsdOsdWindow *window; GtkAllocation allocation; - window = GSD_OSD_WINDOW (widget); + window = MSD_OSD_WINDOW (widget); gtk_widget_get_allocation (widget, &allocation); @@ -321,7 +321,7 @@ expose_when_not_composited (GtkWidget *widget, GdkEventExpose *event) GTK_SHADOW_OUT, &event->area, widget, - NULL, /* NULL detail -> themes should use the GsdOsdWindow widget name, probably */ + NULL, /* NULL detail -> themes should use the MsdOsdWindow widget name, probably */ 0, 0, allocation.width, @@ -329,13 +329,13 @@ expose_when_not_composited (GtkWidget *widget, GdkEventExpose *event) } static gboolean -gsd_osd_window_expose_event (GtkWidget *widget, +msd_osd_window_expose_event (GtkWidget *widget, GdkEventExpose *event) { - GsdOsdWindow *window; + MsdOsdWindow *window; GtkWidget *child; - window = GSD_OSD_WINDOW (widget); + window = MSD_OSD_WINDOW (widget); if (window->priv->is_composited) expose_when_composited (widget, event); @@ -350,34 +350,34 @@ gsd_osd_window_expose_event (GtkWidget *widget, } static void -gsd_osd_window_real_show (GtkWidget *widget) +msd_osd_window_real_show (GtkWidget *widget) { - GsdOsdWindow *window; + MsdOsdWindow *window; - if (GTK_WIDGET_CLASS (gsd_osd_window_parent_class)->show) { - GTK_WIDGET_CLASS (gsd_osd_window_parent_class)->show (widget); + if (GTK_WIDGET_CLASS (msd_osd_window_parent_class)->show) { + GTK_WIDGET_CLASS (msd_osd_window_parent_class)->show (widget); } - window = GSD_OSD_WINDOW (widget); + window = MSD_OSD_WINDOW (widget); remove_hide_timeout (window); add_hide_timeout (window); } static void -gsd_osd_window_real_hide (GtkWidget *widget) +msd_osd_window_real_hide (GtkWidget *widget) { - GsdOsdWindow *window; + MsdOsdWindow *window; - if (GTK_WIDGET_CLASS (gsd_osd_window_parent_class)->hide) { - GTK_WIDGET_CLASS (gsd_osd_window_parent_class)->hide (widget); + if (GTK_WIDGET_CLASS (msd_osd_window_parent_class)->hide) { + GTK_WIDGET_CLASS (msd_osd_window_parent_class)->hide (widget); } - window = GSD_OSD_WINDOW (widget); + window = MSD_OSD_WINDOW (widget); remove_hide_timeout (window); } static void -gsd_osd_window_real_realize (GtkWidget *widget) +msd_osd_window_real_realize (GtkWidget *widget) { GdkColormap *colormap; GtkAllocation allocation; @@ -390,8 +390,8 @@ gsd_osd_window_real_realize (GtkWidget *widget) gtk_widget_set_colormap (widget, colormap); } - if (GTK_WIDGET_CLASS (gsd_osd_window_parent_class)->realize) { - GTK_WIDGET_CLASS (gsd_osd_window_parent_class)->realize (widget); + if (GTK_WIDGET_CLASS (msd_osd_window_parent_class)->realize) { + GTK_WIDGET_CLASS (msd_osd_window_parent_class)->realize (widget); } gtk_widget_get_allocation (widget, &allocation); @@ -412,12 +412,12 @@ gsd_osd_window_real_realize (GtkWidget *widget) } static void -gsd_osd_window_style_set (GtkWidget *widget, +msd_osd_window_style_set (GtkWidget *widget, GtkStyle *previous_style) { GtkStyle *style; - GTK_WIDGET_CLASS (gsd_osd_window_parent_class)->style_set (widget, previous_style); + GTK_WIDGET_CLASS (msd_osd_window_parent_class)->style_set (widget, previous_style); /* We set our border width to 12 (per the MATE standard), plus the * thickness of the frame that we draw in our expose handler. This will @@ -429,14 +429,14 @@ gsd_osd_window_style_set (GtkWidget *widget, } static void -gsd_osd_window_size_request (GtkWidget *widget, +msd_osd_window_size_request (GtkWidget *widget, GtkRequisition *requisition) { GtkStyle *style; - GTK_WIDGET_CLASS (gsd_osd_window_parent_class)->size_request (widget, requisition); + GTK_WIDGET_CLASS (msd_osd_window_parent_class)->size_request (widget, requisition); - /* See the comment in gsd_osd_window_style_set() for why we add the thickness here */ + /* See the comment in msd_osd_window_style_set() for why we add the thickness here */ style = gtk_widget_get_style (widget); @@ -445,13 +445,13 @@ gsd_osd_window_size_request (GtkWidget *widget, } static GObject * -gsd_osd_window_constructor (GType type, +msd_osd_window_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_params) { GObject *object; - object = G_OBJECT_CLASS (gsd_osd_window_parent_class)->constructor (type, n_construct_properties, construct_params); + object = G_OBJECT_CLASS (msd_osd_window_parent_class)->constructor (type, n_construct_properties, construct_params); g_object_set (object, "type", GTK_WINDOW_POPUP, @@ -465,64 +465,64 @@ gsd_osd_window_constructor (GType type, } static void -gsd_osd_window_class_init (GsdOsdWindowClass *klass) +msd_osd_window_class_init (MsdOsdWindowClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - gobject_class->constructor = gsd_osd_window_constructor; + gobject_class->constructor = msd_osd_window_constructor; - widget_class->show = gsd_osd_window_real_show; - widget_class->hide = gsd_osd_window_real_hide; - widget_class->realize = gsd_osd_window_real_realize; - widget_class->style_set = gsd_osd_window_style_set; - widget_class->size_request = gsd_osd_window_size_request; - widget_class->expose_event = gsd_osd_window_expose_event; + widget_class->show = msd_osd_window_real_show; + widget_class->hide = msd_osd_window_real_hide; + widget_class->realize = msd_osd_window_real_realize; + widget_class->style_set = msd_osd_window_style_set; + widget_class->size_request = msd_osd_window_size_request; + widget_class->expose_event = msd_osd_window_expose_event; signals[EXPOSE_WHEN_COMPOSITED] = g_signal_new ("expose-when-composited", G_TYPE_FROM_CLASS (gobject_class), G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (GsdOsdWindowClass, expose_when_composited), + G_STRUCT_OFFSET (MsdOsdWindowClass, expose_when_composited), NULL, NULL, g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER); - g_type_class_add_private (klass, sizeof (GsdOsdWindowPrivate)); + g_type_class_add_private (klass, sizeof (MsdOsdWindowPrivate)); } /** - * gsd_osd_window_is_composited: - * @window: a #GsdOsdWindow + * msd_osd_window_is_composited: + * @window: a #MsdOsdWindow * * Return value: whether the window was created on a composited screen. */ gboolean -gsd_osd_window_is_composited (GsdOsdWindow *window) +msd_osd_window_is_composited (MsdOsdWindow *window) { return window->priv->is_composited; } /** - * gsd_osd_window_is_valid: - * @window: a #GsdOsdWindow + * msd_osd_window_is_valid: + * @window: a #MsdOsdWindow * * Return value: TRUE if the @window's idea of being composited matches whether * its current screen is actually composited. */ gboolean -gsd_osd_window_is_valid (GsdOsdWindow *window) +msd_osd_window_is_valid (MsdOsdWindow *window) { GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (window)); return gdk_screen_is_composited (screen) == window->priv->is_composited; } static void -gsd_osd_window_init (GsdOsdWindow *window) +msd_osd_window_init (MsdOsdWindow *window) { GdkScreen *screen; - window->priv = GSD_OSD_WINDOW_GET_PRIVATE (window); + window->priv = MSD_OSD_WINDOW_GET_PRIVATE (window); screen = gtk_widget_get_screen (GTK_WIDGET (window)); @@ -550,19 +550,19 @@ gsd_osd_window_init (GsdOsdWindow *window) } GtkWidget * -gsd_osd_window_new (void) +msd_osd_window_new (void) { - return g_object_new (GSD_TYPE_OSD_WINDOW, NULL); + return g_object_new (MSD_TYPE_OSD_WINDOW, NULL); } /** - * gsd_osd_window_update_and_hide: - * @window: a #GsdOsdWindow + * msd_osd_window_update_and_hide: + * @window: a #MsdOsdWindow * * Queues the @window for immediate drawing, and queues a timer to hide the window. */ void -gsd_osd_window_update_and_hide (GsdOsdWindow *window) +msd_osd_window_update_and_hide (MsdOsdWindow *window) { remove_hide_timeout (window); add_hide_timeout (window); diff --git a/plugins/common/gsd-osd-window.h b/plugins/common/gsd-osd-window.h index 0d8040b..f539e5e 100644 --- a/plugins/common/gsd-osd-window.h +++ b/plugins/common/gsd-osd-window.h @@ -27,18 +27,18 @@ * */ -/* GsdOsdWindow is an "on-screen-display" window (OSD). It is the cute, +/* MsdOsdWindow is an "on-screen-display" window (OSD). It is the cute, * semi-transparent, curved popup that appears when you press a hotkey global to * the desktop, such as to change the volume, switch your monitor's parameters, * etc. * - * You can create a GsdOsdWindow and use it as a normal GtkWindow. It will + * You can create a MsdOsdWindow and use it as a normal GtkWindow. It will * automatically center itself, figure out if it needs to be composited, etc. * Just pack your widgets in it, sit back, and enjoy the ride. */ -#ifndef GSD_OSD_WINDOW_H -#define GSD_OSD_WINDOW_H +#ifndef MSD_OSD_WINDOW_H +#define MSD_OSD_WINDOW_H #include #include @@ -48,39 +48,39 @@ extern "C" { #endif /* Alpha value to be used for foreground objects drawn in an OSD window */ -#define GSD_OSD_WINDOW_FG_ALPHA 1.0 +#define MSD_OSD_WINDOW_FG_ALPHA 1.0 -#define GSD_TYPE_OSD_WINDOW (gsd_osd_window_get_type ()) -#define GSD_OSD_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GSD_TYPE_OSD_WINDOW, GsdOsdWindow)) -#define GSD_OSD_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GSD_TYPE_OSD_WINDOW, GsdOsdWindowClass)) -#define GSD_IS_OSD_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GSD_TYPE_OSD_WINDOW)) -#define GSD_IS_OSD_WINDOW_CLASS(klass) (G_TYPE_INSTANCE_GET_CLASS ((klass), GSD_TYPE_OSD_WINDOW)) -#define GSD_OSD_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GSD_TYPE_OSD_WINDOW, GsdOsdWindowClass)) +#define MSD_TYPE_OSD_WINDOW (msd_osd_window_get_type ()) +#define MSD_OSD_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MSD_TYPE_OSD_WINDOW, MsdOsdWindow)) +#define MSD_OSD_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MSD_TYPE_OSD_WINDOW, MsdOsdWindowClass)) +#define MSD_IS_OSD_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MSD_TYPE_OSD_WINDOW)) +#define MSD_IS_OSD_WINDOW_CLASS(klass) (G_TYPE_INSTANCE_GET_CLASS ((klass), MSD_TYPE_OSD_WINDOW)) +#define MSD_OSD_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MSD_TYPE_OSD_WINDOW, MsdOsdWindowClass)) -typedef struct GsdOsdWindow GsdOsdWindow; -typedef struct GsdOsdWindowClass GsdOsdWindowClass; -typedef struct GsdOsdWindowPrivate GsdOsdWindowPrivate; +typedef struct MsdOsdWindow MsdOsdWindow; +typedef struct MsdOsdWindowClass MsdOsdWindowClass; +typedef struct MsdOsdWindowPrivate MsdOsdWindowPrivate; -struct GsdOsdWindow { +struct MsdOsdWindow { GtkWindow parent; - GsdOsdWindowPrivate *priv; + MsdOsdWindowPrivate *priv; }; -struct GsdOsdWindowClass { +struct MsdOsdWindowClass { GtkWindowClass parent_class; - void (* expose_when_composited) (GsdOsdWindow *window, cairo_t *cr); + void (* expose_when_composited) (MsdOsdWindow *window, cairo_t *cr); }; -GType gsd_osd_window_get_type (void); +GType msd_osd_window_get_type (void); -GtkWidget * gsd_osd_window_new (void); -gboolean gsd_osd_window_is_composited (GsdOsdWindow *window); -gboolean gsd_osd_window_is_valid (GsdOsdWindow *window); -void gsd_osd_window_update_and_hide (GsdOsdWindow *window); +GtkWidget * msd_osd_window_new (void); +gboolean msd_osd_window_is_composited (MsdOsdWindow *window); +gboolean msd_osd_window_is_valid (MsdOsdWindow *window); +void msd_osd_window_update_and_hide (MsdOsdWindow *window); -void gsd_osd_window_draw_rounded_rectangle (cairo_t *cr, +void msd_osd_window_draw_rounded_rectangle (cairo_t *cr, gdouble aspect, gdouble x, gdouble y, @@ -88,7 +88,7 @@ void gsd_osd_window_draw_rounded_rectangle (cairo_t *cr, gdouble width, gdouble height); -void gsd_osd_window_color_reverse (const GdkColor *a, +void msd_osd_window_color_reverse (const GdkColor *a, GdkColor *b); #ifdef __cplusplus -- cgit v1.2.1 From e46b4adef5c6c6805b3ca6dbfbe99a4299252514 Mon Sep 17 00:00:00 2001 From: haxar Date: Tue, 21 Feb 2012 20:14:01 -0800 Subject: gsd to msd complete rename patch by NiceandGently; file rename commit --- plugins/common/gsd-keygrab.c | 246 ----------------- plugins/common/gsd-keygrab.h | 51 ---- plugins/common/gsd-osd-window.c | 573 ---------------------------------------- plugins/common/gsd-osd-window.h | 98 ------- plugins/common/msd-keygrab.c | 246 +++++++++++++++++ plugins/common/msd-keygrab.h | 51 ++++ plugins/common/msd-osd-window.c | 573 ++++++++++++++++++++++++++++++++++++++++ plugins/common/msd-osd-window.h | 98 +++++++ 8 files changed, 968 insertions(+), 968 deletions(-) delete mode 100644 plugins/common/gsd-keygrab.c delete mode 100644 plugins/common/gsd-keygrab.h delete mode 100644 plugins/common/gsd-osd-window.c delete mode 100644 plugins/common/gsd-osd-window.h create mode 100644 plugins/common/msd-keygrab.c create mode 100644 plugins/common/msd-keygrab.h create mode 100644 plugins/common/msd-osd-window.c create mode 100644 plugins/common/msd-osd-window.h (limited to 'plugins/common') diff --git a/plugins/common/gsd-keygrab.c b/plugins/common/gsd-keygrab.c deleted file mode 100644 index 7a16f4e..0000000 --- a/plugins/common/gsd-keygrab.c +++ /dev/null @@ -1,246 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2001-2003 Bastien Nocera - * Copyright (C) 2006-2007 William Jon McCann - * Copyright (C) 2008 Jens Granseuer - * - * 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 -#include -#ifdef HAVE_X11_EXTENSIONS_XKB_H -#include -#include -#include -#endif - -#include "eggaccelerators.h" - -#include "msd-keygrab.h" - -/* these are the mods whose combinations are ignored by the keygrabbing code */ -static GdkModifierType msd_ignored_mods = 0; - -/* these are the ones we actually use for global keys, we always only check - * for these set */ -static GdkModifierType msd_used_mods = 0; - -static void -setup_modifiers (void) -{ - if (msd_used_mods == 0 || msd_ignored_mods == 0) { - GdkModifierType dynmods; - - /* default modifiers */ - msd_ignored_mods = \ - 0x2000 /*Xkb modifier*/ | GDK_LOCK_MASK | GDK_HYPER_MASK; - msd_used_mods = \ - GDK_SHIFT_MASK | GDK_CONTROL_MASK |\ - GDK_MOD1_MASK | GDK_MOD2_MASK | GDK_MOD3_MASK | GDK_MOD4_MASK |\ - GDK_MOD5_MASK | GDK_SUPER_MASK | GDK_META_MASK; - - /* NumLock can be assigned to varying keys so we need to - * resolve and ignore it specially */ - dynmods = 0; - egg_keymap_resolve_virtual_modifiers (gdk_keymap_get_default (), - EGG_VIRTUAL_NUM_LOCK_MASK, - &dynmods); - - msd_ignored_mods |= dynmods; - msd_used_mods &= ~dynmods; - } -} - -static void -grab_key_real (guint keycode, - GdkWindow *root, - gboolean grab, - int mask) -{ - if (grab) { - XGrabKey (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), - keycode, - mask, - GDK_WINDOW_XID (root), - True, - GrabModeAsync, - GrabModeAsync); - } else { - XUngrabKey (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), - keycode, - mask, - GDK_WINDOW_XID (root)); - } -} - -/* Grab the key. In order to ignore MSD_IGNORED_MODS we need to grab - * all combinations of the ignored modifiers and those actually used - * for the binding (if any). - * - * inspired by all_combinations from mate-panel/mate-panel/global-keys.c - * - * This may generate X errors. The correct way to use this is like: - * - * gdk_error_trap_push (); - * - * grab_key_unsafe (key, grab, screens); - * - * gdk_flush (); - * if (gdk_error_trap_pop ()) - * g_warning ("Grab failed, another application may already have access to key '%u'", - * key->keycode); - * - * This is not done in the function itself, to allow doing multiple grab_key - * operations with one flush only. - */ -#define N_BITS 32 -void -grab_key_unsafe (Key *key, - gboolean grab, - GSList *screens) -{ - int indexes[N_BITS]; /* indexes of bits we need to flip */ - int i; - int bit; - int bits_set_cnt; - int uppervalue; - guint mask; - - setup_modifiers (); - - mask = msd_ignored_mods & ~key->state & GDK_MODIFIER_MASK; - - bit = 0; - /* store the indexes of all set bits in mask in the array */ - for (i = 0; mask; ++i, mask >>= 1) { - if (mask & 0x1) { - indexes[bit++] = i; - } - } - - bits_set_cnt = bit; - - uppervalue = 1 << bits_set_cnt; - /* grab all possible modifier combinations for our mask */ - for (i = 0; i < uppervalue; ++i) { - GSList *l; - int j; - int result = 0; - - /* map bits in the counter to those in the mask */ - for (j = 0; j < bits_set_cnt; ++j) { - if (i & (1 << j)) { - result |= (1 << indexes[j]); - } - } - - for (l = screens; l; l = l->next) { - GdkScreen *screen = l->data; - guint *code; - - for (code = key->keycodes; *code; ++code) { - grab_key_real (*code, - gdk_screen_get_root_window (screen), - grab, - result | key->state); - } - } - } -} - -static gboolean -have_xkb (Display *dpy) -{ - static int have_xkb = -1; - - if (have_xkb == -1) { -#ifdef HAVE_X11_EXTENSIONS_XKB_H - int opcode, error_base, major, minor, xkb_event_base; - - have_xkb = XkbQueryExtension (dpy, - &opcode, - &xkb_event_base, - &error_base, - &major, - &minor) - && XkbUseExtension (dpy, &major, &minor); -#else - have_xkb = 0; -#endif - } - - return have_xkb; -} - -gboolean -key_uses_keycode (const Key *key, guint keycode) -{ - if (key->keycodes != NULL) { - guint *c; - - for (c = key->keycodes; *c; ++c) { - if (*c == keycode) - return TRUE; - } - } - return FALSE; -} - -gboolean -match_key (Key *key, XEvent *event) -{ - guint keyval; - GdkModifierType consumed; - gint group; - - if (key == NULL) - return FALSE; - - setup_modifiers (); - -#ifdef HAVE_X11_EXTENSIONS_XKB_H - if (have_xkb (event->xkey.display)) - group = XkbGroupForCoreState (event->xkey.state); - else -#endif - group = (event->xkey.state & GDK_Mode_switch) ? 1 : 0; - - /* Check if we find a keysym that matches our current state */ - if (gdk_keymap_translate_keyboard_state (NULL, event->xkey.keycode, - event->xkey.state, group, - &keyval, NULL, NULL, &consumed)) { - guint lower, upper; - - gdk_keyval_convert_case (keyval, &lower, &upper); - - /* If we are checking against the lower version of the - * keysym, we might need the Shift state for matching, - * so remove it from the consumed modifiers */ - if (lower == key->keysym) - consumed &= ~GDK_SHIFT_MASK; - - return ((lower == key->keysym || upper == key->keysym) - && (event->xkey.state & ~consumed & msd_used_mods) == key->state); - } - - /* The key we passed doesn't have a keysym, so try with just the keycode */ - return (key != NULL - && key->state == (event->xkey.state & msd_used_mods) - && key_uses_keycode (key, event->xkey.keycode)); -} diff --git a/plugins/common/gsd-keygrab.h b/plugins/common/gsd-keygrab.h deleted file mode 100644 index 8ebef21..0000000 --- a/plugins/common/gsd-keygrab.h +++ /dev/null @@ -1,51 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2008 Jens Granseuer - * - * 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. - */ - -#ifndef __MSD_COMMON_KEYGRAB_H -#define __MSD_COMMON_KEYGRAB_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -typedef struct { - guint keysym; - guint state; - guint *keycodes; -} Key; - - -void grab_key_unsafe (Key *key, - gboolean grab, - GSList *screens); - -gboolean match_key (Key *key, - XEvent *event); - -gboolean key_uses_keycode (const Key *key, - guint keycode); - -#ifdef __cplusplus -} -#endif - -#endif /* __MSD_COMMON_KEYGRAB_H */ diff --git a/plugins/common/gsd-osd-window.c b/plugins/common/gsd-osd-window.c deleted file mode 100644 index 123313c..0000000 --- a/plugins/common/gsd-osd-window.c +++ /dev/null @@ -1,573 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * On-screen-display (OSD) window for mate-settings-daemon's plugins - * - * Copyright (C) 2006-2007 William Jon McCann - * Copyright (C) 2009 Novell, Inc - * - * Authors: - * William Jon McCann - * Federico Mena-Quintero - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2, 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 Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser 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 -#include -#include -#include -#include -#include - -#include "msd-osd-window.h" - -#define DIALOG_TIMEOUT 2000 /* dialog timeout in ms */ -#define DIALOG_FADE_TIMEOUT 1500 /* timeout before fade starts */ -#define FADE_TIMEOUT 10 /* timeout in ms between each frame of the fade */ - -#define BG_ALPHA 0.75 - -#define MSD_OSD_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_OSD_WINDOW, MsdOsdWindowPrivate)) - -struct MsdOsdWindowPrivate -{ - guint is_composited : 1; - guint hide_timeout_id; - guint fade_timeout_id; - double fade_out_alpha; -}; - -enum { - EXPOSE_WHEN_COMPOSITED, - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = { 0 }; - -G_DEFINE_TYPE (MsdOsdWindow, msd_osd_window, GTK_TYPE_WINDOW) - -static gboolean -fade_timeout (MsdOsdWindow *window) -{ - if (window->priv->fade_out_alpha <= 0.0) { - gtk_widget_hide (GTK_WIDGET (window)); - - /* Reset it for the next time */ - window->priv->fade_out_alpha = 1.0; - window->priv->fade_timeout_id = 0; - - return FALSE; - } else { - GdkRectangle rect; - GtkWidget *win = GTK_WIDGET (window); - GtkAllocation allocation; - - window->priv->fade_out_alpha -= 0.10; - - rect.x = 0; - rect.y = 0; - gtk_widget_get_allocation (win, &allocation); - rect.width = allocation.width; - rect.height = allocation.height; - - gtk_widget_realize (win); - gdk_window_invalidate_rect (gtk_widget_get_window (win), &rect, FALSE); - } - - return TRUE; -} - -static gboolean -hide_timeout (MsdOsdWindow *window) -{ - if (window->priv->is_composited) { - window->priv->hide_timeout_id = 0; - window->priv->fade_timeout_id = g_timeout_add (FADE_TIMEOUT, - (GSourceFunc) fade_timeout, - window); - } else { - gtk_widget_hide (GTK_WIDGET (window)); - } - - return FALSE; -} - -static void -remove_hide_timeout (MsdOsdWindow *window) -{ - if (window->priv->hide_timeout_id != 0) { - g_source_remove (window->priv->hide_timeout_id); - window->priv->hide_timeout_id = 0; - } - - if (window->priv->fade_timeout_id != 0) { - g_source_remove (window->priv->fade_timeout_id); - window->priv->fade_timeout_id = 0; - window->priv->fade_out_alpha = 1.0; - } -} - -static void -add_hide_timeout (MsdOsdWindow *window) -{ - int timeout; - - if (window->priv->is_composited) { - timeout = DIALOG_FADE_TIMEOUT; - } else { - timeout = DIALOG_TIMEOUT; - } - window->priv->hide_timeout_id = g_timeout_add (timeout, - (GSourceFunc) hide_timeout, - window); -} - -void -msd_osd_window_draw_rounded_rectangle (cairo_t* cr, - gdouble aspect, - gdouble x, - gdouble y, - gdouble corner_radius, - gdouble width, - gdouble height) -{ - gdouble radius = corner_radius / aspect; - - cairo_move_to (cr, x + radius, y); - - cairo_line_to (cr, - x + width - radius, - y); - cairo_arc (cr, - x + width - radius, - y + radius, - radius, - -90.0f * G_PI / 180.0f, - 0.0f * G_PI / 180.0f); - cairo_line_to (cr, - x + width, - y + height - radius); - cairo_arc (cr, - x + width - radius, - y + height - radius, - radius, - 0.0f * G_PI / 180.0f, - 90.0f * G_PI / 180.0f); - cairo_line_to (cr, - x + radius, - y + height); - cairo_arc (cr, - x + radius, - y + height - radius, - radius, - 90.0f * G_PI / 180.0f, - 180.0f * G_PI / 180.0f); - cairo_line_to (cr, - x, - y + radius); - cairo_arc (cr, - x + radius, - y + radius, - radius, - 180.0f * G_PI / 180.0f, - 270.0f * G_PI / 180.0f); - cairo_close_path (cr); -} - -void -msd_osd_window_color_reverse (const GdkColor *a, - GdkColor *b) -{ - gdouble red; - gdouble green; - gdouble blue; - gdouble h; - gdouble s; - gdouble v; - - red = (gdouble) a->red / 65535.0; - green = (gdouble) a->green / 65535.0; - blue = (gdouble) a->blue / 65535.0; - - gtk_rgb_to_hsv (red, green, blue, &h, &s, &v); - - v = 0.5 + (0.5 - v); - if (v > 1.0) - v = 1.0; - else if (v < 0.0) - v = 0.0; - - gtk_hsv_to_rgb (h, s, v, &red, &green, &blue); - - b->red = red * 65535.0; - b->green = green * 65535.0; - b->blue = blue * 65535.0; -} - -/* This is our expose-event handler when the window is in a compositing manager. - * We draw everything by hand, using Cairo, so that we can have a nice - * transparent/rounded look. - */ -static void -expose_when_composited (GtkWidget *widget, GdkEventExpose *event) -{ - MsdOsdWindow *window; - cairo_t *context; - cairo_t *cr; - cairo_surface_t *surface; - int width; - int height; - GtkStyle *style; - GdkColor color; - double r, g, b; - - window = MSD_OSD_WINDOW (widget); - - context = gdk_cairo_create (gtk_widget_get_window (widget)); - - style = gtk_widget_get_style (widget); - cairo_set_operator (context, CAIRO_OPERATOR_SOURCE); - gtk_window_get_size (GTK_WINDOW (widget), &width, &height); - - surface = cairo_surface_create_similar (cairo_get_target (context), - CAIRO_CONTENT_COLOR_ALPHA, - width, - height); - - if (cairo_surface_status (surface) != CAIRO_STATUS_SUCCESS) { - goto done; - } - - cr = cairo_create (surface); - if (cairo_status (cr) != CAIRO_STATUS_SUCCESS) { - goto done; - } - cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.0); - cairo_set_operator (cr, CAIRO_OPERATOR_OVER); - cairo_paint (cr); - - /* draw a box */ - msd_osd_window_draw_rounded_rectangle (cr, 1.0, 0.5, 0.5, height / 10, width-1, height-1); - msd_osd_window_color_reverse (&style->bg[GTK_STATE_NORMAL], &color); - r = (float)color.red / 65535.0; - g = (float)color.green / 65535.0; - b = (float)color.blue / 65535.0; - cairo_set_source_rgba (cr, r, g, b, BG_ALPHA); - cairo_fill_preserve (cr); - - msd_osd_window_color_reverse (&style->text_aa[GTK_STATE_NORMAL], &color); - r = (float)color.red / 65535.0; - g = (float)color.green / 65535.0; - b = (float)color.blue / 65535.0; - cairo_set_source_rgba (cr, r, g, b, BG_ALPHA / 2); - cairo_set_line_width (cr, 1); - cairo_stroke (cr); - - g_signal_emit (window, signals[EXPOSE_WHEN_COMPOSITED], 0, cr); - - cairo_destroy (cr); - - /* Make sure we have a transparent background */ - cairo_rectangle (context, 0, 0, width, height); - cairo_set_source_rgba (context, 0.0, 0.0, 0.0, 0.0); - cairo_fill (context); - - cairo_set_source_surface (context, surface, 0, 0); - cairo_paint_with_alpha (context, window->priv->fade_out_alpha); - - done: - if (surface != NULL) { - cairo_surface_destroy (surface); - } - cairo_destroy (context); -} - -/* This is our expose-event handler when the window is *not* in a compositing manager. - * We just draw a rectangular frame by hand. We do this with hardcoded drawing code, - * instead of GtkFrame, to avoid changing the window's internal widget hierarchy: in - * either case (composited or non-composited), callers can assume that this works - * identically to a GtkWindow without any intermediate widgetry. - */ -static void -expose_when_not_composited (GtkWidget *widget, GdkEventExpose *event) -{ - MsdOsdWindow *window; - GtkAllocation allocation; - - window = MSD_OSD_WINDOW (widget); - - gtk_widget_get_allocation (widget, &allocation); - - gtk_paint_shadow (gtk_widget_get_style (widget), - gtk_widget_get_window (widget), - gtk_widget_get_state (widget), - GTK_SHADOW_OUT, - &event->area, - widget, - NULL, /* NULL detail -> themes should use the MsdOsdWindow widget name, probably */ - 0, - 0, - allocation.width, - allocation.height); -} - -static gboolean -msd_osd_window_expose_event (GtkWidget *widget, - GdkEventExpose *event) -{ - MsdOsdWindow *window; - GtkWidget *child; - - window = MSD_OSD_WINDOW (widget); - - if (window->priv->is_composited) - expose_when_composited (widget, event); - else - expose_when_not_composited (widget, event); - - child = gtk_bin_get_child (GTK_BIN (window)); - if (child) - gtk_container_propagate_expose (GTK_CONTAINER (window), child, event); - - return FALSE; -} - -static void -msd_osd_window_real_show (GtkWidget *widget) -{ - MsdOsdWindow *window; - - if (GTK_WIDGET_CLASS (msd_osd_window_parent_class)->show) { - GTK_WIDGET_CLASS (msd_osd_window_parent_class)->show (widget); - } - - window = MSD_OSD_WINDOW (widget); - remove_hide_timeout (window); - add_hide_timeout (window); -} - -static void -msd_osd_window_real_hide (GtkWidget *widget) -{ - MsdOsdWindow *window; - - if (GTK_WIDGET_CLASS (msd_osd_window_parent_class)->hide) { - GTK_WIDGET_CLASS (msd_osd_window_parent_class)->hide (widget); - } - - window = MSD_OSD_WINDOW (widget); - remove_hide_timeout (window); -} - -static void -msd_osd_window_real_realize (GtkWidget *widget) -{ - GdkColormap *colormap; - GtkAllocation allocation; - GdkBitmap *mask; - cairo_t *cr; - - colormap = gdk_screen_get_rgba_colormap (gtk_widget_get_screen (widget)); - - if (colormap != NULL) { - gtk_widget_set_colormap (widget, colormap); - } - - if (GTK_WIDGET_CLASS (msd_osd_window_parent_class)->realize) { - GTK_WIDGET_CLASS (msd_osd_window_parent_class)->realize (widget); - } - - gtk_widget_get_allocation (widget, &allocation); - mask = gdk_pixmap_new (gtk_widget_get_window (widget), - allocation.width, - allocation.height, - 1); - cr = gdk_cairo_create (mask); - - cairo_set_source_rgba (cr, 1., 1., 1., 0.); - cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); - cairo_paint (cr); - - /* make the whole window ignore events */ - gdk_window_input_shape_combine_mask (gtk_widget_get_window (widget), mask, 0, 0); - g_object_unref (mask); - cairo_destroy (cr); -} - -static void -msd_osd_window_style_set (GtkWidget *widget, - GtkStyle *previous_style) -{ - GtkStyle *style; - - GTK_WIDGET_CLASS (msd_osd_window_parent_class)->style_set (widget, previous_style); - - /* We set our border width to 12 (per the MATE standard), plus the - * thickness of the frame that we draw in our expose handler. This will - * make our child be 12 pixels away from the frame. - */ - - style = gtk_widget_get_style (widget); - gtk_container_set_border_width (GTK_CONTAINER (widget), 12 + MAX (style->xthickness, style->ythickness)); -} - -static void -msd_osd_window_size_request (GtkWidget *widget, - GtkRequisition *requisition) -{ - GtkStyle *style; - - GTK_WIDGET_CLASS (msd_osd_window_parent_class)->size_request (widget, requisition); - - /* See the comment in msd_osd_window_style_set() for why we add the thickness here */ - - style = gtk_widget_get_style (widget); - - requisition->width += style->xthickness; - requisition->height += style->ythickness; -} - -static GObject * -msd_osd_window_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam *construct_params) -{ - GObject *object; - - object = G_OBJECT_CLASS (msd_osd_window_parent_class)->constructor (type, n_construct_properties, construct_params); - - g_object_set (object, - "type", GTK_WINDOW_POPUP, - "type-hint", GDK_WINDOW_TYPE_HINT_NOTIFICATION, - "skip-taskbar-hint", TRUE, - "skip-pager-hint", TRUE, - "focus-on-map", FALSE, - NULL); - - return object; -} - -static void -msd_osd_window_class_init (MsdOsdWindowClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - - gobject_class->constructor = msd_osd_window_constructor; - - widget_class->show = msd_osd_window_real_show; - widget_class->hide = msd_osd_window_real_hide; - widget_class->realize = msd_osd_window_real_realize; - widget_class->style_set = msd_osd_window_style_set; - widget_class->size_request = msd_osd_window_size_request; - widget_class->expose_event = msd_osd_window_expose_event; - - signals[EXPOSE_WHEN_COMPOSITED] = g_signal_new ("expose-when-composited", - G_TYPE_FROM_CLASS (gobject_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (MsdOsdWindowClass, expose_when_composited), - NULL, NULL, - g_cclosure_marshal_VOID__POINTER, - G_TYPE_NONE, 1, - G_TYPE_POINTER); - - g_type_class_add_private (klass, sizeof (MsdOsdWindowPrivate)); -} - -/** - * msd_osd_window_is_composited: - * @window: a #MsdOsdWindow - * - * Return value: whether the window was created on a composited screen. - */ -gboolean -msd_osd_window_is_composited (MsdOsdWindow *window) -{ - return window->priv->is_composited; -} - -/** - * msd_osd_window_is_valid: - * @window: a #MsdOsdWindow - * - * Return value: TRUE if the @window's idea of being composited matches whether - * its current screen is actually composited. - */ -gboolean -msd_osd_window_is_valid (MsdOsdWindow *window) -{ - GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (window)); - return gdk_screen_is_composited (screen) == window->priv->is_composited; -} - -static void -msd_osd_window_init (MsdOsdWindow *window) -{ - GdkScreen *screen; - - window->priv = MSD_OSD_WINDOW_GET_PRIVATE (window); - - screen = gtk_widget_get_screen (GTK_WIDGET (window)); - - window->priv->is_composited = gdk_screen_is_composited (screen); - - if (window->priv->is_composited) { - gdouble scalew, scaleh, scale; - gint size; - - gtk_window_set_decorated (GTK_WINDOW (window), FALSE); - gtk_widget_set_app_paintable (GTK_WIDGET (window), TRUE); - - /* assume 130x130 on a 640x480 display and scale from there */ - scalew = gdk_screen_get_width (screen) / 640.0; - scaleh = gdk_screen_get_height (screen) / 480.0; - scale = MIN (scalew, scaleh); - size = 130 * MAX (1, scale); - - gtk_window_set_default_size (GTK_WINDOW (window), size, size); - - window->priv->fade_out_alpha = 1.0; - } else { - gtk_container_set_border_width (GTK_CONTAINER (window), 12); - } -} - -GtkWidget * -msd_osd_window_new (void) -{ - return g_object_new (MSD_TYPE_OSD_WINDOW, NULL); -} - -/** - * msd_osd_window_update_and_hide: - * @window: a #MsdOsdWindow - * - * Queues the @window for immediate drawing, and queues a timer to hide the window. - */ -void -msd_osd_window_update_and_hide (MsdOsdWindow *window) -{ - remove_hide_timeout (window); - add_hide_timeout (window); - - if (window->priv->is_composited) { - gtk_widget_queue_draw (GTK_WIDGET (window)); - } -} diff --git a/plugins/common/gsd-osd-window.h b/plugins/common/gsd-osd-window.h deleted file mode 100644 index f539e5e..0000000 --- a/plugins/common/gsd-osd-window.h +++ /dev/null @@ -1,98 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8; tab-width: 8 -*- - * - * On-screen-display (OSD) window for mate-settings-daemon's plugins - * - * Copyright (C) 2006 William Jon McCann - * Copyright (C) 2009 Novell, Inc - * - * Authors: - * William Jon McCann - * Federico Mena-Quintero - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2, 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 Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser 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. - * - */ - -/* MsdOsdWindow is an "on-screen-display" window (OSD). It is the cute, - * semi-transparent, curved popup that appears when you press a hotkey global to - * the desktop, such as to change the volume, switch your monitor's parameters, - * etc. - * - * You can create a MsdOsdWindow and use it as a normal GtkWindow. It will - * automatically center itself, figure out if it needs to be composited, etc. - * Just pack your widgets in it, sit back, and enjoy the ride. - */ - -#ifndef MSD_OSD_WINDOW_H -#define MSD_OSD_WINDOW_H - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* Alpha value to be used for foreground objects drawn in an OSD window */ -#define MSD_OSD_WINDOW_FG_ALPHA 1.0 - -#define MSD_TYPE_OSD_WINDOW (msd_osd_window_get_type ()) -#define MSD_OSD_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MSD_TYPE_OSD_WINDOW, MsdOsdWindow)) -#define MSD_OSD_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MSD_TYPE_OSD_WINDOW, MsdOsdWindowClass)) -#define MSD_IS_OSD_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MSD_TYPE_OSD_WINDOW)) -#define MSD_IS_OSD_WINDOW_CLASS(klass) (G_TYPE_INSTANCE_GET_CLASS ((klass), MSD_TYPE_OSD_WINDOW)) -#define MSD_OSD_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MSD_TYPE_OSD_WINDOW, MsdOsdWindowClass)) - -typedef struct MsdOsdWindow MsdOsdWindow; -typedef struct MsdOsdWindowClass MsdOsdWindowClass; -typedef struct MsdOsdWindowPrivate MsdOsdWindowPrivate; - -struct MsdOsdWindow { - GtkWindow parent; - - MsdOsdWindowPrivate *priv; -}; - -struct MsdOsdWindowClass { - GtkWindowClass parent_class; - - void (* expose_when_composited) (MsdOsdWindow *window, cairo_t *cr); -}; - -GType msd_osd_window_get_type (void); - -GtkWidget * msd_osd_window_new (void); -gboolean msd_osd_window_is_composited (MsdOsdWindow *window); -gboolean msd_osd_window_is_valid (MsdOsdWindow *window); -void msd_osd_window_update_and_hide (MsdOsdWindow *window); - -void msd_osd_window_draw_rounded_rectangle (cairo_t *cr, - gdouble aspect, - gdouble x, - gdouble y, - gdouble corner_radius, - gdouble width, - gdouble height); - -void msd_osd_window_color_reverse (const GdkColor *a, - GdkColor *b); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/plugins/common/msd-keygrab.c b/plugins/common/msd-keygrab.c new file mode 100644 index 0000000..7a16f4e --- /dev/null +++ b/plugins/common/msd-keygrab.c @@ -0,0 +1,246 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2001-2003 Bastien Nocera + * Copyright (C) 2006-2007 William Jon McCann + * Copyright (C) 2008 Jens Granseuer + * + * 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 +#include +#ifdef HAVE_X11_EXTENSIONS_XKB_H +#include +#include +#include +#endif + +#include "eggaccelerators.h" + +#include "msd-keygrab.h" + +/* these are the mods whose combinations are ignored by the keygrabbing code */ +static GdkModifierType msd_ignored_mods = 0; + +/* these are the ones we actually use for global keys, we always only check + * for these set */ +static GdkModifierType msd_used_mods = 0; + +static void +setup_modifiers (void) +{ + if (msd_used_mods == 0 || msd_ignored_mods == 0) { + GdkModifierType dynmods; + + /* default modifiers */ + msd_ignored_mods = \ + 0x2000 /*Xkb modifier*/ | GDK_LOCK_MASK | GDK_HYPER_MASK; + msd_used_mods = \ + GDK_SHIFT_MASK | GDK_CONTROL_MASK |\ + GDK_MOD1_MASK | GDK_MOD2_MASK | GDK_MOD3_MASK | GDK_MOD4_MASK |\ + GDK_MOD5_MASK | GDK_SUPER_MASK | GDK_META_MASK; + + /* NumLock can be assigned to varying keys so we need to + * resolve and ignore it specially */ + dynmods = 0; + egg_keymap_resolve_virtual_modifiers (gdk_keymap_get_default (), + EGG_VIRTUAL_NUM_LOCK_MASK, + &dynmods); + + msd_ignored_mods |= dynmods; + msd_used_mods &= ~dynmods; + } +} + +static void +grab_key_real (guint keycode, + GdkWindow *root, + gboolean grab, + int mask) +{ + if (grab) { + XGrabKey (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), + keycode, + mask, + GDK_WINDOW_XID (root), + True, + GrabModeAsync, + GrabModeAsync); + } else { + XUngrabKey (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), + keycode, + mask, + GDK_WINDOW_XID (root)); + } +} + +/* Grab the key. In order to ignore MSD_IGNORED_MODS we need to grab + * all combinations of the ignored modifiers and those actually used + * for the binding (if any). + * + * inspired by all_combinations from mate-panel/mate-panel/global-keys.c + * + * This may generate X errors. The correct way to use this is like: + * + * gdk_error_trap_push (); + * + * grab_key_unsafe (key, grab, screens); + * + * gdk_flush (); + * if (gdk_error_trap_pop ()) + * g_warning ("Grab failed, another application may already have access to key '%u'", + * key->keycode); + * + * This is not done in the function itself, to allow doing multiple grab_key + * operations with one flush only. + */ +#define N_BITS 32 +void +grab_key_unsafe (Key *key, + gboolean grab, + GSList *screens) +{ + int indexes[N_BITS]; /* indexes of bits we need to flip */ + int i; + int bit; + int bits_set_cnt; + int uppervalue; + guint mask; + + setup_modifiers (); + + mask = msd_ignored_mods & ~key->state & GDK_MODIFIER_MASK; + + bit = 0; + /* store the indexes of all set bits in mask in the array */ + for (i = 0; mask; ++i, mask >>= 1) { + if (mask & 0x1) { + indexes[bit++] = i; + } + } + + bits_set_cnt = bit; + + uppervalue = 1 << bits_set_cnt; + /* grab all possible modifier combinations for our mask */ + for (i = 0; i < uppervalue; ++i) { + GSList *l; + int j; + int result = 0; + + /* map bits in the counter to those in the mask */ + for (j = 0; j < bits_set_cnt; ++j) { + if (i & (1 << j)) { + result |= (1 << indexes[j]); + } + } + + for (l = screens; l; l = l->next) { + GdkScreen *screen = l->data; + guint *code; + + for (code = key->keycodes; *code; ++code) { + grab_key_real (*code, + gdk_screen_get_root_window (screen), + grab, + result | key->state); + } + } + } +} + +static gboolean +have_xkb (Display *dpy) +{ + static int have_xkb = -1; + + if (have_xkb == -1) { +#ifdef HAVE_X11_EXTENSIONS_XKB_H + int opcode, error_base, major, minor, xkb_event_base; + + have_xkb = XkbQueryExtension (dpy, + &opcode, + &xkb_event_base, + &error_base, + &major, + &minor) + && XkbUseExtension (dpy, &major, &minor); +#else + have_xkb = 0; +#endif + } + + return have_xkb; +} + +gboolean +key_uses_keycode (const Key *key, guint keycode) +{ + if (key->keycodes != NULL) { + guint *c; + + for (c = key->keycodes; *c; ++c) { + if (*c == keycode) + return TRUE; + } + } + return FALSE; +} + +gboolean +match_key (Key *key, XEvent *event) +{ + guint keyval; + GdkModifierType consumed; + gint group; + + if (key == NULL) + return FALSE; + + setup_modifiers (); + +#ifdef HAVE_X11_EXTENSIONS_XKB_H + if (have_xkb (event->xkey.display)) + group = XkbGroupForCoreState (event->xkey.state); + else +#endif + group = (event->xkey.state & GDK_Mode_switch) ? 1 : 0; + + /* Check if we find a keysym that matches our current state */ + if (gdk_keymap_translate_keyboard_state (NULL, event->xkey.keycode, + event->xkey.state, group, + &keyval, NULL, NULL, &consumed)) { + guint lower, upper; + + gdk_keyval_convert_case (keyval, &lower, &upper); + + /* If we are checking against the lower version of the + * keysym, we might need the Shift state for matching, + * so remove it from the consumed modifiers */ + if (lower == key->keysym) + consumed &= ~GDK_SHIFT_MASK; + + return ((lower == key->keysym || upper == key->keysym) + && (event->xkey.state & ~consumed & msd_used_mods) == key->state); + } + + /* The key we passed doesn't have a keysym, so try with just the keycode */ + return (key != NULL + && key->state == (event->xkey.state & msd_used_mods) + && key_uses_keycode (key, event->xkey.keycode)); +} diff --git a/plugins/common/msd-keygrab.h b/plugins/common/msd-keygrab.h new file mode 100644 index 0000000..8ebef21 --- /dev/null +++ b/plugins/common/msd-keygrab.h @@ -0,0 +1,51 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2008 Jens Granseuer + * + * 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. + */ + +#ifndef __MSD_COMMON_KEYGRAB_H +#define __MSD_COMMON_KEYGRAB_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +typedef struct { + guint keysym; + guint state; + guint *keycodes; +} Key; + + +void grab_key_unsafe (Key *key, + gboolean grab, + GSList *screens); + +gboolean match_key (Key *key, + XEvent *event); + +gboolean key_uses_keycode (const Key *key, + guint keycode); + +#ifdef __cplusplus +} +#endif + +#endif /* __MSD_COMMON_KEYGRAB_H */ diff --git a/plugins/common/msd-osd-window.c b/plugins/common/msd-osd-window.c new file mode 100644 index 0000000..123313c --- /dev/null +++ b/plugins/common/msd-osd-window.c @@ -0,0 +1,573 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * On-screen-display (OSD) window for mate-settings-daemon's plugins + * + * Copyright (C) 2006-2007 William Jon McCann + * Copyright (C) 2009 Novell, Inc + * + * Authors: + * William Jon McCann + * Federico Mena-Quintero + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2, 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 Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser 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 +#include +#include +#include +#include +#include + +#include "msd-osd-window.h" + +#define DIALOG_TIMEOUT 2000 /* dialog timeout in ms */ +#define DIALOG_FADE_TIMEOUT 1500 /* timeout before fade starts */ +#define FADE_TIMEOUT 10 /* timeout in ms between each frame of the fade */ + +#define BG_ALPHA 0.75 + +#define MSD_OSD_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_OSD_WINDOW, MsdOsdWindowPrivate)) + +struct MsdOsdWindowPrivate +{ + guint is_composited : 1; + guint hide_timeout_id; + guint fade_timeout_id; + double fade_out_alpha; +}; + +enum { + EXPOSE_WHEN_COMPOSITED, + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL] = { 0 }; + +G_DEFINE_TYPE (MsdOsdWindow, msd_osd_window, GTK_TYPE_WINDOW) + +static gboolean +fade_timeout (MsdOsdWindow *window) +{ + if (window->priv->fade_out_alpha <= 0.0) { + gtk_widget_hide (GTK_WIDGET (window)); + + /* Reset it for the next time */ + window->priv->fade_out_alpha = 1.0; + window->priv->fade_timeout_id = 0; + + return FALSE; + } else { + GdkRectangle rect; + GtkWidget *win = GTK_WIDGET (window); + GtkAllocation allocation; + + window->priv->fade_out_alpha -= 0.10; + + rect.x = 0; + rect.y = 0; + gtk_widget_get_allocation (win, &allocation); + rect.width = allocation.width; + rect.height = allocation.height; + + gtk_widget_realize (win); + gdk_window_invalidate_rect (gtk_widget_get_window (win), &rect, FALSE); + } + + return TRUE; +} + +static gboolean +hide_timeout (MsdOsdWindow *window) +{ + if (window->priv->is_composited) { + window->priv->hide_timeout_id = 0; + window->priv->fade_timeout_id = g_timeout_add (FADE_TIMEOUT, + (GSourceFunc) fade_timeout, + window); + } else { + gtk_widget_hide (GTK_WIDGET (window)); + } + + return FALSE; +} + +static void +remove_hide_timeout (MsdOsdWindow *window) +{ + if (window->priv->hide_timeout_id != 0) { + g_source_remove (window->priv->hide_timeout_id); + window->priv->hide_timeout_id = 0; + } + + if (window->priv->fade_timeout_id != 0) { + g_source_remove (window->priv->fade_timeout_id); + window->priv->fade_timeout_id = 0; + window->priv->fade_out_alpha = 1.0; + } +} + +static void +add_hide_timeout (MsdOsdWindow *window) +{ + int timeout; + + if (window->priv->is_composited) { + timeout = DIALOG_FADE_TIMEOUT; + } else { + timeout = DIALOG_TIMEOUT; + } + window->priv->hide_timeout_id = g_timeout_add (timeout, + (GSourceFunc) hide_timeout, + window); +} + +void +msd_osd_window_draw_rounded_rectangle (cairo_t* cr, + gdouble aspect, + gdouble x, + gdouble y, + gdouble corner_radius, + gdouble width, + gdouble height) +{ + gdouble radius = corner_radius / aspect; + + cairo_move_to (cr, x + radius, y); + + cairo_line_to (cr, + x + width - radius, + y); + cairo_arc (cr, + x + width - radius, + y + radius, + radius, + -90.0f * G_PI / 180.0f, + 0.0f * G_PI / 180.0f); + cairo_line_to (cr, + x + width, + y + height - radius); + cairo_arc (cr, + x + width - radius, + y + height - radius, + radius, + 0.0f * G_PI / 180.0f, + 90.0f * G_PI / 180.0f); + cairo_line_to (cr, + x + radius, + y + height); + cairo_arc (cr, + x + radius, + y + height - radius, + radius, + 90.0f * G_PI / 180.0f, + 180.0f * G_PI / 180.0f); + cairo_line_to (cr, + x, + y + radius); + cairo_arc (cr, + x + radius, + y + radius, + radius, + 180.0f * G_PI / 180.0f, + 270.0f * G_PI / 180.0f); + cairo_close_path (cr); +} + +void +msd_osd_window_color_reverse (const GdkColor *a, + GdkColor *b) +{ + gdouble red; + gdouble green; + gdouble blue; + gdouble h; + gdouble s; + gdouble v; + + red = (gdouble) a->red / 65535.0; + green = (gdouble) a->green / 65535.0; + blue = (gdouble) a->blue / 65535.0; + + gtk_rgb_to_hsv (red, green, blue, &h, &s, &v); + + v = 0.5 + (0.5 - v); + if (v > 1.0) + v = 1.0; + else if (v < 0.0) + v = 0.0; + + gtk_hsv_to_rgb (h, s, v, &red, &green, &blue); + + b->red = red * 65535.0; + b->green = green * 65535.0; + b->blue = blue * 65535.0; +} + +/* This is our expose-event handler when the window is in a compositing manager. + * We draw everything by hand, using Cairo, so that we can have a nice + * transparent/rounded look. + */ +static void +expose_when_composited (GtkWidget *widget, GdkEventExpose *event) +{ + MsdOsdWindow *window; + cairo_t *context; + cairo_t *cr; + cairo_surface_t *surface; + int width; + int height; + GtkStyle *style; + GdkColor color; + double r, g, b; + + window = MSD_OSD_WINDOW (widget); + + context = gdk_cairo_create (gtk_widget_get_window (widget)); + + style = gtk_widget_get_style (widget); + cairo_set_operator (context, CAIRO_OPERATOR_SOURCE); + gtk_window_get_size (GTK_WINDOW (widget), &width, &height); + + surface = cairo_surface_create_similar (cairo_get_target (context), + CAIRO_CONTENT_COLOR_ALPHA, + width, + height); + + if (cairo_surface_status (surface) != CAIRO_STATUS_SUCCESS) { + goto done; + } + + cr = cairo_create (surface); + if (cairo_status (cr) != CAIRO_STATUS_SUCCESS) { + goto done; + } + cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.0); + cairo_set_operator (cr, CAIRO_OPERATOR_OVER); + cairo_paint (cr); + + /* draw a box */ + msd_osd_window_draw_rounded_rectangle (cr, 1.0, 0.5, 0.5, height / 10, width-1, height-1); + msd_osd_window_color_reverse (&style->bg[GTK_STATE_NORMAL], &color); + r = (float)color.red / 65535.0; + g = (float)color.green / 65535.0; + b = (float)color.blue / 65535.0; + cairo_set_source_rgba (cr, r, g, b, BG_ALPHA); + cairo_fill_preserve (cr); + + msd_osd_window_color_reverse (&style->text_aa[GTK_STATE_NORMAL], &color); + r = (float)color.red / 65535.0; + g = (float)color.green / 65535.0; + b = (float)color.blue / 65535.0; + cairo_set_source_rgba (cr, r, g, b, BG_ALPHA / 2); + cairo_set_line_width (cr, 1); + cairo_stroke (cr); + + g_signal_emit (window, signals[EXPOSE_WHEN_COMPOSITED], 0, cr); + + cairo_destroy (cr); + + /* Make sure we have a transparent background */ + cairo_rectangle (context, 0, 0, width, height); + cairo_set_source_rgba (context, 0.0, 0.0, 0.0, 0.0); + cairo_fill (context); + + cairo_set_source_surface (context, surface, 0, 0); + cairo_paint_with_alpha (context, window->priv->fade_out_alpha); + + done: + if (surface != NULL) { + cairo_surface_destroy (surface); + } + cairo_destroy (context); +} + +/* This is our expose-event handler when the window is *not* in a compositing manager. + * We just draw a rectangular frame by hand. We do this with hardcoded drawing code, + * instead of GtkFrame, to avoid changing the window's internal widget hierarchy: in + * either case (composited or non-composited), callers can assume that this works + * identically to a GtkWindow without any intermediate widgetry. + */ +static void +expose_when_not_composited (GtkWidget *widget, GdkEventExpose *event) +{ + MsdOsdWindow *window; + GtkAllocation allocation; + + window = MSD_OSD_WINDOW (widget); + + gtk_widget_get_allocation (widget, &allocation); + + gtk_paint_shadow (gtk_widget_get_style (widget), + gtk_widget_get_window (widget), + gtk_widget_get_state (widget), + GTK_SHADOW_OUT, + &event->area, + widget, + NULL, /* NULL detail -> themes should use the MsdOsdWindow widget name, probably */ + 0, + 0, + allocation.width, + allocation.height); +} + +static gboolean +msd_osd_window_expose_event (GtkWidget *widget, + GdkEventExpose *event) +{ + MsdOsdWindow *window; + GtkWidget *child; + + window = MSD_OSD_WINDOW (widget); + + if (window->priv->is_composited) + expose_when_composited (widget, event); + else + expose_when_not_composited (widget, event); + + child = gtk_bin_get_child (GTK_BIN (window)); + if (child) + gtk_container_propagate_expose (GTK_CONTAINER (window), child, event); + + return FALSE; +} + +static void +msd_osd_window_real_show (GtkWidget *widget) +{ + MsdOsdWindow *window; + + if (GTK_WIDGET_CLASS (msd_osd_window_parent_class)->show) { + GTK_WIDGET_CLASS (msd_osd_window_parent_class)->show (widget); + } + + window = MSD_OSD_WINDOW (widget); + remove_hide_timeout (window); + add_hide_timeout (window); +} + +static void +msd_osd_window_real_hide (GtkWidget *widget) +{ + MsdOsdWindow *window; + + if (GTK_WIDGET_CLASS (msd_osd_window_parent_class)->hide) { + GTK_WIDGET_CLASS (msd_osd_window_parent_class)->hide (widget); + } + + window = MSD_OSD_WINDOW (widget); + remove_hide_timeout (window); +} + +static void +msd_osd_window_real_realize (GtkWidget *widget) +{ + GdkColormap *colormap; + GtkAllocation allocation; + GdkBitmap *mask; + cairo_t *cr; + + colormap = gdk_screen_get_rgba_colormap (gtk_widget_get_screen (widget)); + + if (colormap != NULL) { + gtk_widget_set_colormap (widget, colormap); + } + + if (GTK_WIDGET_CLASS (msd_osd_window_parent_class)->realize) { + GTK_WIDGET_CLASS (msd_osd_window_parent_class)->realize (widget); + } + + gtk_widget_get_allocation (widget, &allocation); + mask = gdk_pixmap_new (gtk_widget_get_window (widget), + allocation.width, + allocation.height, + 1); + cr = gdk_cairo_create (mask); + + cairo_set_source_rgba (cr, 1., 1., 1., 0.); + cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); + cairo_paint (cr); + + /* make the whole window ignore events */ + gdk_window_input_shape_combine_mask (gtk_widget_get_window (widget), mask, 0, 0); + g_object_unref (mask); + cairo_destroy (cr); +} + +static void +msd_osd_window_style_set (GtkWidget *widget, + GtkStyle *previous_style) +{ + GtkStyle *style; + + GTK_WIDGET_CLASS (msd_osd_window_parent_class)->style_set (widget, previous_style); + + /* We set our border width to 12 (per the MATE standard), plus the + * thickness of the frame that we draw in our expose handler. This will + * make our child be 12 pixels away from the frame. + */ + + style = gtk_widget_get_style (widget); + gtk_container_set_border_width (GTK_CONTAINER (widget), 12 + MAX (style->xthickness, style->ythickness)); +} + +static void +msd_osd_window_size_request (GtkWidget *widget, + GtkRequisition *requisition) +{ + GtkStyle *style; + + GTK_WIDGET_CLASS (msd_osd_window_parent_class)->size_request (widget, requisition); + + /* See the comment in msd_osd_window_style_set() for why we add the thickness here */ + + style = gtk_widget_get_style (widget); + + requisition->width += style->xthickness; + requisition->height += style->ythickness; +} + +static GObject * +msd_osd_window_constructor (GType type, + guint n_construct_properties, + GObjectConstructParam *construct_params) +{ + GObject *object; + + object = G_OBJECT_CLASS (msd_osd_window_parent_class)->constructor (type, n_construct_properties, construct_params); + + g_object_set (object, + "type", GTK_WINDOW_POPUP, + "type-hint", GDK_WINDOW_TYPE_HINT_NOTIFICATION, + "skip-taskbar-hint", TRUE, + "skip-pager-hint", TRUE, + "focus-on-map", FALSE, + NULL); + + return object; +} + +static void +msd_osd_window_class_init (MsdOsdWindowClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + gobject_class->constructor = msd_osd_window_constructor; + + widget_class->show = msd_osd_window_real_show; + widget_class->hide = msd_osd_window_real_hide; + widget_class->realize = msd_osd_window_real_realize; + widget_class->style_set = msd_osd_window_style_set; + widget_class->size_request = msd_osd_window_size_request; + widget_class->expose_event = msd_osd_window_expose_event; + + signals[EXPOSE_WHEN_COMPOSITED] = g_signal_new ("expose-when-composited", + G_TYPE_FROM_CLASS (gobject_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (MsdOsdWindowClass, expose_when_composited), + NULL, NULL, + g_cclosure_marshal_VOID__POINTER, + G_TYPE_NONE, 1, + G_TYPE_POINTER); + + g_type_class_add_private (klass, sizeof (MsdOsdWindowPrivate)); +} + +/** + * msd_osd_window_is_composited: + * @window: a #MsdOsdWindow + * + * Return value: whether the window was created on a composited screen. + */ +gboolean +msd_osd_window_is_composited (MsdOsdWindow *window) +{ + return window->priv->is_composited; +} + +/** + * msd_osd_window_is_valid: + * @window: a #MsdOsdWindow + * + * Return value: TRUE if the @window's idea of being composited matches whether + * its current screen is actually composited. + */ +gboolean +msd_osd_window_is_valid (MsdOsdWindow *window) +{ + GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (window)); + return gdk_screen_is_composited (screen) == window->priv->is_composited; +} + +static void +msd_osd_window_init (MsdOsdWindow *window) +{ + GdkScreen *screen; + + window->priv = MSD_OSD_WINDOW_GET_PRIVATE (window); + + screen = gtk_widget_get_screen (GTK_WIDGET (window)); + + window->priv->is_composited = gdk_screen_is_composited (screen); + + if (window->priv->is_composited) { + gdouble scalew, scaleh, scale; + gint size; + + gtk_window_set_decorated (GTK_WINDOW (window), FALSE); + gtk_widget_set_app_paintable (GTK_WIDGET (window), TRUE); + + /* assume 130x130 on a 640x480 display and scale from there */ + scalew = gdk_screen_get_width (screen) / 640.0; + scaleh = gdk_screen_get_height (screen) / 480.0; + scale = MIN (scalew, scaleh); + size = 130 * MAX (1, scale); + + gtk_window_set_default_size (GTK_WINDOW (window), size, size); + + window->priv->fade_out_alpha = 1.0; + } else { + gtk_container_set_border_width (GTK_CONTAINER (window), 12); + } +} + +GtkWidget * +msd_osd_window_new (void) +{ + return g_object_new (MSD_TYPE_OSD_WINDOW, NULL); +} + +/** + * msd_osd_window_update_and_hide: + * @window: a #MsdOsdWindow + * + * Queues the @window for immediate drawing, and queues a timer to hide the window. + */ +void +msd_osd_window_update_and_hide (MsdOsdWindow *window) +{ + remove_hide_timeout (window); + add_hide_timeout (window); + + if (window->priv->is_composited) { + gtk_widget_queue_draw (GTK_WIDGET (window)); + } +} diff --git a/plugins/common/msd-osd-window.h b/plugins/common/msd-osd-window.h new file mode 100644 index 0000000..f539e5e --- /dev/null +++ b/plugins/common/msd-osd-window.h @@ -0,0 +1,98 @@ +/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8; tab-width: 8 -*- + * + * On-screen-display (OSD) window for mate-settings-daemon's plugins + * + * Copyright (C) 2006 William Jon McCann + * Copyright (C) 2009 Novell, Inc + * + * Authors: + * William Jon McCann + * Federico Mena-Quintero + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2, 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 Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser 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. + * + */ + +/* MsdOsdWindow is an "on-screen-display" window (OSD). It is the cute, + * semi-transparent, curved popup that appears when you press a hotkey global to + * the desktop, such as to change the volume, switch your monitor's parameters, + * etc. + * + * You can create a MsdOsdWindow and use it as a normal GtkWindow. It will + * automatically center itself, figure out if it needs to be composited, etc. + * Just pack your widgets in it, sit back, and enjoy the ride. + */ + +#ifndef MSD_OSD_WINDOW_H +#define MSD_OSD_WINDOW_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Alpha value to be used for foreground objects drawn in an OSD window */ +#define MSD_OSD_WINDOW_FG_ALPHA 1.0 + +#define MSD_TYPE_OSD_WINDOW (msd_osd_window_get_type ()) +#define MSD_OSD_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MSD_TYPE_OSD_WINDOW, MsdOsdWindow)) +#define MSD_OSD_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MSD_TYPE_OSD_WINDOW, MsdOsdWindowClass)) +#define MSD_IS_OSD_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MSD_TYPE_OSD_WINDOW)) +#define MSD_IS_OSD_WINDOW_CLASS(klass) (G_TYPE_INSTANCE_GET_CLASS ((klass), MSD_TYPE_OSD_WINDOW)) +#define MSD_OSD_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MSD_TYPE_OSD_WINDOW, MsdOsdWindowClass)) + +typedef struct MsdOsdWindow MsdOsdWindow; +typedef struct MsdOsdWindowClass MsdOsdWindowClass; +typedef struct MsdOsdWindowPrivate MsdOsdWindowPrivate; + +struct MsdOsdWindow { + GtkWindow parent; + + MsdOsdWindowPrivate *priv; +}; + +struct MsdOsdWindowClass { + GtkWindowClass parent_class; + + void (* expose_when_composited) (MsdOsdWindow *window, cairo_t *cr); +}; + +GType msd_osd_window_get_type (void); + +GtkWidget * msd_osd_window_new (void); +gboolean msd_osd_window_is_composited (MsdOsdWindow *window); +gboolean msd_osd_window_is_valid (MsdOsdWindow *window); +void msd_osd_window_update_and_hide (MsdOsdWindow *window); + +void msd_osd_window_draw_rounded_rectangle (cairo_t *cr, + gdouble aspect, + gdouble x, + gdouble y, + gdouble corner_radius, + gdouble width, + gdouble height); + +void msd_osd_window_color_reverse (const GdkColor *a, + GdkColor *b); + +#ifdef __cplusplus +} +#endif + +#endif -- cgit v1.2.1