3 ms·
I have always wanted to implement pie menus as a Firefox or Chrome extension, but I've never been able to find a sufficient API that enables me to pop up a moda
by DonHopkins 5y ago
I have always wanted to implement pie menus as a Firefox or Chrome extension, but I've never been able to find a sufficient API that enables me to pop up a modal dialog window at any place on the screen (specifically: centered on the current mouse cursor position, and in an operating system window that exists outside of the browser tab, overlapping all other windows). Or reshape it to any shape (or simply respect the alpha channel of the document and not show any chrome), so I can make a round or arbitrarily shaped window shrink wrapped to the items.
https://developer.chrome.com/docs/extensions/reference/windows/#type-CreateType https://developer.chrome.com/docs/extensions/reference/windo...
Is there a way with that (or any other) API to pop up and precisely measure and position an arbitrarily shaped (alpha channeled) window, without any other chrome or window frames? And then globally capture and track mouse and keyboard events?
Does anyone know if there's now a way for a browser extension to do that in any browser? Or would it require hacking platform specific C++ operating system code?
Here's a demo of an ancient implementation of pie menus I made for ActiveX around 1997, that shows pie menus with arbitrarily shaped windows:
ActiveX Pie Menus: Demo of the free ActiveX Pie Menu Control, developed and demonstrated by Don Hopkins.
https://www.youtube.com/watch?v=nnC8x9x3Xag https://www.youtube.com/watch?v=nnC8x9x3Xag
ActiveX Pie Menus doc, examples, sources, etc:
https://www.donhopkins.com/home/catalog/piemenus/ActiveXPieMenus.html https://www.donhopkins.com/home/catalog/piemenus/ActiveXPieM...
https://www.donhopkins.com/home/catalog/piemenus/PieMenuDescription.html https://www.donhopkins.com/home/catalog/piemenus/PieMenuDesc...
I did all the drawing with Win32 calls, so you could configure the fonts and colors and sizes and window shapes and styles, but you couldn't style everything arbitrarily with css, embed arbitrary web content, or anything nice like that.
At the end of the demo video, I concluded that:
>I ran up into a wall of complexity with this ActiveX control, in that I wanted to be able to have as the menu items animated gifs, mpeg movies, fonts with nice attributes, and things like that.
>So the first thought was "well let's just put a whole web browser in every item!"
>But that was a little heavy-handed. So instead, I put the pie menus into the web browser as a Dynamic HTML Component. Which I'll show next.
Of course it makes a lot more sense to draw and style the pie menus with the browser's renderer, but I still want the best of both worlds, where I can pop browser-drawn pie menus in arbitrarily shaped and positioned operating system windows, and track the mouse globally (capturing the mouse and keyboard events and receiving mouse motion and up and key events outside the window, to pop up and track sub-menus properly).
JavaScript Pie Menus: Pie menus for JavaScript on Internet Explorer version 5, configured in XML, rendered with dynamic HTML, by Don Hopkins:
https://www.youtube.com/watch?v=R5k4gJK-aWw&ab_channel=DonHopkinsDonHopkins https://www.youtube.com/watch?v=R5k4gJK-aWw&ab_channel=DonHo...
- aasasd 5y agoYou'd probably want to use ‘native messaging’ from the extension for this: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Native_messaging https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/Web... I think it's sufficient to override the ‘contextmenu’ event and signal to your app where to show the menu and what to show in it. You can even implement the menu itself in something like Hammerspoon on Mac, with Lua APIs—dunno about Linux. However you'll have to define the whole menu yourself, since you don't have info on the browser's one. Though it might possibly be easier and more performant to have websocket communication with the app—it means the app will have to stay open, but that's not much of a problem in this case. OTOH I'm not sure that browsers won't start blocking requests to localhost servers, after the privacy issues.
- DonHopkins 5y agoThat's in interesting approach. But my desire is to implement the rendering of the pie menus in the same browser that is popping up the pie menus. If it has to run in a separate app, then that app must embed its own separate browser than the one popping up the pie menus. Since it's a lot easier on the Mac to embed a Safari browser than a Chrome browser, it might be amusing to have Safari handling the pop-up pie menus of Chrome, but it wouldn't be the optimal solution of Chrome (or Safari or Firefox) drawing its own pie menus. Chrome's browser window extension api almost but not quite works for my purposes, and I wonder if or why it was a design decision not to make it more flexible. Security? Browser extensions, like clowns, can already get away with murder.
- aasasd 5y ago> implement the rendering of the pie menus in the same browser that is popping up the pie menus Eh, I'm pretty sure it's quite a bit easier and faster to draw a radial menu with proper drawing primitives, like in Hammerspoon's API. Gotta admit I have no idea why you'd want animated pics or videos in such a menu. Though Hammerspoon's docs say that the drawing API does ‘support’ GIFs in some way, dunno exactly how. As a bonus, you could then invoke those menus in apps other than the browser, though you'd need some access to the UI, like AppleScript or accessibility APIs—which are typically neglected in cross-platform UIs.