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

Add Super+Scroll actions #2165

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions data/gala.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
<value nick="switch-to-workspace-last" value="10" />
</enum>

<enum id="SuperScrollAction">
<value nick="none" value="0" />
<value nick="switch-workspace" value="1" />
<value nick="zoom" value="2" />
</enum>

<schema path="/io/elementary/desktop/screensaver/" id="io.elementary.desktop.screensaver">
<key type="b" name="lock-on-suspend">
<default>true</default>
Expand Down Expand Up @@ -96,6 +102,11 @@
<summary>Whether hotcorners should be enabled when fullscreen window is opened</summary>
<description></description>
</key>
<key enum="SuperScrollAction" name="super-scroll-action">
<default>"none"</default>
<summary>What action should be performed on Super + Scroll</summary>
<description></description>
</key>
</schema>

<schema path="/io/elementary/desktop/wm/keybindings/" id="io.elementary.desktop.wm.keybindings">
Expand Down
6 changes: 6 additions & 0 deletions lib/WindowManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ namespace Gala {
*/
public abstract Gala.ActivatableComponent workspace_view { get; protected set; }

/*
* This signal is sent when Super + Scroll was performed and WindowManager couldn't handle it
* which probably means that the user doesn't want to switch workspaces on Super + Scroll.
*/
public abstract signal void super_scroll_triggered (uint32 timestamp, double dx, double dy);

/**
* Enters the modal mode, which means that all events are directed to the stage instead
* of the windows. This is the only way to receive keyboard events besides shortcut listeners.
Expand Down
47 changes: 47 additions & 0 deletions src/SuperScrollAction.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* SPDX-License-Identifier: GPL-3.0-or-later
* SPDX-FileCopyrightText: 2024 elementary, Inc. (https://elementary.io)
*/

public class Gala.SuperScrollAction : Clutter.Action {
public signal void triggered (uint32 timestamp, double dx, double dy);

public Meta.Display display { private get; construct; }

public SuperScrollAction (Meta.Display display) {
Object (display: display);
}

public override bool handle_event (Clutter.Event event) {
if (
event.get_type () == SCROLL &&
(event.get_state () & display.compositor_modifiers) != 0
) {
double dx = 0.0, dy = 0.0;
switch (event.get_scroll_direction ()) {
case LEFT:
dx = -1.0;
break;
case RIGHT:
dx = 1.0;
break;
case UP:
dy = 1.0;
break;
case DOWN:
dy = -1.0;
break;
default:
break;
}

// TODO: support natural scroll settings

triggered (event.get_time (), dx, dy);

return Clutter.EVENT_STOP;
}

return Clutter.EVENT_PROPAGATE;
}
}
19 changes: 19 additions & 0 deletions src/WindowManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,21 @@ namespace Gala {
#endif
}

private void handle_super_scroll (uint32 timestamp, double dx, double dy) {
if (behavior_settings.get_enum ("super-scroll-action") != 1) {
super_scroll_triggered (timestamp, dx, dy);
return;
}

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

#if WITH_SYSTEMD
private async void start_x11_services (GLib.Task task) {
try {
Expand Down Expand Up @@ -396,6 +411,10 @@ namespace Gala {

display.window_created.connect ((window) => window_created (window));

var scroll_action = new SuperScrollAction (display);
scroll_action.triggered.connect (handle_super_scroll);
stage.add_action_full ("super-scroll-action", CAPTURE, scroll_action);

stage.show ();

Idle.add (() => {
Expand Down
18 changes: 18 additions & 0 deletions src/Zoom.vala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class Gala.Zoom : Object {
private ulong wins_handler_id = 0UL;

private GestureTracker gesture_tracker;
private GLib.Settings behavior_settings;

public Zoom (WindowManager wm) {
Object (wm: wm);
Expand All @@ -32,6 +33,9 @@ public class Gala.Zoom : Object {
gesture_tracker = new GestureTracker (ANIMATION_DURATION, ANIMATION_DURATION);
gesture_tracker.enable_touchpad ();
gesture_tracker.on_gesture_detected.connect (on_gesture_detected);

behavior_settings = new GLib.Settings ("io.elementary.desktop.wm.behavior");
wm.super_scroll_triggered.connect (handle_super_scroll);
}

~Zoom () {
Expand Down Expand Up @@ -75,6 +79,20 @@ public class Gala.Zoom : Object {
}
}

private void handle_super_scroll (uint32 timestamp, double dx, double dy) {
if (behavior_settings.get_enum ("super-scroll-action") != 2) {
return;
}

var d = dx.abs () > dy.abs () ? dx : dy;

if (d > 0) {
zoom (SHORTCUT_DELTA, true, AnimationsSettings.get_enable_animations ());
} else if (d < 0) {
zoom (-SHORTCUT_DELTA, true, AnimationsSettings.get_enable_animations ());
}
}

private void zoom_with_gesture (GestureDirection direction) {
var initial_zoom = current_zoom;
var target_zoom = (direction == GestureDirection.IN)
Expand Down
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ gala_bin_sources = files(
'ScreenSaverManager.vala',
'ScreenshotManager.vala',
'SessionManager.vala',
'SuperScrollAction.vala',
'WindowAttentionTracker.vala',
'WindowGrabTracker.vala',
'WindowListener.vala',
Expand Down
Loading