Skip to content

Commit

Permalink
Fix the ability to move non-favorited windows in IconTasklist.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
JoshStrobl committed Oct 2, 2019
1 parent a023c77 commit 3587a61
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 26 deletions.
19 changes: 9 additions & 10 deletions src/applets/icon-tasklist/DesktopHelper.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
48 changes: 41 additions & 7 deletions src/applets/icon-tasklist/IconButton.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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

Expand All @@ -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
});
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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());
});

Expand Down Expand Up @@ -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)
}
});

Expand Down Expand Up @@ -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
}
}
}
}
Expand Down
30 changes: 23 additions & 7 deletions src/applets/icon-tasklist/IconTasklistApplet.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion subprojects/gvc
Submodule gvc updated from 7de39e to 468022
2 changes: 1 addition & 1 deletion subprojects/translations
Submodule translations updated 26 files
+176 −164 ar.po
+1,293 −0 be.po
+1,293 −0 be_Latn.po
+7 −8 bg_BG.po
+19 −20 ca.po
+19 −20 cs.po
+20 −21 de.po
+16 −16 de_CH.po
+5 −4 eo.po
+49 −46 es.po
+7 −6 es_CL.po
+11 −11 he.po
+15 −15 id.po
+22 −22 lt.po
+18 −19 nl.po
+17 −18 nl_BE.po
+52 −59 nn.po
+21 −23 no.po
+10 −7 pl.po
+13 −11 pt_BR.po
+16 −16 pt_PT.po
+40 −38 ru.po
+59 −59 sr_RS.po
+16 −17 sv.po
+16 −18 tr.po
+130 −132 zh.po

0 comments on commit 3587a61

Please sign in to comment.