void CScriptSystem::EndCall(float& fRet) { if (m_nTempArg == -1) { return; } if (ExecuteFunction(m_pLS, m_nTempArg, 1)) { BEHAVIAC_ASSERT(lua_isnumber(m_pLS, -1) && "Invalid return value"); if (lua_isnumber(m_pLS, -1)) { fRet = lua_tonumber(m_pLS, -1); } else { fRet = 0; } lua_pop(m_pLS, 1); } // Check for LUA stack corruption CheckStackOnEndCall(); }
/*********************************************************************** * * Procedure: * HandleClientMessage - client message event handler * ************************************************************************/ void HandleClientMessage() { XEvent button; DBUG("HandleClientMessage","Routine Entered"); if ((Event.xclient.message_type == _XA_WM_CHANGE_STATE)&& (Tmp_win)&&(Event.xclient.data.l[0]==IconicState)&& !(Tmp_win->flags & ICONIFIED)) { XQueryPointer( dpy, Scr.Root, &JunkRoot, &JunkChild, &(button.xmotion.x_root), &(button.xmotion.y_root), &JunkX, &JunkY, &JunkMask); button.type = 0; ExecuteFunction("Iconify",Tmp_win, &button,C_FRAME,-1); return; } /* ** CKH - if we get here, it was an unknown client message, so send ** it to the client if it was in a window we know about. I'm not so ** sure this should be done or not, since every other window manager ** I've looked at doesn't. But it might be handy for a free drag and ** drop setup being developed for Linux. */ if (Tmp_win) { if(Event.xclient.window != Tmp_win->w) { Event.xclient.window = Tmp_win->w; XSendEvent(dpy, Tmp_win->w, False, NoEventMask, &Event); } } }
void CScriptSystem::EndCall(const char*& sRet) { if (m_nTempArg == -1) { return; } if (ExecuteFunction(m_pLS, m_nTempArg, 1)) { BEHAVIAC_ASSERT(lua_isstring(m_pLS, -1) && "Invalid return value"); if (lua_isstring(m_pLS, -1)) { sRet = lua_tostring(m_pLS, -1); } else { sRet = NULL; } lua_pop(m_pLS, 1); } // Check for LUA stack corruption CheckStackOnEndCall(); }
void Done(int restart, char *command) { MenuRoot *mr; #ifndef NON_VIRTUAL MoveViewport(0, 0, False); #endif mr = FindPopup("ExitFunction"); if (mr != NULL) ExecuteFunction("Function ExitFunction", NULL, &Event, C_ROOT, -1); /* Close all my pipes */ ClosePipes(); Reborder(); if (restart) { SaveDesktopState(); /* I wonder why ... */ /* Really make sure that the connection is closed and cleared! */ XSelectInput(dpy, Scr.Root, 0); XSync(dpy, 0); XCloseDisplay(dpy); { char *my_argv[10]; int i, done, j; i = 0; j = 0; done = 0; while ((g_argv[j] != NULL) && (i < 8)) { if (strcmp(g_argv[j], "-s") != 0) { my_argv[i] = g_argv[j]; i++; j++; } else j++; } if (strstr(command, "fvwm") != NULL) my_argv[i++] = "-s"; while (i < 10) my_argv[i++] = NULL; /* really need to destroy all windows, explicitly, * not sleep, but this is adequate for now */ sleep(1); ReapChildren(); execvp(command, my_argv); } fvwm_msg(ERR, "Done", "Call of '%s' failed!!!!", command); execvp(g_argv[0], g_argv); /* that _should_ work */ fvwm_msg(ERR, "Done", "Call of '%s' failed!!!!", g_argv[0]); } else { XCloseDisplay(dpy); exit(0); } }
void cTask::mainExecuteFunction() { // выполнение основной задачи params->endTask = false; ExecuteFunction(); // рабочая функция params->CallBack(); // отчитались о проделанной работе params->endTask = true; }
bool dVirtualMachine::ExecuteFunction(int entryPoint, const char* const paramFormat, ...) { va_list v_args; va_start(v_args, paramFormat); bool ret = ExecuteFunction (entryPoint, paramFormat, v_args); va_end(v_args); return ret; }
void StartupStuff(void) { MenuRoot *mr; CaptureAllWindows(); MakeMenus(); if (Restarting) { mr = FindPopup("RestartFunction"); if (mr != NULL) ExecuteFunction("Function RestartFunction", NULL, &Event, C_ROOT, -1); } else { mr = FindPopup("InitFunction"); if (mr != NULL) ExecuteFunction("Function InitFunction", NULL, &Event, C_ROOT, -1); } }
void CScriptSystem::EndCall() { if (m_nTempArg == -1) { return; } ExecuteFunction(m_pLS, m_nTempArg, 0); // Check for LUA stack corruption CheckStackOnEndCall(); }
bool dVirtualMachine::ExecuteFunction(const dString& name, const char* const paramFormat, ...) { dFunctionTable::dTreeNode* const node = m_functionTable.Find(name); if (node) { va_list v_args; va_start(v_args, paramFormat); bool ret = ExecuteFunction (node->GetInfo().m_entryPoint, paramFormat, v_args); va_end(v_args); return ret; } return false; }
// @brief lua执行函数 // @param handler - Lua函数的句柄 // @param num_args - lua函数的参数 // return 脚本函数的返回值 int LuaManager::ExecuteFunction(int handler, int num_args) { int ret = 0; if (PushFunctionByHandler(handler)) /* L: ... arg1 arg2 ... func */ { if (num_args > 0) { lua_insert(luaState, -(num_args + 1)); /* L: ... func arg1 arg2 ... */ } ret = ExecuteFunction(num_args); } lua_settop(luaState, 0); return ret; }
/*********************************************************************** * running Autoexec code ( if any ) : ************************************************************************/ void DoAutoexec( Bool restarting ) { FunctionData func ; ASEvent event = {0}; char screen_func_name[128]; init_func_data( &func ); func.func = F_FUNCTION ; func.name = restarting?"RestartFunction":"InitFunction"; if( Scr.screen > 0 ) { sprintf (screen_func_name, restarting?"RestartScreen%ldFunction":"InitScreen%ldFunction", Scr.screen); if( find_complex_func( Scr.Feel.ComplexFunctions, &(screen_func_name[0])) != NULL ) func.name = &(screen_func_name[0]); } ExecuteFunction (&func, &event, -1); }
int main(int argc, char *argv[]) { int result = Init(); printf("Init pvm and import of isharp.iface. Result=%i\n", result); wchar_t *value; long ret = ExecuteFunction("create_image", "RGBA,10,10", &value); printf("Id of created image is = %ls\n", value); char id_obj[16000]; sprintf(id_obj, "%ls", value); result = FreeObject(id_obj); printf("Object released = %i\n", result); ShutDown(); return 0; }
/*********************************************************************** * * Procedure: * HandleKeyPress - key press event handler * ************************************************************************/ void HandleKeyPress() { Binding *key; unsigned int modifier; modifier = (Event.xkey.state & mods_used); ButtonWindow = Tmp_win; DBUG("HandleKeyPress","Routine Entered"); Context = GetContext(Tmp_win,&Event, &PressedW); PressedW = None; /* Here's a real hack - some systems have two keys with the * same keysym and different keycodes. This converts all * the cases to one keycode. */ Event.xkey.keycode = XKeysymToKeycode(dpy,XKeycodeToKeysym(dpy,Event.xkey.keycode,0)); for (key = Scr.AllBindings; key != NULL; key = key->NextBinding) { if ((key->Button_Key == Event.xkey.keycode) && ((key->Modifier == (modifier&(~LockMask)))|| (key->Modifier == AnyModifier)) && (key->Context & Context)&& (key->IsMouse == 0)) { ExecuteFunction(key->Action,Tmp_win, &Event,Context,-1); return; } } /* if we get here, no function key was bound to the key. Send it * to the client if it was in a window we know about. */ if (Tmp_win) { if(Event.xkey.window != Tmp_win->w) { Event.xkey.window = Tmp_win->w; XSendEvent(dpy, Tmp_win->w, False, KeyPressMask, &Event); } } ButtonWindow = NULL; }
void VBasePlayer::SetViewState(int position, VState* stnum) { guard(VBasePlayer::SetViewState); VViewState& VSt = ViewStates[position]; VState *state = stnum; do { if (!state) { // Object removed itself. VSt.State = NULL; VSt.StateTime = -1; break; } VSt.State = state; VSt.StateTime = state->Time; // could be 0 if (state->Misc1) { VSt.SX = state->Misc1; } if (state->Misc2) { VSt.SY = state->Misc2; } // Call action routine. if (state->Function) { Level->XLevel->CallingState = state; P_PASS_REF(MO); ExecuteFunction(state->Function); if (!VSt.State) { break; } } state = VSt.State->NextState; } while (!VSt.StateTime); // An initial state of 0 could cycle through. unguard; }
void CScriptSystem::EndCall(IScriptObject* pObj) { if (m_nTempArg == -1) { return; } if (ExecuteFunction(m_pLS, m_nTempArg, 1)) { if (lua_istable(m_pLS, -1)) { //int nRef = lua_ref(m_pLS, 1); pObj->Attach(); } else { lua_pop(m_pLS, 1); } } // Check for LUA stack corruption CheckStackOnEndCall(); }
void SetRCDefaults() { /* set up default colors, menus, fonts, etc... */ ExecuteFunction("MenuFont fixed", NULL, &Event, C_ROOT, -1); ExecuteFunction("HilightColors white black", NULL, &Event, C_ROOT, -1); ExecuteFunction("StickyColors white grey", NULL, &Event, C_ROOT, -1); ExecuteFunction("DefaultColors black grey grey white", NULL, &Event, C_ROOT, -1); ExecuteFunction("MenuColors black grey white black", NULL, &Event, C_ROOT, -1); ExecuteFunction("XORValue 255", NULL, &Event, C_ROOT, -1); ExecuteFunction("IconFont fixed", NULL, &Event, C_ROOT, -1); ExecuteFunction("WindowFont fixed", NULL, &Event, C_ROOT, -1); ExecuteFunction("Style \"*\" ClickToFocus", NULL, &Event, C_ROOT, -1); ExecuteFunction("Style \"*\" DecorateTransient", NULL, &Event, C_ROOT, -1); ExecuteFunction("AddToMenu default_menu \"Default Menu\" Title", NULL, &Event, C_ROOT, -1); ExecuteFunction("+ \"Exit\" Quit", NULL, &Event, C_ROOT, -1); ExecuteFunction("Mouse 1 R N Popup default_menu", NULL, &Event, C_ROOT, -1); }
int main(int argc, char **argv) { unsigned long valuemask; /* mask for create windows */ XSetWindowAttributes attributes; /* attributes for create windows */ void InternUsefulAtoms(void); void InitVariables(void); int i, len; extern int x_fd; char *display_string; char message[255]; Bool single = False; Bool option_error = FALSE; MenuRoot *mr; g_argv = argv; g_argc = argc; OpenConsole(); DBUG("main", "Entered, about to parse args"); for (i = 1; i < argc; i++) { if (strncasecmp(argv[i], "-debug", 6) == 0) { debugging = True; } else if (strncasecmp(argv[i], "-s", 2) == 0) { single = True; } else if (strncasecmp(argv[i], "-d", 2) == 0) { if (++i >= argc) usage(); display_name = argv[i]; } else if (strncasecmp(argv[i], "-f", 2) == 0) { if (++i >= argc) usage(); config_command = (char *) malloc(6 + strlen(argv[i])); strcpy(config_command, "Read "); strcat(config_command, argv[i]); free_config_command = True; } else if (strncasecmp(argv[i], "-cmd", 4) == 0) { if (++i >= argc) usage(); config_command = argv[i]; } else if (strncasecmp(argv[i], "-file", 5) == 0) { if (++i >= argc) usage(); output_file = argv[i]; } else if (strncasecmp(argv[i], "-h", 2) == 0) { usage(); exit(0); } else if (strncasecmp(argv[i], "-blackout", 9) == 0) { Blackout = True; } else if (strncasecmp(argv[i], "-version", 8) == 0) { fvwm_msg(INFO, "main", "Fvwm95 Version %s compiled on %s at %s\n", VERSION, __DATE__, __TIME__); } else { fvwm_msg(ERR, "main", "Unknown option: `%s'\n", argv[i]); option_error = TRUE; } } DBUG("main", "Done parsing args"); if (option_error) { usage(); } DBUG("main", "Installing signal handlers"); newhandler(SIGINT); newhandler(SIGHUP); newhandler(SIGQUIT); newhandler(SIGTERM); signal(SIGUSR1, Restart); signal(SIGPIPE, DeadPipe); ReapChildren(); if (!(dpy = XOpenDisplay(display_name))) { fvwm_msg(ERR, "main", "can't open display %s", XDisplayName(display_name)); exit(1); } Scr.screen = DefaultScreen(dpy); Scr.NumberOfScreens = ScreenCount(dpy); master_pid = getpid(); if (!single) { int myscreen = 0; char *cp; strcpy(message, XDisplayString(dpy)); XCloseDisplay(dpy); for (i = 1; i < Scr.NumberOfScreens; i++) { if (fork() == 0) { myscreen = i; break; } } /* * Truncate the string 'whatever:n.n' to 'whatever:n', * and then append the screen number. */ cp = strchr(message, ':'); if (cp != NULL) { cp = strchr(cp, '.'); if (cp != NULL) *cp = '\0'; /* truncate at display part */ } sprintf(message + strlen(message), ".%d", myscreen); dpy = XOpenDisplay(message); Scr.screen = myscreen; Scr.NumberOfScreens = ScreenCount(dpy); } x_fd = XConnectionNumber(dpy); fd_width = GetFdWidth(); if (fcntl(x_fd, F_SETFD, 1) == -1) { fvwm_msg(ERR, "main", "close-on-exec failed"); exit(1); } /* Add a DISPLAY entry to the environment, in case we were started * with fvwm -display term:0.0 */ len = strlen(XDisplayString(dpy)); display_string = safemalloc(len + 10); sprintf(display_string, "DISPLAY=%s", XDisplayString(dpy)); putenv(display_string); /* Add a HOSTDISPLAY environment variable, which is the same as * DISPLAY, unless display = :0.0 or unix:0.0, in which case the full * host name will be used for ease in networking . */ /* Note: Can't free the rdisplay_string after putenv, because it * becomes part of the environment! */ if (strncmp(display_string, "DISPLAY=:", 9) == 0) { char client[MAXHOSTNAME], *rdisplay_string; mygethostname(client, MAXHOSTNAME); rdisplay_string = safemalloc(len + 14 + strlen(client)); sprintf(rdisplay_string, "HOSTDISPLAY=%s:%s", client, &display_string[9]); putenv(rdisplay_string); } else if (strncmp(display_string, "DISPLAY=unix:", 13) == 0) { char client[MAXHOSTNAME], *rdisplay_string; mygethostname(client, MAXHOSTNAME); rdisplay_string = safemalloc(len + 14 + strlen(client)); sprintf(rdisplay_string, "HOSTDISPLAY=%s:%s", client, &display_string[13]); putenv(rdisplay_string); } else { char *rdisplay_string; rdisplay_string = safemalloc(len + 14); sprintf(rdisplay_string, "HOSTDISPLAY=%s", XDisplayString(dpy)); putenv(rdisplay_string); } Scr.Root = RootWindow(dpy, Scr.screen); if (Scr.Root == None) { fvwm_msg(ERR, "main", "Screen %d is not a valid screen", (char *) Scr.screen); exit(1); } #ifdef SHAPE ShapesSupported = XShapeQueryExtension(dpy, &ShapeEventBase, &ShapeErrorBase); #endif /* SHAPE */ InternUsefulAtoms(); /* Make sure property priority colors is empty */ XChangeProperty(dpy, Scr.Root, _XA_MIT_PRIORITY_COLORS, XA_CARDINAL, 32, PropModeReplace, NULL, 0); XSetErrorHandler((XErrorHandler) CatchRedirectError); XSetIOErrorHandler((XIOErrorHandler) CatchFatal); XSelectInput(dpy, Scr.Root, LeaveWindowMask | EnterWindowMask | PropertyChangeMask | SubstructureRedirectMask | KeyPressMask | SubstructureNotifyMask | ButtonPressMask | ButtonReleaseMask); XSync(dpy, 0); XSetErrorHandler((XErrorHandler) FvwmErrorHandler); BlackoutScreen(); CreateCursors(); InitVariables(); InitEventHandlerJumpTable(); initModules(); InitPictureCMap(dpy, Scr.Root); /* for the pixmap cache... */ Scr.gray_bitmap = XCreateBitmapFromData(dpy, Scr.Root, g_bits, g_width, g_height); DBUG("main", "Setting up rc file defaults..."); SetRCDefaults(); DBUG("main", "Running config_command..."); ExecuteFunction(config_command, NULL, &Event, C_ROOT, -1); DBUG("main", "Done running config_command"); /* CaptureAllWindows(); MakeMenus(); */ #if 0 /* this seems to cause problems for FvwmCpp/M4 startup actually */ /* if not a direct 'Read', we'll capture all windows here, in case cmd fails we'll still have defaults */ if (strncasecmp(config_command, "Read", 4) != 0 && strncasecmp(config_command, "PipeRead", 8) != 0) { /* so if cmd (FvwmM4/Cpp most likely) fails, we can still have borders & stuff... */ StartupStuff(); } #endif /* 0 */ if (free_config_command) { free(config_command); } if (Scr.d_depth < 2) { Scr.gray_pixmap = XCreatePixmapFromBitmapData(dpy, Scr.Root, g_bits, g_width, g_height, Scr.WinColors.fore, Scr.WinColors.back, Scr.d_depth); Scr.light_gray_pixmap = XCreatePixmapFromBitmapData(dpy, Scr.Root, l_g_bits, l_g_width, l_g_height, Scr.WinColors.fore, Scr.WinColors.back, Scr.d_depth); } /* create a window which will accept the keyboard focus when no other windows have it */ attributes.event_mask = KeyPressMask | FocusChangeMask; attributes.override_redirect = True; Scr.NoFocusWin = XCreateWindow(dpy, Scr.Root, -10, -10, 10, 10, 0, 0, InputOnly, CopyFromParent, CWEventMask | CWOverrideRedirect, &attributes); XMapWindow(dpy, Scr.NoFocusWin); SetMWM_INFO(Scr.NoFocusWin); XSetInputFocus(dpy, Scr.NoFocusWin, RevertToParent, CurrentTime); XSync(dpy, 0); if (debugging) XSynchronize(dpy, 1); Scr.SizeStringWidth = XTextWidth(Scr.StdFont.font, " +8888 x +8888 ", 15); attributes.border_pixel = Scr.WinColors.fore; attributes.background_pixel = Scr.WinColors.back; attributes.bit_gravity = NorthWestGravity; attributes.save_under = True; valuemask = (CWBorderPixel | CWBackPixel | CWBitGravity | CWSaveUnder); /* create the window for coordinates */ Scr.SizeWindow = XCreateWindow(dpy, Scr.Root, Scr.MyDisplayWidth / 2 - (Scr.SizeStringWidth + SIZE_HINDENT * 2) / 2, Scr.MyDisplayHeight / 2 - (Scr.StdFont.height + SIZE_VINDENT * 2) / 2, (unsigned int) (Scr.SizeStringWidth + SIZE_HINDENT * 2), (unsigned int) (Scr.StdFont.height + SIZE_VINDENT * 2), (unsigned int) 0, 0, (unsigned int) CopyFromParent, (Visual *) CopyFromParent, valuemask, &attributes); #ifndef NON_VIRTUAL initPanFrames(); #endif XGrabServer(dpy); #ifndef NON_VIRTUAL checkPanFrames(); #endif XUngrabServer(dpy); UnBlackoutScreen(); DBUG("main", "Entering HandleEvents loop..."); HandleEvents(); DBUG("main", "Back from HandleEvents loop? Exiting..."); return 0; }
/***************************************************************************** * * Builtin which determines if the button press was a click or double click... * ****************************************************************************/ void ComplexFunction(XEvent * eventp, Window w, FvwmWindow * tmp_win, unsigned long context, char *action, int *Module) { char type = MOTION; char c; MenuItem *mi; Bool Persist = False; Bool HaveDoubleClick = False; Bool NeedsTarget = False; char *arguments[10], *junk, *taction; int x, y, i; XEvent d, *ev; MenuRoot *mr; extern Bool desperate; mr = FindPopup(action); if (mr == NULL) { if (!desperate) fvwm_msg(ERR, "ComplexFunction", "No such function %s", action); return; } desperate = 0; /* Get the argument list */ /* First entry in action is the function-name, ignore it */ action = GetNextToken(action, &junk); if (junk != NULL) free(junk); for (i = 0; i < 10; i++) action = GetNextToken(action, &arguments[i]); /* These built-ins require a selected window * The function code is >= 100 and < 1000 * F_RESIZE * F_MOVE * F_ICONIFY * F_RAISE * F_LOWER * F_DESTROY * F_DELETE * F_STICK * F_RAISELOWER * F_MAXIMIZE * F_FOCUS * * These do not: * The function code is < 100 * F_NOP * F_TITLE * F_BEEP * F_SCROLL * F_MOVECURSOR * F_RESTART * F_EXEC * F_REFRESH * F_GOTO_PAGE * F_TOGGLE_PAGE * F_CIRCULATE_UP * F_CIRCULATE_DOWN * F_WARP * F_DESK * F_MODULE * F_POPUP * F_QUIT * F_WINDOWLIST * F_FUNCTION * F_SEND_WINDOW_LIST */ ev = eventp; /* In case we want to perform an action on a button press, we * need to fool other routines */ if (eventp->type == ButtonPress) eventp->type = ButtonRelease; mi = mr->first; while (mi != NULL) { /* make lower case */ c = *(mi->item); if ((mi->func_type >= 100) && (mi->func_type < 1000)) NeedsTarget = True; if (isupper(c)) c = tolower(c); if (c == DOUBLE_CLICK) { HaveDoubleClick = True; Persist = True; } else if (c == IMMEDIATE) { if (tmp_win) w = tmp_win->frame; else w = None; taction = expand(mi->action, arguments, tmp_win); ExecuteFunction(taction, tmp_win, eventp, context, -2); free(taction); } else Persist = True; mi = mi->next; } if (!Persist) { for (i = 0; i < 10; i++) if (arguments[i] != NULL) free(arguments[i]); return; } /* Only defer execution if there is a possibility of needing * a window to operate on */ if (NeedsTarget) { if (DeferExecution (eventp, &w, &tmp_win, &context, SELECT, ButtonPress)) { WaitForButtonsUp(); for (i = 0; i < 10; i++) if (arguments[i] != NULL) free(arguments[i]); return; } } if (!GrabEm(SELECT)) { XBell(dpy, Scr.screen); for (i = 0; i < 10; i++) if (arguments[i] != NULL) free(arguments[i]); return; } XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, &x, &y, &JunkX, &JunkY, &JunkMask); /* Wait and see if we have a click, or a move */ /* wait 100 msec, see if the user releases the button */ if (IsClick(x, y, ButtonReleaseMask, &d)) { ev = &d; type = CLICK; } /* If it was a click, wait to see if its a double click */ if ((HaveDoubleClick) && (type == CLICK) && (IsClick(x, y, ButtonPressMask, &d))) { type = ONE_AND_A_HALF_CLICKS; ev = &d; } if ((HaveDoubleClick) && (type == ONE_AND_A_HALF_CLICKS) && (IsClick(x, y, ButtonReleaseMask, &d))) { type = DOUBLE_CLICK; ev = &d; } /* some functions operate on button release instead of * presses. These gets really weird for complex functions ... */ if (ev->type == ButtonPress) ev->type = ButtonRelease; mi = mr->first; while (mi != NULL) { /* make lower case */ c = *(mi->item); if (isupper(c)) c = tolower(c); if (c == type) { if (tmp_win) w = tmp_win->frame; else w = None; taction = expand(mi->action, arguments, tmp_win); ExecuteFunction(taction, tmp_win, ev, context, -2); free(taction); } mi = mi->next; } WaitForButtonsUp(); UngrabEm(); for (i = 0; i < 10; i++) if (arguments[i] != NULL) free(arguments[i]); }
/*********************************************************************** * * Procedure: * HandleButtonPress - ButtonPress event handler * ***********************************************************************/ void HandleButtonPress() { unsigned int modifier; Binding *MouseEntry; Window x; int LocalContext; DBUG("HandleButtonPress","Routine Entered"); /* click to focus stuff goes here */ if((Tmp_win)&&(Tmp_win->flags & ClickToFocus)&&(Tmp_win != Scr.Ungrabbed) && ((Event.xbutton.state& (ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask)) == 0)) { SetFocus(Tmp_win->w,Tmp_win,1); /* #ifdef CLICKY_MODE_1 */ if (Scr.ClickToFocusRaises || ((Event.xany.window != Tmp_win->w)&& (Event.xbutton.subwindow != Tmp_win->w)&& (Event.xany.window != Tmp_win->Parent)&& (Event.xbutton.subwindow != Tmp_win->Parent))) /* #endif */ { RaiseWindow(Tmp_win); } KeepOnTop(); /* Why is this here? Seems to cause breakage with * non-focusing windows! */ if(!(Tmp_win->flags & ICONIFIED)) { XSync(dpy,0); /* pass click event to just clicked to focus window? */ if (Scr.ClickToFocusPassesClick) XAllowEvents(dpy,ReplayPointer,CurrentTime); else /* don't pass click to just focused window */ XAllowEvents(dpy,AsyncPointer,CurrentTime); XSync(dpy,0); return; } } else if ((Tmp_win) && !(Tmp_win->flags & ClickToFocus) && (Event.xbutton.window == Tmp_win->frame) && Scr.MouseFocusClickRaises) { if (Tmp_win != Scr.LastWindowRaised && (Event.xbutton.state & (ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask)) == 0 && GetContext(Tmp_win,&Event, &PressedW) == C_WINDOW) { RaiseWindow(Tmp_win); KeepOnTop(); } XSync(dpy,0); XAllowEvents(dpy,ReplayPointer,CurrentTime); XSync(dpy,0); return; } XSync(dpy,0); XAllowEvents(dpy,ReplayPointer,CurrentTime); XSync(dpy,0); Context = GetContext(Tmp_win,&Event, &PressedW); LocalContext = Context; x= PressedW; if(Context == C_TITLE) SetTitleBar(Tmp_win,(Scr.Hilite == Tmp_win),False); else SetBorder(Tmp_win,(Scr.Hilite == Tmp_win),True,True,PressedW); ButtonWindow = Tmp_win; /* we have to execute a function or pop up a menu */ modifier = (Event.xbutton.state & mods_used); /* need to search for an appropriate mouse binding */ for (MouseEntry = Scr.AllBindings; MouseEntry != NULL; MouseEntry= MouseEntry->NextBinding) { if(((MouseEntry->Button_Key == Event.xbutton.button)|| (MouseEntry->Button_Key == 0))&& (MouseEntry->Context & Context)&& ((MouseEntry->Modifier == AnyModifier)|| (MouseEntry->Modifier == (modifier& (~LockMask))))&& (MouseEntry->IsMouse == 1)) { /* got a match, now process it */ ExecuteFunction(MouseEntry->Action,Tmp_win, &Event,Context,-1); break; } } PressedW = None; if(LocalContext!=C_TITLE) SetBorder(ButtonWindow,(Scr.Hilite == ButtonWindow),True,True,x); else SetTitleBar(ButtonWindow,(Scr.Hilite==ButtonWindow),False); ButtonWindow = NULL; }
/* * Change by PRB ([email protected]), 31/10/93. Prepend a hot key * specifier to each item in the list. This means allocating the * memory for each item (& freeing it) rather than just using the window * title directly. */ void do_windowList(XEvent *eventp,Window w,FvwmWindow *tmp_win, unsigned long context, char *action,int *Module) { MenuRoot *mr; MenuItem *miExecuteAction; FvwmWindow *t; FvwmWindow **windowList; int numWindows; int ii; char tname[80] = ""; char loc[40],*name=NULL; int dwidth,dheight; char tlabel[50]=""; int last_desk_done = INT_MIN; int last_desk_displayed = INT_MIN; int next_desk = 0; char *t_hot=NULL; /* Menu label with hotkey added */ char scut = '0'; /* Current short cut key */ char *line=NULL,*tok=NULL; int desk = Scr.CurrentDesk; int flags = SHOW_EVERYTHING; char *func=NULL; char *tfunc=NULL; char *default_action = NULL; MenuStatus menu_retval; XEvent *teventp; MenuOptions mops; size_t hotlen; mops.flags.allflags = 0; if (action && *action) { /* parse postitioning args */ action = GetMenuOptions(action,w,tmp_win,NULL,&mops); line = action; /* parse options */ while (line && *line) { line = GetNextOption(line, &tok); if (!tok) break; if (StrEquals(tok,"Function")) { line = GetNextOption(line, &func); } else if (StrEquals(tok,"Desk")) { free(tok); line = GetNextOption(line, &tok); if (tok) { desk = atoi(tok); flags &= ~SHOW_ALLDESKS; } } else if (StrEquals(tok,"CurrentDesk")) { desk = Scr.CurrentDesk; flags &= ~SHOW_ALLDESKS; } else if (StrEquals(tok,"NotAlphabetic")) flags &= ~SHOW_ALPHABETIC; else if (StrEquals(tok,"Alphabetic")) flags |= SHOW_ALPHABETIC; else if (StrEquals(tok,"NoDeskSort")) flags |= NO_DESK_SORT; else if (StrEquals(tok,"UseIconName")) flags |= SHOW_ICONNAME; else if (StrEquals(tok,"NoGeometry")) flags &= ~SHOW_GEOMETRY; else if (StrEquals(tok,"Geometry")) flags |= SHOW_GEOMETRY; else if (StrEquals(tok,"NoIcons")) flags &= ~SHOW_ICONIC; else if (StrEquals(tok,"Icons")) flags |= SHOW_ICONIC; else if (StrEquals(tok,"OnlyIcons")) flags = SHOW_ICONIC; else if (StrEquals(tok,"NoNormal")) flags &= ~SHOW_NORMAL; else if (StrEquals(tok,"Normal")) flags |= SHOW_NORMAL; else if (StrEquals(tok,"OnlyNormal")) flags = SHOW_NORMAL; else if (StrEquals(tok,"NoSticky")) flags &= ~SHOW_STICKY; else if (StrEquals(tok,"Sticky")) flags |= SHOW_STICKY; else if (StrEquals(tok,"OnlySticky")) flags = SHOW_STICKY; else if (StrEquals(tok,"NoOnTop")) flags &= ~SHOW_ONTOP; else if (StrEquals(tok,"OnTop")) flags |= SHOW_ONTOP; else if (StrEquals(tok,"OnlyOnTop")) flags = SHOW_ONTOP; else if (!line || !*line) default_action = strdup(tok); else { fvwm_msg(ERR,"WindowList","Unknown option '%s'",tok); } if (tok) free(tok); } } globalFlags = flags; if (flags & SHOW_GEOMETRY) { snprintf(tlabel,sizeof(tlabel),"Desk: %d\tGeometry",desk); } else { snprintf(tlabel,sizeof(tlabel),"Desk: %d",desk); } mr=NewMenuRoot(tlabel, False); AddToMenu(mr, tlabel, "TITLE", FALSE, FALSE); numWindows = 0; for (t = Scr.FvwmRoot.next; t != NULL; t = t->next) { numWindows++; } windowList = malloc(numWindows*sizeof(t)); if (windowList == NULL) { return; } /* get the windowlist starting from the current window (if any)*/ if ((t = Scr.Focus) == NULL) t = Scr.FvwmRoot.next; for (ii = 0; ii < numWindows; ii++) { windowList[ii] = t; if (t->next) t = t->next; else t = Scr.FvwmRoot.next; } /* Do alphabetic sort */ if (flags & SHOW_ALPHABETIC) qsort(windowList,numWindows,sizeof(t), (int(*)(const void*,const void*))winCompare); while(next_desk != INT_MAX) { /* Sort window list by desktop number */ if((flags & SHOW_ALLDESKS) && !(flags & NO_DESK_SORT)) { /* run through the windowlist finding the first desk not already processed */ next_desk = INT_MAX; for (ii = 0; ii < numWindows; ii++) { t = windowList[ii]; if((t->Desk >last_desk_done)&&(t->Desk < next_desk)) next_desk = t->Desk; } } if(!(flags & SHOW_ALLDESKS)) { /* if only doing one desk and it hasn't been done */ if(last_desk_done == INT_MIN) next_desk = desk; /* select the desk */ else next_desk = INT_MAX; /* flag completion */ } if(flags & NO_DESK_SORT) next_desk = INT_MAX; /* only go through loop once */ last_desk_done = next_desk; for (ii = 0; ii < numWindows; ii++) { t = windowList[ii]; if(((t->Desk == next_desk) || (flags & NO_DESK_SORT)) && (!(t->flags & WINDOWLISTSKIP))) { if (!(flags & SHOW_ICONIC) && (t->flags & ICONIFIED)) continue; /* don't want icons - skip */ if (!(flags & SHOW_STICKY) && (t->flags & STICKY)) continue; /* don't want sticky ones - skip */ if (!(flags & SHOW_ONTOP) && (t->flags & ONTOP)) continue; /* don't want ontop ones - skip */ if (!(flags & SHOW_NORMAL) && !((t->flags & ICONIFIED) || (t->flags & STICKY) || (t->flags & ONTOP))) continue; /* don't want "normal" ones - skip */ /* put a seperator between desks, but not at the top */ if (t->Desk != last_desk_displayed) { if (last_desk_displayed != INT_MIN) AddToMenu(mr, NULL, NULL, FALSE, FALSE); last_desk_displayed = t->Desk; } if(flags & SHOW_ICONNAME) name = t->icon_name; else name = t->name; hotlen = strlen(name) + strlen(tname) + 48; t_hot = safemalloc(hotlen); snprintf(t_hot, hotlen, "&%c. %s", scut, name); /* Generate label */ if (scut++ == '9') scut = 'A'; /* Next shortcut key */ if (flags & SHOW_GEOMETRY) { tname[0]=0; if(t->flags & ICONIFIED) strlcpy(tname, "(", sizeof(tname)); snprintf(loc, sizeof(loc), "%d:",t->Desk); strlcat(tname, loc, sizeof(tname)); dheight = t->frame_height - t->title_height - 2*t->boundary_width; dwidth = t->frame_width - 2*t->boundary_width; dwidth -= t->hints.base_width; dheight -= t->hints.base_height; dwidth /= t->hints.width_inc; dheight /= t->hints.height_inc; snprintf(loc, sizeof(loc), "%d", dwidth); strlcat(tname, loc,sizeof(tname)); snprintf(loc, sizeof(loc), "x%d", dheight); strlcat(tname, loc,sizeof(tname)); if(t->frame_x >=0) snprintf(loc, sizeof(loc), "+%d", t->frame_x); else snprintf(loc, sizeof(loc), "%d", t->frame_x); strlcat(tname, loc, sizeof(tname)); if(t->frame_y >=0) snprintf(loc, sizeof(loc), "+%d", t->frame_y); else snprintf(loc, sizeof(loc), "%d", t->frame_y); strlcat(tname, loc, sizeof(tname)); if (t->flags & STICKY) strlcat(tname, " S", sizeof(tname)); if (t->flags & ONTOP) strlcat(tname, " T", sizeof(tname)); if (t->flags & ICONIFIED) strlcat(tname, ")", sizeof(tname)); strlcat(t_hot,"\t",hotlen); strlcat(t_hot,tname,hotlen); } if (!func) { tfunc = safemalloc(40); snprintf(tfunc,40,"WindowListFunc %ld",t->w); } else { size_t funclen = strlen(func) + 32; tfunc = safemalloc(funclen); snprintf(tfunc,funclen,"%s %ld",func,t->w); free(func); func = NULL; } AddToMenu(mr, t_hot, tfunc, FALSE, FALSE); free(tfunc); #ifdef MINI_ICONS /* Add the title pixmap */ if (t->mini_icon) { mr->last->lpicture = t->mini_icon; t->mini_icon->count++; /* increase the cache count!! otherwise the pixmap will be eventually removed from the cache by DestroyMenu */ } #endif if (t_hot) free(t_hot); } } } if (func) free(func); free(windowList); MakeMenu(mr); if (!default_action && eventp && eventp->type == KeyPress) teventp = (XEvent *)1; else teventp = eventp; menu_retval = do_menu(mr, NULL, &miExecuteAction, 0, TRUE, teventp, &mops); DestroyMenu(mr); if (menu_retval == MENU_DOUBLE_CLICKED && default_action && *default_action) ExecuteFunction(default_action,tmp_win,eventp,context,*Module); if (default_action != NULL) free(default_action); }
T ExecuteFunction(Function* func) { return (T)ExecuteFunction(func); }
void HandleModuleInput(Window w, int channel) { char text[256]; int size; int cont, n; /* Already read a (possibly NULL) window id from the pipe, * Now read an fvwm bultin command line */ n = read(readPipes[channel], &size, sizeof(size)); if (n < sizeof(size)) { KillModule(channel, 1); return; } if (size > 255) { fvwm_msg(ERR, "HandleModuleInput", "Module command is too big (%d)", (void *) size); size = 255; } pipeOn[channel] = 1; n = read(readPipes[channel], text, size); if (n < size) { KillModule(channel, 2); return; } text[n] = 0; n = read(readPipes[channel], &cont, sizeof(cont)); if (n < sizeof(cont)) { KillModule(channel, 3); return; } if (cont == 0) { KillModule(channel, 4); } if (strlen(text) > 0) { extern int Context; FvwmWindow *tmp_win; /* first, check to see if module config line */ if (text[0] == '*') { AddToModList(text); return; } /* perhaps the module would like us to kill it? */ if (strncasecmp(text, "KillMe", 6) == 0) { KillModule(channel, 12); return; } /*Event.xany.type = ButtonRelease; hmmm... */ /* If a module does XUngrabPointer(), it can now get proper Popups */ if (strncasecmp(text, "popup", 5) == 0) Event.xany.type = ButtonPress; else Event.xany.type = ButtonRelease; Event.xany.window = w; if ((w == None) || (XFindContext(dpy, w, FvwmContext, (caddr_t *) &tmp_win) == XCNOENT)) { tmp_win = NULL; w = None; } if (tmp_win) { Event.xbutton.button = 1; Event.xbutton.x_root = tmp_win->frame_x; Event.xbutton.y_root = tmp_win->frame_y; Event.xbutton.x = 0; Event.xbutton.y = 0; Event.xbutton.subwindow = None; } else { Event.xbutton.button = 1; Event.xbutton.x_root = 0; Event.xbutton.y_root = 0; Event.xbutton.x = 0; Event.xbutton.y = 0; Event.xbutton.subwindow = None; } Context = GetContext(tmp_win, &Event, &w); ExecuteFunction(text, tmp_win, &Event, Context, channel); SendPacket(channel, M_FUNCTION_END, 1, 0, 0, 0, 0, 0, 0, 0); } return; }
ExecutableInMemory *LoadSharedLibrary(FileNode *file) { //Read data from file and verify if (file == NULL) { return NULL; } ExecutableInMemory *sl = calloc(sizeof(ExecutableInMemory)); ExecutableFileHeader *header = (ExecutableFileHeader *)file->contents; if (header->size != file->size) { debug_print("Invalid file header: size $d != $d\n", header->size, file->size); return NULL; } if (header->magic != EXECUTABLE_FILE_MAGIC) { debug_print("Invalid file header: magic\n"); return NULL; } if ((header->type != EXECUTABLE_TYPE_LIBRARY)&&(header->type != EXECUTABLE_TYPE_EXECUTABLE)) { debug_print("Invalid file header: type\n"); return NULL; } if (header->functionCount == 0) { debug_print("Invalid file header: functions\n"); return NULL; } if (header->functionTableOffset != sizeof(ExecutableFileHeader)) { debug_print("Invalid file header: function table offset\n"); return NULL; } if (header->resourceCount * sizeof(ResourceEntry) > file->size - sizeof(ExecutableFileHeader) - header->functionCount * sizeof(FunctionTableEntry)) { debug_print("Invalid file header: resource size\n"); return NULL; } if (header->resourceOffset > file->size - header->resourceCount * sizeof(ResourceEntry)) { debug_print("Invalid file header: resource offset\n"); return NULL; } if (header->functionsSize > file->size - sizeof(ExecutableFileHeader) - header->functionCount * sizeof(FunctionTableEntry) - header->resourceCount * sizeof(ResourceEntry)) { debug_print("Invalid file header: functions size\n"); return NULL; } if (header->functionsOffset > file->size - header->functionsSize) { debug_print("Invalid file header: functions size\n"); return NULL; } sl->type = header->type; sl->functionCount = header->functionCount; sl->functionTable = calloc(header->functionCount * sizeof(FunctionTableEntry)); cgc_memcpy(sl->functionTable, file->contents + header->functionTableOffset, header->functionCount * sizeof(FunctionTableEntry)); for (int i = 0; i < sl->functionCount; i++) { sl->functionTable[i].offset -= header->functionsOffset; } sl->resourceCount = header->resourceCount; sl->resourceTable = calloc(header->resourceCount * sizeof(ResourceEntry)); cgc_memcpy(sl->resourceTable, file->contents + header->resourceOffset, header->resourceCount * sizeof(ResourceEntry)); sl->functions = calloc(header->functionsSize); cgc_memcpy(sl->functions, file->contents + header->functionsOffset, header->functionsSize); uint8_t *mainAddress = GetFunctionAddress("SharedLibraryMain", sl); ExecuteFunction(mainAddress); return sl; }
T ExecuteFunction(const string& name) { return (T)ExecuteFunction(name); }