diff options
author | Stefano Karapetsas <[email protected]> | 2013-11-12 16:50:44 +0100 |
---|---|---|
committer | Stefano Karapetsas <[email protected]> | 2013-11-12 16:50:44 +0100 |
commit | d5027c1631b5db4197f9d3a6aa518ce0265ac05f (patch) | |
tree | cf5bcdc0b965a1a1f803bbd704300ef51255cb8f | |
parent | fa5f117527e6674168ef613b5e50190fa08d9e26 (diff) | |
download | mate-screensaver-d5027c1631b5db4197f9d3a6aa518ce0265ac05f.tar.bz2 mate-screensaver-d5027c1631b5db4197f9d3a6aa518ce0265ac05f.tar.xz |
Add GTK3 support
-rw-r--r-- | src/gs-fade.c | 30 | ||||
-rw-r--r-- | src/gs-grab-x11.c | 24 | ||||
-rw-r--r-- | src/gs-job.c | 18 | ||||
-rw-r--r-- | src/gs-lock-plug.c | 218 | ||||
-rw-r--r-- | src/gs-manager.c | 23 | ||||
-rw-r--r-- | src/gs-visual-gl.c | 4 | ||||
-rw-r--r-- | src/gs-watcher-x11.c | 17 | ||||
-rw-r--r-- | src/gs-window-x11.c | 302 | ||||
-rw-r--r-- | src/gs-window.h | 5 |
9 files changed, 627 insertions, 14 deletions
diff --git a/src/gs-fade.c b/src/gs-fade.c index e894b36..eaf095e 100644 --- a/src/gs-fade.c +++ b/src/gs-fade.c @@ -43,7 +43,7 @@ #define MATE_DESKTOP_USE_UNSTABLE_API -#include "libmateui/mate-rr.h" +#include "libmate-desktop/mate-rr.h" /* XFree86 4.x+ Gamma fading */ @@ -217,7 +217,11 @@ xf86_whack_gamma (int screen, g2.blue = XF86_MIN_GAMMA; } +#if GTK_CHECK_VERSION (3, 0, 0) + status = XF86VidModeSetGamma (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), screen, &g2); +#else status = XF86VidModeSetGamma (GDK_DISPLAY (), screen, &g2); +#endif } else { @@ -237,7 +241,11 @@ xf86_whack_gamma (int screen, b[i] = gamma_info->b[i] * ratio; } +#if GTK_CHECK_VERSION (3, 0, 0) + status = XF86VidModeSetGammaRamp (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), screen, gamma_info->size, r, g, b); +#else status = XF86VidModeSetGammaRamp (GDK_DISPLAY (), screen, gamma_info->size, r, g, b); +#endif g_free (r); g_free (g); @@ -313,7 +321,11 @@ gamma_fade_setup (GSFade *fade, int screen_idx) { /* have ramps */ +#if GTK_CHECK_VERSION (3, 0, 0) + res = XF86VidModeGetGammaRampSize (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), screen_idx, &screen_priv->info->size); +#else res = XF86VidModeGetGammaRampSize (GDK_DISPLAY (), screen_idx, &screen_priv->info->size); +#endif if (!res || screen_priv->info->size <= 0) { screen_priv->fade_type = FADE_TYPE_GAMMA_NUMBER; @@ -330,7 +342,11 @@ gamma_fade_setup (GSFade *fade, int screen_idx) goto test_number; } +#if GTK_CHECK_VERSION (3, 0, 0) + res = XF86VidModeGetGammaRamp (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), +#else res = XF86VidModeGetGammaRamp (GDK_DISPLAY (), +#endif screen_idx, screen_priv->info->size, screen_priv->info->r, @@ -350,7 +366,11 @@ test_number: { /* only have gamma parameter, not ramps. */ +#if GTK_CHECK_VERSION (3, 0, 0) + res = XF86VidModeGetGamma (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), screen_idx, &screen_priv->vmg); +#else res = XF86VidModeGetGamma (GDK_DISPLAY (), screen_idx, &screen_priv->vmg); +#endif if (! res) { screen_priv->fade_type = FADE_TYPE_NONE; @@ -432,11 +452,19 @@ check_gamma_extension (GSFade *fade, int screen_idx) screen_priv = &fade->priv->screen_priv[screen_idx]; #ifdef HAVE_XF86VMODE_GAMMA +#if GTK_CHECK_VERSION (3, 0, 0) + res = XF86VidModeQueryExtension (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), &event, &error); +#else res = XF86VidModeQueryExtension (GDK_DISPLAY (), &event, &error); +#endif if (! res) goto fade_none; +#if GTK_CHECK_VERSION (3, 0, 0) + res = safe_XF86VidModeQueryVersion (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), &major, &minor); +#else res = safe_XF86VidModeQueryVersion (GDK_DISPLAY (), &major, &minor); +#endif if (! res) goto fade_none; diff --git a/src/gs-grab-x11.c b/src/gs-grab-x11.c index 40650fb..61a376c 100644 --- a/src/gs-grab-x11.c +++ b/src/gs-grab-x11.c @@ -58,6 +58,7 @@ struct GSGrabPrivate GtkWidget *invisible; }; +#if !GTK_CHECK_VERSION (3, 0, 0) static GdkCursor * get_cursor (void) { @@ -82,6 +83,7 @@ get_cursor (void) return cursor; } +#endif static const char * grab_string (int status) @@ -126,7 +128,11 @@ xorg_lock_smasher_set_active (GSGrab *grab, { int status, event, error; +#if GTK_CHECK_VERSION (3, 0, 0) + if (!XF86MiscQueryExtension (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), &event, &error)) +#else if (!XF86MiscQueryExtension (GDK_DISPLAY (), &event, &error)) +#endif { gs_debug ("No XFree86-Misc extension present"); return; @@ -143,7 +149,11 @@ xorg_lock_smasher_set_active (GSGrab *grab, gdk_error_trap_push (); +#if GTK_CHECK_VERSION (3, 0, 0) + status = XF86MiscSetGrabKeysState (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), active); +#else status = XF86MiscSetGrabKeysState (GDK_DISPLAY (), active); +#endif gdk_display_sync (gdk_display_get_default ()); gdk_error_trap_pop (); @@ -216,7 +226,11 @@ gs_grab_get_mouse (GSGrab *grab, g_return_val_if_fail (window != NULL, FALSE); g_return_val_if_fail (screen != NULL, FALSE); +#if GTK_CHECK_VERSION (3, 0, 0) + cursor = gdk_cursor_new (GDK_BLANK_CURSOR); +#else cursor = get_cursor (); +#endif gs_debug ("Grabbing mouse widget=%X", (guint32) GDK_WINDOW_XID (window)); status = gdk_pointer_grab (window, TRUE, 0, NULL, @@ -438,9 +452,13 @@ gs_grab_nuke_focus (void) gdk_error_trap_push (); +#if GTK_CHECK_VERSION (3, 0, 0) + XGetInputFocus (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), &focus, &rev); + XSetInputFocus (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), None, RevertToNone, CurrentTime); +#else XGetInputFocus (GDK_DISPLAY (), &focus, &rev); - XSetInputFocus (GDK_DISPLAY (), None, RevertToNone, CurrentTime); +#endif gdk_display_sync (gdk_display_get_default ()); gdk_error_trap_pop (); @@ -584,7 +602,11 @@ gs_grab_grab_offscreen (GSGrab *grab, gs_debug ("Grabbing an offscreen window"); screen = gtk_invisible_get_screen (GTK_INVISIBLE (grab->priv->invisible)); +#if GTK_CHECK_VERSION (3, 0, 0) + res = gs_grab_grab_window (grab, gtk_widget_get_window (GTK_WIDGET (grab->priv->invisible)), screen, hide_cursor); +#else res = gs_grab_grab_window (grab, grab->priv->invisible->window, screen, hide_cursor); +#endif return res; } diff --git a/src/gs-job.c b/src/gs-job.c index 0a90ba8..af77442 100644 --- a/src/gs-job.c +++ b/src/gs-job.c @@ -80,7 +80,11 @@ widget_get_id_string (GtkWidget *widget) g_return_val_if_fail (widget != NULL, NULL); id = g_strdup_printf ("0x%X", +#if GTK_CHECK_VERSION (3, 0, 0) + (guint32)GDK_WINDOW_XID (gtk_widget_get_window (widget))); +#else (guint32)GDK_WINDOW_XID (widget->window)); +#endif return id; } @@ -339,6 +343,19 @@ spawn_on_widget (GtkWidget *widget, env = get_env_vars (widget); error = NULL; +#if GTK_CHECK_VERSION (3, 0, 0) + result = g_spawn_async_with_pipes (NULL, + argv, + (char **)env->pdata, + G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, + NULL, + NULL, + &child_pid, + NULL, + NULL, + &standard_error, + &error); +#else result = gdk_spawn_on_screen_with_pipes (gtk_widget_get_screen (widget), NULL, argv, @@ -351,6 +368,7 @@ spawn_on_widget (GtkWidget *widget, NULL, &standard_error, &error); +#endif for (i = 0; i < env->len; i++) { g_free (g_ptr_array_index (env, i)); diff --git a/src/gs-lock-plug.c b/src/gs-lock-plug.c index 6f0b465..3945c1b 100644 --- a/src/gs-lock-plug.c +++ b/src/gs-lock-plug.c @@ -38,6 +38,17 @@ #include <gtk/gtk.h> #include <gio/gio.h> +#if GTK_CHECK_VERSION (3, 0, 0) +#include <gdk/gdkkeysyms-compat.h> +#include <gtk/gtkx.h> +#define MATE_DESKTOP_USE_UNSTABLE_API +#include <libmate-desktop/mate-desktop-utils.h> +#define gdk_spawn_command_line_on_screen mate_gdk_spawn_command_line_on_screen +#define GTK_WIDGET_VISIBLE gtk_widget_get_visible +#define GTK_WIDGET_IS_SENSITIVE gtk_widget_is_sensitive +#define GTK_WIDGET_HAS_FOCUS gtk_widget_has_focus +#endif + #ifdef WITH_KBD_LAYOUT_INDICATOR #include <libmatekbd/matekbd-indicator.h> #endif @@ -524,7 +535,11 @@ gs_lock_plug_run (GSLockPlug *plug) g_object_ref (plug); +#if GTK_CHECK_VERSION (3, 0, 0) + was_modal = gtk_window_get_modal (GTK_WINDOW (plug)); +#else was_modal = GTK_WINDOW (plug)->modal; +#endif if (!was_modal) { gtk_window_set_modal (GTK_WINDOW (plug), TRUE); @@ -658,6 +673,182 @@ rounded_rectangle (cairo_t *cr, cairo_close_path (cr); } +#if GTK_CHECK_VERSION (3, 0, 0) +/* copied from gnome-screensaver 3.x */ + +/** + * go_cairo_convert_data_to_pixbuf: + * @src: a pointer to pixel data in cairo format + * @dst: a pointer to pixel data in pixbuf format + * @width: image width + * @height: image height + * @rowstride: data rowstride + * + * Converts the pixel data stored in @src in CAIRO_FORMAT_ARGB32 cairo format + * to GDK_COLORSPACE_RGB pixbuf format and move them + * to @dst. If @src == @dst, pixel are converted in place. + **/ + +static void +go_cairo_convert_data_to_pixbuf (unsigned char *dst, + unsigned char const *src, + int width, + int height, + int rowstride) +{ + int i,j; + unsigned int t; + unsigned char a, b, c; + + g_return_if_fail (dst != NULL); + +#define MULT(d,c,a,t) G_STMT_START { t = (a)? c * 255 / a: 0; d = t;} G_STMT_END + + if (src == dst || src == NULL) { + for (i = 0; i < height; i++) { + for (j = 0; j < width; j++) { +#if G_BYTE_ORDER == G_LITTLE_ENDIAN + MULT(a, dst[2], dst[3], t); + MULT(b, dst[1], dst[3], t); + MULT(c, dst[0], dst[3], t); + dst[0] = a; + dst[1] = b; + dst[2] = c; +#else + MULT(a, dst[1], dst[0], t); + MULT(b, dst[2], dst[0], t); + MULT(c, dst[3], dst[0], t); + dst[3] = dst[0]; + dst[0] = a; + dst[1] = b; + dst[2] = c; +#endif + dst += 4; + } + dst += rowstride - width * 4; + } + } else { + for (i = 0; i < height; i++) { + for (j = 0; j < width; j++) { +#if G_BYTE_ORDER == G_LITTLE_ENDIAN + MULT(dst[0], src[2], src[3], t); + MULT(dst[1], src[1], src[3], t); + MULT(dst[2], src[0], src[3], t); + dst[3] = src[3]; +#else + MULT(dst[0], src[1], src[0], t); + MULT(dst[1], src[2], src[0], t); + MULT(dst[2], src[3], src[0], t); + dst[3] = src[0]; +#endif + src += 4; + dst += 4; + } + src += rowstride - width * 4; + dst += rowstride - width * 4; + } + } +#undef MULT +} + +static void +cairo_to_pixbuf (guint8 *src_data, + GdkPixbuf *dst_pixbuf) +{ + unsigned char *src; + unsigned char *dst; + guint w; + guint h; + guint rowstride; + + w = gdk_pixbuf_get_width (dst_pixbuf); + h = gdk_pixbuf_get_height (dst_pixbuf); + rowstride = gdk_pixbuf_get_rowstride (dst_pixbuf); + + dst = gdk_pixbuf_get_pixels (dst_pixbuf); + src = src_data; + + go_cairo_convert_data_to_pixbuf (dst, src, w, h, rowstride); +} + +static GdkPixbuf * +frame_pixbuf (GdkPixbuf *source) +{ + GdkPixbuf *dest; + cairo_t *cr; + cairo_surface_t *surface; + guint w; + guint h; + guint rowstride; + int frame_width; + double radius; + guint8 *data; + + frame_width = 5; + + w = gdk_pixbuf_get_width (source) + frame_width * 2; + h = gdk_pixbuf_get_height (source) + frame_width * 2; + radius = w / 10; + + dest = gdk_pixbuf_new (GDK_COLORSPACE_RGB, + TRUE, + 8, + w, + h); + rowstride = gdk_pixbuf_get_rowstride (dest); + + + data = g_new0 (guint8, h * rowstride); + + surface = cairo_image_surface_create_for_data (data, + CAIRO_FORMAT_ARGB32, + w, + h, + rowstride); + cr = cairo_create (surface); + cairo_surface_destroy (surface); + + /* set up image */ + cairo_rectangle (cr, 0, 0, w, h); + cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.0); + cairo_fill (cr); + + rounded_rectangle (cr, + 1.0, + frame_width + 0.5, + frame_width + 0.5, + radius, + w - frame_width * 2 - 1, + h - frame_width * 2 - 1); + cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 0.3); + cairo_fill_preserve (cr); + + surface = surface_from_pixbuf (source); + cairo_set_source_surface (cr, surface, frame_width, frame_width); + cairo_fill (cr); + cairo_surface_destroy (surface); + + cairo_to_pixbuf (data, dest); + + cairo_destroy (cr); + g_free (data); + + return dest; +} + +/* end copied from gdm-user.c */ + +static void +image_set_from_pixbuf (GtkImage *image, + GdkPixbuf *source) +{ + GdkPixbuf *pixbuf; + + pixbuf = frame_pixbuf (source); + gtk_image_set_from_pixbuf (image, pixbuf); + g_object_unref (pixbuf); +} +#else static void image_set_from_pixbuf (GtkImage *image, GdkPixbuf *source) @@ -733,7 +924,7 @@ image_set_from_pixbuf (GtkImage *image, cairo_destroy (cr_mask); cairo_destroy (cr); } - +#endif static gboolean check_user_file (const gchar *filename, @@ -891,6 +1082,7 @@ forward_key_events (GSLockPlug *plug) } } +#if !GTK_CHECK_VERSION (3, 0, 0) static void gs_lock_plug_size_request (GtkWidget *widget, GtkRequisition *requisition) @@ -923,6 +1115,7 @@ gs_lock_plug_size_request (GtkWidget *widget, requisition->height = mod_height; } } +#endif static void gs_lock_plug_set_logout_enabled (GSLockPlug *plug, @@ -1112,7 +1305,11 @@ gs_lock_plug_close (GSLockPlug *plug) GdkEvent *event; event = gdk_event_new (GDK_DELETE); +#if GTK_CHECK_VERSION (3, 0, 0) + event->any.window = g_object_ref (gtk_widget_get_window(widget)); +#else event->any.window = g_object_ref (widget->window); +#endif event->any.send_event = TRUE; gtk_main_do_event (event); @@ -1133,7 +1330,9 @@ gs_lock_plug_class_init (GSLockPlugClass *klass) widget_class->style_set = gs_lock_plug_style_set; widget_class->show = gs_lock_plug_show; widget_class->hide = gs_lock_plug_hide; +#if !GTK_CHECK_VERSION (3, 0, 0) widget_class->size_request = gs_lock_plug_size_request; +#endif klass->close = gs_lock_plug_close; @@ -1319,7 +1518,12 @@ gs_lock_plug_set_busy (GSLockPlug *plug) top_level = gtk_widget_get_toplevel (GTK_WIDGET (plug)); cursor = gdk_cursor_new (GDK_WATCH); + +#if GTK_CHECK_VERSION (3, 0, 0) + gdk_window_set_cursor (gtk_widget_get_window (top_level), cursor); +#else gdk_window_set_cursor (top_level->window, cursor); +#endif gdk_cursor_unref (cursor); } @@ -1332,7 +1536,11 @@ gs_lock_plug_set_ready (GSLockPlug *plug) top_level = gtk_widget_get_toplevel (GTK_WIDGET (plug)); cursor = gdk_cursor_new (GDK_LEFT_PTR); +#if GTK_CHECK_VERSION (3, 0, 0) + gdk_window_set_cursor (gtk_widget_get_window (top_level), cursor); +#else gdk_window_set_cursor (top_level->window, cursor); +#endif gdk_cursor_unref (cursor); } @@ -1442,7 +1650,11 @@ gs_lock_plug_add_button (GSLockPlug *plug, button = gtk_button_new_from_stock (button_text); +#if GTK_CHECK_VERSION (3, 0, 0) + gtk_widget_set_can_default (button, TRUE); +#else GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); +#endif gtk_widget_show (button); @@ -1962,7 +2174,11 @@ gs_lock_plug_init (GSLockPlug *plug) { XklEngine *engine; +#if GTK_CHECK_VERSION (3, 0, 0) + engine = xkl_engine_get_instance (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ())); +#else engine = xkl_engine_get_instance (GDK_DISPLAY ()); +#endif if (xkl_engine_get_num_groups (engine) > 1) { GtkWidget *layout_indicator; diff --git a/src/gs-manager.c b/src/gs-manager.c index de8a638..3aed12f 100644 --- a/src/gs-manager.c +++ b/src/gs-manager.c @@ -29,7 +29,7 @@ #include <gio/gio.h> #define MATE_DESKTOP_USE_UNSTABLE_API -#include <libmateui/mate-bg.h> +#include <libmate-desktop/mate-bg.h> #include "gs-prefs.h" /* for GSSaverMode */ @@ -894,6 +894,7 @@ gs_manager_get_property (GObject *object, break; case PROP_ACTIVE: g_value_set_boolean (value, self->priv->active); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -1245,7 +1246,11 @@ static void apply_background_to_window (GSManager *manager, GSWindow *window) { +#if GTK_CHECK_VERSION (3, 0, 0) + cairo_surface_t *surface; +#else GdkPixmap *pixmap; +#endif GdkScreen *screen; int width; int height; @@ -1253,13 +1258,26 @@ apply_background_to_window (GSManager *manager, if (manager->priv->bg == NULL) { gs_debug ("No background available"); +#if GTK_CHECK_VERSION (3, 0, 0) + gs_window_set_background_surface (window, NULL); +#else gs_window_set_background_pixmap (window, NULL); +#endif } screen = gs_window_get_screen (window); width = gdk_screen_get_width (screen); height = gdk_screen_get_height (screen); - gs_debug ("Creating pixmap background w:%d h:%d", width, height); + gs_debug ("Creating background w:%d h:%d", width, height); +#if GTK_CHECK_VERSION (3, 0, 0) + surface = mate_bg_create_surface (manager->priv->bg, + gs_window_get_gdk_window (window), + width, + height, + FALSE); + gs_window_set_background_surface (window, surface); + cairo_surface_destroy (surface); +#else pixmap = mate_bg_create_pixmap (manager->priv->bg, gs_window_get_gdk_window (window), width, @@ -1267,6 +1285,7 @@ apply_background_to_window (GSManager *manager, FALSE); gs_window_set_background_pixmap (window, pixmap); g_object_unref (pixmap); +#endif } static void diff --git a/src/gs-visual-gl.c b/src/gs-visual-gl.c index ac4c535..8a779e3 100644 --- a/src/gs-visual-gl.c +++ b/src/gs-visual-gl.c @@ -93,7 +93,11 @@ gs_visual_gl_get_best_for_screen (GdkScreen *screen) vid = XVisualIDFromVisual (vi->visual); +#if GTK_CHECK_VERSION (3, 0, 0) + visual = gdk_x11_screen_lookup_visual (gdk_screen_get_default (), vid); +#else visual = gdkx_visual_get (vid); +#endif XFree (vi); diff --git a/src/gs-watcher-x11.c b/src/gs-watcher-x11.c index 39c10a6..5f699f1 100644 --- a/src/gs-watcher-x11.c +++ b/src/gs-watcher-x11.c @@ -28,6 +28,7 @@ #include <errno.h> #include <string.h> +#include <gtk/gtk.h> #include <gdk/gdkx.h> #include <dbus/dbus.h> @@ -591,7 +592,11 @@ disable_builtin_screensaver (GSWatcher *watcher, int desired_server_timeout, desired_server_interval; int desired_prefer_blank, desired_allow_exp; +#if GTK_CHECK_VERSION (3, 0, 0) + XGetScreenSaver (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), +#else XGetScreenSaver (GDK_DISPLAY (), +#endif ¤t_server_timeout, ¤t_server_interval, ¤t_prefer_blank, @@ -630,19 +635,31 @@ disable_builtin_screensaver (GSWatcher *watcher, (desired_prefer_blank ? "blank" : "noblank"), (desired_allow_exp ? "expose" : "noexpose")); +#if GTK_CHECK_VERSION (3, 0, 0) + XSetScreenSaver (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), +#else XSetScreenSaver (GDK_DISPLAY (), +#endif desired_server_timeout, desired_server_interval, desired_prefer_blank, desired_allow_exp); +#if GTK_CHECK_VERSION (3, 0, 0) + XSync (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), FALSE); +#else XSync (GDK_DISPLAY (), FALSE); +#endif } if (unblank_screen) { /* Turn off the server builtin saver if it is now running. */ +#if GTK_CHECK_VERSION (3, 0, 0) + XForceScreenSaver (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), ScreenSaverReset); +#else XForceScreenSaver (GDK_DISPLAY (), ScreenSaverReset); +#endif } } diff --git a/src/gs-window-x11.c b/src/gs-window-x11.c index 878893b..c83c015 100644 --- a/src/gs-window-x11.c +++ b/src/gs-window-x11.c @@ -27,9 +27,16 @@ #include <sys/wait.h> #include <string.h> +#include <gtk/gtk.h> #include <gdk/gdkx.h> #include <gdk/gdkkeysyms.h> -#include <gtk/gtk.h> +#if GTK_CHECK_VERSION (3, 0, 0) +#include <gtk/gtkx.h> +#include <gdk/gdkkeysyms-compat.h> +#define GTK_WIDGET_IS_SENSITIVE gtk_widget_get_sensitive +#define GTK_WIDGET_VISIBLE gtk_widget_get_visible +#define GTK_WIDGET_REALIZED gtk_widget_get_realized +#endif #include "gs-window.h" #include "gs-marshal.h" @@ -85,7 +92,11 @@ struct GSWindowPrivate GtkWidget *info_bar; GtkWidget *info_content; +#if GTK_CHECK_VERSION (3, 0, 0) + cairo_surface_t *background_surface; +#else GdkPixmap *background_pixmap; +#endif guint popup_dialog_idle_id; @@ -147,11 +158,16 @@ static void set_invisible_cursor (GdkWindow *window, gboolean invisible) { - GdkBitmap *empty_bitmap; GdkCursor *cursor = NULL; +#if !GTK_CHECK_VERSION (3, 0, 0) + GdkBitmap *empty_bitmap; GdkColor useless; char invisible_cursor_bits [] = { 0x0 }; +#endif +#if GTK_CHECK_VERSION (3, 0, 0) + cursor = gdk_cursor_new (GDK_BLANK_CURSOR); +#else if (invisible) { useless.red = useless.green = useless.blue = 0; @@ -168,12 +184,17 @@ set_invisible_cursor (GdkWindow *window, g_object_unref (empty_bitmap); } +#endif gdk_window_set_cursor (window, cursor); if (cursor) { +#if GTK_CHECK_VERSION (3, 0, 0) + g_object_unref (cursor); +#else gdk_cursor_unref (cursor); +#endif } } @@ -196,10 +217,18 @@ gs_window_override_user_time (GSWindow *window) * NOTE: Last resort for D-BUS or other non-interactive * openings. Causes roundtrip to server. Lame. */ +#if GTK_CHECK_VERSION (3, 0, 0) + ev_time = gdk_x11_get_server_time (gtk_widget_get_window (GTK_WIDGET (window))); +#else ev_time = gdk_x11_get_server_time (GTK_WIDGET (window)->window); +#endif } +#if GTK_CHECK_VERSION (3, 0, 0) + gdk_x11_window_set_user_time (gtk_widget_get_window (GTK_WIDGET (window)), ev_time); +#else gdk_x11_window_set_user_time (GTK_WIDGET (window)->window, ev_time); +#endif } static void @@ -229,6 +258,7 @@ force_no_pixmap_background (GtkWidget *widget) gtk_widget_set_name (widget, "gs-window-drawing-area"); } +#if !GTK_CHECK_VERSION (3, 0, 0) static void clear_children (Window window) { @@ -259,6 +289,7 @@ clear_children (Window window) child = children [--n_children]; XClearWindow (GDK_DISPLAY (), child); + clear_children (child); } @@ -282,13 +313,44 @@ widget_clear_all_children (GtkWidget *widget) gdk_display_sync (gtk_widget_get_display (widget)); gdk_error_trap_pop (); } +#endif + +#if GTK_CHECK_VERSION (3, 0, 0) +static void +gs_window_reset_background_surface (GSWindow *window) +{ + cairo_pattern_t *pattern; + pattern = cairo_pattern_create_for_surface (window->priv->background_surface); + gdk_window_set_background_pattern (gtk_widget_get_window (GTK_WIDGET (window)), + pattern); + cairo_pattern_destroy (pattern); + gtk_widget_queue_draw (GTK_WIDGET (window)); +} +#endif void +#if GTK_CHECK_VERSION (3, 0, 0) +gs_window_set_background_surface (GSWindow *window, + cairo_surface_t *surface) +#else gs_window_set_background_pixmap (GSWindow *window, GdkPixmap *pixmap) +#endif { g_return_if_fail (GS_IS_WINDOW (window)); +#if GTK_CHECK_VERSION (3, 0, 0) + if (window->priv->background_surface != NULL) + { + cairo_surface_destroy (window->priv->background_surface); + } + + if (surface != NULL) + { + window->priv->background_surface = cairo_surface_reference (surface); + gs_window_reset_background_surface (window); + } +#else if (window->priv->background_pixmap != NULL) { g_object_unref (window->priv->background_pixmap); @@ -301,13 +363,20 @@ gs_window_set_background_pixmap (GSWindow *window, pixmap, FALSE); } +#endif } static void +#if GTK_CHECK_VERSION (3, 0, 0) +gs_window_clear_to_background_surface (GSWindow *window) +#else gs_window_clear_to_background_pixmap (GSWindow *window) +#endif { +#if !GTK_CHECK_VERSION (3, 0, 0) GtkStateType state; GtkStyle *style; +#endif g_return_if_fail (GS_IS_WINDOW (window)); @@ -316,7 +385,11 @@ gs_window_clear_to_background_pixmap (GSWindow *window) return; } +#if GTK_CHECK_VERSION (3, 0, 0) + if (window->priv->background_surface == NULL) +#else if (window->priv->background_pixmap == NULL) +#endif { /* don't allow null pixmaps */ return; @@ -324,6 +397,9 @@ gs_window_clear_to_background_pixmap (GSWindow *window) gs_debug ("Clearing window to background pixmap"); +#if GTK_CHECK_VERSION (3, 0, 0) + gs_window_reset_background_surface (window); +#else style = gtk_style_copy (GTK_WIDGET (window)->style); state = (GtkStateType) 0; @@ -352,16 +428,31 @@ gs_window_clear_to_background_pixmap (GSWindow *window) gdk_window_clear (GTK_WIDGET (window)->window); gdk_flush (); +#endif } static void clear_widget (GtkWidget *widget) { +#if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA rgba = { 0.0, 0.0, 0.0, 1.0 }; +#else GdkColor color = { 0, 0x0000, 0x0000, 0x0000 }; - GdkColormap *colormap; GtkStateType state; GtkStyle *style; +#endif + +#if GTK_CHECK_VERSION (3, 0, 0) + if (!gtk_widget_get_realized (widget)) + { + return; + } + + gs_debug ("Clearing widget"); + gtk_widget_override_background_color (widget, GTK_STATE_FLAG_NORMAL, &rgba); + gtk_widget_queue_draw (GTK_WIDGET (widget)); +#else if (! GTK_WIDGET_VISIBLE (widget)) { return; @@ -404,6 +495,7 @@ clear_widget (GtkWidget *widget) widget_clear_all_children (widget); gdk_flush (); +#endif } void @@ -415,20 +507,45 @@ gs_window_clear (GSWindow *window) clear_widget (window->priv->drawing_area); } +#if GTK_CHECK_VERSION (3, 0, 0) +static cairo_region_t * +#else static GdkRegion * +#endif get_outside_region (GSWindow *window) { int i; +#if GTK_CHECK_VERSION (3, 0, 0) + cairo_region_t *region; +#else GdkRegion *region; +#endif +#if GTK_CHECK_VERSION (3, 0, 0) + region = cairo_region_create (); +#else region = gdk_region_new (); +#endif for (i = 0; i < window->priv->monitor; i++) { GdkRectangle geometry; +#if GTK_CHECK_VERSION (3, 0, 0) + cairo_rectangle_int_t rectangle; +#endif +#if GTK_CHECK_VERSION (3, 0, 0) + gdk_screen_get_monitor_geometry (gtk_widget_get_screen (GTK_WIDGET (window)), + i, &geometry); + rectangle.x = geometry.x; + rectangle.y = geometry.y; + rectangle.width = geometry.width; + rectangle.height = geometry.height; + cairo_region_union_rectangle (region, &rectangle); +#else gdk_screen_get_monitor_geometry (GTK_WINDOW (window)->screen, i, &geometry); gdk_region_union_with_rect (region, &geometry); +#endif } return region; @@ -438,12 +555,21 @@ static void update_geometry (GSWindow *window) { GdkRectangle geometry; +#if GTK_CHECK_VERSION (3, 0, 0) + cairo_region_t *outside_region; + cairo_region_t *monitor_region; +#else GdkRegion *outside_region; GdkRegion *monitor_region; +#endif outside_region = get_outside_region (window); +#if GTK_CHECK_VERSION (3, 0, 0) + gdk_screen_get_monitor_geometry (gtk_widget_get_screen (GTK_WIDGET (window)), +#else gdk_screen_get_monitor_geometry (GTK_WINDOW (window)->screen, +#endif window->priv->monitor, &geometry); gs_debug ("got geometry for monitor %d: x=%d y=%d w=%d h=%d", @@ -452,12 +578,23 @@ update_geometry (GSWindow *window) geometry.y, geometry.width, geometry.height); +#if GTK_CHECK_VERSION (3, 0, 0) + monitor_region = cairo_region_create_rectangle ((const cairo_rectangle_int_t *)&geometry); + cairo_region_subtract (monitor_region, outside_region); + cairo_region_destroy (outside_region); +#else monitor_region = gdk_region_rectangle (&geometry); gdk_region_subtract (monitor_region, outside_region); gdk_region_destroy (outside_region); +#endif +#if GTK_CHECK_VERSION (3, 0, 0) + cairo_region_get_extents (monitor_region, (cairo_rectangle_int_t *)&geometry); + cairo_region_destroy (monitor_region); +#else gdk_region_get_clipbox (monitor_region, &geometry); gdk_region_destroy (monitor_region); +#endif gs_debug ("using geometry for monitor %d: x=%d y=%d w=%d h=%d", window->priv->monitor, @@ -487,8 +624,14 @@ gs_window_move_resize_window (GSWindow *window, gboolean resize) { GtkWidget *widget; + GdkWindow *gdkwindow; widget = GTK_WIDGET (window); +#if GTK_CHECK_VERSION (3, 0, 0) + gdkwindow = gtk_widget_get_window (GTK_WIDGET (window)); +#else + gdkwindow = widget->window; +#endif g_assert (GTK_WIDGET_REALIZED (widget)); @@ -501,7 +644,7 @@ gs_window_move_resize_window (GSWindow *window, if (move && resize) { - gdk_window_move_resize (widget->window, + gdk_window_move_resize (gdkwindow, window->priv->geometry.x, window->priv->geometry.y, window->priv->geometry.width, @@ -509,13 +652,13 @@ gs_window_move_resize_window (GSWindow *window, } else if (move) { - gdk_window_move (widget->window, + gdk_window_move (gdkwindow, window->priv->geometry.x, window->priv->geometry.y); } else if (resize) { - gdk_window_resize (widget->window, + gdk_window_resize (gdkwindow, window->priv->geometry.width, window->priv->geometry.height); } @@ -649,7 +792,11 @@ get_best_visual_for_screen (GdkScreen *screen) VisualID visual_id; visual_id = (VisualID) v; +#if GTK_CHECK_VERSION (3, 0, 0) + visual = gdk_x11_screen_lookup_visual (screen, visual_id); +#else visual = gdkx_visual_get (visual_id); +#endif gs_debug ("Found best GL visual for screen %d: 0x%x", gdk_screen_get_number (screen), @@ -663,6 +810,22 @@ out: return visual; } +#if GTK_CHECK_VERSION (3, 0, 0) +static void +widget_set_best_visual (GtkWidget *widget) +{ + GdkVisual *visual; + + g_return_if_fail (widget != NULL); + + visual = get_best_visual_for_screen (gtk_widget_get_screen (widget)); + if (visual != NULL) + { + gtk_widget_set_visual (widget, visual); + g_object_unref (visual); + } +} +#else static GdkColormap * get_best_colormap_for_screen (GdkScreen *screen) { @@ -696,11 +859,16 @@ widget_set_best_colormap (GtkWidget *widget) g_object_unref (colormap); } } +#endif static void gs_window_real_realize (GtkWidget *widget) { +#if GTK_CHECK_VERSION (3, 0, 0) + widget_set_best_visual (widget); +#else widget_set_best_colormap (widget); +#endif if (GTK_WIDGET_CLASS (gs_window_parent_class)->realize) { @@ -724,7 +892,11 @@ watchdog_timer (GSWindow *window) { GtkWidget *widget = GTK_WIDGET (window); +#if GTK_CHECK_VERSION (3, 0, 0) + gdk_window_focus (gtk_widget_get_window (widget), GDK_CURRENT_TIME); +#else gdk_window_focus (widget->window, GDK_CURRENT_TIME); +#endif return TRUE; } @@ -787,7 +959,11 @@ gs_window_raise (GSWindow *window) gs_debug ("Raising screensaver window"); +#if GTK_CHECK_VERSION (3, 0, 0) + win = gtk_widget_get_window (GTK_WIDGET (window)); +#else win = GTK_WIDGET (window)->window; +#endif gdk_window_raise (win); } @@ -800,7 +976,11 @@ x11_window_is_ours (Window window) ret = FALSE; +#if GTK_CHECK_VERSION (3, 0, 0) + gwindow = gdk_x11_window_lookup_for_display (gdk_display_get_default (), window); +#else gwindow = gdk_window_lookup (window); +#endif if (gwindow && (window != GDK_ROOT_WINDOW ())) { ret = TRUE; @@ -813,7 +993,11 @@ x11_window_is_ours (Window window) static void unshape_window (GSWindow *window) { +#if GTK_CHECK_VERSION (3, 0, 0) + gdk_window_shape_combine_region (gtk_widget_get_window (GTK_WIDGET (window)), +#else gdk_window_shape_combine_region (GTK_WIDGET (window)->window, +#endif NULL, 0, 0); @@ -897,10 +1081,18 @@ select_popup_events (void) gdk_error_trap_push (); memset (&attr, 0, sizeof (attr)); +#if GTK_CHECK_VERSION (3, 0, 0) + XGetWindowAttributes (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), GDK_ROOT_WINDOW (), &attr); +#else XGetWindowAttributes (GDK_DISPLAY (), GDK_ROOT_WINDOW (), &attr); +#endif events = SubstructureNotifyMask | attr.your_event_mask; +#if GTK_CHECK_VERSION (3, 0, 0) + XSelectInput (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), GDK_ROOT_WINDOW (), events); +#else XSelectInput (GDK_DISPLAY (), GDK_ROOT_WINDOW (), events); +#endif gdk_display_sync (gdk_display_get_default ()); gdk_error_trap_pop (); @@ -915,11 +1107,18 @@ window_select_shape_events (GSWindow *window) gdk_error_trap_push (); +#if GTK_CHECK_VERSION (3, 0, 0) + if (XShapeQueryExtension (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), &window->priv->shape_event_base, &shape_error_base)) { + events = ShapeNotifyMask; + XShapeSelectInput (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), GDK_WINDOW_XID (gtk_widget_get_window (GTK_WIDGET (window))), events); + } +#else if (XShapeQueryExtension (GDK_DISPLAY (), &window->priv->shape_event_base, &shape_error_base)) { events = ShapeNotifyMask; XShapeSelectInput (GDK_DISPLAY (), GDK_WINDOW_XID (GTK_WIDGET (window)->window), events); } +#endif gdk_display_sync (gdk_display_get_default ()); gdk_error_trap_pop (); @@ -938,7 +1137,11 @@ gs_window_real_show (GtkWidget *widget) gs_window_clear (GS_WINDOW (widget)); +#if GTK_CHECK_VERSION (3, 0, 0) + set_invisible_cursor (gtk_widget_get_window (widget), TRUE); +#else set_invisible_cursor (widget->window, TRUE); +#endif window = GS_WINDOW (widget); if (window->priv->timer) @@ -1088,7 +1291,11 @@ gs_window_get_gdk_window (GSWindow *window) { g_return_val_if_fail (GS_IS_WINDOW (window), NULL); +#if GTK_CHECK_VERSION (3, 0, 0) + return gtk_widget_get_window (GTK_WIDGET (window)); +#else return GTK_WIDGET (window)->window; +#endif } GtkWidget * @@ -1158,6 +1365,9 @@ spawn_on_window (GSWindow *window, { int argc; char **argv; +#if GTK_CHECK_VERSION (3, 0, 0) + char **envp; +#endif GError *error; gboolean result; GIOChannel *channel; @@ -1175,6 +1385,20 @@ spawn_on_window (GSWindow *window, } error = NULL; +#if GTK_CHECK_VERSION (3, 0, 0) + envp = spawn_make_environment_for_screen (gtk_window_get_screen (GTK_WINDOW (window)), NULL); + result = g_spawn_async_with_pipes (NULL, + argv, + envp, + G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH, + NULL, + NULL, + &child_pid, + NULL, + &standard_output, + &standard_error, + &error); +#else result = gdk_spawn_on_screen_with_pipes (GTK_WINDOW (window)->screen, NULL, argv, @@ -1187,6 +1411,7 @@ spawn_on_window (GSWindow *window, &standard_output, &standard_error, &error); +#endif if (! result) { @@ -1234,6 +1459,9 @@ spawn_on_window (GSWindow *window, g_io_channel_unref (channel); g_strfreev (argv); +#if GTK_CHECK_VERSION (3, 0, 0) + g_strfreev (envp); +#endif return result; } @@ -1646,7 +1874,11 @@ popdown_dialog (GSWindow *window) gtk_widget_show (window->priv->drawing_area); gs_window_clear (window); +#if GTK_CHECK_VERSION (3, 0, 0) + set_invisible_cursor (gtk_widget_get_window (GTK_WIDGET (window)), TRUE); +#else set_invisible_cursor (GTK_WIDGET (window)->window, TRUE); +#endif window_set_dialog_up (window, FALSE); @@ -1832,9 +2064,13 @@ popup_dialog (GSWindow *window) gtk_widget_hide (window->priv->drawing_area); +#if GTK_CHECK_VERSION (3, 0, 0) + gs_window_clear_to_background_surface (window); + set_invisible_cursor (gtk_widget_get_window (GTK_WIDGET (window)), FALSE); +#else gs_window_clear_to_background_pixmap (window); - set_invisible_cursor (GTK_WIDGET (window)->window, FALSE); +#endif window->priv->dialog_quit_requested = FALSE; window->priv->dialog_shake_in_progress = FALSE; @@ -1939,7 +2175,11 @@ gs_window_get_screen (GSWindow *window) { g_return_val_if_fail (GS_IS_WINDOW (window), NULL); +#if GTK_CHECK_VERSION (3, 0, 0) + return gtk_widget_get_screen (GTK_WIDGET (window)); +#else return GTK_WINDOW (window)->screen; +#endif } void @@ -2285,16 +2525,22 @@ gs_window_real_size_request (GtkWidget *widget, { GSWindow *window; GtkBin *bin; + GtkWidget *child; GdkRectangle old_geometry; int position_changed = FALSE; int size_changed = FALSE; window = GS_WINDOW (widget); bin = GTK_BIN (widget); +#if GTK_CHECK_VERSION (3, 0, 0) + child = gtk_bin_get_child (bin); +#else + child = bin->child; +#endif - if (bin->child && GTK_WIDGET_VISIBLE (bin->child)) + if (child && GTK_WIDGET_VISIBLE (child)) { - gtk_widget_size_request (bin->child, requisition); + gtk_widget_size_request (child, requisition); } old_geometry = window->priv->geometry; @@ -2324,6 +2570,28 @@ gs_window_real_size_request (GtkWidget *widget, gs_window_move_resize_window (window, position_changed, size_changed); } +#if GTK_CHECK_VERSION (3, 0, 0) +static void +gs_window_real_get_preferred_width (GtkWidget *widget, + gint *minimal_width, + gint *natural_width) +{ + GtkRequisition requisition; + gs_window_real_size_request (widget, &requisition); + *minimal_width = *natural_width = requisition.width; +} + +static void +gs_window_real_get_preferred_height (GtkWidget *widget, + gint *minimal_height, + gint *natural_height) +{ + GtkRequisition requisition; + gs_window_real_size_request (widget, &requisition); + *minimal_height = *natural_height = requisition.height; +} +#endif + static gboolean gs_window_real_grab_broken (GtkWidget *widget, GdkEventGrabBroken *event) @@ -2413,7 +2681,12 @@ gs_window_class_init (GSWindowClass *klass) widget_class->motion_notify_event = gs_window_real_motion_notify_event; widget_class->button_press_event = gs_window_real_button_press_event; widget_class->scroll_event = gs_window_real_scroll_event; +#if GTK_CHECK_VERSION (3, 0, 0) + widget_class->get_preferred_width = gs_window_real_get_preferred_width; + widget_class->get_preferred_height = gs_window_real_get_preferred_height; +#else widget_class->size_request = gs_window_real_size_request; +#endif widget_class->grab_broken_event = gs_window_real_grab_broken; widget_class->visibility_notify_event = gs_window_real_visibility_notify_event; @@ -2566,6 +2839,9 @@ gs_window_init (GSWindow *window) window->priv->drawing_area = gtk_drawing_area_new (); gtk_widget_show (window->priv->drawing_area); +#if GTK_CHECK_VERSION (3, 0, 0) + gtk_widget_set_app_paintable (window->priv->drawing_area, TRUE); +#endif gtk_box_pack_start (GTK_BOX (window->priv->vbox), window->priv->drawing_area, TRUE, TRUE, 0); create_info_bar (window); @@ -2621,10 +2897,17 @@ gs_window_finalize (GObject *object) gs_window_dialog_finish (window); +#if GTK_CHECK_VERSION (3, 0, 0) + if (window->priv->background_surface) + { + cairo_surface_destroy (window->priv->background_surface); + } +#else if (window->priv->background_pixmap) { g_object_unref (window->priv->background_pixmap); } +#endif G_OBJECT_CLASS (gs_window_parent_class)->finalize (object); } @@ -2641,6 +2924,7 @@ gs_window_new (GdkScreen *screen, "screen", screen, "monitor", monitor, "lock-enabled", lock_enabled, + "app-paintable", TRUE, NULL); return GS_WINDOW (result); diff --git a/src/gs-window.h b/src/gs-window.h index 860118c..22f9274 100644 --- a/src/gs-window.h +++ b/src/gs-window.h @@ -66,8 +66,13 @@ void gs_window_set_monitor (GSWindow *window, int monitor); int gs_window_get_monitor (GSWindow *window); +#if GTK_CHECK_VERSION (3, 0, 0) +void gs_window_set_background_surface (GSWindow *window, + cairo_surface_t *surface); +#else void gs_window_set_background_pixmap (GSWindow *window, GdkPixmap *pixmap); +#endif void gs_window_set_lock_enabled (GSWindow *window, gboolean lock_enabled); void gs_window_set_logout_enabled (GSWindow *window, |