helper.rb 2.31 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27


# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----
# helpers

# script arguments
def get_monitor(arguments)
  # ternary operator
  arguments.length > 0 ? arguments[0].to_i : 0
end

# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----
# geometry calculation

def get_geometry(monitor)
  raw = IO.popen('herbstclient monitor_rect '+ monitor.to_s).read()

  if raw.to_s.empty?
    print('Invalid monitor ' + monitor.to_s)
    exit(1)
  end
    
  raw.split(' ')
end

def get_top_panel_geometry(height, geometry)
  # geometry has the format X Y W H
epsi sayidina's avatar
epsi sayidina committed
28
29
  return geometry[0].to_i, geometry[1].to_i, 
         geometry[2].to_i, height
30
31
32
33
end

def get_bottom_panel_geometry(height, geometry)
  # geometry has the format X Y W H
epsi sayidina's avatar
epsi sayidina committed
34
35
  return geometry[0].to_i + 0, (geometry[3].to_i - height), 
         geometry[2].to_i - 0, height
36
37
38
39
40
end

# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----
# lemon Parameters

epsi sayidina's avatar
epsi sayidina committed
41
def get_params_top(monitor, panel_height)
42
43
44
45
46
47
  # calculate geometry
  geometry = get_geometry(monitor)
  xpos, ypos, width, height = get_top_panel_geometry(
    panel_height, geometry)

  # geometry: -g widthxheight+x+y
epsi sayidina's avatar
epsi sayidina committed
48
  geom_res = "#{width}x#{height}+#{xpos}+#{ypos}"
49
50
51
52
53
54
55
56
57
58

  # color, with transparency    
  bgcolor = "'#aa000000'"
  fgcolor = "'#ffffff'"

  # XFT: require lemonbar_xft_git 
  font_takaop  = "takaopgothic-9"
  font_symbol  = "PowerlineSymbols-11"
  font_awesome = "FontAwesome-9"

epsi sayidina's avatar
epsi sayidina committed
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
  parameters = " -g #{geom_res} -u 2" \
               " -B #{bgcolor} -F #{fgcolor}" \
               " -f #{font_takaop} -f #{font_awesome} -f #{font_symbol}"
end

def get_params_bottom(monitor, panel_height)
  # calculate geometry
  geometry = get_geometry(monitor)
  xpos, ypos, width, height = get_bottom_panel_geometry(
    panel_height, geometry)

  # geometry: -g widthxheight+x+y
  geom_res = "#{width}x#{height}+#{xpos}+#{ypos}"

  # color, with transparency    
  bgcolor = "'#aa000000'"
  fgcolor = "'#ffffff'"

  # XFT: require lemonbar_xft_git 
  font_mono    = "monospace-9"
  font_symbol  = "PowerlineSymbols-11"
  font_awesome = "FontAwesome-9"

  parameters = " -g #{geom_res} -u 2" \
               " -B #{bgcolor} -F #{fgcolor}" \
               " -f #{font_mono} -f #{font_awesome} -f #{font_symbol}"
end

def get_lemon_parameters(monitor, panel_height)
  get_params_top(monitor, panel_height)
89
end