-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
634 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/python3 | ||
# | ||
# This is a simple script which demonstrates how to use the Wayfire OBS plugin using the IPC socket with the wayfire_socket.py helper. | ||
# To use this, make sure that the ipc plugin is first in the plugin list, so that the WAYFIRE_SOCKET environment | ||
# variable propagates to all processes, including autostarted processes. Also make sure to enable stipc and obs plugins. | ||
# | ||
# This script can be run from a terminal to change the opacity, brightness and saturation of views. | ||
# 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 * | ||
|
||
addr = os.getenv('WAYFIRE_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(): | ||
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])) | ||
elif sys.argv[2] == "brightness": | ||
commands_sock.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])) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/python3 | ||
|
||
import os | ||
import sys | ||
from wayfire_socket import * | ||
|
||
addr = os.getenv('WAYFIRE_SOCKET') | ||
|
||
commands_sock = WayfireSocket(addr) | ||
commands_sock.watch() | ||
|
||
while True: | ||
try: | ||
msg = commands_sock.read_message() | ||
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) | ||
exit(0) | ||
|
||
if "event" in msg and msg["event"] == "view-focused": | ||
i = 0 | ||
for v in commands_sock.list_views(): | ||
if v["app-id"] == "$unfocus panel" or v["app-id"] == "gtk-layer-shell": | ||
continue | ||
if v["state"] != {} and v["state"]["minimized"]: | ||
continue | ||
i += 1 | ||
step = 0.7 / i | ||
value = 0.3 | ||
for v in commands_sock.list_views()[::-1]: | ||
if v["app-id"] == "$unfocus panel" or v["app-id"] == "gtk-layer-shell": | ||
continue | ||
if v["state"] != {} and v["state"]["minimized"]: | ||
continue | ||
value += step | ||
commands_sock.set_view_opacity(v["id"], value, 1000) | ||
commands_sock.set_view_brightness(v["id"], value, 1000) | ||
commands_sock.set_view_saturation(v["id"], value, 1000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import socket | ||
import json as js | ||
|
||
def get_msg_template(method: str): | ||
# Create generic message template | ||
message = {} | ||
message["method"] = method | ||
message["data"] = {} | ||
return message | ||
|
||
class WayfireSocket: | ||
def __init__(self, socket_name): | ||
self.client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | ||
self.client.connect(socket_name) | ||
|
||
def read_exact(self, n): | ||
response = bytes() | ||
while n > 0: | ||
read_this_time = self.client.recv(n) | ||
if not read_this_time: | ||
raise Exception("Failed to read anything from the socket!") | ||
n -= len(read_this_time) | ||
response += read_this_time | ||
|
||
return response | ||
|
||
def read_message(self): | ||
rlen = int.from_bytes(self.read_exact(4), byteorder="little") | ||
response_message = self.read_exact(rlen) | ||
return js.loads(response_message) | ||
|
||
def send_json(self, msg): | ||
data = js.dumps(msg).encode('utf8') | ||
header = len(data).to_bytes(4, byteorder="little") | ||
self.client.send(header) | ||
self.client.send(data) | ||
return self.read_message() | ||
|
||
def watch(self): | ||
message = get_msg_template("window-rules/events/watch") | ||
return self.send_json(message) | ||
|
||
def set_view_opacity(self, view_id: int, opacity: float, duration: int): | ||
message = get_msg_template("wf/obs/set-view-opacity") | ||
message["data"] = {} | ||
message["data"]["view-id"] = view_id | ||
message["data"]["opacity"] = opacity | ||
message["data"]["duration"] = duration | ||
return self.send_json(message) | ||
|
||
def set_view_brightness(self, view_id: int, brightness: float, duration: int): | ||
message = get_msg_template("wf/obs/set-view-brightness") | ||
message["data"] = {} | ||
message["data"]["view-id"] = view_id | ||
message["data"]["brightness"] = brightness | ||
message["data"]["duration"] = duration | ||
return self.send_json(message) | ||
|
||
def set_view_saturation(self, view_id: int, saturation: float, duration: int): | ||
message = get_msg_template("wf/obs/set-view-saturation") | ||
message["data"] = {} | ||
message["data"]["view-id"] = view_id | ||
message["data"]["saturation"] = saturation | ||
message["data"]["duration"] = duration | ||
return self.send_json(message) | ||
|
||
def list_views(self): | ||
message = get_msg_template("stipc/list_views") | ||
return self.send_json(message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0"?> | ||
<wayfire> | ||
<plugin name="obs"> | ||
<_short>OBS</_short> | ||
<_long>Change the opacity, brightness and saturation of windows using ipc scripts</_long> | ||
<category>Effects</category> | ||
</plugin> | ||
</wayfire> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.