| @@ -31,10 +31,23 @@ static Cursor hand; |
| 31 | 31 | | |
| 32 | 32 | | static GC bgc; |
| 33 | 33 | | |
| 34 | + | void win_set_sizehints(win_t *win) { |
| 35 | + | XSizeHints sizehints; |
| 36 | + | |
| 37 | + | if (!win) |
| 38 | + | return; |
| 39 | + | |
| 40 | + | sizehints.flags = PMinSize | PMaxSize; |
| 41 | + | sizehints.min_width = win->w; |
| 42 | + | sizehints.max_width = win->w; |
| 43 | + | sizehints.min_height = win->h; |
| 44 | + | sizehints.max_height = win->h; |
| 45 | + | XSetWMNormalHints(win->env.dpy, win->xwin, &sizehints); |
| 46 | + | } |
| 47 | + | |
| 34 | 48 | | void win_open(win_t *win) { |
| 35 | 49 | | win_env_t *e; |
| 36 | 50 | | XClassHint classhint; |
| 37 | | − | XSizeHints sizehints; |
| 38 | 51 | | XColor bgcol; |
| 39 | 52 | | int gmask; |
| 40 | 53 | | |
| @@ -104,14 +117,8 @@ void win_open(win_t *win) { |
| 104 | 117 | | classhint.res_class = "sxiv"; |
| 105 | 118 | | XSetClassHint(e->dpy, win->xwin, &classhint); |
| 106 | 119 | | |
| 107 | | − | if (options->fixed) { |
| 108 | | − | sizehints.flags = PMinSize | PMaxSize; |
| 109 | | − | sizehints.min_width = win->w; |
| 110 | | − | sizehints.max_width = win->w; |
| 111 | | − | sizehints.min_height = win->h; |
| 112 | | − | sizehints.max_height = win->h; |
| 113 | | − | XSetWMNormalHints(e->dpy, win->xwin, &sizehints); |
| 114 | | − | } |
| 120 | + | if (options->fixed) |
| 121 | + | win_set_sizehints(win); |
| 115 | 122 | | |
| 116 | 123 | | XMapWindow(e->dpy, win->xwin); |
| 117 | 124 | | XFlush(e->dpy); |
| @@ -133,17 +140,6 @@ void win_close(win_t *win) { |
| 133 | 140 | | XCloseDisplay(win->env.dpy); |
| 134 | 141 | | } |
| 135 | 142 | | |
| 136 | | − | void win_set_title(win_t *win, const char *title) { |
| 137 | | − | if (!win) |
| 138 | | − | return; |
| 139 | | − | |
| 140 | | − | if (!title) |
| 141 | | − | title = "sxiv"; |
| 142 | | − | |
| 143 | | − | XStoreName(win->env.dpy, win->xwin, title); |
| 144 | | − | XSetIconName(win->env.dpy, win->xwin, title); |
| 145 | | − | } |
| 146 | | − | |
| 147 | 143 | | int win_configure(win_t *win, XConfigureEvent *c) { |
| 148 | 144 | | int changed; |
| 149 | 145 | | |
| @@ -161,6 +157,32 @@ int win_configure(win_t *win, XConfigureEvent *c) { |
| 161 | 157 | | return changed; |
| 162 | 158 | | } |
| 163 | 159 | | |
| 160 | + | int win_resize(win_t *win, unsigned int w, unsigned int h) { |
| 161 | + | if (!win) |
| 162 | + | return 0; |
| 163 | + | |
| 164 | + | w = MIN(w, win->env.scrw - 2 * win->bw); |
| 165 | + | h = MIN(h, win->env.scrh - 2 * win->bw); |
| 166 | + | |
| 167 | + | if (win->w == w && win->h == h) |
| 168 | + | return 0; |
| 169 | + | |
| 170 | + | win->w = w; |
| 171 | + | win->h = h; |
| 172 | + | |
| 173 | + | if (win->x + w + 2 * win->bw > win->env.scrw) |
| 174 | + | win->x = win->env.scrw - w - 2 * win->bw; |
| 175 | + | if (win->y + h + 2 * win->bw > win->env.scrh) |
| 176 | + | win->y = win->env.scrh - h - 2 * win->bw; |
| 177 | + | |
| 178 | + | if (options->fixed) |
| 179 | + | win_set_sizehints(win); |
| 180 | + | |
| 181 | + | XMoveResizeWindow(win->env.dpy, win->xwin, win->x, win->y, win->w, win->h); |
| 182 | + | |
| 183 | + | return 1; |
| 184 | + | } |
| 185 | + | |
| 164 | 186 | | void win_toggle_fullscreen(win_t *win) { |
| 165 | 187 | | XEvent ev; |
| 166 | 188 | | XClientMessageEvent *cm; |
| @@ -213,6 +235,17 @@ void win_draw(win_t *win) { |
| 213 | 235 | | XClearWindow(win->env.dpy, win->xwin); |
| 214 | 236 | | } |
| 215 | 237 | | |
| 238 | + | void win_set_title(win_t *win, const char *title) { |
| 239 | + | if (!win) |
| 240 | + | return; |
| 241 | + | |
| 242 | + | if (!title) |
| 243 | + | title = "sxiv"; |
| 244 | + | |
| 245 | + | XStoreName(win->env.dpy, win->xwin, title); |
| 246 | + | XSetIconName(win->env.dpy, win->xwin, title); |
| 247 | + | } |
| 248 | + | |
| 216 | 249 | | void win_set_cursor(win_t *win, win_cur_t cursor) { |
| 217 | 250 | | if (!win) |
| 218 | 251 | | return; |