diff options
Diffstat (limited to 'plugins/xrandr')
-rw-r--r-- | plugins/xrandr/Makefile.am | 18 | ||||
-rw-r--r-- | plugins/xrandr/msd-xrandr-manager.c | 374 | ||||
-rw-r--r-- | plugins/xrandr/msd-xrandr-manager.h | 1 | ||||
-rw-r--r-- | plugins/xrandr/msd-xrandr-manager.xml | 21 | ||||
-rw-r--r-- | plugins/xrandr/msd-xrandr-plugin.c | 1 | ||||
-rw-r--r-- | plugins/xrandr/msd-xrandr-plugin.h | 1 |
6 files changed, 191 insertions, 225 deletions
diff --git a/plugins/xrandr/Makefile.am b/plugins/xrandr/Makefile.am index 0ea6790..ccf6f69 100644 --- a/plugins/xrandr/Makefile.am +++ b/plugins/xrandr/Makefile.am @@ -1,6 +1,7 @@ icondir = $(datadir)/icons/hicolor context = apps + ICON_FILES = \ msd-xrandr-16.png \ msd-xrandr-22.png \ @@ -43,19 +44,8 @@ uninstall-local: plugin_LTLIBRARIES = \ libxrandr.la -msd_xrandr_built_sources = \ - msd-xrandr-generated.h \ - msd-xrandr-generated.c \ - $(NULL) - -$(msd_xrandr_built_sources) : $(srcdir)/msd-xrandr-manager.xml - $(AM_V_GEN) $(GDBUS_CODEGEN) \ - --interface-prefix org.mate.SettingsDaemon. \ - --c-namespace MateXrandr \ - --generate-c-code msd-xrandr-generated $< libxrandr_la_SOURCES = \ - $(msd_xrandr_built_sources) \ msd-xrandr-plugin.h \ msd-xrandr-plugin.c \ msd-xrandr-manager.h \ @@ -87,9 +77,9 @@ plugin_in_files = \ plugin_DATA = $(plugin_in_files:.mate-settings-plugin.desktop.in=.mate-settings-plugin) -EXTRA_DIST = $(plugin_in_files) $(ICON_FILES) msd-xrandr-manager.xml -CLEANFILES = $(plugin_DATA) $(msd_xrandr_built_sources) -DISTCLEANFILES = $(plugin_DATA) $(msd_xrandr_built_sources) +EXTRA_DIST = $(plugin_in_files) $(ICON_FILES) +CLEANFILES = $(plugin_DATA) +DISTCLEANFILES = $(plugin_DATA) $(plugin_DATA): $(plugin_in_files) $(AM_V_GEN) $(MSGFMT) --desktop --template $< -d $(top_srcdir)/po -o $@ diff --git a/plugins/xrandr/msd-xrandr-manager.c b/plugins/xrandr/msd-xrandr-manager.c index a1f5e6d..78e538f 100644 --- a/plugins/xrandr/msd-xrandr-manager.c +++ b/plugins/xrandr/msd-xrandr-manager.c @@ -1,8 +1,8 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * vim: set ts=8 sts=8 sw=8 expandtab: * * Copyright (C) 2007 William Jon McCann <[email protected]> * Copyright (C) 2007, 2008 Red Hat, Inc + * Copyright (C) 2012-2021 MATE Developers * * 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 @@ -52,7 +52,6 @@ #include "mate-settings-profile.h" #include "msd-xrandr-manager.h" -#include "msd-xrandr-generated.h" #define CONF_SCHEMA "org.mate.SettingsDaemon.plugins.xrandr" #define CONF_KEY_SHOW_NOTIFICATION_ICON "show-notification-icon" @@ -79,13 +78,28 @@ #define MSD_DBUS_NAME "org.mate.SettingsDaemon" #define MSD_XRANDR_DBUS_NAME MSD_DBUS_NAME ".XRANDR" #define MSD_XRANDR_DBUS_PATH MSD_DBUS_PATH "/XRANDR" -#define MSD_XRANDR_DBUS_PATH_2 MSD_DBUS_PATH "/XRANDR_2" + +static const gchar introspection_xml[] = +"<node>" +" <interface name='org.mate.SettingsDaemon.XRANDR'>" +" <method name='ApplyConfiguration'>" +" </method>" +" </interface>" +"" +" <interface name='org.mate.SettingsDaemon.XRANDR_2'>" +" <method name='ApplyConfiguration'>" +" <arg name='parent_window_id' type='x' direction='in'/>" +" <arg name='timestamp' type='x' direction='in'/>" +" </method>" +" </interface>" +"</node>"; struct MsdXrandrManagerPrivate { - MateXrandrXRANDR *skeleton; - MateXrandrXRANDR_2 *skeleton_2; - guint bus_name_id; + GDBusConnection *connection; + GDBusNodeInfo *introspection_data; + GCancellable *bus_cancellable; + guint owner_id; /* Key code of the XF86Display key (Fn-F7 on Thinkpads, Fn-F4 on HP machines, etc.) */ guint switch_video_mode_keycode; @@ -129,14 +143,6 @@ static void get_allowed_rotations_for_output (MateRRConfig *config, MateRROutputInfo *output, int *out_num_rotations, MateRRRotation *out_rotations); -static gboolean on_handle_apply_configuration (MateXrandrXRANDR *object, - GDBusMethodInvocation *invocation, - gpointer user_data); -static gboolean on_handle_apply_configuration_2 (MateXrandrXRANDR_2 *object, - GDBusMethodInvocation *invocation, - gint64 parent_window_id, - gint64 timestamp, - gpointer user_data); G_DEFINE_TYPE_WITH_PRIVATE (MsdXrandrManager, msd_xrandr_manager, G_TYPE_OBJECT) @@ -608,6 +614,37 @@ out: return result; } +/* DBus method for org.mate.SettingsDaemon.XRANDR ApplyConfiguration; see msd-xrandr-manager.xml for the interface definition */ +static gboolean +msd_xrandr_manager_apply_configuration (MsdXrandrManager *manager, + GError **error) +{ + return try_to_apply_intended_configuration (manager, NULL, GDK_CURRENT_TIME, error); +} + +/* DBus method for org.mate.SettingsDaemon.XRANDR_2 ApplyConfiguration; see msd-xrandr-manager.xml for the interface definition */ +static gboolean +msd_xrandr_manager_2_apply_configuration (MsdXrandrManager *manager, + gint64 parent_window_id, + gint64 timestamp, + GError **error) +{ + GdkWindow *parent_window; + gboolean result; + + if (parent_window_id != 0) + parent_window = gdk_x11_window_foreign_new_for_display (gdk_display_get_default (), (Window) parent_window_id); + else + parent_window = NULL; + + result = try_to_apply_intended_configuration (manager, parent_window, (guint32) timestamp, error); + + if (parent_window) + g_object_unref (parent_window); + + return result; +} + static gboolean is_laptop (MateRRScreen *screen, MateRROutputInfo *output) { @@ -763,7 +800,7 @@ find_best_mode (MateRROutput *output) MateRRMode *preferred; MateRRMode **modes; int best_size; - int best_width, best_height, best_rate; + int best_rate; int i; MateRRMode *best_mode; @@ -775,7 +812,7 @@ find_best_mode (MateRROutput *output) if (!modes) return NULL; - best_size = best_width = best_height = best_rate = 0; + best_size = best_rate = 0; best_mode = NULL; for (i = 0; modes[i] != NULL; i++) { @@ -790,8 +827,6 @@ find_best_mode (MateRROutput *output) if (size > best_size) { best_size = size; - best_width = w; - best_height = h; best_rate = r; best_mode = modes[i]; } else if (size == best_size) { @@ -985,7 +1020,6 @@ sanitize (MsdXrandrManager *manager, GPtrArray *array) } } - /* Remove configurations that are duplicates of * configurations earlier in the cycle */ @@ -1758,8 +1792,8 @@ make_menu_item_for_output_title (MsdXrandrManager *manager, MateRROutputInfo *ou /*Load the icon unless the user has icons in menus turned off*/ icon_settings = g_settings_new ("org.mate.interface"); if (g_settings_get_boolean (icon_settings, "menus-have-icons")){ - gtk_container_add (GTK_CONTAINER (box), image); - } + gtk_container_add (GTK_CONTAINER (box), image); + } gtk_container_add (GTK_CONTAINER (box), label); gtk_container_add (GTK_CONTAINER (item), box); @@ -2028,11 +2062,10 @@ mirror_outputs_cb(GtkCheckMenuItem *item, gpointer data) struct MsdXrandrManagerPrivate *priv = manager->priv; MateRRScreen *screen = priv->rw_screen; - if (gtk_check_menu_item_get_active(item)){ - + if (gtk_check_menu_item_get_active (item)) { MateRRConfig *config; - config = make_clone_setup (screen); - if (!config || config == NULL){ + + if ((config = make_clone_setup (screen)) == NULL) { error_message (manager, _("Mirroring outputs not supported"), NULL, NULL); } @@ -2221,7 +2254,7 @@ add_menu_items_for_clone (MsdXrandrManager *manager) GtkWidget *item; gulong activate_id; - item = gtk_check_menu_item_new_with_label(_("Same output all monitors")); + item = gtk_check_menu_item_new_with_label(_("Same output on all monitors")); gtk_widget_set_tooltip_text(item, _("Mirror same output to all monitors and turn them on")); gtk_widget_show_all (item); gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), item); @@ -2634,172 +2667,23 @@ msd_xrandr_manager_stop (MsdXrandrManager *manager) manager->priv->rw_screen = NULL; } - status_icon_stop (manager); - - log_open (); - log_msg ("STOPPING XRANDR PLUGIN\n------------------------------------------------------------\n"); - log_close (); -} - -/* - * DBus method for org.mate.SettingsDaemon.XRANDR ApplyConfiguration; - * see msd-xrandr-manager.xml for the interface definition - * */ -static gboolean -on_handle_apply_configuration (MateXrandrXRANDR *object, - GDBusMethodInvocation *invocation, - gpointer user_data) -{ - MsdXrandrManager *manager; - GError *error = NULL; - gboolean result; - - manager = MSD_XRANDR_MANAGER (user_data); - result = try_to_apply_intended_configuration (manager, NULL, GDK_CURRENT_TIME, &error); - if (!result) { - g_dbus_method_invocation_return_gerror (invocation, error); - g_error_free (error); - } else { - mate_xrandr_xrandr_complete_apply_configuration (object, invocation); + if (manager->priv->owner_id > 0) { + g_bus_unown_name (manager->priv->owner_id); + manager->priv->owner_id = 0; } - return result; -} -/* - * DBus method for org.mate.SettingsDaemon.XRANDR_2 ApplyConfiguration; - * see msd-xrandr-manager.xml for the interface definition - * */ -static gboolean -on_handle_apply_configuration_2 (MateXrandrXRANDR_2 *object, - GDBusMethodInvocation *invocation, - gint64 parent_window_id, - gint64 timestamp, - gpointer user_data) -{ - MsdXrandrManager *manager; - GdkWindow *parent_window; - gboolean result; - GError *error = NULL; - - if (parent_window_id != 0) - parent_window = gdk_x11_window_foreign_new_for_display ( - gdk_display_get_default (), - (Window) parent_window_id); - else - parent_window = NULL; - - manager = MSD_XRANDR_MANAGER (user_data); - result = try_to_apply_intended_configuration (manager, - parent_window, - (guint32) timestamp, - &error); - if (!result) { - g_dbus_method_invocation_return_gerror (invocation, error); - g_error_free (error); - } else { - mate_xrandr_xrandr_2_complete_apply_configuration (object, invocation); + if (manager->priv->connection != NULL) { + g_object_unref (manager->priv->connection); + manager->priv->connection = NULL; } - if (parent_window) - g_object_unref (parent_window); - - return result; -} - -static void -bus_acquired_handler_cb (GDBusConnection *connection, - const gchar *name G_GNUC_UNUSED, - gpointer user_data) -{ - MsdXrandrManager *manager; - - GError *error = NULL; - gboolean exported; - manager = MSD_XRANDR_MANAGER (user_data); - - g_signal_connect (manager->priv->skeleton, - "handle-apply-configuration", - G_CALLBACK (on_handle_apply_configuration), - manager); - exported = g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (manager->priv->skeleton), - connection, - MSD_XRANDR_DBUS_PATH, - &error); - if (!exported) - { - g_warning ("MsdXrandrManager: Failed to export interface: %s", error->message); - g_error_free (error); - gtk_main_quit (); - } - - g_signal_connect (manager->priv->skeleton_2, - "handle-apply-configuration", - G_CALLBACK (on_handle_apply_configuration_2), - manager); - exported = g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (manager->priv->skeleton_2), - connection, - MSD_XRANDR_DBUS_PATH_2, - &error); - if (!exported) - { - g_warning ("MsdXrandrManager: Failed to export interface: %s", error->message); - g_error_free (error); - gtk_main_quit (); - } -} - -static void -msd_xrandr_manager_constructed (GObject *object) -{ - MsdXrandrManager *manager; - - manager = MSD_XRANDR_MANAGER (object); - - G_OBJECT_CLASS (msd_xrandr_manager_parent_class)->constructed (object); - - manager->priv->bus_name_id = g_bus_own_name (G_BUS_TYPE_SESSION, - MSD_XRANDR_DBUS_NAME, - G_BUS_NAME_OWNER_FLAGS_NONE, - bus_acquired_handler_cb, - NULL, - NULL, - manager, - NULL); -} - -static void -msd_xrandr_manager_dispose (GObject *object) -{ - MsdXrandrManager *manager; - - manager = MSD_XRANDR_MANAGER (object); - - if (manager->priv->skeleton != NULL) - { - GDBusInterfaceSkeleton *skeleton; - - skeleton = G_DBUS_INTERFACE_SKELETON (manager->priv->skeleton); - g_dbus_interface_skeleton_unexport (skeleton); - g_clear_object (&manager->priv->skeleton); - } - - if (manager->priv->skeleton_2 != NULL) - { - GDBusInterfaceSkeleton *skeleton; - - skeleton = G_DBUS_INTERFACE_SKELETON (manager->priv->skeleton_2); - g_dbus_interface_skeleton_unexport (skeleton); - g_clear_object (&manager->priv->skeleton_2); - } - - if (manager->priv->bus_name_id > 0) - { - g_bus_unown_name (manager->priv->bus_name_id); - manager->priv->bus_name_id = 0; - } + g_clear_pointer (&manager->priv->introspection_data, g_dbus_node_info_unref); + status_icon_stop (manager); - G_OBJECT_CLASS (msd_xrandr_manager_parent_class)->dispose (object); + log_open (); + log_msg ("STOPPING XRANDR PLUGIN\n------------------------------------------------------------\n"); + log_close (); } static void @@ -2808,8 +2692,6 @@ msd_xrandr_manager_class_init (MsdXrandrManagerClass *klass) GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = msd_xrandr_manager_finalize; - object_class->constructed = msd_xrandr_manager_constructed; - object_class->dispose = msd_xrandr_manager_dispose; } static guint @@ -2834,8 +2716,6 @@ msd_xrandr_manager_init (MsdXrandrManager *manager) manager->priv->current_fn_f7_config = -1; manager->priv->fn_f7_configs = NULL; - manager->priv->skeleton = mate_xrandr_xrandr_skeleton_new (); - manager->priv->skeleton_2 = mate_xrandr_xrandr_2_skeleton_new (); } static void @@ -2853,6 +2733,116 @@ msd_xrandr_manager_finalize (GObject *object) G_OBJECT_CLASS (msd_xrandr_manager_parent_class)->finalize (object); } +static void +handle_method_call (GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *method_name, + GVariant *parameters, + GDBusMethodInvocation *invocation, + gpointer user_data) +{ + MsdXrandrManager *manager = (MsdXrandrManager *) user_data; + g_autoptr (GError) error = NULL; + + g_debug ("Calling method '%s' for xrandr", method_name); + + if (g_strcmp0 (method_name, "ApplyConfiguration") == 0) { + msd_xrandr_manager_apply_configuration(manager, &error); + if (error != NULL) + g_dbus_method_invocation_return_gerror (invocation, error); + else + g_dbus_method_invocation_return_value (invocation, NULL); + } +} + +static void +handle_method_call2 (GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *method_name, + GVariant *parameters, + GDBusMethodInvocation *invocation, + gpointer user_data) +{ + MsdXrandrManager *manager = (MsdXrandrManager *) user_data; + g_autoptr (GError) error = NULL; + + g_debug ("Calling method '%s' for xrandr", method_name); + + if (g_strcmp0 (method_name, "ApplyConfiguration") == 0) { + gint64 parent_window_id; + gint64 timestamp; + g_variant_get (parameters, "(xx)", &parent_window_id, ×tamp); + msd_xrandr_manager_2_apply_configuration (manager, parent_window_id, timestamp, &error); + if (error != NULL) + g_dbus_method_invocation_return_gerror (invocation, error); + else + g_dbus_method_invocation_return_value (invocation, NULL); + } +} + +static const GDBusInterfaceVTable interface_vtable = +{ + .method_call = handle_method_call, +}; + +static const GDBusInterfaceVTable interface_vtable2 = +{ + .method_call = handle_method_call2, +}; + +static void +on_bus_gotten (GObject *source_object, + GAsyncResult *res, + MsdXrandrManager *manager) +{ + GDBusConnection *connection; + GError *error = NULL; + + connection = g_bus_get_finish (res, &error); + if (connection == NULL) { + if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + g_warning ("Could not get session bus: %s", error->message); + g_error_free (error); + return; + } + manager->priv->connection = connection; + + g_dbus_connection_register_object (connection, + MSD_XRANDR_DBUS_PATH, + manager->priv->introspection_data->interfaces[0], + &interface_vtable, + manager, + NULL, + NULL); + g_dbus_connection_register_object (connection, + MSD_XRANDR_DBUS_PATH, + manager->priv->introspection_data->interfaces[1], + &interface_vtable2, + manager, + NULL, + NULL); + + manager->priv->owner_id = g_bus_own_name_on_connection (manager->priv->connection, + MSD_DBUS_NAME, + G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT, + NULL, NULL, NULL, NULL); +} + +static void +register_manager_dbus (MsdXrandrManager *manager) +{ + manager->priv->introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL); + manager->priv->bus_cancellable = g_cancellable_new (); + g_bus_get (G_BUS_TYPE_SESSION, + manager->priv->bus_cancellable, + (GAsyncReadyCallback) on_bus_gotten, + manager); +} + MsdXrandrManager * msd_xrandr_manager_new (void) { @@ -2860,6 +2850,10 @@ msd_xrandr_manager_new (void) g_object_ref (manager_object); } else { manager_object = g_object_new (MSD_TYPE_XRANDR_MANAGER, NULL); + g_object_add_weak_pointer (manager_object, + (gpointer *) &manager_object); + + register_manager_dbus (manager_object); } return MSD_XRANDR_MANAGER (manager_object); diff --git a/plugins/xrandr/msd-xrandr-manager.h b/plugins/xrandr/msd-xrandr-manager.h index 8d1a00b..70aac7a 100644 --- a/plugins/xrandr/msd-xrandr-manager.h +++ b/plugins/xrandr/msd-xrandr-manager.h @@ -1,6 +1,7 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2007 William Jon McCann <[email protected]> + * Copyright (C) 2012-2021 MATE Developers * * 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 diff --git a/plugins/xrandr/msd-xrandr-manager.xml b/plugins/xrandr/msd-xrandr-manager.xml deleted file mode 100644 index 68f9dd6..0000000 --- a/plugins/xrandr/msd-xrandr-manager.xml +++ /dev/null @@ -1,21 +0,0 @@ -<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"> -<node> - <interface name="org.mate.SettingsDaemon.XRANDR"> - <method name="ApplyConfiguration"> - <!-- This method is implemented, but deprecated in favor of the - same method in the XRANDR-2 interface defined below. --> - </method> - </interface> - - <interface name="org.mate.SettingsDaemon.XRANDR_2"> - <method name="ApplyConfiguration"> - <!-- transient-parent window for the confirmation dialog; use 0 - for no parent --> - <arg name="parent_window_id" type="x" direction="in"/> - - <!-- Timestamp used to present the confirmation dialog and (in - the future) for the RANDR calls themselves --> - <arg name="timestamp" type="x" direction="in"/> - </method> - </interface> -</node> diff --git a/plugins/xrandr/msd-xrandr-plugin.c b/plugins/xrandr/msd-xrandr-plugin.c index 0175138..79ae93d 100644 --- a/plugins/xrandr/msd-xrandr-plugin.c +++ b/plugins/xrandr/msd-xrandr-plugin.c @@ -1,6 +1,7 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2007 William Jon McCann <[email protected]> + * Copyright (C) 2012-2021 MATE Developers * * 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 diff --git a/plugins/xrandr/msd-xrandr-plugin.h b/plugins/xrandr/msd-xrandr-plugin.h index 9a80ead..60eb7cf 100644 --- a/plugins/xrandr/msd-xrandr-plugin.h +++ b/plugins/xrandr/msd-xrandr-plugin.h @@ -1,6 +1,7 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * * Copyright (C) 2007 William Jon McCann <[email protected]> + * Copyright (C) 2012-2021 MATE Developers * * 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 |