我正在尝试在 gtk3 中为我的应用实现加速器。我从 github 上的一篇文章中找到了如何做到这一点。
#include <stdio.h>
#include <gtk/gtk.h>
// This is a callback that will be called when the accelerator is
// pressed.
void accelerator_pressed(void)
{
printf("accelerator_pressed\n");
}
int main(int argc, char** argv)
{
gtk_init(&argc, &argv);
GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
GClosure* closure = g_cclosure_new(accelerator_pressed, 0, 0);
// Set up the accelerator group.
GtkAccelGroup* accel_group = gtk_accel_group_new();
gtk_accel_group_connect(accel_group,
GDK_KEY_A,
GDK_CONTROL_MASK,
0,
closure);
gtk_window_add_accel_group(GTK_WINDOW(window), accel_group);
// Quit the app when the window is closed.
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
// Display the top level window.
gtk_widget_show(window);
gtk_main();
return 0;
}
我的问题是如何在不创建窗口的情况下实现它。