ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/main.C
(Generate patch)

Comparing rxvt-unicode/src/main.C (file contents):
Revision 1.348 by sf-exg, Thu Jan 20 16:41:23 2011 UTC vs.
Revision 1.404 by root, Thu Jun 17 14:31:39 2021 UTC

11 * Copyright (c) 1997 mj olesen <olesen@me.QueensU.CA> 11 * Copyright (c) 1997 mj olesen <olesen@me.QueensU.CA>
12 * - extensive modifications 12 * - extensive modifications
13 * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de> 13 * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de>
14 * Copyright (c) 1998-2001 Geoff Wing <gcw@pobox.com> 14 * Copyright (c) 1998-2001 Geoff Wing <gcw@pobox.com>
15 * - extensive modifications 15 * - extensive modifications
16 * Copyright (c) 2003-2010 Marc Lehmann <pcg@goof.com> 16 * Copyright (c) 2003-2014 Marc Lehmann <schmorp@schmorp.de>
17 * Copyright (c) 2015 Emanuele Giaquinta <e.giaquinta@glauco.it>
17 * 18 *
18 * This program is free software; you can redistribute it and/or modify 19 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by 20 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or 21 * the Free Software Foundation; either version 3 of the License, or
21 * (at your option) any later version. 22 * (at your option) any later version.
22 * 23 *
23 * This program is distributed in the hope that it will be useful, 24 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of 25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36#include "keyboard.h" 37#include "keyboard.h"
37#include "rxvtperl.h" 38#include "rxvtperl.h"
38 39
39#include <limits> 40#include <limits>
40 41
41#include <cassert> 42#include <assert.h>
42#include <csignal> 43#include <signal.h>
43#include <cstring> 44#include <string.h>
44 45
45#include <termios.h> 46#include <termios.h>
46 47
47#ifdef HAVE_XSETLOCALE 48#ifdef HAVE_XSETLOCALE
48# define X_LOCALE 49# define X_LOCALE
49# include <X11/Xlocale.h> 50# include <X11/Xlocale.h>
50#else 51#else
51# ifdef HAVE_SETLOCALE
52# include <clocale> 52# include <locale.h>
53# endif
54#endif 53#endif
55 54
56struct termios rxvt_term::def_tio; 55struct termios rxvt_term::def_tio;
57vector<rxvt_term *> rxvt_term::termlist; 56vector<rxvt_term *> rxvt_term::termlist;
58 57
60rxvt_t rxvt_current_term; 59rxvt_t rxvt_current_term;
61 60
62static char curlocale[128], savelocale[128]; 61static char curlocale[128], savelocale[128];
63 62
64bool 63bool
65rxvt_set_locale (const char *locale) NOTHROW 64rxvt_set_locale (const char *locale) noexcept
66{ 65{
67 int size = strlen (locale) + 1; 66 int size = strlen (locale) + 1;
68 67
69 if (size > sizeof (curlocale)) 68 if (size > sizeof (curlocale))
70 rxvt_fatal ("locale string too long, aborting.\n"); 69 rxvt_fatal ("locale string too long, aborting.\n");
76 setlocale (LC_CTYPE, curlocale); 75 setlocale (LC_CTYPE, curlocale);
77 return true; 76 return true;
78} 77}
79 78
80void 79void
81rxvt_push_locale (const char *locale) NOTHROW 80rxvt_push_locale (const char *locale) noexcept
82{ 81{
83 strcpy (savelocale, curlocale); 82 strcpy (savelocale, curlocale);
84 rxvt_set_locale (locale); 83 rxvt_set_locale (locale);
85} 84}
86 85
87void 86void
88rxvt_pop_locale () NOTHROW 87rxvt_pop_locale () noexcept
89{ 88{
90 rxvt_set_locale (savelocale); 89 rxvt_set_locale (savelocale);
91} 90}
92 91
93#if ENABLE_COMBINING 92#if ENABLE_COMBINING
105 if (cc->c2 == c2) return c1; 104 if (cc->c2 == c2) return c1;
106 cc = (*this)[cc->c1]; 105 cc = (*this)[cc->c1];
107 } 106 }
108 107
109 // check to see whether this combination already exists otherwise 108 // check to see whether this combination already exists otherwise
110 for (cc = v.end (); cc-- > v.begin (); ) 109 for (cc = v.begin (); cc < v.end (); cc++)
111 if (cc->c1 == c1 && cc->c2 == c2) 110 if (cc->c1 == c1 && cc->c2 == c2)
112 return COMPOSE_LO + (cc - v.begin ()); 111 return COMPOSE_LO + (cc - v.begin ());
113 112
114 // allocate a new combination 113 // allocate a new combination
115 if (v.size () == COMPOSE_HI - COMPOSE_LO + 1) 114 if (v.size () == COMPOSE_HI - COMPOSE_LO + 1)
125 v.push_back (compose_char (c1, c2)); 124 v.push_back (compose_char (c1, c2));
126 125
127 return v.size () - 1 + COMPOSE_LO; 126 return v.size () - 1 + COMPOSE_LO;
128} 127}
129 128
129template<typename T>
130int rxvt_composite_vec::expand (unicode_t c, wchar_t *r) 130int rxvt_composite_vec::expand (unicode_t c, T *r)
131{ 131{
132 compose_char *cc = (*this)[c]; 132 compose_char *cc = (*this)[c];
133 133
134 if (!cc) 134 if (!cc)
135 { 135 {
146 len++; 146 len++;
147 if (r) *r++ = cc->c2; 147 if (r) *r++ = cc->c2;
148 } 148 }
149 149
150 return len; 150 return len;
151
152} 151}
152
153template int rxvt_composite_vec::expand<text_t> (unicode_t c, text_t *);
154template int rxvt_composite_vec::expand<wchar_t> (unicode_t c, wchar_t *);
153#endif 155#endif
154 156
155rxvt_term::rxvt_term () 157rxvt_term::rxvt_term ()
156{ 158{
157#if HAVE_BG_PIXMAP
158 update_background_ev.set<rxvt_term, &rxvt_term::update_background_cb> (this);
159#endif
160#ifdef CURSOR_BLINK 159#ifdef CURSOR_BLINK
161 cursor_blink_ev.set <rxvt_term, &rxvt_term::cursor_blink_cb> (this); cursor_blink_ev.set (0., CURSOR_BLINK_INTERVAL); 160 cursor_blink_ev.set <rxvt_term, &rxvt_term::cursor_blink_cb> (this); cursor_blink_ev.set (0., CURSOR_BLINK_INTERVAL);
162#endif 161#endif
163#ifdef TEXT_BLINK 162#ifdef TEXT_BLINK
164 text_blink_ev.set <rxvt_term, &rxvt_term::text_blink_cb> (this); text_blink_ev.set (0., TEXT_BLINK_INTERVAL); 163 text_blink_ev.set <rxvt_term, &rxvt_term::text_blink_cb> (this); text_blink_ev.set (0., TEXT_BLINK_INTERVAL);
170 sel_scroll_ev.set <rxvt_term, &rxvt_term::sel_scroll_cb> (this); 169 sel_scroll_ev.set <rxvt_term, &rxvt_term::sel_scroll_cb> (this);
171#endif 170#endif
172#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING) 171#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
173 slip_wheel_ev.set <rxvt_term, &rxvt_term::slip_wheel_cb> (this); 172 slip_wheel_ev.set <rxvt_term, &rxvt_term::slip_wheel_cb> (this);
174#endif 173#endif
175#if ENABLE_TRANSPARENCY || ENABLE_PERL 174#if ENABLE_PERL
176 rootwin_ev.set <rxvt_term, &rxvt_term::rootwin_cb> (this), 175 rootwin_ev.set <rxvt_term, &rxvt_term::rootwin_cb> (this),
177#endif 176#endif
178 scrollbar_ev.set <rxvt_term, &rxvt_term::x_cb> (this), 177 scrollbar_ev.set <rxvt_term, &rxvt_term::x_cb> (this),
179#ifdef USE_XIM 178#if USE_XIM
180 im_ev.set <rxvt_term, &rxvt_term::im_cb> (this), 179 im_ev.set <rxvt_term, &rxvt_term::im_cb> (this),
181#endif 180#endif
182#ifdef POINTER_BLANK 181#ifdef POINTER_BLANK
183 pointer_ev.set <rxvt_term, &rxvt_term::pointer_cb> (this); 182 pointer_ev.set <rxvt_term, &rxvt_term::pointer_cb> (this);
184#endif 183#endif
187#endif 186#endif
188 child_ev.set <rxvt_term, &rxvt_term::child_cb> (this); 187 child_ev.set <rxvt_term, &rxvt_term::child_cb> (this);
189 flush_ev.set <rxvt_term, &rxvt_term::flush_cb> (this); 188 flush_ev.set <rxvt_term, &rxvt_term::flush_cb> (this);
190 destroy_ev.set <rxvt_term, &rxvt_term::destroy_cb> (this); 189 destroy_ev.set <rxvt_term, &rxvt_term::destroy_cb> (this);
191 pty_ev.set <rxvt_term, &rxvt_term::pty_cb> (this); 190 pty_ev.set <rxvt_term, &rxvt_term::pty_cb> (this);
192 incr_ev.set <rxvt_term, &rxvt_term::incr_cb> (this);
193 termwin_ev.set <rxvt_term, &rxvt_term::x_cb> (this); 191 termwin_ev.set <rxvt_term, &rxvt_term::x_cb> (this);
194 vt_ev.set <rxvt_term, &rxvt_term::x_cb> (this); 192 vt_ev.set <rxvt_term, &rxvt_term::x_cb> (this);
195 193
196 cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; 194 cmdbuf_ptr = cmdbuf_endp = cmdbuf_base;
197 195
225 if (fontset[i] != fontset[0]) 223 if (fontset[i] != fontset[0])
226 delete fontset[i]; 224 delete fontset[i];
227#endif 225#endif
228 delete fontset[0]; 226 delete fontset[0];
229 227
230#ifdef HAVE_BG_PIXMAP 228#if HAVE_IMG
231 bgPixmap.destroy (); 229 delete bg_img;
232#endif
233#ifdef HAVE_AFTERIMAGE
234 if (asv)
235 destroy_asvisual (asv, 0);
236 if (asimman)
237 destroy_image_manager (asimman, 0);
238#endif 230#endif
239 231
240 if (display) 232 if (display)
241 { 233 {
242 selection_clear (); 234 selection_clear ();
243 selection_clear (true); 235 selection_clear (true);
244 236
245#ifdef USE_XIM 237#if USE_XIM
246 im_destroy (); 238 im_destroy ();
247#endif 239#endif
248 scrollBar.destroy (); 240 scrollBar.destroy ();
241
242 if (gc)
249 if (gc) XFreeGC (dpy, gc); 243 XFreeGC (dpy, gc);
250 244
251 delete drawable; 245 delete drawable;
246
252 // destroy all windows 247 // destroy all windows
253 if (parent[0]) 248 if (parent)
254 XDestroyWindow (dpy, parent[0]); 249 XDestroyWindow (dpy, parent);
255 250
256 for (int i = 0; i < TOTAL_COLORS; i++) 251 for (int i = 0; i < TOTAL_COLORS; i++)
257 if (ISSET_PIXCOLOR (i)) 252 if (ISSET_PIXCOLOR (i))
258 { 253 {
259 pix_colors_focused [i].free (this); 254 pix_colors_focused [i].free (this);
260#if OFF_FOCUS_FADING 255#if OFF_FOCUS_FADING
256 if (rs[Rs_fade])
261 pix_colors_unfocused [i].free (this); 257 pix_colors_unfocused [i].free (this);
262#endif 258#endif
263 } 259 }
264 260
265 clear (); 261 clear ();
266 262
274 for (int i = 0; i < allocated.size (); i++) 270 for (int i = 0; i < allocated.size (); i++)
275 free (allocated [i]); 271 free (allocated [i]);
276 272
277 free (selection.text); 273 free (selection.text);
278 free (selection.clip_text); 274 free (selection.clip_text);
279 // TODO: manage env vars in child only(!)
280 free (env_display);
281 free (env_term);
282 free (locale); 275 free (locale);
283 free (v_buffer); 276 free (v_buffer);
284 free (incr_buf); 277
278 delete selection_req;
279
280 if (env && memcmp (env, envv->begin (), envv->size () * sizeof (char *)))
281 rxvt_warn ("env has been modified, probably as a result of a lib calling setenv.\n");
282
283 delete [] env;
285 284
286 delete envv; 285 delete envv;
287 delete argv; 286 delete argv;
288 287
289#ifdef KEYSYM_RESOURCE 288#ifdef KEYSYM_RESOURCE
290 delete keyboard; 289 delete keyboard;
291#endif 290#endif
292#ifndef NO_RESOURCES 291#ifndef NO_RESOURCES
293 XrmDestroyDatabase (option_db); 292 XrmDestroyDatabase (option_db);
294#endif 293#endif
294
295 SET_R ((rxvt_term *)0);
295} 296}
296 297
297// child has exited, usually destroys 298// child has exited, usually destroys
298void 299void
299rxvt_term::child_cb (ev::child &w, int status) 300rxvt_term::child_cb (ev::child &w, int status)
322 { 323 {
323#if USE_XIM 324#if USE_XIM
324 im_ev.stop (display); 325 im_ev.stop (display);
325#endif 326#endif
326 scrollbar_ev.stop (display); 327 scrollbar_ev.stop (display);
327#if ENABLE_TRANSPARENCY || ENABLE_PERL 328#if ENABLE_PERL
328 rootwin_ev.stop (display); 329 rootwin_ev.stop (display);
329#endif 330#endif
330 incr_ev.stop ();
331 termwin_ev.stop (display); 331 termwin_ev.stop (display);
332 vt_ev.stop (display); 332 vt_ev.stop (display);
333 } 333 }
334 334
335 flush_ev.stop (); 335 flush_ev.stop ();
360 360
361 delete this; 361 delete this;
362} 362}
363 363
364void 364void
365rxvt_term::set_option (uint8_t opt, bool set) 365rxvt_term::set_option (uint8_t opt, bool set) noexcept
366{ 366{
367 if (!opt) 367 if (!opt)
368 return; 368 return;
369 369
370 uint8_t mask = 1 << (opt & 7); 370 uint8_t mask = 1 << (opt & 7);
374} 374}
375 375
376/*----------------------------------------------------------------------*/ 376/*----------------------------------------------------------------------*/
377/* 377/*
378 * Exit gracefully, clearing the utmp entry and restoring tty attributes 378 * Exit gracefully, clearing the utmp entry and restoring tty attributes
379 * TODO: if debugging, this should free up any known resources if we can
380 */ 379 */
381static XErrorHandler old_xerror_handler; 380static XErrorHandler old_xerror_handler;
382 381
383static void 382static void
384rxvt_emergency_cleanup () 383rxvt_emergency_cleanup ()
386 for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++) 385 for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++)
387 (*t)->emergency_cleanup (); 386 (*t)->emergency_cleanup ();
388} 387}
389 388
390#if !ENABLE_MINIMAL 389#if !ENABLE_MINIMAL
391static void 390static void ecb_cold
392print_x_error (Display *dpy, XErrorEvent *event) 391print_x_error (Display *dpy, XErrorEvent *event)
393{ 392{
394 char buffer[BUFSIZ]; 393 char buffer[BUFSIZ];
395 char mesg[BUFSIZ]; 394 char mesg[BUFSIZ];
396 char number[32]; 395 char number[32];
397 const char mtype[] = "XlibMessage"; 396
398 XGetErrorText(dpy, event->error_code, buffer, BUFSIZ);
399 XGetErrorDatabaseText(dpy, mtype, "XError", "X Error", mesg, BUFSIZ);
400 rxvt_warn ("An X Error occurred, trying to continue after report.\n"); 397 rxvt_warn ("An X Error occurred, trying to continue after report.\n");
398
399 XGetErrorDatabaseText (dpy, "XlibMessage", "ErrorSerial", "Error Serial #%d", mesg, BUFSIZ);
400 snprintf (buffer, BUFSIZ, "+ %s\n", mesg); rxvt_warn (buffer, event->serial);
401
402 XGetErrorText (dpy, event->error_code, buffer, BUFSIZ);
403 XGetErrorDatabaseText (dpy, "XlibMessage", "XError", "X Error", mesg, BUFSIZ);
401 rxvt_warn ("%s: %s\n", mesg, buffer); 404 rxvt_warn ("+ %s: %s\n", mesg, buffer);
405
402 XGetErrorDatabaseText(dpy, mtype, "MajorCode", "Request Major code %d", mesg, BUFSIZ); 406 XGetErrorDatabaseText (dpy, "XlibMessage", "MajorCode", "Request Major code %d", mesg, BUFSIZ);
403 rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->request_code); 407 snprintf (buffer, BUFSIZ, "+ %s\n", mesg); rxvt_warn (buffer, event->request_code);
408
409 if (event->request_code >= 128)
410 {
411#if 0
412 /* XListExtensions and probably query extensions hangs when there are multiple queues errors */
413 int nexts;
414 char **exts = XListExtensions (dpy, &nexts);
415
416 while (nexts)
417 {
418 char *extname = exts [nexts - 1];
419 int major, first_event, first_error;
420
421 if (XQueryExtension (dpy, extname, &major, &first_event, &first_error) && major == event->request_code)
422 {
423 XGetErrorDatabaseText (dpy, "XlibMessage", "MinorCode", "Request Minor code %d", mesg, BUFSIZ);
424 rxvt_warn ("+ (which is extension %s minor code %d)\n", extname, event->minor_code);
425
426 snprintf (buffer, BUFSIZ, "%s.%d", extname, event->minor_code);
427 XGetErrorDatabaseText (dpy, "XRequest", buffer, "an unregistered minor code", buffer, BUFSIZ);
428 rxvt_warn ("+ (which is %s)\n", buffer);
429
430 break;
431 }
432
433 printf ("nextss %d %s\n", nexts, extname);//D
434 --nexts;
435 ++exts;
436 }
437#else
438 int nexts = 0;
439 char **exts = 0;
440#endif
441
442 if (!nexts)
443 {
444 rxvt_warn ("+ (which is an unknown extension)\n", buffer);
445
446 XGetErrorDatabaseText (dpy, "XlibMessage", "MinorCode", "Request Minor code %d", mesg, BUFSIZ);
447 snprintf (buffer, BUFSIZ, "+ %s\n", mesg); rxvt_warn (buffer, event->minor_code);
448
449#if 0
450 sprintf (number, "RENDER.%d", event->minor_code);
451 XGetErrorDatabaseText (dpy, "XRequest", number, "", buffer, BUFSIZ);
452 rxvt_warn ("+ (which is %s)\n", buffer);
453#endif
454 }
455
456 XFreeExtensionList (exts);
457 }
458 else
459 {
404 sprintf(number, "%d", event->request_code); 460 sprintf (number, "%d", event->request_code);
405 XGetErrorDatabaseText(dpy, "XRequest", number, "", buffer, BUFSIZ); 461 XGetErrorDatabaseText (dpy, "XRequest", number, "", buffer, BUFSIZ);
406 rxvt_warn ("(which is %s)\n", buffer); 462 rxvt_warn ("+ (which is %s)\n", buffer);
407 if (event->request_code >= 128) {
408 XGetErrorDatabaseText(dpy, mtype, "MinorCode", "Request Minor code %d",
409 mesg, BUFSIZ);
410 rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->minor_code);
411 } 463 }
464
412 if ((event->error_code == BadWindow) || 465 if (event->error_code == BadWindow
413 (event->error_code == BadPixmap) || 466 || event->error_code == BadPixmap
414 (event->error_code == BadCursor) || 467 || event->error_code == BadCursor
415 (event->error_code == BadFont) || 468 || event->error_code == BadFont
416 (event->error_code == BadDrawable) || 469 || event->error_code == BadDrawable
417 (event->error_code == BadColor) || 470 || event->error_code == BadColor
418 (event->error_code == BadGC) || 471 || event->error_code == BadGC
419 (event->error_code == BadIDChoice) || 472 || event->error_code == BadIDChoice
420 (event->error_code == BadValue) || 473 || event->error_code == BadValue
421 (event->error_code == BadAtom)) { 474 || event->error_code == BadAtom)
475 {
422 if (event->error_code == BadValue) 476 if (event->error_code == BadValue)
423 XGetErrorDatabaseText(dpy, mtype, "Value", "Value 0x%x", 477 XGetErrorDatabaseText (dpy, "XlibMessage", "Value", "Value 0x%x", mesg, BUFSIZ);
424 mesg, BUFSIZ);
425 else if (event->error_code == BadAtom) 478 else if (event->error_code == BadAtom)
426 XGetErrorDatabaseText(dpy, mtype, "AtomID", "AtomID 0x%x", 479 XGetErrorDatabaseText (dpy, "XlibMessage", "AtomID", "AtomID 0x%x", mesg, BUFSIZ);
427 mesg, BUFSIZ);
428 else 480 else
429 XGetErrorDatabaseText(dpy, mtype, "ResourceID", "ResourceID 0x%x", 481 XGetErrorDatabaseText (dpy, "XlibMessage", "ResourceID", "ResourceID 0x%x", mesg, BUFSIZ);
430 mesg, BUFSIZ);
431 rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->resourceid);
432 }
433 XGetErrorDatabaseText(dpy, mtype, "ErrorSerial", "Error Serial #%d",
434 mesg, BUFSIZ);
435 rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->serial);
436}
437#endif
438 482
439int 483 snprintf (buffer, BUFSIZ, "+ %s\n", mesg); rxvt_warn (buffer, event->resourceid);
484 }
485}
486#endif
487
488int ecb_cold
440rxvt_xerror_handler (Display *display, XErrorEvent *event) 489rxvt_xerror_handler (Display *display, XErrorEvent *event)
441{ 490{
442 if (GET_R->allowedxerror == -1) 491 if (GET_R && GET_R->allowedxerror == -1)
443 GET_R->allowedxerror = event->error_code; 492 GET_R->allowedxerror = event->error_code;
444 else 493 else
445 { 494 {
446 // GET_R is most likely not the terminal which caused the error, 495 // GET_R is most likely not the terminal which caused the error,
447 // so just output the error and continue 496 // so just output the error and continue
453 } 502 }
454 503
455 return 0; 504 return 0;
456} 505}
457 506
458int 507int ecb_cold
459rxvt_xioerror_handler (Display *display) 508rxvt_xioerror_handler (Display *display)
460{ 509{
461 rxvt_warn ("X connection to '%s' broken, unable to recover, exiting.\n", 510 rxvt_warn ("X connection to '%s' broken, unable to recover, exiting.\n",
462 DisplayString (display)); 511 DisplayString (display));
463 rxvt_emergency_cleanup (); 512 rxvt_emergency_cleanup ();
583 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); 632 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler);
584 // TODO: handle this with exceptions and tolerate the memory loss 633 // TODO: handle this with exceptions and tolerate the memory loss
585 XSetIOErrorHandler (rxvt_xioerror_handler); 634 XSetIOErrorHandler (rxvt_xioerror_handler);
586 635
587 XrmInitialize (); 636 XrmInitialize ();
637
638#if HAVE_PIXBUF
639 #if !GLIB_CHECK_VERSION(2,36,0)
640 g_type_init ();
641 #endif
642#endif
588} 643}
589 644
590/*----------------------------------------------------------------------*/ 645/*----------------------------------------------------------------------*/
591/* 646/*
592 * window size/position calculations for XSizeHint and other storage. 647 * window size/position calculations for XSizeHint and other storage.
713 if (recalc_y) 768 if (recalc_y)
714 szHint.y += DisplayHeight (dpy, display->screen) - szHint.height - 2 * ext_bwidth; 769 szHint.y += DisplayHeight (dpy, display->screen) - szHint.height - 2 * ext_bwidth;
715 770
716 ncol = width / fwidth; 771 ncol = width / fwidth;
717 nrow = height / fheight; 772 nrow = height / fheight;
773
774 // When the size of the vt window is not a multiple of the cell
775 // size, i.e., when the wm does not honour our size hints, there are
776 // extra areas not covered by the terminal screen. Such gaps, when a
777 // bg pixmap is set, would have to be cleared manually to properly
778 // refresh the background. We take the simpler route and shrink the
779 // vt window so as to avoid creating gaps.
780 vt_width = ncol * fwidth;
781 vt_height = nrow * fheight;
718} 782}
719 783
720/*----------------------------------------------------------------------*/ 784/*----------------------------------------------------------------------*/
721/* 785/*
722 * Tell the teletype handler what size the window is. 786 * Tell the teletype handler what size the window is.
730 794
731 struct winsize ws; 795 struct winsize ws;
732 796
733 ws.ws_col = ncol; 797 ws.ws_col = ncol;
734 ws.ws_row = nrow; 798 ws.ws_row = nrow;
735 ws.ws_xpixel = width; 799 ws.ws_xpixel = vt_width;
736 ws.ws_ypixel = height; 800 ws.ws_ypixel = vt_height;
737 ioctl (pty->pty, TIOCSWINSZ, &ws); 801 ioctl (pty->pty, TIOCSWINSZ, &ws);
738 802
739#if 0 803#if 0
740 // TIOCSWINSZ is supposed to do this automatically and correctly 804 // TIOCSWINSZ is supposed to do this automatically and correctly
741 if (cmd_pid) /* force through to the command */ 805 if (cmd_pid) /* force through to the command */
742 kill (-cmd_pid, SIGWINCH); 806 kill (-cmd_pid, SIGWINCH);
743#endif 807#endif
744} 808}
745 809
746/*----------------------------------------------------------------------*/ 810/*----------------------------------------------------------------------*/
747/* set_fonts () - load and set the various fonts 811/* load and set the various fonts */
748 *
749 * init = 1 - initialize
750 *
751 * fontname == FONT_UP - switch to bigger font
752 * fontname == FONT_DN - switch to smaller font
753 */
754bool 812bool
755rxvt_term::set_fonts () 813rxvt_term::set_fonts ()
756{ 814{
757 rxvt_fontset *fs = new rxvt_fontset (this); 815 rxvt_fontset *fs = new rxvt_fontset (this);
758 rxvt_fontprop prop; 816 rxvt_fontprop prop;
773 831
774 delete fontset[0]; 832 delete fontset[0];
775 fontset[0] = fs; 833 fontset[0] = fs;
776 834
777 prop = (*fs)[rxvt_fontset::firstFont]->properties (); 835 prop = (*fs)[rxvt_fontset::firstFont]->properties ();
778 prop.height += lineSpace; 836 prop.width = max (prop.width + letterSpace, 1);
779 prop.width += letterSpace;
780 837
781 fs->set_prop (prop, false); 838 fs->set_prop (prop, false);
782 839
783 fwidth = prop.width; 840 fwidth = prop.width;
784 fheight = prop.height; 841 fheight = prop.height + lineSpace;
785 fbase = prop.ascent; 842 fbase = prop.ascent;
786 843
787 for (int style = 1; style < 4; style++) 844 for (int style = 1; style < 4; style++)
788 { 845 {
789#if ENABLE_STYLES 846#if ENABLE_STYLES
815#else 872#else
816 fontset[style] = fontset[0]; 873 fontset[style] = fontset[0];
817#endif 874#endif
818 } 875 }
819 876
820 if (parent[0]) 877 if (parent)
821 { 878 {
822 resize_all_windows (0, 0, 0); 879 resize_all_windows (0, 0, 0);
823 scr_remap_chars (); 880 scr_remap_chars ();
824 scr_touch (true); 881 scr_touch (true);
825 } 882 }
828} 885}
829 886
830void 887void
831rxvt_term::set_string_property (Atom prop, const char *str, int len) 888rxvt_term::set_string_property (Atom prop, const char *str, int len)
832{ 889{
833 XChangeProperty (dpy, parent[0], 890 XChangeProperty (dpy, parent,
834 prop, XA_STRING, 8, PropModeReplace, 891 prop, XA_STRING, 8, PropModeReplace,
835 (const unsigned char *)str, len >= 0 ? len : strlen (str)); 892 (const unsigned char *)str, len >= 0 ? len : strlen (str));
836} 893}
837 894
838void 895void
840{ 897{
841 XTextProperty ct; 898 XTextProperty ct;
842 899
843 if (XmbTextListToTextProperty (dpy, (char **)&str, 1, XStdICCTextStyle, &ct) >= 0) 900 if (XmbTextListToTextProperty (dpy, (char **)&str, 1, XStdICCTextStyle, &ct) >= 0)
844 { 901 {
845 XSetTextProperty (dpy, parent[0], &ct, prop); 902 XSetTextProperty (dpy, parent, &ct, prop);
846 XFree (ct.value); 903 XFree (ct.value);
847 } 904 }
848} 905}
849 906
850void 907void
851rxvt_term::set_utf8_property (Atom prop, const char *str, int len) 908rxvt_term::set_utf8_property (Atom prop, const char *str, int len)
852{ 909{
853 wchar_t *ws = rxvt_mbstowcs (str, len); 910 wchar_t *ws = rxvt_mbstowcs (str, len);
854 char *s = rxvt_wcstoutf8 (ws); 911 char *s = rxvt_wcstoutf8 (ws);
855 912
856 XChangeProperty (dpy, parent[0], 913 XChangeProperty (dpy, parent,
857 prop, xa[XA_UTF8_STRING], 8, PropModeReplace, 914 prop, xa[XA_UTF8_STRING], 8, PropModeReplace,
858 (const unsigned char *)s, strlen (s)); 915 (const unsigned char *)s, strlen (s));
859 916
860 free (s); 917 free (s);
861 free (ws); 918 free (ws);
884 941
885void 942void
886rxvt_term::set_window_color (int idx, const char *color) 943rxvt_term::set_window_color (int idx, const char *color)
887{ 944{
888#ifdef XTERM_COLOR_CHANGE 945#ifdef XTERM_COLOR_CHANGE
889 rxvt_color xcol;
890
891 if (color == NULL || *color == '\0') 946 if (color == NULL || *color == '\0')
892 return; 947 return;
893 948
894 color = strdup (color); 949 color = strdup (color);
895 allocated.push_back ((void *)color); 950 allocated.push_back ((void *)color);
901 int i = atoi (color); 956 int i = atoi (color);
902 957
903 if (i >= 8 && i <= 15) 958 if (i >= 8 && i <= 15)
904 { 959 {
905 /* bright colors */ 960 /* bright colors */
906 pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i - 8]; 961 alias_color (idx, minBrightCOLOR + i - 8);
907 goto done; 962 goto done;
908 } 963 }
909 964
910 if (i >= 0 && i <= 7) 965 if (i >= 0 && i <= 7)
911 { 966 {
912 /* normal colors */ 967 /* normal colors */
913 pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; 968 alias_color (idx, minCOLOR + i);
914 goto done; 969 goto done;
915 } 970 }
916 } 971 }
917 972
918 set_color (xcol, color); 973 pix_colors_focused[idx].free (this);
919 974 set_color (pix_colors_focused[idx], color);
920 /*
921 * FIXME: should free colors here, but no idea how to do it so instead,
922 * so just keep gobbling up the colormap
923 */
924
925 pix_colors_focused[idx] = xcol;
926 975
927done: 976done:
928 /*TODO: handle Color_BD, scrollbar background, etc. */ 977 /*TODO: handle Color_BD, scrollbar background, etc. */
929 978
930 update_fade_color (idx); 979 update_fade_color (idx);
931 recolour_cursor (); 980 recolor_cursor ();
932 scr_recolour (); 981 scr_recolor ();
933#endif /* XTERM_COLOR_CHANGE */ 982#endif /* XTERM_COLOR_CHANGE */
934} 983}
935 984
936void 985void
937rxvt_term::recolour_cursor () 986rxvt_term::recolor_cursor ()
938{ 987{
939 XColor fg, bg; 988 XColor fg, bg;
940 989
941 (ISSET_PIXCOLOR (Color_pointer_fg) 990 (ISSET_PIXCOLOR (Color_pointer_fg)
942 ? pix_colors_focused[Color_pointer_fg] 991 ? pix_colors_focused[Color_pointer_fg]
951 1000
952/*----------------------------------------------------------------------*/ 1001/*----------------------------------------------------------------------*/
953/* 1002/*
954 * find if fg/bg matches any of the normal (low-intensity) colors 1003 * find if fg/bg matches any of the normal (low-intensity) colors
955 */ 1004 */
956void 1005char *
957rxvt_term::set_colorfgbg () 1006rxvt_term::get_colorfgbg ()
958{ 1007{
959 unsigned int i; 1008 unsigned int i;
960 const char *xpmb = ""; 1009 const char *xpmb = "";
961 char fstr[] = "default"; 1010 char fstr[] = "default";
962 char bstr[] = "default"; 1011 char bstr[] = "default";
1012 char *env_colorfgbg;
963 1013
964 for (i = Color_Black; i <= Color_White; i++) 1014 for (i = Color_Black; i <= Color_White; i++)
965 if (pix_colors[Color_fg] == pix_colors[i]) 1015 if (pix_colors[Color_fg] == pix_colors[i])
966 { 1016 {
967 sprintf (fstr, "%d", i - Color_Black); 1017 sprintf (fstr, "%d", i - Color_Black);
970 1020
971 for (i = Color_Black; i <= Color_White; i++) 1021 for (i = Color_Black; i <= Color_White; i++)
972 if (pix_colors[Color_bg] == pix_colors[i]) 1022 if (pix_colors[Color_bg] == pix_colors[i])
973 { 1023 {
974 sprintf (bstr, "%d", i - Color_Black); 1024 sprintf (bstr, "%d", i - Color_Black);
975#ifdef BG_IMAGE_FROM_FILE 1025#if HAVE_IMG
976 xpmb = "default;"; 1026 xpmb = "default;";
977#endif 1027#endif
978 break; 1028 break;
979 } 1029 }
980 1030
1031 env_colorfgbg = (char *)rxvt_malloc (sizeof ("COLORFGBG=default;default;bg"));
981 sprintf (env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr); 1032 sprintf (env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr);
1033 return env_colorfgbg;
982} 1034}
983 1035
984/*----------------------------------------------------------------------*/ 1036/*----------------------------------------------------------------------*/
985 1037
986bool 1038bool
994} 1046}
995 1047
996void 1048void
997rxvt_term::alias_color (int dst, int src) 1049rxvt_term::alias_color (int dst, int src)
998{ 1050{
1051 pix_colors[dst].free (this);
999 pix_colors[dst].set (this, rs[Rs_color + dst] = rs[Rs_color + src]); 1052 pix_colors[dst].set (this, rs[Rs_color + dst] = rs[Rs_color + src]);
1000} 1053}
1054
1055#ifdef SMART_RESIZE
1056static unsigned int
1057get_parent_bw (Display *dpy, Window w)
1058{
1059 int idummy;
1060 unsigned int udummy;
1061 Window wdummy, parent;
1062 Window *children;
1063 unsigned int nchildren, border_width;
1064
1065 XQueryTree (dpy, w, &wdummy, &parent, &children, &nchildren);
1066 XFree (children);
1067 XGetGeometry (dpy, parent, &wdummy, &idummy, &idummy,
1068 &udummy, &udummy, &border_width, &udummy);
1069
1070 return border_width;
1071}
1072#endif
1001 1073
1002/* -------------------------------------------------------------------- * 1074/* -------------------------------------------------------------------- *
1003 * - WINDOW RESIZING - * 1075 * - WINDOW RESIZING - *
1004 * -------------------------------------------------------------------- */ 1076 * -------------------------------------------------------------------- */
1005void 1077void
1015 1087
1016 // to avoid races between us and the wm, we clear the incremental size hints around the xresizewindow 1088 // to avoid races between us and the wm, we clear the incremental size hints around the xresizewindow
1017 if (set_hint) 1089 if (set_hint)
1018 { 1090 {
1019 szHint.flags &= ~(PBaseSize | PResizeInc); 1091 szHint.flags &= ~(PBaseSize | PResizeInc);
1020 XSetWMNormalHints (dpy, parent[0], &szHint); 1092 XSetWMNormalHints (dpy, parent, &szHint);
1021 szHint.flags |= PBaseSize | PResizeInc; 1093 szHint.flags |= PBaseSize | PResizeInc;
1022 } 1094 }
1023 1095
1024 if (!ignoreparent) 1096 if (!ignoreparent)
1025 { 1097 {
1031 int x, y, x1, y1; 1103 int x, y, x1, y1;
1032 int dx, dy; 1104 int dx, dy;
1033 unsigned int unused_w1, unused_h1, unused_b1, unused_d1; 1105 unsigned int unused_w1, unused_h1, unused_b1, unused_d1;
1034 Window unused_cr; 1106 Window unused_cr;
1035 1107
1036 XTranslateCoordinates (dpy, parent[0], display->root, 1108 XTranslateCoordinates (dpy, parent, display->root,
1037 0, 0, &x, &y, &unused_cr); 1109 0, 0, &x, &y, &unused_cr);
1038 XGetGeometry (dpy, parent[0], &unused_cr, &x1, &y1, 1110 XGetGeometry (dpy, parent, &unused_cr, &x1, &y1,
1039 &unused_w1, &unused_h1, &unused_b1, &unused_d1); 1111 &unused_w1, &unused_h1, &unused_b1, &unused_d1);
1040 /* 1112 /*
1041 * if display->root isn't the parent window, a WM will probably have offset 1113 * if display->root isn't the parent window, a WM will probably have offset
1042 * our position for handles and decorations. Counter it 1114 * our position for handles and decorations. Counter it
1043 */ 1115 */
1044 if (x1 != x || y1 != y) 1116 if (x1 != x || y1 != y)
1045 { 1117 {
1046 x -= x1; 1118 unsigned int border_width = get_parent_bw (dpy, parent);
1047 y -= y1; 1119
1120 x -= x1 + border_width;
1121 y -= y1 + border_width;
1048 } 1122 }
1049 1123
1050 x1 = (DisplayWidth (dpy, display->screen) - old_width ) / 2; 1124 x1 = (DisplayWidth (dpy, display->screen) - old_width ) / 2;
1051 y1 = (DisplayHeight (dpy, display->screen) - old_height) / 2; 1125 y1 = (DisplayHeight (dpy, display->screen) - old_height) / 2;
1052 dx = old_width - szHint.width; 1126 dx = old_width - szHint.width;
1060 if (y < y1) /* top half */ 1134 if (y < y1) /* top half */
1061 dy = 0; 1135 dy = 0;
1062 else if (y == y1) /* exact center */ 1136 else if (y == y1) /* exact center */
1063 dy /= 2; 1137 dy /= 2;
1064 1138
1065 XMoveResizeWindow (dpy, parent[0], x + dx, y + dy, 1139 XMoveResizeWindow (dpy, parent, x + dx, y + dy,
1066 szHint.width, szHint.height); 1140 szHint.width, szHint.height);
1067#else 1141#else
1068 XResizeWindow (dpy, parent[0], szHint.width, szHint.height); 1142 XResizeWindow (dpy, parent, szHint.width, szHint.height);
1069#endif 1143#endif
1070 } 1144 }
1071 1145
1072 if (set_hint) 1146 if (set_hint)
1073 XSetWMNormalHints (dpy, parent[0], &szHint); 1147 XSetWMNormalHints (dpy, parent, &szHint);
1074 1148
1075 fix_screen = ncol != prev_ncol || nrow != prev_nrow; 1149 fix_screen = ncol != prev_ncol || nrow != prev_nrow;
1076 1150
1077 if (fix_screen || newwidth != old_width || newheight != old_height) 1151 if (fix_screen || newwidth != old_width || newheight != old_height)
1078 { 1152 {
1079 if (scrollBar.state) 1153 if (scrollBar.state)
1080 scrollBar.resize (); 1154 scrollBar.resize ();
1081 1155
1082 XMoveResizeWindow (dpy, vt, 1156 XMoveResizeWindow (dpy, vt,
1083 window_vt_x, window_vt_y, 1157 window_vt_x, window_vt_y,
1084 width, height); 1158 vt_width, vt_height);
1085 1159
1086#ifdef HAVE_BG_PIXMAP 1160 HOOK_INVOKE ((this, HOOK_SIZE_CHANGE, DT_INT, newwidth, DT_INT, newheight, DT_END));
1087 if (bgPixmap.window_size_sensitive ())
1088 update_background ();
1089#endif
1090 } 1161 }
1091 1162
1092 if (fix_screen || old_height == 0) 1163 if (fix_screen || old_height == 0)
1093 scr_reset (); 1164 scr_reset ();
1094 1165
1095#ifdef USE_XIM 1166#if USE_XIM
1096 IMSetPosition (); 1167 im_set_position ();
1097#endif 1168#endif
1098} 1169}
1099 1170
1100/* 1171/*
1101 * Set the width/height of the vt window in characters. Units are pixels. 1172 * Set the width/height of the vt window in characters. Units are pixels.
1114 newwidth = wattr.width - szHint.base_width; 1185 newwidth = wattr.width - szHint.base_width;
1115 if (newheight == 0) 1186 if (newheight == 0)
1116 newheight = wattr.height - szHint.base_height; 1187 newheight = wattr.height - szHint.base_height;
1117 } 1188 }
1118 1189
1119 if (newwidth != width || newheight != height) 1190 if (newwidth != vt_width || newheight != vt_height)
1120 { 1191 {
1121 newwidth += szHint.base_width; 1192 newwidth += szHint.base_width;
1122 newheight += szHint.base_height; 1193 newheight += szHint.base_height;
1123 resize_all_windows (newwidth, newheight, 0); 1194 resize_all_windows (newwidth, newheight, 0);
1124 } 1195 }
1125} 1196}
1126 1197
1127/* -------------------------------------------------------------------- * 1198/* -------------------------------------------------------------------- *
1128 * - X INPUT METHOD ROUTINES - * 1199 * - X INPUT METHOD ROUTINES - *
1129 * -------------------------------------------------------------------- */ 1200 * -------------------------------------------------------------------- */
1130#ifdef USE_XIM 1201#if USE_XIM
1131 1202
1132void 1203void
1133rxvt_term::im_set_color (unsigned long &fg, unsigned long &bg) 1204rxvt_term::im_set_color (unsigned long &fg, unsigned long &bg)
1134{ 1205{
1135 fg = pix_colors [Color_fg]; 1206 fg = pix_colors [Color_fg];
1162 status_rect.height = fheight; 1233 status_rect.height = fheight;
1163} 1234}
1164 1235
1165/* Checking whether input method is running. */ 1236/* Checking whether input method is running. */
1166bool 1237bool
1167rxvt_term::IMisRunning () 1238rxvt_term::im_is_running ()
1168{ 1239{
1169 Atom atom; 1240 Atom atom;
1170 Window win; 1241 Window win;
1171 char server[IMBUFSIZ]; 1242 char server[IMBUFSIZ];
1172 1243
1181 1252
1182 atom = XInternAtom (dpy, server, False); 1253 atom = XInternAtom (dpy, server, False);
1183 win = XGetSelectionOwner (dpy, atom); 1254 win = XGetSelectionOwner (dpy, atom);
1184 1255
1185 if (win != None) 1256 if (win != None)
1186 return True; 1257 return true;
1187 } 1258 }
1188 1259
1189 return False; 1260 return false;
1190} 1261}
1191 1262
1192void 1263void
1193rxvt_term::IMSendSpot () 1264rxvt_term::im_send_spot ()
1194{ 1265{
1195 XPoint nspot; 1266 XPoint nspot;
1196 XVaNestedList preedit_attr; 1267 XVaNestedList preedit_attr;
1197 1268
1198 if (!Input_Context 1269 if (!Input_Context
1304/* 1375/*
1305 * Try to open a XIM with the current modifiers, then see if we can 1376 * Try to open a XIM with the current modifiers, then see if we can
1306 * open a suitable preedit type 1377 * open a suitable preedit type
1307 */ 1378 */
1308bool 1379bool
1309rxvt_term::IM_get_IC (const char *modifiers) 1380rxvt_term::im_get_ic (const char *modifiers)
1310{ 1381{
1311 int i, j, found; 1382 int i, j, found;
1312 XIM xim; 1383 XIM xim;
1313 XPoint spot; 1384 XPoint spot;
1314 XRectangle rect, status_rect, needed_rect; 1385 XRectangle rect, status_rect, needed_rect;
1315 unsigned long fg, bg; 1386 unsigned long fg, bg;
1316 const char *p; 1387 const char *p;
1317 char **s; 1388 char **s;
1318 XIMStyles *xim_styles; 1389 XIMStyles *xim_styles;
1319#ifdef ENABLE_XIM_ONTHESPOT
1320 XIMCallback xcb[4];
1321#endif
1322 1390
1323 set_environ (envv); 1391 set_environ (env);
1324 1392
1325 if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) 1393 if (!((p = XSetLocaleModifiers (modifiers)) && *p))
1326 return false; 1394 return false;
1327 1395
1328 input_method = display->get_xim (locale, modifiers); 1396 input_method = display->get_xim (locale, modifiers);
1329 if (input_method == NULL) 1397 if (input_method == NULL)
1330 return false; 1398 return false;
1466 NULL); 1534 NULL);
1467 } 1535 }
1468#if ENABLE_XIM_ONTHESPOT 1536#if ENABLE_XIM_ONTHESPOT
1469 else if (input_style & XIMPreeditCallbacks) 1537 else if (input_style & XIMPreeditCallbacks)
1470 { 1538 {
1539 XIMCallback xcb[4];
1540
1471 im_set_position (spot); 1541 im_set_position (spot);
1472 1542
1473 xcb[0].client_data = (XPointer)this; xcb[0].callback = (XIMProc)xim_preedit_start; 1543 xcb[0].client_data = (XPointer)this; xcb[0].callback = (XIMProc)xim_preedit_start;
1474 xcb[1].client_data = (XPointer)this; xcb[1].callback = (XIMProc)xim_preedit_done; 1544 xcb[1].client_data = (XPointer)this; xcb[1].callback = (XIMProc)xim_preedit_done;
1475 xcb[2].client_data = (XPointer)this; xcb[2].callback = (XIMProc)xim_preedit_draw; 1545 xcb[2].client_data = (XPointer)this; xcb[2].callback = (XIMProc)xim_preedit_draw;
1490#endif 1560#endif
1491 1561
1492 Input_Context = XCreateIC (xim, 1562 Input_Context = XCreateIC (xim,
1493 XNInputStyle, input_style, 1563 XNInputStyle, input_style,
1494 XNClientWindow, vt, 1564 XNClientWindow, vt,
1495 XNFocusWindow, parent[0], 1565 XNFocusWindow, parent,
1496 preedit_attr ? XNPreeditAttributes : NULL, 1566 preedit_attr ? XNPreeditAttributes : NULL,
1497 preedit_attr, 1567 preedit_attr,
1498 status_attr ? XNStatusAttributes : NULL, 1568 status_attr ? XNStatusAttributes : NULL,
1499 status_attr, NULL); 1569 status_attr, NULL);
1500 1570
1513 // unfortunately, only the focus window is used by XIM, hard to fix 1583 // unfortunately, only the focus window is used by XIM, hard to fix
1514 if (!XGetICValues (Input_Context, XNFilterEvents, &vt_emask_xim, NULL)) 1584 if (!XGetICValues (Input_Context, XNFilterEvents, &vt_emask_xim, NULL))
1515 vt_select_input (); 1585 vt_select_input ();
1516#endif 1586#endif
1517 1587
1518 IMSetPosition (); 1588 im_set_position ();
1519 1589
1520 return true; 1590 return true;
1521} 1591}
1522 1592
1523void 1593void
1533 im_destroy (); 1603 im_destroy ();
1534 1604
1535 if (Input_Context) 1605 if (Input_Context)
1536 return; 1606 return;
1537 1607
1538#if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE)
1539 if (rs[Rs_imLocale]) 1608 if (rs[Rs_imLocale])
1540 SET_LOCALE (rs[Rs_imLocale]); 1609 SET_LOCALE (rs[Rs_imLocale]);
1541#endif
1542 1610
1543 p = rs[Rs_inputMethod]; 1611 p = rs[Rs_inputMethod];
1544 if (p && *p) 1612 if (p && *p)
1545 { 1613 {
1546 bool found = false; 1614 bool found = false;
1551 { 1619 {
1552 if (*s[i]) 1620 if (*s[i])
1553 { 1621 {
1554 strcpy (buf, "@im="); 1622 strcpy (buf, "@im=");
1555 strncat (buf, s[i], IMBUFSIZ - 5); 1623 strncat (buf, s[i], IMBUFSIZ - 5);
1556 if (IM_get_IC (buf)) 1624 if (im_get_ic (buf))
1557 { 1625 {
1558 found = true; 1626 found = true;
1559 break; 1627 break;
1560 } 1628 }
1561 } 1629 }
1566 if (found) 1634 if (found)
1567 goto done; 1635 goto done;
1568 } 1636 }
1569 1637
1570 /* try with XMODIFIERS env. var. */ 1638 /* try with XMODIFIERS env. var. */
1571 if (IM_get_IC ("")) 1639 if (im_get_ic (""))
1572 goto done; 1640 goto done;
1573 1641
1574 /* try with no modifiers base IF the user didn't specify an IM */ 1642 /* try with no modifiers base IF the user didn't specify an IM */
1575 if (IM_get_IC ("@im=none")) 1643 if (im_get_ic ("@im=none"))
1576 goto done; 1644 goto done;
1577 1645
1578done: 1646done:
1579#if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE)
1580 if (rs[Rs_imLocale]) 1647 if (rs[Rs_imLocale])
1581 SET_LOCALE (locale); 1648 SET_LOCALE (locale);
1582#endif
1583} 1649}
1584 1650
1585void 1651void
1586rxvt_term::IMSetPosition () 1652rxvt_term::im_set_position ()
1587{ 1653{
1588 XRectangle preedit_rect, status_rect, *needed_rect; 1654 XRectangle preedit_rect, status_rect, *needed_rect;
1589 XVaNestedList preedit_attr, status_attr; 1655 XVaNestedList preedit_attr, status_attr;
1590 1656
1591 if (!Input_Context 1657 if (!Input_Context
1592 || !focus 1658 || !focus
1593 || !(input_style & (XIMPreeditArea | XIMPreeditPosition)) 1659 || !(input_style & (XIMPreeditArea | XIMPreeditPosition))
1594 || !IMisRunning ()) 1660 || !im_is_running ())
1595 return; 1661 return;
1596 1662
1597 if (input_style & XIMPreeditPosition) 1663 if (input_style & XIMPreeditPosition)
1598 { 1664 {
1599 im_set_size (preedit_rect); 1665 im_set_size (preedit_rect);
1629 1695
1630void 1696void
1631rxvt_term::get_window_origin (int &x, int &y) 1697rxvt_term::get_window_origin (int &x, int &y)
1632{ 1698{
1633 Window cr; 1699 Window cr;
1634 XTranslateCoordinates (dpy, parent[0], display->root, 0, 0, &x, &y, &cr); 1700 XTranslateCoordinates (dpy, parent, display->root, 0, 0, &x, &y, &cr);
1635} 1701}
1636
1637Pixmap
1638rxvt_term::get_pixmap_property (Atom property)
1639{
1640 Pixmap pixmap = None;
1641
1642 int aformat;
1643 unsigned long nitems, bytes_after;
1644 Atom atype;
1645 unsigned char *prop;
1646 int result = XGetWindowProperty (dpy, display->root, property,
1647 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
1648 &nitems, &bytes_after, &prop);
1649 if (result == Success)
1650 {
1651 if (atype == XA_PIXMAP)
1652 pixmap = *(Pixmap *)prop;
1653 XFree (prop);
1654 }
1655
1656 return pixmap;
1657}
1658
1659#ifdef HAVE_BG_PIXMAP
1660
1661void
1662rxvt_term::update_background ()
1663{
1664 if (update_background_ev.is_active ())
1665 return;
1666
1667 bgPixmap.invalidate ();
1668
1669 ev_tstamp to_wait = 0.5 - (ev::now () - bgPixmap.valid_since);
1670
1671 if (to_wait <= 0.)
1672 bgPixmap.render ();
1673 else
1674 update_background_ev.start (to_wait);
1675}
1676
1677void
1678rxvt_term::update_background_cb (ev::timer &w, int revents)
1679{
1680 make_current ();
1681
1682 update_background_ev.stop ();
1683 bgPixmap.render ();
1684 refresh_check ();
1685}
1686
1687#endif /* HAVE_BG_PIXMAP */
1688 1702
1689/*----------------------- end-of-file (C source) -----------------------*/ 1703/*----------------------- end-of-file (C source) -----------------------*/

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines