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

OSD capability #657

Merged
merged 11 commits into from
Feb 18, 2025
16 changes: 9 additions & 7 deletions src/daemon/endsession.vala
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ namespace Budgie {
this.cancel_clicked();
return Gdk.EVENT_STOP;
});

GtkLayerShell.init_for_window(this);
GtkLayerShell.set_layer(this, GtkLayerShell.Layer.TOP);
GtkLayerShell.set_anchor(this, GtkLayerShell.Edge.LEFT, false);
GtkLayerShell.set_anchor(this, GtkLayerShell.Edge.TOP, false);
GtkLayerShell.set_keyboard_mode(this, GtkLayerShell.KeyboardMode.ON_DEMAND);
}

public void Open(uint type, uint timestamp, uint open_length, ObjectPath[] inhibiters) throws DBusError, IOError {
Expand Down Expand Up @@ -175,6 +181,8 @@ namespace Budgie {
/* Update the label */
this.label_end_title.set_text(title);

GtkLayerShell.set_monitor(this, new WaylandClient().gdk_monitor);

if (main_show != null) {
/* We have a specific type.. */
for (int i = 0; i < all_widgets.length; i++) {
Expand Down Expand Up @@ -202,13 +210,7 @@ namespace Budgie {

unowned Gdk.Window? win = get_window();
if (win != null) {
Gdk.Display? display = screen.get_display();

if (display is Gdk.X11.Display) {
win.focus(((Gdk.X11.Display) display).get_user_time());
} else {
win.focus(Gtk.get_current_event_time());
}
win.focus(Gtk.get_current_event_time());
}
}

Expand Down
57 changes: 51 additions & 6 deletions src/daemon/manager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,49 @@
*/

namespace Budgie {

/*
The underlying WaylandClient does not appear to be fully thread-safe and either
repeated calls very quickly, or calls within the same process where the
reference was not release will result in mutex-locks causing the daemon to spin
indefinitely.

Our use in the daemon is limited so we can initialise variable we use within
a singleton to make things thread-safe.
*/
[SingleInstance]
public class WaylandClient : GLib.Object {
private unowned libxfce4windowing.Monitor? primary_monitor=null;

public bool is_initialised() { return primary_monitor != null; }
public unowned Gdk.Monitor gdk_monitor {get; private set; }
public Gdk.Rectangle monitor_res { get; private set; }

public WaylandClient() {
if (primary_monitor != null) return;
libxfce4windowing.Screen.get_default().monitors_changed.connect(on_monitors_changed);
on_monitors_changed();
}

void on_monitors_changed() {
int loop = 0;

/* it can take a short-time after first call for the underlying wayland client
to return a reference, so lets loop until we get a reference ... but
don't try indefinitely
*/
Timeout.add(200, ()=> {
primary_monitor = libxfce4windowing.Screen.get_default().get_primary_monitor();
if (primary_monitor != null || loop++ > 10) {
monitor_res = primary_monitor.get_logical_geometry();
gdk_monitor = primary_monitor.get_gdk_monitor();
return false;
}

return true;
});
}
}
/**
* Main lifecycle management, handle all the various session and GTK+ bits
*/
Expand All @@ -18,12 +61,14 @@ namespace Budgie {
/* Keep track of our SessionManager */
private LibSession.SessionClient? sclient;

// define a reference to WaylandClient once for this process
private WaylandClient wayland_client = new WaylandClient();

/* On Screen Display */
Budgie.OSDManager? osd;
Budgie.OSDKeys? osdkeys;
Budgie.Notifications.Server? notifications;
Budgie.StatusNotifier.FreedesktopWatcher? status_notifier;
Budgie.MenuManager? menus;
Budgie.TabSwitcher? switcher;
BudgieScr.ScreenshotServer? screenshotcontrol;
Budgie.XDGDirTracker? xdg_tracker;
Budgie.Background? background;
Expand All @@ -46,14 +91,14 @@ namespace Budgie {
message("Failed to register with Session manager");
}
});

osd = new Budgie.OSDManager();
osd.setup_dbus(replace);
osdkeys = new Budgie.OSDKeys();

notifications = new Budgie.Notifications.Server();
notifications.setup_dbus(replace);
menus = new Budgie.MenuManager();
menus.setup_dbus(replace);
switcher = new Budgie.TabSwitcher();
switcher.setup_dbus(replace);

background = new Budgie.Background();

try {
Expand Down
152 changes: 0 additions & 152 deletions src/daemon/menus.vala

This file was deleted.

13 changes: 6 additions & 7 deletions src/daemon/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,26 @@ daemon_sources = [
'statusnotifier.vala',
'main.vala',
'manager.vala',
'menus.vala',
'nightlight.vala',
'osd.vala',
'settings.vala',
'screenlock.vala',
'tabswitcher.vala',
'xdgdirtracker/dbus.vala',
'osdkeys.vala'
]

daemon_deps = [
dep_canberra,
dep_canberra_gtk3,
dep_giounix,
dep_gtk3,
dep_gdkx11,
dep_notify,
dep_gnomedesktop,
dep_wnck,
dep_xfce4windowing,
dep_gst,
dep_cairo,
gvc.get_variable('libgvc_dep'),
meson.get_compiler('c').find_library('m', required: false),
dep_upower,
link_libbudgieprivate,
libpanelplugin_vapi,
Expand Down Expand Up @@ -90,26 +89,26 @@ executable(
'--pkg', 'budgie-config',
'--pkg', 'gio-unix-2.0',
'--pkg', 'gtk+-3.0',
'--pkg', 'gdk-x11-3.0',
'--pkg', 'libxfce4windowing-0',
'--pkg', 'gvc-1.0',
# Make gresource work
'--target-glib=2.38',
'--gresources=' + gresource,
daemon_vala_args,
],
c_args: [
'-DWNCK_I_KNOW_THIS_IS_UNSTABLE',
'-DGNOME_DESKTOP_USE_UNSTABLE_API'
],
install: true,
install_rpath: rpath_libdir,
)

main_sources = [
'screenshot_main.vala',
]

ScreenshotMainDependencies = [
dependency('gtk+-3.0'),
dep_gtk3,
]

executable(
Expand Down
9 changes: 5 additions & 4 deletions src/daemon/notifications/dbus.vala
Original file line number Diff line number Diff line change
Expand Up @@ -359,12 +359,13 @@
* Configures the location of a notification popup and makes it visible on the screen.
*/
private void configure_window(Popup? popup) {
if (!new WaylandClient().is_initialised()) return;

Gdk.Rectangle mon_rect = new WaylandClient().monitor_res;

GtkLayerShell.init_for_window(popup);
GtkLayerShell.set_layer(popup, GtkLayerShell.Layer.TOP);

var mon = libxfce4windowing.Screen.get_default().get_primary_monitor();
Gdk.Rectangle mon_rect = mon.get_workarea();

ulong handler_id = 0;
handler_id = popup.get_child().size_allocate.connect((alloc) => {
// Disconnect from the signal to avoid trying to recalculate
Expand All @@ -375,7 +376,7 @@

/* determine the y position for the latest notification */
calculate_position(mon_rect.y);
GtkLayerShell.set_monitor(popup, mon.get_gdk_monitor());
GtkLayerShell.set_monitor(popup, new WaylandClient().gdk_monitor);
var pos = (NotificationPosition) this.panel_settings.get_enum("notification-position");
int edge_a, edge_b;

Expand Down
Loading