Class: DockDriver::WorkspacePager

Inherits:
Object
  • Object
show all
Extended by:
Configurability, Loggability
Includes:
Observable, Singleton
Defined in:
lib/dock_driver/workspace_pager.rb

Overview

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 %>

Constant Summary collapse

CONFIG_DEFAULTS =

Defaults for Configurability

{
    :format => "^ca(1,i3-msg workspace %s)^fg(%s)^%s(14x14)^p(-10)" + 
        "^ib(1)^fg(%s)%s^fg()^p(6)^fg()^ca()",
    :fg => '#808080',
    :bg => '#303030',
    :focused_fg => '#ffffff',
    :focused_bg => '#505050',
    :urgent_fg => '#800000',
    :urgent_bg => '#F00000'
}

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWorkspacePager

A boring constructor.



74
75
76
77
78
# File 'lib/dock_driver/workspace_pager.rb', line 74

def initialize
    self.log.debug "WorkspacePager::new"
    @workspaces = []
    @thread = nil
end

Class Attribute Details

.bgObject

A Foreground color for normal workspace squares.



45
46
47
# File 'lib/dock_driver/workspace_pager.rb', line 45

def bg
  @bg
end

.configObject

The loaded config



39
40
41
# File 'lib/dock_driver/workspace_pager.rb', line 39

def config
  @config
end

.fgObject

A Foreground color for normal workspace squares.



43
44
45
# File 'lib/dock_driver/workspace_pager.rb', line 43

def fg
  @fg
end

.focused_bgObject

A Foreground color for focused workspace squares.



49
50
51
# File 'lib/dock_driver/workspace_pager.rb', line 49

def focused_bg
  @focused_bg
end

.focused_fgObject

A Foreground color for focused workspace squares.



47
48
49
# File 'lib/dock_driver/workspace_pager.rb', line 47

def focused_fg
  @focused_fg
end

.formatObject

The format string for dzen2.



41
42
43
# File 'lib/dock_driver/workspace_pager.rb', line 41

def format
  @format
end

.urgent_bgObject

A Foreground color for urgent workspace squares.



53
54
55
# File 'lib/dock_driver/workspace_pager.rb', line 53

def urgent_bg
  @urgent_bg
end

.urgent_fgObject

A Foreground color for urgent workspace squares.



51
52
53
# File 'lib/dock_driver/workspace_pager.rb', line 51

def urgent_fg
  @urgent_fg
end

Instance Attribute Details

#i3Object

IPC communication with i3.



71
72
73
# File 'lib/dock_driver/workspace_pager.rb', line 71

def i3
  @i3
end

#workspacesObject

A list of workspaces.



69
70
71
# File 'lib/dock_driver/workspace_pager.rb', line 69

def workspaces
  @workspaces
end

Class Method Details

.configure(section) ⇒ Object

Merge in what Configurability finds.



57
58
59
60
61
62
63
64
65
66
# 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

Instance Method Details

#threadObject

Lazily create the thread to update the workspaces as necessary.



81
82
83
# File 'lib/dock_driver/workspace_pager.rb', line 81

def thread
    return @thread ||= Thread.new { loop { wait_for_event } }
end

#to_sObject

Return the pager as a formatted string for dzen2.



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/dock_driver/workspace_pager.rb', line 86

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