Skip to content

Commit 7a9df73

Browse files
committed
Convert bring-to-current-workspace to a per-dock setting and only bring the target window
1 parent 0bbe88a commit 7a9df73

6 files changed

Lines changed: 46 additions & 30 deletions

File tree

data/net.launchpad.plank.gschema.xml.in

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@
3131
<summary>Array of names of active/enabled docks</summary>
3232
<description>Contains the names of docks which are created and loaded on start up</description>
3333
</key>
34-
35-
<key name="bring-window-to-current-workspace" type="b">
36-
<default>false</default>
37-
<summary>Bring windows to the current workspace when activated</summary>
38-
<description>If true, activating a window located on another workspace moves it to the current workspace instead of switching to the window's workspace.</description>
39-
</key>
4034
</schema>
4135

4236
<schema id="net.launchpad.plank.dock.settings" gettext-domain="@GETTEXT_PACKAGE@">
@@ -50,6 +44,11 @@
5044
<summary>Automatically pin an application if it seems useful to do</summary>
5145
<description>If true, automatically pin applications when it seems useful to do.</description>
5246
</key>
47+
<key name="bring-to-current-workspace" type="b">
48+
<default>false</default>
49+
<summary>Bring windows to the current workspace when activated</summary>
50+
<description>If true, activating a window located on another workspace moves it to the current workspace instead of switching to the window's workspace.</description>
51+
</key>
5352
<key name="current-workspace-only" type="b">
5453
<default>false</default>
5554
<summary>Only show windows from the current workspace</summary>

