apply_wallpapers.py 1.51 KB
Newer Older
Gabriele Musco's avatar
Gabriele Musco committed
1
2
3
4
5
6
from os import environ as Env
from threading import Thread
from gi.repository import Gtk
from .wallpaper_merger import (
    set_wallpaper_gnome,
    set_wallpaper_mate,
7
    set_wallpaper_sway,
Gabriele Musco's avatar
Gabriele Musco committed
8
9
10
11
    multi_setup_pillow
)
from .confManager import ConfManager

12
13

def _apply_wallpapers_worker(monitors, lockscreen=False):
Gabriele Musco's avatar
Gabriele Musco committed
14
    confman = ConfManager()
15
16
17
18
19
20
    desktop_environment = (
        Env.get('XDG_CURRENT_DESKTOP') or
        Env.get('XDG_SESSION_DESKTOP') or
        Env.get('DESKTOP_SESSION') or
        ''
    ).lower()
Gabriele Musco's avatar
Gabriele Musco committed
21
22
23
    set_wallpaper = set_wallpaper_gnome
    if desktop_environment == 'mate':
        set_wallpaper = set_wallpaper_mate
24
    elif desktop_environment == 'sway':
Gabriele Musco's avatar
Gabriele Musco committed
25
        set_wallpaper_sway(monitors, lockscreen)
Gabriele Musco's avatar
Gabriele Musco committed
26
27
    # add other DE cases as `elif` here
    if len(monitors) == 1:
28
        set_wallpaper(monitors[0].wallpaper, 'zoom', lockscreen)
Gabriele Musco's avatar
Gabriele Musco committed
29
        return
Gabriele Musco's avatar
Gabriele Musco committed
30
31
32
    save_path = '{0}/{1}merged_wallpaper.png'.format(
        confman.cache_path,
        'lockscreen_' if lockscreen else ''
Gabriele Musco's avatar
Gabriele Musco committed
33
    )
34
    multi_setup_pillow(monitors, save_path)
35
    set_wallpaper(save_path, lockscreen=lockscreen)
Gabriele Musco's avatar
Gabriele Musco committed
36
37


38
def apply_wallpapers(monitors, widgets_to_freeze=[], lockscreen=False):
Gabriele Musco's avatar
Gabriele Musco committed
39
    t = Thread(
40
41
42
43
        group=None,
        target=_apply_wallpapers_worker,
        name=None,
        args=(monitors, lockscreen)
Gabriele Musco's avatar
Gabriele Musco committed
44
45
46
47
48
49
50
51
52
    )
    for w in widgets_to_freeze:
        w.set_sensitive(False)
    t.start()
    while t.is_alive():
        while Gtk.events_pending():
            Gtk.main_iteration()
    for w in widgets_to_freeze:
        w.set_sensitive(True)