romgrk / node-gtk

GTK+ bindings for NodeJS (via GObject introspection)
MIT License
494 stars 42 forks source link

Unable to close applications with "Cmd+Q" on macOS #299

Closed mirukuma closed 3 years ago

mirukuma commented 3 years ago

We found that the code below is unable to close applications with Cmd+Q on macOS Big Sur 11.4. We haven't been able to determine why it's not working, but at least setAccelsForAction seems to be working correctly. (For example, if you set it to <Primary>+K, it will also switch the menu bar display.)

const gi = require('node-gtk');
const Gtk = gi.require('Gtk', '3.0');
const Gio = gi.require('Gio', '2.0');

Gtk.init();
gi.startLoop();

const win = new Gtk.Window();
win.on('destroy', process.exit);

const app = new Gtk.Application();
app.register();

const quit = Gio.SimpleAction.new('quit', null);
app.setAccelsForAction('app.quit', ['<Primary>Q']);
quit.connect('activate', process.exit);
app.addAction(quit);

win.showAll();
Gtk.main();
romgrk commented 3 years ago

I don't have access to a macOS so I can't debug, but you're saying that all shortcuts work except Cmd+Q? Is it bound to a system action by default?

mirukuma commented 3 years ago

All shortcuts are not working, and it's usually bound to Quit. Also, we found that Cmd+Q works when the AppMenu is focused like below.

Screen Shot 2021-06-09 at 6 00 51
romgrk commented 3 years ago

Oh but your Window and Application are not linked, are they? You probably need to use new Gtk.ApplicationWindow(app) instead of new Gtk.Window().

mirukuma commented 3 years ago

hmm... Using Gtk.ApplicationWindow(app) instead like below didn't solve the problem...

const gi = require('node-gtk');
const Gtk = gi.require('Gtk', '3.0');
const Gio = gi.require('Gio', '2.0');

Gtk.init();
gi.startLoop();

const app = new Gtk.Application();
app.register();
const quit = Gio.SimpleAction.new('quit', null);
app.setAccelsForAction('app.quit', ['<Primary>Q']);
quit.connect('activate', process.exit);
app.addAction(quit);

const win = new Gtk.ApplicationWindow(app);
win.on('destroy', process.exit);

win.showAll();
Gtk.main();
romgrk commented 3 years ago

Do you have a C or python example of what you're trying to do? GTK documentation will be a better resource for this.

mirukuma commented 3 years ago

Compared to Python code, we found using Gtk.ApplicationWindow.new(app) instead of new Gtk.ApplicationWindow(app) can solve the problem. Thanks for your help!

romgrk commented 3 years ago

Cool :)