[gnome-tweak-tool/gnome-3-16] Add a way to inhibit systemd's default behavior on lid close
- From: Rui Matos <rtcm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-tweak-tool/gnome-3-16] Add a way to inhibit systemd's default behavior on lid close
- Date: Wed, 15 Apr 2015 17:17:27 +0000 (UTC)
commit 9e12b98a3e04555259e1690bfc38dcc44e0b5575
Author: Rui Matos <tiagomatos gmail com>
Date: Sat Feb 15 17:12:29 2014 +0100
Add a way to inhibit systemd's default behavior on lid close
This adds a small user session daemon in libexec that uses logind's
D-Bus API to inhibit the default behavior on lid close which is
suspending the machine.
A new tweak is added to enable and disable this daemon through an
autostart file so that its lifecycle gets tied to the user session.
https://bugzilla.gnome.org/show_bug.cgi?id=715022
Makefile.am | 10 ++++++++-
configure.ac | 1 +
gnome-tweak-tool | 5 ++-
gnome-tweak-tool-lid-inhibitor.in | 39 +++++++++++++++++++++++++++++++++++
gtweak/defs.py.in | 1 +
gtweak/tweaks/tweak_group_shell.py | 40 +++++++++++++++++++++++++++++++++--
6 files changed, 90 insertions(+), 6 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 82d0ca6..89fa71b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,6 +1,13 @@
bin_SCRIPTS = \
gnome-tweak-tool
+libexec_SCRIPTS = \
+ gnome-tweak-tool-lid-inhibitor
+
+gnome-tweak-tool-lid-inhibitor: gnome-tweak-tool-lid-inhibitor.in Makefile
+ $(AM_V_GEN)sed -e s!\ PYTHON\@! PYTHON@! < $< > $@
+ chmod +x $@
+
#nobase means gtweak dir is preserved in site-packages
appdir = $(pythondir)
nobase_dist_app_PYTHON = \
@@ -10,7 +17,8 @@ nobase_dist_app_PYTHON = \
nobase_app_PYTHON = gtweak/defs.py
EXTRA_DIST = \
- $(bin_SCRIPTS)
+ $(bin_SCRIPTS) \
+ gnome-tweak-tool-lid-inhibitor.in
CLEANFILES = \
$(wildcard $(srcdir)/gtweak/*.pyc) \
diff --git a/configure.ac b/configure.ac
index 731839c..fb70864 100644
--- a/configure.ac
+++ b/configure.ac
@@ -25,6 +25,7 @@ AS_AC_EXPAND(PKGDATADIR, "${datadir}/${PACKAGE}")
AS_AC_EXPAND(GSETTINGSSCHEMADIR, "${gsettingsschemadir}")
AS_AC_EXPAND(TWEAKDIR, "${pythondir}/gtweak/tweaks")
AS_AC_EXPAND(LOCALEDIR, "${localedir}")
+AS_AC_EXPAND(LIBEXECDIR, "${libexecdir}")
AC_CONFIG_FILES([ po/Makefile.in
Makefile
diff --git a/gnome-tweak-tool b/gnome-tweak-tool
index a47fa5c..dc97b39 100755
--- a/gnome-tweak-tool
+++ b/gnome-tweak-tool
@@ -40,10 +40,10 @@ if __name__ == '__main__':
options, args = parser.parse_args()
try:
- from gtweak.defs import GSETTINGS_SCHEMA_DIR, TWEAK_DIR, DATA_DIR, PKG_DATA_DIR, LOCALE_DIR
+ from gtweak.defs import GSETTINGS_SCHEMA_DIR, TWEAK_DIR, DATA_DIR, PKG_DATA_DIR, LOCALE_DIR,
LIBEXEC_DIR
_defs_present = True
except ImportError:
- GSETTINGS_SCHEMA_DIR = TWEAK_DIR = DATA_DIR = PKG_DATA_DIR = LOCALE_DIR = ""
+ GSETTINGS_SCHEMA_DIR = TWEAK_DIR = DATA_DIR = PKG_DATA_DIR = LOCALE_DIR = LIBEXEC_DIR = ""
_defs_present = False
#the supplied prefix always beats the contents of defs
@@ -61,6 +61,7 @@ if __name__ == '__main__':
gtweak.DATA_DIR = DATA_DIR
gtweak.PKG_DATA_DIR = PKG_DATA_DIR
gtweak.LOCALE_DIR = LOCALE_DIR
+ gtweak.LIBEXEC_DIR = LIBEXEC_DIR
gtweak.ENABLE_TEST = options.test
gtweak.ALL_TWEAKS = options.load
gtweak.APP_NAME = "gnome-tweak-tool"
diff --git a/gnome-tweak-tool-lid-inhibitor.in b/gnome-tweak-tool-lid-inhibitor.in
new file mode 100644
index 0000000..7a48f6b
--- /dev/null
+++ b/gnome-tweak-tool-lid-inhibitor.in
@@ -0,0 +1,39 @@
+#! PYTHON@
+
+import gi
+gi.require_version("GLib", "2.0")
+
+from gi.repository import Gio, GLib
+
+def on_activate(app):
+ if app._inhibitor:
+ return
+
+ app.hold()
+
+ bus = Gio.bus_get_sync(Gio.BusType.SYSTEM, None)
+ var, fdlist = bus.call_with_unix_fd_list_sync('org.freedesktop.login1',
+ '/org/freedesktop/login1',
+ 'org.freedesktop.login1.Manager',
+ 'Inhibit',
+ GLib.Variant('(ssss)',
+ ('handle-lid-switch',
+ 'gnome-tweak-tool-lid-inhibitor',
+ 'user preference',
+ 'block')),
+ None, 0, -1, None, None)
+ app._inhibitor = Gio.UnixInputStream(fd=fdlist.steal_fds()[var[0]])
+
+def on_quit_action(action, param, app):
+ app.quit()
+
+if __name__ == '__main__':
+ app = Gio.Application(application_id='org.gnome.tweak-tool.lid-inhibitor', flags=0)
+ app.connect('activate', on_activate)
+ app._inhibitor = None
+
+ action = Gio.SimpleAction(name='quit')
+ app.add_action(action)
+ action.connect('activate', on_quit_action, app)
+
+ app.run([])
diff --git a/gtweak/defs.py.in b/gtweak/defs.py.in
index 12180db..6c8fdf8 100644
--- a/gtweak/defs.py.in
+++ b/gtweak/defs.py.in
@@ -4,3 +4,4 @@ GSETTINGS_SCHEMA_DIR = "@GSETTINGSSCHEMADIR@"
TWEAK_DIR = "@TWEAKDIR@"
VERSION = "@VERSION@"
LOCALE_DIR = "@LOCALEDIR@"
+LIBEXEC_DIR = "@LIBEXECDIR@"
diff --git a/gtweak/tweaks/tweak_group_shell.py b/gtweak/tweaks/tweak_group_shell.py
index 9f3674a..b8dd497 100644
--- a/gtweak/tweaks/tweak_group_shell.py
+++ b/gtweak/tweaks/tweak_group_shell.py
@@ -15,13 +15,14 @@
# You should have received a copy of the GNU General Public License
# along with gnome-tweak-tool. If not, see <http://www.gnu.org/licenses/>.
-from gi.repository import Gtk, Gio
+from gi.repository import Gtk, Gio, GLib
+import gtweak
from gtweak.gsettings import GSettingsSetting, GSettingsMissingError, GSettingsFakeSetting
from gtweak.gshellwrapper import GnomeShellFactory
from gtweak.tweakmodel import TWEAK_GROUP_TOPBAR, TWEAK_GROUP_WORKSPACES, TWEAK_GROUP_POWER
from gtweak.widgets import ListBoxTweakGroup, GSettingsComboEnumTweak, GSettingsSwitchTweak,
GSettingsCheckTweak, GetterSetterSwitchTweak, adjust_schema_for_overrides, build_label_beside_widget,
build_horizontal_sizegroup, UI_BOX_SPACING, Title, _GSettingsTweak, build_combo_box_text,
GSettingsSpinButtonTweak
-from gtweak.utils import XSettingsOverrides
+from gtweak.utils import XSettingsOverrides, AutostartFile
_shell = GnomeShellFactory().get_shell()
_shell_loaded = _shell is not None
@@ -60,7 +61,39 @@ class StaticWorkspaceTweak(Gtk.Box, _GSettingsTweak):
value = combo.get_model().get_value(_iter, 0)
val = self.STATUS[value]
self.settings[self.key_name] = val
-
+
+class IgnoreLidSwitchTweak(GetterSetterSwitchTweak):
+ def __init__(self, **options):
+ self._inhibitor_name = "gnome-tweak-tool-lid-inhibitor"
+ self._inhibitor_path = "%s/%s" % (gtweak.LIBEXEC_DIR, self._inhibitor_name)
+
+ self._dfile = AutostartFile(None,
+ autostart_desktop_filename = "ignore-lid-switch-tweak.desktop",
+ exec_cmd = self._inhibitor_path)
+
+ GetterSetterSwitchTweak.__init__(self, _("Don't suspend on lid close"), **options)
+
+ def get_active(self):
+ return self._sync_inhibitor()
+
+ def set_active(self, v):
+ self._dfile.update_start_at_login(v)
+ self._sync_inhibitor()
+
+ def _sync_inhibitor(self):
+ if (self._dfile.is_start_at_login_enabled()):
+ GLib.spawn_command_line_async(self._inhibitor_path)
+ return True
+ else:
+ bus = Gio.bus_get_sync(Gio.BusType.SESSION, None)
+ bus.call('org.gnome.tweak-tool.lid-inhibitor',
+ '/org/gnome/tweak_tool/lid_inhibitor',
+ 'org.gtk.Actions',
+ 'Activate',
+ GLib.Variant('(sava{sv})', ('quit', [], {})),
+ None, 0, -1, None)
+ return False
+
sg = build_horizontal_sizegroup()
sw = StaticWorkspaceTweak(size_group=sg, loaded=_shell_loaded)
depends_how = lambda x,kn: not(x.get_boolean(kn))
@@ -80,6 +113,7 @@ TWEAK_GROUPS = [
GSettingsComboEnumTweak(_("On Battery Power"),"org.gnome.settings-daemon.plugins.power",
"lid-close-battery-action", size_group=sg),
GSettingsComboEnumTweak(_("When plugged in"),"org.gnome.settings-daemon.plugins.power",
"lid-close-ac-action", size_group=sg),
GSettingsSwitchTweak(_("Suspend even if an external monitor is plugged
in"),"org.gnome.settings-daemon.plugins.power", "lid-close-suspend-with-external-monitor", size_group=sg),
+ IgnoreLidSwitchTweak(),
),
ListBoxTweakGroup(TWEAK_GROUP_WORKSPACES,
sw,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]