-
-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathWindowManager.vala
More file actions
1755 lines (1440 loc) · 70.3 KB
/
WindowManager.vala
File metadata and controls
1755 lines (1440 loc) · 70.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// Copyright (C) 2012-2014 Tom Beckmann, Rico Tzschichholz
// 2025 elementary, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
namespace Gala {
public class WindowManagerGala : Meta.Plugin, WindowManager {
private const string OPEN_MULTITASKING_VIEW = "dbus-send --session --dest=org.pantheon.gala --print-reply /org/pantheon/gala org.pantheon.gala.PerformAction int32:1";
private const string OPEN_APPLICATIONS_MENU = "io.elementary.wingpanel --toggle-indicator=app-launcher";
/**
* {@inheritDoc}
*/
public Clutter.Actor ui_group { get; protected set; }
/**
* {@inheritDoc}
*/
public Clutter.Stage stage { get; protected set; }
/**
* {@inheritDoc}
*/
public Clutter.Actor window_group { get; protected set; }
/**
* {@inheritDoc}
*/
public Clutter.Actor top_window_group { get; protected set; }
/**
* The group that contains all WindowActors that make shell elements, that is all windows reported as
* ShellClientsManager.is_shell_window.
* It will (eventually) never be hidden by other components and is always on top of everything. Therefore elements are
* responsible themselves for hiding depending on the state we are currently in (e.g. normal desktop, open multitasking view, fullscreen, etc.).
*/
private Clutter.Actor shell_group { get; private set; }
private Clutter.Actor menu_group { get; set; }
/**
* The group that contains all WindowActors that are system modal.
* See {@link ShellClientsManager.is_system_modal_window}.
*/
public ModalGroup modal_group { get; private set; }
/**
* {@inheritDoc}
*/
public Meta.BackgroundGroup background_group { get; protected set; }
/**
* View that allows to see and manage all your windows and desktops.
*/
public MultitaskingView multitasking_view { get; protected set; }
public PointerLocator pointer_locator { get; private set; }
private SystemBackground system_background;
#if !HAS_MUTTER48
private Meta.PluginInfo info;
#endif
private WindowSwitcher? window_switcher = null;
public ActivatableComponent? window_overview { get; private set; }
public ScreenSaverManager? screensaver { get; private set; }
private HotCornerManager? hot_corner_manager = null;
private KeyboardManager keyboard_manager;
public WindowTracker? window_tracker { get; private set; }
private WindowMover window_mover;
private FilterManager filter_manager;
private NotificationsManager notifications_manager;
private ScreenshotManager screenshot_manager;
/**
* Allow to zoom in/out the entire desktop.
*/
private Zoom? zoom = null;
private Clutter.Actor? tile_preview;
private DaemonManager daemon_manager;
private NotificationStack notification_stack;
private Gee.LinkedList<ModalProxy> modal_stack = new Gee.LinkedList<ModalProxy> ();
private Gee.HashSet<Meta.WindowActor> minimizing = new Gee.HashSet<Meta.WindowActor> ();
private Gee.HashSet<Meta.WindowActor> maximizing = new Gee.HashSet<Meta.WindowActor> ();
private Gee.HashSet<Meta.WindowActor> unmaximizing = new Gee.HashSet<Meta.WindowActor> ();
private Gee.HashSet<Meta.WindowActor> mapping = new Gee.HashSet<Meta.WindowActor> ();
private Gee.HashSet<Meta.WindowActor> destroying = new Gee.HashSet<Meta.WindowActor> ();
private Gee.HashSet<Meta.WindowActor> unminimizing = new Gee.HashSet<Meta.WindowActor> ();
private Meta.SizeChange? which_change = null;
private Mtk.Rectangle old_rect_size_change;
private Clutter.Actor? latest_window_snapshot;
private GLib.Settings behavior_settings;
construct {
#if !HAS_MUTTER48
info = Meta.PluginInfo () {name = "Gala", version = Config.VERSION, author = "Gala Developers",
license = "GPLv3", description = "A nice elementary window manager"};
#endif
behavior_settings = new GLib.Settings ("io.elementary.desktop.wm.behavior");
//Make it start watching the settings daemon bus
Drawing.StyleManager.get_instance ();
}
public override void start () {
ShellClientsManager.init (this);
BlurManager.init (this);
daemon_manager = new DaemonManager (get_display ());
show_stage ();
init_a11y ();
AccessDialog.watch_portal ();
filter_manager = new FilterManager (this);
notifications_manager = new NotificationsManager ();
screenshot_manager = new ScreenshotManager (this, notifications_manager, filter_manager);
DBus.init (this, notifications_manager, screenshot_manager);
unowned Meta.Display display = get_display ();
display.gl_video_memory_purged.connect (() => {
Meta.Background.refresh_all ();
});
display.notify["focus-window"].connect (on_focus_window_changed);
#if WITH_SYSTEMD
if (Meta.Util.is_wayland_compositor ()) {
display.init_xserver.connect ((task) => {
start_x11_services.begin (task);
return true;
});
}
#endif
}
#if WITH_SYSTEMD
private async void start_x11_services (GLib.Task task) {
try {
var session_bus = yield GLib.Bus.@get (GLib.BusType.SESSION);
yield session_bus.call (
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
"StartUnit",
new GLib.Variant ("(ss)", "gnome-session-x11-services-ready.target", "fail"),
new GLib.VariantType ("(o)"),
GLib.DBusCallFlags.NONE,
-1
);
} catch (Error e) {
critical (e.message);
} finally {
task.return_boolean (true);
}
}
#endif
private void show_stage () {
unowned Meta.Display display = get_display ();
WindowListener.init (display);
keyboard_manager = new KeyboardManager (display);
window_tracker = new WindowTracker ();
WindowStateSaver.init (window_tracker);
window_tracker.init (display);
WindowAttentionTracker.init (display);
window_mover = new WindowMover (display, WindowListener.get_default ());
notification_stack = new NotificationStack (display);
#if HAS_MUTTER48
stage = display.get_compositor ().get_stage () as Clutter.Stage;
#else
stage = display.get_stage () as Clutter.Stage;
#endif
var background_settings = new GLib.Settings ("org.gnome.desktop.background");
var color = background_settings.get_string ("primary-color");
#if HAS_MUTTER47
stage.background_color = Cogl.Color.from_string (color);
#else
stage.background_color = Clutter.Color.from_string (color);
#endif
unowned var laters = display.get_compositor ().get_laters ();
laters.add (Meta.LaterType.BEFORE_REDRAW, () => {
WorkspaceManager.init (this);
return false;
});
/* our layer structure:
* stage
* + system background
* + ui group
* +-- window group
* +---- background manager
* +-- top window group
* +-- multitasking view
* +-- window switcher
* +-- window overview
* +-- shell group
* +-- menu group
* +-- modal group
* +-- feedback group (e.g. DND icons)
* +-- pointer locator
* +-- dwell click timer
* +-- session locker
*/
system_background = new SystemBackground (display);
system_background.background_actor.add_constraint (new Clutter.BindConstraint (stage,
Clutter.BindCoordinate.ALL, 0));
stage.insert_child_below (system_background.background_actor, null);
ui_group = new Clutter.Actor ();
update_ui_group_size ();
stage.add_child (ui_group);
#if HAS_MUTTER48
window_group = display.get_compositor ().get_window_group ();
#else
window_group = display.get_window_group ();
#endif
stage.remove_child (window_group);
ui_group.add_child (window_group);
background_group = new BackgroundContainer (display);
((BackgroundContainer)background_group).show_background_menu.connect (daemon_manager.show_background_menu);
window_group.add_child (background_group);
window_group.set_child_below_sibling (background_group, null);
#if HAS_MUTTER48
top_window_group = display.get_compositor ().get_top_window_group ();
#else
top_window_group = display.get_top_window_group ();
#endif
stage.remove_child (top_window_group);
ui_group.add_child (top_window_group);
// Initialize plugins and add default components if no plugin overrides them
unowned var plugin_manager = PluginManager.get_default ();
plugin_manager.initialize (this);
plugin_manager.regions_changed.connect (update_input_area);
multitasking_view = new MultitaskingView (this);
ui_group.add_child (multitasking_view);
if (plugin_manager.window_switcher_provider == null) {
window_switcher = new WindowSwitcher (this);
ui_group.add_child (window_switcher);
Meta.KeyBinding.set_custom_handler ("switch-applications", window_switcher.handle_switch_windows);
Meta.KeyBinding.set_custom_handler ("switch-applications-backward", window_switcher.handle_switch_windows);
Meta.KeyBinding.set_custom_handler ("switch-windows", window_switcher.handle_switch_windows);
Meta.KeyBinding.set_custom_handler ("switch-windows-backward", window_switcher.handle_switch_windows);
Meta.KeyBinding.set_custom_handler ("switch-group", window_switcher.handle_switch_windows);
Meta.KeyBinding.set_custom_handler ("switch-group-backward", window_switcher.handle_switch_windows);
}
if (plugin_manager.window_overview_provider == null
|| (window_overview = (plugin_manager.get_plugin (plugin_manager.window_overview_provider) as ActivatableComponent)) == null
) {
window_overview = new WindowOverview (this);
ui_group.add_child ((Clutter.Actor) window_overview);
}
// Add the remaining components that should be on top
shell_group = new Clutter.Actor ();
ui_group.add_child (shell_group);
menu_group = new Clutter.Actor ();
ui_group.add_child (menu_group);
modal_group = new ModalGroup (this, ShellClientsManager.get_instance ());
modal_group.add_constraint (new Clutter.BindConstraint (stage, SIZE, 0));
ui_group.add_child (modal_group);
var feedback_group = display.get_compositor ().get_feedback_group ();
stage.remove_child (feedback_group);
ui_group.add_child (feedback_group);
pointer_locator = new PointerLocator (display);
ui_group.add_child (pointer_locator);
ui_group.add_child (new DwellClickTimer (display));
var session_locker = new SessionLocker (this);
ui_group.add_child (session_locker);
screensaver = new ScreenSaverManager (session_locker);
// Due to a bug which enables access to the stage when using multiple monitors
// in the screensaver, we have to listen for changes and make sure the input area
// is set to NONE when we are in locked mode
screensaver.active_changed.connect (update_input_area);
/*keybindings*/
var keybinding_settings = new GLib.Settings ("io.elementary.desktop.wm.keybindings");
display.add_keybinding ("switch-to-workspace-first", keybinding_settings, IGNORE_AUTOREPEAT, handle_switch_to_workspace_end);
display.add_keybinding ("switch-to-workspace-last", keybinding_settings, IGNORE_AUTOREPEAT, handle_switch_to_workspace_end);
display.add_keybinding ("move-to-workspace-first", keybinding_settings, IGNORE_AUTOREPEAT, handle_move_to_workspace_end);
display.add_keybinding ("move-to-workspace-last", keybinding_settings, IGNORE_AUTOREPEAT, handle_move_to_workspace_end);
display.add_keybinding ("cycle-workspaces-next", keybinding_settings, NONE, handle_cycle_workspaces);
display.add_keybinding ("cycle-workspaces-previous", keybinding_settings, NONE, handle_cycle_workspaces);
display.add_keybinding ("panel-main-menu", keybinding_settings, IGNORE_AUTOREPEAT, handle_applications_menu);
display.add_keybinding ("toggle-multitasking-view", keybinding_settings, IGNORE_AUTOREPEAT, () => {
if (multitasking_view.is_opened ()) {
multitasking_view.close ();
} else {
multitasking_view.open ();
}
});
display.add_keybinding ("expose-all-windows", keybinding_settings, IGNORE_AUTOREPEAT, () => {
if (window_overview.is_opened ()) {
window_overview.close ();
} else {
window_overview.open ();
}
});
display.overlay_key.connect (() => {
// Showing panels in fullscreen is broken in X11
if (InternalUtils.get_x11_in_fullscreen (display) &&
behavior_settings.get_string ("overlay-action") == OPEN_APPLICATIONS_MENU
) {
return;
}
launch_action (ActionKeys.OVERLAY_ACTION);
});
Meta.KeyBinding.set_custom_handler ("toggle-recording", () => {
launch_action (ActionKeys.TOGGLE_RECORDING_ACTION);
});
Meta.KeyBinding.set_custom_handler ("switch-to-workspace-up", () => {});
Meta.KeyBinding.set_custom_handler ("switch-to-workspace-down", () => {});
Meta.KeyBinding.set_custom_handler ("switch-to-workspace-left", handle_switch_to_workspace);
Meta.KeyBinding.set_custom_handler ("switch-to-workspace-right", handle_switch_to_workspace);
Meta.KeyBinding.set_custom_handler ("move-to-workspace-up", () => {});
Meta.KeyBinding.set_custom_handler ("move-to-workspace-down", () => {});
Meta.KeyBinding.set_custom_handler ("move-to-workspace-left", handle_move_to_workspace);
Meta.KeyBinding.set_custom_handler ("move-to-workspace-right", handle_move_to_workspace);
for (int i = 1; i < 13; i++) {
Meta.KeyBinding.set_custom_handler ("switch-to-workspace-%d".printf (i), handle_switch_to_workspace);
Meta.KeyBinding.set_custom_handler ("move-to-workspace-%d".printf (i), handle_move_to_workspace);
}
unowned var monitor_manager = display.get_context ().get_backend ().get_monitor_manager ();
monitor_manager.monitors_changed.connect (update_ui_group_size);
hot_corner_manager = new HotCornerManager (this, behavior_settings);
hot_corner_manager.on_configured.connect (update_input_area);
hot_corner_manager.configure ();
zoom = new Zoom (this);
update_input_area ();
var scroll_action = new SuperScrollAction (display);
scroll_action.triggered.connect (handle_super_scroll);
stage.add_action_full ("wm-super-scroll-action", CAPTURE, scroll_action);
display.window_created.connect ((window) =>
InternalUtils.wait_for_window_actor_visible (window, check_shell_window)
);
WindowListener.get_default ().window_type_changed.connect ((window) => {
unowned var window_actor = (Meta.WindowActor) window.get_compositor_private ();
if (window_actor != null) {
check_shell_window (window_actor);
}
});
stage.show ();
plugin_manager.load_waiting_plugins ();
Idle.add (() => {
// let the session manager move to the next phase
#if WITH_SYSTEMD
Systemd.Daemon.notify (true, "READY=1");
#endif
display.get_context ().notify_ready ();
return GLib.Source.REMOVE;
});
}
private void init_a11y () {
if (!Clutter.get_accessibility_enabled ()) {
warning ("Clutter has no accessibility enabled");
return;
}
string[] args = {};
unowned string[] _args = args;
AtkBridge.adaptor_init (ref _args);
}
private void update_ui_group_size () {
unowned var display = get_display ();
int max_width = 0;
int max_height = 0;
var num_monitors = display.get_n_monitors ();
for (int i = 0; i < num_monitors; i++) {
var geom = display.get_monitor_geometry (i);
var total_width = geom.x + geom.width;
var total_height = geom.y + geom.height;
max_width = (max_width > total_width) ? max_width : total_width;
max_height = (max_height > total_height) ? max_height : total_height;
}
ui_group.set_size (max_width, max_height);
}
public void launch_action (string action_key) {
try {
var action = behavior_settings.get_string (action_key);
if (action != null) {
Process.spawn_command_line_async (action);
}
} catch (Error e) {
warning (e.message);
}
}
private bool handle_super_scroll (uint32 timestamp, double dx, double dy) {
if (behavior_settings.get_enum ("super-scroll-action") != 1) {
return Clutter.EVENT_PROPAGATE;
}
var d = dx.abs () > dy.abs () ? dx : dy;
if (d > 0) {
switch_to_next_workspace (Meta.MotionDirection.RIGHT, timestamp);
} else if (d < 0) {
switch_to_next_workspace (Meta.MotionDirection.LEFT, timestamp);
}
return Clutter.EVENT_STOP;
}
private void handle_cycle_workspaces (Meta.Display display, Meta.Window? window, Clutter.KeyEvent? event,
Meta.KeyBinding binding) {
var direction = (binding.get_name () == "cycle-workspaces-next" ? 1 : -1);
unowned var manager = display.get_workspace_manager ();
var active_workspace_index = manager.get_active_workspace_index ();
var index = active_workspace_index + direction;
if (index < 0) {
index = manager.get_n_workspaces () - 2;
} else if (index > manager.get_n_workspaces () - 2) {
index = 0;
}
if (active_workspace_index != index) {
var timestamp = event != null ? event.get_time () : Meta.CURRENT_TIME;
manager.get_workspace_by_index (index).activate (timestamp);
} else {
InternalUtils.bell_notify (display);
}
}
private void handle_move_to_workspace (Meta.Display display, Meta.Window? window,
Clutter.KeyEvent? event, Meta.KeyBinding binding) {
if (window == null) {
return;
}
unowned var name = binding.get_name () ;
unowned var workspace_manager = display.get_workspace_manager ();
unowned var active_workspace = workspace_manager.get_active_workspace ();
unowned Meta.Workspace? target_workspace = null;
if (name == "move-to-workspace-left" || name == "move-to-workspace-right") {
var direction = (name == "move-to-workspace-left" ? Meta.MotionDirection.LEFT : Meta.MotionDirection.RIGHT);
target_workspace = active_workspace.get_neighbor (direction);
} else {
var workspace_number = int.parse (name.offset ("move-to-workspace-".length)) - 1;
var workspace_index = workspace_number.clamp (0, workspace_manager.n_workspaces - 1);
target_workspace = workspace_manager.get_workspace_by_index (workspace_index);
}
if (target_workspace != null) {
var timestamp = event != null ? event.get_time () : Meta.CURRENT_TIME;
move_window (window, target_workspace, timestamp);
}
}
private void handle_move_to_workspace_end (Meta.Display display, Meta.Window? window,
Clutter.KeyEvent? event, Meta.KeyBinding binding) {
if (window == null) {
return;
}
var timestamp = event != null ? event.get_time (): Meta.CURRENT_TIME;
unowned Meta.WorkspaceManager manager = display.get_workspace_manager ();
var index = (binding.get_name () == "move-to-workspace-first" ? 0 : manager.get_n_workspaces () - 1);
unowned var workspace = manager.get_workspace_by_index (index);
window.change_workspace (workspace);
workspace.activate_with_focus (window, timestamp);
}
private void handle_switch_to_workspace (Meta.Display display, Meta.Window? window,
Clutter.KeyEvent? event, Meta.KeyBinding binding) {
var timestamp = event != null ? event.get_time () : Meta.CURRENT_TIME;
unowned var name = binding.get_name ();
if (name == "switch-to-workspace-left" || name == "switch-to-workspace-right") {
var direction = (name == "switch-to-workspace-left" ? Meta.MotionDirection.LEFT : Meta.MotionDirection.RIGHT);
switch_to_next_workspace (direction, timestamp);
} else {
unowned var workspace_manager = get_display ().get_workspace_manager ();
var workspace_number = int.parse (name.offset ("switch-to-workspace-".length)) - 1;
var workspace_index = workspace_number.clamp (0, workspace_manager.n_workspaces - 1);
var workspace = workspace_manager.get_workspace_by_index (workspace_index);
if (workspace == null) {
return;
}
workspace.activate (timestamp);
}
}
private void handle_switch_to_workspace_end (Meta.Display display, Meta.Window? window,
Clutter.KeyEvent? event, Meta.KeyBinding binding) {
unowned Meta.WorkspaceManager manager = display.get_workspace_manager ();
var index = (binding.get_name () == "switch-to-workspace-first" ? 0 : manager.n_workspaces - 1);
manager.get_workspace_by_index (index).activate (event != null ? event.get_time () : Meta.CURRENT_TIME);
}
private void handle_applications_menu (Meta.Display display, Meta.Window? window,
Clutter.KeyEvent? event, Meta.KeyBinding binding) {
launch_action (ActionKeys.PANEL_MAIN_MENU_ACTION);
}
/**
* {@inheritDoc}
*/
public void switch_to_next_workspace (Meta.MotionDirection direction, uint32 timestamp) {
multitasking_view.switch_to_next_workspace (direction);
}
private void update_input_area () {
unowned Meta.Display display = get_display ();
if (screensaver != null) {
try {
if (screensaver.get_active ()) {
InternalUtils.set_input_area (display, InputArea.NONE);
return;
}
} catch (Error e) {
// the screensaver object apparently won't be null even though
// it is unavailable. This error will be thrown however, so we
// can just ignore it, because if it is thrown, the screensaver
// is unavailable.
}
}
if (is_modal ()) {
var area = multitasking_view.is_opened () ? InputArea.MULTITASKING_VIEW : InputArea.FULLSCREEN;
InternalUtils.set_input_area (display, area);
} else {
InternalUtils.set_input_area (display, InputArea.DEFAULT);
}
}
/**
* {@inheritDoc}
*/
public void move_window (Meta.Window? window, Meta.Workspace workspace, uint32 timestamp) {
if (window == null) {
return;
}
unowned Meta.Display display = get_display ();
unowned Meta.WorkspaceManager manager = display.get_workspace_manager ();
unowned var active = manager.get_active_workspace ();
// don't allow empty workspaces to be created by moving, if we have dynamic workspaces
if (Utils.get_n_windows (active) == 1 && workspace.index () == manager.n_workspaces - 1) {
InternalUtils.bell_notify (display);
return;
}
// don't allow moving into non-existing workspaces
if (active == workspace) {
InternalUtils.bell_notify (display);
return;
}
multitasking_view.move_window (window, workspace);
}
/**
* {@inheritDoc}
*/
public ModalProxy push_modal (Clutter.Actor actor, bool grab) {
var current_proxy = modal_stack.peek_head ();
if (current_proxy.grab != null) {
current_proxy.grab.dismiss ();
}
var proxy = new ModalProxy (actor, grab, grab ? stage.grab (actor) : null);
modal_stack.offer_head (proxy);
on_focus_window_changed ();
// modal already active
if (modal_stack.size >= 2) {
return proxy;
}
update_input_area ();
#if HAS_MUTTER48
get_display ().get_compositor ().disable_unredirect ();
#else
get_display ().disable_unredirect ();
#endif
return proxy;
}
/**
* {@inheritDoc}
*/
public void pop_modal (ModalProxy proxy) {
if (!modal_stack.remove (proxy)) {
warning ("Attempted to remove a modal proxy that was not in the stack");
return;
}
if (proxy.grab != null) {
proxy.grab.dismiss ();
}
on_focus_window_changed ();
var new_active_proxy = modal_stack.peek_head ();
if (new_active_proxy.should_grab) {
new_active_proxy.grab = stage.grab (new_active_proxy.actor);
}
if (is_modal ()) {
return;
}
update_input_area ();
unowned var display = get_display ();
#if HAS_MUTTER48
display.get_compositor ().enable_unredirect ();
#else
display.enable_unredirect ();
#endif
display.focus_default_window (display.get_current_time ());
}
/**
* {@inheritDoc}
*/
public bool is_modal () {
return !modal_stack.is_empty;
}
/**
* {@inheritDoc}
*/
public bool modal_proxy_valid (ModalProxy proxy) {
return (proxy in modal_stack);
}
private void on_focus_window_changed () {
unowned var display = get_display ();
if (!is_modal () || modal_stack.peek_head ().grab != null || display.focus_window == null ||
ShellClientsManager.get_instance ().is_shell_window (display.focus_window)
) {
return;
}
display.unset_input_focus (display.get_current_time ());
}
private void dim_parent_window (Meta.Window window) {
if (window.window_type != MODAL_DIALOG) {
return;
}
unowned var transient = window.get_transient_for ();
if (transient == null || transient == window) {
warning ("No transient found");
return;
}
unowned var transient_actor = (Meta.WindowActor) transient.get_compositor_private ();
var dark_effect = new Clutter.BrightnessContrastEffect ();
dark_effect.set_brightness (-0.4f);
transient_actor.add_effect_with_name ("dim-parent", dark_effect);
window.unmanaged.connect (() => {
if (transient_actor != null && transient_actor.get_effect ("dim-parent") != null) {
transient_actor.remove_effect_by_name ("dim-parent");
}
});
}
private void set_grab_trigger (Meta.Window window, Meta.GrabOp op) {
var proxy = push_modal (stage, true);
ulong handler = 0;
handler = stage.captured_event.connect ((event) => {
if (event.get_type () == MOTION || event.get_type () == ENTER ||
event.get_type () == TOUCHPAD_HOLD || event.get_type () == TOUCH_BEGIN) {
window.begin_grab_op (
op,
null,
#if !HAS_MUTTER49
event.get_event_sequence (),
#endif
event.get_time ()
#if HAS_MUTTER46
, null
#endif
);
} else if (event.get_type () == LEAVE) {
/* We get leave emitted when beginning a grab op, so we have
to filter it in order to avoid disconnecting and popping twice */
return Clutter.EVENT_PROPAGATE;
}
pop_modal (proxy);
stage.disconnect (handler);
return Clutter.EVENT_PROPAGATE;
});
}
/**
* {@inheritDoc}
*/
public void perform_action (ActionType type) {
unowned var display = get_display ();
unowned var current = display.get_focus_window ();
switch (type) {
case ActionType.SHOW_MULTITASKING_VIEW:
if (multitasking_view.is_opened ())
multitasking_view.close ();
else
multitasking_view.open ();
break;
case ActionType.MAXIMIZE_CURRENT:
if (current == null || current.window_type != Meta.WindowType.NORMAL || !current.can_maximize ())
break;
#if HAS_MUTTER49
if (current.is_maximized ()) {
current.unmaximize ();
} else {
current.maximize ();
}
#else
var maximize_flags = current.get_maximized ();
if (Meta.MaximizeFlags.VERTICAL in maximize_flags || Meta.MaximizeFlags.HORIZONTAL in maximize_flags)
current.unmaximize (Meta.MaximizeFlags.HORIZONTAL | Meta.MaximizeFlags.VERTICAL);
else
current.maximize (Meta.MaximizeFlags.HORIZONTAL | Meta.MaximizeFlags.VERTICAL);
#endif
break;
case ActionType.HIDE_CURRENT:
if (current != null && current.window_type == Meta.WindowType.NORMAL)
current.minimize ();
break;
case ActionType.START_MOVE_CURRENT:
if (current != null && current.allows_move ())
#if HAS_MUTTER46
set_grab_trigger (current, KEYBOARD_MOVING);
#else
current.begin_grab_op (Meta.GrabOp.KEYBOARD_MOVING, null, null, Meta.CURRENT_TIME);
#endif
break;
case ActionType.START_RESIZE_CURRENT:
if (current != null && current.allows_resize ())
#if HAS_MUTTER46
set_grab_trigger (current, KEYBOARD_RESIZING_UNKNOWN);
#else
current.begin_grab_op (Meta.GrabOp.KEYBOARD_RESIZING_UNKNOWN, null, null, Meta.CURRENT_TIME);
#endif
break;
case ActionType.TOGGLE_ALWAYS_ON_TOP_CURRENT:
if (current == null)
break;
if (current.is_above ())
current.unmake_above ();
else
current.make_above ();
break;
case ActionType.TOGGLE_ALWAYS_ON_VISIBLE_WORKSPACE_CURRENT:
if (current == null)
break;
if (current.on_all_workspaces)
current.unstick ();
else
current.stick ();
break;
case ActionType.SWITCH_TO_WORKSPACE_PREVIOUS:
switch_to_next_workspace (Meta.MotionDirection.LEFT, Meta.CURRENT_TIME);
break;
case ActionType.SWITCH_TO_WORKSPACE_NEXT:
switch_to_next_workspace (Meta.MotionDirection.RIGHT, Meta.CURRENT_TIME);
break;
case ActionType.MOVE_CURRENT_WORKSPACE_LEFT:
unowned var workspace_manager = get_display ().get_workspace_manager ();
unowned var active_workspace = workspace_manager.get_active_workspace ();
unowned var target_workspace = active_workspace.get_neighbor (Meta.MotionDirection.LEFT);
move_window (current, target_workspace, Meta.CURRENT_TIME);
break;
case ActionType.MOVE_CURRENT_WORKSPACE_RIGHT:
unowned var workspace_manager = get_display ().get_workspace_manager ();
unowned var active_workspace = workspace_manager.get_active_workspace ();
unowned var target_workspace = active_workspace.get_neighbor (Meta.MotionDirection.RIGHT);
move_window (current, target_workspace, Meta.CURRENT_TIME);
break;
case ActionType.CLOSE_CURRENT:
if (current != null && current.can_close ())
current.@delete (Meta.CURRENT_TIME);
break;
case ActionType.OPEN_LAUNCHER:
launch_action (ActionKeys.PANEL_MAIN_MENU_ACTION);
break;
case ActionType.WINDOW_OVERVIEW:
if (window_overview == null) {
break;
}
if (window_overview.is_opened ()) {
window_overview.close ();
} else {
window_overview.open ();
}
critical ("Window overview is deprecated");
break;
case ActionType.WINDOW_OVERVIEW_ALL:
if (window_overview == null) {
break;
}
if (window_overview.is_opened ()) {
window_overview.close ();
} else {
window_overview.open ();
}
break;
case ActionType.SWITCH_TO_WORKSPACE_LAST:
unowned var manager = display.get_workspace_manager ();
unowned var workspace = manager.get_workspace_by_index (manager.get_n_workspaces () - 1);
workspace.activate (display.get_current_time ());
break;
case ActionType.SCREENSHOT_CURRENT:
screenshot_manager.handle_screenshot_current_window_shortcut.begin (false);
break;
default:
warning ("Trying to run unknown action");
break;
}
}
public override void show_window_menu (Meta.Window window, Meta.WindowMenuType menu, int x, int y) {
switch (menu) {
case Meta.WindowMenuType.WM:
if (NotificationStack.is_notification (window)) {
return;
}
WindowFlags flags = WindowFlags.NONE;
if (window.can_minimize ())
flags |= WindowFlags.CAN_HIDE;
if (window.can_maximize ())
flags |= WindowFlags.CAN_MAXIMIZE;
#if HAS_MUTTER49
if (window.is_maximized ())
flags |= WindowFlags.IS_MAXIMIZED;
if (window.maximized_vertically && !window.maximized_horizontally)
flags |= WindowFlags.IS_TILED;
#else
var maximize_flags = window.get_maximized ();
if (maximize_flags > 0) {
flags |= WindowFlags.IS_MAXIMIZED;
if (Meta.MaximizeFlags.VERTICAL in maximize_flags && !(Meta.MaximizeFlags.HORIZONTAL in maximize_flags)) {
flags |= WindowFlags.IS_TILED;
}
}
#endif
if (window.allows_move ())
flags |= WindowFlags.ALLOWS_MOVE;
if (window.allows_resize ())
flags |= WindowFlags.ALLOWS_RESIZE;
if (window.is_above ())
flags |= WindowFlags.ALWAYS_ON_TOP;
if (window.on_all_workspaces)
flags |= WindowFlags.ON_ALL_WORKSPACES;
if (window.can_close ())
flags |= WindowFlags.CAN_CLOSE;
unowned var workspace = window.get_workspace ();
if (workspace != null) {
unowned var manager = window.display.get_workspace_manager ();
var workspace_index = workspace.workspace_index;
if (workspace_index != 0) {
flags |= WindowFlags.ALLOWS_MOVE_LEFT;
}
if (workspace_index != manager.n_workspaces - 2 || Utils.get_n_windows (workspace) != 1) {
flags |= WindowFlags.ALLOWS_MOVE_RIGHT;
}
}
daemon_manager.show_window_menu.begin (flags, x, y);
break;
case Meta.WindowMenuType.APP:
// FIXME we don't have any sort of app menus
break;
}
}
public override void show_tile_preview (Meta.Window window, Mtk.Rectangle tile_rect, int tile_monitor_number) {
if (tile_preview == null) {
tile_preview = new Clutter.Actor () {
background_color = Drawing.StyleManager.get_instance ().theme_accent_color,
opacity = 0
};
window_group.add_child (tile_preview);
} else {
float width, height, x, y;
tile_preview.get_position (out x, out y);
tile_preview.get_size (out width, out height);
if ((tile_rect.width == width && tile_rect.height == height && tile_rect.x == x && tile_rect.y == y)
|| tile_preview.get_transition ("size") != null) {
return;
}