Skip to content
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
123 changes: 95 additions & 28 deletions src/components/dock/dock.vala
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ namespace Singularity {
private bool _refreshed_once = false;
private bool _intro_pending = false;
private bool _hidden_for_fullscreen = false;
// Set by teardown(), which destroy() runs. A destroyed dock stays alive
// while any closure still references it, and a GTK4 window can be shown
// again after destroy(), so every path that maps the dock checks this.
private bool _disposed = false;
private Singularity.SignalBag _signals = new Singularity.SignalBag();
private ulong _sig_clock = 0;
private bool is_primary = true;
private Gdk.Monitor? gdk_monitor = null;
Expand Down Expand Up @@ -133,12 +138,12 @@ namespace Singularity {
main_container.overflow = Overflow.VISIBLE;
intro_motion = new Singularity.Animation.MotionBin(main_container);
hide_motion = new Singularity.Animation.MotionBin(intro_motion);
HomeCover.get_default().shift_changed.connect((m, shift) => {
_signals.add(HomeCover.get_default(), HomeCover.get_default().shift_changed.connect((m, shift) => {
var mon = get_target_monitor() ?? _shell_mon;
if (m != mon || is_dock_vertical()) return;
hide_motion.translate_x = shift;
update_input_region();
});
}));
dock_overlay.set_child(hide_motion);

layout_surface = new Box(Orientation.HORIZONTAL, 0);
Expand Down Expand Up @@ -184,18 +189,20 @@ namespace Singularity {
dock_box.halign = Align.CENTER;
magnifier = new DockMagnifier(dock_box, _settings);
if (magnifier.enabled) add_css_class("magnify-active");
magnifier.changed.connect(() => {
_signals.add(magnifier, magnifier.changed.connect(() => {
if (magnifier.enabled) add_css_class("magnify-active");
else remove_css_class("magnify-active");
update_gap();
update_layout_viewports();
update_dock_reservation();
});
}));
center_wrapper.append(dock_box);
motion_hints = new DockMotionHints(this, dock_box, (id) => {
return app_system.window_aliases(id);
});
dock_visibility_changed.connect((hidden) => motion_hints.set_hidden(hidden));
dock_visibility_changed.connect((hidden) => {
if (motion_hints != null) motion_hints.set_hidden(hidden);
});
layout_items["applications"] = dock_box;

// Resources (files / folders / links dropped on the
Expand Down Expand Up @@ -234,29 +241,29 @@ namespace Singularity {
{ "overview", "applications", "system", "clock" },
{ _("Overview"), _("Applications"), _("System Status"), _("Clock") }
);
layout_editor.move_requested.connect((item_id, section, index) => {
_signals.add(layout_editor, layout_editor.move_requested.connect((item_id, section, index) => {
if (bar_layout != null && bar_layout.move(item_id, section, index)) save_bar_layout();
});
layout_editor.edit_mode_changed.connect(() => {
}));
_signals.add(layout_editor, layout_editor.edit_mode_changed.connect(() => {
update_layout_viewports();
update_visibility_mode();
update_autohide_state();
if (!_settings.get_boolean("bar-layout-edit-mode") && _hidden_for_fullscreen) {
set_layer(this, GtkLayerShell.Layer.BACKGROUND);
}
update_input_region();
});
}));
update_layout_viewports();

add_css_class("dock-window");

_badges_shown = FocusManager.get_default().show_badges;
FocusManager.get_default().changed.connect(() => {
_signals.add(FocusManager.get_default(), FocusManager.get_default().changed.connect(() => {
bool shown = FocusManager.get_default().show_badges;
if (shown == _badges_shown) return;
_badges_shown = shown;
force_rebuild();
});
}));

_sig_background_effect = _settings.changed["background-effect"].connect(
update_background_effect);
Expand Down Expand Up @@ -411,14 +418,14 @@ namespace Singularity {
schedule_refresh();

var plugin_ctx = Singularity.PluginManager.get_default().get_context();
plugin_ctx.dock_context_menu_provider_added.connect((provider) => {
_signals.add(plugin_ctx, plugin_ctx.dock_context_menu_provider_added.connect((provider) => {
_menu_providers.add(provider);
});
plugin_ctx.dock_context_menu_provider_removed.connect((provider) => {
}));
_signals.add(plugin_ctx, plugin_ctx.dock_context_menu_provider_removed.connect((provider) => {
_menu_providers.remove(provider);
});
plugin_ctx.dock_item_extension_added.connect(register_item_extension);
plugin_ctx.dock_item_extension_removed.connect(unregister_item_extension);
}));
_signals.add(plugin_ctx, plugin_ctx.dock_item_extension_added.connect(register_item_extension));
_signals.add(plugin_ctx, plugin_ctx.dock_item_extension_removed.connect(unregister_item_extension));

// Load the kept-expanded set
foreach (string s in _settings.get_strv("dock-pinned-suffixes")) {
Expand All @@ -427,10 +434,9 @@ namespace Singularity {

// Primary dock owns the DBus service so multi-monitor doesn't conflict
if (is_primary) {
_dbus_service = new Singularity.DockDBusService();
plugin_ctx.add_dock_item_extension(_dbus_service);
plugin_ctx.add_dock_context_menu_provider(_dbus_service);
_dbus_service.own_bus();
_dbus_service = Singularity.DockDBusService.get_default();
register_item_extension(_dbus_service);
_menu_providers.add(_dbus_service);
}
update_clock();
_sig_clock = SharedClock.get_default().minute_changed.connect(() => update_clock());
Expand Down Expand Up @@ -588,6 +594,7 @@ namespace Singularity {
}

private void update_layout_viewports() {
if (_disposed) return;
bool editing = _settings.get_boolean("bar-layout-edit-mode");
bool vertical = is_dock_vertical();
int span = 0;
Expand Down Expand Up @@ -617,6 +624,7 @@ namespace Singularity {
}

private void align_layout_viewports() {
if (_disposed) return;
bool editing = _settings.get_boolean("bar-layout-edit-mode");
bool vertical = is_dock_vertical();
Gtk.Adjustment start_adjustment = vertical
Expand Down Expand Up @@ -836,9 +844,9 @@ namespace Singularity {
bat_icon.pixel_size = sys_icon_size;
sys_box.append(bat_icon);

network.state_changed.connect(() => { net_icon.icon_name = network.wifi_icon; });
audio.state_changed.connect(() => { audio_icon.icon_name = audio.icon_name; });
power.state_changed.connect(() => { bat_icon.icon_name = power.icon_name; });
_signals.add(network, network.state_changed.connect(() => { net_icon.icon_name = network.wifi_icon; }));
_signals.add(audio, audio.state_changed.connect(() => { audio_icon.icon_name = audio.icon_name; }));
_signals.add(power, power.state_changed.connect(() => { bat_icon.icon_name = power.icon_name; }));

layout_items["system"] = sys_box;

Expand Down Expand Up @@ -901,7 +909,22 @@ namespace Singularity {
return int.max(0, body) + _rest_margin;
}

// Every present() in this class goes through here, so a late signal or
// timer cannot bring a destroyed dock back on screen.
public new void present() {
if (_disposed) return;
base.present();
}

// Whoever asks (present(), set_visible(), a property binding), a
// destroyed dock never maps again.
public override void show() {
if (_disposed || window_was_destroyed(this)) return;
base.show();
}

private void update_autohide_state() {
if (_disposed) return;
if (hidden_by_scrolling_tiling()) {
_set_reveal_barrier_active(false);
return;
Expand Down Expand Up @@ -1140,6 +1163,7 @@ namespace Singularity {
// slid-off dock receives no pointer events on this compositor, so this
// always-on-screen strip is what catches the cursor to reveal the dock.
private void _set_reveal_barrier_active(bool active) {
if (_disposed) return;
if (!active) {
if (_reveal_barrier != null) _reveal_barrier.set_visible(false);
return;
Expand Down Expand Up @@ -1190,6 +1214,7 @@ namespace Singularity {
}

private void update_visibility_mode() {
if (_disposed) return;
if (hidden_by_scrolling_tiling()) {
close_layer_window(this);
set_exclusive_zone(this, 0);
Expand Down Expand Up @@ -1255,7 +1280,7 @@ namespace Singularity {
}

private void update_fullscreen_mode() {
if (hidden_by_scrolling_tiling()) return;
if (_disposed || hidden_by_scrolling_tiling()) return;
bool fs = is_any_window_fullscreen_on_my_monitor();
if (_settings.get_boolean("bar-layout-edit-mode")) {
_hidden_for_fullscreen = fs;
Expand Down Expand Up @@ -1372,6 +1397,7 @@ namespace Singularity {
private bool _badges_shown = true;

private void schedule_refresh() {
if (_disposed) return;
if (_refresh_timeout_id != 0) GLib.Source.remove(_refresh_timeout_id);
_refresh_timeout_id = GLib.Timeout.add(150, () => {
_refresh_timeout_id = 0;
Expand All @@ -1381,6 +1407,7 @@ namespace Singularity {
}

private void force_rebuild() {
if (_disposed) return;
_item_cache.clear();
Widget? child = dock_box.get_first_child();
while (child != null) {
Expand Down Expand Up @@ -2101,10 +2128,10 @@ namespace Singularity {
btn.set_child(ws_icon);
var sc_ws = SystemMonitor.get_default().shortcuts;
btn.tooltip_text = sc_ws.tooltip_for(_("Workspaces"), "toggle_workspace_overview");
sc_ws.shortcut_changed.connect((action, accel) => {
_signals.add(sc_ws, sc_ws.shortcut_changed.connect((action, accel) => {
if (action == "toggle_workspace_overview")
btn.tooltip_text = sc_ws.tooltip_for(_("Workspaces"), "toggle_workspace_overview");
});
}));
btn.clicked.connect(() => { workspace_clicked(); });
pill.append(btn);
animate_shell_button(wrapper, pill, btn);
Expand Down Expand Up @@ -3131,7 +3158,43 @@ namespace Singularity {
main_container.add_controller(rt);
}

protected override void dispose() {
// destroy() does not run dispose() in GTK4 (see window_was_destroyed),
// so the teardown has to happen here, not only when the last reference
// goes: otherwise a replaced dock keeps answering signals.
public new void destroy() {
teardown();
base.destroy();
// Not inline: the caller may still be inside one of our handlers.
GLib.Idle.add(() => {
release_window_tree(this);
return GLib.Source.REMOVE;
});
}

~Dock() {
debug("Dock released");
}

private void teardown() {
if (_disposed) return;
_disposed = true;
_signals.clear();
// Its alias callback references this dock.
motion_hints = null;
foreach (var entry in _item_extension_handlers.entries)
GLib.SignalHandler.disconnect(entry.key, entry.value);
_item_extension_handlers.clear();
_item_extensions.clear();
_menu_providers.clear();
_dbus_service = null;
if (_preview_dismiss_id != 0) {
GLib.Source.remove(_preview_dismiss_id);
_preview_dismiss_id = 0;
}
if (_preview_show_id != 0) {
GLib.Source.remove(_preview_show_id);
_preview_show_id = 0;
}
var as = app_system;
if (_sig_config_changed != 0) { GLib.SignalHandler.disconnect(as, _sig_config_changed); _sig_config_changed = 0; }
if (_sig_apps_changed != 0) { GLib.SignalHandler.disconnect(as, _sig_apps_changed); _sig_apps_changed = 0; }
Expand Down Expand Up @@ -3177,6 +3240,10 @@ namespace Singularity {
_reveal_barrier.destroy();
_reveal_barrier = null;
}
}

protected override void dispose() {
teardown();
base.dispose();
}

Expand Down
19 changes: 17 additions & 2 deletions src/components/dock/dock_dbus_service.vala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,22 @@ namespace Singularity {
private uint _own_id = 0;
private uint _reg_id = 0;

public DockDBusService() {}
private static DockDBusService? _instance = null;

// One service for the session, shared by every dock that is built:
// the bus name and object path can only be claimed once, and the
// suffixes, icons and menus apps registered have to survive the dock
// being rebuilt for another display.
[DBus (visible = false)]
public static DockDBusService get_default() {
if (_instance == null) {
_instance = new DockDBusService();
_instance.own_bus();
}
return _instance;
}

private DockDBusService() {}

private void track_owner(string nid, string sender) {
// Drop any old watcher for this app_id.
Expand Down Expand Up @@ -81,7 +96,7 @@ namespace Singularity {
}
}

public void own_bus() {
private void own_bus() {
_own_id = Bus.own_name(
BusType.SESSION,
"dev.sinty.Dock",
Expand Down
Loading