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 menus #1844

Merged
merged 39 commits into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
f20410b
Start daemon via wayland client
leolost2605 Jan 16, 2024
65cdae6
Update desktop file
leolost2605 Jan 16, 2024
9a095be
Minor improvements
leolost2605 Jan 20, 2024
95ae6cf
Ignore when running under x
leolost2605 Jan 21, 2024
ff6e027
Only init on wayland
leolost2605 Jan 21, 2024
47e89da
Make it work but sloppy
leolost2605 Jan 22, 2024
156b060
Add missing file
leolost2605 Jan 22, 2024
98c8e72
Fix wayland
leolost2605 Jan 22, 2024
87d38c1
Start it ourselves always and switch to gtk.application
leolost2605 Jan 22, 2024
e499139
Merge branch 'master' into wayland-daemon-display-labels
leolost2605 Jan 22, 2024
eec54fb
Updates + license
leolost2605 Jan 22, 2024
40b7abd
Lint stuff
leolost2605 Jan 22, 2024
08660ce
More formatting
leolost2605 Jan 22, 2024
d0f287d
Hdy dep + formatting and error catching
leolost2605 Jan 22, 2024
dabbd0a
Lint
leolost2605 Jan 22, 2024
6f707ac
Fix development target
leolost2605 Jan 22, 2024
4c072b1
Add wayland menus mock
leolost2605 Jan 24, 2024
3045d4c
fix position of menu
leolost2605 Feb 6, 2024
553525c
Improve menu appearance a bit
leolost2605 Feb 6, 2024
47ec9d8
Merge branch 'master' into wayland-menus
leolost2605 Feb 6, 2024
763d90b
Make window invisible
leolost2605 Feb 7, 2024
dafa865
More improvements
leolost2605 Feb 7, 2024
35bfe53
Make it great
leolost2605 Feb 8, 2024
d1c8994
Add background menu, misc fixes
leolost2605 Feb 8, 2024
33f321c
License, lint and namespace stuff
leolost2605 Feb 8, 2024
b15dc17
Add back locale setting
leolost2605 Feb 8, 2024
c3433ea
Cleanup
leolost2605 Feb 8, 2024
750dbee
Restart daemon on wayland as well
leolost2605 Feb 8, 2024
3d99e72
Fix wrong order
leolost2605 Feb 8, 2024
8f59e52
Fix lint
leolost2605 Feb 8, 2024
b1ace45
Merge branch 'master' into wayland-menus
leolost2605 Feb 8, 2024
d8e7cde
Switch to has mutter 44
leolost2605 Feb 8, 2024
5a81fa8
Merge branch 'master' into wayland-menus
leolost2605 Feb 10, 2024
ff61063
Update POTFILES
leolost2605 Feb 12, 2024
2cce87d
BackgroundMenu: use actions (#1853)
danirabbit Feb 12, 2024
44f8bbd
Merge branch 'master' into wayland-menus
leolost2605 Feb 14, 2024
3b2d39b
Apply suggestions from code review
leolost2605 Feb 17, 2024
40104e1
Start on construct
leolost2605 Feb 17, 2024
6765d33
Merge branch 'master' into wayland-menus
leolost2605 Feb 17, 2024
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
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);
}
}
}
177 changes: 31 additions & 146 deletions daemon/Main.vala
Original file line number Diff line number Diff line change
@@ -1,160 +1,45 @@
//
// 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);
}
}
});
}

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 MenuDaemon ());

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