All pastes #393265 Raw Edit

Stuff

public text v1 · immutable
·published 2007-03-13 12:24 UTC
rendered paste body
$ cat 2.cpp
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include <stdio.h>
#include <string.h>

#define X 0
#define Y 0
#define WIDTH 1024
#define HEIGHT 768
#define WIDTH_MIN 1024
#define HEIGHT_MIN 768
#define BORDER_WIDTH 0

int main(int argc, char *argv[])
{
    Display * display;  /* &#1059;&#1082;&#1072;&#1079;&#1072;&#1090;&#1077;&#1083;&#1100; &#1085;&#1072; &#1089;&#1090;&#1088;&#1091;&#1082;&#1090;&#1091;&#1088;&#1091; Display */
    int ScreenNumber;    /* &#1053;&#1086;&#1084;&#1077;&#1088; &#1101;&#1082;&#1088;&#1072;&#1085;&#1072; */
    GC gc;                              /* &#1043;&#1088;&#1072;&#1092;&#1080;&#1095;&#1077;&#1089;&#1082;&#1080;&#1081; &#1082;&#1086;&#1085;&#1090;&#1077;&#1082;&#1089;&#1090; */
    XEvent report;
    Window window;

    /* &#1059;&#1089;&#1090;&#1072;&#1085;&#1072;&#1074;&#1083;&#1080;&#1074;&#1072;&#1077;&#1084; &#1089;&#1074;&#1103;&#1079;&#1100; &#1089; &#1089;&#1077;&#1088;&#1074;&#1077;&#1088;&#1086;&#1084; */
    if ( ( display = XOpenDisplay ( NULL ) ) == NULL )
    {
        puts ("Can not connect to the X server!\n");
        return 1;
    }

    /* &#1055;&#1086;&#1083;&#1091;&#1095;&#1072;&#1077;&#1084; &#1085;&#1086;&#1084;&#1077;&#1088; &#1086;&#1089;&#1085;&#1086;&#1074;&#1085;&#1086;&#1075;&#1086; &#1101;&#1082;&#1088;&#1072;&#1085;&#1072; */
    ScreenNumber = DefaultScreen ( display );

    /* &#1057;&#1086;&#1079;&#1076;&#1072;&#1077;&#1084; &#1086;&#1082;&#1085;&#1086; */
    window = XCreateSimpleWindow ( display,
                                   RootWindow ( display, ScreenNumber ),
                                   X, Y, WIDTH, HEIGHT, BORDER_WIDTH,
                                   BlackPixel ( display, ScreenNumber ),
                                   WhitePixel ( display, ScreenNumber ) );

    /* &#1042;&#1099;&#1073;&#1080;&#1088;&#1072;&#1077;&#1084; &#1089;&#1086;&#1073;&#1099;&#1090;&#1080;&#1103;,  &#1082;&#1086;&#1090;&#1086;&#1088;&#1099;&#1077; &#1073;&#1091;&#1076;&#1077;&#1090; &#1086;&#1073;&#1088;&#1072;&#1073;&#1072;&#1090;&#1099;&#1074;&#1072;&#1090;&#1100; &#1087;&#1088;&#1086;&#1075;&#1088;&#1072;&#1084;&#1084;&#1072; */
    XSelectInput ( display, window, KeyPressMask );

    /* &#1055;&#1086;&#1082;&#1072;&#1078;&#1077;&#1084; &#1086;&#1082;&#1085;&#1086; */
    XMapWindow ( display, window );

    // &#1088;&#1072;&#1079;&#1074;&#1077;&#1088;&#1085;&#1077;&#1084; &#1077;&#1075;&#1086; &#1085;&#1072; &#1074;&#1077;&#1089;&#1100; &#1101;&#1082;&#1088;&#1072;&#1085;
    Atom wmState = XInternAtom(display, "_NET_WM_STATE", false);
    Atom atfullScreen = XInternAtom(display,"_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] = 1;//add
    xev.xclient.data.l[1] = atfullScreen;
    xev.xclient.data.l[2] = 0;

    XSendEvent(display, DefaultRootWindow(display), false,
               SubstructureRedirectMask | SubstructureNotifyMask, &xev);

    XMoveResizeWindow(display, window, 0,0,WIDTH,HEIGHT);

    //&#1057;&#1087;&#1088;&#1103;&#1095;&#1077;&#1084; &#1082;&#1091;&#1088;&#1089;&#1086;&#1088; &#1084;&#1099;&#1096;&#1080;
    Pixmap bm_no;
    Colormap cmap;
    Cursor no_ptr;
    XColor black, dummy;
    static char bm_no_data[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

    cmap = DefaultColormap(display, DefaultScreen(display));
    XAllocNamedColor(display, cmap, "black", &black, &dummy);
    bm_no = XCreateBitmapFromData(display, window, bm_no_data, 8, 8);
    no_ptr = XCreatePixmapCursor(display, bm_no, bm_no, &black, &black, 0, 0);

    XDefineCursor(display, window, no_ptr);
    XFreeCursor(display, no_ptr);
    if (bm_no != None)
        XFreePixmap(display, bm_no);
    XFreeColors(display, cmap, &black.pixel, 1, 0);

    /* &#1057;&#1086;&#1079;&#1076;&#1072;&#1076;&#1080;&#1084; &#1094;&#1080;&#1082;&#1083; &#1087;&#1086;&#1083;&#1091;&#1095;&#1077;&#1085;&#1080;&#1103; &#1080; &#1086;&#1073;&#1088;&#1072;&#1073;&#1086;&#1090;&#1082;&#1080; &#1086;&#1096;&#1080;&#1073;&#1086;&#1082; */
    while ( 1 )
    {
        XNextEvent ( display, &report );

        switch ( report.type )
        {
        case KeyPress :
            /* &#1042;&#1099;&#1093;&#1086;&#1076; &#1085;&#1072;&#1078;&#1072;&#1090;&#1080;&#1077;&#1084; &#1082;&#1083;&#1072;&#1074;&#1080;&#1096;&#1080; &#1082;&#1083;&#1072;&#1074;&#1080;&#1072;&#1090;&#1091;&#1088;&#1099; */

            XCloseDisplay ( display );
            return 0;
        }
    }
}


&#1050;&#1086;&#1084;&#1087;&#1080;&#1083;&#1103;&#1077;&#1084;:
g++ 2.cpp -lX11 -lXrender -lXau -lXdmcp -ldl -lpthread -static

&#1074; &#1088;&#1077;&#1079;&#1091;&#1083;&#1100;&#1090;&#1072;&#1090;&#1077; &#1087;&#1086;&#1089;&#1083;&#1077; &#1074;&#1099;&#1093;&#1086;&#1076;&#1072; &#1087;&#1086; &#1085;&#1072;&#1078;&#1072;&#1090;&#1080;&#1102; &#1082;&#1083;&#1072;&#1074;&#1080;&#1096;&#1080;:
$ ./a.out 
*** glibc detected *** double free or corruption (out): 0xb7c4a1c0 ***
Aborted

&#1082;&#1086;&#1084;&#1087;&#1080;&#1083;&#1103;&#1077;&#1084;:
$ g++ 2.cpp -lX11 -lXrender -lXau -lXdmcp -ldl -lpthread        
$ ./a.out 
$