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

Wayland daemon display labels #1840

Closed
wants to merge 17 commits into from
Closed
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
127 changes: 13 additions & 114 deletions daemon/Main.vala
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,13 @@
//

namespace Gala {
[DBus (name = "org.gnome.SessionManager")]
public interface SessionManager : Object {
public abstract async ObjectPath register_client (
string app_id,
string client_start_id
) throws DBusError, IOError;
}

[DBus (name = "org.gnome.SessionManager.ClientPrivate")]
public interface SessionClient : Object {
public abstract void end_session_response (bool is_ok, string reason) throws DBusError, IOError;

public signal void stop () ;
public signal void query_end_session (uint flags);
public signal void end_session (uint flags);
public signal void cancel_end_session ();
}

public class Daemon {
private SessionClient? sclient = null;
public class Daemon.Application : Gtk.Application {
public Application () {
Object (application_id: "org.pantheon.gala.daemon");
}

public Daemon () {
register.begin ((o, res)=> {
bool success = register.end (res);
if (!success) {
message ("Failed to register with Session manager");
}
});
public override void startup () {
base.startup ();

var granite_settings = Granite.Settings.get_default ();
var gtk_settings = Gtk.Settings.get_default ();
Expand All @@ -53,84 +32,19 @@ namespace Gala {
granite_settings.notify["prefers-color-scheme"].connect (() => {
gtk_settings.gtk_application_prefer_dark_theme = granite_settings.prefers_color_scheme == Granite.Settings.ColorScheme.DARK;
});

var menu_daemon = new MenuDaemon ();
menu_daemon.setup_dbus ();
}

public void run () {
Gtk.main ();
}

public static async SessionClient? register_with_session (string app_id) {
ObjectPath? path = null;
string? msg = null;
string? start_id = null;

SessionManager? session = null;
SessionClient? session_client = null;

start_id = Environment.get_variable ("DESKTOP_AUTOSTART_ID");
if (start_id != null) {
Environment.unset_variable ("DESKTOP_AUTOSTART_ID");
} else {
start_id = "";
warning (
"DESKTOP_AUTOSTART_ID not set, session registration may be broken (not running via session?)"
);
}

try {
session = yield Bus.get_proxy (
BusType.SESSION,
"org.gnome.SessionManager",
"/org/gnome/SessionManager"
);
} catch (Error e) {
warning ("Unable to connect to session manager: %s", e.message);
return null;
}

try {
path = yield session.register_client (app_id, start_id);
} catch (Error e) {
msg = e.message;
warning ("Error registering with session manager: %s", e.message);
return null;
}

try {
session_client = yield Bus.get_proxy (BusType.SESSION, "org.gnome.SessionManager", path);
} catch (Error e) {
warning ("Unable to get private sessions client proxy: %s", e.message);
return null;
}

return session_client;
public override void activate () {
hold ();
}

private async bool register () {
sclient = yield register_with_session ("org.pantheon.gala.daemon");
public override bool dbus_register (DBusConnection connection, string object_path) throws Error {
base.dbus_register (connection, object_path);

sclient.query_end_session.connect (() => end_session (false));
sclient.end_session.connect (() => end_session (false));
sclient.stop.connect (() => end_session (true));
connection.register_object (object_path, new MenuDaemon ());

return true;
}

private void end_session (bool quit) {
if (quit) {
Gtk.main_quit ();
return;
}

try {
sclient.end_session_response (true, "");
} catch (Error e) {
warning ("Unable to respond to session manager: %s", e.message);
}
}
}

public static int main (string[] args) {
Expand All @@ -139,22 +53,7 @@ namespace Gala {
GLib.Intl.bind_textdomain_codeset (Config.GETTEXT_PACKAGE, "UTF-8");
GLib.Intl.textdomain (Config.GETTEXT_PACKAGE);

Gtk.init (ref args);

var ctx = new OptionContext ("Gala Daemon");
ctx.set_help_enabled (true);
ctx.add_group (Gtk.get_option_group (false));

try {
ctx.parse (ref args);
} catch (Error e) {
stderr.printf ("Error: %s\n", e.message);
return 0;
}

var daemon = new Daemon ();
daemon.run ();

return 0;
var app = new Daemon.Application ();
return app.run ();
}
}
42 changes: 29 additions & 13 deletions daemon/MenuDaemon.vala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@
//

namespace Gala {
public struct MonitorLabelInfo {
public int monitor;
public string label;
public string background_color;
public string text_color;
public int x;
public int y;
}

private const string DBUS_NAME = "org.pantheon.gala";
private const string DBUS_OBJECT_PATH = "/org/pantheon/gala";

Expand Down Expand Up @@ -59,6 +68,8 @@ namespace Gala {
private ulong always_on_top_sid = 0U;
private ulong on_visible_workspace_sid = 0U;

private List<MonitorLabel> monitor_labels = new List<MonitorLabel> ();

private static GLib.Settings keybind_settings;
private static GLib.Settings gala_keybind_settings;

Expand All @@ -67,11 +78,7 @@ namespace Gala {
gala_keybind_settings = new GLib.Settings ("org.pantheon.desktop.gala.keybindings");
}

[DBus (visible = false)]
public void setup_dbus () {
var flags = BusNameOwnerFlags.ALLOW_REPLACEMENT | BusNameOwnerFlags.REPLACE;
Bus.own_name (BusType.SESSION, DAEMON_DBUS_NAME, flags, on_bus_acquired, () => {}, null);

construct {
Bus.watch_name (BusType.SESSION, DBUS_NAME, BusNameWatcherFlags.NONE, gala_appeared, lost_gala);
}

Expand All @@ -93,14 +100,6 @@ namespace Gala {
}
}

private void on_bus_acquired (DBusConnection conn) {
try {
conn.register_object (DAEMON_DBUS_OBJECT_PATH, this);
} catch (Error e) {
stderr.printf ("Error registering MenuDaemon: %s\n", e.message);
}
}

private void perform_action (Gala.ActionType type) {
if (wm_proxy != null) {
try {
Expand Down Expand Up @@ -363,5 +362,22 @@ namespace Gala {
push_in = false;
}, Gdk.BUTTON_SECONDARY, Gdk.CURRENT_TIME);
}

public void show_monitor_labels (MonitorLabelInfo[] label_infos) throws GLib.DBusError, GLib.IOError {
hide_monitor_labels ();

monitor_labels = new List<MonitorLabel> ();
foreach (var info in label_infos) {
var label = new MonitorLabel (info);
monitor_labels.append (label);
label.present ();
}
}

public void hide_monitor_labels () throws GLib.DBusError, GLib.IOError {
foreach (var monitor_label in monitor_labels) {
monitor_label.close ();
}
}
}
}
67 changes: 67 additions & 0 deletions daemon/MonitorLabel.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright 2024 elementary, Inc. (https://elementary.io)
* SPDX-License-Identifier: LGPL-3.0-or-later
*/

public class Gala.MonitorLabel : Hdy.Window {
private const int SPACING = 12;
private const string COLORED_STYLE_CSS = """
@define-color BG_COLOR %s;
@define-color TEXT_COLOR %s;

@define-color BG_COLOR_ALPHA alpha(@BG_COLOR, 0.75);

.colored {
background-color: @BG_COLOR_ALPHA;
color: @TEXT_COLOR;
text-shadow: 0 1px 1px alpha(white, 0.1);
-gtk-icon-shadow: 0 1px 1px alpha(white, 0.1);
-gtk-icon-palette: warning white;
}
""";

public MonitorLabelInfo info { get; construct; }

public MonitorLabel (MonitorLabelInfo info) {
Object (info: info);
}

construct {
child = new Gtk.Label (info.label) {
margin = 12
};

title = "LABEL-%i".printf (info.monitor);

input_shape_combine_region (null);
accept_focus = false;
decorated = false;
resizable = false;
deletable = false;
can_focus = false;
skip_taskbar_hint = true;
skip_pager_hint = true;
type_hint = Gdk.WindowTypeHint.TOOLTIP;
set_keep_above (true);

stick ();

var scale_factor = get_style_context ().get_scale ();
move (
(int) (info.x / scale_factor) + SPACING,
(int) (info.y / scale_factor) + SPACING
);

var provider = new Gtk.CssProvider ();
try {
provider.load_from_data (COLORED_STYLE_CSS.printf (info.background_color, info.text_color));

get_style_context ().add_provider (provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
get_style_context ().add_class ("colored");
} catch (Error e) {
warning ("Failed to load CSS: %s", e.message);
}

show_all ();
}
}
5 changes: 3 additions & 2 deletions daemon/meson.build
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
gala_daemon_sources = files(
'Main.vala',
'MenuDaemon.vala'
'MenuDaemon.vala',
'MonitorLabel.vala'
)

gala_daemon_bin = executable(
'gala-daemon',
gala_daemon_sources,
dependencies: [gala_dep, gala_base_dep],
dependencies: [gala_dep, gala_base_dep, hdy_dep],
include_directories: config_inc_dir,
install: true,
)
14 changes: 0 additions & 14 deletions data/gala-daemon.desktop

This file was deleted.

5 changes: 0 additions & 5 deletions data/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ install_data(
rename: 'org.pantheon.desktop.gala.gschema.xml'
)

install_data(
'gala-daemon.desktop',
install_dir: join_paths(get_option('sysconfdir'), 'xdg', 'autostart')
)

i18n.merge_file(
input: 'gala.metainfo.xml.in',
output: meson.project_name() + '.metainfo.xml',
Expand Down
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ gee_dep = dependency('gee-0.8')
granite_dep = dependency('granite', version: '>= 5.4.0')
gnome_desktop_dep = dependency('gnome-desktop-3.0')
gsd_dep = dependency('gnome-settings-daemon', version: '>= @0@'.format(gsd_version_required))
hdy_dep = dependency('libhandy-1')
m_dep = cc.find_library('m', required: false)
posix_dep = vala.find_library('posix', required: false)
gexiv2_dep = dependency('gexiv2')
Expand Down
Loading