1 | /*--------------------------------*-C-*---------------------------------*; |
1 | /*--------------------------------*-C-*---------------------------------* |
2 | * File: main.c |
2 | * File: main.C |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * |
4 | * |
5 | * All portions of code are copyright by their respective author/s. |
5 | * All portions of code are copyright by their respective author/s. |
6 | * Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk> |
6 | * Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk> |
7 | * - original version |
7 | * - original version |
… | |
… | |
44 | # include <termios.h> |
44 | # include <termios.h> |
45 | #endif |
45 | #endif |
46 | |
46 | |
47 | #include <cstring> |
47 | #include <cstring> |
48 | |
48 | |
|
|
49 | vector<rxvt_term *> rxvt_term::termlist; |
|
|
50 | |
49 | static char curlocale[128]; |
51 | static char curlocale[128]; |
50 | |
52 | |
51 | void |
53 | bool |
52 | rxvt_set_locale (const char *locale) |
54 | rxvt_set_locale (const char *locale) |
53 | { |
55 | { |
54 | if (locale && STRNCMP (locale, curlocale, 128)) |
56 | if (!locale || !STRNCMP (locale, curlocale, 128)) |
55 | { |
57 | return false; |
|
|
58 | |
56 | STRNCPY (curlocale, locale, 128); |
59 | STRNCPY (curlocale, locale, 128); |
57 | setlocale (LC_CTYPE, curlocale); |
60 | setlocale (LC_CTYPE, curlocale); |
58 | } |
61 | return true; |
59 | } |
62 | } |
60 | |
63 | |
61 | #if ENABLE_COMBINING |
64 | #if ENABLE_COMBINING |
62 | class rxvt_composite_vec rxvt_composite; |
65 | class rxvt_composite_vec rxvt_composite; |
63 | |
66 | |
64 | text_t rxvt_composite_vec::compose (uint32_t c1, uint32_t c2) |
67 | text_t rxvt_composite_vec::compose (unicode_t c1, unicode_t c2) |
65 | { |
68 | { |
66 | compose_char *cc; |
69 | compose_char *cc; |
67 | |
70 | |
68 | // break compose chains, as stupid readline really likes to duplicate |
71 | // break compose chains, as stupid readline really likes to duplicate |
69 | // composing characters for some reason near the end of a line. |
72 | // composing characters for some reason near the end of a line. |
… | |
… | |
95 | v.push_back (compose_char (c1, c2)); |
98 | v.push_back (compose_char (c1, c2)); |
96 | |
99 | |
97 | return v.size () - 1 + COMPOSE_LO; |
100 | return v.size () - 1 + COMPOSE_LO; |
98 | } |
101 | } |
99 | |
102 | |
100 | int rxvt_composite_vec::expand (uint32_t c, wchar_t *r) |
103 | int rxvt_composite_vec::expand (unicode_t c, wchar_t *r) |
101 | { |
104 | { |
102 | compose_char *cc = (*this)[c]; |
105 | compose_char *cc = (*this)[c]; |
103 | |
106 | |
104 | if (!cc) |
107 | if (!cc) |
105 | { |
108 | { |
… | |
… | |
152 | cursor_blink_ev (this, &rxvt_term::cursor_blink_cb), |
155 | cursor_blink_ev (this, &rxvt_term::cursor_blink_cb), |
153 | #endif |
156 | #endif |
154 | #ifdef TEXT_BLINK |
157 | #ifdef TEXT_BLINK |
155 | text_blink_ev (this, &rxvt_term::text_blink_cb), |
158 | text_blink_ev (this, &rxvt_term::text_blink_cb), |
156 | #endif |
159 | #endif |
|
|
160 | #ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING |
|
|
161 | cont_scroll_ev (this, &rxvt_term::cont_scroll_cb), |
|
|
162 | #endif |
|
|
163 | #ifdef SELECTION_SCROLLING |
|
|
164 | sel_scroll_ev (this, &rxvt_term::sel_scroll_cb), |
|
|
165 | #endif |
|
|
166 | #if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING) |
|
|
167 | slip_wheel_ev (this, &rxvt_term::slip_wheel_cb), |
|
|
168 | #endif |
157 | #ifdef POINTER_BLANK |
169 | #ifdef POINTER_BLANK |
158 | pointer_ev (this, &rxvt_term::pointer_cb), |
170 | pointer_ev (this, &rxvt_term::pointer_cb), |
159 | #endif |
171 | #endif |
160 | #ifdef USE_XIM |
172 | #ifdef USE_XIM |
161 | im_ev (this, &rxvt_term::im_cb), |
173 | im_ev (this, &rxvt_term::im_cb), |
162 | #endif |
174 | #endif |
163 | check_ev (this, &rxvt_term::check_cb), |
175 | check_ev (this, &rxvt_term::check_cb), |
|
|
176 | flush_ev (this, &rxvt_term::flush_cb), |
164 | destroy_ev (this, &rxvt_term::destroy_cb), |
177 | destroy_ev (this, &rxvt_term::destroy_cb), |
165 | pty_ev (this, &rxvt_term::pty_cb), |
178 | pty_ev (this, &rxvt_term::pty_cb), |
166 | incr_ev (this, &rxvt_term::incr_cb) |
179 | incr_ev (this, &rxvt_term::incr_cb) |
167 | { |
180 | { |
168 | cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; |
181 | cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; |
|
|
182 | |
|
|
183 | termlist.push_back (this); |
169 | } |
184 | } |
170 | |
185 | |
171 | rxvt_term::~rxvt_term () |
186 | rxvt_term::~rxvt_term () |
172 | { |
187 | { |
|
|
188 | termlist.erase (find (termlist.begin (), termlist.end(), this)); |
|
|
189 | |
173 | if (cmd_fd >= 0) |
190 | if (cmd_fd >= 0) |
174 | close (cmd_fd); |
191 | close (cmd_fd); |
175 | |
192 | |
176 | #ifndef NO_SETOWNER_TTYDEV |
193 | #ifndef NO_SETOWNER_TTYDEV |
177 | privileged_ttydev (RESTORE); |
194 | privileged_ttydev (RESTORE); |
… | |
… | |
182 | |
199 | |
183 | delete TermWin.fontset; |
200 | delete TermWin.fontset; |
184 | |
201 | |
185 | if (display) |
202 | if (display) |
186 | { |
203 | { |
|
|
204 | selection_clear (); |
|
|
205 | |
|
|
206 | #ifdef USE_XIM |
|
|
207 | im_destroy (); |
|
|
208 | #endif |
|
|
209 | #ifdef MENUBAR |
|
|
210 | if (menubarGC) XFreeGC (display->display, menubarGC); |
|
|
211 | #endif |
|
|
212 | #ifdef XTERM_SCROLLBAR |
|
|
213 | if (xscrollbarGC) XFreeGC (display->display, xscrollbarGC); |
|
|
214 | if (ShadowGC) XFreeGC (display->display, ShadowGC); |
|
|
215 | #endif |
|
|
216 | #ifdef PLAIN_SCROLLBAR |
|
|
217 | if (pscrollbarGC) XFreeGC (display->display, pscrollbarGC); |
|
|
218 | #endif |
|
|
219 | #ifdef NEXT_SCROLLBAR |
|
|
220 | if (blackGC) XFreeGC (display->display, blackGC); |
|
|
221 | if (whiteGC) XFreeGC (display->display, whiteGC); |
|
|
222 | if (grayGC) XFreeGC (display->display, grayGC); |
|
|
223 | if (darkGC) XFreeGC (display->display, darkGC); |
|
|
224 | if (stippleGC) XFreeGC (display->display, stippleGC); |
|
|
225 | if (dimple) XFreePixmap (display->display, dimple); |
|
|
226 | if (upArrow) XFreePixmap (display->display, upArrow); |
|
|
227 | if (downArrow) XFreePixmap (display->display, downArrow); |
|
|
228 | if (upArrowHi) XFreePixmap (display->display, upArrowHi); |
|
|
229 | if (downArrowHi) XFreePixmap (display->display, downArrowHi); |
|
|
230 | #endif |
|
|
231 | #if defined(MENUBAR) || defined(RXVT_SCROLLBAR) |
|
|
232 | if (topShadowGC) XFreeGC (display->display, topShadowGC); |
|
|
233 | if (botShadowGC) XFreeGC (display->display, botShadowGC); |
|
|
234 | if (scrollbarGC) XFreeGC (display->display, scrollbarGC); |
|
|
235 | #endif |
|
|
236 | if (TermWin.gc) XFreeGC (display->display, TermWin.gc); |
|
|
237 | |
187 | #if defined(MENUBAR) && (MENUBAR_MAX > 1) |
238 | #if defined(MENUBAR) && (MENUBAR_MAX > 1) |
188 | delete menuBar.drawable; |
239 | delete menuBar.drawable; |
189 | //if (menuBar.win) |
240 | //if (menuBar.win) |
190 | // XDestroyWindow (display->display, menuBar.win); |
241 | // XDestroyWindow (display->display, menuBar.win); |
191 | #endif |
242 | #endif |
… | |
… | |
195 | XDestroyWindow (display->display, TermWin.parent[0]); |
246 | XDestroyWindow (display->display, TermWin.parent[0]); |
196 | } |
247 | } |
197 | |
248 | |
198 | // TODO: free pixcolours, colours should become part of rxvt_display |
249 | // TODO: free pixcolours, colours should become part of rxvt_display |
199 | |
250 | |
200 | delete PixColors; |
251 | delete PixColorsFocused; |
|
|
252 | #ifdef OFF_FOCUS_FADING |
|
|
253 | delete PixColorsUnFocused; |
|
|
254 | #endif |
201 | |
255 | |
202 | displays.put (display); |
256 | displays.put (display); |
203 | |
257 | |
204 | scr_release (); |
258 | scr_release (); |
205 | |
259 | |
|
|
260 | /* clear all resources */ |
|
|
261 | for (int i = 0; i < allocated.size (); i++) |
|
|
262 | free (allocated[i]); |
|
|
263 | |
|
|
264 | free (selection.text); |
|
|
265 | // TODO: manage env vars in child only(!) |
206 | free (env_windowid); |
266 | free (env_windowid); |
207 | free (env_display); |
267 | free (env_display); |
208 | free (env_term); |
268 | free (env_term); |
209 | free (env_colorfgbg); |
269 | free (env_colorfgbg); |
210 | free (locale); |
270 | free (locale); |
|
|
271 | #if 0 |
211 | free (codeset); |
272 | free (codeset); |
|
|
273 | #endif |
212 | |
274 | |
213 | delete envv; |
275 | delete envv; |
214 | delete argv; |
276 | delete argv; |
215 | } |
277 | } |
216 | |
278 | |
217 | void |
279 | void |
218 | rxvt_term::destroy () |
280 | rxvt_term::destroy () |
219 | { |
281 | { |
|
|
282 | if (destroy_ev.active) |
|
|
283 | return; |
|
|
284 | |
220 | if (display) |
285 | if (display) |
221 | { |
286 | { |
|
|
287 | #ifdef USE_XIM |
|
|
288 | im_ev.stop (display); |
|
|
289 | #endif |
|
|
290 | #ifdef HAVE_SCROLLBARS |
|
|
291 | scrollbar_ev.stop (display); |
|
|
292 | #endif |
|
|
293 | #ifdef MENUBAR |
|
|
294 | menubar_ev.stop (display); |
|
|
295 | #endif |
222 | rootwin_ev.stop (display); |
296 | rootwin_ev.stop (display); |
223 | termwin_ev.stop (display); |
297 | termwin_ev.stop (display); |
224 | vt_ev.stop (display); |
298 | vt_ev.stop (display); |
225 | #ifdef USE_XIM |
|
|
226 | im_destroy (); |
|
|
227 | im_ev.stop (display); |
|
|
228 | #endif |
|
|
229 | #ifdef HAVE_SCROLLBARS |
|
|
230 | scrollbar_ev.stop (display); |
|
|
231 | #endif |
|
|
232 | #ifdef MENUBAR |
|
|
233 | menubar_ev.stop (display); |
|
|
234 | #endif |
|
|
235 | } |
299 | } |
236 | |
300 | |
237 | check_ev.stop (); |
301 | check_ev.stop (); |
238 | pty_ev.stop (); |
302 | pty_ev.stop (); |
239 | #ifdef CURSOR_BLINK |
303 | #ifdef CURSOR_BLINK |
240 | cursor_blink_ev.stop (); |
304 | cursor_blink_ev.stop (); |
241 | #endif |
305 | #endif |
242 | #ifdef TEXT_BLINK |
306 | #ifdef TEXT_BLINK |
243 | text_blink_ev.stop (); |
307 | text_blink_ev.stop (); |
244 | #endif |
308 | #endif |
|
|
309 | #ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING |
|
|
310 | cont_scroll_ev.stop (); |
|
|
311 | #endif |
|
|
312 | #ifdef SELECTION_SCROLLING |
|
|
313 | sel_scroll_ev.stop (); |
|
|
314 | #endif |
245 | #ifdef POINTER_BLANK |
315 | #ifdef POINTER_BLANK |
246 | pointer_ev.stop (); |
316 | pointer_ev.stop (); |
247 | #endif |
317 | #endif |
248 | |
318 | |
249 | destroy_ev.start (0); |
319 | destroy_ev.start (0); |
… | |
… | |
257 | delete this; |
327 | delete this; |
258 | } |
328 | } |
259 | |
329 | |
260 | /*----------------------------------------------------------------------*/ |
330 | /*----------------------------------------------------------------------*/ |
261 | /* rxvt_init () */ |
331 | /* rxvt_init () */ |
262 | /* LIBPROTO */ |
|
|
263 | rxvt_t |
|
|
264 | rxvt_init (int argc, const char *const *argv) |
|
|
265 | { |
|
|
266 | SET_R (new rxvt_term); |
|
|
267 | |
|
|
268 | if (!GET_R->init_vars () || !GET_R->init (argc, argv)) |
|
|
269 | { |
|
|
270 | delete GET_R; |
|
|
271 | SET_R (0); |
|
|
272 | } |
|
|
273 | |
|
|
274 | return GET_R; |
|
|
275 | } |
|
|
276 | |
|
|
277 | static int (*old_xerror_handler) (Display *dpy, XErrorEvent *event); |
|
|
278 | |
|
|
279 | void |
|
|
280 | rxvt_init_signals () |
|
|
281 | { |
|
|
282 | /* install exit handler for cleanup */ |
|
|
283 | #if 0 |
|
|
284 | #ifdef HAVE_ATEXIT |
|
|
285 | atexit (rxvt_clean_exit); |
|
|
286 | #else |
|
|
287 | #endif |
|
|
288 | #endif |
|
|
289 | |
|
|
290 | struct sigaction sa; |
|
|
291 | |
|
|
292 | sigfillset (&sa.sa_mask); |
|
|
293 | sa.sa_flags = SA_NOCLDSTOP | SA_RESTART; |
|
|
294 | sa.sa_handler = SIG_IGN; sigaction (SIGHUP , &sa, 0); |
|
|
295 | sa.sa_handler = SIG_IGN; sigaction (SIGPIPE, &sa, 0); |
|
|
296 | sa.sa_handler = rxvt_Exit_signal; sigaction (SIGINT , &sa, 0); |
|
|
297 | sa.sa_handler = rxvt_Exit_signal; sigaction (SIGQUIT, &sa, 0); |
|
|
298 | sa.sa_handler = rxvt_Exit_signal; sigaction (SIGTERM, &sa, 0); |
|
|
299 | sa.sa_handler = rxvt_Child_signal; sigaction (SIGCHLD, &sa, 0); |
|
|
300 | |
|
|
301 | /* need to trap SIGURG for SVR4 (Unixware) rlogin */ |
|
|
302 | /* signal (SIGURG, SIG_DFL); */ |
|
|
303 | |
|
|
304 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
|
|
305 | //XSetIOErrorHandler ((XErrorHandler) rxvt_xioerror_handler); |
|
|
306 | } |
|
|
307 | |
|
|
308 | bool |
332 | bool |
309 | rxvt_term::init (int argc, const char *const *argv) |
333 | rxvt_term::init (int argc, const char *const *argv) |
310 | { |
334 | { |
|
|
335 | SET_R (this); |
|
|
336 | |
|
|
337 | if (!init_vars ()) |
|
|
338 | return false; |
|
|
339 | |
311 | /* |
340 | /* |
312 | * Save and then give up any super-user privileges |
341 | * Save and then give up any super-user privileges |
313 | * If we need privileges in any area then we must specifically request it. |
342 | * If we need privileges in any area then we must specifically request it. |
314 | * We should only need to be root in these cases: |
343 | * We should only need to be root in these cases: |
315 | * 1. write utmp entries on some systems |
344 | * 1. write utmp entries on some systems |
… | |
… | |
370 | check_ev.start (); |
399 | check_ev.start (); |
371 | |
400 | |
372 | return true; |
401 | return true; |
373 | } |
402 | } |
374 | |
403 | |
|
|
404 | static int (*old_xerror_handler) (Display *dpy, XErrorEvent *event); |
|
|
405 | |
|
|
406 | void |
|
|
407 | rxvt_init_signals () |
|
|
408 | { |
|
|
409 | /* install exit handler for cleanup */ |
|
|
410 | #if 0 |
|
|
411 | #ifdef HAVE_ATEXIT |
|
|
412 | atexit (rxvt_clean_exit); |
|
|
413 | #else |
|
|
414 | #endif |
|
|
415 | #endif |
|
|
416 | |
|
|
417 | struct sigaction sa; |
|
|
418 | |
|
|
419 | sigfillset (&sa.sa_mask); |
|
|
420 | sa.sa_flags = SA_NOCLDSTOP | SA_RESTART; |
|
|
421 | sa.sa_handler = SIG_IGN; sigaction (SIGHUP , &sa, 0); |
|
|
422 | sa.sa_handler = SIG_IGN; sigaction (SIGPIPE, &sa, 0); |
|
|
423 | sa.sa_handler = rxvt_Exit_signal; sigaction (SIGINT , &sa, 0); |
|
|
424 | sa.sa_handler = rxvt_Exit_signal; sigaction (SIGQUIT, &sa, 0); |
|
|
425 | sa.sa_handler = rxvt_Exit_signal; sigaction (SIGTERM, &sa, 0); |
|
|
426 | sa.sa_handler = rxvt_Child_signal; sigaction (SIGCHLD, &sa, 0); |
|
|
427 | |
|
|
428 | /* need to trap SIGURG for SVR4 (Unixware) rlogin */ |
|
|
429 | /* signal (SIGURG, SIG_DFL); */ |
|
|
430 | |
|
|
431 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
|
|
432 | //XSetIOErrorHandler ((XErrorHandler) rxvt_xioerror_handler); |
|
|
433 | } |
|
|
434 | |
375 | /* ------------------------------------------------------------------------- * |
435 | /* ------------------------------------------------------------------------- * |
376 | * SIGNAL HANDLING & EXIT HANDLER * |
436 | * SIGNAL HANDLING & EXIT HANDLER * |
377 | * ------------------------------------------------------------------------- */ |
437 | * ------------------------------------------------------------------------- */ |
378 | /* |
438 | /* |
379 | * Catch a SIGCHLD signal and exit if the direct child has died |
439 | * Catch a SIGCHLD signal and exit if the direct child has died |
380 | */ |
440 | */ |
|
|
441 | |
|
|
442 | void rxvt_term::child_exited (int pid) |
|
|
443 | { |
|
|
444 | for (rxvt_term **t = termlist.begin (); t < termlist.end (); t++) |
|
|
445 | if (pid == (*t)->cmd_pid) |
|
|
446 | { |
|
|
447 | (*t)->destroy (); |
|
|
448 | break; |
|
|
449 | } |
|
|
450 | } |
|
|
451 | |
381 | /* ARGSUSED */ |
452 | /* ARGSUSED */ |
382 | /* EXTPROTO */ |
453 | /* EXTPROTO */ |
383 | RETSIGTYPE |
454 | RETSIGTYPE |
384 | rxvt_Child_signal (int sig __attribute__ ((unused))) |
455 | rxvt_Child_signal (int sig __attribute__ ((unused))) |
385 | { |
456 | { |
386 | int pid, save_errno = errno; |
457 | int pid, save_errno = errno; |
|
|
458 | |
387 | while ((pid = waitpid (-1, NULL, WNOHANG)) == -1 && errno == EINTR) |
459 | while ((pid = waitpid (-1, NULL, WNOHANG)) > 0) |
388 | ; |
460 | rxvt_term::child_exited (pid); |
|
|
461 | |
389 | errno = save_errno; |
462 | errno = save_errno; |
390 | |
|
|
391 | #if 0 |
|
|
392 | if (pid == cmd_pid) |
|
|
393 | exit (EXIT_SUCCESS); |
|
|
394 | #endif |
|
|
395 | } |
463 | } |
396 | |
464 | |
397 | /* |
465 | /* |
398 | * Catch a fatal signal and tidy up before quitting |
466 | * Catch a fatal signal and tidy up before quitting |
399 | */ |
467 | */ |
… | |
… | |
401 | RETSIGTYPE |
469 | RETSIGTYPE |
402 | rxvt_Exit_signal (int sig) |
470 | rxvt_Exit_signal (int sig) |
403 | { |
471 | { |
404 | signal (sig, SIG_DFL); |
472 | signal (sig, SIG_DFL); |
405 | #ifdef DEBUG_CMD |
473 | #ifdef DEBUG_CMD |
406 | rxvt_print_error ("signal %d", sig); |
474 | rxvt_warn ("caught signal %d, exiting.\n", sig); |
407 | #endif |
475 | #endif |
408 | rxvt_clean_exit (); |
476 | rxvt_clean_exit (); |
409 | kill (getpid (), sig); |
477 | kill (getpid (), sig); |
410 | } |
478 | } |
411 | |
479 | |
… | |
… | |
696 | max_height = MAX_ROWS * TermWin.fheight; |
764 | max_height = MAX_ROWS * TermWin.fheight; |
697 | |
765 | |
698 | szHint.base_width = szHint.base_height = 2 * TermWin.int_bwidth; |
766 | szHint.base_width = szHint.base_height = 2 * TermWin.int_bwidth; |
699 | |
767 | |
700 | sb_w = mb_h = 0; |
768 | sb_w = mb_h = 0; |
701 | window_vt_x = window_vt_y = 0; |
769 | window_vt_x = window_vt_y = TermWin.int_bwidth; |
|
|
770 | |
702 | if (scrollbar_visible ()) |
771 | if (scrollbar_visible ()) |
703 | { |
772 | { |
704 | sb_w = scrollbar_TotalWidth (); |
773 | sb_w = scrollbar_TotalWidth (); |
705 | szHint.base_width += sb_w; |
774 | szHint.base_width += sb_w; |
706 | if (! (Options & Opt_scrollBar_right)) |
775 | if (!(Options & Opt_scrollBar_right)) |
707 | window_vt_x = sb_w; |
776 | window_vt_x += sb_w; |
708 | } |
777 | } |
|
|
778 | |
709 | if (menubar_visible ()) |
779 | if (menubar_visible ()) |
710 | { |
780 | { |
711 | mb_h = menuBar_TotalHeight (); |
781 | mb_h = menuBar_TotalHeight (); |
712 | szHint.base_height += mb_h; |
782 | szHint.base_height += mb_h; |
713 | window_vt_y = mb_h; |
783 | window_vt_y += mb_h; |
714 | } |
784 | } |
|
|
785 | |
715 | szHint.width_inc = TermWin.fwidth; |
786 | szHint.width_inc = TermWin.fwidth; |
716 | szHint.height_inc = TermWin.fheight; |
787 | szHint.height_inc = TermWin.fheight; |
717 | szHint.min_width = szHint.base_width + szHint.width_inc; |
788 | szHint.min_width = szHint.base_width + szHint.width_inc; |
718 | szHint.min_height = szHint.base_height + szHint.height_inc; |
789 | szHint.min_height = szHint.base_height + szHint.height_inc; |
719 | |
790 | |
… | |
… | |
725 | else |
796 | else |
726 | { |
797 | { |
727 | MIN_IT (TermWin.width, max_width); |
798 | MIN_IT (TermWin.width, max_width); |
728 | szHint.width = szHint.base_width + TermWin.width; |
799 | szHint.width = szHint.base_width + TermWin.width; |
729 | } |
800 | } |
|
|
801 | |
730 | if (height && height - szHint.base_height < max_height) |
802 | if (height && height - szHint.base_height < max_height) |
731 | { |
803 | { |
732 | szHint.height = height; |
804 | szHint.height = height; |
733 | TermWin.height = height - szHint.base_height; |
805 | TermWin.height = height - szHint.base_height; |
734 | } |
806 | } |
735 | else |
807 | else |
736 | { |
808 | { |
737 | MIN_IT (TermWin.height, max_height); |
809 | MIN_IT (TermWin.height, max_height); |
738 | szHint.height = szHint.base_height + TermWin.height; |
810 | szHint.height = szHint.base_height + TermWin.height; |
739 | } |
811 | } |
|
|
812 | |
740 | if (scrollbar_visible () && (Options & Opt_scrollBar_right)) |
813 | if (scrollbar_visible () && (Options & Opt_scrollBar_right)) |
741 | window_sb_x = szHint.width - sb_w; |
814 | window_sb_x = szHint.width - sb_w; |
742 | |
815 | |
743 | if (recalc_x) |
816 | if (recalc_x) |
744 | szHint.x += (DisplayWidth (display->display, DefaultScreen (display->display)) |
817 | szHint.x += (DisplayWidth (display->display, DefaultScreen (display->display)) |
… | |
… | |
819 | resize_all_windows (0, 0, 0); |
892 | resize_all_windows (0, 0, 0); |
820 | scr_remap_chars (); |
893 | scr_remap_chars (); |
821 | scr_touch (true); |
894 | scr_touch (true); |
822 | } |
895 | } |
823 | |
896 | |
|
|
897 | for (unicode_t ch = 0x20; ch <= 0x7f; ch++) |
|
|
898 | TermWin.ascii_map [ch - 0x20] = fs->find_font (ch); |
|
|
899 | |
824 | return true; |
900 | return true; |
825 | } |
901 | } |
826 | } |
902 | } |
827 | |
903 | |
828 | return false; |
904 | return false; |
… | |
… | |
838 | /*----------------------------------------------------------------------*/ |
914 | /*----------------------------------------------------------------------*/ |
839 | /* xterm sequences - title, iconName, color (exptl) */ |
915 | /* xterm sequences - title, iconName, color (exptl) */ |
840 | void |
916 | void |
841 | rxvt_term::set_title (const char *str) |
917 | rxvt_term::set_title (const char *str) |
842 | { |
918 | { |
843 | #ifndef SMART_WINDOW_TITLE |
919 | #ifdef SMART_WINDOW_TITLE |
844 | XStoreName (display->display, TermWin.parent[0], str); |
|
|
845 | #else |
|
|
846 | char *name; |
920 | char *name; |
847 | |
921 | |
848 | if (XFetchName (display->display, TermWin.parent[0], &name) == 0) |
922 | if (!XFetchName (display->display, TermWin.parent[0], &name)) |
849 | name = NULL; |
923 | name = NULL; |
|
|
924 | |
850 | if (name == NULL || STRCMP (name, str)) |
925 | if (name == NULL || STRCMP (name, str)) |
|
|
926 | #endif |
851 | XStoreName (display->display, TermWin.parent[0], str); |
927 | XStoreName (display->display, TermWin.parent[0], str); |
|
|
928 | |
|
|
929 | #ifdef SMART_WINDOW_TITLE |
852 | if (name) |
930 | if (name) |
853 | XFree (name); |
931 | XFree (name); |
854 | #endif |
932 | #endif |
855 | } |
933 | } |
856 | |
934 | |
857 | void |
935 | void |
858 | rxvt_term::set_iconName (const char *str) |
936 | rxvt_term::set_icon_name (const char *str) |
859 | { |
937 | { |
860 | #ifndef SMART_WINDOW_TITLE |
938 | #ifdef SMART_WINDOW_TITLE |
861 | XSetIconName (display->display, TermWin.parent[0], str); |
|
|
862 | #else |
|
|
863 | char *name; |
939 | char *name; |
864 | |
940 | |
865 | if (XGetIconName (display->display, TermWin.parent[0], &name)) |
941 | if (!XGetIconName (display->display, TermWin.parent[0], &name)) |
866 | name = NULL; |
942 | name = NULL; |
|
|
943 | |
867 | if (name == NULL || STRCMP (name, str)) |
944 | if (name == NULL || STRCMP (name, str)) |
|
|
945 | #endif |
868 | XSetIconName (display->display, TermWin.parent[0], str); |
946 | XSetIconName (display->display, TermWin.parent[0], str); |
|
|
947 | |
|
|
948 | #ifdef SMART_WINDOW_TITLE |
869 | if (name) |
949 | if (name) |
870 | XFree (name); |
950 | XFree (name); |
871 | #endif |
951 | #endif |
872 | } |
952 | } |
873 | |
953 | |
… | |
… | |
887 | i = atoi (color); |
967 | i = atoi (color); |
888 | if (i >= 8 && i <= 15) |
968 | if (i >= 8 && i <= 15) |
889 | { /* bright colors */ |
969 | { /* bright colors */ |
890 | i -= 8; |
970 | i -= 8; |
891 | # ifndef NO_BRIGHTCOLOR |
971 | # ifndef NO_BRIGHTCOLOR |
892 | PixColors[idx] = PixColors[minBrightCOLOR + i]; |
972 | PixColorsFocused[idx] = PixColorsFocused[minBrightCOLOR + i]; |
893 | SET_PIXCOLOR (idx); |
973 | SET_PIXCOLOR (idx); |
894 | goto Done; |
974 | goto Done; |
895 | # endif |
975 | # endif |
896 | |
976 | |
897 | } |
977 | } |
898 | if (i >= 0 && i <= 7) |
978 | if (i >= 0 && i <= 7) |
899 | { /* normal colors */ |
979 | { /* normal colors */ |
900 | PixColors[idx] = PixColors[minCOLOR + i]; |
980 | PixColorsFocused[idx] = PixColorsFocused[minCOLOR + i]; |
901 | SET_PIXCOLOR (idx); |
981 | SET_PIXCOLOR (idx); |
902 | goto Done; |
982 | goto Done; |
903 | } |
983 | } |
904 | } |
984 | } |
|
|
985 | |
905 | if (!rXParseAllocColor (& xcol, color)) |
986 | if (!rXParseAllocColor (& xcol, color)) |
906 | return; |
987 | return; |
|
|
988 | |
907 | /* XStoreColor (display->display, XCMAP, XColor*); */ |
989 | /* XStoreColor (display->display, display->cmap, XColor*); */ |
908 | |
990 | |
909 | /* |
991 | /* |
910 | * FIXME: should free colors here, but no idea how to do it so instead, |
992 | * FIXME: should free colors here, but no idea how to do it so instead, |
911 | * so just keep gobbling up the colormap |
993 | * so just keep gobbling up the colormap |
912 | */ |
994 | */ |
… | |
… | |
915 | if (PixColors[idx] == PixColors[i]) |
997 | if (PixColors[idx] == PixColors[i]) |
916 | break; |
998 | break; |
917 | if (i > Color_White) |
999 | if (i > Color_White) |
918 | { |
1000 | { |
919 | /* fprintf (stderr, "XFreeColors: PixColors [%d] = %lu\n", idx, PixColors [idx]); */ |
1001 | /* fprintf (stderr, "XFreeColors: PixColors [%d] = %lu\n", idx, PixColors [idx]); */ |
920 | XFreeColors (display->display, XCMAP, (PixColors + idx), 1, |
1002 | XFreeColors (display->display, display->cmap, (PixColors + idx), 1, |
921 | DisplayPlanes (display->display, display->screen)); |
1003 | DisplayPlanes (display->display, display->screen)); |
922 | } |
1004 | } |
923 | # endif |
1005 | # endif |
924 | |
1006 | |
925 | PixColors[idx] = xcol; |
1007 | PixColorsFocused[idx] = xcol; |
926 | SET_PIXCOLOR (idx); |
1008 | SET_PIXCOLOR (idx); |
927 | |
1009 | |
928 | /* XSetWindowAttributes attr; */ |
1010 | /* XSetWindowAttributes attr; */ |
929 | /* Cursor cursor; */ |
1011 | /* Cursor cursor; */ |
930 | Done: |
1012 | Done: |
|
|
1013 | #ifdef OFF_FOCUS_FADING |
|
|
1014 | PixColorsUnFocused[idx] = PixColorsFocused[idx].fade (display, atoi (rs[Rs_fade])); |
|
|
1015 | #endif |
931 | if (idx == Color_bg && ! (Options & Opt_transparent)) |
1016 | if (idx == Color_bg && ! (Options & Opt_transparent)) |
932 | XSetWindowBackground (display->display, TermWin.vt, |
1017 | XSetWindowBackground (display->display, TermWin.vt, PixColors[Color_bg]); |
933 | PixColors[Color_bg]); |
|
|
934 | |
1018 | |
935 | /* handle Color_BD, scrollbar background, etc. */ |
1019 | /* handle Color_BD, scrollbar background, etc. */ |
936 | |
1020 | |
937 | set_colorfgbg (); |
1021 | set_colorfgbg (); |
938 | recolour_cursor (); |
1022 | recolour_cursor (); |
939 | /* the only reasonable way to enforce a clean update */ |
1023 | scr_touch (true); |
940 | scr_poweron (); |
|
|
941 | } |
1024 | } |
942 | |
1025 | |
943 | #else |
1026 | #else |
944 | # define set_window_color (idx,color) ((void)0) |
1027 | # define set_window_color (idx,color) ((void)0) |
945 | #endif /* XTERM_COLOR_CHANGE */ |
1028 | #endif /* XTERM_COLOR_CHANGE */ |
946 | |
1029 | |
947 | void |
1030 | void |
948 | rxvt_term::recolour_cursor () |
1031 | rxvt_term::recolour_cursor () |
949 | { |
1032 | { |
950 | #if TODO |
|
|
951 | rxvt_color xcol[2]; |
1033 | XColor xcol[2]; |
952 | |
1034 | |
953 | xcol[0] = PixColors[Color_pointer]; |
1035 | xcol[0].pixel = ISSET_PIXCOLOR (Color_pointer_fg) ? PixColorsFocused[Color_pointer_fg] : PixColorsFocused[Color_fg]; |
954 | xcol[1] = PixColors[Color_bg]; |
1036 | xcol[1].pixel = ISSET_PIXCOLOR (Color_pointer_bg) ? PixColorsFocused[Color_pointer_bg] : PixColorsFocused[Color_bg]; |
955 | XQueryColors (display->display, XCMAP, xcol, 2); |
1037 | XQueryColors (display->display, display->cmap, xcol, 2); |
956 | XRecolorCursor (display->display, TermWin_cursor, & (xcol[0]), & (xcol[1])); |
1038 | XRecolorCursor (display->display, TermWin_cursor, xcol + 0, xcol + 1); |
957 | #endif |
|
|
958 | } |
1039 | } |
959 | |
1040 | |
960 | /*----------------------------------------------------------------------*/ |
1041 | /*----------------------------------------------------------------------*/ |
961 | /* |
1042 | /* |
962 | * find if fg/bg matches any of the normal (low-intensity) colors |
1043 | * find if fg/bg matches any of the normal (low-intensity) colors |
… | |
… | |
1011 | int |
1092 | int |
1012 | rxvt_term::rXParseAllocColor (rxvt_color *screen_in_out, const char *colour) |
1093 | rxvt_term::rXParseAllocColor (rxvt_color *screen_in_out, const char *colour) |
1013 | { |
1094 | { |
1014 | if (!screen_in_out->set (display, colour)) |
1095 | if (!screen_in_out->set (display, colour)) |
1015 | { |
1096 | { |
1016 | rxvt_print_error ("can't allocate colour: %s", colour); |
1097 | rxvt_warn ("can't get colour '%s', continuing without.\n", colour); |
1017 | return false; |
1098 | return false; |
1018 | } |
1099 | } |
1019 | |
1100 | |
1020 | return true; |
1101 | return true; |
1021 | } |
1102 | } |
… | |
… | |
1032 | int old_width = szHint.width, old_height = szHint.height; |
1113 | int old_width = szHint.width, old_height = szHint.height; |
1033 | #endif |
1114 | #endif |
1034 | |
1115 | |
1035 | window_calc (width, height); |
1116 | window_calc (width, height); |
1036 | XSetWMNormalHints (display->display, TermWin.parent[0], &szHint); |
1117 | XSetWMNormalHints (display->display, TermWin.parent[0], &szHint); |
|
|
1118 | |
1037 | if (!ignoreparent) |
1119 | if (!ignoreparent) |
1038 | { |
1120 | { |
1039 | #ifdef SMART_RESIZE |
1121 | #ifdef SMART_RESIZE |
1040 | /* |
1122 | /* |
1041 | * resize by Marius Gedminas <marius.gedminas@uosis.mif.vu.lt> |
1123 | * resize by Marius Gedminas <marius.gedminas@uosis.mif.vu.lt> |
… | |
… | |
1076 | dy /= 2; |
1158 | dy /= 2; |
1077 | |
1159 | |
1078 | XMoveResizeWindow (display->display, TermWin.parent[0], x + dx, y + dy, |
1160 | XMoveResizeWindow (display->display, TermWin.parent[0], x + dx, y + dy, |
1079 | szHint.width, szHint.height); |
1161 | szHint.width, szHint.height); |
1080 | #else |
1162 | #else |
1081 | XResizeWindow (display->display, TermWin.parent[0], szHint.width, |
1163 | XResizeWindow (display->display, TermWin.parent[0], szHint.width, szHint.height); |
1082 | szHint.height); |
|
|
1083 | #endif |
1164 | #endif |
1084 | |
|
|
1085 | } |
1165 | } |
1086 | |
1166 | |
1087 | fix_screen = (TermWin.ncol != prev_ncol |
1167 | fix_screen = TermWin.ncol != prev_ncol || TermWin.nrow != prev_nrow; |
1088 | || TermWin.nrow != prev_nrow); |
|
|
1089 | |
1168 | |
1090 | if (fix_screen || width != old_width || height != old_height) |
1169 | if (fix_screen || width != old_width || height != old_height) |
1091 | { |
1170 | { |
1092 | if (scrollbar_visible ()) |
1171 | if (scrollbar_visible ()) |
1093 | { |
1172 | { |
1094 | XMoveResizeWindow (display->display, scrollBar.win, window_sb_x, |
1173 | XMoveResizeWindow (display->display, scrollBar.win, |
|
|
1174 | window_sb_x, 0, |
1095 | 0, scrollbar_TotalWidth (), szHint.height); |
1175 | scrollbar_TotalWidth (), szHint.height); |
1096 | resize_scrollbar (); |
1176 | resize_scrollbar (); |
1097 | } |
1177 | } |
1098 | |
1178 | |
1099 | if (menubar_visible ()) |
1179 | if (menubar_visible ()) |
1100 | XMoveResizeWindow (display->display, menuBar.win, window_vt_x, |
1180 | XMoveResizeWindow (display->display, menuBar.win, |
|
|
1181 | window_vt_x, 0, |
1101 | 0, TermWin_TotalWidth (), menuBar_TotalHeight ()); |
1182 | TermWin_TotalWidth (), menuBar_TotalHeight ()); |
1102 | |
1183 | |
1103 | XMoveResizeWindow (display->display, TermWin.vt, window_vt_x, |
1184 | XMoveResizeWindow (display->display, TermWin.vt, |
1104 | window_vt_y, TermWin_TotalWidth (), |
1185 | window_vt_x, window_vt_y, |
1105 | TermWin_TotalHeight ()); |
1186 | TermWin_TotalWidth (), TermWin_TotalHeight ()); |
1106 | scr_clear (height != old_height); |
1187 | scr_clear (); |
1107 | #ifdef XPM_BACKGROUND |
1188 | #ifdef XPM_BACKGROUND |
1108 | resize_pixmap (); |
1189 | resize_pixmap (); |
1109 | #endif |
1190 | #endif |
1110 | |
|
|
1111 | } |
1191 | } |
1112 | |
1192 | |
1113 | if (fix_screen || old_height == 0) |
1193 | if (fix_screen || old_height == 0) |
1114 | { |
1194 | { |
1115 | int curr_screen = -1; |
1195 | int curr_screen = -1; |
… | |
… | |
1388 | if (preedit_attr) XFree (preedit_attr); |
1468 | if (preedit_attr) XFree (preedit_attr); |
1389 | if (status_attr) XFree (status_attr); |
1469 | if (status_attr) XFree (status_attr); |
1390 | |
1470 | |
1391 | if (Input_Context == NULL) |
1471 | if (Input_Context == NULL) |
1392 | { |
1472 | { |
1393 | rxvt_print_error ("failed to create input context"); |
1473 | rxvt_warn ("failed to create input context, continuing without XIM.\n"); |
1394 | display->put_xim (input_method); |
1474 | display->put_xim (input_method); |
1395 | return false; |
1475 | return false; |
1396 | } |
1476 | } |
1397 | |
1477 | |
1398 | if (input_style & XIMPreeditArea) |
1478 | if (input_style & XIMPreeditArea) |