Skip to content

Commit

Permalink
modified: hello_win.c
Browse files Browse the repository at this point in the history
	modified:   xnotify.c
  • Loading branch information
mos committed Jun 18, 2008
1 parent 3f4b862 commit 511722b
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 10 deletions.
52 changes: 43 additions & 9 deletions hello_win.c
@@ -1,16 +1,21 @@
#include <stdio.h>
/*#include <string.h>
#include <stdlib.h>*/
#include <unistd.h> /* for sleep() */
#include <X11/Xlib.h>
#include <X11/Xutil.h>
/*#include <X11/Xos.h>
#include <X11/Xatom.h>*/
#include <string.h>

#define WIN_TITLE "test_programme"
#define WIN_NAME "TEST"
#define WIN_CLASS "test"

//char* font_name = "*-helvetica-*-12-*";
char* font_name = "9x15";

XFontStruct* font_info;
XGCValues values;
GC gc;
XEvent report;


int main(int argc, char *argv[])
{
Expand All @@ -21,15 +26,20 @@ int main(int argc, char *argv[])
printf("Unable to open display\n");
return 1;
}


font_info = XLoadQueryFont(display, font_name);
if (!font_info) {
fprintf(stderr, "XLoadQueryFont: failed loading font '%s'\n", font_name);
}

XClassHint class_hint;
XSizeHints *size_hints;
size_hints = XAllocSizeHints();
XWMHints *wm_hints;
wm_hints = XAllocWMHints();




int black_color = BlackPixel(display, DefaultScreen(display));
int white_color = WhitePixel(display, DefaultScreen(display));
Expand All @@ -46,6 +56,11 @@ int main(int argc, char *argv[])
);
XStoreName(display, window, WIN_TITLE);

gc = XCreateGC(display, window, 0, &values);

XSetFont(display, gc, font_info->fid);
XSetForeground(display, gc, black_color);

class_hint.res_name = WIN_NAME;
class_hint.res_class = WIN_CLASS;

Expand All @@ -57,13 +72,32 @@ int main(int argc, char *argv[])
size_hints->min_height = 300;

XSetWMNormalHints(display, window, size_hints);


XSelectInput(display, window, ExposureMask);

XMapWindow(display, window);
XFlush(display);

while(1) {
sleep(1);
printf("nextstepi\n");
static char *text = "Hello, Ryan";
static int txt_length;
static int font_height;
static int txt_x_pos,txt_y_pos;

XNextEvent(display, &report);

switch ( report.type ) {

case Expose:
if ( report.xexpose.count != 0 )
break;

txt_length = XTextWidth(font_info, text, strlen(text));

XDrawString(display, window, gc, 100, 100, "hello ryan",
strlen("hello ryan"));
break;
}
}
return 0;
}
14 changes: 13 additions & 1 deletion xnotify.c
Expand Up @@ -324,6 +324,7 @@ static void init_and_start_ev_loop(int xfd)
void display_window()
{
XClassHint class_hint;
XSizeHints *size_hints;

int black_color = BlackPixel(X.display, X.screen);
int white_color = WhitePixel(X.display, X.screen);
Expand All @@ -338,10 +339,21 @@ void display_window()
, 35
, white_color
);
XStoreName(X.display, window, "title");
XStoreName(X.display, window, "test_programme");
class_hint.res_name = "test";
class_hint.res_class = "test";
XSetClassHint(X.display, window, &class_hint);



size_hints = XAllocSizeHints();
size_hints->flags = PPosition | PSize | PMinSize;
size_hints->min_width = WINDOW_WIDTH;
size_hints->min_height = WINDOW_HEIGHT;
XSetWMNormalHints(X.display, window, size_hints);



XMapWindow(X.display, window);
XFlush(X.display);
}
Expand Down

0 comments on commit 511722b

Please sign in to comment.