diff options
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/ui/fixedtip.c | 58 | ||||
-rw-r--r-- | src/ui/meta-tooltip.c | 182 | ||||
-rw-r--r-- | src/ui/meta-tooltip.h | 38 | ||||
-rw-r--r-- | src/ui/resizepopup.c | 57 |
5 files changed, 228 insertions, 109 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index d614f878..2a26bfce 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -98,6 +98,8 @@ metacity_SOURCES= \ ui/menu.h \ ui/metaaccellabel.c \ ui/metaaccellabel.h \ + ui/meta-tooltip.c \ + ui/meta-tooltip.h \ ui/resizepopup.c \ include/resizepopup.h \ ui/tabpopup.c \ diff --git a/src/ui/fixedtip.c b/src/ui/fixedtip.c index a1bb410f..0a0418d3 100644 --- a/src/ui/fixedtip.c +++ b/src/ui/fixedtip.c @@ -21,6 +21,7 @@ #include <config.h> #include "fixedtip.h" +#include "meta-tooltip.h" #include "ui.h" /** @@ -29,32 +30,6 @@ */ static GtkWidget *tip = NULL; -/** - * The actual text that gets displayed. - */ -static GtkWidget *label = NULL; - -static gboolean -draw_handler (GtkWidget *widget, - cairo_t *cr) -{ - GtkStyleContext *context; - gint width; - gint height; - - if (widget == NULL) - return FALSE; - - context = gtk_widget_get_style_context (widget); - width = gtk_widget_get_allocated_width (widget); - height = gtk_widget_get_allocated_height (widget); - - gtk_render_background (context, cr, 0, 0, width, height); - gtk_render_frame (context, cr, 0, 0, width, height); - - return FALSE; -} - void meta_fixed_tip_show (int root_x, int root_y, const char *markup_text) @@ -70,34 +45,7 @@ meta_fixed_tip_show (int root_x, int root_y, if (tip == NULL) { - GdkVisual *visual; - - tip = gtk_window_new (GTK_WINDOW_POPUP); - - gtk_window_set_type_hint (GTK_WINDOW(tip), GDK_WINDOW_TYPE_HINT_TOOLTIP); - gtk_style_context_add_class (gtk_widget_get_style_context (tip), - GTK_STYLE_CLASS_TOOLTIP); - - visual = gdk_screen_get_rgba_visual (screen); - - gtk_window_set_screen (GTK_WINDOW (tip), screen); - - if (visual != NULL) - gtk_widget_set_visual (tip, visual); - - gtk_widget_set_app_paintable (tip, TRUE); - gtk_window_set_resizable (GTK_WINDOW (tip), FALSE); - - g_signal_connect (tip, "draw", G_CALLBACK (draw_handler), NULL); - - label = gtk_label_new (NULL); - gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); - gtk_widget_set_halign (label, GTK_ALIGN_CENTER); - gtk_widget_set_valign (label, GTK_ALIGN_CENTER); - gtk_widget_show (label); - - gtk_container_set_border_width (GTK_CONTAINER (tip), 4); - gtk_container_add (GTK_CONTAINER (tip), label); + tip = meta_tooltip_new (); g_signal_connect (tip, "destroy", G_CALLBACK (gtk_widget_destroyed), &tip); @@ -107,7 +55,7 @@ meta_fixed_tip_show (int root_x, int root_y, gdk_screen_get_monitor_geometry (screen, mon_num, &monitor); screen_right_edge = monitor.x + monitor.width; - gtk_label_set_markup (GTK_LABEL (label), markup_text); + meta_tooltip_set_label_markup (META_TOOLTIP (tip), markup_text); gtk_window_get_size (GTK_WINDOW (tip), &w, &h); diff --git a/src/ui/meta-tooltip.c b/src/ui/meta-tooltip.c new file mode 100644 index 00000000..3126ba9c --- /dev/null +++ b/src/ui/meta-tooltip.c @@ -0,0 +1,182 @@ +/* + * Copyright (C) 2016 Alberts Muktupāvels + * + * 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, see <http://www.gnu.org/licenses/>. + */ + +#include "config.h" + +#include "meta-tooltip.h" +#include "prefs.h" + +struct _MetaTooltip +{ + GtkWindow parent; + + GtkWidget *box; + GtkWidget *label; + + gboolean composited; +}; + +G_DEFINE_TYPE (MetaTooltip, meta_tooltip, GTK_TYPE_WINDOW) + +static void +update_style_class (MetaTooltip *tooltip) +{ + GtkStyleContext *context; + + context = gtk_widget_get_style_context (GTK_WIDGET (tooltip)); + + if (tooltip->composited) + { + gtk_style_context_remove_class (context, "solid-csd"); + gtk_style_context_add_class (context, GTK_STYLE_CLASS_CSD); + } + else + { + gtk_style_context_remove_class (context, GTK_STYLE_CLASS_CSD); + gtk_style_context_add_class (context, "solid-csd"); + } +} + +static void +prefs_changed_cb (MetaPreference pref, + void *data) +{ + MetaTooltip *tooltip; + gboolean composited; + + if (pref != META_PREF_COMPOSITING_MANAGER) + return; + + tooltip = META_TOOLTIP (data); + composited = meta_prefs_get_compositing_manager (); + + if (tooltip->composited == composited) + return; + + tooltip->composited = composited; + update_style_class (tooltip); +} + +static void +meta_tooltip_finalize (GObject *object) +{ + MetaTooltip *tooltip; + + tooltip = META_TOOLTIP (object); + + meta_prefs_remove_listener (prefs_changed_cb, tooltip); + + G_OBJECT_CLASS (meta_tooltip_parent_class)->finalize (object); +} + +static void +meta_tooltip_realize (GtkWidget *widget) +{ + GdkScreen *screen; + GdkVisual *visual; + + screen = gtk_widget_get_screen (widget); + visual = gdk_screen_get_rgba_visual (screen); + + if (visual == NULL) + visual = gdk_screen_get_system_visual (screen); + + gtk_widget_set_visual (widget, visual); + + GTK_WIDGET_CLASS (meta_tooltip_parent_class)->realize (widget); +} + +static void +meta_tooltip_class_init (MetaTooltipClass *tooltip_class) +{ + GObjectClass *object_class; + GtkWidgetClass *widget_class; + + object_class = G_OBJECT_CLASS (tooltip_class); + widget_class = GTK_WIDGET_CLASS (tooltip_class); + + object_class->finalize = meta_tooltip_finalize; + + widget_class->realize = meta_tooltip_realize; + + gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_TOOL_TIP); + gtk_widget_class_set_css_name (widget_class, "tooltip"); +} + +static void +meta_tooltip_init (MetaTooltip *tooltip) +{ + tooltip->box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); + gtk_container_add (GTK_CONTAINER (tooltip), tooltip->box); + gtk_widget_show (tooltip->box); + + gtk_widget_set_margin_start (tooltip->box, 6); + gtk_widget_set_margin_end (tooltip->box, 6); + gtk_widget_set_margin_top (tooltip->box, 6); + gtk_widget_set_margin_bottom (tooltip->box, 6); + + tooltip->label = gtk_label_new (NULL); + gtk_box_pack_start (GTK_BOX (tooltip->box), tooltip->label, FALSE, FALSE, 0); + + gtk_label_set_line_wrap (GTK_LABEL (tooltip->label), TRUE); + gtk_label_set_max_width_chars (GTK_LABEL (tooltip->label), 70); + + tooltip->composited = meta_prefs_get_compositing_manager (); + update_style_class (tooltip); + + meta_prefs_add_listener (prefs_changed_cb, tooltip); +} + +GtkWidget * +meta_tooltip_new (void) +{ + return g_object_new (META_TYPE_TOOLTIP, + "type", GTK_WINDOW_POPUP, + "type-hint", GDK_WINDOW_TYPE_HINT_TOOLTIP, + "resizable", FALSE, + NULL); +} + +void +meta_tooltip_set_label_markup (MetaTooltip *tooltip, + const gchar *markup) +{ + if (markup != NULL) + { + gtk_label_set_markup (GTK_LABEL (tooltip->label), markup); + gtk_widget_show (tooltip->label); + } + else + { + gtk_widget_hide (tooltip->label); + } +} + +void +meta_tooltip_set_label_text (MetaTooltip *tooltip, + const gchar *text) +{ + if (text != NULL) + { + gtk_label_set_text (GTK_LABEL (tooltip->label), text); + gtk_widget_show (tooltip->label); + } + else + { + gtk_widget_hide (tooltip->label); + } +} diff --git a/src/ui/meta-tooltip.h b/src/ui/meta-tooltip.h new file mode 100644 index 00000000..0ae746bb --- /dev/null +++ b/src/ui/meta-tooltip.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2016 Alberts Muktupāvels + * + * 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, see <http://www.gnu.org/licenses/>. + */ + +#ifndef META_TOOLTIP_H +#define META_TOOLTIP_H + +#include <gtk/gtk.h> + +G_BEGIN_DECLS + +#define META_TYPE_TOOLTIP meta_tooltip_get_type () +G_DECLARE_FINAL_TYPE (MetaTooltip, meta_tooltip, META, TOOLTIP, GtkWindow) + +GtkWidget *meta_tooltip_new (void); + +void meta_tooltip_set_label_markup (MetaTooltip *tooltip, + const gchar *markup); + +void meta_tooltip_set_label_text (MetaTooltip *tooltip, + const gchar *text); + +G_END_DECLS + +#endif diff --git a/src/ui/resizepopup.c b/src/ui/resizepopup.c index b0f5616a..d6f02f56 100644 --- a/src/ui/resizepopup.c +++ b/src/ui/resizepopup.c @@ -21,6 +21,7 @@ #include <config.h> #include "resizepopup.h" +#include "meta-tooltip.h" #include "util.h" #include <gtk/gtk.h> #include <gdk/gdkx.h> @@ -28,7 +29,6 @@ struct _MetaResizePopup { GtkWidget *size_window; - GtkWidget *size_label; Display *display; int vertical_size; @@ -62,63 +62,13 @@ meta_ui_resize_popup_free (MetaResizePopup *popup) g_free (popup); } -static gboolean -size_window_draw (GtkWidget *widget, - cairo_t *cr, - MetaResizePopup *popup) -{ - GtkStyleContext *context; - gint width, height; - - context = gtk_widget_get_style_context (widget); - width = gtk_widget_get_allocated_width (widget); - height = gtk_widget_get_allocated_height (widget); - - gtk_render_background (context, cr, 0, 0, width, height); - gtk_render_frame (context, cr, 0, 0, width, height); - - return FALSE; -} - static void ensure_size_window (MetaResizePopup *popup) { - GdkVisual *visual; - GdkScreen *screen; - if (popup->size_window) return; - popup->size_window = gtk_window_new (GTK_WINDOW_POPUP); - - screen = gdk_screen_get_default (); - visual = gdk_screen_get_rgba_visual (screen); - - gtk_window_set_screen (GTK_WINDOW (popup->size_window), screen); - if (visual != NULL) - gtk_widget_set_visual (popup->size_window, visual); - - gtk_window_set_type_hint (GTK_WINDOW (popup->size_window), - GDK_WINDOW_TYPE_HINT_TOOLTIP); - gtk_window_set_resizable (GTK_WINDOW (popup->size_window), FALSE); - - gtk_widget_set_app_paintable (popup->size_window, TRUE); - gtk_style_context_add_class (gtk_widget_get_style_context (popup->size_window), - GTK_STYLE_CLASS_TOOLTIP); - g_signal_connect (popup->size_window, "draw", - G_CALLBACK (size_window_draw), popup); - - popup->size_label = gtk_label_new (""); - - gtk_widget_set_margin_start (popup->size_label, 6); - gtk_widget_set_margin_end (popup->size_label, 6); - gtk_widget_set_margin_top (popup->size_label, 6); - gtk_widget_set_margin_bottom (popup->size_label, 6); - - gtk_container_add (GTK_CONTAINER (popup->size_window), - popup->size_label); - - gtk_widget_show (popup->size_label); + popup->size_window = meta_tooltip_new (); } static void @@ -137,8 +87,7 @@ update_size_window (MetaResizePopup *popup) popup->horizontal_size, popup->vertical_size); - gtk_label_set_text (GTK_LABEL (popup->size_label), str); - + meta_tooltip_set_label_text (META_TOOLTIP (popup->size_window), str); g_free (str); gtk_window_get_size (GTK_WINDOW (popup->size_window), &width, &height); |