Browse Source

screensaver and touchpad settings

master
parent
commit
a2e183eb2c
8 changed files with 221 additions and 3 deletions
  1. +6
    -0
      defaults/main.yaml
  2. +142
    -0
      files/mate-screensaver-helper-inhibition.py
  3. +2
    -3
      tasks/dconf-lock.yaml
  4. +7
    -0
      tasks/main.yaml
  5. +44
    -0
      tasks/screensaver.yaml
  6. +2
    -0
      templates/gdmflexiserver-fake.sh
  7. +7
    -0
      templates/touchpad.conf.j2
  8. +11
    -0
      vars/main.yaml

+ 6
- 0
defaults/main.yaml View File

@@ -0,0 +1,6 @@
---

screensaver_enforce_settings: false
screensaver_locktime: 10
screensaver_theme: screensavers-popsquares
screensaver_sleeptime: "{{screensaver_locktime}}"

+ 142
- 0
files/mate-screensaver-helper-inhibition.py View File

@@ -0,0 +1,142 @@
#!/usr/bin/python3
import os
import sys
import time

import dbus
import dbus.service
import dbus.mainloop.glib
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
from gi.repository import GObject as gobject

# DBus connection information for MATE screensaver
DBUS_MSCR_WAIT = 60
DBUS_MSCR_DBUS = dbus.SessionBus()
DBUS_MSCR_NAME = "org.mate.ScreenSaver"
DBUS_MSCR_PATH = "/"
DBUS_MSCR_IFACE_MAIN = "org.mate.ScreenSaver"

# DBus listening information for the Idle Inhibition Spec
DBUS_IIS_DBUS = dbus.SessionBus()
DBUS_IIS_NAME = "org.freedesktop.ScreenSaver"
DBUS_IIS_PATH = "/org/freedesktop/ScreenSaver"
DBUS_IIS_PATH2= "/ScreenSaver"
DBUS_IIS_IFACE_MAIN = "org.freedesktop.ScreenSaver"

# Connect to the system and session bus
bus_system = dbus.SystemBus()
bus_session = dbus.SessionBus()

# Connect to MATE screensaver
print("Waiting for screensaver...")
for i in range(DBUS_MSCR_WAIT):
try:
mate_screensaver = dbus.Interface(
bus_session.get_object(DBUS_MSCR_NAME, DBUS_MSCR_PATH),
DBUS_MSCR_IFACE_MAIN
)
except dbus.exceptions.DBusException:
# Screensaver not running yet
if i < (DBUS_MSCR_WAIT - 1):
time.sleep(1)
else:
print("MATE screensaver not running, aborting!", file=sys.stderr)
sys.exit(2)
else:
print("MATE screensaver connected!")
break


class IdleInhibitor(object):
"""
Represents a single client that inhibits the screensaver
"""
def __init__(self, screensaver, name, reason, cookie, unique_name):
self.screensaver = screensaver

self.name = name
self.reason = reason
self.cookie = cookie
self.unique_name = unique_name

# Tell MATE screensaver about the application we are proxying
self._cookie = self.screensaver.Inhibit(name, reason)

def destroy(self):
# Stop bothering MATE screensaver
self.screensaver.UnInhibit(self._cookie)


# Create DBus interface
class IdleInhibitionService(dbus.service.Object):
def __init__(self, mate_screensaver):
# Store connection to screensaver
self.screensaver = mate_screensaver

# Counter for inhibition requests (used for cookies)
self.counter = 1

# Storage for clients
self.inhibitors = []

# Store constants
self.bus = DBUS_IIS_DBUS
self.path = DBUS_IIS_PATH
self.path2 = DBUS_IIS_PATH2

# Claim bus name with both paths used by GNOME
dbus.service.Object.__init__(self,
self.bus, self.path, dbus.service.BusName(DBUS_IIS_NAME, self.bus)
)
dbus.service.Object.__init__(self,
self.bus, self.path2, dbus.service.BusName(DBUS_IIS_NAME, self.bus)
)

def on_name_change(self, sender, unique_name):
print("mate-screensaver-helper-inhibition: on_name_change: '%s', '%s'" % (sender, unique_name))

if sender != unique_name:
for inhibitor in self.inhibitors:
if inhibitor.unique_name == sender:
self.UnInhibit(inhibitor.cookie, sender)

@dbus.service.method(DBUS_IIS_IFACE_MAIN, "ss", "u", sender_keyword="sender")
def Inhibit(self, application_name, reason_for_inhibit, sender):
print("mate-screensaver-helper-inhibition: Inhibit: '%s', '%s' -> %d (from '%s')"
% (application_name, reason_for_inhibit, self.counter + 1, sender))

