Skip to content

Commit 83e02e2

Browse files
committed
Filter actions in WindowManager.perform_action ()
ScreenshotManager: simplify composite_stage_cursor (#2740) Add cursor to the `image` directly instead of copying `image` to `target` and then adding cursor Don't handle window menus for windows that are not normal (#2736) Addresses #2723 Rework modal actions (#2739) We currently have duplicate keybinding filters across multiple components. This PR removes keybinding filter capabilities from modal proxies and instead introduces ModalActions flags. Then WindowManager filters keybindings based on these flags
1 parent f2441c7 commit 83e02e2

File tree

6 files changed

+92
-72
lines changed

6 files changed

+92
-72
lines changed

lib/Gestures/Gesture.vala

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,22 @@ namespace Gala {
4141
MULTITASKING_VIEW,
4242
ZOOM,
4343
CUSTOM,
44-
N_ACTIONS
44+
N_ACTIONS;
45+
46+
public ModalActions to_modal_action () {
47+
switch (this) {
48+
case SWITCH_WORKSPACE:
49+
return ModalActions.SWITCH_WORKSPACE;
50+
case SWITCH_WINDOWS:
51+
return ModalActions.SWITCH_WINDOWS;
52+
case MULTITASKING_VIEW:
53+
return ModalActions.MULTITASKING_VIEW;
54+
case ZOOM:
55+
return ModalActions.ZOOM;
56+
default:
57+
return ModalActions.NONE;
58+
}
59+
}
4560
}
4661

4762
public ModalActions gesture_action_to_modal_action (GestureAction gesture_action) {

lib/Gestures/GestureController.vala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public class Gala.GestureController : Object {
157157

158158
var recognized_action = GestureSettings.get_action (gesture, out _action_info);
159159
recognizing = (
160-
recognized_action == action && !wm.filter_action (gesture_action_to_modal_action (recognized_action)) ||
160+
recognized_action == action && !wm.filter_action (recognized_action.to_modal_action ()) ||
161161
backend == scroll_backend && recognized_action == NONE
162162
);
163163

lib/WindowManager.vala

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@ namespace Gala {
3838
MEDIA_KEYS
3939
}
4040

41-
/**
42-
* Function that should return true if the given shortcut should be blocked.
43-
*/
44-
public delegate bool KeybindingFilter (Meta.KeyBinding binding);
45-
4641
/**
4742
* A minimal class mostly used to identify your call to {@link WindowManager.push_modal} and used
4843
* to end your modal mode again with {@link WindowManager.pop_modal}

src/ScreenshotManager.vala

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ public class Gala.ScreenshotManager : Object {
345345
image.set_device_scale (resource_scale, resource_scale);
346346
}
347347

348-
image = composite_stage_cursor (image, { rect.x, rect.y, rect.width, rect.height });
348+
composite_stage_cursor (image, { rect.x, rect.y, rect.width, rect.height });
349349
}
350350

351351
unconceal_text ();
@@ -592,7 +592,7 @@ public class Gala.ScreenshotManager : Object {
592592
return image;
593593
}
594594

595-
private Cairo.ImageSurface composite_stage_cursor (Cairo.ImageSurface image, Cairo.RectangleInt image_rect) {
595+
private void composite_stage_cursor (Cairo.ImageSurface image, Cairo.RectangleInt image_rect) {
596596
#if HAS_MUTTER48
597597
unowned var cursor_tracker = wm.get_display ().get_compositor ().get_backend ().get_cursor_tracker ();
598598
#else
@@ -603,12 +603,12 @@ public class Gala.ScreenshotManager : Object {
603603

604604
var region = new Cairo.Region.rectangle (image_rect);
605605
if (!region.contains_point ((int) coords.x, (int) coords.y)) {
606-
return image;
606+
return;
607607
}
608608

609-
unowned Cogl.Texture texture = cursor_tracker.get_sprite ();
609+
unowned Cogl.Texture? texture = cursor_tracker.get_sprite ();
610610
if (texture == null) {
611-
return image;
611+
return;
612612
}
613613

614614
int width = (int)texture.get_width ();
@@ -618,18 +618,10 @@ public class Gala.ScreenshotManager : Object {
618618
texture.get_data (Cogl.PixelFormat.RGBA_8888, 0, data);
619619

620620
var cursor_image = new Cairo.ImageSurface.for_data (data, Cairo.Format.ARGB32, width, height, width * 4);
621-
var target = new Cairo.ImageSurface (Cairo.Format.ARGB32, image_rect.width, image_rect.height);
622-
623-
var cr = new Cairo.Context (target);
624-
cr.set_operator (Cairo.Operator.OVER);
625-
cr.set_source_surface (image, 0, 0);
626-
cr.paint ();
627-
621+
var cr = new Cairo.Context (image);
628622
cr.set_operator (Cairo.Operator.OVER);
629623
cr.set_source_surface (cursor_image, coords.x - image_rect.x, coords.y - image_rect.y);
630624
cr.paint ();
631-
632-
return (Cairo.ImageSurface)cr.get_target ();
633625
}
634626

635627
private async void wait_stage_repaint () {

src/Widgets/WindowSwitcher/WindowSwitcher.vala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ public class Gala.WindowSwitcher : CanvasActor, GestureTarget, RootTarget {
443443

444444
private void push_modal () {
445445
modal_proxy = wm.push_modal (get_stage (), true);
446-
modal_proxy.allow_actions (SWITCH_WINDOWS);
446+
modal_proxy.allow_actions (SWITCH_WINDOWS | LOCATE_POINTER | MEDIA_KEYS);
447447
}
448448

449449
private void close_switcher (uint32 time, bool cancel = false) {

src/WindowManager.vala

Lines changed: 68 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,10 @@ namespace Gala {
785785

786786
switch (type) {
787787
case ActionType.SHOW_MULTITASKING_VIEW:
788+
if (filter_action (MULTITASKING_VIEW)) {
789+
break;
790+
}
791+
788792
if (multitasking_view.is_opened ())
789793
multitasking_view.close ();
790794
else
@@ -847,9 +851,17 @@ namespace Gala {
847851
current.stick ();
848852
break;
849853
case ActionType.SWITCH_TO_WORKSPACE_PREVIOUS:
854+
if (filter_action (SWITCH_WORKSPACE)) {
855+
break;
856+
}
857+
850858
switch_to_next_workspace (Meta.MotionDirection.LEFT, Meta.CURRENT_TIME);
851859
break;
852860
case ActionType.SWITCH_TO_WORKSPACE_NEXT:
861+
if (filter_action (SWITCH_WORKSPACE)) {
862+
break;
863+
}
864+
853865
switch_to_next_workspace (Meta.MotionDirection.RIGHT, Meta.CURRENT_TIME);
854866
break;
855867
case ActionType.MOVE_CURRENT_WORKSPACE_LEFT:
@@ -872,7 +884,7 @@ namespace Gala {
872884
launch_action (ActionKeys.PANEL_MAIN_MENU_ACTION);
873885
break;
874886
case ActionType.WINDOW_OVERVIEW:
875-
if (window_overview == null) {
887+
if (window_overview == null || filter_action (WINDOW_OVERVIEW)) {
876888
break;
877889
}
878890

@@ -884,7 +896,7 @@ namespace Gala {
884896
critical ("Window overview is deprecated");
885897
break;
886898
case ActionType.WINDOW_OVERVIEW_ALL:
887-
if (window_overview == null) {
899+
if (window_overview == null || filter_action (WINDOW_OVERVIEW)) {
888900
break;
889901
}
890902

@@ -895,11 +907,19 @@ namespace Gala {
895907
}
896908
break;
897909
case ActionType.SWITCH_TO_WORKSPACE_LAST:
910+
if (filter_action (SWITCH_WORKSPACE)) {
911+
break;
912+
}
913+
898914
unowned var manager = display.get_workspace_manager ();
899915
unowned var workspace = manager.get_workspace_by_index (manager.get_n_workspaces () - 1);
900916
workspace.activate (display.get_current_time ());
901917
break;
902918
case ActionType.SCREENSHOT_CURRENT:
919+
if (filter_action (SCREENSHOT_WINDOW)) {
920+
break;
921+
}
922+
903923
screenshot_manager.handle_screenshot_current_window_shortcut.begin (false);
904924
break;
905925
default:
@@ -909,70 +929,68 @@ namespace Gala {
909929
}
910930

911931
public override void show_window_menu (Meta.Window window, Meta.WindowMenuType menu, int x, int y) {
912-
switch (menu) {
913-
case Meta.WindowMenuType.WM:
914-
if (NotificationStack.is_notification (window)) {
915-
return;
916-
}
932+
if (menu != WM) {
933+
warning ("Unsupported window menu type");
934+
return;
935+
}
917936

918-
WindowFlags flags = WindowFlags.NONE;
919-
if (window.can_minimize ())
920-
flags |= WindowFlags.CAN_HIDE;
937+
if (!Utils.get_window_is_normal (window) || NotificationStack.is_notification (window)) {
938+
return;
939+
}
921940

922-
if (window.can_maximize ())
923-
flags |= WindowFlags.CAN_MAXIMIZE;
941+
WindowFlags flags = WindowFlags.NONE;
942+
if (window.can_minimize ())
943+
flags |= WindowFlags.CAN_HIDE;
944+
945+
if (window.can_maximize ())
946+
flags |= WindowFlags.CAN_MAXIMIZE;
924947

925948
#if HAS_MUTTER49
926-
if (window.is_maximized ())
927-
flags |= WindowFlags.IS_MAXIMIZED;
949+
if (window.is_maximized ())
950+
flags |= WindowFlags.IS_MAXIMIZED;
928951

929-
if (window.maximized_vertically && !window.maximized_horizontally)
930-
flags |= WindowFlags.IS_TILED;
952+
if (window.maximized_vertically && !window.maximized_horizontally)
953+
flags |= WindowFlags.IS_TILED;
931954
#else
932-
var maximize_flags = window.get_maximized ();
933-
if (maximize_flags > 0) {
934-
flags |= WindowFlags.IS_MAXIMIZED;
955+
var maximize_flags = window.get_maximized ();
956+
if (maximize_flags > 0) {
957+
flags |= WindowFlags.IS_MAXIMIZED;
935958

936-
if (Meta.MaximizeFlags.VERTICAL in maximize_flags && !(Meta.MaximizeFlags.HORIZONTAL in maximize_flags)) {
937-
flags |= WindowFlags.IS_TILED;
938-
}
939-
}
959+
if (Meta.MaximizeFlags.VERTICAL in maximize_flags && !(Meta.MaximizeFlags.HORIZONTAL in maximize_flags)) {
960+
flags |= WindowFlags.IS_TILED;
961+
}
962+
}
940963
#endif
941964

942-
if (window.allows_move ())
943-
flags |= WindowFlags.ALLOWS_MOVE;
965+
if (window.allows_move ())
966+
flags |= WindowFlags.ALLOWS_MOVE;
944967

945-
if (window.allows_resize ())
946-
flags |= WindowFlags.ALLOWS_RESIZE;
968+
if (window.allows_resize ())
969+
flags |= WindowFlags.ALLOWS_RESIZE;
947970

948-
if (window.is_above ())
949-
flags |= WindowFlags.ALWAYS_ON_TOP;
971+
if (window.is_above ())
972+
flags |= WindowFlags.ALWAYS_ON_TOP;
950973

951-
if (window.on_all_workspaces)
952-
flags |= WindowFlags.ON_ALL_WORKSPACES;
974+
if (window.on_all_workspaces)
975+
flags |= WindowFlags.ON_ALL_WORKSPACES;
953976

954-
if (window.can_close ())
955-
flags |= WindowFlags.CAN_CLOSE;
977+
if (window.can_close ())
978+
flags |= WindowFlags.CAN_CLOSE;
956979

957-
unowned var workspace = window.get_workspace ();
958-
if (workspace != null) {
959-
unowned var manager = window.display.get_workspace_manager ();
960-
var workspace_index = workspace.workspace_index;
961-
if (workspace_index != 0) {
962-
flags |= WindowFlags.ALLOWS_MOVE_LEFT;
963-
}
964-
965-
if (workspace_index != manager.n_workspaces - 2 || Utils.get_n_windows (workspace) != 1) {
966-
flags |= WindowFlags.ALLOWS_MOVE_RIGHT;
967-
}
968-
}
980+
unowned var workspace = window.get_workspace ();
981+
if (workspace != null) {
982+
unowned var manager = window.display.get_workspace_manager ();
983+
var workspace_index = workspace.workspace_index;
984+
if (workspace_index != 0) {
985+
flags |= WindowFlags.ALLOWS_MOVE_LEFT;
986+
}
969987

970-
daemon_manager.show_window_menu.begin (flags, x, y);
971-
break;
972-
case Meta.WindowMenuType.APP:
973-
// FIXME we don't have any sort of app menus
974-
break;
988+
if (workspace_index != manager.n_workspaces - 2 || Utils.get_n_windows (workspace) != 1) {
989+
flags |= WindowFlags.ALLOWS_MOVE_RIGHT;
990+
}
975991
}
992+
993+
daemon_manager.show_window_menu.begin (flags, x, y);
976994
}
977995

978996
public override void show_tile_preview (Meta.Window window, Mtk.Rectangle tile_rect, int tile_monitor_number) {

0 commit comments

Comments
 (0)