Fix scale + cleanup

This commit is contained in:
Leonhard 2023-09-30 15:51:44 +02:00
parent 5742055d4b
commit 8a8cb84fdb
3 changed files with 33 additions and 113 deletions

View File

@ -51,9 +51,6 @@ namespace Gala {
private Gtk.MenuItem close;
private Gtk.MenuItem screenshot;
// Desktop Menu
private Gtk.Menu? desktop_menu = null;
private WMDBus? wm_proxy = null;
private ulong always_on_top_sid = 0U;
@ -292,76 +289,5 @@ namespace Gala {
return opened ? Source.REMOVE : Source.CONTINUE;
});
}
public void show_desktop_menu (int x, int y) throws DBusError, IOError {
if (desktop_menu == null) {
var change_wallpaper = new Gtk.MenuItem.with_label (_("Change Wallpaper…"));
change_wallpaper.activate.connect (() => {
try {
AppInfo.launch_default_for_uri ("settings://desktop/appearance/wallpaper", null);
} catch (Error e) {
var message_dialog = new Granite.MessageDialog.with_image_from_icon_name (
"Failed to Open Wallpaper Settings",
"Unable 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.run ();
message_dialog.destroy ();
}
});
var display_settings = new Gtk.MenuItem.with_label (_("Display Settings…"));
display_settings.activate.connect (() => {
try {
AppInfo.launch_default_for_uri ("settings://display", null);
} catch (Error e) {
var message_dialog = new Granite.MessageDialog.with_image_from_icon_name (
"Failed to Open Display Settings",
"Unable to open System Settings. A handler for the `settings://` URI scheme must be installed.",
"dialog-warning",
Gtk.ButtonsType.CLOSE
);
message_dialog.show_error_details (e.message);
message_dialog.run ();
message_dialog.destroy ();
}
});
var system_settings = new Gtk.MenuItem.with_label (_("System Settings…"));
system_settings.activate.connect (() => {
try {
AppInfo.launch_default_for_uri ("settings://", null);
} catch (Error e) {
var message_dialog = new Granite.MessageDialog.with_image_from_icon_name (
"Failed to Open System Settings",
"Unable to open System Settings. A handler for the `settings://` URI scheme must be installed.",
"dialog-warning",
Gtk.ButtonsType.CLOSE
);
message_dialog.show_error_details (e.message);
message_dialog.run ();
message_dialog.destroy ();
}
});
desktop_menu = new Gtk.Menu ();
desktop_menu.append (change_wallpaper);
desktop_menu.append (display_settings);
desktop_menu.append (new Gtk.SeparatorMenuItem ());
desktop_menu.append (system_settings);
desktop_menu.show_all ();
}
desktop_menu.popup (null, null, (m, ref px, ref py, out push_in) => {
var scale = m.scale_factor;
px = x / scale;
// Move the menu 1 pixel outside of the pointer or else it closes instantly
// on the mouse up event
py = (y / scale) + 1;
push_in = false;
}, Gdk.BUTTON_SECONDARY, Gdk.CURRENT_TIME);
}
}
}

View File

@ -92,7 +92,7 @@ public class Gala.Menu : Clutter.Actor {
container.margin_top = container.margin_bottom = InternalUtils.scale_to_int (6, scale_factor);
foreach (var child in get_children ()) {
foreach (var child in container.get_children ()) {
if (child is MenuItem) {
((MenuItem) child).scale (scale_factor);
continue;

View File

@ -22,7 +22,6 @@ namespace Gala {
[DBus (name = "org.pantheon.gala.daemon")]
public interface Daemon: GLib.Object {
public abstract async void show_window_menu (WindowFlags flags, int x, int y) throws Error;
public abstract async void show_desktop_menu (int x, int y) throws Error;
}
public class WindowManagerGala : Meta.Plugin, WindowManager {
@ -982,53 +981,48 @@ namespace Gala {
public override void show_window_menu (Meta.Window window, Meta.WindowMenuType menu, int x, int y) {
switch (menu) {
case Meta.WindowMenuType.WM:
warning ("CREATE MENU");
var window_menu = new BackgroundMenu (this);
ui_group.add_child (window_menu);
window_menu.set_position (x, y);
window_menu.open_menu ();
// if (daemon_proxy == null || window.get_window_type () == Meta.WindowType.NOTIFICATION) {
// return;
// }
if (daemon_proxy == null || window.get_window_type () == Meta.WindowType.NOTIFICATION) {
return;
}
// WindowFlags flags = WindowFlags.NONE;
// if (window.can_minimize ())
// flags |= WindowFlags.CAN_HIDE;
WindowFlags flags = WindowFlags.NONE;
if (window.can_minimize ())
flags |= WindowFlags.CAN_HIDE;
// if (window.can_maximize ())
// flags |= WindowFlags.CAN_MAXIMIZE;
if (window.can_maximize ())
flags |= WindowFlags.CAN_MAXIMIZE;
// var maximize_flags = window.get_maximized ();
// if (maximize_flags > 0) {
// flags |= WindowFlags.IS_MAXIMIZED;
var maximize_flags = window.get_maximized ();
if (maximize_flags > 0) {
flags |= WindowFlags.IS_MAXIMIZED;
// if (Meta.MaximizeFlags.VERTICAL in maximize_flags && !(Meta.MaximizeFlags.HORIZONTAL in maximize_flags)) {
// flags |= WindowFlags.IS_TILED;
// }
// }
if (Meta.MaximizeFlags.VERTICAL in maximize_flags && !(Meta.MaximizeFlags.HORIZONTAL in maximize_flags)) {
flags |= WindowFlags.IS_TILED;
}
}
// if (window.allows_move ())
// flags |= WindowFlags.ALLOWS_MOVE;
if (window.allows_move ())
flags |= WindowFlags.ALLOWS_MOVE;
// if (window.allows_resize ())
// flags |= WindowFlags.ALLOWS_RESIZE;
if (window.allows_resize ())
flags |= WindowFlags.ALLOWS_RESIZE;
// if (window.is_above ())
// flags |= WindowFlags.ALWAYS_ON_TOP;
if (window.is_above ())
flags |= WindowFlags.ALWAYS_ON_TOP;
// if (window.on_all_workspaces)
// flags |= WindowFlags.ON_ALL_WORKSPACES;
if (window.on_all_workspaces)
flags |= WindowFlags.ON_ALL_WORKSPACES;
// if (window.can_close ())
// flags |= WindowFlags.CAN_CLOSE;
if (window.can_close ())
flags |= WindowFlags.CAN_CLOSE;
// daemon_proxy.show_window_menu.begin (flags, x, y, (obj, res) => {
// try {
// ((Daemon) obj).show_window_menu.end (res);
// } catch (Error e) {
// message ("Error invoking MenuManager: %s", e.message);
// }
// });
daemon_proxy.show_window_menu.begin (flags, x, y, (obj, res) => {
try {
((Daemon) obj).show_window_menu.end (res);
} catch (Error e) {
message ("Error invoking MenuManager: %s", e.message);
}
});
break;
case Meta.WindowMenuType.APP:
// FIXME we don't have any sort of app menus