Handle move-to-workspace-1-12 shortcuts directly (#1721)

Let it take the same codepath as the move to left/right
This commit is contained in:
Leo 2023-07-11 21:46:48 +09:00 committed by GitHub
parent b3e2f30385
commit b94ab5e8cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 15 deletions

View File

@ -168,13 +168,12 @@ namespace Gala {
public abstract void perform_action (ActionType type);
/**
* Moves the window to the workspace next to its current workspace in the given direction.
* Gala currently only supports LEFT and RIGHT.
* Moves the window to the given workspace.
*
* @param window The window to be moved
* @param direction The direction in which to move the window
* @param workspace The workspace the window should be moved to
*/
public abstract void move_window (Meta.Window? window, Meta.MotionDirection direction);
public abstract void move_window (Meta.Window? window, Meta.Workspace workspace);
/**
* Switches to the next workspace in the given direction.

View File

@ -282,6 +282,10 @@ namespace Gala {
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);
for (int i = 1; i < 13; i++) {
Meta.KeyBinding.set_custom_handler ("move-to-workspace-%d".printf (i), (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);
@ -444,11 +448,27 @@ namespace Gala {
[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)
if (window == null) {
return;
}
var direction = (binding.get_name () == "move-to-workspace-left" ? Meta.MotionDirection.LEFT : Meta.MotionDirection.RIGHT);
move_window (window, direction);
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));
var workspace_index = workspace_number - 1;
target_workspace = workspace_manager.get_workspace_by_index (workspace_index);
}
if (target_workspace != null) {
move_window (window, target_workspace);
}
}
[CCode (instance_pos = -1)]
@ -718,7 +738,7 @@ namespace Gala {
/**
* {@inheritDoc}
*/
public void move_window (Meta.Window? window, Meta.MotionDirection direction) {
public void move_window (Meta.Window? window, Meta.Workspace workspace) {
if (window == null) {
return;
}
@ -727,16 +747,15 @@ namespace Gala {
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) {
if (Meta.Prefs.get_dynamic_workspaces () && Utils.get_n_windows (active) == 1 && workspace.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) {
if (active == workspace) {
Clutter.get_default_backend ().get_default_seat ().bell_notify ();
return;
}
@ -744,10 +763,10 @@ namespace Gala {
moving = window;
if (!window.is_on_all_workspaces ()) {
window.change_workspace (next);
window.change_workspace (workspace);
}
next.activate_with_focus (window, display.get_current_time ());
workspace.activate_with_focus (window, display.get_current_time ());
}
/**
@ -913,10 +932,16 @@ namespace Gala {
switch_to_next_workspace (Meta.MotionDirection.RIGHT);
break;
case ActionType.MOVE_CURRENT_WORKSPACE_LEFT:
move_window (current, Meta.MotionDirection.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);
break;
case ActionType.MOVE_CURRENT_WORKSPACE_RIGHT:
move_window (current, Meta.MotionDirection.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);
break;
case ActionType.CLOSE_CURRENT:
if (current != null && current.can_close ())