class DockDriver::WorkspacePager
Provides a list of workspaces as numbered rectangles that shows the number and presence of workspaces, the focused workspace, and any workspaces marked urgent. Example:
<%= pager %>
Constants
- CONFIG_DEFAULTS
Defaults for Configurability
Attributes
A Foreground color for normal workspace squares.
The loaded config
A Foreground color for normal workspace squares.
A Foreground color for focused workspace squares.
A Foreground color for focused workspace squares.
The format string for dzen2.
A Foreground color for urgent workspace squares.
A Foreground color for urgent workspace squares.
A list of workspaces.
Public Class Methods
Merge in what Configurability finds.
# File lib/dock_driver/workspace_pager.rb, line 57 def self::configure( section ) self.config = CONFIG_DEFAULTS.merge( section || {} ) self.format = self.config[:format] self.fg = self.config[:fg] self.bg = self.config[:bg] self.focused_fg = self.config[:focused_fg] self.focused_bg = self.config[:focused_bg] self.urgent_fg = self.config[:urgent_fg] self.urgent_bg = self.config[:urgent_bg] end
A boring constructor.
# File lib/dock_driver/workspace_pager.rb, line 72 def initialize self.log.debug "WorkspacePager::new" @workspaces = [] @thread = nil @i3 = nil end
Public Instance Methods
Lazily connect to i3.
# File lib/dock_driver/workspace_pager.rb, line 85 def i3 if @i3.nil? @i3 = I3.new @i3.subscribe_workspaces self.update end return @i3 rescue Exception => e self.log.debug "The pager was unable to connect to i3 over IPC." self.log.debug e end
Lazily create the thread to update the workspaces as necessary.
# File lib/dock_driver/workspace_pager.rb, line 80 def thread return @thread ||= Thread.new { loop { wait_for_event } } end
Return the pager as a formatted string for dzen2.
# File lib/dock_driver/workspace_pager.rb, line 105 def to_s return '' unless self.workspaces return self.workspaces.inject( '' ) do |str,space| if space['focused'] fg = self.class.focused_fg bg = self.class.focused_bg op = 'r' # a filled rectangle elsif space['urgent'] fg = self.class.urgent_fg bg = self.class.urgent_bg op = 'r' # a filled rectangle else fg = self.class.fg bg = self.class.bg op = 'ro' # a rectangle outline end str += self.class.format % [space['num'], bg, op, fg, space['num']] end end
Update the workspace list.
# File lib/dock_driver/workspace_pager.rb, line 98 def update self.workspaces = self.i3.get_workspaces.sort { |a,b| a['num'] <=> b['num'] } self.changed self.notify_observers end
Private Instance Methods
Wait for workspace events.
# File lib/dock_driver/workspace_pager.rb, line 131 def wait_for_event begin self.i3.wait_for_event( I3::EVENT_WORKSPACE ) self.update rescue Exception => e @i3 = nil self.log.debug "The pager was unable to communicate with i3 over IPC." self.log.debug e sleep 1 end end