monitor-config-manager: Handle laptop lid being closed

Handle configuring when the laptop lid is closed. This is so far
handled by creating a linear configuration while ignoring the laptop
panel. Changing the current configuration will come later.

https://bugzilla.gnome.org/show_bug.cgi?id=777732
This commit is contained in:
Jonas Ådahl 2017-01-10 13:17:16 +08:00
parent cde1a730e8
commit f19cb6a610
2 changed files with 55 additions and 11 deletions

View File

@ -291,8 +291,15 @@ meta_monitor_config_manager_assign (MetaMonitorManager *manager,
return TRUE; return TRUE;
} }
typedef enum _MonitorMatchRule
{
MONITOR_MATCH_ALL = 0,
MONITOR_MATCH_EXTERNAL = (1 << 0)
} MonitorMatchRule;
static MetaMonitor * static MetaMonitor *
find_monitor_with_highest_preferred_resolution (MetaMonitorManager *monitor_manager) find_monitor_with_highest_preferred_resolution (MetaMonitorManager *monitor_manager,
MonitorMatchRule match_rule)
{ {
GList *monitors; GList *monitors;
GList *l; GList *l;
@ -307,6 +314,12 @@ find_monitor_with_highest_preferred_resolution (MetaMonitorManager *monitor_mana
int width, height; int width, height;
int area; int area;
if (match_rule & MONITOR_MATCH_EXTERNAL)
{
if (meta_monitor_is_laptop_panel (monitor))
continue;
}
mode = meta_monitor_get_preferred_mode (monitor); mode = meta_monitor_get_preferred_mode (monitor);
meta_monitor_mode_get_resolution (mode, &width, &height); meta_monitor_mode_get_resolution (mode, &width, &height);
area = width * height; area = width * height;
@ -322,24 +335,48 @@ find_monitor_with_highest_preferred_resolution (MetaMonitorManager *monitor_mana
} }
/* /*
* Tries to find the primary monitor as reported by the underlying system; * Try to find the primary monitor. The priority of classification is:
* or failing that, a monitor looks to be the laptop panel; or failing that, the *
* monitor with the highest preferred resolution. * 1. Find the primary monitor as reported by the underlying system,
* 2. Find the laptop panel
* 3. Find the external monitor with highest resolution
*
* If the laptop lid is closed, exclude the laptop panel from possible
* alternatives, except if no other alternatives exist.
*/ */
static MetaMonitor * static MetaMonitor *
find_primary_monitor (MetaMonitorManager *monitor_manager) find_primary_monitor (MetaMonitorManager *monitor_manager)
{ {
MetaMonitor *monitor; MetaMonitor *monitor;
monitor = meta_monitor_manager_get_primary_monitor (monitor_manager); if (meta_monitor_manager_is_lid_closed (monitor_manager))
if (monitor) {
return monitor; monitor = meta_monitor_manager_get_primary_monitor (monitor_manager);
if (monitor && !meta_monitor_is_laptop_panel (monitor))
return monitor;
monitor = meta_monitor_manager_get_laptop_panel (monitor_manager); monitor =
if (monitor) find_monitor_with_highest_preferred_resolution (monitor_manager,
return monitor; MONITOR_MATCH_EXTERNAL);
if (monitor)
return monitor;
return find_monitor_with_highest_preferred_resolution (monitor_manager); return find_monitor_with_highest_preferred_resolution (monitor_manager,
MONITOR_MATCH_ALL);
}
else
{
monitor = meta_monitor_manager_get_primary_monitor (monitor_manager);
if (monitor)
return monitor;
monitor = meta_monitor_manager_get_laptop_panel (monitor_manager);
if (monitor)
return monitor;
return find_monitor_with_highest_preferred_resolution (monitor_manager,
MONITOR_MATCH_ALL);
}
} }
static MetaMonitorConfig * static MetaMonitorConfig *
@ -421,6 +458,10 @@ meta_monitor_config_manager_create_linear (MetaMonitorConfigManager *config_mana
if (monitor == primary_monitor) if (monitor == primary_monitor)
continue; continue;
if (meta_monitor_is_laptop_panel (monitor) &&
meta_monitor_manager_is_lid_closed (monitor_manager))
continue;
logical_monitor_config = logical_monitor_config =
create_preferred_logical_monitor_config (monitor, x, 0); create_preferred_logical_monitor_config (monitor, x, 0);
config->logical_monitor_configs = config->logical_monitor_configs =

View File

@ -284,6 +284,9 @@ power_save_mode_changed (MetaMonitorManager *manager,
void void
meta_monitor_manager_lid_is_closed_changed (MetaMonitorManager *manager) meta_monitor_manager_lid_is_closed_changed (MetaMonitorManager *manager)
{ {
if (manager->config_manager)
meta_monitor_manager_ensure_configured (manager);
g_signal_emit (manager, signals[LID_IS_CLOSED_CHANGED], 0); g_signal_emit (manager, signals[LID_IS_CLOSED_CHANGED], 0);
} }