Add dot_config/qtile/.keep

Add dot_config/qtile/__pycache__/.keep
Add dot_config/qtile/__pycache__/bars.cpython-38.pyc
Add dot_config/qtile/__pycache__/bars.cpython-39.pyc
Add dot_config/qtile/__pycache__/colors.cpython-38.pyc
Add dot_config/qtile/__pycache__/colors.cpython-39.pyc
Add dot_config/qtile/__pycache__/config-done.cpython-38.pyc
Add dot_config/qtile/__pycache__/config.cpython-38.pyc
Add dot_config/qtile/__pycache__/config.cpython-39.pyc
Add dot_config/qtile/__pycache__/groups.cpython-38.pyc
Add dot_config/qtile/__pycache__/groups.cpython-39.pyc
Add dot_config/qtile/__pycache__/keys.cpython-38.pyc
Add dot_config/qtile/__pycache__/keys.cpython-39.pyc
Add dot_config/qtile/__pycache__/layouts.cpython-38.pyc
Add dot_config/qtile/__pycache__/layouts.cpython-39.pyc
Add dot_config/qtile/__pycache__/screens.cpython-38.pyc
Add dot_config/qtile/__pycache__/screens.cpython-39.pyc
Add dot_config/qtile/bars.py
Add dot_config/qtile/colors.py
Add dot_config/qtile/config.py
Add dot_config/qtile/groups.py
Add dot_config/qtile/keys.py
Add dot_config/qtile/layouts.py
Add dot_config/qtile/old_configs/.keep
Add dot_config/qtile/old_configs/config.py
Add dot_config/qtile/old_configs/sweenu/.keep
Add dot_config/qtile/old_configs/sweenu/bars.py
Add dot_config/qtile/old_configs/sweenu/colors.py
Add dot_config/qtile/old_configs/sweenu/config.py
Add dot_config/qtile/old_configs/sweenu/keys.py
Add dot_config/qtile/old_configs/sweenu/util/.keep
Add dot_config/qtile/old_configs/sweenu/util/__main__.py
Add dot_config/qtile/old_configs/sweenu/util/backlight.py
Add dot_config/qtile/old_configs/sweenu/util/monitor.py
Add dot_config/qtile/old_configs/sweenu/util/screenshot.py
Add dot_config/qtile/old_configs/sweenu/util/soundcard.py
Add dot_config/qtile/old_configs/sweenu/widgets.py
Add dot_config/qtile/screens.py
Add dot_config/qtile/scripts/.keep
Add dot_config/qtile/scripts/executable_autostart.sh
Add dot_config/qtile/themes/.keep
Add dot_config/qtile/themes/ayu-dark.json
Add dot_config/qtile/themes/dracula.json
Add dot_config/qtile/themes/hopscotch.json
Add dot_config/qtile/themes/material-darker.json
Add dot_config/qtile/themes/nord.json
Add dot_config/qtile/themes/one-dark.json
Add dot_config/qtile/themes/operator.json
Add dot_config/qtile/themes/royal.json
Add dot_config/qtile/themes/seashells.json
Add dot_config/qtile/themes/smyck.json
Add dot_config/qtile/themes/spacedust.json
Add dot_config/qtile/themes/spacegray.json
Add dot_config/qtile/themes/square.json
Add dot_config/qtile/themes/tomorrow-nb.json
This commit is contained in:
eeleater 2021-08-26 20:17:03 +02:00
parent d84f84d6cd
commit bc838a571d
55 changed files with 1181 additions and 0 deletions

View file

@ -0,0 +1,23 @@
from functools import wraps
from subprocess import run, PIPE
from typing import Callable, Any
import parse
def qtile_func(func: Callable[..., Any]) -> Callable[..., Any]:
"""
This decorator makes a function suitable to be used as a parameter for
`lazy.function()` by making the wrapped function return a function that
takes the qtile instance as first parameter.
"""
@wraps(func)
def wrapper(*args, **kwargs):
def f(qtile):
func(*args, **kwargs)
return f
return wrapper
def notify(summary: str, body: str, urgency: str='normal') -> None:
run(['notify-send', '-u', urgency, summary, body])

View file

