Hammerspoon: drawing a line in the title bar of a window

719 views Asked by At

I am trying to draw a red line in the title bar of a focused window. For this, I created code similar to the following (it is meant to be a minimal example):

function foo()
    f = hs.window.focusedWindow():frame()
    line = hs.drawing.line(hs.geometry.point(f.x, f.y),hs.geometry.point(f.w,f.y))
    line:setStrokeWidth(10)
    line:setStrokeColor(hs.drawing.color.red)
    line:show()
end

If I enter this into the Hammerspoon Console, followed by

foo()

it draws a line outside the window, not on the title bar, if the Console is placed in the right half of the display. Please see the attached screenshot. In fact, the position and length of the red line change, depending on the location of the Console window, and the desired red line can be drawn on the title bar, if the Console is in the left half of the display. I totally got confused. What is wrong with the code? Can anyone help?

enter image description here

EDIT

More photos are added. Note that setStrokeWith(30) is used.

enter image description here

enter image description here

enter image description here

1

There are 1 answers

0
Azure Heights On BEST ANSWER

As is, the code will place the bar windows width away from the left side of the screen. The seemingly fixed position is because the window width is the same. Use:

hs.geometry.point(f.x + f.w, f.y)

To place the second point as on offset from the first.