osk and cheatsheet: multimonitor

This commit is contained in:
end-4 2024-04-03 19:16:15 +07:00
parent 21cdcba7c1
commit a59fceca4c
7 changed files with 75 additions and 70 deletions

View file

@ -44,14 +44,12 @@ const Windows = () => [
// Dock(),
Overview(),
forMonitors(Indicator),
Cheatsheet(),
forMonitors(Cheatsheet),
SideLeft(),
SideRight(),
Osk(),
forMonitors(Osk),
Session(),
// forMonitors(Bar),
// forMonitors(BarCornerTopleft),
// forMonitors(BarCornerTopright),
forMonitors((id) => Corner(id, 'top left')),
forMonitors((id) => Corner(id, 'top right')),
forMonitors((id) => Corner(id, 'bottom left')),
@ -59,15 +57,20 @@ const Windows = () => [
forMonitors(BarCornerTopleft),
forMonitors(BarCornerTopright),
];
const CLOSE_ANIM_TIME = 210; // Longer than actual anim time to make sure widgets animate fully
const closeWindowDelays = { // For animations
'sideright': CLOSE_ANIM_TIME,
'sideleft': CLOSE_ANIM_TIME,
};
for(let i = 0; i < (Gdk.Display.get_default()?.get_n_monitors() || 1); i++) {
closeWindowDelays[`osk${i}`] = CLOSE_ANIM_TIME;
}
App.config({
css: `${COMPILED_STYLE_DIR}/style.css`,
stackTraceOnError: true,
closeWindowDelay: { // For animations
'sideright': CLOSE_ANIM_TIME,
'sideleft': CLOSE_ANIM_TIME,
'osk': CLOSE_ANIM_TIME,
},
closeWindowDelay: closeWindowDelays,
windows: Windows().flat(1),
});

View file

@ -1,7 +1,7 @@
import Widget from 'resource:///com/github/Aylur/ags/widget.js';
import { keybindList } from "./data_keybinds.js";
export const Keybinds = () => Widget.Box({
export default () => Widget.Box({
vertical: false,
className: "spacing-h-15",
homogeneous: true,

View file

@ -1,11 +1,10 @@
const { Gdk, Gtk } = imports.gi;
const { Gtk } = imports.gi;
import Widget from 'resource:///com/github/Aylur/ags/widget.js';
import Service from 'resource:///com/github/Aylur/ags/service.js';
import { Keybinds } from "./keybinds.js";
import { setupCursorHover } from "../.widgetutils/cursorhover.js";
import PopupWindow from '../.widgethacks/popupwindow.js';
import Keybinds from "./keybinds.js";
const cheatsheetHeader = () => Widget.CenterBox({
const CheatsheetHeader = () => Widget.CenterBox({
vertical: false,
startWidget: Widget.Box({}),
centerWidget: Widget.Box({
@ -63,26 +62,26 @@ const cheatsheetHeader = () => Widget.CenterBox({
}),
});
const clickOutsideToClose = Widget.EventBox({
const ClickOutsideToClose = () => Widget.EventBox({
onPrimaryClick: () => App.closeWindow('cheatsheet'),
onSecondaryClick: () => App.closeWindow('cheatsheet'),
onMiddleClick: () => App.closeWindow('cheatsheet'),
});
export default () => PopupWindow({
name: 'cheatsheet',
export default (id) => PopupWindow({
name: `cheatsheet${id}`,
exclusivity: 'ignore',
keymode: 'exclusive',
visible: false,
child: Widget.Box({
vertical: true,
children: [
clickOutsideToClose,
ClickOutsideToClose(),
Widget.Box({
vertical: true,
className: "cheatsheet-bg spacing-v-15",
children: [
cheatsheetHeader(),
CheatsheetHeader(),
Keybinds(),
]
}),

View file

@ -1,9 +1,9 @@
import PopupWindow from '../.widgethacks/popupwindow.js';
import OnScreenKeyboard from "./onscreenkeyboard.js";
export default () => PopupWindow({
export default (id) => PopupWindow({
anchor: ['bottom'],
name: 'osk',
name: `osk${id}`,
showClassName: 'osk-show',
hideClassName: 'osk-hide',
child: OnScreenKeyboard(),

View file

@ -33,7 +33,7 @@ class ShiftMode {
}
var modsPressed = false;
const topDecor = Box({
const TopDecor = () => Box({
vertical: true,
children: [
Box({
@ -47,7 +47,7 @@ const topDecor = Box({
]
});
const keyboardControlButton = (icon, text, runFunction) => Button({
const KeyboardControlButton = (icon, text, runFunction) => Button({
className: 'osk-control-button spacing-h-10',
onClicked: () => runFunction(),
child: Widget.Box({
@ -60,7 +60,7 @@ const keyboardControlButton = (icon, text, runFunction) => Button({
})
})
const keyboardControls = Box({
const KeyboardControls = () => Box({
vertical: true,
className: 'spacing-v-5',
children: [
@ -90,7 +90,7 @@ var shiftMode = ShiftMode.Off;
var shiftButton;
var rightShiftButton;
var allButtons = [];
const keyboardItself = (kbJson) => {
const KeyboardItself = (kbJson) => {
return Box({
vertical: true,
className: 'spacing-v-5',
@ -192,69 +192,71 @@ const keyboardItself = (kbJson) => {
})
}
const keyboardWindow = Box({
const KeyboardWindow = () => Box({
vexpand: true,
hexpand: true,
vertical: true,
className: 'osk-window spacing-v-5',
children: [
topDecor,
TopDecor(),
Box({
className: 'osk-body spacing-h-10',
children: [
keyboardControls,
KeyboardControls(),
Widget.Box({ className: 'separator-line' }),
keyboardItself(keyboardJson),
KeyboardItself(keyboardJson),
],
})
],
setup: (self) => self.hook(App, (box, name, visible) => { // Update on open
setup: (self) => self.hook(App, (self, name, visible) => { // Update on open
if (name == 'osk' && visible) {
keyboardWindow.setCss(`margin-bottom: -0px;`);
self.setCss(`margin-bottom: -0px;`);
}
}),
});
const gestureEvBox = EventBox({ child: keyboardWindow })
const gesture = Gtk.GestureDrag.new(gestureEvBox);
gesture.connect('drag-begin', async () => {
try {
const Hyprland = (await import('resource:///com/github/Aylur/ags/service/hyprland.js')).default;
Hyprland.messageAsync('j/cursorpos').then((out) => {
gesture.startY = JSON.parse(out).y;
}).catch(print);
} catch {
return;
}
});
gesture.connect('drag-update', async () => {
try {
const Hyprland = (await import('resource:///com/github/Aylur/ags/service/hyprland.js')).default;
Hyprland.messageAsync('j/cursorpos').then((out) => {
const currentY = JSON.parse(out).y;
const offset = gesture.startY - currentY;
export default () => {
const kbWindow = KeyboardWindow();
const gestureEvBox = EventBox({ child: kbWindow })
const gesture = Gtk.GestureDrag.new(gestureEvBox);
gesture.connect('drag-begin', async () => {
try {
const Hyprland = (await import('resource:///com/github/Aylur/ags/service/hyprland.js')).default;
Hyprland.messageAsync('j/cursorpos').then((out) => {
gesture.startY = JSON.parse(out).y;
}).catch(print);
} catch {
return;
}
});
gesture.connect('drag-update', async () => {
try {
const Hyprland = (await import('resource:///com/github/Aylur/ags/service/hyprland.js')).default;
Hyprland.messageAsync('j/cursorpos').then((out) => {
const currentY = JSON.parse(out).y;
const offset = gesture.startY - currentY;
if (offset > 0) return;
if (offset > 0) return;
keyboardWindow.setCss(`
kbWindow.setCss(`
margin-bottom: ${offset}px;
`);
}).catch(print);
} catch {
return;
}
});
gesture.connect('drag-end', () => {
var offset = gesture.get_offset()[2];
if (offset > 50) {
App.closeWindow('osk');
}
else {
keyboardWindow.setCss(`
}).catch(print);
} catch {
return;
}
});
gesture.connect('drag-end', () => {
var offset = gesture.get_offset()[2];
if (offset > 50) {
App.closeWindow('osk');
}
else {
kbWindow.setCss(`
transition: margin-bottom 170ms cubic-bezier(0.05, 0.7, 0.1, 1);
margin-bottom: 0px;
`);
}
})
export default () => gestureEvBox;
}
})
return gestureEvBox;
};

View file

@ -1,4 +1,6 @@
const { Gtk } = imports.gi;
import App from 'resource:///com/github/Aylur/ags/app.js'
import Variable from 'resource:///com/github/Aylur/ags/variable.js';
import Mpris from 'resource:///com/github/Aylur/ags/service/mpris.js';
import * as Utils from 'resource:///com/github/Aylur/ags/utils.js';
@ -11,7 +13,6 @@ export const showMusicControls = Variable(false, {})
export const showColorScheme = Variable(false, {})
globalThis['openMusicControls'] = showMusicControls;
globalThis['openColorScheme'] = showColorScheme;
globalThis['mpris'] = Mpris;
// Screen size

View file

@ -81,14 +81,14 @@ bind = Control+Super, T, exec, ~/.config/ags/scripts/color_generation/switchwall
bind = Control+Alt, Slash, exec, ags run-js 'cycleMode();'
bindir = Super, Super_L, exec, ags -t 'overview'
bind = Super, Tab, exec, ags -t 'overview'
bind = Super, Slash, exec, ags -t 'cheatsheet'
bind = Super, Slash, exec, for ((i=0; i<$(xrandr --listmonitors | grep -c 'Monitor'); i++)); do ags -t "cheatsheet""$i"; done
bind = Super, B, exec, ags -t 'sideleft'
bind = Super, A, exec, ags -t 'sideleft'
bind = Super, O, exec, ags -t 'sideleft'
bind = Super, N, exec, ags -t 'sideright'
bind = Super, M, exec, ags run-js 'openMusicControls.value = (!mpris.getPlayer() ? false : !openMusicControls.value);'
bind = Super, Comma, exec, ags run-js 'openColorScheme.value = true; Utils.timeout(2000, () => openColorScheme.value = false);'
bind = Super, K, exec, ags -t 'osk'
bind = Super, K, exec, for ((i=0; i<$(xrandr --listmonitors | grep -c 'Monitor'); i++)); do ags -t "osk""$i"; done
bind = Control+Alt, Delete, exec, ags -t 'session'
bindle = , XF86AudioRaiseVolume, exec, ags run-js 'indicator.popup(1);'
bindle = , XF86AudioLowerVolume, exec, ags run-js 'indicator.popup(1);'