/** * @brief Set basic properties on a window. */ void wm_wid_set_info(session_t *ps, Window wid, const char *name, Atom window_type) { // Set window name { char *textcpy = mstrjoin("skippy-xd ", name); { XTextProperty text_prop = { }; if (Success == XmbTextListToTextProperty(ps->dpy, &textcpy, 1, XStdICCTextStyle, &text_prop)) XSetWMName(ps->dpy, wid, &text_prop); sxfree(text_prop.value); } wm_wid_set_prop_utf8(ps, wid, _NET_WM_NAME, textcpy); free(textcpy); } // Set window class { XClassHint *classh = allocchk(XAllocClassHint()); classh->res_name = "skippy-xd"; classh->res_class = "skippy-xd"; XSetClassHint(ps->dpy, wid, classh); XFree(classh); } // Set window type { if (!window_type) window_type = _NET_WM_WINDOW_TYPE_NORMAL; long val = window_type; XChangeProperty(ps->dpy, wid, _NET_WM_WINDOW_TYPE, XA_ATOM, 32, PropModeReplace, (unsigned char *) &val, 1); } }
void export_text_xim() { char *text = output_buffer; if (!output_bufferN) return; XTextProperty tp; #if 0 char outbuf[512]; utf8_big5(output_buffer, outbuf); text = outbuf; XmbTextListToTextProperty(dpy, &text, 1, XCompoundTextStyle, &tp); #else Xutf8TextListToTextProperty(dpy, &text, 1, XCompoundTextStyle, &tp); #endif #if DEBUG && 0 dbg("send_utf8_ch: %s\n", text); #endif ((IMCommitStruct*)current_forward_eve)->flag |= XimLookupChars; ((IMCommitStruct*)current_forward_eve)->commit_string = (char *)tp.value; IMCommitString(current_ims, (XPointer)current_forward_eve); clear_output_buffer(); XFree(tp.value); }
int main (int argc, char* argv[]) { Display* display; XTextProperty textprop; char* input; if (argc != 1) exit(1); setlocale(LC_CTYPE,""); display = XOpenDisplay(NULL); if (display == NULL) { fprintf(stderr,"cannot open display\n"); exit(1); } input = ""; if (XmbTextListToTextProperty(display, &input, 1, XTextStyle, &textprop) != Success) { fprintf(stderr,"XmbTextListToTextProperty failed\n"); exit(1); } assert(textprop.format == 8); assert(textprop.nitems == 0); printf("%s\n", XGetAtomName(display, textprop.encoding)); XCloseDisplay(display); exit(0); }
bool QXlibMime::mimeDataForAtom(Display *display, Atom a, QMimeData *mimeData, QByteArray *data, Atom *atomFormat, int *dataFormat) { bool ret = false; *atomFormat = a; *dataFormat = 8; QString atomName = mimeAtomToString(display, a); if (QInternalMimeData::hasFormatHelper(atomName, mimeData)) { *data = QInternalMimeData::renderDataHelper(atomName, mimeData); if (atomName == QLatin1String("application/x-color")) *dataFormat = 16; ret = true; } else { if ((a == QXlibStatic::atom(QXlibStatic::UTF8_STRING) || a == XA_STRING || a == QXlibStatic::atom(QXlibStatic::TEXT) || a == QXlibStatic::atom(QXlibStatic::COMPOUND_TEXT)) && QInternalMimeData::hasFormatHelper(QLatin1String("text/plain"), mimeData)) { if (a == QXlibStatic::atom(QXlibStatic::UTF8_STRING)){ *data = QInternalMimeData::renderDataHelper(QLatin1String("text/plain"), mimeData); ret = true; } else if (a == XA_STRING) { *data = QString::fromUtf8(QInternalMimeData::renderDataHelper( QLatin1String("text/plain"), mimeData)).toLocal8Bit(); ret = true; } else if (a == QXlibStatic::atom(QXlibStatic::TEXT) || a == QXlibStatic::atom(QXlibStatic::COMPOUND_TEXT)) { // the ICCCM states that TEXT and COMPOUND_TEXT are in the // encoding of choice, so we choose the encoding of the locale QByteArray strData = QString::fromUtf8(QInternalMimeData::renderDataHelper( QLatin1String("text/plain"), mimeData)).toLocal8Bit(); char *list[] = { strData.data(), NULL }; XICCEncodingStyle style = (a == QXlibStatic::atom(QXlibStatic::COMPOUND_TEXT)) ? XCompoundTextStyle : XStdICCTextStyle; XTextProperty textprop; if (list[0] != NULL && XmbTextListToTextProperty(display, list, 1, style, &textprop) == Success) { *atomFormat = textprop.encoding; *dataFormat = textprop.format; *data = QByteArray((const char *) textprop.value, textprop.nitems * textprop.format / 8); ret = true; XFree(textprop.value); } } } else if (atomName == QLatin1String("text/x-moz-url") && QInternalMimeData::hasFormatHelper(QLatin1String("text/uri-list"), mimeData)) { QByteArray uri = QInternalMimeData::renderDataHelper( QLatin1String("text/uri-list"), mimeData).split('\n').first(); QString mozUri = QString::fromLatin1(uri, uri.size()); mozUri += QLatin1Char('\n'); *data = QByteArray(reinterpret_cast<const char *>(mozUri.utf16()), mozUri.length() * 2); ret = true; } else if ((a == XA_PIXMAP || a == XA_BITMAP) && mimeData->hasImage()) { ret = true; } } return ret && data != 0; }
static void SelCallback(Widget w, XtPointer cldata, Atom *sel, Atom *seltype, XtPointer val, uint64_t *len, int *fmt) { GwinWidget gw = (GwinWidget)w; XTextProperty p = {0}; char *ls[2] = {(char *)val, NULL}; if (*seltype == 0){ if (gw->gwin.selection == NULL) gw->gwin.selection = strdup(""); return; } if(gw->gwin.selection){ XtFree(gw->gwin.selection); gw->gwin.selection = NULL; } if(*seltype != XInternAtom(_dpy, "UTF8_STRING", 0)) return; if (XmbTextListToTextProperty(_dpy, ls, 1, XUTF8StringStyle, &p) != Success) return; gw->gwin.selection = strdup(p.value); XtFree(val); XFree(p.value); }
/** * @brief Set a UTF-8 string property on a window. */ bool wm_wid_set_prop_utf8(session_t *ps, Window wid, Atom prop, char *text) { XTextProperty text_prop = { }; bool success = (Success == XmbTextListToTextProperty(ps->dpy, &text, 1, XUTF8StringStyle, &text_prop)); if (success) XSetTextProperty(ps->dpy, wid, &text_prop, prop); sxfree(text_prop.value); return success; }
//---------------------------------------------------------------------------------- // //---------------------------------------------------------------------------------- void InitWindow(int width, int height) { g_display = XOpenDisplay(NULL); if( g_display == NULL ) return; unsigned long background = WhitePixel(g_display, 0); unsigned long foreground = BlackPixel(g_display, 0); g_window = XCreateSimpleWindow( g_display, DefaultRootWindow(g_display), 0, 0, width, height, 0, 0, background); /* タイトルの設定を行う。 */ const char* title_ptr = "EffekseerTest"; char* titles_ptr[] = { (char*)title_ptr }; XTextProperty title_prop; setlocale(LC_ALL,""); XmbTextListToTextProperty( g_display, titles_ptr, 1, XCompoundTextStyle, &title_prop ); XSetWMName(g_display,g_window,&title_prop); XmbTextListToTextProperty(g_display, titles_ptr, 1, XCompoundTextStyle, &title_prop ); XSetWMIconName(g_display,g_window,&title_prop); g_gc = XCreateGC(g_display, g_window, 0, 0); XSetBackground(g_display, g_gc, background); XSetForeground(g_display, g_gc, foreground); XMapRaised(g_display, g_window); XSelectInput( g_display, g_window, StructureNotifyMask | ButtonPressMask ); g_wm_delete_window = XInternAtom( g_display, "WM_DELETE_WINDOW", False ); XSetWMProtocols( g_display, g_window, &g_wm_delete_window, 1 ); }
static void InitWindow() { g_display = XOpenDisplay(NULL); if( g_display == nullptr ) return; auto background = WhitePixel(g_display, 0); auto foreground = BlackPixel(g_display, 0); g_window = XCreateSimpleWindow( g_display, DefaultRootWindow(g_display), 0, 0, 640, 480, 0, 0, background); /* タイトルの設定を行う。 */ char* title_ptr = "WindowExternal"; XTextProperty title_prop; setlocale(LC_ALL,""); XmbTextListToTextProperty( g_display, &(title_ptr), 1, XCompoundTextStyle, &title_prop ); XSetWMName(g_display,g_window,&title_prop); XmbTextListToTextProperty(g_display, &(title_ptr), 1, XCompoundTextStyle, &title_prop ); XSetWMIconName(g_display,g_window,&title_prop); g_gc = XCreateGC(g_display, g_window, 0, 0); XSetBackground(g_display, g_gc, background); XSetForeground(g_display, g_gc, foreground); XMapRaised(g_display, g_window); XSelectInput( g_display, g_window, StructureNotifyMask ); g_wm_delete_window = XInternAtom( g_display, "WM_DELETE_WINDOW", False ); XSetWMProtocols( g_display, g_window, &g_wm_delete_window, 1 ); }
virtual char *uStringToCtext(uString *us) { char *str = ustring_to_utf8_str(us); XTextProperty prop; if (!strcmp(mEncoding, "UTF-8")) { XmbTextListToTextProperty(XimServer::gDpy, &str, 1, XCompoundTextStyle, &prop); free(str); } else { char *native_str; native_str = utf8_to_native_str(str); free(str); if (!native_str) return NULL; XmbTextListToTextProperty(XimServer::gDpy, &native_str, 1, XCompoundTextStyle, &prop); free(native_str); } char *res = strdup((char *)prop.value); XFree(prop.value); return res; }
/* * Class: sun_awt_X11_XlibWrapper * Method: SetProperty * Signature: (JJJLjava/lang/String;)V */ JNIEXPORT void JNICALL Java_sun_awt_X11_XlibWrapper_SetProperty (JNIEnv *env, jclass clazz, jlong display, jlong window, jlong atom, jstring jstr) { char *cname; XTextProperty tp; int32_t status; /* In case there are direct support of UTF-8 declared, use UTF-8 strings. */ if (!JNU_IsNull(env, jstr)) { #ifdef X_HAVE_UTF8_STRING cname = (*env)->GetStringUTFChars(env, jstr, JNI_FALSE); #else cname = (char *)JNU_GetStringPlatformChars(env, jstr, NULL); #endif } else { cname = ""; } #ifdef X_HAVE_UTF8_STRING status = Xutf8TextListToTextProperty((Display *)display, &cname, 1, XStdICCTextStyle, &tp); #else status = XmbTextListToTextProperty((Display *)display, &cname, 1, XStdICCTextStyle, &tp); #endif if (status == Success || status > 0) { AWT_CHECK_HAVE_LOCK(); XChangeProperty((Display *)display, window, atom, tp.encoding, tp.format, PropModeReplace, tp.value, tp.nitems); if (tp.value != NULL) { XFree(tp.value); } } if (!JNU_IsNull(env, jstr)) { #ifdef X_HAVE_UTF8_STRING (*env)->ReleaseStringUTFChars(env, jstr, (const char *) cname); #else JNU_ReleaseStringPlatformChars(env, jstr, (const char *) cname); #endif } }
EAPI void ecore_x_icccm_title_set(Ecore_X_Window win, const char *t) { char *list[1]; XTextProperty xprop; int ret; if (!t) return; LOGFN(__FILE__, __LINE__, __FUNCTION__); xprop.value = NULL; #ifdef X_HAVE_UTF8_STRING list[0] = strdup(t); ret = Xutf8TextListToTextProperty(_ecore_x_disp, list, 1, XUTF8StringStyle, &xprop); #else /* ifdef X_HAVE_UTF8_STRING */ list[0] = strdup(t); ret = XmbTextListToTextProperty(_ecore_x_disp, list, 1, XStdICCTextStyle, &xprop); #endif /* ifdef X_HAVE_UTF8_STRING */ if (_ecore_xlib_sync) ecore_x_sync(); if (ret >= Success) { XSetWMName(_ecore_x_disp, win, &xprop); if (_ecore_xlib_sync) ecore_x_sync(); if (xprop.value) XFree(xprop.value); } else if (XStringListToTextProperty(list, 1, &xprop) >= Success) { XSetWMName(_ecore_x_disp, win, &xprop); if (_ecore_xlib_sync) ecore_x_sync(); if (xprop.value) XFree(xprop.value); } free(list[0]); }
void xwindow_set_text_property(Window win, Atom a, const char **ptr, int n) { XTextProperty prop; bool ok; if(!ioncore_g.use_mb){ Status st=XStringListToTextProperty((char **)ptr, n, &prop); ok=(st!=0); }else{ int st=XmbTextListToTextProperty(ioncore_g.dpy, (char **)ptr, n, XTextStyle, &prop); ok=(st>=0); } if(!ok) return; XSetTextProperty(ioncore_g.dpy, win, &prop, a); XFree(prop.value); }
extern Atom XmeGetEncodingAtom(Widget widget) { /* amai: copied from lib/Xm/Selection.c:_XmTextConvert() ... */ Atom encoding=0; int status; char *list = "ABC"; XTextProperty text_prop_ret; status = XmbTextListToTextProperty( XtDisplay(widget), &list, 1, XTextStyle, &text_prop_ret ); encoding = 0x270f; /* ? */ if ( status == Success ) { encoding = text_prop_ret.encoding; } XFree( (char *)text_prop_ret.value ); return encoding; }
static Boolean SendSel(Widget w, Atom *sel, Atom *target, Atom *rtype, XtPointer *ans, uint64_t *anslen, int *ansfmt) { GwinWidget gw = (GwinWidget)w; XTextProperty p = {0}; char *ls[2] = {NULL, NULL}; if (*target == XA_STRING){ ls[0] = gw->gwin.selection? gw->gwin.selection : ""; if (XmbTextListToTextProperty(_dpy, ls, 1, XUTF8StringStyle, &p) != Success) return false; *rtype = p.encoding; *ans = (XtPointer) XtNewString(p.value); *anslen = p.nitems; *ansfmt = p.format; XFree(p.value); return true; } return false; }
Atom convert_sel_inner(Window requestor, Atom target, Atom property) { if (target == XA_STRING) { XChangeProperty (disp, requestor, property, XA_STRING, 8, PropModeReplace, (unsigned char *)seldata, seldatalen); return property; } else if (target == compound_text_atom) { XTextProperty tp; XmbTextListToTextProperty(disp, &seldata, 1, XCompoundTextStyle, &tp); XChangeProperty(disp, requestor, property, target, tp.format, PropModeReplace, tp.value, tp.nitems); return property; } else if (target == targets_atom) { Atom targets[16]; int len = 0; targets[len++] = timestamp_atom; targets[len++] = targets_atom; targets[len++] = multiple_atom; targets[len++] = XA_STRING; targets[len++] = compound_text_atom; XChangeProperty (disp, requestor, property, atom_atom, 32, PropModeReplace, (unsigned char *)targets, len); return property; } else if (target == timestamp_atom) { Time rettime = seltime; XChangeProperty (disp, requestor, property, integer_atom, 32, PropModeReplace, (unsigned char *)&rettime, 1); return property; } else { return None; } }
/* * This gets called from Xt to get a copy of whatever's selected in our text * widget. We're delivering it all in one go; according to Asente & Swick * Xt will break it up for us if the data delivered is too big. * * FIX ME is it wise to do this for e.g. a 1MB selection ? */ static Boolean _XmTextConvertSelection(Widget w, Atom *selection, Atom *target, Atom *type, XtPointer *value, unsigned long *length, int *format) { XmSourceData d = Text_Source(w)->data; DEBUGOUT(_LtDebug(__FILE__, w, "_XmTextConvertSelection\n")); if (d->hasselection) { #if 0 /* rws 12 Dec 1997 I think we need to make a copy of the value here. In ml if you select part of a message and try to paste it into another window you get a segfault in free(). It would appear that Xt is free'ing the contents of value. */ *value = &d->ptr[d->left]; #endif Atom atom_comp_text; Atom atom_text; atom_comp_text = XmInternAtom(XtDisplay(w), "COMPOUND_TEXT", False); atom_text = XmInternAtom(XtDisplay(w), "TEXT", False); if (*target == XA_STRING){ *length = (long)(d->right - d->left); *value = XtMalloc(d->right - d->left + 1); strncpy((char *)*value, &d->ptr[d->left], d->right - d->left); *type = XA_STRING; } else if (*target == atom_comp_text || *target == atom_text){ XTextProperty prop; char *buf; int ret; buf = XtMalloc(d->right - d->left + 1); strncpy(buf, &d->ptr[d->left], d->right - d->left); buf[d->right - d->left] = '\0'; ret = XmbTextListToTextProperty(XtDisplay(w), &buf, 1, XCompoundTextStyle, &prop); XtFree(buf); if (ret != 0){ *length = 0; *value = NULL; } else{ buf = XtMalloc(prop.nitems + 1); strncpy(buf, (char*)prop.value, prop.nitems); buf[prop.nitems] = '\0'; *length = prop.nitems; *value = buf; } *type = atom_comp_text; } else return False; *format = 8; return True; } return False; }
static Boolean ConvertSelection(Widget w, Atom *selection, Atom *target, Atom *type, XtPointer *value, unsigned long *length, int *format) { Display* d = XtDisplay(w); XSelectionRequestEvent* req = XtGetSelectionRequest(w, *selection, (XtRequestId)NULL); if (*target == XA_TARGETS(d)) { Atom* targetP; Atom* std_targets; unsigned long std_length; XmuConvertStandardSelection(w, req->time, selection, target, type, (XPointer*)&std_targets, &std_length, format); *value = XtMalloc(sizeof(Atom)*(std_length + 7)); targetP = *(Atom**)value; *targetP++ = XA_STRING; *targetP++ = XA_TEXT(d); *targetP++ = XA_UTF8_STRING(d); *targetP++ = XA_COMPOUND_TEXT(d); *targetP++ = XA_LENGTH(d); *targetP++ = XA_LIST_LENGTH(d); *targetP++ = XA_CHARACTER_POSITION(d); *length = std_length + (targetP - (*(Atom **) value)); memmove( (char*)targetP, (char*)std_targets, sizeof(Atom)*std_length); XtFree((char*)std_targets); *type = XA_ATOM; *format = 32; return True; } if (*target == XA_LIST_LENGTH(d) || *target == XA_LENGTH(d)) { long * temp; temp = (long *) XtMalloc(sizeof(long)); if (*target == XA_LIST_LENGTH(d)) *temp = 1L; else /* *target == XA_LENGTH(d) */ *temp = (long) TextLength (text); *value = (XPointer) temp; *type = XA_INTEGER; *length = 1L; *format = 32; return True; } if (*target == XA_CHARACTER_POSITION(d)) { long * temp; temp = (long *) XtMalloc(2 * sizeof(long)); temp[0] = (long) 0; temp[1] = TextLength (text); *value = (XPointer) temp; *type = XA_SPAN(d); *length = 2L; *format = 32; return True; } if (*target == XA_STRING || *target == XA_TEXT(d) || *target == XA_UTF8_STRING(d) || *target == XA_COMPOUND_TEXT(d)) { Arg args[1]; Widget source; XTextProperty prop; int ret, style = XStdICCTextStyle; /* a safe default for TEXT */ char *data; source = XawTextGetSource (text); XtSetArg (args[0], XtNstring, &data); XtGetValues (source, args, 1); if (*target == XA_UTF8_STRING(d)) style = XUTF8StringStyle; else if (*target == XA_COMPOUND_TEXT(d)) style = XCompoundTextStyle; else if (*target == XA_STRING) style = XStringStyle; ret = XmbTextListToTextProperty (d, &data, 1, style, &prop); if (ret >= Success) { *length = prop.nitems; *value = prop.value; *type = prop.encoding; *format = prop.format; return True; } else return False; } if (XmuConvertStandardSelection(w, req->time, selection, target, type, (XPointer *) value, length, format)) return True; return False; }
void SendHZtoClient (IMForwardEventStruct * call_data, char *strHZ) { XTextProperty tp; IMCommitStruct cms; char strOutput[300]; char *ps; char *pS2T = (char *) NULL; #ifdef _DEBUG fprintf (stderr, "Sending %s icid=%d connectid=%d\n", strHZ, CurrentIC->id, connect_id); #endif /* avoid Seg fault */ if (!call_data && !CurrentIC) return; #ifdef _ENABLE_RECORDING if (bRecording) { if (OpenRecording(True)) { if ( !bWrittenRecord ) { char buf[20]; struct tm *ts; time_t now; now=time(NULL); ts = localtime(&now); strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", ts); fprintf(fpRecord, "%s\n", buf); } fprintf(fpRecord, "%s", strHZ); bWrittenRecord = True; } } #endif if (bUseGBKT) pS2T = strHZ = ConvertGBKSimple2Tradition (strHZ); if (bIsUtf8) { size_t l1, l2; ps = strOutput; l1 = strlen (strHZ); l2 = 299; l1 = iconv (convUTF8, (ICONV_CONST char **) (&strHZ), &l1, &ps, &l2); *ps = '\0'; ps = strOutput; } else ps = strHZ; XmbTextListToTextProperty (dpy, (char **) &ps, 1, XCompoundTextStyle, &tp); memset (&cms, 0, sizeof (cms)); cms.major_code = XIM_COMMIT; if (call_data) { cms.icid = call_data->icid; cms.connect_id = call_data->connect_id; } else { cms.icid = CurrentIC->id; cms.connect_id = connect_id; } cms.flag = XimLookupChars; cms.commit_string = (char *) tp.value; IMCommitString (ims, (XPointer) & cms); XFree (tp.value); if (bUseGBKT) free (pS2T); }
Boolean _XmTextConvert(Widget w, Atom *selection, Atom *target, Atom *type, XtPointer *value, unsigned long *length, int *format) { char *value_ptr; Boolean get_sel_flag; Boolean motif_sel_flag; Boolean secondary_sel_flag; Boolean primary_sel_flag; Boolean destination_sel_flag; Atom encoding; Atom motif_drop_atom; Atom time_stamp_atom; Atom compound_text_atom; Atom text_atom; Atom multiple_atom; Atom targets_atom; Atom delete_atom; Atom insert_selection_atom; Atom motif_destination_atom; XmTextSource source_ts2; char *source_string; XmTextPosition right_tp; XmTextPosition left_tp; char *list; Arg args; Widget wid; XTextProperty text_prop_ret; int count; Widget wid2; int status; motif_destination_atom = XmInternAtom( XtDisplay(w), "MOTIF_DESTINATION", False ); insert_selection_atom = XmInternAtom( XtDisplay(w), "INSERT_SELECTION", False ); delete_atom = XmInternAtom( XtDisplay(w), "DELETE", False ); targets_atom = XmInternAtom( XtDisplay(w), "TARGETS", False ); multiple_atom = XmInternAtom( XtDisplay(w), "MULTIPLE", False ); text_atom = XmInternAtom( XtDisplay(w), "TEXT" , False ); compound_text_atom = XmInternAtom( XtDisplay(w), "COMPOUND_TEXT", False ); time_stamp_atom = XmInternAtom( XtDisplay(w), "TIMESTAMP", False ); motif_drop_atom = XmInternAtom( XtDisplay(w), "_MOTIF_DROP", False ); left_tp = 0; right_tp = 0; count = 0; list = "ABC"; if ( *selection == motif_drop_atom ) { XtSetArg( args, XmNclientData, &wid ); XtGetValues( w, &args, 1 ); wid2 = wid; } else { wid2 = w; } if ( wid2 == NULL ) { return False; } source_ts2 = Text_Source(wid2); status = XmbTextListToTextProperty( XtDisplay(wid2), &list, 1, XTextStyle, &text_prop_ret ); encoding = 0x270f; if ( status == Success ) { encoding = text_prop_ret.encoding; } XFree( (char *)text_prop_ret.value ); if ( *selection == XA_PRIMARY ) { get_sel_flag = (Text_Source(wid2)->GetSelection)( source_ts2, &left_tp, &right_tp); primary_sel_flag = True; motif_sel_flag = False; destination_sel_flag = False; secondary_sel_flag = False; } else if ( *selection == motif_destination_atom ) { get_sel_flag = Text_Input(wid)->data->sel_start; destination_sel_flag = True; motif_sel_flag = False; primary_sel_flag = False; secondary_sel_flag = False; } else if ( *selection == XA_SECONDARY ) { get_sel_flag = _XmTextGetSel2( (XmTextWidget)wid2, &left_tp, &right_tp ); secondary_sel_flag = True; motif_sel_flag = False; primary_sel_flag = False; destination_sel_flag = False; } else if ( *selection == motif_drop_atom ) { get_sel_flag = (Text_Source(wid2)->GetSelection)( source_ts2, &left_tp, &right_tp ); motif_sel_flag = True; secondary_sel_flag = False; primary_sel_flag = False; destination_sel_flag = False; } else { return False; } if ( *target == targets_atom ) { value_ptr = XtMalloc( 10 * sizeof( void *) ); *value = value_ptr; *value_ptr++ = encoding; *value_ptr++ = targets_atom; *value_ptr++ = multiple_atom; *value_ptr++ = time_stamp_atom; count += 4; if ( primary_sel_flag == False || destination_sel_flag == False ) { *value_ptr++ = insert_selection_atom; count += 1; } if ( primary_sel_flag == True || secondary_sel_flag == True || motif_sel_flag == True ) { *value_ptr++ = compound_text_atom; *value_ptr++ = text_atom; *value_ptr++ = 31; count += 3; } if ( primary_sel_flag == True || motif_sel_flag == True ) { *value_ptr++ = delete_atom; count += 1; } *type = 4; *length = count; *format = 0x20; return True; } else if ( *target == time_stamp_atom ) { value_ptr = XtMalloc( sizeof(void *) ); if ( primary_sel_flag == True ) { *value_ptr = source_ts2->data->prim_time; } else if ( destination_sel_flag == True ) { *value_ptr = Text_Input(wid2)->data->sec_time; } else if ( secondary_sel_flag == True || motif_sel_flag == True ) { *value_ptr = Text_Input(wid2)->data->lasttime; } *value = value_ptr; *type = 0x14; *length = 4; *format = 0x20; return True; } else if ( *target == XA_STRING ) { *type = 0x1f; *format = 8; if ( destination_sel_flag == True || get_sel_flag == False ) { return False; } source_string = _XmStringSourceGetString( (XmTextWidget)wid2, left_tp, right_tp, False ); status = XmbTextListToTextProperty( XtDisplay(wid2), &source_string, 1, 0, (XTextProperty*)&right_tp ); XtFree( source_string ); if ( status == Success || status > 0 ) { value_ptr = XtMalloc( text_prop_ret.nitems ); *value = value_ptr; memcpy( value_ptr, text_prop_ret.value, text_prop_ret.nitems ); XFree( text_prop_ret.value ); *length = text_prop_ret.nitems; return True; } else { *value = NULL; *length = 0x1c; return False; } } else if ( *target == text_atom ) { if ( destination_sel_flag == True || get_sel_flag == False ) { return False; } source_string = _XmStringSourceGetString( (XmTextWidget)wid2, left_tp, right_tp, False ); status = XmbTextListToTextProperty( XtDisplay(wid2), &source_string, 1, XStdICCTextStyle, &text_prop_ret ); *type = text_prop_ret.encoding; *format = text_prop_ret.format; XtFree( source_string ); if ( status == Success || status > 0 ) { value_ptr = XtMalloc( text_prop_ret.nitems ); *value = value_ptr; memcpy( value_ptr, text_prop_ret.value, text_prop_ret.nitems ); XFree( text_prop_ret.value ); *length = text_prop_ret.nitems; return True; } *value = NULL; *length = 0; return False; } else if ( *target == encoding ) { *type = encoding; *format = 0x8; if ( destination_sel_flag == True || get_sel_flag == False ) { return False; } value_ptr = _XmStringSourceGetString( (XmTextWidget)wid2, left_tp, right_tp, False ); *value = value_ptr; *length = strlen( value_ptr ); return True; } else if ( *target == compound_text_atom ) { *type = compound_text_atom; *format = 0x8; if ( destination_sel_flag == True || get_sel_flag == False ) { return False; } source_string = _XmStringSourceGetString( (XmTextWidget)wid2, left_tp, right_tp, False ); status = XmbTextListToTextProperty( XtDisplay(wid2), &source_string, 1, XCompoundTextStyle, &text_prop_ret ); XtFree( source_string ); if ( status == Success || status > 0 ) { value_ptr = XtMalloc( sizeof(void *) ); *value = value_ptr; memcpy( value_ptr, text_prop_ret.value, text_prop_ret.nitems ); XFree( text_prop_ret.value ); *length = text_prop_ret.nitems; return True; } else { *value = NULL; *length = 0; return False; } } else if ( *target == insert_selection_atom ) { if ( secondary_sel_flag == True ) { return False; } #if 0 return ConvertInsertSelection( w, selection, type, value, length, format ); #else return False; #endif } else if ( *target == delete_atom ) { if ( primary_sel_flag == False && motif_sel_flag == False ) { return False; } /* the other flags are valid FIXME */ return False; } else { return False; } }
int winClipboardFlushXEvents(HWND hwnd, Window iWindow, Display * pDisplay, ClipboardConversionData *data, ClipboardAtoms *atoms) { Atom atomClipboard = atoms->atomClipboard; Atom atomLocalProperty = atoms->atomLocalProperty; Atom atomUTF8String = atoms->atomUTF8String; Atom atomCompoundText = atoms->atomCompoundText; Atom atomTargets = atoms->atomTargets; /* Process all pending events */ while (XPending(pDisplay)) { XTextProperty xtpText = { 0 }; XEvent event; XSelectionEvent eventSelection; unsigned long ulReturnBytesLeft; char *pszReturnData = NULL; char *pszGlobalData = NULL; int iReturn; HGLOBAL hGlobal = NULL; XICCEncodingStyle xiccesStyle; char *pszConvertData = NULL; char *pszTextList[2] = { NULL }; int iCount; char **ppszTextList = NULL; wchar_t *pwszUnicodeStr = NULL; Bool fAbort = FALSE; Bool fCloseClipboard = FALSE; Bool fSetClipboardData = TRUE; /* Get the next event - will not block because one is ready */ XNextEvent(pDisplay, &event); /* Branch on the event type */ switch (event.type) { /* * SelectionRequest */ case SelectionRequest: { char *pszAtomName = NULL; winDebug("SelectionRequest - target %ld\n", event.xselectionrequest.target); pszAtomName = XGetAtomName(pDisplay, event.xselectionrequest.target); winDebug("SelectionRequest - Target atom name %s\n", pszAtomName); XFree(pszAtomName); pszAtomName = NULL; } /* Abort if invalid target type */ if (event.xselectionrequest.target != XA_STRING && event.xselectionrequest.target != atomUTF8String && event.xselectionrequest.target != atomCompoundText && event.xselectionrequest.target != atomTargets) { /* Abort */ fAbort = TRUE; goto winClipboardFlushXEvents_SelectionRequest_Done; } /* Handle targets type of request */ if (event.xselectionrequest.target == atomTargets) { Atom atomTargetArr[] = { atomTargets, atomCompoundText, atomUTF8String, XA_STRING }; /* Try to change the property */ iReturn = XChangeProperty(pDisplay, event.xselectionrequest.requestor, event.xselectionrequest.property, XA_ATOM, 32, PropModeReplace, (unsigned char *) atomTargetArr, ARRAY_SIZE(atomTargetArr)); if (iReturn == BadAlloc || iReturn == BadAtom || iReturn == BadMatch || iReturn == BadValue || iReturn == BadWindow) { ErrorF("winClipboardFlushXEvents - SelectionRequest - " "XChangeProperty failed: %d\n", iReturn); } /* Setup selection notify xevent */ eventSelection.type = SelectionNotify; eventSelection.send_event = True; eventSelection.display = pDisplay; eventSelection.requestor = event.xselectionrequest.requestor; eventSelection.selection = event.xselectionrequest.selection; eventSelection.target = event.xselectionrequest.target; eventSelection.property = event.xselectionrequest.property; eventSelection.time = event.xselectionrequest.time; /* * Notify the requesting window that * the operation has completed */ iReturn = XSendEvent(pDisplay, eventSelection.requestor, False, 0L, (XEvent *) &eventSelection); if (iReturn == BadValue || iReturn == BadWindow) { ErrorF("winClipboardFlushXEvents - SelectionRequest - " "XSendEvent () failed\n"); } break; } /* Close clipboard if we have it open already */ if (GetOpenClipboardWindow() == hwnd) { CloseClipboard(); } /* Access the clipboard */ if (!OpenClipboard(hwnd)) { ErrorF("winClipboardFlushXEvents - SelectionRequest - " "OpenClipboard () failed: %08x\n", (unsigned int)GetLastError()); /* Abort */ fAbort = TRUE; goto winClipboardFlushXEvents_SelectionRequest_Done; } /* Indicate that clipboard was opened */ fCloseClipboard = TRUE; /* Check that clipboard format is available */ if (data->fUseUnicode && !IsClipboardFormatAvailable(CF_UNICODETEXT)) { static int count; /* Hack to stop acroread spamming the log */ static HWND lasthwnd; /* I've not seen any other client get here repeatedly? */ if (hwnd != lasthwnd) count = 0; count++; if (count < 6) ErrorF("winClipboardFlushXEvents - CF_UNICODETEXT is not " "available from Win32 clipboard. Aborting %d.\n", count); lasthwnd = hwnd; /* Abort */ fAbort = TRUE; goto winClipboardFlushXEvents_SelectionRequest_Done; } else if (!data->fUseUnicode && !IsClipboardFormatAvailable(CF_TEXT)) { ErrorF("winClipboardFlushXEvents - CF_TEXT is not " "available from Win32 clipboard. Aborting.\n"); /* Abort */ fAbort = TRUE; goto winClipboardFlushXEvents_SelectionRequest_Done; } /* Setup the string style */ if (event.xselectionrequest.target == XA_STRING) xiccesStyle = XStringStyle; #ifdef X_HAVE_UTF8_STRING else if (event.xselectionrequest.target == atomUTF8String) xiccesStyle = XUTF8StringStyle; #endif else if (event.xselectionrequest.target == atomCompoundText) xiccesStyle = XCompoundTextStyle; else xiccesStyle = XStringStyle; /* Get a pointer to the clipboard text, in desired format */ if (data->fUseUnicode) { /* Retrieve clipboard data */ hGlobal = GetClipboardData(CF_UNICODETEXT); } else { /* Retrieve clipboard data */ hGlobal = GetClipboardData(CF_TEXT); } if (!hGlobal) { ErrorF("winClipboardFlushXEvents - SelectionRequest - " "GetClipboardData () failed: %08x\n", (unsigned int)GetLastError()); /* Abort */ fAbort = TRUE; goto winClipboardFlushXEvents_SelectionRequest_Done; } pszGlobalData = (char *) GlobalLock(hGlobal); /* Convert the Unicode string to UTF8 (MBCS) */ if (data->fUseUnicode) { int iConvertDataLen = WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR) pszGlobalData, -1, NULL, 0, NULL, NULL); /* NOTE: iConvertDataLen includes space for null terminator */ pszConvertData = malloc(iConvertDataLen); WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR) pszGlobalData, -1, pszConvertData, iConvertDataLen, NULL, NULL); } else { pszConvertData = strdup(pszGlobalData); } /* Convert DOS string to UNIX string */ winClipboardDOStoUNIX(pszConvertData, strlen(pszConvertData)); /* Setup our text list */ pszTextList[0] = pszConvertData; pszTextList[1] = NULL; /* Initialize the text property */ xtpText.value = NULL; xtpText.nitems = 0; /* Create the text property from the text list */ if (data->fUseUnicode) { #ifdef X_HAVE_UTF8_STRING iReturn = Xutf8TextListToTextProperty(pDisplay, pszTextList, 1, xiccesStyle, &xtpText); #endif } else { iReturn = XmbTextListToTextProperty(pDisplay, pszTextList, 1, xiccesStyle, &xtpText); } if (iReturn == XNoMemory || iReturn == XLocaleNotSupported) { ErrorF("winClipboardFlushXEvents - SelectionRequest - " "X*TextListToTextProperty failed: %d\n", iReturn); /* Abort */ fAbort = TRUE; goto winClipboardFlushXEvents_SelectionRequest_Done; } /* Free the converted string */ free(pszConvertData); pszConvertData = NULL; /* Copy the clipboard text to the requesting window */ iReturn = XChangeProperty(pDisplay, event.xselectionrequest.requestor, event.xselectionrequest.property, event.xselectionrequest.target, 8, PropModeReplace, xtpText.value, xtpText.nitems); if (iReturn == BadAlloc || iReturn == BadAtom || iReturn == BadMatch || iReturn == BadValue || iReturn == BadWindow) { ErrorF("winClipboardFlushXEvents - SelectionRequest - " "XChangeProperty failed: %d\n", iReturn); /* Abort */ fAbort = TRUE; goto winClipboardFlushXEvents_SelectionRequest_Done; } /* Release the clipboard data */ GlobalUnlock(hGlobal); pszGlobalData = NULL; fCloseClipboard = FALSE; CloseClipboard(); /* Clean up */ XFree(xtpText.value); xtpText.value = NULL; xtpText.nitems = 0; /* Setup selection notify event */ eventSelection.type = SelectionNotify; eventSelection.send_event = True; eventSelection.display = pDisplay; eventSelection.requestor = event.xselectionrequest.requestor; eventSelection.selection = event.xselectionrequest.selection; eventSelection.target = event.xselectionrequest.target; eventSelection.property = event.xselectionrequest.property; eventSelection.time = event.xselectionrequest.time; /* Notify the requesting window that the operation has completed */ iReturn = XSendEvent(pDisplay, eventSelection.requestor, False, 0L, (XEvent *) &eventSelection); if (iReturn == BadValue || iReturn == BadWindow) { ErrorF("winClipboardFlushXEvents - SelectionRequest - " "XSendEvent () failed\n"); /* Abort */ fAbort = TRUE; goto winClipboardFlushXEvents_SelectionRequest_Done; } winClipboardFlushXEvents_SelectionRequest_Done: /* Free allocated resources */ if (xtpText.value) { XFree(xtpText.value); xtpText.value = NULL; xtpText.nitems = 0; } free(pszConvertData); if (hGlobal && pszGlobalData) GlobalUnlock(hGlobal); /* * Send a SelectionNotify event to the requesting * client when we abort. */ if (fAbort) { /* Setup selection notify event */ eventSelection.type = SelectionNotify; eventSelection.send_event = True; eventSelection.display = pDisplay; eventSelection.requestor = event.xselectionrequest.requestor; eventSelection.selection = event.xselectionrequest.selection; eventSelection.target = event.xselectionrequest.target; eventSelection.property = None; eventSelection.time = event.xselectionrequest.time; /* Notify the requesting window that the operation is complete */ iReturn = XSendEvent(pDisplay, eventSelection.requestor, False, 0L, (XEvent *) &eventSelection); if (iReturn == BadValue || iReturn == BadWindow) { /* * Should not be a problem if XSendEvent fails because * the client may simply have exited. */ ErrorF("winClipboardFlushXEvents - SelectionRequest - " "XSendEvent () failed for abort event.\n"); } } /* Close clipboard if it was opened */ if (fCloseClipboard) { fCloseClipboard = FALSE; CloseClipboard(); } break; /* * SelectionNotify */ case SelectionNotify: winDebug("winClipboardFlushXEvents - SelectionNotify\n"); { char *pszAtomName; pszAtomName = XGetAtomName(pDisplay, event.xselection.selection); winDebug ("winClipboardFlushXEvents - SelectionNotify - ATOM: %s\n", pszAtomName); XFree(pszAtomName); } /* SelectionNotify with property of None indicates either: (i) Generated by the X server if no owner for the specified selection exists (perhaps it's disappeared on us mid-transaction), or (ii) Sent by the selection owner when the requested selection conversion could not be performed or server errors prevented the conversion data being returned */ if (event.xselection.property == None) { ErrorF("winClipboardFlushXEvents - SelectionNotify - " "Conversion to format %ld refused.\n", event.xselection.target); return WIN_XEVENTS_FAILED; } if (event.xselection.target == atomTargets) { return winClipboardSelectionNotifyTargets(hwnd, iWindow, pDisplay, data, atoms); } /* Retrieve the selection data and delete the property */ iReturn = XGetWindowProperty(pDisplay, iWindow, atomLocalProperty, 0, INT_MAX, True, AnyPropertyType, &xtpText.encoding, &xtpText.format, &xtpText.nitems, &ulReturnBytesLeft, &xtpText.value); if (iReturn != Success) { ErrorF("winClipboardFlushXEvents - SelectionNotify - " "XGetWindowProperty () failed, aborting: %d\n", iReturn); goto winClipboardFlushXEvents_SelectionNotify_Done; } { char *pszAtomName = NULL; winDebug("SelectionNotify - returned data %lu left %lu\n", xtpText.nitems, ulReturnBytesLeft); pszAtomName = XGetAtomName(pDisplay, xtpText.encoding); winDebug("Notify atom name %s\n", pszAtomName); XFree(pszAtomName); pszAtomName = NULL; } if (data->fUseUnicode) { #ifdef X_HAVE_UTF8_STRING /* Convert the text property to a text list */ iReturn = Xutf8TextPropertyToTextList(pDisplay, &xtpText, &ppszTextList, &iCount); #endif } else { iReturn = XmbTextPropertyToTextList(pDisplay, &xtpText, &ppszTextList, &iCount); } if (iReturn == Success || iReturn > 0) { /* Conversion succeeded or some unconvertible characters */ if (ppszTextList != NULL) { int i; int iReturnDataLen = 0; for (i = 0; i < iCount; i++) { iReturnDataLen += strlen(ppszTextList[i]); } pszReturnData = malloc(iReturnDataLen + 1); pszReturnData[0] = '\0'; for (i = 0; i < iCount; i++) { strcat(pszReturnData, ppszTextList[i]); } } else { ErrorF("winClipboardFlushXEvents - SelectionNotify - " "X*TextPropertyToTextList list_return is NULL.\n"); pszReturnData = malloc(1); pszReturnData[0] = '\0'; } } else { ErrorF("winClipboardFlushXEvents - SelectionNotify - " "X*TextPropertyToTextList returned: "); switch (iReturn) { case XNoMemory: ErrorF("XNoMemory\n"); break; case XLocaleNotSupported: ErrorF("XLocaleNotSupported\n"); break; case XConverterNotFound: ErrorF("XConverterNotFound\n"); break; default: ErrorF("%d\n", iReturn); break; } pszReturnData = malloc(1); pszReturnData[0] = '\0'; } /* Free the data returned from XGetWindowProperty */ if (ppszTextList) XFreeStringList(ppszTextList); ppszTextList = NULL; XFree(xtpText.value); xtpText.value = NULL; xtpText.nitems = 0; /* Convert the X clipboard string to DOS format */ winClipboardUNIXtoDOS(&pszReturnData, strlen(pszReturnData)); if (data->fUseUnicode) { /* Find out how much space needed to convert MBCS to Unicode */ int iUnicodeLen = MultiByteToWideChar(CP_UTF8, 0, pszReturnData, -1, NULL, 0); /* NOTE: iUnicodeLen includes space for null terminator */ pwszUnicodeStr = malloc(sizeof(wchar_t) * iUnicodeLen); if (!pwszUnicodeStr) { ErrorF("winClipboardFlushXEvents - SelectionNotify " "malloc failed for pwszUnicodeStr, aborting.\n"); /* Abort */ fAbort = TRUE; goto winClipboardFlushXEvents_SelectionNotify_Done; } /* Do the actual conversion */ MultiByteToWideChar(CP_UTF8, 0, pszReturnData, -1, pwszUnicodeStr, iUnicodeLen); /* Allocate global memory for the X clipboard data */ hGlobal = GlobalAlloc(GMEM_MOVEABLE, sizeof(wchar_t) * iUnicodeLen); } else { int iConvertDataLen = 0; pszConvertData = strdup(pszReturnData); iConvertDataLen = strlen(pszConvertData) + 1; /* Allocate global memory for the X clipboard data */ hGlobal = GlobalAlloc(GMEM_MOVEABLE, iConvertDataLen); } free(pszReturnData); /* Check that global memory was allocated */ if (!hGlobal) { ErrorF("winClipboardFlushXEvents - SelectionNotify " "GlobalAlloc failed, aborting: %08x\n", (unsigned int)GetLastError()); /* Abort */ fAbort = TRUE; goto winClipboardFlushXEvents_SelectionNotify_Done; } /* Obtain a pointer to the global memory */ pszGlobalData = GlobalLock(hGlobal); if (pszGlobalData == NULL) { ErrorF("winClipboardFlushXEvents - Could not lock global " "memory for clipboard transfer\n"); /* Abort */ fAbort = TRUE; goto winClipboardFlushXEvents_SelectionNotify_Done; } /* Copy the returned string into the global memory */ if (data->fUseUnicode) { wcscpy((wchar_t *)pszGlobalData, pwszUnicodeStr); free(pwszUnicodeStr); pwszUnicodeStr = NULL; } else { strcpy(pszGlobalData, pszConvertData); free(pszConvertData); pszConvertData = NULL; } /* Release the pointer to the global memory */ GlobalUnlock(hGlobal); pszGlobalData = NULL; /* Push the selection data to the Windows clipboard */ if (data->fUseUnicode) SetClipboardData(CF_UNICODETEXT, hGlobal); else SetClipboardData(CF_TEXT, hGlobal); /* Flag that SetClipboardData has been called */ fSetClipboardData = FALSE; /* * NOTE: Do not try to free pszGlobalData, it is owned by * Windows after the call to SetClipboardData (). */ winClipboardFlushXEvents_SelectionNotify_Done: /* Free allocated resources */ if (ppszTextList) XFreeStringList(ppszTextList); if (xtpText.value) { XFree(xtpText.value); xtpText.value = NULL; xtpText.nitems = 0; } free(pszConvertData); free(pwszUnicodeStr); if (hGlobal && pszGlobalData) GlobalUnlock(hGlobal); if (fSetClipboardData) { SetClipboardData(CF_UNICODETEXT, NULL); SetClipboardData(CF_TEXT, NULL); } return WIN_XEVENTS_NOTIFY_DATA; case SelectionClear: winDebug("SelectionClear - doing nothing\n"); break; case PropertyNotify: break; case MappingNotify: break; default: if (event.type == XFixesSetSelectionOwnerNotify + xfixes_event_base) { XFixesSelectionNotifyEvent *e = (XFixesSelectionNotifyEvent *) & event; winDebug("winClipboardFlushXEvents - XFixesSetSelectionOwnerNotify\n"); /* Save selection owners for monitored selections, ignore other selections */ if ((e->selection == XA_PRIMARY) && fPrimarySelection) { MonitorSelection(e, CLIP_OWN_PRIMARY); } else if (e->selection == atomClipboard) { MonitorSelection(e, CLIP_OWN_CLIPBOARD); } else break; /* Selection is being disowned */ if (e->owner == None) { winDebug ("winClipboardFlushXEvents - No window, returning.\n"); break; } /* XXX: there are all kinds of wacky edge cases we might need here: - we own windows clipboard, but neither PRIMARY nor CLIPBOARD have an owner, so we should disown it? - root window is taking ownership? */ /* If we are the owner of the most recently owned selection, don't go all recursive :) */ if ((lastOwnedSelectionIndex != CLIP_OWN_NONE) && (s_iOwners[lastOwnedSelectionIndex] == iWindow)) { winDebug("winClipboardFlushXEvents - Ownership changed to us, aborting.\n"); break; } /* Close clipboard if we have it open already (possible? correct??) */ if (GetOpenClipboardWindow() == hwnd) { CloseClipboard(); } /* Access the Windows clipboard */ if (!OpenClipboard(hwnd)) { ErrorF("winClipboardFlushXEvents - OpenClipboard () failed: %08x\n", (int) GetLastError()); break; } /* Take ownership of the Windows clipboard */ if (!EmptyClipboard()) { ErrorF("winClipboardFlushXEvents - EmptyClipboard () failed: %08x\n", (int) GetLastError()); break; } /* Advertise regular text and unicode */ SetClipboardData(CF_UNICODETEXT, NULL); SetClipboardData(CF_TEXT, NULL); /* Release the clipboard */ if (!CloseClipboard()) { ErrorF("winClipboardFlushXEvents - CloseClipboard () failed: %08x\n", (int) GetLastError()); break; } } /* XFixesSelectionWindowDestroyNotifyMask */ /* XFixesSelectionClientCloseNotifyMask */ else { ErrorF("winClipboardFlushXEvents - unexpected event type %d\n", event.type); } break; } } return WIN_XEVENTS_SUCCESS; }
int winClipboardFlushXEvents (HWND hwnd, int iWindow, Display *pDisplay, Bool fUseUnicode) { static Atom atomLocalProperty; static Atom atomCompoundText; static Atom atomUTF8String; static Atom atomTargets; static int generation; if (generation != serverGeneration) { generation = serverGeneration; atomLocalProperty = XInternAtom (pDisplay, WIN_LOCAL_PROPERTY, False); atomUTF8String = XInternAtom (pDisplay, "UTF8_STRING", False); atomCompoundText = XInternAtom (pDisplay, "COMPOUND_TEXT", False); atomTargets = XInternAtom (pDisplay, "TARGETS", False); } /* Process all pending events */ while (XPending (pDisplay)) { XTextProperty xtpText = {0}; XEvent event; XSelectionEvent eventSelection; unsigned long ulReturnBytesLeft; char *pszReturnData = NULL; char *pszGlobalData = NULL; int iReturn; HGLOBAL hGlobal = NULL; XICCEncodingStyle xiccesStyle; int iConvertDataLen = 0; char *pszConvertData = NULL; char *pszTextList[2] = {NULL}; int iCount; char **ppszTextList = NULL; wchar_t *pwszUnicodeStr = NULL; int iUnicodeLen = 0; int iReturnDataLen = 0; int i; Bool fAbort = FALSE; Bool fCloseClipboard = FALSE; Bool fSetClipboardData = TRUE; /* Get the next event - will not block because one is ready */ XNextEvent (pDisplay, &event); /* Branch on the event type */ switch (event.type) { /* * SelectionRequest */ case SelectionRequest: { char *pszAtomName = NULL; winDebug("SelectionRequest - target %d\n", event.xselectionrequest.target); pszAtomName = XGetAtomName (pDisplay, event.xselectionrequest.target); winDebug("SelectionRequest - Target atom name %s\n", pszAtomName); XFree (pszAtomName); pszAtomName = NULL; } /* Abort if invalid target type */ if (event.xselectionrequest.target != XA_STRING && event.xselectionrequest.target != atomUTF8String && event.xselectionrequest.target != atomCompoundText && event.xselectionrequest.target != atomTargets) { /* Abort */ fAbort = TRUE; goto winClipboardFlushXEvents_SelectionRequest_Done; } /* Handle targets type of request */ if (event.xselectionrequest.target == atomTargets) { Atom atomTargetArr[] = {atomTargets, atomCompoundText, atomUTF8String, XA_STRING}; /* Try to change the property */ iReturn = XChangeProperty (pDisplay, event.xselectionrequest.requestor, event.xselectionrequest.property, XA_ATOM, 32, PropModeReplace, (unsigned char *) atomTargetArr, (sizeof (atomTargetArr) / sizeof (atomTargetArr[0]))); if (iReturn == BadAlloc || iReturn == BadAtom || iReturn == BadMatch || iReturn == BadValue || iReturn == BadWindow) { ErrorF ("winClipboardFlushXEvents - SelectionRequest - " "XChangeProperty failed: %d\n", iReturn); } /* Setup selection notify xevent */ eventSelection.type = SelectionNotify; eventSelection.send_event = True; eventSelection.display = pDisplay; eventSelection.requestor = event.xselectionrequest.requestor; eventSelection.selection = event.xselectionrequest.selection; eventSelection.target = event.xselectionrequest.target; eventSelection.property = event.xselectionrequest.property; eventSelection.time = event.xselectionrequest.time; /* * Notify the requesting window that * the operation has completed */ iReturn = XSendEvent (pDisplay, eventSelection.requestor, False, 0L, (XEvent *) &eventSelection); if (iReturn == BadValue || iReturn == BadWindow) { ErrorF ("winClipboardFlushXEvents - SelectionRequest - " "XSendEvent () failed\n"); } break; } /* Check that clipboard format is available */ if (fUseUnicode && !IsClipboardFormatAvailable (CF_UNICODETEXT)) { static int count; /* Hack to stop acroread spamming the log */ static HWND lasthwnd; /* I've not seen any other client get here repeatedly? */ if (hwnd != lasthwnd) count = 0; count++; if (count < 6) ErrorF ("winClipboardFlushXEvents - CF_UNICODETEXT is not " "available from Win32 clipboard. Aborting %d.\n", count); lasthwnd = hwnd; /* Abort */ fAbort = TRUE; goto winClipboardFlushXEvents_SelectionRequest_Done; } else if (!fUseUnicode && !IsClipboardFormatAvailable (CF_TEXT)) { ErrorF ("winClipboardFlushXEvents - CF_TEXT is not " "available from Win32 clipboard. Aborting.\n"); /* Abort */ fAbort = TRUE; goto winClipboardFlushXEvents_SelectionRequest_Done; } /* Close clipboard if we have it open already */ if (GetOpenClipboardWindow () == hwnd) { CloseClipboard (); } /* Access the clipboard */ if (!OpenClipboard (hwnd)) { ErrorF ("winClipboardFlushXEvents - SelectionRequest - " "OpenClipboard () failed: %08lx\n", GetLastError ()); /* Abort */ fAbort = TRUE; goto winClipboardFlushXEvents_SelectionRequest_Done; } /* Indicate that clipboard was opened */ fCloseClipboard = TRUE; /* Setup the string style */ if (event.xselectionrequest.target == XA_STRING) xiccesStyle = XStringStyle; #ifdef X_HAVE_UTF8_STRING else if (event.xselectionrequest.target == atomUTF8String) xiccesStyle = XUTF8StringStyle; #endif else if (event.xselectionrequest.target == atomCompoundText) xiccesStyle = XCompoundTextStyle; else xiccesStyle = XStringStyle; /* * FIXME: Can't pass CF_UNICODETEXT on Windows 95/98/Me */ /* Get a pointer to the clipboard text, in desired format */ if (fUseUnicode) { /* Retrieve clipboard data */ hGlobal = GetClipboardData (CF_UNICODETEXT); } else { /* Retrieve clipboard data */ hGlobal = GetClipboardData (CF_TEXT); } if (!hGlobal) { ErrorF ("winClipboardFlushXEvents - SelectionRequest - " "GetClipboardData () failed: %08lx\n", GetLastError ()); /* Abort */ fAbort = TRUE; goto winClipboardFlushXEvents_SelectionRequest_Done; } pszGlobalData = (char *) GlobalLock (hGlobal); /* Convert the Unicode string to UTF8 (MBCS) */ if (fUseUnicode) { iConvertDataLen = WideCharToMultiByte (CP_UTF8, 0, (LPCWSTR)pszGlobalData, -1, NULL, 0, NULL, NULL); /* NOTE: iConvertDataLen includes space for null terminator */ pszConvertData = (char *) malloc (iConvertDataLen); WideCharToMultiByte (CP_UTF8, 0, (LPCWSTR)pszGlobalData, -1, pszConvertData, iConvertDataLen, NULL, NULL); } else { pszConvertData = strdup (pszGlobalData); iConvertDataLen = strlen (pszConvertData) + 1; } /* Convert DOS string to UNIX string */ winClipboardDOStoUNIX (pszConvertData, strlen (pszConvertData)); /* Setup our text list */ pszTextList[0] = pszConvertData; pszTextList[1] = NULL; /* Initialize the text property */ xtpText.value = NULL; xtpText.nitems = 0; /* Create the text property from the text list */ if (fUseUnicode) { #ifdef X_HAVE_UTF8_STRING iReturn = Xutf8TextListToTextProperty (pDisplay, pszTextList, 1, xiccesStyle, &xtpText); #endif } else { iReturn = XmbTextListToTextProperty (pDisplay, pszTextList, 1, xiccesStyle, &xtpText); } if (iReturn == XNoMemory || iReturn == XLocaleNotSupported) { ErrorF ("winClipboardFlushXEvents - SelectionRequest - " "X*TextListToTextProperty failed: %d\n", iReturn); /* Abort */ fAbort = TRUE; goto winClipboardFlushXEvents_SelectionRequest_Done; } /* Free the converted string */ free (pszConvertData); pszConvertData = NULL; /* Copy the clipboard text to the requesting window */ iReturn = XChangeProperty (pDisplay, event.xselectionrequest.requestor, event.xselectionrequest.property, event.xselectionrequest.target, 8, PropModeReplace, xtpText.value, xtpText.nitems); if (iReturn == BadAlloc || iReturn == BadAtom || iReturn == BadMatch || iReturn == BadValue || iReturn == BadWindow) { ErrorF ("winClipboardFlushXEvents - SelectionRequest - " "XChangeProperty failed: %d\n", iReturn); /* Abort */ fAbort = TRUE; goto winClipboardFlushXEvents_SelectionRequest_Done; } /* Release the clipboard data */ GlobalUnlock (hGlobal); pszGlobalData = NULL; fCloseClipboard = FALSE; CloseClipboard (); /* Clean up */ XFree (xtpText.value); xtpText.value = NULL; xtpText.nitems = 0; /* Setup selection notify event */ eventSelection.type = SelectionNotify; eventSelection.send_event = True; eventSelection.display = pDisplay; eventSelection.requestor = event.xselectionrequest.requestor; eventSelection.selection = event.xselectionrequest.selection; eventSelection.target = event.xselectionrequest.target; eventSelection.property = event.xselectionrequest.property; eventSelection.time = event.xselectionrequest.time; /* Notify the requesting window that the operation has completed */ iReturn = XSendEvent (pDisplay, eventSelection.requestor, False, 0L, (XEvent *) &eventSelection); if (iReturn == BadValue || iReturn == BadWindow) { ErrorF ("winClipboardFlushXEvents - SelectionRequest - " "XSendEvent () failed\n"); /* Abort */ fAbort = TRUE; goto winClipboardFlushXEvents_SelectionRequest_Done; } winClipboardFlushXEvents_SelectionRequest_Done: /* Free allocated resources */ if (xtpText.value) { XFree (xtpText.value); xtpText.value = NULL; xtpText.nitems = 0; } free(pszConvertData); if (hGlobal && pszGlobalData) GlobalUnlock (hGlobal); /* * Send a SelectionNotify event to the requesting * client when we abort. */ if (fAbort) { /* Setup selection notify event */ eventSelection.type = SelectionNotify; eventSelection.send_event = True; eventSelection.display = pDisplay; eventSelection.requestor = event.xselectionrequest.requestor; eventSelection.selection = event.xselectionrequest.selection; eventSelection.target = event.xselectionrequest.target; eventSelection.property = None; eventSelection.time = event.xselectionrequest.time; /* Notify the requesting window that the operation is complete */ iReturn = XSendEvent (pDisplay, eventSelection.requestor, False, 0L, (XEvent *) &eventSelection); if (iReturn == BadValue || iReturn == BadWindow) { /* * Should not be a problem if XSendEvent fails because * the client may simply have exited. */ ErrorF ("winClipboardFlushXEvents - SelectionRequest - " "XSendEvent () failed for abort event.\n"); } } /* Close clipboard if it was opened */ if (fCloseClipboard) { fCloseClipboard = FALSE; CloseClipboard (); } break; /* * SelectionNotify */ case SelectionNotify: winDebug ("winClipboardFlushXEvents - SelectionNotify\n"); { char *pszAtomName; pszAtomName = XGetAtomName (pDisplay, event.xselection.selection); winDebug("winClipboardFlushXEvents - SelectionNotify - ATOM: %s\n", pszAtomName); XFree (pszAtomName); } /* * Request conversion of UTF8 and CompoundText targets. */ if (event.xselection.property == None) { if (event.xselection.target == XA_STRING) { winDebug ("winClipboardFlushXEvents - SelectionNotify - " "XA_STRING\n"); return WIN_XEVENTS_CONVERT; } else if (event.xselection.target == atomUTF8String) { winDebug("winClipboardFlushXEvents - SelectionNotify - " "Requesting conversion of UTF8 target.\n"); XConvertSelection (pDisplay, event.xselection.selection, XA_STRING, atomLocalProperty, iWindow, CurrentTime); /* Process the ConvertSelection event */ XFlush (pDisplay); return WIN_XEVENTS_CONVERT; } #ifdef X_HAVE_UTF8_STRING else if (event.xselection.target == atomCompoundText) { winDebug("winClipboardFlushXEvents - SelectionNotify - " "Requesting conversion of CompoundText target.\n"); XConvertSelection (pDisplay, event.xselection.selection, atomUTF8String, atomLocalProperty, iWindow, CurrentTime); /* Process the ConvertSelection event */ XFlush (pDisplay); return WIN_XEVENTS_CONVERT; } #endif else { ErrorF ("winClipboardFlushXEvents - SelectionNotify - " "Unknown format. Cannot request conversion, " "aborting.\n"); break; } } /* Retrieve the size of the stored data */ iReturn = XGetWindowProperty (pDisplay, iWindow, atomLocalProperty, 0, 0, /* Don't get data, just size */ False, AnyPropertyType, &xtpText.encoding, &xtpText.format, &xtpText.nitems, &ulReturnBytesLeft, &xtpText.value); if (iReturn != Success) { ErrorF ("winClipboardFlushXEvents - SelectionNotify - " "XGetWindowProperty () failed, aborting: %d\n", iReturn); break; } winDebug("SelectionNotify - returned data %d left %d\n", xtpText.nitems, ulReturnBytesLeft); /* Request the selection data */ iReturn = XGetWindowProperty (pDisplay, iWindow, atomLocalProperty, 0, ulReturnBytesLeft, False, AnyPropertyType, &xtpText.encoding, &xtpText.format, &xtpText.nitems, &ulReturnBytesLeft, &xtpText.value); if (iReturn != Success) { ErrorF ("winClipboardFlushXEvents - SelectionNotify - " "XGetWindowProperty () failed, aborting: %d\n", iReturn); break; } { char *pszAtomName = NULL; winDebug("SelectionNotify - returned data %d left %d\n", xtpText.nitems, ulReturnBytesLeft); pszAtomName = XGetAtomName(pDisplay, xtpText.encoding); winDebug("Notify atom name %s\n", pszAtomName); XFree (pszAtomName); pszAtomName = NULL; } if (fUseUnicode) { #ifdef X_HAVE_UTF8_STRING /* Convert the text property to a text list */ iReturn = Xutf8TextPropertyToTextList (pDisplay, &xtpText, &ppszTextList, &iCount); #endif } else { iReturn = XmbTextPropertyToTextList (pDisplay, &xtpText, &ppszTextList, &iCount); } if (iReturn == Success || iReturn > 0) { /* Conversion succeeded or some unconvertible characters */ if (ppszTextList != NULL) { iReturnDataLen = 0; for (i = 0; i < iCount; i++) { iReturnDataLen += strlen(ppszTextList[i]); } pszReturnData = malloc (iReturnDataLen + 1); pszReturnData[0] = '\0'; for (i = 0; i < iCount; i++) { strcat (pszReturnData, ppszTextList[i]); } } else { ErrorF ("winClipboardFlushXEvents - SelectionNotify - " "X*TextPropertyToTextList list_return is NULL.\n"); pszReturnData = malloc (1); pszReturnData[0] = '\0'; } } else { ErrorF ("winClipboardFlushXEvents - SelectionNotify - " "X*TextPropertyToTextList returned: "); switch (iReturn) { case XNoMemory: ErrorF ("XNoMemory\n"); break; case XConverterNotFound: ErrorF ("XConverterNotFound\n"); break; default: ErrorF ("%d", iReturn); break; } pszReturnData = malloc (1); pszReturnData[0] = '\0'; } /* Free the data returned from XGetWindowProperty */ if (ppszTextList) XFreeStringList (ppszTextList); ppszTextList = NULL; XFree (xtpText.value); xtpText.value = NULL; xtpText.nitems = 0; /* Convert the X clipboard string to DOS format */ winClipboardUNIXtoDOS (&pszReturnData, strlen (pszReturnData)); if (fUseUnicode) { /* Find out how much space needed to convert MBCS to Unicode */ iUnicodeLen = MultiByteToWideChar (CP_UTF8, 0, pszReturnData, -1, NULL, 0); /* Allocate memory for the Unicode string */ pwszUnicodeStr = (wchar_t*) malloc (sizeof (wchar_t) * (iUnicodeLen + 1)); if (!pwszUnicodeStr) { ErrorF ("winClipboardFlushXEvents - SelectionNotify " "malloc failed for pwszUnicodeStr, aborting.\n"); /* Abort */ fAbort = TRUE; goto winClipboardFlushXEvents_SelectionNotify_Done; } /* Do the actual conversion */ MultiByteToWideChar (CP_UTF8, 0, pszReturnData, -1, pwszUnicodeStr, iUnicodeLen); /* Allocate global memory for the X clipboard data */ hGlobal = GlobalAlloc (GMEM_MOVEABLE, sizeof (wchar_t) * (iUnicodeLen + 1)); } else { pszConvertData = strdup (pszReturnData); iConvertDataLen = strlen (pszConvertData) + 1; /* Allocate global memory for the X clipboard data */ hGlobal = GlobalAlloc (GMEM_MOVEABLE, iConvertDataLen); } free (pszReturnData); /* Check that global memory was allocated */ if (!hGlobal) { ErrorF ("winClipboardFlushXEvents - SelectionNotify " "GlobalAlloc failed, aborting: %ld\n", GetLastError ()); /* Abort */ fAbort = TRUE; goto winClipboardFlushXEvents_SelectionNotify_Done; } /* Obtain a pointer to the global memory */ pszGlobalData = GlobalLock (hGlobal); if (pszGlobalData == NULL) { ErrorF ("winClipboardFlushXEvents - Could not lock global " "memory for clipboard transfer\n"); /* Abort */ fAbort = TRUE; goto winClipboardFlushXEvents_SelectionNotify_Done; } /* Copy the returned string into the global memory */ if (fUseUnicode) { memcpy (pszGlobalData, pwszUnicodeStr, sizeof (wchar_t) * (iUnicodeLen + 1)); free (pwszUnicodeStr); pwszUnicodeStr = NULL; } else { strcpy (pszGlobalData, pszConvertData); free (pszConvertData); pszConvertData = NULL; } /* Release the pointer to the global memory */ GlobalUnlock (hGlobal); pszGlobalData = NULL; /* Push the selection data to the Windows clipboard */ if (fUseUnicode) SetClipboardData (CF_UNICODETEXT, hGlobal); else SetClipboardData (CF_TEXT, hGlobal); /* Flag that SetClipboardData has been called */ fSetClipboardData = FALSE; /* * NOTE: Do not try to free pszGlobalData, it is owned by * Windows after the call to SetClipboardData (). */ winClipboardFlushXEvents_SelectionNotify_Done: /* Free allocated resources */ if (ppszTextList) XFreeStringList (ppszTextList); if (xtpText.value) { XFree (xtpText.value); xtpText.value = NULL; xtpText.nitems = 0; } free(pszConvertData); free(pwszUnicodeStr); if (hGlobal && pszGlobalData) GlobalUnlock (hGlobal); if (fSetClipboardData && g_fUnicodeSupport) SetClipboardData (CF_UNICODETEXT, NULL); if (fSetClipboardData) SetClipboardData (CF_TEXT, NULL); return WIN_XEVENTS_NOTIFY; case SelectionClear: winDebug("SelectionClear - doing nothing\n"); break; case PropertyNotify: break; case MappingNotify: break; default: ErrorF ("winClipboardFlushXEvents - unexpected event type %d\n", event.type); break; } } return WIN_XEVENTS_SUCCESS; }
void xskin_start_interface( int pipe_in ) { int xskin_sc; XEvent xskin_e; XSetWindowAttributes xskin_attr; XSizeHints xskin_hint; XClassHint xskin_chint; XTextProperty ct; char *namlist[2]; /* setup window */ xskin_d = XOpenDisplay( NULL ); xskin_sc = DefaultScreen( xskin_d ); xskin_r = RootWindow( xskin_d, xskin_sc ); xskin_gc = DefaultGC( xskin_d, xskin_sc ); xskin_vis = DefaultVisual( xskin_d, xskin_sc ); xskin_depth = DefaultDepth( xskin_d, xskin_sc ); xskin_w = XCreateSimpleWindow( xskin_d, xskin_r, 0, 0, skin_width, skin_height, 0, WhitePixel( xskin_d, xskin_sc ), BlackPixel( xskin_d, xskin_sc ) ); xskin_attr.backing_store = True; xskin_attr.override_redirect = False; XChangeWindowAttributes( xskin_d, xskin_w, CWBackingStore|CWOverrideRedirect, &xskin_attr ); XSelectInput( xskin_d, xskin_w, KeyPressMask|ExposureMask| EnterWindowMask|LeaveWindowMask| ButtonPressMask|ButtonReleaseMask| Button1MotionMask ); xskin_hint.flags = USSize | PMinSize | PMaxSize | USPosition; xskin_hint.width = xskin_hint.min_width = xskin_hint.max_width = skin_width; xskin_hint.height = xskin_hint.min_height = xskin_hint.max_height = skin_height; XSetNormalHints( xskin_d, xskin_w, &xskin_hint ); xskin_chint.res_name = XSKIN_RES_NAME; xskin_chint.res_class = XSKIN_RES_CLASS; XSetClassHint( xskin_d, xskin_w, &xskin_chint ); namlist[0]=(char *)safe_malloc(strlen(XSKIN_WINDOW_NAME)+1); strcpy( namlist[0], XSKIN_WINDOW_NAME ); XmbTextListToTextProperty( xskin_d, namlist, 1, XCompoundTextStyle, &ct ); XSetWMName( xskin_d, xskin_w, &ct ); XSetWMIconName( xskin_d, xskin_w, &ct ); free(namlist[0]); /* setup pixmaps */ if ( load_skins()!=0 ) goto finish; XSetWindowBackgroundPixmap( xskin_d, xskin_w, xskin_back ); XClearWindow( xskin_d, xskin_w ); XMapWindow( xskin_d, xskin_w ); while( 1 ) { XNextEvent( xskin_d, &xskin_e ); if ( xskin_e.type == Expose ) break; } fshuf=0; frep=0; fequ=1; fpll=1; fplay=0; fpause=0; fremain=0; play_val=1; vol_val=50; last_current_time=0; total_time=0; speana_buf = NULL; strcpy( last_text, "welcome to timidity" ); install_sighandler(); repaint(); ts_spectrum( -1, speana_buf ); XFlush(xskin_d); xskin_jobs( pipe_in ); /* tskin main jobs */ finish: signal_vector(0); /* finish */ }
int Pane::Initialise( ) { m_pDisplay = XOpenDisplay( "" ); if( !m_pDisplay ) { std::cout << "Failed to open display" << std::endl; return 0; } int VisualAttributes[ ] = { GLX_X_RENDERABLE, True, GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, GLX_RENDER_TYPE, GLX_RGBA_BIT, GLX_X_VISUAL_TYPE, GLX_TRUE_COLOR, GLX_RED_SIZE, 8, GLX_GREEN_SIZE, 8, GLX_BLUE_SIZE, 8, GLX_ALPHA_SIZE, 8, GLX_DEPTH_SIZE, 24, GLX_STENCIL_SIZE, 8, GLX_DOUBLEBUFFER, True, None }; int GLXMajor = 0, GLXMinor = 0; if( !glXQueryVersion( m_pDisplay, &GLXMajor, &GLXMinor ) ) { std::cout << "Failed to query GLX version" << std::endl; return 0; } int FBCount = 0; GLXFBConfig *pFBC = glXChooseFBConfig( m_pDisplay, DefaultScreen( m_pDisplay ), VisualAttributes, &FBCount ); GLXFBConfig FBConfig = pFBC[ 0 ]; XFree( pFBC ); pFBC = NULL; m_pVisualInfo = glXGetVisualFromFBConfig( m_pDisplay, FBConfig ); XSetWindowAttributes WindowAttributes; WindowAttributes.colormap = XCreateColormap( m_pDisplay, RootWindow( m_pDisplay, m_pVisualInfo->screen ), m_pVisualInfo->visual, AllocNone ); WindowAttributes.border_pixel = 0; WindowAttributes.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask | KeyReleaseMask | PointerMotionMask | FocusChangeMask | EnterWindowMask | LeaveWindowMask| ButtonPressMask | ButtonReleaseMask; m_Window = XCreateWindow( m_pDisplay, RootWindow( m_pDisplay, m_pVisualInfo->screen ), 0, 0, 800, 600, 0, m_pVisualInfo->depth, InputOutput, m_pVisualInfo->visual, CWEventMask | CWColormap | CWBorderPixel, &WindowAttributes ); XMapWindow( m_pDisplay, m_Window ); XMapRaised( m_pDisplay, m_Window ); XMoveWindow( m_pDisplay, m_Window, 0, 0 ); XRaiseWindow( m_pDisplay, m_Window ); m_GLXContext = glXCreateContext( m_pDisplay, m_pVisualInfo, 0, True ); glXMakeCurrent( m_pDisplay, m_Window, m_GLXContext ); char *pGLVersion = ( char * )glGetString( GL_VERSION ); char *pTokenVersion = strtok( pGLVersion, ". " ); for( int i = 0; i < 2; ++i ) { m_GLVersion[ i ] = atoi( pTokenVersion ); pTokenVersion = strtok( NULL, ". " ); } std::cout << "OpenGL version: " << m_GLVersion[ 0 ] << "." << m_GLVersion[ 1 ] << std::endl; if( ( m_GLVersion[ 0 ] < 1 ) || ( ( m_GLVersion[ 0 ] == 1 ) && ( m_GLVersion[ 1 ] < 1 ) ) ) { std::cout << "Failed to create an OpenGL 1.1 context" << std::endl; return 0; } XTextProperty Text; char *pList = new char[ 1024 ]; memset( pList, '\0', 1024*sizeof( char ) ); strcat( pList, "MULE | Client" ); #if defined MULE_BUILD_DEBUG strcat( pList, " [DEBUG] " ); #elif defined MULE_BUILD_PROFILE strcat( pList, " [PROFILE] " ); #endif #if defined MULE_BUILD_DEBUG || MULE_BUILD_PROFILE strcat( pList, GIT_COMMITHASH ); #endif XmbTextListToTextProperty( m_pDisplay, &pList, 1, XStringStyle, &Text ); delete [ ] pList; pList = NULL; XSetWMName( m_pDisplay, m_Window, &Text ); /* XEvent Event; Atom State = XInternAtom( m_pDisplay, "_NET_WM_STATE", False ); Atom MaxHorz = XInternAtom( m_pDisplay, "_NET_WM_STATE_MAXIMIZED_HORZ", False ); Atom MaxVert = XInternAtom( m_pDisplay, "_NET_WM_STATE_MAXIMIZED_VERT", False ); memset( &Event, 0, sizeof( Event ) ); Event.type = ClientMessage; Event.xclient.window = m_Window; Event.xclient.message_type = State; Event.xclient.format = 32; Event.xclient.data.l[ 0 ] = 1; //_NET_WM_STATE_ADD; Event.xclient.data.l[ 1 ] = MaxHorz; Event.xclient.data.l[ 2 ] = MaxVert; XSendEvent( m_pDisplay, DefaultRootWindow( m_pDisplay ), False, SubstructureNotifyMask, &Event );*/ if( InitGLExtensions( m_GLVersion[ 0 ], m_GLVersion [ 1 ] ) ) { std::cout << "Failed to initialise GL extensions" << std::endl; return 0; } glClearColor( 1.0f, 0.0f, 1.0f, 1.0f ); glEnable( GL_TEXTURE_2D ); m_pElements = new RemoteDisplayElement[ 1 ]; m_pElements[ 0 ].Dimensions( 800, 600 ); m_pElements[ 0 ].Initialise( ); return 1; }