Class: Uh::WM::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/uh/wm/manager.rb

Constant Summary collapse

INPUT_MASK =
Events::SUBSTRUCTURE_REDIRECT_MASK
ROOT_MASK =
Events::PROPERTY_CHANGE_MASK |
Events::SUBSTRUCTURE_REDIRECT_MASK |
Events::SUBSTRUCTURE_NOTIFY_MASK |
Events::STRUCTURE_NOTIFY_MASK
DEFAULT_GEO =
Geo.new(0, 0, 320, 240).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(events, mod, mod_ignore = [], display = Display.new) ⇒ Manager

Returns a new instance of Manager.



13
14
15
16
17
18
19
# File 'lib/uh/wm/manager.rb', line 13

def initialize events, mod, mod_ignore = [], display = Display.new
  @events           = events
  @modifier         = mod
  @modifier_ignore  = mod_ignore
  @display          = display
  @clients          = []
end

Instance Attribute Details

#clientsObject (readonly)

Returns the value of attribute clients.



11
12
13
# File 'lib/uh/wm/manager.rb', line 11

def clients
  @clients
end

#displayObject (readonly)

Returns the value of attribute display.



11
12
13
# File 'lib/uh/wm/manager.rb', line 11

def display
  @display
end

#modifierObject (readonly)

Returns the value of attribute modifier.



11
12
13
# File 'lib/uh/wm/manager.rb', line 11

def modifier
  @modifier
end

#modifier_ignoreObject (readonly)

Returns the value of attribute modifier_ignore.



11
12
13
# File 'lib/uh/wm/manager.rb', line 11

def modifier_ignore
  @modifier_ignore
end

Instance Method Details

#configure(window) ⇒ Object



52
53
54
55
56
57
58
59
# File 'lib/uh/wm/manager.rb', line 52

def configure window
  if client = client_for(window)
    client.configure
  else
    geo = @events.emit :configure, args: window
    window.configure_event geo ? geo : DEFAULT_GEO
  end
end

#connectObject



25
26
27
28
29
30
31
32
33
# File 'lib/uh/wm/manager.rb', line 25

def connect
  @events.emit :connecting, args: @display
  @display.open
  check_other_wm!
  Display.on_error { |*args| handle_error *args }
  @display.sync false
  @events.emit :connected, args: @display
  @display.root.mask = ROOT_MASK
end

#destroy(window) ⇒ Object



77
78
79
80
# File 'lib/uh/wm/manager.rb', line 77

def destroy window
  return unless client = client_for(window)
  unmanage client
end

#disconnectObject



35
36
37
38
# File 'lib/uh/wm/manager.rb', line 35

def disconnect
  @display.close
  @events.emit :disconnected
end

#flushObject



40
41
42
# File 'lib/uh/wm/manager.rb', line 40

def flush
  @display.flush
end

#grab_key(keysym, mod = nil) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/uh/wm/manager.rb', line 44

def grab_key keysym, mod = nil
  mod_mask = KEY_MODIFIERS[@modifier]
  mod_mask |= KEY_MODIFIERS[mod] if mod
  combine_modifier_masks(@modifier_ignore) do |ignore_mask|
    @display.grab_key keysym.to_s, mod_mask | ignore_mask
  end
end

#handle(event) ⇒ Object



96
97
98
99
100
# File 'lib/uh/wm/manager.rb', line 96

def handle event
  @events.emit :xevent, args: event
  return unless respond_to? handler = "handle_#{event.type}".to_sym, true
  send handler, event
end

#handle_next_eventObject



88
89
90
# File 'lib/uh/wm/manager.rb', line 88

def handle_next_event
  handle @display.next_event
end

#handle_pending_eventsObject



92
93
94
# File 'lib/uh/wm/manager.rb', line 92

def handle_pending_events
  handle_next_event while @display.pending?
end

#map(window) ⇒ Object



61
62
63
64
65
66
# File 'lib/uh/wm/manager.rb', line 61

def map window
  return if window.override_redirect? || client_for(window)
  @clients << client = Client.new(window)
  @events.emit :manage, args: client
  @display.listen_events window, Events::PROPERTY_CHANGE_MASK
end

#to_ioObject



21
22
23
# File 'lib/uh/wm/manager.rb', line 21

def to_io
  IO.new(@display.fileno)
end

#unmap(window) ⇒ Object



68
69
70
71
72
73
74
75
# File 'lib/uh/wm/manager.rb', line 68

def unmap window
  return unless client = client_for(window)
  if client.unmap_count > 0
    client.unmap_count -= 1
  else
    unmanage client
  end
end

#update_properties(window) ⇒ Object



82
83
84
85
86
# File 'lib/uh/wm/manager.rb', line 82

def update_properties window
  return unless client = client_for(window)
  client.update_window_properties
  @events.emit :change, args: client
end