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 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; }
void SelectionFromVNC(Widget w, XEvent *event, String *params, Cardinal *num_params) { Bool always = False; Time t = TimeFromEvent(event); 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: SelectionFromVNC(always|new)\n"); return; } } if (t == CurrentTime) { fprintf(stderr,"Error in translations: SelectionFromVNC() must act on " "event with time field\n"); return; } if (!serverCutText || (!always && !newServerCutText)) return; newServerCutText = False; XStoreBytes(dpy, serverCutText, strlen(serverCutText)); if (XtOwnSelection(desktop, XA_PRIMARY, t, ConvertSelection, LoseSelection, NULL)) { iAmSelectionOwner = True; } }
/*ARGSUSED*/ static void InsertSelection(Widget w, XtPointer client_data, Atom *selection, Atom *type, XtPointer value, unsigned long *length, int *format) { if (*type != XT_CONVERT_FAIL) TextInsert (text, (char *) value, *length); XtOwnSelection(top, mit_console, CurrentTime, ConvertSelection, LoseSelection, NULL); OpenConsole (); }
void BWGrabSelection(Widget w, Time btime) { BitmapWidget BW = (BitmapWidget) w; BW->bitmap.selection.own = XtOwnSelection(w, XA_PRIMARY, btime, ConvertSelection, (XtLoseSelectionProc)LoseSelection, SelectionDone); if (DEBUG && BW->bitmap.selection.own) fprintf(stderr, "Own the selection\n"); }
static void MemoCB(Widget w, XtPointer client_data, Atom *selection, Atom *type, XtPointer value, unsigned long *len, int *format) { if (value==NULL || *len==0) return; /* nothing had been selected to copy */ selected_fen_position = value; selected_fen_position[*len]='\0'; /* normally this string is terminated, but be safe */ XtOwnSelection(menuBarWidget, XA_CLIPBOARD(xDisplay), CurrentTime, SendPositionSelection, NULL/* lose_ownership_proc */ , NULL/* transfer_done_proc */); }
/* ARGSUSED */ static void GetBuffer(Widget w, XtPointer closure, XtPointer callData) { if (options.value) XFree( options.value ); options.value = XFetchBuffer(XtDisplay(w), &options.length, options.buffer); if (options.value != NULL) { if (XtOwnSelection(w, options.selection, XtLastTimestampProcessed(XtDisplay(w)), ConvertSelection, LoseSelection, NULL)) SetButton((ButtonState*)closure, True); } }
void PalMotif::set_selection_owner() { int sts; sts = XtOwnSelection( brow_widget, XA_PRIMARY, XtLastTimestampProcessed(flow_Display(brow_widget)), pal_sel_convert_cb, pal_sel_lose_cb , NULL); if ( !sts) { brow_SelectClear( brow_ctx); return; } selection_owner = 1; }
void WNavMotif::set_selection_owner() { int sts; sts = XtOwnSelection( brow_widget, XA_PRIMARY, XtLastTimestampProcessed(flow_Display(brow_widget)), WNavMotif::sel_convert_cb, WNavMotif::sel_lose_cb , NULL); if ( !sts) { message('E', "Failed attempting to become primary selection owner"); brow_SelectClear( brow->ctx); return; } selection_owner = 1; }
void NavMotif::set_selection_owner( int set) { int sts; if ( set) { sts = XtOwnSelection( brow_widget, XA_PRIMARY, XtLastTimestampProcessed(flow_Display(brow_widget)), nav_sel_convert_cb, nav_sel_lose_cb , NULL); if ( !sts) { brow_SelectClear( brow_ctx); return; } } else { // Todo... } }
/*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); }
/* ARGSUSED */ static void GetClientValue(Widget w, XtPointer data, Atom *selection, Atom *type, XtPointer value, unsigned long *length, int *format) { Event *event; ProtocolStream alloc_stream; ProtocolStream *stream; unsigned char ident; unsigned char error_code; char *error_str; char msg[BUFSIZ]; /* type should be checked if XT_CONVERT_FAIL */ if (*length == 0) { return; } stream = &alloc_stream; /* easier to think of it this way... */ stream->current = stream->top = (unsigned char*)value; stream->size = HEADER_SIZE; /* size of header. */ /* * Retrieve the Header. */ if (*length < HEADER_SIZE) { /* "Incorrectly formatted message from client" */ SetMessage(global_screen_data.info_label, res_labels[9], "Incorrectly formatted message from client"); return; } (void)_XEditResGet8(stream, &ident); if (global_client.ident != ident) { #ifdef DEBUG if (global_resources.debug) { printf("Incorrect ident from client.\n"); } #endif /* DEBUG */ if (!XtOwnSelection(w, *selection, CurrentTime, ConvertCommand, LoseSelection, SelectionDone)) { /* "Unable to own the Resource Editor Command Selection" */ SetMessage(global_screen_data.info_label, res_labels[10], "Unable to own the Resource Editor Command Selection"); } return; } /* if (global_client.ident != ident) */ (void)_XEditResGet8(stream, &error_code); (void)_XEditResGet32(stream, &(stream->size)); stream->top = stream->current; /* reset stream to top of value.*/ switch ((int)error_code) { case PartialSuccess: /***** if (global_client.command == LocalSendWidgetTree && global_effective_protocol_version < CURRENT_PROTOCOL_VERSION) { ++global_effective_protocol_version; } *****/ if ((event = BuildEvent(stream)) != NULL) { error_str = DispatchEvent(event); FreeEvent(event); } else { sprintf(msg, "Unable to unpack protocol request."); error_str = XtNewString(msg); } break; /* PartialSuccess */ case Failure: error_str = GetFailureMessage(stream); break; /* Failure */ case ProtocolMismatch: error_str = ProtocolFailure(stream); --global_effective_protocol_version; /* normaly protocol version is reset to current during a SendWidgetTree * request, however, after a protocol failure this is skiped once for * a retry. */ reset_protocol_level = False; SetCommand(w, LocalSendWidgetTree, NULL); break; /* ProtocolMismatch */ default: /* "Unknown Error code %s" */ if (res_labels[11]) { sprintf(msg, res_labels[11], (int)error_code); } else { sprintf(msg, "Unknown Error code %i", (int)error_code); } SetMessage(global_screen_data.info_label, msg, "?res_labels[11]"); break; /* default */ } /* switch (error_code) */ if (error_str == NULL) { WNode *top; if (global_tree_info == NULL) { return; } top = global_tree_info->top_node; /* "Widget/Style tree for client %s (%s)" */ if (res_labels[12]) { sprintf(msg, res_labels[12], top->name, top->class); } else {
/* ARGSUSED */ static void GetClientValue(Widget w, XtPointer data, Atom *selection, Atom *type, XtPointer value, unsigned long *length, int *format) { Event * event; ProtocolStream alloc_stream, *stream; unsigned char ident, error_code; char * error_str = NULL, msg[BUFSIZ]; if (*length == 0) return; stream = &alloc_stream; /* easier to think of it this way... */ stream->current = stream->top = (unsigned char *) value; stream->size = HEADER_SIZE; /* size of header. */ /* * Retrieve the Header. */ if (*length < HEADER_SIZE) { SetMessage(global_screen_data.info_label, res_labels[9]); return; } (void) _XEditResGet8(stream, &ident); if (global_client.ident != ident) { #ifdef DEBUG if (global_resources.debug) printf("Incorrect ident from client.\n"); #endif if (!XtOwnSelection(w, *selection, CurrentTime, ConvertCommand, LoseSelection, SelectionDone)) SetMessage(global_screen_data.info_label, res_labels[10]); return; } (void) _XEditResGet8(stream, &error_code); (void) _XEditResGet32(stream, &(stream->size)); stream->top = stream->current; /* reset stream to top of value.*/ switch ((int) error_code) { case PartialSuccess: /***** if (global_client.command == LocalSendWidgetTree && global_effective_protocol_version < CURRENT_PROTOCOL_VERSION) ++global_effective_protocol_version; *****/ if ((event = BuildEvent(stream)) != NULL) { error_str = DispatchEvent(event); FreeEvent(event); } else { sprintf(msg, "Unable to unpack protocol request."); error_str = XtNewString(msg); } break; case Failure: error_str = GetFailureMessage(stream); break; case ProtocolMismatch: error_str = ProtocolFailure(stream); --global_effective_protocol_version; /* normaly protocol version is reset to current during a SendWidgetTree * request, however, after a protocol failure this is skiped once for * a retry. */ reset_protocol_level = False; SetCommand(w, LocalSendWidgetTree, NULL); break; default: sprintf(msg, res_labels[11], (int) error_code); SetMessage(global_screen_data.info_label, msg); break; } if (error_str == NULL) { WNode * top; if (global_tree_info == NULL) return; top = global_tree_info->top_node; sprintf(msg, res_labels[12], top->name, top->class); SetMessage(global_screen_data.info_label, msg); return; }
void SWGrabSelection(Widget w, Time time) { (void) XtOwnSelection(w, XA_PRIMARY, time, ConvertSelection, NULL, NULL); }
int main(int argc, char *argv[]) { Arg args[4]; Cardinal n; XtAppContext xtcontext; Widget parent; XtSetLanguageProc(NULL, NULL, NULL); top = XtAppInitialize( &xtcontext, "XClipboard", table, XtNumber(table), &argc, argv, fallback_resources, NULL, 0); XtGetApplicationResources(top, (XtPointer)&userOptions, resources, XtNumber(resources), NULL, 0); XtAppAddActions (xtcontext, xclipboard_actions, XtNumber (xclipboard_actions)); /* CLIPBOARD_MANAGER is a non-standard mechanism */ ManagerAtom = XInternAtom(XtDisplay(top), "CLIPBOARD_MANAGER", False); ClipboardAtom = XA_CLIPBOARD(XtDisplay(top)); if (XGetSelectionOwner(XtDisplay(top), ManagerAtom)) XtError("another clipboard is already running\n"); parent = XtCreateManagedWidget("form", formWidgetClass, top, NULL, ZERO); (void) XtCreateManagedWidget("quit", Command, parent, NULL, ZERO); (void) XtCreateManagedWidget("delete", Command, parent, NULL, ZERO); (void) XtCreateManagedWidget("new", Command, parent, NULL, ZERO); (void) XtCreateManagedWidget("save", Command, parent, NULL, ZERO); nextButton = XtCreateManagedWidget("next", Command, parent, NULL, ZERO); prevButton = XtCreateManagedWidget("prev", Command, parent, NULL, ZERO); indexLabel = XtCreateManagedWidget("index", Label, parent, NULL, ZERO); n=0; XtSetArg(args[n], XtNtype, XawAsciiString); n++; XtSetArg(args[n], XtNeditType, XawtextEdit); n++; if (userOptions.wrap) { XtSetArg(args[n], XtNwrap, XawtextWrapWord); n++; XtSetArg(args[n], XtNscrollHorizontal, False); n++; } text = XtCreateManagedWidget( "text", Text, parent, args, n); currentClip = NewClip (text, (ClipPtr) 0); set_button_state (); fileDialogShell = XtCreatePopupShell("fileDialogShell", transientShellWidgetClass, top, NULL, ZERO); fileDialog = XtCreateManagedWidget ("fileDialog", dialogWidgetClass, fileDialogShell, NULL, ZERO); XawDialogAddButton(fileDialog, "accept", NULL, NULL); XawDialogAddButton(fileDialog, "cancel", NULL, NULL); failDialogShell = XtCreatePopupShell("failDialogShell", transientShellWidgetClass, top, NULL, ZERO); failDialog = XtCreateManagedWidget ("failDialog", dialogWidgetClass, failDialogShell, NULL, ZERO); XawDialogAddButton (failDialog, "continue", NULL, NULL); XtRealizeWidget(top); XtRealizeWidget(fileDialogShell); XtRealizeWidget(failDialogShell); XtOwnSelection(top, ManagerAtom, CurrentTime, RefuseSelection, LoseManager, NULL); if (XGetSelectionOwner (XtDisplay(top), ClipboardAtom)) { LoseSelection (top, &ClipboardAtom); } else { XtOwnSelection(top, ClipboardAtom, CurrentTime, ConvertSelection, LoseSelection, NULL); } wm_delete_window = XInternAtom(XtDisplay(top), "WM_DELETE_WINDOW", False); wm_protocols = XInternAtom(XtDisplay(top), "WM_PROTOCOLS", False); (void) XSetWMProtocols(XtDisplay(top), XtWindow(top), &wm_delete_window,1); (void) XSetWMProtocols(XtDisplay(top), XtWindow(fileDialogShell), &wm_delete_window,1); (void) XSetWMProtocols(XtDisplay(top), XtWindow(failDialogShell), &wm_delete_window,1); XtAppMainLoop(xtcontext); exit(0); }
void SetupWmICCC (void) { enum { #if ((!defined(WSM)) || defined(MWM_QATS_PROTOCOL)) XA_TARGETS, XA_MULTIPLE, XA_TIMESTAMP, #endif XA_WM_STATE, XA_WM_PROTOCOLS, XA_WM_CHANGE_STATE, XA_WM_SAVE_YOURSELF, XA_WM_DELETE_WINDOW, XA_WM_COLORMAP_WINDOWS, XA_WM_TAKE_FOCUS, XA_MWM_HINTS, XA_MWM_MENU, XA_MWM_MESSAGES, XA_MOTIF_WM_OFFSET, #if ((!defined(WSM)) || defined(MWM_QATS_PROTOCOL) || !defined(NO_WMQUERY)) XA_MOTIF_WM_CLIENT_WINDOW, XA_MOTIF_WM_POINTER_WINDOW, XA_MOTIF_WM_ALL_CLIENTS, #endif #if ((!defined(WSM)) || defined(MWM_QATS_PROTOCOL)) XA_MOTIF_WM_DEFINE_COMMAND, XA_MOTIF_WM_INCLUDE_COMMAND, XA_MOTIF_WM_REMOVE_COMMAND, XA_MOTIF_WM_ENABLE_COMMAND, XA_MOTIF_WM_DISABLE_COMMAND, XA_MOTIF_WM_RENAME_COMMAND, XA_MOTIF_WM_INVOKE_COMMAND, XA_MOTIF_WM_REQUEST_COMMAND, XA_MOTIF_WM_WINDOW_FLAGS, XA_MOTIF_WM_AUTOMATION, #endif XA_COMPOUND_TEXT, NUM_ATOMS }; static char *atom_names[] = { #if ((!defined(WSM)) || defined(MWM_QATS_PROTOCOL)) _XA_TARGETS, _XA_MULTIPLE, _XA_TIMESTAMP, #endif _XA_WM_STATE, _XA_WM_PROTOCOLS, _XA_WM_CHANGE_STATE, _XA_WM_SAVE_YOURSELF, _XA_WM_DELETE_WINDOW, _XA_WM_COLORMAP_WINDOWS, _XA_WM_TAKE_FOCUS, _XA_MWM_HINTS, _XA_MWM_MENU, _XA_MWM_MESSAGES, _XA_MOTIF_WM_OFFSET, #if ((!defined(WSM)) || defined(MWM_QATS_PROTOCOL) || !defined(NO_WMQUERY)) # ifdef _XA_MOTIF_WM_CLIENT_WINDOW _XA_MOTIF_WM_CLIENT_WINDOW, _XA_MOTIF_WM_POINTER_WINDOW, _XA_MOTIF_WM_ALL_CLIENTS, # else "_MOTIF_WM_CLIENT_WINDOW", "_MOTIF_WM_POINTER_WINDOW", "_MOTIF_WM_ALL_CLIENTS" # endif #endif #if ((!defined(WSM)) || defined(MWM_QATS_PROTOCOL)) _XA_MOTIF_WM_DEFINE_COMMAND, _XA_MOTIF_WM_INCLUDE_COMMAND, _XA_MOTIF_WM_REMOVE_COMMAND, _XA_MOTIF_WM_ENABLE_COMMAND, _XA_MOTIF_WM_DISABLE_COMMAND, _XA_MOTIF_WM_RENAME_COMMAND, _XA_MOTIF_WM_INVOKE_COMMAND, _XA_MOTIF_WM_REQUEST_COMMAND, _XA_MOTIF_WM_WINDOW_FLAGS, _XA_MOTIF_WM_AUTOMATION, #endif "COMPOUND_TEXT" }; XIconSize sizeList; int scr; Atom atoms[XtNumber(atom_names) + 1]; /* * Make atoms that are required by the ICCC and mwm. The atom for * _MOTIF_WM_INFO is intern'ed in ProcessMotifWmInfo. */ XInternAtoms(DISPLAY, atom_names, XtNumber(atom_names), False, atoms); #if ((!defined(WSM)) || defined(MWM_QATS_PROTOCOL)) wmGD.xa_TARGETS = atoms[XA_TARGETS]; wmGD.xa_MULTIPLE = atoms[XA_MULTIPLE]; wmGD.xa_TIMESTAMP = atoms[XA_TIMESTAMP]; #endif /* !defined(WSM) || defined(MWM_QATS_PROTOCOL) */ wmGD.xa_WM_STATE = atoms[XA_WM_STATE]; wmGD.xa_WM_PROTOCOLS = atoms[XA_WM_PROTOCOLS]; wmGD.xa_WM_CHANGE_STATE = atoms[XA_WM_CHANGE_STATE]; wmGD.xa_WM_SAVE_YOURSELF = atoms[XA_WM_SAVE_YOURSELF]; wmGD.xa_WM_DELETE_WINDOW = atoms[XA_WM_DELETE_WINDOW]; wmGD.xa_WM_COLORMAP_WINDOWS = atoms[XA_WM_COLORMAP_WINDOWS]; wmGD.xa_WM_TAKE_FOCUS = atoms[XA_WM_TAKE_FOCUS]; wmGD.xa_MWM_HINTS = atoms[XA_MWM_HINTS]; wmGD.xa_MWM_MENU = atoms[XA_MWM_MENU]; wmGD.xa_MWM_MESSAGES = atoms[XA_MWM_MESSAGES]; wmGD.xa_MWM_OFFSET = atoms[XA_MOTIF_WM_OFFSET]; #if ((!defined(WSM)) || defined(MWM_QATS_PROTOCOL)) /* wm query targets */ wmGD._MOTIF_WM_CLIENT_WINDOW = atoms[XA_MOTIF_WM_CLIENT_WINDOW]; wmGD._MOTIF_WM_POINTER_WINDOW = atoms[XA_MOTIF_WM_POINTER_WINDOW]; wmGD._MOTIF_WM_ALL_CLIENTS = atoms[XA_MOTIF_WM_ALL_CLIENTS]; /* intern atoms for Client-Commmand Interface protocol. */ wmGD._MOTIF_WM_DEFINE_COMMAND = atoms[XA_MOTIF_WM_DEFINE_COMMAND]; wmGD._MOTIF_WM_INCLUDE_COMMAND= atoms[XA_MOTIF_WM_INCLUDE_COMMAND]; wmGD._MOTIF_WM_REMOVE_COMMAND = atoms[XA_MOTIF_WM_REMOVE_COMMAND]; wmGD._MOTIF_WM_ENABLE_COMMAND = atoms[XA_MOTIF_WM_ENABLE_COMMAND]; wmGD._MOTIF_WM_DISABLE_COMMAND= atoms[XA_MOTIF_WM_DISABLE_COMMAND]; wmGD._MOTIF_WM_RENAME_COMMAND = atoms[XA_MOTIF_WM_RENAME_COMMAND]; wmGD._MOTIF_WM_INVOKE_COMMAND = atoms[XA_MOTIF_WM_INVOKE_COMMAND]; wmGD._MOTIF_WM_REQUEST_COMMAND= atoms[XA_MOTIF_WM_REQUEST_COMMAND]; wmGD._MOTIF_WM_WINDOW_FLAGS = atoms[XA_MOTIF_WM_WINDOW_FLAGS]; wmGD._MOTIF_WM_AUTOMATION = atoms[XA_MOTIF_WM_AUTOMATION]; #endif /* !defined(WSM) || defined(MWM_QATS_PROTOCOL) */ #if ((!defined(WSM)) || defined(MWM_QATS_PROTOCOL)) /* * Assert ownership of the WINDOW_MANAGER selection * on each screen that the window manager controls. * these use the format WM_Si. */ OwnWMSelections(GetTimestamp()); #endif /* !defined(WSM) || defined(MWM_QATS_PROTOCOL) */ wmGD.xa_COMPOUND_TEXT = atoms[XA_COMPOUND_TEXT]; #ifndef NO_WMQUERY if (!(xa_WM_QUERY = (Atom *) XtMalloc (wmGD.numScreens * (sizeof (Atom))))) { Warning (((char *)GETMESSAGE(56, 2, "Insufficient memory to XInternAtom _MOTIF_WM_QUERY_nn"))); } for (scr = 0; scr < wmGD.numScreens; scr++) { if (wmGD.Screens[scr].managed) { char wm_query_scr[32]; sprintf(wm_query_scr, "_MOTIF_WM_QUERY_%d", wmGD.Screens[scr].screen); xa_WM_QUERY[scr] = XInternAtom(DISPLAY, wm_query_scr, False); } else { xa_WM_QUERY[scr] = 0; } } xa_WM_CLIENT_WINDOW = atoms[XA_MOTIF_WM_CLIENT_WINDOW]; xa_WM_POINTER_WINDOW = atoms[XA_MOTIF_WM_POINTER_WINDOW]; xa_WM_ALL_CLIENTS = atoms[XA_MOTIF_WM_ALL_CLIENTS]; #endif /* NO_WMQUERY */ /* * Setup the icon size property on the root window. */ sizeList.width_inc = 1; sizeList.height_inc = 1; for (scr = 0; scr < wmGD.numScreens; scr++) { if (wmGD.Screens[scr].managed) { sizeList.min_width = wmGD.Screens[scr].iconImageMinimum.width; sizeList.min_height = wmGD.Screens[scr].iconImageMinimum.height; sizeList.max_width = wmGD.Screens[scr].iconImageMaximum.width; sizeList.max_height = wmGD.Screens[scr].iconImageMaximum.height; XSetIconSizes (DISPLAY, wmGD.Screens[scr].rootWindow, &sizeList, 1); } } #ifndef NO_WMQUERY /* * Assert ownership of the WM_QUERY selection */ for (scr = 0; scr < wmGD.numScreens; scr++) { if (wmGD.Screens[scr].managed) { if (!XtOwnSelection(wmGD.topLevelW, xa_WM_QUERY[scr], GetTimestamp(), wmq_convert, wmq_lose, wmq_done)) { Warning (((char *)GETMESSAGE(56, 3, "Failed to own _MOTIF_WM_QUERY_nn selection"))); } } } #endif /* NO_WMQUERY */ } /* END OF FUNCTION SetupWmICCC */
/* ARGSUSED */ void SetCommand(Widget w, ResCommand command, char *msg) { XClientMessageEvent client_event; Display *dpy = XtDisplay(w); if (msg == NULL) { /* "Click the mouse pointer on any toolkit client" */ msg = res_labels[6]; } SetMessage(global_screen_data.info_label, msg, "Click the mouse pointer on any toolkit client"); if (global_client.window == None) { if ( (global_client.window = GetClientWindow(w, NULL, NULL)) == None ) { return; } } /* printf("[SetCommand] global_client.window: %d 0x%x\n", */ /* global_client.window, */ /* global_client.window); */ global_client.ident = GetNewIdent(); global_client.command = command; global_client.atom = atom_comm; BuildHeader(&(global_client)); if (!XtOwnSelection(w, global_client.atom, CurrentTime, ConvertCommand, LoseSelection, SelectionDone)) { /* "Unable to own the Resource/Attribute Selection" */ SetMessage(global_screen_data.info_label, res_labels[7], "Unable to own the Resource/Attribute Selection"); } client_event.window = global_client.window; client_event.type = ClientMessage; client_event.message_type = atom_resource_editor; client_event.format = EDITRES_SEND_EVENT_FORMAT; client_event.data.l[0] = XtLastTimestampProcessed(dpy); client_event.data.l[1] = global_client.atom; client_event.data.l[2] = (long) global_client.ident; client_event.data.l[3] = global_effective_protocol_version; global_error_code = NO_ERROR; /* Reset Error code. */ global_old_error_handler = XSetErrorHandler(HandleXErrors); global_serial_num = NextRequest(dpy); XSendEvent(dpy, global_client.window, FALSE, (long)0, (XEvent*)&client_event); XSync(dpy, FALSE); XSetErrorHandler(global_old_error_handler); if (global_error_code == NO_WINDOW) { char error_buf[BUFSIZ]; global_error_code = NO_ERROR; /* Reset Error code. */ sprintf(error_buf, "The communication window with%s%s.", " application is no longer available\n", "Please select a new widget tree"); global_client.window = None; SetCommand(w, LocalSendWidgetTree, error_buf); return; } TellUserAboutMessage(global_screen_data.info_label, command); global_client.timeout = XtAppAddTimeOut(XtWidgetToApplicationContext(w), CLIENT_TIME_OUT, ClientTimedOut, (XtPointer)w); startWait(XtWidgetToApplicationContext(w), CLIENT_TIME_OUT / 1000); } /* SetCommand() */
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; }
/* * SetSelection : indicate that we have the selection. * * Actions : * - indicate it in the source * - deal with Xt Selections (XtOwnSelection etc.) * - call callback(s) (LoseSelection,GainSelection) * - tell the widgets that display us about this (highlight) */ static void SetSelection(XmTextSource source, XmTextPosition left, XmTextPosition right, Time time) { XmSourceData d = source->data; int i; Boolean gain = False; DEBUGOUT(_LtDebug(__FILE__, NULL, "XmTextStrSource SetSelection %d %d\n", left, right)); if (left >= right) { /* No decent selection */ /* SG 23/08/1998, just bring into line with changes in TextF.c */ if(!source->data->hasselection) { return; /* Already no selection, don't do unnecessary work */ } source->data->hasselection = False; source->data->left = -1; source->data->right = -1; source->data->prim_time = time; XtDisownSelection((Widget)d->widgets[0], XA_PRIMARY, time); for (i = 0; i < d->numwidgets; i++) { XmTextSetHighlight((Widget)d->widgets[i], 0, XmTextGetLastPosition((Widget)d->widgets[0]), XmHIGHLIGHT_NORMAL); } return; } /* Remember whether we used to have the selection */ gain = (source->data->hasselection == False); /* We have a decent selection; indicate in memory */ source->data->hasselection = True; source->data->left = left; source->data->right = right; source->data->prim_time = time; /* Xt, callbacks */ DEBUGOUT(_LtDebug(__FILE__, (Widget)d->widgets[0], "XtOwnSelection(_, XA_PRIMARY, ...)\n")); if (!XtOwnSelection((Widget)d->widgets[0], XA_PRIMARY, time, _XmTextConvertSelection, _XmTextLoseSelection, NULL)) { gain = False; } if (gain) { XmAnyCallbackStruct cbs; cbs.reason = XmCR_GAIN_PRIMARY; cbs.event = NULL; /* Have no information nested this deep */ /* FIX ME : Only for one widget ? */ XtCallCallbackList((Widget)source->data->widgets[0], source->data->widgets[0]->text.gain_primary_callback, (XtPointer)&cbs); } /* Widgets */ for (i = 0; i < d->numwidgets; i++) { /* Unset the highlight over the complete widget */ XmTextSetHighlight((Widget)d->widgets[i], 0, XmTextGetLastPosition((Widget)d->widgets[0]), XmHIGHLIGHT_NORMAL); /* Highlight the selected area */ XmTextSetHighlight((Widget)d->widgets[i], left, right, XmHIGHLIGHT_SELECTED); } }