1 | /*--------------------------------*-C-*---------------------------------*; |
1 | /*--------------------------------*-C-*---------------------------------* |
2 | * File: main.c |
2 | * File: main.C |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * |
4 | * |
5 | * All portions of code are copyright by their respective author/s. |
5 | * All portions of code are copyright by their respective author/s. |
6 | * Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk> |
6 | * Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk> |
7 | * - original version |
7 | * - original version |
… | |
… | |
30 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
30 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
31 | *---------------------------------------------------------------------*/ |
31 | *---------------------------------------------------------------------*/ |
32 | |
32 | |
33 | #include "../config.h" /* NECESSARY */ |
33 | #include "../config.h" /* NECESSARY */ |
34 | #include "rxvt.h" /* NECESSARY */ |
34 | #include "rxvt.h" /* NECESSARY */ |
35 | #include "main.intpro" /* PROTOS for internal routines */ |
|
|
36 | |
35 | |
37 | #include <signal.h> |
36 | #include <csignal> |
|
|
37 | #include <cstring> |
38 | |
38 | |
39 | #ifdef TTY_GID_SUPPORT |
39 | #ifdef TTY_GID_SUPPORT |
40 | # include <grp.h> |
40 | # include <grp.h> |
41 | #endif |
41 | #endif |
42 | |
42 | |
43 | #ifdef HAVE_TERMIOS_H |
43 | #ifdef HAVE_TERMIOS_H |
44 | # include <termios.h> |
44 | # include <termios.h> |
45 | #endif |
45 | #endif |
46 | |
46 | |
47 | #include <cstring> |
47 | #ifdef KEYSYM_RESOURCE |
|
|
48 | # include "keyboard.h" |
|
|
49 | #endif |
|
|
50 | |
|
|
51 | vector<rxvt_term *> rxvt_term::termlist; |
48 | |
52 | |
49 | static char curlocale[128]; |
53 | static char curlocale[128]; |
50 | |
54 | |
51 | void |
55 | bool |
52 | rxvt_set_locale (const char *locale) |
56 | rxvt_set_locale (const char *locale) |
53 | { |
57 | { |
54 | if (locale && STRNCMP (locale, curlocale, 128)) |
58 | if (!locale || !strncmp (locale, curlocale, 128)) |
55 | { |
59 | return false; |
|
|
60 | |
56 | STRNCPY (curlocale, locale, 128); |
61 | strncpy (curlocale, locale, 128); |
57 | setlocale (LC_CTYPE, curlocale); |
62 | setlocale (LC_CTYPE, curlocale); |
58 | } |
63 | return true; |
59 | } |
64 | } |
60 | |
65 | |
61 | #if ENABLE_COMBINING |
66 | #if ENABLE_COMBINING |
62 | class rxvt_composite_vec rxvt_composite; |
67 | class rxvt_composite_vec rxvt_composite; |
63 | |
68 | |
… | |
… | |
120 | return len; |
125 | return len; |
121 | |
126 | |
122 | } |
127 | } |
123 | #endif |
128 | #endif |
124 | |
129 | |
125 | void * |
|
|
126 | rxvt_term::operator new (size_t s) |
|
|
127 | { |
|
|
128 | void *p = malloc (s); |
|
|
129 | |
|
|
130 | MEMSET (p, 0, s); |
|
|
131 | return p; |
|
|
132 | } |
|
|
133 | |
|
|
134 | void |
|
|
135 | rxvt_term::operator delete (void *p, size_t s) |
|
|
136 | { |
|
|
137 | free (p); |
|
|
138 | } |
|
|
139 | |
|
|
140 | rxvt_term::rxvt_term () |
130 | rxvt_term::rxvt_term () |
141 | : |
131 | : |
|
|
132 | #if TRANSPARENT |
142 | rootwin_ev (this, &rxvt_term::rootwin_cb), |
133 | rootwin_ev (this, &rxvt_term::rootwin_cb), |
|
|
134 | #endif |
|
|
135 | #ifdef HAVE_SCROLLBARS |
|
|
136 | scrollbar_ev (this, &rxvt_term::x_cb), |
|
|
137 | #endif |
|
|
138 | #ifdef MENUBAR |
|
|
139 | menubar_ev (this, &rxvt_term::x_cb), |
|
|
140 | #endif |
|
|
141 | #ifdef CURSOR_BLINK |
|
|
142 | cursor_blink_ev (this, &rxvt_term::cursor_blink_cb), |
|
|
143 | #endif |
|
|
144 | #ifdef TEXT_BLINK |
|
|
145 | text_blink_ev (this, &rxvt_term::text_blink_cb), |
|
|
146 | #endif |
|
|
147 | #ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING |
|
|
148 | cont_scroll_ev (this, &rxvt_term::cont_scroll_cb), |
|
|
149 | #endif |
|
|
150 | #ifdef SELECTION_SCROLLING |
|
|
151 | sel_scroll_ev (this, &rxvt_term::sel_scroll_cb), |
|
|
152 | #endif |
|
|
153 | #if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING) |
|
|
154 | slip_wheel_ev (this, &rxvt_term::slip_wheel_cb), |
|
|
155 | #endif |
|
|
156 | #ifdef POINTER_BLANK |
|
|
157 | pointer_ev (this, &rxvt_term::pointer_cb), |
|
|
158 | #endif |
|
|
159 | #ifdef USE_XIM |
|
|
160 | im_ev (this, &rxvt_term::im_cb), |
|
|
161 | #endif |
|
|
162 | sw_term (this, &rxvt_term::sig_term), |
|
|
163 | sw_int (this, &rxvt_term::sig_term), |
|
|
164 | sw_chld (this, &rxvt_term::sig_chld), |
143 | termwin_ev (this, &rxvt_term::x_cb), |
165 | termwin_ev (this, &rxvt_term::x_cb), |
144 | vt_ev (this, &rxvt_term::x_cb), |
166 | vt_ev (this, &rxvt_term::x_cb), |
145 | #ifdef HAVE_SCROLLBARS |
|
|
146 | scrollbar_ev (this, &rxvt_term::x_cb), |
|
|
147 | #endif |
|
|
148 | #ifdef MENUBAR |
|
|
149 | menubar_ev (this, &rxvt_term::x_cb), |
|
|
150 | #endif |
|
|
151 | #ifdef CURSOR_BLINK |
|
|
152 | cursor_blink_ev (this, &rxvt_term::cursor_blink_cb), |
|
|
153 | #endif |
|
|
154 | #ifdef TEXT_BLINK |
|
|
155 | text_blink_ev (this, &rxvt_term::text_blink_cb), |
|
|
156 | #endif |
|
|
157 | #ifdef POINTER_BLANK |
|
|
158 | pointer_ev (this, &rxvt_term::pointer_cb), |
|
|
159 | #endif |
|
|
160 | #ifdef USE_XIM |
|
|
161 | im_ev (this, &rxvt_term::im_cb), |
|
|
162 | #endif |
|
|
163 | check_ev (this, &rxvt_term::check_cb), |
167 | check_ev (this, &rxvt_term::check_cb), |
|
|
168 | flush_ev (this, &rxvt_term::flush_cb), |
164 | destroy_ev (this, &rxvt_term::destroy_cb), |
169 | destroy_ev (this, &rxvt_term::destroy_cb), |
165 | pty_ev (this, &rxvt_term::pty_cb), |
170 | pty_ev (this, &rxvt_term::pty_cb), |
166 | incr_ev (this, &rxvt_term::incr_cb) |
171 | incr_ev (this, &rxvt_term::incr_cb) |
167 | { |
172 | { |
168 | cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; |
173 | cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; |
169 | } |
|
|
170 | |
174 | |
171 | rxvt_term::~rxvt_term () |
175 | termlist.push_back (this); |
|
|
176 | |
|
|
177 | #ifdef KEYSYM_RESOURCE |
|
|
178 | keyboard = new keyboard_manager; |
|
|
179 | |
|
|
180 | if (!keyboard) |
|
|
181 | rxvt_fatal ("out of memory, aborting.\n"); |
|
|
182 | #endif |
|
|
183 | } |
|
|
184 | |
|
|
185 | // clean up the most important stuff, do *not* call x or free mem etc. |
|
|
186 | // for use before an emergency exit |
|
|
187 | void rxvt_term::emergency_cleanup () |
172 | { |
188 | { |
173 | if (cmd_fd >= 0) |
189 | if (cmd_pid) |
174 | close (cmd_fd); |
190 | kill (-cmd_pid, SIGHUP); |
175 | |
191 | |
176 | #ifndef NO_SETOWNER_TTYDEV |
|
|
177 | privileged_ttydev (RESTORE); |
|
|
178 | #endif |
|
|
179 | #ifdef UTMP_SUPPORT |
192 | #ifdef UTMP_SUPPORT |
180 | privileged_utmp (RESTORE); |
193 | privileged_utmp (RESTORE); |
181 | #endif |
194 | #endif |
182 | |
195 | |
|
|
196 | pty.put (); |
|
|
197 | } |
|
|
198 | |
|
|
199 | rxvt_term::~rxvt_term () |
|
|
200 | { |
|
|
201 | termlist.erase (find (termlist.begin (), termlist.end(), this)); |
|
|
202 | |
|
|
203 | emergency_cleanup (); |
|
|
204 | |
|
|
205 | #if ENABLE_STYLES |
|
|
206 | for (int i = RS_styleCount; --i; ) |
|
|
207 | if (TermWin.fontset[i] != TermWin.fontset[0]) |
|
|
208 | delete TermWin.fontset[i]; |
|
|
209 | #endif |
183 | delete TermWin.fontset; |
210 | delete TermWin.fontset[0]; |
184 | |
211 | |
185 | if (display) |
212 | if (display) |
186 | { |
213 | { |
|
|
214 | dDisp; |
|
|
215 | |
187 | selection_clear (); |
216 | selection_clear (); |
188 | |
217 | |
|
|
218 | #ifdef USE_XIM |
|
|
219 | im_destroy (); |
|
|
220 | #endif |
189 | #ifdef MENUBAR |
221 | #ifdef MENUBAR |
190 | if (menubarGC) XFreeGC (display->display, menubarGC); |
222 | if (menubarGC) XFreeGC (disp, menubarGC); |
191 | #endif |
223 | #endif |
192 | #ifdef XTERM_SCROLLBAR |
224 | #ifdef XTERM_SCROLLBAR |
193 | if (xscrollbarGC) XFreeGC (display->display, xscrollbarGC); |
225 | if (xscrollbarGC) XFreeGC (disp, xscrollbarGC); |
194 | if (ShadowGC) XFreeGC (display->display, ShadowGC); |
226 | if (ShadowGC) XFreeGC (disp, ShadowGC); |
195 | #endif |
227 | #endif |
196 | #ifdef PLAIN_SCROLLBAR |
228 | #ifdef PLAIN_SCROLLBAR |
197 | if (pscrollbarGC) XFreeGC (display->display, pscrollbarGC); |
229 | if (pscrollbarGC) XFreeGC (disp, pscrollbarGC); |
198 | #endif |
230 | #endif |
199 | #ifdef NEXT_SCROLLBAR |
231 | #ifdef NEXT_SCROLLBAR |
200 | if (blackGC) XFreeGC (display->display, blackGC); |
232 | if (blackGC) XFreeGC (disp, blackGC); |
201 | if (whiteGC) XFreeGC (display->display, whiteGC); |
233 | if (whiteGC) XFreeGC (disp, whiteGC); |
202 | if (grayGC) XFreeGC (display->display, grayGC); |
234 | if (grayGC) XFreeGC (disp, grayGC); |
203 | if (darkGC) XFreeGC (display->display, darkGC); |
235 | if (darkGC) XFreeGC (disp, darkGC); |
204 | if (stippleGC) XFreeGC (display->display, stippleGC); |
236 | if (stippleGC) XFreeGC (disp, stippleGC); |
205 | if (dimple) XFreePixmap (display->display, dimple); |
237 | if (dimple) XFreePixmap (disp, dimple); |
206 | if (upArrow) XFreePixmap (display->display, upArrow); |
238 | if (upArrow) XFreePixmap (disp, upArrow); |
207 | if (downArrow) XFreePixmap (display->display, downArrow); |
239 | if (downArrow) XFreePixmap (disp, downArrow); |
208 | if (upArrowHi) XFreePixmap (display->display, upArrowHi); |
240 | if (upArrowHi) XFreePixmap (disp, upArrowHi); |
209 | if (downArrowHi) XFreePixmap (display->display, downArrowHi); |
241 | if (downArrowHi) XFreePixmap (disp, downArrowHi); |
210 | #endif |
242 | #endif |
211 | #if defined(MENUBAR) || defined(RXVT_SCROLLBAR) |
243 | #if defined(MENUBAR) || defined(RXVT_SCROLLBAR) |
212 | if (topShadowGC) XFreeGC (display->display, topShadowGC); |
244 | if (topShadowGC) XFreeGC (disp, topShadowGC); |
213 | if (botShadowGC) XFreeGC (display->display, botShadowGC); |
245 | if (botShadowGC) XFreeGC (disp, botShadowGC); |
214 | if (scrollbarGC) XFreeGC (display->display, scrollbarGC); |
246 | if (scrollbarGC) XFreeGC (disp, scrollbarGC); |
215 | #endif |
247 | #endif |
216 | if (TermWin.gc) XFreeGC (display->display, TermWin.gc); |
248 | if (TermWin.gc) XFreeGC (disp, TermWin.gc); |
217 | |
249 | |
218 | #if defined(MENUBAR) && (MENUBAR_MAX > 1) |
250 | #if defined(MENUBAR) && (MENUBAR_MAX > 1) |
219 | delete menuBar.drawable; |
251 | delete menuBar.drawable; |
220 | //if (menuBar.win) |
252 | //if (menuBar.win) |
221 | // XDestroyWindow (display->display, menuBar.win); |
253 | // XDestroyWindow (disp, menuBar.win); |
222 | #endif |
254 | #endif |
223 | delete TermWin.drawable; |
255 | delete TermWin.drawable; |
224 | // destroy all windows |
256 | // destroy all windows |
225 | if (TermWin.parent[0]) |
257 | if (TermWin.parent[0]) |
226 | XDestroyWindow (display->display, TermWin.parent[0]); |
258 | XDestroyWindow (disp, TermWin.parent[0]); |
227 | } |
259 | } |
228 | |
260 | |
229 | // TODO: free pixcolours, colours should become part of rxvt_display |
261 | // TODO: free pixcolours, colours should become part of rxvt_display |
230 | |
262 | |
231 | delete PixColors; |
263 | delete pix_colors_focused; |
|
|
264 | #if OFF_FOCUS_FADING |
|
|
265 | delete pix_colors_unfocused; |
|
|
266 | #endif |
232 | |
267 | |
233 | displays.put (display); |
268 | displays.put (display); |
234 | |
269 | |
235 | scr_release (); |
270 | scr_release (); |
236 | |
271 | |
237 | /* clear all resources */ |
272 | /* clear all resources */ |
238 | for (int i = 0; i < allocated.size (); i++) |
273 | for (int i = 0; i < allocated.size (); i++) |
239 | free (allocated[i]); |
274 | free (allocated [i]); |
240 | |
275 | |
241 | free (selection.text); |
276 | free (selection.text); |
242 | // TODO: manage env vars in child only(!) |
277 | // TODO: manage env vars in child only(!) |
243 | free (env_windowid); |
278 | free (env_windowid); |
244 | free (env_display); |
279 | free (env_display); |
245 | free (env_term); |
280 | free (env_term); |
246 | free (env_colorfgbg); |
281 | free (env_colorfgbg); |
247 | free (locale); |
282 | free (locale); |
248 | #if 0 |
283 | free (v_buffer); |
249 | free (codeset); |
284 | free (incr_buf); |
250 | #endif |
|
|
251 | |
285 | |
252 | delete envv; |
286 | delete envv; |
253 | delete argv; |
287 | delete argv; |
|
|
288 | |
|
|
289 | #ifdef KEYSYM_RESOURCE |
|
|
290 | delete keyboard; |
|
|
291 | #endif |
254 | } |
292 | } |
255 | |
293 | |
256 | void |
294 | void |
257 | rxvt_term::destroy () |
295 | rxvt_term::destroy () |
258 | { |
296 | { |
|
|
297 | if (destroy_ev.active) |
|
|
298 | return; |
|
|
299 | |
|
|
300 | #if ENABLE_OVERLAY |
|
|
301 | scr_overlay_off (); |
|
|
302 | #endif |
|
|
303 | |
259 | if (display) |
304 | if (display) |
260 | { |
305 | { |
|
|
306 | #if USE_XIM |
|
|
307 | im_ev.stop (display); |
|
|
308 | #endif |
|
|
309 | #if HAVE_SCROLLBARS |
|
|
310 | scrollbar_ev.stop (display); |
|
|
311 | #endif |
|
|
312 | #if MENUBAR |
|
|
313 | menubar_ev.stop (display); |
|
|
314 | #endif |
|
|
315 | #if TRANSPARENT |
261 | rootwin_ev.stop (display); |
316 | rootwin_ev.stop (display); |
|
|
317 | #endif |
|
|
318 | incr_ev.stop (); |
262 | termwin_ev.stop (display); |
319 | termwin_ev.stop (display); |
263 | vt_ev.stop (display); |
320 | vt_ev.stop (display); |
264 | #ifdef USE_XIM |
|
|
265 | im_destroy (); |
|
|
266 | im_ev.stop (display); |
|
|
267 | #endif |
|
|
268 | #ifdef HAVE_SCROLLBARS |
|
|
269 | scrollbar_ev.stop (display); |
|
|
270 | #endif |
|
|
271 | #ifdef MENUBAR |
|
|
272 | menubar_ev.stop (display); |
|
|
273 | #endif |
|
|
274 | } |
321 | } |
275 | |
322 | |
276 | check_ev.stop (); |
323 | check_ev.stop (); |
277 | pty_ev.stop (); |
324 | pty_ev.stop (); |
278 | #ifdef CURSOR_BLINK |
325 | #ifdef CURSOR_BLINK |
279 | cursor_blink_ev.stop (); |
326 | cursor_blink_ev.stop (); |
280 | #endif |
327 | #endif |
281 | #ifdef TEXT_BLINK |
328 | #ifdef TEXT_BLINK |
282 | text_blink_ev.stop (); |
329 | text_blink_ev.stop (); |
283 | #endif |
330 | #endif |
|
|
331 | #ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING |
|
|
332 | cont_scroll_ev.stop (); |
|
|
333 | #endif |
|
|
334 | #ifdef SELECTION_SCROLLING |
|
|
335 | sel_scroll_ev.stop (); |
|
|
336 | #endif |
284 | #ifdef POINTER_BLANK |
337 | #ifdef POINTER_BLANK |
285 | pointer_ev.stop (); |
338 | pointer_ev.stop (); |
286 | #endif |
339 | #endif |
287 | |
340 | |
288 | destroy_ev.start (0); |
341 | destroy_ev.start (0); |
… | |
… | |
292 | rxvt_term::destroy_cb (time_watcher &w) |
345 | rxvt_term::destroy_cb (time_watcher &w) |
293 | { |
346 | { |
294 | SET_R (this); |
347 | SET_R (this); |
295 | |
348 | |
296 | delete this; |
349 | delete this; |
|
|
350 | } |
|
|
351 | |
|
|
352 | /*----------------------------------------------------------------------*/ |
|
|
353 | /* |
|
|
354 | * Exit gracefully, clearing the utmp entry and restoring tty attributes |
|
|
355 | * TODO: if debugging, this should free up any known resources if we can |
|
|
356 | */ |
|
|
357 | static XErrorHandler old_xerror_handler; |
|
|
358 | |
|
|
359 | static void |
|
|
360 | rxvt_emergency_cleanup () |
|
|
361 | { |
|
|
362 | for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++) |
|
|
363 | (*t)->emergency_cleanup (); |
|
|
364 | } |
|
|
365 | |
|
|
366 | #if ENABLE_FRILLS |
|
|
367 | static void |
|
|
368 | print_x_error (Display *dpy, XErrorEvent *event) |
|
|
369 | { |
|
|
370 | char buffer[BUFSIZ]; |
|
|
371 | char mesg[BUFSIZ]; |
|
|
372 | char number[32]; |
|
|
373 | char *mtype = "XlibMessage"; |
|
|
374 | XGetErrorText(dpy, event->error_code, buffer, BUFSIZ); |
|
|
375 | XGetErrorDatabaseText(dpy, mtype, "XError", "X Error", mesg, BUFSIZ); |
|
|
376 | rxvt_warn ("An X Error occured, trying to continue after report.\n"); |
|
|
377 | rxvt_warn ("%s: %s\n", mesg, buffer); |
|
|
378 | XGetErrorDatabaseText(dpy, mtype, "MajorCode", "Request Major code %d", mesg, BUFSIZ); |
|
|
379 | rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->request_code); |
|
|
380 | sprintf(number, "%d", event->request_code); |
|
|
381 | XGetErrorDatabaseText(dpy, "XRequest", number, "", buffer, BUFSIZ); |
|
|
382 | rxvt_warn ("(which is %s)\n", buffer); |
|
|
383 | if (event->request_code >= 128) { |
|
|
384 | XGetErrorDatabaseText(dpy, mtype, "MinorCode", "Request Minor code %d", |
|
|
385 | mesg, BUFSIZ); |
|
|
386 | rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->minor_code); |
|
|
387 | } |
|
|
388 | if ((event->error_code == BadWindow) || |
|
|
389 | (event->error_code == BadPixmap) || |
|
|
390 | (event->error_code == BadCursor) || |
|
|
391 | (event->error_code == BadFont) || |
|
|
392 | (event->error_code == BadDrawable) || |
|
|
393 | (event->error_code == BadColor) || |
|
|
394 | (event->error_code == BadGC) || |
|
|
395 | (event->error_code == BadIDChoice) || |
|
|
396 | (event->error_code == BadValue) || |
|
|
397 | (event->error_code == BadAtom)) { |
|
|
398 | if (event->error_code == BadValue) |
|
|
399 | XGetErrorDatabaseText(dpy, mtype, "Value", "Value 0x%x", |
|
|
400 | mesg, BUFSIZ); |
|
|
401 | else if (event->error_code == BadAtom) |
|
|
402 | XGetErrorDatabaseText(dpy, mtype, "AtomID", "AtomID 0x%x", |
|
|
403 | mesg, BUFSIZ); |
|
|
404 | else |
|
|
405 | XGetErrorDatabaseText(dpy, mtype, "ResourceID", "ResourceID 0x%x", |
|
|
406 | mesg, BUFSIZ); |
|
|
407 | rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->resourceid); |
|
|
408 | } |
|
|
409 | XGetErrorDatabaseText(dpy, mtype, "ErrorSerial", "Error Serial #%d", |
|
|
410 | mesg, BUFSIZ); |
|
|
411 | rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->serial); |
|
|
412 | } |
|
|
413 | #endif |
|
|
414 | |
|
|
415 | int |
|
|
416 | rxvt_xerror_handler (Display *display, XErrorEvent *event) |
|
|
417 | { |
|
|
418 | if (GET_R->allowedxerror == -1) |
|
|
419 | GET_R->allowedxerror = event->error_code; |
|
|
420 | else |
|
|
421 | { |
|
|
422 | // GET_R is most likely not the terminal which caused the error, |
|
|
423 | // so just output the error and continue |
|
|
424 | #if ENABLE_FRILLS |
|
|
425 | print_x_error (display, event); |
|
|
426 | #else |
|
|
427 | old_xerror_handler (display, event); |
|
|
428 | #endif |
|
|
429 | } |
|
|
430 | |
|
|
431 | return 0; |
|
|
432 | } |
|
|
433 | |
|
|
434 | int |
|
|
435 | rxvt_xioerror_handler (Display *display) |
|
|
436 | { |
|
|
437 | rxvt_warn ("X connection to '%s' broken, unable to recover, exiting.\n", |
|
|
438 | DisplayString (display)); |
|
|
439 | rxvt_emergency_cleanup (); |
|
|
440 | _exit (EXIT_FAILURE); |
|
|
441 | } |
|
|
442 | |
|
|
443 | /* |
|
|
444 | * Catch a fatal signal and tidy up before quitting |
|
|
445 | */ |
|
|
446 | void |
|
|
447 | rxvt_term::sig_term (sig_watcher &w) |
|
|
448 | { |
|
|
449 | #ifdef DEBUG_CMD |
|
|
450 | rxvt_warn ("caught signal %d, exiting.\n", w.signum); |
|
|
451 | #endif |
|
|
452 | rxvt_emergency_cleanup (); |
|
|
453 | signal (w.signum, SIG_DFL); |
|
|
454 | kill (getpid (), w.signum); |
297 | } |
455 | } |
298 | |
456 | |
299 | /*----------------------------------------------------------------------*/ |
457 | /*----------------------------------------------------------------------*/ |
300 | /* rxvt_init () */ |
458 | /* rxvt_init () */ |
301 | bool |
459 | bool |
302 | rxvt_term::init (int argc, const char *const *argv) |
460 | rxvt_term::init (int argc, const char *const *argv) |
303 | { |
461 | { |
304 | SET_R (this); |
462 | SET_R (this); |
305 | |
463 | |
|
|
464 | set_locale (""); |
|
|
465 | |
306 | if (!init_vars ()) |
466 | if (!init_vars ()) |
307 | return false; |
467 | return false; |
308 | |
468 | |
|
|
469 | init_secondary (); |
|
|
470 | |
|
|
471 | const char **cmd_argv = init_resources (argc, argv); |
|
|
472 | |
|
|
473 | #ifdef KEYSYM_RESOURCE |
|
|
474 | keyboard->register_done (); |
|
|
475 | #endif |
|
|
476 | |
|
|
477 | #if MENUBAR_MAX |
|
|
478 | menubar_read (rs[Rs_menu]); |
|
|
479 | #endif |
|
|
480 | #ifdef HAVE_SCROLLBARS |
|
|
481 | if (options & Opt_scrollBar) |
|
|
482 | scrollBar.setIdle (); /* set existence for size calculations */ |
|
|
483 | #endif |
|
|
484 | |
|
|
485 | create_windows (argc, argv); |
|
|
486 | |
|
|
487 | dDisp; |
|
|
488 | |
|
|
489 | init_xlocale (); |
|
|
490 | |
|
|
491 | scr_reset (); /* initialize screen */ |
|
|
492 | |
|
|
493 | #if 0 |
|
|
494 | XSynchronize (disp, True); |
|
|
495 | #endif |
|
|
496 | |
|
|
497 | #ifdef HAVE_SCROLLBARS |
|
|
498 | if (options & Opt_scrollBar) |
|
|
499 | resize_scrollbar (); /* create and map scrollbar */ |
|
|
500 | #endif |
|
|
501 | #if (MENUBAR_MAX) |
|
|
502 | if (menubar_visible ()) |
|
|
503 | XMapWindow (disp, menuBar.win); |
|
|
504 | #endif |
|
|
505 | #ifdef TRANSPARENT |
|
|
506 | if (options & Opt_transparent) |
|
|
507 | { |
|
|
508 | XSelectInput (disp, display->root, PropertyChangeMask); |
|
|
509 | check_our_parents (); |
|
|
510 | rootwin_ev.start (display, display->root); |
|
|
511 | } |
|
|
512 | #endif |
|
|
513 | |
|
|
514 | XMapWindow (disp, TermWin.vt); |
|
|
515 | XMapWindow (disp, TermWin.parent[0]); |
|
|
516 | |
|
|
517 | set_colorfgbg (); |
|
|
518 | |
|
|
519 | init_command (cmd_argv); |
|
|
520 | |
|
|
521 | free (cmd_argv); |
|
|
522 | |
|
|
523 | pty_ev.start (pty.pty, EVENT_READ); |
|
|
524 | |
|
|
525 | check_ev.start (); |
|
|
526 | |
|
|
527 | return true; |
|
|
528 | } |
|
|
529 | |
|
|
530 | void |
|
|
531 | rxvt_init () |
|
|
532 | { |
309 | /* |
533 | /* |
310 | * Save and then give up any super-user privileges |
534 | * Save and then give up any super-user privileges |
311 | * If we need privileges in any area then we must specifically request it. |
535 | * If we need privileges in any area then we must specifically request it. |
312 | * We should only need to be root in these cases: |
536 | * We should only need to be root in these cases: |
313 | * 1. write utmp entries on some systems |
537 | * 1. write utmp entries on some systems |
314 | * 2. chown tty on some systems |
538 | * 2. chown tty on some systems |
315 | */ |
539 | */ |
316 | privileges (SAVE); |
540 | rxvt_privileges (SAVE); |
317 | privileges (IGNORE); |
541 | rxvt_privileges (IGNORE); |
318 | |
542 | |
319 | init_secondary (); |
543 | signal (SIGHUP, SIG_IGN); |
320 | |
544 | signal (SIGPIPE, SIG_IGN); |
321 | const char **cmd_argv = init_resources (argc, argv); |
|
|
322 | |
|
|
323 | set_locale (""); |
|
|
324 | |
|
|
325 | #if MENUBAR_MAX |
|
|
326 | menubar_read (rs[Rs_menu]); |
|
|
327 | #endif |
|
|
328 | #ifdef HAVE_SCROLLBARS |
|
|
329 | if (Options & Opt_scrollBar) |
|
|
330 | scrollBar.setIdle (); /* set existence for size calculations */ |
|
|
331 | #endif |
|
|
332 | |
|
|
333 | create_windows (argc, argv); |
|
|
334 | |
|
|
335 | init_xlocale (); |
|
|
336 | |
|
|
337 | scr_reset (); /* initialize screen */ |
|
|
338 | |
|
|
339 | #if 0 |
|
|
340 | XSynchronize (display->display, True); |
|
|
341 | #endif |
|
|
342 | |
|
|
343 | #ifdef HAVE_SCROLLBARS |
|
|
344 | if (Options & Opt_scrollBar) |
|
|
345 | resize_scrollbar (); /* create and map scrollbar */ |
|
|
346 | #endif |
|
|
347 | #if (MENUBAR_MAX) |
|
|
348 | if (menubar_visible ()) |
|
|
349 | XMapWindow (display->display, menuBar.win); |
|
|
350 | #endif |
|
|
351 | #ifdef TRANSPARENT |
|
|
352 | if (Options & Opt_transparent) |
|
|
353 | { |
|
|
354 | XSelectInput (display->display, display->root, PropertyChangeMask); |
|
|
355 | check_our_parents (); |
|
|
356 | } |
|
|
357 | #endif |
|
|
358 | |
|
|
359 | rootwin_ev.start (display, display->root); |
|
|
360 | |
|
|
361 | XMapWindow (display->display, TermWin.vt); |
|
|
362 | XMapWindow (display->display, TermWin.parent[0]); |
|
|
363 | |
|
|
364 | init_command (cmd_argv); |
|
|
365 | |
|
|
366 | pty_ev.start (cmd_fd, EVENT_READ); |
|
|
367 | |
|
|
368 | check_ev.start (); |
|
|
369 | |
|
|
370 | return true; |
|
|
371 | } |
|
|
372 | |
|
|
373 | static int (*old_xerror_handler) (Display *dpy, XErrorEvent *event); |
|
|
374 | |
|
|
375 | void |
|
|
376 | rxvt_init_signals () |
|
|
377 | { |
|
|
378 | /* install exit handler for cleanup */ |
|
|
379 | #if 0 |
|
|
380 | #ifdef HAVE_ATEXIT |
|
|
381 | atexit (rxvt_clean_exit); |
|
|
382 | #else |
|
|
383 | #endif |
|
|
384 | #endif |
|
|
385 | |
|
|
386 | struct sigaction sa; |
|
|
387 | |
|
|
388 | sigfillset (&sa.sa_mask); |
|
|
389 | sa.sa_flags = SA_NOCLDSTOP | SA_RESTART; |
|
|
390 | sa.sa_handler = SIG_IGN; sigaction (SIGHUP , &sa, 0); |
|
|
391 | sa.sa_handler = SIG_IGN; sigaction (SIGPIPE, &sa, 0); |
|
|
392 | sa.sa_handler = rxvt_Exit_signal; sigaction (SIGINT , &sa, 0); |
|
|
393 | sa.sa_handler = rxvt_Exit_signal; sigaction (SIGQUIT, &sa, 0); |
|
|
394 | sa.sa_handler = rxvt_Exit_signal; sigaction (SIGTERM, &sa, 0); |
|
|
395 | sa.sa_handler = rxvt_Child_signal; sigaction (SIGCHLD, &sa, 0); |
|
|
396 | |
545 | |
397 | /* need to trap SIGURG for SVR4 (Unixware) rlogin */ |
546 | /* need to trap SIGURG for SVR4 (Unixware) rlogin */ |
398 | /* signal (SIGURG, SIG_DFL); */ |
547 | /* signal (SIGURG, SIG_DFL); */ |
399 | |
548 | |
400 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
549 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
|
|
550 | // TODO: handle this with exceptions and tolerate the memory loss |
401 | //XSetIOErrorHandler ((XErrorHandler) rxvt_xioerror_handler); |
551 | XSetIOErrorHandler (rxvt_xioerror_handler); |
402 | } |
552 | } |
403 | |
553 | |
404 | /* ------------------------------------------------------------------------- * |
554 | /* ------------------------------------------------------------------------- * |
405 | * SIGNAL HANDLING & EXIT HANDLER * |
555 | * SIGNAL HANDLING & EXIT HANDLER * |
406 | * ------------------------------------------------------------------------- */ |
556 | * ------------------------------------------------------------------------- */ |
407 | /* |
557 | /* |
408 | * Catch a SIGCHLD signal and exit if the direct child has died |
558 | * Catch a SIGCHLD signal and exit if the direct child has died |
409 | */ |
559 | */ |
410 | /* ARGSUSED */ |
560 | |
411 | /* EXTPROTO */ |
561 | void |
412 | RETSIGTYPE |
562 | rxvt_term::sig_chld (sig_watcher &w) |
413 | rxvt_Child_signal (int sig __attribute__ ((unused))) |
|
|
414 | { |
563 | { |
415 | int pid, save_errno = errno; |
564 | // we are being called for every SIGCHLD, not just ours |
|
|
565 | int pid; |
|
|
566 | |
416 | while ((pid = waitpid (-1, NULL, WNOHANG)) == -1 && errno == EINTR) |
567 | while ((pid = waitpid (-1, NULL, WNOHANG)) > 0) |
417 | ; |
568 | for (rxvt_term **t = termlist.begin (); t < termlist.end (); t++) |
418 | errno = save_errno; |
|
|
419 | |
|
|
420 | #if 0 |
|
|
421 | if (pid == cmd_pid) |
569 | if (pid == (*t)->cmd_pid) |
422 | exit (EXIT_SUCCESS); |
570 | { |
423 | #endif |
571 | (*t)->destroy (); |
424 | } |
572 | break; |
425 | |
573 | } |
426 | /* |
|
|
427 | * Catch a fatal signal and tidy up before quitting |
|
|
428 | */ |
|
|
429 | /* EXTPROTO */ |
|
|
430 | RETSIGTYPE |
|
|
431 | rxvt_Exit_signal (int sig) |
|
|
432 | { |
|
|
433 | signal (sig, SIG_DFL); |
|
|
434 | #ifdef DEBUG_CMD |
|
|
435 | rxvt_warn ("caught signal %d, exiting.\n", sig); |
|
|
436 | #endif |
|
|
437 | rxvt_clean_exit (); |
|
|
438 | kill (getpid (), sig); |
|
|
439 | } |
|
|
440 | |
|
|
441 | /* INTPROTO */ |
|
|
442 | int |
|
|
443 | rxvt_xerror_handler (Display *display, XErrorEvent *event) |
|
|
444 | { |
|
|
445 | if (GET_R->allowedxerror == -1) |
|
|
446 | GET_R->allowedxerror = event->error_code; |
|
|
447 | else |
|
|
448 | { |
|
|
449 | old_xerror_handler (display, event); |
|
|
450 | GET_R->destroy (); |
|
|
451 | } |
|
|
452 | |
|
|
453 | return 0; |
|
|
454 | } |
|
|
455 | |
|
|
456 | /*----------------------------------------------------------------------*/ |
|
|
457 | /* |
|
|
458 | * Exit gracefully, clearing the utmp entry and restoring tty attributes |
|
|
459 | * TODO: if debugging, this should free up any known resources if we can |
|
|
460 | */ |
|
|
461 | /* EXTPROTO */ |
|
|
462 | void |
|
|
463 | rxvt_clean_exit () |
|
|
464 | { |
|
|
465 | // TODO: rxvtd should clean up all ressources |
|
|
466 | if (GET_R) |
|
|
467 | GET_R->destroy (); |
|
|
468 | } |
574 | } |
469 | |
575 | |
470 | /* ------------------------------------------------------------------------- * |
576 | /* ------------------------------------------------------------------------- * |
471 | * MEMORY ALLOCATION WRAPPERS * |
577 | * MEMORY ALLOCATION WRAPPERS * |
472 | * ------------------------------------------------------------------------- */ |
578 | * ------------------------------------------------------------------------- */ |
473 | /* EXTPROTO */ |
579 | void * |
474 | void * |
|
|
475 | rxvt_malloc (size_t size) |
580 | rxvt_malloc (size_t size) |
476 | { |
581 | { |
477 | void *p; |
|
|
478 | |
|
|
479 | p = malloc (size); |
582 | void *p = malloc (size); |
|
|
583 | |
480 | if (p) |
584 | if (!p) |
|
|
585 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
|
|
586 | |
481 | return p; |
587 | return p; |
482 | |
|
|
483 | fprintf (stderr, RESNAME ": memory allocation failure. Aborting"); |
|
|
484 | rxvt_clean_exit (); |
|
|
485 | exit (EXIT_FAILURE); |
|
|
486 | /* NOTREACHED */ |
|
|
487 | } |
588 | } |
488 | |
589 | |
489 | /* EXTPROTO */ |
|
|
490 | void * |
590 | void * |
491 | rxvt_calloc (size_t number, size_t size) |
591 | rxvt_calloc (size_t number, size_t size) |
492 | { |
592 | { |
493 | void *p; |
|
|
494 | |
|
|
495 | p = calloc (number, size); |
593 | void *p = calloc (number, size); |
|
|
594 | |
496 | if (p) |
595 | if (!p) |
|
|
596 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
|
|
597 | |
497 | return p; |
598 | return p; |
498 | |
|
|
499 | fprintf (stderr, RESNAME ": memory allocation failure. Aborting"); |
|
|
500 | rxvt_clean_exit (); |
|
|
501 | exit (EXIT_FAILURE); |
|
|
502 | /* NOTREACHED */ |
|
|
503 | } |
599 | } |
504 | |
600 | |
505 | /* EXTPROTO */ |
|
|
506 | void * |
601 | void * |
507 | rxvt_realloc (void *ptr, size_t size) |
602 | rxvt_realloc (void *ptr, size_t size) |
508 | { |
603 | { |
509 | void *p; |
|
|
510 | |
|
|
511 | if (ptr) |
|
|
512 | p = realloc (ptr, size); |
604 | void *p = realloc (ptr, size); |
513 | else |
605 | |
514 | p = malloc (size); |
|
|
515 | if (p) |
606 | if (!p) |
|
|
607 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
|
|
608 | |
516 | return p; |
609 | return p; |
517 | |
|
|
518 | fprintf (stderr, RESNAME ": memory allocation failure. Aborting"); |
|
|
519 | rxvt_clean_exit (); |
|
|
520 | exit (EXIT_FAILURE); |
|
|
521 | /* NOTREACHED */ |
|
|
522 | } |
610 | } |
523 | |
611 | |
524 | /* ------------------------------------------------------------------------- * |
612 | /* ------------------------------------------------------------------------- * |
525 | * PRIVILEGED OPERATIONS * |
613 | * PRIVILEGED OPERATIONS * |
526 | * ------------------------------------------------------------------------- */ |
614 | * ------------------------------------------------------------------------- */ |
527 | /* take care of suid/sgid super-user (root) privileges */ |
615 | /* take care of suid/sgid super-user (root) privileges */ |
528 | void |
616 | void |
529 | rxvt_term::privileges (int mode) |
617 | rxvt_privileges (rxvt_privaction action) |
530 | { |
618 | { |
|
|
619 | #if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) |
|
|
620 | static uid_t euid; |
|
|
621 | static gid_t egid; |
|
|
622 | #endif |
|
|
623 | |
531 | #if ! defined(__CYGWIN32__) |
624 | #if ! defined(__CYGWIN32__) |
532 | # if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) |
625 | # if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) |
533 | /* setreuid () is the poor man's setuid (), seteuid () */ |
626 | /* setreuid () is the poor man's setuid (), seteuid () */ |
534 | # define seteuid(a) setreuid(-1, (a)) |
627 | # define seteuid(a) setreuid(-1, (a)) |
535 | # define setegid(a) setregid(-1, (a)) |
628 | # define setegid(a) setregid(-1, (a)) |
536 | # define HAVE_SETEUID |
629 | # define HAVE_SETEUID |
537 | # endif |
630 | # endif |
538 | # ifdef HAVE_SETEUID |
631 | # ifdef HAVE_SETEUID |
539 | switch (mode) |
632 | switch (action) |
540 | { |
633 | { |
541 | case IGNORE: |
634 | case IGNORE: |
542 | /* |
635 | /* |
543 | * change effective uid/gid - not real uid/gid - so we can switch |
636 | * change effective uid/gid - not real uid/gid - so we can switch |
544 | * back to root later, as required |
637 | * back to root later, as required |
… | |
… | |
554 | seteuid (euid); |
647 | seteuid (euid); |
555 | setegid (egid); |
648 | setegid (egid); |
556 | break; |
649 | break; |
557 | } |
650 | } |
558 | # else |
651 | # else |
559 | switch (mode) |
652 | switch (action) |
560 | { |
653 | { |
561 | case IGNORE: |
654 | case IGNORE: |
562 | setuid (getuid ()); |
655 | setuid (getuid ()); |
563 | setgid (getgid ()); |
656 | setgid (getgid ()); |
564 | /* FALLTHROUGH */ |
657 | /* FALLTHROUGH */ |
… | |
… | |
571 | #endif |
664 | #endif |
572 | } |
665 | } |
573 | |
666 | |
574 | #ifdef UTMP_SUPPORT |
667 | #ifdef UTMP_SUPPORT |
575 | void |
668 | void |
576 | rxvt_term::privileged_utmp (char action) |
669 | rxvt_term::privileged_utmp (rxvt_privaction action) |
577 | { |
670 | { |
578 | D_MAIN ((stderr, "rxvt_privileged_utmp (%c); waiting for: %c (pid: %d)", |
|
|
579 | action, next_utmp_action, getpid ())); |
|
|
580 | if (next_utmp_action != action || (action != SAVE && action != RESTORE) |
|
|
581 | || (Options & Opt_utmpInhibit) |
671 | if ((options & Opt_utmpInhibit) |
582 | || ttydev == NULL || *ttydev == '\0') |
672 | || !pty.name || !*pty.name) |
583 | return; |
673 | return; |
584 | |
674 | |
585 | privileges (RESTORE); |
675 | rxvt_privileges (RESTORE); |
|
|
676 | |
586 | if (action == SAVE) |
677 | if (action == SAVE) |
587 | { |
|
|
588 | next_utmp_action = RESTORE; |
|
|
589 | makeutent (ttydev, rs[Rs_display_name]); |
678 | makeutent (pty.name, rs[Rs_display_name]); |
590 | } |
|
|
591 | else |
679 | else |
592 | { /* action == RESTORE */ |
|
|
593 | next_utmp_action = IGNORE; |
|
|
594 | cleanutent (); |
680 | cleanutent (); |
595 | } |
681 | |
596 | privileges (IGNORE); |
682 | rxvt_privileges (IGNORE); |
597 | } |
|
|
598 | #endif |
|
|
599 | |
|
|
600 | #ifndef NO_SETOWNER_TTYDEV |
|
|
601 | void |
|
|
602 | rxvt_term::privileged_ttydev (char action) |
|
|
603 | { |
|
|
604 | D_MAIN ((stderr, |
|
|
605 | "privileged_ttydev (%c); waiting for: %c (pid: %d)", |
|
|
606 | action, next_tty_action, getpid ())); |
|
|
607 | if (next_tty_action != action || (action != SAVE && action != RESTORE) |
|
|
608 | || ttydev == NULL || *ttydev == '\0') |
|
|
609 | return; |
|
|
610 | |
|
|
611 | privileges (RESTORE); |
|
|
612 | |
|
|
613 | if (action == SAVE) |
|
|
614 | { |
|
|
615 | next_tty_action = RESTORE; |
|
|
616 | # ifndef RESET_TTY_TO_COMMON_DEFAULTS |
|
|
617 | /* store original tty status for restoration rxvt_clean_exit () -- rgg 04/12/95 */ |
|
|
618 | if (lstat (ttydev, &ttyfd_stat) < 0) /* you lose out */ |
|
|
619 | next_tty_action = IGNORE; |
|
|
620 | else |
|
|
621 | # endif |
|
|
622 | |
|
|
623 | { |
|
|
624 | chown (ttydev, getuid (), ttygid); /* fail silently */ |
|
|
625 | chmod (ttydev, ttymode); |
|
|
626 | # ifdef HAVE_REVOKE |
|
|
627 | revoke (ttydev); |
|
|
628 | # endif |
|
|
629 | |
|
|
630 | } |
|
|
631 | } |
|
|
632 | else |
|
|
633 | { /* action == RESTORE */ |
|
|
634 | next_tty_action = IGNORE; |
|
|
635 | # ifndef RESET_TTY_TO_COMMON_DEFAULTS |
|
|
636 | chmod (ttydev, ttyfd_stat.st_mode); |
|
|
637 | chown (ttydev, ttyfd_stat.st_uid, ttyfd_stat.st_gid); |
|
|
638 | # else |
|
|
639 | chmod (ttydev, |
|
|
640 | (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)); |
|
|
641 | chown (ttydev, 0, 0); |
|
|
642 | # endif |
|
|
643 | |
|
|
644 | } |
|
|
645 | |
|
|
646 | privileges (IGNORE); |
|
|
647 | |
|
|
648 | # ifndef RESET_TTY_TO_COMMON_DEFAULTS |
|
|
649 | D_MAIN ((stderr, "%s \"%s\": mode %03o, uid %d, gid %d", |
|
|
650 | action == RESTORE ? "Restoring" : (action == |
|
|
651 | SAVE ? "Saving" : |
|
|
652 | "UNKNOWN ERROR for"), ttydev, |
|
|
653 | ttyfd_stat.st_mode, ttyfd_stat.st_uid, |
|
|
654 | ttyfd_stat.st_gid)); |
|
|
655 | # endif |
|
|
656 | } |
683 | } |
657 | #endif |
684 | #endif |
658 | |
685 | |
659 | /*----------------------------------------------------------------------*/ |
686 | /*----------------------------------------------------------------------*/ |
660 | /* |
687 | /* |
… | |
… | |
662 | * if width/height are non-zero then override calculated width/height |
689 | * if width/height are non-zero then override calculated width/height |
663 | */ |
690 | */ |
664 | void |
691 | void |
665 | rxvt_term::window_calc (unsigned int width, unsigned int height) |
692 | rxvt_term::window_calc (unsigned int width, unsigned int height) |
666 | { |
693 | { |
667 | short recalc_x, recalc_y; |
694 | short recalc_x, recalc_y; |
668 | int x, y, sb_w, mb_h, flags; |
695 | int x, y, sb_w, mb_h, flags; |
669 | unsigned int w, h; |
696 | unsigned int w, h; |
670 | unsigned int max_width, max_height; |
697 | unsigned int max_width, max_height; |
|
|
698 | dDisp; |
671 | |
699 | |
672 | D_SIZE ((stderr, "< Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d", |
700 | D_SIZE ((stderr, "< Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d", |
673 | TermWin.ncol, TermWin.nrow, szHint.width, |
701 | TermWin.ncol, TermWin.nrow, szHint.width, |
674 | szHint.height)); |
702 | szHint.height)); |
675 | szHint.flags = PMinSize | PResizeInc | PBaseSize | PWinGravity; |
703 | szHint.flags = PMinSize | PResizeInc | PBaseSize | PWinGravity; |
… | |
… | |
681 | if (!parsed_geometry) |
709 | if (!parsed_geometry) |
682 | { |
710 | { |
683 | parsed_geometry = 1; |
711 | parsed_geometry = 1; |
684 | if (rs[Rs_geometry]) |
712 | if (rs[Rs_geometry]) |
685 | flags = XParseGeometry (rs[Rs_geometry], &x, &y, &w, &h); |
713 | flags = XParseGeometry (rs[Rs_geometry], &x, &y, &w, &h); |
|
|
714 | |
686 | if (flags & WidthValue) |
715 | if (flags & WidthValue) |
687 | { |
716 | { |
688 | TermWin.ncol = BOUND_POSITIVE_INT16 (w); |
717 | TermWin.ncol = BOUND_POSITIVE_INT16 (w); |
689 | szHint.flags |= USSize; |
718 | szHint.flags |= USSize; |
690 | } |
719 | } |
|
|
720 | |
691 | if (flags & HeightValue) |
721 | if (flags & HeightValue) |
692 | { |
722 | { |
693 | TermWin.nrow = BOUND_POSITIVE_INT16 (h); |
723 | TermWin.nrow = BOUND_POSITIVE_INT16 (h); |
694 | szHint.flags |= USSize; |
724 | szHint.flags |= USSize; |
695 | } |
725 | } |
|
|
726 | |
696 | if (flags & XValue) |
727 | if (flags & XValue) |
697 | { |
728 | { |
698 | szHint.x = x; |
729 | szHint.x = x; |
699 | szHint.flags |= USPosition; |
730 | szHint.flags |= USPosition; |
700 | if (flags & XNegative) |
731 | if (flags & XNegative) |
701 | { |
732 | { |
702 | recalc_x = 1; |
733 | recalc_x = 1; |
703 | szHint.win_gravity = NorthEastGravity; |
734 | szHint.win_gravity = NorthEastGravity; |
704 | } |
735 | } |
705 | } |
736 | } |
|
|
737 | |
706 | if (flags & YValue) |
738 | if (flags & YValue) |
707 | { |
739 | { |
708 | szHint.y = y; |
740 | szHint.y = y; |
709 | szHint.flags |= USPosition; |
741 | szHint.flags |= USPosition; |
710 | if (flags & YNegative) |
742 | if (flags & YNegative) |
… | |
… | |
725 | max_height = MAX_ROWS * TermWin.fheight; |
757 | max_height = MAX_ROWS * TermWin.fheight; |
726 | |
758 | |
727 | szHint.base_width = szHint.base_height = 2 * TermWin.int_bwidth; |
759 | szHint.base_width = szHint.base_height = 2 * TermWin.int_bwidth; |
728 | |
760 | |
729 | sb_w = mb_h = 0; |
761 | sb_w = mb_h = 0; |
730 | window_vt_x = window_vt_y = 0; |
762 | window_vt_x = window_vt_y = TermWin.int_bwidth; |
|
|
763 | |
731 | if (scrollbar_visible ()) |
764 | if (scrollbar_visible ()) |
732 | { |
765 | { |
733 | sb_w = scrollbar_TotalWidth (); |
766 | sb_w = scrollbar_TotalWidth (); |
734 | szHint.base_width += sb_w; |
767 | szHint.base_width += sb_w; |
735 | if (! (Options & Opt_scrollBar_right)) |
768 | if (!(options & Opt_scrollBar_right)) |
736 | window_vt_x = sb_w; |
769 | window_vt_x += sb_w; |
737 | } |
770 | } |
|
|
771 | |
738 | if (menubar_visible ()) |
772 | if (menubar_visible ()) |
739 | { |
773 | { |
740 | mb_h = menuBar_TotalHeight (); |
774 | mb_h = menuBar_TotalHeight (); |
741 | szHint.base_height += mb_h; |
775 | szHint.base_height += mb_h; |
742 | window_vt_y = mb_h; |
776 | window_vt_y += mb_h; |
743 | } |
777 | } |
|
|
778 | |
744 | szHint.width_inc = TermWin.fwidth; |
779 | szHint.width_inc = TermWin.fwidth; |
745 | szHint.height_inc = TermWin.fheight; |
780 | szHint.height_inc = TermWin.fheight; |
746 | szHint.min_width = szHint.base_width + szHint.width_inc; |
781 | szHint.min_width = szHint.base_width + szHint.width_inc; |
747 | szHint.min_height = szHint.base_height + szHint.height_inc; |
782 | szHint.min_height = szHint.base_height + szHint.height_inc; |
748 | |
783 | |
… | |
… | |
754 | else |
789 | else |
755 | { |
790 | { |
756 | MIN_IT (TermWin.width, max_width); |
791 | MIN_IT (TermWin.width, max_width); |
757 | szHint.width = szHint.base_width + TermWin.width; |
792 | szHint.width = szHint.base_width + TermWin.width; |
758 | } |
793 | } |
|
|
794 | |
759 | if (height && height - szHint.base_height < max_height) |
795 | if (height && height - szHint.base_height < max_height) |
760 | { |
796 | { |
761 | szHint.height = height; |
797 | szHint.height = height; |
762 | TermWin.height = height - szHint.base_height; |
798 | TermWin.height = height - szHint.base_height; |
763 | } |
799 | } |
764 | else |
800 | else |
765 | { |
801 | { |
766 | MIN_IT (TermWin.height, max_height); |
802 | MIN_IT (TermWin.height, max_height); |
767 | szHint.height = szHint.base_height + TermWin.height; |
803 | szHint.height = szHint.base_height + TermWin.height; |
768 | } |
804 | } |
|
|
805 | |
769 | if (scrollbar_visible () && (Options & Opt_scrollBar_right)) |
806 | if (scrollbar_visible () && (options & Opt_scrollBar_right)) |
770 | window_sb_x = szHint.width - sb_w; |
807 | window_sb_x = szHint.width - sb_w; |
771 | |
808 | |
772 | if (recalc_x) |
809 | if (recalc_x) |
773 | szHint.x += (DisplayWidth (display->display, DefaultScreen (display->display)) |
810 | szHint.x += (DisplayWidth (disp, display->screen) |
774 | - szHint.width - 2 * TermWin.ext_bwidth); |
811 | - szHint.width - 2 * TermWin.ext_bwidth); |
775 | if (recalc_y) |
812 | if (recalc_y) |
776 | szHint.y += (DisplayHeight (display->display, DefaultScreen (display->display)) |
813 | szHint.y += (DisplayHeight (disp, display->screen) |
777 | - szHint.height - 2 * TermWin.ext_bwidth); |
814 | - szHint.height - 2 * TermWin.ext_bwidth); |
778 | |
815 | |
779 | TermWin.ncol = TermWin.width / TermWin.fwidth; |
816 | TermWin.ncol = TermWin.width / TermWin.fwidth; |
780 | TermWin.nrow = TermWin.height / TermWin.fheight; |
817 | TermWin.nrow = TermWin.height / TermWin.fheight; |
781 | D_SIZE ((stderr, "> Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d", |
818 | D_SIZE ((stderr, "> Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d", |
… | |
… | |
790 | * Called after a window size change. |
827 | * Called after a window size change. |
791 | */ |
828 | */ |
792 | void |
829 | void |
793 | rxvt_term::tt_winch () |
830 | rxvt_term::tt_winch () |
794 | { |
831 | { |
|
|
832 | if (pty.pty < 0) |
|
|
833 | return; |
|
|
834 | |
795 | struct winsize ws; |
835 | struct winsize ws; |
796 | |
|
|
797 | if (cmd_fd < 0) |
|
|
798 | return; |
|
|
799 | |
836 | |
800 | ws.ws_col = TermWin.ncol; |
837 | ws.ws_col = TermWin.ncol; |
801 | ws.ws_row = TermWin.nrow; |
838 | ws.ws_row = TermWin.nrow; |
802 | ws.ws_xpixel = ws.ws_ypixel = 0; |
839 | ws.ws_xpixel = TermWin.width; |
803 | #ifndef DEBUG_SIZE |
840 | ws.ws_ypixel = TermWin.height; |
804 | (void)ioctl (cmd_fd, TIOCSWINSZ, &ws); |
841 | (void)ioctl (pty.pty, TIOCSWINSZ, &ws); |
805 | #else |
842 | |
806 | if (ioctl (cmd_fd, TIOCSWINSZ, &ws) < 0) |
843 | #if 0 |
807 | D_SIZE ((stderr, "Failed to send TIOCSWINSZ to fd %d", fd)); |
844 | // TIOCSWINSZ⎈ is supposed to do this automatically and correctly |
808 | # ifdef SIGWINCH |
|
|
809 | else if (cmd_pid) /* force through to the command */ |
845 | if (cmd_pid) /* force through to the command */ |
810 | kill (cmd_pid, SIGWINCH); |
846 | kill (-cmd_pid, SIGWINCH); |
811 | # endif |
|
|
812 | #endif |
847 | #endif |
813 | } |
848 | } |
814 | |
849 | |
815 | /*----------------------------------------------------------------------*/ |
850 | /*----------------------------------------------------------------------*/ |
816 | /* rxvt_change_font () - Switch to a new font */ |
851 | /* set_fonts () - load and set the various fonts |
817 | /* |
852 | * |
818 | * init = 1 - initialize |
853 | * init = 1 - initialize |
819 | * |
854 | * |
820 | * fontname == FONT_UP - switch to bigger font |
855 | * fontname == FONT_UP - switch to bigger font |
821 | * fontname == FONT_DN - switch to smaller font |
856 | * fontname == FONT_DN - switch to smaller font |
822 | */ |
857 | */ |
823 | bool |
858 | bool |
824 | rxvt_term::change_font (const char *fontname) |
859 | rxvt_term::set_fonts () |
825 | { |
860 | { |
826 | if (fontname == FONT_UP) |
|
|
827 | { |
|
|
828 | // TODO |
|
|
829 | } |
|
|
830 | else if (fontname == FONT_DN) |
|
|
831 | { |
|
|
832 | // TODO |
|
|
833 | } |
|
|
834 | else |
|
|
835 | { |
|
|
836 | rxvt_fontset *fs = new rxvt_fontset (this); |
861 | rxvt_fontset *fs = new rxvt_fontset (this); |
|
|
862 | rxvt_fontprop prop; |
837 | |
863 | |
838 | if (fs && fs->populate (fontname ? fontname : "fixed")) |
864 | if (!fs |
|
|
865 | || !fs->populate (rs[Rs_font] ? rs[Rs_font] : "fixed") |
|
|
866 | || !fs->realize_font (1)) |
|
|
867 | { |
|
|
868 | delete fs; |
|
|
869 | return false; |
|
|
870 | } |
|
|
871 | |
|
|
872 | #if ENABLE_STYLES |
|
|
873 | for (int i = RS_styleCount; --i; ) |
|
|
874 | if (TermWin.fontset[i] != TermWin.fontset[0]) |
|
|
875 | delete TermWin.fontset[i]; |
|
|
876 | #endif |
|
|
877 | |
|
|
878 | delete TermWin.fontset[0]; |
|
|
879 | TermWin.fontset[0] = fs; |
|
|
880 | |
|
|
881 | prop = (*fs)[1]->properties (); |
|
|
882 | prop.height += TermWin.lineSpace; |
|
|
883 | fs->set_prop (prop); |
|
|
884 | |
|
|
885 | TermWin.fwidth = prop.width; |
|
|
886 | TermWin.fheight = prop.height; |
|
|
887 | TermWin.fweight = prop.weight; |
|
|
888 | TermWin.fslant = prop.slant; |
|
|
889 | TermWin.fbase = (*fs)[1]->ascent; |
|
|
890 | |
|
|
891 | for (int style = 1; style < 4; style++) |
|
|
892 | { |
|
|
893 | #if ENABLE_STYLES |
|
|
894 | const char *res = rs[Rs_font + style]; |
|
|
895 | |
|
|
896 | if (res && !*res) |
|
|
897 | TermWin.fontset[style] = TermWin.fontset[0]; |
|
|
898 | else |
839 | { |
899 | { |
840 | delete TermWin.fontset; |
900 | TermWin.fontset[style] = fs = new rxvt_fontset (this); |
841 | TermWin.fontset = fs; |
901 | rxvt_fontprop prop2 = prop; |
842 | TermWin.fwidth = fs->base_font ()->width; |
|
|
843 | TermWin.fheight = fs->base_font ()->height; |
|
|
844 | TermWin.fbase = fs->base_font ()->ascent; |
|
|
845 | |
902 | |
846 | if (TermWin.parent[0]) |
903 | if (res) |
|
|
904 | prop2.weight = prop2.slant = rxvt_fontprop::unset; |
|
|
905 | else |
847 | { |
906 | { |
848 | resize_all_windows (0, 0, 0); |
907 | res = TermWin.fontset[0]->fontdesc; |
849 | scr_remap_chars (); |
908 | |
850 | scr_touch (true); |
909 | if (SET_STYLE (0, style) & RS_Bold) prop2.weight = rxvt_fontprop::bold; |
|
|
910 | if (SET_STYLE (0, style) & RS_Italic) prop2.slant = rxvt_fontprop::italic; |
851 | } |
911 | } |
852 | |
912 | |
853 | return true; |
913 | fs->populate (res); |
|
|
914 | fs->set_prop (prop2); |
854 | } |
915 | } |
|
|
916 | #else |
|
|
917 | TermWin.fontset[style] = TermWin.fontset[0]; |
|
|
918 | #endif |
|
|
919 | } |
|
|
920 | |
|
|
921 | if (TermWin.parent[0]) |
855 | } |
922 | { |
|
|
923 | resize_all_windows (0, 0, 0); |
|
|
924 | scr_remap_chars (); |
|
|
925 | scr_touch (true); |
|
|
926 | } |
856 | |
927 | |
857 | return false; |
928 | return true; |
858 | } |
929 | } |
859 | |
930 | |
860 | bool |
931 | void rxvt_term::set_string_property (Atom prop, const char *str, int len) |
861 | rxvt_term::font_up_down (int n, int direction) |
|
|
862 | { |
932 | { |
863 | return false; |
933 | // TODO: SMART_WINDOW_TITLE |
|
|
934 | XChangeProperty (display->display, TermWin.parent[0], |
|
|
935 | prop, XA_STRING, 8, PropModeReplace, |
|
|
936 | (const unsigned char *)str, len >= 0 ? len : strlen (str)); |
|
|
937 | } |
|
|
938 | |
|
|
939 | void rxvt_term::set_utf8_property (Atom prop, const char *str, int len) |
|
|
940 | { |
|
|
941 | // TODO: SMART_WINDOW_TITLE |
|
|
942 | wchar_t *ws = rxvt_mbstowcs (str, len); |
|
|
943 | char *s = rxvt_wcstoutf8 (ws); |
|
|
944 | |
|
|
945 | XChangeProperty (display->display, TermWin.parent[0], |
|
|
946 | prop, xa[XA_UTF8_STRING], 8, PropModeReplace, |
|
|
947 | (const unsigned char *)s, strlen (s)); |
|
|
948 | |
|
|
949 | free (s); |
|
|
950 | free (ws); |
864 | } |
951 | } |
865 | |
952 | |
866 | /*----------------------------------------------------------------------*/ |
953 | /*----------------------------------------------------------------------*/ |
867 | /*----------------------------------------------------------------------*/ |
954 | /*----------------------------------------------------------------------*/ |
868 | /* xterm sequences - title, iconName, color (exptl) */ |
955 | /* xterm sequences - title, iconName, color (exptl) */ |
869 | void |
956 | void |
870 | rxvt_term::set_title (const char *str) |
957 | rxvt_term::set_title (const char *str) |
871 | { |
958 | { |
872 | #ifndef SMART_WINDOW_TITLE |
959 | set_string_property (XA_WM_NAME, str); |
873 | XStoreName (display->display, TermWin.parent[0], str); |
960 | #if ENABLE_EWMH |
874 | #else |
961 | set_utf8_property (xa[XA_NET_WM_NAME], str); |
875 | char *name; |
|
|
876 | |
|
|
877 | if (!XFetchName (display->display, TermWin.parent[0], &name)) |
|
|
878 | name = NULL; |
|
|
879 | |
|
|
880 | if (name == NULL || STRCMP (name, str)) |
|
|
881 | XStoreName (display->display, TermWin.parent[0], str); |
|
|
882 | |
|
|
883 | if (name) |
|
|
884 | XFree (name); |
|
|
885 | #endif |
962 | #endif |
886 | } |
963 | } |
887 | |
964 | |
888 | void |
965 | void |
889 | rxvt_term::set_icon_name (const char *str) |
966 | rxvt_term::set_icon_name (const char *str) |
890 | { |
967 | { |
891 | #ifndef SMART_WINDOW_TITLE |
968 | set_string_property (XA_WM_ICON_NAME, str); |
892 | XSetIconName (display->display, TermWin.parent[0], str); |
969 | #if ENABLE_EWMH |
893 | #else |
970 | set_utf8_property (xa[XA_NET_WM_ICON_NAME], str); |
894 | char *name; |
|
|
895 | |
|
|
896 | if (!XGetIconName (display->display, TermWin.parent[0], &name)) |
|
|
897 | name = NULL; |
|
|
898 | |
|
|
899 | if (name == NULL || STRCMP (name, str)) |
|
|
900 | XSetIconName (display->display, TermWin.parent[0], str); |
|
|
901 | |
|
|
902 | if (name) |
|
|
903 | XFree (name); |
|
|
904 | #endif |
971 | #endif |
905 | } |
972 | } |
906 | |
973 | |
907 | #ifdef XTERM_COLOR_CHANGE |
974 | #ifdef XTERM_COLOR_CHANGE |
908 | void |
975 | void |
… | |
… | |
916 | |
983 | |
917 | /* handle color aliases */ |
984 | /* handle color aliases */ |
918 | if (isdigit (*color)) |
985 | if (isdigit (*color)) |
919 | { |
986 | { |
920 | i = atoi (color); |
987 | i = atoi (color); |
|
|
988 | |
921 | if (i >= 8 && i <= 15) |
989 | if (i >= 8 && i <= 15) |
922 | { /* bright colors */ |
990 | { /* bright colors */ |
923 | i -= 8; |
991 | i -= 8; |
924 | # ifndef NO_BRIGHTCOLOR |
992 | # ifndef NO_BRIGHTCOLOR |
925 | PixColors[idx] = PixColors[minBrightCOLOR + i]; |
993 | pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; |
926 | SET_PIXCOLOR (idx); |
994 | SET_PIXCOLOR (idx); |
927 | goto Done; |
995 | goto done; |
928 | # endif |
996 | # endif |
929 | |
|
|
930 | } |
997 | } |
|
|
998 | |
931 | if (i >= 0 && i <= 7) |
999 | if (i >= 0 && i <= 7) |
932 | { /* normal colors */ |
1000 | { /* normal colors */ |
933 | PixColors[idx] = PixColors[minCOLOR + i]; |
1001 | pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; |
934 | SET_PIXCOLOR (idx); |
1002 | SET_PIXCOLOR (idx); |
935 | goto Done; |
1003 | goto done; |
936 | } |
1004 | } |
937 | } |
1005 | } |
|
|
1006 | |
938 | if (!rXParseAllocColor (& xcol, color)) |
1007 | if (!rXParseAllocColor (&xcol, color)) |
939 | return; |
1008 | return; |
|
|
1009 | |
940 | /* XStoreColor (display->display, XCMAP, XColor*); */ |
1010 | /* XStoreColor (display->display, display->cmap, XColor*); */ |
941 | |
1011 | |
942 | /* |
1012 | /* |
943 | * FIXME: should free colors here, but no idea how to do it so instead, |
1013 | * FIXME: should free colors here, but no idea how to do it so instead, |
944 | * so just keep gobbling up the colormap |
1014 | * so just keep gobbling up the colormap |
945 | */ |
1015 | */ |
946 | # if 0 |
1016 | # if 0 |
947 | for (i = Color_Black; i <= Color_White; i++) |
1017 | for (i = Color_Black; i <= Color_White; i++) |
948 | if (PixColors[idx] == PixColors[i]) |
1018 | if (pix_colors[idx] == pix_colors[i]) |
949 | break; |
1019 | break; |
950 | if (i > Color_White) |
1020 | if (i > Color_White) |
951 | { |
1021 | { |
952 | /* fprintf (stderr, "XFreeColors: PixColors [%d] = %lu\n", idx, PixColors [idx]); */ |
1022 | /* fprintf (stderr, "XFreeColors: pix_colors [%d] = %lu\n", idx, pix_colors [idx]); */ |
953 | XFreeColors (display->display, XCMAP, (PixColors + idx), 1, |
1023 | XFreeColors (display->display, display->cmap, (pix_colors + idx), 1, |
954 | DisplayPlanes (display->display, display->screen)); |
1024 | DisplayPlanes (display->display, display->screen)); |
955 | } |
1025 | } |
956 | # endif |
1026 | # endif |
957 | |
1027 | |
958 | PixColors[idx] = xcol; |
1028 | pix_colors_focused[idx] = xcol; |
959 | SET_PIXCOLOR (idx); |
1029 | SET_PIXCOLOR (idx); |
960 | |
1030 | |
961 | /* XSetWindowAttributes attr; */ |
1031 | /* XSetWindowAttributes attr; */ |
962 | /* Cursor cursor; */ |
1032 | /* Cursor cursor; */ |
963 | Done: |
1033 | done: |
964 | if (idx == Color_bg && ! (Options & Opt_transparent)) |
|
|
965 | XSetWindowBackground (display->display, TermWin.vt, |
|
|
966 | PixColors[Color_bg]); |
|
|
967 | |
1034 | |
|
|
1035 | #if OFF_FOCUS_FADING |
|
|
1036 | if (rs[Rs_fade]) |
|
|
1037 | pix_colors_unfocused[idx] = pix_colors_focused[idx].fade (display, atoi (rs[Rs_fade]), pix_colors[Color_fade]); |
|
|
1038 | #endif |
|
|
1039 | |
968 | /* handle Color_BD, scrollbar background, etc. */ |
1040 | /*TODO: handle Color_BD, scrollbar background, etc. */ |
969 | |
1041 | |
970 | set_colorfgbg (); |
|
|
971 | recolour_cursor (); |
1042 | recolour_cursor (); |
972 | /* the only reasonable way to enforce a clean update */ |
1043 | scr_recolour (); |
973 | scr_poweron (); |
|
|
974 | } |
1044 | } |
975 | |
1045 | |
976 | #else |
1046 | #else |
977 | # define set_window_color (idx,color) ((void)0) |
1047 | # define set_window_color (idx,color) ((void)0) |
978 | #endif /* XTERM_COLOR_CHANGE */ |
1048 | #endif /* XTERM_COLOR_CHANGE */ |
979 | |
1049 | |
980 | void |
1050 | void |
981 | rxvt_term::recolour_cursor () |
1051 | rxvt_term::recolour_cursor () |
982 | { |
1052 | { |
983 | #if TODO |
|
|
984 | rxvt_color xcol[2]; |
1053 | XColor xcol[2]; |
985 | |
1054 | |
986 | xcol[0] = PixColors[Color_pointer]; |
1055 | xcol[0].pixel = ISSET_PIXCOLOR (Color_pointer_fg) |
987 | xcol[1] = PixColors[Color_bg]; |
1056 | ? pix_colors_focused[Color_pointer_fg] |
|
|
1057 | : pix_colors_focused[Color_fg]; |
|
|
1058 | xcol[1].pixel = ISSET_PIXCOLOR (Color_pointer_bg) |
|
|
1059 | ? pix_colors_focused[Color_pointer_bg] |
|
|
1060 | : pix_colors_focused[Color_bg]; |
|
|
1061 | |
988 | XQueryColors (display->display, XCMAP, xcol, 2); |
1062 | XQueryColors (display->display, display->cmap, xcol, 2); |
989 | XRecolorCursor (display->display, TermWin_cursor, & (xcol[0]), & (xcol[1])); |
1063 | XRecolorCursor (display->display, TermWin_cursor, xcol + 0, xcol + 1); |
990 | #endif |
|
|
991 | } |
1064 | } |
992 | |
1065 | |
993 | /*----------------------------------------------------------------------*/ |
1066 | /*----------------------------------------------------------------------*/ |
994 | /* |
1067 | /* |
995 | * find if fg/bg matches any of the normal (low-intensity) colors |
1068 | * find if fg/bg matches any of the normal (low-intensity) colors |
996 | */ |
1069 | */ |
997 | void |
1070 | void |
998 | rxvt_term::set_colorfgbg () |
1071 | rxvt_term::set_colorfgbg () |
999 | { |
1072 | { |
1000 | unsigned int i; |
1073 | unsigned int i; |
1001 | const char *xpmb = "\0"; |
1074 | const char *xpmb = "\0"; |
1002 | char fstr[sizeof ("default") + 1], bstr[sizeof ("default") + 1]; |
1075 | char fstr[sizeof ("default") + 1], bstr[sizeof ("default") + 1]; |
1003 | |
1076 | |
1004 | env_colorfgbg = |
|
|
1005 | (char *)rxvt_malloc (sizeof ("COLORFGBG=default;default;bg") + 1); |
1077 | env_colorfgbg = (char *)rxvt_malloc (sizeof ("COLORFGBG=default;default;bg") + 1); |
1006 | STRCPY (fstr, "default"); |
1078 | strcpy (fstr, "default"); |
1007 | STRCPY (bstr, "default"); |
1079 | strcpy (bstr, "default"); |
1008 | for (i = Color_Black; i <= Color_White; i++) |
1080 | for (i = Color_Black; i <= Color_White; i++) |
1009 | if (PixColors[Color_fg] == PixColors[i]) |
1081 | if (pix_colors[Color_fg] == pix_colors[i]) |
1010 | { |
1082 | { |
1011 | sprintf (fstr, "%d", (i - Color_Black)); |
1083 | sprintf (fstr, "%d", (i - Color_Black)); |
1012 | break; |
1084 | break; |
1013 | } |
1085 | } |
|
|
1086 | |
1014 | for (i = Color_Black; i <= Color_White; i++) |
1087 | for (i = Color_Black; i <= Color_White; i++) |
1015 | if (PixColors[Color_bg] == PixColors[i]) |
1088 | if (pix_colors[Color_bg] == pix_colors[i]) |
1016 | { |
1089 | { |
1017 | sprintf (bstr, "%d", (i - Color_Black)); |
1090 | sprintf (bstr, "%d", (i - Color_Black)); |
1018 | #ifdef XPM_BACKGROUND |
1091 | #ifdef XPM_BACKGROUND |
1019 | xpmb = "default;"; |
1092 | xpmb = "default;"; |
1020 | #endif |
1093 | #endif |
1021 | break; |
1094 | break; |
1022 | } |
1095 | } |
1023 | |
1096 | |
1024 | sprintf (env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr); |
1097 | sprintf (env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr); |
1025 | |
|
|
1026 | #ifndef NO_BRIGHTCOLOR |
|
|
1027 | colorfgbg = DEFAULT_RSTYLE; |
|
|
1028 | for (i = minCOLOR; i <= maxCOLOR; i++) |
|
|
1029 | { |
|
|
1030 | if (PixColors[Color_fg] == PixColors[i]) |
|
|
1031 | colorfgbg = SET_FGCOLOR (colorfgbg, i); |
|
|
1032 | if (PixColors[Color_bg] == PixColors[i]) |
|
|
1033 | colorfgbg = SET_BGCOLOR (colorfgbg, i); |
|
|
1034 | } |
|
|
1035 | #endif |
|
|
1036 | } |
1098 | } |
1037 | |
1099 | |
1038 | /*----------------------------------------------------------------------*/ |
1100 | /*----------------------------------------------------------------------*/ |
1039 | /* |
|
|
1040 | * Colour determination for low colour displays, routine from |
|
|
1041 | * Hans de Goede <hans@highrise.nl> |
|
|
1042 | */ |
|
|
1043 | |
1101 | |
1044 | int |
1102 | int |
1045 | rxvt_term::rXParseAllocColor (rxvt_color *screen_in_out, const char *colour) |
1103 | rxvt_term::rXParseAllocColor (rxvt_color *screen_in_out, const char *colour) |
1046 | { |
1104 | { |
1047 | if (!screen_in_out->set (display, colour)) |
1105 | if (!screen_in_out->set (display, colour)) |
… | |
… | |
1058 | * -------------------------------------------------------------------- */ |
1116 | * -------------------------------------------------------------------- */ |
1059 | void |
1117 | void |
1060 | rxvt_term::resize_all_windows (unsigned int width, unsigned int height, int ignoreparent) |
1118 | rxvt_term::resize_all_windows (unsigned int width, unsigned int height, int ignoreparent) |
1061 | { |
1119 | { |
1062 | int fix_screen; |
1120 | int fix_screen; |
1063 | |
|
|
1064 | #ifdef SMART_RESIZE |
1121 | #ifdef SMART_RESIZE |
1065 | int old_width = szHint.width, old_height = szHint.height; |
1122 | int old_width = szHint.width, old_height = szHint.height; |
1066 | #endif |
1123 | #endif |
|
|
1124 | dDisp; |
1067 | |
1125 | |
1068 | window_calc (width, height); |
1126 | window_calc (width, height); |
1069 | XSetWMNormalHints (display->display, TermWin.parent[0], &szHint); |
1127 | XSetWMNormalHints (disp, TermWin.parent[0], &szHint); |
|
|
1128 | |
1070 | if (!ignoreparent) |
1129 | if (!ignoreparent) |
1071 | { |
1130 | { |
1072 | #ifdef SMART_RESIZE |
1131 | #ifdef SMART_RESIZE |
1073 | /* |
1132 | /* |
1074 | * resize by Marius Gedminas <marius.gedminas@uosis.mif.vu.lt> |
1133 | * resize by Marius Gedminas <marius.gedminas@uosis.mif.vu.lt> |
… | |
… | |
1077 | int x, y, x1, y1; |
1136 | int x, y, x1, y1; |
1078 | int dx, dy; |
1137 | int dx, dy; |
1079 | unsigned int unused_w1, unused_h1, unused_b1, unused_d1; |
1138 | unsigned int unused_w1, unused_h1, unused_b1, unused_d1; |
1080 | Window unused_cr; |
1139 | Window unused_cr; |
1081 | |
1140 | |
1082 | XTranslateCoordinates (display->display, TermWin.parent[0], display->root, |
1141 | XTranslateCoordinates (disp, TermWin.parent[0], display->root, |
1083 | 0, 0, &x, &y, &unused_cr); |
1142 | 0, 0, &x, &y, &unused_cr); |
1084 | XGetGeometry (display->display, TermWin.parent[0], &unused_cr, &x1, &y1, |
1143 | XGetGeometry (disp, TermWin.parent[0], &unused_cr, &x1, &y1, |
1085 | &unused_w1, &unused_h1, &unused_b1, &unused_d1); |
1144 | &unused_w1, &unused_h1, &unused_b1, &unused_d1); |
1086 | /* |
1145 | /* |
1087 | * if display->root isn't the parent window, a WM will probably have offset |
1146 | * if display->root isn't the parent window, a WM will probably have offset |
1088 | * our position for handles and decorations. Counter it |
1147 | * our position for handles and decorations. Counter it |
1089 | */ |
1148 | */ |
… | |
… | |
1091 | { |
1150 | { |
1092 | x -= x1; |
1151 | x -= x1; |
1093 | y -= y1; |
1152 | y -= y1; |
1094 | } |
1153 | } |
1095 | |
1154 | |
1096 | x1 = (DisplayWidth (display->display, display->screen) - old_width) / 2; |
1155 | x1 = (DisplayWidth (disp, display->screen) - old_width) / 2; |
1097 | y1 = (DisplayHeight (display->display, display->screen) - old_height) / 2; |
1156 | y1 = (DisplayHeight (disp, display->screen) - old_height) / 2; |
1098 | dx = old_width - szHint.width; |
1157 | dx = old_width - szHint.width; |
1099 | dy = old_height - szHint.height; |
1158 | dy = old_height - szHint.height; |
1100 | |
1159 | |
1101 | /* Check position of the center of the window */ |
1160 | /* Check position of the center of the window */ |
1102 | if (x < x1) /* left half */ |
1161 | if (x < x1) /* left half */ |
… | |
… | |
1106 | if (y < y1) /* top half */ |
1165 | if (y < y1) /* top half */ |
1107 | dy = 0; |
1166 | dy = 0; |
1108 | else if (y == y1) /* exact center */ |
1167 | else if (y == y1) /* exact center */ |
1109 | dy /= 2; |
1168 | dy /= 2; |
1110 | |
1169 | |
1111 | XMoveResizeWindow (display->display, TermWin.parent[0], x + dx, y + dy, |
1170 | XMoveResizeWindow (disp, TermWin.parent[0], x + dx, y + dy, |
1112 | szHint.width, szHint.height); |
1171 | szHint.width, szHint.height); |
1113 | #else |
1172 | #else |
1114 | XResizeWindow (display->display, TermWin.parent[0], szHint.width, |
1173 | XResizeWindow (disp, TermWin.parent[0], szHint.width, szHint.height); |
1115 | szHint.height); |
|
|
1116 | #endif |
1174 | #endif |
1117 | |
|
|
1118 | } |
1175 | } |
1119 | |
1176 | |
1120 | fix_screen = (TermWin.ncol != prev_ncol |
1177 | fix_screen = TermWin.ncol != prev_ncol || TermWin.nrow != prev_nrow; |
1121 | || TermWin.nrow != prev_nrow); |
|
|
1122 | |
1178 | |
1123 | if (fix_screen || width != old_width || height != old_height) |
1179 | if (fix_screen || width != old_width || height != old_height) |
1124 | { |
1180 | { |
1125 | if (scrollbar_visible ()) |
1181 | if (scrollbar_visible ()) |
1126 | { |
1182 | { |
1127 | XMoveResizeWindow (display->display, scrollBar.win, window_sb_x, |
1183 | XMoveResizeWindow (disp, scrollBar.win, |
|
|
1184 | window_sb_x, 0, |
1128 | 0, scrollbar_TotalWidth (), szHint.height); |
1185 | scrollbar_TotalWidth (), szHint.height); |
1129 | resize_scrollbar (); |
1186 | resize_scrollbar (); |
1130 | } |
1187 | } |
1131 | |
1188 | |
1132 | if (menubar_visible ()) |
1189 | if (menubar_visible ()) |
1133 | XMoveResizeWindow (display->display, menuBar.win, window_vt_x, |
1190 | XMoveResizeWindow (disp, menuBar.win, |
|
|
1191 | window_vt_x, 0, |
1134 | 0, TermWin_TotalWidth (), menuBar_TotalHeight ()); |
1192 | TermWin_TotalWidth (), menuBar_TotalHeight ()); |
1135 | |
1193 | |
1136 | XMoveResizeWindow (display->display, TermWin.vt, window_vt_x, |
1194 | XMoveResizeWindow (disp, TermWin.vt, |
1137 | window_vt_y, TermWin_TotalWidth (), |
1195 | window_vt_x, window_vt_y, |
1138 | TermWin_TotalHeight ()); |
1196 | TermWin_TotalWidth (), TermWin_TotalHeight ()); |
1139 | scr_clear (height != old_height); |
1197 | |
|
|
1198 | scr_clear (); |
1140 | #ifdef XPM_BACKGROUND |
1199 | #ifdef XPM_BACKGROUND |
1141 | resize_pixmap (); |
1200 | resize_pixmap (); |
1142 | #endif |
1201 | #endif |
1143 | |
|
|
1144 | } |
1202 | } |
1145 | |
1203 | |
1146 | if (fix_screen || old_height == 0) |
1204 | if (fix_screen || old_height == 0) |
1147 | { |
1205 | { |
1148 | int curr_screen = -1; |
1206 | int curr_screen = -1; |
… | |
… | |
1167 | } |
1225 | } |
1168 | |
1226 | |
1169 | old_width = szHint.width; |
1227 | old_width = szHint.width; |
1170 | old_height = szHint.height; |
1228 | old_height = szHint.height; |
1171 | |
1229 | |
|
|
1230 | #ifdef XPM_BACKGROUND |
|
|
1231 | if (TermWin.pixmap) |
|
|
1232 | scr_touch (false); |
|
|
1233 | #endif |
|
|
1234 | |
1172 | #ifdef USE_XIM |
1235 | #ifdef USE_XIM |
1173 | IMSetStatusPosition (); |
1236 | IMSetStatusPosition (); |
1174 | #endif |
1237 | #endif |
1175 | } |
1238 | } |
1176 | |
1239 | |
… | |
… | |
1184 | XWindowAttributes wattr; |
1247 | XWindowAttributes wattr; |
1185 | |
1248 | |
1186 | if (width == 0 || height == 0) |
1249 | if (width == 0 || height == 0) |
1187 | { |
1250 | { |
1188 | XGetWindowAttributes (display->display, display->root, &wattr); |
1251 | XGetWindowAttributes (display->display, display->root, &wattr); |
|
|
1252 | |
1189 | if (width == 0) |
1253 | if (width == 0) |
1190 | width = wattr.width - szHint.base_width; |
1254 | width = wattr.width - szHint.base_width; |
1191 | if (height == 0) |
1255 | if (height == 0) |
1192 | height = wattr.height - szHint.base_height; |
1256 | height = wattr.height - szHint.base_height; |
1193 | } |
1257 | } |
|
|
1258 | |
1194 | if (width != TermWin.width || height != TermWin.height) |
1259 | if (width != TermWin.width || height != TermWin.height) |
1195 | { |
1260 | { |
1196 | width += szHint.base_width; |
1261 | width += szHint.base_width; |
1197 | height += szHint.base_height; |
1262 | height += szHint.base_height; |
1198 | resize_all_windows (width, height, 0); |
1263 | resize_all_windows (width, height, 0); |
… | |
… | |
1203 | * - X INPUT METHOD ROUTINES - * |
1268 | * - X INPUT METHOD ROUTINES - * |
1204 | * -------------------------------------------------------------------- */ |
1269 | * -------------------------------------------------------------------- */ |
1205 | #ifdef USE_XIM |
1270 | #ifdef USE_XIM |
1206 | |
1271 | |
1207 | void |
1272 | void |
|
|
1273 | rxvt_term::im_set_color (unsigned long &fg, unsigned long &bg) |
|
|
1274 | { |
|
|
1275 | fg = pix_colors[Color_fg]; |
|
|
1276 | bg = pix_colors[Color_bg]; |
|
|
1277 | } |
|
|
1278 | |
|
|
1279 | void |
1208 | rxvt_term::im_set_size (XRectangle *size) |
1280 | rxvt_term::im_set_size (XRectangle &size) |
1209 | { |
1281 | { |
|
|
1282 | // the int_bwidth terms make no sense to me |
1210 | size->x = TermWin.int_bwidth; |
1283 | size.x = TermWin.int_bwidth; |
1211 | size->y = TermWin.int_bwidth; |
1284 | size.y = TermWin.int_bwidth; |
1212 | size->width = Width2Pixel (TermWin.ncol); |
1285 | size.width = Width2Pixel (TermWin.ncol) + TermWin.int_bwidth; |
1213 | size->height = Height2Pixel (TermWin.nrow); |
1286 | size.height = Height2Pixel (TermWin.nrow) + TermWin.int_bwidth; |
1214 | } |
1287 | } |
1215 | |
1288 | |
1216 | void |
1289 | void |
1217 | rxvt_term::im_set_color (unsigned long *fg, unsigned long *bg) |
1290 | rxvt_term::im_set_preedit_area (XRectangle &preedit_rect, |
|
|
1291 | XRectangle &status_rect, |
|
|
1292 | const XRectangle &needed_rect) |
1218 | { |
1293 | { |
1219 | *fg = PixColors[Color_fg]; |
1294 | preedit_rect.x = needed_rect.width; |
1220 | *bg = PixColors[Color_bg]; |
1295 | preedit_rect.y = 0; |
|
|
1296 | preedit_rect.width = Width2Pixel (TermWin.ncol) - needed_rect.width + 1; |
|
|
1297 | preedit_rect.height = TermWin.fheight; |
|
|
1298 | |
|
|
1299 | status_rect.x = 0; |
|
|
1300 | status_rect.y = 0; |
|
|
1301 | status_rect.width = needed_rect.width ? needed_rect.width : Width2Pixel (TermWin.ncol) + 1; |
|
|
1302 | status_rect.height = TermWin.fheight; |
1221 | } |
1303 | } |
1222 | |
1304 | |
1223 | /* Checking whether input method is running. */ |
1305 | /* Checking whether input method is running. */ |
1224 | bool |
1306 | bool |
1225 | rxvt_term::IMisRunning () |
1307 | rxvt_term::IMisRunning () |
1226 | { |
1308 | { |
1227 | char *p; |
1309 | char *p; |
1228 | Atom atom; |
1310 | Atom atom; |
1229 | Window win; |
1311 | Window win; |
1230 | char server[IMBUFSIZ]; |
1312 | char server[IMBUFSIZ]; |
1231 | |
1313 | |
1232 | /* get current locale modifier */ |
1314 | /* get current locale modifier */ |
1233 | if ((p = XSetLocaleModifiers (NULL)) != NULL) |
1315 | if ((p = XSetLocaleModifiers (NULL)) != NULL) |
1234 | { |
1316 | { |
1235 | STRCPY (server, "@server="); |
1317 | strcpy (server, "@server="); |
1236 | STRNCAT (server, & (p[4]), IMBUFSIZ - 9); /* skip "@im=" */ |
1318 | strncat (server, & (p[4]), IMBUFSIZ - 9); /* skip "@im=" */ |
|
|
1319 | |
1237 | if ((p = STRCHR (server + 1, '@')) != NULL) /* first one only */ |
1320 | if ((p = strchr (server + 1, '@')) != NULL) /* first one only */ |
1238 | *p = '\0'; |
1321 | *p = '\0'; |
1239 | |
1322 | |
1240 | atom = XInternAtom (display->display, server, False); |
1323 | atom = XInternAtom (display->display, server, False); |
1241 | win = XGetSelectionOwner (display->display, atom); |
1324 | win = XGetSelectionOwner (display->display, atom); |
|
|
1325 | |
1242 | if (win != None) |
1326 | if (win != None) |
1243 | return True; |
1327 | return True; |
1244 | } |
1328 | } |
|
|
1329 | |
1245 | return False; |
1330 | return False; |
1246 | } |
1331 | } |
1247 | |
1332 | |
1248 | void |
1333 | void |
1249 | rxvt_term::IMSendSpot () |
1334 | rxvt_term::IMSendSpot () |
1250 | { |
1335 | { |
1251 | XPoint spot; |
1336 | XPoint nspot; |
1252 | XVaNestedList preedit_attr; |
1337 | XVaNestedList preedit_attr; |
1253 | |
1338 | |
1254 | if (Input_Context == NULL |
1339 | if (!Input_Context |
|
|
1340 | || !TermWin.focus |
1255 | || !TermWin.focus || ! (input_style & XIMPreeditPosition) |
1341 | || !(input_style & XIMPreeditPosition)) |
1256 | || ! (event_type == KeyPress |
|
|
1257 | || event_type == Expose |
|
|
1258 | || event_type == NoExpose |
|
|
1259 | || event_type == SelectionNotify |
|
|
1260 | || event_type == ButtonRelease || event_type == FocusIn) |
|
|
1261 | || !IMisRunning ()) |
|
|
1262 | return; |
1342 | return; |
1263 | |
1343 | |
1264 | im_set_position (&spot); |
1344 | im_set_position (nspot); |
|
|
1345 | |
|
|
1346 | if (nspot.x == spot.x && nspot.y == spot.y) |
|
|
1347 | return; |
|
|
1348 | |
|
|
1349 | spot = nspot; |
1265 | |
1350 | |
1266 | preedit_attr = XVaCreateNestedList (0, XNSpotLocation, &spot, NULL); |
1351 | preedit_attr = XVaCreateNestedList (0, XNSpotLocation, &spot, NULL); |
1267 | XSetICValues (Input_Context, XNPreeditAttributes, preedit_attr, NULL); |
1352 | XSetICValues (Input_Context, XNPreeditAttributes, preedit_attr, NULL); |
1268 | XFree (preedit_attr); |
1353 | XFree (preedit_attr); |
1269 | } |
1354 | } |
1270 | |
1355 | |
1271 | void |
1356 | void |
1272 | rxvt_term::im_set_preedit_area (XRectangle * preedit_rect, XRectangle * status_rect, |
|
|
1273 | XRectangle * needed_rect) |
|
|
1274 | { |
|
|
1275 | int mbh, vtx = 0; |
|
|
1276 | |
|
|
1277 | if (scrollbar_visible () && ! (Options & Opt_scrollBar_right)) |
|
|
1278 | vtx = scrollbar_TotalWidth (); |
|
|
1279 | |
|
|
1280 | mbh = menubar_visible () ? menuBar_TotalHeight () : 0; |
|
|
1281 | mbh -= TermWin.lineSpace; |
|
|
1282 | |
|
|
1283 | preedit_rect->x = needed_rect->width + vtx; |
|
|
1284 | preedit_rect->y = Height2Pixel (TermWin.nrow - 1) + mbh; |
|
|
1285 | |
|
|
1286 | preedit_rect->width = Width2Pixel (TermWin.ncol + 1) - needed_rect->width + vtx; |
|
|
1287 | preedit_rect->height = Height2Pixel (1); |
|
|
1288 | |
|
|
1289 | status_rect->x = vtx; |
|
|
1290 | status_rect->y = Height2Pixel (TermWin.nrow - 1) + mbh; |
|
|
1291 | |
|
|
1292 | status_rect->width = needed_rect->width ? needed_rect->width : Width2Pixel (TermWin.ncol + 1); |
|
|
1293 | status_rect->height = Height2Pixel (1); |
|
|
1294 | } |
|
|
1295 | |
|
|
1296 | void |
|
|
1297 | rxvt_term::im_destroy () |
1357 | rxvt_term::im_destroy () |
1298 | { |
1358 | { |
1299 | if (Input_Context) |
|
|
1300 | { |
|
|
1301 | XDestroyIC (Input_Context); |
|
|
1302 | Input_Context = NULL; |
|
|
1303 | } |
|
|
1304 | |
|
|
1305 | if (input_method) |
1359 | if (input_method) |
1306 | { |
1360 | { |
|
|
1361 | if (Input_Context && input_method->xim) |
|
|
1362 | XDestroyIC (Input_Context); |
|
|
1363 | |
1307 | display->put_xim (input_method); |
1364 | display->put_xim (input_method); |
1308 | input_method = 0; |
1365 | input_method = 0; |
1309 | } |
1366 | } |
|
|
1367 | |
|
|
1368 | Input_Context = 0; |
1310 | } |
1369 | } |
1311 | |
1370 | |
1312 | /* |
1371 | /* |
1313 | * Try to open a XIM with the current modifiers, then see if we can |
1372 | * Try to open a XIM with the current modifiers, then see if we can |
1314 | * open a suitable preedit type |
1373 | * open a suitable preedit type |
1315 | */ |
1374 | */ |
1316 | bool |
1375 | bool |
1317 | rxvt_term::IM_get_IC (const char *modifiers) |
1376 | rxvt_term::IM_get_IC (const char *modifiers) |
1318 | { |
1377 | { |
1319 | int i, j, found; |
1378 | int i, j, found; |
1320 | XIM xim; |
1379 | XIM xim; |
1321 | XPoint spot; |
1380 | XPoint spot; |
1322 | XRectangle rect, status_rect, needed_rect; |
1381 | XRectangle rect, status_rect, needed_rect; |
1323 | unsigned long fg, bg; |
1382 | unsigned long fg, bg; |
1324 | const char *p; |
1383 | const char *p; |
1325 | char **s; |
1384 | char **s; |
1326 | XIMStyles *xim_styles; |
1385 | XIMStyles *xim_styles; |
1327 | XVaNestedList preedit_attr, status_attr; |
|
|
1328 | |
1386 | |
1329 | if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) |
1387 | if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) |
1330 | return false; |
1388 | return false; |
1331 | |
1389 | |
1332 | D_MAIN ((stderr, "rxvt_IM_get_IC ()")); |
1390 | D_MAIN ((stderr, "rxvt_IM_get_IC ()")); |
1333 | input_method = display->get_xim (locale, modifiers); |
1391 | input_method = display->get_xim (locale, modifiers); |
1334 | if (input_method == NULL) |
1392 | if (input_method == NULL) |
1335 | return false; |
1393 | return false; |
1336 | |
1394 | |
1337 | xim = input_method->xim; |
1395 | xim = input_method->xim; |
|
|
1396 | spot.x = spot.y = -1; |
1338 | |
1397 | |
1339 | xim_styles = NULL; |
1398 | xim_styles = NULL; |
1340 | if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL) |
1399 | if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL) |
1341 | || !xim_styles || !xim_styles->count_styles) |
1400 | || !xim_styles || !xim_styles->count_styles) |
1342 | { |
1401 | { |
1343 | display->put_xim (input_method); |
1402 | im_destroy (); |
1344 | return false; |
1403 | return false; |
1345 | } |
1404 | } |
1346 | |
1405 | |
1347 | p = rs[Rs_preeditType] ? rs[Rs_preeditType] : "OverTheSpot,OffTheSpot,Root"; |
1406 | const char *pet[] = { rs[Rs_preeditType], "OverTheSpot,OffTheSpot,Root,None" }; |
|
|
1407 | |
|
|
1408 | for (int pi = 0; pi < 2; pi++) |
|
|
1409 | { |
|
|
1410 | p = pet[pi]; |
|
|
1411 | |
|
|
1412 | if (!p) |
|
|
1413 | continue; |
|
|
1414 | |
1348 | s = rxvt_splitcommastring (p); |
1415 | s = rxvt_splitcommastring (p); |
|
|
1416 | |
1349 | for (i = found = 0; !found && s[i]; i++) |
1417 | for (i = found = 0; !found && s[i]; i++) |
1350 | { |
1418 | { |
1351 | if (!STRCMP (s[i], "OverTheSpot")) |
1419 | if (!strcmp (s[i], "OverTheSpot")) |
1352 | input_style = (XIMPreeditPosition | XIMStatusNothing); |
1420 | input_style = (XIMPreeditPosition | XIMStatusNothing); |
1353 | else if (!STRCMP (s[i], "OffTheSpot")) |
1421 | else if (!strcmp (s[i], "OffTheSpot")) |
1354 | input_style = (XIMPreeditArea | XIMStatusArea); |
1422 | input_style = (XIMPreeditArea | XIMStatusArea); |
1355 | else if (!STRCMP (s[i], "Root")) |
1423 | else if (!strcmp (s[i], "Root")) |
1356 | input_style = (XIMPreeditNothing | XIMStatusNothing); |
1424 | input_style = (XIMPreeditNothing | XIMStatusNothing); |
|
|
1425 | else if (!strcmp (s[i], "None")) |
|
|
1426 | input_style = (XIMPreeditNone | XIMStatusNone); |
1357 | |
1427 | |
1358 | for (j = 0; j < xim_styles->count_styles; j++) |
1428 | for (j = 0; j < xim_styles->count_styles; j++) |
1359 | if (input_style == xim_styles->supported_styles[j]) |
1429 | if (input_style == xim_styles->supported_styles[j]) |
1360 | { |
1430 | { |
|
|
1431 | rxvt_freecommastring (s); |
|
|
1432 | |
1361 | found = 1; |
1433 | found = 1; |
1362 | break; |
1434 | goto foundpet; |
|
|
1435 | } |
|
|
1436 | |
1363 | } |
1437 | } |
1364 | } |
|
|
1365 | |
1438 | |
1366 | for (i = 0; s[i]; i++) |
1439 | rxvt_freecommastring (s); |
1367 | free (s[i]); |
1440 | } |
1368 | |
1441 | |
1369 | free (s); |
1442 | foundpet: |
|
|
1443 | |
1370 | XFree (xim_styles); |
1444 | XFree (xim_styles); |
1371 | |
1445 | |
1372 | if (!found) |
1446 | if (!found) |
1373 | { |
1447 | { |
1374 | display->put_xim (input_method); |
1448 | im_destroy (); |
1375 | return false; |
1449 | return false; |
1376 | } |
1450 | } |
1377 | |
1451 | |
1378 | preedit_attr = status_attr = NULL; |
1452 | XFontSet fs = 0; |
|
|
1453 | XVaNestedList preedit_attr = 0, status_attr = 0; |
|
|
1454 | |
|
|
1455 | if (input_style & (XIMPreeditPosition | XIMPreeditArea)) |
|
|
1456 | { |
|
|
1457 | // fake us a font-set, please |
|
|
1458 | char **missing_charset_list; |
|
|
1459 | int missing_charset_count; |
|
|
1460 | char *def_string; |
|
|
1461 | char pat[512]; |
|
|
1462 | |
|
|
1463 | sprintf (pat, |
|
|
1464 | "-*-*-*-R-*-*-%d-*-*-*-*-*-*," |
|
|
1465 | "-*-*-*-R-*-*-%d-*-*-*-*-*-*," |
|
|
1466 | "-*-*-*-R-*-*-%d-*-*-*-*-*-*," |
|
|
1467 | "-*-*-*-R-*-*-%d-*-*-*-*-*-*," |
|
|
1468 | "-*-*-*-R-*-*-%d-*-*-*-*-*-*," |
|
|
1469 | "*", |
|
|
1470 | TermWin.fheight, |
|
|
1471 | TermWin.fheight + 1, TermWin.fheight - 1, |
|
|
1472 | TermWin.fheight - 2, TermWin.fheight + 2); |
|
|
1473 | |
|
|
1474 | fs = XCreateFontSet (display->display, rs[Rs_imFont] ? rs[Rs_imFont] : pat, |
|
|
1475 | &missing_charset_list, &missing_charset_count, &def_string); |
|
|
1476 | |
|
|
1477 | if (missing_charset_list) |
|
|
1478 | XFreeStringList (missing_charset_list); |
|
|
1479 | |
|
|
1480 | if (!fs) |
|
|
1481 | { |
|
|
1482 | input_style &= ~(XIMPreeditPosition | XIMPreeditArea); |
|
|
1483 | rxvt_warn ("unable to create fontset for input method, try \"-pt Root\". Continuing.\n"); |
|
|
1484 | } |
|
|
1485 | } |
1379 | |
1486 | |
1380 | if (input_style & XIMPreeditPosition) |
1487 | if (input_style & XIMPreeditPosition) |
1381 | { |
1488 | { |
1382 | im_set_size (&rect); |
1489 | im_set_size (rect); |
1383 | im_set_position (&spot); |
1490 | im_set_position (spot); |
1384 | im_set_color (&fg, &bg); |
1491 | im_set_color (fg, bg); |
1385 | |
1492 | |
1386 | preedit_attr = XVaCreateNestedList (0, XNArea, &rect, |
1493 | preedit_attr = XVaCreateNestedList (0, |
|
|
1494 | XNForeground, fg, |
|
|
1495 | XNBackground, bg, |
|
|
1496 | XNArea, &rect, |
1387 | XNSpotLocation, &spot, |
1497 | XNSpotLocation, &spot, |
1388 | XNForeground, fg, XNBackground, bg, |
|
|
1389 | //XNFontSet, TermWin.fontset, |
1498 | XNFontSet, fs, |
1390 | NULL); |
1499 | NULL); |
1391 | } |
1500 | } |
1392 | else if (input_style & XIMPreeditArea) |
1501 | else if (input_style & XIMPreeditArea) |
1393 | { |
1502 | { |
1394 | im_set_color (&fg, &bg); |
1503 | im_set_color (fg, bg); |
1395 | |
1504 | |
1396 | /* |
1505 | /* |
1397 | * The necessary width of preedit area is unknown |
1506 | * The necessary width of preedit area is unknown |
1398 | * until create input context. |
1507 | * until create input context. |
1399 | */ |
1508 | */ |
1400 | needed_rect.width = 0; |
1509 | needed_rect.width = 0; |
1401 | |
|
|
1402 | im_set_preedit_area (&rect, &status_rect, &needed_rect); |
1510 | im_set_preedit_area (rect, status_rect, needed_rect); |
1403 | |
1511 | |
1404 | preedit_attr = XVaCreateNestedList (0, XNArea, &rect, |
1512 | preedit_attr = XVaCreateNestedList (0, |
|
|
1513 | XNForeground, fg, |
1405 | XNForeground, fg, XNBackground, bg, |
1514 | XNBackground, bg, |
|
|
1515 | XNArea, &rect, |
|
|
1516 | XNFontSet, fs, |
|
|
1517 | NULL); |
|
|
1518 | status_attr = XVaCreateNestedList (0, |
|
|
1519 | XNForeground, fg, |
|
|
1520 | XNBackground, bg, |
|
|
1521 | XNArea, &status_rect, |
1406 | //XNFontSet, TermWin.fontset, |
1522 | XNFontSet, fs, |
1407 | NULL); |
1523 | NULL); |
1408 | status_attr = XVaCreateNestedList (0, XNArea, &status_rect, |
|
|
1409 | XNForeground, fg, XNBackground, bg, |
|
|
1410 | //XNFontSet, TermWin.fontset, |
|
|
1411 | NULL); |
|
|
1412 | } |
1524 | } |
1413 | |
1525 | |
1414 | Input_Context = XCreateIC (xim, XNInputStyle, input_style, |
1526 | Input_Context = XCreateIC (xim, |
|
|
1527 | XNInputStyle, input_style, |
1415 | XNClientWindow, TermWin.parent[0], |
1528 | XNClientWindow, TermWin.vt, |
1416 | XNFocusWindow, TermWin.parent[0], |
1529 | XNFocusWindow, TermWin.parent[0], |
1417 | preedit_attr ? XNPreeditAttributes : NULL, |
1530 | preedit_attr ? XNPreeditAttributes : NULL, |
1418 | preedit_attr, |
1531 | preedit_attr, |
1419 | status_attr ? XNStatusAttributes : NULL, |
1532 | status_attr ? XNStatusAttributes : NULL, |
1420 | status_attr, NULL); |
1533 | status_attr, NULL); |
|
|
1534 | |
1421 | if (preedit_attr) XFree (preedit_attr); |
1535 | if (preedit_attr) XFree (preedit_attr); |
1422 | if (status_attr) XFree (status_attr); |
1536 | if (status_attr) XFree (status_attr); |
|
|
1537 | if (fs) XFreeFontSet (display->display, fs); |
1423 | |
1538 | |
1424 | if (Input_Context == NULL) |
1539 | if (Input_Context == NULL) |
1425 | { |
1540 | { |
1426 | rxvt_warn ("failed to create input context, continuing without XIM.\n"); |
1541 | rxvt_warn ("failed to create input context, continuing without XIM.\n"); |
1427 | display->put_xim (input_method); |
1542 | im_destroy (); |
1428 | return false; |
1543 | return false; |
1429 | } |
1544 | } |
1430 | |
1545 | |
1431 | if (input_style & XIMPreeditArea) |
1546 | if (input_style & XIMPreeditArea) |
1432 | IMSetStatusPosition (); |
1547 | IMSetStatusPosition (); |
… | |
… | |
1436 | } |
1551 | } |
1437 | |
1552 | |
1438 | void |
1553 | void |
1439 | rxvt_term::im_cb () |
1554 | rxvt_term::im_cb () |
1440 | { |
1555 | { |
1441 | int i, found, had_im; |
1556 | int i; |
1442 | const char *p; |
1557 | const char *p; |
1443 | char **s; |
1558 | char **s; |
1444 | char buf[IMBUFSIZ]; |
1559 | char buf[IMBUFSIZ]; |
1445 | |
1560 | |
|
|
1561 | SET_R (this); |
|
|
1562 | |
1446 | im_destroy (); |
1563 | im_destroy (); |
1447 | |
1564 | |
1448 | D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()")); |
1565 | D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()")); |
1449 | if (Input_Context) |
1566 | if (Input_Context) |
1450 | return; |
1567 | return; |
… | |
… | |
1458 | if (p && *p) |
1575 | if (p && *p) |
1459 | { |
1576 | { |
1460 | bool found = false; |
1577 | bool found = false; |
1461 | |
1578 | |
1462 | s = rxvt_splitcommastring (p); |
1579 | s = rxvt_splitcommastring (p); |
|
|
1580 | |
1463 | for (i = 0; s[i]; i++) |
1581 | for (i = 0; s[i]; i++) |
1464 | { |
1582 | { |
1465 | if (*s[i]) |
1583 | if (*s[i]) |
1466 | { |
1584 | { |
1467 | STRCPY (buf, "@im="); |
1585 | strcpy (buf, "@im="); |
1468 | STRNCAT (buf, s[i], IMBUFSIZ - 5); |
1586 | strncat (buf, s[i], IMBUFSIZ - 5); |
1469 | if (IM_get_IC (buf)) |
1587 | if (IM_get_IC (buf)) |
1470 | { |
1588 | { |
1471 | found = true; |
1589 | found = true; |
1472 | break; |
1590 | break; |
1473 | } |
1591 | } |
1474 | } |
1592 | } |
1475 | } |
1593 | } |
1476 | for (i = 0; s[i]; i++) |
1594 | |
1477 | free (s[i]); |
1595 | rxvt_freecommastring (s); |
1478 | free (s); |
|
|
1479 | |
1596 | |
1480 | if (found) |
1597 | if (found) |
1481 | goto done; |
1598 | goto done; |
1482 | } |
1599 | } |
1483 | |
1600 | |
… | |
… | |
1497 | } |
1614 | } |
1498 | |
1615 | |
1499 | void |
1616 | void |
1500 | rxvt_term::IMSetStatusPosition () |
1617 | rxvt_term::IMSetStatusPosition () |
1501 | { |
1618 | { |
1502 | XRectangle preedit_rect, status_rect, *needed_rect; |
1619 | XRectangle preedit_rect, status_rect, *needed_rect; |
1503 | XVaNestedList preedit_attr, status_attr; |
1620 | XVaNestedList preedit_attr, status_attr; |
1504 | |
1621 | |
1505 | if (Input_Context == NULL |
1622 | if (!Input_Context |
|
|
1623 | || !TermWin.focus |
1506 | || !TermWin.focus || ! (input_style & XIMPreeditArea) |
1624 | || !(input_style & XIMPreeditArea) |
1507 | || !IMisRunning ()) |
1625 | || !IMisRunning ()) |
1508 | return; |
1626 | return; |
1509 | |
1627 | |
1510 | /* Getting the necessary width of preedit area */ |
1628 | /* Getting the necessary width of preedit area */ |
1511 | status_attr = XVaCreateNestedList (0, XNAreaNeeded, &needed_rect, NULL); |
1629 | status_attr = XVaCreateNestedList (0, XNAreaNeeded, &needed_rect, NULL); |
1512 | XGetICValues (Input_Context, XNStatusAttributes, status_attr, NULL); |
1630 | XGetICValues (Input_Context, XNStatusAttributes, status_attr, NULL); |
1513 | XFree (status_attr); |
1631 | XFree (status_attr); |
1514 | |
1632 | |
1515 | im_set_preedit_area (&preedit_rect, &status_rect, needed_rect); |
1633 | im_set_preedit_area (preedit_rect, status_rect, *needed_rect); |
|
|
1634 | XFree (needed_rect); |
1516 | |
1635 | |
1517 | preedit_attr = XVaCreateNestedList (0, XNArea, &preedit_rect, NULL); |
1636 | preedit_attr = XVaCreateNestedList (0, XNArea, &preedit_rect, NULL); |
1518 | status_attr = XVaCreateNestedList (0, XNArea, &status_rect, NULL); |
1637 | status_attr = XVaCreateNestedList (0, XNArea, &status_rect, NULL); |
1519 | |
1638 | |
1520 | XSetICValues (Input_Context, |
1639 | XSetICValues (Input_Context, |
1521 | XNPreeditAttributes, preedit_attr, |
1640 | XNPreeditAttributes, preedit_attr, |
1522 | XNStatusAttributes, status_attr, NULL); |
1641 | XNStatusAttributes, status_attr, NULL); |
1523 | |
1642 | |
1524 | XFree (preedit_attr); |
1643 | XFree (preedit_attr); |
1525 | XFree (status_attr); |
1644 | XFree (status_attr); |
1526 | } |
1645 | } |
1527 | #endif /* USE_XIM */ |
1646 | #endif /* USE_XIM */ |