diff --git a/compile.sh b/compile.sh index 1a06566..9cc3849 100755 --- a/compile.sh +++ b/compile.sh @@ -15,7 +15,7 @@ fi mkdir -p "$DIR/build" -gcc -shared -fPIC -Wall -Wextra -o "$DIR/build/X-kutu.so" "$DIR/X-kutu.c" $XCB +gcc -shared -fPIC -Wall -Wextra -o "$DIR/build/X-kutu.so" "$DIR/src/c/X-kutu.c" $XCB if [ ! -f "$DIR/build/X-kutu.so" ]; then echo "Error: compilation failed." >&2 diff --git a/kutu.rb b/kutu.rb index 21eb533..543ba95 100755 --- a/kutu.rb +++ b/kutu.rb @@ -2,7 +2,7 @@ # Require X-kutu library for all x11 functions -require_relative "./src/X-kutu" +require_relative "./src/ruby/X-kutu" # Initialize X @@ -16,10 +16,10 @@ end # Require modules -require_relative "./src/utils" -require_relative "./src/node" -require_relative "./src/workspace" -require_relative "./src/events" +require_relative "./src/ruby/utils" +require_relative "./src/ruby/node" +require_relative "./src/ruby/workspace" +require_relative "./src/ruby/events" # Cleanup on exit @@ -50,9 +50,15 @@ $rect = {} refresh_monitors! +# Run startup script + +pid = spawn File.join(__dir__, "/src/shell/startup.sh") +Process.detach pid + + # Add keybinds -load File.join(__dir__, "/src/bindings.rb") +load File.join(__dir__, "/src/ruby/bindings.rb") # Initialize workspaces diff --git a/X-kutu.c b/src/c/X-kutu.c similarity index 92% rename from X-kutu.c rename to src/c/X-kutu.c index 80d1a5f..0fdae42 100644 --- a/X-kutu.c +++ b/src/c/X-kutu.c @@ -1,23 +1,5 @@ -#define CLEANMASK(m) ((m & ~0x80)) - -// Definitions for modifier keys -#define SUPER XCB_MOD_MASK_4 -#define ALT XCB_MOD_MASK_1 -#define CTRL XCB_MOD_MASK_CONTROL -#define SHIFT XCB_MOD_MASK_SHIFT - -// Change this to change the modifier key you want to use -#define MOD SUPER - -// Standard headers -#include -#include -#include -#include - -// XCB header -#include -#include +// Self-header +#include "X-kutu.h" // Global variables // Connection to X server @@ -27,28 +9,6 @@ xcb_screen_t *scr; // Currently focused window xcb_window_t focuswin; -// Geometry structure for rectangles and positions -typedef struct Geometry { - int16_t x; - int16_t y; - uint16_t width; - uint16_t height; -} Geometry; - -// Event structure to represent various X events -typedef struct Event { - int32_t type; - uint32_t window; - int8_t override_redirect; - uint32_t btn; - int32_t x; - int32_t y; - uint32_t height; - uint32_t width; - uint32_t state; - int8_t is_root; -} Event; - // Cleanup function to close the X connection on exit void cleanup(void) { if (conn != NULL) diff --git a/src/c/X-kutu.h b/src/c/X-kutu.h new file mode 100644 index 0000000..b415bee --- /dev/null +++ b/src/c/X-kutu.h @@ -0,0 +1,94 @@ +#ifndef X_KUTU_H +#define X_KUTU_H + +// Standard headers +#include +#include +#include +#include + +// XCB headers +#include +#include + +// Macro to clean modifier masks +#define CLEANMASK(m) ((m & ~0x80)) + +// Definitions for modifier keys +#define SUPER XCB_MOD_MASK_4 +#define ALT XCB_MOD_MASK_1 +#define CTRL XCB_MOD_MASK_CONTROL +#define SHIFT XCB_MOD_MASK_SHIFT + +// Change this to change the modifier key you want to use +#define MOD SUPER + +// Forward declarations of global variables +extern xcb_connection_t *conn; +extern xcb_screen_t *scr; +extern xcb_window_t focuswin; + +// Geometry structure for rectangles and positions +typedef struct Geometry { + int16_t x; + int16_t y; + uint16_t width; + uint16_t height; +} Geometry; + +// Event structure to represent various X events +typedef struct Event { + int32_t type; + uint32_t window; + int8_t override_redirect; + uint32_t btn; + int32_t x; + int32_t y; + uint32_t height; + uint32_t width; + uint32_t state; + int8_t is_root; +} Event; + +// Function prototypes +int deploy(void); +void cleanup(void); + +void add_keybind(int key); +void add_mousebind(int button); + +xcb_window_t get_focus(void); +xcb_window_t get_root(void); + +void focus(xcb_window_t win); +void subscribe(xcb_window_t win); +void kill(xcb_window_t window); +void destroy(xcb_window_t win); +void show(xcb_window_t window); +void hide(xcb_window_t window); +void send_to_top(xcb_window_t win); + +Geometry get_geometry(xcb_window_t win); +Geometry get_pointer(void); +Geometry get_screen(void); +void free_geometry(Geometry *g); + +void warp_pointer(xcb_window_t win, int x, int y); +void move_window(xcb_window_t win, int x, int y); +void resize_window(xcb_window_t win, int width, int height); + +xcb_size_hints_t get_wm_n_hints(xcb_window_t win); +xcb_icccm_wm_hints_t get_wm_hints(xcb_window_t win); +char *get_wm_name(xcb_window_t win); +uint8_t get_wm_transient_for(xcb_window_t win); +void set_wm_state(xcb_window_t win, int state); + +xcb_window_t draw_rectangle(int x, int y, int width, int height, + uint32_t color); + +void grab_pointer(xcb_window_t win); +void ungrab_pointer(void); + +Event wait_for_event(void); + +#endif // X_KUTU_H diff --git a/src/X-kutu.rb b/src/ruby/X-kutu.rb similarity index 98% rename from src/X-kutu.rb rename to src/ruby/X-kutu.rb index 297c93e..3c6648a 100644 --- a/src/X-kutu.rb +++ b/src/ruby/X-kutu.rb @@ -2,7 +2,7 @@ require "ffi" module X extend FFI::Library - ffi_lib File.join(__dir__, "../build/X-kutu.so") + ffi_lib File.join(__dir__, "../../build/X-kutu.so") typedef :uint32, :xcb_window_t typedef :uint32, :xcb_pixmap_t diff --git a/src/bindings.rb b/src/ruby/bindings.rb similarity index 55% rename from src/bindings.rb rename to src/ruby/bindings.rb index 376c50b..9891b7b 100644 --- a/src/bindings.rb +++ b/src/ruby/bindings.rb @@ -3,7 +3,7 @@ keybind(24) do |event| end keybind(25) do |_event| - pid = spawn("kitty") + pid = spawn "kitty" Process.detach pid end @@ -12,6 +12,11 @@ keybind(26) do |_event| exit 1 end +keybind(55) do |_event| + pid = spawn "rofi -modi 'clipboard:greenclip print' -show clipboard -run-command '{cmd}'" + Process.detach pid +end + mousebind 1 diff --git a/src/events.rb b/src/ruby/events.rb similarity index 100% rename from src/events.rb rename to src/ruby/events.rb diff --git a/src/node.rb b/src/ruby/node.rb similarity index 100% rename from src/node.rb rename to src/ruby/node.rb diff --git a/src/utils.rb b/src/ruby/utils.rb similarity index 100% rename from src/utils.rb rename to src/ruby/utils.rb diff --git a/src/window.rb b/src/ruby/window.rb similarity index 100% rename from src/window.rb rename to src/ruby/window.rb diff --git a/src/window_block.rb b/src/ruby/window_block.rb similarity index 100% rename from src/window_block.rb rename to src/ruby/window_block.rb diff --git a/src/workspace.rb b/src/ruby/workspace.rb similarity index 100% rename from src/workspace.rb rename to src/ruby/workspace.rb diff --git a/src/shell/startup.sh b/src/shell/startup.sh new file mode 100755 index 0000000..0cab5a4 --- /dev/null +++ b/src/shell/startup.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +picom --config ~/.config/i3/picom.conf