Skip to content
Permalink
Browse files

xrandr-applet-popup: enable turning monitors on an off

Add menu item to allow turning a monitor on or off from the popup menu. Borrow code from m-s-d display capplet to set geometry when a monitor is turned on. Turning on a monitor now works the same was as when turning it on but not reconfiguring it in mate-control-center's display capplet
  • Loading branch information...
lukefromdc committed May 24, 2018
1 parent 05d1d3c commit 409c8d856a75ea5a00913722d4565796add6edc3
Showing with 83 additions and 0 deletions.
  1. +83 −0 plugins/xrandr/msd-xrandr-manager.c
@@ -1930,6 +1930,47 @@ ensure_current_configuration_is_saved (void)
g_object_unref (rr_screen);
}

static void
monitor_activate_cb (GtkCheckMenuItem *item, gpointer data)
{
MsdXrandrManager *manager = MSD_XRANDR_MANAGER (data);
struct MsdXrandrManagerPrivate *priv = manager->priv;
MateRROutputInfo *output;
GError *error;

ensure_current_configuration_is_saved ();

output = g_object_get_data (G_OBJECT (item), "output");

/*This is borrowed from the capplet in mate-control-center
*And shares the same limitations concerning monitors
*which have been turned off and back on without being reconfigured
*/
if (gtk_check_menu_item_get_active (item)){
int x, y, width, height;
mate_rr_output_info_get_geometry (output, &x, &y, NULL, NULL);
width = mate_rr_output_info_get_preferred_width (output);
height = mate_rr_output_info_get_preferred_height (output);
mate_rr_output_info_set_geometry (output, x, y, width, height);
mate_rr_output_info_set_active (output, TRUE);

}
else{
mate_rr_output_info_set_active (output, FALSE);
}

error = NULL;
if (!mate_rr_config_save (priv->configuration, &error)) {
error_message (manager, _("Could not save monitor configuration"), error, NULL);
if (error)
g_error_free (error);

return;
}

try_to_apply_intended_configuration (manager, NULL, gtk_get_current_event_time (), NULL);
}

static void
output_rotation_item_activate_cb (GtkCheckMenuItem *item, gpointer data)
{
@@ -2048,6 +2089,47 @@ add_rotation_items_for_output (MsdXrandrManager *manager, MateRROutputInfo *outp
add_items_for_rotations (manager, output, rotations);
}

static void
add_enable_option_for_output (MsdXrandrManager *manager, MateRROutputInfo *output)
{
struct MsdXrandrManagerPrivate *priv = manager->priv;
GtkWidget *item;
gulong activate_id;

item = gtk_check_menu_item_new();

if (mate_rr_output_info_is_active (output)){
gtk_menu_item_set_label (GTK_MENU_ITEM(item), "Using this monitor");
gtk_widget_set_tooltip_text(item, "Turn this monitor off");
}
else {
gtk_menu_item_set_label (GTK_MENU_ITEM(item), "Not using this monitor");
gtk_widget_set_tooltip_text(item ,"Turn this monitor on");
}

gtk_widget_show_all (item);
gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), item);

g_object_set_data (G_OBJECT (item), "output", output);

activate_id = g_signal_connect (item, "activate",
G_CALLBACK (monitor_activate_cb), manager);

/* Block the signal temporarily so our callback won't be called;
* we are just setting up the UI.
*/
g_signal_handler_block (item, activate_id);

if (mate_rr_output_info_is_active (output)){
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), TRUE);
}
else{
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), FALSE);
}

g_signal_handler_unblock (item, activate_id);
}

static void
add_menu_items_for_output (MsdXrandrManager *manager, MateRROutputInfo *output)
{
@@ -2057,6 +2139,7 @@ add_menu_items_for_output (MsdXrandrManager *manager, MateRROutputInfo *output)
item = make_menu_item_for_output_title (manager, output);
gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), item);

add_enable_option_for_output (manager, output);
add_rotation_items_for_output (manager, output);
}

0 comments on commit 409c8d8

Please sign in to comment.
You can’t perform that action at this time.