Make it work
This commit is contained in:
+44
-20
@@ -1,34 +1,47 @@
|
||||
class Window < Node
|
||||
attr_accessor :window_id, :x, :y, :width, :height, :state, :floating, :workspace
|
||||
class Window
|
||||
attr_accessor :window_id, :floating, :workspace, :def_floating, :size, :x, :y, :width, :height
|
||||
|
||||
def initialize(window_id, workspace)
|
||||
@size = 0
|
||||
@workspace = workspace
|
||||
@window_id = window_id
|
||||
@name = X.get_wm_name(window_id)
|
||||
@wm_n_hints = X.get_wm_n_hints(window_id)
|
||||
wm_n_hints = X.get_wm_n_hints(window_id)
|
||||
@floating = false
|
||||
if @wm_n_hints
|
||||
if fixed_size_or_aspect?(@wm_n_hints)
|
||||
if wm_n_hints
|
||||
if fixed_size_or_aspect?(wm_n_hints)
|
||||
@floating = true
|
||||
@width = @wm_n_hints[:max_width]
|
||||
if @wm_n_hints[:flags] & 128 != 0
|
||||
@height = @wm_n_hints[:max_width] * (@wm_n_hints[:min_aspect_num] / @wm_n_hints[:min_aspect_den])
|
||||
@def_floating = true
|
||||
@width = wm_n_hints[:max_width]
|
||||
if wm_n_hints[:flags] & 128 != 0
|
||||
@height = wm_n_hints[:max_width] * (wm_n_hints[:min_aspect_num] / wm_n_hints[:min_aspect_den])
|
||||
else
|
||||
@height = @wm_n_hints[:max_height]
|
||||
@height = wm_n_hints[:max_height]
|
||||
end
|
||||
@x = @workspace.width / 2 - @width / 2
|
||||
@y = @workspace.height / 2 - @height / 2
|
||||
@x = $monitors[@workspace.monitor_id][:width] / 2 - @width / 2
|
||||
@y = $monitors[@workspace.monitor_id][:height] / 2 - @height / 2
|
||||
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
|
||||
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
|
||||
@transient_for = X.get_wm_transient_for(window_id)
|
||||
@floating = true unless @transient_for.zero?
|
||||
transient_for = X.get_wm_transient_for(window_id)
|
||||
unless transient_for.zero?
|
||||
@floating = true
|
||||
@def_floating = true
|
||||
@width = wm_n_hints[:max_width]
|
||||
if wm_n_hints[:flags] & 128 != 0
|
||||
@height = wm_n_hints[:max_width] * (wm_n_hints[:min_aspect_num] / wm_n_hints[:min_aspect_den])
|
||||
else
|
||||
@height = wm_n_hints[:max_height]
|
||||
end
|
||||
@x = $monitors[@workspace.monitor_id][:width] / 2 - @width / 2
|
||||
@y = $monitors[@workspace.monitor_id][:height] / 2 - @height / 2
|
||||
apply_geometry!
|
||||
end
|
||||
super()
|
||||
end
|
||||
|
||||
@@ -40,21 +53,32 @@ class Window < Node
|
||||
block.call(self)
|
||||
end
|
||||
|
||||
def toggle_floating
|
||||
if !@def_floating
|
||||
@floating = !@floating
|
||||
@workspace.check_floating self
|
||||
apply_geometry!
|
||||
end
|
||||
end
|
||||
|
||||
def move(x, y)
|
||||
return unless @floating
|
||||
@x, @y = x, y
|
||||
apply_geometry!
|
||||
end
|
||||
|
||||
def resize(width, height)
|
||||
def resize(width, height, force = false)
|
||||
return unless @floating
|
||||
@x = @workspace.width / 2 - width / 2
|
||||
@y = @workspace.height / 2 - height / 2
|
||||
@width, @height = width, height
|
||||
if !force
|
||||
@x = $monitors[@workspace.monitor_id][:width] / 2 - @width / 2
|
||||
@y = $monitors[@workspace.monitor_id][:height] / 2 - @height / 2
|
||||
end
|
||||
apply_geometry!
|
||||
end
|
||||
|
||||
def apply_geometry!
|
||||
X.send_to_top @window_id if @floating
|
||||
X.move_window @window_id, @x, @y
|
||||
X.resize_window @window_id, @width, @height
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user