Skip to content

Commit

Permalink
Fix X and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
leolost2605 committed Sep 18, 2024
1 parent 626b0e4 commit 44fda80
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 89 deletions.
80 changes: 24 additions & 56 deletions src/PanelWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@ public class Wingpanel.PanelWindow : Gtk.Window {
public Services.PopoverManager popover_manager;

private Widgets.Panel panel;
private Gtk.EventControllerKey key_controller; // For keeping in memory
private Gtk.Revealer revealer;
private int monitor_width;
private int monitor_height;
private int panel_height;
private bool expanded = false;

private Pantheon.Desktop.Shell? desktop_shell;
private Pantheon.Desktop.Panel? desktop_panel;
Expand All @@ -43,7 +38,7 @@ public class Wingpanel.PanelWindow : Gtk.Window {
app_provider.load_from_resource ("io/elementary/wingpanel/Application.css");
Gtk.StyleContext.add_provider_for_display (Gdk.Display.get_default (), app_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);

popover_manager = new Services.PopoverManager (this);
popover_manager = new Services.PopoverManager ();

panel = new Widgets.Panel (popover_manager);
panel.realize.connect (on_realize);
Expand All @@ -59,19 +54,29 @@ public class Wingpanel.PanelWindow : Gtk.Window {
application.set_accels_for_action ("app.cycle", {"<Control>Tab"});
application.set_accels_for_action ("app.cycle-back", {"<Control><Shift>Tab"});

revealer = new Gtk.Revealer () {
child = panel,
reveal_child = true,
transition_type = NONE
};
child = panel;

child = revealer;
popover_manager.notify["indicator-open"].connect (() => {
if (!popover_manager.indicator_open) {
Services.BackgroundManager.get_default ().restore_window ();
return;
} else {
Services.BackgroundManager.get_default ().remember_window ();
}

if (desktop_panel != null) {
desktop_panel.focus ();
} else if (Gdk.Display.get_default () is Gdk.X11.Display) {
var display = (Gdk.X11.Display) Gdk.Display.get_default ();
var surface = (Gdk.X11.Surface) get_surface ();

display.get_xdisplay ().set_input_focus (surface.get_xid (), 0, 0);
}
});

key_controller = new Gtk.EventControllerKey ();
var key_controller = new Gtk.EventControllerKey ();
((Gtk.Widget) this).add_controller (key_controller);
key_controller.key_pressed.connect (on_key_pressed);

panel.map.connect (update_panel_dimensions);
}

private void on_realize () {
Expand All @@ -98,10 +103,7 @@ public class Wingpanel.PanelWindow : Gtk.Window {
monitor_dimensions.y /= get_scale_factor ();
}

monitor_width = monitor_dimensions.width;
monitor_height = monitor_dimensions.height;

this.set_size_request (monitor_width, (popover_manager.current_indicator != null ? monitor_height : -1));
this.set_size_request (monitor_dimensions.width, -1);
}

private bool on_key_pressed (uint keyval, uint keycode, Gdk.ModifierType state) {
Expand All @@ -112,43 +114,8 @@ public class Wingpanel.PanelWindow : Gtk.Window {
return Gdk.EVENT_PROPAGATE;
}

public void set_expanded (bool expand) {
if (Gdk.Display.get_default () is Gdk.Wayland.Display) {
return;
}

if (expand && !this.expanded) {
Services.BackgroundManager.get_default ().remember_window ();

this.expanded = true;
this.set_size_request (monitor_width, monitor_height);

if (desktop_panel != null) {
desktop_panel.focus ();
}
} else if (!expand) {
Services.BackgroundManager.get_default ().restore_window ();

this.expanded = false;
this.set_size_request (monitor_width, -1);
this.set_default_size (monitor_width, 1);
}
}

public void toggle_indicator (string name) {
popover_manager.toggle_popover_visible (name);

if (desktop_panel != null) {
desktop_panel.focus ();
}
}

private int get_actual_height () {
if (!Services.DisplayConfig.is_logical_layout () && Gdk.Display.get_default () is Gdk.Wayland.Display) {
return get_allocated_height () * get_scale_factor ();
}

return get_allocated_height ();
}

private void init_x () {
Expand All @@ -160,9 +127,11 @@ public class Wingpanel.PanelWindow : Gtk.Window {

var prop = xdisplay.intern_atom ("_MUTTER_HINTS", false);

var value = "anchor=4:hide-mode=0:size=-1,%d".printf (get_actual_height ());
var value = "anchor=4:hide-mode=0";

xdisplay.change_property (window, prop, X.XA_STRING, 8, 0, (uchar[]) value, value.length);

Idle.add_once (update_panel_dimensions); // Update again since we now can be 100% sure that we are on the primary monitor
}
}

Expand All @@ -175,7 +144,6 @@ public class Wingpanel.PanelWindow : Gtk.Window {
desktop_panel = desktop_shell.get_panel (wl_surface);
desktop_panel.set_anchor (TOP);
desktop_panel.set_hide_mode (NEVER);
desktop_panel.set_size (-1, get_actual_height ());

Idle.add_once (update_panel_dimensions); // Update again since we now can be 100% sure that we are on the primary monitor
}
Expand Down
33 changes: 5 additions & 28 deletions src/Services/PopoverManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
*/

public class Wingpanel.Services.PopoverManager : Object {
private unowned Wingpanel.PanelWindow? owner;

private Gtk.GestureClick owner_gesture_controller;
public bool indicator_open { get; private set; default = false; }

private Gee.HashMap<string, Wingpanel.Widgets.IndicatorEntry> registered_indicators;
private Wingpanel.Widgets.IndicatorPopover popover;
Expand All @@ -36,8 +34,10 @@ public class Wingpanel.Services.PopoverManager : Object {
}

if (_current_indicator == null && value != null) { // First open
indicator_open = true;
_current_indicator = value;
} else if (value == null && _current_indicator != null) { // Close requested
indicator_open = false;
_current_indicator.base_indicator.closed ();
_current_indicator = null;
} else if (_current_indicator.base_indicator.code_name == value.base_indicator.code_name) { // Close due to toggle
Expand All @@ -49,13 +49,9 @@ public class Wingpanel.Services.PopoverManager : Object {
_current_indicator = value;
}

popover.unparent ();

if (_current_indicator != null) {
popover.set_content (_current_indicator.indicator_widget);
update_has_tooltip (_current_indicator.display_widget, false);
owner.set_expanded (true);
owner.present ();
popover.set_parent (_current_indicator);
popover.popup ();
_current_indicator.base_indicator.opened ();
Expand All @@ -66,34 +62,15 @@ public class Wingpanel.Services.PopoverManager : Object {
}
}

public PopoverManager (Wingpanel.PanelWindow? owner) {
public PopoverManager () {
registered_indicators = new Gee.HashMap<string, Wingpanel.Widgets.IndicatorEntry> ();

this.owner = owner;

popover = new Wingpanel.Widgets.IndicatorPopover ();

popover.closed.connect (() => {
current_indicator = null;

// We have to wait for unmap otherwise the popover is confined to the panel space
// on X. But we also can't just connect to it because unmap gets emitted when repositioning
// for some reason.
ulong handler_id = 0;
handler_id = popover.unmap.connect (() => {
owner.set_expanded (false);
popover.disconnect (handler_id);
});
popover.unparent ();
});

owner_gesture_controller = new Gtk.GestureClick () {
propagation_limit = SAME_NATIVE
};
((Gtk.Widget) owner).add_controller (owner_gesture_controller);
owner_gesture_controller.pressed.connect (() => current_indicator = null);

//Replace with EventController propagation limit SAME_NATIVE in GTK 4
// owner.realize.connect (() => owner_gesture_controller.window = owner.get_window ());
}

public void set_popover_visible (string code_name, bool visible) {
Expand Down
15 changes: 10 additions & 5 deletions src/Widgets/Panel.vala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* Boston, MA 02110-1301 USA.
*/

public class Wingpanel.Widgets.Panel : Gtk.Box {
public class Wingpanel.Widgets.Panel : Gtk.Widget {
private static Settings panel_settings = new Settings ("io.elementary.desktop.wingpanel");

public Services.PopoverManager popover_manager { get; construct; }
Expand All @@ -26,6 +26,8 @@ public class Wingpanel.Widgets.Panel : Gtk.Box {
private IndicatorBar left_menubar;
private IndicatorBar center_menubar;

private Gtk.CenterBox box;

private unowned Gtk.StyleContext style_context;
private Gtk.CssProvider? style_provider = null;

Expand All @@ -39,6 +41,7 @@ public class Wingpanel.Widgets.Panel : Gtk.Box {

class construct {
set_css_name ("panel");
set_layout_manager_type (typeof (Gtk.BinLayout));
}

construct {
Expand All @@ -57,14 +60,12 @@ public class Wingpanel.Widgets.Panel : Gtk.Box {
halign = END
};

var box = new Gtk.CenterBox () {
hexpand = true
};
box = new Gtk.CenterBox ();
box.set_start_widget (left_menubar);
box.set_center_widget (center_menubar);
box.set_end_widget (right_menubar);

append (box);
box.set_parent (this);

unowned IndicatorManager indicator_manager = IndicatorManager.get_default ();
indicator_manager.indicator_added.connect (add_indicator);
Expand Down Expand Up @@ -108,6 +109,10 @@ public class Wingpanel.Widgets.Panel : Gtk.Box {
});
}

~Panel () {
box.unparent ();
}

private void begin_drag (double x, double y) {
var window = get_root ().get_surface ();
if (window == null) {
Expand Down

0 comments on commit 44fda80

Please sign in to comment.