summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefano Karapetsas <[email protected]>2014-02-04 19:20:19 +0100
committerStefano Karapetsas <[email protected]>2014-02-04 19:20:19 +0100
commit6965a1269bc83414f78d82baa4202e8f6f4669c9 (patch)
tree9540bb61faa322ca7b9026f0273222be02b0d8c8
parentd6d686e6af7d95284e4a35b6d4d19a3209252777 (diff)
downloadmate-control-center-6965a1269bc83414f78d82baa4202e8f6f4669c9.tar.bz2
mate-control-center-6965a1269bc83414f78d82baa4202e8f6f4669c9.tar.xz
typing-break: Add GTK3 support
-rw-r--r--typing-break/Makefile.am3
-rw-r--r--typing-break/drw-break-window.c36
-rw-r--r--typing-break/drw-selection.c4
-rw-r--r--typing-break/drw-utils.c46
-rw-r--r--typing-break/drwright.c6
-rw-r--r--typing-break/main.c4
6 files changed, 95 insertions, 4 deletions
diff --git a/typing-break/Makefile.am b/typing-break/Makefile.am
index 18bb61af..c004f21d 100644
--- a/typing-break/Makefile.am
+++ b/typing-break/Makefile.am
@@ -21,9 +21,10 @@ mate_typing_monitor_CPPFLAGS = \
$(AM_CPPFLAGS)
mate_typing_monitor_CFLAGS = \
@TYPING_CFLAGS@ \
+ @MATE_DESKTOP_CFLAGS@ \
$(AM_CFLAGS)
-mate_typing_monitor_LDADD = @TYPING_LIBS@ @SCREENSAVER_LIBS@
+mate_typing_monitor_LDADD = @TYPING_LIBS@ @MATE_DESKTOP_LIBS@ @SCREENSAVER_LIBS@
if HAVE_LIBCANBERRA_GTK
mate_typing_monitor_CFLAGS += -DHAVE_CANBERRA_GTK @LIBCANBERRA_GTK_CFLAGS@
diff --git a/typing-break/drw-break-window.c b/typing-break/drw-break-window.c
index bd34015f..4c3484c3 100644
--- a/typing-break/drw-break-window.c
+++ b/typing-break/drw-break-window.c
@@ -73,8 +73,13 @@ static gboolean postpone_sensitize_cb (DrwBreakWindow *window)
static gboolean clock_timeout_cb (DrwBreakWindow *window);
static void postpone_clicked_cb (GtkWidget *button,
GtkWidget *window);
+#if GTK_CHECK_VERSION (3, 0, 0)
+static gboolean label_draw_event_cb (GtkLabel *label,
+ cairo_t *cr,
+#else
static gboolean label_expose_event_cb (GtkLabel *label,
GdkEventExpose *event,
+#endif
gpointer user_data);
static void label_size_request_cb (GtkLabel *label,
GtkRequisition *requisition,
@@ -233,8 +238,13 @@ drw_break_window_init (DrwBreakWindow *window)
gtk_widget_show (priv->break_label);
g_signal_connect (priv->break_label,
+#if GTK_CHECK_VERSION (3, 0, 0)
+ "draw",
+ G_CALLBACK (label_draw_event_cb),
+#else
"expose_event",
G_CALLBACK (label_expose_event_cb),
+#endif
NULL);
g_signal_connect_after (priv->break_label,
@@ -256,8 +266,13 @@ drw_break_window_init (DrwBreakWindow *window)
gtk_box_pack_start (GTK_BOX (vbox), priv->clock_label, TRUE, TRUE, 8);
g_signal_connect (priv->clock_label,
+#if GTK_CHECK_VERSION (3, 0, 0)
+ "draw",
+ G_CALLBACK (label_draw_event_cb),
+#else
"expose_event",
G_CALLBACK (label_expose_event_cb),
+#endif
NULL);
g_signal_connect_after (priv->clock_label,
@@ -477,7 +492,7 @@ postpone_entry_key_press_event_cb (GtkEntry *entry,
priv = window->priv;
- if (event->keyval == GDK_Escape) {
+ if (event->keyval == GDK_KEY_Escape) {
if (priv->postpone_timeout_id) {
g_source_remove (priv->postpone_timeout_id);
}
@@ -576,15 +591,22 @@ get_layout_location (GtkLabel *label,
}
static gboolean
+#if GTK_CHECK_VERSION (3, 0, 0)
+label_draw_event_cb (GtkLabel *label,
+ cairo_t *cr,
+#else
label_expose_event_cb (GtkLabel *label,
GdkEventExpose *event,
+#endif
gpointer user_data)
{
gint x, y;
GdkColor color;
GtkWidget *widget;
GdkWindow *window;
+#if !GTK_CHECK_VERSION (3, 0, 0)
GdkGC *gc;
+#endif
color.red = 0;
color.green = 0;
@@ -596,10 +618,15 @@ label_expose_event_cb (GtkLabel *label,
widget = GTK_WIDGET (label);
window = gtk_widget_get_window (widget);
+#if !GTK_CHECK_VERSION (3, 0, 0)
gc = gdk_gc_new (window);
gdk_gc_set_rgb_fg_color (gc, &color);
gdk_gc_set_clip_rectangle (gc, &event->area);
+#endif
+#if GTK_CHECK_VERSION (3, 0, 0)
+ pango_cairo_show_layout (cr, gtk_label_get_layout (label));
+#else
gdk_draw_layout_with_colors (window,
gc,
x + 1,
@@ -608,12 +635,19 @@ label_expose_event_cb (GtkLabel *label,
&color,
NULL);
g_object_unref (gc);
+#endif
gtk_paint_layout (gtk_widget_get_style (widget),
+#if GTK_CHECK_VERSION (3, 0, 0)
+ cr,
+#else
window,
+#endif
gtk_widget_get_state (widget),
FALSE,
+#if !GTK_CHECK_VERSION (3, 0, 0)
&event->area,
+#endif
widget,
"label",
x, y,
diff --git a/typing-break/drw-selection.c b/typing-break/drw-selection.c
index 28a96533..5f6b81f7 100644
--- a/typing-break/drw-selection.c
+++ b/typing-break/drw-selection.c
@@ -78,7 +78,11 @@ drw_selection_find_existing (DrwSelection *drw_selection)
gdk_x11_get_xatom_by_name (SELECTION_NAME));
if (old) {
XSelectInput (xdisplay, old, StructureNotifyMask);
+#if GTK_CHECK_VERSION (3, 0, 0)
+ drw_selection->owner_window = gdk_x11_window_foreign_new_for_display (gdk_display_get_default (), old);
+#else
drw_selection->owner_window = gdk_window_foreign_new (old);
+#endif
}
XSync (xdisplay, False);
diff --git a/typing-break/drw-utils.c b/typing-break/drw-utils.c
index 96113246..0bf27c59 100644
--- a/typing-break/drw-utils.c
+++ b/typing-break/drw-utils.c
@@ -90,20 +90,29 @@ create_tile_pixbuf (GdkPixbuf *dest_pixbuf,
}
static gboolean
+#if GTK_CHECK_VERSION (3, 0, 0)
+window_draw_event (GtkWidget *widget,
+ cairo_t *cr,
+#else
window_expose_event (GtkWidget *widget,
GdkEventExpose *event,
+#endif
gpointer data)
{
+#if !GTK_CHECK_VERSION (3, 0, 0)
cairo_t *context;
cairo_t *cr;
cairo_surface_t *surface;
+#endif
int width;
int height;
+ gtk_window_get_size (GTK_WINDOW (widget), &width, &height);
+
+#if !GTK_CHECK_VERSION (3, 0, 0)
context = gdk_cairo_create (gtk_widget_get_window (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,
@@ -118,6 +127,7 @@ window_expose_event (GtkWidget *widget,
if (cairo_status (cr) != CAIRO_STATUS_SUCCESS) {
goto done;
}
+#endif
cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.0);
cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
cairo_paint (cr);
@@ -127,16 +137,17 @@ window_expose_event (GtkWidget *widget,
cairo_set_source_rgba (cr, 0.2, 0.2, 0.2, 0.5);
cairo_fill (cr);
+#if !GTK_CHECK_VERSION (3, 0, 0)
cairo_destroy (cr);
cairo_set_source_surface (context, surface, 0, 0);
cairo_paint (context);
-
done:
if (surface != NULL) {
cairo_surface_destroy (surface);
}
cairo_destroy (context);
+#endif
return FALSE;
}
@@ -146,7 +157,11 @@ set_pixmap_background (GtkWidget *window)
{
GdkScreen *screen;
GdkPixbuf *tmp_pixbuf, *pixbuf, *tile_pixbuf;
+#if GTK_CHECK_VERSION (3, 0, 0)
+ cairo_t *cr;
+#else
GdkPixmap *pixmap;
+#endif
GdkRectangle rect;
GdkColor color;
gint width, height;
@@ -157,6 +172,12 @@ set_pixmap_background (GtkWidget *window)
width = gdk_screen_get_width (screen);
height = gdk_screen_get_height (screen);
+#if GTK_CHECK_VERSION (3, 0, 0)
+ tmp_pixbuf = gdk_pixbuf_get_from_window (gdk_screen_get_root_window (screen),
+ 0,
+ 0,
+ width, height);
+#else
tmp_pixbuf = gdk_pixbuf_get_from_drawable (NULL,
gdk_screen_get_root_window (screen),
gdk_screen_get_system_colormap (screen),
@@ -165,6 +186,7 @@ set_pixmap_background (GtkWidget *window)
0,
0,
width, height);
+#endif
pixbuf = gdk_pixbuf_new_from_file (IMAGEDIR "/ocean-stripes.png", NULL);
@@ -200,6 +222,11 @@ set_pixmap_background (GtkWidget *window)
g_object_unref (tile_pixbuf);
+#if GTK_CHECK_VERSION (3, 0, 0)
+ cr = gdk_cairo_create (gtk_widget_get_window (window));
+ gdk_cairo_set_source_pixbuf (cr, tmp_pixbuf, 0, 0);
+ cairo_paint (cr);
+#else
pixmap = gdk_pixmap_new (gtk_widget_get_window (window),
width,
height,
@@ -217,21 +244,31 @@ set_pixmap_background (GtkWidget *window)
GDK_RGB_DITHER_NONE,
0,
0);
+#endif
g_object_unref (tmp_pixbuf);
+#if GTK_CHECK_VERSION (3, 0, 0)
+ cairo_destroy (cr);
+#else
gdk_window_set_back_pixmap (gtk_widget_get_window (window), pixmap, FALSE);
g_object_unref (pixmap);
+#endif
}
void
drw_setup_background (GtkWidget *window)
{
GdkScreen *screen;
+#if !GTK_CHECK_VERSION (3, 0, 0)
GdkColormap *colormap;
+#endif
gboolean is_composited;
screen = gtk_widget_get_screen (window);
+#if GTK_CHECK_VERSION (3, 0, 0)
+ is_composited = gdk_screen_is_composited (screen);
+#else
colormap = gdk_screen_get_rgba_colormap (screen);
if (colormap != NULL && gdk_screen_is_composited (screen)) {
@@ -240,9 +277,14 @@ drw_setup_background (GtkWidget *window)
} else {
is_composited = FALSE;
}
+#endif
if (is_composited) {
+#if GTK_CHECK_VERSION (3, 0, 0)
+ g_signal_connect (window, "draw", G_CALLBACK (window_draw_event), window);
+#else
g_signal_connect (window, "expose-event", G_CALLBACK (window_expose_event), window);
+#endif
} else {
set_pixmap_background (window);
}
diff --git a/typing-break/drwright.c b/typing-break/drwright.c
index e3af80dc..acba892b 100644
--- a/typing-break/drwright.c
+++ b/typing-break/drwright.c
@@ -33,6 +33,12 @@
#include <libappindicator/app-indicator.h>
#endif /* HAVE_APP_INDICATOR */
+#if GTK_CHECK_VERSION (3, 0, 0)
+#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()
+#endif
+
#include "drwright.h"
#include "drw-break-window.h"
#include "drw-monitor.h"
diff --git a/typing-break/main.c b/typing-break/main.c
index c8ded7bb..dcc1d89f 100644
--- a/typing-break/main.c
+++ b/typing-break/main.c
@@ -35,7 +35,11 @@ gboolean debug = FALSE;
static gboolean
have_tray (void)
{
+#if GTK_CHECK_VERSION (3, 0, 0)
+ Screen *xscreen = DefaultScreenOfDisplay (gdk_x11_display_get_xdisplay(gdk_display_get_default()));
+#else
Screen *xscreen = DefaultScreenOfDisplay (gdk_display);
+#endif
Atom selection_atom;
char *selection_atom_name;