Add basic event handling

This commit is contained in:
2026-07-25 22:04:22 +01:00
parent a810fa82fb
commit 20f8421426
3 changed files with 74 additions and 9 deletions
+18 -1
View File
@@ -4,6 +4,7 @@ import Control.Concurrent (threadDelay)
import Control.Exception (bracket)
import Foreign (Ptr)
import System.Environment (getArgs)
import System.Process
import WM.Layout
import WM.Mruby
import WM.XKutu
@@ -28,6 +29,8 @@ run = do
is_started <- deploy
print is_started
add_keybind 24 0
add_keybind 25 0
add_keybind 26 0
w_id <- draw_rectangle 10 100 10 10 0x500070
geom <- get_geometry w_id
print geom
@@ -50,10 +53,24 @@ handle_args mrb = do
runRuby mrb script
_ -> putStrLn "unknown arguments"
handle_key :: State -> Event -> IO State
handle_key s (Event {event_btn = 24}) = get_focus >>= kill >> pure s
handle_key s (Event {event_btn = 25}) = runCommand "kitty" >> pure s
handle_key s (Event {event_btn = 26}) = pure s {running = False}
handle_key s _ = pure s
handle_show :: State -> Event -> IO State
handle_show s ev = do
let win = event_window ev
c_show win
focus win
pure s
handle_event :: Maybe Event -> State -> IO State
handle_event Nothing s = pure s
handle_event (Just ev) s
| event_btn ev == 24 = pure s {running = False}
| event_type ev == EvKeyPress = handle_key s ev
| event_type ev == EvShowRequest = handle_show s ev
| otherwise = print ev >> pure s
loop :: State -> IO ()