Skip to content

Commit

Permalink
Merge branch 'master' into leolost/barrier
Browse files Browse the repository at this point in the history
  • Loading branch information
leolost2605 authored Mar 13, 2024
2 parents 3015ed9 + 0a2d54f commit 2d275e3
Show file tree
Hide file tree
Showing 254 changed files with 9,525 additions and 7,258 deletions.
57 changes: 57 additions & 0 deletions daemon/BackgroundMenu.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: GPL-3.0-or-later
*/

public class Gala.Daemon.BackgroundMenu : Gtk.Menu {
public const string ACTION_GROUP_PREFIX = "background-menu";
public const string ACTION_PREFIX = ACTION_GROUP_PREFIX + ".";

construct {
var change_wallpaper = new Gtk.MenuItem.with_label (_("Change Wallpaper…")) {
action_name = ACTION_PREFIX + "launch-uri",
action_target = new Variant.string ("settings://desktop/appearance/wallpaper")
};

var display_settings = new Gtk.MenuItem.with_label (_("Display Settings…")) {
action_name = ACTION_PREFIX + "launch-uri",
action_target = new Variant.string ("settings://display")
};


var system_settings = new Gtk.MenuItem.with_label (_("System Settings…")) {
action_name = ACTION_PREFIX + "launch-uri",
action_target = new Variant.string ("settings://")
};

append (change_wallpaper);
append (display_settings);
append (new Gtk.SeparatorMenuItem ());
append (system_settings);
show_all ();

var launch_action = new SimpleAction ("launch-uri", VariantType.STRING);
launch_action.activate.connect (action_launch);

var action_group = new SimpleActionGroup ();
action_group.add_action (launch_action);

insert_action_group (ACTION_GROUP_PREFIX, action_group);
}

private void action_launch (SimpleAction action, Variant? variant) {
try {
AppInfo.launch_default_for_uri (variant.get_string (), null);
} catch (Error e) {
var message_dialog = new Granite.MessageDialog.with_image_from_icon_name (
_("Failed to open System Settings"),
_("A handler for the “settings://” URI scheme must be installed."),
"dialog-error",
Gtk.ButtonsType.CLOSE
);
message_dialog.show_error_details (e.message);
message_dialog.present ();
message_dialog.response.connect (message_dialog.destroy);
}
}
}
133 changes: 133 additions & 0 deletions daemon/DBus.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*
* Copyright 2024 elementary, Inc. (https://elementary.io)
* SPDX-License-Identifier: GPL-3.0-or-later
*/

[DBus (name = "org.pantheon.gala")]
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.DBus : GLib.Object {
private const string DBUS_NAME = "org.pantheon.gala";
private const string DBUS_OBJECT_PATH = "/org/pantheon/gala";

private const string DAEMON_DBUS_NAME = "org.pantheon.gala.daemon";
private const string DAEMON_DBUS_OBJECT_PATH = "/org/pantheon/gala/daemon";

private WMDBus? wm_proxy = null;

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);
}

private void on_gala_get (GLib.Object? obj, GLib.AsyncResult? res) {
try {
wm_proxy = Bus.get_proxy.end (res);
} catch (Error e) {
warning ("Failed to get Gala proxy: %s", e.message);
}
}

private void lost_gala () {
wm_proxy = null;
}

private void gala_appeared () {
if (wm_proxy == null) {
Bus.get_proxy.begin<WMDBus> (BusType.SESSION, DBUS_NAME, DBUS_OBJECT_PATH, 0, null, on_gala_get);
}
}

private void perform_action (Gala.ActionType type) {
if (wm_proxy != null) {
try {
wm_proxy.perform_action (type);
} catch (Error e) {
warning ("Failed to perform Gala action over DBus: %s", e.message);
}
}
}

public void show_window_menu (Gala.WindowFlags flags, int display_width, int display_height, int x, int y) throws DBusError, IOError {
if (window_menu == null) {
window_menu = new WindowMenu ();
window_menu.perform_action.connect (perform_action);
}

window_menu.update (flags);

show_menu (window_menu, display_width, display_height, x, y, true);
}

