From 3587a611cf46dbfa83168f946f3a7689b5ef2769 Mon Sep 17 00:00:00 2001 From: Joshua Strobl Date: Wed, 2 Oct 2019 21:21:17 +0300 Subject: [PATCH] Fix the ability to move non-favorited windows in IconTasklist. This commit fixes the ability to move non-favorited running applications / windows in IconTasklist across grouping and non-grouping modes. These are now allowed to intermingle with your favorited applications without concern for a panel crash. We're doing this by more heavily leveraging our AbominationRunningApp to provide more consistent window-specific IDs. --- src/applets/icon-tasklist/DesktopHelper.vala | 19 ++++---- src/applets/icon-tasklist/IconButton.vala | 48 ++++++++++++++++--- .../icon-tasklist/IconTasklistApplet.vala | 30 +++++++++--- subprojects/gvc | 2 +- subprojects/translations | 2 +- 5 files changed, 75 insertions(+), 26 deletions(-) diff --git a/src/applets/icon-tasklist/DesktopHelper.vala b/src/applets/icon-tasklist/DesktopHelper.vala index d6b56e336..3754229da 100644 --- a/src/applets/icon-tasklist/DesktopHelper.vala +++ b/src/applets/icon-tasklist/DesktopHelper.vala @@ -55,17 +55,16 @@ public class DesktopHelper : GLib.Object string[] buttons = {}; foreach (Gtk.Widget widget in icon_layout.get_children()) { IconButton button = (widget as ButtonWrapper).button; - if (!button.is_pinned()) { - continue; - } - if (button.get_appinfo() == null) { - continue; - } - string id = button.get_appinfo().get_id(); - if (id in buttons) { - continue; + + if (button.is_pinned()) { + if (button.get_appinfo() != null) { + string id = button.get_appinfo().get_id(); + if (id in buttons) { + continue; + } + buttons += id; + } } - buttons += id; } settings.set_strv("pinned-launchers", buttons); // Keeping with pinned- internally for compatibility. diff --git a/src/applets/icon-tasklist/IconButton.vala b/src/applets/icon-tasklist/IconButton.vala index 6fbb5a643..3011fc6eb 100644 --- a/src/applets/icon-tasklist/IconButton.vala +++ b/src/applets/icon-tasklist/IconButton.vala @@ -33,6 +33,7 @@ public class IconButton : Gtk.ToggleButton private Gtk.Allocation definite_allocation; public bool pinned = false; private bool is_from_window = false; + private bool originally_pinned = false; private Gdk.AppLaunchContext launch_context; private int64 last_scroll_time = 0; public Wnck.Window? last_active_window = null; @@ -48,6 +49,7 @@ public class IconButton : Gtk.ToggleButton this.settings = c_settings; this.app_info = info; this.pinned = pinned; + this.originally_pinned = pinned; gobject_constructors_suck(); create_popover(); // Create our popover @@ -64,8 +66,13 @@ public class IconButton : Gtk.ToggleButton this.app_info = info; this.is_from_window = true; this.pinned = pinned; + this.originally_pinned = pinned; this.first_app = new Budgie.AbominationRunningApp(app_system, window); + if (this.first_app != null && this.first_app.app != null && this.app_info == null) { // Didn't get passed a valid DesktopAppInfo but got one from AbominationRunningApp + this.app_info = this.first_app.app; + } + this.first_app.name_changed.connect(() => { // When the name of the app has changed set_tooltip(); // Update our tooltip }); @@ -94,6 +101,8 @@ public class IconButton : Gtk.ToggleButton this.settings = c_settings; this.class_group = class_group; this.app_info = info; + this.pinned = false; + this.originally_pinned = false; gobject_constructors_suck(); create_popover(); // Create our popover @@ -157,12 +166,33 @@ public class IconButton : Gtk.ToggleButton }); drag_data_get.connect((widget, context, selection_data, info, time)=> { - string id; - if (this.app_info != null) { - id = this.app_info.get_id(); - } else { - id = this.window.get_name(); + string id = ""; + if (this.is_from_window) { // If this is from a window + if (this.pinned && this.originally_pinned) { // Has been pinned from the start + if (this.app_info != null) { + id = this.app_info.get_id(); + } else { + id = this.window.get_name(); + } + } else { // If this hasn't been pinned from the start + if (this.app_info != null && this.first_app != null) { + id = "%s|%lu".printf(this.app_info.get_id(), this.first_app.id); + } else if (this.app_info == null && this.first_app != null) { + id = "%s|%lu".printf(this.first_app.group, this.first_app.id); + } + } + } else { // If this is from a group + if (this.app_info != null) { + id = this.app_info.get_id(); + } else if (this.first_app != null) { + id = this.first_app.group; + } + } + + if (id == "" && this.window != null) { // If id isn't set + id = this.window.get_name(); // Just use name } + selection_data.set(selection_data.get_target(), 8, (uchar[])id.to_utf8()); }); @@ -207,8 +237,8 @@ public class IconButton : Gtk.ToggleButton this.pinned = new_pinned_state; this.desktop_helper.update_pinned(); // Update via desktop helper - if (!has_valid_windows(null) || is_from_window) { // Does not have any windows open (or this is only a single window) - became_empty(); // Trigger our became_empty event + if (!has_valid_windows(null)) { // Does not have any windows open and no longer pinned + became_empty(); // Trigger our became_empty event (for removal) } }); @@ -815,6 +845,10 @@ public class IconButton : Gtk.ToggleButton this.first_app.name_changed.connect(() => { // When the name of the app has changed set_tooltip(); // Update our tooltip }); + + if (this.app_info == null) { // If app_info hasn't been set yet + this.app_info = this.first_app.app; // Set to our first_app's DesktopAppInfo + } } } } diff --git a/src/applets/icon-tasklist/IconTasklistApplet.vala b/src/applets/icon-tasklist/IconTasklistApplet.vala index 3a6cb0427..c70fef984 100644 --- a/src/applets/icon-tasklist/IconTasklistApplet.vala +++ b/src/applets/icon-tasklist/IconTasklistApplet.vala @@ -264,11 +264,15 @@ public class IconTasklistApplet : Budgie.Applet if (app_id.has_prefix("file://")) { app_id = app_id.split("://")[1]; - GLib.DesktopAppInfo? info = new GLib.DesktopAppInfo.from_filename(app_id.strip()); + app_id = app_id.strip(); + + GLib.DesktopAppInfo? info = new GLib.DesktopAppInfo.from_filename(app_id); if (info == null) { return; } - app_id = info.get_id(); + + app_id = info.get_filename(); + if (buttons.contains(app_id)) { original_button = (buttons[app_id].get_parent() as ButtonWrapper); } else { @@ -286,9 +290,18 @@ public class IconTasklistApplet : Budgie.Applet }); main_layout.pack_start(original_button, false, false, 0); } - } else { - unowned IconButton? button = buttons.get(app_id) ?? buttons.get(id_map.get(app_id)); - original_button = (button != null) ? button.get_parent() as ButtonWrapper : null; + } else { // Doesn't start with file:// + unowned IconButton? button = null; + + if (buttons.contains(app_id)) { // If buttons contains this app_id + button = buttons.get(app_id); + } else if (id_map.contains(app_id)) { // id_map contains the app + button = buttons.get(id_map.get(app_id)); + } + + if (button != null) { + original_button = button.get_parent() as ButtonWrapper; + } } if (original_button == null) { @@ -378,6 +391,7 @@ public class IconTasklistApplet : Budgie.Applet GLib.DesktopAppInfo? app_info = first_app.app; string app_id = (app_info == null) ? "%s".printf(group_name) : app_info.get_id(); + app_id = app_id.strip(); id_map.insert(group_name, app_id); @@ -476,8 +490,10 @@ public class IconTasklistApplet : Budgie.Applet buttons.insert("%s|%lu".printf(app.group, app.id), button); button.became_empty.connect(() => { - buttons.remove("%s|%lu".printf(app.group, app.id)); - wrapper.gracefully_die(); + if (!button.pinned) { + buttons.remove("%s|%lu".printf(app.group, app.id)); + wrapper.gracefully_die(); + } }); main_layout.add(wrapper); diff --git a/subprojects/gvc b/subprojects/gvc index 7de39e768..468022b70 160000 --- a/subprojects/gvc +++ b/subprojects/gvc @@ -1 +1 @@ -Subproject commit 7de39e768e769a075e1057b7d6a1b948fcce274a +Subproject commit 468022b708fc1a56154f3b0cc5af3b938fb3e9fb diff --git a/subprojects/translations b/subprojects/translations index 063aa24c8..cc47673fc 160000 --- a/subprojects/translations +++ b/subprojects/translations @@ -1 +1 @@ -Subproject commit 063aa24c8da694354649ad12b57305c1aa689887 +Subproject commit cc47673fc206dc2bd37db5d94b061f639a27fb2e