forked from Shinonome/dots-hyprland
ags: allow configuring keybinds
https://github.com/end-4/dots-hyprland-wiki/issues/5
This commit is contained in:
@@ -0,0 +1,26 @@
|
|||||||
|
const { Gdk } = imports.gi;
|
||||||
|
|
||||||
|
const MODS = {
|
||||||
|
'NoMod': Gdk.ModifierType.NO_MODIFIER_MASK,
|
||||||
|
'Shift': Gdk.ModifierType.SHIFT_MASK,
|
||||||
|
'Ctrl': Gdk.ModifierType.CONTROL_MASK,
|
||||||
|
'Alt': Gdk.ModifierType.ALT_MASK,
|
||||||
|
'Hyper': Gdk.ModifierType.HYPER_MASK,
|
||||||
|
'Meta': Gdk.ModifierType.META_MASK
|
||||||
|
}
|
||||||
|
|
||||||
|
export const checkKeybind = (event, keybind) => {
|
||||||
|
const pressedModMask = event.get_state()[1];
|
||||||
|
const pressedKey = event.get_keyval()[1];
|
||||||
|
const keys = keybind.split('+');
|
||||||
|
for (let i = 0; i < keys.length; i++) {
|
||||||
|
if (keys[i] in MODS) {
|
||||||
|
if (!(pressedModMask & MODS[keys[i]])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (pressedKey !== Gdk[`KEY_${keys[i]}`]) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
CalculationResultButton, CustomCommandButton, DirectoryButton,
|
CalculationResultButton, CustomCommandButton, DirectoryButton,
|
||||||
DesktopEntryButton, ExecuteCommandButton, SearchButton
|
DesktopEntryButton, ExecuteCommandButton, SearchButton
|
||||||
} from './searchbuttons.js';
|
} from './searchbuttons.js';
|
||||||
|
import { checkKeybind } from '../.widgetutils/keybind.js';
|
||||||
|
|
||||||
// Add math funcs
|
// Add math funcs
|
||||||
const { abs, sin, cos, tan, cot, asin, acos, atan, acot } = Math;
|
const { abs, sin, cos, tan, cot, asin, acos, atan, acot } = Math;
|
||||||
@@ -237,24 +238,18 @@ export const SearchAndWindows = () => {
|
|||||||
.on('key-press-event', (widget, event) => { // Typing
|
.on('key-press-event', (widget, event) => { // Typing
|
||||||
const keyval = event.get_keyval()[1];
|
const keyval = event.get_keyval()[1];
|
||||||
const modstate = event.get_state()[1];
|
const modstate = event.get_state()[1];
|
||||||
if (modstate & Gdk.ModifierType.CONTROL_MASK) { // Ctrl held
|
if (checkKeybind(event, userOptions.keybinds.overview.altMoveLeft))
|
||||||
if (keyval == Gdk.KEY_b)
|
entry.set_position(Math.max(entry.get_position() - 1, 0));
|
||||||
entry.set_position(Math.max(entry.get_position() - 1, 0));
|
else if (checkKeybind(event, userOptions.keybinds.overview.altMoveRight))
|
||||||
else if (keyval == Gdk.KEY_f)
|
entry.set_position(Math.min(entry.get_position() + 1, entry.get_text().length));
|
||||||
entry.set_position(Math.min(entry.get_position() + 1, entry.get_text().length));
|
else if (checkKeybind(event, userOptions.keybinds.overview.deleteToEnd)) {
|
||||||
else if (keyval == Gdk.KEY_n) { // simulate Down arrow
|
const text = entry.get_text();
|
||||||
entry.get_root_window().simulate_key_press(Gdk.KEY_Down, Gdk.ModifierType.NONE);
|
const pos = entry.get_position();
|
||||||
// entry.get_root_window().simulate_key_release(Gdk.KEY_Down, Gdk.ModifierType.NONE);
|
const newText = text.slice(0, pos);
|
||||||
}
|
entry.set_text(newText);
|
||||||
else if (keyval == Gdk.KEY_k) { // Delete to end
|
entry.set_position(newText.length);
|
||||||
const text = entry.get_text();
|
|
||||||
const pos = entry.get_position();
|
|
||||||
const newText = text.slice(0, pos);
|
|
||||||
entry.set_text(newText);
|
|
||||||
entry.set_position(newText.length);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else { // Ctrl not held
|
else if (!(modstate & Gdk.ModifierType.CONTROL_MASK)) { // Ctrl not held
|
||||||
if (keyval >= 32 && keyval <= 126 && widget != entry) {
|
if (keyval >= 32 && keyval <= 126 && widget != entry) {
|
||||||
Utils.timeout(1, () => entry.grab_focus());
|
Utils.timeout(1, () => entry.grab_focus());
|
||||||
entry.set_text(entry.text + String.fromCharCode(keyval));
|
entry.set_text(entry.text + String.fromCharCode(keyval));
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import { chatGPTView, chatGPTCommands, sendMessage as chatGPTSendMessage, chatGP
|
|||||||
import { waifuView, waifuCommands, sendMessage as waifuSendMessage, waifuTabIcon } from './apis/waifu.js';
|
import { waifuView, waifuCommands, sendMessage as waifuSendMessage, waifuTabIcon } from './apis/waifu.js';
|
||||||
import { booruView, booruCommands, sendMessage as booruSendMessage, booruTabIcon } from './apis/booru.js';
|
import { booruView, booruCommands, sendMessage as booruSendMessage, booruTabIcon } from './apis/booru.js';
|
||||||
import { enableClickthrough } from "../.widgetutils/clickthrough.js";
|
import { enableClickthrough } from "../.widgetutils/clickthrough.js";
|
||||||
|
import { checkKeybind } from '../.widgetutils/keybind.js';
|
||||||
const TextView = Widget.subclass(Gtk.TextView, "AgsTextView");
|
const TextView = Widget.subclass(Gtk.TextView, "AgsTextView");
|
||||||
|
|
||||||
import { widgetContent } from './sideleft.js';
|
import { widgetContent } from './sideleft.js';
|
||||||
@@ -83,31 +84,25 @@ export const chatEntry = TextView({
|
|||||||
self.placeholderText = (Gemini.key.length > 0 ? 'Message Gemini...' : 'Enter Google AI API Key...');
|
self.placeholderText = (Gemini.key.length > 0 ? 'Message Gemini...' : 'Enter Google AI API Key...');
|
||||||
}, 'hasKey')
|
}, 'hasKey')
|
||||||
.on("key-press-event", (widget, event) => {
|
.on("key-press-event", (widget, event) => {
|
||||||
const keyval = event.get_keyval()[1];
|
// Don't send when Shift+Enter
|
||||||
if (event.get_keyval()[1] === Gdk.KEY_Return && event.get_state()[1] == Gdk.ModifierType.MOD2_MASK) {
|
if (event.get_keyval()[1] === Gdk.KEY_Return && event.get_state()[1] == Gdk.ModifierType.MOD2_MASK) {
|
||||||
apiSendMessage(widget);
|
apiSendMessage(widget);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// Keybinds
|
// Keybinds
|
||||||
if (!(event.get_state()[1] & Gdk.ModifierType.CONTROL_MASK)) {
|
if (checkKeybind(event, userOptions.keybinds.sidebar.cycleTab))
|
||||||
if (event.get_keyval()[1] === Gdk.KEY_Page_Down) {
|
widgetContent.cycleTab();
|
||||||
apiWidgets.attribute.nextTab();
|
else if (checkKeybind(event, userOptions.keybinds.sidebar.nextTab))
|
||||||
return true;
|
widgetContent.nextTab();
|
||||||
}
|
else if (checkKeybind(event, userOptions.keybinds.sidebar.prevTab))
|
||||||
else if (event.get_keyval()[1] === Gdk.KEY_Page_Up) {
|
widgetContent.prevTab();
|
||||||
apiWidgets.attribute.prevTab();
|
else if (checkKeybind(event, userOptions.keybinds.sidebar.apis.nextTab)) {
|
||||||
return true;
|
apiWidgets.attribute.nextTab();
|
||||||
}
|
return true;
|
||||||
}
|
}
|
||||||
else if (event.get_state()[1] & Gdk.ModifierType.CONTROL_MASK) {
|
else if (checkKeybind(event, userOptions.keybinds.sidebar.apis.prevTab)) {
|
||||||
if (event.get_keyval()[1] === Gdk.KEY_Page_Down) {
|
apiWidgets.attribute.prevTab();
|
||||||
widgetContent.nextTab();
|
return true;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if (event.get_keyval()[1] === Gdk.KEY_Page_Up) {
|
|
||||||
widgetContent.prevTab();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
,
|
,
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import toolBox from './toolbox.js';
|
|||||||
import apiWidgets from './apiwidgets.js';
|
import apiWidgets from './apiwidgets.js';
|
||||||
import { chatEntry } from './apiwidgets.js';
|
import { chatEntry } from './apiwidgets.js';
|
||||||
import { TabContainer } from '../.commonwidgets/tabcontainer.js';
|
import { TabContainer } from '../.commonwidgets/tabcontainer.js';
|
||||||
|
import { checkKeybind } from '../.widgetutils/keybind.js';
|
||||||
|
|
||||||
const contents = [
|
const contents = [
|
||||||
{
|
{
|
||||||
@@ -85,18 +86,15 @@ export default () => Box({
|
|||||||
],
|
],
|
||||||
setup: (self) => self
|
setup: (self) => self
|
||||||
.on('key-press-event', (widget, event) => { // Handle keybinds
|
.on('key-press-event', (widget, event) => { // Handle keybinds
|
||||||
if (event.get_state()[1] & Gdk.ModifierType.CONTROL_MASK) { // Ctrl held
|
if (checkKeybind(event, userOptions.keybinds.sidebar.pin))
|
||||||
// Pin sidebar
|
pinButton.attribute.toggle(pinButton);
|
||||||
if (event.get_keyval()[1] == Gdk.KEY_p)
|
else if (checkKeybind(event, userOptions.keybinds.sidebar.cycleTab))
|
||||||
pinButton.attribute.toggle(pinButton);
|
widgetContent.cycleTab();
|
||||||
// Switch sidebar tab
|
else if (checkKeybind(event, userOptions.keybinds.sidebar.nextTab))
|
||||||
else if (event.get_keyval()[1] === Gdk.KEY_Tab)
|
widgetContent.nextTab();
|
||||||
widgetContent.cycleTab();
|
else if (checkKeybind(event, userOptions.keybinds.sidebar.prevTab))
|
||||||
else if (event.get_keyval()[1] === Gdk.KEY_Page_Up)
|
widgetContent.prevTab();
|
||||||
widgetContent.prevTab();
|
|
||||||
else if (event.get_keyval()[1] === Gdk.KEY_Page_Down)
|
|
||||||
widgetContent.nextTab();
|
|
||||||
}
|
|
||||||
if (widgetContent.attribute.names[widgetContent.attribute.shown.value] == 'APIs') { // If api tab is focused
|
if (widgetContent.attribute.names[widgetContent.attribute.shown.value] == 'APIs') { // If api tab is focused
|
||||||
// Focus entry when typing
|
// Focus entry when typing
|
||||||
if ((
|
if ((
|
||||||
@@ -113,13 +111,11 @@ export default () => Box({
|
|||||||
buffer.place_cursor(buffer.get_iter_at_offset(-1));
|
buffer.place_cursor(buffer.get_iter_at_offset(-1));
|
||||||
}
|
}
|
||||||
// Switch API type
|
// Switch API type
|
||||||
else if (!(event.get_state()[1] & Gdk.ModifierType.CONTROL_MASK) &&
|
else if (checkKeybind(event, userOptions.keybinds.sidebar.apis.nextTab)) {
|
||||||
event.get_keyval()[1] === Gdk.KEY_Page_Down) {
|
|
||||||
const toSwitchTab = widgetContent.attribute.children[widgetContent.attribute.shown.value];
|
const toSwitchTab = widgetContent.attribute.children[widgetContent.attribute.shown.value];
|
||||||
toSwitchTab.attribute.nextTab();
|
toSwitchTab.attribute.nextTab();
|
||||||
}
|
}
|
||||||
else if (!(event.get_state()[1] & Gdk.ModifierType.CONTROL_MASK) &&
|
else if (checkKeybind(event, userOptions.keybinds.sidebar.apis.prevTab)) {
|
||||||
event.get_keyval()[1] === Gdk.KEY_Page_Up) {
|
|
||||||
const toSwitchTab = widgetContent.attribute.children[widgetContent.attribute.shown.value];
|
const toSwitchTab = widgetContent.attribute.children[widgetContent.attribute.shown.value];
|
||||||
toSwitchTab.attribute.prevTab();
|
toSwitchTab.attribute.prevTab();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
|
|
||||||
let userConfigOptions = {
|
let userConfigOptions = {
|
||||||
|
// General stuff
|
||||||
'ai': {
|
'ai': {
|
||||||
'defaultGPTProvider': 'openai',
|
'defaultGPTProvider': 'openai',
|
||||||
'defaultTemperature': 0.9,
|
'defaultTemperature': 0.9,
|
||||||
@@ -43,7 +44,8 @@ let userConfigOptions = {
|
|||||||
'workspaces': {
|
'workspaces': {
|
||||||
'shown': 10,
|
'shown': 10,
|
||||||
},
|
},
|
||||||
icons: {
|
// Longer stuff
|
||||||
|
'icons': {
|
||||||
substitutions: {
|
substitutions: {
|
||||||
'code-url-handler': 'visual-studio-code',
|
'code-url-handler': 'visual-studio-code',
|
||||||
'Code': 'visual-studio-code',
|
'Code': 'visual-studio-code',
|
||||||
@@ -55,7 +57,27 @@ let userConfigOptions = {
|
|||||||
'wpsoffice': 'wps-office2019-kprometheus',
|
'wpsoffice': 'wps-office2019-kprometheus',
|
||||||
'': 'image-missing',
|
'': 'image-missing',
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
'keybinds': {
|
||||||
|
// Format: Mod1+Mod2+key. CaSe SeNsItIvE!
|
||||||
|
// Modifiers: Shift Ctrl Alt Hyper Meta NoMod
|
||||||
|
// See https://docs.gtk.org/gdk3/index.html#constants for the other keys
|
||||||
|
'overview': {
|
||||||
|
'altMoveLeft': 'Ctrl+b',
|
||||||
|
'altMoveRight': 'Ctrl+f',
|
||||||
|
'deleteToEnd': 'Ctrl+k',
|
||||||
|
},
|
||||||
|
'sidebar': {
|
||||||
|
'apis': {
|
||||||
|
'nextTab': 'Page_Down',
|
||||||
|
'prevTab': 'Page_Up',
|
||||||
|
},
|
||||||
|
'pin': 'Ctrl+p',
|
||||||
|
'cycleTab': 'Ctrl+Tab',
|
||||||
|
'nextTab': 'Ctrl+Page_Down',
|
||||||
|
'prevTab': 'Ctrl+Page_Up',
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
globalThis['userOptions'] = userConfigOptions;
|
globalThis['userOptions'] = userConfigOptions;
|
||||||
|
|||||||
Reference in New Issue
Block a user