Merge ~quequotion/plank:instance_controls into plank:master

Proposed by quequotion
Status: Needs review
Proposed branch: ~quequotion/plank:instance_controls
Merge into: plank:master
Diff against target: 94 lines (+58/-3)
2 files modified
lib/Items/ApplicationDockItem.vala (+32/-3)
lib/Services/WindowControl.vala (+26/-0)
Reviewer Review Type Date Requested Status
Docky Core Pending
Review via email: mp+390649@code.launchpad.net

Commit message

Add window controls for individual instances as a submenu on window_item.

Description of the change

Allow plank to provide a submenu for controlling individual instances of an application when multiple instances are open.

This moves window switching from window_item into a submenu, also adding a close feature for individual instances and a minimize feature for an active instance.

For an active instance, the menu provides "Close" and "Minimize", while inactive instances (minimized, unfocused, on another viewport, etc) are provided "Close" and "Switch to".

Also adds two WindowControl routines for minimizing an individual instance and closing an individual instance.

To post a comment you must log in.

Unmerged commits

bba6dca... by quequotion

Add window controls to instance menu items /as a submenu/

Currently only "Close", "Switch to", and "Minimize".

The submenu is required to have a "close instance" feature.

Gtk won't allow a button on a MenuItem. Unfortunately, submenus
break MenuItem's .activate.connnect() signal--contrary to how
this is documented--so window switching also had to move from the
window_item into the submenu. I wanted "minimize active instance"
to happen on the window_item as well, but for the same reason it
must be done in the submenu.

It isn't as pretty as what I had in mind, but it does *work*.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/Items/ApplicationDockItem.vala b/lib/Items/ApplicationDockItem.vala
2index a58dbed..0c375f7 100644
3--- a/lib/Items/ApplicationDockItem.vala
4+++ b/lib/Items/ApplicationDockItem.vala
5@@ -469,13 +469,35 @@ namespace Plank
6
7 if (pbuf != null)
8 window_item = create_literal_menu_item_with_pixbuf (window_name, pbuf);
9- else
10+ else
11 window_item = create_literal_menu_item (window_name, Icon);
12
13+ //instance "Close"
14+ Gdk.Pixbuf close_icon = Gtk.IconTheme.get_default ().load_icon ("window-close-symbolic", Gtk.IconSize.MENU, 0);
15+ Gtk.MenuItem close_item = create_literal_menu_item_with_pixbuf ("Close", close_icon);
16+ close_item.activate.connect (() => WindowControl.close_window (window, event_time));
17+
18+ //instance "Switch to"
19+ Gdk.Pixbuf switch_icon = Gtk.IconTheme.get_default ().load_icon ("go-next-symbolic", Gtk.IconSize.MENU, 0);
20+ Gtk.MenuItem switch_item = create_literal_menu_item_with_pixbuf ("Switch to", switch_icon);
21+ switch_item.activate.connect (() => WindowControl.focus_window (window, event_time));
22+
23+ //instance "Minimize"
24+ Gdk.Pixbuf minimize_icon = Gtk.IconTheme.get_default ().load_icon ("window-minimize-symbolic", Gtk.IconSize.MENU, 0);
25+ Gtk.MenuItem minimize_item = create_literal_menu_item_with_pixbuf ("Minimize", minimize_icon);
26+ minimize_item.activate.connect (() => minimized_active (window, minimize_item, switch_item));
27+
28+ //instance control submenu
29+ var control_menu = new Gtk.Menu ();
30+ control_menu.append (close_item);
31+ control_menu.append (minimize_item);
32+ control_menu.append (switch_item);
33+ close_item.show();
34 if (window.is_active ())
35- window_item.set_sensitive (false);
36+ minimize_item.show();
37 else
38- window_item.activate.connect (() => WindowControl.focus_window (window, event_time));
39+ switch_item.show();
40+ window_item.set_submenu (control_menu);
41
42 items.add (window_item);
43 }
44@@ -484,6 +506,13 @@ namespace Plank
45 return items;
46 }
47
48+ public static void minimized_active (Bamf.Window window, Gtk.MenuItem minimize_item, Gtk.MenuItem switch_item)
49+ {
50+ WindowControl.minimize_window (window);
51+ minimize_item.hide();
52+ switch_item.show();
53+ }
54+
55 /**
56 * {@inheritDoc}
57 */
58diff --git a/lib/Services/WindowControl.vala b/lib/Services/WindowControl.vala
59index e387612..db2997b 100644
60--- a/lib/Services/WindowControl.vala
61+++ b/lib/Services/WindowControl.vala
62@@ -225,6 +225,32 @@ namespace Plank
63 }
64 }
65
66+ public static void close_window (Bamf.Window window, uint32 event_time)
67+ {
68+ Wnck.Screen.get_default ();
69+ unowned Wnck.Window w = Wnck.Window.@get (window.get_xid ());
70+
71+ warn_if_fail (w != null);
72+
73+ if (w == null)
74+ return;
75+
76+ w.close (event_time);
77+ }
78+
79+ public static void minimize_window (Bamf.Window window)
80+ {
81+ Wnck.Screen.get_default ();
82+ unowned Wnck.Window w = Wnck.Window.@get (window.get_xid ());
83+
84+ warn_if_fail (w != null);
85+
86+ if (w == null)
87+ return;
88+
89+ w.minimize ();
90+ }
91+
92 public static void focus_window (Bamf.Window window, uint32 event_time)
93 {
94 Wnck.Screen.get_default ();

Subscribers

People subscribed via source and target branches

to all changes: