summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ui/fixedtip.c15
-rw-r--r--src/ui/frames.c17
-rw-r--r--src/ui/frames.h4
-rw-r--r--src/ui/preview-widget.c168
-rw-r--r--src/ui/theme.c33
-rw-r--r--src/ui/theme.h8
-rw-r--r--src/ui/ui.c54
7 files changed, 243 insertions, 56 deletions
diff --git a/src/ui/fixedtip.c b/src/ui/fixedtip.c
index 3d9aea06..b06c9708 100644
--- a/src/ui/fixedtip.c
+++ b/src/ui/fixedtip.c
@@ -52,16 +52,19 @@ static int screen_bottom_edge = 0;
#if GTK_CHECK_VERSION(3, 0, 0)
-static gboolean
+static gint
draw_handler (GtkWidget *tooltips,
cairo_t *cr,
gpointer user_data)
{
- gtk_render_background (gtk_widget_get_style_context (tooltips),
- cr,
- 0, 0,
- gtk_widget_get_allocated_width (tooltips),
- gtk_widget_get_allocated_height (tooltips));
+ if (tooltips != NULL)
+ {
+ gtk_render_background (gtk_widget_get_style_context (tooltips),
+ cr,
+ 0, 0,
+ gtk_widget_get_allocated_width (tooltips),
+ gtk_widget_get_allocated_height (tooltips));
+ }
return FALSE;
}
diff --git a/src/ui/frames.c b/src/ui/frames.c
index 5c19bd4c..3f8f0113 100644
--- a/src/ui/frames.c
+++ b/src/ui/frames.c
@@ -663,16 +663,19 @@ meta_frames_attach_style (MetaFrames *frames,
MetaUIFrame *frame)
{
if (frame->style != NULL)
+#if GTK_CHECK_VERSION(3, 0, 0)
+ g_object_unref (frame->style);
+#else
gtk_style_detach (frame->style);
+#endif
+#if GTK_CHECK_VERSION(3, 0, 0)
+ frame->style = g_object_ref (gtk_widget_get_style_context (GTK_WIDGET (frames)));
+#else
/* Weirdly, gtk_style_attach() steals a reference count from the style passed in */
- #if GTK_CHECK_VERSION(3, 0, 0)
- g_object_ref (gtk_widget_get_style (GTK_WIDGET (frames)));
- frame->style = gtk_style_attach (gtk_widget_get_style (GTK_WIDGET (frames)), frame->window);
- #else
g_object_ref (GTK_WIDGET (frames)->style);
frame->style = gtk_style_attach (GTK_WIDGET (frames)->style, frame->window);
- #endif
+#endif
}
void
@@ -2926,8 +2929,12 @@ meta_frames_set_window_background (MetaFrames *frames,
}
else
{
+#if GTK_CHECK_VERSION (3, 0, 0)
+ gtk_style_context_set_background (frame->style, frame->window);
+#else
gtk_style_set_background (frame->style,
frame->window, GTK_STATE_NORMAL);
+#endif
}
}
diff --git a/src/ui/frames.h b/src/ui/frames.h
index b1d178ad..b6fdd0de 100644
--- a/src/ui/frames.h
+++ b/src/ui/frames.h
@@ -75,7 +75,11 @@ struct _MetaUIFrame
{
Window xwindow;
GdkWindow *window;
+#if GTK_CHECK_VERSION(3, 0, 0)
+ GtkStyleContext *style;
+#else
GtkStyle *style;
+#endif
MetaFrameStyle *cache_style;
PangoLayout *layout;
int text_height;
diff --git a/src/ui/preview-widget.c b/src/ui/preview-widget.c
index cb05c2f8..9e592cdc 100644
--- a/src/ui/preview-widget.c
+++ b/src/ui/preview-widget.c
@@ -37,10 +37,10 @@ static void meta_preview_get_preferred_width(GtkWidget *widget,
gint *minimal, gint *natural);
static void meta_preview_get_preferred_height(GtkWidget *widget,
gint *minimal, gint *natural);
-#endif
-
+#else
static void meta_preview_size_request (GtkWidget *widget,
GtkRequisition *req);
+#endif
static void meta_preview_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
#if GTK_CHECK_VERSION(3, 0, 0)
@@ -52,6 +52,8 @@ static gboolean meta_preview_expose (GtkWidget *widget,
#endif
static void meta_preview_finalize (GObject *object);
+#define NO_CHILD_WIDTH 80
+#define NO_CHILD_HEIGHT 20
#if GTK_CHECK_VERSION(3, 0, 0)
@@ -110,6 +112,10 @@ meta_preview_class_init (MetaPreviewClass *class)
widget_class->size_request = meta_preview_size_request;
#endif
widget_class->size_allocate = meta_preview_size_allocate;
+
+#if GTK_CHECK_VERSION(3, 0, 0)
+ gtk_container_class_handle_border_width (GTK_CONTAINER_CLASS (class));
+#endif
}
static void
@@ -247,53 +253,118 @@ ensure_info (MetaPreview *preview)
}
#if GTK_CHECK_VERSION(3, 0, 0)
-static void meta_preview_get_preferred_width(GtkWidget *widget, gint *minimal, gint *natural)
+static void
+meta_preview_get_preferred_width (GtkWidget *widget,
+ gint *minimum,
+ gint *natural)
{
- GtkRequisition requisition;
- meta_preview_size_request (widget, &requisition);
- *minimal = *natural = requisition.width;
+ MetaPreview *preview;
+ int border_width;
+ GtkWidget *child;
+
+ preview = META_PREVIEW (widget);
+
+ ensure_info (preview);
+
+ *minimum = *natural = preview->left_width + preview->right_width;
+
+ child = gtk_bin_get_child (GTK_BIN (preview));
+ if (child && gtk_widget_get_visible (child))
+ {
+ gint child_min, child_nat;
+
+ gtk_widget_get_preferred_width (child, &child_min, &child_nat);
+
+ *minimum += child_min;
+ *natural += child_nat;
+ }
+ else
+ {
+ *minimum += NO_CHILD_WIDTH;
+ *natural += NO_CHILD_WIDTH;
+ }
+
+ border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
+ *minimum += border_width * 2;
+ *natural += border_width * 2;
}
-static void meta_preview_get_preferred_height(GtkWidget *widget, gint *minimal, gint *natural)
+static void
+meta_preview_get_preferred_height (GtkWidget *widget,
+ gint *minimum,
+ gint *natural)
{
- GtkRequisition requisition;
- meta_preview_size_request (widget, &requisition);
- *minimal = *natural = requisition.height;
-}
+ MetaPreview *preview;
+ int border_width;
+ GtkWidget *child;
+
+ preview = META_PREVIEW (widget);
+ ensure_info (preview);
+
+ *minimum = *natural = preview->top_height + preview->bottom_height;
+
+ child = gtk_bin_get_child (GTK_BIN (preview));
+ if (child && gtk_widget_get_visible (child))
+ {
+ gint child_min, child_nat;
+
+ gtk_widget_get_preferred_height (child, &child_min, &child_nat);
+
+ *minimum += child_min;
+ *natural += child_nat;
+ }
+ else
+ {
+ *minimum += NO_CHILD_HEIGHT;
+ *natural += NO_CHILD_HEIGHT;
+ }
+
+ border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
+ *minimum += border_width * 2;
+ *natural += border_width * 2;
+}
static gboolean
meta_preview_draw(GtkWidget *widget,
cairo_t *cr)
{
- MetaPreview *preview = META_PREVIEW (widget);
+ MetaPreview *preview;
GtkAllocation allocation;
+ int border_width;
+ int client_width;
+ int client_height;
+ MetaButtonState button_states[META_BUTTON_TYPE_LAST] =
+ {
+ META_BUTTON_STATE_NORMAL,
+ META_BUTTON_STATE_NORMAL,
+ META_BUTTON_STATE_NORMAL,
+ META_BUTTON_STATE_NORMAL
+ };
+
+ g_return_val_if_fail (META_IS_PREVIEW (widget), FALSE);
+ preview = META_PREVIEW (widget);
+
+ ensure_info (preview);
+
+ cairo_save (cr);
+
+ border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
+
gtk_widget_get_allocation (widget, &allocation);
+ client_width = allocation.width - preview->left_width - preview->right_width - border_width * 2;
+ client_height = allocation.height - preview->top_height - preview->bottom_height - border_width * 2;
+ if (client_width < 0)
+ client_width = 1;
+ if (client_height < 0)
+ client_height = 1;
+
if (preview->theme)
{
- int client_width;
- int client_height;
- MetaButtonState button_states[META_BUTTON_TYPE_LAST] =
- {
- META_BUTTON_STATE_NORMAL,
- META_BUTTON_STATE_NORMAL,
- META_BUTTON_STATE_NORMAL,
- META_BUTTON_STATE_NORMAL
- };
-
- ensure_info (preview);
- cairo_save (cr);
-
- client_width = allocation.width - preview->left_width - preview->right_width;
- client_height = allocation.height - preview->top_height - preview->bottom_height;
+ border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
- if (client_width < 0)
- client_width = 1;
- if (client_height < 0)
- client_height = 1;
-
meta_theme_draw_frame (preview->theme,
widget,
cr,
@@ -306,11 +377,12 @@ meta_preview_draw(GtkWidget *widget,
button_states,
meta_preview_get_mini_icon (),
meta_preview_get_icon ());
-
- cairo_restore (cr);
}
- return GTK_WIDGET_CLASS (parent_class)->draw (widget, cr);
+ cairo_restore (cr);
+
+ /* draw child */
+ return GTK_WIDGET_CLASS (meta_preview_parent_class)->draw (widget, cr);
}
#else
@@ -377,6 +449,7 @@ meta_preview_expose (GtkWidget *widget,
#endif
+#if !GTK_CHECK_VERSION (3, 0, 0)
static void
meta_preview_size_request (GtkWidget *widget,
GtkRequisition *req)
@@ -405,8 +478,6 @@ meta_preview_size_request (GtkWidget *widget,
}
else
{
-#define NO_CHILD_WIDTH 80
-#define NO_CHILD_HEIGHT 20
req->width += NO_CHILD_WIDTH;
req->height += NO_CHILD_HEIGHT;
}
@@ -415,6 +486,7 @@ meta_preview_size_request (GtkWidget *widget,
req->width += border_width * 2;
req->height += border_width * 2;
}
+#endif
static void
meta_preview_size_allocate (GtkWidget *widget,
@@ -422,16 +494,22 @@ meta_preview_size_allocate (GtkWidget *widget,
{
MetaPreview *preview;
int border_width;
+#if GTK_CHECK_VERSION(3, 0, 0)
+ GtkAllocation widget_allocation, child_allocation;
+#else
GtkAllocation child_allocation;
+#endif
GtkWidget *child;
preview = META_PREVIEW (widget);
ensure_info (preview);
- #if !GTK_CHECK_VERSION(3, 0, 0)
+#if GTK_CHECK_VERSION(3, 0, 0)
+ gtk_widget_set_allocation (widget, allocation);
+#else
widget->allocation = *allocation;
- #endif
+#endif
border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
@@ -439,12 +517,20 @@ meta_preview_size_allocate (GtkWidget *widget,
if (child &&
gtk_widget_get_visible (child))
{
+#if GTK_CHECK_VERSION (3, 0, 0)
+ gtk_widget_get_allocation (widget, &widget_allocation);
+ child_allocation.x = widget_allocation.x + border_width + preview->left_width;
+ child_allocation.y = widget_allocation.y + border_width + preview->top_height;
+
+ child_allocation.width = MAX (1, widget_allocation.width - border_width * 2 - preview->left_width - preview->right_width);
+ child_allocation.height = MAX (1, widget_allocation.height - border_width * 2 - preview->top_height - preview->bottom_height);
+#else
child_allocation.x = allocation->x + border_width + preview->left_width;
child_allocation.y = allocation->y + border_width + preview->top_height;
child_allocation.width = MAX (1, allocation->width - border_width * 2 - preview->left_width - preview->right_width);
child_allocation.height = MAX (1, allocation->height - border_width * 2 - preview->top_height - preview->bottom_height);
-
+#endif
gtk_widget_size_allocate (gtk_bin_get_child (GTK_BIN (widget)), &child_allocation);
}
}
@@ -704,4 +790,4 @@ meta_preview_get_clip_region (MetaPreview *preview, gint new_window_width, gint
gdk_region_destroy (corners_xregion);
return window_xregion;
-} \ No newline at end of file
+}
diff --git a/src/ui/theme.c b/src/ui/theme.c
index 4d430b7c..be948369 100644
--- a/src/ui/theme.c
+++ b/src/ui/theme.c
@@ -3425,7 +3425,11 @@ state_flags_from_gtk_state (GtkStateType state)
*/
static void
meta_draw_op_draw_with_env (const MetaDrawOp *op,
+ #if GTK_CHECK_VERSION(3, 0, 0)
+ GtkStyleContext *style_gtk,
+ #else
GtkStyle *style_gtk,
+ #endif
GtkWidget *widget,
#if GTK_CHECK_VERSION(3, 0, 0)
cairo_t *cr,
@@ -3990,7 +3994,12 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op,
break;
}
+#if GTK_CHECK_VERSION (3, 0, 0)
+ cairo_restore (cr);
+ gtk_style_context_restore (style_gtk);
+#else
cairo_destroy (cr);
+#endif
}
void
@@ -4532,7 +4541,11 @@ button_rect (MetaButtonType type,
void
meta_frame_style_draw_with_style (MetaFrameStyle *style,
+ #if GTK_CHECK_VERSION(3, 0, 0)
+ GtkStyleContext *style_gtk,
+ #else
GtkStyle *style_gtk,
+ #endif
GtkWidget *widget,
#if GTK_CHECK_VERSION(3, 0, 0)
cairo_t *cr,
@@ -4908,7 +4921,13 @@ meta_frame_style_draw (MetaFrameStyle *style,
GdkPixbuf *mini_icon,
GdkPixbuf *icon)
{
- meta_frame_style_draw_with_style (style, gtk_widget_get_style (widget), widget,
+ meta_frame_style_draw_with_style (style,
+ #if GTK_CHECK_VERSION(3, 0, 0)
+ gtk_widget_get_style_context (widget),
+ #else
+ gtk_widget_get_style (widget),
+ #endif
+ widget,
#if GTK_CHECK_VERSION(3, 0, 0)
cr,
#else
@@ -5467,7 +5486,11 @@ meta_theme_get_title_scale (MetaTheme *theme,
void
meta_theme_draw_frame_with_style (MetaTheme *theme,
+ #if GTK_CHECK_VERSION(3, 0, 0)
+ GtkStyleContext *style_gtk,
+ #else
GtkStyle *style_gtk,
+ #endif
GtkWidget *widget,
#if GTK_CHECK_VERSION(3, 0, 0)
cairo_t *cr,
@@ -5545,7 +5568,13 @@ meta_theme_draw_frame (MetaTheme *theme,
GdkPixbuf *mini_icon,
GdkPixbuf *icon)
{
- meta_theme_draw_frame_with_style (theme, gtk_widget_get_style (widget), widget,
+ meta_theme_draw_frame_with_style (theme,
+ #if GTK_CHECK_VERSION(3, 0, 0)
+ gtk_widget_get_style_context (widget),
+ #else
+ gtk_widget_get_style (widget),
+ #endif
+ widget,
#if GTK_CHECK_VERSION(3, 0, 0)
cr,
#else
diff --git a/src/ui/theme.h b/src/ui/theme.h
index 30cf7ade..cfa3bde4 100644
--- a/src/ui/theme.h
+++ b/src/ui/theme.h
@@ -990,7 +990,11 @@ void meta_frame_style_draw (MetaFrameStyle *style,
void meta_frame_style_draw_with_style (MetaFrameStyle *style,
+ #if GTK_CHECK_VERSION(3, 0, 0)
+ GtkStyleContext *style_gtk,
+ #else
GtkStyle *style_gtk,
+ #endif
GtkWidget *widget,
#if GTK_CHECK_VERSION(3, 0, 0)
cairo_t *cr,
@@ -1085,7 +1089,11 @@ void meta_theme_draw_frame_by_name (MetaTheme *theme,
GdkPixbuf *icon);
void meta_theme_draw_frame_with_style (MetaTheme *theme,
+ #if GTK_CHECK_VERSION(3, 0, 0)
+ GtkStyleContext *style_gtk,
+ #else
GtkStyle *style_gtk,
+ #endif
GtkWidget *widget,
#if GTK_CHECK_VERSION(3, 0, 0)
cairo_t *cr,
diff --git a/src/ui/ui.c b/src/ui/ui.c
index c170adb8..02c88c1c 100644
--- a/src/ui/ui.c
+++ b/src/ui/ui.c
@@ -52,6 +52,16 @@ struct _MetaUI {
void meta_ui_init(int* argc, char*** argv)
{
+ /* As of 2.91.7, Gdk uses XI2 by default, which conflicts with the
+ * direct X calls we use - in particular, events caused by calls to
+ * XGrabPointer/XGrabKeyboard are no longer understood by GDK, while
+ * GDK will no longer generate the core XEvents we process.
+ * So at least for now, enforce the previous behavior.
+ */
+#if GTK_CHECK_VERSION(2, 91, 7)
+ gdk_disable_multidevice ();
+#endif
+
if (!gtk_init_check (argc, argv))
{
meta_fatal ("Unable to open X display %s\n", XDisplayName (NULL));
@@ -313,7 +323,14 @@ meta_ui_new (Display *xdisplay,
g_assert (xdisplay == GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()));
ui->frames = meta_frames_new (XScreenNumberOfScreen (screen));
+#if GTK_CHECK_VERSION (3, 0, 0)
+ /* This does not actually show any widget. MetaFrames has been hacked so
+ * that showing it doesn't actually do anything. But we need the flags
+ * set for GTK to deliver events properly. */
+ gtk_widget_show (GTK_WIDGET (ui->frames));
+#else
gtk_widget_realize (GTK_WIDGET (ui->frames));
+#endif
g_object_set_data (G_OBJECT (gdisplay), "meta-ui", ui);
@@ -901,7 +918,10 @@ meta_ui_window_should_not_cause_focus (Display *xdisplay,
GdkWindow *window;
#if GTK_CHECK_VERSION (3, 0, 0)
- window = gdk_x11_window_lookup_for_display (gdk_display_get_default (), xwindow);
+ GdkDisplay *display;
+
+ display = gdk_x11_lookup_xdisplay (xdisplay);
+ window = gdk_x11_window_lookup_for_display (display, xwindow);
#else
window = gdk_xid_table_lookup (xwindow);
#endif
@@ -967,6 +987,10 @@ meta_ui_theme_get_frame_borders (MetaUI *ui,
int *right_width)
{
int text_height;
+#if GTK_CHECK_VERSION (3, 0, 0)
+ GtkStyleContext *style = NULL;
+ PangoFontDescription *free_font_desc = NULL;
+#endif
PangoContext *context;
const PangoFontDescription *font_desc;
GtkStyle *default_style;
@@ -978,8 +1002,24 @@ meta_ui_theme_get_frame_borders (MetaUI *ui,
if (!font_desc)
{
+#if GTK_CHECK_VERSION (3, 0, 0)
+ GdkDisplay *display = gdk_x11_lookup_xdisplay (ui->xdisplay);
+ GdkScreen *screen = gdk_display_get_screen (display, XScreenNumberOfScreen (ui->xscreen));
+ GtkWidgetPath *widget_path;
+
+ style = gtk_style_context_new ();
+ gtk_style_context_set_screen (style, screen);
+ widget_path = gtk_widget_path_new ();
+ gtk_widget_path_append_type (widget_path, GTK_TYPE_WINDOW);
+ gtk_style_context_set_path (style, widget_path);
+ gtk_widget_path_free (widget_path);
+
+ gtk_style_context_get (style, GTK_STATE_FLAG_NORMAL, "font", &free_font_desc, NULL);
+ font_desc = (const PangoFontDescription *) free_font_desc;
+#else
default_style = gtk_widget_get_default_style ();
font_desc = default_style->font_desc;
+#endif
}
text_height = meta_pango_font_desc_get_text_height (font_desc, context);
@@ -988,11 +1028,21 @@ meta_ui_theme_get_frame_borders (MetaUI *ui,
type, text_height, flags,
top_height, bottom_height,
left_width, right_width);
+
+#if GTK_CHECK_VERSION (3, 0, 0)
+ if (free_font_desc)
+ pango_font_description_free (free_font_desc);
+#endif
}
else
{
*top_height = *bottom_height = *left_width = *right_width = 0;
}
+
+#if GTK_CHECK_VERSION (3, 0, 0)
+ if (style != NULL)
+ g_object_unref (style);
+#endif
}
void
@@ -1171,7 +1221,7 @@ meta_ui_window_is_widget (MetaUI *ui,
#if GTK_CHECK_VERSION (3, 0, 0)
GdkDisplay *display;
-
+ display = gdk_x11_lookup_xdisplay (ui->xdisplay);
window = gdk_x11_window_lookup_for_display (display, xwindow);
#else
window = gdk_xid_table_lookup (xwindow);