Class: Uh::WM

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Events
Defined in:
lib/uh/wm.rb,
lib/uh/wm/client.rb,
lib/uh/wm/manager.rb,
lib/uh/wm/action_handler.rb,
lib/uh/wm/workers/base_worker.rb,
lib/uh/wm/workers/blocking_worker.rb,
lib/uh/wm/workers/multiplexing_worker.rb

Defined Under Namespace

Modules: Workers Classes: ActionHandler, Client, Manager

Constant Summary collapse

LOGGER_FORMAT_STR =
"%s.%03i %s: %s\n".freeze
LOGGER_FORMATER =
proc do |severity, datetime, progname, message|
  LOGGER_FORMAT_STR % [
    datetime.strftime('%FT%T'),
    datetime.usec / 1000,
    severity[0..0],
    message
  ]
end
LOGGER_LEVEL =
Logger::INFO
LOGGER_DEBUG_ENV =
'UH_DEBUG'.freeze
WORKERS =
{
  blocking:     Workers::BlockingWorker,
  multiplexing: Workers::MultiplexingWorker
}.freeze
DEFAULT_MODIFIER =
:mod1
INPUT_MASK =
SUBSTRUCTURE_REDIRECT_MASK
ROOT_MASK =
PROPERTY_CHANGE_MASK |
SUBSTRUCTURE_REDIRECT_MASK |
SUBSTRUCTURE_NOTIFY_MASK |
STRUCTURE_NOTIFY_MASK

Constants included from Events

Events::BUTTON1_MOTION_MASK, Events::BUTTON2_MOTION_MASK, Events::BUTTON3_MOTION_MASK, Events::BUTTON4_MOTION_MASK, Events::BUTTON5_MOTION_MASK, Events::BUTTON_MOTION_MASK, Events::BUTTON_PRESS_MASK, Events::BUTTON_RELEASE_MASK, Events::COLORMAP_CHANGE_MASK, Events::ENTER_WINDOW_MASK, Events::EXPOSURE_MASK, Events::FOCUS_CHANGE_MASK, Events::KEYMAP_STATE_MASK, Events::KEY_PRESS_MASK, Events::KEY_RELEASE_MASK, Events::LEAVE_WINDOW_MASK, Events::NO_EVENT_MASK, Events::OWNER_GRAB_BUTTON_MASK, Events::POINTER_MOTION_HINT_MASK, Events::POINTER_MOTION_MASK, Events::PROPERTY_CHANGE_MASK, Events::RESIZE_REDIRECT_MASK, Events::STRUCTURE_NOTIFY_MASK, Events::SUBSTRUCTURE_NOTIFY_MASK, Events::SUBSTRUCTURE_REDIRECT_MASK, Events::VISIBILITY_CHANGE_MASK

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(layout) ⇒ WM

Returns a new instance of WM.



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/uh/wm.rb', line 47

def initialize(layout)
  @layout   = layout
  @display  = Display.new
  @logger   = Logger.new($stdout).tap do |o|
    o.level     = ENV.key?(LOGGER_DEBUG_ENV) ? Logger::DEBUG : LOGGER_LEVEL
    o.formatter = LOGGER_FORMATER
  end
  @manager  = Manager.new
  @actions  = ActionHandler.new(self, @manager, @layout)
  @keys     = {}
  @rules    = {}
end

Instance Attribute Details

#actionsObject (readonly)

Returns the value of attribute actions.



45
46
47
# File 'lib/uh/wm.rb', line 45

def actions
  @actions
end

#keysObject (readonly)

Returns the value of attribute keys.



45
46
47
# File 'lib/uh/wm.rb', line 45

def keys
  @keys
end

#rulesObject (readonly)

Returns the value of attribute rules.



45
46
47
# File 'lib/uh/wm.rb', line 45

def rules
  @rules
end

Instance Method Details

#connectObject



93
94
95
96
97
98
99
100
101
102
103
# File 'lib/uh/wm.rb', line 93

def connect
  @display.open
  Display.on_error proc { fail OtherWMRunningError }
  @display.listen_events INPUT_MASK
  @display.sync false
  Display.on_error proc { |*args| handle_error(*args) }
  @display.sync false
  @display.root.mask = ROOT_MASK
  @worker.setup
  @on_init.call @display if @on_init
end

#disconnectObject



105
106
107
# File 'lib/uh/wm.rb', line 105

def disconnect
  @display.close
end

#grab_keysObject



109
110
111
112
113
114
115
116
# File 'lib/uh/wm.rb', line 109

def grab_keys
  @keys.each do |k, v|
    key, mod = *k
    key = key.to_s.gsub /\AXK_/, ''
    @display.grab_key key, mod
  end
  @display.sync false
end

#key(key, mod = nil, &block) ⇒ Object



65
66
67
68
69
# File 'lib/uh/wm.rb', line 65

def key(key, mod = nil, &block)
  mod_mask = KEY_MODIFIERS[modifier]
  mod_mask |= KEY_MODIFIERS[mod] if mod
  @keys[[key, mod_mask]] = block
end

#modifier(mod = nil) ⇒ Object



60
61
62
63
# File 'lib/uh/wm.rb', line 60

def modifier(mod = nil)
  return (@modifier or DEFAULT_MODIFIER) unless mod
  @modifier = mod
end

#on_expose(&block) ⇒ Object



81
82
83
# File 'lib/uh/wm.rb', line 81

def on_expose(&block)
  @on_expose = block
end

#on_init(&block) ⇒ Object



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

def on_init(&block)
  @on_init = block
end

#request_quit!Object



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

def request_quit!
  @quit_requested = true
end

#rule(selectors = '', &block) ⇒ Object



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

def rule(selectors = '', &block)
  [*selectors].each do |selector|
    @rules[/\A#{selector}/i] = block
  end
end

#runObject



125
126
127
# File 'lib/uh/wm.rb', line 125

def run
  run_until { quit_requested? }
end

#run_until(&block) ⇒ Object



118
119
120
121
122
123
# File 'lib/uh/wm.rb', line 118

def run_until(&block)
  @worker.each_event do |e|
    process_event e
    break if block.call
  end
end

#worker(*args, **options) ⇒ Object



85
86
87
# File 'lib/uh/wm.rb', line 85

def worker(*args, **options)
  @worker = WORKERS[args.first].new(@display, @logger, options)
end