A Simple X Image Viewer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

88 lines
2.1 KiB

  1. /* sxiv: window.c
  2. * Copyright (c) 2011 Bert Muennich <muennich at informatik.hu-berlin.de>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. */
  18. #include <stdlib.h>
  19. #include <stdio.h>
  20. #include <X11/Xutil.h>
  21. #include "sxiv.h"
  22. #include "window.h"
  23. Display *dpy;
  24. int scr;
  25. int scrw, scrh;
  26. GC gc;
  27. XColor bgcol;
  28. void win_open(win_t *win) {
  29. XClassHint *classhint;
  30. if (win == NULL)
  31. return;
  32. if (!(dpy = XOpenDisplay(NULL)))
  33. FATAL("could not open display");
  34. scr = DefaultScreen(dpy);
  35. scrw = DisplayWidth(dpy, scr);
  36. scrh = DisplayHeight(dpy, scr);
  37. bgcol.red = 0x7000;
  38. bgcol.green = 0x7000;
  39. bgcol.blue = 0x7000;
  40. XAllocColor(dpy, DefaultColormap(dpy, scr), &bgcol);
  41. if (win->w > scrw)
  42. win->w = scrw;
  43. if (win->h > scrh)
  44. win->h = scrh;
  45. win->x = (scrw - win->w) / 2;
  46. win->y = (scrh - win->h) / 2;
  47. win->xwin = XCreateWindow(dpy, RootWindow(dpy, scr),
  48. win->x, win->y, win->w, win->h, 0, DefaultDepth(dpy, scr), InputOutput,
  49. DefaultVisual(dpy, scr), 0, NULL);
  50. if (win->xwin == None)
  51. FATAL("could not create window");
  52. XSelectInput(dpy, win->xwin,
  53. StructureNotifyMask | ExposureMask | KeyPressMask);
  54. gc = XCreateGC(dpy, win->xwin, 0, NULL);
  55. if ((classhint = XAllocClassHint())) {
  56. classhint->res_name = "sxvi";
  57. classhint->res_class = "sxvi";
  58. XSetClassHint(dpy, win->xwin, classhint);
  59. XFree(classhint);
  60. }
  61. XMapWindow(dpy, win->xwin);
  62. XFlush(dpy);
  63. }
  64. void win_close(win_t *win) {
  65. if (win == NULL)
  66. return;
  67. XDestroyWindow(dpy, win->xwin);
  68. XFreeGC(dpy, gc);
  69. XCloseDisplay(dpy);
  70. }