Commit b2058f9b authored by Gabriele Musco's avatar Gabriele Musco
Browse files

finalized sway support (still need to avoid manual config reload)

parent 7a7a0566
Pipeline #114909 passed with stage
in 22 seconds
......@@ -23,7 +23,7 @@ from .confManager import ConfManager
from .app_window import HydraPaperAppWindow
from .settings_box import HydraPaperSettingsWindow
from .is_image import is_image
from .monitor_parser import build_monitors_from_gdk
from .monitor_parser import build_monitors_autodetect
from .apply_wallpapers import apply_wallpapers
class HydraPaperApplication(Gtk.Application):
......@@ -101,7 +101,7 @@ class HydraPaperApplication(Gtk.Application):
def apply_random(self, *args):
from random import randint
monitors = build_monitors_from_gdk()
monitors = build_monitors_autodetect()
all_wallpapers = self.confman.wallpapers
wallpapers = []
for i in range(len(monitors)):
......@@ -115,7 +115,7 @@ class HydraPaperApplication(Gtk.Application):
def apply_from_cli(self, wlist_cli):
# check all the passed wallpapers to be correct
monitors = build_monitors_from_gdk()
monitors = build_monitors_autodetect()
if len(wlist_cli) < len(monitors):
print(
_('Error: you passed {0} wallpapers for {1} monitors').format(
......
......@@ -22,7 +22,7 @@ def _apply_wallpapers_worker(monitors, lockscreen=False):
if desktop_environment == 'mate':
set_wallpaper = set_wallpaper_mate
elif desktop_environment == 'sway':
set_wallpaper = set_wallpaper_sway
set_wallpaper_sway(monitors)
# add other DE cases as `elif` here
if len(monitors) == 1:
set_wallpaper(monitors[0].wallpaper, 'zoom', lockscreen)
......
from gettext import gettext as _
from gi.repository import Gdk
from subprocess import run, PIPE
import json
from os import environ as Env
class Monitor:
class Monitor:
def __init__(self, width, height, scaling, offset_x, offset_y, index, name, primary=False):
self.width = int(width)
self.height = int(height)
......@@ -22,6 +25,25 @@ class Monitor:
- Offset: {self.offset_x} x {self.offset_y};
- Wallpaper path: {self.wallpaper};'''
def build_monitors_from_swaymsg():
monitors = []
res = run('swaymsg -rt get_outputs'.split(' '), stdout=PIPE)
outputs = json.loads(res.stdout.decode())
for i, out in enumerate(outputs):
monitors.append(Monitor(
out['rect']['width'],
out['rect']['height'],
out['scale'],
out['rect']['x'],
out['rect']['y'],
i,
out['name'],
out['primary']
))
return monitors
def build_monitors_from_gdk():
monitors = []
try:
......@@ -40,9 +62,22 @@ def build_monitors_from_gdk():
f'Monitor {i} ({monitor.get_model()})',
monitor.is_primary()
))
except Exception as e:
except Exception:
print(_('Error parsing monitors (Gdk)'))
import traceback
traceback.print_exc()
monitors = None
return monitors
def build_monitors_autodetect():
desktop_environment = (
Env.get('XDG_CURRENT_DESKTOP') or
Env.get('XDG_SESSION_DESKTOP') or
Env.get('DESKTOP_SESSION') or
''
).lower()
if desktop_environment == 'sway':
return build_monitors_from_swaymsg()
else:
return build_monitors_from_gdk()
from gi.repository import Gtk, GdkPixbuf
from .confManager import ConfManager
from .monitor_parser import build_monitors_from_gdk
from .monitor_parser import build_monitors_autodetect
from .is_image import is_image
from hashlib import sha256
from os.path import isfile
......@@ -54,7 +54,7 @@ class HydraPaperMonitorsFlowbox(Gtk.FlowBox):
super().__init__(**kwargs)
self.confman = ConfManager()
self.monitors = build_monitors_from_gdk()
self.monitors = build_monitors_autodetect()
self.set_min_children_per_line(1)
self.set_max_children_per_line(len(self.monitors))
......
......@@ -2,8 +2,7 @@ from gi.repository import Gio
from PIL import Image
from PIL.ImageOps import fit
from os import environ as Env
from subprocess import run
import json
import re
TMP_DIR = '/tmp/HydraPaper/'
SWAY_CONF_PATH = f'{Env.get("HOME")}/.config/sway/config'
......@@ -58,6 +57,17 @@ def set_wallpaper_mate(path, wp_mode='spanned', lockscreen=False):
gsettings.set_string(mode_key, wp_mode)
def set_wallpaper_sway(path, wp_mode='spanned', lockscreen=False):
res = run('swaymsg -rt get_outputs'.split(' '))
json.loads(res.stdout.decode())
def set_wallpaper_sway(monitors, lockscreen=False):
if lockscreen:
print('Lock screen wallpaper on sway unsupported')
return
with open(SWAY_CONF_PATH) as fd:
conf = fd.read()
fd.close()
n_conf = re.sub(r'output .* bg .*', '', conf)
n_conf += '\n' + '\n'.join([
f'output {m.name} bg {m.wallpaper} fill' for m in monitors
])
with open(SWAY_CONF_PATH, 'w') as fd:
fd.write(n_conf)
fd.close()
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