Skip to content

Commit 3cfc8b5

Browse files
committed
xrandr-applet-popup: add item to mirror displays
Add menuitem for mirroring same output to all displays Toggle between mirrored mode and xinerama mode (displays all on, laid out left to right)
1 parent 4e412a5 commit 3cfc8b5

1 file changed

Lines changed: 103 additions & 3 deletions

File tree

plugins/xrandr/msd-xrandr-manager.c

Lines changed: 103 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,16 @@ is_laptop (MateRRScreen *screen, MateRROutputInfo *output)
641641
return mate_rr_output_is_laptop (rr_output);
642642
}
643643

644+
static gboolean
645+
is_primary (MateRRScreen *screen, MateRROutputInfo *output)
646+
{
647+
MateRROutput *rr_output;
648+
649+
rr_output = mate_rr_screen_get_output_by_name (screen, mate_rr_output_info_get_name (output));
650+
return mate_rr_output_get_is_primary(rr_output);
651+
}
652+
653+
644654
static gboolean
645655
get_clone_size (MateRRScreen *screen, int *width, int *height)
646656
{
@@ -758,9 +768,7 @@ make_clone_setup (MateRRScreen *screen)
758768
h = mate_rr_mode_get_height (mode);
759769

760770
if (w == width && h == height) {
761-
int r = mate_rr_mode_get_freq (mode);
762-
if (r > best_rate)
763-
best_rate = r;
771+
best_rate = mate_rr_mode_get_freq (mode);
764772
}
765773
}
766774

@@ -851,6 +859,35 @@ turn_on (MateRRScreen *screen,
851859
return FALSE;
852860
}
853861

862+
static MateRRConfig *
863+
make_primary_only_setup (MateRRScreen *screen)
864+
{
865+
/*Leave all of the monitors turned on, just change from mirror to xinerama layout*/
866+
MateRRConfig *result = mate_rr_config_new_current (screen, NULL);
867+
MateRROutputInfo **outputs = mate_rr_config_get_outputs (result);
868+
int i, x, width,height;
869+
x = 0;
870+
871+
for (i = 0; outputs[i] != NULL; ++i) {
872+
MateRROutputInfo *info = outputs[i];
873+
width = mate_rr_output_info_get_preferred_width (info);
874+
height = mate_rr_output_info_get_preferred_height (info);
875+
mate_rr_output_info_set_geometry (info, x, 0, width, height);
876+
mate_rr_output_info_set_active (info, TRUE);
877+
x = x + width;
878+
}
879+
880+
if (result && config_is_all_off (result)) {
881+
g_object_unref (G_OBJECT (result));
882+
result = NULL;
883+
}
884+
885+
mate_rr_config_set_clone (result, FALSE);
886+
print_configuration (result, "Primary only setup");
887+
888+
return result;
889+
}
890+
854891
static MateRRConfig *
855892
make_laptop_setup (MateRRScreen *screen)
856893
{
@@ -2017,6 +2054,41 @@ output_rotation_item_activate_cb (GtkCheckMenuItem *item, gpointer data)
20172054
try_to_apply_intended_configuration (manager, NULL, gtk_get_current_event_time (), NULL); /* NULL-GError */
20182055
}
20192056

2057+
static void
2058+
mirror_outputs_cb(GtkCheckMenuItem *item, gpointer data)
2059+
{
2060+
MsdXrandrManager *manager = MSD_XRANDR_MANAGER (data);
2061+
struct MsdXrandrManagerPrivate *priv = manager->priv;
2062+
MateRRScreen *screen = priv->rw_screen;
2063+
2064+
if (gtk_check_menu_item_get_active(item)){
2065+
2066+
MateRRConfig *config;
2067+
config = make_clone_setup (screen);
2068+
if (!config || config == NULL){
2069+
error_message (manager, _("Mirroring outputs not supported"), NULL, NULL);
2070+
}
2071+
2072+
mate_rr_config_save (config, NULL);
2073+
try_to_apply_intended_configuration (manager, NULL, gtk_get_current_event_time (), NULL);
2074+
2075+
g_object_unref (config);
2076+
2077+
}
2078+
else{
2079+
2080+
MateRRConfig *config;
2081+
config = make_primary_only_setup (screen);
2082+
/*If nothing worked, bring up the display capplet so the user can reconfigure*/
2083+
if (config == NULL)
2084+
run_display_capplet(GTK_WIDGET(item));
2085+
mate_rr_config_save (config, NULL);
2086+
try_to_apply_intended_configuration (manager, NULL, gtk_get_current_event_time (), NULL);
2087+
2088+
g_object_unref (config);
2089+
2090+
}
2091+
}
20202092
static void
20212093
add_items_for_rotations (MsdXrandrManager *manager, MateRROutputInfo *output, MateRRRotation allowed_rotations)
20222094
{
@@ -2175,6 +2247,31 @@ add_menu_items_for_outputs (MsdXrandrManager *manager)
21752247
}
21762248
}
21772249

2250+
static void
2251+
add_menu_items_for_clone (MsdXrandrManager *manager)
2252+
{
2253+
struct MsdXrandrManagerPrivate *priv = manager->priv;
2254+
GtkWidget *item;
2255+
gulong activate_id;
2256+
2257+
item = gtk_check_menu_item_new_with_label("Same output all monitors");
2258+
gtk_widget_set_tooltip_text(item, "Mirror same output to all monitors and turn them on");
2259+
gtk_widget_show_all (item);
2260+
gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), item);
2261+
activate_id = g_signal_connect (item, "activate",
2262+
G_CALLBACK (mirror_outputs_cb), manager);
2263+
/*Block the handler until the GUI is set up no matter what the monitor state*/
2264+
g_signal_handler_block (item, activate_id);
2265+
2266+
if (mate_rr_config_get_clone(priv->configuration)){
2267+
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), TRUE);
2268+
}
2269+
else{
2270+
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), FALSE);
2271+
}
2272+
g_signal_handler_unblock (item, activate_id);
2273+
}
2274+
21782275
static void
21792276
status_icon_popup_menu (MsdXrandrManager *manager, guint button, guint32 timestamp)
21802277
{
@@ -2196,7 +2293,10 @@ status_icon_popup_menu (MsdXrandrManager *manager, guint button, guint32 timesta
21962293
gtk_widget_show (item);
21972294
gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), item);
21982295

2296+
add_menu_items_for_clone (manager);
2297+
21992298
item = gtk_menu_item_new_with_mnemonic (_("_Configure Display Settings…"));
2299+
gtk_widget_set_tooltip_text(item, "Open the display configuration dialog (all settings)");
22002300
g_signal_connect (item, "activate",
22012301
G_CALLBACK (popup_menu_configure_display_cb), manager);
22022302
gtk_widget_show (item);

0 commit comments

Comments
 (0)