Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare for a release #2413

Merged
merged 5 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions ipc-scripts/cfg.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import wayfire_socket as ws
import os
from wayfire.ipc import WayfireSocket
import sys

addr = os.getenv('WAYFIRE_SOCKET')
sock = ws.WayfireSocket(addr)
sock = WayfireSocket()

if sys.argv[1] == "get":
opt = sock.get_option_value(sys.argv[2])
Expand Down
7 changes: 2 additions & 5 deletions ipc-scripts/headless.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import wayfire_socket as ws
import os
from wayfire.ipc import WayfireSocket
import json
import argparse

addr = os.getenv('WAYFIRE_SOCKET')
sock = ws.WayfireSocket(addr)

sock = WayfireSocket()
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(dest='action')

Expand Down
11 changes: 4 additions & 7 deletions ipc-scripts/inactive-alpha.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,22 @@
#
# This script demonstrates how Wayfire's IPC can be used to set the opacity of inactive views.

import os
from wayfire_socket import *
from wayfire.ipc import WayfireSocket

addr = os.getenv('WAYFIRE_SOCKET')
sock = WayfireSocket(addr)
sock = WayfireSocket()
sock.watch(['view-focused'])

last_focused_toplevel = -1
while True:
msg = sock.read_message()
# The view-mapped event is emitted when a new window has been opened.
msg = sock.read_next_event()
if "event" in msg:
print(msg["event"])
view = msg["view"]
new_focus = view["id"] if view and view["type"] == "toplevel" else -1
if last_focused_toplevel != new_focus:
if last_focused_toplevel != -1 and new_focus != -1:
try:
sock.set_view_alpha(last_focused_toplevel, 0.8)
sock.set_view_alpha(last_focused_toplevel, 0.6)
except:
print("Last focused toplevel was closed?")

Expand Down
7 changes: 2 additions & 5 deletions ipc-scripts/input.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import wayfire_socket as ws
import os
from wayfire.ipc import WayfireSocket
import argparse
import tabulate

Expand All @@ -22,9 +21,7 @@
print('Invalid usage, an input id >= 0 is required!')
exit(-1)

addr = os.getenv('WAYFIRE_SOCKET')
sock = ws.WayfireSocket(addr)

sock = WayfireSocket()
devices = sock.list_input_devices()

def find_device_id(name_or_id_or_type):
Expand Down
19 changes: 9 additions & 10 deletions ipc-scripts/ipc-bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,28 @@
# This script demonstrates how to use custom bindings to achieve more complex command sequences in Wayfire
# The binding realised with this script is double pressing and releasing the left control button, which causes Expo to be activated.

import os
import time
from wayfire_socket import *
from wayfire.ipc import WayfireSocket

addr = os.getenv('WAYFIRE_SOCKET')
sock = WayfireSocket()

sock = WayfireSocket(addr)

response = sock.register_binding('<alt>', 'press', True)
response = sock.register_binding('KEY_D', 'press', True)
print(response)
binding_id = response['binding-id']
last_release_time = 0
MAX_DELAY = 0.5

while True:
msg = sock.read_message()
msg = sock.read_next_event()
print(msg)
if "event" in msg and msg["event"] == "command-binding":
assert msg['binding-id'] == binding_id

now = time.time()
if now - last_release_time <= MAX_DELAY:
msg = get_msg_template("expo/toggle")
sock.send_json(msg)

print("toggle")
sock.toggle_expo()
last_release_time = now - 2 * MAX_DELAY # Prevent triple press
else:
print("reset")
last_release_time = now
23 changes: 8 additions & 15 deletions ipc-scripts/ipc-rules-demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,18 @@
# Lastly, this script can be run from a terminal for testing purposes, or started as an autostart entry.
# It is safe to kill/restart the process at any point in time.

import os
from wayfire_socket import *
from wayfire.ipc import WayfireSocket

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.
events_sock = WayfireSocket(addr)
commands_sock = WayfireSocket(addr)
events_sock.watch(['view-mapped'])
sock = WayfireSocket()
sock.watch(['view-mapped'])

while True:
msg = events_sock.read_message()
msg = sock.read_next_event()
# The view-mapped event is emitted when a new window has been opened.
if "event" in msg:
view = msg["view"]
if view["app-id"] == "gedit":
output_data = commands_sock.query_output(view["output"])
output_data = sock.query_output(view["output"])
print(output_data)
workarea = output_data["workarea"]

Expand All @@ -37,7 +30,7 @@
w = workarea['width'] // 2
h = workarea['height'] // 2

commands_sock.configure_view(view["id"], x, y, w, h)
sock.configure_view(view["id"], x, y, w, h)
# sock.assign_slot(view["id"], "slot_br")
commands_sock.set_always_on_top(view["id"], True)
commands_sock.set_view_alpha(view["id"], 0.5)
sock.set_view_always_on_top(view["id"], True)
sock.set_view_alpha(view["id"], 0.5)
14 changes: 4 additions & 10 deletions ipc-scripts/list-methods.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import wayfire_socket as ws
import os
from wayfire.ipc import WayfireSocket
import json

