Back to index

texmacs  1.0.7.15
x_init.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : x_init.cpp
00004 * DESCRIPTION: Initialization of the X11 window manager
00005 * COPYRIGHT  : (C) 1999  Joris van der Hoeven
00006 *******************************************************************************
00007 * This software falls under the GNU general public license version 3 or later.
00008 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00009 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00010 ******************************************************************************/
00011 
00012 #include "X11/x_window.hpp"
00013 #include "language.hpp"
00014 #include "font.hpp"
00015 #include "analyze.hpp"
00016 #include "dictionary.hpp"
00017 #include "iterator.hpp"
00018 #include "message.hpp"
00019 #include "sys_utils.hpp"
00020 #include <locale.h>
00021 
00022 x_gui_rep* the_gui= NULL;
00023 extern hashmap<Window,pointer> Window_to_window;
00024 
00025 /******************************************************************************
00026 * Set up colors
00027 ******************************************************************************/
00028 
00029 bool true_color= false;
00030 bool reverse_colors= false;
00031 
00032 color black, white, red, green, blue;
00033 color yellow, magenta, orange, brown, pink;
00034 color light_grey, grey, dark_grey;
00035 
00036 static int CSCALES= 4;
00037 static int CFACTOR= 5;
00038 static int GREYS  = 16;
00039 static int CTOTAL = (CFACTOR*CFACTOR*CFACTOR+GREYS+1);
00040 
00041 static void
00042 reverse (int& r, int& g, int& b) {
00043   int m= min (r, min (g, b));
00044   int M= max (r, max (g, b));
00045   int t= (r + g + b) / 3;
00046   int tt= 255 - t;
00047   double mu= 1.0;
00048   // tt= 6 * tt / 7;
00049   if (M != m) {
00050     double lambda1= max (((double) (t - m)) / t,
00051                       ((double) (M - t)) / (255 - t));
00052     double lambda2= max (((double) (t - m)) / tt,
00053                       ((double) (M - t)) / (255 - tt));
00054     mu= lambda1 / lambda2;
00055   }
00056   r= (int) (tt + mu * (r - t) + 0.5);
00057   g= (int) (tt + mu * (g - t) + 0.5);
00058   b= (int) (tt + mu * (b - t) + 0.5);
00059 }
00060 
00061 int
00062 x_alloc_color (int r, int g, int b) {
00063   if (true_color)
00064     return ((r >> 8) << 16) + ((g >> 8) << 8) + (b >> 8);
00065 
00066   if (reverse_colors) {
00067     int m= min (r, min (g, b));
00068     int M= max (r, max (g, b));
00069     int t= (r + g + b) / 3;
00070     int tt= 65535 - t;
00071     double mu= 1.0;
00072     tt= 6 * tt / 7;
00073     if (M != m) {
00074       double lambda1= max (((double) (t - m)) / t,
00075                         ((double) (M - t)) / (65535 - t));
00076       double lambda2= max (((double) (t - m)) / tt,
00077                         ((double) (M - t)) / (65535 - tt));
00078       mu= lambda1 / lambda2;
00079     }
00080     r= (int) (tt + mu * (r - t) + 0.5);
00081     g= (int) (tt + mu * (g - t) + 0.5);
00082     b= (int) (tt + mu * (b - t) + 0.5);
00083   }
00084 
00085   XColor col;
00086   col.red  = r;
00087   col.green= g;
00088   col.blue = b;
00089   if (!XAllocColor (the_gui->dpy, the_gui->cols, &col))
00090     cerr << "Warning: can't allocate color\n";
00091   return col.pixel;
00092 }
00093 
00094 void
00095 x_init_color_map () {
00096   if (true_color) return;
00097 
00098   int i, r, g, b;
00099   the_gui->cmap= tm_new_array<color> (CTOTAL);
00100 
00101   for (i=0; i<=GREYS; i++)
00102     the_gui->cmap[i]=
00103       x_alloc_color ((i*65535)/GREYS, (i*65535)/GREYS, (i*65535)/GREYS);
00104 
00105   for (r=0; r<=CSCALES; r++)
00106     for (g=0; g<=CSCALES; g++)
00107       for (b=0; b<=CSCALES; b++) {
00108        i= r*CFACTOR*CFACTOR+ g*CFACTOR+ b+ GREYS+ 1;
00109        the_gui->cmap[i]= x_alloc_color ((r*65535)/CSCALES,
00110                                     (g*65535)/CSCALES,
00111                                     (b*65535)/CSCALES);
00112       }
00113 }
00114 
00115 color
00116 rgb_color (int r, int g, int b, int a) {
00117   if (true_color) {
00118     if (reverse_colors) reverse (r, g, b);
00119     return (a << 24) + (r << 16) + (g << 8) + b;
00120   }
00121   else if ((r==g) && (g==b))
00122     return (a << 24) + ((r*GREYS+ 128)/255);
00123   else {
00124     r= (r*CSCALES+ 128)/255;
00125     g= (g*CSCALES+ 128)/255;
00126     b= (b*CSCALES+ 128)/255;
00127     return (a << 24) + r*CFACTOR*CFACTOR + g*CFACTOR + b + GREYS + 1;
00128   }
00129 }
00130 
00131 void
00132 get_rgb_color (color col, int& r, int& g, int& b, int& a) {
00133   if (true_color) {
00134     a= (col >> 24) & 255;
00135     r= (col >> 16) & 255;
00136     g= (col >> 8 ) & 255;
00137     b=  col        & 255;
00138     if (reverse_colors) reverse (r, g, b);
00139   }
00140   else {
00141     a= (col >> 24) & 255;
00142     col= col & 0xffffff;
00143     if (col <= ((color) GREYS)) {
00144       r= (col*255)/GREYS;
00145       g= (col*255)/GREYS;
00146       b= (col*255)/GREYS;
00147     }
00148     else {
00149       int rr, gg, bb;
00150       col-= (GREYS+1);
00151       bb  = col % CFACTOR;
00152       gg  = (col/CFACTOR) % CFACTOR;
00153       rr  = (col/(CFACTOR*CFACTOR)) % CFACTOR;
00154       r   = (rr*255)/CSCALES;
00155       g   = (gg*255)/CSCALES;
00156       b   = (bb*255)/CSCALES;
00157     }
00158   }
00159 }
00160 
00161 static color
00162 named_color_bis (string s) {
00163   if ((N(s) == 4) && (s[0]=='#')) {
00164     int r= 17 * from_hexadecimal (s (1, 2));
00165     int g= 17 * from_hexadecimal (s (2, 3));
00166     int b= 17 * from_hexadecimal (s (3, 4));
00167     return rgb_color (r, g, b);
00168   }
00169   if ((N(s) == 7) && (s[0]=='#')) {
00170     int r= from_hexadecimal (s (1, 3));
00171     int g= from_hexadecimal (s (3, 5));
00172     int b= from_hexadecimal (s (5, 7));
00173     return rgb_color (r, g, b);
00174   }
00175   int pastel= (the_gui->depth>=16? 223: 191);
00176   if (s == "black")          return black;
00177   if (s == "white")          return white;
00178   if (s == "grey")           return grey;
00179   if (s == "red")            return red;
00180   if (s == "blue")           return blue;
00181   if (s == "yellow")         return yellow;
00182   if (s == "green")          return green;
00183   if (s == "magenta")        return magenta;
00184   if (s == "cyan")           return rgb_color (0, 255, 255);
00185   if (s == "orange")         return orange;
00186   if (s == "brown")          return brown;
00187   if (s == "pink")           return pink;
00188   if (s == "broken white")   return rgb_color (255, 255, pastel);
00189   if (s == "light grey")     return light_grey;
00190   if (s == "darker grey")    return rgb_color (64, 64, 64);
00191   if (s == "dark grey")      return dark_grey;
00192   if (s == "dark red")       return rgb_color (128, 0, 0);
00193   if (s == "dark blue")      return rgb_color (0, 0, 128);
00194   if (s == "dark yellow")    return rgb_color (128, 128, 0);
00195   if (s == "dark green")     return rgb_color (0, 128, 0);
00196   if (s == "dark magenta")   return rgb_color (128, 0, 128);
00197   if (s == "dark cyan")      return rgb_color (0, 128, 128);
00198   if (s == "dark orange")    return rgb_color (128, 64, 0);
00199   if (s == "dark brown")     return rgb_color (64, 16, 0);
00200   if (s == "pastel grey")    return rgb_color (pastel, pastel, pastel);
00201   if (s == "pastel red")     return rgb_color (255, pastel, pastel);
00202   if (s == "pastel blue")    return rgb_color (pastel, pastel, 255);
00203   if (s == "pastel yellow")  return rgb_color (255, 255, pastel);
00204   if (s == "pastel green")   return rgb_color (pastel, 255, pastel);
00205   if (s == "pastel magenta") return rgb_color (255, pastel, 255);
00206   if (s == "pastel cyan")    return rgb_color (pastel, 255, 255);
00207   if (s == "pastel orange")  return rgb_color (255, pastel, 2*pastel-255);
00208   if (s == "pastel brown")   return rgb_color (pastel, 2*pastel-255, 2*pastel-255);
00209   return black;
00210 }
00211 
00212 color
00213 named_color (string s, int a) {
00214   color c= named_color_bis (s);
00215   return (a << 24) + (c & 0xffffff);
00216 }
00217 
00218 string
00219 get_named_color (color c) {
00220   int r, g, b, a;
00221   get_rgb_color (c, r, g, b, a);
00222   return "#" *
00223     as_hexadecimal (r, 2) *
00224     as_hexadecimal (g, 2) *
00225     as_hexadecimal (b, 2);
00226 }
00227 
00228 color
00229 blend (color fg, color bg) {
00230   if (((fg >> 24) & 255) == 255) return fg;
00231   int fR, fG, fB, fA, bR, bG, bB, bA;
00232   get_rgb_color (fg, fR, fG, fB, fA);
00233   get_rgb_color (bg, bR, bG, bB, bA);
00234   fR= (bR * (255 - fA) + fR * fA) / 255;
00235   fG= (bG * (255 - fA) + fG * fA) / 255;
00236   fB= (bB * (255 - fA) + fB * fA) / 255;
00237   return rgb_color (fR, fG, fB);
00238 }
00239 
00240 void
00241 x_initialize_colors () {
00242   if (the_gui->depth >= 16) {
00243     CSCALES= 8;
00244     CFACTOR= 9;
00245     GREYS  = 256;
00246     CTOTAL = (CFACTOR*CFACTOR*CFACTOR+GREYS+1);
00247   }
00248 
00249   x_init_color_map ();
00250 
00251   black   = rgb_color (0, 0, 0);
00252   white   = rgb_color (255, 255, 255);
00253   red     = rgb_color (255, 0, 0);
00254   blue    = rgb_color (0, 0, 255);
00255   yellow  = rgb_color (255, 255, 0);
00256   green   = rgb_color (0, 255, 0);
00257   magenta = rgb_color (255, 0, 255);
00258   orange  = rgb_color (255, 128, 0);
00259   brown   = rgb_color (128, 32, 0);
00260   pink    = rgb_color (255, 128, 128);
00261 
00262   light_grey = rgb_color (208, 208, 208);
00263   grey       = rgb_color (184, 184, 184);
00264   dark_grey  = rgb_color (112, 112, 112);
00265 }
00266 
00267 /******************************************************************************
00268 * Set up input method
00269 ******************************************************************************/
00270 
00271 void
00272 x_gui_rep::initialize_input_method () {
00273   im_ok= false;
00274   if (setlocale (LC_CTYPE, "") == NULL)
00275     cerr << "TeXmacs] Warning: locale could not be set\n";
00276   else {
00277     if (!XSetLocaleModifiers (""))
00278       cerr << "TeXmacs] Warning: could not set locale modifiers\n";
00279     if (XSupportsLocale () == False)
00280       cerr << "TeXmacs] Warning: locale is not supported\n";
00281     else if ((im = XOpenIM (dpy, NULL, NULL, NULL)) == NULL)
00282       cout << "TeXmacs] Warning: could not open input method\n";
00283     else im_ok= true;
00284   }
00285 }
00286 
00287 /******************************************************************************
00288 * Get xmodmap
00289 ******************************************************************************/
00290 
00291 #ifndef XK_ISO_Left_Tab
00292 #define       XK_ISO_Left_Tab 0xFE20
00293 #endif
00294 
00295 static XModifierKeymap* xmodmap;
00296 static int        mod_n;
00297 static KeyCode*   mod_k;
00298 static array<int> mod_shift;
00299 static array<int> mod_ctrl;
00300 static array<int> mod_alt;
00301 
00302 void
00303 x_gui_rep::insert_keysym (array<int>& a, int i, int j) {
00304   int ks= XKeycodeToKeysym (dpy, mod_k[i*mod_n+j], 0);
00305   if (ks!=0) a << ks;
00306 }
00307 
00308 void
00309 x_gui_rep::get_xmodmap () {
00310   int i;
00311   xmodmap= XGetModifierMapping (dpy);
00312   mod_n= xmodmap->max_keypermod;
00313   mod_k= xmodmap->modifiermap;
00314   for (i=0; i<mod_n; i++) {
00315     insert_keysym (mod_shift, 0, i);
00316     insert_keysym (mod_shift, 1, i);
00317     insert_keysym (mod_ctrl, 2, i);
00318     insert_keysym (mod_alt, 3, i);
00319   }
00320   XFreeModifiermap (xmodmap);
00321 }
00322 
00323 /******************************************************************************
00324 * Set up keyboard
00325 ******************************************************************************/
00326 
00327 void
00328 x_gui_rep::map (int key, string s) {
00329   lower_key (key)= s;
00330   upper_key (key)= "S-" * s;
00331 }
00332 
00333 void
00334 x_gui_rep::Map (int key, string s) {
00335   lower_key (key)= s;
00336   upper_key (key)= s;
00337 }
00338 
00339 void
00340 x_gui_rep::initialize_keyboard_pointer () {
00341   // Latin characters
00342   Map (XK_a, "a");
00343   Map (XK_b, "b");
00344   Map (XK_c, "c");
00345   Map (XK_d, "d");
00346   Map (XK_e, "e");
00347   Map (XK_f, "f");
00348   Map (XK_g, "g");
00349   Map (XK_h, "h");
00350   Map (XK_i, "i");
00351   Map (XK_j, "j");
00352   Map (XK_k, "k");
00353   Map (XK_l, "l");
00354   Map (XK_m, "m");
00355   Map (XK_n, "n");
00356   Map (XK_o, "o");
00357   Map (XK_p, "p");
00358   Map (XK_q, "q");
00359   Map (XK_r, "r");
00360   Map (XK_s, "s");
00361   Map (XK_t, "t");
00362   Map (XK_u, "u");
00363   Map (XK_v, "v");
00364   Map (XK_w, "w");
00365   Map (XK_x, "x");
00366   Map (XK_y, "y");
00367   Map (XK_z, "z");
00368   Map (XK_A, "A");
00369   Map (XK_B, "B");
00370   Map (XK_C, "C");
00371   Map (XK_D, "D");
00372   Map (XK_E, "E");
00373   Map (XK_F, "F");
00374   Map (XK_G, "G");
00375   Map (XK_H, "H");
00376   Map (XK_I, "I");
00377   Map (XK_J, "J");
00378   Map (XK_K, "K");
00379   Map (XK_L, "L");
00380   Map (XK_M, "M");
00381   Map (XK_N, "N");
00382   Map (XK_O, "O");
00383   Map (XK_P, "P");
00384   Map (XK_Q, "Q");
00385   Map (XK_R, "R");
00386   Map (XK_S, "S");
00387   Map (XK_T, "T");
00388   Map (XK_U, "U");
00389   Map (XK_V, "V");
00390   Map (XK_W, "W");
00391   Map (XK_X, "X");
00392   Map (XK_Y, "Y");
00393   Map (XK_Z, "Z");
00394   Map (XK_0, "0");
00395   Map (XK_1, "1");
00396   Map (XK_2, "2");
00397   Map (XK_3, "3");
00398   Map (XK_4, "4");
00399   Map (XK_5, "5");
00400   Map (XK_6, "6");
00401   Map (XK_7, "7");
00402   Map (XK_8, "8");
00403   Map (XK_9, "9");
00404 
00405   // Cyrillic letters
00406   Map (XK_Cyrillic_a,   "\xe0");
00407   Map (XK_Cyrillic_be,  "\xe1");
00408   Map (XK_Cyrillic_ve,  "\xe2");
00409   Map (XK_Cyrillic_ghe, "\xe3");
00410   Map (XK_Cyrillic_de,  "\xe4");
00411   Map (XK_Cyrillic_ie,  "\xe5");
00412   Map (XK_Cyrillic_io,  "\xbc");
00413   Map (XK_Cyrillic_zhe, "\xe6");
00414   Map (XK_Cyrillic_ze,  "\xe7");
00415   Map (XK_Cyrillic_i,   "\xe8");
00416   Map (XK_Cyrillic_shorti,   "\xe9");
00417   Map (XK_Cyrillic_ka,  "\xea");
00418   Map (XK_Cyrillic_el,  "\xeb");
00419   Map (XK_Cyrillic_em,  "\xec");
00420   Map (XK_Cyrillic_en,  "\xed");
00421   Map (XK_Cyrillic_o,   "\xee");
00422   Map (XK_Cyrillic_pe,  "\xef");
00423   Map (XK_Cyrillic_er,  "\xf0");
00424   Map (XK_Cyrillic_es,  "\xf1");
00425   Map (XK_Cyrillic_te,  "\xf2");
00426   Map (XK_Cyrillic_u,   "\xf3");
00427   Map (XK_Cyrillic_ef,  "\xf4");
00428   Map (XK_Cyrillic_ha,  "\xf5");
00429   Map (XK_Cyrillic_tse, "\xf6");
00430   Map (XK_Cyrillic_che, "\xf7");
00431   Map (XK_Cyrillic_sha, "\xf8");
00432   Map (XK_Cyrillic_shcha,    "\xf9");
00433   Map (XK_Cyrillic_hardsign, "\xfa");
00434   Map (XK_Cyrillic_yeru,     "\xfb");
00435   Map (XK_Cyrillic_softsign, "\xfc");
00436   Map (XK_Cyrillic_e,   "\xfd");
00437   Map (XK_Cyrillic_yu,  "\xfe");
00438   Map (XK_Cyrillic_ya,  "\xff");
00439   Map (XK_Cyrillic_A,   "\xc0");
00440   Map (XK_Cyrillic_BE,  "\xc1");
00441   Map (XK_Cyrillic_VE,  "\xc2");
00442   Map (XK_Cyrillic_GHE, "\xc3");
00443   Map (XK_Cyrillic_DE,  "\xc4");
00444   Map (XK_Cyrillic_IE,  "\xc5");
00445   Map (XK_Cyrillic_IO,  "\x9c");
00446   Map (XK_Cyrillic_ZHE, "\xc6");
00447   Map (XK_Cyrillic_ZE,  "\xc7");
00448   Map (XK_Cyrillic_I,   "\xc8");
00449   Map (XK_Cyrillic_SHORTI,   "\xc9");
00450   Map (XK_Cyrillic_KA,  "\xca");
00451   Map (XK_Cyrillic_EL,  "\xcb");
00452   Map (XK_Cyrillic_EM,  "\xcc");
00453   Map (XK_Cyrillic_EN,  "\xcd");
00454   Map (XK_Cyrillic_O,   "\xce");
00455   Map (XK_Cyrillic_PE,  "\xcf");
00456   Map (XK_Cyrillic_ER,  "\xd0");
00457   Map (XK_Cyrillic_ES,  "\xd1");
00458   Map (XK_Cyrillic_TE,  "\xd2");
00459   Map (XK_Cyrillic_U,   "\xd3");
00460   Map (XK_Cyrillic_EF,  "\xd4");
00461   Map (XK_Cyrillic_HA,  "\xd5");
00462   Map (XK_Cyrillic_TSE, "\xd6");
00463   Map (XK_Cyrillic_CHE, "\xd7");
00464   Map (XK_Cyrillic_SHA, "\xd8");
00465   Map (XK_Cyrillic_SHCHA,    "\xd9");
00466   Map (XK_Cyrillic_HARDSIGN, "\xda");
00467   Map (XK_Cyrillic_YERU,     "\xdb");
00468   Map (XK_Cyrillic_SOFTSIGN, "\xdc");
00469   Map (XK_Cyrillic_E,   "\xdd");
00470   Map (XK_Cyrillic_YU,  "\xde");
00471   Map (XK_Cyrillic_YA,  "\xdf");
00472 
00473   //Ukrainian letters in T2A encoding
00474   Map (XK_Ukrainian_i,   "i"); // Fall back!
00475   Map (XK_Ukrainian_I,   "I"); // Fall back!
00476   Map (XK_Ukrainian_yi,   "\xa8");
00477   Map (XK_Ukrainian_YI,   "\x88");
00478   Map (XK_Ukrainian_ie,   "\xb9");
00479   Map (XK_Ukrainian_IE,   "\x99");
00480   // Map (XK_Ukrainian_ghe_with_upturn,   "\xa0");
00481   // Map (XK_Ukrainian_GHE_WITH_UPTURN,   "\x80");
00482   Map (0x6ad,   "\xa0");
00483   Map (0x6bd,   "\x80");
00484 
00485   // Standard ASCII Symbols
00486   Map (XK_exclam, "!");
00487   Map (XK_quotedbl, "\x22");
00488   Map (XK_numbersign, "#");
00489   Map (XK_dollar, "$");
00490   Map (XK_percent, "%");
00491   Map (XK_ampersand, "&");
00492   Map (XK_apostrophe, "'");
00493   Map (XK_quoteright, "'");
00494   Map (XK_parenleft, "(");
00495   Map (XK_parenright, ")");
00496   Map (XK_asterisk, "*");
00497   Map (XK_plus, "+");
00498   Map (XK_comma, ",");
00499   Map (XK_minus, "-");
00500   Map (XK_period, ".");
00501   Map (XK_slash, "/");
00502   Map (XK_colon, ":");
00503   Map (XK_semicolon, ";");
00504   Map (XK_less, "<");
00505   Map (XK_equal, "=");
00506   Map (XK_greater, ">");
00507   Map (XK_question, "?");
00508   Map (XK_at, "@");
00509   Map (XK_bracketleft, "[");
00510   Map (XK_backslash, "\\");
00511   Map (XK_bracketright, "]");
00512   Map (XK_asciicircum, "^");
00513   Map (XK_underscore, "_");
00514   Map (XK_grave, "`");
00515   Map (XK_quoteleft, "`");
00516   Map (XK_braceleft, "{");
00517   Map (XK_bar, "|");
00518   Map (XK_braceright, "}");
00519   Map (XK_asciitilde, "~");
00520 
00521   // dead keys
00522   Map (0xFE50, "grave");
00523   Map (0xFE51, "acute");
00524   Map (0xFE52, "hat");
00525   Map (0xFE53, "tilde");
00526   Map (0xFE54, "macron");
00527   Map (0xFE55, "breve");
00528   Map (0xFE56, "abovedot");
00529   Map (0XFE57, "umlaut");
00530   Map (0xFE58, "abovering");
00531   Map (0xFE59, "doubleacute");
00532   Map (0xFE5A, "check");
00533   Map (0xFE5B, "cedilla");
00534   Map (0xFE5C, "ogonek");
00535   Map (0xFE5D, "iota");
00536   Map (0xFE5E, "voicedsound");
00537   Map (0xFE5F, "semivoicedsound");
00538   Map (0xFE60, "belowdot");
00539 
00540   // Extended symbols and accented characters
00541   Map (XK_nobreakspace, "varspace");
00542   Map (XK_exclamdown, "exclamdown");
00543   Map (XK_cent, "cent");
00544   Map (XK_sterling, "sterling");
00545   Map (XK_currency, "currency");
00546   Map (XK_yen, "yen");
00547   Map (XK_brokenbar, "brokenbar");
00548   Map (XK_section, "section");
00549   Map (XK_diaeresis, "umlaut");
00550   Map (XK_copyright, "copyright");
00551   Map (XK_ordfeminine, "ordfeminine");
00552   Map (XK_guillemotleft, "guillemotleft");
00553   Map (XK_notsign, "notsign");
00554   Map (XK_hyphen, "hyphen");
00555   Map (XK_registered, "registered");
00556   Map (XK_macron, "macron");
00557   Map (XK_degree, "degree");
00558   Map (XK_plusminus, "plusminus");
00559   Map (XK_twosuperior, "twosuperior");
00560   Map (XK_threesuperior, "threesuperior");
00561   Map (XK_acute, "acute");
00562   Map (XK_mu, "mu");
00563   Map (XK_paragraph, "paragraph");
00564   Map (XK_periodcentered, "periodcentered");
00565   Map (XK_cedilla, "cedilla");
00566   Map (XK_onesuperior, "onesuperior");
00567   Map (XK_masculine, "masculine");
00568   Map (XK_guillemotright, "guillemotright");
00569   Map (XK_onequarter, "onequarter");
00570   Map (XK_onehalf, "onehalf");
00571   Map (XK_threequarters, "threequarters");
00572   Map (XK_questiondown, "questiondown");
00573   Map (XK_multiply, "times");
00574   Map (XK_division, "div");
00575 
00576   Map (XK_Agrave, "\xc0");
00577   Map (XK_Aacute, "\xc1");
00578   Map (XK_Acircumflex, "\xc2");
00579   Map (XK_Atilde, "\xc3");
00580   Map (XK_Adiaeresis, "\xc4");
00581   Map (XK_Aring, "\xc5");
00582   Map (XK_AE, "\xc6");
00583   Map (XK_Ccedilla, "\xc7");
00584   Map (XK_Egrave, "\xc8");
00585   Map (XK_Eacute, "\xc9");
00586   Map (XK_Ecircumflex, "\xca");
00587   Map (XK_Ediaeresis, "\xcb");
00588   Map (XK_Igrave, "\xcc");
00589   Map (XK_Iacute, "\xcd");
00590   Map (XK_Icircumflex, "\xce");
00591   Map (XK_Idiaeresis, "\xcf");
00592   Map (XK_ETH, "\xd0");
00593   Map (XK_Eth, "\xd0");
00594   Map (XK_Ntilde, "\xd1");
00595   Map (XK_Ograve, "\xd2");
00596   Map (XK_Oacute, "\xd3");
00597   Map (XK_Ocircumflex, "\xd4");
00598   Map (XK_Otilde, "\xd5");
00599   Map (XK_Odiaeresis, "\xd6");
00600   Map (XK_OE, "\xd7");
00601   Map (XK_Ooblique, "\xd8");
00602   Map (XK_Ugrave, "\xd9");
00603   Map (XK_Uacute, "\xda");
00604   Map (XK_Ucircumflex, "\xdb");
00605   Map (XK_Udiaeresis, "\xdc");
00606   Map (XK_Yacute, "\xdd");
00607   Map (XK_THORN, "\xde");
00608   Map (XK_Thorn, "\xde");
00609   Map (XK_ssharp, "sz");
00610   Map (XK_agrave, "\xe0");
00611   Map (XK_aacute, "\xe1");
00612   Map (XK_acircumflex, "\xe2");
00613   Map (XK_atilde, "\xe3");
00614   Map (XK_adiaeresis, "\xe4");
00615   Map (XK_aring, "\xe5");
00616   Map (XK_ae, "\xe6");
00617   Map (XK_ccedilla, "\xe7");
00618   Map (XK_egrave, "\xe8");
00619   Map (XK_eacute, "\xe9");
00620   Map (XK_ecircumflex, "\xea");
00621   Map (XK_ediaeresis, "\xeb");
00622   Map (XK_igrave, "\xec");
00623   Map (XK_iacute, "\xed");
00624   Map (XK_icircumflex, "\xee");
00625   Map (XK_idiaeresis, "\xef");
00626   Map (XK_eth, "\xf0");
00627   Map (XK_ntilde, "\xf1");
00628   Map (XK_ograve, "\xf2");
00629   Map (XK_oacute, "\xf3");
00630   Map (XK_ocircumflex, "\xf4");
00631   Map (XK_otilde, "\xf5");
00632   Map (XK_odiaeresis, "\xf6");
00633   Map (XK_oe, "\xf7");
00634   Map (XK_oslash, "\xf8");
00635   Map (XK_ugrave, "\xf9");
00636   Map (XK_uacute, "\xfa");
00637   Map (XK_ucircumflex, "\xfb");
00638   Map (XK_udiaeresis, "\xfc");
00639   Map (XK_yacute, "\xfd");
00640   Map (XK_thorn, "\xfe");
00641   Map (XK_ydiaeresis, "\xff");
00642 
00643   // Symbols from iso-latin-2
00644   Map (XK_Aogonek, "\x81");
00645   Map (XK_breve, "breve");
00646   Map (XK_Lstroke, "\x8a");
00647   Map (XK_Lcaron, "\x89");
00648   Map (XK_Sacute, "\x91");
00649   Map (XK_Scaron, "\x92");
00650   Map (XK_Scedilla, "\x93");
00651   Map (XK_Tcaron, "\x94");
00652   Map (XK_Zacute, "\x99");
00653   Map (XK_Zcaron, "\x9a");
00654   Map (XK_Zabovedot, "\x9b");
00655   Map (XK_aogonek, "\xa1");
00656   Map (XK_ogonek, "ogonek");
00657   Map (XK_lstroke, "\xaa");
00658   Map (XK_lcaron, "\xa9");
00659   Map (XK_sacute, "\xb1");
00660   Map (XK_caron, "caron");
00661   Map (XK_scaron, "\xb2");
00662   Map (XK_scedilla, "\xb3");
00663   Map (XK_tcaron, "\xb4");
00664   Map (XK_zacute, "\xb9");
00665   Map (XK_doubleacute, "doubleacute");
00666   Map (XK_zcaron, "\xba");
00667   Map (XK_zabovedot, "\xbb");
00668   Map (XK_Racute, "\x8f");
00669   Map (XK_Abreve, "\x80");
00670   Map (XK_Lacute, "\x88");
00671   Map (XK_Cacute, "\x82");
00672   Map (XK_Ccaron, "\x83");
00673   Map (XK_Eogonek, "\x86");
00674   Map (XK_Ecaron, "\x85");
00675   Map (XK_Dcaron, "\x84");
00676   Map (XK_Dstroke, "\xd0");
00677   Map (XK_Nacute, "\x8b");
00678   Map (XK_Ncaron, "\x8c");
00679   Map (XK_Odoubleacute, "\x8e");
00680   Map (XK_Rcaron, "\x90");
00681   Map (XK_Uring, "\x97");
00682   Map (XK_Udoubleacute, "\x96");
00683   Map (XK_Tcedilla, "\x95");
00684   Map (XK_racute, "\xaf");
00685   Map (XK_abreve, "\xa0");
00686   Map (XK_lacute, "\xa8");
00687   Map (XK_cacute, "\xa2");
00688   Map (XK_ccaron, "\xa3");
00689   Map (XK_eogonek, "\xa6");
00690   Map (XK_ecaron, "\xa5");
00691   Map (XK_dcaron, "\xa4");
00692   Map (XK_dstroke, "\x9e");
00693   Map (XK_nacute, "\xab");
00694   Map (XK_ncaron, "\xac");
00695   Map (XK_odoubleacute, "\xae");
00696   Map (XK_udoubleacute, "\xb6");
00697   Map (XK_rcaron, "\xb0");
00698   Map (XK_uring, "\xb7");
00699   Map (XK_tcedilla, "\xb5");
00700   Map (XK_abovedot, "abovedot");
00701 
00702   // Special control keys
00703   Map (XK_Prior, "pageup");
00704   Map (XK_Next, "pagedown");
00705   Map (XK_Undo, "undo");
00706   Map (XK_Redo, "redo");
00707   Map (XK_Cancel, "cancel");
00708 
00709   // Control keys
00710   map (XK_space, "space");
00711   map (XK_Return, "return");
00712   map (XK_BackSpace, "backspace");
00713   map (XK_Delete, "delete");
00714   map (XK_Insert, "insert");
00715   map (XK_Tab, "tab");
00716   map (XK_ISO_Left_Tab, "tab");
00717   map (XK_Escape, "escape");
00718   map (XK_Left, "left");
00719   map (XK_Right, "right");
00720   map (XK_Up, "up");
00721   map (XK_Down, "down");
00722   map (XK_Page_Up, "pageup");
00723   map (XK_Page_Down, "pagedown");
00724   map (XK_Home, "home");
00725   map (XK_End, "end");
00726   map (XK_F1, "F1");
00727   map (XK_F2, "F2");
00728   map (XK_F3, "F3");
00729   map (XK_F4, "F4");
00730   map (XK_F5, "F5");
00731   map (XK_F6, "F6");
00732   map (XK_F7, "F7");
00733   map (XK_F8, "F8");
00734   map (XK_F9, "F9");
00735   map (XK_F10, "F10");
00736   map (XK_F11, "F11");
00737   map (XK_F12, "F12");
00738   map (XK_F13, "F13");
00739   map (XK_F14, "F14");
00740   map (XK_F15, "F15");
00741   map (XK_F16, "F16");
00742   map (XK_F17, "F17");
00743   map (XK_F18, "F18");
00744   map (XK_F19, "F19");
00745   map (XK_F20, "F20");
00746   // map (XK_Mode_switch, "modeswitch");
00747 
00748   // Keypad keys
00749   Map (XK_KP_Space, "K-space");
00750   Map (XK_KP_Enter, "K-return");
00751   Map (XK_KP_Delete, "K-delete");
00752   Map (XK_KP_Insert, "K-insert");
00753   Map (XK_KP_Tab, "K-tab");
00754   Map (XK_KP_Left, "K-left");
00755   Map (XK_KP_Right, "K-right");
00756   Map (XK_KP_Up, "K-up");
00757   Map (XK_KP_Down, "K-down");
00758   Map (XK_KP_Page_Up, "K-pageup");
00759   Map (XK_KP_Page_Down, "K-pagedown");
00760   Map (XK_KP_Home, "K-home");
00761   Map (XK_KP_Begin, "K-begin");
00762   Map (XK_KP_End, "K-end");
00763   Map (XK_KP_F1, "K-F1");
00764   Map (XK_KP_F2, "K-F2");
00765   Map (XK_KP_F3, "K-F3");
00766   Map (XK_KP_F4, "K-F4");
00767   Map (XK_KP_Equal, "K-=");
00768   Map (XK_KP_Multiply, "K-*");
00769   Map (XK_KP_Add, "K-+");
00770   Map (XK_KP_Subtract, "K--");
00771   Map (XK_KP_Decimal, "K-.");
00772   Map (XK_KP_Separator, "K-,");
00773   Map (XK_KP_Divide, "K-/");
00774   Map (XK_KP_0, "K-0");
00775   Map (XK_KP_1, "K-1");
00776   Map (XK_KP_2, "K-2");
00777   Map (XK_KP_3, "K-3");
00778   Map (XK_KP_4, "K-4");
00779   Map (XK_KP_5, "K-5");
00780   Map (XK_KP_6, "K-6");
00781   Map (XK_KP_7, "K-7");
00782   Map (XK_KP_8, "K-8");
00783   Map (XK_KP_9, "K-9");
00784 
00785   // For Sun keyboards
00786   Map (SunXK_FA_Grave, "grave");
00787   Map (SunXK_FA_Circum, "hat");
00788   Map (SunXK_FA_Tilde, "tilde");
00789   Map (SunXK_FA_Acute, "acute");
00790   Map (SunXK_FA_Diaeresis, "umlaut");
00791   Map (SunXK_FA_Cedilla, "cedilla");
00792   Map (SunXK_F36, "F11");
00793   Map (SunXK_F37, "F12");
00794   Map (SunXK_Copy, "copy");
00795   Map (SunXK_Paste, "paste");
00796   Map (SunXK_Cut, "cut");
00797   // Map (XK_L1, "stop");   On Sun, but conflicts with F11
00798   // Map (XK_L2, "again");  On Sun, but conflicts with F12
00799   Map (XK_L3, "props");
00800   Map (XK_L4, "undo");
00801   Map (XK_L5, "front");
00802   Map (XK_L6, "copy");
00803   Map (XK_L7, "open");
00804   Map (XK_L8, "paste");
00805   Map (XK_L9, "find");
00806   Map (XK_L10, "cut");
00807 
00808   // Miscellaneous
00809   Map (0x20ac, "euro");
00810 }
00811 
00812 /******************************************************************************
00813 * Miscellaneous
00814 ******************************************************************************/
00815 
00816 void
00817 x_gui_rep::get_extents (SI& width, SI& height) {
00818   width = screen_width  * PIXEL;
00819   height= screen_height * PIXEL;
00820 }
00821 
00822 void
00823 x_gui_rep::get_max_size (SI& width, SI& height) {
00824   width = 8000 * PIXEL;
00825   height= 6000 * PIXEL;
00826 }
00827 
00828 /******************************************************************************
00829 * Main initialization
00830 ******************************************************************************/
00831 
00832 x_gui_rep::x_gui_rep (int& argc2, char** argv2):
00833   color_scale ((void*) NULL),
00834   character_bitmap (NULL), character_pixmap ((pointer) 0),
00835   xpm_bitmap (0), xpm_pixmap (0),
00836   lower_key (""), upper_key (""),
00837   selection_t ("none"), selection_s (""), selection_w ((Window) 0)
00838 {
00839   the_gui= this;
00840   ASSERT ((dpy= XOpenDisplay (NULL)) != NULL,
00841          "failure to connect to Xserver");
00842   // XSynchronize (dpy, true);
00843 
00844   XGCValues values;
00845   XVisualInfo visual;
00846 
00847   scr                = DefaultScreen (dpy);
00848   root               = RootWindow (dpy, scr);
00849   gc                 = XCreateGC (dpy, root, 0, &values);
00850   pixmap_gc          = XCreateGC (dpy, root, 0, &values);
00851   depth              = DefaultDepth (dpy, scr);
00852   screen_width       = DisplayWidth  (dpy, scr);
00853   screen_height      = DisplayHeight (dpy, scr);
00854   cols               = DefaultColormap (dpy, DefaultScreen (dpy));
00855   state              = 0;
00856   gswindow           = NULL;
00857   argc               = argc2;
00858   argv               = argv2;
00859   balloon_win        = NULL;
00860   interrupted        = false;
00861   interrupt_time     = texmacs_time ();
00862 
00863   XA_CLIPBOARD = XInternAtom (dpy, "CLIPBOARD", false);
00864   XA_TARGETS = XInternAtom (dpy, "TARGETS", false);
00865 
00866   if (XMatchVisualInfo (dpy, scr, depth, TrueColor, &visual) != 0) {
00867     if (visual.red_mask   == (255 << 16) &&
00868        visual.green_mask == (255 << 8) &&
00869        visual.blue_mask  == 255)
00870       true_color= true;
00871   }
00872 
00873   XSetGraphicsExposures (dpy, gc, true);
00874 
00875   int start= 0;
00876   string xmm= eval_system ("xmodmap");
00877   for (int i=0; i<=N(xmm); i++)
00878     if (i == N(xmm) || xmm[i] == '\n') {
00879       string s= xmm (start, i);
00880       if (starts (s, "mod") && N(s)>3 && s[3] >= '1' && s[3] <= '5') {
00881        int nr= ((int) (s[3] - '0'));
00882        int mask= 4 << nr;
00883        if (occurs ("Alt_L", s) || occurs ("Alt_R", s)) {
00884          //cout << "alt_mask= " << mask << "\n";
00885          alt_mask= mask;
00886        }
00887        else if (alt_mask == 0 && occurs ("Mode_switch", s)) {
00888          //cout << "alt_mask= " << mask << "\n";
00889          alt_mask= mask;
00890        }
00891        else if (occurs ("Meta_L", s) || occurs ("Meta_R", s)) {
00892          //cout << "meta_mask= " << mask << "\n";
00893          meta_mask= mask;
00894        }
00895        else if (meta_mask == 0 &&
00896                (occurs ("Super_L", s) || occurs ("Super_R", s))) {
00897          //cout << "meta_mask= " << mask << "\n";
00898          meta_mask= mask;
00899        }
00900       }
00901       start= i+1;
00902     }
00903   if (alt_mask == 0) alt_mask= 8;
00904   if (meta_mask == 0) meta_mask= 16;
00905 
00906   //get_xmodmap ();
00907   x_initialize_colors ();
00908   initialize_input_method ();
00909   initialize_keyboard_pointer ();
00910   set_output_language (get_locale_language ());
00911   (void) default_font ();
00912 }
00913 
00914 x_gui_rep::~x_gui_rep () {
00915   if (im_ok) XCloseIM (im);
00916   clear_selection ("primary");
00917   XFreeGC (dpy, gc);
00918   XCloseDisplay (dpy);
00919   if (!true_color) tm_delete_array (cmap);
00920 }
00921 
00922 void
00923 gui_open (int& argc2, char** argv2) {
00924   ASSERT (the_gui == NULL, "gui already open");
00925   the_gui= tm_new<x_gui_rep> (argc2, argv2);
00926 }
00927 
00928 void
00929 gui_start_loop () {
00930   the_gui->event_loop ();
00931 }
00932 
00933 void
00934 gui_close () {
00935   ASSERT (the_gui != NULL, "gui not yet open");
00936   tm_delete (the_gui);
00937   the_gui= NULL;
00938 }
00939 
00940 void
00941 gui_root_extents (SI& width, SI& height) {
00942   the_gui->get_extents (width, height);
00943 }
00944 
00945 void
00946 gui_maximal_extents (SI& width, SI& height) {
00947   the_gui->get_max_size (width, height);
00948 }
00949 
00950 void
00951 gui_refresh () {
00952   iterator<Window> it= iterate (Window_to_window);
00953   while (it->busy()) {
00954     x_window win= (x_window) Window_to_window [it->next()];
00955     if (get_x_window (win->w) != NULL)
00956       send_update (win->w);
00957   }
00958 }