Commit 7a7a0566 authored by Gabriele Musco's avatar Gabriele Musco
Browse files

initial work towards sway support

parent 4672fea1
Pipeline #114795 passed with stage
in 28 seconds
from gettext import gettext as _
from os import environ as Env
from os.path import isfile
from threading import Thread
from gi.repository import Gtk
from .wallpaper_merger import (
set_wallpaper_gnome,
set_wallpaper_mate,
set_wallpaper_sway,
multi_setup_pillow
)
from .confManager import ConfManager
def _apply_wallpapers_worker(monitors, lockscreen = False):
def _apply_wallpapers_worker(monitors, lockscreen=False):
confman = ConfManager()
desktop_environment = Env.get('XDG_CURRENT_DESKTOP').lower()
desktop_environment = (
Env.get('XDG_CURRENT_DESKTOP') or
Env.get('XDG_SESSION_DESKTOP') or
Env.get('DESKTOP_SESSION') or
''
).lower()
set_wallpaper = set_wallpaper_gnome
if desktop_environment == 'mate':
set_wallpaper = set_wallpaper_mate
elif desktop_environment == 'sway':
set_wallpaper = set_wallpaper_sway
# add other DE cases as `elif` here
if len(monitors) == 1:
set_wallpaper(monitors[0].wallpaper, 'zoom', lockscreen)
return
wp_unique_str = '_'.join([m.__repr__() for m in monitors])
save_path = '{0}/{1}merged_wallpaper.png'.format(
confman.cache_path,
'lockscreen_' if lockscreen else ''
)
multi_setup_pillow(monitors, save_path)
set_wallpaper(save_path, lockscreen = lockscreen)
set_wallpaper(save_path, lockscreen=lockscreen)
def apply_wallpapers(monitors, widgets_to_freeze = [], lockscreen = False):
def apply_wallpapers(monitors, widgets_to_freeze=[], lockscreen=False):
t = Thread(
group = None,
target = _apply_wallpapers_worker,
name = None,
args = (monitors, lockscreen)
group=None,
target=_apply_wallpapers_worker,
name=None,
args=(monitors, lockscreen)
)
for w in widgets_to_freeze:
w.set_sensitive(False)
......
from gi.repository import Gio
from PIL import Image
from PIL.ImageOps import fit
from .confManager import ConfManager
from os import environ as Env
from subprocess import run
import json
TMP_DIR = '/tmp/HydraPaper/'
SWAY_CONF_PATH = f'{Env.get("HOME")}/.config/sway/config'
TMP_DIR='/tmp/HydraPaper/'
def multi_setup_pillow(monitors, save_path, wp_setter_func=None):
images = list(map(Image.open, [m.wallpaper for m in monitors]))
resolutions = [(m.width * m.scaling, m.height * m.scaling) for m in monitors]
resolutions = [
(m.width * m.scaling, m.height * m.scaling) for m in monitors
]
offsets = [(m.offset_x, m.offset_y) for m in monitors]
# DEBUG
# for m in monitors:
# print(m)
final_image_width = max([m.offset_x + m.width * m.scaling for m in monitors])
final_image_height = max([m.offset_y + m.height * m.scaling for m in monitors])
# DEBUG
# print('Final Size: {} x {}'.format(final_image_width, final_image_height))
final_image_width = max([
m.offset_x + m.width * m.scaling for m in monitors
])
final_image_height = max([
m.offset_y + m.height * m.scaling for m in monitors
])
n_images = []
for i, r in zip(images, resolutions):
......@@ -28,7 +35,8 @@ def multi_setup_pillow(monitors, save_path, wp_setter_func=None):
final_image.paste(i, o)
final_image.save(save_path)
def set_wallpaper_gnome(path, wp_mode = 'spanned', lockscreen = False):
def set_wallpaper_gnome(path, wp_mode='spanned', lockscreen=False):
gsettings_path = 'org.gnome.desktop.background'
if lockscreen:
gsettings_path = 'org.gnome.desktop.screensaver'
......@@ -38,7 +46,8 @@ def set_wallpaper_gnome(path, wp_mode = 'spanned', lockscreen = False):
gsettings.set_string(wp_key, 'file://{}'.format(path))
gsettings.set_string(mode_key, wp_mode)
def set_wallpaper_mate(path, wp_mode = 'spanned', lockscreen = False):
def set_wallpaper_mate(path, wp_mode='spanned', lockscreen=False):
if lockscreen:
print('Lock screen wallpaper on MATE unsupported')
return
......@@ -47,3 +56,8 @@ def set_wallpaper_mate(path, wp_mode = 'spanned', lockscreen = False):
mode_key = 'picture-options'
gsettings.set_string(wp_key, path)
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())
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