… | |
… | |
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 | |
… | |
… | |
60 | rxvt_t rxvt_current_term; |
59 | rxvt_t rxvt_current_term; |
61 | |
60 | |
62 | static char curlocale[128], savelocale[128]; |
61 | static char curlocale[128], savelocale[128]; |
63 | |
62 | |
64 | bool |
63 | bool |
65 | rxvt_set_locale (const char *locale) NOTHROW |
64 | rxvt_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 | |
80 | void |
79 | void |
81 | rxvt_push_locale (const char *locale) NOTHROW |
80 | rxvt_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 | |
87 | void |
86 | void |
88 | rxvt_pop_locale () NOTHROW |
87 | rxvt_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 | |
|
|
129 | template<typename T> |
130 | int rxvt_composite_vec::expand (unicode_t c, wchar_t *r) |
130 | int 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 | |
|
|
153 | template int rxvt_composite_vec::expand<text_t> (unicode_t c, text_t *); |
|
|
154 | template int rxvt_composite_vec::expand<wchar_t> (unicode_t c, wchar_t *); |
153 | #endif |
155 | #endif |
154 | |
156 | |
155 | rxvt_term::rxvt_term () |
157 | rxvt_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 |
298 | void |
299 | void |
299 | rxvt_term::child_cb (ev::child &w, int status) |
300 | rxvt_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 | |
364 | void |
364 | void |
365 | rxvt_term::set_option (uint8_t opt, bool set) |
365 | rxvt_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 | */ |
381 | static XErrorHandler old_xerror_handler; |
380 | static XErrorHandler old_xerror_handler; |
382 | |
381 | |
383 | static void |
382 | static void |
384 | rxvt_emergency_cleanup () |
383 | rxvt_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 |
391 | static void |
390 | static void ecb_cold |
392 | print_x_error (Display *dpy, XErrorEvent *event) |
391 | print_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 | |
439 | int |
483 | snprintf (buffer, BUFSIZ, "+ %s\n", mesg); rxvt_warn (buffer, event->resourceid); |
|
|
484 | } |
|
|
485 | } |
|
|
486 | #endif |
|
|
487 | |
|
|
488 | int ecb_cold |
440 | rxvt_xerror_handler (Display *display, XErrorEvent *event) |
489 | rxvt_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 | |
458 | int |
507 | int ecb_cold |
459 | rxvt_xioerror_handler (Display *display) |
508 | rxvt_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 | g_type_init (); |
|
|
640 | #endif |
588 | } |
641 | } |
589 | |
642 | |
590 | /*----------------------------------------------------------------------*/ |
643 | /*----------------------------------------------------------------------*/ |
591 | /* |
644 | /* |
592 | * window size/position calculations for XSizeHint and other storage. |
645 | * window size/position calculations for XSizeHint and other storage. |
… | |
… | |
713 | if (recalc_y) |
766 | if (recalc_y) |
714 | szHint.y += DisplayHeight (dpy, display->screen) - szHint.height - 2 * ext_bwidth; |
767 | szHint.y += DisplayHeight (dpy, display->screen) - szHint.height - 2 * ext_bwidth; |
715 | |
768 | |
716 | ncol = width / fwidth; |
769 | ncol = width / fwidth; |
717 | nrow = height / fheight; |
770 | nrow = height / fheight; |
|
|
771 | |
|
|
772 | // When the size of the vt window is not a multiple of the cell |
|
|
773 | // size, i.e., when the wm does not honour our size hints, there are |
|
|
774 | // extra areas not covered by the terminal screen. Such gaps, when a |
|
|
775 | // bg pixmap is set, would have to be cleared manually to properly |
|
|
776 | // refresh the background. We take the simpler route and shrink the |
|
|
777 | // vt window so as to avoid creating gaps. |
|
|
778 | vt_width = ncol * fwidth; |
|
|
779 | vt_height = nrow * fheight; |
718 | } |
780 | } |
719 | |
781 | |
720 | /*----------------------------------------------------------------------*/ |
782 | /*----------------------------------------------------------------------*/ |
721 | /* |
783 | /* |
722 | * Tell the teletype handler what size the window is. |
784 | * Tell the teletype handler what size the window is. |
… | |
… | |
730 | |
792 | |
731 | struct winsize ws; |
793 | struct winsize ws; |
732 | |
794 | |
733 | ws.ws_col = ncol; |
795 | ws.ws_col = ncol; |
734 | ws.ws_row = nrow; |
796 | ws.ws_row = nrow; |
735 | ws.ws_xpixel = width; |
797 | ws.ws_xpixel = vt_width; |
736 | ws.ws_ypixel = height; |
798 | ws.ws_ypixel = vt_height; |
737 | ioctl (pty->pty, TIOCSWINSZ, &ws); |
799 | ioctl (pty->pty, TIOCSWINSZ, &ws); |
738 | |
800 | |
739 | #if 0 |
801 | #if 0 |
740 | // TIOCSWINSZ is supposed to do this automatically and correctly |
802 | // TIOCSWINSZ is supposed to do this automatically and correctly |
741 | if (cmd_pid) /* force through to the command */ |
803 | if (cmd_pid) /* force through to the command */ |
742 | kill (-cmd_pid, SIGWINCH); |
804 | kill (-cmd_pid, SIGWINCH); |
743 | #endif |
805 | #endif |
744 | } |
806 | } |
745 | |
807 | |
746 | /*----------------------------------------------------------------------*/ |
808 | /*----------------------------------------------------------------------*/ |
747 | /* set_fonts () - load and set the various fonts |
809 | /* 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 |
810 | bool |
755 | rxvt_term::set_fonts () |
811 | rxvt_term::set_fonts () |
756 | { |
812 | { |
757 | rxvt_fontset *fs = new rxvt_fontset (this); |
813 | rxvt_fontset *fs = new rxvt_fontset (this); |
758 | rxvt_fontprop prop; |
814 | rxvt_fontprop prop; |
… | |
… | |
773 | |
829 | |
774 | delete fontset[0]; |
830 | delete fontset[0]; |
775 | fontset[0] = fs; |
831 | fontset[0] = fs; |
776 | |
832 | |
777 | prop = (*fs)[rxvt_fontset::firstFont]->properties (); |
833 | prop = (*fs)[rxvt_fontset::firstFont]->properties (); |
778 | prop.height += lineSpace; |
834 | prop.width = max (prop.width + letterSpace, 1); |
779 | prop.width += letterSpace; |
|
|
780 | |
835 | |
781 | fs->set_prop (prop, false); |
836 | fs->set_prop (prop, false); |
782 | |
837 | |
783 | fwidth = prop.width; |
838 | fwidth = prop.width; |
784 | fheight = prop.height; |
839 | fheight = prop.height + lineSpace; |
785 | fbase = prop.ascent; |
840 | fbase = prop.ascent; |
786 | |
841 | |
787 | for (int style = 1; style < 4; style++) |
842 | for (int style = 1; style < 4; style++) |
788 | { |
843 | { |
789 | #if ENABLE_STYLES |
844 | #if ENABLE_STYLES |
… | |
… | |
815 | #else |
870 | #else |
816 | fontset[style] = fontset[0]; |
871 | fontset[style] = fontset[0]; |
817 | #endif |
872 | #endif |
818 | } |
873 | } |
819 | |
874 | |
820 | if (parent[0]) |
875 | if (parent) |
821 | { |
876 | { |
822 | resize_all_windows (0, 0, 0); |
877 | resize_all_windows (0, 0, 0); |
823 | scr_remap_chars (); |
878 | scr_remap_chars (); |
824 | scr_touch (true); |
879 | scr_touch (true); |
825 | } |
880 | } |
… | |
… | |
828 | } |
883 | } |
829 | |
884 | |
830 | void |
885 | void |
831 | rxvt_term::set_string_property (Atom prop, const char *str, int len) |
886 | rxvt_term::set_string_property (Atom prop, const char *str, int len) |
832 | { |
887 | { |
833 | XChangeProperty (dpy, parent[0], |
888 | XChangeProperty (dpy, parent, |
834 | prop, XA_STRING, 8, PropModeReplace, |
889 | prop, XA_STRING, 8, PropModeReplace, |
835 | (const unsigned char *)str, len >= 0 ? len : strlen (str)); |
890 | (const unsigned char *)str, len >= 0 ? len : strlen (str)); |
836 | } |
891 | } |
837 | |
892 | |
838 | void |
893 | void |
… | |
… | |
840 | { |
895 | { |
841 | XTextProperty ct; |
896 | XTextProperty ct; |
842 | |
897 | |
843 | if (XmbTextListToTextProperty (dpy, (char **)&str, 1, XStdICCTextStyle, &ct) >= 0) |
898 | if (XmbTextListToTextProperty (dpy, (char **)&str, 1, XStdICCTextStyle, &ct) >= 0) |
844 | { |
899 | { |
845 | XSetTextProperty (dpy, parent[0], &ct, prop); |
900 | XSetTextProperty (dpy, parent, &ct, prop); |
846 | XFree (ct.value); |
901 | XFree (ct.value); |
847 | } |
902 | } |
848 | } |
903 | } |
849 | |
904 | |
850 | void |
905 | void |
851 | rxvt_term::set_utf8_property (Atom prop, const char *str, int len) |
906 | rxvt_term::set_utf8_property (Atom prop, const char *str, int len) |
852 | { |
907 | { |
853 | wchar_t *ws = rxvt_mbstowcs (str, len); |
908 | wchar_t *ws = rxvt_mbstowcs (str, len); |
854 | char *s = rxvt_wcstoutf8 (ws); |
909 | char *s = rxvt_wcstoutf8 (ws); |
855 | |
910 | |
856 | XChangeProperty (dpy, parent[0], |
911 | XChangeProperty (dpy, parent, |
857 | prop, xa[XA_UTF8_STRING], 8, PropModeReplace, |
912 | prop, xa[XA_UTF8_STRING], 8, PropModeReplace, |
858 | (const unsigned char *)s, strlen (s)); |
913 | (const unsigned char *)s, strlen (s)); |
859 | |
914 | |
860 | free (s); |
915 | free (s); |
861 | free (ws); |
916 | free (ws); |
… | |
… | |
884 | |
939 | |
885 | void |
940 | void |
886 | rxvt_term::set_window_color (int idx, const char *color) |
941 | rxvt_term::set_window_color (int idx, const char *color) |
887 | { |
942 | { |
888 | #ifdef XTERM_COLOR_CHANGE |
943 | #ifdef XTERM_COLOR_CHANGE |
889 | rxvt_color xcol; |
|
|
890 | |
|
|
891 | if (color == NULL || *color == '\0') |
944 | if (color == NULL || *color == '\0') |
892 | return; |
945 | return; |
893 | |
946 | |
894 | color = strdup (color); |
947 | color = strdup (color); |
895 | allocated.push_back ((void *)color); |
948 | allocated.push_back ((void *)color); |
… | |
… | |
901 | int i = atoi (color); |
954 | int i = atoi (color); |
902 | |
955 | |
903 | if (i >= 8 && i <= 15) |
956 | if (i >= 8 && i <= 15) |
904 | { |
957 | { |
905 | /* bright colors */ |
958 | /* bright colors */ |
906 | pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i - 8]; |
959 | alias_color (idx, minBrightCOLOR + i - 8); |
907 | goto done; |
960 | goto done; |
908 | } |
961 | } |
909 | |
962 | |
910 | if (i >= 0 && i <= 7) |
963 | if (i >= 0 && i <= 7) |
911 | { |
964 | { |
912 | /* normal colors */ |
965 | /* normal colors */ |
913 | pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; |
966 | alias_color (idx, minCOLOR + i); |
914 | goto done; |
967 | goto done; |
915 | } |
968 | } |
916 | } |
969 | } |
917 | |
970 | |
918 | set_color (xcol, color); |
971 | pix_colors_focused[idx].free (this); |
919 | |
972 | 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 | |
973 | |
927 | done: |
974 | done: |
928 | /*TODO: handle Color_BD, scrollbar background, etc. */ |
975 | /*TODO: handle Color_BD, scrollbar background, etc. */ |
929 | |
976 | |
930 | update_fade_color (idx); |
977 | update_fade_color (idx); |
931 | recolour_cursor (); |
978 | recolor_cursor (); |
932 | scr_recolour (); |
979 | scr_recolor (); |
933 | #endif /* XTERM_COLOR_CHANGE */ |
980 | #endif /* XTERM_COLOR_CHANGE */ |
934 | } |
981 | } |
935 | |
982 | |
936 | void |
983 | void |
937 | rxvt_term::recolour_cursor () |
984 | rxvt_term::recolor_cursor () |
938 | { |
985 | { |
939 | XColor fg, bg; |
986 | XColor fg, bg; |
940 | |
987 | |
941 | (ISSET_PIXCOLOR (Color_pointer_fg) |
988 | (ISSET_PIXCOLOR (Color_pointer_fg) |
942 | ? pix_colors_focused[Color_pointer_fg] |
989 | ? pix_colors_focused[Color_pointer_fg] |
… | |
… | |
951 | |
998 | |
952 | /*----------------------------------------------------------------------*/ |
999 | /*----------------------------------------------------------------------*/ |
953 | /* |
1000 | /* |
954 | * find if fg/bg matches any of the normal (low-intensity) colors |
1001 | * find if fg/bg matches any of the normal (low-intensity) colors |
955 | */ |
1002 | */ |
956 | void |
1003 | char * |
957 | rxvt_term::set_colorfgbg () |
1004 | rxvt_term::get_colorfgbg () |
958 | { |
1005 | { |
959 | unsigned int i; |
1006 | unsigned int i; |
960 | const char *xpmb = ""; |
1007 | const char *xpmb = ""; |
961 | char fstr[] = "default"; |
1008 | char fstr[] = "default"; |
962 | char bstr[] = "default"; |
1009 | char bstr[] = "default"; |
|
|
1010 | char *env_colorfgbg; |
963 | |
1011 | |
964 | for (i = Color_Black; i <= Color_White; i++) |
1012 | for (i = Color_Black; i <= Color_White; i++) |
965 | if (pix_colors[Color_fg] == pix_colors[i]) |
1013 | if (pix_colors[Color_fg] == pix_colors[i]) |
966 | { |
1014 | { |
967 | sprintf (fstr, "%d", i - Color_Black); |
1015 | sprintf (fstr, "%d", i - Color_Black); |
… | |
… | |
970 | |
1018 | |
971 | for (i = Color_Black; i <= Color_White; i++) |
1019 | for (i = Color_Black; i <= Color_White; i++) |
972 | if (pix_colors[Color_bg] == pix_colors[i]) |
1020 | if (pix_colors[Color_bg] == pix_colors[i]) |
973 | { |
1021 | { |
974 | sprintf (bstr, "%d", i - Color_Black); |
1022 | sprintf (bstr, "%d", i - Color_Black); |
975 | #ifdef BG_IMAGE_FROM_FILE |
1023 | #if HAVE_IMG |
976 | xpmb = "default;"; |
1024 | xpmb = "default;"; |
977 | #endif |
1025 | #endif |
978 | break; |
1026 | break; |
979 | } |
1027 | } |
980 | |
1028 | |
|
|
1029 | env_colorfgbg = (char *)rxvt_malloc (sizeof ("COLORFGBG=default;default;bg")); |
981 | sprintf (env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr); |
1030 | sprintf (env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr); |
|
|
1031 | return env_colorfgbg; |
982 | } |
1032 | } |
983 | |
1033 | |
984 | /*----------------------------------------------------------------------*/ |
1034 | /*----------------------------------------------------------------------*/ |
985 | |
1035 | |
986 | bool |
1036 | bool |
… | |
… | |
994 | } |
1044 | } |
995 | |
1045 | |
996 | void |
1046 | void |
997 | rxvt_term::alias_color (int dst, int src) |
1047 | rxvt_term::alias_color (int dst, int src) |
998 | { |
1048 | { |
|
|
1049 | pix_colors[dst].free (this); |
999 | pix_colors[dst].set (this, rs[Rs_color + dst] = rs[Rs_color + src]); |
1050 | pix_colors[dst].set (this, rs[Rs_color + dst] = rs[Rs_color + src]); |
1000 | } |
1051 | } |
|
|
1052 | |
|
|
1053 | #ifdef SMART_RESIZE |
|
|
1054 | static unsigned int |
|
|
1055 | get_parent_bw (Display *dpy, Window w) |
|
|
1056 | { |
|
|
1057 | int idummy; |
|
|
1058 | unsigned int udummy; |
|
|
1059 | Window wdummy, parent; |
|
|
1060 | Window *children; |
|
|
1061 | unsigned int nchildren, border_width; |
|
|
1062 | |
|
|
1063 | XQueryTree (dpy, w, &wdummy, &parent, &children, &nchildren); |
|
|
1064 | XFree (children); |
|
|
1065 | XGetGeometry (dpy, parent, &wdummy, &idummy, &idummy, |
|
|
1066 | &udummy, &udummy, &border_width, &udummy); |
|
|
1067 | |
|
|
1068 | return border_width; |
|
|
1069 | } |
|
|
1070 | #endif |
1001 | |
1071 | |
1002 | /* -------------------------------------------------------------------- * |
1072 | /* -------------------------------------------------------------------- * |
1003 | * - WINDOW RESIZING - * |
1073 | * - WINDOW RESIZING - * |
1004 | * -------------------------------------------------------------------- */ |
1074 | * -------------------------------------------------------------------- */ |
1005 | void |
1075 | void |
… | |
… | |
1015 | |
1085 | |
1016 | // to avoid races between us and the wm, we clear the incremental size hints around the xresizewindow |
1086 | // to avoid races between us and the wm, we clear the incremental size hints around the xresizewindow |
1017 | if (set_hint) |
1087 | if (set_hint) |
1018 | { |
1088 | { |
1019 | szHint.flags &= ~(PBaseSize | PResizeInc); |
1089 | szHint.flags &= ~(PBaseSize | PResizeInc); |
1020 | XSetWMNormalHints (dpy, parent[0], &szHint); |
1090 | XSetWMNormalHints (dpy, parent, &szHint); |
1021 | szHint.flags |= PBaseSize | PResizeInc; |
1091 | szHint.flags |= PBaseSize | PResizeInc; |
1022 | } |
1092 | } |
1023 | |
1093 | |
1024 | if (!ignoreparent) |
1094 | if (!ignoreparent) |
1025 | { |
1095 | { |
… | |
… | |
1031 | int x, y, x1, y1; |
1101 | int x, y, x1, y1; |
1032 | int dx, dy; |
1102 | int dx, dy; |
1033 | unsigned int unused_w1, unused_h1, unused_b1, unused_d1; |
1103 | unsigned int unused_w1, unused_h1, unused_b1, unused_d1; |
1034 | Window unused_cr; |
1104 | Window unused_cr; |
1035 | |
1105 | |
1036 | XTranslateCoordinates (dpy, parent[0], display->root, |
1106 | XTranslateCoordinates (dpy, parent, display->root, |
1037 | 0, 0, &x, &y, &unused_cr); |
1107 | 0, 0, &x, &y, &unused_cr); |
1038 | XGetGeometry (dpy, parent[0], &unused_cr, &x1, &y1, |
1108 | XGetGeometry (dpy, parent, &unused_cr, &x1, &y1, |
1039 | &unused_w1, &unused_h1, &unused_b1, &unused_d1); |
1109 | &unused_w1, &unused_h1, &unused_b1, &unused_d1); |
1040 | /* |
1110 | /* |
1041 | * if display->root isn't the parent window, a WM will probably have offset |
1111 | * if display->root isn't the parent window, a WM will probably have offset |
1042 | * our position for handles and decorations. Counter it |
1112 | * our position for handles and decorations. Counter it |
1043 | */ |
1113 | */ |
1044 | if (x1 != x || y1 != y) |
1114 | if (x1 != x || y1 != y) |
1045 | { |
1115 | { |
1046 | x -= x1; |
1116 | unsigned int border_width = get_parent_bw (dpy, parent); |
1047 | y -= y1; |
1117 | |
|
|
1118 | x -= x1 + border_width; |
|
|
1119 | y -= y1 + border_width; |
1048 | } |
1120 | } |
1049 | |
1121 | |
1050 | x1 = (DisplayWidth (dpy, display->screen) - old_width ) / 2; |
1122 | x1 = (DisplayWidth (dpy, display->screen) - old_width ) / 2; |
1051 | y1 = (DisplayHeight (dpy, display->screen) - old_height) / 2; |
1123 | y1 = (DisplayHeight (dpy, display->screen) - old_height) / 2; |
1052 | dx = old_width - szHint.width; |
1124 | dx = old_width - szHint.width; |
… | |
… | |
1060 | if (y < y1) /* top half */ |
1132 | if (y < y1) /* top half */ |
1061 | dy = 0; |
1133 | dy = 0; |
1062 | else if (y == y1) /* exact center */ |
1134 | else if (y == y1) /* exact center */ |
1063 | dy /= 2; |
1135 | dy /= 2; |
1064 | |
1136 | |
1065 | XMoveResizeWindow (dpy, parent[0], x + dx, y + dy, |
1137 | XMoveResizeWindow (dpy, parent, x + dx, y + dy, |
1066 | szHint.width, szHint.height); |
1138 | szHint.width, szHint.height); |
1067 | #else |
1139 | #else |
1068 | XResizeWindow (dpy, parent[0], szHint.width, szHint.height); |
1140 | XResizeWindow (dpy, parent, szHint.width, szHint.height); |
1069 | #endif |
1141 | #endif |
1070 | } |
1142 | } |
1071 | |
1143 | |
1072 | if (set_hint) |
1144 | if (set_hint) |
1073 | XSetWMNormalHints (dpy, parent[0], &szHint); |
1145 | XSetWMNormalHints (dpy, parent, &szHint); |
1074 | |
1146 | |
1075 | fix_screen = ncol != prev_ncol || nrow != prev_nrow; |
1147 | fix_screen = ncol != prev_ncol || nrow != prev_nrow; |
1076 | |
1148 | |
1077 | if (fix_screen || newwidth != old_width || newheight != old_height) |
1149 | if (fix_screen || newwidth != old_width || newheight != old_height) |
1078 | { |
1150 | { |
1079 | if (scrollBar.state) |
1151 | if (scrollBar.state) |
1080 | scrollBar.resize (); |
1152 | scrollBar.resize (); |
1081 | |
1153 | |
1082 | XMoveResizeWindow (dpy, vt, |
1154 | XMoveResizeWindow (dpy, vt, |
1083 | window_vt_x, window_vt_y, |
1155 | window_vt_x, window_vt_y, |
1084 | width, height); |
1156 | vt_width, vt_height); |
1085 | |
1157 | |
1086 | #ifdef HAVE_BG_PIXMAP |
1158 | 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 | } |
1159 | } |
1091 | |
1160 | |
1092 | if (fix_screen || old_height == 0) |
1161 | if (fix_screen || old_height == 0) |
1093 | scr_reset (); |
1162 | scr_reset (); |
1094 | |
1163 | |
1095 | #ifdef USE_XIM |
1164 | #if USE_XIM |
1096 | IMSetPosition (); |
1165 | im_set_position (); |
1097 | #endif |
1166 | #endif |
1098 | } |
1167 | } |
1099 | |
1168 | |
1100 | /* |
1169 | /* |
1101 | * Set the width/height of the vt window in characters. Units are pixels. |
1170 | * Set the width/height of the vt window in characters. Units are pixels. |
… | |
… | |
1114 | newwidth = wattr.width - szHint.base_width; |
1183 | newwidth = wattr.width - szHint.base_width; |
1115 | if (newheight == 0) |
1184 | if (newheight == 0) |
1116 | newheight = wattr.height - szHint.base_height; |
1185 | newheight = wattr.height - szHint.base_height; |
1117 | } |
1186 | } |
1118 | |
1187 | |
1119 | if (newwidth != width || newheight != height) |
1188 | if (newwidth != vt_width || newheight != vt_height) |
1120 | { |
1189 | { |
1121 | newwidth += szHint.base_width; |
1190 | newwidth += szHint.base_width; |
1122 | newheight += szHint.base_height; |
1191 | newheight += szHint.base_height; |
1123 | resize_all_windows (newwidth, newheight, 0); |
1192 | resize_all_windows (newwidth, newheight, 0); |
1124 | } |
1193 | } |
1125 | } |
1194 | } |
1126 | |
1195 | |
1127 | /* -------------------------------------------------------------------- * |
1196 | /* -------------------------------------------------------------------- * |
1128 | * - X INPUT METHOD ROUTINES - * |
1197 | * - X INPUT METHOD ROUTINES - * |
1129 | * -------------------------------------------------------------------- */ |
1198 | * -------------------------------------------------------------------- */ |
1130 | #ifdef USE_XIM |
1199 | #if USE_XIM |
1131 | |
1200 | |
1132 | void |
1201 | void |
1133 | rxvt_term::im_set_color (unsigned long &fg, unsigned long &bg) |
1202 | rxvt_term::im_set_color (unsigned long &fg, unsigned long &bg) |
1134 | { |
1203 | { |
1135 | fg = pix_colors [Color_fg]; |
1204 | fg = pix_colors [Color_fg]; |
… | |
… | |
1162 | status_rect.height = fheight; |
1231 | status_rect.height = fheight; |
1163 | } |
1232 | } |
1164 | |
1233 | |
1165 | /* Checking whether input method is running. */ |
1234 | /* Checking whether input method is running. */ |
1166 | bool |
1235 | bool |
1167 | rxvt_term::IMisRunning () |
1236 | rxvt_term::im_is_running () |
1168 | { |
1237 | { |
1169 | Atom atom; |
1238 | Atom atom; |
1170 | Window win; |
1239 | Window win; |
1171 | char server[IMBUFSIZ]; |
1240 | char server[IMBUFSIZ]; |
1172 | |
1241 | |
… | |
… | |
1181 | |
1250 | |
1182 | atom = XInternAtom (dpy, server, False); |
1251 | atom = XInternAtom (dpy, server, False); |
1183 | win = XGetSelectionOwner (dpy, atom); |
1252 | win = XGetSelectionOwner (dpy, atom); |
1184 | |
1253 | |
1185 | if (win != None) |
1254 | if (win != None) |
1186 | return True; |
1255 | return true; |
1187 | } |
1256 | } |
1188 | |
1257 | |
1189 | return False; |
1258 | return false; |
1190 | } |
1259 | } |
1191 | |
1260 | |
1192 | void |
1261 | void |
1193 | rxvt_term::IMSendSpot () |
1262 | rxvt_term::im_send_spot () |
1194 | { |
1263 | { |
1195 | XPoint nspot; |
1264 | XPoint nspot; |
1196 | XVaNestedList preedit_attr; |
1265 | XVaNestedList preedit_attr; |
1197 | |
1266 | |
1198 | if (!Input_Context |
1267 | if (!Input_Context |
… | |
… | |
1304 | /* |
1373 | /* |
1305 | * Try to open a XIM with the current modifiers, then see if we can |
1374 | * Try to open a XIM with the current modifiers, then see if we can |
1306 | * open a suitable preedit type |
1375 | * open a suitable preedit type |
1307 | */ |
1376 | */ |
1308 | bool |
1377 | bool |
1309 | rxvt_term::IM_get_IC (const char *modifiers) |
1378 | rxvt_term::im_get_ic (const char *modifiers) |
1310 | { |
1379 | { |
1311 | int i, j, found; |
1380 | int i, j, found; |
1312 | XIM xim; |
1381 | XIM xim; |
1313 | XPoint spot; |
1382 | XPoint spot; |
1314 | XRectangle rect, status_rect, needed_rect; |
1383 | XRectangle rect, status_rect, needed_rect; |
1315 | unsigned long fg, bg; |
1384 | unsigned long fg, bg; |
1316 | const char *p; |
1385 | const char *p; |
1317 | char **s; |
1386 | char **s; |
1318 | XIMStyles *xim_styles; |
1387 | XIMStyles *xim_styles; |
1319 | #ifdef ENABLE_XIM_ONTHESPOT |
|
|
1320 | XIMCallback xcb[4]; |
|
|
1321 | #endif |
|
|
1322 | |
1388 | |
1323 | set_environ (envv); |
1389 | set_environ (env); |
1324 | |
1390 | |
1325 | if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) |
1391 | if (!((p = XSetLocaleModifiers (modifiers)) && *p)) |
1326 | return false; |
1392 | return false; |
1327 | |
1393 | |
1328 | input_method = display->get_xim (locale, modifiers); |
1394 | input_method = display->get_xim (locale, modifiers); |
1329 | if (input_method == NULL) |
1395 | if (input_method == NULL) |
1330 | return false; |
1396 | return false; |
… | |
… | |
1466 | NULL); |
1532 | NULL); |
1467 | } |
1533 | } |
1468 | #if ENABLE_XIM_ONTHESPOT |
1534 | #if ENABLE_XIM_ONTHESPOT |
1469 | else if (input_style & XIMPreeditCallbacks) |
1535 | else if (input_style & XIMPreeditCallbacks) |
1470 | { |
1536 | { |
|
|
1537 | XIMCallback xcb[4]; |
|
|
1538 | |
1471 | im_set_position (spot); |
1539 | im_set_position (spot); |
1472 | |
1540 | |
1473 | xcb[0].client_data = (XPointer)this; xcb[0].callback = (XIMProc)xim_preedit_start; |
1541 | 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; |
1542 | 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; |
1543 | xcb[2].client_data = (XPointer)this; xcb[2].callback = (XIMProc)xim_preedit_draw; |
… | |
… | |
1490 | #endif |
1558 | #endif |
1491 | |
1559 | |
1492 | Input_Context = XCreateIC (xim, |
1560 | Input_Context = XCreateIC (xim, |
1493 | XNInputStyle, input_style, |
1561 | XNInputStyle, input_style, |
1494 | XNClientWindow, vt, |
1562 | XNClientWindow, vt, |
1495 | XNFocusWindow, parent[0], |
1563 | XNFocusWindow, parent, |
1496 | preedit_attr ? XNPreeditAttributes : NULL, |
1564 | preedit_attr ? XNPreeditAttributes : NULL, |
1497 | preedit_attr, |
1565 | preedit_attr, |
1498 | status_attr ? XNStatusAttributes : NULL, |
1566 | status_attr ? XNStatusAttributes : NULL, |
1499 | status_attr, NULL); |
1567 | status_attr, NULL); |
1500 | |
1568 | |
… | |
… | |
1513 | // unfortunately, only the focus window is used by XIM, hard to fix |
1581 | // unfortunately, only the focus window is used by XIM, hard to fix |
1514 | if (!XGetICValues (Input_Context, XNFilterEvents, &vt_emask_xim, NULL)) |
1582 | if (!XGetICValues (Input_Context, XNFilterEvents, &vt_emask_xim, NULL)) |
1515 | vt_select_input (); |
1583 | vt_select_input (); |
1516 | #endif |
1584 | #endif |
1517 | |
1585 | |
1518 | IMSetPosition (); |
1586 | im_set_position (); |
1519 | |
1587 | |
1520 | return true; |
1588 | return true; |
1521 | } |
1589 | } |
1522 | |
1590 | |
1523 | void |
1591 | void |
… | |
… | |
1533 | im_destroy (); |
1601 | im_destroy (); |
1534 | |
1602 | |
1535 | if (Input_Context) |
1603 | if (Input_Context) |
1536 | return; |
1604 | return; |
1537 | |
1605 | |
1538 | #if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) |
|
|
1539 | if (rs[Rs_imLocale]) |
1606 | if (rs[Rs_imLocale]) |
1540 | SET_LOCALE (rs[Rs_imLocale]); |
1607 | SET_LOCALE (rs[Rs_imLocale]); |
1541 | #endif |
|
|
1542 | |
1608 | |
1543 | p = rs[Rs_inputMethod]; |
1609 | p = rs[Rs_inputMethod]; |
1544 | if (p && *p) |
1610 | if (p && *p) |
1545 | { |
1611 | { |
1546 | bool found = false; |
1612 | bool found = false; |
… | |
… | |
1551 | { |
1617 | { |
1552 | if (*s[i]) |
1618 | if (*s[i]) |
1553 | { |
1619 | { |
1554 | strcpy (buf, "@im="); |
1620 | strcpy (buf, "@im="); |
1555 | strncat (buf, s[i], IMBUFSIZ - 5); |
1621 | strncat (buf, s[i], IMBUFSIZ - 5); |
1556 | if (IM_get_IC (buf)) |
1622 | if (im_get_ic (buf)) |
1557 | { |
1623 | { |
1558 | found = true; |
1624 | found = true; |
1559 | break; |
1625 | break; |
1560 | } |
1626 | } |
1561 | } |
1627 | } |
… | |
… | |
1566 | if (found) |
1632 | if (found) |
1567 | goto done; |
1633 | goto done; |
1568 | } |
1634 | } |
1569 | |
1635 | |
1570 | /* try with XMODIFIERS env. var. */ |
1636 | /* try with XMODIFIERS env. var. */ |
1571 | if (IM_get_IC ("")) |
1637 | if (im_get_ic ("")) |
1572 | goto done; |
1638 | goto done; |
1573 | |
1639 | |
1574 | /* try with no modifiers base IF the user didn't specify an IM */ |
1640 | /* try with no modifiers base IF the user didn't specify an IM */ |
1575 | if (IM_get_IC ("@im=none")) |
1641 | if (im_get_ic ("@im=none")) |
1576 | goto done; |
1642 | goto done; |
1577 | |
1643 | |
1578 | done: |
1644 | done: |
1579 | #if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) |
|
|
1580 | if (rs[Rs_imLocale]) |
1645 | if (rs[Rs_imLocale]) |
1581 | SET_LOCALE (locale); |
1646 | SET_LOCALE (locale); |
1582 | #endif |
|
|
1583 | } |
1647 | } |
1584 | |
1648 | |
1585 | void |
1649 | void |
1586 | rxvt_term::IMSetPosition () |
1650 | rxvt_term::im_set_position () |
1587 | { |
1651 | { |
1588 | XRectangle preedit_rect, status_rect, *needed_rect; |
1652 | XRectangle preedit_rect, status_rect, *needed_rect; |
1589 | XVaNestedList preedit_attr, status_attr; |
1653 | XVaNestedList preedit_attr, status_attr; |
1590 | |
1654 | |
1591 | if (!Input_Context |
1655 | if (!Input_Context |
1592 | || !focus |
1656 | || !focus |
1593 | || !(input_style & (XIMPreeditArea | XIMPreeditPosition)) |
1657 | || !(input_style & (XIMPreeditArea | XIMPreeditPosition)) |
1594 | || !IMisRunning ()) |
1658 | || !im_is_running ()) |
1595 | return; |
1659 | return; |
1596 | |
1660 | |
1597 | if (input_style & XIMPreeditPosition) |
1661 | if (input_style & XIMPreeditPosition) |
1598 | { |
1662 | { |
1599 | im_set_size (preedit_rect); |
1663 | im_set_size (preedit_rect); |
… | |
… | |
1629 | |
1693 | |
1630 | void |
1694 | void |
1631 | rxvt_term::get_window_origin (int &x, int &y) |
1695 | rxvt_term::get_window_origin (int &x, int &y) |
1632 | { |
1696 | { |
1633 | Window cr; |
1697 | Window cr; |
1634 | XTranslateCoordinates (dpy, parent[0], display->root, 0, 0, &x, &y, &cr); |
1698 | XTranslateCoordinates (dpy, parent, display->root, 0, 0, &x, &y, &cr); |
1635 | } |
1699 | } |
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 | } |
|
|
1658 | |
|
|
1659 | #ifdef HAVE_BG_PIXMAP |
|
|
1660 | |
|
|
1661 | void |
|
|
1662 | rxvt_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 | |
|
|
1677 | void |
|
|
1678 | rxvt_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 | |
1700 | |
1689 | /*----------------------- end-of-file (C source) -----------------------*/ |
1701 | /*----------------------- end-of-file (C source) -----------------------*/ |