Giter VIP home page Giter VIP logo

Comments (2)

R-7200 avatar R-7200 commented on September 20, 2024 1

Hi!

Works as described :-) I mistook the declaration of

switcher = hs.window.switcher.new()

for a general function (switcher.ui.highlight). Sorry for that - I was tired...

Thank you for clarifying; marked as solved!

Have a nice day!

from hammerspoon.

Rhys-T avatar Rhys-T commented on September 20, 2024

It doesn't look like there's currently any official way to make those corners rounded, but it could probably be added.

As a workaround for now, if you're okay poking around inside hs.window.switcher's implementation details, you can get the hs.drawing object being used to draw the highlight rectangle and set its corner radius manually using the setRoundedRectRadii method:

ws = hs.window.switcher.new( --[[ whatever arguments ]] )
-- any ws.ui configuration goes here
local highlightRadius = 10 -- or whatever
ws.drawings.highlightRect:setRoundedRectRadii(highlightRadius, highlightRadius)

Make sure you finish modifying that switcher's ui object before you set the radius. Any changes to ws.ui will cause the highlight drawing to be recreated and lose that change. (Changes to the global hs.window.switcher.ui object won't do that, but they also won't properly update switchers you've already created.)

If you want to avoid losing the radius whenever you change `ws.ui`…

It's possible, but requires messing with hs.window.switcher's internals even more using Lua's debug functions:

local function findUpvalue(f, name)
	local i = 0
	local n, v
	repeat
		i = i + 1
		n, v = debug.getupvalue(f, i)
	until not n or n == name
	if not n then return nil end
	return i, v
end

local setUiPrefsUpvalueIndex, oldSetUiPrefs = findUpvalue(hs.window.switcher.new, 'setUiPrefs')
if not setUiPrefsUpvalueIndex then
	error "Couldn't find hs.window.switcher's setUiPrefs function"
end
debug.setupvalue(hs.window.switcher.new, setUiPrefsUpvalueIndex, function(self)
	oldSetUiPrefs(self)
	local highlightRadius = self.ui.highlightRadius or 0
	self.drawings.highlightRect:setRoundedRectRadii(highlightRadius, highlightRadius)
end)

-- Now you can do:
hs.window.switcher.ui.highlightRadius = 10 -- or whatever
ws = hs.window.switcher.new( --[[ whatever arguments ]] )

-- or for a specific switcher:
ws.ui.highlightRadius = 15 -- or whatever
If you want to make it match the size of the existing rounded corners…

There are three radii that are computed and used by hs.window.switcher, so it depends which one you're trying to match:

  • ui.titleRectRadius: Used for the window titles in the main switcher area. Defined as 1/4 of ui.textSize (which defaults to 16, making this radius 4).
  • selectedRectRadius: Used for the large preview box for the selected window, as well as the title box at the top of that preview. Defined as 1/4 of the height of an uppercase O in the selected-window title font (with the odd effect of not rounding those corners if you turn that title off). With default settings, that seems to work out to 8.
  • padding: Used for the corners of the switcher itself. Also has some non-corner-radius uses: It's the amount of space between two thumbnails, or between the first/last thumbnail and the corresponding edge of the switcher. Defined in a complicated way based on ui.thumbnailSize, the number of windows, and the available screen width. If you're trying to match the switcher's corners, it will probably take a more involved patch to actually find that value.

from hammerspoon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.