Skip to content
This repository
Browse code

modified: hello_win.c

	modified:   xnotify.c
  • Loading branch information...
commit 511722be9b22efc1920976c5d871426442434b4f 1 parent 3f4b862
mos authored

Showing 2 changed files with 56 additions and 10 deletions. Show diff stats Hide diff stats

  1. +43 9 hello_win.c
  2. +13 1 xnotify.c
52 hello_win.c
... ... @@ -1,16 +1,21 @@
1 1 #include <stdio.h>
2   -/*#include <string.h>
3   -#include <stdlib.h>*/
4 2 #include <unistd.h> /* for sleep() */
5 3 #include <X11/Xlib.h>
6 4 #include <X11/Xutil.h>
7   -/*#include <X11/Xos.h>
8   -#include <X11/Xatom.h>*/
  5 +#include <string.h>
9 6
10 7 #define WIN_TITLE "test_programme"
11 8 #define WIN_NAME "TEST"
12 9 #define WIN_CLASS "test"
13 10
  11 +//char* font_name = "*-helvetica-*-12-*";
  12 +char* font_name = "9x15";
  13 +
  14 +XFontStruct* font_info;
  15 +XGCValues values;
  16 +GC gc;
  17 +XEvent report;
  18 +
14 19
15 20 int main(int argc, char *argv[])
16 21 {
@@ -21,7 +26,12 @@ int main(int argc, char *argv[])
21 26 printf("Unable to open display\n");
22 27 return 1;
23 28 }
24   -
  29 +
  30 + font_info = XLoadQueryFont(display, font_name);
  31 + if (!font_info) {
  32 + fprintf(stderr, "XLoadQueryFont: failed loading font '%s'\n", font_name);
  33 + }
  34 +
25 35 XClassHint class_hint;
26 36 XSizeHints *size_hints;
27 37 size_hints = XAllocSizeHints();
@@ -29,7 +39,7 @@ int main(int argc, char *argv[])
29 39 wm_hints = XAllocWMHints();
30 40
31 41
32   -
  42 +
33 43
34 44 int black_color = BlackPixel(display, DefaultScreen(display));
35 45 int white_color = WhitePixel(display, DefaultScreen(display));
@@ -46,6 +56,11 @@ int main(int argc, char *argv[])
46 56 );
47 57 XStoreName(display, window, WIN_TITLE);
48 58
  59 + gc = XCreateGC(display, window, 0, &values);
  60 +
  61 + XSetFont(display, gc, font_info->fid);
  62 + XSetForeground(display, gc, black_color);
  63 +
49 64 class_hint.res_name = WIN_NAME;
50 65 class_hint.res_class = WIN_CLASS;
51 66
@@ -57,13 +72,32 @@ int main(int argc, char *argv[])
57 72 size_hints->min_height = 300;
58 73
59 74 XSetWMNormalHints(display, window, size_hints);
60   -
  75 +
  76 + XSelectInput(display, window, ExposureMask);
  77 +
61 78 XMapWindow(display, window);
62 79 XFlush(display);
63 80
64 81 while(1) {
65   - sleep(1);
66   - printf("nextstepi\n");
  82 + static char *text = "Hello, Ryan";
  83 + static int txt_length;
  84 + static int font_height;
  85 + static int txt_x_pos,txt_y_pos;
  86 +
  87 + XNextEvent(display, &report);
  88 +
  89 + switch ( report.type ) {
  90 +
  91 + case Expose:
  92 + if ( report.xexpose.count != 0 )
  93 + break;
  94 +
  95 + txt_length = XTextWidth(font_info, text, strlen(text));
  96 +
  97 + XDrawString(display, window, gc, 100, 100, "hello ryan",
  98 + strlen("hello ryan"));
  99 + break;
  100 + }
67 101 }
68 102 return 0;
69 103 }
14 xnotify.c
@@ -324,6 +324,7 @@ static void init_and_start_ev_loop(int xfd)
324 324 void display_window()
325 325 {
326 326 XClassHint class_hint;
  327 + XSizeHints *size_hints;
327 328
328 329 int black_color = BlackPixel(X.display, X.screen);
329 330 int white_color = WhitePixel(X.display, X.screen);
@@ -338,10 +339,21 @@ void display_window()
338 339 , 35
339 340 , white_color
340 341 );
341   - XStoreName(X.display, window, "title");
  342 + XStoreName(X.display, window, "test_programme");
342 343 class_hint.res_name = "test";
343 344 class_hint.res_class = "test";
344 345 XSetClassHint(X.display, window, &class_hint);
  346 +
  347 +
  348 +
  349 + size_hints = XAllocSizeHints();
  350 + size_hints->flags = PPosition | PSize | PMinSize;
  351 + size_hints->min_width = WINDOW_WIDTH;
  352 + size_hints->min_height = WINDOW_HEIGHT;
  353 + XSetWMNormalHints(X.display, window, size_hints);
  354 +
  355 +
  356 +
345 357 XMapWindow(X.display, window);
346 358 XFlush(X.display);
347 359 }

0 comments on commit 511722b

Please sign in to comment.
Something went wrong with that request. Please try again.