-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_wm
executable file
·104 lines (95 loc) · 3.58 KB
/
get_wm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env python3
# Author: Zac the Wise
# License: GPL-v3.0
# CLI utility that returns to the command line
# the name of the window manager that is being used
# Lists of window managers and related info was obtained from neofetch
# https://github.com/dylanaraps/neofetch/blob/ccd5d9f52609bbdcd5d8fa78c4fdb0f12954125f/neofetch#L1892
from platform import system
import psutil
from sys import argv
def get_wm(use_env=False):
"""Returns the WM or an error"""
if use_env: # look for a WM env variable
from os import environ
env_list = ["WM", "wm", "WINDOW_MANAGER", "window_manager"]
# look for any env variables with the above names
for env_var_name in env_list:
try:
wm = environ[env_var_name]
except KeyError: # if the variable isn't found
pass
else:
return wm.lower()
else:
return "error, no env variable with name wm, WM, WINDOW_MANAGER or window_manager found"
else:
os = system()
if os == "Darwin": # refers to mac os
# add the wms from these links
# https://github.com/jaywcjlove/awesome-mac#window-management
# https://github.com/iCHAIT/awesome-macOS#window-management
wms = [
"amethyst", "spectacle",
"kwm", "chunkwm",
"yabai", "rectangle"
]
wm = get_processes(wms)
if wm in wms:
return wm
return "quartz compositor" # default mac wm
elif os == "Windows":
wms = ["explorer"]
elif os == "Linux":
wms = [
"arcan", "asc",
"clayland", "dwc",
"fireplace", "gnome-shell",
"greenfield", "grefsen",
"hikari", "kwin",
"lipstick", "maynard",
"mazecompositor", "motorcar",
"orbital", "orbment",
"perceptia", "river",
"rustland", "sway",
"ulubis", "velox",
"wavy", "wavy-cooler",
"wayfire", "wayhouse",
"westeros", "westford",
"weston", "sowm",
"catwm", "fvwm",
"dwm", "2bwm",
"monsterwm", "tinywm",
"x11fs", "xmonad",
"e16", "sawfish",
"cinnamon", "muffin",
"compiz", "mutter", "gala",
"metacity"
"e17", "enlightenment",
"fluxbox", "icewm",
"openbox", "pekwm",
"kwin", "blackbox", "bblean"
]
wm = get_processes(wms)
if wm in wms:
return wm
return "wm not found please submit an issue"
def get_processes(known_managers):
"""Loops through computer's processes until an item from the
provided knowm_managers list is detected and return with it's name"""
# https://thispointer.com/python-check-if-a-process-is-running-by-name-and-find-its-process-id-pid/
for process in psutil.process_iter():
try:
if process.name().lower() in known_managers:
return process.name().lower()
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
# error occured with the process and we can ignore it
pass
if __name__ == "__main__":
try:
second_arg = argv[1]
except IndexError:
print(get_wm(use_env=False))
else:
if second_arg in ("--use-env", "--env"):
print(get_wm(use_env=True))