@ -0,0 +1,50 @@
from subprocess import run, PIPE
from typing import Optional
from pynput import mouse
from . import qtile_func
class Backlight:
def __init__(self, ctrl: Optional[str]=None) -> None:
self.command = ['xbacklight']
if ctrl:
self.command += ['-ctrl', ctrl]
def _get_brightness(self) -> int:
return int(run(self.command + ['-get'], stdout=PIPE).stdout)
def _set_brightness(self, percentage: int) -> None:
run(self.command + [f'-set', str(percentage)])
@qtile_func
def change_backlight(self, action: str) -> None:
"""
Increase or decrease bightness.
Takes 'dec' or 'inc' as parameter. Goes 1% percent at a time from
1% to 40% and 10% at a time from 40% to 100%.
"""
brightness = self._get_brightness()
if brightness != 1 or action != 'dec':
if (brightness > 49 and action == 'dec') \
or (brightness > 39 and action == 'inc'):
run(self.command + [f'-{action}', '10', '-fps', '10'])
else:
run(self.command + [f'-{action}', '1'])
@qtile_func
def turn_off_screen(self, screen_offset: int) -> None:
"""
Turn off the laptop's screen.
Use xset if there is only one screen, else, set backlight to
zero. In both case, moving the mouse will turn on the screen.
"""
current_brightness = self._get_brightness()
self._set_brightness(0)
def on_move(x: int, y: int):
if x > screen_offset:
self._set_brightness(current_brightness)
raise mouse.Listener.StopException
mouse.Listener(on_move=on_move).start()

View file

@ -0,0 +1,24 @@
from subprocess import run
from pathlib import Path
from typing import Optional
from libqtile.log_utils import logger
from libqtile.xcbq import Monitor
from .backlight import Backlight
Side = str # one of 'left-of', 'right-of', 'above', 'below' or 'same-as'
def enable_monitor(monitor: Monitor, primary: bool=False, side: Optional[Side]=None,
relative_monitor: Optional[Monitor]=None) -> None:
command = ['xrandr', '--output', monitor.name, '--auto']
if primary:
command += ['--primary']
if side:
if not relative_monitor:
raise Exception('Need a monitor to be relative to')
command += ['--{}'.format(side), relative_monitor.name]
run(command)
logger.info(f'Running command: {" ".join(command)}')

View file

@ -0,0 +1,16 @@
from time import time
from pathlib import Path
from subprocess import run, PIPE
from . import qtile_func
@qtile_func
def screenshot(save: bool=True, copy: bool=True) -> None:
shot = run(['maim'], stdout=PIPE)
if save:
path = Path.home() / 'Pictures'
path /= f'screenshot_{str(int(time() * 100))}.png'
with open(path, 'wb') as sc:
sc.write(shot.stdout)
if copy:
run('xclip -sel clip -t image/png'.split(), input=shot.stdout)

View file

@ -0,0 +1,79 @@
from subprocess import run, PIPE
import parse
from . import qtile_func, notify
class SoundCard():
def __init__(self, primary_card_name):
self.primary_card = primary_card_name
def get_current_sink(self):
cp = run(['pactl', 'info'], stdout=PIPE)
output = cp.stdout.decode('utf-8')
return parse.search('Default Sink: {}\n', output)[0]
def list_sinks(self):
"""Generator that yields for each sink, the sink and card name."""
cp = run(['pactl', 'list', 'sinks'], stdout=PIPE)
output = cp.stdout.decode('utf-8')
for sink in output.split('\nSink'):
sink_name = parse.search('Name: {}\n', sink)[0]
card_name = parse.search('alsa.card_name = "{}"', sink)[0]
yield sink_name, card_name
def set_new_sink(self, sink_card_tuple):
run(['pactl', 'set-default-sink', sink_card_tuple[0]])
def list_sink_inputs(self):
cp = run(['pactl', 'list', 'short', 'sink-inputs'], stdout=PIPE)
output = cp.stdout.decode('utf-8')
return {line.split()[0] for line in output.split('\n') if line}
def move_sink_input(self, name, new_sink):
run(['pactl', 'move-sink-input', name, new_sink])
def get_current_profile(self):
cp = run(['pactl', 'list', 'cards'], stdout=PIPE)
cp = run(['grep', 'Active'], stdout=PIPE, input=cp.stdout)
return 'hdmi' if b'hdmi' in cp.stdout else 'analog'
def set_profile(self, profile):
cmd = f'output:{profile}-stereo+input:analog-stereo'
run(['pactl', 'set-card-profile', self.primary_card, cmd])
@qtile_func
def change_sink(self, direction):
sinks = list(self.list_sinks())
# get the index of the tuple containing the current default sink
current_sink = self.get_current_sink()
for index, tup in enumerate(sinks):
if current_sink in tup:
default_sink_index = index
break
if direction == 'next':
new_sink = sinks[default_sink_index - 1]
elif direction == 'prev':
new_sink = sinks[(default_sink_index + 1) % len(sinks)]
self.set_new_sink(new_sink)
notify('Sound Card', new_sink[1])
# move current sink inputs, if any, to the new default sink
sink_inputs = self.list_sink_inputs()
if sink_inputs:
for sink_input in sink_inputs:
self.move_sink_input(sink_input, new_sink[0])
@qtile_func
def swap_profile(self):
profile = self.get_current_profile()
if profile == 'analog':
self.set_profile('hdmi')
notify('Sound Profile', 'HDMI')
elif profile == 'hdmi':
self.set_profile('analog')
notify('Sound Profile', 'Analog')