PageRenderTime 428ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/project-wizard/templates/xlib/src/main.c

https://github.com/abderrahim/anjuta
C | 78 lines | 59 code | 6 blank | 13 comment | 0 complexity | a8fc6f1a9bc7c6b3f2a4e2c21470d15a MD5 | raw file
Possible License(s): GPL-2.0
  1. [+ autogen5 template +]
  2. /*
  3. * main.c
  4. * Copyright (C) [+Author+] [+(shell "date +%Y")+] <[+Email+]>
  5. *
  6. [+CASE (get "License") +]
  7. [+ == "BSD" +][+(bsd (get "Name") (get "Author") "\t")+]
  8. [+ == "LGPL" +][+(lgpl (get "Name") (get "Author") "\t")+]
  9. [+ == "GPL" +][+(gpl (get "Name") "\t")+]
  10. [+ESAC+] */
  11. /*Program closes with a mouse click or keypress */
  12. #ifdef HAVE_CONFIG_H
  13. # include <config.h>
  14. #endif
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <X11/Xlib.h>
  18. int main (int argc, char *argv[])
  19. {
  20. Display *dpy;
  21. Visual *visual;
  22. int depth;
  23. XSetWindowAttributes attributes;
  24. Window win;
  25. XFontStruct *fontinfo;
  26. XColor color, dummy;
  27. XGCValues gr_values;
  28. GC gc;
  29. XKeyEvent event;
  30. dpy = XOpenDisplay(NULL);
  31. visual = DefaultVisual(dpy, 0);
  32. depth = DefaultDepth(dpy, 0);
  33. attributes.background_pixel = XWhitePixel(dpy, 0);
  34. /* create the application window */
  35. win = XCreateWindow(dpy, XRootWindow(dpy, 0),
  36. 50, 50, 400, 400, 5, depth,
  37. InputOutput, visual, CWBackPixel,
  38. &attributes);
  39. XSelectInput(dpy, win, ExposureMask | KeyPressMask |
  40. ButtonPressMask | StructureNotifyMask);
  41. fontinfo = XLoadQueryFont(dpy, "6x10");
  42. XAllocNamedColor(dpy, DefaultColormap(dpy, 0),
  43. "green", &color, &dummy);
  44. gr_values.font = fontinfo->fid;
  45. gr_values.foreground = color.pixel;
  46. gc = XCreateGC(dpy, win, GCFont+GCForeground, &gr_values);
  47. XMapWindow(dpy, win);
  48. /* run till key press */
  49. while(1){
  50. XNextEvent(dpy, (XEvent *)&event);
  51. switch(event.type) {
  52. case Expose:
  53. XDrawLine(dpy, win, gc, 0, 0, 100, 100);
  54. XDrawRectangle(dpy, win, gc, 140, 140, 50, 50);
  55. XDrawString(dpy, win, gc, 100, 100, "hello X world", 13);
  56. break;
  57. case ButtonPress:
  58. case KeyPress:
  59. XUnloadFont(dpy, fontinfo->fid);
  60. XFreeGC(dpy, gc);
  61. XCloseDisplay(dpy);
  62. exit(0);
  63. break;
  64. case ConfigureNotify:
  65. /* reconfigure size of window here */
  66. break;
  67. default:
  68. break;
  69. }
  70. }
  71. return(0);
  72. }