-
-
Notifications
You must be signed in to change notification settings - Fork 76
/
WindowManager.vala
2242 lines (1836 loc) · 93.2 KB
/
WindowManager.vala
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
//
// 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 {
private const string DAEMON_DBUS_NAME = "org.pantheon.gala.daemon";
private const string DAEMON_DBUS_OBJECT_PATH = "/org/pantheon/gala/daemon";
[DBus (name = "org.pantheon.gala.daemon")]
public interface Daemon: GLib.Object {
public abstract async void show_window_menu (WindowFlags flags, int x, int y) throws Error;
public abstract async void show_desktop_menu (int x, int y) throws Error;
}
public class WindowManagerGala : Meta.Plugin, WindowManager {
/**
* {@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; }
public Clutter.Actor notification_group { get; protected set; }
/**
* {@inheritDoc}
*/
public Meta.BackgroundGroup background_group { get; protected set; }
/**
* {@inheritDoc}
*/
public Gala.ActivatableComponent workspace_view { get; protected set; }
/**
* {@inheritDoc}
*/
public bool enable_animations { get; protected set; }
public ScreenShield? screen_shield { get; private set; }
public PointerLocator pointer_locator { get; private set; }
private SystemBackground system_background;
private Meta.PluginInfo info;
private WindowSwitcher? winswitcher = null;
private ActivatableComponent? window_overview = null;
public ScreenSaverManager? screensaver { get; private set; }
private HotCornerManager? hot_corner_manager = null;
public WindowTracker? window_tracker { get; private set; }
/**
* Allow to zoom in/out the entire desktop.
*/
private Zoom? zoom = null;
private AccentColorManager accent_color_manager;
private Clutter.Actor? tile_preview;
private Meta.Window? moving; //place for the window that is being moved over
private Daemon? daemon_proxy = null;
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 GLib.HashTable<Meta.Window, int> ws_assoc = new GLib.HashTable<Meta.Window, int> (direct_hash, direct_equal);
private Meta.SizeChange? which_change = null;
private Meta.Rectangle old_rect_size_change;
private Clutter.Actor latest_window_snapshot;
private GLib.Settings animations_settings;
private GLib.Settings behavior_settings;
private GestureTracker gesture_tracker;
private bool animating_switch_workspace = false;
private bool animating_nudge = false;
private bool switch_workspace_with_gesture = false;
/**
* Amount of pixels to move on the nudge animation.
*/
public const float NUDGE_GAP = 32;
/**
* Gap to show between workspaces while switching between them.
*/
public const int WORKSPACE_GAP = 24;
construct {
gesture_tracker = new GestureTracker (AnimationDuration.WORKSPACE_SWITCH_MIN, AnimationDuration.WORKSPACE_SWITCH);
gesture_tracker.enable_touchpad ();
gesture_tracker.on_gesture_detected.connect (on_gesture_detected);
info = Meta.PluginInfo () {name = "Gala", version = Config.VERSION, author = "Gala Developers",
license = "GPLv3", description = "A nice elementary window manager"};
animations_settings = new GLib.Settings (Config.SCHEMA + ".animations");
animations_settings.bind ("enable-animations", this, "enable-animations", GLib.SettingsBindFlags.GET);
behavior_settings = new GLib.Settings (Config.SCHEMA + ".behavior");
enable_animations = animations_settings.get_boolean ("enable-animations");
}
public override void start () {
show_stage ();
Bus.watch_name (BusType.SESSION, DAEMON_DBUS_NAME, BusNameWatcherFlags.NONE, daemon_appeared, lost_daemon);
AccessDialog.watch_portal ();
unowned Meta.Display display = get_display ();
display.gl_video_memory_purged.connect (() => {
Meta.Background.refresh_all ();
SystemBackground.refresh ();
});
}
private void lost_daemon () {
daemon_proxy = null;
}
private void daemon_appeared () {
if (daemon_proxy == null) {
Bus.get_proxy.begin<Daemon> (BusType.SESSION, DAEMON_DBUS_NAME, DAEMON_DBUS_OBJECT_PATH, 0, null, (obj, res) => {
try {
daemon_proxy = Bus.get_proxy.end (res);
} catch (Error e) {
warning ("Failed to get Menu proxy: %s", e.message);
}
});
}
}
private bool show_stage () {
unowned Meta.Display display = get_display ();
screen_shield = new ScreenShield (this);
screensaver = new ScreenSaverManager (screen_shield);
DBus.init (this);
DBusAccelerator.init (this);
MediaFeedback.init ();
WindowListener.init (display);
KeyboardManager.init (display);
window_tracker = new WindowTracker ();
window_tracker.init (display);
notification_stack = new NotificationStack (display);
// 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);
stage = display.get_stage () as Clutter.Stage;
var background_settings = new GLib.Settings ("org.gnome.desktop.background");
var color = background_settings.get_string ("primary-color");
stage.background_color = Clutter.Color.from_string (color);
WorkspaceManager.init (this);
/* our layer structure:
* stage
* + system background
* + ui group
* +-- window group
* +---- background manager
* +-- shell elements
* +-- top window group
* +-- workspace view
* +-- window switcher
* +-- window overview
* +-- notification group
* +-- pointer locator
* +-- dwell click timer
* +-- screen shield
*/
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 ();
ui_group.reactive = true;
stage.add_child (ui_group);
window_group = display.get_window_group ();
stage.remove_child (window_group);
ui_group.add_child (window_group);
background_group = new BackgroundContainer (display);
((BackgroundContainer)background_group).show_background_menu.connect (on_show_background_menu);
window_group.add_child (background_group);
window_group.set_child_below_sibling (background_group, null);
top_window_group = display.get_top_window_group ();
stage.remove_child (top_window_group);
ui_group.add_child (top_window_group);
FilterManager.init (this);
/*keybindings*/
var keybinding_settings = new GLib.Settings (Config.SCHEMA + ".keybindings");
display.add_keybinding ("switch-to-workspace-first", keybinding_settings, Meta.KeyBindingFlags.IGNORE_AUTOREPEAT, (Meta.KeyHandlerFunc) handle_switch_to_workspace_end);
display.add_keybinding ("switch-to-workspace-last", keybinding_settings, Meta.KeyBindingFlags.IGNORE_AUTOREPEAT, (Meta.KeyHandlerFunc) handle_switch_to_workspace_end);
display.add_keybinding ("move-to-workspace-first", keybinding_settings, Meta.KeyBindingFlags.IGNORE_AUTOREPEAT, (Meta.KeyHandlerFunc) handle_move_to_workspace_end);
display.add_keybinding ("move-to-workspace-last", keybinding_settings, Meta.KeyBindingFlags.IGNORE_AUTOREPEAT, (Meta.KeyHandlerFunc) handle_move_to_workspace_end);
display.add_keybinding ("cycle-workspaces-next", keybinding_settings, Meta.KeyBindingFlags.NONE, (Meta.KeyHandlerFunc) handle_cycle_workspaces);
display.add_keybinding ("cycle-workspaces-previous", keybinding_settings, Meta.KeyBindingFlags.NONE, (Meta.KeyHandlerFunc) handle_cycle_workspaces);
display.add_keybinding ("panel-main-menu", keybinding_settings, Meta.KeyBindingFlags.IGNORE_AUTOREPEAT, (Meta.KeyHandlerFunc) handle_applications_menu);
display.add_keybinding ("switch-input-source", keybinding_settings, Meta.KeyBindingFlags.IGNORE_AUTOREPEAT, (Meta.KeyHandlerFunc) handle_switch_input_source);
display.add_keybinding ("switch-input-source-backward", keybinding_settings, Meta.KeyBindingFlags.IGNORE_AUTOREPEAT, (Meta.KeyHandlerFunc) handle_switch_input_source);
display.add_keybinding ("screenshot", keybinding_settings, Meta.KeyBindingFlags.IGNORE_AUTOREPEAT, (Meta.KeyHandlerFunc) handle_screenshot);
display.add_keybinding ("window-screenshot", keybinding_settings, Meta.KeyBindingFlags.IGNORE_AUTOREPEAT, (Meta.KeyHandlerFunc) handle_screenshot);
display.add_keybinding ("area-screenshot", keybinding_settings, Meta.KeyBindingFlags.IGNORE_AUTOREPEAT, (Meta.KeyHandlerFunc) handle_screenshot);
display.add_keybinding ("screenshot-clip", keybinding_settings, Meta.KeyBindingFlags.IGNORE_AUTOREPEAT, (Meta.KeyHandlerFunc) handle_screenshot);
display.add_keybinding ("window-screenshot-clip", keybinding_settings, Meta.KeyBindingFlags.IGNORE_AUTOREPEAT, (Meta.KeyHandlerFunc) handle_screenshot);
display.add_keybinding ("area-screenshot-clip", keybinding_settings, Meta.KeyBindingFlags.IGNORE_AUTOREPEAT, (Meta.KeyHandlerFunc) handle_screenshot);
display.overlay_key.connect (() => {
launch_action ("overlay-action");
});
Meta.KeyBinding.set_custom_handler ("toggle-recording", () => {
launch_action ("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", (Meta.KeyHandlerFunc) handle_switch_to_workspace);
Meta.KeyBinding.set_custom_handler ("switch-to-workspace-right", (Meta.KeyHandlerFunc) 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", (Meta.KeyHandlerFunc) handle_move_to_workspace);
Meta.KeyBinding.set_custom_handler ("move-to-workspace-right", (Meta.KeyHandlerFunc) handle_move_to_workspace);
unowned var monitor_manager = display.get_context ().get_backend ().get_monitor_manager ();
monitor_manager.monitors_changed.connect (on_monitors_changed);
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);
accent_color_manager = new AccentColorManager ();
// initialize plugins and add default components if no plugin overrides them
var plugin_manager = PluginManager.get_default ();
plugin_manager.initialize (this);
plugin_manager.regions_changed.connect (update_input_area);
if (plugin_manager.workspace_view_provider == null
|| (workspace_view = (plugin_manager.get_plugin (plugin_manager.workspace_view_provider) as ActivatableComponent)) == null) {
workspace_view = new MultitaskingView (this);
ui_group.add_child ((Clutter.Actor) workspace_view);
}
Meta.KeyBinding.set_custom_handler ("show-desktop", () => {
if (workspace_view.is_opened ())
workspace_view.close ();
else
workspace_view.open ();
});
if (plugin_manager.window_switcher_provider == null) {
winswitcher = new WindowSwitcher (this);
ui_group.add_child (winswitcher);
Meta.KeyBinding.set_custom_handler ("switch-applications", (Meta.KeyHandlerFunc) winswitcher.handle_switch_windows);
Meta.KeyBinding.set_custom_handler ("switch-applications-backward", (Meta.KeyHandlerFunc) winswitcher.handle_switch_windows);
Meta.KeyBinding.set_custom_handler ("switch-windows", (Meta.KeyHandlerFunc) winswitcher.handle_switch_windows);
Meta.KeyBinding.set_custom_handler ("switch-windows-backward", (Meta.KeyHandlerFunc) winswitcher.handle_switch_windows);
Meta.KeyBinding.set_custom_handler ("switch-group", (Meta.KeyHandlerFunc) winswitcher.handle_switch_windows);
Meta.KeyBinding.set_custom_handler ("switch-group-backward", (Meta.KeyHandlerFunc) winswitcher.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);
}
notification_group = new Clutter.Actor ();
ui_group.add_child (notification_group);
pointer_locator = new PointerLocator (this);
ui_group.add_child (pointer_locator);
ui_group.add_child (new DwellClickTimer (this));
ui_group.add_child (screen_shield);
display.add_keybinding ("expose-windows", keybinding_settings, Meta.KeyBindingFlags.IGNORE_AUTOREPEAT, () => {
if (window_overview.is_opened ()) {
window_overview.close ();
} else {
window_overview.open ();
}
});
display.add_keybinding ("expose-all-windows", keybinding_settings, Meta.KeyBindingFlags.IGNORE_AUTOREPEAT, () => {
if (window_overview.is_opened ()) {
window_overview.close ();
} else {
var hints = new HashTable<string,Variant> (str_hash, str_equal);
hints.@set ("all-windows", true);
window_overview.open (hints);
}
});
plugin_manager.load_waiting_plugins ();
update_input_area ();
// while a workspace is being switched mutter doesn't map windows
// TODO: currently only notifications are handled here, other windows should be too
display.window_created.connect ((window) => {
if (!animating_switch_workspace) {
return;
}
if (window.window_type == Meta.WindowType.NOTIFICATION) {
unowned var actor = (Meta.WindowActor) window.get_compositor_private ();
clutter_actor_reparent (actor, notification_group);
notification_stack.show_notification (actor, enable_animations);
}
});
stage.show ();
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;
});
return false;
}
private void launch_action (string action_key) {
try {
var action = behavior_settings.get_string (action_key);
if (action != null && action != "") {
Process.spawn_command_line_async (action);
}
} catch (Error e) { warning (e.message); }
}
private void on_show_background_menu (int x, int y) {
if (daemon_proxy == null) {
return;
}
daemon_proxy.show_desktop_menu.begin (x, y, (obj, res) => {
try {
((Daemon) obj).show_desktop_menu.end (res);
} catch (Error e) {
message ("Error invoking MenuManager: %s", e.message);
}
});
}
private void on_monitors_changed () {
screen_shield.expand_to_screen_size ();
}
[CCode (instance_pos = -1)]
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 Meta.WorkspaceManager manager = display.get_workspace_manager ();
var index = manager.get_active_workspace_index () + direction;
int dynamic_offset = Meta.Prefs.get_dynamic_workspaces () ? 1 : 0;
if (index < 0)
index = manager.get_n_workspaces () - 1 - dynamic_offset;
else if (index > manager.get_n_workspaces () - 1 - dynamic_offset)
index = 0;
manager.get_workspace_by_index (index).activate (display.get_current_time ());
}
[CCode (instance_pos = -1)]
private void handle_move_to_workspace (Meta.Display display, Meta.Window? window,
Clutter.KeyEvent event, Meta.KeyBinding binding) {
if (window == null)
return;
var direction = (binding.get_name () == "move-to-workspace-left" ? Meta.MotionDirection.LEFT : Meta.MotionDirection.RIGHT);
move_window (window, direction);
}
[CCode (instance_pos = -1)]
private void handle_move_to_workspace_end (Meta.Display display, Meta.Window? window,
Clutter.KeyEvent event, Meta.KeyBinding binding) {
if (window == null)
return;
unowned Meta.WorkspaceManager manager = display.get_workspace_manager ();
var index = (binding.get_name () == "move-to-workspace-first" ? 0 : manager.get_n_workspaces () - 1);
var workspace = manager.get_workspace_by_index (index);
window.change_workspace (workspace);
workspace.activate_with_focus (window, display.get_current_time ());
}
[CCode (instance_pos = -1)]
private void handle_switch_to_workspace (Meta.Display display, Meta.Window? window,
Clutter.KeyEvent event, Meta.KeyBinding binding) {
var direction = (binding.get_name () == "switch-to-workspace-left" ? Meta.MotionDirection.LEFT : Meta.MotionDirection.RIGHT);
switch_to_next_workspace (direction);
}
[CCode (instance_pos = -1)]
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 (display.get_current_time ());
}
[CCode (instance_pos = -1)]
private void handle_applications_menu (Meta.Display display, Meta.Window? window,
Clutter.KeyEvent event, Meta.KeyBinding binding) {
launch_action ("panel-main-menu-action");
}
[CCode (instance_pos = -1)]
private void handle_switch_input_source (Meta.Display display, Meta.Window? window,
Clutter.KeyEvent event, Meta.KeyBinding binding) {
KeyboardManager.handle_modifiers_accelerator_activated (display, binding.get_name ().has_suffix ("-backward"));
}
[CCode (instance_pos = -1)]
private void handle_screenshot (Meta.Display display, Meta.Window? window,
Clutter.KeyEvent event, Meta.KeyBinding binding) {
switch (binding.get_name ()) {
case "screenshot":
screenshot_screen.begin ();
break;
case "area-screenshot":
screenshot_area.begin ();
break;
case "window-screenshot":
screenshot_current_window.begin ();
break;
case "screenshot-clip":
screenshot_screen.begin (true);
break;
case "area-screenshot-clip":
screenshot_area.begin (true);
break;
case "window-screenshot-clip":
screenshot_current_window.begin (true);
break;
}
}
private void on_gesture_detected (Gesture gesture) {
if (workspace_view.is_opened ()) {
return;
}
var can_handle_swipe = gesture.type == Clutter.EventType.TOUCHPAD_SWIPE &&
(gesture.direction == GestureDirection.LEFT || gesture.direction == GestureDirection.RIGHT);
var fingers = (gesture.fingers == 3 && GestureSettings.get_string ("three-finger-swipe-horizontal") == "switch-to-workspace") ||
(gesture.fingers == 4 && GestureSettings.get_string ("four-finger-swipe-horizontal") == "switch-to-workspace");
switch_workspace_with_gesture = can_handle_swipe && fingers;
if (switch_workspace_with_gesture) {
var direction = gesture_tracker.settings.get_natural_scroll_direction (gesture);
switch_to_next_workspace (direction);
}
}
/**
* {@inheritDoc}
*/
public void switch_to_next_workspace (Meta.MotionDirection direction) {
if (animating_switch_workspace || animating_nudge) {
return;
}
unowned Meta.Display display = get_display ();
var active_workspace = display.get_workspace_manager ().get_active_workspace ();
var neighbor = active_workspace.get_neighbor (direction);
if (neighbor != active_workspace) {
neighbor.activate (display.get_current_time ());
} else {
// if we didn't switch, show a nudge-over animation if one is not already in progress
if (workspace_view.is_opened () && workspace_view is MultitaskingView) {
((MultitaskingView) workspace_view).play_nudge_animation (direction);
} else {
play_nudge_animation (direction);
}
}
}
private void play_nudge_animation (Meta.MotionDirection direction) {
if (!enable_animations) {
return;
}
animating_nudge = true;
var scale = get_display ().get_monitor_scale (get_display ().get_primary_monitor ());
var nudge_gap = InternalUtils.scale_to_int ((int)NUDGE_GAP, scale);
float dest = 0;
if (!switch_workspace_with_gesture) {
dest = nudge_gap;
} else {
unowned Meta.Display display = get_display ();
var workspaces_geometry = InternalUtils.get_workspaces_geometry (display);
dest = workspaces_geometry.width;
}
if (direction == Meta.MotionDirection.RIGHT) {
dest *= -1;
}
GestureTracker.OnUpdate on_animation_update = (percentage) => {
var x = GestureTracker.animation_value (0.0f, dest, percentage, true);
ui_group.translation_x = x.clamp (-nudge_gap, nudge_gap);
};
GestureTracker.OnEnd on_animation_end = (percentage, cancel_action) => {
var nudge_gesture = new Clutter.PropertyTransition ("translation-x") {
duration = (AnimationDuration.NUDGE / 2),
remove_on_complete = true,
progress_mode = Clutter.AnimationMode.LINEAR
};
nudge_gesture.set_from_value (ui_group.translation_x);
nudge_gesture.set_to_value (0.0f);
ui_group.add_transition ("nudge", nudge_gesture);
switch_workspace_with_gesture = false;
animating_nudge = false;
};
if (!switch_workspace_with_gesture) {
double[] keyframes = { 0.5 };
GLib.Value[] x = { dest };
var nudge = new Clutter.KeyframeTransition ("translation-x") {
duration = AnimationDuration.NUDGE,
remove_on_complete = true,
progress_mode = Clutter.AnimationMode.EASE_IN_QUAD
};
nudge.set_from_value (0.0f);
nudge.set_to_value (0.0f);
nudge.set_key_frames (keyframes);
nudge.set_values (x);
nudge.completed.connect (() => {
animating_nudge = false;
});
ui_group.add_transition ("nudge", nudge);
} else {
gesture_tracker.connect_handlers (null, (owned) on_animation_update, (owned) on_animation_end);
}
}
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 ())
InternalUtils.set_input_area (display, InputArea.FULLSCREEN);
else
InternalUtils.set_input_area (display, InputArea.DEFAULT);
}
private void show_bottom_stack_window (Meta.Window bottom_window) {
unowned Meta.Workspace workspace = bottom_window.get_workspace ();
if (Utils.get_n_windows (workspace) == 0) {
return;
}
var bottom_actor = bottom_window.get_compositor_private () as Meta.WindowActor;
if (enable_animations) {
animate_bottom_window_scale (bottom_actor);
}
uint fade_out_duration = 900U;
double[] op_keyframes = { 0.1, 0.9 };
GLib.Value[] opacity = { 20U, 20U };
workspace.list_windows ().@foreach ((window) => {
if (window.get_xwindow () == bottom_window.get_xwindow ()
|| !InternalUtils.get_window_is_normal (window)
|| window.minimized) {
return;
}
var actor = window.get_compositor_private () as Clutter.Actor;
if (enable_animations) {
var op_trans = new Clutter.KeyframeTransition ("opacity") {
duration = fade_out_duration,
remove_on_complete = true,
progress_mode = Clutter.AnimationMode.EASE_IN_OUT_QUAD
};
op_trans.set_from_value (255.0f);
op_trans.set_to_value (255.0f);
op_trans.set_key_frames (op_keyframes);
op_trans.set_values (opacity);
actor.add_transition ("opacity-hide", op_trans);
} else {
Timeout.add ((uint)(fade_out_duration * op_keyframes[0]), () => {
actor.opacity = (uint)opacity[0];
return false;
});
Timeout.add ((uint)(fade_out_duration * op_keyframes[1]), () => {
actor.opacity = 255U;
return false;
});
}
});
}
private void animate_bottom_window_scale (Meta.WindowActor actor) {
const string[] PROPS = { "scale-x", "scale-y" };
foreach (string prop in PROPS) {
double[] scale_keyframes = { 0.2, 0.3, 0.8 };
GLib.Value[] scale = { 1.0f, 1.07f, 1.07f };
var scale_trans = new Clutter.KeyframeTransition (prop) {
duration = 500,
remove_on_complete = true,
progress_mode = Clutter.AnimationMode.EASE_IN_QUAD
};
scale_trans.set_from_value (1.0f);
scale_trans.set_to_value (1.0f);
scale_trans.set_key_frames (scale_keyframes);
scale_trans.set_values (scale);
actor.add_transition ("magnify-%s".printf (prop), scale_trans);
}
}
/**
* {@inheritDoc}
*/
public void move_window (Meta.Window? window, Meta.MotionDirection direction) {
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 ();
unowned var next = active.get_neighbor (direction);
// don't allow empty workspaces to be created by moving, if we have dynamic workspaces
if (Meta.Prefs.get_dynamic_workspaces () && Utils.get_n_windows (active) == 1 && next.index () == manager.n_workspaces - 1) {
Clutter.get_default_backend ().get_default_seat ().bell_notify ();
return;
}
// don't allow moving into non-existing workspaces
if (active == next) {
Clutter.get_default_backend ().get_default_seat ().bell_notify ();
return;
}
moving = window;
if (!window.is_on_all_workspaces ()) {
window.change_workspace (next);
}
next.activate_with_focus (window, display.get_current_time ());
}
/**
* {@inheritDoc}
*/
public ModalProxy push_modal (Clutter.Actor actor) {
var proxy = new ModalProxy ();
modal_stack.offer_head (proxy);
// modal already active
if (modal_stack.size >= 2)
return proxy;
unowned Meta.Display display = get_display ();
update_input_area ();
proxy.grab = stage.grab (actor);
if (modal_stack.size == 1) {
display.disable_unredirect ();
}
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;
}
proxy.grab.dismiss ();
if (is_modal ())
return;
update_input_area ();
unowned Meta.Display display = get_display ();
display.enable_unredirect ();
}
/**
* {@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 dim_parent_window (Meta.Window window, bool dim) {
unowned var ancestor = window.get_transient_for ();
if (ancestor != null && ancestor != window) {
unowned var win = (Meta.WindowActor) ancestor.get_compositor_private ();
// Can't rely on win.has_effects since other effects could be applied
if (dim) {
if (window.window_type == Meta.WindowType.MODAL_DIALOG) {
var dark_effect = new Clutter.BrightnessContrastEffect ();
dark_effect.set_brightness (-0.4f);
win.add_effect_with_name ("dim-parent", dark_effect);
}
} else if (win.get_effect ("dim-parent") != null) {
win.remove_effect_by_name ("dim-parent");
}
}
}
/**
* {@inheritDoc}
*/
public void perform_action (ActionType type) {
unowned Meta.Display display = get_display ();
var current = display.get_focus_window ();
switch (type) {
case ActionType.SHOW_WORKSPACE_VIEW:
if (workspace_view == null)
break;
if (workspace_view.is_opened ())
workspace_view.close ();
else
workspace_view.open ();
break;
case ActionType.MAXIMIZE_CURRENT:
if (current == null || current.window_type != Meta.WindowType.NORMAL || !current.can_maximize ())
break;
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);
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_MUTTER44
current.begin_grab_op (Meta.GrabOp.KEYBOARD_MOVING, null, null, Gtk.get_current_event_time ());
#else
current.begin_grab_op (Meta.GrabOp.KEYBOARD_MOVING, true, Gtk.get_current_event_time ());
#endif
break;
case ActionType.START_RESIZE_CURRENT:
if (current != null && current.allows_resize ())
#if HAS_MUTTER44
current.begin_grab_op (Meta.GrabOp.KEYBOARD_RESIZING_UNKNOWN, null, null, Gtk.get_current_event_time ());
#else
current.begin_grab_op (Meta.GrabOp.KEYBOARD_RESIZING_UNKNOWN, true, Gtk.get_current_event_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);
break;
case ActionType.SWITCH_TO_WORKSPACE_NEXT:
switch_to_next_workspace (Meta.MotionDirection.RIGHT);
break;
case ActionType.MOVE_CURRENT_WORKSPACE_LEFT:
move_window (current, Meta.MotionDirection.LEFT);
break;
case ActionType.MOVE_CURRENT_WORKSPACE_RIGHT:
move_window (current, Meta.MotionDirection.RIGHT);
break;
case ActionType.CLOSE_CURRENT:
if (current != null && current.can_close ())
current.@delete (Gtk.get_current_event_time ());
break;
case ActionType.OPEN_LAUNCHER:
try {
Process.spawn_command_line_async (
behavior_settings.get_string ("panel-main-menu-action")
);
} catch (Error e) {
warning (e.message);
}
break;
case ActionType.WINDOW_OVERVIEW:
if (window_overview == null)
break;
if (window_overview.is_opened ())
window_overview.close ();
else
window_overview.open ();
break;
case ActionType.WINDOW_OVERVIEW_ALL:
if (window_overview == null)
break;
if (window_overview.is_opened ())
window_overview.close ();
else {
var hints = new HashTable<string,Variant> (str_hash, str_equal);
hints.@set ("all-windows", true);
window_overview.open (hints);
}
break;
case ActionType.SWITCH_TO_WORKSPACE_LAST:
unowned Meta.WorkspaceManager manager = display.get_workspace_manager ();
var workspace = manager.get_workspace_by_index (manager.get_n_workspaces () - 1);
workspace.activate (display.get_current_time ());
break;
case ActionType.SCREENSHOT_CURRENT:
screenshot_current_window.begin ();
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 (daemon_proxy == null || window.get_window_type () == Meta.WindowType.NOTIFICATION) {
return;
}
WindowFlags flags = WindowFlags.NONE;
if (window.can_minimize ())
flags |= WindowFlags.CAN_HIDE;
if (window.can_maximize ())
flags |= WindowFlags.CAN_MAXIMIZE;
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;
}
}
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;
daemon_proxy.show_window_menu.begin (flags, x, y, (obj, res) => {
try {
((Daemon) obj).show_window_menu.end (res);
} catch (Error e) {
message ("Error invoking MenuManager: %s", e.message);
}
});
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, Meta.Rectangle tile_rect, int tile_monitor_number) {
if (tile_preview == null) {
tile_preview = new Clutter.Actor ();
var rgba = InternalUtils.get_theme_accent_color ();
tile_preview.background_color = {
(uint8)(255.0 * rgba.red),
(uint8)(255.0 * rgba.green),
(uint8)(255.0 * rgba.blue),