Application::Application() : KApplication(), owner(screen_number) { KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); if(!config()->isImmutable() && args->isSet("lock")) { config()->setReadOnly(true); config()->reparseConfiguration(); } if(screen_number == -1) screen_number = DefaultScreen(qt_xdisplay()); if(!owner.claim(args->isSet("replace"), true)) { fputs(i18n("kwin: unable to claim manager selection, another wm running? (try using --replace)\n").local8Bit(), stderr); ::exit(1); } connect(&owner, SIGNAL(lostOwnership()), SLOT(lostSelection())); // if there was already kwin running, it saved its configuration after loosing the selection -> reread config()->reparseConfiguration(); initting = TRUE; // startup.... // install X11 error handler XSetErrorHandler(x11ErrorHandler); // check whether another windowmanager is running XSelectInput(qt_xdisplay(), qt_xrootwin(), SubstructureRedirectMask); syncX(); // trigger error now options = new Options; atoms = new Atoms; // create workspace. (void)new Workspace(isSessionRestored()); syncX(); // trigger possible errors, there's still a chance to abort DCOPRef ref("kded", "kded"); ref.send("unloadModule", QCString("kdetrayproxy")); initting = FALSE; // startup done, we are up and running now. dcopClient()->send("ksplash", "", "upAndRunning(QString)", QString("wm started")); XEvent e; e.xclient.type = ClientMessage; e.xclient.message_type = XInternAtom(qt_xdisplay(), "_KDE_SPLASH_PROGRESS", False); e.xclient.display = qt_xdisplay(); e.xclient.window = qt_xrootwin(); e.xclient.format = 8; strcpy(e.xclient.data.b, "wm started"); XSendEvent(qt_xdisplay(), qt_xrootwin(), False, SubstructureNotifyMask, &e); }
static void selectionNotification(void *observerData, WMNotification * notification) { WMView *observerView = (WMView *) observerData; WMView *newOwnerView = (WMView *) WMGetNotificationClientData(notification); if (observerView != newOwnerView) { /* //if (tPtr->flags.ownsSelection) // WMDeleteSelectionHandler(observerView, XA_PRIMARY, CurrentTime); */ lostSelection(observerView, XA_PRIMARY, NULL); } }
static void handleTextFieldKeyPress(TextField * tPtr, XEvent * event) { char buffer[64]; KeySym ksym; char *textEvent = NULL; void *data = NULL; int count, refresh = 0; int control_pressed = 0; int cancelSelection = 1; Bool shifted, controled, modified; Bool relay = True; /*printf("(%d,%d) -> ", tPtr->selection.position, tPtr->selection.count); */ if (((XKeyEvent *) event)->state & WM_EMACSKEYMASK) control_pressed = 1; shifted = (event->xkey.state & ShiftMask ? True : False); controled = (event->xkey.state & ControlMask ? True : False); modified = shifted || controled; count = W_LookupString(tPtr->view, &event->xkey, buffer, 63, &ksym, NULL); //count = XLookupString(&event->xkey, buffer, 63, &ksym, NULL); buffer[count] = '\0'; switch (ksym) { case XK_Tab: #ifdef XK_ISO_Left_Tab case XK_ISO_Left_Tab: #endif if (!controled) { if (shifted) { if (tPtr->view->prevFocusChain) { W_SetFocusOfTopLevel(W_TopLevelOfView(tPtr->view), tPtr->view->prevFocusChain); tPtr->flags.notIllegalMovement = 1; } data = (void *)WMBacktabTextMovement; } else { if (tPtr->view->nextFocusChain) { W_SetFocusOfTopLevel(W_TopLevelOfView(tPtr->view), tPtr->view->nextFocusChain); tPtr->flags.notIllegalMovement = 1; } data = (void *)WMTabTextMovement; } textEvent = WMTextDidEndEditingNotification; cancelSelection = 0; relay = False; } break; case XK_Escape: if (!modified) { data = (void *)WMEscapeTextMovement; textEvent = WMTextDidEndEditingNotification; relay = False; } break; case XK_Return: if (!modified) { data = (void *)WMReturnTextMovement; textEvent = WMTextDidEndEditingNotification; relay = False; } break; case WM_EMACSKEY_LEFT: if (!control_pressed) goto normal_key; else controled = False; #ifdef XK_KP_Left case XK_KP_Left: #endif case XK_Left: if (tPtr->cursorPosition > 0) { int i; paintCursor(tPtr); i = tPtr->cursorPosition; i += oneUTF8CharBackward(&tPtr->text[i], i); if (controled) { while (i > 0 && tPtr->text[i] != ' ') i--; while (i > 0 && tPtr->text[i] == ' ') i--; tPtr->cursorPosition = (i > 0) ? i + 1 : 0; } else tPtr->cursorPosition = i; if (tPtr->cursorPosition < tPtr->viewPosition) { tPtr->viewPosition = tPtr->cursorPosition; refresh = 1; } else paintCursor(tPtr); } if (shifted) cancelSelection = 0; relay = False; break; case WM_EMACSKEY_RIGHT: if (!control_pressed) goto normal_key; else controled = False; #ifdef XK_KP_Right case XK_KP_Right: #endif case XK_Right: if (tPtr->cursorPosition < tPtr->textLen) { int i; paintCursor(tPtr); i = tPtr->cursorPosition; if (controled) { while (tPtr->text[i] && tPtr->text[i] != ' ') i++; while (tPtr->text[i] == ' ') i++; } else { i += oneUTF8CharForward(&tPtr->text[i], tPtr->textLen - i); } tPtr->cursorPosition = i; refresh = incrToFit2(tPtr); if (!refresh) paintCursor(tPtr); } if (shifted) cancelSelection = 0; relay = False; break; case WM_EMACSKEY_HOME: if (!control_pressed) goto normal_key; else controled = False; #ifdef XK_KP_Home case XK_KP_Home: #endif case XK_Home: if (!controled) { if (tPtr->cursorPosition > 0) { paintCursor(tPtr); tPtr->cursorPosition = 0; if (tPtr->viewPosition > 0) { tPtr->viewPosition = 0; refresh = 1; } else paintCursor(tPtr); } if (shifted) cancelSelection = 0; relay = False; } break; case WM_EMACSKEY_END: if (!control_pressed) goto normal_key; else controled = False; #ifdef XK_KP_End case XK_KP_End: #endif case XK_End: if (!controled) { if (tPtr->cursorPosition < tPtr->textLen) { paintCursor(tPtr); tPtr->cursorPosition = tPtr->textLen; tPtr->viewPosition = 0; refresh = incrToFit(tPtr); if (!refresh) paintCursor(tPtr); } if (shifted) cancelSelection = 0; relay = False; } break; case WM_EMACSKEY_BS: if (!control_pressed) goto normal_key; else modified = False; case XK_BackSpace: if (!modified) { if (tPtr->selection.count) { WMDeleteTextFieldRange(tPtr, tPtr->selection); data = (void *)WMDeleteTextEvent; textEvent = WMTextDidChangeNotification; } else if (tPtr->cursorPosition > 0) { int i = oneUTF8CharBackward(&tPtr->text[tPtr->cursorPosition], tPtr->cursorPosition); WMRange range; range.position = tPtr->cursorPosition + i; range.count = -i; WMDeleteTextFieldRange(tPtr, range); data = (void *)WMDeleteTextEvent; textEvent = WMTextDidChangeNotification; } relay = False; } break; case WM_EMACSKEY_DEL: if (!control_pressed) goto normal_key; else modified = False; #ifdef XK_KP_Delete case XK_KP_Delete: #endif case XK_Delete: if (!modified) { if (tPtr->selection.count) { WMDeleteTextFieldRange(tPtr, tPtr->selection); data = (void *)WMDeleteTextEvent; textEvent = WMTextDidChangeNotification; } else if (tPtr->cursorPosition < tPtr->textLen) { WMRange range; range.position = tPtr->cursorPosition; range.count = oneUTF8CharForward(&tPtr->text[tPtr->cursorPosition], tPtr->textLen - tPtr->cursorPosition); WMDeleteTextFieldRange(tPtr, range); data = (void *)WMDeleteTextEvent; textEvent = WMTextDidChangeNotification; } relay = False; } break; normal_key: default: if (!controled) { if (count > 0 && !iscntrl(buffer[0])) { if (tPtr->selection.count) WMDeleteTextFieldRange(tPtr, tPtr->selection); WMInsertTextFieldText(tPtr, buffer, tPtr->cursorPosition); data = (void *)WMInsertTextEvent; textEvent = WMTextDidChangeNotification; relay = False; } } break; } if (relay) { WMRelayToNextResponder(W_VIEW(tPtr), event); return; } /* Do not allow text selection in secure text fields */ if (cancelSelection || tPtr->flags.secure) { lostSelection(tPtr->view, XA_PRIMARY, NULL); if (tPtr->selection.count) { tPtr->selection.count = 0; refresh = 1; } tPtr->selection.position = tPtr->cursorPosition; } else { if (tPtr->selection.count != tPtr->cursorPosition - tPtr->selection.position) { tPtr->selection.count = tPtr->cursorPosition - tPtr->selection.position; refresh = 1; } } /*printf("(%d,%d)\n", tPtr->selection.position, tPtr->selection.count); */ if (textEvent) { WMNotification *notif = WMCreateNotification(textEvent, tPtr, data); if (tPtr->delegate) { if (textEvent == WMTextDidBeginEditingNotification && tPtr->delegate->didBeginEditing) (*tPtr->delegate->didBeginEditing) (tPtr->delegate, notif); else if (textEvent == WMTextDidEndEditingNotification && tPtr->delegate->didEndEditing) (*tPtr->delegate->didEndEditing) (tPtr->delegate, notif); else if (textEvent == WMTextDidChangeNotification && tPtr->delegate->didChange) (*tPtr->delegate->didChange) (tPtr->delegate, notif); } WMPostNotification(notif); WMReleaseNotification(notif); } if (refresh) paintTextField(tPtr); /*printf("(%d,%d)\n", tPtr->selection.position, tPtr->selection.count); */ }