diff options
author | infirit <[email protected]> | 2014-11-08 00:59:16 +0100 |
---|---|---|
committer | infirit <[email protected]> | 2014-11-28 08:51:50 +0100 |
commit | fd55cee48a6fa2fd5ee312923abe2c2893f519f8 (patch) | |
tree | 21bae779443090c3a10ac6522c9c5c5219b7b1f7 /libmate-desktop/mate-rr-labeler.c | |
parent | 6d6ea55cd7f962fc7d1b7a773d716552c8d4e36b (diff) | |
download | mate-desktop-fd55cee48a6fa2fd5ee312923abe2c2893f519f8.tar.bz2 mate-desktop-fd55cee48a6fa2fd5ee312923abe2c2893f519f8.tar.xz |
Turn GnomeRRConfig and GnomeOutputInfo into GObjects
Based on gnome-desktop commits:
1d1f8ef64f404eccb29d384a75939701327e8e77
2c7a2e90fee98ff61e530098bc962a65dec670bc
7436f759bec00d87f597ef0b6945da8fa8969e85
From: Giovanni Campagna <[email protected]>
Gnome Bug: https://bugzilla.gnome.org/show_bug.cgi?id=630913
Diffstat (limited to 'libmate-desktop/mate-rr-labeler.c')
-rw-r--r-- | libmate-desktop/mate-rr-labeler.c | 212 |
1 files changed, 128 insertions, 84 deletions
diff --git a/libmate-desktop/mate-rr-labeler.c b/libmate-desktop/mate-rr-labeler.c index e515b51..e4aaa3e 100644 --- a/libmate-desktop/mate-rr-labeler.c +++ b/libmate-desktop/mate-rr-labeler.c @@ -29,7 +29,6 @@ #include <config.h> #include <glib/gi18n-lib.h> -#include "mate-rr-labeler.h" #include <gtk/gtk.h> #include <X11/Xproto.h> @@ -38,9 +37,9 @@ #include <X11/Xatom.h> #include <gdk/gdkx.h> -struct _MateRRLabeler { - GObject parent; +#include "mate-rr-labeler.h" +struct _MateRRLabelerPrivate { MateRRConfig *config; int num_outputs; @@ -56,14 +55,17 @@ struct _MateRRLabeler { Atom workarea_atom; }; -struct _MateRRLabelerClass { - GObjectClass parent_class; +enum { + PROP_0, + PROP_CONFIG, + PROP_LAST }; G_DEFINE_TYPE (MateRRLabeler, mate_rr_labeler, G_TYPE_OBJECT); static void mate_rr_labeler_finalize (GObject *object); static void create_label_windows (MateRRLabeler *labeler); +static void setup_from_config (MateRRLabeler *labeler); static gboolean get_work_area (MateRRLabeler *labeler, @@ -82,16 +84,16 @@ get_work_area (MateRRLabeler *labeler, int disp_screen; Display *display; - display = GDK_DISPLAY_XDISPLAY (gdk_screen_get_display (labeler->screen)); + display = GDK_DISPLAY_XDISPLAY (gdk_screen_get_display (labeler->priv->screen)); workarea = XInternAtom (display, "_NET_WORKAREA", True); - disp_screen = GDK_SCREEN_XNUMBER (labeler->screen); + disp_screen = GDK_SCREEN_XNUMBER (labeler->priv->screen); /* Defaults in case of error */ rect->x = 0; rect->y = 0; - rect->width = gdk_screen_get_width (labeler->screen); - rect->height = gdk_screen_get_height (labeler->screen); + rect->width = gdk_screen_get_width (labeler->priv->screen); + rect->height = gdk_screen_get_height (labeler->priv->screen); if (workarea == None) return FALSE; @@ -139,7 +141,7 @@ screen_xevent_filter (GdkXEvent *xevent, xev = (XEvent *) xevent; if (xev->type == PropertyNotify && - xev->xproperty.atom == labeler->workarea_atom) { + xev->xproperty.atom == labeler->priv->workarea_atom) { /* update label positions */ mate_rr_labeler_hide (labeler); create_label_windows (labeler); @@ -153,25 +155,62 @@ mate_rr_labeler_init (MateRRLabeler *labeler) { GdkWindow *gdkwindow; - labeler->workarea_atom = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), - "_NET_WORKAREA", - True); + labeler->priv = G_TYPE_INSTANCE_GET_PRIVATE (labeler, MATE_TYPE_RR_LABELER, MateRRLabelerPrivate); - labeler->screen = gdk_screen_get_default (); + labeler->priv->workarea_atom = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), + "_NET_WORKAREA", + True); + + labeler->priv->screen = gdk_screen_get_default (); /* code is not really designed to handle multiple screens so *shrug* */ - gdkwindow = gdk_screen_get_root_window (labeler->screen); + gdkwindow = gdk_screen_get_root_window (labeler->priv->screen); gdk_window_add_filter (gdkwindow, (GdkFilterFunc) screen_xevent_filter, labeler); gdk_window_set_events (gdkwindow, gdk_window_get_events (gdkwindow) | GDK_PROPERTY_CHANGE_MASK); } static void -mate_rr_labeler_class_init (MateRRLabelerClass *class) +mate_rr_labeler_set_property (GObject *gobject, guint property_id, const GValue *value, GParamSpec *param_spec) +{ + MateRRLabeler *self = MATE_RR_LABELER (gobject); + + switch (property_id) { + case PROP_CONFIG: + self->priv->config = MATE_RR_CONFIG (g_value_get_object (value)); + return; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, property_id, param_spec); + } +} + +static GObject * +mate_rr_labeler_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties) +{ + MateRRLabeler *self = (MateRRLabeler*) G_OBJECT_CLASS (mate_rr_labeler_parent_class)->constructor (type, n_construct_properties, construct_properties); + + setup_from_config (self); + + return (GObject*) self; +} + +static void +mate_rr_labeler_class_init (MateRRLabelerClass *klass) { GObjectClass *object_class; - object_class = (GObjectClass *) class; + g_type_class_add_private (klass, sizeof (MateRRLabelerPrivate)); + object_class = (GObjectClass *) klass; + + object_class->set_property = mate_rr_labeler_set_property; object_class->finalize = mate_rr_labeler_finalize; + object_class->constructor = mate_rr_labeler_constructor; + + g_object_class_install_property (object_class, PROP_CONFIG, g_param_spec_object ("config", + "Configuration", + "RandR configuration to label", + MATE_TYPE_RR_CONFIG, + G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); } static void @@ -182,21 +221,19 @@ mate_rr_labeler_finalize (GObject *object) labeler = MATE_RR_LABELER (object); - gdkwindow = gdk_screen_get_root_window (labeler->screen); + gdkwindow = gdk_screen_get_root_window (labeler->priv->screen); gdk_window_remove_filter (gdkwindow, (GdkFilterFunc) screen_xevent_filter, labeler); - /* We don't destroy the labeler->config (a MateRRConfig*) here; let our - * caller do that instead. - */ + if (labeler->priv->config != NULL) { + g_object_unref (labeler->priv->config); + } - if (labeler->windows != NULL) { + if (labeler->priv->windows != NULL) { mate_rr_labeler_hide (labeler); - g_free (labeler->windows); - labeler->windows = NULL; + g_free (labeler->priv->windows); } - g_free (labeler->palette); - labeler->palette = NULL; + g_free (labeler->priv->palette); G_OBJECT_CLASS (mate_rr_labeler_parent_class)->finalize (object); } @@ -205,8 +242,9 @@ static int count_outputs (MateRRConfig *config) { int i; + MateRROutputInfo **outputs = mate_rr_config_get_outputs (config); - for (i = 0; config->outputs[i] != NULL; i++) + for (i = 0; outputs[i] != NULL; i++) ; return i; @@ -227,36 +265,36 @@ make_palette (MateRRLabeler *labeler) double end_hue; int i; - g_assert (labeler->num_outputs > 0); + g_assert (labeler->priv->num_outputs > 0); #if GTK_CHECK_VERSION (3, 0, 0) - labeler->palette = g_new (GdkRGBA, labeler->num_outputs); + labeler->priv->palette = g_new (GdkRGBA, labeler->priv->num_outputs); #else - labeler->palette = g_new (GdkColor, labeler->num_outputs); + labeler->priv->palette = g_new (GdkColor, labeler->priv->num_outputs); #endif start_hue = 0.0; /* red */ end_hue = 2.0/3; /* blue */ - for (i = 0; i < labeler->num_outputs; i++) { + for (i = 0; i < labeler->priv->num_outputs; i++) { double h, s, v; double r, g, b; - h = start_hue + (end_hue - start_hue) / labeler->num_outputs * i; + h = start_hue + (end_hue - start_hue) / labeler->priv->num_outputs * i; s = 1.0 / 3; v = 1.0; gtk_hsv_to_rgb (h, s, v, &r, &g, &b); #if GTK_CHECK_VERSION (3, 0, 0) - labeler->palette[i].red = r; - labeler->palette[i].green = g; - labeler->palette[i].blue = b; - labeler->palette[i].alpha = 1.0; + labeler->priv->palette[i].red = r; + labeler->priv->palette[i].green = g; + labeler->priv->palette[i].blue = b; + labeler->priv->palette[i].alpha = 1.0; #else - labeler->palette[i].red = (int) (65535 * r + 0.5); - labeler->palette[i].green = (int) (65535 * g + 0.5); - labeler->palette[i].blue = (int) (65535 * b + 0.5); + labeler->priv->palette[i].red = (int) (65535 * r + 0.5); + labeler->priv->palette[i].green = (int) (65535 * g + 0.5); + labeler->priv->palette[i].blue = (int) (65535 * b + 0.5); #endif } } @@ -327,8 +365,8 @@ position_window (MateRRLabeler *labeler, int monitor_num; get_work_area (labeler, &workarea); - monitor_num = gdk_screen_get_monitor_at_point (labeler->screen, x, y); - gdk_screen_get_monitor_geometry (labeler->screen, + monitor_num = gdk_screen_get_monitor_at_point (labeler->priv->screen, x, y); + gdk_screen_get_monitor_geometry (labeler->priv->screen, monitor_num, &monitor); gdk_rectangle_intersect (&monitor, &workarea, &workarea); @@ -338,10 +376,10 @@ position_window (MateRRLabeler *labeler, #if GTK_CHECK_VERSION (3, 0, 0) static GtkWidget * -create_label_window (MateRRLabeler *labeler, MateOutputInfo *output, GdkRGBA *color) +create_label_window (MateRRLabeler *labeler, MateRROutputInfo *output, GdkRGBA *color) #else static GtkWidget * -create_label_window (MateRRLabeler *labeler, MateOutputInfo *output, GdkColor *color) +create_label_window (MateRRLabeler *labeler, MateRROutputInfo *output, GdkColor *color) #endif { GtkWidget *window; @@ -349,6 +387,7 @@ create_label_window (MateRRLabeler *labeler, MateOutputInfo *output, GdkColor *c char *str; const char *display_name; GdkColor black = { 0, 0, 0, 0 }; + int x,y; window = gtk_window_new (GTK_WINDOW_POPUP); gtk_widget_set_app_paintable (window, TRUE); @@ -369,7 +408,7 @@ create_label_window (MateRRLabeler *labeler, MateOutputInfo *output, GdkColor *c G_CALLBACK (label_window_expose_event_cb), labeler); #endif - if (labeler->config->clone) { + if (mate_rr_config_get_clone (labeler->priv->config)) { /* Keep this string in sync with mate-control-center/capplets/display/xrandr-capplet.c:get_display_name() */ /* Translators: this is the feature where what you see on your laptop's @@ -379,7 +418,7 @@ create_label_window (MateRRLabeler *labeler, MateOutputInfo *output, GdkColor *c */ display_name = _("Mirror Screens"); } else - display_name = output->display_name; + display_name = mate_rr_output_info_get_display_name (output); str = g_strdup_printf ("<b>%s</b>", display_name); widget = gtk_label_new (NULL); @@ -395,7 +434,8 @@ create_label_window (MateRRLabeler *labeler, MateOutputInfo *output, GdkColor *c gtk_container_add (GTK_CONTAINER (window), widget); /* Should we center this at the top edge of the monitor, instead of using the upper-left corner? */ - position_window (labeler, window, output->x, output->y); + mate_rr_output_info_get_geometry (output, &x, &y, NULL, NULL); + position_window (labeler, window, x, y); gtk_widget_show_all (window); @@ -407,26 +447,29 @@ create_label_windows (MateRRLabeler *labeler) { int i; gboolean created_window_for_clone; + MateRROutputInfo **outputs; - labeler->windows = g_new (GtkWidget *, labeler->num_outputs); + labeler->priv->windows = g_new (GtkWidget *, labeler->priv->num_outputs); created_window_for_clone = FALSE; - for (i = 0; i < labeler->num_outputs; i++) { - if (!created_window_for_clone && labeler->config->outputs[i]->on) { - labeler->windows[i] = create_label_window (labeler, labeler->config->outputs[i], labeler->palette + i); + outputs = mate_rr_config_get_outputs (labeler->priv->config); + + for (i = 0; i < labeler->priv->num_outputs; i++) { + if (!created_window_for_clone && mate_rr_output_info_get_active (outputs[i])) { + labeler->priv->windows[i] = create_label_window (labeler, outputs[i], labeler->priv->palette + i); - if (labeler->config->clone) + if (mate_rr_config_get_clone (labeler->priv->config)) created_window_for_clone = TRUE; } else - labeler->windows[i] = NULL; + labeler->priv->windows[i] = NULL; } } static void setup_from_config (MateRRLabeler *labeler) { - labeler->num_outputs = count_outputs (labeler->config); + labeler->priv->num_outputs = count_outputs (labeler->priv->config); make_palette (labeler); @@ -436,51 +479,49 @@ setup_from_config (MateRRLabeler *labeler) MateRRLabeler * mate_rr_labeler_new (MateRRConfig *config) { - MateRRLabeler *labeler; - - g_return_val_if_fail (config != NULL, NULL); - - labeler = g_object_new (MATE_TYPE_RR_LABELER, NULL); - labeler->config = config; + g_return_val_if_fail (MATE_IS_RR_CONFIG (config), NULL); - setup_from_config (labeler); - - return labeler; + return g_object_new (MATE_TYPE_RR_LABELER, "config", config, NULL); } void mate_rr_labeler_hide (MateRRLabeler *labeler) { int i; + MateRRLabelerPrivate *priv; g_return_if_fail (MATE_IS_RR_LABELER (labeler)); - if (labeler->windows == NULL) - return; + priv = labeler->priv; - for (i = 0; i < labeler->num_outputs; i++) - if (labeler->windows[i] != NULL) { - gtk_widget_destroy (labeler->windows[i]); - labeler->windows[i] = NULL; - } - g_free (labeler->windows); - labeler->windows = NULL; + if (priv->windows == NULL) + return; + for (i = 0; i < priv->num_outputs; i++) + if (priv->windows[i] != NULL) { + gtk_widget_destroy (priv->windows[i]); + priv->windows[i] = NULL; + } + g_free (priv->windows); + priv->windows = NULL; } #if GTK_CHECK_VERSION (3, 0, 0) void -mate_rr_labeler_get_rgba_for_output (MateRRLabeler *labeler, MateOutputInfo *output, GdkRGBA *color_out) +mate_rr_labeler_get_rgba_for_output (MateRRLabeler *labeler, MateRROutputInfo *output, GdkRGBA *color_out) { int i; + MateRROutputInfo **outputs; g_return_if_fail (MATE_IS_RR_LABELER (labeler)); - g_return_if_fail (output != NULL); + g_return_if_fail (MATE_IS_RR_OUTPUT_INFO (output)) g_return_if_fail (color_out != NULL); - for (i = 0; i < labeler->num_outputs; i++) - if (labeler->config->outputs[i] == output) { - *color_out = labeler->palette[i]; + outputs = mate_rr_config_get_outputs (labeler->priv->config); + + for (i = 0; i < labeler->priv->num_outputs; i++) + if (outputs[i] == output) { + *color_out = labeler->priv->palette[i]; return; } @@ -494,22 +535,25 @@ mate_rr_labeler_get_rgba_for_output (MateRRLabeler *labeler, MateOutputInfo *out #endif void -mate_rr_labeler_get_color_for_output (MateRRLabeler *labeler, MateOutputInfo *output, GdkColor *color_out) +mate_rr_labeler_get_color_for_output (MateRRLabeler *labeler, MateRROutputInfo *output, GdkColor *color_out) { int i; + MateRROutputInfo **outputs; g_return_if_fail (MATE_IS_RR_LABELER (labeler)); - g_return_if_fail (output != NULL); + g_return_if_fail (MATE_IS_RR_OUTPUT_INFO (output)); g_return_if_fail (color_out != NULL); - for (i = 0; i < labeler->num_outputs; i++) - if (labeler->config->outputs[i] == output) { + outputs = mate_rr_config_get_outputs (labeler->priv->config); + + for (i = 0; i < labeler->priv->num_outputs; i++) + if (outputs[i] == output) { #if GTK_CHECK_VERSION (3, 0, 0) - color_out->red = labeler->palette[i].red * 0xffff; - color_out->green = labeler->palette[i].green * 0xffff; - color_out->blue = labeler->palette[i].blue * 0xffff; + color_out->red = labeler->priv->palette[i].red * 0xffff; + color_out->green = labeler->priv->palette[i].green * 0xffff; + color_out->blue = labeler->priv->palette[i].blue * 0xffff; #else - *color_out = labeler->palette[i]; + *color_out = labeler->priv->palette[i]; #endif return; } |