如何使用xlib监听Linux上的屏幕分辨率更改
发布时间:2020-12-25 22:50:26 所属栏目:Linux 来源:网络整理
导读:我正在写一个小的本地例程来通知另一个进程用户已经改变了屏幕分辨率.我尝试使用gtk但它在非复合窗口管理器上不稳定并经常崩溃.我正在研究xlib并有一个示例工作,当生成的X Window的大小发生变化时通知我,但我无法弄清楚如何通知屏幕分辨率已经改变.任何帮
我正在写一个小的本地例程来通知另一个进程用户已经改变了屏幕分辨率.我尝试使用gtk但它在非复合窗口管理器上不稳定并经常崩溃.我正在研究xlib并有一个示例工作,当生成的X Window的大小发生变化时通知我,但我无法弄清楚如何通知屏幕分辨率已经改变.任何帮助,将不胜感激.我包含了我的xlib测试代码和gtk测试代码,当使用非复合窗口管理器时,这些代码崩溃了很多. 这是我使用xlib的测试代码 Display * display; int screen; Window root,window; display = XOpenDisplay (NULL); if (!display){ syslog(LOG_INFO,"Could not open display.n"); } screen = DefaultScreen(display); root = RootWindow(display,screen); window = XCreateSimpleWindow (display,root,300,// xpos,ypos,width,height 0,// border width,border pixel 0 /* background */); // Add StructureNotifyMask to send us events involving resizing of the window,etc. XSelectInput (display,window,ExposureMask | StructureNotifyMask); XMapWindow (display,window); while (1){ XEvent e; XNextEvent (display,&e); // Respond to ConfigureNotify,the type of event sent by the // server if the window is resized. if (e.type == ConfigureNotify){ XConfigureEvent xce = e.xconfigure; /* This event type is generated for a variety of happenings,so check whether the window has been resized. */ syslog(LOG_INFO,"New Width,Height %d,%d",xce.width,xce.height); } } 使用GTK测试代码 GtkWidget *window; GdkScreen *screen; screen = gdk_screen_get_default(); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); syslog(LOG_INFO,"NATIVESUPPORT: startDisplayChangedEventThread(): screen and window objects created.n"); if (!screen){ syslog(LOG_INFO,"NATIVESUPPORT: screen is null."); } if (!window){ syslog(LOG_INFO,"NATIVESUPPORT: window is null."); } g_signal_connect(screen,"size-changed",G_CALLBACK(resize_cb),(gpointer)window); g_signal_connect(screen,"monitors-changed",(gpointer)window); syslog(LOG_INFO,"NATIVESUPPORT: startDisplayChangedEventThread(): call back created.n"); syslog(LOG_INFO,"NATIVESUPPORT: startDisplayChangedEventThread(): starting main.n"); gtk_main(); 解决方法解决方案是映射到默认的根窗口.display = XOpenDisplay (NULL); if (!display) { syslog(LOG_INFO,"Could not open display.n"); } screen = DefaultScreen (display); root = RootWindow (display,screen); window = DefaultRootWindow( display ); if ( 0 > window ) { syslog(LOG_INFO,"Failed to obtain the root windows Id of the default screen of given display.n"); } Status ret = XGetWindowAttributes( display,&xwAttr ); width = xwAttr.width; height = xwAttr.height; XSelectInput (display,ExposureMask | /* Add StructureNotifyMask to send us events involving resizing of the window,etc. */ StructureNotifyMask); XMapWindow (display,window); (编辑:开发网_郴州站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- pthreads:以编程方式收集有关在不同状态上花费的时间的信息
- 如何搭建自己的可引导 Linux Live CD
- Linux入门基础(七) Linux权限机制
- linux – pthread_create():什么是默认优先级和shceduling
- Linux大文件重定向与管道的效率是怎样的
- red hat enterprise 5.4下安装mysql 5.6.10
- 我的linux服务器需要一个多小时才能启动.建议?
- linux – Jenkins可以根据代理操作系统有条件地执行shell或
- java.net.ProtocolException:unexpected end of stream
- linux定时任务之crontab
站长推荐
热点阅读