Skip to content

Commit

Permalink
getModiferState: always return 0 on X11
Browse files Browse the repository at this point in the history
The clutter reported modifier state is easily stuck on X11:
- Enter "clutter mode". Press and hold ctrl whild exiting (usually ctrl-ecs)
- Clutter will now report ctrl after ctrl is released causing windows to go
  directly to dnd mode when moved.
  • Loading branch information
olejorgenb committed Mar 14, 2020
1 parent 3bfcb46 commit b33f2d8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
2 changes: 2 additions & 0 deletions notes.org
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,5 @@ To turn on off without disrupting flow too much use ~GLib.setenv("CLUTTER_SHOW_F
** Focus and active workspace
It's not possible the have a focused window which doesn't belong to the active workspace
~global.display.focus_window.workspace === workspaceManger.get_active_workspace()~
* Clutter animation
~time: 0~ does not result in an instant animation. A default duration seems to be selected instead.
11 changes: 1 addition & 10 deletions tiling.js
Original file line number Diff line number Diff line change
Expand Up @@ -2706,16 +2706,7 @@ function grabBegin(metaWindow, type) {
case Meta.GrabOp.MOVING:
inGrab = new Extension.imports.grab.MoveGrab(metaWindow, type);

let d;
if (Clutter.DeviceManager) {
let dm = Clutter.DeviceManager.get_default();
d = dm.get_core_device(Clutter.InputDeviceType.KEYBOARD_DEVICE);
} else {
let backend = Clutter.get_default_backend()
let seat = backend.get_default_seat()
d = seat.get_keyboard()
}
if (d.get_modifier_state() & Clutter.ModifierType.CONTROL_MASK) {
if (utils.getModiferState() & Clutter.ModifierType.CONTROL_MASK) {
inGrab.begin();
inGrab.beginDnD();
} else if (inGrab.initialSpace && inGrab.initialSpace.indexOf(metaWindow) > -1) {
Expand Down
33 changes: 33 additions & 0 deletions utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ function ppEnumValue(value, genum) {
}
}

function ppModiferState(state) {
let mods = [];
for (let [mod, mask] of Object.entries(imports.gi.Clutter.ModifierType)) {
if (mask & state) {
mods.push(mod);
}
}
return mods.join(", ")
}

/**
* Look up the function by name at call time. This makes it convenient to
* redefine the function without re-registering all signal handler, keybindings,
Expand Down Expand Up @@ -264,6 +274,29 @@ function warpPointer(x, y) {
}
}

/**
* Return current modifiers state (or'ed Clutter.ModifierType.*)
* NB: Only on wayland. (Returns 0 on X11)
*
* Note: It's possible to get the modifier state through Gdk on X11, but move
* grabs is not triggered when ctrl is held down, making it useless for our purpose atm.
*/
function getModiferState() {
if (!Meta.is_wayland_compositor())
return 0;

let keyboard;
if (Clutter.DeviceManager) {
let dm = Clutter.DeviceManager.get_default();
keyboard = dm.get_core_device(Clutter.InputDeviceType.KEYBOARD_DEVICE);
} else {
let backend = Clutter.get_default_backend();
let seat = backend.get_default_seat();
keyboard = seat.get_keyboard();
}
return keyboard.get_modifier_state();
}

function monitorOfPoint(x, y) {
// get_monitor_index_for_rect "helpfully" returns the primary monitor index for out of bounds rects..
const Main = imports.ui.main;
Expand Down

0 comments on commit b33f2d8

Please sign in to comment.