Skip to content

Commit

Permalink
cosmetic
Browse files Browse the repository at this point in the history
  • Loading branch information
totaam committed Dec 7, 2023
1 parent ff27042 commit 8ebe175
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 66 deletions.
34 changes: 7 additions & 27 deletions xpra/gtk/configure/opengl.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from xpra.util.io import load_binary_file
from xpra.gtk.dialogs.base_gui_window import BaseGUIWindow
from xpra.gtk.configure.common import sync, parse_user_config_file, save_user_config_file, get_user_config_file
from xpra.gtk.widget import label
from xpra.log import Logger

Gtk = gi_import("Gtk")
Expand Down Expand Up @@ -167,11 +166,8 @@ def populate(self):
"This tool can cause your system to crash if your GPU drivers are buggy.",
"Use with caution.",
"",
"When enabled, OpenGL rendering is faster.",
"Your xpra client will be able to skip its OpenGL self-tests and start faster.",
"",
"This test will present two windows which will be painted using various picture encodings.",
"You will be asked to confirm that the rendering was correct and identical in both windows.",
"Enabling the OpenGL renderer can improve the framerate and general performance of the client.",
"Your xpra client will also be able to skip its OpenGL self-tests and start faster.",
),
("Proceed", self.start_test),
("Exit", self.dismiss),
Expand All @@ -190,11 +186,11 @@ def start_test(self, *_args):
self.populate_form(
(
glinfo,
"",
"This tool will now be showing two windows which will be painted using various picture encodings.",
"Try to arrange them side by side.",
"",
""
"This tool will now present two windows which will be painted using various picture encodings.",
"You will be asked to confirm that the rendering was correct and identical in both windows.",
"",
"Try to arrange them side by side to make it easier to compare.",
),
("Understood", self.paint_step),
("Exit", self.dismiss),
Expand Down Expand Up @@ -252,7 +248,7 @@ def test_passed(self, *_args):
(
"OpenGL can be enabled safely using this GPU.",
""
"You revert this change by running this tool again, or resetting your user configuration."
"You can revert this change by running this tool again, or by resetting your user configuration."
),
("Enable OpenGL", self.enable_opengl),
("Exit", self.dismiss),
Expand All @@ -273,7 +269,6 @@ def enable_opengl(self, *_args):

def test_failed(self, *_args):
description = self.test_steps[self.step][0]
self.close_test_windows()
self.populate_form(
(
"Please report this issue at https://github.com/Xpra-org/xpra/issues/new/choose",
Expand All @@ -284,21 +279,6 @@ def test_failed(self, *_args):
("Exit", self.dismiss),
)

def populate_form(self, lines: tuple[str, ...] = (), *buttons):
self.clear_vbox()
self.add_widget(label("Configure Xpra's OpenGL Renderer", font="sans 20"))
text = "\n".join(lines)
lbl = label(text, font="Sans 14")
lbl.set_line_wrap(True)
self.add_widget(lbl)
hbox = Gtk.HBox()
self.add_widget(hbox)
for button_label, callback in buttons:
btn = Gtk.Button.new_with_label(button_label)
btn.connect("clicked", callback)
hbox.pack_start(btn, True, True)
self.show_all()


def main(_args) -> int:
from xpra.gtk.configure.main import run_gui
Expand Down
31 changes: 27 additions & 4 deletions xpra/gtk/dialogs/base_gui_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from collections.abc import Callable

from xpra.gtk.window import add_close_accel, add_window_accel
from xpra.gtk.widget import imagebutton
from xpra.gtk.widget import imagebutton, label
from xpra.gtk.pixbuf import get_icon_pixbuf
from xpra.os_util import gi_import
from xpra.util.env import IgnoreWarningsContext
Expand Down Expand Up @@ -82,19 +82,41 @@ def __init__(self,
with IgnoreWarningsContext():
self.set_wmclass(*wm_class)
self.vbox = Gtk.VBox(homogeneous=False, spacing=10)
self.vbox.set_margin_start(40)
self.vbox.set_margin_end(40)
self.set_box_margin()
self.vbox.set_vexpand(True)
self.add(self.vbox)
self.populate()
self.vbox.show_all()
self.set_default_size(*default_size)
self.connect("focus-in-event", self.focus_in)
self.connect("focus-out-event", self.focus_out)

def set_box_margin(self, start=40, end=40, top=0, bottom=20):
self.vbox.set_margin_start(start)
self.vbox.set_margin_end(end)
self.vbox.set_margin_top(top)
self.vbox.set_margin_bottom(bottom)

def clear_vbox(self):
for x in self.vbox.get_children():
self.vbox.remove(x)

def populate_form(self, lines: tuple[str, ...] = (), *buttons):
self.clear_vbox()
self.add_widget(label(self.get_title(), font="sans 20"))
text = "\n".join(lines)
lbl = label(text, font="Sans 14")
lbl.set_line_wrap(True)
self.add_widget(lbl)
hbox = Gtk.HBox()
hbox.set_vexpand(False)
self.add_widget(hbox)
for button_label, callback in buttons:
btn = Gtk.Button.new_with_label(button_label)
btn.connect("clicked", callback)
hbox.pack_start(btn, True, True)
self.show_all()

def dismiss(self, *args):
log(f"dismiss{args} calling {self.do_dismiss}")
self.do_dismiss()
Expand Down Expand Up @@ -123,7 +145,7 @@ def hide(*_args):
hb.show_all()
self.set_titlebar(hb)

def ib(self, title="", icon_name="browse.png", tooltip="", callback: Callable = noop, sensitive=True) -> None:
def ib(self, title="", icon_name="browse.png", tooltip="", callback: Callable = noop, sensitive=True) -> Gtk.Button:
label_font = "sans 16"
icon = get_icon_pixbuf(icon_name)
btn = imagebutton(
Expand All @@ -132,6 +154,7 @@ def ib(self, title="", icon_name="browse.png", tooltip="", callback: Callable =
icon_size=48, label_font=label_font,
)
self.add_widget(btn)
return btn

def add_widget(self, widget):
self.vbox.add(widget)
Expand Down
16 changes: 11 additions & 5 deletions xpra/platform/posix/fd_portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class AvailableDeviceTypes(IntEnum):
POINTER = 2
TOUCHSCREEN = 4


class AvailableSourceTypes(IntEnum):
MONITOR = 1
WINDOW = 2
Expand All @@ -38,14 +39,17 @@ class AvailableSourceTypes(IntEnum):
dbus_sender_name : str = (bus.get_unique_name()[1:]).replace(".", "_")
request_counter : int = 0

def screenscast_dbus_call(method, callback:Callable, *args, options=None) -> None:

def screenscast_dbus_call(method, callback: Callable, *args, options=None) -> None:
dbus_desktop_call(SCREENCAST_IFACE, method, callback, *args, options=options)

def remotedesktop_dbus_call(method, callback:Callable, *args, options=None) -> None:

def remotedesktop_dbus_call(method, callback: Callable, *args, options=None) -> None:
dbus_desktop_call(REMOTEDESKTOP_IFACE, method, callback, *args, options=options)

def dbus_desktop_call(interface:str, method, callback:Callable, *args, options=None) -> None:
#generate a new token and path:

def dbus_desktop_call(interface:str, method, callback: Callable, *args, options=None) -> None:
# generate a new token and path:
options = options or {}
global request_counter
request_counter += 1
Expand All @@ -61,8 +65,10 @@ def dbus_desktop_call(interface:str, method, callback:Callable, *args, options=N
log(f"calling {method} with args={args}, options={options}")
method(*(args + (options, )), dbus_interface=interface)


def get_portal_interface():
return bus.get_object(PORTAL_DESKTOP_INTERFACE, PORTAL_DESKTOP_PATH)

def get_session_interface(session_path:str):

def get_session_interface(session_path: str):
return bus.get_object(PORTAL_DESKTOP_INTERFACE, session_path)
43 changes: 17 additions & 26 deletions xpra/platform/posix/fd_portal_shadow.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
class PipewireWindowModel(RootWindowModel):
__slots__ = ("pipewire_id", "pipewire_props")

def __init__(self, root_window, capture, title:str, geometry, node_id:int, props:typedict):
def __init__(self, root_window, capture, title:str, geometry, node_id: int, props:typedict):
super().__init__(root_window=root_window, capture=capture, title=title, geometry=geometry)
self.pipewire_id = node_id
self.pipewire_props = props
Expand All @@ -56,15 +56,14 @@ def __init__(self, multi_window=True):
self.authenticating_client = None
self.capture : Capture | None = None
self.portal_interface = get_portal_interface()
self.input_devices = 0
log(f"setup_capture() self.portal_interface={self.portal_interface}")
#we're not using X11, so no need for this check:
# we're not using X11, so no need for this check:
os.environ["XPRA_UI_THREAD_CHECK"] = "0"


def get_server_mode(self) -> str:
return "portal shadow"


def notify_new_user(self, ss) -> None:
log("notify_new_user() start capture")
super().notify_new_user(ss)
Expand All @@ -77,7 +76,7 @@ def last_client_exited(self) -> None:
self.stop_capture()
self.stop_session()

def client_auth_error(self, message:str) -> None:
def client_auth_error(self, message: str) -> None:
self.disconnect_authenticating_client(ConnectionMessage.AUTHENTICATION_FAILED, message)

def disconnect_authenticating_client(self, reason : ConnectionMessage, message : str) -> None:
Expand All @@ -87,7 +86,6 @@ def disconnect_authenticating_client(self, reason : ConnectionMessage, message :
self.disconnect_protocol(ac.protocol, reason, message)
self.cleanup_source(ac)


def makeRootWindowModels(self) -> list:
log("makeRootWindowModels()")
return []
Expand All @@ -99,8 +97,7 @@ def makeDynamicWindowModels(self) -> list:
def set_keymap(self, server_source, force=False) -> None:
raise NotImplementedError()


def start_refresh(self, wid:int) -> None:
def start_refresh(self, wid: int) -> None:
self.start_capture()

def start_capture(self) -> None:
Expand All @@ -119,13 +116,12 @@ def cleanup(self) -> None:
GTKShadowServerBase.cleanup(self)
self.portal_interface = None


def stop_session(self) -> None:
s = self.session
if not s:
return
self.session = None
#https://gitlab.gnome.org/-/snippets/1122
# https://gitlab.gnome.org/-/snippets/1122
log(f"trying to close the session {s}")
try:
s.Close(dbus_interface=PORTAL_SESSION_INTERFACE)
Expand All @@ -137,7 +133,7 @@ def create_session(self) -> None:
session_counter += 1
token = f"u{session_counter}"
self.session_path = f"/org/freedesktop/portal/desktop/session/{dbus_sender_name}/{token}"
options : dict[str,Any] = {
options : dict[str, Any] = {
"session_handle_token" : token,
}
log(f"create_session() session_counter={session_counter}")
Expand Down Expand Up @@ -169,7 +165,6 @@ def on_create_session_response(self, response, results) -> None:
def on_session_created(self) -> None:
self.select_devices()


def select_devices(self) -> None:
log("select_devices()")
options = {
Expand All @@ -192,7 +187,6 @@ def on_select_devices_response(self, response, results) -> None:
log(f"on_select_devices_response devices selected, results={res}")
self.select_sources()


def select_sources(self) -> None:
options = {
"multiple" : self.multi_window,
Expand All @@ -216,7 +210,6 @@ def on_select_sources_response(self, response, results) -> None:
log(f"on_select_sources_response sources selected, results={res}")
self.portal_start()


def portal_start(self) -> None:
log("portal_start()")
remotedesktop_dbus_call(
Expand Down Expand Up @@ -245,12 +238,11 @@ def on_start_response(self, response, results) -> None:
self.start_pipewire_capture(int(node_id), typedict(props))
self.input_devices = res.intget("devices")
if not self.input_devices and not self.readonly:
#ss.notify("", nid, "Xpra", 0, "", title, body, [], {}, 10*1000, icon)
# ss.notify("", nid, "Xpra", 0, "", title, body, [], {}, 10*1000, icon)
log.warn("Warning: no input devices,")
log.warn(" keyboard and pointer events cannot be forwarded")


def create_capture_pipeline(self, fd : int, node_id : int, w : int, h : int) -> Capture:
def create_capture_pipeline(self, fd: int, node_id: int, w: int, h: int) -> Capture:
el = get_element_str("pipewiresrc", {
"fd" : fd,
"path" : str(node_id),
Expand All @@ -269,13 +261,13 @@ def create_capture_pipeline(self, fd : int, node_id : int, w : int, h : int) ->
log.info(f"cannot use {encoding}: {e}")
return Capture(el, pixel_format="BGRX", width=w, height=h)

def start_pipewire_capture(self, node_id:int, props:typedict) -> None:
def start_pipewire_capture(self, node_id: int, props: typedict) -> None:
log(f"start_pipewire_capture({node_id}, {props})")
if not isinstance(node_id, int):
raise ValueError(f"node-id is a {type(node_id)}, must be an int")
x, y = props.inttupleget("position", (0, 0))
w, h = props.inttupleget("size", (0, 0))
if w<=0 or h<=0:
if w <= 0 or h <= 0:
raise ValueError(f"invalid dimensions: {w}x{h}")
empty_dict = Dictionary(signature="sv")
fd_object = self.portal_interface.OpenPipeWireRemote(
Expand All @@ -294,12 +286,12 @@ def start_pipewire_capture(self, node_id:int, props:typedict) -> None:
title = f"{AvailableSourceTypes(source_type)} {node_id}"
geometry = (x, y, w, h)
model = PipewireWindowModel(self.root, self.capture, title, geometry, node_id, props)
#must be called from the main thread:
# must be called from the main thread:
log(f"new model: {model}")
self.do_add_new_window_common(node_id, model)
self._send_new_window_packet(model)

def capture_new_image(self, capture, coding:str, data, client_info:dict) -> None:
def capture_new_image(self, capture, coding: str, data, client_info: dict) -> None:
wid = capture.node_id
model = self._id_to_window.get(wid)
log(f"capture_new_image({capture}, {coding}, {type(data)}, {client_info}) model({wid})={model}")
Expand All @@ -312,19 +304,18 @@ def capture_new_image(self, capture, coding:str, data, client_info:dict) -> None
if not isinstance(data, bytes):
log.warn(f"Warning: unexpected image datatype: {type(data)}")
return
#this is a frame from a compressed stream,
#send it to all the window sources for this window:
# this is a frame from a compressed stream,
# send it to all the window sources for this window:
for ss in tuple(self._server_sources.values()):
if not hasattr(ss, "get_window_source"):
#client is not showing any windows
# client is not showing any windows
continue
ws = ss.get_window_source(wid)
if not ws:
#client not showing this window
# client not showing this window
continue
ws.direct_queue_draw(coding, data, client_info)


def capture_error(self, capture, message) -> None:
wid = capture.node_id
log(f"capture_error({capture}, {message}) wid={wid}")
Expand Down
5 changes: 2 additions & 3 deletions xpra/platform/posix/screencast.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ class ScreenCast(PortalShadow):
def get_server_mode(self) -> str:
return "pipewire screencast"


def on_session_created(self) -> None:
#skip select_devices() and go straight to sources then start:
# skip select_devices() and go straight to sources then start:
self.select_sources()

def set_keymap(self, server_source, force=False) -> None:
#no input devices
# no input devices
pass

def do_process_button_action(self, *args) -> None:
Expand Down
Loading

0 comments on commit 8ebe175

Please sign in to comment.