Skip to content

Commit

Permalink
Merge branch 'develop' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
jtaala committed Jul 31, 2024
2 parents 1fef23a + 6f03be5 commit a21aa55
Show file tree
Hide file tree
Showing 11 changed files with 179 additions and 50 deletions.
50 changes: 50 additions & 0 deletions Settings.ui
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
<property name="step_increment">0.01</property>
<property name="page_increment">0.1</property>
</object>
<object class="GtkAdjustment" id="drag_drift_speed_adjustment">
<property name="upper">15</property>
<property name="lower">0</property>
<property name="step_increment">1</property>
<property name="page_increment">5</property>
</object>
<object class="GtkAdjustment" id="minimap_scale">
<property name="upper">95</property>
<property name="lower">0</property>
Expand Down Expand Up @@ -1248,6 +1254,50 @@
</child>
</object>
</child>
<child>
<object class="GtkListBoxRow">
<property name="activatable">False</property>
<property name="focusable">False</property>
<child>
<object class="GtkGrid">
<property name="focusable">False</property>
<property name="tooltip_text" translatable="yes">Sets the drift speed (px/ms) when mouse is at edge of montior when dragging windows.</property>
<property name="margin_start">12</property>
<property name="margin_end">12</property>
<property name="margin_top">6</property>
<property name="margin_bottom">6</property>
<property name="column_spacing">32</property>
<child>
<object class="GtkLabel">
<property name="focusable">False</property>
<property name="hexpand">1</property>
<property name="label" translatable="yes">Window drag (at edge) drift speed (px/ms)</property>
<property name="use_markup">1</property>
<property name="xalign">0</property>
<layout>
<property name="column">0</property>
<property name="row">0</property>
</layout>
</object>
</child>
<child>
<object class="GtkSpinButton" id="drag_drift_speed_spin">
<property name="width_chars">3</property>
<property name="max_width_chars">3</property>
<property name="adjustment">drag_drift_speed_adjustment</property>
<property name="numeric">1</property>
<property name="snap_to_ticks">1</property>
<property name="update_policy">always</property>
<layout>
<property name="column">1</property>
<property name="row">0</property>
</layout>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkListBoxRow">
<property name="activatable">False</property>
Expand Down
5 changes: 2 additions & 3 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as Util from 'resource:///org/gnome/shell/misc/util.js';

import {
Utils, Settings, Gestures, Keybindings, LiveAltTab, Navigator,
Stackoverlay, Scratch, Workspace, Tiling, Topbar, Patches, App
Stackoverlay, Scratch, Workspace, Tiling, Topbar, Patches, App, Grab
} from './imports.js';

import { Extension } from 'resource:///org/gnome/shell/extensions/extension.js';
Expand Down Expand Up @@ -49,14 +49,13 @@ export default class PaperWM extends Extension {
modules = [
Utils, Settings, Patches,
Gestures, Keybindings, LiveAltTab, Navigator, Stackoverlay, Scratch,
Workspace, Tiling, Topbar, App,
Workspace, Tiling, Topbar, App, Grab,
];

#userStylesheet = null;

enable() {
console.log(`#PaperWM enabled`);

this.enableUserConfig();
this.enableUserStylesheet();

Expand Down
6 changes: 6 additions & 0 deletions gestures.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,12 @@ export function done(space) {
});
}

