Chinaunix首页 | 论坛 | 博客
  • 博客访问: 346128
  • 博文数量: 135
  • 博客积分: 4637
  • 博客等级: 上校
  • 技术积分: 1410
  • 用 户 组: 普通用户
  • 注册时间: 2008-02-21 13:22
文章分类

全部博文(135)

文章存档

2013年(12)

2012年(14)

2011年(42)

2010年(22)

2009年(18)

2008年(27)

分类: LINUX

2010-03-31 13:36:53

#include
#include

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);

}

阅读(782) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~