static String SelectSwap(Widget w, String s) { GwinWidget gw; String ans; gw = (GwinWidget)w; if(gw->gwin.selection){ XtFree(gw->gwin.selection); gw->gwin.selection = 0; } #ifdef R3 XtGetSelectionValue(w, XA_PRIMARY, XA_STRING, SelCallback, 0, CurrentTime); #else XtGetSelectionValue(w, XA_PRIMARY, XA_STRING, SelCallback, 0, XtLastTimestampProcessed(XtDisplay(w))); #endif while(gw->gwin.selection == 0) XtAppProcessEvent(XtWidgetToApplicationContext(w) , XtIMAll); ans = gw->gwin.selection; gw->gwin.selection = XtMalloc(strlen(s)+1); strcpy(gw->gwin.selection, s); #ifdef R3 XtOwnSelection(w, XA_PRIMARY, CurrentTime, SendSel, NULL, NULL); #else XtOwnSelection(w, XA_PRIMARY, XtLastTimestampProcessed(XtDisplay(w)), SendSel, NULL, NULL); #endif return ans; }
static void terminate_transfer(Widget dt, Atom *select) { Atom how; DEBUGOUT(_LtDebug(__FILE__, dt, "%s:terminate_transfer(%d) - drag context %s receiver info %s %s\n", __FILE__, __LINE__, DT_DragContext(dt) ? "Yes" : "No", DC_CurrReceiverInfo(DT_DragContext(dt)) ? "Yes" : "No", XGetAtomName(XtDisplay(dt), *select) )); if (DT_TransferStatus(dt) == XmTRANSFER_SUCCESS) { how = XmInternAtom(XtDisplay(dt), _XA_XmTRANSFER_SUCCESS, False); } else { how = XmInternAtom(XtDisplay(dt), _XA_XmTRANSFER_FAILURE, False); } if (DT_DragContext(dt) && DC_CurrReceiverInfo(DT_DragContext(dt)) && DC_CurrReceiverInfo(DT_DragContext(dt))->shell) { XtGetSelectionValue(DC_CurrReceiverInfo(DT_DragContext(dt))->shell, *select, how, notified_callback, (XtPointer)dt, DT_Timestamp(dt)); } }
/* ** Getting the current selection by making the request, and then blocking ** (processing events) while waiting for a reply. On failure (timeout or ** bad format) returns NULL, otherwise returns the contents of the selection. */ char *GetAnySelection(WindowInfo *window) { static char waitingMarker[1] = ""; char *selText = waitingMarker; XEvent nextEvent; /* If the selection is in the window's own buffer get it from there, but substitute null characters as if it were an external selection */ if (window->buffer->primary.selected) { selText = BufGetSelectionText(window->buffer); BufUnsubstituteNullChars(selText, window->buffer); return selText; } /* Request the selection value to be delivered to getAnySelectionCB */ XtGetSelectionValue(window->textArea, XA_PRIMARY, XA_STRING, (XtSelectionCallbackProc)getAnySelectionCB, &selText, XtLastTimestampProcessed(XtDisplay(window->textArea))); /* Wait for the value to appear */ while (selText == waitingMarker) { XtAppNextEvent(XtWidgetToApplicationContext(window->textArea), &nextEvent); ServerDispatchEvent(&nextEvent); } return selText; }
static void LoseSelection(Widget w, Atom *selection) { Display *d = XtDisplay(w); XtGetSelectionValue(w, *selection, XA_UTF8_STRING(d), InsertClipboard, (XtPointer)(XA_UTF8_STRING(d)), CurrentTime); }
/* ARGSUSED */ static void GetSelection(Widget w, XtPointer closure, XtPointer callData) { XtGetSelectionValue(w, options.selection, XA_STRING, StoreBuffer, NULL, XtLastTimestampProcessed(XtDisplay(w))); }
/* Function Name: LoseSelection * Description: Called when we have lost the selection, asks client * for the selection value. * Arguments: w - the widget that just lost the selection. * sel - the selection. * Returns: none. */ static void LoseSelection(Widget w, Atom *sel) { if (global_client.timeout != 0) { XtRemoveTimeOut(global_client.timeout); global_client.timeout = 0; /* reset the countdown */ global_countdown = 0; if (global_timeout) { XtRemoveTimeOut(global_timeout); global_timeout = 0; SetWaitLabel(0); } /* if (old timeout running) */ } XtGetSelectionValue(w, *sel, atom_client_value, GetClientValue, NULL, XtLastTimestampProcessed(XtDisplay(w))); } /* LoseSelection() */
static String SelectSwap(Widget w, String s) { GwinWidget gw; String ans; gw = (GwinWidget)w; if(gw->gwin.selection){ XtFree(gw->gwin.selection); gw->gwin.selection = NULL; } XtGetSelectionValue(w, XInternAtom(_dpy, clipatom, 0), XInternAtom(_dpy, "UTF8_STRING", 0), SelCallback, 0, XtLastTimestampProcessed(XtDisplay(w))); while(gw->gwin.selection == NULL) XtAppProcessEvent(XtWidgetToApplicationContext(w) , XtIMAll); ans = gw->gwin.selection; gw->gwin.selection = XtMalloc(strlen(s)+1); strcpy(gw->gwin.selection, s); XtOwnSelection(w, XInternAtom(_dpy, clipatom, 0), XtLastTimestampProcessed(XtDisplay(w)), SendSel, NULL, NULL); return ans; }
static void GetSelectionTimeCallback(Widget w, XtPointer clientData, Atom* selection, Atom* type, XtPointer value, unsigned long* length, int* format) { if (value && *format == 32 && *length == 1) { Time t = *(CARD32 *)value; if (TIME_LATER(t, prevSelectionTime)) { prevSelectionTime = t; XtGetSelectionValue(w, XA_PRIMARY, XA_STRING, GetSelectionCallback, NULL, CurrentTime); } } else { if (TIME_LATER(cutBufferTime, prevSelectionTime)) { prevSelectionTime = cutBufferTime; SendCutBuffer(); } } if (value) XtFree(value); }
static void LoseSelection(Widget w, Atom *sel) { if (global_client.timeout != 0) { XtRemoveTimeOut(global_client.timeout); global_client.timeout = 0; } XtGetSelectionValue(w, *sel, atom_client_value, GetClientValue, NULL, XtLastTimestampProcessed(XtDisplay(w))); }
void SelectionToVNC(Widget w, XEvent *event, String *params, Cardinal *num_params) { Bool always = False; if (*num_params != 0) { if (strcmp(params[0],"always") == 0) { always = True; } else if (strcmp(params[0],"new") == 0) { always = False; } else { fprintf(stderr,"Invalid params: SelectionToVNC(always|new)\n"); return; } } if (always) { XtGetSelectionValue(w, XA_PRIMARY, XA_STRING, GetSelectionCallback, NULL, TimeFromEvent(event)); } else { XtGetSelectionValue(w, XA_PRIMARY, XInternAtom(dpy, "TIMESTAMP", False), GetSelectionTimeCallback, NULL, TimeFromEvent(event)); } }
void CopyMemoProc (Widget w, XEvent *event, String *prms, Cardinal *nprms) { if(appData.pasteSelection) return; if (selected_fen_position) free(selected_fen_position); XtGetSelectionValue(menuBarWidget, XA_PRIMARY, XA_STRING, /* (XtSelectionCallbackProc) */ MemoCB, NULL, /* client_data passed to PastePositionCB */ /* better to use the time field from the event that triggered the * call to this function, but that isn't trivial to get */ CurrentTime ); }
void InitialiseSelection() { #if XtSpecificationRelease >= 6 XtRegisterDrawable(dpy, DefaultRootWindow(dpy), toplevel); #else _XtRegisterWindow(DefaultRootWindow(dpy), toplevel); #endif XSelectInput(dpy, DefaultRootWindow(dpy), PropertyChangeMask); XtAddRawEventHandler(toplevel, PropertyChangeMask, False, CutBufferChange, NULL); XtGetSelectionValue(toplevel, XA_PRIMARY, XInternAtom(dpy, "TIMESTAMP", False), GetInitialSelectionTimeCallback, NULL, CurrentTime); }
int CoWowMotif::GetSelection( Widget w, char *str, int size, Atom atom) { wow_sSelection data; data.received = 0; data.atom = atom; XtGetSelectionValue( w, XA_PRIMARY, atom, wow_get_selection_cb, &data, CurrentTime); while( !data.received) { XEvent e; XtAppNextEvent( XtWidgetToApplicationContext(w), &e); XtDispatchEvent( &e); } if ( data.sts && data.len < size) strcpy( str, data.str); return data.sts; }
void ServiceMgr::get_olias_event (XEvent *event) { // Make sure it's the right event first. if (event->type != ClientMessage || event->xclient.message_type != _XA_OLIAS_EVENT) return; Atom selection = event->xclient.data.l[2]; Time time = event->xclient.data.l[3]; /* -------- Ask for the client the event from the client. -------- */ ON_DEBUG(puts ("OLIAS: Received a client display event!")); XtGetSelectionValue (window_system().toplevel(), selection, _XA_OLIAS_EVENT, (XtSelectionCallbackProc) receive_olias_event, this, time); }
void BWRequestSelection(Widget w, Time btime, Boolean wait) { BitmapWidget BW = (BitmapWidget) w; if (BW->bitmap.selection.own) BWStore(w); else { XtGetSelectionValue(w, XA_PRIMARY, XA_PIXMAP, SelectionCallback, NULL, btime); BW->bitmap.selection.limbo = TRUE; if (wait) while (BW->bitmap.selection.limbo) { XEvent event; XtNextEvent(&event); XtDispatchEvent(&event); } } }
void GotoSelectedLineNumber(WindowInfo *window, Time time) { XtGetSelectionValue(window->textArea, XA_PRIMARY, XA_STRING, (XtSelectionCallbackProc)gotoCB, window, time); }
void SWRequestSelection(Widget w, Time time) { XtGetSelectionValue(w, XA_PRIMARY, XA_PIXMAP, SelectionCallback, NULL, time); }
XtEnum XmPrintPopupPDM(Widget print_shell, Widget transient_for_video_shell) { Atom pdm_selection; Atom type; unsigned char * value; int length; int format; Atom PDM_START ; Display * display_used ; PDMSelectData * pdm_select_data ; Widget widget_for_selection ; XtAppContext app; unsigned long old_timeout; /* get parameter for PDM_START from libXp ask conversion using XtSetSelectionParameters, and then call XtGetSelectionValue, which registers a XtSelectionCallbackProc that will wait for failure (no pdm owner, or timeout) or success. Phase 2 of the pdm (clientmessage) will be handled by a event handler set up from the selection callback on success */ if (!XpGetPdmStartParams (XtDisplay(print_shell), XtWindow(print_shell), XpGetContext(XtDisplay(print_shell)), XtDisplay(transient_for_video_shell), XtWindow(transient_for_video_shell), &display_used, &pdm_selection, &type, &format, &value, &length)) return XmPDM_NOTIFY_FAIL; /* only support XPDMDISPLAY = "print" or "video" */ if (display_used == XtDisplay(print_shell)) widget_for_selection = print_shell ; else if (display_used == XtDisplay(transient_for_video_shell)) widget_for_selection = transient_for_video_shell ; else return XmPDM_NOTIFY_FAIL ; XtSetSelectionParameters(widget_for_selection, pdm_selection, type, (XtPointer)value, length, format); XFree(value); pdm_select_data = (PDMSelectData *) XtMalloc(sizeof(PDMSelectData)); pdm_select_data->pdm_selection = pdm_selection ; pdm_select_data->transient_for_video_shell = transient_for_video_shell ; pdm_select_data->print_shell = (XmPrintShellWidget) print_shell ; /* need this one in all cases */ PDM_START = XInternAtom(XtDisplay(widget_for_selection), XmIPDM_START, False); app = XtWidgetToApplicationContext(widget_for_selection); /* twenty minutes */ #define REALLY_LONG_TIMEOUT (2 * 60 * 1000) _XmAppLock(app); old_timeout = XtAppGetSelectionTimeout(app); XtAppSetSelectionTimeout(app, REALLY_LONG_TIMEOUT); XtGetSelectionValue(widget_for_selection, pdm_selection, PDM_START, PDMSelectionProc, (XtPointer)pdm_select_data, XtLastTimestampProcessed( XtDisplay(widget_for_selection))); XtAppSetSelectionTimeout(app, old_timeout); _XmAppUnlock(app); /* put up a InputOnly window on top of the dialog, so that the end-user cannot muck around with the print setup dialog hile the PDM is trying to come up. This is removed in PDMSelectionProc */ pdm_select_data->transient_for_input_only_window = XCreateWindow(XtDisplay(transient_for_video_shell), XtWindow(transient_for_video_shell), 0, 0, XtWidth(transient_for_video_shell), XtHeight(transient_for_video_shell), 0, CopyFromParent, InputOnly, CopyFromParent, 0, NULL); XMapRaised(XtDisplay(transient_for_video_shell), pdm_select_data->transient_for_input_only_window); return XmPDM_NOTIFY_SUCCESS ; }
/*ARGSUSED*/ static void InsertClipboard(Widget w, XtPointer client_data, Atom *selection, Atom *type, XtPointer value, unsigned long *length, int *format) { Display *d = XtDisplay(w); Atom target = (Atom)client_data; Boolean convert_failed = (*type == XT_CONVERT_FAIL); if (!convert_failed) { char **list; int i, ret, count; XTextProperty prop; prop.value = value; prop.nitems = *length; prop.format = *format; prop.encoding = *type; ret = XmbTextPropertyToTextList(d, &prop, &list, &count); if (ret >= Success) { /* manuals say something about multiple strings in a disjoint text selection (?), it should be harmless to get them all */ for (i = 0; i < count; i++) NewCurrentClipContents(list[i], strlen(list[i])); XFreeStringList(list); } else convert_failed = True; XFree(value); } if (convert_failed) { /* if UTF8_STRING failed try COMPOUND_TEXT */ if (target == XA_UTF8_STRING(d)) { XtGetSelectionValue(w, *selection, XA_COMPOUND_TEXT(d), InsertClipboard, (XtPointer)(XA_COMPOUND_TEXT(d)), CurrentTime); return; } /* if COMPOUND_TEXT failed try STRING */ else if (target == XA_COMPOUND_TEXT(d)) { XtGetSelectionValue(w, *selection, XA_STRING, InsertClipboard, NULL, CurrentTime); return; } /* all conversions failed */ else { Arg arg; XtSetArg (arg, XtNlabel, "CLIPBOARD selection conversion failed"); XtSetValues (failDialog, &arg, 1); CenterWidgetOnWidget (failDialogShell, text); XtPopup (failDialogShell, XtGrabNone); #ifdef XKB XkbStdBell (d, XtWindow(w), 0, XkbBI_MinorError); #else XBell (d, 0); #endif } } XtOwnSelection(top, ClipboardAtom, CurrentTime, ConvertSelection, LoseSelection, NULL); }
int main(int argc, char *argv[]) { Arg arglist[10]; Cardinal num_args; #ifdef USE_PRIVSEP struct passwd *pw; #endif XtSetLanguageProc(NULL,NULL,NULL); top = XtInitialize ("xconsole", "XConsole", options, XtNumber (options), &argc, argv); XtGetApplicationResources (top, (XtPointer)&app_resources, resources, XtNumber (resources), NULL, 0); #ifdef USE_PRIVSEP /* Revoke privileges if any */ if (getuid() == 0) { /* Running as root */ pw = getpwnam(XCONSOLE_USER); if (!pw) { fprintf(stderr, "%s user not found\n", XCONSOLE_USER); exit(2); } if (priv_init(pw->pw_uid, pw->pw_gid) < 0) { fprintf(stderr, "priv_init failed\n"); exit(2); } } else if (priv_init(-1, -1) < 0) { fprintf(stderr, "priv_init failed\n"); exit(2); } #endif if (app_resources.daemon) if (fork ()) exit (0); XtAddActions (actions, XtNumber (actions)); text = XtCreateManagedWidget ("text", asciiTextWidgetClass, top, NULL, 0); XtRealizeWidget (top); num_args = 0; XtSetArg(arglist[num_args], XtNiconic, &iconified); num_args++; XtGetValues(top, arglist, num_args); if (iconified) Iconified((Widget)NULL, (XEvent*)NULL, (String*)NULL, (Cardinal*)NULL); else Deiconified((Widget)NULL,(XEvent*)NULL,(String*)NULL,(Cardinal*)NULL); wm_delete_window = XInternAtom(XtDisplay(top), "WM_DELETE_WINDOW", False); (void) XSetWMProtocols (XtDisplay(top), XtWindow(top), &wm_delete_window, 1); XmuGetHostname (mit_console_name + MIT_CONSOLE_LEN, 255); mit_console = XInternAtom(XtDisplay(top), mit_console_name, False); if (XGetSelectionOwner (XtDisplay (top), mit_console)) { XtGetSelectionValue(top, mit_console, XA_STRING, InsertSelection, NULL, CurrentTime); } else { XtOwnSelection(top, mit_console, CurrentTime, ConvertSelection, LoseSelection, NULL); OpenConsole (); } #ifdef USE_OSM ioerror = XSetIOErrorHandler(IOError); #endif #ifdef USE_PRIVSEP if (pledge("stdio rpath sendfd recvfd", NULL) == -1) err(1, "pledge"); #endif XtMainLoop (); return 0; }
void OpenSelectedFile(WindowInfo *window, Time time) { XtGetSelectionValue(window->textArea, XA_PRIMARY, XA_STRING, (XtSelectionCallbackProc)fileCB, window, time); }