toggle fullscreen using xlib
来源:互联网 发布:windows 64 oracle sga 编辑:程序博客网 时间:2024/06/02 18:30
#include <X11/Xlib.h>
#include <stdlib.h>
enum
{
_NET_WM_STATE_REMOVE =0,
_NET_WM_STATE_ADD = 1,
_NET_WM_STATE_TOGGLE =2
};
int main()
{
Display * pDisplay = XOpenDisplay(NULL);
int screen = DefaultScreen(pDisplay);
XSetWindowAttributes attr;
attr.border_pixel = 0;
attr.background_pixel = 0;
attr.event_mask = ExposureMask | StructureNotifyMask;
Window parentWindow = RootWindow(pDisplay, screen);
Window window = XCreateWindow(pDisplay,
parentWindow,
0,0, //left top
640, 480,
0,
0,
InputOutput,
CopyFromParent,
CWBackPixel | CWBorderPixel |
CWEventMask,
&attr);
XWarpPointer(pDisplay, None, window, 0, 0, 0, 0, 100, 100);
XGrabKeyboard(pDisplay, window, True, GrabModeAsync, GrabModeAsync,
CurrentTime);
XMapRaised(pDisplay, window);
XSelectInput(pDisplay, window, KeyPressMask | ButtonPressMask);
bool isFullscreen = false;
bool run = true;
while (run)
{
XEvent event;
KeySym keySym;
while (XPending(pDisplay) > 0)
{
XNextEvent(pDisplay, &event);
switch(event.type)
{
case KeyPress:
{
isFullscreen = !isFullscreen;
Atom wmState = XInternAtom(pDisplay, "_NET_WM_STATE", False);
Atom fullScreen = XInternAtom(pDisplay,
"_NET_WM_STATE_FULLSCREEN", False);
XEvent xev;
xev.xclient.type=ClientMessage;
xev.xclient.serial = 0;
xev.xclient.send_event=True;
xev.xclient.window=window;
xev.xclient.message_type=wmState;
xev.xclient.format=32;
xev.xclient.data.l[0] = (isFullscreen ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE);
xev.xclient.data.l[1] = fullScreen;
xev.xclient.data.l[2] = 0;
XSendEvent(pDisplay, DefaultRootWindow(pDisplay), False,
SubstructureRedirectMask | SubstructureNotifyMask,
&xev);
break;
}
case ButtonPress:
{
run = false;
break;
}
default:
{
break;
}
}
}
}
XCloseDisplay(pDisplay);
}
#include <stdlib.h>
enum
{
_NET_WM_STATE_REMOVE =0,
_NET_WM_STATE_ADD = 1,
_NET_WM_STATE_TOGGLE =2
};
int main()
{
Display * pDisplay = XOpenDisplay(NULL);
int screen = DefaultScreen(pDisplay);
XSetWindowAttributes attr;
attr.border_pixel = 0;
attr.background_pixel = 0;
attr.event_mask = ExposureMask | StructureNotifyMask;
Window parentWindow = RootWindow(pDisplay, screen);
Window window = XCreateWindow(pDisplay,
parentWindow,
0,0, //left top
640, 480,
0,
0,
InputOutput,
CopyFromParent,
CWBackPixel | CWBorderPixel |
CWEventMask,
&attr);
XWarpPointer(pDisplay, None, window, 0, 0, 0, 0, 100, 100);
XGrabKeyboard(pDisplay, window, True, GrabModeAsync, GrabModeAsync,
CurrentTime);
XMapRaised(pDisplay, window);
XSelectInput(pDisplay, window, KeyPressMask | ButtonPressMask);
bool isFullscreen = false;
bool run = true;
while (run)
{
XEvent event;
KeySym keySym;
while (XPending(pDisplay) > 0)
{
XNextEvent(pDisplay, &event);
switch(event.type)
{
case KeyPress:
{
isFullscreen = !isFullscreen;
Atom wmState = XInternAtom(pDisplay, "_NET_WM_STATE", False);
Atom fullScreen = XInternAtom(pDisplay,
"_NET_WM_STATE_FULLSCREEN", False);
XEvent xev;
xev.xclient.type=ClientMessage;
xev.xclient.serial = 0;
xev.xclient.send_event=True;
xev.xclient.window=window;
xev.xclient.message_type=wmState;
xev.xclient.format=32;
xev.xclient.data.l[0] = (isFullscreen ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE);
xev.xclient.data.l[1] = fullScreen;
xev.xclient.data.l[2] = 0;
XSendEvent(pDisplay, DefaultRootWindow(pDisplay), False,
SubstructureRedirectMask | SubstructureNotifyMask,
&xev);
break;
}
case ButtonPress:
{
run = false;
break;
}
default:
{
break;
}
}
}
}
XCloseDisplay(pDisplay);
}
0
上一篇:Insight into GNU/Linux boot process
下一篇:NIC bonding with Ubuntu
相关热门文章
- linux 常见服务端口
- 【ROOTFS搭建】busybox的httpd...
- 什么是shell
- linux socket的bug??
- linux的线程是否受到了保护?...
- 关于enqueue 的dump 文件帮看...
- tar --newer 05/12/2013 这个...
- 请教nginx代理tomcat作为子目...
- LDAP安装 bus error是什么问...
- select语句不修改sql,如何优...
给主人留下些什么吧!~~
评论热议
- toggle fullscreen using xlib
- FullScreen
- FullScreen
- xlib
- Xlib
- Xlib
- Display fullscreen website using javascript (Internet Explorer/Safari/Chrome/Firefox)//
- toggle()
- Fullscreen API
- xlib入门
- xlib图形界面
- html5 video fullscreen and exit fullscreen
- Android fullscreen application
- JQuery js / Fullscreen.js
- (libgdx学习)Fullscreen&vsync
- 12 jQuery Fullscreen Plugins
- Android DialogFragment fullscreen 解决方法
- gvim fullscreen on startup
- Network anlysis tool wireshark
- how to analyze system crash(memory dump)of windows
- 对 Android 开发者有益的 40 条优化建议
- Insight into GNU/Linux boot process
- compile spice qxl driver for windows
- toggle fullscreen using xlib
- NIC bonding with Ubuntu
- gdb 高级技巧
- Resolve VNC and guest cursor are not consistence
- 【Sikuli】init: tessdata folder not found at C:/Program Files/Sikuli X
- Ubuntu字符编码
- lsof查看端口被哪些程式使用
- C++智能指针使用注意事项
- 链接静态库循环依赖解决方法
原创粉丝点击
热门IT博客