docs » MenubarFlag

Color the menubar according to the current keyboard layout

Download: https://github.com/Hammerspoon/Spoons/raw/master/Spoons/MenubarFlag.spoon.zip

Functionality inspired by ShowyEdge

API Overview

API Documentation

Variables

allScreens
Signature MenubarFlag.allScreens
Type Variable
Description Boolean to specify whether the indicators should be shown on all monitors or just the current one. Defaults to `true`
Source Source/MenubarFlag.spoon/init.lua line 22
colors
Signature MenubarFlag.colors
Type Variable
Description Table that contains the configuration of indicator colors
Notes
  • The table below indicates the colors to use for a given keyboard layout.
  • The index is the name of the layout as it appears in the input source menu.
  • The value of each indicator is a table made of an arbitrary number of segments, which will be distributed evenly across the width of the screen.
  • Each segment must be a valid hs.drawing.color specification (most commonly, you should just use the named colors from within the tables). If a layout is not found, then the indicators are removed when that layout is active.
  • Indicator specs can be static flag-like:
  Spanish = {col.green, col.white, col.red},
  German = {col.black, col.red, col.yellow},

or complex, programmatically-generated:

["U.S."] = (
   function() res={}
      for i = 0,10,1 do
         table.insert(res, col.blue)
         table.insert(res, col.white)
         table.insert(res, col.red)
      end
      return res
   end)()

or solid colors:

  Spanish = {col.red},
  German = {col.yellow},
  • Contributions of indicator specs are welcome!
Source Source/MenubarFlag.spoon/init.lua line 42
indicatorAlpha
Signature MenubarFlag.indicatorAlpha
Type Variable
Description Number to specify the indicator transparency (0.0 - invisible; 1.0 - fully opaque). Defaults to 0.3
Source Source/MenubarFlag.spoon/init.lua line 32
indicatorHeight
Signature MenubarFlag.indicatorHeight
Type Variable
Description Number to specify the height of the indicator. Specify 0.0-1.0 to specify a percentage of the height of the menu bar, larger values indicate a fixed height in pixels. Defaults to 1.0
Source Source/MenubarFlag.spoon/init.lua line 27
indicatorInAllSpaces
Signature MenubarFlag.indicatorInAllSpaces
Type Variable
Description Boolean to specify whether the indicator should be shown in all spaces (this includes full-screen mode). Defaults to `true`
Source Source/MenubarFlag.spoon/init.lua line 37
timerFreq
Signature MenubarFlag.timerFreq
Type Variable
Description Number to indicate how frequently (in seconds) should the menubar indicator be updated. Defaults to 1.0.
Notes
  • Sometimes Hammerspoon misses the callback when the keyboard layout changes. As a workaround, MenuBarFlag can automatically update the indicator at a fixed frequency.
  • The timer can be disabled by setting this parameter to 0.
Source Source/MenubarFlag.spoon/init.lua line 80

Methods

drawIndicators
Signature MenubarFlag:drawIndicators(src)
Type Method
Description Draw the indicators corresponding to the given layout name
Parameters
  • src - name of the layout to draw. If the given element exists in MenubarFlag.colors, it will be drawn. If it does not exist, then the indicators will be removed from the screen.
Returns
  • The MenubarFlag object
Source Source/MenubarFlag.spoon/init.lua line 118
getLayoutAndDrawindicators
Signature MenubarFlag:getLayoutAndDrawindicators()
Type Method
Description Draw indicators for the current keyboard method or layout
Parameters
  • None
Returns
  • The MenubarFlag object
Source Source/MenubarFlag.spoon/init.lua line 175
start
Signature MenubarFlag:start()
Type Method
Description Start the keyboard layout watcher to draw the menubar indicators.
Parameters
  • None
Returns
Source Source/MenubarFlag.spoon/init.lua line 188
stop
Signature MenubarFlag:stop()
Type Method
Description Remove indicators and stop the keyboard layout watcher
Parameters
  • None
Returns
Source Source/MenubarFlag.spoon/init.lua line 208