Commit 6e17bc78 authored by Federico Mena Quintero's avatar Federico Mena Quintero
Browse files

Merge branch 'docking-stations' - bgo#663126

This lets docking stations work better in the light of plugging external monitors.

It used to be that a docked laptop, with a closed lid, would still keep the
LCD active, thus making it pretty useless with an external monitor.

Now, we disable the LCD if the laptop's lid is closed, as expected.
Additionally, to decide when to suspend the laptop, we do so if there
are no plugged or usable RANDR outputs.  For example, a docked laptop
with a closed lid and *no* external monitor has no usable outputs, so
it will get suspended.

This requires gnome-desktop 3.3.4 or later, as the semantics of
gnome_rr_screen_new() are slightly different there - now it returns a
singleton instead of a new object every time.
parents 7675bffd 7e238f2d
......@@ -48,7 +48,7 @@ GLIB_REQUIRED_VERSION=2.29.14
GTK_REQUIRED_VERSION=3.3.4
GCONF_REQUIRED_VERSION=2.6.1
GIO_REQUIRED_VERSION=2.26.0
GNOME_DESKTOP_REQUIRED_VERSION=3.3.1
GNOME_DESKTOP_REQUIRED_VERSION=3.3.4
LIBNOTIFY_REQUIRED_VERSION=0.7.3
UPOWER_GLIB_REQUIRED_VERSION=0.9.1
PA_REQUIRED_VERSION=0.9.16
......
......@@ -9,6 +9,7 @@ INCLUDES = \
$(DISABLE_DEPRECATED_CFLAGS) \
$(SETTINGS_DAEMON_CFLAGS) \
$(LIBNOTIFY_CFLAGS) \
$(UPOWER_CFLAGS) \
$(GNOME_DESKTOP_CFLAGS) \
$(NULL)
......@@ -75,6 +76,7 @@ gnome_settings_daemon_LDADD = \
libgsd-profile.la \
$(SETTINGS_DAEMON_LIBS) \
$(LIBNOTIFY_LIBS) \
$(UPOWER_LIBS) \
$(GNOME_DESKTOP_LIBS) \
$(NULL)
......
......@@ -307,18 +307,3 @@ gnome_settings_session_new (void)
session = g_object_new (GNOME_TYPE_SETTINGS_SESSION, NULL);
return GNOME_SETTINGS_SESSION (session);
}
GnomeRRScreen *
gnome_settings_session_get_screen (GError **error)
{
static GnomeRRScreen *screen = NULL;
if (screen != NULL)
return g_object_ref (screen);
screen = gnome_rr_screen_new (gdk_screen_get_default (), error);
if (screen != NULL)
g_object_add_weak_pointer (G_OBJECT (screen), (gpointer *) &screen);
return screen;
}
......@@ -24,9 +24,6 @@
#include <glib-object.h>
#define GNOME_DESKTOP_USE_UNSTABLE_API
#include <libgnome-desktop/gnome-rr.h>
G_BEGIN_DECLS
#define GNOME_TYPE_SETTINGS_SESSION (gnome_settings_session_get_type ())
......@@ -61,7 +58,6 @@ GType gnome_settings_session_state_get_type (void);
GnomeSettingsSession *gnome_settings_session_new (void);
GnomeSettingsSessionState gnome_settings_session_get_state (GnomeSettingsSession *session);
GnomeRRScreen *gnome_settings_session_get_screen (GError **error);
G_END_DECLS
......
......@@ -1590,7 +1590,7 @@ gsd_color_manager_start (GsdColorManager *manager,
gnome_settings_profile_start (NULL);
/* coldplug the list of screens */
priv->x11_screen = gnome_settings_session_get_screen (error);
priv->x11_screen = gnome_rr_screen_new (gdk_screen_get_default (), error);
if (priv->x11_screen == NULL)
goto out;
......
......@@ -32,7 +32,7 @@
#include <canberra-gtk.h>
#define GNOME_DESKTOP_USE_UNSTABLE_API
#include <libgnome-desktop/gnome-rr.h>
#include <libgnome-desktop/gnome-rr-config.h>
#include "gpm-common.h"
#include "gpm-phone.h"
......@@ -2163,6 +2163,46 @@ do_lid_open_action (GsdPowerManager *manager)
}
static gboolean
is_laptop (GnomeRRScreen *screen, GnomeRROutputInfo *output)
{
GnomeRROutput *rr_output;
rr_output = gnome_rr_screen_get_output_by_name (screen, gnome_rr_output_info_get_name (output));
return gnome_rr_output_is_laptop (rr_output);
}
static gboolean
non_laptop_outputs_are_all_off (GnomeRRScreen *screen)
{
GnomeRRConfig *config;
GnomeRROutputInfo **outputs;
int i;
gboolean all_off;
config = gnome_rr_config_new_current (screen, NULL); /* NULL-GError */
if (!config)
return FALSE;
outputs = gnome_rr_config_get_outputs (config);
for (i = 0; outputs[i] != NULL; i++) {
if (is_laptop (screen, outputs[i]))
continue;
if (gnome_rr_output_info_is_active (outputs[i])) {
all_off = FALSE;
goto out;
}
}
all_off = TRUE;
out:
g_object_unref (config);
return all_off;
}
static void
do_lid_closed_action (GsdPowerManager *manager)
{
......@@ -2196,12 +2236,6 @@ do_lid_closed_action (GsdPowerManager *manager)
}
}
/* are we docked? */
if (up_client_get_is_docked (manager->priv->up_client)) {
g_debug ("ignoring lid closed action because we are docked");
return;
}
/* ensure we turn the panel back on after resume */
ret = gnome_rr_screen_set_dpms_mode (manager->priv->x11_screen,
GNOME_RR_DPMS_OFF,
......@@ -2224,7 +2258,11 @@ do_lid_closed_action (GsdPowerManager *manager)
}
/* perform policy action */
do_power_action_type (manager, action_type);
if (non_laptop_outputs_are_all_off (manager->priv->x11_screen)) {
g_debug ("lid is closed; suspending or hibernating");
do_power_action_type (manager, action_type);
} else
g_debug ("lid is closed; not suspending nor hibernating since some external monitor outputs are still active");
}
......@@ -3487,8 +3525,8 @@ gsd_power_manager_start (GsdPowerManager *manager,
G_CALLBACK (engine_device_removed_cb), manager);
g_signal_connect (manager->priv->up_client, "device-changed",
G_CALLBACK (engine_device_changed_cb), manager);
g_signal_connect (manager->priv->up_client, "changed",
G_CALLBACK (up_client_changed_cb), manager);
g_signal_connect_after (manager->priv->up_client, "changed",
G_CALLBACK (up_client_changed_cb), manager);
/* use the fallback name from gnome-power-manager so the shell
* blocks this, and uses the power extension instead */
......@@ -3601,7 +3639,7 @@ gsd_power_manager_start (GsdPowerManager *manager,
G_CALLBACK (idle_idletime_alarm_expired_cb), manager);
/* coldplug the list of screens */
manager->priv->x11_screen = gnome_settings_session_get_screen (error);
manager->priv->x11_screen = gnome_rr_screen_new (gdk_screen_get_default (), error);
if (manager->priv->x11_screen == NULL)
return FALSE;
......@@ -3644,40 +3682,71 @@ gsd_power_manager_stop (GsdPowerManager *manager)
manager->priv->connection = NULL;
}
if (manager->priv->timeout_blank_id != 0)
if (manager->priv->timeout_blank_id != 0) {
g_source_remove (manager->priv->timeout_blank_id);
if (manager->priv->timeout_sleep_id != 0)
manager->priv->timeout_blank_id = 0;
}
if (manager->priv->timeout_sleep_id != 0) {
g_source_remove (manager->priv->timeout_sleep_id);
manager->priv->timeout_sleep_id = 0;
}
g_object_unref (manager->priv->session);
g_object_unref (manager->priv->settings);
g_object_unref (manager->priv->settings_screensaver);
g_object_unref (manager->priv->up_client);
if (manager->priv->x11_screen != NULL)
manager->priv->session = NULL;
manager->priv->settings = NULL;
manager->priv->settings_screensaver = NULL;
manager->priv->up_client = NULL;
if (manager->priv->x11_screen != NULL) {
g_object_unref (manager->priv->x11_screen);
manager->priv->x11_screen = NULL;
}
g_ptr_array_unref (manager->priv->devices_array);
g_object_unref (manager->priv->phone);
g_object_unref (manager->priv->device_composite);
manager->priv->devices_array = NULL;
manager->priv->phone = NULL;
manager->priv->device_composite = NULL;
if (manager->priv->previous_icon != NULL)
if (manager->priv->previous_icon != NULL) {
g_object_unref (manager->priv->previous_icon);
manager->priv->previous_icon = NULL;
}
g_free (manager->priv->previous_summary);
manager->priv->previous_summary = NULL;
if (manager->priv->upower_proxy != NULL)
if (manager->priv->upower_proxy != NULL) {
g_object_unref (manager->priv->upower_proxy);
if (manager->priv->session_proxy != NULL)
manager->priv->upower_proxy = NULL;
}
if (manager->priv->session_proxy != NULL) {
g_object_unref (manager->priv->session_proxy);
if (manager->priv->session_presence_proxy != NULL)
manager->priv->session_proxy = NULL;
}
if (manager->priv->session_presence_proxy != NULL) {
g_object_unref (manager->priv->session_presence_proxy);
manager->priv->session_presence_proxy = NULL;
}
if (manager->priv->critical_alert_timeout_id > 0)
if (manager->priv->critical_alert_timeout_id > 0) {
g_source_remove (manager->priv->critical_alert_timeout_id);
manager->priv->critical_alert_timeout_id = 0;
}
gpm_idletime_alarm_remove (manager->priv->idletime,
GSD_POWER_IDLETIME_ID);
g_object_unref (manager->priv->idletime);
g_object_unref (manager->priv->status_icon);
manager->priv->idletime = NULL;
manager->priv->status_icon = NULL;
}
static void
......
......@@ -49,6 +49,7 @@ libxrandr_la_CPPFLAGS = \
libxrandr_la_CFLAGS = \
$(PLUGIN_CFLAGS) \
$(UPOWER_CFLAGS) \
$(SETTINGS_PLUGIN_CFLAGS) \
$(GNOME_DESKTOP_CFLAGS) \
$(AM_CFLAGS)
......@@ -58,6 +59,7 @@ libxrandr_la_LDFLAGS = \
libxrandr_la_LIBADD = \
$(top_builddir)/plugins/common/libcommon.la \
$(UPOWER_LIBS) \
$(SETTINGS_PLUGIN_LIBS) \
$(GNOME_DESKTOP_LIBS)
......
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment