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

Daemon: Implement monitor labels #1861

Merged
merged 3 commits into from
Feb 19, 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
30 changes: 29 additions & 1 deletion daemon/MenuDaemon.vala → daemon/DBus.vala
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,17 @@ public interface Gala.WMDBus : GLib.Object {
public abstract void perform_action (Gala.ActionType type) throws DBusError, IOError;
}

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

[DBus (name = "org.pantheon.gala.daemon")]
public class Gala.Daemon.MenuDaemon : GLib.Object {
public class Gala.Daemon.DBus : GLib.Object {
private const string DBUS_NAME = "org.pantheon.gala";
private const string DBUS_OBJECT_PATH = "/org/pantheon/gala";

Expand All @@ -21,6 +30,8 @@ public class Gala.Daemon.MenuDaemon : GLib.Object {
private WindowMenu? window_menu;
private BackgroundMenu? background_menu;

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

construct {
Bus.watch_name (BusType.SESSION, DBUS_NAME, BusNameWatcherFlags.NONE, gala_appeared, lost_gala);
}
Expand Down Expand Up @@ -102,4 +113,21 @@ public class Gala.Daemon.MenuDaemon : GLib.Object {
});
}
}

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 ();
}
}
}
6 changes: 5 additions & 1 deletion daemon/Main.vala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ public class Gala.Daemon.Application : Gtk.Application {
granite_settings.notify["prefers-color-scheme"].connect (() => {
gtk_settings.gtk_application_prefer_dark_theme = granite_settings.prefers_color_scheme == Granite.Settings.ColorScheme.DARK;
});

var app_provider = new Gtk.CssProvider ();
app_provider.load_from_resource ("io/elementary/desktop/gala-daemon/gala-daemon.css");
Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), app_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
}

public override void activate () {
Expand All @@ -28,7 +32,7 @@ public class Gala.Daemon.Application : Gtk.Application {
public override bool dbus_register (DBusConnection connection, string object_path) throws Error {
base.dbus_register (connection, object_path);

connection.register_object (object_path, new MenuDaemon ());
connection.register_object (object_path, new DBus ());

return true;
}
Expand Down
57 changes: 57 additions & 0 deletions daemon/MonitorLabel.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 2024 elementary, Inc. (https://elementary.io)
* SPDX-License-Identifier: LGPL-3.0-or-later
*/

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

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 ();
}
}
7 changes: 1 addition & 6 deletions daemon/Window.vala
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@
*/

public class Gala.Daemon.Window : Gtk.Window {
static construct {
var app_provider = new Gtk.CssProvider ();
app_provider.load_from_resource ("io/elementary/desktop/gala-daemon/gala-daemon.css");
Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), app_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
}

public Gtk.Box content { get; construct; }

public Window (int width, int height) {
Expand All @@ -37,6 +31,7 @@ public class Gala.Daemon.Window : Gtk.Window {
type_hint = Gdk.WindowTypeHint.DOCK;
set_keep_above (true);

title = "MODAL";
child = content = new Gtk.Box (HORIZONTAL, 0) {
hexpand = true,
vexpand = true
Expand Down
7 changes: 4 additions & 3 deletions daemon/meson.build
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
gala_daemon_sources = files(
'Main.vala',
'MenuDaemon.vala',
'DBus.vala',
'MonitorLabel.vala',
'Window.vala',
'WindowMenu.vala',
'BackgroundMenu.vala'
'BackgroundMenu.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,
)
15 changes: 15 additions & 0 deletions data/gala-daemon.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,18 @@
daemon-window {
background-color: transparent;
}

/* For better dark style support */
@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;
}

window.colored {
background-color: alpha (@BG_COLOR, 0.8);
}
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)
sqlite3_dep = dependency('sqlite3')
Expand Down
27 changes: 25 additions & 2 deletions src/DaemonManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,31 @@ public class Gala.DaemonManager : GLib.Object {
}

private void handle_daemon_window (Meta.Window window) {
window.move_frame (false, 0, 0);
window.make_above ();
var info = window.title.split ("-");

if (info.length == 0) {
critical ("Couldn't handle daemon window: No title provided");
return;
}

switch (info[0]) {
case "LABEL":
if (info.length < 2) {
return;
}

var index = int.parse (info[1]);

var monitor_geometry = display.get_monitor_geometry (index);
window.move_frame (false, monitor_geometry.x + SPACING, monitor_geometry.y + SPACING);
window.make_above ();
break;

case "MODAL":
window.move_frame (false, 0, 0);
window.make_above ();
break;
}
}

private void lost_daemon () {
Expand Down