/**
* Finds a target window given a space and direction (-1 is left, 1 is right)
* @param {Tiling.Space} space
* @param {Boolean} direction
* @returns
*/
export function findTargetWindow(space, direction) {
let selected = space.selectedWindow?.clone;
if (!selected) {
Expand Down
142 changes: 99 additions & 43 deletions grab.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
import Clutter from 'gi://Clutter';
import GLib from 'gi://GLib';
import Graphene from 'gi://Graphene';
import Meta from 'gi://Meta';
import St from 'gi://St';

import * as Main from 'resource:///org/gnome/shell/ui/main.js';

import { Settings, Utils, Tiling, Navigator, Scratch } from './imports.js';
import { Settings, Utils, Tiling, Navigator, Scratch, Gestures } from './imports.js';
import { Easer } from './utils.js';

export let grabbed = false;

let dragDriftTimeout;
export function enable() {

}

export function disable() {
grabbed = null;
Utils.timeout_remove(dragDriftTimeout);
dragDriftTimeout = null;
}

/**
* Returns a virtual pointer (i.e. mouse) device that can be used to
* "clickout" of a drag operation when `grab_end_op` is unavailable
Expand All @@ -30,7 +44,8 @@ export class MoveGrab {
this.window = metaWindow;
this.type = type;
this.signals = new Utils.Signals();
this.grabbed = false;

this.dragDriftPx = 12;

this.initialSpace = space || Tiling.spaces.spaceOfWindow(metaWindow);
this.zoneActors = new Set();
Expand All @@ -46,10 +61,10 @@ export class MoveGrab {
console.debug("#grab", "begin");

this.center = center;
if (this.grabbed)
if (grabbed)
return;

this.grabbed = true;
grabbed = true;
global.display.end_grab_op?.(global.get_current_time());
global.display.set_cursor(Meta.Cursor.MOVE_OR_RESIZE_WINDOW);
this.dispatcher = new Navigator.getActionDispatcher(Clutter.GrabState.POINTER);
Expand Down Expand Up @@ -288,33 +303,73 @@ export class MoveGrab {
}

const sameTarget = (a, b) => {
if (a === b)
if (a === b) {
return true;
if (!a || !b)
}
if (!a || !b) {
return false;
}
if (a.space !== b.space) {
return false;
}
if (a.position.length !== b.position.length) {
return false;
return a.space === b.space && a.position[0] === b.position[0] && a.position[1] === b.position[1];
}
return a.position[0] === b.position[0] &&
a.position[1] === b.position[1];
};

if (!sameTarget(target, this.dndTarget)) {
// has a new zone target
if (target) {
this.dndTargets.push(target);
}
this.dndTarget = null;
this.activateDndTarget(target, initial);
}
}

_dragDrfit(space, dx, xfunc) {
// only dift is more than one tiled window
if (space.getWindows().filter(w => Tiling.isTiled(w)).length <= 0) {
return;
}

Utils.timeout_remove(dragDriftTimeout);
dragDriftTimeout = GLib.timeout_add(GLib.PRIORITY_DEFAULT, 1, () => {
const [px] = global.get_pointer();
if (xfunc(px)) {
return false;
}
if (space !== Tiling?.spaces?.activeSpace) {
return false;
}
Gestures.update(space, dx, 1);
return true;
});
}

motion(_actor, event) {
let metaWindow = this.window;
const metaWindow = this.window;
let [gx, gy] = global.get_pointer();

// drift move
const monitor = Utils.monitorAtPoint(gx, gy);
if (gx >= monitor.x && gx <= monitor.x + this.dragDriftPx) {
this._dragDrfit(
this.initialSpace,
-1 * Settings.prefs.drag_drift_speed, x => x > monitor.x + this.dragDriftPx
);
}
if (gx <= monitor.x + monitor.width && gx >= monitor.x + monitor.width - this.dragDriftPx) {
this._dragDrfit(
this.initialSpace,
Settings.prefs.drag_drift_speed, x => x < monitor.x + monitor.width - this.dragDriftPx
);
}

if (event.type() === Clutter.EventType.TOUCH_UPDATE) {
[gx, gy] = event.get_coords();
// We update global pointer to match touch event
Utils.warpPointer(gx, gy, false);
}
let [dx, dy] = this.pointerOffset;
let clone = metaWindow?.clone;
const clone = metaWindow?.clone;

// check if window and clone exists
if (!clone) {
Expand All @@ -333,41 +388,42 @@ export class MoveGrab {
clone.x = gx - dx;
clone.y = gy - dy;
}
} else {
let monitor = Utils.monitorAtPoint(gx, gy);
if (monitor !== this.initialSpace.monitor) {
this.beginDnD();
return;
}
return;
}

if (event.get_state() & Clutter.ModifierType.CONTROL_MASK) {
// NB: only works in wayland
this.beginDnD();
return;
}
if (monitor !== this.initialSpace.monitor) {
this.beginDnD();
return;
}

let space = this.initialSpace;
let clone = metaWindow.clone;
let [x, y] = space.globalToViewport(gx, gy);
space.targetX = x - this.scrollAnchor;
space.cloneContainer.x = space.targetX;

clone.y = y - dy;

const threshold = 300;
dy = Math.min(threshold, Math.abs(clone.y - this.initialY));
let s = 1 - Math.pow(dy / 500, 3);
let actor = metaWindow.get_compositor_private();
actor.set_scale(s, s);
clone.set_scale(s, s);

if (dy >= threshold) {
this.beginDnD();
}
if (event.get_state() & Clutter.ModifierType.CONTROL_MASK) {
// NB: only works in wayland
this.beginDnD();
return;
}

const space = this.initialSpace;
let [x, y] = space.globalToViewport(gx, gy);
space.targetX = x - this.scrollAnchor;
space.cloneContainer.x = space.targetX;

clone.y = y - dy;

const threshold = 300;
dy = Math.min(threshold, Math.abs(clone.y - this.initialY));
let s = 1 - Math.pow(dy / 500, 3);
let actor = metaWindow.get_compositor_private();
actor.set_scale(s, s);
clone.set_scale(s, s);

if (dy >= threshold) {
this.beginDnD();
}
}

end() {
grabbed = null;
Utils.timeout_remove(dragDriftTimeout);
console.debug("#grab", "end");
this.signals.destroy();
this.signals = null;
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"url": "https://github.com/paperwm/PaperWM",
"settings-schema": "org.gnome.shell.extensions.paperwm",
"shell-version": [ "45", "46" ],
"version-name": "46.13.8",
"version-name": "46.14.0",
"donations": {
"buymeacoffee": "jaytaala",
"patreon": "valpackett"
Expand Down
1 change: 1 addition & 0 deletions prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ class SettingsWidget {
hFric.connect('value-changed', fricChanged);

doubleValueChanged('animation_time_spin', 'animation-time');
intValueChanged('drag_drift_speed_spin', 'drag-drift-speed');
percentValueChanged('minimap_scale_spin', 'minimap-scale');
percentValueChanged('window_switcher_preview_scale_spin', 'window-switcher-preview-scale');
percentValueChanged('overview_max_window_scale_spin', 'overview-max-window-scale');
Expand Down
Binary file modified schemas/gschemas.compiled
Binary file not shown.
5 changes: 5 additions & 0 deletions schemas/org.gnome.shell.extensions.paperwm.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,11 @@
<summary>Duration of animations in seconds</summary>
</key>

<key type="i" name="drag-drift-speed">
<default>2</default>
<summary>Drift speed (px/ms) when mouse is at edge of montior when dragging windows</summary>
</key>

<key type="d" name="overview-max-window-scale">
<default>0.95</default>
<summary>Sets the maximum window scale (compared to actual window size) of Gnome overview windows</summary>
Expand Down
1 change: 1 addition & 0 deletions settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export function enable(extension) {
'workspace-colors',
'default-background',
'animation-time',
'drag-drift-speed',
'default-show-top-bar',
'swipe-sensitivity',
'swipe-friction',
Expand Down
15 changes: 13 additions & 2 deletions stackoverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,18 @@ export class StackOverlay {
const [x] = global.get_pointer();
switch (this._direction) {
case Meta.MotionDirection.LEFT:
if (x <= 2) {
if (
x >= this.monitor.x &&
x <= this.monitor.x + 2
) {
return true;
}
break;
case Meta.MotionDirection.RIGHT:
if (x >= this.monitor.width - 2) {
if (
x <= this.monitor.x + this.monitor.width &&
x >= this.monitor.x + this.monitor.width - 2
) {
return true;
}
break;
Expand Down Expand Up @@ -355,6 +361,11 @@ export class StackOverlay {
return;
}

// don't show if window grabbed
if (Grab.grabbed) {
return;
}

/**
* if timeout is enabled, only show if valid timeout (e.g. if SHOW_DELAY <= timeout,
* then won't see the preview anyway).
Expand Down
2 changes: 1 addition & 1 deletion tiling.js
Original file line number Diff line number Diff line change
Expand Up @@ -4217,7 +4217,7 @@ export function ensuredX(meta_window, space) {
* @returns
*/
export function ensureViewport(meta_window, space, options = {}) {
space = space || spaces.spaceOfWindow(meta_window);
space = space ?? spaces.spaceOfWindow(meta_window);
let force = options?.force ?? false;
let moveto = options?.moveto ?? true;
let animate = options?.animate ?? true;
Expand Down

0 comments on commit a21aa55

Please sign in to comment.