This commit is contained in:
sankalp committed 2024-10-18 10:21:37 +05:45
1 parent 2095c1f071
commit 1b7ec29d26
52 files changed
+18934

No files matched your search

+49
View File
@@ -0,0 +1,49 @@
#!/bin/bash
GENERATOR="$HOME/dotfiles/material-colors/generate.py"
SETTINGS_FILE="$HOME/dotfiles/.settings/settings.json"
# Function to read a value from the JSON file
get_json_value() {
local key=$1
jq -r --arg key "$key" '.[$key]' $SETTINGS_FILE
}
# Function to update a value in the JSON file
update_json_value() {
local key=$1
local value=$2
jq --arg key "$key" --arg value "$value" \
'.[$key] = $value' $SETTINGS_FILE > "$SETTINGS_FILE.tmp" && mv "$SETTINGS_FILE.tmp" $SETTINGS_FILE
}
toggle() {
local color_scheme=$(get_json_value "color-scheme")
local generation_scheme=$(get_json_value "generation-scheme")
if [ "$color_scheme" == "dark" ]; then
python -O $GENERATOR -R --color-scheme light --scheme $generation_scheme
update_json_value "color-scheme" "light"
elif [ "$color_scheme" == "light" ]; then
python -O $GENERATOR -R --color-scheme dark --scheme $generation_scheme
update_json_value "color-scheme" "dark"
else
echo "Unknown color scheme: $color_scheme"
fi
}
set() {
local new_scheme=$1
local generation_scheme=$(get_json_value "generation-scheme")
python -O $GENERATOR -R --color-scheme $new_scheme --scheme $generation_scheme
update_json_value "color-scheme" $new_scheme
}
# Process arguments
if [[ "$1" == "--toggle" ]]; then
toggle
elif [[ "$1" == "--set" ]]; then
set $2
else
echo "Usage: $0 --toggle | --set <color-scheme>"
fi
+83
View File
@@ -0,0 +1,83 @@
#!/usr/bin/env python
import sys
from dataclasses import dataclass
from signal import SIGINT, SIGTERM, signal
from threading import Event
import setproctitle
from pywayland.client.display import Display # type: ignore
from pywayland.protocol.idle_inhibit_unstable_v1.zwp_idle_inhibit_manager_v1 import ( # type: ignore
ZwpIdleInhibitManagerV1,
)
from pywayland.protocol.wayland.wl_compositor import WlCompositor # type: ignore
from pywayland.protocol.wayland.wl_registry import WlRegistryProxy # type: ignore
from pywayland.protocol.wayland.wl_surface import WlSurface # type: ignore
@dataclass
class GlobalRegistry:
surface: WlSurface | None = None
inhibit_manager: ZwpIdleInhibitManagerV1 | None = None
def handle_registry_global(
wl_registry: WlRegistryProxy, id_num: int, iface_name: str, version: int
) -> None:
global_registry: GlobalRegistry = wl_registry.user_data or GlobalRegistry()
if iface_name == "wl_compositor":
compositor = wl_registry.bind(id_num, WlCompositor, version)
global_registry.surface = compositor.create_surface() # type: ignore
elif iface_name == "zwp_idle_inhibit_manager_v1":
global_registry.inhibit_manager = wl_registry.bind(
id_num, ZwpIdleInhibitManagerV1, version
)
def main() -> None:
done = Event()
signal(SIGINT, lambda _, __: done.set())
signal(SIGTERM, lambda _, __: done.set())
global_registry = GlobalRegistry()
display = Display()
display.connect()
registry = display.get_registry() # type: ignore
registry.user_data = global_registry
registry.dispatcher["global"] = handle_registry_global
def shutdown() -> None:
display.dispatch()
display.roundtrip()
display.disconnect()
display.dispatch()
display.roundtrip()
if global_registry.surface is None or global_registry.inhibit_manager is None:
print("Wayland seems not to support idle_inhibit_unstable_v1 protocol.")
shutdown()
sys.exit(1)
inhibitor = global_registry.inhibit_manager.create_inhibitor( # type: ignore
global_registry.surface
)
display.dispatch()
display.roundtrip()
print("Inhibiting idle...")
done.wait()
print("Shutting down...")
inhibitor.destroy()
shutdown()
if __name__ == "__main__":
setproctitle.setproctitle("wayland-idle-inhibitor.py")
main()