Spectacle currently works by resizing windows using a number of native builtin window actions. To make Spectacle even more flexible let's introduce the concept custom JavaScript-based window actions. Given an expressive enough API this should allow anybody to build custom window actions and assign them to keyboard shortcuts of their choosing.
At a high level the following work needs to be done:
Spectacle will load custom window actions from ~/.spectacle and all builtin window actions from the application bundle. Loading builtin window actions from the application bundle means that a particular release of Spectacle will have a known set of builtin window actions. Instead of customizing builtin window actions folks can instead replace them with their own custom window actions.
Spectacle's window position calculator is now built using JavaScript-based window calculations. This is the first big step towards adding support for custom window actions.
Those interested in this work can try out the latest changes on master to get a feel for the JavaScript integration.
Hello @eczarny !
First of all thank you for developing this great piece of software 👍
I'm interested in testing out the scriptable approach with javascript.
I would like to reproduce the behaviour of keyboard shortcuts like the one in Linux Mint - where depending on where current Window is placed (for example left-half) you can just press cmd+up arrow and Window will be placed in upper-left half of monitor.
Is there any documentation regarding JS API?
Or any specific place in source code I could look into to get the overview?
I am not very much experienced with Obj-C - that's why I am bugging you here %)
Thank you very much!
@nazriel no documentation yet. Your best option to try things out is to open the application bundle and tweak the .js files you will find there.
The customization of the JavaScript actions is a big step, very helpful. Is it also possible to customize their display names in the Spectacle menu & preferences?
Anyone has samples on how to make actions like?
I have tried on
// original in /Applications/Spectacle.app/Contents/Resources/Window Position Calculations/SpectacleFullscreenWindowCalculation.js
// return visibleFrameOfDestinationScreen;
// modify
var doubleMonitorRect = SpectacleCalculationHelpers.copyRect(visibleFrameOfDestinationScreen);
doubleMonitorRect.x = doubleMonitorRect.width;
doubleMonitorRect.width = doubleMonitorRect.width * 2;
return doubleMonitorRect;
It now can fullscreen correctly on both two monitors, but only when the windows is on the right monitor.
When it on left monitor my window expanded width to correct size (2 * width), but have it right edge match the divider of two monitor.
I am trying to solve by detect which is current screen but no success.
The input only have 3 args: windowRect, visibleFrameOfSourceScreen, visibleFrameOfDestinationScreen which I do not fully understand what are those too.
Hi,
I would need to give a window a specific width. Where should I go to do that ?
Best !
Roch
Most helpful comment
Spectacle's window position calculator is now built using JavaScript-based window calculations. This is the first big step towards adding support for custom window actions.
Those interested in this work can try out the latest changes on master to get a feel for the JavaScript integration.