… | |
… | |
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 | |
56 | struct termios rxvt_term::def_tio; |
55 | struct termios rxvt_term::def_tio; |
57 | vector<rxvt_term *> rxvt_term::termlist; |
56 | vector<rxvt_term *> rxvt_term::termlist; |
58 | |
57 | |
… | |
… | |
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) |
… | |
… | |
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 BG_IMAGE_FROM_ROOT || 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 | |
… | |
… | |
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 | #ifdef HAVE_BG_PIXMAP |
231 | bgPixmap.destroy (); |
229 | bg_destroy (); |
232 | #endif |
230 | #endif |
233 | #ifdef HAVE_AFTERIMAGE |
231 | |
234 | if (asv) |
232 | #if HAVE_IMG |
235 | destroy_asvisual (asv, 0); |
233 | delete bg_img; |
236 | if (asimman) |
|
|
237 | destroy_image_manager (asimman, 0); |
|
|
238 | #endif |
234 | #endif |
239 | |
235 | |
240 | if (display) |
236 | if (display) |
241 | { |
237 | { |
242 | selection_clear (); |
238 | selection_clear (); |
243 | selection_clear (true); |
239 | selection_clear (true); |
244 | |
240 | |
245 | #ifdef USE_XIM |
241 | #if USE_XIM |
246 | im_destroy (); |
242 | im_destroy (); |
247 | #endif |
243 | #endif |
248 | scrollBar.destroy (); |
244 | scrollBar.destroy (); |
|
|
245 | |
|
|
246 | if (gc) |
249 | if (gc) XFreeGC (dpy, gc); |
247 | XFreeGC (dpy, gc); |
250 | |
248 | |
251 | delete drawable; |
249 | delete drawable; |
|
|
250 | |
252 | // destroy all windows |
251 | // destroy all windows |
253 | if (parent[0]) |
252 | if (parent) |
254 | XDestroyWindow (dpy, parent[0]); |
253 | XDestroyWindow (dpy, parent); |
255 | |
254 | |
256 | for (int i = 0; i < TOTAL_COLORS; i++) |
255 | for (int i = 0; i < TOTAL_COLORS; i++) |
257 | if (ISSET_PIXCOLOR (i)) |
256 | if (ISSET_PIXCOLOR (i)) |
258 | { |
257 | { |
259 | pix_colors_focused [i].free (this); |
258 | pix_colors_focused [i].free (this); |
260 | #if OFF_FOCUS_FADING |
259 | #if OFF_FOCUS_FADING |
|
|
260 | if (rs[Rs_fade]) |
261 | pix_colors_unfocused [i].free (this); |
261 | pix_colors_unfocused [i].free (this); |
262 | #endif |
262 | #endif |
263 | } |
263 | } |
264 | |
264 | |
265 | clear (); |
265 | clear (); |
266 | |
266 | |
… | |
… | |
274 | for (int i = 0; i < allocated.size (); i++) |
274 | for (int i = 0; i < allocated.size (); i++) |
275 | free (allocated [i]); |
275 | free (allocated [i]); |
276 | |
276 | |
277 | free (selection.text); |
277 | free (selection.text); |
278 | free (selection.clip_text); |
278 | free (selection.clip_text); |
279 | // TODO: manage env vars in child only(!) |
|
|
280 | free (env_display); |
|
|
281 | free (env_term); |
|
|
282 | free (locale); |
279 | free (locale); |
283 | free (v_buffer); |
280 | free (v_buffer); |
284 | free (incr_buf); |
281 | |
|
|
282 | delete selection_req; |
|
|
283 | |
|
|
284 | if (env && memcmp (env, envv->begin (), envv->size () * sizeof (char *))) |
|
|
285 | rxvt_warn ("env has been modified, probably as a result of a lib calling setenv.\n"); |
|
|
286 | |
|
|
287 | delete [] env; |
285 | |
288 | |
286 | delete envv; |
289 | delete envv; |
287 | delete argv; |
290 | delete argv; |
288 | |
291 | |
289 | #ifdef KEYSYM_RESOURCE |
292 | #ifdef KEYSYM_RESOURCE |
290 | delete keyboard; |
293 | delete keyboard; |
291 | #endif |
294 | #endif |
292 | #ifndef NO_RESOURCES |
295 | #ifndef NO_RESOURCES |
293 | XrmDestroyDatabase (option_db); |
296 | XrmDestroyDatabase (option_db); |
294 | #endif |
297 | #endif |
|
|
298 | |
|
|
299 | SET_R ((rxvt_term *)0); |
295 | } |
300 | } |
296 | |
301 | |
297 | // child has exited, usually destroys |
302 | // child has exited, usually destroys |
298 | void |
303 | void |
299 | rxvt_term::child_cb (ev::child &w, int status) |
304 | rxvt_term::child_cb (ev::child &w, int status) |
… | |
… | |
322 | { |
327 | { |
323 | #if USE_XIM |
328 | #if USE_XIM |
324 | im_ev.stop (display); |
329 | im_ev.stop (display); |
325 | #endif |
330 | #endif |
326 | scrollbar_ev.stop (display); |
331 | scrollbar_ev.stop (display); |
327 | #if ENABLE_TRANSPARENCY || ENABLE_PERL |
332 | #if BG_IMAGE_FROM_ROOT || ENABLE_PERL |
328 | rootwin_ev.stop (display); |
333 | rootwin_ev.stop (display); |
329 | #endif |
334 | #endif |
330 | incr_ev.stop (); |
|
|
331 | termwin_ev.stop (display); |
335 | termwin_ev.stop (display); |
332 | vt_ev.stop (display); |
336 | vt_ev.stop (display); |
333 | } |
337 | } |
334 | |
338 | |
335 | flush_ev.stop (); |
339 | flush_ev.stop (); |
… | |
… | |
360 | |
364 | |
361 | delete this; |
365 | delete this; |
362 | } |
366 | } |
363 | |
367 | |
364 | void |
368 | void |
365 | rxvt_term::set_option (uint8_t opt, bool set) |
369 | rxvt_term::set_option (uint8_t opt, bool set) NOTHROW |
366 | { |
370 | { |
367 | if (!opt) |
371 | if (!opt) |
368 | return; |
372 | return; |
369 | |
373 | |
370 | uint8_t mask = 1 << (opt & 7); |
374 | uint8_t mask = 1 << (opt & 7); |
… | |
… | |
374 | } |
378 | } |
375 | |
379 | |
376 | /*----------------------------------------------------------------------*/ |
380 | /*----------------------------------------------------------------------*/ |
377 | /* |
381 | /* |
378 | * Exit gracefully, clearing the utmp entry and restoring tty attributes |
382 | * 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 | */ |
383 | */ |
381 | static XErrorHandler old_xerror_handler; |
384 | static XErrorHandler old_xerror_handler; |
382 | |
385 | |
383 | static void |
386 | static void |
384 | rxvt_emergency_cleanup () |
387 | rxvt_emergency_cleanup () |
… | |
… | |
386 | for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++) |
389 | for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++) |
387 | (*t)->emergency_cleanup (); |
390 | (*t)->emergency_cleanup (); |
388 | } |
391 | } |
389 | |
392 | |
390 | #if !ENABLE_MINIMAL |
393 | #if !ENABLE_MINIMAL |
391 | static void |
394 | static void ecb_cold |
392 | print_x_error (Display *dpy, XErrorEvent *event) |
395 | print_x_error (Display *dpy, XErrorEvent *event) |
393 | { |
396 | { |
394 | char buffer[BUFSIZ]; |
397 | char buffer[BUFSIZ]; |
395 | char mesg[BUFSIZ]; |
398 | char mesg[BUFSIZ]; |
396 | char number[32]; |
399 | char number[32]; |
397 | const char mtype[] = "XlibMessage"; |
400 | |
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"); |
401 | rxvt_warn ("An X Error occurred, trying to continue after report.\n"); |
|
|
402 | |
|
|
403 | XGetErrorDatabaseText (dpy, "XlibMessage", "ErrorSerial", "Error Serial #%d", mesg, BUFSIZ); |
|
|
404 | snprintf (buffer, BUFSIZ, "+ %s\n", mesg); rxvt_warn (buffer, event->serial); |
|
|
405 | |
|
|
406 | XGetErrorText (dpy, event->error_code, buffer, BUFSIZ); |
|
|
407 | XGetErrorDatabaseText (dpy, "XlibMessage", "XError", "X Error", mesg, BUFSIZ); |
401 | rxvt_warn ("%s: %s\n", mesg, buffer); |
408 | rxvt_warn ("+ %s: %s\n", mesg, buffer); |
|
|
409 | |
402 | XGetErrorDatabaseText(dpy, mtype, "MajorCode", "Request Major code %d", mesg, BUFSIZ); |
410 | XGetErrorDatabaseText (dpy, "XlibMessage", "MajorCode", "Request Major code %d", mesg, BUFSIZ); |
403 | rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->request_code); |
411 | snprintf (buffer, BUFSIZ, "+ %s\n", mesg); rxvt_warn (buffer, event->request_code); |
|
|
412 | |
|
|
413 | if (event->request_code >= 128) |
|
|
414 | { |
|
|
415 | #if 0 |
|
|
416 | /* XListExtensions and probably query extensions hangs when there are multiple queues errors */ |
|
|
417 | int nexts; |
|
|
418 | char **exts = XListExtensions (dpy, &nexts); |
|
|
419 | |
|
|
420 | while (nexts) |
|
|
421 | { |
|
|
422 | char *extname = exts [nexts - 1]; |
|
|
423 | int major, first_event, first_error; |
|
|
424 | |
|
|
425 | if (XQueryExtension (dpy, extname, &major, &first_event, &first_error) && major == event->request_code) |
|
|
426 | { |
|
|
427 | XGetErrorDatabaseText (dpy, "XlibMessage", "MinorCode", "Request Minor code %d", mesg, BUFSIZ); |
|
|
428 | rxvt_warn ("+ (which is extension %s minor code %d)\n", extname, event->minor_code); |
|
|
429 | |
|
|
430 | snprintf (buffer, BUFSIZ, "%s.%d", extname, event->minor_code); |
|
|
431 | XGetErrorDatabaseText (dpy, "XRequest", buffer, "an unregistered minor code", buffer, BUFSIZ); |
|
|
432 | rxvt_warn ("+ (which is %s)\n", buffer); |
|
|
433 | |
|
|
434 | break; |
|
|
435 | } |
|
|
436 | |
|
|
437 | printf ("nextss %d %s\n", nexts, extname);//D |
|
|
438 | --nexts; |
|
|
439 | ++exts; |
|
|
440 | } |
|
|
441 | #else |
|
|
442 | int nexts = 0; |
|
|
443 | char **exts = 0; |
|
|
444 | #endif |
|
|
445 | |
|
|
446 | if (!nexts) |
|
|
447 | { |
|
|
448 | rxvt_warn ("+ (which is an unknown extension)\n", buffer); |
|
|
449 | |
|
|
450 | XGetErrorDatabaseText (dpy, "XlibMessage", "MinorCode", "Request Minor code %d", mesg, BUFSIZ); |
|
|
451 | snprintf (buffer, BUFSIZ, "+ %s\n", mesg); rxvt_warn (buffer, event->minor_code); |
|
|
452 | |
|
|
453 | #if 0 |
|
|
454 | sprintf (number, "RENDER.%d", event->minor_code); |
|
|
455 | XGetErrorDatabaseText (dpy, "XRequest", number, "", buffer, BUFSIZ); |
|
|
456 | rxvt_warn ("+ (which is %s)\n", buffer); |
|
|
457 | #endif |
|
|
458 | } |
|
|
459 | |
|
|
460 | XFreeExtensionList (exts); |
|
|
461 | } |
|
|
462 | else |
|
|
463 | { |
404 | sprintf(number, "%d", event->request_code); |
464 | sprintf (number, "%d", event->request_code); |
405 | XGetErrorDatabaseText(dpy, "XRequest", number, "", buffer, BUFSIZ); |
465 | XGetErrorDatabaseText (dpy, "XRequest", number, "", buffer, BUFSIZ); |
406 | rxvt_warn ("(which is %s)\n", buffer); |
466 | 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 | } |
467 | } |
|
|
468 | |
412 | if ((event->error_code == BadWindow) || |
469 | if (event->error_code == BadWindow |
413 | (event->error_code == BadPixmap) || |
470 | || event->error_code == BadPixmap |
414 | (event->error_code == BadCursor) || |
471 | || event->error_code == BadCursor |
415 | (event->error_code == BadFont) || |
472 | || event->error_code == BadFont |
416 | (event->error_code == BadDrawable) || |
473 | || event->error_code == BadDrawable |
417 | (event->error_code == BadColor) || |
474 | || event->error_code == BadColor |
418 | (event->error_code == BadGC) || |
475 | || event->error_code == BadGC |
419 | (event->error_code == BadIDChoice) || |
476 | || event->error_code == BadIDChoice |
420 | (event->error_code == BadValue) || |
477 | || event->error_code == BadValue |
421 | (event->error_code == BadAtom)) { |
478 | || event->error_code == BadAtom) |
|
|
479 | { |
422 | if (event->error_code == BadValue) |
480 | if (event->error_code == BadValue) |
423 | XGetErrorDatabaseText(dpy, mtype, "Value", "Value 0x%x", |
481 | XGetErrorDatabaseText (dpy, "XlibMessage", "Value", "Value 0x%x", mesg, BUFSIZ); |
424 | mesg, BUFSIZ); |
|
|
425 | else if (event->error_code == BadAtom) |
482 | else if (event->error_code == BadAtom) |
426 | XGetErrorDatabaseText(dpy, mtype, "AtomID", "AtomID 0x%x", |
483 | XGetErrorDatabaseText (dpy, "XlibMessage", "AtomID", "AtomID 0x%x", mesg, BUFSIZ); |
427 | mesg, BUFSIZ); |
|
|
428 | else |
484 | else |
429 | XGetErrorDatabaseText(dpy, mtype, "ResourceID", "ResourceID 0x%x", |
485 | 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 | |
486 | |
439 | int |
487 | snprintf (buffer, BUFSIZ, "+ %s\n", mesg); rxvt_warn (buffer, event->resourceid); |
|
|
488 | } |
|
|
489 | } |
|
|
490 | #endif |
|
|
491 | |
|
|
492 | int ecb_cold |
440 | rxvt_xerror_handler (Display *display, XErrorEvent *event) |
493 | rxvt_xerror_handler (Display *display, XErrorEvent *event) |
441 | { |
494 | { |
442 | if (GET_R->allowedxerror == -1) |
495 | if (GET_R && GET_R->allowedxerror == -1) |
443 | GET_R->allowedxerror = event->error_code; |
496 | GET_R->allowedxerror = event->error_code; |
444 | else |
497 | else |
445 | { |
498 | { |
446 | // GET_R is most likely not the terminal which caused the error, |
499 | // GET_R is most likely not the terminal which caused the error, |
447 | // so just output the error and continue |
500 | // so just output the error and continue |
… | |
… | |
453 | } |
506 | } |
454 | |
507 | |
455 | return 0; |
508 | return 0; |
456 | } |
509 | } |
457 | |
510 | |
458 | int |
511 | int ecb_cold |
459 | rxvt_xioerror_handler (Display *display) |
512 | rxvt_xioerror_handler (Display *display) |
460 | { |
513 | { |
461 | rxvt_warn ("X connection to '%s' broken, unable to recover, exiting.\n", |
514 | rxvt_warn ("X connection to '%s' broken, unable to recover, exiting.\n", |
462 | DisplayString (display)); |
515 | DisplayString (display)); |
463 | rxvt_emergency_cleanup (); |
516 | rxvt_emergency_cleanup (); |
… | |
… | |
583 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
636 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
584 | // TODO: handle this with exceptions and tolerate the memory loss |
637 | // TODO: handle this with exceptions and tolerate the memory loss |
585 | XSetIOErrorHandler (rxvt_xioerror_handler); |
638 | XSetIOErrorHandler (rxvt_xioerror_handler); |
586 | |
639 | |
587 | XrmInitialize (); |
640 | XrmInitialize (); |
|
|
641 | |
|
|
642 | #if HAVE_PIXBUF |
|
|
643 | g_type_init (); |
|
|
644 | #endif |
588 | } |
645 | } |
589 | |
646 | |
590 | /*----------------------------------------------------------------------*/ |
647 | /*----------------------------------------------------------------------*/ |
591 | /* |
648 | /* |
592 | * window size/position calculations for XSizeHint and other storage. |
649 | * window size/position calculations for XSizeHint and other storage. |
… | |
… | |
713 | if (recalc_y) |
770 | if (recalc_y) |
714 | szHint.y += DisplayHeight (dpy, display->screen) - szHint.height - 2 * ext_bwidth; |
771 | szHint.y += DisplayHeight (dpy, display->screen) - szHint.height - 2 * ext_bwidth; |
715 | |
772 | |
716 | ncol = width / fwidth; |
773 | ncol = width / fwidth; |
717 | nrow = height / fheight; |
774 | nrow = height / fheight; |
|
|
775 | |
|
|
776 | // When the size of the vt window is not a multiple of the cell |
|
|
777 | // size, i.e., when the wm does not honour our size hints, there are |
|
|
778 | // extra areas not covered by the terminal screen. Such gaps, when a |
|
|
779 | // bg pixmap is set, would have to be cleared manually to properly |
|
|
780 | // refresh the background. We take the simpler route and shrink the |
|
|
781 | // vt window so as to avoid creating gaps. |
|
|
782 | vt_width = ncol * fwidth; |
|
|
783 | vt_height = nrow * fheight; |
718 | } |
784 | } |
719 | |
785 | |
720 | /*----------------------------------------------------------------------*/ |
786 | /*----------------------------------------------------------------------*/ |
721 | /* |
787 | /* |
722 | * Tell the teletype handler what size the window is. |
788 | * Tell the teletype handler what size the window is. |
… | |
… | |
730 | |
796 | |
731 | struct winsize ws; |
797 | struct winsize ws; |
732 | |
798 | |
733 | ws.ws_col = ncol; |
799 | ws.ws_col = ncol; |
734 | ws.ws_row = nrow; |
800 | ws.ws_row = nrow; |
735 | ws.ws_xpixel = width; |
801 | ws.ws_xpixel = vt_width; |
736 | ws.ws_ypixel = height; |
802 | ws.ws_ypixel = vt_height; |
737 | ioctl (pty->pty, TIOCSWINSZ, &ws); |
803 | ioctl (pty->pty, TIOCSWINSZ, &ws); |
738 | |
804 | |
739 | #if 0 |
805 | #if 0 |
740 | // TIOCSWINSZ is supposed to do this automatically and correctly |
806 | // TIOCSWINSZ is supposed to do this automatically and correctly |
741 | if (cmd_pid) /* force through to the command */ |
807 | if (cmd_pid) /* force through to the command */ |
742 | kill (-cmd_pid, SIGWINCH); |
808 | kill (-cmd_pid, SIGWINCH); |
743 | #endif |
809 | #endif |
744 | } |
810 | } |
745 | |
811 | |
746 | /*----------------------------------------------------------------------*/ |
812 | /*----------------------------------------------------------------------*/ |
747 | /* set_fonts () - load and set the various fonts |
813 | /* 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 | */ |
|
|
754 | bool |
814 | bool |
755 | rxvt_term::set_fonts () |
815 | rxvt_term::set_fonts () |
756 | { |
816 | { |
757 | rxvt_fontset *fs = new rxvt_fontset (this); |
817 | rxvt_fontset *fs = new rxvt_fontset (this); |
758 | rxvt_fontprop prop; |
818 | rxvt_fontprop prop; |
… | |
… | |
773 | |
833 | |
774 | delete fontset[0]; |
834 | delete fontset[0]; |
775 | fontset[0] = fs; |
835 | fontset[0] = fs; |
776 | |
836 | |
777 | prop = (*fs)[rxvt_fontset::firstFont]->properties (); |
837 | prop = (*fs)[rxvt_fontset::firstFont]->properties (); |
778 | prop.height += lineSpace; |
838 | prop.width = max (prop.width + letterSpace, 1); |
779 | prop.width += letterSpace; |
|
|
780 | |
839 | |
781 | fs->set_prop (prop, false); |
840 | fs->set_prop (prop, false); |
782 | |
841 | |
783 | fwidth = prop.width; |
842 | fwidth = prop.width; |
784 | fheight = prop.height; |
843 | fheight = prop.height + lineSpace; |
785 | fbase = prop.ascent; |
844 | fbase = prop.ascent; |
786 | |
845 | |
787 | for (int style = 1; style < 4; style++) |
846 | for (int style = 1; style < 4; style++) |
788 | { |
847 | { |
789 | #if ENABLE_STYLES |
848 | #if ENABLE_STYLES |
… | |
… | |
815 | #else |
874 | #else |
816 | fontset[style] = fontset[0]; |
875 | fontset[style] = fontset[0]; |
817 | #endif |
876 | #endif |
818 | } |
877 | } |
819 | |
878 | |
820 | if (parent[0]) |
879 | if (parent) |
821 | { |
880 | { |
822 | resize_all_windows (0, 0, 0); |
881 | resize_all_windows (0, 0, 0); |
823 | scr_remap_chars (); |
882 | scr_remap_chars (); |
824 | scr_touch (true); |
883 | scr_touch (true); |
825 | } |
884 | } |
… | |
… | |
828 | } |
887 | } |
829 | |
888 | |
830 | void |
889 | void |
831 | rxvt_term::set_string_property (Atom prop, const char *str, int len) |
890 | rxvt_term::set_string_property (Atom prop, const char *str, int len) |
832 | { |
891 | { |
833 | XChangeProperty (dpy, parent[0], |
892 | XChangeProperty (dpy, parent, |
834 | prop, XA_STRING, 8, PropModeReplace, |
893 | prop, XA_STRING, 8, PropModeReplace, |
835 | (const unsigned char *)str, len >= 0 ? len : strlen (str)); |
894 | (const unsigned char *)str, len >= 0 ? len : strlen (str)); |
836 | } |
895 | } |
837 | |
896 | |
838 | void |
897 | void |
… | |
… | |
840 | { |
899 | { |
841 | XTextProperty ct; |
900 | XTextProperty ct; |
842 | |
901 | |
843 | if (XmbTextListToTextProperty (dpy, (char **)&str, 1, XStdICCTextStyle, &ct) >= 0) |
902 | if (XmbTextListToTextProperty (dpy, (char **)&str, 1, XStdICCTextStyle, &ct) >= 0) |
844 | { |
903 | { |
845 | XSetTextProperty (dpy, parent[0], &ct, prop); |
904 | XSetTextProperty (dpy, parent, &ct, prop); |
846 | XFree (ct.value); |
905 | XFree (ct.value); |
847 | } |
906 | } |
848 | } |
907 | } |
849 | |
908 | |
850 | void |
909 | void |
851 | rxvt_term::set_utf8_property (Atom prop, const char *str, int len) |
910 | rxvt_term::set_utf8_property (Atom prop, const char *str, int len) |
852 | { |
911 | { |
853 | wchar_t *ws = rxvt_mbstowcs (str, len); |
912 | wchar_t *ws = rxvt_mbstowcs (str, len); |
854 | char *s = rxvt_wcstoutf8 (ws); |
913 | char *s = rxvt_wcstoutf8 (ws); |
855 | |
914 | |
856 | XChangeProperty (dpy, parent[0], |
915 | XChangeProperty (dpy, parent, |
857 | prop, xa[XA_UTF8_STRING], 8, PropModeReplace, |
916 | prop, xa[XA_UTF8_STRING], 8, PropModeReplace, |
858 | (const unsigned char *)s, strlen (s)); |
917 | (const unsigned char *)s, strlen (s)); |
859 | |
918 | |
860 | free (s); |
919 | free (s); |
861 | free (ws); |
920 | free (ws); |
… | |
… | |
884 | |
943 | |
885 | void |
944 | void |
886 | rxvt_term::set_window_color (int idx, const char *color) |
945 | rxvt_term::set_window_color (int idx, const char *color) |
887 | { |
946 | { |
888 | #ifdef XTERM_COLOR_CHANGE |
947 | #ifdef XTERM_COLOR_CHANGE |
889 | rxvt_color xcol; |
|
|
890 | |
|
|
891 | if (color == NULL || *color == '\0') |
948 | if (color == NULL || *color == '\0') |
892 | return; |
949 | return; |
893 | |
950 | |
894 | color = strdup (color); |
951 | color = strdup (color); |
895 | allocated.push_back ((void *)color); |
952 | allocated.push_back ((void *)color); |
… | |
… | |
901 | int i = atoi (color); |
958 | int i = atoi (color); |
902 | |
959 | |
903 | if (i >= 8 && i <= 15) |
960 | if (i >= 8 && i <= 15) |
904 | { |
961 | { |
905 | /* bright colors */ |
962 | /* bright colors */ |
906 | pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i - 8]; |
963 | alias_color (idx, minBrightCOLOR + i - 8); |
907 | goto done; |
964 | goto done; |
908 | } |
965 | } |
909 | |
966 | |
910 | if (i >= 0 && i <= 7) |
967 | if (i >= 0 && i <= 7) |
911 | { |
968 | { |
912 | /* normal colors */ |
969 | /* normal colors */ |
913 | pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; |
970 | alias_color (idx, minCOLOR + i); |
914 | goto done; |
971 | goto done; |
915 | } |
972 | } |
916 | } |
973 | } |
917 | |
974 | |
918 | set_color (xcol, color); |
975 | pix_colors_focused[idx].free (this); |
919 | |
976 | 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 | |
977 | |
927 | done: |
978 | done: |
928 | /*TODO: handle Color_BD, scrollbar background, etc. */ |
979 | /*TODO: handle Color_BD, scrollbar background, etc. */ |
929 | |
980 | |
930 | update_fade_color (idx); |
981 | update_fade_color (idx); |
931 | recolour_cursor (); |
982 | recolor_cursor (); |
932 | scr_recolour (); |
983 | scr_recolor (); |
933 | #endif /* XTERM_COLOR_CHANGE */ |
984 | #endif /* XTERM_COLOR_CHANGE */ |
934 | } |
985 | } |
935 | |
986 | |
936 | void |
987 | void |
937 | rxvt_term::recolour_cursor () |
988 | rxvt_term::recolor_cursor () |
938 | { |
989 | { |
939 | XColor fg, bg; |
990 | XColor fg, bg; |
940 | |
991 | |
941 | (ISSET_PIXCOLOR (Color_pointer_fg) |
992 | (ISSET_PIXCOLOR (Color_pointer_fg) |
942 | ? pix_colors_focused[Color_pointer_fg] |
993 | ? pix_colors_focused[Color_pointer_fg] |
… | |
… | |
951 | |
1002 | |
952 | /*----------------------------------------------------------------------*/ |
1003 | /*----------------------------------------------------------------------*/ |
953 | /* |
1004 | /* |
954 | * find if fg/bg matches any of the normal (low-intensity) colors |
1005 | * find if fg/bg matches any of the normal (low-intensity) colors |
955 | */ |
1006 | */ |
956 | void |
1007 | char * |
957 | rxvt_term::set_colorfgbg () |
1008 | rxvt_term::get_colorfgbg () |
958 | { |
1009 | { |
959 | unsigned int i; |
1010 | unsigned int i; |
960 | const char *xpmb = ""; |
1011 | const char *xpmb = ""; |
961 | char fstr[] = "default"; |
1012 | char fstr[] = "default"; |
962 | char bstr[] = "default"; |
1013 | char bstr[] = "default"; |
|
|
1014 | char *env_colorfgbg; |
963 | |
1015 | |
964 | for (i = Color_Black; i <= Color_White; i++) |
1016 | for (i = Color_Black; i <= Color_White; i++) |
965 | if (pix_colors[Color_fg] == pix_colors[i]) |
1017 | if (pix_colors[Color_fg] == pix_colors[i]) |
966 | { |
1018 | { |
967 | sprintf (fstr, "%d", i - Color_Black); |
1019 | sprintf (fstr, "%d", i - Color_Black); |
… | |
… | |
970 | |
1022 | |
971 | for (i = Color_Black; i <= Color_White; i++) |
1023 | for (i = Color_Black; i <= Color_White; i++) |
972 | if (pix_colors[Color_bg] == pix_colors[i]) |
1024 | if (pix_colors[Color_bg] == pix_colors[i]) |
973 | { |
1025 | { |
974 | sprintf (bstr, "%d", i - Color_Black); |
1026 | sprintf (bstr, "%d", i - Color_Black); |
975 | #ifdef BG_IMAGE_FROM_FILE |
1027 | #if BG_IMAGE_FROM_FILE |
976 | xpmb = "default;"; |
1028 | xpmb = "default;"; |
977 | #endif |
1029 | #endif |
978 | break; |
1030 | break; |
979 | } |
1031 | } |
980 | |
1032 | |
|
|
1033 | env_colorfgbg = (char *)rxvt_malloc (sizeof ("COLORFGBG=default;default;bg")); |
981 | sprintf (env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr); |
1034 | sprintf (env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr); |
|
|
1035 | return env_colorfgbg; |
982 | } |
1036 | } |
983 | |
1037 | |
984 | /*----------------------------------------------------------------------*/ |
1038 | /*----------------------------------------------------------------------*/ |
985 | |
1039 | |
986 | bool |
1040 | bool |
… | |
… | |
994 | } |
1048 | } |
995 | |
1049 | |
996 | void |
1050 | void |
997 | rxvt_term::alias_color (int dst, int src) |
1051 | rxvt_term::alias_color (int dst, int src) |
998 | { |
1052 | { |
|
|
1053 | pix_colors[dst].free (this); |
999 | pix_colors[dst].set (this, rs[Rs_color + dst] = rs[Rs_color + src]); |
1054 | pix_colors[dst].set (this, rs[Rs_color + dst] = rs[Rs_color + src]); |
1000 | } |
1055 | } |
|
|
1056 | |
|
|
1057 | #ifdef SMART_RESIZE |
|
|
1058 | static unsigned int |
|
|
1059 | get_parent_bw (Display *dpy, Window w) |
|
|
1060 | { |
|
|
1061 | int idummy; |
|
|
1062 | unsigned int udummy; |
|
|
1063 | Window wdummy, parent; |
|
|
1064 | Window *children; |
|
|
1065 | unsigned int nchildren, border_width; |
|
|
1066 | |
|
|
1067 | XQueryTree (dpy, w, &wdummy, &parent, &children, &nchildren); |
|
|
1068 | XFree (children); |
|
|
1069 | XGetGeometry (dpy, parent, &wdummy, &idummy, &idummy, |
|
|
1070 | &udummy, &udummy, &border_width, &udummy); |
|
|
1071 | |
|
|
1072 | return border_width; |
|
|
1073 | } |
|
|
1074 | #endif |
1001 | |
1075 | |
1002 | /* -------------------------------------------------------------------- * |
1076 | /* -------------------------------------------------------------------- * |
1003 | * - WINDOW RESIZING - * |
1077 | * - WINDOW RESIZING - * |
1004 | * -------------------------------------------------------------------- */ |
1078 | * -------------------------------------------------------------------- */ |
1005 | void |
1079 | void |
… | |
… | |
1015 | |
1089 | |
1016 | // to avoid races between us and the wm, we clear the incremental size hints around the xresizewindow |
1090 | // to avoid races between us and the wm, we clear the incremental size hints around the xresizewindow |
1017 | if (set_hint) |
1091 | if (set_hint) |
1018 | { |
1092 | { |
1019 | szHint.flags &= ~(PBaseSize | PResizeInc); |
1093 | szHint.flags &= ~(PBaseSize | PResizeInc); |
1020 | XSetWMNormalHints (dpy, parent[0], &szHint); |
1094 | XSetWMNormalHints (dpy, parent, &szHint); |
1021 | szHint.flags |= PBaseSize | PResizeInc; |
1095 | szHint.flags |= PBaseSize | PResizeInc; |
1022 | } |
1096 | } |
1023 | |
1097 | |
1024 | if (!ignoreparent) |
1098 | if (!ignoreparent) |
1025 | { |
1099 | { |
… | |
… | |
1031 | int x, y, x1, y1; |
1105 | int x, y, x1, y1; |
1032 | int dx, dy; |
1106 | int dx, dy; |
1033 | unsigned int unused_w1, unused_h1, unused_b1, unused_d1; |
1107 | unsigned int unused_w1, unused_h1, unused_b1, unused_d1; |
1034 | Window unused_cr; |
1108 | Window unused_cr; |
1035 | |
1109 | |
1036 | XTranslateCoordinates (dpy, parent[0], display->root, |
1110 | XTranslateCoordinates (dpy, parent, display->root, |
1037 | 0, 0, &x, &y, &unused_cr); |
1111 | 0, 0, &x, &y, &unused_cr); |
1038 | XGetGeometry (dpy, parent[0], &unused_cr, &x1, &y1, |
1112 | XGetGeometry (dpy, parent, &unused_cr, &x1, &y1, |
1039 | &unused_w1, &unused_h1, &unused_b1, &unused_d1); |
1113 | &unused_w1, &unused_h1, &unused_b1, &unused_d1); |
1040 | /* |
1114 | /* |
1041 | * if display->root isn't the parent window, a WM will probably have offset |
1115 | * if display->root isn't the parent window, a WM will probably have offset |
1042 | * our position for handles and decorations. Counter it |
1116 | * our position for handles and decorations. Counter it |
1043 | */ |
1117 | */ |
1044 | if (x1 != x || y1 != y) |
1118 | if (x1 != x || y1 != y) |
1045 | { |
1119 | { |
1046 | x -= x1; |
1120 | unsigned int border_width = get_parent_bw (dpy, parent); |
1047 | y -= y1; |
1121 | |
|
|
1122 | x -= x1 + border_width; |
|
|
1123 | y -= y1 + border_width; |
1048 | } |
1124 | } |
1049 | |
1125 | |
1050 | x1 = (DisplayWidth (dpy, display->screen) - old_width ) / 2; |
1126 | x1 = (DisplayWidth (dpy, display->screen) - old_width ) / 2; |
1051 | y1 = (DisplayHeight (dpy, display->screen) - old_height) / 2; |
1127 | y1 = (DisplayHeight (dpy, display->screen) - old_height) / 2; |
1052 | dx = old_width - szHint.width; |
1128 | dx = old_width - szHint.width; |
… | |
… | |
1060 | if (y < y1) /* top half */ |
1136 | if (y < y1) /* top half */ |
1061 | dy = 0; |
1137 | dy = 0; |
1062 | else if (y == y1) /* exact center */ |
1138 | else if (y == y1) /* exact center */ |
1063 | dy /= 2; |
1139 | dy /= 2; |
1064 | |
1140 | |
1065 | XMoveResizeWindow (dpy, parent[0], x + dx, y + dy, |
1141 | XMoveResizeWindow (dpy, parent, x + dx, y + dy, |
1066 | szHint.width, szHint.height); |
1142 | szHint.width, szHint.height); |
1067 | #else |
1143 | #else |
1068 | XResizeWindow (dpy, parent[0], szHint.width, szHint.height); |
1144 | XResizeWindow (dpy, parent, szHint.width, szHint.height); |
1069 | #endif |
1145 | #endif |
1070 | } |
1146 | } |
1071 | |
1147 | |
1072 | if (set_hint) |
1148 | if (set_hint) |
1073 | XSetWMNormalHints (dpy, parent[0], &szHint); |
1149 | XSetWMNormalHints (dpy, parent, &szHint); |
1074 | |
1150 | |
1075 | fix_screen = ncol != prev_ncol || nrow != prev_nrow; |
1151 | fix_screen = ncol != prev_ncol || nrow != prev_nrow; |
1076 | |
1152 | |
1077 | if (fix_screen || newwidth != old_width || newheight != old_height) |
1153 | if (fix_screen || newwidth != old_width || newheight != old_height) |
1078 | { |
1154 | { |
1079 | if (scrollBar.state) |
1155 | if (scrollBar.state) |
1080 | scrollBar.resize (); |
1156 | scrollBar.resize (); |
1081 | |
1157 | |
1082 | XMoveResizeWindow (dpy, vt, |
1158 | XMoveResizeWindow (dpy, vt, |
1083 | window_vt_x, window_vt_y, |
1159 | window_vt_x, window_vt_y, |
1084 | width, height); |
1160 | vt_width, vt_height); |
|
|
1161 | |
|
|
1162 | HOOK_INVOKE ((this, HOOK_SIZE_CHANGE, DT_INT, newwidth, DT_INT, newheight, DT_END)); |
1085 | |
1163 | |
1086 | #ifdef HAVE_BG_PIXMAP |
1164 | #ifdef HAVE_BG_PIXMAP |
1087 | if (bgPixmap.window_size_sensitive ()) |
1165 | if (bg_window_size_sensitive ()) |
1088 | update_background (); |
1166 | update_background (); |
1089 | #endif |
1167 | #endif |
1090 | } |
1168 | } |
1091 | |
1169 | |
1092 | if (fix_screen || old_height == 0) |
1170 | if (fix_screen || old_height == 0) |
1093 | scr_reset (); |
1171 | scr_reset (); |
1094 | |
1172 | |
1095 | #ifdef USE_XIM |
1173 | #if USE_XIM |
1096 | IMSetPosition (); |
1174 | im_set_position (); |
1097 | #endif |
1175 | #endif |
1098 | } |
1176 | } |
1099 | |
1177 | |
1100 | /* |
1178 | /* |
1101 | * Set the width/height of the vt window in characters. Units are pixels. |
1179 | * Set the width/height of the vt window in characters. Units are pixels. |
… | |
… | |
1114 | newwidth = wattr.width - szHint.base_width; |
1192 | newwidth = wattr.width - szHint.base_width; |
1115 | if (newheight == 0) |
1193 | if (newheight == 0) |
1116 | newheight = wattr.height - szHint.base_height; |
1194 | newheight = wattr.height - szHint.base_height; |
1117 | } |
1195 | } |
1118 | |
1196 | |
1119 | if (newwidth != width || newheight != height) |
1197 | if (newwidth != vt_width || newheight != vt_height) |
1120 | { |
1198 | { |
1121 | newwidth += szHint.base_width; |
1199 | newwidth += szHint.base_width; |
1122 | newheight += szHint.base_height; |
1200 | newheight += szHint.base_height; |
1123 | resize_all_windows (newwidth, newheight, 0); |
1201 | resize_all_windows (newwidth, newheight, 0); |
1124 | } |
1202 | } |
1125 | } |
1203 | } |
1126 | |
1204 | |
1127 | /* -------------------------------------------------------------------- * |
1205 | /* -------------------------------------------------------------------- * |
1128 | * - X INPUT METHOD ROUTINES - * |
1206 | * - X INPUT METHOD ROUTINES - * |
1129 | * -------------------------------------------------------------------- */ |
1207 | * -------------------------------------------------------------------- */ |
1130 | #ifdef USE_XIM |
1208 | #if USE_XIM |
1131 | |
1209 | |
1132 | void |
1210 | void |
1133 | rxvt_term::im_set_color (unsigned long &fg, unsigned long &bg) |
1211 | rxvt_term::im_set_color (unsigned long &fg, unsigned long &bg) |
1134 | { |
1212 | { |
1135 | fg = pix_colors [Color_fg]; |
1213 | fg = pix_colors [Color_fg]; |
… | |
… | |
1162 | status_rect.height = fheight; |
1240 | status_rect.height = fheight; |
1163 | } |
1241 | } |
1164 | |
1242 | |
1165 | /* Checking whether input method is running. */ |
1243 | /* Checking whether input method is running. */ |
1166 | bool |
1244 | bool |
1167 | rxvt_term::IMisRunning () |
1245 | rxvt_term::im_is_running () |
1168 | { |
1246 | { |
1169 | Atom atom; |
1247 | Atom atom; |
1170 | Window win; |
1248 | Window win; |
1171 | char server[IMBUFSIZ]; |
1249 | char server[IMBUFSIZ]; |
1172 | |
1250 | |
… | |
… | |
1181 | |
1259 | |
1182 | atom = XInternAtom (dpy, server, False); |
1260 | atom = XInternAtom (dpy, server, False); |
1183 | win = XGetSelectionOwner (dpy, atom); |
1261 | win = XGetSelectionOwner (dpy, atom); |
1184 | |
1262 | |
1185 | if (win != None) |
1263 | if (win != None) |
1186 | return True; |
1264 | return true; |
1187 | } |
1265 | } |
1188 | |
1266 | |
1189 | return False; |
1267 | return false; |
1190 | } |
1268 | } |
1191 | |
1269 | |
1192 | void |
1270 | void |
1193 | rxvt_term::IMSendSpot () |
1271 | rxvt_term::im_send_spot () |
1194 | { |
1272 | { |
1195 | XPoint nspot; |
1273 | XPoint nspot; |
1196 | XVaNestedList preedit_attr; |
1274 | XVaNestedList preedit_attr; |
1197 | |
1275 | |
1198 | if (!Input_Context |
1276 | if (!Input_Context |
… | |
… | |
1304 | /* |
1382 | /* |
1305 | * Try to open a XIM with the current modifiers, then see if we can |
1383 | * Try to open a XIM with the current modifiers, then see if we can |
1306 | * open a suitable preedit type |
1384 | * open a suitable preedit type |
1307 | */ |
1385 | */ |
1308 | bool |
1386 | bool |
1309 | rxvt_term::IM_get_IC (const char *modifiers) |
1387 | rxvt_term::im_get_ic (const char *modifiers) |
1310 | { |
1388 | { |
1311 | int i, j, found; |
1389 | int i, j, found; |
1312 | XIM xim; |
1390 | XIM xim; |
1313 | XPoint spot; |
1391 | XPoint spot; |
1314 | XRectangle rect, status_rect, needed_rect; |
1392 | XRectangle rect, status_rect, needed_rect; |
1315 | unsigned long fg, bg; |
1393 | unsigned long fg, bg; |
1316 | const char *p; |
1394 | const char *p; |
1317 | char **s; |
1395 | char **s; |
1318 | XIMStyles *xim_styles; |
1396 | XIMStyles *xim_styles; |
1319 | #ifdef ENABLE_XIM_ONTHESPOT |
|
|
1320 | XIMCallback xcb[4]; |
|
|
1321 | #endif |
|
|
1322 | |
1397 | |
1323 | set_environ (envv); |
1398 | set_environ (env); |
1324 | |
1399 | |
1325 | if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) |
1400 | if (!((p = XSetLocaleModifiers (modifiers)) && *p)) |
1326 | return false; |
1401 | return false; |
1327 | |
1402 | |
1328 | input_method = display->get_xim (locale, modifiers); |
1403 | input_method = display->get_xim (locale, modifiers); |
1329 | if (input_method == NULL) |
1404 | if (input_method == NULL) |
1330 | return false; |
1405 | return false; |
… | |
… | |
1466 | NULL); |
1541 | NULL); |
1467 | } |
1542 | } |
1468 | #if ENABLE_XIM_ONTHESPOT |
1543 | #if ENABLE_XIM_ONTHESPOT |
1469 | else if (input_style & XIMPreeditCallbacks) |
1544 | else if (input_style & XIMPreeditCallbacks) |
1470 | { |
1545 | { |
|
|
1546 | XIMCallback xcb[4]; |
|
|
1547 | |
1471 | im_set_position (spot); |
1548 | im_set_position (spot); |
1472 | |
1549 | |
1473 | xcb[0].client_data = (XPointer)this; xcb[0].callback = (XIMProc)xim_preedit_start; |
1550 | 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; |
1551 | 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; |
1552 | xcb[2].client_data = (XPointer)this; xcb[2].callback = (XIMProc)xim_preedit_draw; |
… | |
… | |
1490 | #endif |
1567 | #endif |
1491 | |
1568 | |
1492 | Input_Context = XCreateIC (xim, |
1569 | Input_Context = XCreateIC (xim, |
1493 | XNInputStyle, input_style, |
1570 | XNInputStyle, input_style, |
1494 | XNClientWindow, vt, |
1571 | XNClientWindow, vt, |
1495 | XNFocusWindow, parent[0], |
1572 | XNFocusWindow, parent, |
1496 | preedit_attr ? XNPreeditAttributes : NULL, |
1573 | preedit_attr ? XNPreeditAttributes : NULL, |
1497 | preedit_attr, |
1574 | preedit_attr, |
1498 | status_attr ? XNStatusAttributes : NULL, |
1575 | status_attr ? XNStatusAttributes : NULL, |
1499 | status_attr, NULL); |
1576 | status_attr, NULL); |
1500 | |
1577 | |
… | |
… | |
1513 | // unfortunately, only the focus window is used by XIM, hard to fix |
1590 | // unfortunately, only the focus window is used by XIM, hard to fix |
1514 | if (!XGetICValues (Input_Context, XNFilterEvents, &vt_emask_xim, NULL)) |
1591 | if (!XGetICValues (Input_Context, XNFilterEvents, &vt_emask_xim, NULL)) |
1515 | vt_select_input (); |
1592 | vt_select_input (); |
1516 | #endif |
1593 | #endif |
1517 | |
1594 | |
1518 | IMSetPosition (); |
1595 | im_set_position (); |
1519 | |
1596 | |
1520 | return true; |
1597 | return true; |
1521 | } |
1598 | } |
1522 | |
1599 | |
1523 | void |
1600 | void |
… | |
… | |
1533 | im_destroy (); |
1610 | im_destroy (); |
1534 | |
1611 | |
1535 | if (Input_Context) |
1612 | if (Input_Context) |
1536 | return; |
1613 | return; |
1537 | |
1614 | |
1538 | #if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) |
|
|
1539 | if (rs[Rs_imLocale]) |
1615 | if (rs[Rs_imLocale]) |
1540 | SET_LOCALE (rs[Rs_imLocale]); |
1616 | SET_LOCALE (rs[Rs_imLocale]); |
1541 | #endif |
|
|
1542 | |
1617 | |
1543 | p = rs[Rs_inputMethod]; |
1618 | p = rs[Rs_inputMethod]; |
1544 | if (p && *p) |
1619 | if (p && *p) |
1545 | { |
1620 | { |
1546 | bool found = false; |
1621 | bool found = false; |
… | |
… | |
1551 | { |
1626 | { |
1552 | if (*s[i]) |
1627 | if (*s[i]) |
1553 | { |
1628 | { |
1554 | strcpy (buf, "@im="); |
1629 | strcpy (buf, "@im="); |
1555 | strncat (buf, s[i], IMBUFSIZ - 5); |
1630 | strncat (buf, s[i], IMBUFSIZ - 5); |
1556 | if (IM_get_IC (buf)) |
1631 | if (im_get_ic (buf)) |
1557 | { |
1632 | { |
1558 | found = true; |
1633 | found = true; |
1559 | break; |
1634 | break; |
1560 | } |
1635 | } |
1561 | } |
1636 | } |
… | |
… | |
1566 | if (found) |
1641 | if (found) |
1567 | goto done; |
1642 | goto done; |
1568 | } |
1643 | } |
1569 | |
1644 | |
1570 | /* try with XMODIFIERS env. var. */ |
1645 | /* try with XMODIFIERS env. var. */ |
1571 | if (IM_get_IC ("")) |
1646 | if (im_get_ic ("")) |
1572 | goto done; |
1647 | goto done; |
1573 | |
1648 | |
1574 | /* try with no modifiers base IF the user didn't specify an IM */ |
1649 | /* try with no modifiers base IF the user didn't specify an IM */ |
1575 | if (IM_get_IC ("@im=none")) |
1650 | if (im_get_ic ("@im=none")) |
1576 | goto done; |
1651 | goto done; |
1577 | |
1652 | |
1578 | done: |
1653 | done: |
1579 | #if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) |
|
|
1580 | if (rs[Rs_imLocale]) |
1654 | if (rs[Rs_imLocale]) |
1581 | SET_LOCALE (locale); |
1655 | SET_LOCALE (locale); |
1582 | #endif |
|
|
1583 | } |
1656 | } |
1584 | |
1657 | |
1585 | void |
1658 | void |
1586 | rxvt_term::IMSetPosition () |
1659 | rxvt_term::im_set_position () |
1587 | { |
1660 | { |
1588 | XRectangle preedit_rect, status_rect, *needed_rect; |
1661 | XRectangle preedit_rect, status_rect, *needed_rect; |
1589 | XVaNestedList preedit_attr, status_attr; |
1662 | XVaNestedList preedit_attr, status_attr; |
1590 | |
1663 | |
1591 | if (!Input_Context |
1664 | if (!Input_Context |
1592 | || !focus |
1665 | || !focus |
1593 | || !(input_style & (XIMPreeditArea | XIMPreeditPosition)) |
1666 | || !(input_style & (XIMPreeditArea | XIMPreeditPosition)) |
1594 | || !IMisRunning ()) |
1667 | || !im_is_running ()) |
1595 | return; |
1668 | return; |
1596 | |
1669 | |
1597 | if (input_style & XIMPreeditPosition) |
1670 | if (input_style & XIMPreeditPosition) |
1598 | { |
1671 | { |
1599 | im_set_size (preedit_rect); |
1672 | im_set_size (preedit_rect); |
… | |
… | |
1629 | |
1702 | |
1630 | void |
1703 | void |
1631 | rxvt_term::get_window_origin (int &x, int &y) |
1704 | rxvt_term::get_window_origin (int &x, int &y) |
1632 | { |
1705 | { |
1633 | Window cr; |
1706 | Window cr; |
1634 | XTranslateCoordinates (dpy, parent[0], display->root, 0, 0, &x, &y, &cr); |
1707 | XTranslateCoordinates (dpy, parent, display->root, 0, 0, &x, &y, &cr); |
1635 | } |
|
|
1636 | |
|
|
1637 | Pixmap |
|
|
1638 | rxvt_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 | } |
1708 | } |
1658 | |
1709 | |
1659 | #ifdef HAVE_BG_PIXMAP |
1710 | #ifdef HAVE_BG_PIXMAP |
1660 | |
1711 | |
1661 | void |
1712 | void |
1662 | rxvt_term::update_background () |
1713 | rxvt_term::update_background () |
1663 | { |
1714 | { |
1664 | if (update_background_ev.is_active ()) |
1715 | if (update_background_ev.is_active ()) |
1665 | return; |
1716 | return; |
1666 | |
1717 | |
1667 | bgPixmap.invalidate (); |
|
|
1668 | |
|
|
1669 | ev_tstamp to_wait = 0.5 - (ev::now () - bgPixmap.valid_since); |
1718 | ev_tstamp to_wait = 0.5 - (ev::now () - bg_valid_since); |
1670 | |
1719 | |
1671 | if (to_wait <= 0.) |
1720 | if (to_wait <= 0.) |
1672 | bgPixmap.render (); |
1721 | bg_render (); |
1673 | else |
1722 | else |
1674 | update_background_ev.start (to_wait); |
1723 | update_background_ev.start (to_wait); |
1675 | } |
1724 | } |
1676 | |
1725 | |
1677 | void |
1726 | void |
1678 | rxvt_term::update_background_cb (ev::timer &w, int revents) |
1727 | rxvt_term::update_background_cb (ev::timer &w, int revents) |
1679 | { |
1728 | { |
1680 | make_current (); |
1729 | make_current (); |
1681 | |
1730 | |
1682 | update_background_ev.stop (); |
1731 | update_background_ev.stop (); |
1683 | bgPixmap.render (); |
1732 | bg_render (); |
1684 | refresh_check (); |
1733 | refresh_check (); |
1685 | } |
1734 | } |
1686 | |
1735 | |
1687 | #endif /* HAVE_BG_PIXMAP */ |
1736 | #endif /* HAVE_BG_PIXMAP */ |
1688 | |
1737 | |