Skip to content

Commit

Permalink
update all scripts to use pywayfire (#255)
Browse files Browse the repository at this point in the history
  • Loading branch information
ammen99 authored Aug 24, 2024
1 parent df679db commit 268e05d
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 142 deletions.
15 changes: 6 additions & 9 deletions ipc-scripts/ipc-ghost-toggle.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
#!/usr/bin/python3

import os
import sys
from wayfire_socket import *
from wayfire import WayfireSocket
from wayfire.extra.wpe import WPE

if len(sys.argv) < 2:
print(f"Usage: {sys.argv[0]} <app_id>")
exit(1)

addr = os.getenv('WAYFIRE_SOCKET')
socket = WayfireSocket()
wpe = WPE(socket)

events_sock = WayfireSocket(addr)
commands_sock = WayfireSocket(addr)
events_sock.watch()

for view in commands_sock.list_views():
for view in socket.list_views():
if view["app-id"] == sys.argv[1]:
commands_sock.ghost_view_toggle(view["id"])
wpe.ghost_view_toggle(view["id"])
20 changes: 8 additions & 12 deletions ipc-scripts/set-obs-effect.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,19 @@
# Usage: ./script.py <app-id> <effect> <value> <duration>
# where <effect> is one of opacity, brightness or saturation, <value> is in the range 0-1 and <duration> is the animation duration in milliseconds

import os
import sys
from wayfire_socket import *
from wayfire import WayfireSocket
from wayfire.extra.wpe import WPE

addr = os.getenv('WAYFIRE_SOCKET')
socket = WayfireSocket()
wpe = WPE(socket)

# Important: we connect to Wayfire's IPC two times. The one socket is used for reading events (view-mapped, view-focused, etc).
# The other is used for sending commands and querying Wayfire.
# We could use the same socket, but this would complicate reading responses, as events and query responses would be mixed with just one socket.
commands_sock = WayfireSocket(addr)

for v in commands_sock.list_views():
for v in socket.list_views():
if v["app-id"] == sys.argv[1]:
if sys.argv[2] == "opacity":
commands_sock.set_view_opacity(v["id"], float(sys.argv[3]), int(sys.argv[4]))
wpe.set_view_opacity(v["id"], float(sys.argv[3]), int(sys.argv[4]))
elif sys.argv[2] == "brightness":
commands_sock.set_view_brightness(v["id"], float(sys.argv[3]), int(sys.argv[4]))
wpe.set_view_brightness(v["id"], float(sys.argv[3]), int(sys.argv[4]))
elif sys.argv[2] == "saturation":
commands_sock.set_view_saturation(v["id"], float(sys.argv[3]), int(sys.argv[4]))
wpe.set_view_saturation(v["id"], float(sys.argv[3]), int(sys.argv[4]))

36 changes: 16 additions & 20 deletions ipc-scripts/trailfocus.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
#!/usr/bin/python3

import os
import sys
from wayfire_socket import *
from wayfire import WayfireSocket
from wayfire.extra.wpe import WPE

addr = os.getenv('WAYFIRE_SOCKET')

commands_sock = WayfireSocket(addr)
commands_sock.watch()
socket = WayfireSocket()
wpe = WPE(socket)
socket.watch(['view-focused'])

def sort_views():
try:
views = commands_sock.list_views()
outputs = commands_sock.list_outputs()
views = socket.list_views()
outputs = socket.list_outputs()
for o in outputs:
i = 0
timestamps = []
Expand Down Expand Up @@ -49,9 +47,9 @@ def sort_views():
o_value += o_step
b_value += b_step
s_value += s_step
commands_sock.set_view_opacity(v["id"], o_value, 1000)
commands_sock.set_view_brightness(v["id"], b_value, 1000)
commands_sock.set_view_saturation(v["id"], s_value, 1000)
wpe.set_view_opacity(v["id"], o_value, 1000)
wpe.set_view_brightness(v["id"], b_value, 1000)
wpe.set_view_saturation(v["id"], s_value, 1000)
break
except Exception as error:
print("An exception occurred:", error)
Expand All @@ -61,13 +59,11 @@ def sort_views():

while True:
try:
msg = commands_sock.read_message()
msg = socket.read_next_event()
except KeyboardInterrupt:
for v in commands_sock.list_views():
commands_sock.set_view_opacity(v["id"], 1.0, 500)
commands_sock.set_view_brightness(v["id"], 1.0, 500)
commands_sock.set_view_saturation(v["id"], 1.0, 500)
for v in socket.list_views():
wpe.set_view_opacity(v["id"], 1.0, 500)
wpe.set_view_brightness(v["id"], 1.0, 500)
wpe.set_view_saturation(v["id"], 1.0, 500)
exit(0)

if "event" in msg and msg["event"] == "view-focused":
sort_views()
sort_views()
14 changes: 7 additions & 7 deletions ipc-scripts/unpin-view.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#!/usr/bin/python3

import os
import sys
from wayfire_socket import *

from wayfire import WayfireSocket
from wayfire.extra.wpe import WPE

if len(sys.argv) < 2:
print(f"Usage: {sys.argv[0]} <view_id>")
exit(1)

addr = os.getenv('WAYFIRE_SOCKET')

commands_sock = WayfireSocket(addr)
socket = WayfireSocket()
wpe = WPE(socket)

for view in commands_sock.list_views():
for view in socket.list_views():
if view["id"] == int(sys.argv[1]):
commands_sock.unpin_view(int(sys.argv[1]))
wpe.unpin_view(int(sys.argv[1]))
94 changes: 0 additions & 94 deletions ipc-scripts/wayfire_socket.py

This file was deleted.

0 comments on commit 268e05d

Please sign in to comment.