Skip to content

Commit

Permalink
fix(shortcuts): add missing shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
eythaann committed Oct 11, 2024
1 parent 6f5611d commit c13d869
Show file tree
Hide file tree
Showing 13 changed files with 383 additions and 126 deletions.
352 changes: 258 additions & 94 deletions documentation/schemas/settings.schema.json

Large diffs are not rendered by default.

24 changes: 22 additions & 2 deletions lib/src/state/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ pub struct SeelenLauncherSettings {
impl Default for SeelenLauncherSettings {
fn default() -> Self {
Self {
enabled: true,
enabled: false,
monitor: SeelenLauncherMonitor::MouseOver,
runners: vec![
SeelenLauncherRunner {
Expand Down Expand Up @@ -330,18 +330,27 @@ macro_rules! define_struct_and_hashmap {
pub struct AhkVar {
pub fancy: String,
pub ahk: String,
#[serde(default)]
pub readonly: bool,
}

impl AhkVar {
pub fn new(f: &str, ahk: &str) -> Self {
Self {
fancy: f.to_string(),
ahk: ahk.to_string(),
readonly: false,
}
}

pub fn readonly(mut self) -> Self {
self.readonly = true;
self
}
}

define_struct_and_hashmap![
toggle_launcher,
reserve_top,
reserve_bottom,
reserve_left,
Expand Down Expand Up @@ -387,12 +396,18 @@ define_struct_and_hashmap![
send_to_workspace_6,
send_to_workspace_7,
send_to_workspace_8,
send_to_workspace_9
send_to_workspace_9,
misc_open_settings,
misc_toggle_lock_tracing,
misc_toggle_win_event_tracing
];

impl Default for AhkVarList {
fn default() -> Self {
Self {
// launcher
toggle_launcher: AhkVar::new("Win + Space", "LWin & Space").readonly(),
// wm
reserve_top: AhkVar::new("Win + Shift + I", "#+i"),
reserve_bottom: AhkVar::new("Win + Shift + K", "#+k"),
reserve_left: AhkVar::new("Win + Shift + J", "#+j"),
Expand All @@ -409,6 +424,7 @@ impl Default for AhkVarList {
increase_height: AhkVar::new("Win + Shift + =", "#+="),
decrease_height: AhkVar::new("Win + Shift + -", "#+-"),
restore_sizes: AhkVar::new("Win + Alt + 0", "#!0"),
// virtual desktops
switch_workspace_0: AhkVar::new("Alt + 1", "!1"),
switch_workspace_1: AhkVar::new("Alt + 2", "!2"),
switch_workspace_2: AhkVar::new("Alt + 3", "!3"),
Expand Down Expand Up @@ -439,6 +455,10 @@ impl Default for AhkVarList {
send_to_workspace_7: AhkVar::new("Win + Shift + 8", "#+8"),
send_to_workspace_8: AhkVar::new("Win + Shift + 9", "#+9"),
send_to_workspace_9: AhkVar::new("Win + Shift + 0", "#+0"),
// miscellaneous
misc_open_settings: AhkVar::new("Win + K", "#k").readonly(),
misc_toggle_lock_tracing: AhkVar::new("Ctrl + Win + Alt + T", "^#!t").readonly(),
misc_toggle_win_event_tracing: AhkVar::new("Ctrl + Win + Alt + L", "^#!l").readonly(),
}
}
}
Expand Down
13 changes: 12 additions & 1 deletion lib/src/state/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class SeelenLauncherRunner {
}

export class SeelenLauncherSettings {
enabled: boolean = true;
enabled: boolean = false;
monitor: SeelenLauncherMonitor = SeelenLauncherMonitor.MouseOver;
runners: SeelenLauncherRunner[] = [];
}
Expand Down Expand Up @@ -122,13 +122,19 @@ export class WindowManagerSettings {
export class AhkVar {
fancy: string;
ahk: string;
readonly: boolean = false;

constructor(fancy: string = '', ahk: string = '') {
this.fancy = fancy;
this.ahk = ahk;
}
}

/// TODO: find the way to avoid duplicated code between rust and this class
export class AhkVarList {
// launcher
toggleLauncher = new AhkVar('Win + Space', 'LWin & Space');
// wm
reserveTop = new AhkVar('Win + Shift + I', '#+i');
reserveBottom = new AhkVar('Win + Shift + K', '#+k');
reserveLeft = new AhkVar('Win + Shift + J', '#+j');
Expand All @@ -145,6 +151,7 @@ export class AhkVarList {
increaseHeight = new AhkVar('Win + Shift + =', '#+=');
decreaseHeight = new AhkVar('Win + Shift + -', '#+-');
restoreSizes = new AhkVar('Win + Alt + 0', '#!0');
// virtual desktops
switchWorkspace0 = new AhkVar('Alt + 1', '!1');
switchWorkspace1 = new AhkVar('Alt + 2', '!2');
switchWorkspace2 = new AhkVar('Alt + 3', '!3');
Expand Down Expand Up @@ -175,4 +182,8 @@ export class AhkVarList {
sendToWorkspace7 = new AhkVar('Win + Shift + 8', '#+8');
sendToWorkspace8 = new AhkVar('Win + Shift + 9', '#+9');
sendToWorkspace9 = new AhkVar('Win + Shift + 0', '#+0');
// miscellaneous
miscOpenSettings = new AhkVar('Win + K', '#k');
miscToggleLockTracing = new AhkVar('Ctrl + Win + Alt + T', '^#!t');
miscToggleWinEventTracing = new AhkVar('Ctrl + Win + Alt + L', '^#!l');
}
6 changes: 6 additions & 0 deletions src/apps/settings/i18n/translations/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ delete: Delete
insert: Insert
more: More
inherit: Inherit
miscellaneous: Miscellaneous
sides:
left: Left
right: Right
Expand Down Expand Up @@ -183,7 +184,9 @@ shortcuts:
enable: Enable Integrated Shortcuts (ahk)
reset: Reset to Defaults
enable_tooltip: Disable if you will implement your own shortcuts using the Seelen Core Api
readonly_tooltip: This is a read-only shortcut
labels:
toggle_launcher: Toogle
reserve_top: Reserve Top
reserve_bottom: Reserve Bottom
reserve_left: Reserve Left
Expand Down Expand Up @@ -230,5 +233,8 @@ shortcuts:
send_to_workspace_7: Send to Workspace 8
send_to_workspace_8: Send to Workspace 9
send_to_workspace_9: Send to Workspace 10
misc_open_settings: Open Settings
misc_toggle_lock_tracing: Toggle Lock Tracing (logs)
misc_toggle_win_event_tracing: Toggle Win Event Tracing (logs)
update:
available: Update Available!
1 change: 1 addition & 0 deletions src/apps/settings/modules/shared/store/app/StateBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const StateToJsonSettings = (state: RootState): Settings => {
'fancyToolbar',
'windowManager',
'seelenweg',
'iconPacks',
'selectedThemes',
'monitors',
'ahkEnabled',
Expand Down
1 change: 1 addition & 0 deletions src/apps/settings/modules/shared/store/app/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const initialState: RootState = {
availableThemes: [],
availableLayouts: [],
availablePlaceholders: [],
iconPacks: [],
selectedThemes: [],
devTools: false,
language: navigator.language.split('-')[0] || 'en',
Expand Down
3 changes: 2 additions & 1 deletion src/apps/settings/modules/shortcuts/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function getAHK(code: string): string | undefined {
return;
}

export function KeyCodeToAHK(e: React.KeyboardEvent<HTMLInputElement>) {
export function KeyCodeToAHK(e: React.KeyboardEvent<HTMLInputElement>): AhkVar | undefined {
e.preventDefault();
let fancy = '';
let ahk = '';
Expand Down Expand Up @@ -65,6 +65,7 @@ export function KeyCodeToAHK(e: React.KeyboardEvent<HTMLInputElement>) {
return {
fancy,
ahk,
readonly: false,
};
}

Expand Down
27 changes: 26 additions & 1 deletion src/apps/settings/modules/shortcuts/infrastructure.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,17 @@ function AhkOptions({ variables, onChangeVar }: AhkOptionsProps) {
return (
<SettingsOption key={key}>
<div>{t(`shortcuts.labels.${VariableConvention.camelToSnake(key)}`)}</div>
<Input value={value.fancy} onKeyDown={(e) => onChangeVar(key as keyof AhkVarList, e)} />
<Tooltip title={value.readonly ? t('shortcuts.readonly_tooltip') : null}>
<Input
value={value.fancy}
disabled={value.readonly}
onKeyDown={(e) => {
if (!value.readonly) {
onChangeVar(key as keyof AhkVarList, e);
}
}}
/>
</Tooltip>
</SettingsOption>
);
});
Expand Down Expand Up @@ -76,6 +86,12 @@ export function Shortcuts() {
</SettingsOption>
</SettingsGroup>

<SettingsGroup>
<SettingsSubGroup label={t('header.labels.seelen_rofi')}>
<AhkOptions variables={['toggleLauncher']} onChangeVar={onChangeVar} />
</SettingsSubGroup>
</SettingsGroup>

<SettingsGroup>
<SettingsSubGroup label={t('header.labels.seelen_wm')}>
<AhkOptions
Expand Down Expand Up @@ -175,6 +191,15 @@ export function Shortcuts() {
/>
</SettingsSubGroup>
</SettingsGroup>

<SettingsGroup>
<SettingsSubGroup label={t('miscellaneous')}>
<AhkOptions
variables={['miscOpenSettings', 'miscToggleLockTracing', 'miscToggleWinEventTracing']}
onChangeVar={onChangeVar}
/>
</SettingsSubGroup>
</SettingsGroup>
</div>
);
}
26 changes: 16 additions & 10 deletions src/background/seelen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,42 +345,48 @@ impl Seelen {
Ok(())
}

// TODO: split ahk logic into another file/module
pub fn start_ahk_shortcuts() -> Result<()> {
// kill all running shortcuts before starting again
Self::kill_ahk_shortcuts()?;

let state = FULL_STATE.load();
if state.is_ahk_enabled() {
log::trace!("Creating AHK shortcuts");
let vars = state.get_ahk_variables();

AutoHotKey::new(include_str!("utils/ahk/mocks/seelen.lib.ahk"))
.name("seelen.lib.ahk")
.save()?;

AutoHotKey::new(include_str!("utils/ahk/mocks/seelen.ahk"))
AutoHotKey::from_template(include_str!("utils/ahk/mocks/seelen.ahk"), &vars)
.name("seelen.ahk")
.execute()?;

AutoHotKey::from_template(
include_str!("utils/ahk/mocks/seelen.vd.ahk"),
state.get_ahk_variables(),
)
.name("seelen.vd.ahk")
.execute()?;
AutoHotKey::from_template(include_str!("utils/ahk/mocks/seelen.vd.ahk"), &vars)
.name("seelen.vd.ahk")
.execute()?;

if state.is_window_manager_enabled() {
AutoHotKey::from_template(include_str!("utils/ahk/mocks/seelen.wm.ahk"), &vars)
.name("seelen.wm.ahk")
.execute()?;
}

if state.is_rofi_enabled() {
AutoHotKey::from_template(
include_str!("utils/ahk/mocks/seelen.wm.ahk"),
state.get_ahk_variables(),
include_str!("utils/ahk/mocks/seelen.launcher.ahk"),
&vars,
)
.name("seelen.wm.ahk")
.name("seelen.launcher.ahk")
.execute()?;
}
}
log::trace!("AHK shortcuts started successfully");
Ok(())
}

// TODO: split ahk logic into another file/module
pub fn kill_ahk_shortcuts() -> Result<()> {
log::trace!("Killing AHK shortcuts");
get_app_handle()
Expand Down
16 changes: 8 additions & 8 deletions src/background/utils/ahk/mocks/seelen.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@

CloseIfNotRunning()

; Open Settings
#k:: OpenSettings()

; Resume Window Manager
^#!p:: {
ResumeWM()
}

^#!l:: {
;misc_open_settings
x:: OpenSettings()

;misc_toggle_lock_tracing
x:: {
ToggleWinEventTracing()
}

^#!t:: {
;misc_toggle_win_event_tracing
x:: {
ToggleMutexLockTracing()
}

LWin & Space::ToggleAppLauncher()
}
15 changes: 15 additions & 0 deletions src/background/utils/ahk/mocks/seelen.launcher.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* This file is generated by Seelen UI and will be replaced on each update please don't modify manually.
* If you want to introduce your own implementation for shortcuts with AHK or any other scripting language
* just disable Seelen UI intergrated shortcuts in the shortcuts tab, and this file will be ignored.
*/
#Requires AutoHotkey v2.0
#SingleInstance Force
#NoTrayIcon

#Include seelen.lib.ahk

CloseIfNotRunning()

;toggle_launcher
x::ToggleAppLauncher()
Loading

0 comments on commit c13d869

Please sign in to comment.