#!/usr/bin/env python3 # Copyright (c) 2026 Storm Dragon # Authors: Storm Dragon, Angus Kola # SPDX-License-Identifier: GPL-3.0-or-later """Real GTK socket/plug embedding on separate providers for private tests.""" import ctypes import os import sys import gi gi.require_version("Gtk", "3.0") gi.require_version("Atk", "1.0") gi.require_version("GdkX11", "3.0") from gi.repository import Atk, GdkX11, GLib, Gtk mode = sys.argv[1] processName = "mate-panel" if mode == "panel" else "applet" if mode == "standalone" else mode GLib.set_prgname(processName) if ctypes.CDLL(None).prctl(15, processName.encode(), 0, 0, 0) != 0: raise RuntimeError("cannot set fixture process name") window = Gtk.Plug.new(int(sys.argv[2])) if mode == "applet" else Gtk.Window() if mode == "applet": window.connect("delete-event", lambda *_args: True) if mode == "standalone": Atk.get_root().set_name("mate-panel") window.set_title("Embedded applet fixture " + mode) window.set_default_size(400, 120) box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) window.add(box) socket = None if mode in ("applet", "standalone"): box.get_accessible().set_role(Atk.Role.PANEL) box.get_accessible().set_name("Network applet") first = Gtk.Button(label="Network") first.get_accessible().set_role(Atk.Role.ICON) first.get_accessible().set_name("") second = Gtk.Button(label="Applet settings") box.add(first) box.add(second) elif mode == "editor": first = Gtk.Entry() first.get_accessible().set_name("Editor entry") box.add(first) else: first = Gtk.Button(label="Before applet") second = Gtk.Button(label="After applet") socket = Gtk.Socket() box.add(first) box.add(socket) box.add(second) barrier = Gtk.Label() barrier.get_accessible().set_role(Atk.Role.ALERT) box.add(barrier) window.show_all() pendingInput = "" def receive_command(_source, _condition): global pendingInput content = os.read(sys.stdin.fileno(), 4096) if not content: Gtk.main_quit() return False pendingInput += content.decode() while "\n" in pendingInput: command, pendingInput = pendingInput.split("\n", 1) if command == "first": first.grab_focus() elif command == "second": second.grab_focus() elif command == "stale": first.get_accessible().notify_state_change(Atk.StateType.FOCUSED, True) barrier.set_text("") barrier.set_text("Applet barrier") elif command == "detach": socket.destroy() barrier.set_text("Detached host barrier") elif command.startswith("edit "): first.set_text(command.removeprefix("edit ")) first.grab_focus() elif command == "quit": Gtk.main_quit() return False return True GLib.io_add_watch(sys.stdin, GLib.IO_IN | GLib.IO_HUP, receive_command) GLib.idle_add(lambda: print( "ready", GdkX11.X11Window.get_xid(window.get_window()), socket.get_id() if socket is not None else 0, flush=True) or False) Gtk.main()