gpt4 book ai didi

c - Gtk 不检测全屏或非全屏窗口

转载 作者:太空宇宙 更新时间:2023-11-04 03:21:30 26 4
gpt4 key购买 nike

这是我的项目的一部分……我对全屏功能有疑问:

#include "header.h"

gboolean my_gtk_key_press_event(GtkWidget *widget, GdkEventKey *event, gpointer data)
{
GdkWindow *window = gtk_widget_get_window(widget);

GdkWindowState state = gdk_window_get_state(GDK_WINDOW(window));

switch(event->keyval) {
case GDK_KEY_F11:
if(state == GDK_WINDOW_STATE_FULLSCREEN) {
gtk_window_unfullscreen(GTK_WINDOW(widget));
}
else {
gtk_window_fullscreen(GTK_WINDOW(widget));
}

printf("win_state %d\n", state);
printf("gdk_state %d\n", GDK_WINDOW_STATE_FULLSCREEN);

break;
case GDK_KEY_Escape:
destroy(NULL, NULL);
break;
}
}

int main(int argc, char **argv)
{
GtkWidget *win;
char *s = "In progress";

gtk_init(&argc, &argv);

win = win_principal(win, s, 600, 400, 10);

g_signal_connect(G_OBJECT(win), "key-press-event", G_CALLBACK(my_gtk_key_press_event), NULL);

g_signal_connect(G_OBJECT(win), "destroy", G_CALLBACK(destroy), NULL);

gtk_widget_show_all(win);

gtk_main();

return 0;
}

非全屏显示 128 而全屏显示 144而 GDK_WINDOW_STATE_FULLSCREEN 的值等于 16 ...我怎么解决这个问题?或者哪里出了问题?

最佳答案

GDK_WINDOW_STATE_FULLSCREEN 是一个位标志,因此,您不能直接比较状态,而是进行按位运算。

改变:

if (state == GDK_WINDOW_STATE_FULLSCREEN)

收件人:

if (state & GDK_WINDOW_STATE_FULLSCREEN)

这是你的代码,没有依赖:

#include <gtk/gtk.h>

gboolean my_gtk_key_press_event(GtkWidget *widget, GdkEventKey *event, gpointer data)
{
GdkWindow *window = gtk_widget_get_window(widget);

GdkWindowState state = gdk_window_get_state(GDK_WINDOW(window));

switch(event->keyval) {
case GDK_KEY_F11:
if (state & GDK_WINDOW_STATE_FULLSCREEN) {
gtk_window_unfullscreen(GTK_WINDOW(widget));
}
else {
gtk_window_fullscreen(GTK_WINDOW(widget));
}
break;
case GDK_KEY_Escape:
gtk_main_quit ();
break;
}
}

int main(int argc, char **argv)
{
GtkWidget *win;
char *s = "In progress";

gtk_init(&argc, &argv);

//win = win_principal(win, s, 600, 400, 10);
win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size (GTK_WINDOW(win), 640, 400);

g_signal_connect(G_OBJECT(win), "key-press-event", G_CALLBACK(my_gtk_key_press_event), win);

g_signal_connect(G_OBJECT(win), "destroy", G_CALLBACK(gtk_main_quit), NULL);

gtk_widget_show_all(win);

gtk_main();

return 0;
}

编译:

gcc -o window window.c `pkg-config --cflags --libs gtk+-3.0`

窗口将通过 F11 切换全屏并通过 Esc 关闭。

关于c - Gtk 不检测全屏或非全屏窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45634452/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com