lib/DockPreferences.vala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ namespace Plank {
3737
[Description (nick = "current-workspace-only", blurb = "Whether to show only windows of the current workspace.")]
3838
public bool CurrentWorkspaceOnly { get; set; }
3939

40+
[Description (nick = "bring-to-current-workspace", blurb = "Whether to bring windows to the current workspace when activated instead of switching to the window's workspace.")]
41+
public bool BringToCurrentWorkspace { get; set; }
42+
4043
[Description (nick = "icon-size", blurb = "The size of dock icons (in pixels).")]
4144
public int IconSize { get; set; }
4245

lib/Items/ApplicationDockItem.vala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ namespace Plank {
358358
}
359359

360360
if (button == PopupButton.LEFT && App != null && Helpers.window_count (App, default_provider) > 0) {
361-
WindowControl.smart_focus (App, event_time);
361+
WindowControl.smart_focus (App, event_time, Helpers.bring_to_current_workspace (default_provider));
362362
return AnimationType.DARKEN;
363363
}
364364

@@ -494,6 +494,7 @@ namespace Plank {
494494
items.add (new Gtk.SeparatorMenuItem ());
495495

496496
bool cw_only = Helpers.current_workspace_only (default_provider);
497+
bool bring_to_current = Helpers.bring_to_current_workspace (default_provider);
497498
unowned Wnck.Workspace? active_workspace = Wnck.Screen.get_default ().get_active_workspace ();
498499

499500
foreach (var window in windows) {
@@ -573,7 +574,7 @@ namespace Plank {
573574
}
574575

575576
if (!window.is_active ()) {
576-
WindowControl.focus_window (window, event_time);
577+
WindowControl.focus_window (window, event_time, bring_to_current);
577578
}
578579
});
579580

lib/Services/Helpers.vala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ namespace Plank {
5858
return current_workspace_only;
5959
}
6060

61+
public static bool bring_to_current_workspace (DefaultApplicationDockItemProvider? provider) {
62+
bool bring_to_current_workspace = false;
63+
64+
if (provider != null) {
65+
bring_to_current_workspace = provider.Prefs.BringToCurrentWorkspace;
66+
}
67+
68+
return bring_to_current_workspace;
69+
}
70+
6171
public static int window_count (Bamf.Application? app, DefaultApplicationDockItemProvider? provider) {
6272
int window_count = 0;
6373

lib/Services/WindowControl.vala

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ namespace Plank {
4343
static uint delayed_focus_timer_id = 0U;
4444
static ulong delayed_focus_xid = 0UL;
4545

46-
static GLib.Settings? global_settings = null;
47-
static bool bring_window_to_current_workspace = false;
48-
4946
// Action type for pending operations
5047
enum PendingActionType {
5148
MINIMIZE,
@@ -190,12 +187,6 @@ namespace Plank {
190187
public static void initialize () {
191188
Wnck.set_client_type (Wnck.ClientType.PAGER);
192189

193-
global_settings = create_settings ("net.launchpad.plank");
194-
bring_window_to_current_workspace = global_settings.get_boolean ("bring-window-to-current-workspace");
195-
global_settings.changed["bring-window-to-current-workspace"].connect (() => {
196-
bring_window_to_current_workspace = global_settings.get_boolean ("bring-window-to-current-workspace");
197-
});
198-
199190
unowned Wnck.Screen screen = Wnck.Screen.get_default ();
200191

201192
// Make sure internal window-list of Wnck is most up to date
@@ -512,15 +503,15 @@ namespace Plank {
512503
}
513504
}
514505

515-
public static void focus_window (Bamf.Window window, uint32 event_time) {
506+
public static void focus_window (Bamf.Window window, uint32 event_time, bool bring_to_current = false) {
516507
unowned Wnck.Window w = Wnck.Window.@get (window.get_xid ());
517508

518509
warn_if_fail (w != null);
519510

520511
if (w == null)
521512
return;
522513

523-
center_and_focus_window (w, event_time);
514+
center_and_focus_window (w, event_time, bring_to_current);
524515
}
525516

526517
static void focus_window_by_xid (uint32 xid, uint32 event_time) {
@@ -637,7 +628,7 @@ namespace Plank {
637628
return windows;
638629
}
639630

640-
public static void smart_focus (Bamf.Application app, uint32 event_time) {
631+
public static void smart_focus (Bamf.Application app, uint32 event_time, bool bring_to_current = false) {
641632
var windows = get_ordered_window_stack (app);
642633

643634
var not_in_viewport = true;
@@ -657,7 +648,7 @@ namespace Plank {
657648
continue;
658649

659650
if (!window.is_skip_tasklist ()) {
660-
intelligent_focus_off_viewport_window (window, windows, event_time);
651+
intelligent_focus_off_viewport_window (window, windows, event_time, bring_to_current);
661652
return;
662653
}
663654
}
@@ -701,15 +692,22 @@ namespace Plank {
701692
}
702693

703694
// Focus most-top window and all others on its workspace
704-
intelligent_focus_off_viewport_window (windows.nth_data (0), windows, event_time);
695+
intelligent_focus_off_viewport_window (windows.nth_data (0), windows, event_time, bring_to_current);
705696
}
706697

707698
static void intelligent_focus_off_viewport_window (Wnck.Window? targetWindow,
708-
GLib.List<unowned Wnck.Window> additional_windows, uint32 event_time) {
699+
GLib.List<unowned Wnck.Window> additional_windows, uint32 event_time,
700+
bool bring_to_current = false) {
709701
if (targetWindow == null) {
710702
return;
711703
}
712704

705+
// Bring only the target window to the current workspace, the others stay put
706+
if (bring_to_current) {
707+
center_and_focus_window (targetWindow, event_time, true);
708+
return;
709+
}
710+
713711
additional_windows.reverse ();
714712

715713
var windows_to_focus = new Gee.ArrayList<unowned Wnck.Window> ();
@@ -817,12 +815,12 @@ namespace Plank {
817815
return active_workspace != null && window.is_in_viewport (active_workspace);
818816
}
819817

820-
static void center_and_focus_window (Wnck.Window w, uint32 event_time) {
818+
static void center_and_focus_window (Wnck.Window w, uint32 event_time, bool bring_to_current = false) {
821819
unowned Wnck.Workspace? workspace = w.get_workspace ();
822820
unowned Wnck.Workspace? active_workspace = w.get_screen ().get_active_workspace ();
823821

824822
if (!w.is_pinned () && !w.is_sticky () && workspace != null && active_workspace != null && workspace != active_workspace) {
825-
if (bring_window_to_current_workspace)
823+
if (bring_to_current)
826824
w.move_to_workspace (active_workspace);
827825
else
828826
workspace.activate (event_time);

lib/Widgets/PreferencesWindow.vala

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ namespace Plank {
2626
public DockController controller { get; construct set; }
2727

2828
DockPreferences prefs;
29-
GLib.Settings global_settings;
3029

3130
bool refreshing_display_plugs = false;
3231

@@ -107,10 +106,6 @@ namespace Plank {
107106

108107
prefs = controller.prefs;
109108

110-
global_settings = create_settings ("net.launchpad.plank");
111-
global_settings.bind ("bring-window-to-current-workspace", sw_bring_to_workspace,
112-
"active", SettingsBindFlags.DEFAULT);
113-
114109
init_dock_tab ();
115110
init_docklets_tab ();
116111
connect_signals ();
@@ -142,6 +137,9 @@ namespace Plank {
142137
case "CurrentWorkspaceOnly":
143138
sw_workspace_only.set_active (prefs.CurrentWorkspaceOnly);
144139
break;
140+
case "BringToCurrentWorkspace":
141+
sw_bring_to_workspace.set_active (prefs.BringToCurrentWorkspace);
142+
break;
145143
case "IconSize":
146144
adj_iconsize.value = prefs.IconSize;
147145
break;
@@ -280,6 +278,10 @@ namespace Plank {
280278
prefs.CurrentWorkspaceOnly = ((Gtk.Switch) widget).get_active ();
281279
}
282280

281+
void bring_to_workspace_toggled (GLib.Object widget, ParamSpec param) {
282+
prefs.BringToCurrentWorkspace = ((Gtk.Switch) widget).get_active ();
283+
}
284+
283285
void show_unpinned_toggled (GLib.Object widget, ParamSpec param) {
284286
prefs.PinnedOnly = !((Gtk.Switch) widget).get_active ();
285287
}
@@ -419,6 +421,7 @@ namespace Plank {
419421
sw_active_display.notify["active"].connect (active_display_toggled);
420422
adj_active_display_polling_interval.value_changed.connect (active_display_polling_interval_changed);
421423
sw_workspace_only.notify["active"].connect (workspace_only_toggled);
424+
sw_bring_to_workspace.notify["active"].connect (bring_to_workspace_toggled);
422425
sw_show_unpinned.notify["active"].connect (show_unpinned_toggled);
423426
sw_lock_items.notify["active"].connect (lock_items_toggled);
424427
sw_tooltips_enabled.notify["active"].connect (tooltips_enabled_toggled);
@@ -451,6 +454,7 @@ namespace Plank {
451454
sw_active_display.notify["active"].disconnect (active_display_toggled);
452455
adj_active_display_polling_interval.value_changed.disconnect (active_display_polling_interval_changed);
453456
sw_workspace_only.notify["active"].disconnect (workspace_only_toggled);
457+
sw_bring_to_workspace.notify["active"].disconnect (bring_to_workspace_toggled);
454458
sw_show_unpinned.notify["active"].disconnect (show_unpinned_toggled);
455459
sw_lock_items.notify["active"].disconnect (lock_items_toggled);
456460
sw_tooltips_enabled.notify["active"].disconnect (tooltips_enabled_toggled);
@@ -504,6 +508,7 @@ namespace Plank {
504508
s_active_display_polling_interval.sensitive = false;
505509
}
506510
sw_workspace_only.set_active (prefs.CurrentWorkspaceOnly);
511+
sw_bring_to_workspace.set_active (prefs.BringToCurrentWorkspace);
507512
sw_show_unpinned.set_active (!prefs.PinnedOnly);
508513
sw_lock_items.set_active (prefs.LockItems);
509514
sw_tooltips_enabled.set_active (prefs.TooltipsEnabled);

0 commit comments

Comments
 (0)