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

bg[RW]

A Foreground color for normal workspace squares.

config[RW]

The loaded config

fg[RW]

A Foreground color for normal workspace squares.

focused_bg[RW]

A Foreground color for focused workspace squares.

focused_fg[RW]

A Foreground color for focused workspace squares.

format[RW]

The format string for dzen2.

urgent_bg[RW]

A Foreground color for urgent workspace squares.

urgent_fg[RW]

A Foreground color for urgent workspace squares.

workspaces[RW]

A list of workspaces.

Public Class Methods

configure( section ) click to toggle source

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
new() click to toggle source

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

i3() click to toggle source

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
thread() click to toggle source

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
to_s() click to toggle source

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() click to toggle source

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_event() click to toggle source

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