--- rxvt-unicode/src/rxvtcolor.C 2004/02/11 08:13:45 1.6 +++ rxvt-unicode/src/rxvtcolor.C 2004/04/02 20:41:01 1.12 @@ -5,6 +5,23 @@ #include #include +class byteorder byteorder; + +byteorder::byteorder () +{ + union { + uint32_t u; + uint8_t b[4]; + } w; + + w.b[0] = 0x11; + w.b[1] = 0x22; + w.b[2] = 0x33; + w.b[3] = 0x44; + + e = w.u; +} + refcounted::refcounted (const char *id) { this->id = STRDUP (id); @@ -104,7 +121,7 @@ rxvt_display::rxvt_display (const char *id) : refcounted (id) -, x_watcher (this, &rxvt_display::x_event) +, x_ev (this, &rxvt_display::x_cb) , selection_owner (0) { } @@ -113,6 +130,9 @@ { display = XOpenDisplay (id); + if (!display) + return false; + screen = DefaultScreen (display); root = DefaultRootWindow (display); visual = DefaultVisual (display, screen); @@ -139,20 +159,23 @@ #endif int fd = XConnectionNumber (display); - x_watcher.start (fd, EVENT_READ); + x_ev.start (fd, EVENT_READ); fcntl (fd, F_SETFL, FD_CLOEXEC); XSelectInput (display, root, PropertyChangeMask); xa_xim_servers = XInternAtom (display, "XIM_SERVERS", 0); + flush (); + return true; } rxvt_display::~rxvt_display () { - x_watcher.stop (); + x_ev.stop (); - XCloseDisplay (display); + if (display) + XCloseDisplay (display); } void rxvt_display::im_change_cb () @@ -161,7 +184,7 @@ (*i)->call (); } -void rxvt_display::x_event (io_watcher &w, short revents) +void rxvt_display::x_cb (io_watcher &w, short revents) { do { @@ -184,6 +207,21 @@ } } while (XPending (display)); + + flush (); +} + +void rxvt_display::flush () +{ + for (;;) + { + XFlush (display); + + if (!XPending (display)) + break; + + x_cb (x_ev, 0); + } } void rxvt_display::reg (xevent_watcher *w) @@ -218,12 +256,18 @@ rxvt_xim *rxvt_display::get_xim (const char *locale, const char *modifiers) { - // asprintf is a GNU and *BSD extension.. sorry... char *id; + int l, m; - if (asprintf (&id, "%s\n%s", locale, modifiers) < 0) + l = strlen (locale); + m = strlen (modifiers); + + if (!(id = (char *)malloc (l + m + 2))) return 0; + memcpy (id, locale, l); id[l] = '\n'; + memcpy (id + l + 1, modifiers, m); id[l + m + 1] = 0; + rxvt_xim *xim = xims.get (id); free (id); @@ -236,6 +280,11 @@ xims.put (xim); } +Atom rxvt_display::atom (const char *name) +{ + return XInternAtom (display, name, False); +} + ///////////////////////////////////////////////////////////////////////////// template refcache; @@ -324,7 +373,7 @@ #if XFT XftColorFree (display->display, display->visual, display->cmap, &c); #else - XFreeColors (display->display, display->cmap, &c, 1, AllPlanes); + XFreeColors (display->display, display->cmap, &p, 1, AllPlanes); #endif }