-
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.
A plugin that allows control of opacity, brightness and saturation of windows, using ipc plugin. There are two scripts demonstrating usage in ./ipc-scripts directory.
- Loading branch information
Showing
9 changed files
with
650 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,51 @@ | ||
#!/usr/bin/python3 | ||
|
||
import os | ||
import sys | ||
from wayfire_socket import * | ||
|
||
addr = os.getenv('WAYFIRE_SOCKET') | ||
|
||
commands_sock = WayfireSocket(addr) | ||
commands_sock.watch() | ||
|
||
def sort_views(): | ||
i = 0 | ||
for v in commands_sock.list_views(): | ||
if v["app-id"] == "$unfocus panel" or v["layer"] == "background": | ||
continue | ||
if v["state"] != {} and v["state"]["minimized"]: | ||
continue | ||
i += 1 | ||
o_step = 0.2 / i | ||
b_step = 0.5 / i | ||
s_step = 1.0 / i | ||
o_value = 0.8 | ||
b_value = 0.5 | ||
s_value = 0.0 | ||
for v in commands_sock.list_views()[::-1]: | ||
if v["app-id"] == "$unfocus panel" or v["layer"] == "background": | ||
continue | ||
if v["state"] != {} and v["state"]["minimized"]: | ||
continue | ||
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) | ||
|
||
sort_views() | ||
|
||
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": | ||
sort_views() |
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 list_views(self): | ||
message = get_msg_template("window-rules/list-views") | ||
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) |
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.