public void show_desktop_menu (int display_width, int display_height, int x, int y) throws DBusError, IOError {
if (background_menu == null) {
background_menu = new BackgroundMenu ();
}

show_menu (background_menu, display_width, display_height, x, y, false);
}

private void show_menu (Gtk.Menu menu, int display_width, int display_height, int x, int y, bool ignore_first_release) {
var window = new Window (display_width, display_height);
window.present ();

menu.attach_to_widget (window.content, null);

Gdk.Rectangle rect = {
x,
y,
0,
0
};

menu.show_all ();
menu.popup_at_rect (window.get_window (), rect, NORTH, NORTH_WEST);

menu.deactivate.connect (window.close);

if (ignore_first_release) {
bool first = true;
menu.button_release_event.connect (() => {
if (first) {
first = false;
return Gdk.EVENT_STOP;
}

return Gdk.EVENT_PROPAGATE;
});
}
}

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 ();
}
}
}
179 changes: 34 additions & 145 deletions daemon/Main.vala
Original file line number Diff line number Diff line change
@@ -1,160 +1,49 @@
//
// Copyright (c) 2018 elementary LLC. (https://elementary.io)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

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 ();
/*
* Copyright 2024 elementary, Inc. (https://elementary.io)
* SPDX-License-Identifier: GPL-3.0-or-later
*/

public class Gala.Daemon.Application : Gtk.Application {
public Application () {
Object (application_id: "org.pantheon.gala.daemon");
}

public class Daemon {
private SessionClient? sclient = null;
public override void startup () {
base.startup ();

public Daemon () {
register.begin ((o, res)=> {
bool success = register.end (res);
if (!success) {
message ("Failed to register with Session manager");
}
});
var granite_settings = Granite.Settings.get_default ();
var gtk_settings = Gtk.Settings.get_default ();

var granite_settings = Granite.Settings.get_default ();
var gtk_settings = Gtk.Settings.get_default ();
gtk_settings.gtk_application_prefer_dark_theme = granite_settings.prefers_color_scheme == Granite.Settings.ColorScheme.DARK;

granite_settings.notify["prefers-color-scheme"].connect (() => {
gtk_settings.gtk_application_prefer_dark_theme = granite_settings.prefers_color_scheme == Granite.Settings.ColorScheme.DARK;
});

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;
}

private async bool register () {
sclient = yield register_with_session ("org.pantheon.gala.daemon");

sclient.query_end_session.connect (() => end_session (false));
sclient.end_session.connect (() => end_session (false));
sclient.stop.connect (() => end_session (true));

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);
}
}
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 static int main (string[] args) {
GLib.Intl.setlocale (LocaleCategory.ALL, "");
GLib.Intl.bindtextdomain (Config.GETTEXT_PACKAGE, Config.LOCALEDIR);
GLib.Intl.bind_textdomain_codeset (Config.GETTEXT_PACKAGE, "UTF-8");
GLib.Intl.textdomain (Config.GETTEXT_PACKAGE);
public override void activate () {
hold ();
}

Gtk.init (ref args);
public override bool dbus_register (DBusConnection connection, string object_path) throws Error {
base.dbus_register (connection, object_path);

var ctx = new OptionContext ("Gala Daemon");
ctx.set_help_enabled (true);
ctx.add_group (Gtk.get_option_group (false));
connection.register_object (object_path, new DBus ());

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

var daemon = new Daemon ();
daemon.run ();
public static int main (string[] args) {
GLib.Intl.setlocale (LocaleCategory.ALL, "");
GLib.Intl.bindtextdomain (Config.GETTEXT_PACKAGE, Config.LOCALEDIR);
GLib.Intl.bind_textdomain_codeset (Config.GETTEXT_PACKAGE, "UTF-8");
GLib.Intl.textdomain (Config.GETTEXT_PACKAGE);

return 0;
}
var app = new Gala.Daemon.Application ();
return app.run ();
}
Loading

0 comments on commit 2d275e3

Please sign in to comment.