Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
37
Task/Window-creation-X11/C/window-creation-x11-1.c
Normal file
37
Task/Window-creation-X11/C/window-creation-x11-1.c
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
#include <X11/Xlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(void) {
|
||||
Display *d;
|
||||
Window w;
|
||||
XEvent e;
|
||||
const char *msg = "Hello, World!";
|
||||
int s;
|
||||
|
||||
d = XOpenDisplay(NULL);
|
||||
if (d == NULL) {
|
||||
fprintf(stderr, "Cannot open display\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
s = DefaultScreen(d);
|
||||
w = XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 100, 100, 1,
|
||||
BlackPixel(d, s), WhitePixel(d, s));
|
||||
XSelectInput(d, w, ExposureMask | KeyPressMask);
|
||||
XMapWindow(d, w);
|
||||
|
||||
while (1) {
|
||||
XNextEvent(d, &e);
|
||||
if (e.type == Expose) {
|
||||
XFillRectangle(d, w, DefaultGC(d, s), 20, 20, 10, 10);
|
||||
XDrawString(d, w, DefaultGC(d, s), 10, 50, msg, strlen(msg));
|
||||
}
|
||||
if (e.type == KeyPress)
|
||||
break;
|
||||
}
|
||||
|
||||
XCloseDisplay(d);
|
||||
return 0;
|
||||
}
|
||||
83
Task/Window-creation-X11/C/window-creation-x11-2.c
Normal file
83
Task/Window-creation-X11/C/window-creation-x11-2.c
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <xcb/xcb.h>
|
||||
|
||||
int main ()
|
||||
{
|
||||
xcb_connection_t *c;
|
||||
xcb_screen_t *screen;
|
||||
xcb_drawable_t win;
|
||||
xcb_gcontext_t foreground;
|
||||
xcb_gcontext_t background;
|
||||
xcb_generic_event_t *e;
|
||||
uint32_t mask = 0;
|
||||
uint32_t values[2];
|
||||
|
||||
char string[] = "Hello, XCB!";
|
||||
uint8_t string_len = strlen(string);
|
||||
|
||||
xcb_rectangle_t rectangles[] = {
|
||||
{40, 40, 20, 20},
|
||||
};
|
||||
|
||||
c = xcb_connect (NULL, NULL);
|
||||
|
||||
/* get the first screen */
|
||||
screen = xcb_setup_roots_iterator (xcb_get_setup (c)).data;
|
||||
|
||||
/* root window */
|
||||
win = screen->root;
|
||||
|
||||
/* create black (foreground) graphic context */
|
||||
foreground = xcb_generate_id (c);
|
||||
mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES;
|
||||
values[0] = screen->black_pixel;
|
||||
values[1] = 0;
|
||||
xcb_create_gc (c, foreground, win, mask, values);
|
||||
|
||||
/* create white (background) graphic context */
|
||||
background = xcb_generate_id (c);
|
||||
mask = XCB_GC_BACKGROUND | XCB_GC_GRAPHICS_EXPOSURES;
|
||||
values[0] = screen->white_pixel;
|
||||
values[1] = 0;
|
||||
xcb_create_gc (c, background, win, mask, values);
|
||||
|
||||
/* create the window */
|
||||
win = xcb_generate_id(c);
|
||||
mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
|
||||
values[0] = screen->white_pixel;
|
||||
values[1] = XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_KEY_PRESS;
|
||||
xcb_create_window (c, /* connection */
|
||||
XCB_COPY_FROM_PARENT, /* depth */
|
||||
win, /* window Id */
|
||||
screen->root, /* parent window */
|
||||
0, 0, /* x, y */
|
||||
150, 150, /* width, height */
|
||||
10, /* border_width */
|
||||
XCB_WINDOW_CLASS_INPUT_OUTPUT, /* class */
|
||||
screen->root_visual, /* visual */
|
||||
mask, values); /* masks */
|
||||
|
||||
/* map the window on the screen */
|
||||
xcb_map_window (c, win);
|
||||
|
||||
xcb_flush (c);
|
||||
|
||||
while ((e = xcb_wait_for_event (c))) {
|
||||
switch (e->response_type & ~0x80) {
|
||||
case XCB_EXPOSE:
|
||||
xcb_poly_rectangle (c, win, foreground, 1, rectangles);
|
||||
xcb_image_text_8 (c, string_len, win, background, 20, 20, string);
|
||||
xcb_flush (c);
|
||||
break;
|
||||
case XCB_KEY_PRESS:
|
||||
goto endloop;
|
||||
}
|
||||
free (e);
|
||||
}
|
||||
endloop:
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue