mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-03-18 07:23:57 +01:00
refactor(derive-ahk): push up generation logic
This commit pushes as much of the generation logic as possible to the derive-ahk crate, so that when it is used in komorebic, we only need to do an as_bytes() call to prepare it for being written to a file. Besides that, this commit changes the generation command name to 'ahk-library' for clarity, and adds both additional samples and instructions in the readme file and Scoop post-install hook.
This commit is contained in:
@@ -55,5 +55,6 @@ scoop:
|
||||
pre_install:
|
||||
- if (Get-Process -Name komorebi -ErrorAction SilentlyContinue) { komorebic stop }
|
||||
post_install:
|
||||
- Write-Host "Run 'cp $original_dir\komorebi.sample.ahk $Env:UserProfile\komorebi.ahk' to get started with the sample configuration"
|
||||
- Write-Host "Once you have a configuration file in place, you can run 'komorebic start' to start the window manager"
|
||||
- Write-Host "`nRun 'cp $original_dir\komorebi.sample.ahk $Env:UserProfile\komorebi.ahk' to get started with the sample configuration"
|
||||
- Write-Host "`nRun 'komorebic ahk-library' if you would like to generate an AHK helper library to use in your configuration"
|
||||
- Write-Host "`nOnce you have a configuration file in place, you can run 'komorebic start' to start the window manager"
|
||||
|
||||
12
README.md
12
README.md
@@ -213,15 +213,19 @@ manage-rule Add a rule to always manage the specified applicati
|
||||
workspace-rule Add a rule to associate an application with a workspace
|
||||
identify-tray-application Identify an application that closes to the system tray
|
||||
focus-follows-mouse Enable or disable focus follows mouse for the operating system
|
||||
ahk-lib Generate a library of AutoHotKey helper functions
|
||||
ahk-library Generate a library of AutoHotKey helper functions
|
||||
help Print this message or the help of the given subcommand(s)
|
||||
```
|
||||
|
||||
Additionally, you may run `komorebic.exe ahk-lib` to generate [a helper library for AutoHotKey](komorebic.lib.sample.ahk)
|
||||
which wraps every `komorebic` command in a native AHK function.
|
||||
### AutoHotKey Helper Library for `komorebic`
|
||||
|
||||
Additionally, you may run `komorebic.exe ahk-library` to
|
||||
generate [a helper library for AutoHotKey](komorebic.lib.sample.ahk) which wraps every `komorebic` command in a native
|
||||
AHK function.
|
||||
|
||||
If you include the generated library at the top of your `~/komorebi.ahk` configuration file, you will be able to call
|
||||
any of the functions that it contains.
|
||||
any of the functions that it contains. A sample AHK script that shows how this library can be
|
||||
used [is available here](komorebi.sample.with.lib.ahk).
|
||||
|
||||
## Features
|
||||
|
||||
|
||||
@@ -83,13 +83,12 @@ pub fn ahk(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
||||
|
||||
quote! {
|
||||
impl #name {
|
||||
fn ahk_functions() -> Vec<String> {
|
||||
let mut v: Vec<String> = vec![];
|
||||
v.push(String::from("; Generated by komorebic.exe ahk-lib"));
|
||||
fn generate_ahk_library() -> String {
|
||||
let mut v: Vec<String> = vec![String::from("; Generated by komorebic.exe")];
|
||||
|
||||
#stream
|
||||
|
||||
v
|
||||
v.join("\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
218
komorebi.sample.with.lib.ahk
Normal file
218
komorebi.sample.with.lib.ahk
Normal file
@@ -0,0 +1,218 @@
|
||||
#SingleInstance Force
|
||||
#Include %A_ScriptDir%\komorebic.lib.ahk
|
||||
|
||||
; Enable hot reloading of changes to this file
|
||||
WatchConfiguration("enable")
|
||||
|
||||
; Enable focus follows mouse
|
||||
FocusFollowsMouse("enable")
|
||||
|
||||
; Ensure there are 5 workspaces created on monitor 0
|
||||
EnsureWorkspaces(0, 5)
|
||||
|
||||
; Configure the 1st workspace
|
||||
WorkspaceName(0, 0, "bsp")
|
||||
|
||||
; Configure the 2nd workspace
|
||||
WorkspaceName(0, 1, "columns") ; Optionally set the name of the workspace
|
||||
WorkspacePadding(0, 1, 30) ; Set the padding around the edge of the screen
|
||||
ContainerPadding(0, 1, 30) ; Set the padding between the containers on the screen
|
||||
WorkspaceRule("exe", "slack.exe", 0, 1) ; Always show chat apps on this workspace
|
||||
|
||||
; Configure the 3rd workspace
|
||||
WorkspaceName(0, 2, "thicc")
|
||||
WorkspacePadding(0, 2, 200) ; Set some super thicc padding
|
||||
|
||||
; Configure the 4th workspace
|
||||
WorkspaceName(0, 3, "matrix")
|
||||
WorkspacePadding(0, 3, 0) ; No padding at all
|
||||
ContainerPadding(0, 3, 0) ; Matrix-y hacker vibes
|
||||
|
||||
; Configure the 5th workspace
|
||||
WorkspaceName(0, 4, "floaty")
|
||||
WorkspaceTiling(0, 4, "disable") ; Everything floats here
|
||||
|
||||
; Configure floating rules
|
||||
FloatRule("class", "SunAwtDialog") ; All the IntelliJ popups
|
||||
FloatRule("title", "Control Panek")
|
||||
FloatRule("class", "TaskManagerWindow")
|
||||
FloatRule("exe", "Wally.exe")
|
||||
FloatRule("exe", "wincompose.exe")
|
||||
FloatRule("exe", "1Password.exe")
|
||||
FloatRule("exe", "Wox.exe")
|
||||
|
||||
; Change the focused window, Alt + Vim direction keys
|
||||
!h::
|
||||
Focus("left")
|
||||
return
|
||||
|
||||
!j::
|
||||
Focus("down")
|
||||
return
|
||||
|
||||
!k::
|
||||
Focus("up")
|
||||
return
|
||||
|
||||
!l::
|
||||
Focus("right")
|
||||
return
|
||||
|
||||
; Move the focused window in a given direction, Alt + Shift + Vim direction keys
|
||||
!+h::
|
||||
Move("left")
|
||||
return
|
||||
|
||||
!+j::
|
||||
Move("down")
|
||||
return
|
||||
|
||||
!+k::
|
||||
Move("up")
|
||||
return
|
||||
|
||||
!+l::
|
||||
Move("right")
|
||||
return
|
||||
|
||||
; Stack the focused window in a given direction, Alt + Shift + direction keys
|
||||
!+Left::
|
||||
Stack("left")
|
||||
return
|
||||
|
||||
!+Down::
|
||||
Stack("down")
|
||||
return
|
||||
|
||||
!+Up::
|
||||
Stack("up")
|
||||
return
|
||||
|
||||
!+Right::
|
||||
Stack("right")
|
||||
return
|
||||
|
||||
!]::
|
||||
CycleStack("next")
|
||||
return
|
||||
|
||||
![::
|
||||
CycleStack("previous")
|
||||
return
|
||||
|
||||
; Unstack the focused window, Alt + Shift + D
|
||||
!+d::
|
||||
Unstack()
|
||||
return
|
||||
|
||||
; Promote the focused window to the top of the tree, Alt + Shift + Enter
|
||||
!+Enter::
|
||||
Promote()
|
||||
return
|
||||
|
||||
; Manage the focused window
|
||||
!=::
|
||||
Manage()
|
||||
return
|
||||
|
||||
; Unmanage the focused window
|
||||
!-::
|
||||
Unmanage()
|
||||
return
|
||||
|
||||
; Switch to an equal-width, max-height column layout on the main workspace, Alt + Shift + C
|
||||
!+c::
|
||||
ChangeLayout("columns")
|
||||
return
|
||||
|
||||
; Switch to the default bsp tiling layout on the main workspace, Alt + Shift + T
|
||||
!+t::
|
||||
ChangeLayout("bsp")
|
||||
return
|
||||
|
||||
; Toggle the Monocle layout for the focused window, Alt + Shift + F
|
||||
!+f::
|
||||
ToggleMonocle()
|
||||
return
|
||||
|
||||
; Toggle native maximize for the focused window, Alt + Shift + =
|
||||
!+=::
|
||||
ToggleMaximize()
|
||||
return
|
||||
|
||||
; Flip horizontally, Alt + X
|
||||
!x::
|
||||
FlipLayout("horizontal")
|
||||
return
|
||||
|
||||
; Flip vertically, Alt + Y
|
||||
!y::
|
||||
FlipLayout("vertical")
|
||||
return
|
||||
|
||||
; Force a retile if things get janky, Alt + Shift + R
|
||||
!+r::
|
||||
Retile()
|
||||
return
|
||||
|
||||
; Float the focused window, Alt + T
|
||||
!t::
|
||||
ToggleFloat()
|
||||
return
|
||||
|
||||
; Reload ~/komorebi.ahk, Alt + O
|
||||
!o::
|
||||
ReloadConfiguration()
|
||||
return
|
||||
|
||||
; Pause responding to any window events or komorebic commands, Alt + P
|
||||
!p::
|
||||
TogglePause()
|
||||
return
|
||||
|
||||
; Switch to workspace
|
||||
!1::
|
||||
Send !
|
||||
FocusWorkspace(0)
|
||||
return
|
||||
|
||||
!2::
|
||||
Send !
|
||||
FocusWorkspace(1)
|
||||
return
|
||||
|
||||
!3::
|
||||
Send !
|
||||
FocusWorkspace(2)
|
||||
return
|
||||
|
||||
!4::
|
||||
Send !
|
||||
FocusWorkspace(3)
|
||||
return
|
||||
|
||||
!5::
|
||||
Send !
|
||||
FocusWorkspace(4)
|
||||
return
|
||||
|
||||
; Move window to workspace
|
||||
!+1::
|
||||
MoveToWorkspace(0)
|
||||
return
|
||||
|
||||
!+2::
|
||||
MoveToWorkspace(1)
|
||||
return
|
||||
|
||||
!+3::
|
||||
MoveToWorkspace(2)
|
||||
return
|
||||
|
||||
!+4::
|
||||
MoveToWorkspace(3)
|
||||
return
|
||||
|
||||
!+5::
|
||||
MoveToWorkspace(4)
|
||||
return
|
||||
@@ -1,4 +1,4 @@
|
||||
; Generated by komorebic.exe generate-ahk-library
|
||||
; Generated by komorebic.exe
|
||||
|
||||
Start() {
|
||||
Run, komorebic.exe start, , Hide
|
||||
@@ -168,6 +168,6 @@ FocusFollowsMouse(boolean_state) {
|
||||
Run, komorebic.exe focus-follows-mouse %boolean_state%, , Hide
|
||||
}
|
||||
|
||||
AhkLib() {
|
||||
Run, komorebic.exe ahk-lib, , Hide
|
||||
AhkLibrary() {
|
||||
Run, komorebic.exe ahk-library, , Hide
|
||||
}
|
||||
@@ -337,7 +337,7 @@ enum SubCommand {
|
||||
/// Enable or disable focus follows mouse for the operating system
|
||||
FocusFollowsMouse(FocusFollowsMouse),
|
||||
/// Generate a library of AutoHotKey helper functions
|
||||
AhkLib,
|
||||
AhkLibrary,
|
||||
}
|
||||
|
||||
pub fn send_message(bytes: &[u8]) -> Result<()> {
|
||||
@@ -354,7 +354,7 @@ fn main() -> Result<()> {
|
||||
let opts: Opts = Opts::parse();
|
||||
|
||||
match opts.subcmd {
|
||||
SubCommand::AhkLib => {
|
||||
SubCommand::AhkLibrary => {
|
||||
let mut library = dirs::home_dir().context("there is no home directory")?;
|
||||
library.push("komorebic.lib.ahk");
|
||||
let mut file = OpenOptions::new()
|
||||
@@ -363,8 +363,7 @@ fn main() -> Result<()> {
|
||||
.truncate(true)
|
||||
.open(library.clone())?;
|
||||
|
||||
let library_text: String = SubCommand::ahk_functions().join("\n");
|
||||
file.write_all(library_text.as_bytes())?;
|
||||
file.write_all(SubCommand::generate_ahk_library().as_bytes())?;
|
||||
|
||||
println!(
|
||||
"\nAHK helper library for komorebic written to {}",
|
||||
|
||||
Reference in New Issue
Block a user