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.
 
 
 
 
 
 

116 rindas
2.8 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. Visual *vis;
  27. Colormap cmap;
  28. int depth;
  29. GC gc;
  30. XColor bgcol;
  31. void win_open(win_t *win) {
  32. XClassHint *classhint;
  33. XSetWindowAttributes attr;
  34. unsigned long mask;
  35. if (!win)
  36. return;
  37. if (!(dpy = XOpenDisplay(NULL)))
  38. FATAL("could not open display");
  39. scr = DefaultScreen(dpy);
  40. scrw = DisplayWidth(dpy, scr);
  41. scrh = DisplayHeight(dpy, scr);
  42. vis = DefaultVisual(dpy, scr);
  43. cmap = DefaultColormap(dpy, scr);
  44. depth = DefaultDepth(dpy, scr);
  45. if (!XAllocNamedColor(dpy, DefaultColormap(dpy, scr), BG_COLOR,
  46. &bgcol, &bgcol))
  47. FATAL("could not allocate color: %s", BG_COLOR);
  48. if (win->w > scrw)
  49. win->w = scrw;
  50. if (win->h > scrh)
  51. win->h = scrh;
  52. win->x = (scrw - win->w) / 2;
  53. win->y = (scrh - win->h) / 2;
  54. attr.backing_store = NotUseful;
  55. attr.background_pixel = bgcol.pixel;
  56. attr.save_under = False;
  57. mask = CWBackingStore | CWBackPixel | CWSaveUnder;
  58. win->xwin = XCreateWindow(dpy, RootWindow(dpy, scr), win->x, win->y,
  59. win->w, win->h, 0, depth, InputOutput, vis, mask, &attr);
  60. if (win->xwin == None)
  61. FATAL("could not create window");
  62. XSelectInput(dpy, win->xwin,
  63. StructureNotifyMask | ExposureMask | KeyPressMask);
  64. gc = XCreateGC(dpy, win->xwin, 0, NULL);
  65. if ((classhint = XAllocClassHint())) {
  66. classhint->res_name = "sxvi";
  67. classhint->res_class = "sxvi";
  68. XSetClassHint(dpy, win->xwin, classhint);
  69. XFree(classhint);
  70. }
  71. XMapWindow(dpy, win->xwin);
  72. XFlush(dpy);
  73. }
  74. void win_close(win_t *win) {
  75. if (!win)
  76. return;
  77. XDestroyWindow(dpy, win->xwin);
  78. XFreeGC(dpy, gc);
  79. XCloseDisplay(dpy);
  80. }
  81. int win_configure(win_t *win, XConfigureEvent *cev) {
  82. int changed;
  83. if (!win)
  84. return 0;
  85. changed = win->x != cev->x || win->y != cev->y ||
  86. win->w != cev->width || win->h != cev->height;
  87. win->x = cev->x;
  88. win->y = cev->y;
  89. win->w = cev->width;
  90. win->h = cev->height;
  91. win->bw = cev->border_width;
  92. return changed;
  93. }