Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve handling of move-to-workspace shortcut #1721

Merged
merged 4 commits into from Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 3 additions & 4 deletions lib/WindowManager.vala
Expand Up @@ -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.
Expand Down
48 changes: 37 additions & 11 deletions src/WindowManager.vala
Expand Up @@ -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);

Expand Down Expand Up @@ -444,11 +448,28 @@ 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;
}

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;

var direction = (binding.get_name () == "move-to-workspace-left" ? Meta.MotionDirection.LEFT : Meta.MotionDirection.RIGHT);
move_window (window, direction);
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 name_parts = name.split ("-", 4);
var workspace_number = int.parse (name_parts[3]);
lenemter marked this conversation as resolved.
Show resolved Hide resolved
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)]
Expand Down Expand Up @@ -718,7 +739,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;
}
Expand All @@ -727,27 +748,26 @@ 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;
}

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 ());
}

/**
Expand Down Expand Up @@ -913,10 +933,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 ())
Expand Down