Add remote commands support
This commit is contained in:
+3
-1
@@ -60,6 +60,7 @@ module X
|
||||
:window_group, :xcb_window_t
|
||||
end
|
||||
|
||||
attach_function :flush, [], :void
|
||||
attach_function :deploy, [], :int
|
||||
attach_function :add_keybind, [:int, :int], :void
|
||||
attach_function :add_mousebind, [:int, :int], :void
|
||||
@@ -79,7 +80,8 @@ module X
|
||||
attach_function :warp_pointer, [:xcb_window_t, :int, :int], :void
|
||||
attach_function :move_window, [:xcb_window_t, :int, :int], :void
|
||||
attach_function :resize_window, [:xcb_window_t, :int, :int], :void
|
||||
attach_function :wait_for_event, [], Event.by_value
|
||||
attach_function :translate_event, [:pointer], Event.by_value
|
||||
attach_function :next_event, [], :pointer
|
||||
attach_function :get_wm_name, [:xcb_window_t], :string
|
||||
attach_function :get_wm_n_hints, [:xcb_window_t], SizeHints.by_value
|
||||
attach_function :get_wm_hints, [:xcb_window_t], WMHints.by_value
|
||||
|
||||
+105
-54
@@ -1,71 +1,115 @@
|
||||
keybind(23) do |_event|
|
||||
keybind 23 do |_event|
|
||||
run "firefox"
|
||||
end
|
||||
|
||||
keybind(24) do |event|
|
||||
keybind 24 do |event|
|
||||
X.kill event[:window]
|
||||
end
|
||||
|
||||
keybind(25) do |_event|
|
||||
keybind 25 do |_event|
|
||||
run "kitty"
|
||||
end
|
||||
|
||||
keybind(26) do |_event|
|
||||
# run "~/dotfiles/scripts/power.sh"
|
||||
exit 1
|
||||
keybind 26 do |_event|
|
||||
run "~/dotfiles/scripts/power.sh"
|
||||
end
|
||||
|
||||
keybind(38) do |_event|
|
||||
keybind 123, 0 do |_event|
|
||||
run "pactl set-sink-volume @DEFAULT_SINK@ +5%;vol=$(pactl get-sink-volume @DEFAULT_SINK@ | grep -o '[0-9]\+%' | head -n1);dunstify 'Volume Adjusted' '' -h int:value:$vol -r 997"
|
||||
end
|
||||
|
||||
keybind 122, 0 do |_event|
|
||||
run "pactl set-sink-volume @DEFAULT_SINK@ -5%;vol=$(pactl get-sink-volume @DEFAULT_SINK@ | grep -o '[0-9]\+%' | head -n1);dunstify 'Volume Adjusted' '' -h int:value:$vol -r 997"
|
||||
end
|
||||
|
||||
keybind 121, 0 do |_event|
|
||||
run "pactl set-sink-mute @DEFAULT_SINK@ toggle;vol=$(pactl get-sink-volume @DEFAULT_SINK@ | grep -o '[0-9]\+%' | head -n1);dunstify 'Volume Adjusted' '' -h int:value:$vol -r 997"
|
||||
end
|
||||
|
||||
keybind 38 do |_event|
|
||||
run "maim -c 0.3,0.5,1.0,0.8 -s | tee /tmp/screenshot_temp.png | xclip -selection clipboard -t image/png && if [ -s '/tmp/screenshot_temp.png' ]; then mv /tmp/screenshot_temp.png ~/screenshots/$(date +%Y-%m-%d_%H:%M:%S).png; fi"
|
||||
end
|
||||
|
||||
keybind(54) do |_event|
|
||||
keybind 54 do |_event|
|
||||
run "kitty -e fish -c \"y\""
|
||||
end
|
||||
|
||||
keybind(53) do |_event|
|
||||
keybind 53 do |_event|
|
||||
run "kitty -e fish -c \"editor\""
|
||||
end
|
||||
|
||||
keybind(40) do |_event|
|
||||
keybind 40 do |_event|
|
||||
run "~/dotfiles/scripts/run.sh"
|
||||
end
|
||||
|
||||
keybind(33) do |_event|
|
||||
keybind 33 do |_event|
|
||||
run "~/.config/polybar/launch.sh"
|
||||
end
|
||||
|
||||
keybind(56) do |_event|
|
||||
keybind 45 do |_event|
|
||||
run "~/dotfiles/scripts/caffiene.sh"
|
||||
end
|
||||
|
||||
keybind 56 do |_event|
|
||||
monitor = current_monitor
|
||||
create_workspace monitor
|
||||
persistence_path = File.join(__dir__, ".num.json")
|
||||
persistence = File.exist?(persistence_path) ?
|
||||
JSON.parse(File.read(persistence_path), symbolize_names: true) :
|
||||
{}
|
||||
persistence[$monitors.key(monitor)] = monitor[:workspaces].length
|
||||
persistence[$monitors.key(monitor)] ||= {}
|
||||
persistence[$monitors.key(monitor)][:length] = monitor[:workspaces].length
|
||||
File.write(persistence_path, JSON.pretty_generate(persistence))
|
||||
end
|
||||
|
||||
keybind(57) do |_event|
|
||||
keybind 57 do |_event|
|
||||
monitor = current_monitor
|
||||
delete_workspace monitor[:workspaces].length - 1, monitor
|
||||
persistence_path = File.join(__dir__, ".num.json")
|
||||
persistence = File.exist?(persistence_path) ?
|
||||
JSON.parse(File.read(persistence_path), symbolize_names: true) :
|
||||
{}
|
||||
persistence[$monitors.key(monitor)] = monitor[:workspaces].length
|
||||
persistence[$monitors.key(monitor)] ||= {}
|
||||
persistence[$monitors.key(monitor)][:length] = monitor[:workspaces].length
|
||||
File.write(persistence_path, JSON.pretty_generate(persistence))
|
||||
end
|
||||
|
||||
keybind(112, 0) do |_event|
|
||||
keybind 110, 0 do |_event|
|
||||
run "dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Pause;" \
|
||||
"dbus-send --print-reply --dest=$(busctl --user list | grep -oP 'org.mpris.MediaPlayer2.firefox.instance_1_\d+') /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause"
|
||||
end
|
||||
|
||||
keybind 110 do |_event|
|
||||
monitor = current_monitor
|
||||
next_ws = (monitor[:selected_workspace] + 1) % monitor[:workspaces].length
|
||||
persistence_path = File.join(__dir__, ".num.json")
|
||||
persistence = File.exist?(persistence_path) ?
|
||||
JSON.parse(File.read(persistence_path), symbolize_names: true) :
|
||||
{}
|
||||
if monitor[:selected_workspace] == 0
|
||||
select_workspace persistence[$monitors.key(monitor)]&.[](:saved) || 1, monitor
|
||||
else
|
||||
persistence[$monitors.key(monitor)] ||= {}
|
||||
persistence[$monitors.key(monitor)][:saved] = monitor[:selected_workspace]
|
||||
File.write(persistence_path, JSON.pretty_generate(persistence))
|
||||
select_workspace 0, monitor
|
||||
end
|
||||
end
|
||||
|
||||
keybind 118, 0 do |_event|
|
||||
run "dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause"
|
||||
end
|
||||
|
||||
keybind 117, 0 do |_event|
|
||||
monitor = current_monitor
|
||||
next if monitor[:selected_workspace].zero?
|
||||
next_ws = (monitor[:selected_workspace] % (monitor[:workspaces].length - 1)) + 1
|
||||
select_workspace next_ws, monitor
|
||||
end
|
||||
|
||||
keybind(112) do |_event|
|
||||
monitor = current_monitor
|
||||
keybind 117 do |_event|
|
||||
pointer = X.get_pointer
|
||||
monitor = current_monitor pointer
|
||||
next if monitor[:selected_workspace].zero?
|
||||
|
||||
window = monitor[:workspaces][monitor[:selected_workspace]].windows.find do |w|
|
||||
pointer[:x] >= w.x &&
|
||||
@@ -74,19 +118,21 @@ keybind(112) do |_event|
|
||||
pointer[:y] < w.y + w.height
|
||||
end
|
||||
|
||||
next_ws = (monitor[:selected_workspace] + 1) % monitor[:workspaces].length
|
||||
next_ws = (monitor[:selected_workspace] % (monitor[:workspaces].length - 1)) + 1
|
||||
monitor[:workspaces][next_ws].drop monitor[:workspaces][next_ws].tiled_windows.length, window if window
|
||||
end
|
||||
|
||||
keybind(117, 0) do |_event|
|
||||
keybind 112, 0 do |_event|
|
||||
monitor = current_monitor
|
||||
next_ws = (monitor[:selected_workspace] - 1) % monitor[:workspaces].length
|
||||
next if monitor[:selected_workspace].zero?
|
||||
next_ws = ((monitor[:selected_workspace] - 2) % (monitor[:workspaces].length - 1)) + 1
|
||||
select_workspace next_ws, monitor
|
||||
end
|
||||
|
||||
keybind(117) do |_event|
|
||||
monitor = current_monitor
|
||||
keybind 112 do |_event|
|
||||
pointer = X.get_pointer
|
||||
monitor = current_monitor pointer
|
||||
next if monitor[:selected_workspace].zero?
|
||||
|
||||
window = monitor[:workspaces][monitor[:selected_workspace]].windows.find do |w|
|
||||
pointer[:x] >= w.x &&
|
||||
@@ -95,21 +141,22 @@ keybind(117) do |_event|
|
||||
pointer[:y] < w.y + w.height
|
||||
end
|
||||
|
||||
next_ws = (monitor[:selected_workspace] - 1) % monitor[:workspaces].length
|
||||
next_ws = ((monitor[:selected_workspace] - 2) % (monitor[:workspaces].length - 1)) + 1
|
||||
monitor[:workspaces][next_ws].drop monitor[:workspaces][next_ws].tiled_windows.length, window if window
|
||||
end
|
||||
|
||||
keybind(27) do |_event|
|
||||
keybind 27 do |_event|
|
||||
load File.join(__dir__, "./bindings.rb")
|
||||
monitor = current_monitor
|
||||
return unless monitor
|
||||
next unless monitor
|
||||
monitor[:workspaces][monitor[:selected_workspace]].switch_direction
|
||||
end
|
||||
|
||||
keybind(55) do |_event|
|
||||
keybind 55 do |_event|
|
||||
run "rofi -modi 'clipboard:greenclip print' -show clipboard -run-command '{cmd}'"
|
||||
end
|
||||
|
||||
keybind(39) do |event|
|
||||
keybind 39 do |event|
|
||||
window = $windows[event[:window]]
|
||||
window.toggle_floating if window
|
||||
end
|
||||
@@ -119,36 +166,17 @@ mousebind 1
|
||||
|
||||
mousebind 3
|
||||
|
||||
mousebind(8, 0) do |_event|
|
||||
mousebind 9, 0 do |_event|
|
||||
monitor = current_monitor
|
||||
next_ws = (monitor[:selected_workspace] + 1) % monitor[:workspaces].length
|
||||
select_workspace next_ws, monitor
|
||||
end
|
||||
|
||||
mousebind 8 do |_event|
|
||||
monitor = current_monitor
|
||||
pointer = X.get_pointer
|
||||
|
||||
window = monitor[:workspaces][monitor[:selected_workspace]].windows.find do |w|
|
||||
pointer[:x] >= w.x &&
|
||||
pointer[:x] < w.x + w.width &&
|
||||
pointer[:y] >= w.y &&
|
||||
pointer[:y] < w.y + w.height
|
||||
end
|
||||
|
||||
next_ws = (monitor[:selected_workspace] + 1) % monitor[:workspaces].length
|
||||
monitor[:workspaces][next_ws].drop monitor[:workspaces][next_ws].tiled_windows.length, window if window
|
||||
end
|
||||
|
||||
mousebind(9, 0) do |_event|
|
||||
monitor = current_monitor
|
||||
next_ws = (monitor[:selected_workspace] - 1) % monitor[:workspaces].length
|
||||
next if monitor[:selected_workspace].zero?
|
||||
next_ws = (monitor[:selected_workspace] % (monitor[:workspaces].length - 1)) + 1
|
||||
select_workspace next_ws, monitor
|
||||
end
|
||||
|
||||
mousebind 9 do |_event|
|
||||
monitor = current_monitor
|
||||
pointer = X.get_pointer
|
||||
monitor = current_monitor pointer
|
||||
next if monitor[:selected_workspace].zero?
|
||||
|
||||
window = monitor[:workspaces][monitor[:selected_workspace]].windows.find do |w|
|
||||
pointer[:x] >= w.x &&
|
||||
@@ -157,6 +185,29 @@ mousebind 9 do |_event|
|
||||
pointer[:y] < w.y + w.height
|
||||
end
|
||||
|
||||
next_ws = (monitor[:selected_workspace] - 1) % monitor[:workspaces].length
|
||||
next_ws = (monitor[:selected_workspace] % (monitor[:workspaces].length - 1)) + 1
|
||||
monitor[:workspaces][next_ws].drop monitor[:workspaces][next_ws].tiled_windows.length, window if window
|
||||
end
|
||||
|
||||
mousebind 8, 0 do |_event|
|
||||
monitor = current_monitor
|
||||
next if monitor[:selected_workspace].zero?
|
||||
next_ws = ((monitor[:selected_workspace] - 2) % (monitor[:workspaces].length - 1)) + 1
|
||||
select_workspace next_ws, monitor
|
||||
end
|
||||
|
||||
mousebind 8 do |_event|
|
||||
pointer = X.get_pointer
|
||||
monitor = current_monitor pointer
|
||||
next if monitor[:selected_workspace].zero?
|
||||
|
||||
window = monitor[:workspaces][monitor[:selected_workspace]].windows.find do |w|
|
||||
pointer[:x] >= w.x &&
|
||||
pointer[:x] < w.x + w.width &&
|
||||
pointer[:y] >= w.y &&
|
||||
pointer[:y] < w.y + w.height
|
||||
end
|
||||
|
||||
next_ws = ((monitor[:selected_workspace] - 2) % (monitor[:workspaces].length - 1)) + 1
|
||||
monitor[:workspaces][next_ws].drop monitor[:workspaces][next_ws].tiled_windows.length, window if window
|
||||
end
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
def handle_command(command)
|
||||
reply = {}
|
||||
|
||||
command_parts = command.split(" ")
|
||||
command = command_parts[0]
|
||||
args = command_parts[1..-1]
|
||||
|
||||
case command
|
||||
when "get-ws"
|
||||
monitor = args[0] ? $monitors[args[0].to_sym] : current_monitor
|
||||
return reply if monitor.nil?
|
||||
reply[:workspace] = monitor[:selected_workspace]
|
||||
reply[:monitor] = $monitors.key(monitor)
|
||||
reply[:count] = monitor[:workspaces].length
|
||||
when "set-ws"
|
||||
monitor = args[1] ? $monitors[args[1].to_sym] : current_monitor
|
||||
return reply if monitor.nil?
|
||||
select_workspace args[0].to_i, monitor
|
||||
reply[:workspace] = monitor[:selected_workspace]
|
||||
reply[:monitor] = $monitors.key(monitor)
|
||||
reply[:count] = monitor[:workspaces].length
|
||||
when "topped"
|
||||
reply[:topped] = $topped_windows
|
||||
when "stop"
|
||||
exit 1
|
||||
end
|
||||
|
||||
reply
|
||||
end
|
||||
@@ -4,7 +4,7 @@ def create_workspace(monitor)
|
||||
end
|
||||
|
||||
def delete_workspace(n, monitor)
|
||||
return if monitor[:workspaces].length <= 1
|
||||
return if monitor[:workspaces].length <= 2
|
||||
monitor[:workspaces][n].windows.each { |w| monitor[:workspaces][(n - 1) % monitor[:workspaces].length].drop 0, w }
|
||||
monitor[:workspaces].delete_at n
|
||||
if monitor[:selected_workspace] >= n
|
||||
@@ -13,6 +13,11 @@ def delete_workspace(n, monitor)
|
||||
end
|
||||
|
||||
def select_workspace(n, monitor)
|
||||
if n >= monitor[:workspaces].length
|
||||
select_workspace monitor[:workspaces].length - 1, monitor
|
||||
elsif n < 0
|
||||
select_workspace 1, monitor
|
||||
end
|
||||
monitor[:workspaces].each { |w| w.hide if w != monitor[:workspaces][n] }
|
||||
monitor[:selected_workspace] = n
|
||||
monitor[:workspaces][n].show
|
||||
|
||||
@@ -20,12 +20,15 @@ def handle_event(event)
|
||||
|
||||
|
||||
when :create
|
||||
$all_windows << event[:window]
|
||||
return unless event[:override_redirect].zero?
|
||||
X.subscribe event[:window]
|
||||
|
||||
|
||||
when :closed
|
||||
$all_windows.delete event[:window]
|
||||
$windows[event[:window]]&.delete
|
||||
X.focus $root
|
||||
|
||||
|
||||
when :enter
|
||||
@@ -37,6 +40,10 @@ def handle_event(event)
|
||||
if $windows[event[:window]].nil?
|
||||
monitor[:workspaces][monitor[:selected_workspace]].create event[:window]
|
||||
X.show event[:window]
|
||||
$all_windows.each do |window|
|
||||
above = `xprop -id #{window} _NET_WM_STATE`
|
||||
X.send_to_top window if above.include?("ABOVE")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
+5
-3
@@ -1,5 +1,3 @@
|
||||
require 'json'
|
||||
|
||||
def keybind(key, mod = 1, &block)
|
||||
X.add_keybind key, mod
|
||||
$keybind_actions[[key, mod]] = block if block
|
||||
@@ -31,7 +29,11 @@ def load_monitors!
|
||||
next unless line =~ /(\d+)x(\d+)\+(\d+)\+(\d+)/
|
||||
w, h, x, y = $1.to_i, $2.to_i, $3.to_i, $4.to_i
|
||||
key = index.zero? ? :primary : :secondary
|
||||
$monitors[key] = { x: x, y: y, width: w, height: h, workspaces: Array.new(persistence[key] || 1) { Workspace.new(key) }, selected_workspace: 0 }
|
||||
$monitors[key] = {
|
||||
x: x, y: y, width: w, height: h,
|
||||
workspaces: Array.new(persistence[key]&.[](:length) || 2) { Workspace.new(key) },
|
||||
selected_workspace: 1
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
+1
-6
@@ -22,12 +22,7 @@ class Window
|
||||
apply_geometry!
|
||||
end
|
||||
end
|
||||
wm_hints = X.get_wm_hints(window_id)
|
||||
if wm_hints
|
||||
if wm_hints[:flags] & 1 != 0 && wm_hints[:initial_state] == 3
|
||||
X.set_wm_state window_id, 1
|
||||
end
|
||||
end
|
||||
X.set_wm_state window_id, 1
|
||||
transient_for = X.get_wm_transient_for(window_id)
|
||||
unless transient_for.zero?
|
||||
@floating = true
|
||||
|
||||
@@ -144,10 +144,17 @@ class Workspace
|
||||
end
|
||||
|
||||
def hide
|
||||
self.windows.each { |window| X.hide window.window_id }
|
||||
self.windows.each do |window|
|
||||
X.hide window.window_id
|
||||
X.set_wm_state window.window_id, 3
|
||||
end
|
||||
X.focus $root
|
||||
end
|
||||
|
||||
def show
|
||||
self.windows.each { |window| X.show window.window_id }
|
||||
self.windows.each do |window|
|
||||
X.show window.window_id
|
||||
X.set_wm_state window.window_id, 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user