A Simple X Image Viewer
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

103 rindas
2.5 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. if (!XAllocNamedColor(dpy, DefaultColormap(dpy, scr), BG_COLOR,
  38. &bgcol, &bgcol))
  39. FATAL("could not allocate color: %s", BG_COLOR);
  40. if (win->w > scrw)
  41. win->w = scrw;
  42. if (win->h > scrh)
  43. win->h = scrh;
  44. win->x = (scrw - win->w) / 2;
  45. win->y = (scrh - win->h) / 2;
  46. win->xwin = XCreateWindow(dpy, RootWindow(dpy, scr),
  47. win->x, win->y, win->w, win->h, 0, DefaultDepth(dpy, scr), InputOutput,
  48. DefaultVisual(dpy, scr), 0, NULL);
  49. if (win->xwin == None)
  50. FATAL("could not create window");
  51. XSelectInput(dpy, win->xwin,
  52. StructureNotifyMask | ExposureMask | KeyPressMask);
  53. gc = XCreateGC(dpy, win->xwin, 0, NULL);
  54. if ((classhint = XAllocClassHint())) {
  55. classhint->res_name = "sxvi";
  56. classhint->res_class = "sxvi";
  57. XSetClassHint(dpy, win->xwin, classhint);
  58. XFree(classhint);
  59. }
  60. XMapWindow(dpy, win->xwin);
  61. XFlush(dpy);
  62. }
  63. void win_close(win_t *win) {
  64. if (win == NULL)
  65. return;
  66. XDestroyWindow(dpy, win->xwin);
  67. XFreeGC(dpy, gc);
  68. XCloseDisplay(dpy);
  69. }
  70. int win_configure(win_t *win, XConfigureEvent *cev) {
  71. int changed;
  72. if (win == NULL)
  73. return 0;
  74. changed = win->x != cev->x || win->y != cev->y ||
  75. win->w != cev->width || win->h != cev->height;
  76. win->x = cev->x;
  77. win->y = cev->y;
  78. win->w = cev->width;
  79. win->h = cev->height;
  80. win->bw = cev->border_width;
  81. return changed;
  82. }