mirror of
https://github.com/gosticks/PaperWM.git
synced 2026-07-05 08:30:05 +00:00
Move keybinding bookkeeping out of extension.js
This commit is contained in:
101
extension.js
101
extension.js
@@ -6,7 +6,8 @@ var modules = [
|
||||
Extension.imports.liveAltTab, Extension.imports.utils,
|
||||
Extension.imports.stackoverlay, Extension.imports.app,
|
||||
Extension.imports.kludges, Extension.imports.topbar,
|
||||
Extension.imports.navigator, Extension.imports.settings
|
||||
Extension.imports.navigator, Extension.imports.settings,
|
||||
Extension.imports.keybindings,
|
||||
];
|
||||
var [ Tiling, Scratch, LiveAltTab,
|
||||
utils, StackOverlay,
|
||||
@@ -36,7 +37,9 @@ window.PaperWM = Extension;
|
||||
var wmSettings;
|
||||
var shellSettings;
|
||||
var paperSettings;
|
||||
var paperActions;
|
||||
|
||||
var paperActions = Extension.imports.keybindings.paperActions;
|
||||
|
||||
function init() {
|
||||
SESSIONID += "#";
|
||||
log(`init: ${SESSIONID}`);
|
||||
@@ -55,63 +58,6 @@ function init() {
|
||||
shellSettings = new Gio.Settings({ schema_id: "org.gnome.shell.keybindings"});
|
||||
paperSettings = convenience.getSettings();
|
||||
|
||||
/*
|
||||
Keep track of some mappings mutter doesn't do/expose
|
||||
- action-name -> action-id mapping
|
||||
- action-id -> action mapping
|
||||
- action -> handler
|
||||
*/
|
||||
paperActions = {
|
||||
actions: [],
|
||||
nameMap: {},
|
||||
unregisterSchemaless(actionId) {
|
||||
const i = this.actions.findIndex(a => a.id === actionId);
|
||||
if (i < 0) {
|
||||
log("Tried to remove un registered action", actionId);
|
||||
return;
|
||||
}
|
||||
delete this.nameMap[this.actions[i].name];
|
||||
this.actions.splice(i, 1);
|
||||
},
|
||||
registerSchemaless(actionId, actionName, handler) {
|
||||
let action = {
|
||||
id: actionId, name: actionName, handler
|
||||
}
|
||||
this.actions.push(action);
|
||||
this.nameMap[actionName] = action;
|
||||
},
|
||||
register: function(actionName, handler, metaKeyBindingFlags) {
|
||||
let id = registerMutterAction(actionName,
|
||||
handler,
|
||||
metaKeyBindingFlags);
|
||||
// If the id is NONE the action is already registered
|
||||
if (id === Meta.KeyBindingAction.NONE)
|
||||
return null;
|
||||
|
||||
let action = { id: id
|
||||
, name: actionName
|
||||
, handler: handler
|
||||
};
|
||||
this.actions.push(action);
|
||||
this.nameMap[actionName] = action;
|
||||
return action;
|
||||
},
|
||||
idOf: function(name) {
|
||||
let action = this.byName(name);
|
||||
if (action) {
|
||||
return action.id;
|
||||
} else {
|
||||
return Meta.KeyBindingAction.NONE;
|
||||
}
|
||||
},
|
||||
byName: function(name) {
|
||||
return this.nameMap[name];
|
||||
},
|
||||
byId: function(mutterId) {
|
||||
return this.actions.find(action => action.id == mutterId);
|
||||
}
|
||||
};
|
||||
|
||||
let dynamic_function_ref = utils.dynamic_function_ref;
|
||||
let as_key_handler = utils.as_key_handler;
|
||||
|
||||
@@ -311,43 +257,6 @@ function disable() {
|
||||
enabled = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a key-bindable action (from our own schema) in mutter.
|
||||
*
|
||||
* Return the assigned numeric id.
|
||||
*
|
||||
* NB: use `Meta.keybindings_set_custom_handler` to re-assign the handler.
|
||||
*/
|
||||
function registerMutterAction(action_name, handler, flags) {
|
||||
// Ripped from https://github.com/negesti/gnome-shell-extensions-negesti
|
||||
// Handles multiple gnome-shell versions
|
||||
flags = flags || Meta.KeyBindingFlags.NONE;
|
||||
|
||||
let settings = convenience.getSettings('org.gnome.Shell.Extensions.PaperWM.Keybindings')
|
||||
|
||||
if (Main.wm.addKeybinding && Shell.ActionMode){ // introduced in 3.16
|
||||
return Main.wm.addKeybinding(action_name,
|
||||
settings, flags,
|
||||
Shell.ActionMode.NORMAL,
|
||||
handler
|
||||
);
|
||||
} else if (Main.wm.addKeybinding && Shell.KeyBindingMode) { // introduced in 3.7.5
|
||||
// Shell.KeyBindingMode.NORMAL | Shell.KeyBindingMode.MESSAGE_TRAY,
|
||||
return Main.wm.addKeybinding(action_name,
|
||||
settings, flags,
|
||||
Shell.KeyBindingMode.NORMAL,
|
||||
handler
|
||||
);
|
||||
} else {
|
||||
return global.display.add_keybinding(
|
||||
action_name,
|
||||
settings,
|
||||
flags,
|
||||
handler
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function getConfigDir() {
|
||||
return Gio.file_new_for_path(GLib.getenv('HOME') + '/.config/paperwm');
|
||||
|
||||
@@ -8,10 +8,105 @@ var Utils = Extension.imports.utils;
|
||||
var Main = imports.ui.main;
|
||||
var Shell = imports.gi.Shell;
|
||||
|
||||
var convenience = Extension.imports.convenience;
|
||||
var signals = new Utils.Signals();
|
||||
|
||||
var Navigator = Extension.imports.navigator;
|
||||
var paperActions = Extension.imports.extension.paperActions;
|
||||
|
||||
/*
|
||||
Keep track of some mappings mutter doesn't do/expose
|
||||
- action-name -> action-id mapping
|
||||
- action-id -> action mapping
|
||||
- action -> handler
|
||||
*/
|
||||
var paperActions = {
|
||||
actions: [],
|
||||
nameMap: {},
|
||||
unregisterSchemaless(actionId) {
|
||||
const i = this.actions.findIndex(a => a.id === actionId);
|
||||
if (i < 0) {
|
||||
log("Tried to remove un registered action", actionId);
|
||||
return;
|
||||
}
|
||||
delete this.nameMap[this.actions[i].name];
|
||||
this.actions.splice(i, 1);
|
||||
},
|
||||
registerSchemaless(actionId, actionName, handler) {
|
||||
let action = {
|
||||
id: actionId, name: actionName, handler
|
||||
}
|
||||
this.actions.push(action);
|
||||
this.nameMap[actionName] = action;
|
||||
},
|
||||
register: function(actionName, handler, metaKeyBindingFlags) {
|
||||
let id = registerMutterAction(actionName,
|
||||
handler,
|
||||
metaKeyBindingFlags);
|
||||
// If the id is NONE the action is already registered
|
||||
if (id === Meta.KeyBindingAction.NONE)
|
||||
return null;
|
||||
|
||||
let action = { id: id
|
||||
, name: actionName
|
||||
, handler: handler
|
||||
};
|
||||
this.actions.push(action);
|
||||
this.nameMap[actionName] = action;
|
||||
return action;
|
||||
},
|
||||
idOf: function(name) {
|
||||
let action = this.byName(name);
|
||||
if (action) {
|
||||
return action.id;
|
||||
} else {
|
||||
return Meta.KeyBindingAction.NONE;
|
||||
}
|
||||
},
|
||||
byName: function(name) {
|
||||
return this.nameMap[name];
|
||||
},
|
||||
byId: function(mutterId) {
|
||||
return this.actions.find(action => action.id == mutterId);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Register a key-bindable action (from our own schema) in mutter.
|
||||
*
|
||||
* Return the assigned numeric id.
|
||||
*
|
||||
* NB: use `Meta.keybindings_set_custom_handler` to re-assign the handler.
|
||||
*/
|
||||
function registerMutterAction(action_name, handler, flags) {
|
||||
// Ripped from https://github.com/negesti/gnome-shell-extensions-negesti
|
||||
// Handles multiple gnome-shell versions
|
||||
flags = flags || Meta.KeyBindingFlags.NONE;
|
||||
|
||||
let settings = convenience.getSettings('org.gnome.Shell.Extensions.PaperWM.Keybindings')
|
||||
|
||||
if (Main.wm.addKeybinding && Shell.ActionMode){ // introduced in 3.16
|
||||
return Main.wm.addKeybinding(action_name,
|
||||
settings, flags,
|
||||
Shell.ActionMode.NORMAL,
|
||||
handler
|
||||
);
|
||||
} else if (Main.wm.addKeybinding && Shell.KeyBindingMode) { // introduced in 3.7.5
|
||||
// Shell.KeyBindingMode.NORMAL | Shell.KeyBindingMode.MESSAGE_TRAY,
|
||||
return Main.wm.addKeybinding(action_name,
|
||||
settings, flags,
|
||||
Shell.KeyBindingMode.NORMAL,
|
||||
handler
|
||||
);
|
||||
} else {
|
||||
return global.display.add_keybinding(
|
||||
action_name,
|
||||
settings,
|
||||
flags,
|
||||
handler
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var actionIdMap = {}; // actionID -> handler
|
||||
var keycomboMap = {}
|
||||
|
||||
Reference in New Issue
Block a user