addr = os.getenv('WAYFIRE_SOCKET')
sock = ws.WayfireSocket(addr)
sock = WayfireSocket()

query = ws.get_msg_template('wayfire/configuration')
response = sock.send_json(query)
print("Wayfire version:")
print(json.dumps(response, indent=4))
print(json.dumps(sock.get_configuration(), indent=4))

query = ws.get_msg_template('list-methods')
response = sock.send_json(query)
print("Supported methods:")
print(json.dumps(response['methods'], indent=4))
print(json.dumps(sock.list_methods(), indent=4))
39 changes: 9 additions & 30 deletions ipc-scripts/master-stack-tile-layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,10 @@
# A simple script which demonstrates how simple-tile's IPC scripting capabilities can be used to achieve automatic tiling policies.
# This script in particular listens for the view-mapped event and places new views in a master-stack layout: one view remains on the left,
# and all other views are piled on top of each other vertically in the right column.
import os
from wayfire_socket import *
from wayfire.ipc import WayfireSocket

addr = os.getenv('WAYFIRE_SOCKET')

events_sock = WayfireSocket(addr)
commands_sock = WayfireSocket(addr)
events_sock.watch(['view-mapped'])

def get_tiling_layout(wset, x, y):
msg = get_msg_template('simple-tile/get-layout')
msg['data']['wset-index'] = wset
msg['data']['workspace'] = {}
msg['data']['workspace']['x'] = x
msg['data']['workspace']['y'] = y
return commands_sock.send_json(msg)['layout']

def set_tiling_layout(wset, x, y, layout):
msg = get_msg_template('simple-tile/set-layout')
msg['data']['wset-index'] = wset
msg['data']['workspace'] = {}
msg['data']['workspace']['x'] = x
msg['data']['workspace']['y'] = y
msg['data']['layout'] = layout
return commands_sock.send_json(msg)
sock = WayfireSocket()
sock.watch(['view-mapped'])

def create_list_views(layout):
if 'view-id' in layout:
Expand All @@ -40,26 +19,26 @@ def create_list_views(layout):
return list

while True:
msg = events_sock.read_message()
msg = sock.read_next_event()
# The view-mapped event is emitted when a new window has been opened.
if "event" in msg:
view = msg["view"]
if view["type"] == "toplevel" and view["parent"] == -1:
# Tile the new view appropriately

# First, figure out current wset and workspace and existing layout
output = commands_sock.query_output(view["output-id"])
output = sock.query_output(view["output-id"])
wset = output['wset-index']
wsx = output['workspace']['x']
wsy = output['workspace']['y']
layout = get_tiling_layout(wset, wsx, wsy)
layout = sock.get_tiling_layout(wset, wsx, wsy)
all_views = create_list_views(layout)

desired_layout = {}
if not all_views or (len(all_views) == 1 and all_views[0][0] == view["id"]):
# Degenerate case 1: we have just our view
desired_layout = { 'vertical-split': [ {'view-id': view["id"], 'weight': 1} ]}
set_tiling_layout(wset, wsx, wsy, desired_layout)
sock.set_tiling_layout(wset, wsx, wsy, desired_layout)
continue

main_view = all_views[0][0]
Expand All @@ -74,7 +53,7 @@ def create_list_views(layout):
if not stack_views_old:
# Degenerate case 2: the new view is the first on the stack, set 2:1 ratio and place the new view on the right
desired_layout = { 'vertical-split': [ {'view-id': main_view, 'weight': 2}, {'view-id': view["id"], 'weight': 1} ]}
set_tiling_layout(wset, wsx, wsy, desired_layout)
sock.set_tiling_layout(wset, wsx, wsy, desired_layout)
continue

stack = [{'view-id': v[0], 'weight': v[2]} for v in stack_views_old]
Expand All @@ -87,4 +66,4 @@ def create_list_views(layout):
]
}

set_tiling_layout(wset, wsx, wsy, desired_layout)
sock.set_tiling_layout(wset, wsx, wsy, desired_layout)
44 changes: 0 additions & 44 deletions ipc-scripts/move-to-workspace.py

This file was deleted.

6 changes: 2 additions & 4 deletions ipc-scripts/set-touch-state.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import wayfire_socket as ws
import os
from wayfire.ipc import WayfireSocket
import sys

# This is a small example of how to use the Wayfire socket to set the touchscreen state to on or off.
Expand All @@ -11,8 +10,7 @@
exit(-1)

state: bool = sys.argv[1] == 'enabled'
addr = os.getenv('WAYFIRE_SOCKET')
sock = ws.WayfireSocket(addr)
sock = WayfireSocket()

devices = sock.list_input_devices()
for dev in devices:
Expand Down
Loading
Loading