# Create new cookie
self.counter += 1

# Add inhibitor
self.inhibitors.append(IdleInhibitor(
self.screensaver,
application_name,
reason_for_inhibit,
self.counter,
sender
))

# Watch if bus name owner disappears
self.bus.watch_name_owner(sender, lambda name: self.on_name_change(sender, name))

return self.counter

@dbus.service.method(DBUS_IIS_IFACE_MAIN, "u", "", sender_keyword="sender")
def UnInhibit(self, cookie, sender):
print("mate-screensaver-helper-inhibition: UnInhibit: %d (from '%s')" % (cookie, sender))

for inhibitor in self.inhibitors:
if inhibitor.cookie == cookie and inhibitor.unique_name == sender:
# Stop inhibiting
inhibitor.destroy()

# Remove inhibitor from list
self.inhibitors.remove(inhibitor)


# Create service
service = IdleInhibitionService(mate_screensaver)

# Wait for stuff to happen
gobject.MainLoop().run()

+ 2
- 3
tasks/dconf-lock.yaml View File

@@ -16,7 +16,6 @@
dest: /etc/dconf/profile/user
notify: dconf update


- name: dconf local db directory
file:
path: /etc/dconf/db/local.d/
@@ -24,7 +23,7 @@

- name: dconf settings
template:
src: settings.j2
src: dconf-lock/settings.j2
dest: /etc/dconf/db/local.d/{{dconf_lock_id}}
notify: dconf update

@@ -35,6 +34,6 @@

- name: dconf locks
template:
src: locks.j2
src: dconf-lock/locks.j2
dest: /etc/dconf/db/local.d/locks/{{dconf_lock_id}}
notify: dconf update

+ 7
- 0
tasks/main.yaml View File

@@ -11,3 +11,10 @@
apt:
pkg: dunst
state: absent

- name: xorg touchpad config
template:
src: touchpad.conf.j2
dest: /etc/X11/xorg.conf.d/30-touchpad.conf

- import_tasks: screensaver.yaml

+ 44
- 0
tasks/screensaver.yaml View File

@@ -0,0 +1,44 @@
---

- name: ensure old screensavers are absent
apt:
pkg:
- light-locker
- xscreensaver
state: absent

- name: gdmflexiserver dummy script
copy:
src: gdmflexiserver-fake.sh
dest: /usr/local/bin/gdmflexiserver
mode: 0755

# Bug: https://github.com/mate-desktop/mate-screensaver/issues/57
# https://gist.github.com/alexander255/9b991816418e4e60ee7c
- name: mate-screensaver-helper-inhibition script
copy:
src: mate-screensaver-helper-inhibition.py
dest: /usr/local/bin/mate-screensaver-helper-inhibition
mode: 0755

- import_tasks: dconf-lock.yaml
vars:
dconf_lock_id: screensaver
dconf_lock_settings:
/org/mate/screensaver:
idle-activation-enabled: 'true'
lock-enabled: 'true'
mode: "'single'"
themes: "['{{screensaver_theme}}']"
/org/mate/desktop/session:
idle-delay: "{{ screensaver_locktime | int }}"
/org/mate/power-manager:
sleep-display-ac: "{{ screensaver_sleeptime | int * 60 }}"
dconf_lock_paths:
- /org/mate/desktop/session/idle-delay
- /org/mate/screensaver/idle-activation-enabled
- /org/mate/screensaver/lock-enabled
- /org/mate/screensaver/mode
- /org/mate/screensaver/themes
- /org/mate/power-manager/sleep-display-ac
when: "{{screensaver_enforce_settings}}"

+ 2
- 0
templates/gdmflexiserver-fake.sh View File

@@ -0,0 +1,2 @@
#!/bin/sh
/usr/bin/dm-tool switch-to-greeter

+ 7
- 0
templates/touchpad.conf.j2 View File

@@ -0,0 +1,7 @@
Section "InputClass"
Identifier "touchpad"
Driver "libinput"
MatchIsTouchpad "on"
Option "Tapping" "on"
Option "TappingButtonMap" "lrm"
EndSection

+ 11
- 0
vars/main.yaml View File

@@ -122,6 +122,17 @@ desktop_packages:
- chromium-l10n
- webext-ublock-origin

# lockscreen
- mate-screensaver
- xscreensaver-gl
- python3
- mate-power-manager
- xautolock
- xss-lock
- xbacklight
- i3lock
- xssproxy

# xfce
- xfce4