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

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?
EDIT
More photos are added. Note that setStrokeWith(30) is used.

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.

Related

How to suppress tqdm flashing bar after description

I need to update the description in a loop. I've simplified my case to just print text; there's no progress bar. Code is like this:
fake = faker.Faker()
pbar = tqdm(bar_format=" {desc}")
for _ in range(1000):
time.sleep(0.1)
pbar.set_description_str(fake.name())
pbar.close()
Problem: there's always a narrow, flashing bar at the end of the description, very much like the wide cursor.
Question: how can I get rid of this flashing bar, and just cleanly print text only?
Earlier I wanted to show this text line below a progress bar. This flashing bar goes above its own line and causes worse interference. I'm not attempting that now. Hope to solve the simpler problem above. Thanks.

Buttons in UITextView

I want to create a View very similar To the iOS notes application. The main function is to allow the user to get a check box in front of a line of Text.
My first attempt is this:
I have a UITextView where i try to insert buttons on the left side of the View, the Problem is i dont get the right y Position for each line and the whole text is offsetted even if there is no Button in Front of the line.
Question:
Is there a better approach, maybe much simpler or even built in functionality in UITextView i couldnā€˜t find?
If not, how do i get the exact y position of the line the cursor is currently in, so i can set the Buttons in the correct positions?

GAMBAS3 - show form on second screen

Does anybody know how to show a specific form from GAMBAS3 in the second monitor? The main frm should open on primaryscreen and the second one on the second screen. i cannot find any solution.
All the physical screens are merged to form a single big virtual screen. So you have to move the window to a position located on your second screen.
For example, if your first screen is 1024x768, and your second screen is the same size, sticked to the right of the first screen, then you do:
MyForm1.Move(1200, 0)
MyForm1.Show
and the form should open on the second screen.

How to get red distance lines in storyboard Xcode?

Watching a tutorial and it looks like the guy is holding down a button to show the distance between his selected view and what's around it.
I've tried command, option, control, and every other button I can think might work. What button needs to be held to get these lines?
By pressing option key only on your keyboard.
Select an element, and move the mouse while pressing the option key, it will show the red lines with the distances.
Hovering over another element will show you the distance between the selected element and that element.

Detect height of a window's title bar

I am using ClipCursor to lock a mouse in a window. How do I detect the height of the window's title bar and border of the window (so the only place the mouse can't click the title bar and the minimize, restore and maximize button)?
The height of the title bar depends on OS (I can't give a definite value for this).
I'm not sure if the borders have different widths with different operating systems.
I'm using windows XP on classic mode.
When I change to themed mode the height of the title bar changes so it won't work.
No specific language used.
You can use AutoIt.
You don't have to deal with that specific titlebar height and border width. Instead try to set the MouseCoordMode to relative client position, move the mouse to the top/left position and get the window client size. This is the exact area you want your mouse to be trapped into.
These values can then be used in the _MouseTrap function. It should be similar to your ClipCursor().
The old mouse Position could be saved and restored but it won't make sense as your mouse might be repositioned into the trap field anyways so I commented this out.
#include <GuiConstantsEx.au3>
#include <Misc.au3>
Opt("MustDeclareVars", 1)
_Main()
Func _Main()
Local $GUI, $oldMouseCoordMode, $topLeft, $size ;,$oldMousePos
$GUI = GUICreate("Example MouseTrap", 392, 323)
GUISetBkColor( 0xff0000, $GUI)
GUISetState()
;~ $oldMousePos = MouseGetPos()
$oldMouseCoordMode = Opt("MouseCoordMode", 2)
MouseMove(0, 0, 0)
Opt("MouseCoordMode", 1)
$topLeft = MouseGetPos()
;~ MouseMove($oldMousePos[0], $oldMousePos[1], 0)
$size = WinGetClientSize($GUI)
Opt("MouseCoordMode", $oldMouseCoordMode)
_MouseTrap($topLeft[0], $topLeft[1], $topLeft[0] + $size[0], $topLeft[1] + $size[1])
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
Case Else
;;;
EndSwitch
WEnd
_MouseTrap()
Exit
EndFunc ;==>_Main
Would it work to get the window's client rect, rather than its full rect? I believe that will return the client area of the window, which is the window's rect minus the border and title bar.
If you go this route, you will need to convert the rect into screen coordinates before calling ClipCursor(), though.
I just found out a more specific answer to your problem while browsing the AutoIt help. In the description of the function _WinAPI_CreateRectRgn() there is the following way to get the wished sizes:
#include <WinAPI.au3>
; get height of window title and width of window frame - may be different when
; XP theme is ON/OFF
Global $htit = _WinAPI_GetSystemMetrics($SM_CYCAPTION)
Global $frame = _WinAPI_GetSystemMetrics($SM_CXDLGFRAME)
looks like
GetSystemMetrics(SM_CYCAPTION)+GetSystemMetrics(SM_CYSIZEFRAME)
is the correct height of title bar
One solution in AutoHotKey is to simply remove the bar! That will still allow people to use short cuts to manipulate the window though...
^F11:: ; Ctrl+F11 = Toggle show Window title bar
WinSet, Style, ^0xC00000, A ; Toggle the active window's title bar (WS_CAPTION).
If (TopbarHide := !TopbarHide) ;
ToolTip Topbar Ctrl F11,A_ScreenWidth/2-50,0
else
Tooltip
Return

Resources