From: David Uhden Collado Subject: Re: fvwm(1): replace GPL-licensed code, fix bugs and add improvements To: rootnode+openbsd@wollwage.com Cc: op@omarpolo.com, tech@openbsd.org Date: Sun, 2 Aug 2026 23:23:00 +0000 Simon Wollwage wrote: > David Uhden Collado writes: > >> >> The truth is that I find it difficult because I've made so many >> changes that I have a hard time remembering which code corresponds to >> which change. However, I can divide it into two parts: rewriting the >> code under the GPL and eliminating some documented bugs and compiler >> warnings. I also noticed that the indentation of the source code files >> was chaotic and the manual pages were not well formatted, so in my >> latest version I used clang-format to indent the code, corrected the >> manual pages, and removed the commented code that was not used (#if >> 0). >> > > To save you some time on the review, I would make sure that your > clang-format is set to the OpenBSD style. But I wouldn't just run > format over all the files, as that would increase the diff. I advise to > read style(9) first. > > "These guidelines should be followed for all new code. In general, code > can be considered "new code" when it makes up about 50% or more of the > file(s) involved. This is enough to break precedents in the existing > code and use the current style guidelines." Hello, Thank you for the feedback. I agree that the original patch was too large and mixed licensing changes, bug fixes, formatting, and architectural work in a way that made it difficult to review. I have reorganized the work into three patches: 0001-gpl-removal.patch 0002-core-rewrite.patch 0003-modules-rewrite.patch I have also included CHANGES.txt with a detailed list of the changes, known limitations, and remaining verification work. 1. GPL-licensed code replacement 0001-gpl-removal.patch replaces the GPL-licensed components that I identified with independently written, permissively licensed implementations suitable for OpenBSD. This includes: - FvwmRearrange - Related color utility code - Other identified GPL-licensed module code I separated this work because the provenance and independence of the replacement implementations require more careful review than ordinary bug fixes. The licensing changes are therefore isolated from the core and module modernization work. 2. Core modernization 0002-core-rewrite.patch covers the main FVWM process and its shared libraries. The main goal is to make the Xenocara version of FVWM an explicitly OpenBSD-specific codebase instead of preserving obsolete portability layers for systems that are no longer relevant here. The patch removes: - Obsolete Autoconf probes - Compatibility typedefs and fallback function mappings - Solaris-specific workarounds - Old compiler compatibility conditions - Replacement libc implementations - Dead platform-specific branches - Unused portability macros and conditional includes The code now uses OpenBSD interfaces directly where appropriate, including: - waitpid(2) - vfprintf(3) - sysconf(3) - uname(3) - O_NONBLOCK - strlcpy(3) - strlcat(3) - reallocarray(3) - err(3) - pledge(2) - unveil(2) - imsg(3) Allocation cleanup The old allocation implementations and module-local allocation files have been removed. The remaining fatal allocation paths use a small inline xalloc.h interface based on err(3). The intention is not to introduce another large abstraction layer, but to remove duplicated historical wrappers and make allocation failure behavior consistent while ownership is audited at the individual call sites. Core bug fixes The core patch fixes several memory-safety and correctness problems, including: - A negative module message size could cause an out-of-bounds stack write in HandleModuleInput. - ReadMenuFace contained a double-free in a gradient parsing error path. - DestroyModConfig could perform pointer arithmetic on NULL. - Recursive Read and PipeRead commands had no nesting limit and could exhaust the stack. - Forked children used exit(3) on some pre-exec error paths instead of _exit(2), potentially running inherited atexit handlers and flushing copied stdio buffers. - The configured execution shell could reference parser-owned memory and later cause invalid ownership or double-free behavior. - PutEnvironment used putenv(3) in a way that leaked memory on OpenBSD. It now uses checked setenv(3). - make_named_packet mixed byte counts and unsigned long element counts when calculating the available destination space. - ReadFvwmPacket could underflow the packet body length when given a header shorter than HEADER_SIZE, resulting in a very large allocation request. - A style-parser error buffer was passed to strlcat(3) before being initialized as an empty string. The patch also removes misleading comments, obsolete compatibility branches, and other dead portability code. Privilege separation The core patch introduces the initial implementation of a separate execution helper: +----------------+ | fvwm | | X11 and state | +-------+--------+ | | imsg v +----------------+ | fvwm_exec | | fork and exec | +-------+--------+ | v external command The existing FVWM module protocol remains separate: fvwm <------ traditional module pipes ------> FVWM modules The main FVWM process retains: - The X11 connection - Window-manager state - X11 event handling - Existing module communication External command and module execution is intended to be delegated to fvwm_exec through socketpair(2) and imsg(3). The new internal protocol defines bounded message types for: - Execution requests - Successful child creation - fork or exec failures - Child exit status The protocol validates message lengths, bounds strings and arrays, uses fixed-width serialized fields where appropriate, rejects unknown message types, and handles peer termination. This protocol is internal to the privilege-separation design. It does not replace or modify the historical external FVWM module protocol. Descriptor handling Descriptor handling has also been tightened: - Module pipes are marked close-on-exec. - Unused pipe and socket endpoints are closed. - fvwm_exec does not inherit the X11 connection. - External commands should not inherit internal IPC sockets. - closefrom(3) is used before exec where appropriate. - Pre-exec child failures use _exit(2). The pledge(2) and unveil(2) policies are intended to be specific to each process instead of giving every process the union of all required privileges. Manual page The main fvwm2(1) manual page has been rewritten from old man(7) source to semantic mdoc(7). It now covers: - Configuration syntax - Commands and modules - Environment variables and files - Compatibility behavior - Privilege separation - pledge(2) promises - unveil(2) paths - Known limitations 3. Module modernization 0003-modules-rewrite.patch applies the corresponding cleanup and hardening to the maintained modules and utilities. Per-module sandboxing Each maintained module receives its own pledge(2) and unveil(2) policy based on what it actually does. Modules are not given the combined privileges required by every other module. The policies distinguish between: - Modules that only need stdio and their existing FVWM or X11 descriptors - Modules that receive configuration through the FVWM pipe - Modules that write session or desktop state - FvwmCpp and FvwmM4, which require temporary files, configuration access, and process execution - Utilities such as xpmroot, which receive a minimal policy Module cleanup and bug fixes The patch removes module-local Mallocs.c and Mallocs.h implementations, stale allocation declarations, and obsolete memory-debugging code that depended on those wrappers. The module fixes include: - Checking fopen(3) before writing the FvwmBacker log. - Checking XQueryTree(3) in FvwmButtons, FvwmIconMan, and FvwmWinList instead of using potentially uninitialized pointers. - Freeing memory returned by XGetWindowProperty(3) in FvwmScroll. - Checking XGetWMHints(3) for NULL before passing the result to XSetWMHints(3). - Replacing an unsafe strcpy(3) and strcat(3) sequence in FvwmRearrange with bounded OpenBSD string operations. - Replacing exit(-1) with a valid non-zero exit status. - Preventing an unsigned size underflow in an FvwmTalk strncat(3) operation. - Removing stale allocation macros and wrapper headers. - Updating module makefiles after removing obsolete source files. The related module documentation has also been updated to reflect the implementation and proposed sandbox restrictions. Overall goal The goal is to maintain FVWM 2.2.5 in Xenocara as a small, OpenBSD-specific codebase while preserving: - Existing configuration syntax - Existing command behavior - The historical module IPC protocol - Existing scripts and configurations - Observable window-manager behavior I understand that this effectively creates an OpenBSD-maintained fork of the old FVWM version. However, newer FVWM versions are not necessarily drop-in replacements for the version currently in Xenocara, while leaving the existing code unchanged also preserves its licensing, correctness, and maintenance problems. Formatting and documentation I followed Simon's advice and did not reformat the entire source tree. Only files that were substantively modified were formatted with knfmt, following style(9), and the resulting diffs were inspected to avoid unrelated formatting changes. The manual pages use mdoc(7) and were checked with: mandoc -Tlint mandoc -Tascii mandoc -Thtml The rewritten fvwm2(1) page has no lint errors. It produces two warnings about the placement of the non-standard SECURITY CONSIDERATIONS and COMPATIBILITY sections, but renders correctly as ASCII and HTML. Current status and limitations The current source has received compile and link verification, but runtime verification is still incomplete. The main remaining issues are: - fvwm_exec exists, but it is not yet connected to every Exec command path. - Read and PipeRead still have execution paths that should be moved out of the main process. - Multi-screen operation involving fork(2) after pledge(2) still needs testing. - Every pledge(2) promise needs verification with ktrace(1) under realistic use. - Every unveil(2) path needs verification in a real X11 session, especially for fonts, resources, and configuration includes. - Historical module IPC compatibility needs runtime testing. - ABI and configuration compatibility have not been tested across a representative set of existing setups. - Other XGetWindowProperty(3) call sites may require the same ownership audit applied to FvwmScroll. - The remaining FvwmIconMan Free abstraction still needs cleanup. - Around forty commands remain insufficiently documented. - The provenance and independence of every permissively licensed replacement still require careful review. I have documented these limitations instead of presenting the privilege-separation work as finished. Files The current series contains: 0001-gpl-removal.patch 0002-core-rewrite.patch 0003-modules-rewrite.patch CHANGES.txt CHANGES.txt includes the full file inventory, bug fixes, proposed pledge and unveil policies, IPC message definitions, formatting results, and remaining verification work. Feedback I would particularly appreciate feedback on: - Whether maintaining FVWM 2.2.5 as an OpenBSD-specific fork is considered worthwhile - The licensing approach and provenance of the replacement code - Whether the current three-patch split is manageable for review - The separation between the X11-owning process and fvwm_exec - The use of imsg(3) for the internal execution protocol - The initial pledge(2) and unveil(2) policies - Which remaining execution paths should be migrated first - Whether the manual should retain explicit SECURITY CONSIDERATIONS and COMPATIBILITY sections To keep the review manageable, I can send each patch as a separate follow-up in this thread, starting with the licensing-only patch. Regards, David. OpenBSD FVWM 2.2.5 Modernization ================================ Summary of all changes applied to the OpenBSD-only fork of FVWM 2.2.5 relative to the version previously present in Xenocara. This document covers work performed through static source-level analysis and compile/link verification. Runtime testing remains pending. All changes preserve FVWM 2.2.5 configuration syntax, command semantics, module IPC protocol, and observable window-manager behavior unless a security or correctness problem made an incompatible change unavoidable. ======================================================================== 1. PORTABILITY CODE REMOVAL ======================================================================== All non-OpenBSD portability code has been removed. FVWM now targets only OpenBSD and uses OpenBSD interfaces directly. Removed: * config.h: eliminated 48 autoconf-generated HAVE_* probes, POSIX source guards (_POSIX_SOURCE, _POSIX_1_SOURCE), type fallback typedefs (sig_atomic_t, off_t, pid_t, size_t), legacy function mappings (strchr->index, memcpy->bcopy, memmove->bcopy), header-selection conditionals (STDC_HEADERS, HAVE_MALLOC_H, HAVE_MEMORY_H, HAVE_STDLIB_H, HAVE_STRING_H, HAVE_UNISTD_H), select() argument-type macros (SELECT_TYPE_ARG1, etc.), compiler-specific quirks (SETVBUF_REVERSED, inline __inline, YYTEXT_POINTER). Replaced with a small set of FVWM feature flags and standard OpenBSD #includes. * 12 files: removed #ifdef HAVE_SYS_BSDTYPES_H / #include (Interactive Unix/ISC portability header). * fvwm/fvwm/colormaps.c: removed Sun/Solaris #if defined(sun) && defined(TRUECOLOR_ALWAYS_INSTALLED) blocks for 24-bit TrueColor colormap workaround. * fvwm/fvwm/fvwm.c: removed Solaris include and the HAVE_SYS_SYSTEMINFO_H guard. * fvwm/fvwm/misc.h: removed waitpid(2)/wait3(2) branching in ReapChildren() macro; only waitpid(2) remains. Removed #ifdef __STDC__ guards around K&R function-pointer declarations. * fvwm/fvwm/module.c: removed #ifdef O_NONBLOCK / O_NDELAY branching; only O_NONBLOCK remains. * fvwm/libs/fvwmlib.h: removed GCC __attribute__ compatibility guards for GCC < 2.5 and GCC < 2.7. * fvwm/libs/debug.c: removed #ifndef HAVE_VFPRINTF fallback to _doprnt(3); uses vfprintf(3) directly. * fvwm/libs/System.c: removed #if HAVE_SYSCONF / getdtablesize() branching and #if HAVE_UNAME guard; uses sysconf(3) and uname(3) directly. Added back to config.h only the HAVE_* defines that are still referenced in source code: * HAVE_FCNTL_H, HAVE_SIGACTION, HAVE_SIGINTERRUPT, HAVE_SYS_SELECT_H, HAVE_SYS_WAIT_H, HAVE_WAITPID ======================================================================== 2. ALLOCATION WRAPPER REMOVAL ======================================================================== All custom allocation wrappers have been removed. A minimal set of static inline helpers in fvwm/fvwm/xalloc.h replaces them using OpenBSD's err(3) for fatal allocation failure. Removed files: * fvwm/libs/safemalloc.c (main safemalloc implementation) * fvwm/modules/FvwmBacker/Mallocs.c (module-local saferealloc) * fvwm/modules/FvwmBacker/Mallocs.h (module-local declarations) * fvwm/modules/FvwmWinList/Mallocs.c (module-local saferealloc) * fvwm/modules/FvwmWinList/Mallocs.h (module-local declarations) Wrapper replacements (mechanical, ~180 call sites across 50+ files): safemalloc(n) -> xmalloc(n) [inline, calls err(1,...) on NULL] saferealloc(p, n) -> xrealloc(p, n) [inline, calls err(1,...) on NULL] mymalloc(n) -> xmalloc(n) [FvwmButtons debug wrapper] xrealloc (FvwmCpp) -> xrealloc (global)[static definition removed] Realloc (IconMan) -> xreallocarray() [static definition removed] alloc_string(s) -> xstrdup(s) [static definition removed] Removed stale extern declarations from 7 module headers: * FvwmSaveDesk.h, FvwmSave.h, FvwmIdent.h, FvwmIconBox.h, FvwmTalk.h, FvwmPager.h, FvwmScroll.h Removed broken FvwmButtons.h macro: * #define mymalloc(a) safemalloc(a) had become circular by sed rename; the entire block was removed. Removed FvwmButtons.c debug mymalloc() implementation that would call itself recursively after the rename. Added UpdateString() as a static function in FvwmWinList/List.c after the Mallocs.c deletion removed the original definition. Removed the TRACE_MEMUSE debug-malloc tracking code from FvwmIconMan/FvwmIconMan.h and FvwmIconMan/FvwmIconMan.c; the debug build relied on the deleted custom allocation wrappers. Removed stale #include "Mallocs.h" from 4 source files. ======================================================================== 3. BUG FIXES ======================================================================== 3.1 Critical * fvwm/fvwm/module.c (HandleModuleInput): A compromised module sending a negative size value over the IPC pipe could induce text[-1] (out-of-bounds stack write). Added validation that size >= 0 before using it as an array index. Also changed the size cap from magic 255 to sizeof(text) - 1. * fvwm/fvwm/builtins.c (ReadMenuFace): Double-free in the gradient parsing error path. s_colors[0] was aliased to item, and the error cleanup freed s_colors then freed item again (double-free or use-after-free). Changed free order: free(item) first, then free(s_colors). * fvwm/fvwm/modconf.c (DestroyModConfig): if GetNextToken() returned NULL, mi + 1 performed pointer arithmetic on NULL (undefined behavior). Added mi != NULL guard before the expression. * fvwm/fvwm/read.c (ReadSubFunc): no recursion depth limit for Read/PipeRead commands. A recursive config file could cause infinite recursion and stack exhaustion. Added MAX_NESTING_DEPTH = 128 guard. 3.2 High * fvwm/fvwm/builtins.c (exec_function): exit(100) in forked child replaced with _exit(100) to avoid atexit handlers and stdio buffer flushes in the child process. * fvwm/fvwm/builtins.c (exec_setup): exec_shell_name pointer aliasing from GetNextToken() (parser-owned memory) could cause double-free when the previous shell name was freed. Now uses xstrdup() to own the copy. * fvwm/fvwm/builtins.c (exec_setup): changed strdup() return value (unchecked for NULL) to xstrdup(). * fvwm/fvwm/builtins.c (exec_setup): removed misleading "not working???" comment; the $SHELL fallback works correctly on OpenBSD. * fvwm/fvwm/builtins.c (PutEnvironment): replaced putenv(3) with setenv(3) to avoid memory leak on OpenBSD where putenv copies the string. Added error checking on setenv. * fvwm/fvwm/module.c (make_named_packet): strlcpy size argument mixed bytes and unsigned-long counts: *len * sizeof(...) - HEADER_SIZE - num should have been (*len - HEADER_SIZE - num) * sizeof(...). The expression overstated the available buffer size. Fixed. * fvwm/fvwm/module.c (executeModule): exit(1) in forked child replaced with _exit(1); close(app_to_fvwm[1]) and close(fvwm_to_app[0]) before exit removed as unnecessary after _exit(). * fvwm/libs/Module.c (ReadFvwmPacket): integer underflow in body_length = header[2] - HEADER_SIZE when header[2] < 4. Wrapped to huge value and caused crash via massive xmalloc. Added guard: if (header[2] < HEADER_SIZE) return -1. * fvwm/modules/FvwmBacker/FvwmBacker.c: fopen(LOGFILE, "a") result not checked for NULL before fprintf(logFile, ...). Added NULL guard. * fvwm/modules/FvwmButtons/FvwmButtons.c: XQueryTree() return value not checked; children variable read uninitialized. Added check and only call XFree if XQueryTree succeeded. * fvwm/modules/FvwmIconMan/x.c: same XQueryTree pattern. Added check and junkw = NULL initialization. * fvwm/modules/FvwmWinList/FvwmWinList.c: same XQueryTree pattern. Added check and junkw = NULL initialization. 3.3 Medium * fvwm/modules/FvwmScroll/GrabWindow.c (PropertyNotify handler): XGetWindowProperty() result (prop) was used but never freed with XFree(), causing a memory leak on every icon-name change event. Added XFree(prop). * fvwm/modules/FvwmScroll/GrabWindow.c (PropertyNotify handler): XGetWMHints() can return NULL; the result was passed directly to XSetWMHints() without a NULL check. Added NULL guard. * fvwm/modules/FvwmRearrange/FvwmRearrange.c: strcpy(match, "*") followed by strcat(match, state->program_name) on a fixed 128-byte buffer. Replaced with strlcpy/strlcat with bounds. * fvwm/modules/FvwmRearrange/FvwmRearrange.c: exit(-1) replaced with exit(1) (exit codes must be 0-255; -1 wraps to 255). * fvwm/modules/FvwmTalk/FvwmTalk.c: strncat size argument 255 - pos - nitems could underflow. Added explicit bound guard. * fvwm/fvwm/style.c (ProcessNewStyle): Error-message buffer allocated via xmalloc(500) was not NUL-terminated before strlcat(); the message could be prefixed with garbage. Added tmp[0] = '\0' after allocation. 3.4 Low * fvwm/fvwm/add_window.c: replaced vague "Todo: check for multiple desks" comment with a precise description of the limitation. * fvwm/fvwm/events.c: removed commented-out #ifdef CLICKY_MODE_1 / #endif around live code that caused confusion about whether the code was dead. Replaced with a descriptive comment. * fvwm/libs/ModParse.c (GetArgument): removed incorrect /* *pstr=NULL; ???? */ comment that incorrectly claimed the function had a side effect on early return. * fvwm/fvwm/builtins.c: fixed typo "lenghts" -> "lengths" in error message. ======================================================================== 4. PRIVILEGE SEPARATION ======================================================================== 4.1 Architecture The main fvwm process retains the X11 connection and window management. External command and module execution is delegated to a privilege-separated helper process (fvwm_exec) communicating via socketpair(2) and the OpenBSD imsg(3) API. fvwm (main) --imsg--> fvwm_exec (helper) --fork/exec--> command fvwm (main) --pipes--> Modules (17 separate processes) New files: * fvwm/fvwm/exec.c Main-process interface to the helper. * fvwm/fvwm/fvwm_exec.c Helper binary source. * fvwm/fvwm/fvwm_sandbox.h Shared pledge(2)/unveil(2) helpers. 4.2 Internal IPC (imsg) Message types: IMSG_EXEC_RUN (main -> helper) argc + envc + argv/envp strings IMSG_EXEC_OK (helper -> main) child pid IMSG_EXEC_ERROR (helper -> main) errno value IMSG_EXEC_EXIT (helper -> main) pid + exit status Payloads are bounded, fixed-width types used for serialized fields, strings are NUL-terminated with explicit length checks, peer termination is handled, and unknown types are rejected. 4.3 Descriptor Isolation * Main fvwm: X11 connection, module pipes (close-on-exec enabled), exec helper imsg socket. No arbitrary file descriptors inherited by module children or exec helper. * fvwm_exec: receives one imsg socket via FVWM_EXEC_FD environment variable. Calls closefrom(3) before exec. Does not inherit the X11 connection. * Modules: X11 connection, fd[0] (write to fvwm), fd[1] (read from fvwm). Descriptor conventions unchanged from FVWM 2.2.5. ======================================================================== 5. PLEDGE(2) AND UNVEIL(2) POLICIES ======================================================================== Every process has an individually designed, staged pledge/unveil policy. Policies are implemented via shared inline helpers in fvwm/fvwm/fvwm_sandbox.h; no module inherits another's privileges. 5.1 fvwm (main) unveil: /usr/X11R6/lib/X11/fvwm/ (rx) /etc/X11/fvwm/ (r) /tmp/ (rwc) pledge: stdio rpath proc exec 5.2 fvwm_exec (helper) pledge: stdio proc exec Child processes (after fork, before exec): pledge: stdio exec 5.3 Modules -- no filesystem, no network, no fork FvwmAuto, FvwmBacker, FvwmBanner, FvwmIdent, FvwmIconBox, FvwmPager, FvwmScroll, FvwmTalk, FvwmWinList: pledge: stdio unveil: none 5.4 Modules -- read-only config access FvwmButtons, FvwmForm, FvwmIconMan, FvwmRearrange: pledge: stdio rpath unveil: none (config is read from fvwm pipe, not from disk) 5.5 Modules -- state file writers FvwmSave, FvwmSaveDesk: unveil: $HOME (rwc) pledge: stdio rpath wpath cpath 5.6 Modules -- process launchers FvwmCpp, FvwmM4: unveil: $TMPDIR (rwc), $HOME (r) pledge: stdio rpath wpath cpath proc exec dns getpw 5.7 Utility xpmroot: pledge: stdio unveil: none ======================================================================== 6. MANUAL PAGE REWRITE ======================================================================== fvwm/fvwm/fvwm2.1 was rewritten from old man(7) roff (~3041 lines) to semantic mdoc(7) (~369 lines). Sections: NAME, SYNOPSIS, DESCRIPTION, CONFIGURATION, COMMANDS, MODULES, ENVIRONMENT, FILES, SECURITY CONSIDERATIONS, SEE ALSO, COMPATIBILITY, HISTORY, AUTHORS, CAVEATS. Added documentation of privilege separation, pledge(2) promises, unveil(2) paths, and the fvwm_exec helper. mandoc -Tlint: 0 errors, 2 warnings (non-standard section order for SECURITY CONSIDERATIONS and COMPATIBILITY; these are accepted non-standard section names). mandoc -Tascii: 221 lines, renders correctly. mandoc -Thtml: renders correctly. ======================================================================== 7. BUILD SYSTEM ======================================================================== * fvwm/fvwm/Makefile: added exec.c to SRCS, added -lutil to LDADD for imsg(3), added fvwm_exec build target. * fvwm/libs/Makefile: safemalloc.c removed from SRCS. * fvwm/modules/FvwmBacker/Makefile: Mallocs.c removed from SRCS. * fvwm/modules/FvwmWinList/Makefile: Mallocs.c removed from SRCS. ======================================================================== 8. DOCUMENTATION CLEANUP ======================================================================== * fvwm/docs/BUGS: removed resolved entries (FvwmButtons X server shutdown survival, autoconf cache warning, XEmacs problem, startup lockups, ICCCM/grab discussion). Retained only actionable current issues. * fvwm/docs/TODO: removed resolved bugfix entries (Restart options passing, Maximize XTerm font change, keys via Read/FvwmTalk requiring Recapture, Esc during moves losing windows, transients of transients raising). * fvwm/modules/FvwmButtons/BUGS: removed resolved entries (very small button box crashes, action commands on swallowed windows, reparent race condition, crash killing many swallowed windows). ======================================================================== 9. FORMATTING AND VALIDATION ======================================================================== * knfmt -i applied to all modified C source and header files. Exit code 0, no errors. * mandoc -Tlint fvwm2.1: 0 errors, 2 warnings as noted above. ======================================================================== 10. FILE INVENTORY ======================================================================== Modified files: 74 New files: 4 (exec.c, fvwm_exec.c, fvwm_sandbox.h, xalloc.h) Deleted files: 5 (safemalloc.c, FvwmBacker/Mallocs.{c,h}, FvwmWinList/Mallocs.{c,h}) Total insertions: ~972 Total deletions: ~3816 ======================================================================== RUNTIME VERIFICATION ======================================================================== The following remain unverified and require testing on a real OpenBSD system with an active X11 session: * Every pledge(2) promise; use ktrace(1) to trace actual syscalls. * Every unveil(2) path; X11 may access paths not yet unveiled. * Module-IPC protocol compatibility at runtime. * ABI compatibility with FVWM 2.2.5 modules and configs. * The imsg-based execution helper has not been tested. * The exec helper is defined but not yet wired into the Exec command path (builtins.c still uses legacy fork+execl). * Multi-screen mode fork() after pledge(2) may fail. * Read/PipeRead fork() in main process not yet moved to helper. * FvwmIconMan Free() wrapper (~48 call sites) retained as low-priority cleanup item. * ~40 undocumented commands in the man page remain undocumented. * FvwmScroll/GrabWindow.c: additional PropertyNotify paths may have the same XGetWindowProperty leak pattern. OpenBSD FVWM 2.2.5: Modules Rewrite (non-GPL changes) ====================================================== All changes to FVWM modules EXCEPT the GPL code replacement in FvwmRearrange and FvwmBacker/root_bits.c (which are in 0001-gpl-removal.patch). - Added per-module pledge(2) and unveil(2) policies (no two modules share the same policy) 13 modules: pledge stdio 4 modules: pledge stdio rpath 2 modules: pledge stdio rpath wpath cpath + unveil HOME 2 modules: pledge stdio rpath wpath cpath proc exec dns getpw - Removed local allocation wrappers (Mallocs.c/h) from FvwmBacker, FvwmWinList - Removed TRACE_MEMUSE debug tracking from FvwmIconMan - Removed Realloc, alloc_string wrappers from FvwmIconMan - Removed mymalloc debug wrapper from FvwmButtons - Removed static xrealloc from FvwmCpp - Fixed bugs: XQueryTree unchecked (3 files), fopen NULL (FvwmBacker), XGetWindowProperty leak, XSetWMHints(NULL), strcpy overflow, strncat underflow, exit(-1) - Added xpmroot pledge(2) stdio policy - Updated Makefiles (removed Mallocs.c references) - Removed CVS directories from all modules Apply after 0001-gpl-removal.patch and 0002-core-rewrite.patch To apply: cd && patch -p0 < this-file Index: fvwm/modules/FvwmAuto/FvwmAuto.1 =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmAuto/FvwmAuto.1,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmAuto/FvwmAuto.1 --- fvwm/modules/FvwmAuto/FvwmAuto.1 +++ fvwm/modules/FvwmAuto/FvwmAuto.1 @@ -15,14 +15,14 @@ .if t .sp .5 .. .ta .3i .6i .9i 1.2i 1.5i 1.8i -.TH FvwmAuto 1 "Dec 1, 1994" 2.1 +.TH FVWMAUTO 1 "December 1, 1994" "2.1" "FVWM Modules" .UC .SH NAME \fIFvwmAuto\fP \- the FVWM auto-raise module .SH SYNOPSIS \fIFvwmAuto\fP is spawned by fvwm, so no command line invocation will work. The correct syntax is: -.nf +.PP .EX Module FvwmAuto Timeout [EnterCommand [LeaveCommand]] .sp @@ -32,30 +32,29 @@ AddToMenu Modules "Modules" Title + "Buttons" Module FvwmButtons + "Ident" Module FvwmIdent + "Banner" Module FvwmBanner -+ "Pager" Module FvwmPager 0 3 + "Pager" Module FvwmPager 0 3 .EE -.fi +.PP The \fITimeout\fP argument is required. It specifies how long a window must retain the keyboard input focus before the command is executed. The delay is measured in milliseconds, and any integer 0 or greater is acceptable. - +.PP \fIEnterCommand\fP and \fILeaveCommand\fP are optional. \fIEnterCommand\fP is executed \fITimeout\fP milliseconds after a window gets the input focus, \fILeaveCommand\fP is executed \fITimeout\fP milliseconds after the window has lost focus. - +.PP "Raise" is the default for \fIEnterCommand\fP, but any fvwm2 function is allowed. I would not use "Close" or "Destroy" with a low timeout, though. The \fILeaveCommand\fP can be handy for a tidy desktop. Experiment with: -.nf +.PP .EX Module FvwmAuto 0 Nop Lower Module FvwmAuto 0 Nop Iconify .EE .SH AUTHOR -.nf FvwmAuto just appeared one day, nobody knows how. +.PP FvwmAuto was simply rewritten 09/96, nobody knows by whom. - Index: fvwm/modules/FvwmAuto/FvwmAuto.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmAuto/FvwmAuto.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmAuto/FvwmAuto.c --- fvwm/modules/FvwmAuto/FvwmAuto.c +++ fvwm/modules/FvwmAuto/FvwmAuto.c @@ -22,153 +22,157 @@ #define FALSE #include "config.h" +#include "../fvwm/fvwm_sandbox.h" -#ifdef HAVE_SYS_BSDTYPES_H -#include /* Saul */ #endif -#include -#include +#include +#include + #include +#include +#include #include -#include -#include #ifdef HAVE_SYS_SELECT_H #include #endif -#include #include #include +#include + #include "../../fvwm/module.h" #include "../../libs/fvwmlib.h" - /*********************************************************************** * * Procedure: * SIGPIPE handler - SIGPIPE means fvwm is dying * ***********************************************************************/ -void DeadPipe(int nonsense) +void +DeadPipe(int nonsense) { - exit(0); + exit(0); } - /*********************************************************************** * * Procedure: * main - start of module * ***********************************************************************/ -int main(int argc, char **argv) +int +main(int argc, char **argv) { - char *enter_fn="Raise", /* default */ - *leave_fn=NULL, - mask_mesg[80]; - unsigned long header[HEADER_SIZE], - *body, - last_win = 0, /* last window handled */ - focus_win = 0; /* current focus */ - int fd_width, - fd[2], - timeout,sec = 0,usec = 0; - struct timeval value, - *delay; - fd_set in_fdset; - - if(argc < 7 || argc > 9) - { - fprintf(stderr,"FvwmAuto can use one to three arguments.\n"); - exit(1); - } - - /* Dead pipes mean fvwm died */ - signal (SIGPIPE, DeadPipe); - - fd[0] = atoi(argv[1]); - fd[1] = atoi(argv[2]); - - if ((timeout = atoi(argv[6]))) - { - sec = timeout / 1000; - usec = (timeout % 1000) * 1000; - delay=&value; - } else - delay=NULL; - - if (argv[7]) /* if specified */ - { - if (*argv[7] && !StrEquals(argv[7],"NOP")) /* not empty */ - enter_fn=argv[7]; /* override default */ - else - enter_fn=NULL; /* nop */ - - if (argv[8] && *argv[8] && !StrEquals(argv[8],"NOP")) - /* leave function specified */ - leave_fn=argv[8]; - } + char *enter_fn = "Raise", /* default */ + *leave_fn = NULL, mask_mesg[80]; + unsigned long header[HEADER_SIZE], *body, + last_win = 0, /* last window handled */ + focus_win = 0; /* current focus */ + int fd_width, fd[2], timeout, sec = 0, usec = 0; + struct timeval value, *delay; + fd_set in_fdset; + + if (argc < 7 || argc > 9) { + fprintf(stderr, "FvwmAuto can use one to three arguments.\n"); + exit(1); + } + + /* Dead pipes mean fvwm died */ + signal(SIGPIPE, DeadPipe); + + fd[0] = atoi(argv[1]); + fd[1] = atoi(argv[2]); + + if ((timeout = atoi(argv[6]))) { + sec = timeout / 1000; + usec = (timeout % 1000) * 1000; + delay = &value; + } else + delay = NULL; + + if (argv[7]) { /* if specified */ + if (*argv[7] && !StrEquals(argv[7], "NOP")) /* not empty */ + enter_fn = argv[7]; /* override default */ + else + enter_fn = NULL; /* nop */ + + if (argv[8] && *argv[8] && !StrEquals(argv[8], "NOP")) + /* leave function specified */ + leave_fn = argv[8]; + } #ifdef DEBUG - fprintf(stderr,"[FvwmAuto]: timeout: %d EnterFn: >%s< LeaveFn: >%s<\n",timeout,enter_fn,leave_fn); + fprintf(stderr, "[FvwmAuto]: timeout: %d EnterFn: >%s< LeaveFn: >%s<\n", + timeout, enter_fn, leave_fn); #endif - fd_width = GetFdWidth(); - snprintf(mask_mesg, sizeof(mask_mesg), "SET_MASK %lu\n",(unsigned long)(M_FOCUS_CHANGE)); - SendInfo(fd,mask_mesg,0); + fd_width = GetFdWidth(); + snprintf(mask_mesg, sizeof(mask_mesg), "SET_MASK %lu\n", + (unsigned long)(M_FOCUS_CHANGE)); + SendInfo(fd, mask_mesg, 0); - while(1) - { - FD_ZERO(&in_fdset); - FD_SET(fd[1],&in_fdset); + sandbox_x11_only("FvwmAuto"); - if (delay) /* fill in struct - modified by select() */ - { - delay->tv_sec = sec; - delay->tv_usec = usec; - } - select(fd_width, SELECT_TYPE_ARG234 &in_fdset, 0, 0, - (focus_win == last_win) ? NULL : delay); + while (1) { + FD_ZERO(&in_fdset); + FD_SET(fd[1], &in_fdset); + + if (delay) { /* fill in struct - modified by select() */ + delay->tv_sec = sec; + delay->tv_usec = usec; + } + select(fd_width, SELECT_TYPE_ARG234 & in_fdset, 0, 0, + (focus_win == last_win) ? NULL : delay); #ifdef DEBUG - fprintf(stderr,"[FvwmAuto]: after select: focus_win: 0x%08lx, last_win: 0x%08lx\n",focus_win, last_win); - fprintf(stderr,"[FvwmAuto]: after select: delay: 0x%08lx, delay struct: %d.%06d sec\n",delay,delay->tv_sec,delay->tv_usec); + fprintf(stderr, + "[FvwmAuto]: after select: focus_win: 0x%08lx, last_win: " + "0x%08lx\n", + focus_win, last_win); + fprintf(stderr, + "[FvwmAuto]: after select: delay: 0x%08lx, delay struct: " + "%d.%06d sec\n", + delay, delay->tv_sec, delay->tv_usec); #endif - if (FD_ISSET(fd[1], &in_fdset) && - ReadFvwmPacket(fd[1],header, &body) > 0) - { - focus_win = body[0]; - free(body); + if (FD_ISSET(fd[1], &in_fdset) && + ReadFvwmPacket(fd[1], header, &body) > 0) { + focus_win = body[0]; + free(body); #ifdef DEBUG - fprintf(stderr,"[FvwmAuto]: M_FOCUS_CHANGE to 0x%08lx\n",focus_win); + fprintf(stderr, + "[FvwmAuto]: M_FOCUS_CHANGE to 0x%08lx\n", + focus_win); #endif - } - if (((FD_ISSET(fd[1], &in_fdset)==0) == (delay!=NULL)) && - /* new message and timeout==0 or */ - /* no message and timeout>0 */ - focus_win!=last_win) /* there's sth. to do */ - { - if (last_win && leave_fn) /* if last_win isn't the root */ - { - SendInfo(fd,leave_fn,last_win); + } + if (((FD_ISSET(fd[1], &in_fdset) == 0) == (delay != NULL)) && + /* new message and timeout==0 or */ + /* no message and timeout>0 */ + focus_win != last_win) { /* there's sth. to do */ + if (last_win && + leave_fn) { /* if last_win isn't the root */ + SendInfo(fd, leave_fn, last_win); #ifdef DEBUG - fprintf(stderr,"[FvwmAuto]: executing %s on window 0x%08lx\n",leave_fn,focus_win); + fprintf(stderr, + "[FvwmAuto]: executing %s on window " + "0x%08lx\n", + leave_fn, focus_win); #endif - } - if (focus_win && enter_fn) /* if focus_win isn't the root */ - { - SendInfo(fd,enter_fn,focus_win); + } + if (focus_win && + enter_fn) { /* if focus_win isn't the root */ + SendInfo(fd, enter_fn, focus_win); #ifdef DEBUG - fprintf(stderr,"[FvwmAuto]: executing %s on window 0x%08lx\n",enter_fn,focus_win); + fprintf(stderr, + "[FvwmAuto]: executing %s on window " + "0x%08lx\n", + enter_fn, focus_win); #endif - } - last_win = focus_win; /* switch to wait mode again */ + } + last_win = focus_win; /* switch to wait mode again */ + } } - } - return 0; + return 0; } - - - Index: fvwm/modules/FvwmBacker/FvwmBacker.1 =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmBacker/FvwmBacker.1,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmBacker/FvwmBacker.1 --- fvwm/modules/FvwmBacker/FvwmBacker.1 +++ fvwm/modules/FvwmBacker/FvwmBacker.1 @@ -1,60 +1,51 @@ .\" $OpenBSD: FvwmBacker.1,v 1.1.1.1 2006/11/26 10:53:43 matthieu Exp $ .\" t .\" @(#)FvwmBacker.1 11/8/94 -.TH FvwmBacker 1 "September 8th, 1994" 0.1 +.TH FVWMBACKER 1 "September 8, 1994" "0.1" "FVWM Modules" .UC .SH NAME FvwmBacker \- the FVWM background changer module .SH SYNOPSIS FvwmBacker is spawned by fvwm, so no command line invocation will work. - .SH DESCRIPTION - The FvwmBacker module provides functionality to change the background when changing desktops. Any command can be executed to change the backgrounds. Actually, any arbitrary command can be sent to fvwm to execute, so you could also do things such as changing window border colors, etc. - .SH COPYRIGHTS The FvwmBacker module is the original work of Mike Finger. - -Copyright 1994, Mike Finger. The author makes no guarantees or -warranties of any kind about the use of this module. Use this modules +.PP +Copyright 1994, Mike Finger. The author makes no guarantees or +warranties of any kind about the use of this module. Use this module at your own risk. You may freely use this module or any portion of it for any purpose as long as the copyright is kept intact. - .SH INITIALIZATION During initialization, \fIFvwmBacker\fP will scan the same configuration file that FVWM used during startup to find the options that pertain to it. These options are discussed in a later section. - .SH INVOCATION FvwmBacker can be invoked by fvwm during initialization by inserting the line 'Module FvwmBacker' in the .fvwmrc file. - +.PP FvwmBacker must reside in a directory that is listed in the ModulePath option of FVWM for it to be executed by FVWM. - .SH CONFIGURATION OPTIONS The following is the only supported option at present: - .IP "*FvwmBackerDesk \fIDeskNumber command\fP" Specifies the \fIcommand\fP to execute when the specified \fIDeskNumber\fP becomes active. - +.PP If the command begins with \fI-solid\fP FvwmBacker uses the next argument as a color in the X database and sets the background to that color without generating a system call to xsetroot (only single word color names may be used). Otherwise the command is sent to fvwm to execute. - .SH SAMPLE CONFIGURATION The following are excepts from an .fvwmrc file which describe FvwmBacker initialization commands: - -.nf -.sp +.PP +.EX #### # Set Up Backgrounds for different desktops. #### @@ -62,12 +53,10 @@ FvwmBacker initialization commands: *FvwmBackerDesk 1 -solid midnightblue *FvwmBackerDesk 2 -solid yellow *FvwmBackerDesk 3 Exec xpmroot /usr/include/X11/pixmaps/background2.xpm -.sp -.fi - +.EE .SH AUTHOR Mike Finger (mfinger@mermaid.micro.umn.edu) - (Mike_Finger@atk.com) - (doodman on IRC, check the #linux channel) -.SH Modified by +.PP +(Mike_Finger@atk.com) +.SH MODIFIED BY Andrew Davison (davison@cs.monash.edu.au) Index: fvwm/modules/FvwmBacker/FvwmBacker.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmBacker/FvwmBacker.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmBacker/FvwmBacker.c --- fvwm/modules/FvwmBacker/FvwmBacker.c +++ fvwm/modules/FvwmBacker/FvwmBacker.c @@ -25,48 +25,45 @@ * A. Davison * Septmber 1994. */ -#include "config.h" +#include +#include -#include -#include #include +#include +#include #include -#include -#include + +#include "config.h" +#include "../../fvwm/fvwm_sandbox.h" #ifdef HAVE_SYS_SELECT_H #include #endif -#include #include +#include -#ifdef HAVE_SYS_BSDTYPES_H -#include /* Saul */ -#endif /* Saul */ +#endif /* Saul */ +#include #include #include "../../fvwm/module.h" #include "FvwmBacker.h" -#include "Mallocs.h" - -#include unsigned long GetColor(char *color); -typedef struct -{ - int type; /* The command type. - * -1 = no command. - * 0 = command to be spawned - * 1 = a solid color to be set */ - char* cmdStr; /* The command string (Type 0) */ - unsigned long solidColor; /* A solid color after X parsing (Type 1) */ +typedef struct { + int type; /* The command type. + * -1 = no command. + * 0 = command to be spawned + * 1 = a solid color to be set */ + char *cmdStr; /* The command string (Type 0) */ + unsigned long solidColor; /* A solid color after X parsing (Type 1) */ } Command; Command *commands; -int DeskCount=0; +int DeskCount = 0; int Fvwm_fd[2]; int fd_width; @@ -75,104 +72,110 @@ char *Module; /* X Display information. */ -Display* dpy; -Window root; -int screen; +Display *dpy; +Window root; +int screen; -FILE* logFile; +FILE *logFile; /* Comment this out if you don't want a logfile. */ /* #define LOGFILE "/tmp/FvwmBacker.log"*/ - -int main(int argc, char **argv) +int +main(int argc, char **argv) { -char *temp, *s; - char* displayName = NULL; + char *temp, *s; + char *displayName = NULL; - commands=NULL; + commands = NULL; - /* Save the program name for error messages and config parsing */ - temp = argv[0]; - s=strrchr(argv[0], '/'); - if (s != NULL) - temp = s + 1; + /* Save the program name for error messages and config parsing */ + temp = argv[0]; + s = strrchr(argv[0], '/'); + if (s != NULL) + temp = s + 1; - Module=temp; + Module = temp; - if((argc != 6)&&(argc != 7)) { - fprintf(stderr,"%s Version %s should only be executed by fvwm!\n",Module, - VERSION); - exit(1); - } + if ((argc != 6) && (argc != 7)) { + fprintf(stderr, + "%s Version %s should only be executed by fvwm!\n", Module, + VERSION); + exit(1); + } - Fvwm_fd[0] = atoi(argv[1]); - Fvwm_fd[1] = atoi(argv[2]); + Fvwm_fd[0] = atoi(argv[1]); + Fvwm_fd[1] = atoi(argv[2]); - /* Grab the X display information now. */ + /* Grab the X display information now. */ dpy = XOpenDisplay(displayName); - if (!dpy) - { - fprintf(stderr, "%s: unable to open display '%s'\n", - Module, XDisplayName (displayName)); - exit (2); + if (!dpy) { + fprintf(stderr, "%s: unable to open display '%s'\n", Module, + XDisplayName(displayName)); + exit(2); } screen = DefaultScreen(dpy); root = RootWindow(dpy, screen); /* Open a log file if necessary */ -# ifdef LOGFILE - logFile = fopen(LOGFILE,"a"); - fprintf(logFile,"Initialising FvwmBacker\n"); -# endif - - signal (SIGPIPE, DeadPipe); +#ifdef LOGFILE + logFile = fopen(LOGFILE, "a"); + if (logFile != NULL) + fprintf(logFile, "Initialising FvwmBacker\n"); +#endif - /* Parse the config file */ - ParseConfig(); + signal(SIGPIPE, DeadPipe); - fd_width = GetFdWidth(); + /* Parse the config file */ + ParseConfig(); - SetMessageMask(Fvwm_fd,M_NEW_DESK|M_CONFIG_INFO|M_END_CONFIG_INFO); + fd_width = GetFdWidth(); - /* - ** we really only want the current desk, and window list sends it - */ - SendInfo(Fvwm_fd,"Send_WindowList",0); + SetMessageMask(Fvwm_fd, M_NEW_DESK | M_CONFIG_INFO | M_END_CONFIG_INFO); + /* + ** we really only want the current desk, and window list sends it + */ + SendInfo(Fvwm_fd, "Send_WindowList", 0); - /* Recieve all messages from Fvwm */ - EndLessLoop(); + /* Recieve all messages from Fvwm */ + EndLessLoop(); - /* Should never get here! */ - return 1; + /* Should never get here! */ + return 1; } /****************************************************************************** EndLessLoop - Read until we get killed, blocking when can't read ******************************************************************************/ -void EndLessLoop() +void +EndLessLoop() { -fd_set readset; -struct timeval tv; - - while(1) { - FD_ZERO(&readset); - FD_SET(Fvwm_fd[1],&readset); - tv.tv_sec=0; - tv.tv_usec=0; - - if (!select(fd_width,SELECT_TYPE_ARG234 &readset,NULL,NULL,&tv)) { - FD_ZERO(&readset); - FD_SET(Fvwm_fd[1],&readset); - select(fd_width,SELECT_TYPE_ARG234 &readset,NULL,NULL,NULL); - } - - if (!FD_ISSET(Fvwm_fd[1],&readset)) continue; - ReadFvwmPipe(); - } + fd_set readset; + struct timeval tv; + + sandbox_x11_only("FvwmBacker"); + + while (1) { + FD_ZERO(&readset); + FD_SET(Fvwm_fd[1], &readset); + tv.tv_sec = 0; + tv.tv_usec = 0; + + if (!select(fd_width, SELECT_TYPE_ARG234 & readset, NULL, NULL, + &tv)) { + FD_ZERO(&readset); + FD_SET(Fvwm_fd[1], &readset); + select(fd_width, SELECT_TYPE_ARG234 & readset, NULL, + NULL, NULL); + } + + if (!FD_ISSET(Fvwm_fd[1], &readset)) + continue; + ReadFvwmPipe(); + } } /****************************************************************************** @@ -180,75 +183,69 @@ struct timeval tv; Originally Loop() from FvwmIdent: Copyright 1994, Robert Nation and Nobutaka Suzuki. ******************************************************************************/ -void ReadFvwmPipe() +void +ReadFvwmPipe() { - int count; - unsigned long header[HEADER_SIZE],*body; - - body = NULL; - if((count = ReadFvwmPacket(Fvwm_fd[1],header,&body)) > 0) - { - ProcessMessage(header[1],body); - free(body); - } -} + int count; + unsigned long header[HEADER_SIZE], *body; + body = NULL; + if ((count = ReadFvwmPacket(Fvwm_fd[1], header, &body)) > 0) { + ProcessMessage(header[1], body); + free(body); + } +} /****************************************************************************** ProcessMessage - Process the message coming from Fvwm Skeleton based on processmessage() from FvwmIdent: Copyright 1994, Robert Nation and Nobutaka Suzuki. ******************************************************************************/ -void ProcessMessage(unsigned long type,unsigned long *body) +void +ProcessMessage(unsigned long type, unsigned long *body) { - if (type==M_NEW_DESK) - { - if (body[0]>DeskCount || commands[body[0]].type == -1) - { - return; - } + if (type == M_NEW_DESK) { + if (body[0] > DeskCount || commands[body[0]].type == -1) { + return; + } #ifdef LOGFILE - fprintf(logFile,"Desk: %d\n",body[0]); - fprintf(logFile,"Command type: %d\n",commands[body[0]].type); - if (commands[body[0]].type == 0) - fprintf(logFile,"Command String: %s\n",commands[body[0]].cmdStr); - else if (commands[body[0]].type == 1) - fprintf(logFile,"Color Number: %d\n",commands[body[0]].solidColor); - else if (commands[body[0]].type == -1) - fprintf(logFile,"No Command\n"); - else - { - fprintf(logFile,"Illegal command type !\n"); - exit(1); - } - fflush(logFile); -# endif - + fprintf(logFile, "Desk: %d\n", body[0]); + fprintf(logFile, "Command type: %d\n", commands[body[0]].type); + if (commands[body[0]].type == 0) + fprintf(logFile, "Command String: %s\n", + commands[body[0]].cmdStr); + else if (commands[body[0]].type == 1) + fprintf(logFile, "Color Number: %d\n", + commands[body[0]].solidColor); + else if (commands[body[0]].type == -1) + fprintf(logFile, "No Command\n"); + else { + fprintf(logFile, "Illegal command type !\n"); + exit(1); + } + fflush(logFile); +#endif - if (commands[body[0]].type == 1) - { - /* Process a solid color request */ + if (commands[body[0]].type == 1) { + /* Process a solid color request */ - XSetWindowBackground(dpy, root, commands[body[0]].solidColor); - XClearWindow(dpy, root); - XFlush(dpy); - /* XSetWindowBackground(dpy, root, commands[body[0]].solidColor); - */ + XSetWindowBackground( + dpy, root, commands[body[0]].solidColor); + XClearWindow(dpy, root); + XFlush(dpy); + /* XSetWindowBackground(dpy, root, + * commands[body[0]].solidColor); + */ -# ifdef LOGFILE - fprintf(logFile,"Color set.\n"); - fflush(logFile); -# endif - } - else if(commands[body[0]].cmdStr != NULL) - { -#if 0 - system(commands[body[0]].cmdStr); -#else /* much more useful: */ - SendFvwmPipe(commands[body[0]].cmdStr, (unsigned long)0); +#ifdef LOGFILE + fprintf(logFile, "Color set.\n"); + fflush(logFile); #endif + } else if (commands[body[0]].cmdStr != NULL) { + SendFvwmPipe( + commands[body[0]].cmdStr, (unsigned long)0); + } } - } } /****************************************************************************** @@ -256,34 +253,38 @@ void ProcessMessage(unsigned long type,unsigned long *body) Based on SendInfo() from FvwmIdent: Copyright 1994, Robert Nation and Nobutaka Suzuki. ******************************************************************************/ -void SendFvwmPipe(char *message,unsigned long window) +void +SendFvwmPipe(char *message, unsigned long window) { -int w; -char *hold,*temp,*temp_msg; - hold=message; - - while(1) { - temp=strchr(hold,','); - if (temp!=NULL) { - temp_msg=malloc(temp-hold+1); - strncpy(temp_msg,hold,(temp-hold)); - temp_msg[(temp-hold)]='\0'; - hold=temp+1; - } else temp_msg=hold; - - write(Fvwm_fd[0],&window, sizeof(unsigned long)); - - w=strlen(temp_msg); - write(Fvwm_fd[0],&w,sizeof(int)); - write(Fvwm_fd[0],temp_msg,w); - - /* keep going */ - w=1; - write(Fvwm_fd[0],&w,sizeof(int)); - - if(temp_msg!=hold) free(temp_msg); - else break; - } + int w; + char *hold, *temp, *temp_msg; + hold = message; + + while (1) { + temp = strchr(hold, ','); + if (temp != NULL) { + temp_msg = malloc(temp - hold + 1); + strncpy(temp_msg, hold, (temp - hold)); + temp_msg[(temp - hold)] = '\0'; + hold = temp + 1; + } else + temp_msg = hold; + + write(Fvwm_fd[0], &window, sizeof(unsigned long)); + + w = strlen(temp_msg); + write(Fvwm_fd[0], &w, sizeof(int)); + write(Fvwm_fd[0], temp_msg, w); + + /* keep going */ + w = 1; + write(Fvwm_fd[0], &w, sizeof(int)); + + if (temp_msg != hold) + free(temp_msg); + else + break; + } } /*********************************************************************** @@ -291,9 +292,10 @@ char *hold,*temp,*temp_msg; Based on DeadPipe() from FvwmIdent: Copyright 1994, Robert Nation and Nobutaka Suzuki. **********************************************************************/ -void DeadPipe(int nonsense) +void +DeadPipe(int nonsense) { - exit(1); + exit(1); } /****************************************************************************** @@ -301,86 +303,83 @@ void DeadPipe(int nonsense) Based on part of main() from FvwmIdent: Copyright 1994, Robert Nation and Nobutaka Suzuki. ******************************************************************************/ -void ParseConfig() +void +ParseConfig() { - char line2[40]; - char *tline; - - sprintf(line2,"*%sDesk",Module); - - GetConfigLine(Fvwm_fd,&tline); - - while(tline != (char *)0) - { - if(strlen(tline)>1) - { - if(strncasecmp(tline,line2,strlen(line2))==0) - AddCommand(&tline[strlen(line2)]); - } - GetConfigLine(Fvwm_fd,&tline); - } + char line2[40]; + char *tline; + + snprintf(line2, sizeof(line2), "*%sDesk", Module); + + GetConfigLine(Fvwm_fd, &tline); + + while (tline != (char *)0) { + if (strlen(tline) > 1) { + if (strncasecmp(tline, line2, strlen(line2)) == 0) + AddCommand(&tline[strlen(line2)]); + } + GetConfigLine(Fvwm_fd, &tline); + } } /****************************************************************************** AddCommand - Add a command to the correct spot on the dynamic array. ******************************************************************************/ -void AddCommand(char *string) +void +AddCommand(char *string) { -char *temp; -int num; - temp=string; - while(isspace(*temp)) temp++; - num=atoi(temp); - while(!isspace(*temp)) temp++; - while(isspace(*temp)) temp++; - if (DeskCount<1) { - commands=(Command*)safemalloc((num+1)*sizeof(Command)); - while(DeskCountDeskCount) { - commands=(Command*)realloc(commands,(num+1)*sizeof(Command)); - while(DeskCount DeskCount) { + commands = (Command *)xrealloc( + (char *)commands, (num + 1) * sizeof(Command)); + while (DeskCount < num + 1) + commands[DeskCount++].type = -1; + } + } + + if (strncmp(temp, "-solid", 6) == 0) { + char *color; + char *tmp; /* Process a solid color request */ color = &temp[7]; while (isspace(*color)) color++; - tmp= color; + tmp = color; while (!isspace(*tmp)) tmp++; *tmp = 0; commands[num].type = 1; commands[num].solidColor = (!color || !*color) ? - BlackPixel(dpy, screen) : - GetColor(color); + BlackPixel(dpy, screen) : + GetColor(color); #ifdef LOGFILE - fprintf(logFile,"Adding color: %s as number %d to desk %d\n", - color,commands[num].solidColor, num); + fprintf(logFile, "Adding color: %s as number %d to desk %d\n", + color, commands[num].solidColor, num); fflush(logFile); #endif - } - else - { + } else { #ifdef LOGFILE - fprintf(logFile,"Adding command: %s to desk %d\n",temp, num); + fprintf(logFile, "Adding command: %s to desk %d\n", temp, num); fflush(logFile); #endif commands[num].type = 0; - commands[num].cmdStr = (char *)safemalloc(strlen(temp)+1); - strcpy(commands[num].cmdStr,temp); + size_t cmd_len = strlen(temp); + commands[num].cmdStr = (char *)xmalloc(cmd_len + 1); + strlcpy(commands[num].cmdStr, temp, cmd_len + 1); } - } Index: fvwm/modules/FvwmBacker/FvwmBacker.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmBacker/FvwmBacker.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmBacker/FvwmBacker.h --- fvwm/modules/FvwmBacker/FvwmBacker.h +++ fvwm/modules/FvwmBacker/FvwmBacker.h @@ -1,4 +1,4 @@ -/* FvwmBacker Module for Fvwm. +/* FvwmBacker Module for Fvwm. * * Copyright 1994, Mike Finger (mfinger@mermaid.micro.umn.edu or * Mike_Finger@atk.com) @@ -18,14 +18,14 @@ * own risk. Permission to use this program for any purpose is given, * as long as the copyright is kept intact. */ -#include "../../libs/fvwmlib.h" +#include "../../libs/fvwmlib.h" /* Function Prototypes */ void EndLessLoop(); void ReadFvwmPipe(); -void ProcessMessage(unsigned long type,unsigned long *body); -void SendFvwmPipe(char *message,unsigned long window); +void ProcessMessage(unsigned long type, unsigned long *body); +void SendFvwmPipe(char *message, unsigned long window); void DeadPipe(int nonsense); void ParseConfig(void); void AddCommand(char *string); Index: fvwm/modules/FvwmBacker/Makefile =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmBacker/Makefile,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmBacker/Makefile --- fvwm/modules/FvwmBacker/Makefile +++ fvwm/modules/FvwmBacker/Makefile @@ -5,7 +5,7 @@ .PATH: ${DIST}/modules/FvwmBacker PROG= FvwmBacker -SRCS= FvwmBacker.c Mallocs.c root_bits.c +SRCS= FvwmBacker.c root_bits.c LDADD+= -lXpm ${XLIB} BINDIR= ${FVWMLIBDIR} Index: fvwm/modules/FvwmBacker/Mallocs.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmBacker/Mallocs.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmBacker/Mallocs.c --- fvwm/modules/FvwmBacker/Mallocs.c +++ /dev/null @@ -1,55 +0,0 @@ -/* FvwmWinList Module for Fvwm. - * - * Copyright 1994, Mike Finger (mfinger@mermaid.micro.umn.edu or - * Mike_Finger@atk.com) - * - * The author makes not guarantees or warantees, either express or - * implied. Feel free to use any contained here for any purpose, as long - * and this and any other applicible copyrights are kept intact. - - * The functions in this source file that are based on part of the FvwmIdent - * module for Fvwm are noted by a small copyright atop that function, all others - * are copyrighted by Mike Finger. For those functions modified/used, here is - * the full, original copyright: - * - * Copyright 1994, Robert Nation and Nobutaka Suzuki. - * No guarantees or warantees or anything - * are provided or implied in any way whatsoever. Use this program at your - * own risk. Permission to use this program for any purpose is given, - * as long as the copyright is kept intact. */ - -#include "config.h" -#include -#include -#include -#include -#include -#include "../../libs/fvwmlib.h" - -extern char *Module; - -/****************************************************************************** - saferealloc - safely reallocate memory or exit if fails. (Doesn't work right) -******************************************************************************/ -char *saferealloc(char *ptr, int length) -{ -char *newptr; - - if(length <=0) length=1; - - newptr=realloc(ptr,length); - if (ptr == (char *)0) { - fprintf(stderr,"%s:realloc failed",Module); - exit(1); - } - return ptr; -} - -void UpdateString(char **string,char *value) -{ - if (value==NULL) return; - if (*string==NULL) *string=safemalloc(strlen(value)+1); - else *string=(char *)realloc(*string,strlen(value)+1); - strcpy(*string,value); -} - Index: fvwm/modules/FvwmBacker/Mallocs.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmBacker/Mallocs.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmBacker/Mallocs.h --- fvwm/modules/FvwmBacker/Mallocs.h +++ /dev/null @@ -1,24 +0,0 @@ -/* FvwmBacker Module for Fvwm. - * - * Copyright 1994, Mike Finger (mfinger@mermaid.micro.umn.edu or - * Mike_Finger@atk.com) - * - * The author makes not guarantees or warantees, either express or - * implied. Feel free to use any contained here for any purpose, as long - * and this and any other applicible copyrights are kept intact. - - * The functions in this source file that are based on part of the FvwmIdent - * module for Fvwm are noted by a small copyright atop that function, all others - * are copyrighted by Mike Finger. For those functions modified/used, here is - * the full, original copyright: - * - * Copyright 1994, Robert Nation and Nobutaka Suzuki. - * No guarantees or warantees or anything - * are provided or implied in any way whatsoever. Use this program at your - * own risk. Permission to use this program for any purpose is given, - * as long as the copyright is kept intact. */ - -/* Function Prototypes */ -char *safemalloc(int length); -char *saferealloc(char *ptr, int length); -void UpdateString(char **string,char *value); Index: fvwm/modules/FvwmBanner/FvwmBanner.1 =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmBanner/FvwmBanner.1,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmBanner/FvwmBanner.1 --- fvwm/modules/FvwmBanner/FvwmBanner.1 +++ fvwm/modules/FvwmBanner/FvwmBanner.1 @@ -1,41 +1,33 @@ .\" $OpenBSD: FvwmBanner.1,v 1.1.1.1 2006/11/26 10:53:43 matthieu Exp $ .\" t .\" @(#)FvwmBanner.1 1/12/94 -.TH FvwmBanner 1 "Jan 28, 1994" 1.20 +.TH FVWMBANNER 1 "January 28, 1994" "1.20" "FVWM Modules" .UC .SH NAME FvwmBanner \- the FVWM Banner .SH SYNOPSIS FvwmBanner is intended to be spawned by fvwm. - .SH DESCRIPTION -The FvwmInitBanner displays an Fvwm Logo in the center of the screen -for 3 seconds. - +The FvwmInitBanner displays an Fvwm Logo in the center of the screen for 3 +seconds. .SH COPYRIGHTS None. - .SH INITIALIZATION Nothing interesting. - .SH INVOCATION -FvwmBanner can be invoked by binding the action 'Module FvwmBanner' to -a menu or key-stroke in the .fvwmrc file. Fvwm will search directory +FvwmBanner can be invoked by binding the action 'Module FvwmBanner' to a +menu or key-stroke in the .fvwmrc file. Fvwm will search the directory specified in the ModulePath configuration option to attempt to locate -FvwmBanner. Although nothing keeps you from launching FvwmBanner at -start-up time, you probably don't want to. You can also give it an -optional file parameter, like 'FvwmBanner doomface.xpm' or spcify an -alternate default pixmap via configuration options. - +FvwmBanner. Although nothing keeps you from launching FvwmBanner at +start-up time, you probably do not want to. +.PP +You can also give it an optional file parameter, for example +\fBFvwmBanner doomface.xpm\fP, +or specify an alternate default pixmap via configuration options. .SH CONFIGURATION OPTIONS - .IP "*FvwmBannerPixmap \fIfile\fP" Tells the module to display \fIfile\fP instead of the built in pixmap. - .IP "*FvwmBannerTimeout \fIsec\fP" Tells the module to display for \fIsec\fP seconds instead of default of 3. - - .SH AUTHOR -Robert Nation - +Robert Nation Index: fvwm/modules/FvwmBanner/FvwmBanner.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmBanner/FvwmBanner.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmBanner/FvwmBanner.c --- fvwm/modules/FvwmBanner/FvwmBanner.c +++ fvwm/modules/FvwmBanner/FvwmBanner.c @@ -6,56 +6,48 @@ ***************************************************************************/ #include "config.h" -#ifdef HAVE_SYS_BSDTYPES_H -#include /* Saul */ +#include "../../fvwm/fvwm_sandbox.h" #endif -#include -#include +#include +#include + #include +#include +#include #include -#include -#include #ifdef HAVE_SYS_SELECT_H #include #endif -#include -#include -#include - -#include #include #include +#include #include - #include - - -#include "../../libs/fvwmlib.h" +#include +#include +#include #include "../../icons/fvwm2_big.xpm" -#if 0 -#include "../../icons/k2.xpm" -#endif /* 0 */ - +#include "../../libs/fvwmlib.h" typedef struct _XpmIcon { - Pixmap pixmap; - Pixmap mask; - XpmAttributes attributes; -} XpmIcon; + Pixmap pixmap; + Pixmap mask; + XpmAttributes attributes; +} XpmIcon; /************************************************************************** * A few function prototypes **************************************************************************/ void RedrawWindow(void); void GetXPMData(char **); -void GetXPMFile(char *,char *); +void GetXPMFile(char *, char *); void change_window_name(char *str); -int flush_expose (Window w); -static void parseOptions (int fd[2]); +int flush_expose(Window w); +static void parseOptions(int fd[2]); XpmIcon view; Window win; @@ -66,7 +58,7 @@ char *myName = NULL; int timeout = 3000000; /* default time of 3 seconds */ -Display *dpy; /* which display are we talking to */ +Display *dpy; /* which display are we talking to */ Window Root; int screen; int x_fd; @@ -74,176 +66,160 @@ int d_depth; int ScreenWidth, ScreenHeight; XSizeHints mysizehints; Pixel back_pix, fore_pix; -GC NormalGC,FGC; +GC NormalGC, FGC; static Atom wm_del_win; Colormap colormap; -#define MW_EVENTS (ExposureMask | ButtonReleaseMask) +#define MW_EVENTS (ExposureMask | ButtonReleaseMask) /**************************************************************************** * * Creates an icon window as needed * ****************************************************************************/ -int main(int argc, char **argv) +int +main(int argc, char **argv) { - char *display_name = NULL, *string = NULL; - int retval = 0; - XEvent Event; - fd_set in_fdset; - int fd_width ; - struct timeval value; - int fd[2]; - - fd_width = GetFdWidth(); - - /* Save our program name - for error messages */ - string = strrchr (argv[0], '/'); - if (string != (char *) 0) string++; - - myName = safemalloc (strlen (string) + 1); - strcpy (myName, string); - - if(argc>=3) - { - /* sever our connection with fvwm, if we have one. */ - fd[0] = atoi(argv[1]); - fd[1] = atoi(argv[2]); - -#if 0 - if(fd[0]>0)close(fd[0]); - if(fd[1]>0)close(fd[1]); -#endif /* 0 */ - } - else - { - fprintf (stderr, - "%s version %s should only be executed by fvwm!\n", - myName, - VERSION); - exit(1); - } - - if (argc > 6) { - pixmapName = safemalloc (strlen (argv[6]) + 1); - strcpy (pixmapName, argv[6]); - } - - /* Open the display */ - if (!(dpy = XOpenDisplay(display_name))) - { - fprintf(stderr,"FvwmBanner: can't open display %s", - XDisplayName(display_name)); - exit (1); - } - screen= DefaultScreen(dpy); - Root = RootWindow(dpy, screen); - colormap = XDefaultColormap(dpy,screen); - d_depth = DefaultDepth(dpy, screen); - x_fd = XConnectionNumber(dpy); - - ScreenHeight = DisplayHeight(dpy,screen); - ScreenWidth = DisplayWidth(dpy,screen); - - parseOptions(fd); - - /* Get the xpm banner */ - if (pixmapName) - GetXPMFile(pixmapName,pixmapPath); - else -#if 0 - if(d_depth > 4) - GetXPMData(k2_xpm); - else -#endif /* 0 */ - GetXPMData(fvwm2_big_xpm); - - /* Create a window to hold the banner */ - mysizehints.flags= - USSize|USPosition|PWinGravity|PResizeInc|PBaseSize|PMinSize|PMaxSize; - /* subtract one for the right/bottom border */ - mysizehints.width = view.attributes.width; - mysizehints.height=view.attributes.height; - mysizehints.width_inc = 1; - mysizehints.height_inc = 1; - mysizehints.base_height = mysizehints.height; - mysizehints.base_width = mysizehints.width; - mysizehints.min_height = mysizehints.height; - mysizehints.min_width = mysizehints.width; - mysizehints.max_height = mysizehints.height; - mysizehints.max_width = mysizehints.width; - mysizehints.win_gravity = NorthWestGravity; - - mysizehints.x = (ScreenWidth - view.attributes.width)/2; - mysizehints.y = (ScreenHeight - view.attributes.height)/2; - - win = XCreateSimpleWindow(dpy,Root,mysizehints.x,mysizehints.y, - mysizehints.width,mysizehints.height, - 0,fore_pix ,None); - - - /* Set assorted info for the window */ - XSetTransientForHint(dpy,win,Root); - wm_del_win = XInternAtom(dpy,"WM_DELETE_WINDOW",False); - XSetWMProtocols(dpy,win,&wm_del_win,1); - - XSetWMNormalHints(dpy,win,&mysizehints); - change_window_name("FvwmBanner"); - - XSetWindowBackgroundPixmap(dpy,win,view.pixmap); + char *display_name = NULL, *string = NULL; + int retval = 0; + XEvent Event; + fd_set in_fdset; + int fd_width; + struct timeval value; + int fd[2]; + + fd_width = GetFdWidth(); + + /* Save our program name - for error messages */ + string = strrchr(argv[0], '/'); + if (string != (char *)0) + string++; + else + string = argv[0]; + + size_t name_len = strlen(string); + myName = xmalloc(name_len + 1); + strlcpy(myName, string, name_len + 1); + + if (argc >= 3) { + /* sever our connection with fvwm, if we have one. */ + fd[0] = atoi(argv[1]); + fd[1] = atoi(argv[2]); + } else { + fprintf(stderr, + "%s version %s should only be executed by fvwm!\n", myName, + VERSION); + exit(1); + } + + if (argc > 6) { + size_t pixmap_len = strlen(argv[6]); + pixmapName = xmalloc(pixmap_len + 1); + strlcpy(pixmapName, argv[6], pixmap_len + 1); + } + + /* Open the display */ + if (!(dpy = XOpenDisplay(display_name))) { + fprintf(stderr, "FvwmBanner: can't open display %s", + XDisplayName(display_name)); + exit(1); + } + screen = DefaultScreen(dpy); + Root = RootWindow(dpy, screen); + colormap = XDefaultColormap(dpy, screen); + d_depth = DefaultDepth(dpy, screen); + x_fd = XConnectionNumber(dpy); + + ScreenHeight = DisplayHeight(dpy, screen); + ScreenWidth = DisplayWidth(dpy, screen); + + parseOptions(fd); + + /* Get the xpm banner */ + if (pixmapName) + GetXPMFile(pixmapName, pixmapPath); + else + GetXPMData(fvwm2_big_xpm); + + /* Create a window to hold the banner */ + mysizehints.flags = USSize | USPosition | PWinGravity | PResizeInc | + PBaseSize | PMinSize | PMaxSize; + /* subtract one for the right/bottom border */ + mysizehints.width = view.attributes.width; + mysizehints.height = view.attributes.height; + mysizehints.width_inc = 1; + mysizehints.height_inc = 1; + mysizehints.base_height = mysizehints.height; + mysizehints.base_width = mysizehints.width; + mysizehints.min_height = mysizehints.height; + mysizehints.min_width = mysizehints.width; + mysizehints.max_height = mysizehints.height; + mysizehints.max_width = mysizehints.width; + mysizehints.win_gravity = NorthWestGravity; + + mysizehints.x = (ScreenWidth - view.attributes.width) / 2; + mysizehints.y = (ScreenHeight - view.attributes.height) / 2; + + win = XCreateSimpleWindow(dpy, Root, mysizehints.x, mysizehints.y, + mysizehints.width, mysizehints.height, 0, fore_pix, None); + + /* Set assorted info for the window */ + XSetTransientForHint(dpy, win, Root); + wm_del_win = XInternAtom(dpy, "WM_DELETE_WINDOW", False); + XSetWMProtocols(dpy, win, &wm_del_win, 1); + + XSetWMNormalHints(dpy, win, &mysizehints); + change_window_name("FvwmBanner"); + + XSetWindowBackgroundPixmap(dpy, win, view.pixmap); #ifdef SHAPE - if(view.mask != None) - XShapeCombineMask(dpy, win, ShapeBounding,0,0,view.mask, ShapeSet); + if (view.mask != None) + XShapeCombineMask( + dpy, win, ShapeBounding, 0, 0, view.mask, ShapeSet); #endif - XMapWindow(dpy,win); - XSync(dpy,0); -#if 0 - usleep(timeout); -#else - XSelectInput(dpy,win,ButtonReleaseMask); - /* Display the window */ - value.tv_usec = timeout % 1000000; - value.tv_sec = timeout / 1000000; - while(1) - { - FD_ZERO(&in_fdset); - FD_SET(x_fd,&in_fdset); - - if(!XPending(dpy)) - - retval=select(fd_width,SELECT_TYPE_ARG234 &in_fdset, 0, 0, &value); - - if (retval==0) - { - XDestroyWindow(dpy,win); - XSync(dpy,0); - exit(0); - } - - if(FD_ISSET(x_fd, &in_fdset)) - { - /* read a packet */ - XNextEvent(dpy,&Event); - switch(Event.type) - { - case ButtonRelease: - XDestroyWindow(dpy,win); - XSync(dpy,0); - exit(0); - case ClientMessage: - if (Event.xclient.format==32 && Event.xclient.data.l[0]==wm_del_win) - { - XDestroyWindow(dpy,win); - XSync(dpy,0); - exit(0); - } - default: - break; - } - } - } -#endif /* 0 */ - return 0; + XMapWindow(dpy, win); + XSync(dpy, 0); + XSelectInput(dpy, win, ButtonReleaseMask); + /* Display the window */ + value.tv_usec = timeout % 1000000; + value.tv_sec = timeout / 1000000; + sandbox_x11_only("FvwmBanner"); + + while (1) { + FD_ZERO(&in_fdset); + FD_SET(x_fd, &in_fdset); + + if (!XPending(dpy)) + retval = select(fd_width, SELECT_TYPE_ARG234 & in_fdset, + 0, 0, &value); + + if (retval == 0) { + XDestroyWindow(dpy, win); + XSync(dpy, 0); + exit(0); + } + + if (FD_ISSET(x_fd, &in_fdset)) { + /* read a packet */ + XNextEvent(dpy, &Event); + switch (Event.type) { + case ButtonRelease: + XDestroyWindow(dpy, win); + XSync(dpy, 0); + exit(0); + case ClientMessage: + if (Event.xclient.format == 32 && + Event.xclient.data.l[0] == wm_del_win) { + XDestroyWindow(dpy, win); + XSync(dpy, 0); + exit(0); + } + default: + break; + } + } + } + return 0; } /**************************************************************************** @@ -251,116 +227,108 @@ int main(int argc, char **argv) * Looks for a color XPM icon file * ****************************************************************************/ -void GetXPMData(char **data) +void +GetXPMData(char **data) { - view.attributes.valuemask = XpmReturnPixels| XpmCloseness | XpmExtensions; - view.attributes.closeness = 40000 /* Allow for "similar" colors */; - if(XpmCreatePixmapFromData(dpy, Root, data, - &view.pixmap, &view.mask, - &view.attributes)!=XpmSuccess) - { - fprintf(stderr,"FvwmBanner: ERROR couldn't convert data to pixmap\n"); - exit(1); - } + view.attributes.valuemask = + XpmReturnPixels | XpmCloseness | XpmExtensions; + view.attributes.closeness = 40000 /* Allow for "similar" colors */; + if (XpmCreatePixmapFromData(dpy, Root, data, &view.pixmap, &view.mask, + &view.attributes) != XpmSuccess) { + fprintf(stderr, + "FvwmBanner: ERROR couldn't convert data to pixmap\n"); + exit(1); + } } -void GetXPMFile(char *file, char *path) + +void +GetXPMFile(char *file, char *path) { - char *full_file = NULL; - - view.attributes.valuemask = XpmReturnPixels| XpmCloseness | XpmExtensions; - view.attributes.closeness = 40000 /* Allow for "similar" colors */; - - if (file) - full_file = findIconFile(file,path,R_OK); - - if (full_file) - { - if(XpmReadFileToPixmap(dpy, - Root, - full_file, - &view.pixmap, - &view.mask, - &view.attributes) == XpmSuccess) - { - return; - } - fprintf(stderr,"FvwmBanner: ERROR reading pixmap file\n"); - } - else - fprintf(stderr,"FvwmBanner: ERROR finding pixmap file in PixmapPath\n"); - GetXPMData(fvwm2_big_xpm); + char *full_file = NULL; + + view.attributes.valuemask = + XpmReturnPixels | XpmCloseness | XpmExtensions; + view.attributes.closeness = 40000 /* Allow for "similar" colors */; + + if (file) + full_file = findIconFile(file, path, R_OK); + + if (full_file) { + if (XpmReadFileToPixmap(dpy, Root, full_file, &view.pixmap, + &view.mask, &view.attributes) == XpmSuccess) { + return; + } + fprintf(stderr, "FvwmBanner: ERROR reading pixmap file\n"); + } else + fprintf(stderr, + "FvwmBanner: ERROR finding pixmap file in PixmapPath\n"); + GetXPMData(fvwm2_big_xpm); } -void nocolor(char *a, char *b) +void +nocolor(char *a, char *b) { - fprintf(stderr,"FvwmBanner: can't %s %s\n", a,b); + fprintf(stderr, "FvwmBanner: can't %s %s\n", a, b); } -static void parseOptions (int fd[2]) +static void +parseOptions(int fd[2]) { - char *tline= NULL; - int clength; - - clength = strlen (myName); - - while (GetConfigLine (fd, &tline),tline != NULL) - { - if (strlen (tline) > 1) - { - if (strncasecmp (tline, - CatString3 ("*", myName, "Pixmap"), - clength + 7) ==0) - { - if (pixmapName == (char *) 0) - { - CopyString (&pixmapName, &tline[clength+7]); - if (pixmapName[0] == 0) - { - free (pixmapName); - pixmapName = (char *) 0; - } + char *tline = NULL; + int clength; + + clength = strlen(myName); + + while (GetConfigLine(fd, &tline), tline != NULL) { + if (strlen(tline) > 1) { + if (strncasecmp(tline, + CatString3("*", myName, "Pixmap"), + clength + 7) == 0) { + if (pixmapName == (char *)0) { + CopyString( + &pixmapName, &tline[clength + 7]); + if (pixmapName[0] == 0) { + free(pixmapName); + pixmapName = (char *)0; + } + } + continue; + } + if (strncasecmp(tline, + CatString3("*", myName, "Timeout"), + clength + 8) == 0) { + timeout = atoi(&tline[clength + 8]) * 1000000; + continue; + } + if (strncasecmp(tline, "PixmapPath", 10) == 0) { + CopyString(&pixmapPath, &tline[10]); + if (pixmapPath[0] == 0) { + free(pixmapPath); + pixmapPath = (char *)0; + } + continue; + } + } } - continue; - } - if (strncasecmp (tline, - CatString3 ("*", myName, "Timeout"), - clength + 8) ==0) - { - timeout = atoi(&tline[clength+8]) * 1000000; - continue; - } - if (strncasecmp(tline, "PixmapPath",10)==0) - { - CopyString (&pixmapPath, &tline[10]); - if (pixmapPath[0] == 0) - { - free (pixmapPath); - pixmapPath = (char *) 0; - } - continue; - } - } - } - return; + return; } /************************************************************************** * Change the window name displayed in the title bar. **************************************************************************/ -void change_window_name(char *str) +void +change_window_name(char *str) { - XTextProperty name; - - if (XStringListToTextProperty(&str,1,&name) == 0) - { - fprintf(stderr,"FvwmBanner: cannot allocate window name"); - return; - } - XSetWMName(dpy,win,&name); - XSetWMIconName(dpy,win,&name); - XFree(name.value); -} + XTextProperty name; + if (XStringListToTextProperty(&str, 1, &name) == 0) { + fprintf(stderr, "FvwmBanner: cannot allocate window name"); + return; + } + XSetWMName(dpy, win, &name); + XSetWMIconName(dpy, win, &name); + XFree(name.value); +} /*********************************************************************** * @@ -370,8 +338,8 @@ void change_window_name(char *str) ***********************************************************************/ /*ARGSUSED*/ -void DeadPipe (int nonsense) +void +DeadPipe(int nonsense) { - exit (0); + exit(0); } - Index: fvwm/modules/FvwmButtons/BUGS =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmButtons/BUGS,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmButtons/BUGS --- fvwm/modules/FvwmButtons/BUGS +++ fvwm/modules/FvwmButtons/BUGS @@ -16,30 +16,3 @@ Known bugs as of FvwmButtons-080396: debug on this; DEBUG_HANGON. There has also been reported problems with buttons hanging forever after being pressed, this might be related. - - * When you make the buttonbox small enough (= very small, less than 1x1 - pixel inside relief and padding) it exits. Should make it silently suffer - with grace instead. Update: actually this is a problem with the swallowed - windows, some crash when made 1x1. Otherwise the rest is fixed. - -Known bugs as of FvwmButtons-070396: - - * Action commands are supposed to work also on swallowed windows, but there - is a problem with X. After reparenting, XSelectInput is called with a mask - including ButtonPressMask|ButtonReleaseMask, but evidently no buttonpresses - are received, even though the program (like xload) doesn't use them for - itself. So where is the bottleneck? Send the solution if you got it. - OK, so I need to do SubstructureRedirectMask, and shuffle all the events - onwards... really? No better way? Mmm.. - -Known bugs as of FvwmButtons-040396: - - * There are still some problems related to swallowed windows, but I haven't - found a reliable way to reproduce them. What probably happens is that a - window is created, FvwmButtons gets its name and desides to swallow it, it - is mapped, but before it gets swallowed it fails, thus the reparent code - does a BadWindow. - - * When you kill many swallowed windows quickly, FvwmButtons crashes probably - because after gracefully removing one of it's children it tries to redraw - some other before handling more destroy_requests. Index: fvwm/modules/FvwmButtons/FvwmButtons.1 =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmButtons/FvwmButtons.1,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmButtons/FvwmButtons.1 --- fvwm/modules/FvwmButtons/FvwmButtons.1 +++ fvwm/modules/FvwmButtons/FvwmButtons.1 @@ -1,49 +1,43 @@ .\" $OpenBSD: FvwmButtons.1,v 1.1.1.1 2006/11/26 10:53:44 matthieu Exp $ .\" t # I don't know this stuff, sorry. -Jarl .\" @(#)FvwmButtons.1 1/28/94 -.TH FvwmButtons 1 "Nov 1 1998" +.TH FVWMBUTTONS 1 "November 1, 1998" "2.0.41" "FVWM Modules" .UC .SH NAME FvwmButtons \- the FVWM buttonbox module .SH SYNOPSIS FvwmButtons is spawned by fvwm, so no command line invocation will work. - .SH DESCRIPTION The FvwmButtons module provides a window of buttons which sits on the X terminal's root window. The user can press the buttons at any time, and trigger invocation of a user-specified command by the window manager. FvwmButtons only works when fvwm is used as the window manager. - +.PP The buttonbox can be of any configuration or geometry, and can have -monochrome or color icons to represent the actions which would be -invoked. - +monochrome or color icons to represent the actions which would be invoked. .SH INITIALIZATION During initialization, \fIFvwmButtons\fP will search for a configuration -file which describes the buttonbox geometry, color, icons, and -actions. The format of -this files will be described later. The configuration file will be the -one which fvwm used during its initialization. - -To use FvwmButtons with several different configurations, you can -invoke FvwmButtons with an optional parameter, which it will use +file which describes the buttonbox geometry, color, icons, and actions. The +format of this file will be described later. The configuration file will be +the one which fvwm used during its initialization. +.PP +To use FvwmButtons with several different configurations, you can invoke +FvwmButtons with an optional parameter, which it will use as its name instead (e.g "Module FvwmButtons SomeButtons"). SomeButtons will then read only the lines in the configuration file starting with "*SomeButtons", and not the lines belonging to FvwmButtons. - +.PP You can also specify an optional configuration file to use instead of the default fvwm configuration file, by giving a second argument which is a filename. This will override the setting "*FvwmButtonsFile", see below. - .SH INVOCATION FvwmButtons can be invoked by inserting the line 'Module FvwmButtons' in the .fvwmrc file. This should be placed in the InitFunction if FvwmButtons -is to be spawned during fvwm's initialization, or can be bound to a -menu or mouse button or keystroke to invoke it later. Fvwm will search -directory specified in the ModulePath configuration option to attempt -to locate FvwmButtons. - +is to be spawned during fvwm's initialization, or can be bound to a menu +or mouse button or keystroke to invoke it later. Fvwm will search directory +specified in the ModulePath configuration option to attempt to locate +FvwmButtons. .SH CONFIGURATION OPTIONS The following options int the .fvwmrc file are understood by FvwmButtons: .IP "*FvwmButtonsBack \fIcolor\fP" @@ -123,10 +117,11 @@ Specifies an fvwm command to be executed when the button is activated by pressing return or a mouse button. The \fIcommand\fP needs to be quoted if it contains a comma or a closing parenthesis. The current options are: - -Mouse \fIn\fP - this action is only executed for mouse button \fIn\fP. -One actions can be defined for each mouse button, in addition to the -general action. +.RS +.IP "Mouse \fIn\fP" +This action is only executed for mouse button \fIn\fP. One action can be +defined for each mouse button, in addition to the general action. +.RE .IP " Back \fIcolor\fP" Specifies the background color to be used drawing this box. A relief color and a shadow color will also be calculated from this. @@ -143,24 +138,24 @@ be set with \fITitle(flags)\fP and \fISwallow(flags)\fP. You should also specify either "Columns \fIwidth\fP" or "Rows \fIheight\fP", or "Rows 2" will be assumed for purpose of arranging the buttons inside the container. For an example, see the \fISample configuration\fP section. - +.PP The container button itself (separate from the contents) can take format -options like -\fIFrame\fP and \fIPadding\fP, and commands can be bound to it. This means -you can make a sensitive relief around a container, like - - *FvwmButtons(2x2, Frame 5, Padding 2 2, Action Beep,\\ - Container(Frame 1)) - +options like \fIFrame\fP and \fIPadding\fP, and commands can be bound to it. +This means you can make a sensitive relief around a container, like +.EX +*FvwmButtons(2x2, Frame 5, Padding 2 2, Action Beep,\ + Container(Frame 1)) +.EE +.PP Typically you will want to at least give the container a size setting \fIwidth\fPx\fIheight\fP. - .IP " End" Specifies that no more buttons are defined for the current container, and further buttons will be put in the container's parent. This option should be given on a line by itself, i.e - - *FvwmButtons(End) +.EX +*FvwmButtons(End) +.EE .IP " Font \fIfontname\fP" Specifies that the font \fIfontname\fP is to be used for labeling this button. .IP " Fore \fIcolor\fP" @@ -213,60 +208,62 @@ larger sizes. Causes FvwmButtons to execute \fIcommand\fP, and when a window matching the name \fIhangon\fP appears, it is captured and swallowed into this button. An example: - - *FvwmButtons(Swallow XClock 'Exec xclock &') - -will take the first window whose name, class or resource is "XClock" and -display it in the button. Modules can be swallowed by specifying -the module instead of 'Exec whatever', like: - - *FvwmButtons(Swallow "FvwmPager" "FvwmPager 0 0") - +.EX +*FvwmButtons(Swallow XClock 'Exec xclock &') +.EE +.PP +This takes the first window whose name, class or resource is "XClock" and +displays it in the button. Modules can be swallowed by specifying the module +instead of 'Exec whatever', like: +.EX +*FvwmButtons(Swallow "FvwmPager" "FvwmPager 0 0") +.EE +.PP The flags that can be given to swallow are: - -NoClose / Close - +.RS +.IP "NoClose / Close" Specifies whether the swallowed program in this button will be unswallowed -or closed when FvwmButtons exit cleanly. "NoClose" can be combined with -"UseOld" to have windows survive restart of windowmanager. The default +or closed when FvwmButtons exits cleanly. "NoClose" can be combined with +"UseOld" to have windows survive restart of the window manager. The default setting is "Close". - -NoHints / Hints - -Specifies whether hints from the swallowed program in this -button will be ignored or not, useful in forcing a window to resize itself -to fit its button. The default value is "Hints". - -NoKill / Kill - +.IP "NoHints / Hints" +Specifies whether hints from the swallowed program in this button will be +ignored or not, useful in forcing a window to resize itself to fit its +button. The default value is "Hints". +.IP "NoKill / Kill" Specifies whether the swallowed program will be closed by killing it or by -sending a message to it. This can be useful in ending programs that -doesn't accept window manager protocol. The default value is "NoKill". -This has no effect if "NoClose" is specified. - -NoRespawn / Respawn - -Specifies whether the swallowed program is to be respawn if it dies. +sending a message to it. This can be useful in ending programs that do not +accept window manager protocol. The default value is "NoKill". This has no +effect if "NoClose" is specified. +.IP "NoRespawn / Respawn" +Specifies whether the swallowed program is to be respawned if it dies. If "Respawn" is specified, the program will be respawned using the original \fIcommand\fP. Use this option with care, the program might have a very legitimate reason to die. - -NoOld / UseOld - +.IP "NoOld / UseOld" Specifies whether the button will try to swallow an existing window matching the \fIhangon\fP name before spawning one itself with \fIcommand\fP. -The default value is "NoOld". -"UseOld" can be combined with "NoKill" to have windows survive restart of -windowmanager. If you want FvwmButtons to swallow an old window, and not -spawn one itself if failing, let the \fIcommand\fP be "Nop": - - *FvwmButtons(Swallow (UseOld) "Console" Nop) - +The default value is "NoOld". "UseOld" can be combined with "NoKill" to +have windows survive restart of the window manager. If you want FvwmButtons +to swallow an old window, and not spawn one itself if failing, let the +\fIcommand\fP be "Nop": +.EX +*FvwmButtons(Swallow (UseOld) "Console" Nop) +.EE +.RE +.PP If you want to be able to start it yourself, combine it with an action: - - *FvwmButtons(Swallow (UseOld) "Console" Nop, \\ - Action `Exec "Console" console &`) - -NoTitle / UseTitle - +.EX +*FvwmButtons(Swallow (UseOld) "Console" Nop, \ + Action `Exec "Console" console &`) +.EE +.PP +.RS +.IP "NoTitle / UseTitle" Specifies whether the title of the button will be taken from the swallowed window's title or not. If "UseTitle" is given, the title on the button will change dynamically to reflect the window name. The default is "NoTitle". - +.RE .IP " Title [(\fIoptions\fP)] \fIname\fP" Specifies the title which will be written on the button. Whitespace can be included in the title by quoting it. @@ -275,17 +272,19 @@ its buttons, characters are chopped of one at a time until it fits. If \fIjustify\fP is "Right", the head is removed, otherwise its tail is removed. These \fIoptions\fP can be given to Title: - -Center - The title will be centered horizontally. This is the default. - -Left - The title will be justified to the left side. - -Right - The title will be justified to the right side. - -Side - This will cause the title to appear on the right hand side of -any icon or swallowed window, instead of below it which is the default. -If you use small icons, and combine this with the "Left" option, you can -get a look similar to fvwm's menus. +.RS +.IP Center +The title will be centered horizontally. This is the default. +.IP Left +The title will be justified to the left side. +.IP Right +The title will be justified to the right side. +.IP Side +This will cause the title to appear on the right-hand side of any icon or +swallowed window, instead of below it which is the default. If you use small +icons, and combine this with the "Left" option, you can get a look similar to +fvwm's menus. +.RE .IP "Legacy fields [\fItitle icon command\fP]" These fields are kept for compatibility with previous versions of FvwmButtons, and their use is discouraged. @@ -299,15 +298,16 @@ Action \fIcommand\fP or alternatively Swallow "\fIhangon\fP" \fIcommand\fP. Any fvwm command is recognized by FvwmButtons. See fvwm(1) for more info on this. The Exec command has a small extension when used in Actions, its syntax is here: - - Exec ["hangon"] command - +.EX +Exec ["hangon"] command +.EE +.PP When FvwmButtons finds such an Exec command, the button will remain pushed in until a window whose name or class matches the qouted portion of the command is encountered. This is intended to provide visual feedback to the user that the action he has requested -will be performed. If the qouted portion -contains no characters, then the button will pop out immediately. +will be performed. If the qouted portion contains no characters, then the +button will pop out immediately. Note that users can continue pressing the button, and re-executing the command, even when it looks "pressed in." .IP "Quoting" @@ -316,31 +316,31 @@ earlier versions commands no longer need to be quoted. In this case any quoting character will be passed on to the application untouched. Only commas ',' and closing parentheses ')' have to be quoted inside a command. -Quoting can be done with any of the three quotation characters; -single quote: - - 'This is a "quote"', - +Quoting can be done with any of the three quotation characters; single +quote: +.EX +\&'This is a "quote"', +.EE +.PP double quote: - - "It's another `quote'", - +.EX +\&"It's another `quote'", +.EE +.PP and backquote: - - `This is a strange quote`. - -The backquoting is purposeful -if you use a preprocessor like FvwmCpp and want it to get into your -commands, like this: - - #define BG gray60 - *FvwmButtons(Swallow "xload" `Exec xload -bg BG &`) - -Furthermore a single character can be quoted with a preceding -backslash '\'. - +.EX +`This is a strange quote`. +.EE +.PP +The backquoting is purposeful if you use a preprocessor like FvwmCpp and +want it to get into your commands, like this: +.EX +#define BG gray60 +*FvwmButtons(Swallow "xload" `Exec xload -bg BG &`) +.EE +.PP +Furthermore a single character can be quoted with a preceding backslash '\'. .SH ARRANGEMENT ALGORITHM - FvwmButtons tries to arrange its buttons as best it can, by using recursively, on each container including the buttonbox itself, the following algorithm. @@ -379,28 +379,27 @@ are placed if necessary if the BoxSize option \fIsmart\fP is used. Containers are arranged by the same algorithm, in fact they are shuffled recursively as the algorithm finds them. .IP "Clarifying example" -An example might be useful here: Suppose you have 6 buttons, all unit sized -except number two, which is 2x2. This makes for 5 times 1 plus 1 times 4 -equals 9 unit buttons total area. Assume you have requested 3 columns. -.nf -.sp +An example might be useful here: Suppose you have six buttons, all unit +sized except number two, which is 2x2. This makes for five times 1 plus one +times 4 equals nine unit buttons total area. Assume you have requested three +columns. +.EX 1) +---+---+---+ 2) +---+---+---+ 3) +---+---+---+ - | 1 | | | 1 | | | 1 | | - +---+ + +---+ 2 + +---+ 2 + - | | | | | | 3 | | - + + + +---+---+ +---+---+---+ - | | | | | | | | - +-----------+ +---+-------+ +---+---+---+ + | 1 | | | 1 | | | 1 | | + +---+ + +---+ 2 + +---+ 2 + + | | | | | | 3 | | + + + + +---+---+ +---+---+---+ + | | | | | | | | + +-----------+ +---+-------+ +---+---+---+ 4) +---+---+---+ 5) +---+-------+ 6) +---+-------+ - | 1 | | | 1 | | | 1 | | - +---+ 2 + +---+ 2 | +---+ 2 | - | 3 | | | 3 | | | 3 | | - +---+---+---+ +---+---+---+ +---+-------+ - | 4 | | | 4 | 5 | | | 4 | 5 | 6 | - +---+---+---+ +---+---+---+ +---+---+---+ -.sp -.fi + | 1 | | | 1 | | | 1 | | + +---+ 2 + +---+ 2 | +---+ 2 | + | 3 | | | 3 | | | 3 | | + +---+---+---+ +---+---+---+ +---+---+---+ + | 4 | | | 4 | 5 | | | 4 | 5 | 6 | + +---+---+---+ +---+---+---+ +---+---+---+ +.EE .IP "What size will the buttons be?" When FvwmButtons has read the icons and fonts that are required by its configuration, it can find out which size is needed for every non-swallowing @@ -412,13 +411,10 @@ for a swallowed window, it can be set in that button's configuration line using the option "Size \fIwidth height\fP". This will tell FvwmButtons to give this button at least \fIwidth\fP by \fIheight\fP pixels inside the relief and padding. - .SH SAMPLE CONFIGURATION The following are excepts from a .fvwmrc file which describe FvwmButtons initialization commands: - -.nf -.sp +.EX XCOMM######################################################### XCOMM Load any modules which should be started during fvwm XCOMM initialization @@ -474,22 +470,20 @@ XCOMM######################################################### *FvwmButtons(Swallow(UseOld,NoKill) "xload15" `Exec xload \\ -title xload15 -nolabel -bg rgb:90/80/90 -update 15 &`) -.sp -.fi - +.EE +.PP The last lines are a little tricky - one spawns an FvwmPager module, and captures it to display in a quadruple width button. -is used, the Pager will be as big as possible within the button's relief. - +If this is used, the Pager will be as big as possible within the button's +relief. +.PP The final line is even more magic. Note the combination of \fIUseOld\fP and \fINoKill\fP, which will try to swallow an existing window with the name "xload15" when starting up (if failing: starting one with the specified command), which is unswallowed when ending FvwmButtons. - +.PP The other panels are specified after the root panel: - -.nf -.sp +.EX XCOMM######### PANEL *FvwmButtonsPanel WinOps *FvwmButtonsBack bisque2 @@ -508,21 +502,19 @@ XCOMM######### PANEL *FvwmButtonsColumns 1 *FvwmButtons(Title Kill ,Icon bomb.xpm ,Action Destroy) -.sp -.fi - +.EE +.PP The color specification \fIrgb:90/80/90\fP is actually the most correct way of specifying independent colors in X, and should be used instead of the older \fI#908090\fP. If the latter specification is used in your configuration file, you should be sure to escape the hash in any of the \fIcommand\fPs which will be executed, or fvwm will consider the rest of the line a comment. - +.PP Note that with the x/y geometry specs you can easily build button windows with gaps. Here is another example. You can not accomplish this without geometry specs for the buttons: -.nf -.sp +.EX XCOMM######################################################### XCOMM Make it titlebar-less, sticky, and give it an icon @@ -565,26 +557,18 @@ XCOMM big items *FvwmButtons(20x5, Padding 0, Swallow "xosview" \\ `Exec /usr/X11R6/bin/xosview -cpu -int -page -net \\ -geometry 100x50+0-0 -font 5x7`) -.sp -.fi - -.SH BUGS - -The action part of the Swallow option must be quoted if it contains -any whitespace character. - +.EE .SH COPYRIGHTS -The FvwmButtons program, and the concept for interfacing this module to -the Window Manager, are all original work by Robert Nation - -Copyright 1993, Robert Nation. No guarantees or warranties or anything -are provided or implied in any way whatsoever. Use this program at your -own risk. Permission to use this program for any purpose is given, -as long as the copyright is kept intact. - -Further modifications and patching by Jarl Totland, copyright 1996. -The statement above still applies. - +The FvwmButtons program, and the concept for interfacing this module to the +Window Manager, are all original work by Robert Nation. +.PP +Copyright 1993, Robert Nation. No guarantees or warranties or anything are +provided or implied in any way whatsoever. Use this program at your own risk. +Permission to use this program for any purpose is given, as long as the +copyright is kept intact. +.PP +Further modifications and patching by Jarl Totland, copyright 1996. The +statement above still applies. .SH AUTHOR Robert Nation. Somewhat enhanced by Jarl Totland, Jui-Hsuan Joshua Feng and Dominik Vogt. Index: fvwm/modules/FvwmButtons/FvwmButtons.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmButtons/FvwmButtons.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmButtons/FvwmButtons.c --- fvwm/modules/FvwmButtons/FvwmButtons.c +++ fvwm/modules/FvwmButtons/FvwmButtons.c @@ -14,32 +14,32 @@ /* ------------------------------- includes -------------------------------- */ #include "config.h" +#include "../../fvwm/fvwm_sandbox.h" -#ifdef HAVE_SYS_BSDTYPES_H -#include /* Saul */ #endif -#include +#include +#include +#include + #include -#include -#include -#include #include +#include +#include +#include #include -#include -#include -#include +#include #ifdef HAVE_SYS_SELECT_H #include #endif -#include +#include +#include #include -#include #include -#include -#include +#include +#include #ifdef XPM #include #endif @@ -50,59 +50,62 @@ #include "../../fvwm/module.h" #include "../../libs/fvwmlib.h" #include "FvwmButtons.h" -#include "misc.h" /* ConstrainSize() */ -#include "parse.h" /* ParseOptions() */ -#include "icons.h" /* CreateIconWindow(), ConfigureIconWindow() */ #include "draw.h" +#include "icons.h" /* CreateIconWindow(), ConfigureIconWindow() */ +#include "misc.h" /* ConstrainSize() */ +#include "parse.h" /* ParseOptions() */ - -#define MW_EVENTS (ExposureMask |\ - StructureNotifyMask |\ - ButtonReleaseMask | ButtonPressMask |\ - KeyReleaseMask | KeyPressMask) +#define MW_EVENTS \ + (ExposureMask | StructureNotifyMask | ButtonReleaseMask | \ + ButtonPressMask | KeyReleaseMask | KeyPressMask) /* SW_EVENTS are for swallowed windows... */ -#define SW_EVENTS (PropertyChangeMask | StructureNotifyMask |\ - ResizeRedirectMask | SubstructureNotifyMask) +#define SW_EVENTS \ + (PropertyChangeMask | StructureNotifyMask | ResizeRedirectMask |\ + SubstructureNotifyMask | ButtonPressMask | ButtonReleaseMask) #ifdef DEBUG_FVWM -#define MySendText(a,b,c) {\ - fprintf(stderr,"%s: Sending text to fvwm: \"%s\"\n",MyName,(b));\ - SendText((a),(b),(c));} +#define MySendText(a, b, c) \ + { \ + fprintf(stderr, "%s: Sending text to fvwm: \"%s\"\n", MyName,\ + (b)); \ + SendText((a), (b), (c)); \ + } #else -#define MySendText(a,b,c) SendText((a),(b),(c)); +#define MySendText(a, b, c) SendText((a), (b), (c)); #endif /* --------------------------- external functions -------------------------- */ -extern void DumpButtons(button_info*); -extern void SaveButtons(button_info*); +extern void DumpButtons(button_info *); +extern void SaveButtons(button_info *); /* ------------------------------ prototypes ------------------------------- */ void DeadPipe(int nonsense) __attribute__((__noreturn__)); static void DeadPipeCleanup(void); -static RETSIGTYPE TerminateHandler(int sig); -void SetButtonSize(button_info*,int,int); +static void TerminateHandler(int sig); +void SetButtonSize(button_info *, int, int); /* main */ void Loop(void); -void RedrawWindow(button_info*); -void RecursiveLoadData(button_info*,int*,int*); -void CreateWindow(button_info*,int,int); +void RedrawWindow(button_info *); +void RecursiveLoadData(button_info *, int *, int *); +void CreateWindow(button_info *, int, int); void nocolor(const char *a, const char *b) __attribute__((__noreturn__)); Pixel GetColor(char *name); int My_XNextEvent(Display *dpy, XEvent *event); -void process_message(unsigned long type,unsigned long *body); -extern void send_clientmessage (Display *disp, Window w, Atom a, Time timestamp); -void CheckForHangon(unsigned long*); -Window GetRealGeometry(Display*,Window,int*,int*,ushort*,ushort*, - ushort*,ushort*); -void swallow(unsigned long*); -void AddButtonAction(button_info*,int,char*); -char *GetButtonAction(button_info*,int); +void process_message(unsigned long type, unsigned long *body); +extern void send_clientmessage(Display *disp, Window w, Atom a, Time timestamp); +void CheckForHangon(unsigned long *); +Window GetRealGeometry( + Display *, Window, int *, int *, ushort *, ushort *, ushort *, ushort *); +void swallow(unsigned long *); +void AddButtonAction(button_info *, int, char *); +char *GetButtonAction(button_info *, int); -void DebugEvents(XEvent*); +void DebugEvents(XEvent *); panel_info *seekpanel(button_info *); void Slide(panel_info *, button_info *); +static int IOErrorHandler(Display *dpy); /* -------------------------------- globals ---------------------------------*/ @@ -114,7 +117,7 @@ XFontStruct *font; int screen; int d_depth; -int x_fd,fd_width; +int x_fd, fd_width; char *config_file = NULL; @@ -124,10 +127,10 @@ char *iconPath = NULL; char *pixmapPath = NULL; Pixel hilite_pix, back_pix, shadow_pix, fore_pix; -GC NormalGC; -int Width,Height; +GC NormalGC; +int Width, Height; -int x= -30000,y= -30000,w= -1,h= -1,gravity = NorthWestGravity; +int x = -30000, y = -30000, w = -1, h = -1, gravity = NorthWestGravity; int new_desk = 0; int ready = 0; int xneg = 0, yneg = 0; @@ -135,43 +138,36 @@ int xneg = 0, yneg = 0; button_info *CurrentButton = NULL; int fd[2]; -button_info *UberButton=NULL; +button_info *UberButton = NULL; panel_info *MainPanel = NULL, *CurrentPanel = NULL, *PanelIndex; int dpw, dph; -int save_color_limit; /* Color limit, if any */ +int save_color_limit; /* Color limit, if any */ static volatile sig_atomic_t isTerminated = False; +static volatile sig_atomic_t connection_dead = False; /* ------------------------------ Misc functions ----------------------------*/ -#ifdef DEBUG -char *mymalloc(int length) -{ - int i=length; - char *p=safemalloc(length); - while(i) - p[--i]=255; - return p; -} -#endif - /** *** Some fancy routines straight out of the manual :-) Used in DeadPipe. **/ -Bool DestroyedWindow(Display *d,XEvent *e,char *a) +Bool +DestroyedWindow(Display *d, XEvent *e, char *a) { - if(e->xany.window == (Window)a) - if((e->type == DestroyNotify && e->xdestroywindow.window == (Window)a)|| - (e->type == UnmapNotify && e->xunmap.window == (Window)a)) - return True; - return False; + if (e->xany.window == (Window)a) + if ((e->type == DestroyNotify && + e->xdestroywindow.window == (Window)a) || + (e->type == UnmapNotify && e->xunmap.window == (Window)a)) + return True; + return False; } -int IsThereADestroyEvent(button_info *b) + +int +IsThereADestroyEvent(button_info *b) { - XEvent event; - Bool DestroyedWindow(); - return XCheckIfEvent(Dpy,&event,DestroyedWindow,(char*)b->IconWin); + XEvent event; + return XCheckIfEvent(Dpy, &event, DestroyedWindow, (char *)b->IconWin); } /** @@ -179,205 +175,205 @@ int IsThereADestroyEvent(button_info *b) *** Externally callable function to quit! Note that DeadPipeCleanup *** is an exit-procedure and so will be called automatically **/ -void DeadPipe(int whatever) +void +DeadPipe(int whatever) { - exit(0); + exit(0); } /** *** TerminateHandler() *** Signal handler that will make the event-loop terminate **/ -static RETSIGTYPE +static void TerminateHandler(int sig) { - isTerminated = True; + isTerminated = True; } /** *** DeadPipeCleanup() *** Remove all the windows from the Button-Bar, and close them as necessary **/ -static void DeadPipeCleanup(void) +static void +DeadPipeCleanup(void) { - button_info *b,*ub=UberButton; - int button=-1; - - signal(SIGPIPE, SIG_IGN);/* Xsync may cause SIGPIPE */ - - XSync(Dpy,0); /* Wait for thing to settle down a bit */ - XGrabServer(Dpy); /* We don't want interference right now */ - while(NextButton(&ub,&b,&button,0)) - { - /* delete swallowed windows */ - if((buttonSwallowCount(b)==3) && b->IconWin) - { -# ifdef DEBUG_HANGON - fprintf(stderr,"%s: Button 0x%06x window 0x%x (\"%s\") is ", - MyName,(ushort)b,(ushort)b->IconWin,b->hangon); -# endif - if(!IsThereADestroyEvent(b)) { /* Has someone destroyed it? */ - if(!(buttonSwallow(b)&b_NoClose)) - { - if(buttonSwallow(b)&b_Kill) - { - XKillClient(Dpy,b->IconWin); -# ifdef DEBUG_HANGON - fprintf(stderr,"now killed\n"); -# endif - } - else - { - send_clientmessage(Dpy,b->IconWin,_XA_WM_DEL_WIN, - CurrentTime); -# ifdef DEBUG_HANGON - fprintf(stderr,"now deleted\n"); -# endif - } - } - else - { -# ifdef DEBUG_HANGON - fprintf(stderr,"now unswallowed\n"); -# endif - XReparentWindow(Dpy,b->IconWin,Root,b->x,b->y); - XMoveWindow(Dpy,b->IconWin,b->x,b->y); - XResizeWindow(Dpy,b->IconWin,b->w,b->h); - XSetWindowBorderWidth(Dpy,b->IconWin,b->bw); - } - } -# ifdef DEBUG_HANGON - else - fprintf(stderr,"already handled\n"); -# endif + button_info *b, *ub = UberButton; + int button = -1; + + if (connection_dead) + return; + + signal(SIGPIPE, SIG_IGN); /* Xsync may cause SIGPIPE */ + + XSync(Dpy, 0); /* Wait for thing to settle down a bit */ + XGrabServer(Dpy); /* We don't want interference right now */ + while (NextButton(&ub, &b, &button, 0)) { + /* delete swallowed windows */ + if ((buttonSwallowCount(b) == 3) && b->IconWin) { +#ifdef DEBUG_HANGON + fprintf(stderr, + "%s: Button 0x%06x window 0x%x (\"%s\") is ", + MyName, (ushort)b, (ushort)b->IconWin, b->hangon); +#endif + if (!IsThereADestroyEvent( + b)) { /* Has someone destroyed it? */ + if (!(buttonSwallow(b) & b_NoClose)) { + if (buttonSwallow(b) & b_Kill) { + XKillClient(Dpy, b->IconWin); +#ifdef DEBUG_HANGON + fprintf(stderr, "now killed\n"); +#endif + } else { + send_clientmessage(Dpy, + b->IconWin, _XA_WM_DEL_WIN, + CurrentTime); +#ifdef DEBUG_HANGON + fprintf( + stderr, "now deleted\n"); +#endif + } + } else { +#ifdef DEBUG_HANGON + fprintf(stderr, "now unswallowed\n"); +#endif + XReparentWindow( + Dpy, b->IconWin, Root, b->x, b->y); + XMoveWindow( + Dpy, b->IconWin, b->x, b->y); + XResizeWindow( + Dpy, b->IconWin, b->w, b->h); + XSetWindowBorderWidth( + Dpy, b->IconWin, b->bw); + } + } +#ifdef DEBUG_HANGON + else + fprintf(stderr, "already handled\n"); +#endif + } + } + XUngrabServer(Dpy); /* We're through */ + XSync(Dpy, + 0); /* Let it all die down again so we can catch our X errors... */ + + /* Hey, we have to free the pictures too! */ + button = -1; + ub = UberButton; + while (NextButton(&ub, &b, &button, 1)) { + if (b->flags & b_Icon) + DestroyPicture(Dpy, b->icon); + if (b->flags & b_IconBack) + DestroyPicture(Dpy, b->backicon); + if (b->flags & b_Container && b->c->flags & b_IconBack && + !(b->c->flags & b_TransBack)) + DestroyPicture(Dpy, b->c->backicon); } - } - XUngrabServer(Dpy); /* We're through */ - XSync(Dpy,0); /* Let it all die down again so we can catch our X errors... */ - - /* Hey, we have to free the pictures too! */ - button=-1;ub=UberButton; - while(NextButton(&ub,&b,&button,1)) - { - if(b->flags&b_Icon) - DestroyPicture(Dpy,b->icon); - if(b->flags&b_IconBack) - DestroyPicture(Dpy,b->backicon); - if(b->flags&b_Container && b->c->flags&b_IconBack - && !(b->c->flags&b_TransBack)) - DestroyPicture(Dpy,b->c->backicon); - } } /** *** SetButtonSize() *** Propagates global geometry down through the buttonhierarchy. **/ -void SetButtonSize(button_info *ub,int w,int h) +void +SetButtonSize(button_info *ub, int w, int h) { - int i=0,dx,dy; - if(!ub || !(ub->flags&b_Container)) - { - fprintf(stderr,"%s: BUG: Tried to set size of noncontainer\n",MyName); - exit(2); - } - if(ub->c->num_rows==0 || ub->c->num_columns==0) - { - fprintf(stderr,"%s: BUG: Set size when rows/cols was unset\n",MyName); - exit(2); - } - w*=ub->BWidth; - h*=ub->BHeight; - - if(ub->parent) - { - i=buttonNum(ub); - ub->c->xpos=buttonXPos(ub,i); - ub->c->ypos=buttonYPos(ub,i); - } - dx=buttonXPad(ub)+buttonFrame(ub); - dy=buttonYPad(ub)+buttonFrame(ub); - ub->c->xpos+=dx; - ub->c->ypos+=dy; - w-=2*dx; - h-=2*dy; - ub->c->ButtonWidth=w/ub->c->num_columns; - ub->c->ButtonHeight=h/ub->c->num_rows; - - i=0; - while(ic->num_buttons) - { - if(ub->c->buttons[i] && ub->c->buttons[i]->flags&b_Container) - SetButtonSize(ub->c->buttons[i], - ub->c->ButtonWidth,ub->c->ButtonHeight); - i++; - } -} + int i = 0, dx, dy; + if (!ub || !(ub->flags & b_Container)) { + fprintf(stderr, "%s: BUG: Tried to set size of noncontainer\n", + MyName); + exit(2); + } + if (ub->c->num_rows == 0 || ub->c->num_columns == 0) { + fprintf(stderr, "%s: BUG: Set size when rows/cols was unset\n", + MyName); + exit(2); + } + w *= ub->BWidth; + h *= ub->BHeight; + if (ub->parent) { + i = buttonNum(ub); + ub->c->xpos = buttonXPos(ub, i); + ub->c->ypos = buttonYPos(ub, i); + } + dx = buttonXPad(ub) + buttonFrame(ub); + dy = buttonYPad(ub) + buttonFrame(ub); + ub->c->xpos += dx; + ub->c->ypos += dy; + w -= 2 * dx; + h -= 2 * dy; + ub->c->ButtonWidth = w / ub->c->num_columns; + ub->c->ButtonHeight = h / ub->c->num_rows; + + i = 0; + while (i < ub->c->num_buttons) { + if (ub->c->buttons[i] && ub->c->buttons[i]->flags & b_Container) + SetButtonSize(ub->c->buttons[i], ub->c->ButtonWidth, + ub->c->ButtonHeight); + i++; + } +} /** *** AddButtonAction() **/ -void AddButtonAction(button_info *b,int n,char *action) +void +AddButtonAction(button_info *b, int n, char *action) { - int l; - char *s; - char *t; - - if(!b || n<0 || n>3 || !action) - { - fprintf(stderr,"%s: BUG: AddButtonAction failed\n",MyName); - exit(2); - } - if(b->flags&b_Action) - { - if(b->action[n]) - free(b->action[n]); - } - else - { - int i; - b->action=(char**)mymalloc(4*sizeof(char*)); - for(i=0;i<4;b->action[i++]=NULL); - b->flags|=b_Action; - } - - while (*action && isspace(*action)) - action++; - l = strlen(action); - if (l > 1) - { - switch (action[0]) - { - case '\"': - case '\'': - case '`': - s = SkipQuote(action, NULL, "", ""); - /* Strip outer quotes */ - if (*s == 0) - { - action++; - l -= 2; - } - break; - default: - break; - } - } - t = (char *)mymalloc(l + 1); - memmove(t, action, l); - t[l] = 0; - b->action[n] = t; + int l; + char *s; + char *t; + + if (!b || n < 0 || n > 3 || !action) { + fprintf(stderr, "%s: BUG: AddButtonAction failed\n", MyName); + exit(2); + } + if (b->flags & b_Action) { + if (b->action[n]) + free(b->action[n]); + } else { + int i; + b->action = (char **)xmalloc(4 * sizeof(char *)); + for (i = 0; i < 4; b->action[i++] = NULL) + ; + b->flags |= b_Action; + } + + while (*action && isspace(*action)) + action++; + l = strlen(action); + if (l > 1) { + switch (action[0]) { + case '\"': + case '\'': + case '`': + s = SkipQuote(action, NULL, "", ""); + /* Strip outer quotes */ + if (*s == 0) { + action++; + l -= 2; + } + break; + default: + break; + } + } + t = (char *)xmalloc(l + 1); + memmove(t, action, l); + t[l] = 0; + b->action[n] = t; } /** *** GetButtonAction() **/ -char *GetButtonAction(button_info *b,int n) +char * +GetButtonAction(button_info *b, int n) { - if(!b || !(b->flags&b_Action) || !(b->action) || n<0 || n>3) - return NULL; - return b->action[n]; + if (!b || !(b->flags & b_Action) || !(b->action) || n < 0 || n > 3) + return NULL; + return b->action[n]; } #ifdef SHAPE @@ -386,71 +382,69 @@ char *GetButtonAction(button_info *b,int n) *** use the Shape extension to create a transparent background. *** Patrice Fortier **/ -void SetTransparentBackground(button_info *ub,int w,int h) +void +SetTransparentBackground(button_info *ub, int w, int h) { - Pixmap pmap_mask; - button_info *b; - GC gc; - XGCValues gvals; - unsigned long gcm=0; - Window root_return; - int x_return, y_return; - unsigned int width_return, height_return; - unsigned int border_width_return; - unsigned int depth_return; - int number, i; - XFontStruct *font; - - pmap_mask = XCreatePixmap(Dpy,MyWindow,w,h,1); - gc = XCreateGC(Dpy,pmap_mask,(unsigned long)0,&gvals); - XSetForeground(Dpy,gc,0); - XFillRectangle(Dpy,pmap_mask,gc,0,0,w,h); - XSetForeground(Dpy,gc,1); - - /* - * if button has an icon, draw a rect with the same size as the icon - * (or the mask of the icon), - * else draw a rect with the same size as the button. - */ - - i=-1; - while(NextButton(&ub,&b,&i,0)) - { - if(b->flags&b_Icon) - { - XGetGeometry(Dpy,b->IconWin,&root_return,&x_return,&y_return, - &width_return,&height_return, - &border_width_return,&depth_return); - - number=buttonNum(b); - if (b->icon->mask == None) - XFillRectangle(Dpy,pmap_mask,gc,x_return, y_return, - b->icon->width,b->icon->height); - else - XCopyArea(Dpy,b->icon->mask,pmap_mask,gc,0,0, - b->icon->width,b->icon->height,x_return,y_return); - } - else - { - number=buttonNum(b); - XFillRectangle(Dpy,pmap_mask,gc,buttonXPos(b,number), - buttonYPos(b,number), - buttonWidth(b),buttonHeight(b)); - } + Pixmap pmap_mask; + button_info *b; + GC gc; + XGCValues gvals; + unsigned long gcm = 0; + Window root_return; + int x_return, y_return; + unsigned int width_return, height_return; + unsigned int border_width_return; + unsigned int depth_return; + int number, i; + XFontStruct *font; + + pmap_mask = XCreatePixmap(Dpy, MyWindow, w, h, 1); + gc = XCreateGC(Dpy, pmap_mask, (unsigned long)0, &gvals); + XSetForeground(Dpy, gc, 0); + XFillRectangle(Dpy, pmap_mask, gc, 0, 0, w, h); + XSetForeground(Dpy, gc, 1); + + /* + * if button has an icon, draw a rect with the same size as the icon + * (or the mask of the icon), + * else draw a rect with the same size as the button. + */ + + i = -1; + while (NextButton(&ub, &b, &i, 0)) { + if (b->flags & b_Icon) { + XGetGeometry(Dpy, b->IconWin, &root_return, &x_return, + &y_return, &width_return, &height_return, + &border_width_return, &depth_return); + + number = buttonNum(b); + if (b->icon->mask == None) + XFillRectangle(Dpy, pmap_mask, gc, x_return, + y_return, b->icon->width, b->icon->height); + else + XCopyArea(Dpy, b->icon->mask, pmap_mask, gc, 0, + 0, b->icon->width, b->icon->height, + x_return, y_return); + } else { + number = buttonNum(b); + XFillRectangle(Dpy, pmap_mask, gc, + buttonXPos(b, number), buttonYPos(b, number), + buttonWidth(b), buttonHeight(b)); + } - /* handle button's title */ - font=buttonFont(b); - if(b->flags&b_Title && font) - { - gcm = GCForeground | GCFont; - gvals.foreground=1; - gvals.font = font->fid; - XChangeGC(Dpy,gc,gcm,&gvals); - DrawTitle(b,pmap_mask,gc); + /* handle button's title */ + font = buttonFont(b); + if (b->flags & b_Title && font) { + gcm = GCForeground | GCFont; + gvals.foreground = 1; + gvals.font = font->fid; + XChangeGC(Dpy, gc, gcm, &gvals); + DrawTitle(b, pmap_mask, gc); + } } - } - XFreeGC(Dpy,gc); - XShapeCombineMask(Dpy,MyWindow,ShapeBounding,0,0,pmap_mask,ShapeSet); + XFreeGC(Dpy, gc); + XShapeCombineMask( + Dpy, MyWindow, ShapeBounding, 0, 0, pmap_mask, ShapeSet); } #endif @@ -458,12 +452,21 @@ void SetTransparentBackground(button_info *ub,int w,int h) *** myErrorHandler() *** Shows X errors made by FvwmButtons. **/ -XErrorHandler oldErrorHandler=NULL; -int myErrorHandler(Display *dpy, XErrorEvent *event) +XErrorHandler oldErrorHandler = NULL; +int +myErrorHandler(Display *dpy, XErrorEvent *event) { - fprintf(stderr,"%s: Cause of next X Error.\n",MyName); - /* return (*oldErrorHandler)(dpy,event); */ - return 0; + fprintf(stderr, "%s: Cause of next X Error.\n", MyName); + /* return (*oldErrorHandler)(dpy,event); */ + return 0; +} + +static int +IOErrorHandler(Display *dpy) +{ + (void)dpy; + connection_dead = True; + _exit(1); } /* ---------------------------------- main ----------------------------------*/ @@ -471,217 +474,227 @@ int myErrorHandler(Display *dpy, XErrorEvent *event) /** *** main() **/ -int main(int argc, char **argv) +int +main(int argc, char **argv) { - char *display_name = NULL; - int i; - Window root; - int x,y,maxx,maxy,border_width,depth; - char *temp, *s; - button_info *b,*ub; - - temp=argv[0]; - s=strrchr(argv[0],'/'); - if(s) temp=s+1; - MyName=mymalloc(strlen(temp)+1); - strcpy(MyName,temp); + char *display_name = NULL; + int i; + Window root; + int x, y, maxx, maxy, border_width, depth; + char *temp, *s; + button_info *b, *ub; + + temp = argv[0]; + s = strrchr(argv[0], '/'); + if (s) + temp = s + 1; + { + size_t name_len = strlen(temp) + 1; + MyName = xmalloc((int)name_len); + strlcpy(MyName, temp, name_len); + } #ifdef HAVE_SIGACTION - { - struct sigaction sigact; - - sigemptyset(&sigact.sa_mask); -# ifdef SA_INTERRUPT - sigact.sa_flags = SA_INTERRUPT; -# else - sigact.sa_flags = 0; -# endif - sigact.sa_handler = TerminateHandler; - - sigaction(SIGPIPE, &sigact, NULL); - sigaction(SIGINT, &sigact, NULL); - sigaction(SIGHUP, &sigact, NULL); - sigaction(SIGQUIT, &sigact, NULL); - sigaction(SIGTERM, &sigact, NULL); - } + { + struct sigaction sigact; + + sigemptyset(&sigact.sa_mask); +#ifdef SA_INTERRUPT + sigact.sa_flags = SA_INTERRUPT; #else - /* We don't have sigaction(), so fall back to less robust methods. */ - signal(SIGPIPE, TerminateHandler); - signal(SIGINT, TerminateHandler); - signal(SIGHUP, TerminateHandler); - signal(SIGQUIT, TerminateHandler); - signal(SIGTERM, TerminateHandler); + sigact.sa_flags = 0; #endif + sigact.sa_handler = TerminateHandler; + + sigaction(SIGPIPE, &sigact, NULL); + sigaction(SIGINT, &sigact, NULL); + sigaction(SIGHUP, &sigact, NULL); + sigaction(SIGQUIT, &sigact, NULL); + sigaction(SIGTERM, &sigact, NULL); + } +#else + /* We don't have sigaction(), so fall back to less robust methods. */ + signal(SIGPIPE, TerminateHandler); + signal(SIGINT, TerminateHandler); + signal(SIGHUP, TerminateHandler); + signal(SIGQUIT, TerminateHandler); + signal(SIGTERM, TerminateHandler); +#endif + + if (argc < 6 || argc > 8) { + fprintf(stderr, "%s v%s should only be executed by fvwm!\n", + MyName, VERSION); + exit(1); + } + + if (argc > 6) { /* There is a naming argument here! */ + free(MyName); + MyName = strdup(argv[6]); + } + + if (argc > 7) { /* There is a config file here! */ + config_file = strdup(argv[7]); + } + + fd[0] = atoi(argv[1]); + fd[1] = atoi(argv[2]); + if (!(Dpy = XOpenDisplay(display_name))) { + fprintf(stderr, "%s: Can't open display %s", MyName, + XDisplayName(display_name)); + exit(1); + } + XSetIOErrorHandler(IOErrorHandler); + x_fd = XConnectionNumber(Dpy); + fd_width = GetFdWidth(); + + screen = DefaultScreen(Dpy); + Root = RootWindow(Dpy, screen); + if (Root == None) { + fprintf(stderr, "%s: Screen %d is not valid\n", MyName, screen); + exit(1); + } + d_depth = DefaultDepth(Dpy, screen); + + oldErrorHandler = XSetErrorHandler(myErrorHandler); + + UberButton = (button_info *)xmalloc(sizeof(button_info)); + memset(UberButton, 0, sizeof(button_info)); + UberButton->flags = 0; + UberButton->parent = NULL; + UberButton->BWidth = 1; + UberButton->BHeight = 1; + UberButton->font = NULL; + UberButton->font_string = NULL; + UberButton->x = -30000; + UberButton->y = -30000; + MakeContainer(UberButton); + + dpw = DisplayWidth(Dpy, screen); + dph = DisplayHeight(Dpy, screen); + +#ifdef DEBUG_INIT + fprintf(stderr, "%s: Parsing...", MyName); +#endif + + CurrentPanel = MainPanel = (panel_info *)xmalloc(sizeof(panel_info)); + memset(MainPanel, 0, sizeof(panel_info)); + MainPanel->next = NULL; + MainPanel->uber = UberButton; + MainPanel->geom_w = -1; + MainPanel->geom_h = -1; + UberButton->title = MyName; + UberButton->swallow = 1; /* the panel is shown */ + + ParseOptions(UberButton); + + CurrentPanel = MainPanel; /* reassign CurrentPanel */ + while (CurrentPanel) { + UberButton = CurrentPanel->uber; + + if (UberButton->c->num_buttons == 0) { + fprintf(stderr, "%s: No buttons defined. Quitting\n", + MyName); + exit(0); + } + +#ifdef DEBUG_INIT + fprintf(stderr, "OK\n%s: Shuffling...", MyName); +#endif + + ShuffleButtons(UberButton); + NumberButtons(UberButton); + +#ifdef DEBUG_INIT + fprintf(stderr, "OK\n%s: Loading data...\n", MyName); +#endif + + /* Load fonts and icons, calculate max buttonsize */ + maxx = 0; + maxy = 0; + InitPictureCMap(Dpy, Root); /* store the root cmap */ + RecursiveLoadData(UberButton, &maxx, &maxy); + +#ifdef DEBUG_INIT + fprintf(stderr, "%s: Creating main window...", MyName); +#endif + + CreateWindow(UberButton, maxx, maxy); + + CurrentPanel->uber->IconWinParent = MyWindow; + CurrentPanel->uber->icon_w = maxx; + CurrentPanel->uber->icon_h = maxy; + +#ifdef DEBUG_INIT + fprintf(stderr, "OK\n%s: Creating icon windows...", MyName); +#endif + + i = -1; + ub = UberButton; + while (NextButton(&ub, &b, &i, 0)) + if (b->flags & b_Icon) { +#ifdef DEBUG_INIT + fprintf(stderr, "0x%06x...", (ushort)b); +#endif + CreateIconWindow(b); + } + +#ifdef DEBUG_INIT + fprintf(stderr, "OK\n%s: Configuring windows...", MyName); +#endif + + XGetGeometry(Dpy, MyWindow, &root, &x, &y, (ushort *)&Width, + (ushort *)&Height, (ushort *)&border_width, + (ushort *)&depth); + SetButtonSize(UberButton, Width, Height); + i = -1; + ub = UberButton; + while (NextButton(&ub, &b, &i, 0)) + ConfigureIconWindow(b); + +#ifdef SHAPE + if (UberButton->c->flags & b_TransBack) + SetTransparentBackground(UberButton, Width, Height); +#endif + + i = -1; + ub = UberButton; + while (NextButton(&ub, &b, &i, 0)) + MakeButton(b); + + CurrentPanel = CurrentPanel->next; + } + CurrentPanel = MainPanel; + UberButton = CurrentPanel->uber; + MyWindow = UberButton->IconWinParent; + +#ifdef DEBUG_INIT + fprintf(stderr, "OK\n%s: Mapping windows...", MyName); +#endif + + XMapSubwindows(Dpy, MyWindow); + XMapWindow(Dpy, MyWindow); + + SetMessageMask(fd, M_NEW_DESK | M_END_WINDOWLIST | M_MAP | + M_WINDOW_NAME | M_RES_CLASS | M_CONFIG_INFO | + M_END_CONFIG_INFO | M_RES_NAME); + + /* request a window list, since this triggers a response which + * will tell us the current desktop and paging status, needed to + * indent buttons correctly */ + MySendText(fd, "Send_WindowList", 0); - if(argc<6 || argc>8) - { - fprintf(stderr,"%s v%s should only be executed by fvwm!\n",MyName, - VERSION); - exit(1); - } - - if(argc>6) /* There is a naming argument here! */ - { - free(MyName); - MyName=strdup(argv[6]); - } - - if(argc>7) /* There is a config file here! */ - { - config_file=strdup(argv[7]); - } - - fd[0]=atoi(argv[1]); - fd[1]=atoi(argv[2]); - if (!(Dpy = XOpenDisplay(display_name))) - { - fprintf(stderr,"%s: Can't open display %s", MyName, - XDisplayName(display_name)); - exit (1); - } - x_fd=XConnectionNumber(Dpy); - fd_width=GetFdWidth(); - - screen=DefaultScreen(Dpy); - Root=RootWindow(Dpy, screen); - if(Root==None) - { - fprintf(stderr,"%s: Screen %d is not valid\n",MyName,screen); - exit(1); - } - d_depth = DefaultDepth(Dpy, screen); - - oldErrorHandler=XSetErrorHandler(myErrorHandler); - - UberButton=(button_info*)mymalloc(sizeof(button_info)); - memset(UberButton, 0, sizeof(button_info)); - UberButton->flags=0; - UberButton->parent=NULL; - UberButton->BWidth=1; - UberButton->BHeight=1; - UberButton->font = NULL; - UberButton->font_string = NULL; - MakeContainer(UberButton); - - dpw = DisplayWidth(Dpy,screen); - dph = DisplayHeight(Dpy,screen); - -# ifdef DEBUG_INIT - fprintf(stderr,"%s: Parsing...",MyName); -# endif - - CurrentPanel = MainPanel - = (panel_info *) mymalloc(sizeof(panel_info)); - MainPanel->next = NULL; - MainPanel->uber = UberButton; - UberButton->title = MyName; - UberButton->swallow = 1; /* the panel is shown */ - - ParseOptions(UberButton); - - CurrentPanel = MainPanel; /* reassign CurrentPanel */ - while (CurrentPanel) - { UberButton = CurrentPanel->uber; - - if(UberButton->c->num_buttons==0) - { - fprintf(stderr,"%s: No buttons defined. Quitting\n", MyName); - exit(0); - } - -# ifdef DEBUG_INIT - fprintf(stderr,"OK\n%s: Shuffling...",MyName); -# endif - - ShuffleButtons(UberButton); - NumberButtons(UberButton); - -# ifdef DEBUG_INIT - fprintf(stderr,"OK\n%s: Loading data...\n",MyName); -# endif - - /* Load fonts and icons, calculate max buttonsize */ - maxx=0;maxy=0; - InitPictureCMap(Dpy,Root); /* store the root cmap */ - RecursiveLoadData(UberButton,&maxx,&maxy); - -# ifdef DEBUG_INIT - fprintf(stderr,"%s: Creating main window...",MyName); -# endif - - CreateWindow(UberButton,maxx,maxy); - - CurrentPanel->uber->IconWinParent = MyWindow; - CurrentPanel->uber->icon_w = maxx; - CurrentPanel->uber->icon_h = maxy; - -# ifdef DEBUG_INIT - fprintf(stderr,"OK\n%s: Creating icon windows...",MyName); -# endif - - i=-1;ub=UberButton; - while(NextButton(&ub,&b,&i,0)) - if(b->flags&b_Icon) - { #ifdef DEBUG_INIT - fprintf(stderr,"0x%06x...",(ushort)b); + fprintf(stderr, "OK\n%s: Startup complete\n", MyName); #endif - CreateIconWindow(b); - } - -# ifdef DEBUG_INIT - fprintf(stderr,"OK\n%s: Configuring windows...",MyName); -# endif - - XGetGeometry(Dpy,MyWindow,&root,&x,&y,(ushort*)&Width,(ushort*)&Height, - (ushort*)&border_width,(ushort*)&depth); - SetButtonSize(UberButton,Width,Height); - i=-1;ub=UberButton; - while(NextButton(&ub,&b,&i,0)) - ConfigureIconWindow(b); - -# ifdef SHAPE - if(UberButton->c->flags&b_TransBack) - SetTransparentBackground(UberButton,Width,Height); -# endif - - i=-1;ub=UberButton; - while(NextButton(&ub,&b,&i,0)) - MakeButton(b); - - CurrentPanel = CurrentPanel->next; - } - CurrentPanel = MainPanel; - UberButton = CurrentPanel->uber; - MyWindow = UberButton->IconWinParent; - -# ifdef DEBUG_INIT - fprintf(stderr,"OK\n%s: Mapping windows...",MyName); -# endif - - XMapSubwindows(Dpy,MyWindow); - XMapWindow(Dpy,MyWindow); - - SetMessageMask(fd, M_NEW_DESK | M_END_WINDOWLIST | M_MAP | M_WINDOW_NAME | - M_RES_CLASS | M_CONFIG_INFO | M_END_CONFIG_INFO | M_RES_NAME); - - /* request a window list, since this triggers a response which - * will tell us the current desktop and paging status, needed to - * indent buttons correctly */ - MySendText(fd,"Send_WindowList",0); - -# ifdef DEBUG_INIT - fprintf(stderr,"OK\n%s: Startup complete\n",MyName); -# endif - - /* - ** Now that we have finished initialising everything, - ** it is safe(r) to install the clean-up handlers ... - */ - atexit(DeadPipeCleanup); - Loop(); - - return 0; + + /* + ** Now that we have finished initialising everything, + ** it is safe(r) to install the clean-up handlers ... + */ + atexit(DeadPipeCleanup); + Loop(); + + return 0; } /* -------------------------------- Main Loop -------------------------------*/ @@ -689,308 +702,427 @@ int main(int argc, char **argv) /** *** Loop **/ -void Loop(void) +void +Loop(void) { - XEvent Event; - KeySym keysym; - char buffer[10],*tmp,*act; - int i,i2,button; - button_info *ub,*b; - panel_info *ppi; + XEvent Event; + KeySym keysym; + char buffer[10], *tmp, *act; + int i, i2, button; + button_info *ub, *b; + panel_info *ppi; #ifndef OLD_EXPOSE - int ex=10000,ey=10000,ex2=0,ey2=0; + int ex = 10000, ey = 10000, ex2 = 0, ey2 = 0; #endif - while( !isTerminated ) - { - if(My_XNextEvent(Dpy,&Event)) - { - switch(Event.type) - { - case Expose: - PanelIndex = MainPanel; - while (PanelIndex && (PanelIndex->uber->IconWinParent != Event.xany.window)) - PanelIndex = PanelIndex->next; - if (PanelIndex) - { UberButton = PanelIndex->uber; - MyWindow = UberButton->IconWinParent; - } - else - break; + sandbox_x11_config("FvwmButtons"); + sandbox_x11_config("FvwmButtons"); + + while (!isTerminated) { + if (My_XNextEvent(Dpy, &Event)) { + switch (Event.type) { + case Expose: + PanelIndex = MainPanel; + while (PanelIndex && + (PanelIndex->uber->IconWinParent != + Event.xany.window)) + PanelIndex = PanelIndex->next; + if (PanelIndex) { + UberButton = PanelIndex->uber; + MyWindow = UberButton->IconWinParent; + } else + break; #ifdef OLD_EXPOSE - if(Event.xexpose.count == 0) - { - button=-1;ub=UberButton; - while(NextButton(&ub,&b,&button,1)) - { - if(!ready && !(b->flags&b_Container)) - MakeButton(b); - RedrawButton(b,1); - } - if(!ready) - ready++; - } + if (Event.xexpose.count == 0) { + button = -1; + ub = UberButton; + while (NextButton(&ub, &b, &button, + 1)) { + if (!ready && + !(b->flags & b_Container)) + MakeButton(b); + RedrawButton(b, 1); + } + if (!ready) + ready++; + } #else - ex=min(ex,Event.xexpose.x); - ey=min(ey,Event.xexpose.y); - ex2=max(ex2,Event.xexpose.x+Event.xexpose.width); - ey2=max(ey2,Event.xexpose.y+Event.xexpose.height); - - if(Event.xexpose.count==0) - { - button=-1;ub=UberButton; - while(NextButton(&ub,&b,&button,1)) - { - if(b->flags&b_Container) - { - x=buttonXPos(b,buttonNum(b)); - y=buttonYPos(b,buttonNum(b)); - } - else - { - x=buttonXPos(b,button); - y=buttonYPos(b,button); - } - if(!(ex > x + buttonWidth(b) || ex2 < x || - ey > y + buttonHeight(b) || ey2 < y)) - { - if(ready<1 && !(b->flags&b_Container)) - MakeButton(b); - RedrawButton(b,1); - } - } - if(ready<1) - ready++; - - ex=ey=10000;ex2=ey2=0; - } + ex = min(ex, Event.xexpose.x); + ey = min(ey, Event.xexpose.y); + ex2 = max( + ex2, Event.xexpose.x + Event.xexpose.width); + ey2 = max(ey2, + Event.xexpose.y + Event.xexpose.height); + + if (Event.xexpose.count == 0) { + button = -1; + ub = UberButton; + while (NextButton(&ub, &b, &button, + 1)) { + if (b->flags & b_Container) { + x = buttonXPos( + b, buttonNum(b)); + y = buttonYPos( + b, buttonNum(b)); + } else { + x = buttonXPos( + b, button); + y = buttonYPos( + b, button); + } + if (!(ex > x + buttonWidth(b) || + ex2 < x || + ey > y + buttonHeight( + b) || + ey2 < y)) { + if (ready < 1 && + !(b->flags & + b_Container)) + MakeButton(b); + RedrawButton(b, 1); + } + } + if (ready < 1) + ready++; + + ex = ey = 10000; + ex2 = ey2 = 0; + } #endif - break; - - case ConfigureNotify: - /* XGetGeometry(Dpy, MyWindow, &root, &x, &y, - (ushort*)&tw,(ushort*)&th, - (ushort*)&border_width,(ushort*)&depth); - if(tw!=Width || th!=Height) - { - Width=tw; - Height=th; - SetButtonSize(UberButton,Width,Height); - button=-1;ub=UberButton; - while(NextButton(&ub,&b,&button,0)) - MakeButton(b); - RedrawWindow(NULL); - } */ /* I don't like to change its size after it started */ - break; - - case KeyPress: - XLookupString(&Event.xkey,buffer,10,&keysym,0); - if(keysym!=XK_Return && keysym!=XK_KP_Enter && keysym!=XK_Linefeed) - break; /* fall through to ButtonPress */ - case ButtonPress: - PanelIndex = MainPanel; - b = NULL; - do - if (PanelIndex->uber->swallow) /* is the panel shown? */ - { - UberButton = PanelIndex->uber; - MyWindow = UberButton->IconWinParent; - if (Event.xany.window == MyWindow) - CurrentButton = b = - select_button(UberButton,Event.xbutton.x,Event.xbutton.y); - } - while (!b && PanelIndex->next && (PanelIndex = PanelIndex->next)) - ; - - if(!b || !(b->flags&b_Action) || - ((act=GetButtonAction(b,Event.xbutton.button)) == NULL && - (act=GetButtonAction(b,0)) == NULL)) - { - CurrentButton=NULL; - break; - } - - /* record the panel, the button pressed */ - CurrentPanel = PanelIndex; - UberButton = CurrentPanel->uber; - MyWindow = UberButton->IconWinParent; - - RedrawButton(b,0); - if(strncasecmp(act,"popup",5)!=0) - { - if (strncasecmp(act, "panel-", 6) == 0) - Slide(seekpanel(b), b); - break; - } - else /* i.e. action is Popup */ - XUngrabPointer(Dpy,CurrentTime); /* And fall through */ - - case KeyRelease: - case ButtonRelease: - PanelIndex = MainPanel; - b = NULL; - do - { if (PanelIndex->uber->swallow) - { - UberButton = PanelIndex->uber; - MyWindow = UberButton->IconWinParent; - if (Event.xany.window == MyWindow) - b=select_button(UberButton,Event.xbutton.x,Event.xbutton.y); - } - } while (!b && (PanelIndex = PanelIndex->next)); - - if(!(act=GetButtonAction(b,Event.xbutton.button))) - act=GetButtonAction(b,0); - if(b && b==CurrentButton && act) - { - if(strncasecmp(act,"Exec",4)==0) - { - /* close current subpanel */ - if (PanelIndex != MainPanel) - Slide(PanelIndex, NULL); - - /* Look for Exec "identifier", in which case the button - stays down until window "identifier" materializes */ - i=4; - while(act[i]!=0 && act[i]!='"' && - isspace(act[i])) - i++; - if(act[i] == '"') - { - i2=i+1; - while(act[i2]!=0 && act[i2]!='"') - i2++; - - if(i2-i>1) - { - b->flags|=b_Hangon; - b->hangon = mymalloc(i2-i); - strncpy(b->hangon,&act[i+1],i2-i-1); - b->hangon[i2-i-1] = 0; - } - i2++; - } - else - i2=i; - - tmp=mymalloc(strlen(act)+1); - strcpy(tmp,"Exec "); - while(act[i2]!=0 && isspace(act[i2])) - i2++; - strcat(tmp,&act[i2]); - MySendText(fd,tmp,0); - free(tmp); - } - else if(strncasecmp(act,"DumpButtons",11)==0) - DumpButtons(UberButton); - else if(strncasecmp(act,"SaveButtons",11)==0) - SaveButtons(UberButton); - else if(strncasecmp(act,"panel",5)) - MySendText(fd,act,0); - } - - /* recover the old record */ - UberButton = CurrentPanel->uber; /* the panel, the button pressed */ - MyWindow = UberButton->IconWinParent; - - b=CurrentButton; - CurrentButton=NULL; - if(b) - RedrawButton(b,0); - break; - - case ClientMessage: - if(Event.xclient.format==32 && - Event.xclient.data.l[0]==_XA_WM_DEL_WIN) - { - for (ppi = MainPanel->next; ppi != NULL; - ppi = ppi->next) - { - if (ppi->uber->IconWinParent == Event.xany.window) - { - /* Only close the panel */ - Slide(ppi, NULL); - break; - } - } - if (ppi == NULL) - DeadPipe(1); - } - break; - - case PropertyNotify: - if(Event.xany.window==None) - break; - ub=UberButton;button=-1; - while(NextButton(&ub,&b,&button,0)) - if((buttonSwallowCount(b)==3) && Event.xany.window==b->IconWin) - { - if(Event.xproperty.atom==XA_WM_NAME && - buttonSwallow(b)&b_UseTitle) - { - if(b->flags&b_Title) - free(b->title); - b->flags|=b_Title; - XFetchName(Dpy,b->IconWin,&tmp); - CopyString(&b->title,tmp); - XFree(tmp); - MakeButton(b); - } - else if((Event.xproperty.atom==XA_WM_NORMAL_HINTS) && - (!(buttonSwallow(b)&b_NoHints))) - { - long supp; - if(!XGetWMNormalHints(Dpy,b->IconWin,b->hints,&supp)) - b->hints->flags = 0; - MakeButton(b); - } - RedrawButton(b,1); - } - break; - - /* Not really sure if this is abandon all hope.. */ - /* case UnmapNotify: */ - case DestroyNotify: - ub=UberButton;button=-1; - while(NextButton(&ub,&b,&button,0)) - if((buttonSwallowCount(b)==3) && Event.xany.window==b->IconWin) - { -# ifdef DEBUG_HANGON - fprintf(stderr, - "%s: Button 0x%06x lost its window 0x%x (\"%s\")", - MyName,(ushort)b,(ushort)b->IconWin,b->hangon); -# endif - b->swallow&=~b_Count; - b->IconWin=None; - if(buttonSwallow(b)&b_Respawn && b->hangon && b->spawn) - { -# ifdef DEBUG_HANGON - fprintf(stderr,", respawning\n"); -# endif - b->swallow|=1; - b->flags|=b_Swallow|b_Hangon; - MySendText(fd,b->spawn,0); - } - else - { - b->flags&=~b_Swallow; -# ifdef DEBUG_HANGON - fprintf(stderr,"\n"); -# endif - } - break; + break; + + case ConfigureNotify: + /* XGetGeometry(Dpy, MyWindow, &root, &x, &y, + (ushort*)&tw,(ushort*)&th, + (ushort*)&border_width,(ushort*)&depth); + if(tw!=Width || th!=Height) + { + Width=tw; + Height=th; + SetButtonSize(UberButton,Width,Height); + button=-1;ub=UberButton; + while(NextButton(&ub,&b,&button,0)) + MakeButton(b); + RedrawWindow(NULL); + } */ +/* I don't like to change its size after it started */ + break; + + case KeyPress: + XLookupString( + &Event.xkey, buffer, 10, &keysym, 0); + if (keysym != XK_Return && + keysym != XK_KP_Enter && + keysym != XK_Linefeed) + break; /* fall through to ButtonPress */ + case ButtonPress: { + button_info *ub2, *b2; + int b2num = -1; + + ub2 = UberButton; + while (NextButton(&ub2, &b2, &b2num, 0)) + if ((buttonSwallowCount(b2) == 3) && + Event.xany.window == b2->IconWin) { + b = b2; + CurrentButton = b; + break; + } + } + if (!b) { + PanelIndex = MainPanel; + b = NULL; + do + if (PanelIndex->uber + ->swallow) { /* is the panel + shown? */ + UberButton = PanelIndex->uber; + MyWindow = + UberButton->IconWinParent; + if (Event.xany.window == + MyWindow) + CurrentButton = b = + select_button( + UberButton, + Event.xbutton.x, + Event.xbutton + .y); + } + while (!b && PanelIndex->next && + (PanelIndex = PanelIndex->next)); + } else { + button_info *btn; + + btn = b; + PanelIndex = MainPanel; + while (PanelIndex && + PanelIndex->uber != + btn->uber) + PanelIndex = + PanelIndex->next; + UberButton = CurrentPanel ? + CurrentPanel->uber : + PanelIndex ? PanelIndex->uber : + UberButton; + MyWindow = UberButton->IconWinParent; + } + + if (!b || !(b->flags & b_Action) || + ((act = GetButtonAction( + b, Event.xbutton.button)) == NULL && + (act = GetButtonAction(b, 0)) == + NULL)) { + CurrentButton = NULL; + break; + } + + /* record the panel, the button pressed */ + CurrentPanel = PanelIndex; + UberButton = CurrentPanel->uber; + MyWindow = UberButton->IconWinParent; + + RedrawButton(b, 0); + if (strncasecmp(act, "popup", 5) != 0) { + if (strncasecmp(act, "panel-", 6) == 0) + Slide(seekpanel(b), b); + break; + } else /* i.e. action is Popup */ + XUngrabPointer(Dpy, + CurrentTime); /* And fall through */ + + case KeyRelease: + case ButtonRelease: + PanelIndex = MainPanel; + b = NULL; + do { + if (PanelIndex->uber->swallow) { + UberButton = PanelIndex->uber; + MyWindow = + UberButton->IconWinParent; + if (Event.xany.window == + MyWindow) + b = select_button( + UberButton, + Event.xbutton.x, + Event.xbutton.y); + } + } while (!b && (PanelIndex = PanelIndex->next)); + + if (!(act = GetButtonAction( + b, Event.xbutton.button))) + act = GetButtonAction(b, 0); + if (b && b == CurrentButton && act) { + if (strncasecmp(act, "Exec", 4) == 0) { + /* close current subpanel */ + if (PanelIndex != MainPanel) + Slide(PanelIndex, NULL); + + /* Look for Exec "identifier", + in which case the button + stays down until + window "identifier" + materializes */ + i = 4; + while (act[i] != 0 && + act[i] != '"' && + isspace(act[i])) + i++; + if (act[i] == '"') { + i2 = i + 1; + while (act[i2] != 0 && + act[i2] != '"') + i2++; + + if (i2 - i > 1) { + b->flags |= + b_Hangon; + b->hangon = + xmalloc( + i2 - i); + strncpy( + b->hangon, + &act[i + 1], + i2 - i - 1); + b->hangon[i2 - + i - + 1] = + 0; + } + i2++; + } else + i2 = i; + + { + size_t tmp_len = + strlen(act) + 1; + tmp = xmalloc( + (int)tmp_len); + strlcpy(tmp, "Exec ", + tmp_len); + while (act[i2] != 0 && + isspace(act[i2])) + i2++; + strlcat(tmp, &act[i2], + tmp_len); + MySendText(fd, tmp, 0); + free(tmp); + } + } else if (strncasecmp(act, + "DumpButtons", 11) == 0) + DumpButtons(UberButton); + else if (strncasecmp(act, "SaveButtons", + 11) == 0) + SaveButtons(UberButton); + else if (strncasecmp(act, "panel", 5)) + MySendText(fd, act, 0); + } + + /* recover the old record */ + UberButton = + CurrentPanel->uber; /* the panel, the button + pressed */ + MyWindow = UberButton->IconWinParent; + + b = CurrentButton; + CurrentButton = NULL; + if (b) + RedrawButton(b, 0); + break; + + case ClientMessage: + if (Event.xclient.format == 32 && + Event.xclient.data.l[0] == _XA_WM_DEL_WIN) { + for (ppi = MainPanel->next; ppi != NULL; + ppi = ppi->next) { + if (ppi->uber->IconWinParent == + Event.xany.window) { + /* Only close the panel + */ + Slide(ppi, NULL); + break; + } + } + if (ppi == NULL) + DeadPipe(1); + } + break; + + case PropertyNotify: + if (Event.xany.window == None) + break; + ub = UberButton; + button = -1; + while (NextButton(&ub, &b, &button, 0)) + if ((buttonSwallowCount(b) == 3) && + Event.xany.window == b->IconWin) { + if (Event.xproperty.atom == + XA_WM_NAME && + buttonSwallow(b) & + b_UseTitle) { + if (b->flags & b_Title) + free(b->title); + b->flags |= b_Title; + XFetchName(Dpy, + b->IconWin, &tmp); + CopyString( + &b->title, tmp); + XFree(tmp); + MakeButton(b); + } else if ((Event.xproperty.atom == + XA_WM_NORMAL_HINTS) && + (!(buttonSwallow(b) & + b_NoHints))) { + long supp; + if (!XGetWMNormalHints( + Dpy, b->IconWin, + b->hints, + &supp)) + b->hints + ->flags = 0; + MakeButton(b); + } + RedrawButton(b, 1); + } + break; + + /* Not really sure if this is abandon all hope.. */ + /* case UnmapNotify: */ + case DestroyNotify: + ub = UberButton; + button = -1; + while (NextButton(&ub, &b, &button, 0)) + if ((buttonSwallowCount(b) == 3) && + Event.xany.window == b->IconWin) { +#ifdef DEBUG_HANGON + fprintf(stderr, + "%s: Button 0x%06x lost " + "its window 0x%x (\"%s\")", + MyName, (ushort)b, + (ushort)b->IconWin, + b->hangon); +#endif + b->swallow &= ~b_Count; + b->IconWin = None; + if (buttonSwallow(b) & + b_Respawn && + b->hangon && b->spawn) { +#ifdef DEBUG_HANGON + fprintf(stderr, + ", respawning\n"); +#endif + b->swallow |= 1; + b->flags |= b_Swallow | + b_Hangon; + MySendText( + fd, b->spawn, 0); + } else { + b->flags &= ~b_Swallow; +#ifdef DEBUG_HANGON + fprintf(stderr, "\n"); +#endif + } + break; + } + break; + + default: +#ifdef DEBUG_EVENTS + fprintf(stderr, + "%s: Event fell through unhandled\n", + MyName); +#endif + break; + } } - break; + } +} - default: -# ifdef DEBUG_EVENTS - fprintf(stderr,"%s: Event fell through unhandled\n",MyName); -# endif - break; - } - } - } +static void +DrainDestroyEvents(void) +{ + XEvent dummy; + int button; + button_info *ub, *b; + + while (XCheckTypedEvent(Dpy, DestroyNotify, &dummy)) { + ub = UberButton; + button = -1; + while (NextButton(&ub, &b, &button, 0)) + if ((buttonSwallowCount(b) == 3) && + dummy.xany.window == b->IconWin) { + b->swallow &= ~b_Count; + b->IconWin = None; + if (buttonSwallow(b) & b_Respawn && + b->hangon && b->spawn) { + b->swallow |= 1; + b->flags |= b_Swallow | b_Hangon; + MySendText(fd, b->spawn, 0); + } else { + b->flags &= ~b_Swallow; + } + break; + } + } } /** @@ -998,408 +1130,411 @@ void Loop(void) *** Draws the window by traversing the button tree, draws all if NULL is given, *** otherwise only the given button. **/ -void RedrawWindow(button_info *b) +void +RedrawWindow(button_info *b) { - int button; - XEvent dummy; - button_info *ub; + int button; + XEvent dummy; + button_info *ub; - if(ready<1) - return; + if (ready < 1) + return; - /* Flush expose events */ - while (XCheckTypedWindowEvent (Dpy, MyWindow, Expose, &dummy)); + /* Flush expose events */ + while (XCheckTypedWindowEvent(Dpy, MyWindow, Expose, &dummy)) + ; - if(b) - { - RedrawButton(b,0); - return; - } + if (b) { + RedrawButton(b, 0); + return; + } - button=-1;ub=UberButton; - while(NextButton(&ub,&b,&button,1)) - RedrawButton(b,1); + button = -1; + ub = UberButton; + while (NextButton(&ub, &b, &button, 1)) + RedrawButton(b, 1); } /** *** LoadIconFile() **/ -int LoadIconFile(char *s,FvwmPicture **p) +int +LoadIconFile(char *s, FvwmPicture **p) { - *p=CachePicture(Dpy,Root,iconPath,pixmapPath,s, save_color_limit); - if(*p) - return 1; - return 0; + *p = CachePicture(Dpy, Root, iconPath, pixmapPath, s, save_color_limit); + if (*p) + return 1; + return 0; } /** *** RecursiveLoadData() *** Loads colors, fonts and icons, and calculates buttonsizes **/ -void RecursiveLoadData(button_info *b,int *maxx,int *maxy) +void +RecursiveLoadData(button_info *b, int *maxx, int *maxy) { - int i,j,x=0,y=0; - XFontStruct *font; + int i, j, x = 0, y = 0; + XFontStruct *font; - if(!b) return; + if (!b) + return; #ifdef DEBUG_LOADDATA - fprintf(stderr,"%s: Loading: Button 0x%06x: colors",MyName,(ushort)b); + fprintf( + stderr, "%s: Loading: Button 0x%06x: colors", MyName, (ushort)b); #endif - /* Load colors */ - if(b->flags&b_Fore) - b->fc=GetColor(b->fore); - if(b->flags&b_Back) - { - if(b->flags&b_IconBack) - { - if(!LoadIconFile(b->back,&b->backicon)) - b->flags&=~b_Back; - } - else - { - b->bc=GetColor(b->back); - b->hc=GetHilite(b->bc); - b->sc=GetShadow(b->bc); - } - } - if(b->flags&b_Container) - { -# ifdef DEBUG_LOADDATA - fprintf(stderr,", colors2"); -# endif - if(b->c->flags&b_Fore) - b->c->fc=GetColor(b->c->fore); - if(b->c->flags&b_Back) - { - if(b->c->flags&b_IconBack && !(b->c->flags&b_TransBack)) - { - if(!LoadIconFile(b->c->back_file,&b->c->backicon)) - b->c->flags&=~b_IconBack; - } - - { - b->c->bc=GetColor(b->c->back); - b->c->hc=GetHilite(b->c->bc); - b->c->sc=GetShadow(b->c->bc); - } + /* Load colors */ + if (b->flags & b_Fore) + b->fc = GetColor(b->fore); + if (b->flags & b_Back) { + if (b->flags & b_IconBack) { + if (!LoadIconFile(b->back, &b->backicon)) + b->flags &= ~b_Back; + } else { + b->bc = GetColor(b->back); + b->hc = GetHilite(b->bc); + b->sc = GetShadow(b->bc); + } } - } - - /* Load the font */ - if(b->flags&b_Font) - { -# ifdef DEBUG_LOADDATA - fprintf(stderr,", font \"%s\"",b->font_string); -# endif - - fprintf(stderr, "b=0x%lx, font_string=%s\n", - (unsigned long)b, b? b->font_string : "(NULL)"); - if(strncasecmp(b->font_string,"none",4)==0) - b->font=NULL; - else if(!(b->font=XLoadQueryFont(Dpy,b->font_string))) - { - b->flags&=~b_Font; - fprintf(stderr,"%s: Couldn't load font %s\n",MyName, - b->font_string); + if (b->flags & b_Container) { +#ifdef DEBUG_LOADDATA + fprintf(stderr, ", colors2"); +#endif + if (b->c->flags & b_Fore) + b->c->fc = GetColor(b->c->fore); + if (b->c->flags & b_Back) { + if (b->c->flags & b_IconBack && + !(b->c->flags & b_TransBack)) { + if (!LoadIconFile( + b->c->back_file, &b->c->backicon)) + b->c->flags &= ~b_IconBack; + } + + { + b->c->bc = GetColor(b->c->back); + b->c->hc = GetHilite(b->c->bc); + b->c->sc = GetShadow(b->c->bc); + } + } } - } - - if(b->flags&b_Container && b->c->flags&b_Font) - { -# ifdef DEBUG_LOADDATA - fprintf(stderr,", font2 \"%s\"",b->c->font_string); -# endif - if(strncasecmp(b->c->font_string,"none",4)==0) - b->c->font=NULL; - else if(!(b->c->font=XLoadQueryFont(Dpy,b->c->font_string))) - { - fprintf(stderr,"%s: Couldn't load font %s\n",MyName, - b->c->font_string); - if(b==UberButton) - { - if(!(b->c->font=XLoadQueryFont(Dpy,"fixed"))) - fprintf(stderr,"%s: Couldn't load font fixed\n",MyName); - } - else - b->c->flags&=~b_Font; + + /* Load the font */ + if (b->flags & b_Font) { +#ifdef DEBUG_LOADDATA + fprintf(stderr, ", font \"%s\"", b->font_string); +#endif + +#ifdef DEBUG_LOADDATA + fprintf(stderr, "b=0x%lx, font_string=%s\n", (unsigned long)b, + b ? b->font_string : "(NULL)"); +#endif + if (strncasecmp(b->font_string, "none", 4) == 0) + b->font = NULL; + else if (!(b->font = XLoadQueryFont(Dpy, b->font_string))) { + b->flags &= ~b_Font; + fprintf(stderr, "%s: Couldn't load font %s\n", MyName, + b->font_string); + } } - } + if (b->flags & b_Container && b->c->flags & b_Font) { +#ifdef DEBUG_LOADDATA + fprintf(stderr, ", font2 \"%s\"", b->c->font_string); +#endif + if (strncasecmp(b->c->font_string, "none", 4) == 0) + b->c->font = NULL; + else if (!(b->c->font = + XLoadQueryFont(Dpy, b->c->font_string))) { + fprintf(stderr, "%s: Couldn't load font %s\n", MyName, + b->c->font_string); + if (b == UberButton) { + if (!(b->c->font = + XLoadQueryFont(Dpy, "fixed"))) + fprintf(stderr, + "%s: Couldn't load font fixed\n", + MyName); + } else + b->c->flags &= ~b_Font; + } + } + /* Calculate subbutton sizes */ + if (b->flags & b_Container && b->c->num_buttons) { +#ifdef DEBUG_LOADDATA + fprintf(stderr, ", entering container\n"); +#endif + for (i = 0; i < b->c->num_buttons; i++) + if (b->c->buttons[i]) + RecursiveLoadData(b->c->buttons[i], &x, &y); - /* Calculate subbutton sizes */ - if(b->flags&b_Container && b->c->num_buttons) - { -# ifdef DEBUG_LOADDATA - fprintf(stderr,", entering container\n"); -# endif - for(i=0;ic->num_buttons;i++) - if(b->c->buttons[i]) - RecursiveLoadData(b->c->buttons[i],&x,&y); + if (b->c->flags & b_Size) { + x = b->c->minx; + y = b->c->miny; + } +#ifdef DEBUG_LOADDATA + fprintf(stderr, "%s: Loading: Back to container 0x%06x", MyName, + (ushort)b); +#endif - if(b->c->flags&b_Size) - { - x=b->c->minx; - y=b->c->miny; - } -# ifdef DEBUG_LOADDATA - fprintf(stderr,"%s: Loading: Back to container 0x%06x",MyName,(ushort)b); -# endif - - b->c->ButtonWidth=x; - b->c->ButtonHeight=y; - x*=b->c->num_columns; - y*=b->c->num_rows; - } - - - - i=0;j=0; - - /* Load the icon */ - if(b->flags&b_Icon && LoadIconFile(b->icon_file,&b->icon)) - { -# ifdef DEBUG_LOADDATA - fprintf(stderr,", icon \"%s\"",b->icon_file); -# endif - i=b->icon->width; - j=b->icon->height; - } - else - b->flags&=~b_Icon; - - if(b->flags&b_Title && (font=buttonFont(b))) - { -# ifdef DEBUG_LOADDATA - fprintf(stderr,", title \"%s\"",b->title); -# endif - if(buttonJustify(b)&b_Horizontal) - { - i+=buttonXPad(b)+XTextWidth(font,b->title,strlen(b->title)); - j=max(j,font->ascent+font->descent); + b->c->ButtonWidth = x; + b->c->ButtonHeight = y; + x *= b->c->num_columns; + y *= b->c->num_rows; } - else - { - i=max(i,XTextWidth(font,b->title,strlen(b->title))); - j+=font->ascent+font->descent; + + i = 0; + j = 0; + + /* Load the icon */ + if (b->flags & b_Icon && LoadIconFile(b->icon_file, &b->icon)) { +#ifdef DEBUG_LOADDATA + fprintf(stderr, ", icon \"%s\"", b->icon_file); +#endif + i = b->icon->width; + j = b->icon->height; + } else + b->flags &= ~b_Icon; + + if (b->flags & b_Title && (font = buttonFont(b))) { +#ifdef DEBUG_LOADDATA + fprintf(stderr, ", title \"%s\"", b->title); +#endif + if (buttonJustify(b) & b_Horizontal) { + i += buttonXPad(b) + + XTextWidth(font, b->title, strlen(b->title)); + j = max(j, font->ascent + font->descent); + } else { + i = max( + i, XTextWidth(font, b->title, strlen(b->title))); + j += font->ascent + font->descent; + } } - } - x+=i; - y+=j; + x += i; + y += j; - if(b->flags&b_Size) - { - x=b->minx; - y=b->miny; - } + if (b->flags & b_Size) { + x = b->minx; + y = b->miny; + } - x+=2*(buttonFrame(b)+buttonXPad(b)); - y+=2*(buttonFrame(b)+buttonYPad(b)); + x += 2 * (buttonFrame(b) + buttonXPad(b)); + y += 2 * (buttonFrame(b) + buttonYPad(b)); - x/=b->BWidth; - y/=b->BHeight; + x /= b->BWidth; + y /= b->BHeight; - *maxx=max(x,*maxx); - *maxy=max(y,*maxy); -# ifdef DEBUG_LOADDATA - fprintf(stderr,", size %ux%u, done\n",x,y); -# endif + *maxx = max(x, *maxx); + *maxy = max(y, *maxy); +#ifdef DEBUG_LOADDATA + fprintf(stderr, ", size %ux%u, done\n", x, y); +#endif } /** *** CreateWindow() *** Sizes and creates the window **/ -void CreateWindow(button_info *ub,int maxx,int maxy) +void +CreateWindow(button_info *ub, int maxx, int maxy) { - XSizeHints mysizehints; - XGCValues gcv; - unsigned long gcm; - XClassHint myclasshints; - - x = CurrentPanel->uber->x; /* Geometry x where to put the panel */ - y = CurrentPanel->uber->y; /* Geometry y where to put the panel */ - xneg = CurrentPanel->uber->w; - yneg = CurrentPanel->uber->h; - - if(maxx<16) - maxx=16; - if(maxy<16) - maxy=16; - -# ifdef DEBUG_INIT - fprintf(stderr,"making atoms..."); -# endif - - _XA_WM_DEL_WIN = XInternAtom(Dpy,"WM_DELETE_WINDOW",0); - -# ifdef DEBUG_INIT - fprintf(stderr,"sizing..."); -# endif - - mysizehints.flags = PWinGravity | PResizeInc | PBaseSize; - - mysizehints.base_width=mysizehints.base_height=0; - -/* This should never be executed anyway, let's remove it. - if(ub->flags&b_Frame) - { - mysizehints.base_width+=2*abs(ub->framew); - mysizehints.base_height+=2*abs(ub->framew); - } - if(ub->flags&b_Padding) - { - mysizehints.base_width+=2*ub->xpad; - mysizehints.base_height+=2*ub->ypad; - } -*/ - mysizehints.width=mysizehints.base_width+maxx; - mysizehints.height=mysizehints.base_height+maxy; - mysizehints.width_inc=ub->c->num_columns; - mysizehints.height_inc=ub->c->num_rows; - mysizehints.base_height+=ub->c->num_rows*2; - mysizehints.base_width+=ub->c->num_columns*2; - - if(w>-1) /* from geometry */ - { -# ifdef DEBUG_INIT - fprintf(stderr,"constraining (w=%i)...",w); -# endif - ConstrainSize(&mysizehints,&w,&h); - mysizehints.width = w; - mysizehints.height = h; - mysizehints.flags |= USSize; - } - -# ifdef DEBUG_INIT - fprintf(stderr,"gravity..."); -# endif - mysizehints.x=0; - mysizehints.y=0; - if(x > -30000) - { - if (xneg) - { - mysizehints.x = DisplayWidth(Dpy,screen) + x - mysizehints.width; - gravity = NorthEastGravity; + XSizeHints mysizehints; + XGCValues gcv; + unsigned long gcm; + XClassHint myclasshints; + int req_w = -1; + int req_h = -1; + + x = CurrentPanel->uber->x; /* Geometry x where to put the panel */ + y = CurrentPanel->uber->y; /* Geometry y where to put the panel */ + xneg = CurrentPanel->uber->w; + yneg = CurrentPanel->uber->h; + gravity = NorthWestGravity; + + if (CurrentPanel) { + req_w = CurrentPanel->geom_w; + req_h = CurrentPanel->geom_h; } - else - mysizehints.x = x; - if (yneg) + w = (req_w > -1) ? req_w : -1; + h = (req_h > -1) ? req_h : -1; + + if (maxx < 16) + maxx = 16; + if (maxy < 16) + maxy = 16; + +#ifdef DEBUG_INIT + fprintf(stderr, "making atoms..."); +#endif + + _XA_WM_DEL_WIN = XInternAtom(Dpy, "WM_DELETE_WINDOW", 0); + +#ifdef DEBUG_INIT + fprintf(stderr, "sizing..."); +#endif + + mysizehints.flags = PWinGravity | PResizeInc | PBaseSize; + + mysizehints.base_width = mysizehints.base_height = 0; + + /* This should never be executed anyway, let's remove it. + if(ub->flags&b_Frame) + { + mysizehints.base_width+=2*abs(ub->framew); + mysizehints.base_height+=2*abs(ub->framew); + } + if(ub->flags&b_Padding) + { + mysizehints.base_width+=2*ub->xpad; + mysizehints.base_height+=2*ub->ypad; + } + */ + mysizehints.width = mysizehints.base_width + maxx; + mysizehints.height = mysizehints.base_height + maxy; + mysizehints.width_inc = ub->c->num_columns; + mysizehints.height_inc = ub->c->num_rows; + mysizehints.base_height += ub->c->num_rows * 2; + mysizehints.base_width += ub->c->num_columns * 2; + + if (req_w > -1 || req_h > -1) { /* from geometry */ +#ifdef DEBUG_INIT + fprintf(stderr, "constraining (w=%i,h=%i)...", req_w, req_h); +#endif + { + int tmp_w = (req_w > -1) ? req_w : mysizehints.width; + int tmp_h = (req_h > -1) ? req_h : mysizehints.height; + ConstrainSize(&mysizehints, &tmp_w, &tmp_h); + if (req_w > -1) + w = tmp_w; + else + w = -1; + if (req_h > -1) + h = tmp_h; + else + h = -1; + mysizehints.width = tmp_w; + mysizehints.height = tmp_h; + } + mysizehints.flags |= USSize; + } else { + w = -1; + h = -1; + } + +#ifdef DEBUG_INIT + fprintf(stderr, "gravity..."); +#endif + mysizehints.x = 0; + mysizehints.y = 0; + if (x > -30000) { + if (xneg) { + mysizehints.x = + DisplayWidth(Dpy, screen) + x - mysizehints.width; + gravity = NorthEastGravity; + } else + mysizehints.x = x; + if (yneg) { + mysizehints.y = + DisplayHeight(Dpy, screen) + y - mysizehints.height; + gravity = SouthWestGravity; + } else + mysizehints.y = y; + if (xneg && yneg) + gravity = SouthEastGravity; + mysizehints.flags |= USPosition; + } + mysizehints.win_gravity = gravity; + +#ifdef DEBUG_INIT + fprintf(stderr, "colors..."); +#endif + if (d_depth < 2) { + back_pix = GetColor("white"); + fore_pix = GetColor("black"); + hilite_pix = back_pix; + shadow_pix = fore_pix; + } else { + back_pix = GetColor(ub->c->back); + fore_pix = GetColor(ub->c->fore); + hilite_pix = GetHilite(back_pix); + shadow_pix = GetShadow(back_pix); + } + +#ifdef DEBUG_INIT + if (mysizehints.flags & USPosition) + fprintf(stderr, "create(%i,%i,%u,%u,1,%u,%u)...", mysizehints.x, + mysizehints.y, mysizehints.width, mysizehints.height, + (ushort)fore_pix, (ushort)back_pix); + else + fprintf(stderr, "create(-,-,%u,%u,1,%u,%u)...", + mysizehints.width, mysizehints.height, (ushort)fore_pix, + (ushort)back_pix); +#endif + + MyWindow = XCreateSimpleWindow(Dpy, Root, mysizehints.x, mysizehints.y, + mysizehints.width, mysizehints.height, 0, fore_pix, back_pix); + if (ub->c->flags & b_IconBack && !(ub->c->flags & b_TransBack)) + XSetWindowBackgroundPixmap( + Dpy, MyWindow, ub->c->backicon->picture); + +#ifdef DEBUG_INIT + fprintf(stderr, "properties..."); +#endif + XSetWMProtocols(Dpy, MyWindow, &_XA_WM_DEL_WIN, 1); + + if (CurrentPanel == MainPanel) { + myclasshints.res_name = strdup(MyName); + } else { + size_t total_len = strlen(MyName) + sizeof("Panel"); + myclasshints.res_name = (char *)xmalloc(total_len); + strlcpy(myclasshints.res_name, MyName, total_len); + strlcat(myclasshints.res_name, "Panel", total_len); + } + myclasshints.res_class = strdup( + (CurrentPanel == MainPanel) ? "FvwmButtons" : "FvwmButtonsPanel"); + { - mysizehints.y = DisplayHeight(Dpy,screen) + y - mysizehints.height; - gravity = SouthWestGravity; + XTextProperty mynametext; + char *list[] = {NULL, NULL}; + list[0] = (CurrentPanel == MainPanel) ? + MyName : + CurrentPanel->uber->title; + if (!XStringListToTextProperty(list, 1, &mynametext)) { + fprintf(stderr, "%s: Failed to convert name to XText\n", + MyName); + exit(1); + } + XSetWMProperties(Dpy, MyWindow, &mynametext, &mynametext, NULL, + 0, &mysizehints, NULL, &myclasshints); + XFree(mynametext.value); } - else - mysizehints.y = y; - if(xneg && yneg) - gravity = SouthEastGravity; - mysizehints.flags |= USPosition; - } - mysizehints.win_gravity = gravity; - -# ifdef DEBUG_INIT - fprintf(stderr,"colors..."); -# endif - if(d_depth < 2) - { - back_pix = GetColor("white"); - fore_pix = GetColor("black"); - hilite_pix = back_pix; - shadow_pix = fore_pix; - } - else - { - back_pix = GetColor(ub->c->back); - fore_pix = GetColor(ub->c->fore); - hilite_pix = GetHilite(back_pix); - shadow_pix = GetShadow(back_pix); - } - -# ifdef DEBUG_INIT - if(mysizehints.flags&USPosition) - fprintf(stderr,"create(%i,%i,%u,%u,1,%u,%u)...", - mysizehints.x,mysizehints.y, - mysizehints.width,mysizehints.height, - (ushort)fore_pix,(ushort)back_pix); - else - fprintf(stderr,"create(-,-,%u,%u,1,%u,%u)...", - mysizehints.width,mysizehints.height, - (ushort)fore_pix,(ushort)back_pix); -# endif - - MyWindow = XCreateSimpleWindow(Dpy,Root,mysizehints.x,mysizehints.y, - mysizehints.width,mysizehints.height, - 0,fore_pix,back_pix); - if(ub->c->flags&b_IconBack && !(ub->c->flags&b_TransBack)) - XSetWindowBackgroundPixmap(Dpy,MyWindow,ub->c->backicon->picture); - - -# ifdef DEBUG_INIT - fprintf(stderr,"properties..."); -# endif - XSetWMProtocols(Dpy,MyWindow,&_XA_WM_DEL_WIN,1); - -#if 0 - myclasshints.res_name=strdup((CurrentPanel == MainPanel) - ? MyName : CurrentPanel->uber->title); -#else - if (CurrentPanel == MainPanel) - { - myclasshints.res_name=strdup(MyName); - } - else - { - myclasshints.res_name=(char *)malloc(strlen(MyName)+6); - strcpy(myclasshints.res_name,MyName); - strcat(myclasshints.res_name,"Panel"); - } + + XSelectInput(Dpy, MyWindow, MW_EVENTS); + +#ifdef DEBUG_INIT + fprintf(stderr, "GC..."); #endif - myclasshints.res_class=strdup((CurrentPanel == MainPanel) - ? "FvwmButtons" : "FvwmButtonsPanel"); - - { - XTextProperty mynametext; - char *list[]={NULL,NULL}; - list[0]=(CurrentPanel == MainPanel) ? MyName : CurrentPanel->uber->title; - if(!XStringListToTextProperty(list,1,&mynametext)) - { - fprintf(stderr,"%s: Failed to convert name to XText\n",MyName); - exit(1); - } - XSetWMProperties(Dpy,MyWindow,&mynametext,&mynametext, - NULL,0,&mysizehints,NULL,&myclasshints); - XFree(mynametext.value); - } - - XSelectInput(Dpy,MyWindow,MW_EVENTS); - -# ifdef DEBUG_INIT - fprintf(stderr,"GC..."); -# endif - gcm = GCForeground|GCBackground; - gcv.foreground = fore_pix; - gcv.background = back_pix; - if(ub && ub->c && ub->c->font && ub->font) - { - gcv.font = ub->c->font->fid; - gcm |= GCFont; - } - NormalGC = XCreateGC(Dpy, Root, gcm, &gcv); - - free(myclasshints.res_class); - free(myclasshints.res_name); + gcm = GCForeground | GCBackground; + gcv.foreground = fore_pix; + gcv.background = back_pix; + if (ub && ub->c && ub->c->font && ub->font) { + gcv.font = ub->c->font->fid; + gcm |= GCFont; + } + NormalGC = XCreateGC(Dpy, Root, gcm, &gcv); + + free(myclasshints.res_class); + free(myclasshints.res_name); } /* ----------------------------- color functions --------------------------- */ #ifdef XPM -# define MyAllocColor(a,b,c) PleaseAllocColor(c) +#define MyAllocColor(a, b, c) PleaseAllocColor(c) #else -# define MyAllocColor(a,b,c) XAllocColor(a,b,c) +#define MyAllocColor(a, b, c) XAllocColor(a, b, c) #endif /** @@ -1408,27 +1543,31 @@ void CreateWindow(button_info *ub,int maxx,int maxy) *** space. **/ #ifdef XPM -int PleaseAllocColor(XColor *color) +int +PleaseAllocColor(XColor *color) { - char *xpm[] = {"1 1 1 1",NULL,"x"}; - XpmAttributes attr; - XImage *dummy1=None,*dummy2=None; - static char buf[20]; - - sprintf(buf,"x c #%04x%04x%04x",color->red,color->green,color->blue); - xpm[1]=buf; - attr.valuemask=XpmCloseness; - attr.closeness=40000; /* value used by fvwm and fvwmlib */ - - if(XpmCreateImageFromData(Dpy,xpm,&dummy1,&dummy2,&attr)!=XpmSuccess) - { - fprintf(stderr,"%s: Unable to get similar color\n",MyName); - exit(1); - } - color->pixel=XGetPixel(dummy1,0,0); - if(dummy1!=None)XDestroyImage(dummy1); - if(dummy2!=None)XDestroyImage(dummy2); - return 1; + char *xpm[] = {"1 1 1 1", NULL, "x"}; + XpmAttributes attr; + XImage *dummy1 = None, *dummy2 = None; + static char buf[20]; + + snprintf(buf, sizeof(buf), "x c #%04x%04x%04x", color->red, + color->green, color->blue); + xpm[1] = buf; + attr.valuemask = XpmCloseness; + attr.closeness = 40000; /* value used by fvwm and fvwmlib */ + + if (XpmCreateImageFromData(Dpy, xpm, &dummy1, &dummy2, &attr) != + XpmSuccess) { + fprintf(stderr, "%s: Unable to get similar color\n", MyName); + exit(1); + } + color->pixel = XGetPixel(dummy1, 0, 0); + if (dummy1 != None) + XDestroyImage(dummy1); + if (dummy2 != None) + XDestroyImage(dummy2); + return 1; } #endif @@ -1436,86 +1575,71 @@ int PleaseAllocColor(XColor *color) *** nocolor() *** Complain **/ -void nocolor(const char *a, const char *b) +void +nocolor(const char *a, const char *b) { - fprintf(stderr,"%s: Can't %s %s, quitting, sorry...\n", MyName, a,b); - exit(1); + fprintf(stderr, "%s: Can't %s %s, quitting, sorry...\n", MyName, a, b); + exit(1); } /** *** GetColor() *** Loads a single color **/ -Pixel GetColor(char *name) +Pixel +GetColor(char *name) { - XColor color; - XWindowAttributes attributes; - - XGetWindowAttributes(Dpy,Root,&attributes); - color.pixel = 0; - if (!XParseColor (Dpy, attributes.colormap, name, &color)) - nocolor("parse",name); - else if(!MyAllocColor(Dpy,attributes.colormap,&color)) - nocolor("alloc",name); - return color.pixel; + XColor color; + XWindowAttributes attributes; + + XGetWindowAttributes(Dpy, Root, &attributes); + color.pixel = 0; + if (!XParseColor(Dpy, attributes.colormap, name, &color)) + nocolor("parse", name); + else if (!MyAllocColor(Dpy, attributes.colormap, &color)) + nocolor("alloc", name); + return color.pixel; } - /* --------------------------------------------------------------------------*/ #ifdef DEBUG_EVENTS -void DebugEvents(XEvent *event) +void +DebugEvents(XEvent *event) { - char *event_names[]={NULL,NULL, - "KeyPress","KeyRelease","ButtonPress", - "ButtonRelease","MotionNotify","EnterNotify", - "LeaveNotify","FocusIn","FocusOut", - "KeymapNotify","Expose","GraphicsExpose", - "NoExpose","VisibilityNotify","CreateNotify", - "DestroyNotify","UnmapNotify","MapNotify", - "MapRequest","ReparentNotify","ConfigureNotify", - "ConfigureRequest","GravityNotify","ResizeRequest", - "CirculateNotify","CirculateRequest","PropertyNotify", - "SelectionClear","SelectionRequest","SelectionNotify", - "ColormapNotify","ClientMessage","MappingNotify"}; - fprintf(stderr,"%s: Received %s event from window 0x%x\n", - MyName,event_names[event->type],(ushort)event->xany.window); + char *event_names[] = {NULL, NULL, "KeyPress", "KeyRelease", + "ButtonPress", "ButtonRelease", "MotionNotify", "EnterNotify", + "LeaveNotify", "FocusIn", "FocusOut", "KeymapNotify", "Expose", + "GraphicsExpose", "NoExpose", "VisibilityNotify", "CreateNotify", + "DestroyNotify", "UnmapNotify", "MapNotify", "MapRequest", + "ReparentNotify", "ConfigureNotify", "ConfigureRequest", + "GravityNotify", "ResizeRequest", "CirculateNotify", + "CirculateRequest", "PropertyNotify", "SelectionClear", + "SelectionRequest", "SelectionNotify", "ColormapNotify", + "ClientMessage", "MappingNotify"}; + fprintf(stderr, "%s: Received %s event from window 0x%x\n", MyName, + event_names[event->type], (ushort)event->xany.window); } #endif #ifdef DEBUG_FVWM -void DebugFvwmEvents(unsigned long type) +void +DebugFvwmEvents(unsigned long type) { - char *events[]={ -"M_NEW_PAGE", -"M_NEW_DESK", -"M_ADD_WINDOW", -"M_RAISE_WINDOW", -"M_LOWER_WINDOW", -"M_CONFIGURE_WINDOW", -"M_FOCUS_CHANGE", -"M_DESTROY_WINDOW", -"M_ICONIFY", -"M_DEICONIFY", -"M_WINDOW_NAME", -"M_ICON_NAME", -"M_RES_CLASS", -"M_RES_NAME", -"M_END_WINDOWLIST", -"M_ICON_LOCATION", -"M_MAP", -"M_ERROR", -"M_CONFIG_INFO", -"M_END_CONFIG_INFO", -"M_ICON_FILE", -"M_DEFAULTICON",NULL}; - int i=0; - while(events[i]) - { - if(type&1< 0) - { - - if(FD_ISSET(x_fd, &in_fdset)) - { - if(XPending(Dpy)) - { - XNextEvent(Dpy,event); - miss_counter = 0; -# ifdef DEBUG_EVENTS - DebugEvents(event); -# endif - return 1; - } - else - miss_counter++; - if(miss_counter > 100) - DeadPipe(0); - } - - if(FD_ISSET(fd[1], &in_fdset)) - { - if((count = ReadFvwmPacket(fd[1], header, &body)) > 0) - { - process_message(header[1],body); - free(body); + fd_set in_fdset; + unsigned long header[HEADER_SIZE]; + int count; + static int miss_counter = 0; + unsigned long *body; + + if (XPending(Dpy)) { + XNextEvent(Dpy, event); +#ifdef DEBUG_EVENTS + DebugEvents(event); +#endif + return 1; } - } - } - return 0; + FD_ZERO(&in_fdset); + FD_SET(x_fd, &in_fdset); + FD_SET(fd[1], &in_fdset); + + if (select(fd_width, SELECT_TYPE_ARG234 & in_fdset, 0, 0, NULL) > 0) { + if (FD_ISSET(x_fd, &in_fdset)) { + if (XPending(Dpy)) { + XNextEvent(Dpy, event); + miss_counter = 0; +#ifdef DEBUG_EVENTS + DebugEvents(event); +#endif + return 1; + } else + miss_counter++; + if (miss_counter > 100) + DeadPipe(0); + } + + if (FD_ISSET(fd[1], &in_fdset)) { + if ((count = ReadFvwmPacket(fd[1], header, &body)) > + 0) { + process_message(header[1], body); + free(body); + } + } + } + return 0; } /** @@ -1582,67 +1699,69 @@ int My_XNextEvent(Display *Dpy, XEvent *event) *** Is run after the windowlist is checked. If any button hangs on UseOld, *** it has failed, so we try to spawn a window for them. **/ -void SpawnSome() +void +SpawnSome() { - static char first=1; - button_info *b,*ub=UberButton; - int button=-1; - if(!first) - return; - first=0; - while(NextButton(&ub,&b,&button,0)) - if((buttonSwallowCount(b)==1) && b->flags&b_Hangon && - buttonSwallow(b)&b_UseOld) - if(b->spawn) - { -# ifdef DEBUG_HANGON - fprintf(stderr,"%s: Button 0x%06x did not find a \"%s\" window, %s", - MyName,(ushort)b,b->hangon,"spawning own\n"); -# endif - SendText(fd,b->spawn,0); - } + static char first = 1; + button_info *b, *ub = UberButton; + int button = -1; + if (!first) + return; + first = 0; + while (NextButton(&ub, &b, &button, 0)) + if ((buttonSwallowCount(b) == 1) && b->flags & b_Hangon && + buttonSwallow(b) & b_UseOld) + if (b->spawn) { +#ifdef DEBUG_HANGON + fprintf(stderr, + "%s: Button 0x%06x did not find a \"%s\" " + "window, %s", + MyName, (ushort)b, b->hangon, + "spawning own\n"); +#endif + SendText(fd, b->spawn, 0); + } } /** *** process_message() *** Process window list messages **/ -void process_message(unsigned long type,unsigned long *body) +void +process_message(unsigned long type, unsigned long *body) { -# ifdef DEBUG_FVWM - DebugFvwmEvents(type); -# endif - panel_info *PanelIndex = MainPanel; - do - { - UberButton = PanelIndex->uber; - MyWindow = UberButton->IconWinParent; - - switch(type) - { - case M_NEW_DESK: - new_desk = body[0]; - RedrawWindow(NULL); - break; - case M_END_WINDOWLIST: - SpawnSome(); - RedrawWindow(NULL); - break; - case M_MAP: - swallow(body); - break; - case M_RES_NAME: - case M_RES_CLASS: - case M_WINDOW_NAME: - CheckForHangon(body); - break; - default: - break; - } - - } while ((PanelIndex = PanelIndex->next)); -} +#ifdef DEBUG_FVWM + DebugFvwmEvents(type); +#endif + panel_info *PanelIndex = MainPanel; + do { + UberButton = PanelIndex->uber; + MyWindow = UberButton->IconWinParent; + switch (type) { + case M_NEW_DESK: + new_desk = body[0]; + DrainDestroyEvents(); + RedrawWindow(NULL); + break; + case M_END_WINDOWLIST: + SpawnSome(); + DrainDestroyEvents(); + RedrawWindow(NULL); + break; + case M_MAP: + swallow(body); + break; + case M_RES_NAME: + case M_RES_CLASS: + case M_WINDOW_NAME: + CheckForHangon(body); + break; + default: + break; + } + } while ((PanelIndex = PanelIndex->next)); +} /* --------------------------------- swallow code -------------------------- */ @@ -1650,56 +1769,60 @@ void process_message(unsigned long type,unsigned long *body) *** CheckForHangon() *** Is the window here now? **/ -void CheckForHangon(unsigned long *body) +void +CheckForHangon(unsigned long *body) { - button_info *b,*ub=UberButton; - int button=-1; - ushort d; - char *cbody; - cbody = (char *)&body[3]; - - while(NextButton(&ub,&b,&button,0)) - if(b->flags&b_Hangon && strcmp(cbody,b->hangon)==0) - { - /* Is this a swallowing button in state 1? */ - if(buttonSwallowCount(b)==1) - { - b->swallow&=~b_Count; - b->swallow|=2; - b->IconWin=(Window)body[0]; - b->flags&=~b_Hangon; - - /* We get the parent of the window to compare with later... */ - b->IconWinParent= - GetRealGeometry(Dpy,b->IconWin, - &b->x,&b->y,&b->w,&b->h,&b->bw,&d); - -# ifdef DEBUG_HANGON - fprintf(stderr,"%s: Button 0x%06x %s 0x%lx \"%s\", parent 0x%lx\n", - MyName,(ushort)b,"will swallow window",body[0],cbody, - b->IconWinParent); -# endif - - if(buttonSwallow(b)&b_UseOld) - swallow(body); - } - else - { - /* Else it is an executing button with a confirmed kill */ -# ifdef DEBUG_HANGON - fprintf(stderr,"%s: Button 0x%06x %s 0x%lx \"%s\", released\n", - MyName,(int)b,"hung on window",body[0],cbody); -# endif - b->flags&=~b_Hangon; - free(b->hangon); - b->hangon=NULL; - RedrawButton(b,0); + button_info *b, *ub = UberButton; + int button = -1; + ushort d; + char *cbody; + cbody = (char *)&body[3]; + + while (NextButton(&ub, &b, &button, 0)) + if (b->flags & b_Hangon && strcmp(cbody, b->hangon) == 0) { + /* Is this a swallowing button in state 1? */ + if (buttonSwallowCount(b) == 1) { + b->swallow &= ~b_Count; + b->swallow |= 2; + b->IconWin = (Window)body[0]; + b->flags &= ~b_Hangon; + + /* We get the parent of the window to compare + * with later... */ + b->IconWinParent = + GetRealGeometry(Dpy, b->IconWin, &b->x, + &b->y, &b->w, &b->h, &b->bw, &d); + +#ifdef DEBUG_HANGON + fprintf(stderr, + "%s: Button 0x%06x %s 0x%lx \"%s\", parent " + "0x%lx\n", + MyName, (ushort)b, "will swallow window", + body[0], cbody, b->IconWinParent); +#endif - } - break; - } - else if(buttonSwallowCount(b)>=2 && (Window)body[0]==b->IconWin) - break; /* This window has already been swallowed by someone else! */ + if (buttonSwallow(b) & b_UseOld) + swallow(body); + } else { + /* Else it is an executing button with a confirmed kill + */ +#ifdef DEBUG_HANGON + fprintf(stderr, + "%s: Button 0x%06x %s 0x%lx \"%s\", " + "released\n", + MyName, (int)b, "hung on window", body[0], + cbody); +#endif + b->flags &= ~b_Hangon; + free(b->hangon); + b->hangon = NULL; + RedrawButton(b, 0); + } + break; + } else if (buttonSwallowCount(b) >= 2 && + (Window)body[0] == b->IconWin) + break; /* This window has already been swallowed by + someone else! */ } /** @@ -1707,102 +1830,130 @@ void CheckForHangon(unsigned long *body) *** Traverses window tree to find the real x,y of a window. Any simpler? *** Returns parent window, or None if failed. **/ -Window GetRealGeometry(Display *dpy,Window win,int *x,int *y,ushort *w, - ushort *h,ushort *bw,ushort *d) +Window +GetRealGeometry(Display *dpy, Window win, int *x, int *y, ushort *w, ushort *h, + ushort *bw, ushort *d) { - Window root; - Window rp=None; - Window *children; - unsigned int n; + Window root; + Window rp = None; + Window *children; + unsigned int n; - if(!XGetGeometry(dpy,win,&root,x,y,w,h,bw,d)) - return None; + if (!XGetGeometry(dpy, win, &root, x, y, w, h, bw, d)) + return None; - /* Now, x and y are not correct. They are parent relative, not root... */ - /* Hmm, ever heard of XTranslateCoordinates!? */ + /* Now, x and y are not correct. They are parent relative, not root... + */ + /* Hmm, ever heard of XTranslateCoordinates!? */ - XTranslateCoordinates(dpy,win,root,*x,*y,x,y,&rp); + XTranslateCoordinates(dpy, win, root, *x, *y, x, y, &rp); - XQueryTree(dpy,win,&root,&rp,&children,&n); - if (children) - XFree(children); + if (XQueryTree(dpy, win, &root, &rp, &children, &n) && children) + XFree(children); - return rp; + return rp; } /** *** swallow() *** Executed when swallowed windows get mapped **/ -void swallow(unsigned long *body) +void +swallow(unsigned long *body) { - char *temp; - button_info *ub=UberButton,*b; - int button=-1; - ushort d; - Window p; - - while(NextButton(&ub,&b,&button,0)) - if((b->IconWin==(Window)body[0]) && (buttonSwallowCount(b)==2)) - { - /* Store the geometry in case we need to unswallow. Get parent */ - p=GetRealGeometry(Dpy,b->IconWin,&b->x,&b->y,&b->w,&b->h,&b->bw,&d); -# ifdef DEBUG_HANGON - fprintf(stderr,"%s: Button 0x%06x %s 0x%lx, with parent 0x%lx\n", - MyName,(ushort)b,"trying to swallow window",body[0],p); -# endif - - if(p==None) /* This means the window is no more */ /* NO! wrong */ - { - fprintf(stderr,"%s: Window 0x%lx (\"%s\") disappeared %s\n", - MyName,b->IconWin,b->hangon,"before swallow complete"); - /* Now what? Nothing? For now: give up that button */ - b->flags&=~(b_Hangon|b_Swallow); - return; - } - - if(p!=b->IconWinParent) /* The window has been reparented */ - { - fprintf(stderr,"%s: Window 0x%lx (\"%s\") was %s (window 0x%lx)\n", - MyName,b->IconWin,b->hangon,"grabbed by someone else",p); - - /* Request a new windowlist, we might have ignored another - matching window.. */ - SendText(fd,"Send_WindowList",0); - - /* Back one square and lose one turn */ - b->swallow&=~b_Count; - b->swallow|=1; - b->flags|=b_Hangon; - return; - } - -# ifdef DEBUG_HANGON - fprintf(stderr,"%s: Button 0x%06x swallowed window 0x%lx\n", - MyName,(ushort)b,body[0]); -# endif + char *temp; + button_info *ub = UberButton, *b; + int button = -1; + ushort d; + Window p; + + while (NextButton(&ub, &b, &button, 0)) + if ((b->IconWin == (Window)body[0]) && + (buttonSwallowCount(b) == 2)) { + /* Store the geometry in case we need to unswallow. Get + * parent */ + p = GetRealGeometry(Dpy, b->IconWin, &b->x, &b->y, + &b->w, &b->h, &b->bw, &d); +#ifdef DEBUG_HANGON + fprintf(stderr, + "%s: Button 0x%06x %s 0x%lx, with parent 0x%lx\n", + MyName, (ushort)b, "trying to swallow window", + body[0], p); +#endif - b->swallow&=~b_Count; - b->swallow|=3; + if (p == + None) { /* This means the window is no more */ /* NO! + wrong + */ + fprintf(stderr, + "%s: Window 0x%lx (\"%s\") disappeared " + "%s\n", + MyName, b->IconWin, b->hangon, + "before swallow complete"); + /* Now what? Nothing? For now: give up that + * button */ + b->flags &= ~(b_Hangon | b_Swallow); + return; + } + + if (p != b->IconWinParent) { /* The window has been + reparented */ + fprintf(stderr, + "%s: Window 0x%lx (\"%s\") was %s (window " + "0x%lx)\n", + MyName, b->IconWin, b->hangon, + "grabbed by someone else", p); + + /* Request a new windowlist, we might have + ignored another matching window.. */ + SendText(fd, "Send_WindowList", 0); + + /* Back one square and lose one turn */ + b->swallow &= ~b_Count; + b->swallow |= 1; + b->flags |= b_Hangon; + return; + } + +#ifdef DEBUG_HANGON + fprintf(stderr, + "%s: Button 0x%06x swallowed window 0x%lx\n", + MyName, (ushort)b, body[0]); +#endif - /* "Swallow" the window! Place it in the void so we don't see it - until it's MoveResize'd */ - XReparentWindow(Dpy,b->IconWin,MyWindow,-1500,-1500); - XSelectInput(Dpy,b->IconWin,SW_EVENTS); - if(buttonSwallow(b)&b_UseTitle) - { - if(b->flags&b_Title) - free(b->title); - b->flags|=b_Title; - XFetchName(Dpy,b->IconWin,&temp); - CopyString(&b->title,temp); - XFree(temp); - } - XMapWindow(Dpy,b->IconWin); - MakeButton(b); - RedrawButton(b,1); - break; - } + b->swallow &= ~b_Count; + b->swallow |= 3; + + /* "Swallow" the window! Place it in the void so we + don't see it until it's MoveResize'd */ + XGrabServer(Dpy); + p = GetRealGeometry(Dpy, b->IconWin, &b->x, + &b->y, &b->w, &b->h, &b->bw, &d); + if (p != None) { + XReparentWindow(Dpy, b->IconWin, MyWindow, + -1500, -1500); + XSync(Dpy, False); + XSelectInput(Dpy, b->IconWin, SW_EVENTS); + if (buttonSwallow(b) & b_UseTitle) { + if (b->flags & b_Title) + free(b->title); + b->flags |= b_Title; + XFetchName(Dpy, b->IconWin, &temp); + CopyString(&b->title, temp); + XFree(temp); + } + XMapWindow(Dpy, b->IconWin); + MakeButton(b); + RedrawButton(b, 1); + } else { + fprintf(stderr, + "%s: Window 0x%lx disappeared during %s\n", + MyName, b->IconWin, "swallow"); + b->flags &= ~(b_Hangon | b_Swallow); + } + XUngrabServer(Dpy); + break; + } } /* @@ -1830,172 +1981,158 @@ void swallow(unsigned long *body) #define PanelPopUpStep 32 -panel_info *seekpanel (button_info *b) +panel_info * +seekpanel(button_info *b) { - panel_info *PanelIndex = MainPanel->next; /* skip the main panel */ + panel_info *PanelIndex = MainPanel->next; /* skip the main panel */ - while (PanelIndex && strcmp(b->hangon, PanelIndex->uber->title)) - PanelIndex = PanelIndex->next; + while (PanelIndex && strcmp(b->hangon, PanelIndex->uber->title)) + PanelIndex = PanelIndex->next; - return PanelIndex; + return PanelIndex; } -void Slide (panel_info *p, button_info *b) +void +Slide(panel_info *p, button_info *b) { - Window PanelWin; - Window root; - int x, y, iw, ih, BW, depth; - char direction; - ushort i, c, xstep, ystep, wstep, hstep; - - if (!p) - /* no such panel */ - return; - /* PanelWin is found */ - PanelWin = p->uber->IconWinParent; - - direction = b ? b->action[0][6] : (char) p->uber->n; - - if (p->uber->swallow) - { - /* shown ---> hidden */ - root = GetRealGeometry(Dpy, PanelWin, &x, &y, - (ushort*)&iw, (ushort*)&ih, - (ushort*)&BW, (ushort*)&depth); - - switch (direction) - { - case 'l': - c = iw / PanelPopUpStep; - xstep = wstep = PanelPopUpStep; - ystep = hstep = 0; - break; - case 'r': - c = iw / PanelPopUpStep; - wstep = PanelPopUpStep; - xstep = ystep = hstep = 0; - break; - case 'd': - c = ih / PanelPopUpStep; - hstep = PanelPopUpStep; - xstep = ystep = wstep = 0; - break; - case 'g': - /* just pop down without animation */ - c = 0; - break; - case 'u': - default: - c = ih / PanelPopUpStep; - ystep = hstep = PanelPopUpStep; - xstep = wstep = 0; - break; - } - - for (i = 1; i < c; i++) - { - iw -= wstep; - ih -= hstep; - x += xstep; - y += ystep; - XMoveResizeWindow(Dpy, PanelWin, x, y, iw, ih); - } - - XUnmapWindow(Dpy, PanelWin); - p->uber->swallow = 0; - } - else - { - /* hidden ---> shown */ - int ix = buttonXPos(b, b->n); /* button in the CurrentPanel */ - int iy = buttonYPos(b, b->n); /* button in the CurrentPanel */ - - int mw = p->uber->icon_w; /* panel menu width */ - int mh = p->uber->icon_h; /* panel menu height */ - int w; /* current width */ - int h; /* current height */ - - root = GetRealGeometry(Dpy, CurrentPanel->uber->IconWinParent, &x, &y, - (ushort*)&iw, (ushort*)&ih, - (ushort*)&BW, (ushort*)&depth); - - x += p->uber->x + ix; - y += p->uber->y + iy; - c = 0; - - /* initial position and size */ - switch (direction) - { - case 'g': - /* just pop up without animation */ - c = 0; - break; - case 'l': - case 'r': - h = mh; - w = mw % PanelPopUpStep; - if (w == 0) - { - w = PanelPopUpStep; - c--; - } - if (direction == 'l') - { - x -= w; - c += mw / PanelPopUpStep; - xstep = wstep = PanelPopUpStep; - ystep = hstep = 0; - } - else - { - x += b->BWidth * b->parent->c->ButtonWidth; - c += mw / PanelPopUpStep; - wstep = PanelPopUpStep; - xstep = ystep = hstep = 0; - } - break; - case 'd': - case 'u': - default: - w = mw; - h = mh % PanelPopUpStep; - if (h == 0) - { - h = PanelPopUpStep; - c--; - } - if (direction == 'd') - { - y += b->BHeight * b->parent->c->ButtonHeight; - c += mh / PanelPopUpStep; - hstep = PanelPopUpStep; - xstep = ystep = wstep = 0; - } - else - { - y -= h; - c += mh / PanelPopUpStep; - ystep = hstep = PanelPopUpStep; - xstep = wstep = 0; - } - break; - } - - if (c > 0) - XMoveResizeWindow(Dpy, PanelWin, x, y, w, h); - XMapSubwindows(Dpy, PanelWin); - XMapWindow(Dpy, PanelWin); - - for (i = 0; i < c; i++) - { - x -= xstep; - w += wstep; - y -= ystep; - h += hstep; - XMoveResizeWindow(Dpy, PanelWin, x, y, w, h); - } - - p->uber->n = (int) direction; - p->uber->swallow = 1; - } + Window PanelWin; + Window root; + int x, y, iw, ih, BW, depth; + char direction; + ushort i, c, xstep, ystep, wstep, hstep; + + if (!p) + /* no such panel */ + return; + /* PanelWin is found */ + PanelWin = p->uber->IconWinParent; + + direction = b ? b->action[0][6] : (char)p->uber->n; + + if (p->uber->swallow) { + /* shown ---> hidden */ + root = GetRealGeometry(Dpy, PanelWin, &x, &y, (ushort *)&iw, + (ushort *)&ih, (ushort *)&BW, (ushort *)&depth); + + switch (direction) { + case 'l': + c = iw / PanelPopUpStep; + xstep = wstep = PanelPopUpStep; + ystep = hstep = 0; + break; + case 'r': + c = iw / PanelPopUpStep; + wstep = PanelPopUpStep; + xstep = ystep = hstep = 0; + break; + case 'd': + c = ih / PanelPopUpStep; + hstep = PanelPopUpStep; + xstep = ystep = wstep = 0; + break; + case 'g': + /* just pop down without animation */ + c = 0; + break; + case 'u': + default: + c = ih / PanelPopUpStep; + ystep = hstep = PanelPopUpStep; + xstep = wstep = 0; + break; + } + + for (i = 1; i < c; i++) { + iw -= wstep; + ih -= hstep; + x += xstep; + y += ystep; + XMoveResizeWindow(Dpy, PanelWin, x, y, iw, ih); + } + + XUnmapWindow(Dpy, PanelWin); + p->uber->swallow = 0; + } else { + /* hidden ---> shown */ + int ix = buttonXPos(b, b->n); /* button in the CurrentPanel */ + int iy = buttonYPos(b, b->n); /* button in the CurrentPanel */ + + int mw = p->uber->icon_w; /* panel menu width */ + int mh = p->uber->icon_h; /* panel menu height */ + int w; /* current width */ + int h; /* current height */ + + root = GetRealGeometry(Dpy, CurrentPanel->uber->IconWinParent, + &x, &y, (ushort *)&iw, (ushort *)&ih, (ushort *)&BW, + (ushort *)&depth); + + x += p->uber->x + ix; + y += p->uber->y + iy; + c = 0; + + /* initial position and size */ + switch (direction) { + case 'g': + /* just pop up without animation */ + c = 0; + break; + case 'l': + case 'r': + h = mh; + w = mw % PanelPopUpStep; + if (w == 0) { + w = PanelPopUpStep; + c--; + } + if (direction == 'l') { + x -= w; + c += mw / PanelPopUpStep; + xstep = wstep = PanelPopUpStep; + ystep = hstep = 0; + } else { + x += b->BWidth * b->parent->c->ButtonWidth; + c += mw / PanelPopUpStep; + wstep = PanelPopUpStep; + xstep = ystep = hstep = 0; + } + break; + case 'd': + case 'u': + default: + w = mw; + h = mh % PanelPopUpStep; + if (h == 0) { + h = PanelPopUpStep; + c--; + } + if (direction == 'd') { + y += b->BHeight * b->parent->c->ButtonHeight; + c += mh / PanelPopUpStep; + hstep = PanelPopUpStep; + xstep = ystep = wstep = 0; + } else { + y -= h; + c += mh / PanelPopUpStep; + ystep = hstep = PanelPopUpStep; + xstep = wstep = 0; + } + break; + } + + if (c > 0) + XMoveResizeWindow(Dpy, PanelWin, x, y, w, h); + XMapSubwindows(Dpy, PanelWin); + XMapWindow(Dpy, PanelWin); + + for (i = 0; i < c; i++) { + x -= xstep; + w += wstep; + y -= ystep; + h += hstep; + XMoveResizeWindow(Dpy, PanelWin, x, y, w, h); + } + + p->uber->n = (int)direction; + p->uber->swallow = 1; + } } Index: fvwm/modules/FvwmButtons/FvwmButtons.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmButtons/FvwmButtons.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmButtons/FvwmButtons.h --- fvwm/modules/FvwmButtons/FvwmButtons.h +++ fvwm/modules/FvwmButtons/FvwmButtons.h @@ -25,12 +25,12 @@ #define DEBUG_HANGON /* Debug hangon, swallow and unswallow */ /* #define DEBUG_EVENTS */ /* Get much info on events */ #define DEBUG_FVWM /* Debug communciation with fvwm */ -/* #define DEBUG_X */ +/* #define DEBUG_X */ #endif /* ---------------------------- compatibility ------------------------------ */ -#define OLD_EXPOSE /* Try this if resizing/exposes screw up */ +#define OLD_EXPOSE /* Try this if resizing/exposes screw up */ /* -------------------------------- more ---------------------------------- */ @@ -39,42 +39,44 @@ /* ------------------------------- structs --------------------------------- */ /* flags for b->flags */ -#define b_Container 0x00000001 /* Contains several buttons */ -#define b_Font 0x00000002 /* Has personal font data */ -#define b_Fore 0x00000004 /* Has personal text color */ -#define b_Back 0x00000008 /* Has personal background color (or "none")*/ -#define b_Padding 0x00000010 /* Has personal padding data */ -#define b_Frame 0x00000020 /* Has personal framewidth */ -#define b_Title 0x00000040 /* Contains title */ -#define b_Icon 0x00000080 /* Contains icon */ -#define b_Swallow 0x00000100 /* Contains swallowed window */ -#define b_Action 0x00000200 /* Fvwm action when clicked on */ -#define b_Hangon 0x00000400 /* Is waiting for a window before turning - * active */ -#define b_Justify 0x00000800 /* Has justification info */ -#define b_Size 0x00001000 /* Has a minimum size, don't guess */ -#define b_IconBack 0x00002000 /* Has an icon as background */ +#define b_Container 0x00000001 /* Contains several buttons */ +#define b_Font 0x00000002 /* Has personal font data */ +#define b_Fore 0x00000004 /* Has personal text color */ +#define b_Back 0x00000008 /* Has personal background color (or "none")*/ +#define b_Padding 0x00000010 /* Has personal padding data */ +#define b_Frame 0x00000020 /* Has personal framewidth */ +#define b_Title 0x00000040 /* Contains title */ +#define b_Icon 0x00000080 /* Contains icon */ +#define b_Swallow 0x00000100 /* Contains swallowed window */ +#define b_Action 0x00000200 /* Fvwm action when clicked on */ +#define b_Hangon \ + 0x00000400 /* Is waiting for a window before turning\ + * active */ +#define b_Justify 0x00000800 /* Has justification info */ +#define b_Size 0x00001000 /* Has a minimum size, don't guess */ +#define b_IconBack 0x00002000 /* Has an icon as background */ #define b_IconParent 0x00004000 /* Parent button has an icon as background */ -#define b_TransBack 0x00008000 /* Transparent background */ -#define b_Left 0x00010000 /* Button is left-aligned */ -#define b_Right 0x00020000 /* Button is right-aligned */ -#define b_SizeFixed 0x00040000 /* User provided rows/columns may not be - * altered */ -#define b_PosFixed 0x00080000 /* User provided button position */ -#define b_SizeSmart 0x00100000 /* Improved button box sizing */ +#define b_TransBack 0x00008000 /* Transparent background */ +#define b_Left 0x00010000 /* Button is left-aligned */ +#define b_Right 0x00020000 /* Button is right-aligned */ +#define b_SizeFixed \ + 0x00040000 /* User provided rows/columns may not be \ + * altered */ +#define b_PosFixed 0x00080000 /* User provided button position */ +#define b_SizeSmart 0x00100000 /* Improved button box sizing */ /* Flags for b->swallow */ -#define b_Count 0x03 /* Init counter for swallowing */ -#define b_NoHints 0x04 /* Ignore window hints from swallowed window */ -#define b_NoClose 0x08 /* Don't close window when exiting, unswallow it */ -#define b_Kill 0x10 /* Don't close window when exiting, kill it */ -#define b_Respawn 0x20 /* Respawn if swallowed window dies */ -#define b_UseOld 0x40 /* Try to capture old window, don't spawn it */ -#define b_UseTitle 0x80 /* Allow window to write to b->title */ +#define b_Count 0x03 /* Init counter for swallowing */ +#define b_NoHints 0x04 /* Ignore window hints from swallowed window */ +#define b_NoClose 0x08 /* Don't close window when exiting, unswallow it */ +#define b_Kill 0x10 /* Don't close window when exiting, kill it */ +#define b_Respawn 0x20 /* Respawn if swallowed window dies */ +#define b_UseOld 0x40 /* Try to capture old window, don't spawn it */ +#define b_UseTitle 0x80 /* Allow window to write to b->title */ /* Flags for b->justify */ -#define b_TitleHoriz 0x03 /* Mask for title x positioning info */ -#define b_Horizontal 0x04 /* HACK: stack title and iconwin horizontally */ +#define b_TitleHoriz 0x03 /* Mask for title x positioning info */ +#define b_Horizontal 0x04 /* HACK: stack title and iconwin horizontally */ typedef struct panel_info_struct panel_info; typedef struct button_info_struct button_info; @@ -83,90 +85,85 @@ typedef struct container_info_struct container_info; #define byte unsigned char /* This structure contains data that the parents give their children */ -struct container_info_struct -{ - button_info **buttons; /* Required fields */ - int allocated_buttons; - int num_buttons; - int num_columns; - int num_rows; - int ButtonWidth; - int ButtonHeight; - int xpos,ypos; - - unsigned long flags; /* Which data are set in this container? */ - byte justify; /* b_Justify */ - byte justify_mask; /* b_Justify */ - byte swallow; /* b_Swallow */ - byte swallow_mask; /* b_Swallow */ - byte xpad,ypad; /* b_Padding */ - signed char framew; /* b_Frame */ - XFontStruct *font; /* b_Font */ - char *font_string; /* b_Font */ - char *back; /* b_Back && !b_IconBack */ - char *back_file; /* b_Back && b_IconBack */ - char *fore; /* b_Fore */ - Pixel fc; /* b_Fore */ - Pixel bc,hc,sc; /* b_Back && !b_IconBack */ - FvwmPicture *backicon; /* b_Back && b_IconBack */ - ushort minx,miny; /* b_Size */ +struct container_info_struct { + button_info **buttons; /* Required fields */ + int allocated_buttons; + int num_buttons; + int num_columns; + int num_rows; + int ButtonWidth; + int ButtonHeight; + int xpos, ypos; + + unsigned long flags; /* Which data are set in this container? */ + byte justify; /* b_Justify */ + byte justify_mask; /* b_Justify */ + byte swallow; /* b_Swallow */ + byte swallow_mask; /* b_Swallow */ + byte xpad, ypad; /* b_Padding */ + signed char framew; /* b_Frame */ + XFontStruct *font; /* b_Font */ + char *font_string; /* b_Font */ + char *back; /* b_Back && !b_IconBack */ + char *back_file; /* b_Back && b_IconBack */ + char *fore; /* b_Fore */ + Pixel fc; /* b_Fore */ + Pixel bc, hc, sc; /* b_Back && !b_IconBack */ + FvwmPicture *backicon; /* b_Back && b_IconBack */ + ushort minx, miny; /* b_Size */ }; -struct button_info_struct -{ - /* required fields */ - unsigned long flags; - int BPosX,BPosY; /* position in button units from top left */ - byte BWidth,BHeight; /* width and height in button units */ - button_info *parent; - int n; /* number in parent */ - - /* conditional fields */ /* applicable if these flags are set */ - XFontStruct *font; /* b_Font */ - char *font_string; /* b_Font */ - char *back; /* b_Back */ - char *fore; /* b_Fore */ - byte xpad,ypad; /* b_Padding */ - signed char framew; /* b_Frame */ - byte justify; /* b_Justify */ - byte justify_mask; /* b_Justify */ - container_info *c; /* b_Container */ - char *title; /* b_Title */ - char **action; /* b_Action */ - char *icon_file; /* b_Icon */ - char *hangon; /* b_Hangon || b_Swallow */ - Window IconWin; /* b_Icon || b_Swallow */ - Pixel fc; /* b_Fore */ - Pixel bc,hc,sc; /* b_Back && !b_IconBack */ - FvwmPicture *backicon; /* b_Back && b_IconBack */ - ushort minx,miny; /* b_Size */ - FvwmPicture *icon; /* b_Icon */ - - byte swallow; /* b_Swallow */ - byte swallow_mask; /* b_Swallow */ - int icon_w,icon_h; /* b_Swallow */ - Window IconWinParent; /* b_Swallow */ - XSizeHints *hints; /* b_Swallow && !b_NoHints */ - char *spawn; /* b_Swallow */ - int x,y; /* b_Swallow */ - ushort w,h,bw; /* b_Swallow */ +struct button_info_struct { + /* required fields */ + unsigned long flags; + int BPosX, BPosY; /* position in button units from top left */ + byte BWidth, BHeight; /* width and height in button units */ + button_info *parent; + int n; /* number in parent */ + + /* conditional fields */ /* applicable if these flags are set */ + XFontStruct *font; /* b_Font */ + char *font_string; /* b_Font */ + char *back; /* b_Back */ + char *fore; /* b_Fore */ + byte xpad, ypad; /* b_Padding */ + signed char framew; /* b_Frame */ + byte justify; /* b_Justify */ + byte justify_mask; /* b_Justify */ + container_info *c; /* b_Container */ + char *title; /* b_Title */ + char **action; /* b_Action */ + char *icon_file; /* b_Icon */ + char *hangon; /* b_Hangon || b_Swallow */ + Window IconWin; /* b_Icon || b_Swallow */ + Pixel fc; /* b_Fore */ + Pixel bc, hc, sc; /* b_Back && !b_IconBack */ + FvwmPicture *backicon; /* b_Back && b_IconBack */ + ushort minx, miny; /* b_Size */ + FvwmPicture *icon; /* b_Icon */ + + byte swallow; /* b_Swallow */ + byte swallow_mask; /* b_Swallow */ + int icon_w, icon_h; /* b_Swallow */ + Window IconWinParent; /* b_Swallow */ + XSizeHints *hints; /* b_Swallow && !b_NoHints */ + char *spawn; /* b_Swallow */ + int x, y; /* b_Swallow */ + ushort w, h, bw; /* b_Swallow */ }; -struct panel_info_struct -{ button_info *uber; /* panel */ - panel_info *next; +struct panel_info_struct { + button_info *uber; /* panel */ + panel_info *next; + int geom_w; /* requested width, -1 if unset */ + int geom_h; /* requested height, -1 if unset */ }; #include "button.h" /* -------------------------------- prototypes ----------------------------- */ -void AddButtonAction(button_info*,int,char*); -void MakeContainer(button_info*); -#ifdef DEBUG -char *mymalloc(int); -#else -#define mymalloc(a) safemalloc(a) -#endif +void AddButtonAction(button_info *, int, char *); +void MakeContainer(button_info *); /* ----------------------------- global variables -------------------------- */ @@ -174,7 +171,7 @@ extern Display *Dpy; extern Window Root; extern Window MyWindow; extern char *MyName; -extern button_info *UberButton,*CurrentButton; +extern button_info *UberButton, *CurrentButton; extern panel_info *MainPanel, *CurrentPanel; extern char *iconPath; @@ -184,8 +181,7 @@ extern int fd[]; extern int screen; extern int d_depth; extern int new_desk; -extern GC NormalGC; -extern int x,y,xneg,yneg,w,h; /* Dirty... */ +extern GC NormalGC; +extern int x, y, xneg, yneg, w, h; /* Dirty... */ /* ---------------------------------- misc --------------------------------- */ - Index: fvwm/modules/FvwmButtons/button.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmButtons/button.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmButtons/button.c --- fvwm/modules/FvwmButtons/button.c +++ fvwm/modules/FvwmButtons/button.c @@ -12,11 +12,12 @@ */ -#include +#include #include -#include #include -#include +#include +#include + #include "FvwmButtons.h" extern char *MyName; @@ -25,247 +26,252 @@ extern char *MyName; *** buttonInfo() *** Give lots of info for this button: XPos, YPos, XPad, YPad, Frame(signed) **/ -void buttonInfo(button_info *b,int *x,int *y,int *px,int *py,int *f) +void +buttonInfo(button_info *b, int *x, int *y, int *px, int *py, int *f) { - ushort w=b_Padding|b_Frame; - *x=buttonXPos(b,b->n); - *y=buttonYPos(b,b->n); - *px=b->xpad; - *py=b->ypad; - *f=b->framew; - w&=~(b->flags&(b_Frame|b_Padding)); - - if(b->flags&b_Container && w&b_Frame) - { - *f=0; - w&=~b_Frame; - } - if((b->flags&b_Container || b->flags&b_Swallow) && w&b_Padding) - { - *px=*py=0; - w&=~b_Padding; - } - - while(w && (b=b->parent)) - { - if(w&b_Frame && b->c->flags&b_Frame) - { - *f=b->c->framew; - w&=~b_Frame; + ushort w = b_Padding | b_Frame; + *x = buttonXPos(b, b->n); + *y = buttonYPos(b, b->n); + *px = b->xpad; + *py = b->ypad; + *f = b->framew; + w &= ~(b->flags & (b_Frame | b_Padding)); + + if (b->flags & b_Container && w & b_Frame) { + *f = 0; + w &= ~b_Frame; + } + if ((b->flags & b_Container || b->flags & b_Swallow) && w & b_Padding) { + *px = *py = 0; + w &= ~b_Padding; } - if(w&b_Padding && b->c->flags&b_Padding) - { - *px=b->c->xpad; - *py=b->c->ypad; - w&=~b_Padding; + + while (w && (b = b->parent)) { + if (w & b_Frame && b->c->flags & b_Frame) { + *f = b->c->framew; + w &= ~b_Frame; + } + if (w & b_Padding && b->c->flags & b_Padding) { + *px = b->c->xpad; + *py = b->c->ypad; + w &= ~b_Padding; + } } - } } /** *** GetInternalSize() **/ -void GetInternalSize(button_info *b,int *x,int *y,int *w,int *h) +void +GetInternalSize(button_info *b, int *x, int *y, int *w, int *h) { - int f; - int px,py; - buttonInfo(b,x,y,&px,&py,&f); - f=abs(f); + int f; + int px, py; + buttonInfo(b, x, y, &px, &py, &f); + f = abs(f); - *w=buttonWidth(b)-2*(px+f); - *h=buttonHeight(b)-2*(py+f); + *w = buttonWidth(b) - 2 * (px + f); + *h = buttonHeight(b) - 2 * (py + f); - *x+=f+px; - *y+=f+py; + *x += f + px; + *y += f + py; - if(*w<=1 || *h<=1) - *w=*h=1; + if (*w <= 1 || *h <= 1) + *w = *h = 1; } /** *** buttonFrameSigned() *** Give the signed framewidth for this button. **/ -int buttonFrameSigned(button_info *b) +int +buttonFrameSigned(button_info *b) { - if(b->flags&b_Frame) - return b->framew; - if(b->flags&b_Container) /* Containers usually gets 0 relief */ - return 0; - while((b=b->parent)) - if(b->c->flags&b_Frame) - return b->c->framew; + if (b->flags & b_Frame) + return b->framew; + if (b->flags & b_Container) /* Containers usually gets 0 relief */ + return 0; + while ((b = b->parent)) + if (b->c->flags & b_Frame) + return b->c->framew; #ifdef DEBUG - fprintf(stderr,"%s: BUG: No relief width definition?\n",MyName); + fprintf(stderr, "%s: BUG: No relief width definition?\n", MyName); #endif - return 0; + return 0; } /** *** buttonXPad() *** Give the x padding for this button **/ -int buttonXPad(button_info *b) +int +buttonXPad(button_info *b) { - if(b->flags&b_Padding) - return b->xpad; - if(b->flags&(b_Container|b_Swallow)) /* Normally no padding for these */ - return 0; - while((b=b->parent)) - if(b->c->flags&b_Padding) - return b->c->xpad; + if (b->flags & b_Padding) + return b->xpad; + if (b->flags & + (b_Container | b_Swallow)) /* Normally no padding for these */ + return 0; + while ((b = b->parent)) + if (b->c->flags & b_Padding) + return b->c->xpad; #ifdef DEBUG - fprintf(stderr,"%s: BUG: No padding definition?\n",MyName); + fprintf(stderr, "%s: BUG: No padding definition?\n", MyName); #endif - return 0; + return 0; } /** *** buttonYPad() *** Give the y padding for this button **/ -int buttonYPad(button_info *b) +int +buttonYPad(button_info *b) { - if(b->flags&b_Padding) - return b->ypad; - if(b->flags&(b_Container|b_Swallow)) /* Normally no padding for these */ - return 0; - while((b=b->parent)) - if(b->c->flags&b_Padding) - return b->c->ypad; + if (b->flags & b_Padding) + return b->ypad; + if (b->flags & + (b_Container | b_Swallow)) /* Normally no padding for these */ + return 0; + while ((b = b->parent)) + if (b->c->flags & b_Padding) + return b->c->ypad; #ifdef DEBUG - fprintf(stderr,"%s: BUG: No padding definition?\n",MyName); + fprintf(stderr, "%s: BUG: No padding definition?\n", MyName); #endif - return 0; + return 0; } /** *** buttonFont() *** Give the font pointer for this button **/ -XFontStruct *buttonFont(button_info *b) +XFontStruct * +buttonFont(button_info *b) { - if(b->flags&b_Font) - return b->font; - while((b=b->parent)) - if(b->c->flags&b_Font) - return b->c->font; + if (b->flags & b_Font) + return b->font; + while ((b = b->parent)) + if (b->c->flags & b_Font) + return b->c->font; #ifdef DEBUG - fprintf(stderr,"%s: BUG: No font definition?\n",MyName); + fprintf(stderr, "%s: BUG: No font definition?\n", MyName); #endif - return None; + return None; } /** *** buttonFore() *** Give the foreground pixel of this button **/ -Pixel buttonFore(button_info *b) +Pixel +buttonFore(button_info *b) { - if(b->flags&b_Fore) - return b->fc; - while((b=b->parent)) - if(b->c->flags&b_Fore) - return b->c->fc; + if (b->flags & b_Fore) + return b->fc; + while ((b = b->parent)) + if (b->c->flags & b_Fore) + return b->c->fc; #ifdef DEBUG - fprintf(stderr,"%s: BUG: No foreground definition?\n",MyName); + fprintf(stderr, "%s: BUG: No foreground definition?\n", MyName); #endif - return None; + return None; } /** *** buttonBack() *** Give the background pixel of this button **/ -Pixel buttonBack(button_info *b) +Pixel +buttonBack(button_info *b) { - if(b->flags&b_Back) - return b->bc; - while((b=b->parent)) - if(b->c->flags&b_Back) - return b->c->bc; + if (b->flags & b_Back) + return b->bc; + while ((b = b->parent)) + if (b->c->flags & b_Back) + return b->c->bc; #ifdef DEBUG - fprintf(stderr,"%s: BUG: No background definition?\n",MyName); + fprintf(stderr, "%s: BUG: No background definition?\n", MyName); #endif - return None; + return None; } /** *** buttonHilite() *** Give the relief pixel of this button **/ -Pixel buttonHilite(button_info *b) +Pixel +buttonHilite(button_info *b) { - if(b->flags&b_Back) - return b->hc; - while((b=b->parent)) - if(b->c->flags&b_Back) - return b->c->hc; + if (b->flags & b_Back) + return b->hc; + while ((b = b->parent)) + if (b->c->flags & b_Back) + return b->c->hc; #ifdef DEBUG - fprintf(stderr,"%s: BUG: No background definition?\n",MyName); + fprintf(stderr, "%s: BUG: No background definition?\n", MyName); #endif - return None; + return None; } /** *** buttonShadow() *** Give the shadow pixel of this button **/ -Pixel buttonShadow(button_info *b) +Pixel +buttonShadow(button_info *b) { - if(b->flags&b_Back) - return b->sc; - while((b=b->parent)) - if(b->c->flags&b_Back) - return b->c->sc; + if (b->flags & b_Back) + return b->sc; + while ((b = b->parent)) + if (b->c->flags & b_Back) + return b->c->sc; #ifdef DEBUG - fprintf(stderr,"%s: BUG: No background definition?\n",MyName); + fprintf(stderr, "%s: BUG: No background definition?\n", MyName); #endif - return None; + return None; } /** *** buttonSwallow() *** Give the swallowing flags for this button **/ -byte buttonSwallow(button_info *b) +byte +buttonSwallow(button_info *b) { - byte s=0,t=0; - if(b->flags&b_Swallow) - { - s=b->swallow; - t=b->swallow_mask; - } - while((b=b->parent)) - if(b->c->flags&b_Swallow) - { - s&=~(b->c->swallow_mask&~t); - s|=(b->c->swallow&b->c->swallow_mask&~t); - t|=b->c->swallow_mask; - } - return s; + byte s = 0, t = 0; + if (b->flags & b_Swallow) { + s = b->swallow; + t = b->swallow_mask; + } + while ((b = b->parent)) + if (b->c->flags & b_Swallow) { + s &= ~(b->c->swallow_mask & ~t); + s |= (b->c->swallow & b->c->swallow_mask & ~t); + t |= b->c->swallow_mask; + } + return s; } /** *** buttonJustify() *** Give the justify flags for this button **/ -byte buttonJustify(button_info *b) +byte +buttonJustify(button_info *b) { - byte j=1,i=0; - if(b->flags&b_Justify) - { - i=b->justify_mask; - j=b->justify; - } - while((b=b->parent)) - if(b->c->flags&b_Justify) - { - j&=~(b->c->justify_mask&~i); - j|=(b->c->justify&b->c->justify_mask&~i); - i|=b->c->justify_mask; - } - return j; + byte j = 1, i = 0; + if (b->flags & b_Justify) { + i = b->justify_mask; + j = b->justify; + } + while ((b = b->parent)) + if (b->c->flags & b_Justify) { + j &= ~(b->c->justify_mask & ~i); + j |= (b->c->justify & b->c->justify_mask & ~i); + i |= b->c->justify_mask; + } + return j; } /* ---------------------------- button creation ---------------------------- */ @@ -275,32 +281,32 @@ byte buttonJustify(button_info *b) *** Makes sure the list of butten_info's is long enough, if not it reallocates *** a longer one. This happens in steps of 32. Inital length is 0. **/ -void alloc_buttonlist(button_info *ub,int num) +void +alloc_buttonlist(button_info *ub, int num) { - button_info **bb; - int i,old; - - if(num>=ub->c->allocated_buttons) - { - old=ub->c->allocated_buttons; - if(numc->allocated_buttons<=num) - ub->c->allocated_buttons+=32; - bb=(button_info**) - mymalloc(ub->c->allocated_buttons*sizeof(button_info*)); - for(i=old;ic->allocated_buttons;i++) - bb[i]=NULL; - if(ub->c->buttons) - { - for(i=0;ic->buttons[i]; - free(ub->c->buttons); + button_info **bb; + int i, old; + + if (num >= ub->c->allocated_buttons) { + old = ub->c->allocated_buttons; + if (num < old || old + 32 < old) { + fprintf(stderr, + "%s: Too many buttons, integer overflow\n", MyName); + exit(1); + } + while (ub->c->allocated_buttons <= num) + ub->c->allocated_buttons += 32; + bb = (button_info **)xmalloc( + ub->c->allocated_buttons * sizeof(button_info *)); + for (i = old; i < ub->c->allocated_buttons; i++) + bb[i] = NULL; + if (ub->c->buttons) { + for (i = 0; i < old; i++) + bb[i] = ub->c->buttons[i]; + free(ub->c->buttons); + } + ub->c->buttons = bb; } - ub->c->buttons=bb; - } } /** @@ -308,71 +314,71 @@ void alloc_buttonlist(button_info *ub,int num) *** Allocates memory for a new button struct. Calles alloc_buttonlist to *** assure enough space is present. Also initiates most elements of the struct. **/ -button_info *alloc_button(button_info *ub,int num) +button_info * +alloc_button(button_info *ub, int num) { - button_info *b; - if(num>=ub->c->allocated_buttons) - alloc_buttonlist(ub,num); - if(ub->c->buttons[num]) - { - fprintf(stderr,"%s: Allocated button twice, report bug twice\n",MyName); - exit(2); - } - - b=(button_info*)mymalloc(sizeof(button_info)); - ub->c->buttons[num]=b; - - memset((void *)b, 0, sizeof(*b)); - b->flags = 0; - b->swallow = 0; - b->BWidth = b->BHeight = 1; - b->BPosX = b->BPosY = 0; - b->parent = ub; - b->n = -1; - b->IconWin = 0; - - b->framew = 1; - b->xpad = 2; - b->ypad = 4; - b->w=1; - b->h=1; - b->bw=1; - - return(b); + button_info *b; + if (num >= ub->c->allocated_buttons) + alloc_buttonlist(ub, num); + if (ub->c->buttons[num]) { + fprintf(stderr, + "%s: Allocated button twice, report bug twice\n", MyName); + exit(2); + } + + b = (button_info *)xmalloc(sizeof(button_info)); + ub->c->buttons[num] = b; + + memset((void *)b, 0, sizeof(*b)); + b->flags = 0; + b->swallow = 0; + b->BWidth = b->BHeight = 1; + b->BPosX = b->BPosY = 0; + b->parent = ub; + b->n = -1; + b->IconWin = 0; + + b->framew = 1; + b->xpad = 2; + b->ypad = 4; + b->w = 1; + b->h = 1; + b->bw = 1; + + return (b); } /** *** MakeContainer() *** Allocs and sets the container-specific fields of a button. **/ -void MakeContainer(button_info *b) +void +MakeContainer(button_info *b) { - b->c=(container_info*)mymalloc(sizeof(container_info)); - b->flags|=b_Container; - b->c->buttons=NULL; - b->c->num_buttons=0; - b->c->num_rows=0; - b->c->num_columns=0; - b->c->allocated_buttons=0; - b->c->xpos=0; - b->c->ypos=0; - if(b->parent != NULL) - { - if (b->parent->c->flags&b_IconBack || b->parent->c->flags&b_IconParent) - b->c->flags=b_IconParent; - else - b->c->flags=0; - } - else /* This applies to the UberButton */ - { - b->c->flags=b_Font|b_Padding|b_Frame|b_Back|b_Fore; - b->c->font_string=strdup("fixed"); - b->c->xpad=2; - b->c->ypad=4; - b->c->back=strdup("#908090"); - b->c->fore=strdup("black"); - b->c->framew=2; - } + b->c = (container_info *)xmalloc(sizeof(container_info)); + b->flags |= b_Container; + b->c->buttons = NULL; + b->c->num_buttons = 0; + b->c->num_rows = 0; + b->c->num_columns = 0; + b->c->allocated_buttons = 0; + b->c->xpos = 0; + b->c->ypos = 0; + if (b->parent != NULL) { + if (b->parent->c->flags & b_IconBack || + b->parent->c->flags & b_IconParent) + b->c->flags = b_IconParent; + else + b->c->flags = 0; + } else /* This applies to the UberButton */ { + b->c->flags = b_Font | b_Padding | b_Frame | b_Back | b_Fore; + b->c->font_string = strdup("fixed"); + b->c->xpad = 2; + b->c->ypad = 4; + b->c->back = strdup("#908090"); + b->c->fore = strdup("black"); + b->c->framew = 2; + } } /* -------------------------- button administration ------------------------ */ @@ -381,114 +387,112 @@ void MakeContainer(button_info *b) *** NumberButtons() *** Prepare the n fields in each button **/ -void NumberButtons(button_info *b) +void +NumberButtons(button_info *b) { - int i=-1; - while(++ic->num_buttons) - if(b->c->buttons[i]) - { - b->c->buttons[i]->n=i; - if(b->c->buttons[i]->flags&b_Container) - NumberButtons(b->c->buttons[i]); - } + int i = -1; + while (++i < b->c->num_buttons) + if (b->c->buttons[i]) { + b->c->buttons[i]->n = i; + if (b->c->buttons[i]->flags & b_Container) + NumberButtons(b->c->buttons[i]); + } } /** *** PlaceAndExpandButton() *** Places a button in it's container and claims all needed slots. - **/ -char PlaceAndExpandButton(int x, int y, button_info *b, button_info *ub) +**/ +char +PlaceAndExpandButton(int x, int y, button_info *b, button_info *ub) { - int i,j,k; - container_info *c=ub->c; - - i = x+y*c->num_columns; - if (x>=c->num_columns || x<0) - { - fprintf(stderr,"%s: Button out of horizontal range. Quitting.\n",MyName); - fprintf(stderr,"Button=%d num_columns=%d BPosX=%d\n", - i,c->num_columns,b->BPosX); - exit(1); - } - if (y>=c->num_rows || y<0) - { - if (b->flags&b_PosFixed || !(ub->c->flags&b_SizeSmart) || y<0) - { - fprintf(stderr,"%s: Button out of vertical range. Quitting.\n", - MyName); - fprintf(stderr,"Button=%d num_rows=%d BPosY=%d\n", - i,c->num_rows,b->BPosY); - exit(1); + int i, j, k; + container_info *c = ub->c; + + i = x + y * c->num_columns; + if (x >= c->num_columns || x < 0) { + fprintf(stderr, + "%s: Button out of horizontal range. Quitting.\n", MyName); + fprintf(stderr, "Button=%d num_columns=%d BPosX=%d\n", i, + c->num_columns, b->BPosX); + exit(1); } - c->num_rows=y+b->BHeight; - c->num_buttons=c->num_columns*c->num_rows; - alloc_buttonlist(ub,c->num_buttons); - } - if(x+b->BWidth>c->num_columns) - { - fprintf(stderr,"%s: Button too wide. giving up\n",MyName); - fprintf(stderr,"Button=%d num_columns=%d bwidth=%d w=%d\n", - i,c->num_columns,b->BWidth,x); - b->BWidth = c->num_columns-x; - } - if(y+b->BHeight>c->num_rows) - { - if (c->flags&b_SizeSmart) - { - c->num_rows=y+b->BHeight; - c->num_buttons=c->num_columns*c->num_rows; - alloc_buttonlist(ub,c->num_buttons); + if (y >= c->num_rows || y < 0) { + if (b->flags & b_PosFixed || !(ub->c->flags & b_SizeSmart) || + y < 0) { + fprintf(stderr, + "%s: Button out of vertical range. Quitting.\n", + MyName); + fprintf(stderr, "Button=%d num_rows=%d BPosY=%d\n", i, + c->num_rows, b->BPosY); + exit(1); + } + c->num_rows = y + b->BHeight; + c->num_buttons = c->num_columns * c->num_rows; + alloc_buttonlist(ub, c->num_buttons); + } + if (x + b->BWidth > c->num_columns) { + fprintf(stderr, "%s: Button too wide. giving up\n", MyName); + fprintf(stderr, "Button=%d num_columns=%d bwidth=%d w=%d\n", i, + c->num_columns, b->BWidth, x); + b->BWidth = c->num_columns - x; } - else - { - fprintf(stderr,"%s: Button too tall. Giving up\n",MyName); - fprintf(stderr,"Button=%d num_rows=%d bheight=%d h=%d\n", - i,c->num_rows,b->BHeight,y); - b->BHeight = c->num_rows-y; + if (y + b->BHeight > c->num_rows) { + if (c->flags & b_SizeSmart) { + c->num_rows = y + b->BHeight; + c->num_buttons = c->num_columns * c->num_rows; + alloc_buttonlist(ub, c->num_buttons); + } else { + fprintf( + stderr, "%s: Button too tall. Giving up\n", MyName); + fprintf(stderr, + "Button=%d num_rows=%d bheight=%d h=%d\n", i, + c->num_rows, b->BHeight, y); + b->BHeight = c->num_rows - y; + } } - } - - /* check if buttons are free */ - for(k=0;kBHeight;k++) - for(j=0;jBWidth;j++) - if (c->buttons[i+j+k*c->num_columns]) - return 1; - /* claim all buttons */ - for(k=0;kBHeight;k++) - for(j=0;jBWidth;j++) - c->buttons[i+j+k*c->num_columns] = b; - b->BPosX = x; - b->BPosY = y; - return 0; + + /* check if buttons are free */ + for (k = 0; k < b->BHeight; k++) + for (j = 0; j < b->BWidth; j++) + if (c->buttons[i + j + k * c->num_columns]) + return 1; + /* claim all buttons */ + for (k = 0; k < b->BHeight; k++) + for (j = 0; j < b->BWidth; j++) + c->buttons[i + j + k * c->num_columns] = b; + b->BPosX = x; + b->BPosY = y; + return 0; } /** *** ShrinkButton() *** Frees all but the upper left slot a button uses in it's container. - **/ -void ShrinkButton(button_info *b, container_info *c) +**/ +void +ShrinkButton(button_info *b, container_info *c) { - int i,j,k,l; - - if (!b) - { - fprintf(stderr,"error: shrink1: button is empty but shouldn't\n"); - exit(1); - } - i = b->BPosX+b->BPosY*c->num_columns; - /* free all buttons but the upper left corner */ - for(k=0;kBHeight;k++) - for(j=0;jBWidth;j++) - if(j||k) - { - l = i+j+k*c->num_columns; - if (c->buttons[l] != b) - { - fprintf(stderr,"error: shrink2: button was stolen\n"); - exit(1); - } - c->buttons[l] = NULL; + int i, j, k, l; + + if (!b) { + fprintf( + stderr, "error: shrink1: button is empty but shouldn't\n"); + exit(1); } + i = b->BPosX + b->BPosY * c->num_columns; + /* free all buttons but the upper left corner */ + for (k = 0; k < b->BHeight; k++) + for (j = 0; j < b->BWidth; j++) + if (j || k) { + l = i + j + k * c->num_columns; + if (c->buttons[l] != b) { + fprintf(stderr, "error: shrink2: " + "button was stolen\n"); + exit(1); + } + c->buttons[l] = NULL; + } } /** @@ -496,129 +500,139 @@ void ShrinkButton(button_info *b, container_info *c) *** Orders and sizes the buttons in the UberButton, corrects num_rows and *** num_columns in containers. **/ -void ShuffleButtons(button_info *ub) +void +ShuffleButtons(button_info *ub) { - int i,actual_buttons_used; - int next_button_x, next_button_y, num_items; - button_info *b; - button_info **local_buttons; - container_info *c=ub->c; - - /* make local copy of buttons in ub */ - num_items = c->num_buttons; - local_buttons=(button_info**)mymalloc(sizeof(button_info)*num_items); - for(i=0;ibuttons[i]; - c->buttons[i] = NULL; - } - - /* Allow for multi-width/height buttons */ - actual_buttons_used = 0; - for(i=0;iBWidth*local_buttons[i]->BHeight; - - if (!(c->flags&b_SizeFixed)||!(c->num_rows)||!(c->num_columns)) - { - /* Size and create the window */ - if(c->num_rows==0 && c->num_columns==0) - c->num_rows=2; - if(c->num_columns==0) - c->num_columns=1+(actual_buttons_used-1)/c->num_rows; - if(c->num_rows==0) - c->num_rows=1+(actual_buttons_used-1)/c->num_columns; - while(c->num_rows * c->num_columns < actual_buttons_used) - c->num_columns++; - if (!(c->flags&b_SizeFixed)) - { - while(c->num_rows*c->num_columns >= actual_buttons_used + c->num_columns) - c->num_rows--; + int i, actual_buttons_used; + int next_button_x, next_button_y, num_items; + button_info *b; + button_info **local_buttons; + container_info *c = ub->c; + + /* make local copy of buttons in ub */ + num_items = c->num_buttons; + local_buttons = + (button_info **)xmalloc(sizeof(button_info) * num_items); + for (i = 0; i < num_items; i++) { + local_buttons[i] = c->buttons[i]; + c->buttons[i] = NULL; + } + + /* Allow for multi-width/height buttons */ + actual_buttons_used = 0; + for (i = 0; i < num_items; i++) + actual_buttons_used += + local_buttons[i]->BWidth * local_buttons[i]->BHeight; + + if (!(c->flags & b_SizeFixed) || !(c->num_rows) || !(c->num_columns)) { + /* Size and create the window */ + if (c->num_rows == 0 && c->num_columns == 0) + c->num_rows = 2; + if (c->num_columns == 0) + c->num_columns = + 1 + (actual_buttons_used - 1) / c->num_rows; + if (c->num_rows == 0) + c->num_rows = + 1 + (actual_buttons_used - 1) / c->num_columns; + while (c->num_rows * c->num_columns < actual_buttons_used) + c->num_columns++; + if (!(c->flags & b_SizeFixed)) { + while (c->num_rows * c->num_columns >= + actual_buttons_used + c->num_columns) + c->num_rows--; + } + } + + if (c->flags & b_SizeSmart) { + /* Set rows/columns to at least the height/width of largest + * button */ + for (i = 0; i < num_items; i++) { + b = local_buttons[i]; + if (c->num_rows < b->BHeight) + c->num_rows = b->BHeight; + if (c->num_columns < b->BWidth) + c->num_columns = b->BWidth; + if (b->flags & b_PosFixed && + c->num_columns < b->BWidth + b->BPosX) + c->num_columns = b->BWidth + b->BPosX; + if (b->flags & b_PosFixed && + c->num_columns < b->BWidth - b->BPosX) + c->num_columns = b->BWidth - b->BPosX; + if (b->flags & b_PosFixed && + c->num_rows < b->BHeight + b->BPosY) + c->num_rows = b->BHeight + b->BPosY; + if (b->flags & b_PosFixed && + c->num_rows < b->BHeight - b->BPosY) + c->num_rows = b->BHeight - b->BPosY; + } } - } - - if (c->flags&b_SizeSmart) - { - /* Set rows/columns to at least the height/width of largest button */ - for(i=0;inum_rowsBHeight) c->num_rows=b->BHeight; - if (c->num_columnsBWidth) c->num_columns=b->BWidth; - if (b->flags&b_PosFixed && c->num_columnsBWidth+b->BPosX) - c->num_columns=b->BWidth+b->BPosX; - if (b->flags&b_PosFixed && c->num_columnsBWidth-b->BPosX) - c->num_columns=b->BWidth-b->BPosX; - if (b->flags&b_PosFixed && c->num_rowsBHeight+b->BPosY) - c->num_rows=b->BHeight+b->BPosY; - if (b->flags&b_PosFixed && c->num_rowsBHeight-b->BPosY) - c->num_rows=b->BHeight-b->BPosY; + + /* this was buggy before */ + c->num_buttons = c->num_rows * c->num_columns; + alloc_buttonlist(ub, c->num_buttons); + + /* Shuffle subcontainers */ + for (i = 0; i < num_items; i++) { + b = local_buttons[i]; + /* Shuffle subcontainers recursively */ + if (b && b->flags & b_Container) + ShuffleButtons(b); } - } - - /* this was buggy before */ - c->num_buttons = c->num_rows*c->num_columns; - alloc_buttonlist(ub,c->num_buttons); - - /* Shuffle subcontainers */ - for(i=0;iflags&b_Container) - ShuffleButtons(b); - } - - /* Place fixed buttons as given in BPosX and BPosY */ - for(i=0;iflags&b_PosFixed)) continue; - /* recalculate position for negative offsets */ - if (b->BPosX<0) b->BPosX=b->BPosX+c->num_columns-b->BWidth+1; - if (b->BPosY<0) b->BPosY=b->BPosY+c->num_rows-b->BHeight+1; - /* Move button if position given by user */ - if (PlaceAndExpandButton(b->BPosX,b->BPosY,b,ub)) - { - fprintf(stderr, "%s: Overlapping fixed buttons. Quitting.\n",MyName); - fprintf(stderr, "Button=%d, x=%d, y=%d\n", i,b->BPosX,b->BPosY); - exit(1); + + /* Place fixed buttons as given in BPosX and BPosY */ + for (i = 0; i < num_items; i++) { + b = local_buttons[i]; + if (!(b->flags & b_PosFixed)) + continue; + /* recalculate position for negative offsets */ + if (b->BPosX < 0) + b->BPosX = b->BPosX + c->num_columns - b->BWidth + 1; + if (b->BPosY < 0) + b->BPosY = b->BPosY + c->num_rows - b->BHeight + 1; + /* Move button if position given by user */ + if (PlaceAndExpandButton(b->BPosX, b->BPosY, b, ub)) { + fprintf(stderr, + "%s: Overlapping fixed buttons. Quitting.\n", + MyName); + fprintf(stderr, "Button=%d, x=%d, y=%d\n", i, b->BPosX, + b->BPosY); + exit(1); + } } - } - - /* place floating buttons dynamically */ - next_button_x = next_button_y = 0; - for(i=0;iflags&b_PosFixed) continue; - - if (next_button_x+b->BWidth>c->num_columns) - { - next_button_y++; - next_button_x=0; - } - /* Search for next free position to accomodate button */ - while (PlaceAndExpandButton(next_button_x,next_button_y,b,ub)) - { - next_button_x++; - if (next_button_x+b->BWidth>c->num_columns) - { - next_button_y++; - next_button_x=0; - if (next_button_y>=c->num_rows) - { - /* could not place button */ - fprintf(stderr,"%s: Button confusion! Quitting\n", MyName); - exit(1); + + /* place floating buttons dynamically */ + next_button_x = next_button_y = 0; + for (i = 0; i < num_items; i++) { + b = local_buttons[i]; + if (b->flags & b_PosFixed) + continue; + + if (next_button_x + b->BWidth > c->num_columns) { + next_button_y++; + next_button_x = 0; + } + /* Search for next free position to accomodate button */ + while (PlaceAndExpandButton(next_button_x, next_button_y, b, + ub)) { + next_button_x++; + if (next_button_x + b->BWidth > c->num_columns) { + next_button_y++; + next_button_x = 0; + if (next_button_y >= c->num_rows) { + /* could not place button */ + fprintf(stderr, + "%s: Button confusion! Quitting\n", + MyName); + exit(1); + } + } } - } } - } - /* shrink buttons in Container */ - for(i=0;ic->num_buttons && !(*ub)->c->buttons[*i]) - (*i)++; - /* End of contained buttons */ - if((*i)>=(*ub)->c->num_buttons) - { - *b=*ub; - *ub=(*b)->parent; - /* End of the world as we know it */ - if(!(*ub)) - { - *b=NULL; - return *b; + /* Get next button */ + (*i)++; + /* Skip fake buttons */ + while ((*i) < (*ub)->c->num_buttons && !(*ub)->c->buttons[*i]) + (*i)++; + /* End of contained buttons */ + if ((*i) >= (*ub)->c->num_buttons) { + *b = *ub; + *ub = (*b)->parent; + /* End of the world as we know it */ + if (!(*ub)) { + *b = NULL; + return *b; + } + *i = (*b)->n; + if ((*i) >= (*ub)->c->num_buttons) { + fprintf(stderr, + "%s: BUG: Couldn't return to uberbutton\n", MyName); + exit(2); + } + NextButton(ub, b, i, all); + return *b; } - *i=(*b)->n; - if((*i)>=(*ub)->c->num_buttons) - { - fprintf(stderr,"%s: BUG: Couldn't return to uberbutton\n",MyName); - exit(2); + *b = (*ub)->c->buttons[*i]; + + /* Found new container */ + if ((*b)->flags & b_Container) { + *i = -1; + *ub = *b; + if (!all) + NextButton(ub, b, i, all); + return *b; } - NextButton(ub,b,i,all); - return *b; - } - *b=(*ub)->c->buttons[*i]; - - /* Found new container */ - if((*b)->flags & b_Container) - { - *i=-1; - *ub=*b; - if(!all) - NextButton(ub,b,i,all); - return *b; - } - return *b; + return *b; } /* --------------------------- button navigation --------------------------- */ @@ -678,50 +690,54 @@ button_info *NextButton(button_info **ub,button_info **b,int *i,int all) *** Function that finds out which button a given position belongs to. *** Returns -1 is not part of any, button if a proper button. **/ -int button_belongs_to(button_info *ub,int button) +int +button_belongs_to(button_info *ub, int button) { - int x,y,xx,yy; - button_info *b; - if(!ub || button<0 || button>ub->c->num_buttons) - return -1; - if(ub->c->buttons[button]) - return button; - yy=button/ub->c->num_columns; - xx=button%ub->c->num_columns; - for(y=yy;y>=0;y--) - for(x=xx;x>=0;x--) - { - b=ub->c->buttons[x+y*ub->c->num_columns]; - if(b && (x+b->BWidth > xx) && (y+b->BHeight > yy)) - { - return x+y*ub->c->num_columns; - } - } - return -1; + int x, y, xx, yy; + button_info *b; + if (!ub || button < 0 || button > ub->c->num_buttons) + return -1; + if (ub->c->buttons[button]) + return button; + yy = button / ub->c->num_columns; + xx = button % ub->c->num_columns; + for (y = yy; y >= 0; y--) + for (x = xx; x >= 0; x--) { + b = ub->c->buttons[x + y * ub->c->num_columns]; + if (b && (x + b->BWidth > xx) && + (y + b->BHeight > yy)) { + return x + y * ub->c->num_columns; + } + } + return -1; } /** *** select_button() *** Given (x,y) and uberbutton, returns pointer to referred button, or NULL **/ -button_info *select_button(button_info *ub,int x,int y) +button_info * +select_button(button_info *ub, int x, int y) { - int i; - button_info *b; - if(!(ub->flags&b_Container)) - return ub; - - x-=buttonXPad(ub)+buttonFrame(ub); - y-=buttonYPad(ub)+buttonFrame(ub); - - if(x >= ub->c->ButtonWidth * ub->c->num_columns || x<0 || - y >= ub->c->ButtonHeight * ub->c->num_rows || y<0) - return ub; - - i=x/ub->c->ButtonWidth + (y/ub->c->ButtonHeight)*ub->c->num_columns; - i=button_belongs_to(ub,i); - if(i==-1)return ub; - b=ub->c->buttons[i]; - return select_button(b,x-(i%ub->c->num_columns)*ub->c->ButtonWidth, - y-(i/ub->c->num_columns)*ub->c->ButtonHeight); + int i; + button_info *b; + if (!(ub->flags & b_Container)) + return ub; + + x -= buttonXPad(ub) + buttonFrame(ub); + y -= buttonYPad(ub) + buttonFrame(ub); + + if (x >= ub->c->ButtonWidth * ub->c->num_columns || x < 0 || + y >= ub->c->ButtonHeight * ub->c->num_rows || y < 0) + return ub; + + i = x / ub->c->ButtonWidth + + (y / ub->c->ButtonHeight) * ub->c->num_columns; + i = button_belongs_to(ub, i); + if (i == -1) + return ub; + b = ub->c->buttons[i]; + return select_button(b, + x - (i % ub->c->num_columns) * ub->c->ButtonWidth, + y - (i / ub->c->num_columns) * ub->c->ButtonHeight); } Index: fvwm/modules/FvwmButtons/button.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmButtons/button.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmButtons/button.h --- fvwm/modules/FvwmButtons/button.h +++ fvwm/modules/FvwmButtons/button.h @@ -14,51 +14,50 @@ /* --------------------------- button information -------------------------- */ -#define buttonXPos(b,i) \ - ((b)->parent->c->xpos + \ - ((i)%(b)->parent->c->num_columns)*((b)->parent->c->ButtonWidth)) -#define buttonYPos(b,i) \ - ((b)->parent->c->ypos + \ - ((i)/(b)->parent->c->num_columns)*((b)->parent->c->ButtonHeight)) -#define buttonWidth(b) \ - ((b)->BWidth*(b)->parent->c->ButtonWidth) -#define buttonHeight(b) \ - ((b)->BHeight*(b)->parent->c->ButtonHeight) - -#define buttonSwallowCount(b) \ - (((b)->flags&b_Swallow)?((b)->swallow&b_Count):0) - -void buttonInfo(button_info*,int *x,int *y,int *padx,int *pady,int *frame); -void GetInternalSize(button_info*,int*,int*,int*,int*); +#define buttonXPos(b, i) \ + ((b)->parent->c->xpos + ((i) % (b)->parent->c->num_columns) * \ + ((b)->parent->c->ButtonWidth)) +#define buttonYPos(b, i) \ + ((b)->parent->c->ypos + ((i) / (b)->parent->c->num_columns) * \ + ((b)->parent->c->ButtonHeight)) +#define buttonWidth(b) ((b)->BWidth * (b)->parent->c->ButtonWidth) +#define buttonHeight(b) ((b)->BHeight * (b)->parent->c->ButtonHeight) + +#define buttonSwallowCount(b) \ + (((b)->flags & b_Swallow) ? ((b)->swallow & b_Count) : 0) + +void buttonInfo( + button_info *, int *x, int *y, int *padx, int *pady, int *frame); +void GetInternalSize(button_info *, int *, int *, int *, int *); #define buttonFrame(b) abs(buttonFrameSigned(b)) -int buttonFrameSigned(button_info*); -int buttonXPad(button_info*); -int buttonYPad(button_info*); -XFontStruct *buttonFont(button_info*); -Pixel buttonFore(button_info*); -Pixel buttonBack(button_info*); -Pixel buttonHilite(button_info*); -Pixel buttonShadow(button_info*); -byte buttonSwallow(button_info*); -byte buttonJustify(button_info*); +int buttonFrameSigned(button_info *); +int buttonXPad(button_info *); +int buttonYPad(button_info *); +XFontStruct *buttonFont(button_info *); +Pixel buttonFore(button_info *); +Pixel buttonBack(button_info *); +Pixel buttonHilite(button_info *); +Pixel buttonShadow(button_info *); +byte buttonSwallow(button_info *); +byte buttonJustify(button_info *); #define buttonNum(b) ((b)->n) /* ---------------------------- button creation ---------------------------- */ -void alloc_buttonlist(button_info*,int); -button_info *alloc_button(button_info*,int); -void MakeContainer(button_info*); +void alloc_buttonlist(button_info *, int); +button_info *alloc_button(button_info *, int); +void MakeContainer(button_info *); /* ------------------------- button administration ------------------------- */ -void NumberButtons(button_info*); -void ShuffleButtons(button_info*); +void NumberButtons(button_info *); +void ShuffleButtons(button_info *); /* ---------------------------- button iterator ---------------------------- */ -button_info *NextButton(button_info**,button_info**,int*,int); +button_info *NextButton(button_info **, button_info **, int *, int); /* --------------------------- button navigation --------------------------- */ -int button_belongs_to(button_info*,int); -button_info *select_button(button_info*,int,int); +int button_belongs_to(button_info *, int); +button_info *select_button(button_info *, int, int); Index: fvwm/modules/FvwmButtons/draw.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmButtons/draw.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmButtons/draw.c --- fvwm/modules/FvwmButtons/draw.c +++ fvwm/modules/FvwmButtons/draw.c @@ -16,26 +16,23 @@ #include "config.h" -#ifdef HAVE_SYS_BSDTYPES_H -#include /* Saul */ #endif -#include -#include -#include -#include - +#include +#include #include -#include #include -#include -#include +#include +#include +#include +#include +#include #include "FvwmButtons.h" -#include "misc.h" /* ConstrainSize() */ -#include "icons.h" /* ConfigureIconWindow() */ #include "button.h" #include "draw.h" +#include "icons.h" /* ConfigureIconWindow() */ +#include "misc.h" /* ConstrainSize() */ /* ---------------- Functions that design and draw buttons ----------------- */ @@ -43,134 +40,156 @@ *** RelieveWindow() *** Draws the relief pattern around a window. **/ -void RelieveWindow(Window wn,int width,int x,int y,int w,int h,Pixel relief, - Pixel shadow,int rev) +void +RelieveWindow(Window wn, int width, int x, int y, int w, int h, Pixel relief, + Pixel shadow, int rev) { - XSegment seg[4]; - unsigned long gcm=0; - XGCValues gcv; - Pixel p; - int i,j; - - if(!width) - return; - if(width<0) - { - width=-width; - p=relief;relief=shadow;shadow=p; - } - if(rev) - { - p=relief;relief=shadow;shadow=p; - } - - gcm=GCForeground; - gcv.foreground=relief; - XChangeGC(Dpy,NormalGC,gcm,&gcv); - - for(j=0;j1 && h>1 ;j++,w-=2,h-=2,x+=1,y+=1) - { - i=0; - seg[i].x1 = x; seg[i].y1 = y; - seg[i].x2 = x+w-1; seg[i++].y2 = y; - seg[i].x1 = x; seg[i].y1 = y; - seg[i].x2 = x; seg[i++].y2 = y+h-1; - XDrawSegments(Dpy,wn,NormalGC,seg,i); - } - - w+=width*2;h+=width*2;x-=width;y-=width; - - gcm=GCForeground; - gcv.foreground=shadow; - XChangeGC(Dpy,NormalGC,gcm,&gcv); - - for(j=0;j1 && h>1 ;j++,w-=2,h-=2,x+=1,y+=1) - { - i=0; - seg[i].x1 = x+1; seg[i].y1 = y+h-1; - seg[i].x2 = x+w-1; seg[i++].y2 = y+h-1; - seg[i].x1 = x+w-1; seg[i].y1 = y+1; - seg[i].x2 = x+w-1; seg[i++].y2 = y+h-1; - XDrawSegments(Dpy,wn,NormalGC,seg,i); - } + XSegment seg[4]; + unsigned long gcm = 0; + XGCValues gcv; + Pixel p; + int i, j; + + if (!width) + return; + if (width < 0) { + width = -width; + p = relief; + relief = shadow; + shadow = p; + } + if (rev) { + p = relief; + relief = shadow; + shadow = p; + } + + gcm = GCForeground; + gcv.foreground = relief; + XChangeGC(Dpy, NormalGC, gcm, &gcv); + + for (j = 0; j < width && w > 1 && h > 1; + j++, w -= 2, h -= 2, x += 1, y += 1) { + i = 0; + seg[i].x1 = x; + seg[i].y1 = y; + seg[i].x2 = x + w - 1; + seg[i++].y2 = y; + seg[i].x1 = x; + seg[i].y1 = y; + seg[i].x2 = x; + seg[i++].y2 = y + h - 1; + XDrawSegments(Dpy, wn, NormalGC, seg, i); + } + + w += width * 2; + h += width * 2; + x -= width; + y -= width; + + gcm = GCForeground; + gcv.foreground = shadow; + XChangeGC(Dpy, NormalGC, gcm, &gcv); + + for (j = 0; j < width && w > 1 && h > 1; + j++, w -= 2, h -= 2, x += 1, y += 1) { + i = 0; + seg[i].x1 = x + 1; + seg[i].y1 = y + h - 1; + seg[i].x2 = x + w - 1; + seg[i++].y2 = y + h - 1; + seg[i].x1 = x + w - 1; + seg[i].y1 = y + 1; + seg[i].x2 = x + w - 1; + seg[i++].y2 = y + h - 1; + XDrawSegments(Dpy, wn, NormalGC, seg, i); + } } /** *** MakeButton() *** To position subwindows in a button: icons and swallowed windows. **/ -void MakeButton(button_info *b) +void +MakeButton(button_info *b) { - /* This is resposible for drawing the contents of a button, placing the - icon and/or swallowed item in the correct position inside potential - padding or frame. - */ - int ih,iw,ix,iy; - XFontStruct *font; - - if(!b) - { - fprintf(stderr,"%s: BUG: DrawButton called with NULL pointer\n",MyName); - exit(2); - } - if(b->flags&b_Container) - { - fprintf(stderr,"%s: BUG: DrawButton called with container\n",MyName); - exit(2); - } - - if(!(b->flags&b_Icon) && (buttonSwallowCount(b)<3)) - return; - - /* Check if parent container has an icon as background */ - if (b->parent->c->flags&b_IconBack || b->parent->c->flags&b_IconParent) - b->flags|=b_IconParent; - - font = buttonFont(b); - - GetInternalSize(b,&ix,&iy,&iw,&ih); - - /* At this point iw,ih,ix and iy should be correct. Now all we have to do is - place title and iconwin in their proper positions */ - - /* For now, use the old routine in icons.h for buttons with icons */ - if(b->flags&b_Icon) - ConfigureIconWindow(b); - - /* For now, hardcoded window centered, title bottom centered, below window */ - else if(buttonSwallowCount(b)==3) - { - long supplied; - if(!b->IconWin) - { - fprintf(stderr,"%s: BUG: Swallowed window has no IconWin\n",MyName); - exit(2); + /* This is resposible for drawing the contents of a button, placing the + icon and/or swallowed item in the correct position inside potential + padding or frame. + */ + int ih, iw, ix, iy; + XFontStruct *font; + + if (!b) { + fprintf(stderr, + "%s: BUG: DrawButton called with NULL pointer\n", MyName); + exit(2); + } + if (b->flags & b_Container) { + fprintf(stderr, "%s: BUG: DrawButton called with container\n", + MyName); + exit(2); } - if(b->flags&b_Title && font && !(buttonJustify(b)&b_Horizontal)) - ih -= font->ascent+font->descent; - - b->icon_w=iw; - b->icon_h=ih; - - if(iw>0 && ih>0) - { - if(!(buttonSwallow(b)&b_NoHints)) - { - if(!XGetWMNormalHints(Dpy,b->IconWin,b->hints,&supplied)) - b->hints->flags=0; - ConstrainSize(b->hints,&b->icon_w,&b->icon_h); - } - if (b->flags & b_Right) - ix += iw-b->icon_w; - else if (!(b->flags & b_Left)) - ix += (iw-b->icon_w)/2; - XMoveResizeWindow(Dpy,b->IconWin,ix,iy+(ih-b->icon_h)/2, - b->icon_w,b->icon_h); + if (!(b->flags & b_Icon) && (buttonSwallowCount(b) < 3)) + return; + + /* Check if parent container has an icon as background */ + if (b->parent->c->flags & b_IconBack || + b->parent->c->flags & b_IconParent) + b->flags |= b_IconParent; + + font = buttonFont(b); + + GetInternalSize(b, &ix, &iy, &iw, &ih); + + /* At this point iw,ih,ix and iy should be correct. Now all we have to + do is place title and iconwin in their proper positions */ + + /* For now, use the old routine in icons.h for buttons with icons */ + if (b->flags & b_Icon) + ConfigureIconWindow(b); + + /* For now, hardcoded window centered, title bottom centered, below + * window */ + else if (buttonSwallowCount(b) == 3) { + long supplied; + if (!b->IconWin) { + fprintf(stderr, + "%s: BUG: Swallowed window has no IconWin\n", + MyName); + exit(2); + } + + if (b->flags & b_Title && font && + !(buttonJustify(b) & b_Horizontal)) + ih -= font->ascent + font->descent; + + b->icon_w = iw; + b->icon_h = ih; + + if (iw > 8 && ih > 8) { + if (!(buttonSwallow(b) & b_NoHints)) { + if (!XGetWMNormalHints( + Dpy, b->IconWin, b->hints, &supplied)) + b->hints->flags = 0; + ConstrainSize(b->hints, &b->icon_w, &b->icon_h); + if (b->icon_w < 1) + b->icon_w = 1; + if (b->icon_h < 1) + b->icon_h = 1; + } + b->icon_w = max(b->icon_w, 8); + b->icon_h = max(b->icon_h, 8); + if (b->flags & b_Right) + ix += iw - b->icon_w; + else if (!(b->flags & b_Left)) + ix += (iw - b->icon_w) / 2; + XMoveResizeWindow(Dpy, b->IconWin, ix, + iy + (ih - b->icon_h) / 2, b->icon_w, b->icon_h); + } else + XMoveWindow(Dpy, b->IconWin, 2000, 2000); } - else - XMoveWindow(Dpy,b->IconWin,2000,2000); - } } /** @@ -178,163 +197,167 @@ void MakeButton(button_info *b) *** Writes out title, if any, and displays the bevel right, by calling *** RelieveWindow. If clean is nonzero, also clears background. **/ -void RedrawButton(button_info *b,int clean) +void +RedrawButton(button_info *b, int clean) { - int i,j,k,BH,BW; - int f,x,y,px,py; - int ix,iy,iw,ih; - XFontStruct *font=buttonFont(b); - XGCValues gcv; - unsigned long gcm=0; - int rev=0; - - BW = buttonWidth(b); - BH = buttonHeight(b); - buttonInfo(b,&x,&y,&px,&py,&f); - GetInternalSize(b,&ix,&iy,&iw,&ih); - - /* This probably isn't the place for this, but it seems to work here and not - elsewhere, so... */ - if((buttonSwallowCount(b)==3) && b->IconWin!=None) - XSetWindowBorderWidth(Dpy,b->IconWin,0); - - /* ----------------------------------------------------------------------- */ - - if(b->flags&b_Hangon || b==CurrentButton) /* Hanging or held down by user */ - rev=1; - if(b->flags&b_Action) /* If this is a Desk button that takes you to here.. */ - { - int n=0; - while(n<4 && (!b->action[n] || strncasecmp(b->action[n],"Desk",4))) - n++; - if(n<4) - { - k=sscanf(&b->action[n][4],"%d%d",&i,&j); - if(k==2 && i==0 && j==new_desk) - rev=1; + int i, j, k, BH, BW; + int f, x, y, px, py; + int ix, iy, iw, ih; + XFontStruct *font = buttonFont(b); + XGCValues gcv; + unsigned long gcm = 0; + int rev = 0; + + BW = buttonWidth(b); + BH = buttonHeight(b); + buttonInfo(b, &x, &y, &px, &py, &f); + GetInternalSize(b, &ix, &iy, &iw, &ih); + + /* This probably isn't the place for this, but it seems to work here and + not elsewhere, so... */ + if ((buttonSwallowCount(b) == 3) && b->IconWin != None) + XSetWindowBorderWidth(Dpy, b->IconWin, 0); + + /* ----------------------------------------------------------------------- + */ + + if (b->flags & b_Hangon || + b == CurrentButton) /* Hanging or held down by user */ + rev = 1; + if (b->flags & + b_Action) { /* If this is a Desk button that takes you to here.. */ + int n = 0; + while (n < 4 && + (!b->action[n] || strncasecmp(b->action[n], "Desk", 4))) + n++; + if (n < 4) { + k = sscanf(&b->action[n][4], "%d%d", &i, &j); + if (k == 2 && i == 0 && j == new_desk) + rev = 1; + } } - } - RelieveWindow(MyWindow,f,x,y,BW,BH,buttonHilite(b),buttonShadow(b),rev); - - /* ----------------------------------------------------------------------- */ - - f=abs(f); - - if(clean && BW>2*f && BH>2*f) - { - gcm = GCForeground; - gcv.foreground=buttonBack(b); - XChangeGC(Dpy,NormalGC,gcm,&gcv); - - if(b->flags&b_Container) - { - int x1=x+f,y1=y+f; - int w1=px,h1=py,w2=w1,h2=h1; - int w=BW-2*f,h=BH-2*f; - w2+=iw - b->c->num_columns*b->c->ButtonWidth; - h2+=ih - b->c->num_rows*b->c->ButtonHeight; - - if(w1)XFillRectangle(Dpy,MyWindow,NormalGC,x1,y1,w1,h); - if(w2)XFillRectangle(Dpy,MyWindow,NormalGC,x1+w-w2,y1,w2,h); - if(h1)XFillRectangle(Dpy,MyWindow,NormalGC,x1,y1,w,h1); - if(h2)XFillRectangle(Dpy,MyWindow,NormalGC,x1,y1+h-h2,w,h2); + RelieveWindow( + MyWindow, f, x, y, BW, BH, buttonHilite(b), buttonShadow(b), rev); + + /* ----------------------------------------------------------------------- + */ + + f = abs(f); + + if (clean && BW > 2 * f && BH > 2 * f) { + gcm = GCForeground; + gcv.foreground = buttonBack(b); + XChangeGC(Dpy, NormalGC, gcm, &gcv); + + if (b->flags & b_Container) { + int x1 = x + f, y1 = y + f; + int w1 = px, h1 = py, w2 = w1, h2 = h1; + int w = BW - 2 * f, h = BH - 2 * f; + w2 += iw - b->c->num_columns * b->c->ButtonWidth; + h2 += ih - b->c->num_rows * b->c->ButtonHeight; + + if (w1) + XFillRectangle( + Dpy, MyWindow, NormalGC, x1, y1, w1, h); + if (w2) + XFillRectangle(Dpy, MyWindow, NormalGC, + x1 + w - w2, y1, w2, h); + if (h1) + XFillRectangle( + Dpy, MyWindow, NormalGC, x1, y1, w, h1); + if (h2) + XFillRectangle(Dpy, MyWindow, NormalGC, x1, + y1 + h - h2, w, h2); + } else if (!(b->flags & b_IconBack) && + !(b->flags & b_IconParent) && + !(b->flags & b_Swallow)) + XFillRectangle(Dpy, MyWindow, NormalGC, x + f, y + f, + BW - 2 * f, BH - 2 * f); + } + + /* ----------------------------------------------------------------------- + */ + + if (b->flags & b_Title && font) { + gcm = GCForeground | GCFont; + gcv.foreground = buttonFore(b); + gcv.font = font->fid; + XChangeGC(Dpy, NormalGC, gcm, &gcv); + DrawTitle(b, MyWindow, NormalGC); } - else if(!(b->flags&b_IconBack) && !(b->flags&b_IconParent) && - !(b->flags&b_Swallow)) - XFillRectangle(Dpy,MyWindow,NormalGC,x+f,y+f,BW-2*f,BH-2*f); - } - - /* ----------------------------------------------------------------------- */ - - if(b->flags&b_Title && font) - { - gcm = GCForeground | GCFont; - gcv.foreground=buttonFore(b); - gcv.font = font->fid; - XChangeGC(Dpy,NormalGC,gcm,&gcv); - DrawTitle(b,MyWindow,NormalGC); - } } /** *** DrawTitle() *** Writes out title. **/ -void DrawTitle(button_info *b,Window win,GC gc) +void +DrawTitle(button_info *b, Window win, GC gc) { - int BH; - int ix,iy,iw,ih; - XFontStruct *font=buttonFont(b); - int justify=buttonJustify(b); - int l,i,xpos; - char *s; - int just=justify&b_TitleHoriz; /* Left, center, right */ - - BH = buttonHeight(b); - - GetInternalSize(b,&ix,&iy,&iw,&ih); - - /* ----------------------------------------------------------------------- */ - - if(!(b->flags&b_Title) || !font) - return; - - /* If a title is to be shown, truncate it until it fits */ - if(justify&b_Horizontal) - { - if(b->flags&b_Icon) - { - ix+=b->icon->width+buttonXPad(b); - iw-=b->icon->width+buttonXPad(b); - } - else if (buttonSwallowCount(b)==3) - { - ix+=b->icon_w+buttonXPad(b); - iw-=b->icon_w+buttonXPad(b); + int BH; + int ix, iy, iw, ih; + XFontStruct *font = buttonFont(b); + int justify = buttonJustify(b); + int l, i, xpos; + char *s; + int just = justify & b_TitleHoriz; /* Left, center, right */ + + BH = buttonHeight(b); + + GetInternalSize(b, &ix, &iy, &iw, &ih); + + /* ----------------------------------------------------------------------- + */ + + if (!(b->flags & b_Title) || !font) + return; + + /* If a title is to be shown, truncate it until it fits */ + if (justify & b_Horizontal) { + if (b->flags & b_Icon) { + ix += b->icon->width + buttonXPad(b); + iw -= b->icon->width + buttonXPad(b); + } else if (buttonSwallowCount(b) == 3) { + ix += b->icon_w + buttonXPad(b); + iw -= b->icon_w + buttonXPad(b); + } } - } - - s=b->title; - l=strlen(s); - i=XTextWidth(font,s,l); - - if(i>iw) - { - if(just==2) - { - while(i>iw && *s) - i=XTextWidth(font,++s,--l); - } - else /* Left or center - cut off its tail */ - { - while(i>iw && l>0) - i=XTextWidth(font,s,--l); - } - } - if(just==0) /* Left */ - xpos=ix; - else if(just==2) /* Right */ - xpos=max(ix,ix+iw-i); - else /* Centered, I guess */ - xpos=ix+(iw-i)/2; - - if(*s && l>0 && BH>=font->descent+font->ascent) /* Clip it somehow? */ - { - /* If there is more than the title, put it at the bottom */ - /* Unless stack flag is set, put it to the right of icon */ - if((b->flags&b_Icon || (buttonSwallowCount(b)==3)) && - !(justify&b_Horizontal)) - { - XDrawString(Dpy,win,gc,xpos, - iy+ih-font->descent,s,l); - /* Shrink the space available for icon/window */ - ih-=font->descent+font->ascent; + + s = b->title; + l = strlen(s); + i = XTextWidth(font, s, l); + + if (i > iw) { + if (just == 2) { + while (i > iw && *s) + i = XTextWidth(font, ++s, --l); + } else /* Left or center - cut off its tail */ { + while (i > iw && l > 0) + i = XTextWidth(font, s, --l); + } } - /* Or else center vertically */ - else - { - XDrawString(Dpy,win,gc,xpos, - iy+(ih+font->ascent-font->descent)/2,s,l); + if (just == 0) /* Left */ + xpos = ix; + else if (just == 2) /* Right */ + xpos = max(ix, ix + iw - i); + else /* Centered, I guess */ + xpos = ix + (iw - i) / 2; + + if (*s && l > 0 && + BH >= font->descent + font->ascent) { /* Clip it somehow? */ + /* If there is more than the title, put it at the bottom */ + /* Unless stack flag is set, put it to the right of icon */ + if ((b->flags & b_Icon || (buttonSwallowCount(b) == 3)) && + !(justify & b_Horizontal)) { + XDrawString( + Dpy, win, gc, xpos, iy + ih - font->descent, s, l); + /* Shrink the space available for icon/window */ + ih -= font->descent + font->ascent; + } + /* Or else center vertically */ + else { + XDrawString(Dpy, win, gc, xpos, + iy + (ih + font->ascent - font->descent) / 2, s, l); + } } - } } Index: fvwm/modules/FvwmButtons/draw.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmButtons/draw.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmButtons/draw.h --- fvwm/modules/FvwmButtons/draw.h +++ fvwm/modules/FvwmButtons/draw.h @@ -12,8 +12,7 @@ */ -void RelieveWindow(Window,int,int,int,int,int,Pixel,Pixel,int); -void MakeButton(button_info*); -void RedrawButton(button_info*,int); -void DrawTitle(button_info*,Window,GC); - +void RelieveWindow(Window, int, int, int, int, int, Pixel, Pixel, int); +void MakeButton(button_info *); +void RedrawButton(button_info *, int); +void DrawTitle(button_info *, Window, GC); Index: fvwm/modules/FvwmButtons/icons.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmButtons/icons.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmButtons/icons.c --- fvwm/modules/FvwmButtons/icons.c +++ fvwm/modules/FvwmButtons/icons.c @@ -8,7 +8,7 @@ * Copyright 1993, Robert Nation. No guarantees or warantees or anything * are provided or implied in any way whatsoever. Use this program at your * own risk. Permission to use this program for any purpose is given, - * as long as the copyright is kept intact. + * as long as the copyright is kept intact. */ /*********************************************************************** @@ -17,19 +17,18 @@ * ***********************************************************************/ -#include "config.h" - -#include -#include +#include +#include +#include +#include +#include #include -#include +#include #include +#include +#include -#include -#include -#include -#include -#include +#include "config.h" #ifdef HAVE_FCNTL_H #include @@ -51,159 +50,161 @@ * Creates an Icon Window * ****************************************************************************/ -void CreateIconWindow(button_info *b) +void +CreateIconWindow(button_info *b) { #ifndef NO_ICONS - unsigned long valuemask; /* mask for create windows */ - XSetWindowAttributes attributes; /* attributes for create windows */ - - if(!(b->flags&b_Icon)) - return; - - if(b->IconWin != None) - { - fprintf(stderr,"%s: BUG: Iconwindow already created for 0x%lx!\n", - MyName,(unsigned long)b); - exit(2); - } - - attributes.background_pixel = buttonBack(b); - attributes.event_mask = ExposureMask; - valuemask = CWEventMask | CWBackPixel; - - if(b->icon->width<1 || b->icon->height<1) - { - fprintf(stderr,"%s: BUG: Illegal iconwindow tried created\n",MyName); - exit(2); - } - b->IconWin=XCreateWindow(Dpy,MyWindow,0,0,b->icon->width,b->icon->height, - 0, CopyFromParent, CopyFromParent,CopyFromParent, - valuemask,&attributes); + unsigned long valuemask; /* mask for create windows */ + XSetWindowAttributes attributes; /* attributes for create windows */ + + if (!(b->flags & b_Icon)) + return; + + if (b->IconWin != None) { + fprintf(stderr, + "%s: BUG: Iconwindow already created for 0x%lx!\n", MyName, + (unsigned long)b); + exit(2); + } + + attributes.background_pixel = buttonBack(b); + attributes.event_mask = ExposureMask; + valuemask = CWEventMask | CWBackPixel; + + if (b->icon->width < 1 || b->icon->height < 1) { + fprintf(stderr, "%s: BUG: Illegal iconwindow tried created\n", + MyName); + exit(2); + } + b->IconWin = XCreateWindow(Dpy, MyWindow, 0, 0, b->icon->width, + b->icon->height, 0, CopyFromParent, CopyFromParent, CopyFromParent, + valuemask, &attributes); #ifdef XPM #ifdef SHAPE - if (b->icon->mask!=None) - XShapeCombineMask(Dpy,b->IconWin,ShapeBounding,0,0, - b->icon->mask,ShapeSet); + if (b->icon->mask != None) + XShapeCombineMask(Dpy, b->IconWin, ShapeBounding, 0, 0, + b->icon->mask, ShapeSet); #endif #endif - if(b->icon->depth==0) - { - XGCValues gcv; - unsigned long gcm=0; - Pixmap temp; - - gcm = GCForeground | GCBackground; - gcv.background=buttonBack(b); - gcv.foreground=buttonFore(b); - XChangeGC(Dpy,NormalGC,gcm,&gcv); - + if (b->icon->depth == 0) { + XGCValues gcv; + unsigned long gcm = 0; + Pixmap temp; + + gcm = GCForeground | GCBackground; + gcv.background = buttonBack(b); + gcv.foreground = buttonFore(b); + XChangeGC(Dpy, NormalGC, gcm, &gcv); + #ifdef SHAPE - XShapeCombineMask(Dpy,b->IconWin,ShapeBounding,0,0, - b->icon->picture,ShapeSet); + XShapeCombineMask(Dpy, b->IconWin, ShapeBounding, 0, 0, + b->icon->picture, ShapeSet); #endif - - temp = XCreatePixmap(Dpy,Root,b->icon->width, - b->icon->height,d_depth); - XCopyPlane(Dpy,b->icon->picture,temp,NormalGC, - 0,0,b->icon->width,b->icon->height,0,0,1); - - XSetWindowBackgroundPixmap(Dpy,b->IconWin,temp); - XFreePixmap(Dpy,temp); - /* We won't use the icon pixmap anymore... but we still need it for - width/height etc. so we can't destroy it. */ - } - else - XSetWindowBackgroundPixmap(Dpy,b->IconWin,b->icon->picture); - - return; + + temp = XCreatePixmap( + Dpy, Root, b->icon->width, b->icon->height, d_depth); + XCopyPlane(Dpy, b->icon->picture, temp, NormalGC, 0, 0, + b->icon->width, b->icon->height, 0, 0, 1); + + XSetWindowBackgroundPixmap(Dpy, b->IconWin, temp); + XFreePixmap(Dpy, temp); + /* We won't use the icon pixmap anymore... but we still need it + for width/height etc. so we can't destroy it. */ + } else + XSetWindowBackgroundPixmap(Dpy, b->IconWin, b->icon->picture); + + return; #endif } - /**************************************************************************** * * Combines icon shape masks after a resize * ****************************************************************************/ -void ConfigureIconWindow(button_info *b) +void +ConfigureIconWindow(button_info *b) { #ifndef NO_ICONS - int x,y,w,h; - int xoff,yoff; - int framew,xpad,ypad; - XFontStruct *font; - int BW,BH; - - if(!b || !(b->flags&b_Icon)) - return; - - if(!b->IconWin) - { - fprintf(stderr,"%s: DEBUG: Tried to configure erroneous iconwindow\n", - MyName); - exit(2); - } - - buttonInfo(b,&x,&y,&xpad,&ypad,&framew); - framew=abs(framew); - - font = buttonFont(b); - w = b->icon->width; - h = b->icon->height; - BW = buttonWidth(b); - BH = buttonHeight(b); - - w=min(w,BW-2*(xpad+framew)); - - if(b->flags&b_Title && font && !(buttonJustify(b)&b_Horizontal)) - h=min(h,BH-2*(ypad+framew)-font->ascent-font->descent); - else - h=min(h,BH-2*(ypad+framew)); - - if(w < 1 || h < 1) - { - XMoveResizeWindow(Dpy, b->IconWin, 2000,2000,1,1); - return; /* No need drawing to this */ - } - - if(buttonJustify(b)&b_Horizontal) - xoff=0; - else - xoff=(BW-w)>>1; - - if(b->flags&b_Title && font && !(buttonJustify(b)&b_Horizontal)) - yoff=(BH-(h+font->ascent+font->descent))>>1; - else - yoff=(BH-h)>>1; - - if(xoff < framew+xpad) - xoff = framew+xpad; - if(yoff < framew+ypad) - yoff = framew+ypad; - - x += xoff; - y += yoff; - - XMoveResizeWindow(Dpy, b->IconWin, x,y,w,h); - -/* Doesn't this belong above? -#ifdef XPM -#ifdef SHAPE - if (b->icon->mask!=None) - { - XShapeCombineMask(Dpy,b->IconWin,ShapeBounding,0,0, - b->icon->mask,ShapeSet); - } -#endif -#endif - if(b->icon->depth==0) - { - PixmapFromBitmap(b); - } - XSetWindowBackgroundPixmap(Dpy,b->IconWin,b->icon->picture); -*/ + int x, y, w, h; + int xoff, yoff; + int framew, xpad, ypad; + XFontStruct *font; + int BW, BH; + + if (!b || !(b->flags & b_Icon)) + return; + + if (!b->IconWin) { + fprintf(stderr, + "%s: DEBUG: Tried to configure erroneous iconwindow\n", + MyName); + exit(2); + } + + buttonInfo(b, &x, &y, &xpad, &ypad, &framew); + framew = abs(framew); + + font = buttonFont(b); + w = b->icon->width; + h = b->icon->height; + BW = buttonWidth(b); + BH = buttonHeight(b); + + w = min(w, BW - 2 * (xpad + framew)); + + if (b->flags & b_Title && font && !(buttonJustify(b) & b_Horizontal)) + h = min( + h, BH - 2 * (ypad + framew) - font->ascent - font->descent); + else + h = min(h, BH - 2 * (ypad + framew)); + + if (w < 1 || h < 1) { + if (buttonSwallowCount(b) == 3) + XMoveWindow(Dpy, b->IconWin, 2000, 2000); + else + XMoveResizeWindow(Dpy, b->IconWin, 2000, 2000, 1, 1); + return; /* No need drawing to this */ + } + + if (buttonJustify(b) & b_Horizontal) + xoff = 0; + else + xoff = (BW - w) >> 1; + + if (b->flags & b_Title && font && !(buttonJustify(b) & b_Horizontal)) + yoff = (BH - (h + font->ascent + font->descent)) >> 1; + else + yoff = (BH - h) >> 1; + + if (xoff < framew + xpad) + xoff = framew + xpad; + if (yoff < framew + ypad) + yoff = framew + ypad; + + x += xoff; + y += yoff; + + XMoveResizeWindow(Dpy, b->IconWin, x, y, w, h); + + /* Doesn't this belong above? + #ifdef XPM + #ifdef SHAPE + if (b->icon->mask!=None) + { + XShapeCombineMask(Dpy,b->IconWin,ShapeBounding,0,0, + b->icon->mask,ShapeSet); + } + #endif + #endif + if(b->icon->depth==0) + { + PixmapFromBitmap(b); + } + XSetWindowBackgroundPixmap(Dpy,b->IconWin,b->icon->picture); + */ -#endif +#endif } Index: fvwm/modules/FvwmButtons/icons.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmButtons/icons.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmButtons/icons.h --- fvwm/modules/FvwmButtons/icons.h +++ fvwm/modules/FvwmButtons/icons.h @@ -13,8 +13,5 @@ */ /* ------------------------------ prototypes ------------------------------- */ -#if 0 -void LoadIconFile(button_info*); -#endif -void CreateIconWindow(button_info*); -void ConfigureIconWindow(button_info*); +void CreateIconWindow(button_info *); +void ConfigureIconWindow(button_info *); Index: fvwm/modules/FvwmButtons/misc.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmButtons/misc.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmButtons/misc.c --- fvwm/modules/FvwmButtons/misc.c +++ fvwm/modules/FvwmButtons/misc.c @@ -21,138 +21,126 @@ *** The general algorithm, especially the aspect ratio stuff, is borrowed from *** uwm's CheckConsistency routine. **/ -void ConstrainSize (XSizeHints *hints, int *widthp, int *heightp) +void +ConstrainSize(XSizeHints *hints, int *widthp, int *heightp) { -#define makemult(a,b) ((b==1) ? (a) : (((int)((a)/(b))) * (b)) ) +#define makemult(a, b) ((b == 1) ? (a) : (((int)((a) / (b))) * (b))) - int minWidth, minHeight, maxWidth, maxHeight, xinc, yinc, delta; - int baseWidth, baseHeight; - int dwidth = *widthp, dheight = *heightp; + int minWidth, minHeight, maxWidth, maxHeight, xinc, yinc, delta; + int baseWidth, baseHeight; + int dwidth = *widthp, dheight = *heightp; - if(hints->flags & PMinSize) - { - minWidth = hints->min_width; - minHeight = hints->min_height; - if(hints->flags & PBaseSize) - { - baseWidth = hints->base_width; - baseHeight = hints->base_height; + if (hints->flags & PMinSize) { + minWidth = hints->min_width; + minHeight = hints->min_height; + if (hints->flags & PBaseSize) { + baseWidth = hints->base_width; + baseHeight = hints->base_height; + } else { + baseWidth = hints->min_width; + baseHeight = hints->min_height; + } + } else if (hints->flags & PBaseSize) { + minWidth = hints->base_width; + minHeight = hints->base_height; + baseWidth = hints->base_width; + baseHeight = hints->base_height; + } else { + minWidth = 1; + minHeight = 1; + baseWidth = 1; + baseHeight = 1; } - else - { - baseWidth = hints->min_width; - baseHeight = hints->min_height; + + if (hints->flags & PMaxSize) { + maxWidth = hints->max_width; + maxHeight = hints->max_height; + } else { + maxWidth = 10000; + maxHeight = 10000; + } + if (hints->flags & PResizeInc) { + xinc = hints->width_inc; + yinc = hints->height_inc; + } else { + xinc = 1; + yinc = 1; } - } - else if(hints->flags & PBaseSize) - { - minWidth = hints->base_width; - minHeight = hints->base_height; - baseWidth = hints->base_width; - baseHeight = hints->base_height; - } - else - { - minWidth = 1; - minHeight = 1; - baseWidth = 1; - baseHeight = 1; - } - - if(hints->flags & PMaxSize) - { - maxWidth = hints->max_width; - maxHeight = hints->max_height; - } - else - { - maxWidth = 10000; - maxHeight = 10000; - } - if(hints->flags & PResizeInc) - { - xinc = hints->width_inc; - yinc = hints->height_inc; - } - else - { - xinc = 1; - yinc = 1; - } - - /* - * First, clamp to min and max values - */ - if (dwidth < minWidth) dwidth = minWidth; - if (dheight < minHeight) dheight = minHeight; - - if (dwidth > maxWidth) dwidth = maxWidth; - if (dheight > maxHeight) dheight = maxHeight; - - - /* - * Second, fit to base + N * inc - */ - dwidth = ((dwidth - baseWidth) / xinc * xinc) + baseWidth; - dheight = ((dheight - baseHeight) / yinc * yinc) + baseHeight; - - - /* - * Third, adjust for aspect ratio - */ + + /* + * First, clamp to min and max values + */ + if (dwidth < minWidth) + dwidth = minWidth; + if (dheight < minHeight) + dheight = minHeight; + + if (dwidth > maxWidth) + dwidth = maxWidth; + if (dheight > maxHeight) + dheight = maxHeight; + + /* + * Second, fit to base + N * inc + */ + dwidth = ((dwidth - baseWidth) / xinc * xinc) + baseWidth; + dheight = ((dheight - baseHeight) / yinc * yinc) + baseHeight; + + /* + * Third, adjust for aspect ratio + */ #define maxAspectX hints->max_aspect.x #define maxAspectY hints->max_aspect.y #define minAspectX hints->min_aspect.x #define minAspectY hints->min_aspect.y - /* - * The math looks like this: - * - * minAspectX dwidth maxAspectX - * ---------- <= ------- <= ---------- - * minAspectY dheight maxAspectY - * - * If that is multiplied out, then the width and height are - * invalid in the following situations: - * - * minAspectX * dheight > minAspectY * dwidth - * maxAspectX * dheight < maxAspectY * dwidth - * - */ - - if (hints->flags & PAspect) - { - if (minAspectX * dheight > minAspectY * dwidth) - { - delta = makemult(minAspectX * dheight / minAspectY - dwidth, - xinc); - if (dwidth + delta <= maxWidth) - dwidth += delta; - else - { - delta = makemult(dheight - dwidth*minAspectY/minAspectX, - yinc); - if (dheight - delta >= minHeight) dheight -= delta; - } - } - - if (maxAspectX * dheight < maxAspectY * dwidth) - { - delta = makemult(dwidth * maxAspectY / maxAspectX - dheight, - yinc); - if (dheight + delta <= maxHeight) - dheight += delta; - else - { - delta = makemult(dwidth - maxAspectX*dheight/maxAspectY, - xinc); - if (dwidth - delta >= minWidth) dwidth -= delta; - } + /* + * The math looks like this: + * + * minAspectX dwidth maxAspectX + * ---------- <= ------- <= ---------- + * minAspectY dheight maxAspectY + * + * If that is multiplied out, then the width and height are + * invalid in the following situations: + * + * minAspectX * dheight > minAspectY * dwidth + * maxAspectX * dheight < maxAspectY * dwidth + * + */ + + if (hints->flags & PAspect) { + if (minAspectX * dheight > minAspectY * dwidth) { + delta = makemult( + minAspectX * dheight / minAspectY - dwidth, xinc); + if (dwidth + delta <= maxWidth) + dwidth += delta; + else { + delta = makemult( + dheight - dwidth * minAspectY / minAspectX, + yinc); + if (dheight - delta >= minHeight) + dheight -= delta; + } + } + + if (maxAspectX * dheight < maxAspectY * dwidth) { + delta = makemult( + dwidth * maxAspectY / maxAspectX - dheight, yinc); + if (dheight + delta <= maxHeight) + dheight += delta; + else { + delta = makemult( + dwidth - maxAspectX * dheight / maxAspectY, + xinc); + if (dwidth - delta >= minWidth) + dwidth -= delta; + } + } } - } - - *widthp = dwidth; - *heightp = dheight; - return; + + *widthp = dwidth; + *heightp = dheight; + return; #undef makemult #undef maxAspectX #undef maxAspectY Index: fvwm/modules/FvwmButtons/misc.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmButtons/misc.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmButtons/misc.h --- fvwm/modules/FvwmButtons/misc.h +++ fvwm/modules/FvwmButtons/misc.h @@ -15,4 +15,4 @@ #include #include -void ConstrainSize (XSizeHints *hints, int *widthp, int *heightp); +void ConstrainSize(XSizeHints *hints, int *widthp, int *heightp); Index: fvwm/modules/FvwmButtons/output.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmButtons/output.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmButtons/output.c --- fvwm/modules/FvwmButtons/output.c +++ fvwm/modules/FvwmButtons/output.c @@ -12,268 +12,259 @@ */ -#include +#include #include -#include #include -#include +#include +#include + #include "FvwmButtons.h" /** *** DumpButtons() *** Debug function. May only be called after ShuffleButtons has been called. **/ -void DumpButtons(button_info *b) +void +DumpButtons(button_info *b) { - if(!b) - { - fprintf(stderr,"NULL\n"); - return; - } - if(b!=UberButton) - { - int button=buttonNum(b); - fprintf(stderr,"0x%lx(%ix%i@(%i,%i),0x%04lx): ", - (unsigned long)b,b->BWidth,b->BHeight, - buttonXPos(b,button),buttonYPos(b,button),b->flags); - } - else - fprintf(stderr,"0x%lx(%ix%i@,0x%04lx): ",(unsigned long)b, - b->BWidth,b->BHeight,b->flags); - - if(b->flags&b_Font) - fprintf(stderr,"Font(%s,0x%lx) ",b->font_string,(unsigned long)b->font); - if(b->flags&b_Padding) - fprintf(stderr,"Padding(%i,%i) ",b->xpad,b->ypad); - if(b->flags&b_Frame) - fprintf(stderr,"Framew(%i) ",b->framew); - if(b->flags&b_Title) - fprintf(stderr,"Title(%s) ",b->title); - if(b->flags&b_Icon) - fprintf(stderr,"Icon(%s,%i) ",b->icon_file,(int)b->IconWin); - if(b->flags&b_Action) - fprintf(stderr,"\n Action(%s,%s,%s,%s) ", - b->action[0]?b->action[0]:"", - b->action[1]?b->action[1]:"", - b->action[2]?b->action[2]:"", - b->action[3]?b->action[3]:""); - if(b->flags&b_Swallow) - { - fprintf(stderr,"Swallow(0x%02x) ",b->swallow); - if(b->swallow&b_Respawn) - fprintf(stderr,"\n Respawn(%s) ",b->spawn); - } - if(b->flags&b_Hangon) - fprintf(stderr,"Hangon(%s) ",b->hangon); - fprintf(stderr,"\n"); - if(b->flags&b_Container) - { - int i=0; - fprintf(stderr," Container(%ix%i=%i buttons 0x%04lx (alloc %i), size %ix%i, pos %i,%i)\n{ ", - b->c->num_columns,b->c->num_rows,b->c->num_buttons,b->c->flags, - b->c->allocated_buttons, - b->c->ButtonWidth,b->c->ButtonHeight,b->c->xpos,b->c->ypos); -/* - fprintf(stderr," font(%s,%i) framew(%i) pad(%i,%i) { ", - b->c->font_string,(int)b->c->font,b->c->framew,b->c->xpad, - b->c->ypad); -*/ - while(ic->num_buttons) - fprintf(stderr,"0x%lx ",(unsigned long)b->c->buttons[i++]); - fprintf(stderr,"}\n"); - i=0; - while(ic->num_buttons) - DumpButtons(b->c->buttons[i++]); - return; - } + if (!b) { + fprintf(stderr, "NULL\n"); + return; + } + if (b != UberButton) { + int button = buttonNum(b); + fprintf(stderr, + "0x%lx(%ix%i@(%i,%i),0x%04lx): ", (unsigned long)b, + b->BWidth, b->BHeight, buttonXPos(b, button), + buttonYPos(b, button), b->flags); + } else + fprintf(stderr, "0x%lx(%ix%i@,0x%04lx): ", (unsigned long)b, + b->BWidth, b->BHeight, b->flags); + + if (b->flags & b_Font) + fprintf(stderr, "Font(%s,0x%lx) ", b->font_string, + (unsigned long)b->font); + if (b->flags & b_Padding) + fprintf(stderr, "Padding(%i,%i) ", b->xpad, b->ypad); + if (b->flags & b_Frame) + fprintf(stderr, "Framew(%i) ", b->framew); + if (b->flags & b_Title) + fprintf(stderr, "Title(%s) ", b->title); + if (b->flags & b_Icon) + fprintf(stderr, "Icon(%s,%i) ", b->icon_file, (int)b->IconWin); + if (b->flags & b_Action) + fprintf(stderr, "\n Action(%s,%s,%s,%s) ", + b->action[0] ? b->action[0] : "", + b->action[1] ? b->action[1] : "", + b->action[2] ? b->action[2] : "", + b->action[3] ? b->action[3] : ""); + if (b->flags & b_Swallow) { + fprintf(stderr, "Swallow(0x%02x) ", b->swallow); + if (b->swallow & b_Respawn) + fprintf(stderr, "\n Respawn(%s) ", b->spawn); + } + if (b->flags & b_Hangon) + fprintf(stderr, "Hangon(%s) ", b->hangon); + fprintf(stderr, "\n"); + if (b->flags & b_Container) { + int i = 0; + fprintf(stderr, + " Container(%ix%i=%i buttons 0x%04lx (alloc %i), size " + "%ix%i, pos %i,%i)\n{ ", + b->c->num_columns, b->c->num_rows, b->c->num_buttons, + b->c->flags, b->c->allocated_buttons, b->c->ButtonWidth, + b->c->ButtonHeight, b->c->xpos, b->c->ypos); + /* + fprintf(stderr," font(%s,%i) framew(%i) pad(%i,%i) { ", + b->c->font_string,(int)b->c->font,b->c->framew,b->c->xpad, + b->c->ypad); + */ + while (i < b->c->num_buttons) + fprintf(stderr, "0x%lx ", + (unsigned long)b->c->buttons[i++]); + fprintf(stderr, "}\n"); + i = 0; + while (i < b->c->num_buttons) + DumpButtons(b->c->buttons[i++]); + return; + } } -void SaveButtons(button_info *b) +void +SaveButtons(button_info *b) { - int i; - if(!b) - return; - if(b->BWidth>1 || b->BHeight>1) - fprintf(stderr,"%ix%i ",b->BWidth,b->BHeight); - if(b->flags&b_Font) - fprintf(stderr,"Font %s ",b->font_string); - if(b->flags&b_Fore) - fprintf(stderr,"Fore %s ",b->fore); - if(b->flags&b_Back) - fprintf(stderr,"Back %s ",b->back); - if(b->flags&b_Frame) - fprintf(stderr,"Frame %i ",b->framew); - if(b->flags&b_Padding) - fprintf(stderr,"Padding %i %i ",b->xpad,b->ypad); - if(b->flags&b_Title) - { - fprintf(stderr,"Title "); - if(b->flags&b_Justify) - { - fprintf(stderr,"("); - switch(b->justify&b_TitleHoriz) - { - case 0: - fprintf(stderr,"Left"); - break; - case 1: - fprintf(stderr,"Center"); - break; - case 2: - fprintf(stderr,"Right"); - break; - } - if(b->justify&b_Horizontal) - fprintf(stderr,", Side"); - fprintf(stderr,") "); + int i; + if (!b) + return; + if (b->BWidth > 1 || b->BHeight > 1) + fprintf(stderr, "%ix%i ", b->BWidth, b->BHeight); + if (b->flags & b_Font) + fprintf(stderr, "Font %s ", b->font_string); + if (b->flags & b_Fore) + fprintf(stderr, "Fore %s ", b->fore); + if (b->flags & b_Back) + fprintf(stderr, "Back %s ", b->back); + if (b->flags & b_Frame) + fprintf(stderr, "Frame %i ", b->framew); + if (b->flags & b_Padding) + fprintf(stderr, "Padding %i %i ", b->xpad, b->ypad); + if (b->flags & b_Title) { + fprintf(stderr, "Title "); + if (b->flags & b_Justify) { + fprintf(stderr, "("); + switch (b->justify & b_TitleHoriz) { + case 0: + fprintf(stderr, "Left"); + break; + case 1: + fprintf(stderr, "Center"); + break; + case 2: + fprintf(stderr, "Right"); + break; + } + if (b->justify & b_Horizontal) + fprintf(stderr, ", Side"); + fprintf(stderr, ") "); + } + fprintf(stderr, "\"%s\" ", b->title); + } + if (b->flags & b_Icon) + fprintf(stderr, "Icon \"%s\" ", b->icon_file); + if (b->flags & b_Swallow) { + fprintf(stderr, "Swallow "); + if (b->swallow_mask) { + fprintf(stderr, "("); + if (b->swallow_mask & b_NoHints) { + if (b->swallow & b_NoHints) + fprintf(stderr, "NoHints "); + else + fprintf(stderr, "Hints "); + } + if (b->swallow_mask & b_Kill) { + if (b->swallow & b_Kill) + fprintf(stderr, "Kill "); + else + fprintf(stderr, "NoKill "); + } + if (b->swallow_mask & b_NoClose) { + if (b->swallow & b_NoClose) + fprintf(stderr, "NoClose "); + else + fprintf(stderr, "Close "); + } + if (b->swallow_mask & b_Respawn) { + if (b->swallow & b_Respawn) + fprintf(stderr, "Respawn "); + else + fprintf(stderr, "NoRespawn "); + } + if (b->swallow_mask & b_UseOld) { + if (b->swallow & b_UseOld) + fprintf(stderr, "UseOld "); + else + fprintf(stderr, "NoOld "); + } + if (b->swallow_mask & b_UseTitle) { + if (b->swallow & b_UseTitle) + fprintf(stderr, "UseTitle "); + else + fprintf(stderr, "NoTitle "); + } + fprintf(stderr, ") "); + } + fprintf(stderr, "\"%s\" \"%s\" ", b->hangon, b->spawn); } - fprintf(stderr,"\"%s\" ",b->title); - } - if(b->flags&b_Icon) - fprintf(stderr,"Icon \"%s\" ",b->icon_file); - if(b->flags&b_Swallow) - { - fprintf(stderr,"Swallow "); - if(b->swallow_mask) - { - fprintf(stderr,"("); - if(b->swallow_mask&b_NoHints) { - if(b->swallow&b_NoHints) - fprintf(stderr,"NoHints "); - else - fprintf(stderr,"Hints "); - } - if(b->swallow_mask&b_Kill) { - if(b->swallow&b_Kill) - fprintf(stderr,"Kill "); - else - fprintf(stderr,"NoKill "); - } - if(b->swallow_mask&b_NoClose) { - if(b->swallow&b_NoClose) - fprintf(stderr,"NoClose "); - else - fprintf(stderr,"Close "); - } - if(b->swallow_mask&b_Respawn) { - if(b->swallow&b_Respawn) - fprintf(stderr,"Respawn "); - else - fprintf(stderr,"NoRespawn "); - } - if(b->swallow_mask&b_UseOld) { - if(b->swallow&b_UseOld) - fprintf(stderr,"UseOld "); - else - fprintf(stderr,"NoOld "); - } - if(b->swallow_mask&b_UseTitle) { - if(b->swallow&b_UseTitle) - fprintf(stderr,"UseTitle "); - else - fprintf(stderr,"NoTitle "); - } - fprintf(stderr,") "); + if (b->flags & b_Action) { + if (b->action[0]) + fprintf(stderr, "Action `%s` ", b->action[0]); + for (i = 1; i < 4; i++) + if (b->action[i]) + fprintf(stderr, "Action (Mouse %i) `%s` ", i, + b->action[i]); } - fprintf(stderr,"\"%s\" \"%s\" ",b->hangon,b->spawn); - } - if(b->flags&b_Action) - { - if(b->action[0]) - fprintf(stderr,"Action `%s` ",b->action[0]); - for(i=1;i<4;i++) - if(b->action[i]) - fprintf(stderr,"Action (Mouse %i) `%s` ",i,b->action[i]); - } - - if(b->flags&b_Container) - { - fprintf(stderr,"Container (Columns %i Rows %i ",b->c->num_columns, - b->c->num_rows); - if(b->c->flags) - { - if(b->c->flags&b_Font) - fprintf(stderr,"Font %s ",b->c->font_string); - if(b->c->flags&b_Fore) - fprintf(stderr,"Fore %s ",b->c->fore); - if(b->c->flags&b_Back) - fprintf(stderr,"Back %s ",b->c->back); - if(b->c->flags&b_Frame) - fprintf(stderr,"Frame %i ",b->c->framew); - if(b->c->flags&b_Padding) - fprintf(stderr,"Padding %i %i ",b->c->xpad,b->c->ypad); - if(b->c->flags&b_Justify) - { - fprintf(stderr,"Title ("); - switch(b->c->justify&b_TitleHoriz) - { - case 0: - fprintf(stderr,"Left"); - break; - case 1: - fprintf(stderr,"Center"); - break; - case 2: - fprintf(stderr,"Right"); - break; + if (b->flags & b_Container) { + fprintf(stderr, "Container (Columns %i Rows %i ", + b->c->num_columns, b->c->num_rows); + if (b->c->flags) { + if (b->c->flags & b_Font) + fprintf(stderr, "Font %s ", b->c->font_string); + if (b->c->flags & b_Fore) + fprintf(stderr, "Fore %s ", b->c->fore); + if (b->c->flags & b_Back) + fprintf(stderr, "Back %s ", b->c->back); + if (b->c->flags & b_Frame) + fprintf(stderr, "Frame %i ", b->c->framew); + if (b->c->flags & b_Padding) + fprintf(stderr, "Padding %i %i ", b->c->xpad, + b->c->ypad); + if (b->c->flags & b_Justify) { + fprintf(stderr, "Title ("); + switch (b->c->justify & b_TitleHoriz) { + case 0: + fprintf(stderr, "Left"); + break; + case 1: + fprintf(stderr, "Center"); + break; + case 2: + fprintf(stderr, "Right"); + break; + } + if (b->c->justify & b_Horizontal) + fprintf(stderr, ", Side"); + fprintf(stderr, ") "); + } + if (b->c->swallow_mask) { + fprintf(stderr, "Swallow ("); + if (b->c->swallow_mask & b_NoHints) { + if (b->c->swallow & b_NoHints) + fprintf(stderr, "NoHints "); + else + fprintf(stderr, "Hints "); + } + if (b->c->swallow_mask & b_Kill) { + if (b->c->swallow & b_Kill) + fprintf(stderr, "Kill "); + else + fprintf(stderr, "NoKill "); + } + if (b->c->swallow_mask & b_NoClose) { + if (b->c->swallow & b_NoClose) + fprintf(stderr, "NoClose "); + else + fprintf(stderr, "Close "); + } + if (b->c->swallow_mask & b_Respawn) { + if (b->c->swallow & b_Respawn) + fprintf(stderr, "Respawn "); + else + fprintf(stderr, "NoRespawn "); + } + if (b->c->swallow_mask & b_UseOld) { + if (b->c->swallow & b_UseOld) + fprintf(stderr, "UseOld "); + else + fprintf(stderr, "NoOld "); + } + if (b->c->swallow_mask & b_UseTitle) { + if (b->c->swallow & b_UseTitle) + fprintf(stderr, "UseTitle "); + else + fprintf(stderr, "NoTitle "); + } + fprintf(stderr, ") "); + } } - if(b->c->justify&b_Horizontal) - fprintf(stderr,", Side"); - fprintf(stderr,") "); - } - if(b->c->swallow_mask) - { - fprintf(stderr,"Swallow ("); - if(b->c->swallow_mask&b_NoHints) { - if(b->c->swallow&b_NoHints) - fprintf(stderr,"NoHints "); - else - fprintf(stderr,"Hints "); - } - if(b->c->swallow_mask&b_Kill) { - if(b->c->swallow&b_Kill) - fprintf(stderr,"Kill "); - else - fprintf(stderr,"NoKill "); - } - if(b->c->swallow_mask&b_NoClose) { - if(b->c->swallow&b_NoClose) - fprintf(stderr,"NoClose "); - else - fprintf(stderr,"Close "); - } - if(b->c->swallow_mask&b_Respawn) { - if(b->c->swallow&b_Respawn) - fprintf(stderr,"Respawn "); - else - fprintf(stderr,"NoRespawn "); - } - if(b->c->swallow_mask&b_UseOld) { - if(b->c->swallow&b_UseOld) - fprintf(stderr,"UseOld "); - else - fprintf(stderr,"NoOld "); - } - if(b->c->swallow_mask&b_UseTitle) { - if(b->c->swallow&b_UseTitle) - fprintf(stderr,"UseTitle "); - else - fprintf(stderr,"NoTitle "); - } - fprintf(stderr,") "); - } + fprintf(stderr, ")"); } - fprintf(stderr,")"); - } - fprintf(stderr,"\n"); - - if(b->flags&b_Container) - { - i=0; - while(ic->num_buttons) - SaveButtons(b->c->buttons[i++]); - fprintf(stderr,"End\n"); - } -} + fprintf(stderr, "\n"); + if (b->flags & b_Container) { + i = 0; + while (i < b->c->num_buttons) + SaveButtons(b->c->buttons[i++]); + fprintf(stderr, "End\n"); + } +} Index: fvwm/modules/FvwmButtons/parse.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmButtons/parse.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmButtons/parse.c --- fvwm/modules/FvwmButtons/parse.c +++ fvwm/modules/FvwmButtons/parse.c @@ -12,15 +12,14 @@ */ -#include "config.h" - +#include +#include #include #include #include #include -#include -#include +#include "config.h" /* #include #include @@ -30,7 +29,7 @@ #include "FvwmButtons.h" #include "button.h" -extern int w,h,x,y,xneg,yneg; /* used in ParseConfigLine */ +extern int w, h, x, y, xneg, yneg; /* used in ParseConfigLine */ extern char *config_file; /* contains the character that terminated the last string from seekright */ @@ -38,11 +37,12 @@ static char terminator = '\0'; /* ----------------------------------- macros ------------------------------ */ -char *trimleft(char *s) +char * +trimleft(char *s) { - while (s && isspace(*s)) - s++; - return s; + while (s && isspace(*s)) + s++; + return s; } /** @@ -52,358 +52,403 @@ char *trimleft(char *s) *** string and move the old pointer forward. Accepts and strips quoting with *** '," or `, and the current quote q can be escaped inside the string with \q. **/ -char *seekright(char **s) +char * +seekright(char **s) { - char *token = NULL; - char *line = *s; + char *token = NULL; + char *line = *s; - line = DoGetNextToken(line, &token, NULL, "),", &terminator); - if (*s != NULL && line == NULL) - line = strchr(*s, '\0'); - *s = line; + line = DoGetNextToken(line, &token, NULL, "),", &terminator); + if (*s != NULL && line == NULL) + line = strchr(*s, '\0'); + *s = line; + + return token; +} + +static char * +seekright_command(char **s) +{ + char *command = seekright(s); + + if (command == NULL) + return NULL; + + while (terminator != '\0' && terminator != ')' && terminator != ',') { + char *next = seekright(s); + + if (next == NULL) + break; + + size_t len_command = strlen(command); + size_t len_next = strlen(next); + char *combined = xmalloc(len_command + len_next + 2); + + memcpy(combined, command, len_command); + combined[len_command] = ' '; + memcpy(combined + len_command + 1, next, len_next + 1); + + free(command); + free(next); + command = combined; + } - return token; + return command; } /** *** ParseBack() *** Parses the options possible to Back **/ -int ParseBack(char **ss) +int +ParseBack(char **ss) { - char *opts[]={"icon",NULL}; - char *t,*s=*ss; - int r=0; - - while(*s && *s!=')') - { - s = trimleft(s); - if(*s==',') - s++; - else switch(GetTokenIndex(s,opts,-1,&s)) - { - case 0: /* Icon */ - r=1; - fprintf(stderr,"%s: Back(Icon) not supported yet\n",MyName); - break; - default: - t=seekright(&s); - fprintf(stderr,"%s: Illegal back option \"%s\"\n",MyName,(t)?t:""); - if (t) - free(t); + char *opts[] = {"icon", NULL}; + char *t, *s = *ss; + int r = 0; + + while (*s && *s != ')') { + s = trimleft(s); + if (*s == ',') + s++; + else + switch (GetTokenIndex(s, opts, -1, &s)) { + case 0: /* Icon */ + r = 1; + fprintf(stderr, + "%s: Back(Icon) not supported yet\n", + MyName); + break; + default: + t = seekright(&s); + fprintf(stderr, + "%s: Illegal back option \"%s\"\n", MyName, + (t) ? t : ""); + if (t) + free(t); + } } - } - if(*s) s++; - *ss=s; - return r; + if (*s) + s++; + *ss = s; + return r; } /** *** ParseBoxSize() *** Parses the options possible to BoxSize **/ -void ParseBoxSize(char **ss, unsigned long *flags) +void +ParseBoxSize(char **ss, unsigned long *flags) { - char *opts[]={"dumb","fixed","smart",NULL}; - char *s = *ss; - int m; - - if (!s) - return; - *ss = GetNextTokenIndex(*ss, opts, 0, &m); - switch(m) - { - case 0: - *flags &= ~(b_SizeFixed|b_SizeSmart); - break; - case 1: - *flags |= b_SizeFixed; - *flags &= ~b_SizeSmart; - break; - case 2: - *flags |= b_SizeSmart; - *flags &= ~b_SizeFixed; - break; - default: - *flags &= ~(b_SizeFixed|b_SizeSmart); - fprintf(stderr,"%s: Illegal boxsize option \"%s\"\n",MyName, s); - break; - } - return; + char *opts[] = {"dumb", "fixed", "smart", NULL}; + char *s = *ss; + int m; + + if (!s) + return; + *ss = GetNextTokenIndex(*ss, opts, 0, &m); + switch (m) { + case 0: + *flags &= ~(b_SizeFixed | b_SizeSmart); + break; + case 1: + *flags |= b_SizeFixed; + *flags &= ~b_SizeSmart; + break; + case 2: + *flags |= b_SizeSmart; + *flags &= ~b_SizeFixed; + break; + default: + *flags &= ~(b_SizeFixed | b_SizeSmart); + fprintf( + stderr, "%s: Illegal boxsize option \"%s\"\n", MyName, s); + break; + } + return; } /** *** ParseTitle() *** Parses the options possible to Title **/ -void ParseTitle(char **ss, byte *flags, byte *mask) +void +ParseTitle(char **ss, byte *flags, byte *mask) { - char *titleopts[]={"left","right","center","side",NULL}; - char *t,*s=*ss; - - while(*s && *s!=')') - { - s = trimleft(s); - if(*s==',') - s++; - else switch(GetTokenIndex(s,titleopts,-1,&s)) - { - case 0: /* Left */ - *flags&=~b_TitleHoriz; - *mask|=b_TitleHoriz; - break; - case 1: /* Right */ - *flags&=~b_TitleHoriz; - *flags|=2; - *mask|=b_TitleHoriz; - break; - case 2: /* Center */ - *flags&=~b_TitleHoriz; - *flags|=1; - *mask|=b_TitleHoriz; - break; - case 3: /* Side */ - *flags|=b_Horizontal; - *mask|=b_Horizontal; - break; - default: - t=seekright(&s); - fprintf(stderr,"%s: Illegal title option \"%s\"\n",MyName,(t)?t:""); - if (t) - free(t); + char *titleopts[] = {"left", "right", "center", "side", NULL}; + char *t, *s = *ss; + + while (*s && *s != ')') { + s = trimleft(s); + if (*s == ',') + s++; + else + switch (GetTokenIndex(s, titleopts, -1, &s)) { + case 0: /* Left */ + *flags &= ~b_TitleHoriz; + *mask |= b_TitleHoriz; + break; + case 1: /* Right */ + *flags &= ~b_TitleHoriz; + *flags |= 2; + *mask |= b_TitleHoriz; + break; + case 2: /* Center */ + *flags &= ~b_TitleHoriz; + *flags |= 1; + *mask |= b_TitleHoriz; + break; + case 3: /* Side */ + *flags |= b_Horizontal; + *mask |= b_Horizontal; + break; + default: + t = seekright(&s); + fprintf(stderr, + "%s: Illegal title option \"%s\"\n", MyName, + (t) ? t : ""); + if (t) + free(t); + } } - } - if(*s) s++; - *ss=s; + if (*s) + s++; + *ss = s; } /** *** ParseSwallow() *** Parses the options possible to Swallow **/ -void ParseSwallow(char **ss,byte *flags,byte *mask) +void +ParseSwallow(char **ss, byte *flags, byte *mask) { - char *swallowopts[]={"nohints","hints","nokill","kill","noclose","close", - "respawn","norespawn","useold", - "noold","usetitle","notitle",NULL}; - char *t,*s=*ss; - - while(*s && *s!=')') - { - s = trimleft(s); - if(*s==',') - s++; - else switch(GetTokenIndex(s,swallowopts,-1,&s)) - { - case 0: /* NoHints */ - *flags|=b_NoHints; - *mask|=b_NoHints; - break; - case 1: /* Hints */ - *flags&=~b_NoHints; - *mask|=b_NoHints; - break; - case 2: /* NoKill */ - *flags&=~b_Kill; - *mask|=b_Kill; - break; - case 3: /* Kill */ - *flags|=b_Kill; - *mask|=b_Kill; - break; - case 4: /* NoClose */ - *flags|=b_NoClose; - *mask|=b_NoClose; - break; - case 5: /* Close */ - *flags&=~b_NoClose; - *mask|=b_NoClose; - break; - case 6: /* Respawn */ - *flags|=b_Respawn; - *mask|=b_Respawn; - break; - case 7: /* NoRespawn */ - *flags&=~b_Respawn; - *mask|=b_Respawn; - break; - case 8: /* UseOld */ - *flags|=b_UseOld; - *mask|=b_UseOld; - break; - case 9: /* NoOld */ - *flags&=~b_UseOld; - *mask|=b_UseOld; - break; - case 10: /* UseTitle */ - *flags|=b_UseTitle; - *mask|=b_UseTitle; - break; - case 11: /* NoTitle */ - *flags&=~b_UseTitle; - *mask|=b_UseTitle; - break; - default: - t=seekright(&s); - fprintf(stderr,"%s: Illegal swallow option \"%s\"\n",MyName, - (t)?t:""); - if (t) - free(t); + char *swallowopts[] = {"nohints", "hints", "nokill", "kill", "noclose", + "close", "respawn", "norespawn", "useold", "noold", "usetitle", + "notitle", NULL}; + char *t, *s = *ss; + + while (*s && *s != ')') { + s = trimleft(s); + if (*s == ',') + s++; + else + switch (GetTokenIndex(s, swallowopts, -1, &s)) { + case 0: /* NoHints */ + *flags |= b_NoHints; + *mask |= b_NoHints; + break; + case 1: /* Hints */ + *flags &= ~b_NoHints; + *mask |= b_NoHints; + break; + case 2: /* NoKill */ + *flags &= ~b_Kill; + *mask |= b_Kill; + break; + case 3: /* Kill */ + *flags |= b_Kill; + *mask |= b_Kill; + break; + case 4: /* NoClose */ + *flags |= b_NoClose; + *mask |= b_NoClose; + break; + case 5: /* Close */ + *flags &= ~b_NoClose; + *mask |= b_NoClose; + break; + case 6: /* Respawn */ + *flags |= b_Respawn; + *mask |= b_Respawn; + break; + case 7: /* NoRespawn */ + *flags &= ~b_Respawn; + *mask |= b_Respawn; + break; + case 8: /* UseOld */ + *flags |= b_UseOld; + *mask |= b_UseOld; + break; + case 9: /* NoOld */ + *flags &= ~b_UseOld; + *mask |= b_UseOld; + break; + case 10: /* UseTitle */ + *flags |= b_UseTitle; + *mask |= b_UseTitle; + break; + case 11: /* NoTitle */ + *flags &= ~b_UseTitle; + *mask |= b_UseTitle; + break; + default: + t = seekright(&s); + fprintf(stderr, + "%s: Illegal swallow option \"%s\"\n", + MyName, (t) ? t : ""); + if (t) + free(t); + } } - } - if(*s) s++; - *ss=s; + if (*s) + s++; + *ss = s; } /** *** ParseContainer() *** Parses the options possible to Container **/ -void ParseContainer(char **ss,button_info *b) +void +ParseContainer(char **ss, button_info *b) { - char *conts[]={"columns","rows","font","frame","back","fore", - "padding","title","swallow","nosize","size", - "boxsize",NULL}; - char *t,*o,*s=*ss; - int i,j; - - while(*s && *s!=')') - { - s = trimleft(s); - if(*s==',') - s++; - else switch(GetTokenIndex(s,conts,-1,&s)) - { - case 0: /* Columns */ - b->c->num_columns=max(1,strtol(s,&t,10)); - s=t; - break; - case 1: /* Rows */ - b->c->num_rows=max(1,strtol(s,&t,10)); - s=t; - break; - case 2: /* Font */ - if (b->c->font_string) free(b->c->font_string); - b->c->font_string=seekright(&s); - if(b->c->font_string) - b->c->flags|=b_Font; - else - b->c->flags&=~b_Font; - break; - case 3: /* Frame */ - b->c->framew=strtol(s,&t,10); - b->c->flags|=b_Frame; - s=t; - break; - case 4: /* Back */ - s = trimleft(s); - if(*s=='(' && s++) - if(ParseBack(&s)) - b->c->flags|=b_IconBack; - if (b->c->back) free(b->c->back); - b->c->back=seekright(&s); - if(b->c->back) - b->c->flags|=b_Back; - else - b->c->flags&=~(b_IconBack|b_Back); - break; - case 5: /* Fore */ - if (b->c->fore) free(b->c->fore); - b->c->fore=seekright(&s); - if(b->c->fore) - b->c->flags|=b_Fore; - else - b->c->flags&=~b_Fore; - break; - case 6: /* Padding */ - i=strtol(s,&t,10); - if(t>s) - { - b->c->xpad=b->c->ypad=i; - s=t; - i=strtol(s,&t,10); - if(t>s) - { - b->c->ypad=i; - s=t; - } - b->c->flags|=b_Padding; - } - else - fprintf(stderr,"%s: Illegal padding argument\n",MyName); - break; - case 7: /* Title - flags */ - s = trimleft(s); - if(*s=='(' && s++) - { - b->c->justify=0; - b->c->justify_mask=0; - ParseTitle(&s,&b->c->justify,&b->c->justify_mask); - if(b->c->justify_mask) - b->c->flags|=b_Justify; - } - else - { - char *temp; - fprintf(stderr,"%s: Illegal title in container options\n", - MyName); - temp = seekright(&s); - if (temp) - free(temp); - } - break; - case 8: /* Swallow - flags */ - s = trimleft(s); - if(*s=='(' && s++) - { - b->c->swallow=0; - b->c->swallow_mask=0; - ParseSwallow(&s,&b->c->swallow,&b->c->swallow_mask); - if(b->c->swallow_mask) - b->c->flags|=b_Swallow; - } - else - { - char *temp; - fprintf(stderr,"%s: Illegal swallow in container options\n", - MyName); - temp = seekright(&s); - if (temp) - free(temp); - } - break; - case 9: /* NoSize */ - b->c->flags|=b_Size; - b->c->minx=b->c->miny=0; - break; - - case 10: /* Size */ - i=strtol(s,&t,10); - j=strtol(t,&o,10); - if(t>s && o>t) - { - b->c->minx=i; - b->c->miny=j; - b->c->flags|=b_Size; - s=o; - } - else - fprintf(stderr,"%s: Illegal size arguments\n",MyName); - break; - case 11: /* BoxSize */ - ParseBoxSize(&s, &b->c->flags); - break; - - default: - t=seekright(&s); - fprintf(stderr,"%s: Illegal container option \"%s\"\n",MyName, - (t)?t:""); - if (t) - free(t); + char *conts[] = {"columns", "rows", "font", "frame", "back", "fore", + "padding", "title", "swallow", "nosize", "size", "boxsize", NULL}; + char *t, *o, *s = *ss; + int i, j; + + while (*s && *s != ')') { + s = trimleft(s); + if (*s == ',') + s++; + else + switch (GetTokenIndex(s, conts, -1, &s)) { + case 0: /* Columns */ + b->c->num_columns = max(1, strtol(s, &t, 10)); + s = t; + break; + case 1: /* Rows */ + b->c->num_rows = max(1, strtol(s, &t, 10)); + s = t; + break; + case 2: /* Font */ + if (b->c->font_string) + free(b->c->font_string); + b->c->font_string = seekright(&s); + if (b->c->font_string) + b->c->flags |= b_Font; + else + b->c->flags &= ~b_Font; + break; + case 3: /* Frame */ + b->c->framew = strtol(s, &t, 10); + b->c->flags |= b_Frame; + s = t; + break; + case 4: /* Back */ + s = trimleft(s); + if (*s == '(' && s++) + if (ParseBack(&s)) + b->c->flags |= b_IconBack; + if (b->c->back) + free(b->c->back); + b->c->back = seekright(&s); + if (b->c->back) + b->c->flags |= b_Back; + else + b->c->flags &= ~(b_IconBack | b_Back); + break; + case 5: /* Fore */ + if (b->c->fore) + free(b->c->fore); + b->c->fore = seekright(&s); + if (b->c->fore) + b->c->flags |= b_Fore; + else + b->c->flags &= ~b_Fore; + break; + case 6: /* Padding */ + i = strtol(s, &t, 10); + if (t > s) { + b->c->xpad = b->c->ypad = i; + s = t; + i = strtol(s, &t, 10); + if (t > s) { + b->c->ypad = i; + s = t; + } + b->c->flags |= b_Padding; + } else + fprintf(stderr, + "%s: Illegal padding argument\n", + MyName); + break; + case 7: /* Title - flags */ + s = trimleft(s); + if (*s == '(' && s++) { + b->c->justify = 0; + b->c->justify_mask = 0; + ParseTitle(&s, &b->c->justify, + &b->c->justify_mask); + if (b->c->justify_mask) + b->c->flags |= b_Justify; + } else { + char *temp; + fprintf(stderr, + "%s: Illegal title in container " + "options\n", + MyName); + temp = seekright(&s); + if (temp) + free(temp); + } + break; + case 8: /* Swallow - flags */ + s = trimleft(s); + if (*s == '(' && s++) { + b->c->swallow = 0; + b->c->swallow_mask = 0; + ParseSwallow(&s, &b->c->swallow, + &b->c->swallow_mask); + if (b->c->swallow_mask) + b->c->flags |= b_Swallow; + } else { + char *temp; + fprintf(stderr, + "%s: Illegal swallow in container " + "options\n", + MyName); + temp = seekright(&s); + if (temp) + free(temp); + } + break; + case 9: /* NoSize */ + b->c->flags |= b_Size; + b->c->minx = b->c->miny = 0; + break; + + case 10: /* Size */ + i = strtol(s, &t, 10); + j = strtol(t, &o, 10); + if (t > s && o > t) { + b->c->minx = i; + b->c->miny = j; + b->c->flags |= b_Size; + s = o; + } else + fprintf(stderr, + "%s: Illegal size arguments\n", + MyName); + break; + case 11: /* BoxSize */ + ParseBoxSize(&s, &b->c->flags); + break; + + default: + t = seekright(&s); + fprintf(stderr, + "%s: Illegal container option \"%s\"\n", + MyName, (t) ? t : ""); + if (t) + free(t); + } } - } - if(*s) s++; - *ss=s; + if (*s) + s++; + *ss = s; } /** @@ -413,610 +458,635 @@ void ParseContainer(char **ss,button_info *b) *** *FvwmButtons(option[ options]) title iconname command **/ /*#define DEBUG_PARSER*/ -void match_string(button_info **uberb,char *s) +void +match_string(button_info **uberb, char *s) { - button_info *b,*ub=*uberb; - int i,j; - char *t,*o; - b=alloc_button(ub,(ub->c->num_buttons)++); - s = trimleft(s); - - if(*s=='(' && s++) - { - char *opts[]={"back","fore","font","title","icon","frame","padding", - "swallow","action","container","end","nosize","size", - "panel", "left", "right", "center", - NULL}; - s = trimleft(s); - while(*s && *s!=')') - { - if((*s>='0' && *s<='9') || *s=='+' || *s=='-') - { - char *geom; - int x,y,w,h,flags; - geom=seekright(&s); - if (geom) - { - flags=XParseGeometry(geom, &x, &y, &w, &h); - if(flags&WidthValue) - b->BWidth=w; - if(flags&HeightValue) - b->BHeight=h; - if(flags&XValue) - { - b->BPosX=x; - b->flags|=b_PosFixed; - } - if(flags&YValue) - { - b->BPosY=y; - b->flags|=b_PosFixed; - } - if(flags&XNegative) - b->BPosX=-1-x; - if(flags&YNegative) - b->BPosY=-1-y; - free(geom); - } - s = trimleft(s); - continue; - } - if(*s==',' && s++) - s = trimleft(s); - switch(GetTokenIndex(s,opts,-1,&s)) - { - case 0: /* Back */ - s = trimleft(s); - if(*s=='(' && s++) - if(ParseBack(&s)) - b->flags|=b_IconBack; - if(b->flags&b_Back && b->back) free(b->back); - b->back=seekright(&s); - if(b->back) - b->flags|=b_Back; - else - b->flags&=~(b_IconBack|b_Back); - break; - - case 1: /* Fore */ - if(b->flags&b_Fore && b->fore) free(b->fore); - b->fore=seekright(&s); - if(b->fore) - b->flags|=b_Fore; - else - b->flags&=~b_Fore; - break; - - case 2: /* Font */ - if(b->flags&b_Font && b->font_string) free(b->font_string); - b->font_string=seekright(&s); - if(b->font_string) - b->flags|=b_Font; - else - b->flags&=~b_Font; - break; - - /* --------------------------- Title ------------------------- */ - - case 3: /* Title */ - s = trimleft(s); - if(*s=='(' && s++) - { - b->justify=0; - b->justify_mask=0; - ParseTitle(&s,&b->justify,&b->justify_mask); - if(b->justify_mask) - b->flags|=b_Justify; - } - t=seekright(&s); - if(t && *t && (t[0]!='-' || t[1]!=0)) - { - if (b->title) - free(b->title); - b->title=t; + button_info *b, *ub = *uberb; + int i, j; + char *t, *o; + b = alloc_button(ub, (ub->c->num_buttons)++); + s = trimleft(s); + + if (*s == '(' && s++) { + char *opts[] = {"back", "fore", "font", "title", "icon", + "frame", "padding", "swallow", "action", "container", "end", + "nosize", "size", "panel", "left", "right", "center", NULL}; + s = trimleft(s); + while (*s && *s != ')') { + if ((*s >= '0' && *s <= '9') || *s == '+' || + *s == '-') { + char *geom; + int x, y, w, h, flags; + geom = seekright(&s); + if (geom) { + flags = XParseGeometry( + geom, &x, &y, &w, &h); + if (flags & WidthValue) + b->BWidth = w; + if (flags & HeightValue) + b->BHeight = h; + if (flags & XValue) { + b->BPosX = x; + b->flags |= b_PosFixed; + } + if (flags & YValue) { + b->BPosY = y; + b->flags |= b_PosFixed; + } + if (flags & XNegative) + b->BPosX = -1 - x; + if (flags & YNegative) + b->BPosY = -1 - y; + free(geom); + } + s = trimleft(s); + continue; + } + if (*s == ',' && s++) + s = trimleft(s); + switch (GetTokenIndex(s, opts, -1, &s)) { + case 0: /* Back */ + s = trimleft(s); + if (*s == '(' && s++) + if (ParseBack(&s)) + b->flags |= b_IconBack; + if (b->flags & b_Back && b->back) + free(b->back); + b->back = seekright(&s); + if (b->back) + b->flags |= b_Back; + else + b->flags &= ~(b_IconBack | b_Back); + break; + + case 1: /* Fore */ + if (b->flags & b_Fore && b->fore) + free(b->fore); + b->fore = seekright(&s); + if (b->fore) + b->flags |= b_Fore; + else + b->flags &= ~b_Fore; + break; + + case 2: /* Font */ + if (b->flags & b_Font && b->font_string) + free(b->font_string); + b->font_string = seekright(&s); + if (b->font_string) + b->flags |= b_Font; + else + b->flags &= ~b_Font; + break; + + /* --------------------------- Title + * ------------------------- */ + + case 3: /* Title */ + s = trimleft(s); + if (*s == '(' && s++) { + b->justify = 0; + b->justify_mask = 0; + ParseTitle( + &s, &b->justify, &b->justify_mask); + if (b->justify_mask) + b->flags |= b_Justify; + } + t = seekright(&s); + if (t && *t && (t[0] != '-' || t[1] != 0)) { + if (b->title) + free(b->title); + b->title = t; #ifdef DEBUG_PARSER - fprintf(stderr,"PARSE: Title \"%s\"\n",b->title); + fprintf(stderr, "PARSE: Title \"%s\"\n", + b->title); #endif - b->flags|=b_Title; - } - else - { - fprintf(stderr,"%s: Missing title argument\n",MyName); - if(t)free(t); + b->flags |= b_Title; + } else { + fprintf(stderr, + "%s: Missing title argument\n", + MyName); + if (t) + free(t); + } + break; + + /* ---------------------------- icon + * ------------------------- */ + + case 4: /* Icon */ + t = seekright(&s); + if (t && *t && (t[0] != '-' || t[1] != 0)) { + if (b->icon_file) + free(b->icon_file); + b->icon_file = t; + b->IconWin = None; + b->flags |= b_Icon; + } else { + fprintf(stderr, + "%s: Missing icon argument\n", + MyName); + if (t) + free(t); + } + break; + + /* --------------------------- frame + * ------------------------- */ + + case 5: /* Frame */ + i = strtol(s, &t, 10); + if (t > s) { + b->flags |= b_Frame; + b->framew = i; + s = t; + } else + fprintf(stderr, + "%s: Illegal frame argument\n", + MyName); + break; + + /* -------------------------- padding + * ------------------------ */ + + case 6: /* Padding */ + i = strtol(s, &t, 10); + if (t > s) { + b->xpad = b->ypad = i; + b->flags |= b_Padding; + s = t; + i = strtol(s, &t, 10); + if (t > s) { + b->ypad = i; + s = t; + } + } else + fprintf(stderr, + "%s: Illegal padding argument\n", + MyName); + break; + + /* -------------------------- swallow + * ------------------------ */ + + case 7: /* Swallow */ + s = trimleft(s); + b->swallow = 0; + b->swallow_mask = 0; + if (*s == '(' && s++) + ParseSwallow( + &s, &b->swallow, &b->swallow_mask); + t = seekright(&s); + o = seekright_command(&s); + if (t) { + if (b->hangon) + free(b->hangon); + b->hangon = t; + b->flags |= b_Hangon; + b->flags |= b_Swallow; + b->swallow |= 1; + if (!(b->swallow & b_NoHints)) + b->hints = + (XSizeHints *)xmalloc( + sizeof(XSizeHints)); + if (o) { + if (!(buttonSwallow(b) & + b_UseOld)) + SendText(fd, o, 0); + if (b->spawn) + free(b->spawn); + b->spawn = + o; /* Might be needed if + respawning sometime */ + } + } else { + fprintf(stderr, + "%s: Missing swallow argument\n", + MyName); + if (t) + free(t); + if (o) + free(o); + } + break; + + /* --------------------------- action + * ------------------------ */ + + case 8: /* Action */ + s = trimleft(s); + i = 0; + if (*s == '(') { + s++; + if (strncasecmp(s, "mouse", 5) != 0) { + fprintf(stderr, + "%s: Couldn't parse " + "action\n", + MyName); + } + s += 5; + i = strtol(s, &t, 10); + s = t; + while (*s && *s != ')') + s++; + if (*s == ')') + s++; + } + s = GetQuotedString( + s, &t, ",)", NULL, NULL, NULL); + if (t) { + AddButtonAction(b, i, t); + free(t); + } else + fprintf(stderr, + "%s: Missing action argument\n", + MyName); + break; + + /* -------------------------- container + * ---------------------- */ + + case 9: /* Container */ + b->flags &= b_Frame | b_Back | b_Fore | + b_Padding | b_Action; + MakeContainer(b); + *uberb = b; + s = trimleft(s); + if (*s == '(' && s++) + ParseContainer(&s, b); + break; + + case 10: /* End */ + *uberb = ub->parent; + ub->c->buttons[--(ub->c->num_buttons)] = NULL; + if (!ub->parent) { + fprintf(stderr, + "%s: Unmatched END in config " + "file\n", + MyName); + exit(1); + } + break; + + case 11: /* NoSize */ + b->flags |= b_Size; + b->minx = b->miny = 0; + break; + + case 12: /* Size */ + i = strtol(s, &t, 10); + j = strtol(t, &o, 10); + if (t > s && o > t) { + b->minx = i; + b->miny = j; + b->flags |= b_Size; + s = o; + } else + fprintf(stderr, + "%s: Illegal size arguments\n", + MyName); + break; + + /* --------------------------- panel + * ------------------------ */ + + case 13: /* Panel */ + s = trimleft(s); + if (*s == '(') { + s++; + t = seekright(&s); + if (terminator != ')') + while (*s && *s != ')') + s++; + if (*s == ')') + s++; + if (strncasecmp(t, "right", 5) == 0) + t = "panel-r"; + else if (strncasecmp(t, "left", 4) == 0) + t = "panel-l"; + else if (strncasecmp(t, "down", 4) == 0) + t = "panel-d"; + else if (strncasecmp( + t, "geometry", 8) == 0) + t = "panel-g"; + else + t = "panel-u"; + } else + t = "panel-u"; + AddButtonAction(b, 0, t); + + b->IconWin = None; + t = seekright(&s); + b->hangon = + (t) ? t : + strdup(""); /* which panel to popup */ + break; + + case 14: /* Left */ + b->flags |= b_Left; + b->flags &= ~b_Right; + break; + + case 15: /* Right */ + b->flags |= b_Right; + b->flags &= ~b_Left; + break; + + case 16: /* Center */ + b->flags &= ~(b_Right | b_Left); + break; + + default: + t = seekright(&s); + fprintf(stderr, + "%s: Illegal button option \"%s\"\n", + MyName, (t) ? t : ""); + if (t) + free(t); + break; + } + s = trimleft(s); } - break; - - /* ---------------------------- icon ------------------------- */ - - case 4: /* Icon */ - t=seekright(&s); - if(t && *t && (t[0] != '-' || t[1] != 0)) - { - if (b->icon_file) - free(b->icon_file); - b->icon_file=t; - b->IconWin=None; - b->flags|=b_Icon; + if (s && *s) { + s++; + s = trimleft(s); } - else - { - fprintf(stderr,"%s: Missing icon argument\n",MyName); - if(t)free(t); - } - break; + } - /* --------------------------- frame ------------------------- */ + /* get title and iconname */ + if (!(b->flags & b_Title)) { + b->title = seekright(&s); + if (b->title && *b->title && + ((b->title)[0] != '-' || (b->title)[1] != 0)) + b->flags |= b_Title; + else if (b->title) + free(b->title); + } else { + char *temp; + temp = seekright(&s); + if (temp) + free(temp); + } - case 5: /* Frame */ - i=strtol(s,&t,10); - if(t>s) - { - b->flags|=b_Frame; - b->framew=i; - s=t; - } - else - fprintf(stderr,"%s: Illegal frame argument\n",MyName); - break; - - /* -------------------------- padding ------------------------ */ - - case 6: /* Padding */ - i=strtol(s,&t,10); - if(t>s) - { - b->xpad=b->ypad=i; - b->flags |= b_Padding; - s=t; - i=strtol(s,&t,10); - if(t>s) - { - b->ypad=i; - s=t; - } - } - else - fprintf(stderr,"%s: Illegal padding argument\n",MyName); - break; - - /* -------------------------- swallow ------------------------ */ - - case 7: /* Swallow */ - s = trimleft(s); - b->swallow=0; - b->swallow_mask=0; - if(*s=='(' && s++) - ParseSwallow(&s,&b->swallow,&b->swallow_mask); - t=seekright(&s); - o=seekright(&s); - if(t) - { - if (b->hangon) - free(b->hangon); - b->hangon=t; - b->flags|=b_Hangon; - b->flags|=b_Swallow; - b->swallow|=1; - if(!(b->swallow&b_NoHints)) - b->hints=(XSizeHints*)mymalloc(sizeof(XSizeHints)); - if(o) - { - if(!(buttonSwallow(b)&b_UseOld)) - SendText(fd,o,0); - if (b->spawn) - free(b->spawn); - b->spawn=o; /* Might be needed if respawning sometime */ - } - } - else - { - fprintf(stderr,"%s: Missing swallow argument\n",MyName); - if(t)free(t); - if(o)free(o); - } - break; - - /* --------------------------- action ------------------------ */ - - case 8: /* Action */ - s = trimleft(s); - i=0; - if(*s=='(') - { - s++; - if(strncasecmp(s,"mouse",5)!=0) - { - fprintf(stderr,"%s: Couldn't parse action\n",MyName); - } - s+=5; - i=strtol(s,&t,10); - s=t; - while(*s && *s!=')') - s++; - if(*s==')')s++; - } - s = GetQuotedString(s, &t, ",)", NULL, NULL, NULL); - if(t) - { - AddButtonAction(b,i,t); - free(t); + if (!(b->flags & b_Icon)) { + b->icon_file = seekright(&s); + if (b->icon_file && b->icon_file && + ((b->icon_file)[0] != '-' || (b->icon_file)[1] != 0)) { + b->flags |= b_Icon; + b->IconWin = None; + } else if (b->icon_file) + free(b->icon_file); + } else { + char *temp; + temp = seekright(&s); + if (temp) + free(temp); + } + + s = trimleft(s); + + /* Swallow hangon command */ + if (strncasecmp(s, "swallow", 7) == 0) { + if (b->flags & b_Swallow) { + fprintf(stderr, + "%s: Illegal with both old and new swallow!\n", + MyName); + exit(1); } - else - fprintf(stderr,"%s: Missing action argument\n",MyName); - break; - - /* -------------------------- container ---------------------- */ - - case 9: /* Container */ - b->flags&=b_Frame|b_Back|b_Fore|b_Padding|b_Action; - MakeContainer(b); - *uberb=b; - s = trimleft(s); - if(*s=='(' && s++) - ParseContainer(&s,b); - break; - - case 10: /* End */ - *uberb=ub->parent; - ub->c->buttons[--(ub->c->num_buttons)]=NULL; - if(!ub->parent) - { - fprintf(stderr,"%s: Unmatched END in config file\n",MyName); - exit(1); + s += 7; + /* + * Swallow old 'swallowmodule' command + */ + if (strncasecmp(s, "module", 6) == 0) { + s += 6; } - break; - - case 11: /* NoSize */ - b->flags|=b_Size; - b->minx=b->miny=0; - break; - - case 12: /* Size */ - i=strtol(s,&t,10); - j=strtol(t,&o,10); - if(t>s && o>t) - { - b->minx=i; - b->miny=j; - b->flags|=b_Size; - s=o; + if (b->hangon) + free(b->hangon); + b->hangon = seekright(&s); + if (!b->hangon) + b->hangon = strdup(""); + b->flags |= (b_Swallow | b_Hangon); + b->swallow |= 1; + s = trimleft(s); + if (!(b->swallow & b_NoHints)) + b->hints = (XSizeHints *)xmalloc(sizeof(XSizeHints)); + if (*s) { + if (!(buttonSwallow(b) & b_UseOld)) + SendText(fd, s, 0); + b->spawn = strdup(s); } - else - fprintf(stderr,"%s: Illegal size arguments\n",MyName); - break; - - /* --------------------------- panel ------------------------ */ - - case 13: /* Panel */ - s = trimleft(s); - if(*s=='(') - { - s++; - t = seekright(&s); - if (terminator != ')') - while(*s && *s!=')') - s++; - if(*s==')') - s++; - if (strncasecmp(t,"right",5)==0) - t = "panel-r"; - else if (strncasecmp(t,"left" ,4)==0) - t = "panel-l"; - else if (strncasecmp(t,"down" ,4)==0) - t = "panel-d"; - else if (strncasecmp(t,"geometry",8)==0) - t = "panel-g"; - else - t = "panel-u"; - } - else - t = "panel-u"; - AddButtonAction(b, 0, t); - - b->IconWin = None; - t = seekright(&s); - b->hangon = (t)? t : strdup(""); /* which panel to popup */ - break; - - case 14: /* Left */ - b->flags |= b_Left; - b->flags &= ~b_Right; - break; - - case 15: /* Right */ - b->flags |= b_Right; - b->flags &= ~b_Left; - break; - - case 16: /* Center */ - b->flags &= ~(b_Right|b_Left); - break; - - default: - t=seekright(&s); - fprintf(stderr,"%s: Illegal button option \"%s\"\n",MyName, - (t)?t:""); - if (t) - free(t); - break; - } - s = trimleft(s); - } - if (s && *s) - { - s++; - s = trimleft(s); - } - } - - /* get title and iconname */ - if(!(b->flags&b_Title)) - { - b->title=seekright(&s); - if(b->title && *b->title && ((b->title)[0]!='-'||(b->title)[1]!=0)) - b->flags |= b_Title; - else - if(b->title)free(b->title); - } - else - { - char *temp; - temp = seekright(&s); - if (temp) - free(temp); - } - - if(!(b->flags&b_Icon)) - { - b->icon_file=seekright(&s); - if(b->icon_file && b->icon_file && - ((b->icon_file)[0]!='-'||(b->icon_file)[1]!=0)) - { - b->flags|=b_Icon; - b->IconWin=None; - } - else - if(b->icon_file)free(b->icon_file); - } - else - { - char *temp; - temp = seekright(&s); - if (temp) - free(temp); - } - - s = trimleft(s); - - /* Swallow hangon command */ - if(strncasecmp(s,"swallow",7)==0) - { - if(b->flags&b_Swallow) - { - fprintf(stderr,"%s: Illegal with both old and new swallow!\n", - MyName); - exit(1); - } - s+=7; - /* - * Swallow old 'swallowmodule' command - */ - if (strncasecmp(s,"module",6)==0) - { - s+=6; - } - if (b->hangon) - free(b->hangon); - b->hangon=seekright(&s); - if (!b->hangon) - b->hangon = strdup(""); - b->flags|=(b_Swallow|b_Hangon); - b->swallow|=1; - s = trimleft(s); - if(!(b->swallow&b_NoHints)) - b->hints=(XSizeHints*)mymalloc(sizeof(XSizeHints)); - if(*s) - { - if(!(buttonSwallow(b)&b_UseOld)) - SendText(fd,s,0); - b->spawn=strdup(s); - } - } - else if(*s) - AddButtonAction(b,0,s); - return; + } else if (*s) + AddButtonAction(b, 0, s); + return; } /** *** ParseConfigLine **/ -void ParseConfigLine(button_info **ubb,char *s) +void +ParseConfigLine(button_info **ubb, char *s) { - button_info *ub=*ubb; - char *opts[]={"geometry","font","padding","columns","rows","back","fore", - "frame","file","pixmap","panel","boxsize",NULL}; - int i,j,k; - - switch(GetTokenIndex(s,opts,-1,&s)) - { - case 0:/* Geometry */ - { - char geom[64]; - int flags,g_x,g_y; - unsigned int width,height; - i=sscanf(s,"%63s",geom); - if(i==1) - { - flags=XParseGeometry(geom,&g_x,&g_y,&width,&height); - UberButton->w = 0; - UberButton->h = 0; - if(flags&WidthValue) - w=width; - if(flags&HeightValue) - h=height; - if(flags&XValue) - UberButton->x = g_x; - if(flags&YValue) - UberButton->y = g_y; - if(flags&XNegative) - UberButton->w = 1; - if(flags&YNegative) - UberButton->h = 1; - } - break; - } - case 1:/* Font */ - CopyString(&ub->c->font_string,s); - break; - case 2:/* Padding */ - i=sscanf(s,"%d %d",&j,&k); - if(i>0) ub->c->xpad=ub->c->ypad=j; - if(i>1) ub->c->ypad=k; - break; - case 3:/* Columns */ - i=sscanf(s,"%d",&j); - if(i>0) ub->c->num_columns=j; - break; - case 4:/* Rows */ - i=sscanf(s,"%d",&j); - if(i>0) ub->c->num_rows=j; - break; - case 5:/* Back */ - CopyString(&(ub->c->back),s); - break; - case 6:/* Fore */ - CopyString(&(ub->c->fore),s); - break; - case 7:/* Frame */ - i=sscanf(s,"%d",&j); - if(i>0) ub->c->framew=j; - break; - case 8:/* File */ - s = trimleft(s); - if (config_file) - free(config_file); - config_file=seekright(&s); - break; - case 9:/* Pixmap */ - s = trimleft(s); - if (strncasecmp(s,"none",4)==0) - ub->c->flags|=b_TransBack; - else - CopyString(&(ub->c->back_file),s); - ub->c->flags|=b_IconBack; - break; - case 10:/* Panel */ - s = trimleft(s); - CurrentPanel->next = (panel_info *) mymalloc(sizeof(panel_info)); - CurrentPanel = CurrentPanel->next; - CurrentPanel->next = NULL; - CurrentPanel->uber = UberButton - = (button_info *) mymalloc(sizeof(button_info)); - if (UberButton->title) - free(UberButton->title); - UberButton->title = seekright(&s); - UberButton->flags = 0; - UberButton->parent = NULL; - UberButton->BWidth = 1; - UberButton->BHeight = 1; - UberButton->swallow = 0; /* subpanel is hidden initially */ - MakeContainer(UberButton); - ub = *ubb = UberButton; - break; - case 11: /* BoxSize */ - ParseBoxSize(&s, &ub->c->flags); - break; - default: - s = trimleft(s); - match_string(ubb,s); - break; - } + button_info *ub = *ubb; + char *opts[] = {"geometry", "font", "padding", "columns", "rows", + "back", "fore", "frame", "file", "pixmap", "panel", "boxsize", + NULL}; + int i, j, k; + + switch (GetTokenIndex(s, opts, -1, &s)) { + case 0: /* Geometry */ { + char geom[64]; + int flags, g_x, g_y; + unsigned int width, height; + i = sscanf(s, "%63s", geom); + if (i == 1) { + flags = + XParseGeometry(geom, &g_x, &g_y, &width, &height); + w = -1; + h = -1; + CurrentPanel->geom_w = -1; + CurrentPanel->geom_h = -1; + UberButton->w = 0; + UberButton->h = 0; + UberButton->x = -30000; + UberButton->y = -30000; + if (flags & WidthValue) { + w = (int)width; + CurrentPanel->geom_w = (int)width; + } + if (flags & HeightValue) { + h = (int)height; + CurrentPanel->geom_h = (int)height; + } + if (flags & XValue) + UberButton->x = g_x; + if (flags & YValue) + UberButton->y = g_y; + if (flags & XNegative) + UberButton->w = 1; + if (flags & YNegative) + UberButton->h = 1; + } + break; + } + case 1: /* Font */ + CopyString(&ub->c->font_string, s); + break; + case 2: /* Padding */ + i = sscanf(s, "%d %d", &j, &k); + if (i > 0) + ub->c->xpad = ub->c->ypad = j; + if (i > 1) + ub->c->ypad = k; + break; + case 3: /* Columns */ + i = sscanf(s, "%d", &j); + if (i > 0) + ub->c->num_columns = j; + break; + case 4: /* Rows */ + i = sscanf(s, "%d", &j); + if (i > 0) + ub->c->num_rows = j; + break; + case 5: /* Back */ + CopyString(&(ub->c->back), s); + break; + case 6: /* Fore */ + CopyString(&(ub->c->fore), s); + break; + case 7: /* Frame */ + i = sscanf(s, "%d", &j); + if (i > 0) + ub->c->framew = j; + break; + case 8: /* File */ + s = trimleft(s); + if (config_file) + free(config_file); + config_file = seekright(&s); + break; + case 9: /* Pixmap */ + s = trimleft(s); + if (strncasecmp(s, "none", 4) == 0) + ub->c->flags |= b_TransBack; + else + CopyString(&(ub->c->back_file), s); + ub->c->flags |= b_IconBack; + break; + case 10: /* Panel */ + s = trimleft(s); + CurrentPanel->next = (panel_info *)xmalloc(sizeof(panel_info)); + CurrentPanel = CurrentPanel->next; + memset(CurrentPanel, 0, sizeof(panel_info)); + CurrentPanel->geom_w = -1; + CurrentPanel->geom_h = -1; + CurrentPanel->next = NULL; + CurrentPanel->uber = UberButton = + (button_info *)xmalloc(sizeof(button_info)); + memset(UberButton, 0, sizeof(button_info)); + UberButton->title = seekright(&s); + UberButton->flags = 0; + UberButton->parent = NULL; + UberButton->BWidth = 1; + UberButton->BHeight = 1; + UberButton->swallow = 0; /* subpanel is hidden initially */ + UberButton->x = -30000; + UberButton->y = -30000; + MakeContainer(UberButton); + ub = *ubb = UberButton; + break; + case 11: /* BoxSize */ + ParseBoxSize(&s, &ub->c->flags); + break; + default: + s = trimleft(s); + match_string(ubb, s); + break; + } } /** *** ParseConfigFile() *** Parses optional separate configuration file for FvwmButtons **/ -void ParseConfigFile(button_info *ub) +void +ParseConfigFile(button_info *ub) { - char s[1024],*t; - FILE *f=fopen(config_file,"r"); - int l; - if(!f) - { - fprintf(stderr,"%s: Couldn't open config file %s\n",MyName,config_file); - return; - } - - while (fgets(s, 1023, f)) - { - /* Allow for line continuation: */ - while ((l=strlen(s)) < sizeof(s) - && l>=2 && s[l-1]=='\n' && s[l-2]=='\\') - fgets(s+l-2, sizeof(s)-l, f); - - /* And comments: */ - t=s; - while(*t) - { - if(*t=='#' && (t==s || *(t-1)!='\\')) - { - *t=0; - break; - } - t++; + char s[1024], *t; + FILE *f = fopen(config_file, "r"); + int l; + if (!f) { + fprintf(stderr, "%s: Couldn't open config file %s\n", MyName, + config_file); + return; } - t = s; - t = trimleft(t); - if(*t) - ParseConfigLine(&ub,t); - } - fclose(f); + while (fgets(s, 1023, f)) { + /* Allow for line continuation: */ + while ((l = strlen(s)) < sizeof(s) && l >= 2 && + s[l - 1] == '\n' && s[l - 2] == '\\') + fgets(s + l - 2, sizeof(s) - l, f); + + /* And comments: */ + t = s; + while (*t) { + if (*t == '#' && (t == s || *(t - 1) != '\\')) { + *t = 0; + break; + } + t++; + } + t = s; + t = trimleft(t); + if (*t) + ParseConfigLine(&ub, t); + } + + fclose(f); } -extern int save_color_limit; /* global for xpm color limiting */ +extern int save_color_limit; /* global for xpm color limiting */ /** *** ParseOptions() **/ -void ParseOptions(button_info *ub) +void +ParseOptions(button_info *ub) { - char *s; - char *items[]={"iconpath","pixmappath","colorlimit",NULL,NULL}; - - items[3]=mymalloc(strlen(MyName)+2); - sprintf(items[3],"*%s",MyName); - - GetConfigLine(fd,&s); - while(s && s[0]) - { - switch(GetTokenIndex(s,items,-1,&s)) - { - case -1: - break; - case 0: - if (iconPath) - free(iconPath); - CopyString(&iconPath,s); - break; - case 1: - if (pixmapPath) - free(pixmapPath); - CopyString(&pixmapPath,s); - break; - case 2: /* colorlimit */ - sscanf(s,"%d",&save_color_limit); - break; - case 3: - if(s && s[0] && !config_file) - ParseConfigLine(&ub,s); + char *s; + char *items[] = {"iconpath", "pixmappath", "colorlimit", NULL, NULL}; + + size_t name_len = strlen(MyName); + items[3] = xmalloc(name_len + 2); + snprintf(items[3], name_len + 2, "*%s", MyName); + + GetConfigLine(fd, &s); + while (s && s[0]) { + switch (GetTokenIndex(s, items, -1, &s)) { + case -1: + break; + case 0: + if (iconPath) + free(iconPath); + CopyString(&iconPath, s); + break; + case 1: + if (pixmapPath) + free(pixmapPath); + CopyString(&pixmapPath, s); + break; + case 2: /* colorlimit */ + sscanf(s, "%d", &save_color_limit); + break; + case 3: + if (s && s[0] && !config_file) + ParseConfigLine(&ub, s); + } + GetConfigLine(fd, &s); } - GetConfigLine(fd,&s); - } - if(config_file) - ParseConfigFile(ub); + if (config_file) + ParseConfigFile(ub); - free(items[3]); - return; + free(items[3]); + return; } Index: fvwm/modules/FvwmButtons/parse.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmButtons/parse.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmButtons/parse.h --- fvwm/modules/FvwmButtons/parse.h +++ fvwm/modules/FvwmButtons/parse.h @@ -12,6 +12,4 @@ */ -void ParseOptions(button_info*); - - +void ParseOptions(button_info *); Index: fvwm/modules/FvwmCpp/FvwmCpp.1 =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmCpp/FvwmCpp.1,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmCpp/FvwmCpp.1 --- fvwm/modules/FvwmCpp/FvwmCpp.1 +++ fvwm/modules/FvwmCpp/FvwmCpp.1 @@ -14,52 +14,43 @@ .if n .sp 1 .if t .sp .5 .. -.TH FvwmCpp 1 12/12/94 2.0 +.TH FVWMCPP 1 "December 12, 1994" "2.0" "FVWM Modules" .UC .SH NAME FvwmCpp \- the FVWM Cpp pre-processor .SH SYNOPSIS FvwmCpp is spawned by fvwm, so no command line invocation will work. - .SH DESCRIPTION When called, this module will attempt to have /usr/lib/cpp pre-process the file specified in its invocation, and then have fvwm read the resulting file. - .SH INVOCATION FvwmCpp can be invoked by inserting the line 'FvwmCpp' in the .fvwmrc file. It can also be called from a menu or mouse binding. If the user wants his entire .fvwmrc file pre-processed with FvwmCpp, then fvwm should be invoked as: - .EX fvwm2 -cmd "FvwmCpp .fvwmrc" .EE - +.PP Some options can be specified on the command line: .TP -cppopt \fIoption\fP Lets you pass an option to the cpp program. Not really needed as any unknown options will be passed on automatically. - .TP -cppprog \fIname\fP Instead of invoking "/usr/lib/cpp", fvwm will invoke \fIname\fP. - .TP -outfile \fIfilename\fP Instead of creating a random unique name for the temporary file for the preprocessed rc file, this option will let you specify the name of the temporary file it will create. - .IP -debug -Causes the temporary file create by Cpp to -be retained. This file is usually called "/tmp/fvwmrcXXXXXXXXXX" - - +Causes the temporary file created by Cpp to be retained. This file is usually +called "/tmp/fvwmrcXXXXXXXXXX". .SH CONFIGURATION OPTIONS FvwmCpp defines some values for use in the pre-processor file: - .IP TWM_TYPE Always set to "fvwm". .IP SERVERHOST @@ -104,9 +95,7 @@ configure.h at compile time. .IP FVWM_MODULEDIR The directory where fvwm looks for .fvwmrc and modules by default, as determined at compile time. - .SH EXAMPLE PROLOG - .EX #define TWM_TYPE fvwm #define SERVERHOST spx20 @@ -126,17 +115,11 @@ determined at compile time. #define PLANES 8 #define BITS_PER_RGB 8 #define CLASS PseudoColor -#define COLOR Yes #define FVWM_VERSION 2.0 pl 1 #define OPTIONS SHAPE XPM Cpp #define FVWM_MODULEDIR /local/homes/dsp/nation/modules - .EE - .SH BUGS -Module configurations do not become active until fvwm2 has restarted -if you use FvwmCpp on startup. FvwmCpp creates a temporary file -and passes this to fvwm2, so you would have to edit this file too. There are some problems with comments in your .fvwmrc file. The comment sign # is misinterpreted by the preprocessor. This has usually no impact on functionality but generates @@ -161,7 +144,6 @@ and not .EX "Exec "ls" -l" (one word). .EE - .SH AUTHOR FvwmCpp is the result of a random bit mutation on a hard disk, -presumably a result of a cosmic-ray or some such thing. +presumably a result of a cosmic-ray or some such thing. Index: fvwm/modules/FvwmCpp/FvwmCpp.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmCpp/FvwmCpp.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmCpp/FvwmCpp.c --- fvwm/modules/FvwmCpp/FvwmCpp.c +++ fvwm/modules/FvwmCpp/FvwmCpp.c @@ -3,45 +3,44 @@ * by Robert Nation * * Copyright 1994, Robert Nation - * No guarantees or warantees or anything + * No guarantees or warantees or anything * are provided or implied in any way whatsoever. Use this program at your * own risk. Permission to use this program for any purpose is given, * as long as the copyright is kept intact. */ #define TRUE 1 -#define FALSE 0 +#define FALSE 0 -#include "config.h" +#include "FvwmCpp.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include -#include #include -#include +#include +#include +#include +#include +#include +#include +#include #include -#include #include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "../../fvwm/module.h" - -#include "FvwmCpp.h" #include "../../libs/fvwmlib.h" -#include -#include -#include -#define Resolution(pixels, mm) ((((pixels) * 100000 / (mm)) + 50) / 100) +#include "config.h" +#include "../../fvwm/fvwm_sandbox.h" +#define Resolution(pixels, mm) ((((pixels) * 100000 / (mm)) + 50) / 100) char *MyName; int fd[2]; @@ -52,16 +51,18 @@ int ScreenWidth, ScreenHeight; int Mscreen; long Vx, Vy; -static char *MkDef(char *name, char *def); -static char *MkNum(char *name,int def); -static char *cpp_defs(Display *display, const char *host, char *m4_options, char *config_file); +static char *MkDef(const char *name, const char *def); +static char *MkNum(const char *name, int def); +static int cpp_process(Display *display, const char *host, char *options, + const char *config_file, int keep_output); +static int is_cpp_linemarker(const char *line); #define MAXHOSTNAME 255 #define EXTRA 20 -char *cpp_prog = FVWM_CPP; /* Name of the cpp program */ +char *cpp_prog = FVWM_CPP; /* Name of the cpp program */ char cpp_options[BUFSIZ]; -char cpp_outfile[BUFSIZ]=""; +char cpp_outfile[BUFSIZ] = ""; /*********************************************************************** * @@ -70,294 +71,433 @@ char cpp_outfile[BUFSIZ]=""; * main - start of module * ***********************************************************************/ -int main(int argc, char **argv) +int +main(int argc, char **argv) { - Display *dpy; /* which display are we talking to */ - char *temp, *s; - char *display_name = NULL; - char *filename = NULL; - char *tmp_file, read_string[80],delete_string[80]; - int i,cpp_debug = 0; - - strcpy(cpp_options,""); - - /* Record the program name for error messages */ - temp = argv[0]; - - s=strrchr(argv[0], '/'); - if (s != NULL) - temp = s + 1; - - MyName = safemalloc(strlen(temp)+2); - strcpy(MyName,"*"); - strcat(MyName, temp); - - if(argc < 6) - { - fprintf(stderr,"%s Version %s should only be executed by fvwm!\n",MyName, - VERSION); - exit(1); - } - - /* Open the X display */ - if (!(dpy = XOpenDisplay(display_name))) - { - fprintf(stderr,"%s: can't open display %s", MyName, - XDisplayName(display_name)); - exit (1); - } - - - Mscreen= DefaultScreen(dpy); - ScreenHeight = DisplayHeight(dpy,Mscreen); - ScreenWidth = DisplayWidth(dpy,Mscreen); - - /* We should exit if our fvwm pipes die */ - signal (SIGPIPE, DeadPipe); - - fd[0] = atoi(argv[1]); - fd[1] = atoi(argv[2]); - - for(i=6;i", sizeof(options)); - strlcat(options, tmp_name, sizeof(options)); - - tmpf = popen(options, "w"); - if (tmpf == NULL) { - perror("Cannot open pipe to cpp"); - exit(0377); - } - - gethostname(client,MAXHOSTNAME); - - getostype (ostype, sizeof ostype); - - hostname = gethostbyname(client); - strlcpy(server, XDisplayName(host), sizeof(server)); - colon = strchr(server, ':'); - if (colon != NULL) *colon = '\0'; - if ((server[0] == '\0') || (!strcmp(server, "unix"))) - strlcpy(server, client, sizeof(server)); /* must be connected to :0 or unix:0 */ - - /* TWM_TYPE is fvwm, for completeness */ - - fputs(MkDef("TWM_TYPE", "fvwm"), tmpf); - - /* The machine running the X server */ - fputs(MkDef("SERVERHOST", server), tmpf); - /* The machine running the window manager process */ - fputs(MkDef("CLIENTHOST", client), tmpf); - if (hostname) - fputs(MkDef("HOSTNAME", (char *)hostname->h_name), tmpf); - else - fputs(MkDef("HOSTNAME", (char *)client), tmpf); - - fputs(MkDef("OSTYPE", ostype), tmpf); - - pwent=getpwuid(geteuid()); - fputs(MkDef("USER", pwent->pw_name), tmpf); - - fputs(MkDef("HOME", getenv("HOME")), tmpf); - fputs(MkNum("VERSION", ProtocolVersion(display)), tmpf); - fputs(MkNum("REVISION", ProtocolRevision(display)), tmpf); - fputs(MkDef("VENDOR", ServerVendor(display)), tmpf); - fputs(MkNum("RELEASE", VendorRelease(display)), tmpf); - screen = ScreenOfDisplay(display, Mscreen); - visual = DefaultVisualOfScreen(screen); - fputs(MkNum("WIDTH", DisplayWidth(display,Mscreen)), tmpf); - fputs(MkNum("HEIGHT", DisplayHeight(display,Mscreen)), tmpf); - - fputs(MkNum("X_RESOLUTION",Resolution(screen->width,screen->mwidth)),tmpf); - fputs(MkNum("Y_RESOLUTION",Resolution(screen->height,screen->mheight)),tmpf); - fputs(MkNum("PLANES",DisplayPlanes(display, Mscreen)), tmpf); - - fputs(MkNum("BITS_PER_RGB", visual->bits_per_rgb), tmpf); - fputs(MkNum("SCREEN", Mscreen), tmpf); - - switch(visual->class) - { - case(StaticGray): - vc = "StaticGray"; - break; - case(GrayScale): - vc = "GrayScale"; - break; - case(StaticColor): - vc = "StaticColor"; - break; - case(PseudoColor): - vc = "PseudoColor"; - break; - case(TrueColor): - vc = "TrueColor"; - break; - case(DirectColor): - vc = "DirectColor"; - break; - default: - vc = "NonStandard"; - break; - } - - fputs(MkDef("CLASS", vc), tmpf); - if (visual->class != StaticGray && visual->class != GrayScale) - fputs(MkDef("COLOR", "Yes"), tmpf); - else - fputs(MkDef("COLOR", "No"), tmpf); - fputs(MkDef("FVWM_VERSION", VERSION), tmpf); - - /* Add options together */ - *options = '\0'; -#ifdef SHAPE - strcat(options, "SHAPE "); -#endif -#ifdef XPM - strcat(options, "XPM "); -#endif + Screen *screen; + Visual *visual; + char client[MAXHOSTNAME], server[MAXHOSTNAME], *colon; + char ostype[BUFSIZ]; + char feature_opts[BUFSIZ]; + struct hostent *hostname; + char *vc; + struct passwd *pwent; + FILE *cpp_in = NULL; + FILE *cpp_out = NULL; + FILE *mirror = NULL; + int to_child[2]; + int from_child[2]; + pid_t pid; + int status; + char command[2 * BUFSIZ]; + char tmp_name[BUFSIZ]; + int created_temp = 0; + char kept_path[BUFSIZ]; + size_t line_cap = 1024; + char *linebuf = NULL; + size_t line_len = 0; + unsigned char chunk[BUFSIZ]; + size_t nread; + int appended_newline = 0; + + kept_path[0] = '\0'; + + if (cpp_outfile[0] != '\0') { + mirror = fopen(cpp_outfile, "w"); + if (mirror == NULL) + fprintf(stderr, "%s: unable to open %s for writing\n", + MyName, cpp_outfile); + } else if (keep_output) { + const char *tmpdir = getenv("TMPDIR"); + if (tmpdir == NULL) + tmpdir = "/tmp"; + strlcpy(tmp_name, tmpdir, sizeof(tmp_name)); + strlcat(tmp_name, "/fvwmcppXXXXXXXXXX", sizeof(tmp_name)); + { + int fd_tmp = mkstemp(tmp_name); + if (fd_tmp >= 0) { + mirror = fdopen(fd_tmp, "w"); + if (mirror != NULL) { + strlcpy(kept_path, tmp_name, + sizeof(kept_path)); + created_temp = 1; + } else { + close(fd_tmp); + } + } else { + perror("mkstemp failed in cpp_process"); + } + } + } - strcat(options, "Cpp "); + if (pipe(to_child) == -1 || pipe(from_child) == -1) { + perror("pipe in cpp_process"); + if (mirror) + fclose(mirror); + return -1; + } -#ifdef NO_SAVEUNDERS - strcat(options, "NO_SAVEUNDERS "); -#endif + snprintf(command, sizeof(command), "%s %s", cpp_prog, + (cpp_opts != NULL) ? cpp_opts : ""); + + pid = fork(); + if (pid == -1) { + perror("fork in cpp_process"); + close(to_child[0]); + close(to_child[1]); + close(from_child[0]); + close(from_child[1]); + if (mirror) + fclose(mirror); + return -1; + } - fputs(MkDef("OPTIONS", options), tmpf); + if (pid == 0) { + dup2(to_child[0], STDIN_FILENO); + dup2(from_child[1], STDOUT_FILENO); + close(to_child[0]); + close(to_child[1]); + close(from_child[0]); + close(from_child[1]); + execl("/bin/sh", "sh", "-c", command, (char *)NULL); + _exit(127); + } - fputs(MkDef("FVWM_MODULEDIR", FVWM_MODULEDIR), tmpf); - fputs(MkDef("FVWM_CONFIGDIR", FVWM_CONFIGDIR), tmpf); + close(to_child[0]); + close(from_child[1]); + + cpp_in = fdopen(to_child[1], "w"); + cpp_out = fdopen(from_child[0], "r"); + if (cpp_in == NULL || cpp_out == NULL) { + perror("fdopen in cpp_process"); + if (cpp_in) + fclose(cpp_in); + else + close(to_child[1]); + if (cpp_out) + fclose(cpp_out); + else + close(from_child[0]); + if (mirror) + fclose(mirror); + waitpid(pid, NULL, 0); + return -1; + } - /* - * At this point, we've sent the definitions to cpp. Just include - * the fvwmrc file now. - */ +#define WRITE_DEF(name, value) \ + do { \ + char *tmp__ = MkDef((name), (value)); \ + fputs(tmp__, cpp_in); \ + free(tmp__); \ + } while (0) +#define WRITE_NUM(name, value) \ + do { \ + char *tmp__ = MkNum((name), (value)); \ + fputs(tmp__, cpp_in); \ + free(tmp__); \ + } while (0) + + gethostname(client, MAXHOSTNAME); + getostype(ostype, sizeof ostype); + + hostname = gethostbyname(client); + strlcpy(server, XDisplayName(host), sizeof(server)); + colon = strchr(server, ':'); + if (colon != NULL) + *colon = '\0'; + if ((server[0] == '\0') || (!strcmp(server, "unix"))) + strlcpy(server, client, sizeof(server)); + + WRITE_DEF("TWM_TYPE", "fvwm"); + WRITE_DEF("SERVERHOST", server); + WRITE_DEF("CLIENTHOST", client); + if (hostname) + WRITE_DEF("HOSTNAME", (char *)hostname->h_name); + else + WRITE_DEF("HOSTNAME", client); + WRITE_DEF("OSTYPE", ostype); + + pwent = getpwuid(geteuid()); + if (pwent && pwent->pw_name) + WRITE_DEF("USER", pwent->pw_name); + else + WRITE_DEF("USER", ""); - fprintf(tmpf, "#include \"%s\"\n", config_file); + { + const char *home = getenv("HOME"); + WRITE_DEF("HOME", (home != NULL) ? home : ""); + } - pclose(tmpf); - return(tmp_name); -} + WRITE_NUM("VERSION", ProtocolVersion(display)); + WRITE_NUM("REVISION", ProtocolRevision(display)); + WRITE_DEF("VENDOR", ServerVendor(display)); + WRITE_NUM("RELEASE", VendorRelease(display)); + + screen = ScreenOfDisplay(display, Mscreen); + visual = DefaultVisualOfScreen(screen); + WRITE_NUM("WIDTH", DisplayWidth(display, Mscreen)); + WRITE_NUM("HEIGHT", DisplayHeight(display, Mscreen)); + WRITE_NUM("X_RESOLUTION", Resolution(screen->width, screen->mwidth)); + WRITE_NUM("Y_RESOLUTION", Resolution(screen->height, screen->mheight)); + WRITE_NUM("PLANES", DisplayPlanes(display, Mscreen)); + WRITE_NUM("BITS_PER_RGB", visual->bits_per_rgb); + WRITE_NUM("SCREEN", Mscreen); + + switch (visual->class) { + case StaticGray: + vc = "StaticGray"; + break; + case GrayScale: + vc = "GrayScale"; + break; + case StaticColor: + vc = "StaticColor"; + break; + case PseudoColor: + vc = "PseudoColor"; + break; + case TrueColor: + vc = "TrueColor"; + break; + case DirectColor: + vc = "DirectColor"; + break; + default: + vc = "NonStandard"; + break; + } + + WRITE_DEF("CLASS", vc); + if (visual->class != StaticGray && visual->class != GrayScale) + WRITE_DEF("COLOR", "Yes"); + else + WRITE_DEF("COLOR", "No"); + WRITE_DEF("FVWM_VERSION", VERSION); + + feature_opts[0] = '\0'; +#ifdef SHAPE + strlcat(feature_opts, "SHAPE ", sizeof(feature_opts)); +#endif +#ifdef XPM + strlcat(feature_opts, "XPM ", sizeof(feature_opts)); +#endif + strlcat(feature_opts, "Cpp ", sizeof(feature_opts)); +#ifdef NO_SAVEUNDERS + strlcat(feature_opts, "NO_SAVEUNDERS ", sizeof(feature_opts)); +#endif + WRITE_DEF("OPTIONS", feature_opts); + WRITE_DEF("FVWM_MODULEDIR", FVWM_MODULEDIR); + WRITE_DEF("FVWM_CONFIGDIR", FVWM_CONFIGDIR); + + fprintf(cpp_in, "#include \"%s\"\n", config_file); + fflush(cpp_in); + fclose(cpp_in); + +#undef WRITE_DEF +#undef WRITE_NUM + + linebuf = xmalloc(line_cap); + while ((nread = fread(chunk, 1, sizeof(chunk), cpp_out)) > 0) { + if (mirror) + fwrite(chunk, 1, nread, mirror); + for (size_t i = 0; i < nread; i++) { + if (line_len + 1 >= line_cap) { + line_cap *= 2; + linebuf = xrealloc(linebuf, line_cap); + } + linebuf[line_len++] = chunk[i]; + if (chunk[i] == '\n') { + if (line_len >= 2 && + linebuf[line_len - 2] == '\\') { + /* Preserve fvwm's "\" line continuation + * semantics. */ + line_len -= 2; + continue; + } + linebuf[line_len] = '\0'; + if (!is_cpp_linemarker(linebuf)) + SendInfo(fd, linebuf, 0); + line_len = 0; + } + } + } + + if (ferror(cpp_out)) + perror("cpp output read"); + + if (line_len > 0) { + if (line_len + 2 >= line_cap) { + line_cap *= 2; + linebuf = xrealloc(linebuf, line_cap); + } + if (linebuf[line_len - 1] != '\n') { + linebuf[line_len++] = '\n'; + appended_newline = 1; + } + linebuf[line_len] = '\0'; + if (mirror && appended_newline) + fputc('\n', mirror); + if (!is_cpp_linemarker(linebuf)) + SendInfo(fd, linebuf, 0); + } + free(linebuf); + fclose(cpp_out); + if (mirror) + fclose(mirror); + if (waitpid(pid, &status, 0) == -1) { + perror("waitpid for cpp"); + status = 1; + } + + if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { + fprintf(stderr, "%s: cpp exited with status %d\n", MyName, + WEXITSTATUS(status)); + return -1; + } + + if (created_temp && kept_path[0] != '\0') { + char msg[BUFSIZ]; + snprintf(msg, sizeof(msg), + "Echo %s: preprocessor output kept in %s\n", MyName, + kept_path); + SendInfo(fd, msg, 0); + } + return 0; +} + +static int +is_cpp_linemarker(const char *line) +{ + const unsigned char *p; + + if (line == NULL) + return 0; + + p = (const unsigned char *)line; + while (*p == ' ' || *p == '\t') + p++; + if (*p != '#') + return 0; + p++; + while (*p == ' ' || *p == '\t') + p++; + if (*p == '\0' || *p == '\n') + return 1; + if (isdigit(*p)) { + while (isdigit(*p)) + p++; + while (*p == ' ' || *p == '\t') + p++; + if (*p == '\0' || *p == '\n' || *p == '"') + return 1; + } + if (strncmp((const char *)p, "line", 4) == 0) + return 1; + return 0; +} /*********************************************************************** * @@ -365,31 +505,34 @@ static char *cpp_defs(Display *display, const char *host, char *cpp_options, cha * SIGPIPE handler - SIGPIPE means fvwm is dying * ***********************************************************************/ -void DeadPipe(int nonsense) +void +DeadPipe(int nonsense) { - exit(0); + exit(0); } -static char *MkDef(char *name, char *def) +static char * +MkDef(const char *name, const char *def) { - char *cp = NULL; - int n; + char *cp = NULL; + int n; - /* Get space to hold everything, if needed */ + /* Get space to hold everything, if needed */ - n = EXTRA + strlen(name) + strlen(def); - cp = safemalloc(n); + n = EXTRA + strlen(name) + strlen(def); + cp = xmalloc(n); - sprintf(cp, "#define %s %s\n",name,def); + snprintf(cp, n, "#define %s %s\n", name, def); - return(cp); + return (cp); } -static char *MkNum(char *name,int def) +static char * +MkNum(const char *name, int def) { - char num[20]; + char num[20]; - sprintf(num, "%d", def); + snprintf(num, sizeof(num), "%d", def); - return(MkDef(name, num)); + return (MkDef(name, num)); } Index: fvwm/modules/FvwmCpp/FvwmCpp.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmCpp/FvwmCpp.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmCpp/FvwmCpp.h --- fvwm/modules/FvwmCpp/FvwmCpp.h +++ fvwm/modules/FvwmCpp/FvwmCpp.h @@ -1,13 +1,9 @@ -#include "../../libs/fvwmlib.h" +#include "../../libs/fvwmlib.h" /************************************************************************* * * Subroutine Prototypes - * + * *************************************************************************/ void DeadPipe(int nonsense); - - - - Index: fvwm/modules/FvwmForm/FvwmForm.1 =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmForm/FvwmForm.1,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmForm/FvwmForm.1 --- fvwm/modules/FvwmForm/FvwmForm.1 +++ fvwm/modules/FvwmForm/FvwmForm.1 @@ -1,29 +1,29 @@ .\" $OpenBSD: FvwmForm.1,v 1.2 2010/03/20 20:13:27 schwarze Exp $ -.TH FvwmForm 1 +.TH FVWMFORM 1 "February 1, 1995" "1.0" "FVWM Modules" .SH NAME -FvwmForm - input form module for Fvwm +FvwmForm \- input form module for Fvwm .SH SYNOPSIS -FvwmForm must be spawned by Fvwm. +FvwmForm must be spawned by Fvwm. It will not work from the command line. .SH DESCRIPTION FvwmForm provides a mechanism to get user input and act accordingly. This is achieved by means of a form that the user can fill out, and from which the user can select actions he wants Fvwm to take. A form consists of five types of items: -text labels, +text labels, single-line text inputs, mutually-exclusive selections, multiple-choice selections, and action buttons. These items are arranged into several lines, with a very flexible layout. - +.PP A text label only serves the purpose of explanation. It cannot accept any input. A text input field can be used to edit a single-line string. FvwmForm accepts Emacs-style cursor movement keys. No copying and pasting functions exist. - +.PP A selection consists of several choices. The selection itself is a logical entity that doesn't have any display feature. @@ -31,7 +31,7 @@ Each choice is displayed as a push-button followed by a explanatory text label. When selected, an exclusive choice shows a circle in the middle, while a multiple choice shows a check. - +.PP An action button, when clicked on, will send a set of commands to Fvwm. FvwmForm will do variable substitutions in the command text to reflect @@ -45,17 +45,17 @@ and they will be treated as different modules. Or, you can invoke FvwmForm with an optional parameter, which it will use as the name instead (e.g. 'Module FvwmForm QuitVerify'). That way you don't even have to make a symbolic link for it! - +.PP Be sure to set ModulePath in your .fvwmrc file to include FvwmForm's path. - +.PP When FvwmForm is invoked with a window context, e.g. from a window menu, all commands it sends to Fvwm will have that window context. .SH CONFIGURATION The following options can be set in the .fvwmrc file. Note that the string "FvwmForm" should be changed if another module with different name is used. - +.PP The order of the options DOES matter. In general, colors and fonts should be specified first. Lines, text labels, and input items should appear in their logical order. @@ -72,7 +72,6 @@ It saves the user some mouse-travelling. Puts the FvwmForm window at location (\fIx\fP, \fIy\fP) on the screen. By convention, a negative \fIx\fP (resp. \fIy\fP) value measures distance from the right (resp. bottom) of the screen. - If this option is omitted, FvwmForm will start at the center of the screen. .TP 4 .B *FvwmFormBack \fIcolor\fP @@ -104,7 +103,7 @@ A line can contain an arbitrary number of items whose options should follow. A FvwmForm window can have an arbitrary number of lines. The width of the window is that of the longest line. - +.PP Justification of items in the line is specified by \fIjustification\fP, which can be one of the following: .TP 16 @@ -151,7 +150,7 @@ Specifies a choice for a selection. The choice item has a \fIname\fP and a \fIvalue\fP. The \fIstring\fP will be displayed to the right of the choice button as a label. - +.PP The choice will assume the specified initial state ("on" means selected) when FvwmForm starts or resets. Note that if the selections are mutually exclusive, @@ -162,10 +161,10 @@ FvwmForm will assure only one is selected. .TP 4 .B *FvwmFormButton \fItype\fP "\fIstring\fP" [\fIkey\fP] This option specifies an action button. -The button has \fIstring\fP as a label, +The button has \fIstring\fP as a label, and excutes a set of Fvwm \fIcommand\fP when it is activated. The commands should be specified using the *FvwmFormCommand option. - +.PP The optional \fIkey\fP specifies a keyboard shortcut that activates the button. It is in either a control character, specified as ^@, ^A, ..., ^_, @@ -173,14 +172,14 @@ or a function key, specified as F1, F2, ..., F35. Control keys that are used for cursor movement in text input fields cannot activate any buttons, with the exception of TAB, RETURN, LINEFEED, which can activate a button when the cursor is in the last text input field. - +.PP The behavior of the button is determined by \fItype\fP: .TP 16 continue FvwmForm will resume execution after sending the commands. .TP 16 restart -After sending the commands, +After sending the commands, FvwmForm will reset all the values to the initial ones, and then resume execution. .TP 16 @@ -191,7 +190,7 @@ FvwmForm will quit after sending the commands. This option specifies an Fvwm command associated with the current button. Commands that appear before any *FvwmFormButton option will be executed at start-up time. This is usually a beep that gets the user's attention. - +.PP Before sending each command to Fvwm, FvwmForm recognizes variables of the following forms, and supply values to them. .TP 16 @@ -199,12 +198,12 @@ following forms, and supply values to them. If \fIname\fP corresponds to a text input field, the result is the user's input string. Special chars such as ", ', and \ will be preceded by a backslash. - +.PP If \fIname\fP corresponds to a choice, the result is the value of the choice (as specified in *FvwmFormChoice) if the choice is selected. If the choice is not selected, the result is a blank string. - +.PP If \fIname\fP corresponds to a selection, the result will be a list of the selected values of all its choices. .TP 16 @@ -213,7 +212,7 @@ If \fIname\fP is a text input field and its value is not an empty string, the result is \fIstring\fP, with recursive variable substitution applied. If the input value is empty, the result is empty. - +.PP If \fIname\fP is a choice and it is selected, the result is \fIstring\fP, with recursive variable substitution applied. @@ -223,170 +222,101 @@ If the choice is not selected, the result is empty. The same as the above, except that the converse conditions are taken. .SH EXAMPLE 1 - QuitVerify This example simulates the mwm way of confirming logout. - +.RS +.nf *QuitVerifyGrabServer -.br *QuitVerifyWarpPointer -.br -*QuitVerifyFont *helvetica*m*r*n*14* -.br -*QuitVerifyButtonFont *helvetica*m*o*n*14* -.br -*QuitVerifyFore Black -.br -*QuitVerifyBack Light Gray -.br -*QuitVerifyItemFore Wheat -.br -*QuitVerifyItemBack Gray50 -.br +*QuitVerifyFont *helvetica*m*r*n*14* +*QuitVerifyButtonFont *helvetica*m*o*n*14* +*QuitVerifyFore Black +*QuitVerifyBack Light Gray +*QuitVerifyItemFore Wheat +*QuitVerifyItemBack Gray50 # begin items -.br -*QuitVerifyCommand Beep -.br -*QuitVerifyLine center -.br -*QuitVerifyText "Do you really want to logout?" -.br -*QuitVerifyLine expand -.br -*QuitVerifyButton quit "Logout" ^M -.br -*QuitVerifyCommand Quit -.br -*QuitVerifyButton quit "Cancel" ^[ -.br -*QuitVerifyCommand Nop -.br +*QuitVerifyCommand Beep +*QuitVerifyLine center +*QuitVerifyText "Do you really want to logout?" +*QuitVerifyLine expand +*QuitVerifyButton quit "Logout" ^M +*QuitVerifyCommand Quit +*QuitVerifyButton quit "Cancel" ^[ +*QuitVerifyCommand Nop # Fvwm window style -.br Style "QuitVerify" NoTitle, NoHandles, BorderWidth 3 - +.fi +.RE .SH EXAMPLE 2 - Remote Login -This example lets the user type in a hostname, +This example lets the user type in a hostname, and optionally a user name on the remote machine, and opens an xterm window from the remote host. - +.RS +.nf *RloginWarpPointer -.br -*RloginFont *helvetica*m*r*n*14* -.br -*RloginButtonFont *helvetica*m*o*n*14* -.br -*RloginInputFont *cour*m*r*n*14* -.br -*RloginFore Black -.br -*RloginBack Light Gray -.br -*RloginItemFore Wheat -.br -*RloginItemBack Gray50 -.br +*RloginFont *helvetica*m*r*n*14* +*RloginButtonFont *helvetica*m*o*n*14* +*RloginInputFont *cour*m*r*n*14* +*RloginFore Black +*RloginBack Light Gray +*RloginItemFore Wheat +*RloginItemBack Gray50 # begin items -.br -*RloginLine center -.br -*RloginText "Login to Remote Host" -.br -*RloginLine center -.br -*RloginText "Host:" -.br -*RloginInput HostName 20 "" -.br -*RloginLine center -.br -*RloginSelection UserSel single -.br -*RloginChoice Default Default on "same user" -.br -*RloginChoice Custom Custom off "user:" -.br -*RloginInput UserName 10 "" -.br -*RloginLine expand -.br -*RloginButton quit "Login" ^M -.br -*RloginCommand Exec exec rsh $(Custom?-l $(UserName)) $(HostName) xterm -T xterm@$(HostName) -display $HOSTDISPLAY & -.br -*RloginButton restart "Clear" -.br -*RloginButton quit "Cancel" ^[ -.br -*RloginCommand Nop - +*RloginLine center +*RloginText "Login to Remote Host" +*RloginLine center +*RloginText "Host:" +*RloginInput HostName 20 "" +*RloginLine center +*RloginSelection UserSel single +*RloginChoice Default Default on "same user" +*RloginChoice Custom Custom off "user:" +*RloginInput UserName 10 "" +*RloginLine expand +*RloginButton quit "Login" ^M +*RloginCommand Exec exec rsh $(Custom?-l $(UserName)) $(HostName) \ +xterm -T xterm@$(HostName) -display $HOSTDISPLAY & +*RloginButton restart "Clear" +*RloginButton quit "Cancel" ^[ +*RloginCommand Nop +.fi +.RE .SH EXAMPLE 3 - Capture Window This example provides a front-end to xwd, xwud, and xpr. - -*CaptureFont *helvetica*m*r*n*14* -.br -*CaptureButtonFont *helvetica*m*o*n*14* -.br -*CaptureInputFont *cour*m*r*n*14* -.br -*CaptureLine center -.br -*CaptureText "Capture Window" -.br -*CaptureLine left -.br -*CaptureText "File: " -.br -*CaptureInput file 25 "/tmp/Capture" -.br -*CaptureLine left -.br -*CaptureText "Printer: " -.br -*CaptureInput printer 20 "ps1" -.br -*CaptureLine expand -.br -*CaptureSelection PtrType single -.br -*CaptureChoice PS ps on "PostScript" -.br -*CaptureChoice Ljet ljet off "HP LaserJet" -.br -*CaptureLine left -.br -*CaptureText "xwd options:" -.br -*CaptureLine expand -.br -*CaptureSelection Options multiple -.br -*CaptureChoice Brd -nobdrs off "No border" -.br -*CaptureChoice Frm -frame on "With frame" -.br -*CaptureChoice XYZ -xy off "XY format" -.br -*CaptureLine expand -.br -*CaptureButton continue "Capture" ^M -.br -*CaptureCommand Exec exec xwd -out $(file) $(Options) & -.br -*CaptureButton continue "Preview" -.br -*CaptureCommand Exec exec xwud -in $(file) & -.br -*CaptureButton continue "Print" -.br -*CaptureCommand Exec xpr -device $(PtrType) $(file) | lpr -P $(printer) & -.br -*CaptureButton quit "Quit" - -.SH BUGS AND LIMITATIONS -There is a hard-coded limit on the number of items. - -Report bugs to ztfeng@math.princeton.edu. +.RS +.nf +*CaptureFont *helvetica*m*r*n*14* +*CaptureButtonFont *helvetica*m*o*n*14* +*CaptureInputFont *cour*m*r*n*14* +*CaptureLine center +*CaptureText "Capture Window" +*CaptureLine left +*CaptureText "File: " +*CaptureInput file 25 "/tmp/Capture" +*CaptureLine left +*CaptureText "Printer: " +*CaptureInput printer 20 "ps1" +*CaptureLine expand +*CaptureSelection PtrType single +*CaptureChoice PS ps on "PostScript" +*CaptureChoice Ljet ljet off "HP LaserJet" +*CaptureLine left +*CaptureText "xwd options:" +*CaptureLine expand +*CaptureSelection Options multiple +*CaptureChoice Brd -nobdrs off "No border" +*CaptureChoice Frm -frame on "With frame" +*CaptureChoice XYZ -xy off "XY format" +*CaptureLine expand +*CaptureButton continue "Capture" ^M +*CaptureCommand Exec exec xwd -out $(file) $(Options) & +*CaptureButton continue "Preview" +*CaptureCommand Exec exec xwud -in $(file) & +*CaptureButton continue "Print" +*CaptureCommand Exec xpr -device $(PtrType) $(file) | lpr -P $(printer) & +*CaptureButton quit "Quit" +.fi +.RE .SH COPYRIGHT FvwmForm is original work of Thomas Zuwei Feng. - Copyright Feb 1995, Thomas Zuwei Feng. No guarantees or warantees are provided or implied in any way whatsoever. Use this program at your own risk. Permission to use, modify, and redistribute this program is hereby Index: fvwm/modules/FvwmForm/FvwmForm.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmForm/FvwmForm.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmForm/FvwmForm.c --- fvwm/modules/FvwmForm/FvwmForm.c +++ fvwm/modules/FvwmForm/FvwmForm.c @@ -5,29 +5,33 @@ * risk. Permission to use, modify, and redistribute this program is hereby * given, provided that this copyright is kept intact. */ -#include "config.h" - -#include "../../libs/fvwmlib.h" +#include +#include -#include #include - -#include -#include #include +#include +#include +#include + +#include "../../libs/fvwmlib.h" +#include "config.h" +#include "../../fvwm/fvwm_sandbox.h" #if HAVE_SYS_SELECT_H #include #endif -#include #include +#include #include #include #define XK_MISCELLANY #include -void dummy (FILE *f, const char *fmt, ...) { +void +dummy(FILE *f, const char *fmt, ...) +{ } #ifdef DEBUG @@ -36,110 +40,107 @@ void dummy (FILE *f, const char *fmt, ...) { #define fprintf dummy #endif +#define TEXT_SPC 3 +#define BOX_SPC 3 +#define ITEM_HSPC 10 +#define ITEM_VSPC 5 -#define TEXT_SPC 3 -#define BOX_SPC 3 -#define ITEM_HSPC 10 -#define ITEM_VSPC 5 - -/* tba: use dynamic buffer expanding */ -#define MAX_LINES 50 -#define MAX_ITEMS 100 -#define ITEMS_PER_LINE 64 -#define CHOICES_PER_SEL 64 +/* initial allocation sizes, structures grow dynamically as needed */ +#define INITIAL_LINE_CAPACITY 8 +#define INITIAL_LINE_ITEMS_CAPACITY 8 +#define INITIAL_ITEMS_CAPACITY 128 +#define INITIAL_CHOICES_CAPACITY 8 -#define I_TEXT 1 -#define I_INPUT 2 -#define I_SELECT 3 -#define I_CHOICE 4 -#define I_BUTTON 5 +#define I_TEXT 1 +#define I_INPUT 2 +#define I_SELECT 3 +#define I_CHOICE 4 +#define I_BUTTON 5 -#define IS_SINGLE 1 -#define IS_MULTIPLE 2 +#define IS_SINGLE 1 +#define IS_MULTIPLE 2 -#define IB_CONTINUE 1 -#define IB_RESTART 2 -#define IB_QUIT 3 +#define IB_CONTINUE 1 +#define IB_RESTART 2 +#define IB_QUIT 3 typedef union _item { - int type; /* item type, one of I_TEXT .. I_BUTTON */ - struct _head { /* common header */ - int type; - int win; /* X window id */ - char *name; /* identifier name */ - int size_x, size_y; /* size of bounding box */ - int pos_x, pos_y; /* position of top-left corner */ - } header; - struct { /* I_TEXT */ - struct _head head; - int n; /* string length */ - char *value; /* string to display */ - } text; - struct { /* I_INPUT */ - struct _head head; - int buf; /* input string buffer */ - int n; /* string length */ - char *value; /* input string */ - char *init_value; /* default string */ - char *blanks; /* blank string */ - int size; /* input field size */ - int left; /* position of the left-most displayed char */ - int o_cursor; /* store relative cursor position */ - } input; - struct { /* I_SELECT */ - struct _head head; - int key; /* one of IS_MULTIPLE, IS_SINGLE */ - int n; /* number of choices */ - union _item **choices; /* list of choices */ - } select; - struct { /* I_CHOICE */ - struct _head head; - int on; /* selected or not */ - int init_on; /* initially selected or not */ - char *value; /* value if selected */ - int n; /* text string length */ - char *text; /* text string */ - union _item *sel; /* selection it belongs to */ - } choice; - struct { /* I_BUTTON */ - struct _head head; - int key; /* one of IB_CONTINUE, IB_RESTART, IB_QUIT */ - int n; /* # of commands */ - int len; /* text length */ - char *text; /* text string */ - int keypress; /* short cut */ - /* Fvwm command to execute */ - char **commands; - } button; + int type; /* item type, one of I_TEXT .. I_BUTTON */ + struct _head { /* common header */ + int type; + int win; /* X window id */ + char *name; /* identifier name */ + int size_x, size_y; /* size of bounding box */ + int pos_x, pos_y; /* position of top-left corner */ + } header; + struct { /* I_TEXT */ + struct _head head; + int n; /* string length */ + char *value; /* string to display */ + } text; + struct { /* I_INPUT */ + struct _head head; + int buf; /* input string buffer */ + int n; /* string length */ + char *value; /* input string */ + char *init_value; /* default string */ + char *blanks; /* blank string */ + int size; /* input field size */ + int left; /* position of the left-most displayed char */ + int o_cursor; /* store relative cursor position */ + } input; + struct { /* I_SELECT */ + struct _head head; + int key; /* one of IS_MULTIPLE, IS_SINGLE */ + int n; /* number of choices */ + union _item **choices; /* list of choices */ + int choices_cap; + } select; + struct { /* I_CHOICE */ + struct _head head; + int on; /* selected or not */ + int init_on; /* initially selected or not */ + char *value; /* value if selected */ + int n; /* text string length */ + char *text; /* text string */ + union _item *sel; /* selection it belongs to */ + } choice; + struct { /* I_BUTTON */ + struct _head head; + int key; /* one of IB_CONTINUE, IB_RESTART, IB_QUIT */ + int n; /* # of commands */ + int len; /* text length */ + char *text; /* text string */ + int keypress; /* short cut */ + /* Fvwm command to execute */ + char **commands; + int commands_cap; + } button; } Item; - -#define L_LEFT 1 -#define L_RIGHT 2 -#define L_CENTER 3 -#define L_LEFTRIGHT 4 +#define L_LEFT 1 +#define L_RIGHT 2 +#define L_CENTER 3 +#define L_LEFTRIGHT 4 typedef struct _line { - int n; /* number of items on the line */ - int justify; /* justification */ - int size_x, size_y; /* size of bounding rectangle */ - Item **items; /* list of items */ + int n; /* number of items on the line */ + int justify; /* justification */ + int size_x, size_y; /* size of bounding rectangle */ + Item **items; /* list of items */ + int items_cap; /* capacity of items array */ } Line; - -/* global variables */ -char *prog_name; /* program name, e.g. FvwmForm */ - -int fd_in; /* fd for Fvwm->Module packets */ -int fd_out; /* fd for Module->Fvwm packets */ -int fd[2]; /* pipe pair */ -int fd_err; +int fd_in; /* fd for Fvwm->Module packets */ +int fd_out; /* fd for Module->Fvwm packets */ FILE *fp_err; -Line lines[MAX_LINES]; +Line *lines = NULL; int n_lines; -Item items[MAX_ITEMS]; +int lines_capacity = 0; +Item *items = NULL; int n_items; +int items_capacity = 0; Item def_button; int grab_server = 0, server_grabbed = 0; @@ -147,27 +148,24 @@ int gx, gy, geom = 0; int warp_pointer = 0; Display *dpy; -int fd_x; /* fd for X connection */ +int fd_x; /* fd for X connection */ +char *prog_name; +int fd[2]; +int fd_err; Window root, frame, ref; Colormap d_cmap; int screen; int scr_depth; -int max_width, total_height; /* frame size */ +int max_width, total_height; /* frame size */ enum { c_back, c_fore, c_itemback, c_itemfore, c_itemlo, c_itemhi }; -char *color_names[4] = { - "Light Gray", "Black", "Gray50", "Wheat" -}; +char *color_names[4] = {"Light Gray", "Black", "Gray50", "Wheat"}; unsigned long colors[6]; enum { f_text, f_input, f_button }; -char *font_names[3] = { - "fixed", - "fixed", - "fixed" -}; +char *font_names[3] = {"fixed", "fixed", "fixed"}; Font fonts[3]; XFontStruct *xfs[3]; @@ -182,1396 +180,1793 @@ int rel_cursor; static char *buf; static int N = 8; +static void +ensure_line_capacity(int count) +{ + if (lines_capacity >= count) { + return; + } + int new_cap = lines_capacity ? lines_capacity : INITIAL_LINE_CAPACITY; + while (new_cap < count) { + new_cap *= 2; + } + lines = (Line *)realloc(lines, sizeof(Line) * new_cap); + for (int i = lines_capacity; i < new_cap; ++i) { + lines[i].n = 0; + lines[i].justify = L_CENTER; + lines[i].size_x = 0; + lines[i].size_y = 0; + lines[i].items = NULL; + lines[i].items_cap = 0; + } + lines_capacity = new_cap; +} + +static void +ensure_line_item_capacity(Line *line, int count) +{ + if (line->items_cap >= count) { + return; + } + int new_cap = + line->items_cap ? line->items_cap : INITIAL_LINE_ITEMS_CAPACITY; + while (new_cap < count) { + new_cap *= 2; + } + line->items = (Item **)realloc(line->items, sizeof(Item *) * new_cap); + line->items_cap = new_cap; +} + +static Line * +add_line(int justify) +{ + ensure_line_capacity(n_lines + 1); + Line *line = &lines[n_lines++]; + line->n = 0; + line->justify = justify; + line->size_x = 0; + line->size_y = 0; + if (!line->items) { + line->items_cap = 0; + } + ensure_line_item_capacity(line, 1); + return line; +} + +static void +append_item_to_line(Line *line, Item *item) +{ + ensure_line_item_capacity(line, line->n + 1); + line->items[line->n++] = item; + line->size_x += item->header.size_x; + if (line->size_y < item->header.size_y) { + line->size_y = item->header.size_y; + } +} + /* copy a string until '\0', or up to n chars, and delete trailing spaces */ -char *CopyNString (char *cp, int n) +char * +CopyNString(char *cp, int n) { - char *dp, *bp; - if (n == 0) - n = strlen(cp); - bp = dp = (char *)malloc(n+1); - while (n-- > 0) - *dp++ = *cp++; - while (isspace(*(--dp))); - *(++dp) = '\0'; - return bp; + char *dp, *bp; + if (n == 0) + n = strlen(cp); + bp = dp = (char *)malloc(n + 1); + while (n-- > 0) + *dp++ = *cp++; + while (isspace(*(--dp))) + ; + *(++dp) = '\0'; + return bp; } /* copy a string until '"', or '\n', or '\0' */ -char *CopyQuotedString (char *cp) +char * +CopyQuotedString(char *cp) { - char *dp, *bp, c; - bp = dp = (char *)malloc(strlen(cp) + 1); - while (1) { - switch (c = *(cp++)) { - case '\\': - *(dp++) = *(cp++); - break; - case '\"': - case '\n': - case '\0': - *dp = '\0'; - return bp; - break; - default: - *(dp++) = c; - break; - } - } + char *dp, *bp, c; + bp = dp = (char *)malloc(strlen(cp) + 1); + sandbox_x11_config("FvwmForm"); + + while (1) { + switch (c = *(cp++)) { + case '\\': + *(dp++) = *(cp++); + break; + case '\"': + case '\n': + case '\0': + *dp = '\0'; + return bp; + break; + default: + *(dp++) = c; + break; + } + } } /* copy a string until the first space */ -char *CopySolidString (char *cp) +char * +CopySolidString(char *cp) { - char *dp, *bp, c; - bp = dp = (char *)malloc(strlen(cp) + 1); - while (1) { - c = *(cp++); - if (c == '\\') { - *(dp++) = '\\'; - *(dp++) = *(cp++); - } else if (isspace(c) || c == '\0') { - *dp = '\0'; - return bp; - } else - *(dp++) = c; - } + char *dp, *bp, c; + bp = dp = (char *)malloc(strlen(cp) + 1); + while (1) { + c = *(cp++); + if (c == '\\') { + *(dp++) = '\\'; + *(dp++) = *(cp++); + } else if (isspace(c) || c == '\0') { + *dp = '\0'; + return bp; + } else + *(dp++) = c; + } } /* get the font height */ -int FontHeight (XFontStruct *xfs) +int +FontHeight(XFontStruct *xfs) { - return (xfs->ascent + xfs->descent); + return (xfs->ascent + xfs->descent); } /* get the font width, for fixed-width font only */ -int FontWidth (XFontStruct *xfs) +int +FontWidth(XFontStruct *xfs) { - return (xfs->per_char[0].width); + return (xfs->per_char[0].width); } /* read the configuration file */ -void ReadConfig () +void +ReadConfig() { - FILE *fopen(); - int prog_name_len, i, j, l, extra; - char *line_buf; - char *cp; - Line *cur_line, *line; - Item *item, *cur_sel, *cur_button; - -#define AddToLine(item) { cur_line->items[cur_line->n++] = item; cur_line->size_x += item->header.size_x; if (cur_line->size_y < item->header.size_y) cur_line->size_y = item->header.size_y; } - - n_items = 0; - n_lines = 0; - - /* default line in case the first *FFLine is missing */ - lines[0].n = 0; - lines[0].justify = L_CENTER; - lines[0].size_x = lines[0].size_y = 0; - lines[0].items = (Item **)malloc(sizeof(Item *) * ITEMS_PER_LINE); - cur_line = lines; - - /* default button is for initial functions */ - cur_button = &def_button; - def_button.button.n = 0; - def_button.button.commands = (char **)malloc(sizeof(char *) * MAX_ITEMS); - def_button.button.key = IB_CONTINUE; - - /* default fonts in case the *FFFont's are missing */ - xfs[f_text] = xfs[f_input] = xfs[f_button] = - GetFontOrFixed(dpy, "fixed"); - fonts[f_text] = fonts[f_input] = fonts[f_button] = xfs[f_text]->fid; - - prog_name_len = strlen(prog_name); - - while (GetConfigLine(fd,&line_buf),line_buf) { - cp = line_buf; - while (isspace(*cp)) cp++; /* skip blanks */ - if (*cp != '*') continue; - if (strncmp(++cp, prog_name, prog_name_len) != 0) continue; - cp += prog_name_len; - /* at this point we have recognized "*FvwmForm" */ - if (strncmp(cp, "GrabServer", 10) == 0) { - grab_server = 1; - continue; - } - else if (strncmp(cp, "WarpPointer", 11) == 0) { - warp_pointer = 1; - } - else if (strncmp(cp, "Position", 8) == 0) { - cp += 8; - geom = 1; - while (isspace(*cp)) cp++; - gx = atoi(cp); - while (!isspace(*cp)) cp++; - while (isspace(*cp)) cp++; - gy = atoi(cp); - fprintf(fp_err, "Position @ (%d, %d)\n", gx, gy); - continue; - } - else if (strncmp(cp, "Fore", 4) == 0) { - cp += 4; - while (isspace(*cp)) cp++; - color_names[c_fore] = CopyNString(cp, 0); - fprintf(fp_err, "ColorFore: %s\n", color_names[c_fore]); - continue; - } else if (strncmp(cp, "Back", 4) == 0) { - cp += 4; - while (isspace(*cp)) cp++; - color_names[c_back] = CopyNString(cp, 0); - fprintf(fp_err, "ColorBack: %s\n", color_names[c_back]); - continue; - } else if (strncmp(cp, "ItemFore", 8) == 0) { - cp += 8; - while (isspace(*cp)) cp++; - color_names[c_itemfore] = CopyNString(cp, 0); - fprintf(fp_err, "ColorItemFore: %s\n", color_names[c_itemfore]); - continue; - } else if (strncmp(cp, "ItemBack", 8) == 0) { - cp += 8; - while (isspace(*cp)) cp++; - color_names[c_itemback] = CopyNString(cp, 0); - fprintf(fp_err, "ColorItemBack: %s\n", color_names[c_itemback]); - continue; - } else if (strncmp(cp, "Font", 4) == 0) { - cp += 4; - while (isspace(*cp)) cp++; - font_names[f_text] = CopyNString(cp, 0); - fprintf(fp_err, "Font: %s\n", font_names[f_text]); - xfs[f_text] = GetFontOrFixed(dpy, font_names[f_text]); - fonts[f_text] = xfs[f_text]->fid; - continue; - } else if (strncmp(cp, "ButtonFont", 10) == 0) { - cp += 10; - while (isspace(*cp)) cp++; - font_names[f_button] = CopyNString(cp, 0); - fprintf(fp_err, "ButtonFont: %s\n", font_names[f_button]); - xfs[f_button] = GetFontOrFixed(dpy, font_names[f_button]); - fonts[f_button] = xfs[f_button]->fid; - continue; - } else if (strncmp(cp, "InputFont", 9) == 0) { - cp += 9; - while (isspace(*cp)) cp++; - font_names[f_input] = CopyNString(cp, 0); - fprintf(fp_err, "InputFont: %s\n", font_names[f_input]); - xfs[f_input] = GetFontOrFixed(dpy, font_names[f_input]); - fonts[f_input] = xfs[f_input]->fid; - continue; - } else if (strncmp(cp, "Line", 4) == 0) { - cp += 4; - cur_line = lines + n_lines++; - while (isspace(*cp)) cp++; - if (strncmp(cp, "left", 4) == 0) - cur_line->justify = L_LEFT; - else if (strncmp(cp, "right", 5) == 0) - cur_line->justify = L_RIGHT; - else if (strncmp(cp, "center", 6) == 0) - cur_line->justify = L_CENTER; - else - cur_line->justify = L_LEFTRIGHT; - cur_line->n = 0; - cur_line->items = (Item **)malloc(sizeof(Item *) * ITEMS_PER_LINE); - continue; - } else if (strncmp(cp, "Text", 4) == 0) { -/* syntax: *FFText "" */ - cp += 4; - item = items + n_items++; - item->type = I_TEXT; - item->header.name = ""; - while (isspace(*cp)) cp++; - if (*cp == '\"') - item->text.value = CopyQuotedString(++cp); - else - item->text.value = ""; - item->text.n = strlen(item->text.value); - item->header.size_x = XTextWidth(xfs[f_text], item->text.value, - item->text.n) + 2 * TEXT_SPC; - item->header.size_y = FontHeight(xfs[f_text]) + 2 * TEXT_SPC; - fprintf(fp_err, "Text \"%s\" [%d, %d]\n", item->text.value, - item->header.size_x, item->header.size_y); - AddToLine(item); - continue; - } - else if (strncmp(cp, "Input", 5) == 0) { -/* syntax: *FFInput "" */ - cp += 5; - item = items + n_items++; - item->type = I_INPUT; - while (isspace(*cp)) cp++; - item->header.name = CopySolidString(cp); - cp += strlen(item->header.name); - while (isspace(*cp)) cp++; - item->input.size = atoi(cp); - while (!isspace(*cp)) cp++; - while (isspace(*cp)) cp++; - if (*cp == '\"') - item->input.init_value = CopyQuotedString(++cp); - else - item->input.init_value = ""; - item->input.blanks = (char *)malloc(item->input.size); - for (j = 0; j < item->input.size; j++) - item->input.blanks[j] = ' '; - item->input.buf = strlen(item->input.init_value) + 1; - item->input.value = (char *)malloc(item->input.buf); - item->header.size_x = FontWidth(xfs[f_input]) * item->input.size - + 2 * TEXT_SPC + 2 * BOX_SPC; - item->header.size_y = FontHeight(xfs[f_input]) + 3 * TEXT_SPC - + 2 * BOX_SPC; - fprintf(fp_err, "Input, %s, [%d], \"%s\"\n", item->header.name, - item->input.size, item->input.init_value); - AddToLine(item); - } - else if (strncmp(cp, "Selection", 9) == 0) { -/* syntax: *FFSelection single | multiple */ - cp += 9; - cur_sel = items + n_items++; - cur_sel->type = I_SELECT; - while (isspace(*cp)) cp++; - cur_sel->header.name = CopySolidString(cp); - cp += strlen(cur_sel->header.name); - while (isspace(*cp)) cp++; - if (strncmp(cp, "multiple", 8) == 0) - cur_sel->select.key = IS_MULTIPLE; - else - cur_sel->select.key = IS_SINGLE; - cur_sel->select.n = 0; - cur_sel->select.choices = - (Item **)malloc(sizeof(Item *) * CHOICES_PER_SEL); - continue; - } else if (strncmp(cp, "Choice", 6) == 0) { -/* syntax: *FFChoice [on | _off_] [""] */ - cp += 6; - item = items + n_items++; - item->type = I_CHOICE; - while (isspace(*cp)) cp++; - item->header.name = CopySolidString(cp); - cp += strlen(item->header.name); - while (isspace(*cp)) cp++; - item->choice.value = CopySolidString(cp); - cp += strlen(item->choice.value); - while (isspace(*cp)) cp++; - if (strncmp(cp, "on", 2) == 0) - item->choice.init_on = 1; - else - item->choice.init_on = 0; - while (!isspace(*cp)) cp++; - while (isspace(*cp)) cp++; - if (*cp == '\"') - item->choice.text = CopyQuotedString(++cp); - else - item->choice.text = ""; - item->choice.n = strlen(item->choice.text); - item->choice.sel = cur_sel; - cur_sel->select.choices[cur_sel->select.n++] = item; - item->header.size_y = FontHeight(xfs[f_text]) + 2 * TEXT_SPC; - item->header.size_x = FontHeight(xfs[f_text]) + 4 * TEXT_SPC + - XTextWidth(xfs[f_text], item->choice.text, item->choice.n); - fprintf(fp_err, "Choice %s, \"%s\", [%d, %d]\n", item->header.name, - item->choice.text, item->header.size_x, item->header.size_y); - AddToLine(item); - continue; - } else if (strncmp(cp, "Button", 6) == 0) { -/* syntax: *FFButton continue | restart | quit "" */ - cp += 6; - item = items + n_items++; - item->type = I_BUTTON; - item->header.name = ""; - while (isspace(*cp)) cp++; - if (strncmp(cp, "restart", 7) == 0) - item->button.key = IB_RESTART; - else if (strncmp(cp, "quit", 4) == 0) - item->button.key = IB_QUIT; - else - item->button.key = IB_CONTINUE; - while (!isspace(*cp)) cp++; - while (isspace(*cp)) cp++; - if (*cp == '\"') { - item->button.text = CopyQuotedString(++cp); - cp += strlen(item->button.text) + 1; - while (isspace(*cp)) cp++; - } else - item->button.text = ""; - if (*cp == '^') - item->button.keypress = *(++cp) - '@'; - else if (*cp == 'F') - item->button.keypress = 256 + atoi(++cp); - else - item->button.keypress = -1; - item->button.len = strlen(item->button.text); - item->button.n = 0; - item->button.commands = (char **)malloc(sizeof(char *) * MAX_ITEMS); - item->header.size_y = FontHeight(xfs[f_button]) + 2 * TEXT_SPC - + 2 * BOX_SPC; - item->header.size_x = 2 * TEXT_SPC + 2 * BOX_SPC - + XTextWidth(xfs[f_button], item->button.text, item->button.len); - AddToLine(item); - cur_button = item; - continue; - } else if (strncmp(cp, "Command", 7) == 0) { -/* syntax: *FFCommand */ - cp += 7; - while (isspace(*cp)) cp++; - cur_button->button.commands[cur_button->button.n++] = - CopyNString(cp, 0); - } - } /* end of switch() */ - /* get the geometry right */ - max_width = 0; - total_height = ITEM_VSPC; - for (l = 0; l < n_lines; l++) { - line = lines + l; - for (i = 0; i < line->n; i++) { - line->items[i]->header.pos_y = total_height; - if (line->items[i]->header.size_y < line->size_y) - line->items[i]->header.pos_y += (line->size_y - line->items[i]->header.size_y) / 2 + 1 ; - } - total_height += ITEM_VSPC + line->size_y; - line->size_x += (line->n + 1) * ITEM_HSPC; - if (line->size_x > max_width) - max_width = line->size_x; - } - for (l = 0; l < n_lines; l++) { - int width; - line = lines + l; - fprintf(fp_err, "Line[%d], %d, %d items\n", l, line->justify, line->n); - switch (line->justify) { - case L_LEFT: - width = ITEM_HSPC; - for (i = 0; i < line->n; i++) { - line->items[i]->header.pos_x = width; - width += ITEM_HSPC + line->items[i]->header.size_x; - } - break; - case L_RIGHT: - width = max_width - line->size_x + ITEM_HSPC; - for (i = 0; i < line->n; i++) { - line->items[i]->header.pos_x = width; - width += ITEM_HSPC + line->items[i]->header.size_x; - } - break; - case L_CENTER: - width = (max_width - line->size_x) / 2 + ITEM_HSPC; - for (i = 0; i < line->n; i++) { - line->items[i]->header.pos_x = width; - fprintf(fp_err, "Line[%d], Item[%d] @ (%d, %d)\n", l, i, - line->items[i]->header.pos_x, line->items[i]->header.pos_y); - width += ITEM_HSPC + line->items[i]->header.size_x; - } - break; - case L_LEFTRIGHT: - /* count the number of inputs on the line - the extra space will be - * shared amongst these if there are any, otherwise it will be added - * as space in between the elements - */ - extra = 0 ; - for (i = 0 ; i < line->n ; i++) { - if (line->items[i]->type == I_INPUT) - extra++ ; - } - if (extra == 0) { - if (line->n < 2) { /* same as L_CENTER */ - width = (max_width - line->size_x) / 2 + ITEM_HSPC; - for (i = 0; i < line->n; i++) { - line->items[i]->header.pos_x = width; - width += ITEM_HSPC + line->items[i]->header.size_x; - } - } else { - extra = (max_width - line->size_x) / (line->n - 1); - width = ITEM_HSPC; - for (i = 0; i < line->n; i++) { - line->items[i]->header.pos_x = width; - width += ITEM_HSPC + line->items[i]->header.size_x + extra; - } - } - } else { - extra = (max_width - line->size_x) / extra ; - width = ITEM_HSPC ; - for (i = 0 ; i < line->n ; i++) { - line->items[i]->header.pos_x = width ; - if (line->items[i]->type == I_INPUT) - line->items[i]->header.size_x += extra ; - width += ITEM_HSPC + line->items[i]->header.size_x ; - } - } - break; - } - } + int prog_name_len, i, j, l, extra; + char *line_buf; + char *cp; + Line *cur_line, *line; + Item *item, *cur_sel, *cur_button; + + /* ensure items array capacity (dynamic) */ + if (!items) { + items_capacity = INITIAL_ITEMS_CAPACITY; + items = (Item *)malloc(sizeof(Item) * items_capacity); + } + + n_items = 0; + + /* default line in case the first *FFLine is missing */ + ensure_line_capacity(1); + n_lines = 0; + cur_line = add_line(L_CENTER); + + /* default button is for initial functions */ + cur_button = &def_button; + def_button.button.n = 0; + if (!def_button.button.commands) { + def_button.button.commands = + (char **)malloc(sizeof(char *) * 8); + def_button.button.commands_cap = 8; + } + def_button.button.key = IB_CONTINUE; + cur_sel = NULL; + + /* default fonts in case the *FFFont's are missing */ + xfs[f_text] = xfs[f_input] = xfs[f_button] = + GetFontOrFixed(dpy, "fixed"); + fonts[f_text] = fonts[f_input] = fonts[f_button] = xfs[f_text]->fid; + + prog_name_len = strlen(prog_name); + + while (GetConfigLine(fd, &line_buf), line_buf) { + cp = line_buf; + while (isspace(*cp)) + cp++; /* skip blanks */ + if (*cp != '*') + continue; + if (strncmp(++cp, prog_name, prog_name_len) != 0) + continue; + cp += prog_name_len; + /* at this point we have recognized "*FvwmForm" */ + if (strncmp(cp, "GrabServer", 10) == 0) { + grab_server = 1; + continue; + } else if (strncmp(cp, "WarpPointer", 11) == 0) { + warp_pointer = 1; + } else if (strncmp(cp, "Position", 8) == 0) { + cp += 8; + geom = 1; + while (isspace(*cp)) + cp++; + gx = atoi(cp); + while (!isspace(*cp)) + cp++; + while (isspace(*cp)) + cp++; + gy = atoi(cp); + fprintf(fp_err, "Position @ (%d, %d)\n", gx, gy); + continue; + } else if (strncmp(cp, "Fore", 4) == 0) { + cp += 4; + while (isspace(*cp)) + cp++; + color_names[c_fore] = CopyNString(cp, 0); + fprintf(fp_err, "ColorFore: %s\n", color_names[c_fore]); + continue; + } else if (strncmp(cp, "Back", 4) == 0) { + cp += 4; + while (isspace(*cp)) + cp++; + color_names[c_back] = CopyNString(cp, 0); + fprintf(fp_err, "ColorBack: %s\n", color_names[c_back]); + continue; + } else if (strncmp(cp, "ItemFore", 8) == 0) { + cp += 8; + while (isspace(*cp)) + cp++; + color_names[c_itemfore] = CopyNString(cp, 0); + fprintf(fp_err, "ColorItemFore: %s\n", + color_names[c_itemfore]); + continue; + } else if (strncmp(cp, "ItemBack", 8) == 0) { + cp += 8; + while (isspace(*cp)) + cp++; + color_names[c_itemback] = CopyNString(cp, 0); + fprintf(fp_err, "ColorItemBack: %s\n", + color_names[c_itemback]); + continue; + } else if (strncmp(cp, "Font", 4) == 0) { + cp += 4; + while (isspace(*cp)) + cp++; + font_names[f_text] = CopyNString(cp, 0); + fprintf(fp_err, "Font: %s\n", font_names[f_text]); + xfs[f_text] = GetFontOrFixed(dpy, font_names[f_text]); + fonts[f_text] = xfs[f_text]->fid; + continue; + } else if (strncmp(cp, "ButtonFont", 10) == 0) { + cp += 10; + while (isspace(*cp)) + cp++; + font_names[f_button] = CopyNString(cp, 0); + fprintf( + fp_err, "ButtonFont: %s\n", font_names[f_button]); + xfs[f_button] = + GetFontOrFixed(dpy, font_names[f_button]); + fonts[f_button] = xfs[f_button]->fid; + continue; + } else if (strncmp(cp, "InputFont", 9) == 0) { + cp += 9; + while (isspace(*cp)) + cp++; + font_names[f_input] = CopyNString(cp, 0); + fprintf(fp_err, "InputFont: %s\n", font_names[f_input]); + xfs[f_input] = GetFontOrFixed(dpy, font_names[f_input]); + fonts[f_input] = xfs[f_input]->fid; + continue; + } else if (strncmp(cp, "Line", 4) == 0) { + cp += 4; + if (n_lines == 0) { + cur_line = add_line(L_CENTER); + } else if (n_lines == 1 && lines[0].n == 0) { + cur_line = &lines[0]; + cur_line->n = 0; + cur_line->size_x = 0; + cur_line->size_y = 0; + } else { + cur_line = add_line(L_CENTER); + } + while (isspace(*cp)) + cp++; + if (strncmp(cp, "left", 4) == 0) + cur_line->justify = L_LEFT; + else if (strncmp(cp, "right", 5) == 0) + cur_line->justify = L_RIGHT; + else if (strncmp(cp, "center", 6) == 0) + cur_line->justify = L_CENTER; + else + cur_line->justify = L_LEFTRIGHT; + cur_line->n = 0; + cur_line->size_x = cur_line->size_y = 0; + continue; + } else if (strncmp(cp, "Text", 4) == 0) { + /* syntax: *FFText "" */ + cp += 4; + if (n_items + 1 > items_capacity) { + items_capacity = items_capacity ? + items_capacity * 2 : + INITIAL_ITEMS_CAPACITY; + items = (Item *)realloc( + items, sizeof(Item) * items_capacity); + } + item = &items[n_items++]; + item->type = I_TEXT; + item->header.name = ""; + while (isspace(*cp)) + cp++; + if (*cp == '\"') + item->text.value = CopyQuotedString(++cp); + else + item->text.value = ""; + item->text.n = strlen(item->text.value); + item->header.size_x = + XTextWidth( + xfs[f_text], item->text.value, item->text.n) + + 2 * TEXT_SPC; + item->header.size_y = + FontHeight(xfs[f_text]) + 2 * TEXT_SPC; + fprintf(fp_err, "Text \"%s\" [%d, %d]\n", + item->text.value, item->header.size_x, + item->header.size_y); + append_item_to_line(cur_line, item); + continue; + } else if (strncmp(cp, "Input", 5) == 0) { + /* syntax: *FFInput "" */ + cp += 5; + if (n_items + 1 > items_capacity) { + items_capacity = items_capacity ? + items_capacity * 2 : + INITIAL_ITEMS_CAPACITY; + items = (Item *)realloc( + items, sizeof(Item) * items_capacity); + } + item = &items[n_items++]; + item->type = I_INPUT; + while (isspace(*cp)) + cp++; + item->header.name = CopySolidString(cp); + cp += strlen(item->header.name); + while (isspace(*cp)) + cp++; + item->input.size = atoi(cp); + while (!isspace(*cp)) + cp++; + while (isspace(*cp)) + cp++; + if (*cp == '\"') + item->input.init_value = CopyQuotedString(++cp); + else + item->input.init_value = ""; + item->input.blanks = (char *)malloc(item->input.size); + for (j = 0; j < item->input.size; j++) + item->input.blanks[j] = ' '; + item->input.buf = strlen(item->input.init_value) + 1; + item->input.value = (char *)malloc(item->input.buf); + item->header.size_x = + FontWidth(xfs[f_input]) * item->input.size + + 2 * TEXT_SPC + 2 * BOX_SPC; + item->header.size_y = FontHeight(xfs[f_input]) + + 3 * TEXT_SPC + 2 * BOX_SPC; + fprintf(fp_err, "Input, %s, [%d], \"%s\"\n", + item->header.name, item->input.size, + item->input.init_value); + append_item_to_line(cur_line, item); + } else if (strncmp(cp, "Selection", 9) == 0) { + /* syntax: *FFSelection single | multiple */ + cp += 9; + if (n_items + 1 > items_capacity) { + items_capacity = items_capacity ? + items_capacity * 2 : + INITIAL_ITEMS_CAPACITY; + items = (Item *)realloc( + items, sizeof(Item) * items_capacity); + } + cur_sel = &items[n_items++]; + cur_sel->type = I_SELECT; + while (isspace(*cp)) + cp++; + cur_sel->header.name = CopySolidString(cp); + cp += strlen(cur_sel->header.name); + while (isspace(*cp)) + cp++; + if (strncmp(cp, "multiple", 8) == 0) + cur_sel->select.key = IS_MULTIPLE; + else + cur_sel->select.key = IS_SINGLE; + cur_sel->select.n = 0; + cur_sel->select.choices_cap = INITIAL_CHOICES_CAPACITY; + cur_sel->select.choices = (Item **)malloc( + sizeof(Item *) * cur_sel->select.choices_cap); + cur_sel->header.size_x = 0; + cur_sel->header.size_y = 0; + fprintf(fp_err, "Selection %s (%s)\n", + cur_sel->header.name, + (cur_sel->select.key == IS_MULTIPLE) ? "multiple" : + "single"); + continue; + } else if (strncmp(cp, "Choice", 6) == 0) { + /* syntax: *FFChoice on|off "" */ + cp += 6; + while (isspace(*cp)) + cp++; + if (cur_sel == NULL) { + fprintf(fp_err, "Choice specified before " + "Selection, skipping\n"); + continue; + } + if (cur_sel->select.n + 1 > + cur_sel->select.choices_cap) { + cur_sel->select.choices_cap *= 2; + cur_sel->select.choices = + (Item **)realloc(cur_sel->select.choices, + sizeof(Item *) * + cur_sel->select.choices_cap); + } + if (n_items + 1 > items_capacity) { + items_capacity = items_capacity ? + items_capacity * 2 : + INITIAL_ITEMS_CAPACITY; + items = (Item *)realloc( + items, sizeof(Item) * items_capacity); + } + item = &items[n_items++]; + item->type = I_CHOICE; + item->choice.sel = cur_sel; + item->header.name = CopySolidString(cp); + cp += strlen(item->header.name); + while (isspace(*cp)) + cp++; + item->choice.value = CopySolidString(cp); + cp += strlen(item->choice.value); + while (isspace(*cp)) + cp++; + if (strncmp(cp, "on", 2) == 0) { + item->choice.on = 1; + item->choice.init_on = 1; + } else { + item->choice.on = 0; + item->choice.init_on = 0; + } + while (!isspace(*cp) && *cp != '\0') + cp++; + while (isspace(*cp)) + cp++; + if (*cp == '"') + item->choice.text = CopyQuotedString(++cp); + else + item->choice.text = ""; + item->choice.n = strlen(item->choice.text); + cur_sel->select.choices[cur_sel->select.n++] = item; + item->header.size_y = + FontHeight(xfs[f_text]) + 2 * TEXT_SPC; + item->header.size_x = + FontHeight(xfs[f_text]) + 4 * TEXT_SPC + + XTextWidth( + xfs[f_text], item->choice.text, item->choice.n); + fprintf(fp_err, "Choice %s, \"%s\", [%d, %d]\n", + item->header.name, item->choice.text, + item->header.size_x, item->header.size_y); + append_item_to_line(cur_line, item); + continue; + } else if (strncmp(cp, "Button", 6) == 0) { + /* syntax: *FFButton continue | restart | quit "" + */ + cp += 6; + if (n_items + 1 > items_capacity) { + items_capacity = items_capacity ? + items_capacity * 2 : + INITIAL_ITEMS_CAPACITY; + items = (Item *)realloc( + items, sizeof(Item) * items_capacity); + } + item = &items[n_items++]; + item->type = I_BUTTON; + item->header.name = ""; + while (isspace(*cp)) + cp++; + if (strncmp(cp, "restart", 7) == 0) + item->button.key = IB_RESTART; + else if (strncmp(cp, "quit", 4) == 0) + item->button.key = IB_QUIT; + else + item->button.key = IB_CONTINUE; + while (!isspace(*cp)) + cp++; + while (isspace(*cp)) + cp++; + if (*cp == '\"') { + item->button.text = CopyQuotedString(++cp); + cp += strlen(item->button.text) + 1; + while (isspace(*cp)) + cp++; + } else + item->button.text = ""; + if (*cp == '^') + item->button.keypress = *(++cp) - '@'; + else if (*cp == 'F') + item->button.keypress = 256 + atoi(++cp); + else + item->button.keypress = -1; + item->button.len = strlen(item->button.text); + item->button.n = 0; + item->button.commands = + (char **)malloc(sizeof(char *) * 8); + item->button.commands_cap = 8; + item->header.size_y = FontHeight(xfs[f_button]) + + 2 * TEXT_SPC + 2 * BOX_SPC; + item->header.size_x = + 2 * TEXT_SPC + 2 * BOX_SPC + + XTextWidth(xfs[f_button], item->button.text, + item->button.len); + append_item_to_line(cur_line, item); + cur_button = item; + continue; + } else if (strncmp(cp, "Command", 7) == 0) { + /* syntax: *FFCommand */ + cp += 7; + while (isspace(*cp)) + cp++; + if (cur_button->button.n + 1 > + cur_button->button.commands_cap) { + cur_button->button.commands_cap *= 2; + cur_button->button.commands = (char **)realloc( + cur_button->button.commands, + sizeof(char *) * + cur_button->button.commands_cap); + } + cur_button->button.commands[cur_button->button.n++] = + CopyNString(cp, 0); + } + } /* end of switch() */ + /* get the geometry right */ + max_width = 0; + total_height = ITEM_VSPC; + for (l = 0; l < n_lines; l++) { + line = lines + l; + for (i = 0; i < line->n; i++) { + line->items[i]->header.pos_y = total_height; + if (line->items[i]->header.size_y < line->size_y) + line->items[i]->header.pos_y += + (line->size_y - + line->items[i]->header.size_y) / + 2 + + 1; + } + total_height += ITEM_VSPC + line->size_y; + line->size_x += (line->n + 1) * ITEM_HSPC; + if (line->size_x > max_width) + max_width = line->size_x; + } + for (l = 0; l < n_lines; l++) { + int width; + line = lines + l; + fprintf(fp_err, "Line[%d], %d, %d items\n", l, line->justify, + line->n); + switch (line->justify) { + case L_LEFT: + width = ITEM_HSPC; + for (i = 0; i < line->n; i++) { + line->items[i]->header.pos_x = width; + width += + ITEM_HSPC + line->items[i]->header.size_x; + } + break; + case L_RIGHT: + width = max_width - line->size_x + ITEM_HSPC; + for (i = 0; i < line->n; i++) { + line->items[i]->header.pos_x = width; + width += + ITEM_HSPC + line->items[i]->header.size_x; + } + break; + case L_CENTER: + width = (max_width - line->size_x) / 2 + ITEM_HSPC; + for (i = 0; i < line->n; i++) { + line->items[i]->header.pos_x = width; + fprintf(fp_err, + "Line[%d], Item[%d] @ (%d, %d)\n", l, i, + line->items[i]->header.pos_x, + line->items[i]->header.pos_y); + width += + ITEM_HSPC + line->items[i]->header.size_x; + } + break; + case L_LEFTRIGHT: + /* count the number of inputs on the line - the extra + * space will be shared amongst these if there are any, + * otherwise it will be added as space in between the + * elements + */ + extra = 0; + for (i = 0; i < line->n; i++) { + if (line->items[i]->type == I_INPUT) + extra++; + } + if (extra == 0) { + if (line->n < 2) { /* same as L_CENTER */ + width = (max_width - line->size_x) / 2 + + ITEM_HSPC; + for (i = 0; i < line->n; i++) { + line->items[i]->header.pos_x = + width; + width += ITEM_HSPC + + line->items[i] + ->header.size_x; + } + } else { + extra = (max_width - line->size_x) / + (line->n - 1); + width = ITEM_HSPC; + for (i = 0; i < line->n; i++) { + line->items[i]->header.pos_x = + width; + width += ITEM_HSPC + + line->items[i] + ->header.size_x + + extra; + } + } + } else { + extra = (max_width - line->size_x) / extra; + width = ITEM_HSPC; + for (i = 0; i < line->n; i++) { + line->items[i]->header.pos_x = width; + if (line->items[i]->type == I_INPUT) + line->items[i]->header.size_x += + extra; + width += ITEM_HSPC + + line->items[i]->header.size_x; + } + } + break; + } + } } #define MAX_INTENSITY 65535 /* allocate color cells */ -void GetColors () +void +GetColors() { - Visual* visual = DefaultVisual(dpy, screen); - XColor xc_item; - int red, green, blue, tmp1, tmp2 ; - if (scr_depth < 8) { - colors[c_back] = colors[c_itemback] = WhitePixel(dpy, screen); - colors[c_fore] = colors[c_itemfore] = colors[c_itemlo] = colors[c_itemhi] - = BlackPixel(dpy, screen); - } else if (visual->class == TrueColor || - visual->class == StaticColor || - visual->class == StaticGray) { - if (XParseColor(dpy, d_cmap, color_names[c_fore], &xc_item) && - XAllocColor(dpy, d_cmap, &xc_item)) - colors[c_fore] = xc_item.pixel; - else - colors[c_fore] = BlackPixel(dpy, screen); - - if (XParseColor(dpy, d_cmap, color_names[c_back], &xc_item) && - XAllocColor(dpy, d_cmap, &xc_item)) - colors[c_back] = xc_item.pixel; - else - colors[c_back] = WhitePixel(dpy, screen); - - if (XParseColor(dpy, d_cmap, color_names[c_itemfore], &xc_item) && - XAllocColor(dpy, d_cmap, &xc_item)) - colors[c_itemfore] = xc_item.pixel; - else - colors[c_itemfore] = BlackPixel(dpy, screen); - - if (XParseColor(dpy, d_cmap, color_names[c_itemback], &xc_item) && - XAllocColor(dpy, d_cmap, &xc_item)) - colors[c_itemback] = xc_item.pixel; - else - colors[c_itemback] = WhitePixel(dpy, screen); - - InitPictureCMap(dpy,root); /* for shadow routines */ - colors[c_itemlo] = GetShadow(colors[c_itemback]); /* alloc shadow */ - colors[c_itemhi] = GetHilite(colors[c_itemback]); /* alloc shadow */ - } else if (!XAllocColorCells(dpy, d_cmap, 0, NULL, 0, colors, 6)) { - colors[c_back] = colors[c_itemback] = WhitePixel(dpy, screen); - colors[c_fore] = colors[c_itemfore] = colors[c_itemlo] = colors[c_itemhi] - = BlackPixel(dpy, screen); - } else { - XStoreNamedColor(dpy, d_cmap, color_names[c_fore], colors[c_fore], - DoRed | DoGreen | DoBlue); - XStoreNamedColor(dpy, d_cmap, color_names[c_back], colors[c_back], - DoRed | DoGreen | DoBlue); - XStoreNamedColor(dpy, d_cmap, color_names[c_itemfore], - colors[c_itemfore], DoRed | DoGreen | DoBlue); - XStoreNamedColor(dpy, d_cmap, color_names[c_itemback], - colors[c_itemback], DoRed | DoGreen | DoBlue); - XParseColor(dpy, d_cmap, color_names[c_itemback], &xc_item); - red = (int) xc_item.red ; - green = (int) xc_item.green ; - blue = (int) xc_item.blue ; - xc_item.red = (60 * red) / 100 ; - xc_item.green = (60 * green) / 100 ; - xc_item.blue = (60 * blue) / 100 ; - xc_item.pixel = colors[c_itemlo]; - xc_item.flags = DoRed | DoGreen | DoBlue; - XStoreColor(dpy, d_cmap, &xc_item); - XParseColor(dpy, d_cmap, color_names[c_itemback], &xc_item); - tmp1 = (14 * red) / 10 ; - if (tmp1 > MAX_INTENSITY) tmp1 = MAX_INTENSITY ; - tmp2 = (MAX_INTENSITY + red) / 2 ; - xc_item.red = (tmp1 > tmp2) ? tmp1 : tmp2 ; - tmp1 = (14 * green) / 10 ; - if (tmp1 > MAX_INTENSITY) tmp1 = MAX_INTENSITY ; - tmp2 = (MAX_INTENSITY + green) / 2 ; - xc_item.green = (tmp1 > tmp2) ? tmp1 : tmp2 ; - tmp1 = (14 * blue) / 10 ; - if (tmp1 > MAX_INTENSITY) tmp1 = MAX_INTENSITY ; - tmp2 = (MAX_INTENSITY + blue) / 2 ; - xc_item.blue = (tmp1 > tmp2) ? tmp1 : tmp2 ; - xc_item.pixel = colors[c_itemhi]; - xc_item.flags = DoRed | DoGreen | DoBlue; - XStoreColor(dpy, d_cmap, &xc_item); - } + Visual *visual = DefaultVisual(dpy, screen); + XColor xc_item; + int red, green, blue, tmp1, tmp2; + if (scr_depth < 8) { + colors[c_back] = colors[c_itemback] = WhitePixel(dpy, screen); + colors[c_fore] = colors[c_itemfore] = colors[c_itemlo] = + colors[c_itemhi] = BlackPixel(dpy, screen); + } else if (visual->class == TrueColor || visual->class == StaticColor || + visual->class == StaticGray) { + if (XParseColor(dpy, d_cmap, color_names[c_fore], &xc_item) && + XAllocColor(dpy, d_cmap, &xc_item)) + colors[c_fore] = xc_item.pixel; + else + colors[c_fore] = BlackPixel(dpy, screen); + + if (XParseColor(dpy, d_cmap, color_names[c_back], &xc_item) && + XAllocColor(dpy, d_cmap, &xc_item)) + colors[c_back] = xc_item.pixel; + else + colors[c_back] = WhitePixel(dpy, screen); + + if (XParseColor( + dpy, d_cmap, color_names[c_itemfore], &xc_item) && + XAllocColor(dpy, d_cmap, &xc_item)) + colors[c_itemfore] = xc_item.pixel; + else + colors[c_itemfore] = BlackPixel(dpy, screen); + + if (XParseColor( + dpy, d_cmap, color_names[c_itemback], &xc_item) && + XAllocColor(dpy, d_cmap, &xc_item)) + colors[c_itemback] = xc_item.pixel; + else + colors[c_itemback] = WhitePixel(dpy, screen); + + InitPictureCMap(dpy, root); /* for shadow routines */ + colors[c_itemlo] = + GetShadow(colors[c_itemback]); /* alloc shadow */ + colors[c_itemhi] = + GetHilite(colors[c_itemback]); /* alloc shadow */ + } else if (!XAllocColorCells(dpy, d_cmap, 0, NULL, 0, colors, 6)) { + colors[c_back] = colors[c_itemback] = WhitePixel(dpy, screen); + colors[c_fore] = colors[c_itemfore] = colors[c_itemlo] = + colors[c_itemhi] = BlackPixel(dpy, screen); + } else { + XStoreNamedColor(dpy, d_cmap, color_names[c_fore], + colors[c_fore], DoRed | DoGreen | DoBlue); + XStoreNamedColor(dpy, d_cmap, color_names[c_back], + colors[c_back], DoRed | DoGreen | DoBlue); + XStoreNamedColor(dpy, d_cmap, color_names[c_itemfore], + colors[c_itemfore], DoRed | DoGreen | DoBlue); + XStoreNamedColor(dpy, d_cmap, color_names[c_itemback], + colors[c_itemback], DoRed | DoGreen | DoBlue); + XParseColor(dpy, d_cmap, color_names[c_itemback], &xc_item); + red = (int)xc_item.red; + green = (int)xc_item.green; + blue = (int)xc_item.blue; + xc_item.red = (60 * red) / 100; + xc_item.green = (60 * green) / 100; + xc_item.blue = (60 * blue) / 100; + xc_item.pixel = colors[c_itemlo]; + xc_item.flags = DoRed | DoGreen | DoBlue; + XStoreColor(dpy, d_cmap, &xc_item); + XParseColor(dpy, d_cmap, color_names[c_itemback], &xc_item); + tmp1 = (14 * red) / 10; + if (tmp1 > MAX_INTENSITY) + tmp1 = MAX_INTENSITY; + tmp2 = (MAX_INTENSITY + red) / 2; + xc_item.red = (tmp1 > tmp2) ? tmp1 : tmp2; + tmp1 = (14 * green) / 10; + if (tmp1 > MAX_INTENSITY) + tmp1 = MAX_INTENSITY; + tmp2 = (MAX_INTENSITY + green) / 2; + xc_item.green = (tmp1 > tmp2) ? tmp1 : tmp2; + tmp1 = (14 * blue) / 10; + if (tmp1 > MAX_INTENSITY) + tmp1 = MAX_INTENSITY; + tmp2 = (MAX_INTENSITY + blue) / 2; + xc_item.blue = (tmp1 > tmp2) ? tmp1 : tmp2; + xc_item.pixel = colors[c_itemhi]; + xc_item.flags = DoRed | DoGreen | DoBlue; + XStoreColor(dpy, d_cmap, &xc_item); + } } /* reset all the values */ -void Restart () +void +Restart() { - int i; - Item *item; - - cur_text = NULL; - abs_cursor = rel_cursor = 0; - for (i = 0; i < n_items; i++) { - item = items + i; - switch (item->type) { - case I_INPUT: - if (!cur_text) - cur_text = item; - item->input.n = strlen(item->input.init_value); - strcpy(item->input.value, item->input.init_value); - item->input.left = 0; - item->input.o_cursor = 0; - break; - case I_CHOICE: - item->choice.on = item->choice.init_on; - break; - } - } + int i; + Item *item; + + cur_text = NULL; + abs_cursor = rel_cursor = 0; + for (i = 0; i < n_items; i++) { + item = items + i; + switch (item->type) { + case I_INPUT: + if (!cur_text) + cur_text = item; + size_t init_len = strlen(item->input.init_value); + item->input.n = init_len; + strlcpy(item->input.value, item->input.init_value, + item->input.buf); + item->input.left = 0; + item->input.o_cursor = 0; + break; + case I_CHOICE: + item->choice.on = item->choice.init_on; + break; + } + } } /* redraw the frame */ -void RedrawFrame () +void +RedrawFrame() { - int i, x, y; - Item *item; - - for (i = 0; i < n_items; i++) { - item = items + i; - switch (item->type) { - case I_TEXT: - x = item->header.pos_x + TEXT_SPC; - y = item->header.pos_y + TEXT_SPC + xfs[f_text]->ascent; - XDrawImageString(dpy, frame, gc_text, x, y, item->text.value, - item->text.n); - break; - case I_CHOICE: - x = item->header.pos_x + TEXT_SPC + item->header.size_y; - y = item->header.pos_y + TEXT_SPC + xfs[f_text]->ascent; - XDrawImageString(dpy, frame, gc_text, x, y, item->choice.text, - item->choice.n); - break; - } - } + int i, x, y; + Item *item; + + for (i = 0; i < n_items; i++) { + item = items + i; + switch (item->type) { + case I_TEXT: + x = item->header.pos_x + TEXT_SPC; + y = item->header.pos_y + TEXT_SPC + xfs[f_text]->ascent; + XDrawImageString(dpy, frame, gc_text, x, y, + item->text.value, item->text.n); + break; + case I_CHOICE: + x = item->header.pos_x + TEXT_SPC + item->header.size_y; + y = item->header.pos_y + TEXT_SPC + xfs[f_text]->ascent; + XDrawImageString(dpy, frame, gc_text, x, y, + item->choice.text, item->choice.n); + break; + } + } } /* redraw an item */ -void RedrawItem (Item *item, int click) +void +RedrawItem(Item *item, int click) { - int dx, dy, len, x; - static XSegment xsegs[4]; - - switch (item->type) { - case I_INPUT: - dx = item->header.size_x - 1; - dy = item->header.size_y - 1; - XSetForeground(dpy, gc_button, colors[c_itemlo]); - xsegs[0].x1 = 0, xsegs[0].y1 = 0; - xsegs[0].x2 = 0, xsegs[0].y2 = dy; - xsegs[1].x1 = 0, xsegs[1].y1 = 0; - xsegs[1].x2 = dx, xsegs[1].y2 = 0; - xsegs[2].x1 = 1, xsegs[2].y1 = 1; - xsegs[2].x2 = 1, xsegs[2].y2 = dy - 1; - xsegs[3].x1 = 1, xsegs[3].y1 = 1; - xsegs[3].x2 = dx - 1, xsegs[3].y2 = 1; - XDrawSegments(dpy, item->header.win, gc_button, xsegs, 4); - XSetForeground(dpy, gc_button, colors[c_itemhi]); - xsegs[0].x1 = 1, xsegs[0].y1 = dy; - xsegs[0].x2 = dx, xsegs[0].y2 = dy; - xsegs[1].x1 = 2, xsegs[1].y1 = dy - 1; - xsegs[1].x2 = dx, xsegs[1].y2 = dy - 1; - xsegs[2].x1 = dx, xsegs[2].y1 = 1; - xsegs[2].x2 = dx, xsegs[2].y2 = dy; - xsegs[3].x1 = dx - 1, xsegs[3].y1 = 2; - xsegs[3].x2 = dx - 1, xsegs[3].y2 = dy; - XDrawSegments(dpy, item->header.win, gc_button, xsegs, 4); - if (click) { - x = BOX_SPC + TEXT_SPC + FontWidth(xfs[f_input]) * abs_cursor - 1; - XSetForeground(dpy, gc_button, colors[c_itemback]); - XDrawLine(dpy, item->header.win, gc_button, - x, BOX_SPC, x, dy - BOX_SPC); - } - len = item->input.n - item->input.left; - if (len > item->input.size) - len = item->input.size; - else - XDrawImageString(dpy, item->header.win, gc_input, - BOX_SPC + TEXT_SPC + FontWidth(xfs[f_input]) * len, - BOX_SPC + TEXT_SPC + xfs[f_input]->ascent, - item->input.blanks, item->input.size - len); - XDrawImageString(dpy, item->header.win, gc_input, - BOX_SPC + TEXT_SPC, - BOX_SPC + TEXT_SPC + xfs[f_input]->ascent, - item->input.value + item->input.left, len); - if (item == cur_text && !click) { - x = BOX_SPC + TEXT_SPC + FontWidth(xfs[f_input]) * abs_cursor - 1; - XDrawLine(dpy, item->header.win, gc_input, - x, BOX_SPC, x, dy - BOX_SPC); - } - break; - case I_CHOICE: - dx = dy = item->header.size_y - 1; - if (item->choice.on) { - XSetForeground(dpy, gc_button, colors[c_itemfore]); - if (item->choice.sel->select.key == IS_MULTIPLE) { - xsegs[0].x1 = 5, xsegs[0].y1 = 5; - xsegs[0].x2 = dx - 5, xsegs[0].y2 = dy - 5; - xsegs[1].x1 = 5, xsegs[1].y1 = dy - 5; - xsegs[1].x2 = dx - 5, xsegs[1].y2 = 5; - XDrawSegments(dpy, item->header.win, gc_button, xsegs, 2); - } else { - XDrawArc(dpy, item->header.win, gc_button, - 5, 5, dx - 10, dy - 10, 0, 360 * 64); - } - } else - XClearWindow(dpy, item->header.win); - if (item->choice.on) - XSetForeground(dpy, gc_button, colors[c_itemlo]); - else - XSetForeground(dpy, gc_button, colors[c_itemhi]); - xsegs[0].x1 = 0, xsegs[0].y1 = 0; - xsegs[0].x2 = 0, xsegs[0].y2 = dy; - xsegs[1].x1 = 0, xsegs[1].y1 = 0; - xsegs[1].x2 = dx, xsegs[1].y2 = 0; - xsegs[2].x1 = 1, xsegs[2].y1 = 1; - xsegs[2].x2 = 1, xsegs[2].y2 = dy - 1; - xsegs[3].x1 = 1, xsegs[3].y1 = 1; - xsegs[3].x2 = dx - 1, xsegs[3].y2 = 1; - XDrawSegments(dpy, item->header.win, gc_button, xsegs, 4); - if (item->choice.on) - XSetForeground(dpy, gc_button, colors[c_itemhi]); - else - XSetForeground(dpy, gc_button, colors[c_itemlo]); - xsegs[0].x1 = 1, xsegs[0].y1 = dy; - xsegs[0].x2 = dx, xsegs[0].y2 = dy; - xsegs[1].x1 = 2, xsegs[1].y1 = dy - 1; - xsegs[1].x2 = dx, xsegs[1].y2 = dy - 1; - xsegs[2].x1 = dx, xsegs[2].y1 = 1; - xsegs[2].x2 = dx, xsegs[2].y2 = dy; - xsegs[3].x1 = dx - 1, xsegs[3].y1 = 2; - xsegs[3].x2 = dx - 1, xsegs[3].y2 = dy; - XDrawSegments(dpy, item->header.win, gc_button, xsegs, 4); - break; - case I_BUTTON: - dx = item->header.size_x - 1; - dy = item->header.size_y - 1; - if (click) - XSetForeground(dpy, gc_button, colors[c_itemlo]); - else - XSetForeground(dpy, gc_button, colors[c_itemhi]); - xsegs[0].x1 = 0, xsegs[0].y1 = 0; - xsegs[0].x2 = 0, xsegs[0].y2 = dy; - xsegs[1].x1 = 0, xsegs[1].y1 = 0; - xsegs[1].x2 = dx, xsegs[1].y2 = 0; - xsegs[2].x1 = 1, xsegs[2].y1 = 1; - xsegs[2].x2 = 1, xsegs[2].y2 = dy - 1; - xsegs[3].x1 = 1, xsegs[3].y1 = 1; - xsegs[3].x2 = dx - 1, xsegs[3].y2 = 1; - XDrawSegments(dpy, item->header.win, gc_button, xsegs, 4); - if (click) - XSetForeground(dpy, gc_button, colors[c_itemhi]); - else - XSetForeground(dpy, gc_button, colors[c_itemlo]); - xsegs[0].x1 = 1, xsegs[0].y1 = dy; - xsegs[0].x2 = dx, xsegs[0].y2 = dy; - xsegs[1].x1 = 2, xsegs[1].y1 = dy - 1; - xsegs[1].x2 = dx, xsegs[1].y2 = dy - 1; - xsegs[2].x1 = dx, xsegs[2].y1 = 1; - xsegs[2].x2 = dx, xsegs[2].y2 = dy; - xsegs[3].x1 = dx - 1, xsegs[3].y1 = 2; - xsegs[3].x2 = dx - 1, xsegs[3].y2 = dy; - XDrawSegments(dpy, item->header.win, gc_button, xsegs, 4); - XSetForeground(dpy, gc_button, colors[c_itemfore]); - XDrawImageString(dpy, item->header.win, gc_button, - BOX_SPC + TEXT_SPC, - BOX_SPC + TEXT_SPC + xfs[f_button]->ascent, - item->button.text, item->button.len); - break; - } - XFlush(dpy); + int dx, dy, len, x; + static XSegment xsegs[4]; + + switch (item->type) { + case I_INPUT: + dx = item->header.size_x - 1; + dy = item->header.size_y - 1; + XSetForeground(dpy, gc_button, colors[c_itemlo]); + xsegs[0].x1 = 0, xsegs[0].y1 = 0; + xsegs[0].x2 = 0, xsegs[0].y2 = dy; + xsegs[1].x1 = 0, xsegs[1].y1 = 0; + xsegs[1].x2 = dx, xsegs[1].y2 = 0; + xsegs[2].x1 = 1, xsegs[2].y1 = 1; + xsegs[2].x2 = 1, xsegs[2].y2 = dy - 1; + xsegs[3].x1 = 1, xsegs[3].y1 = 1; + xsegs[3].x2 = dx - 1, xsegs[3].y2 = 1; + XDrawSegments(dpy, item->header.win, gc_button, xsegs, 4); + XSetForeground(dpy, gc_button, colors[c_itemhi]); + xsegs[0].x1 = 1, xsegs[0].y1 = dy; + xsegs[0].x2 = dx, xsegs[0].y2 = dy; + xsegs[1].x1 = 2, xsegs[1].y1 = dy - 1; + xsegs[1].x2 = dx, xsegs[1].y2 = dy - 1; + xsegs[2].x1 = dx, xsegs[2].y1 = 1; + xsegs[2].x2 = dx, xsegs[2].y2 = dy; + xsegs[3].x1 = dx - 1, xsegs[3].y1 = 2; + xsegs[3].x2 = dx - 1, xsegs[3].y2 = dy; + XDrawSegments(dpy, item->header.win, gc_button, xsegs, 4); + if (click) { + x = BOX_SPC + TEXT_SPC + + FontWidth(xfs[f_input]) * abs_cursor - 1; + XSetForeground(dpy, gc_button, colors[c_itemback]); + XDrawLine(dpy, item->header.win, gc_button, x, BOX_SPC, + x, dy - BOX_SPC); + } + len = item->input.n - item->input.left; + if (len > item->input.size) + len = item->input.size; + else + XDrawImageString(dpy, item->header.win, gc_input, + BOX_SPC + TEXT_SPC + FontWidth(xfs[f_input]) * len, + BOX_SPC + TEXT_SPC + xfs[f_input]->ascent, + item->input.blanks, item->input.size - len); + XDrawImageString(dpy, item->header.win, gc_input, + BOX_SPC + TEXT_SPC, + BOX_SPC + TEXT_SPC + xfs[f_input]->ascent, + item->input.value + item->input.left, len); + if (item == cur_text && !click) { + x = BOX_SPC + TEXT_SPC + + FontWidth(xfs[f_input]) * abs_cursor - 1; + XDrawLine(dpy, item->header.win, gc_input, x, BOX_SPC, + x, dy - BOX_SPC); + } + break; + case I_CHOICE: + dx = dy = item->header.size_y - 1; + if (item->choice.on) { + XSetForeground(dpy, gc_button, colors[c_itemfore]); + if (item->choice.sel->select.key == IS_MULTIPLE) { + xsegs[0].x1 = 5, xsegs[0].y1 = 5; + xsegs[0].x2 = dx - 5, xsegs[0].y2 = dy - 5; + xsegs[1].x1 = 5, xsegs[1].y1 = dy - 5; + xsegs[1].x2 = dx - 5, xsegs[1].y2 = 5; + XDrawSegments( + dpy, item->header.win, gc_button, xsegs, 2); + } else { + XDrawArc(dpy, item->header.win, gc_button, 5, 5, + dx - 10, dy - 10, 0, 360 * 64); + } + } else + XClearWindow(dpy, item->header.win); + if (item->choice.on) + XSetForeground(dpy, gc_button, colors[c_itemlo]); + else + XSetForeground(dpy, gc_button, colors[c_itemhi]); + xsegs[0].x1 = 0, xsegs[0].y1 = 0; + xsegs[0].x2 = 0, xsegs[0].y2 = dy; + xsegs[1].x1 = 0, xsegs[1].y1 = 0; + xsegs[1].x2 = dx, xsegs[1].y2 = 0; + xsegs[2].x1 = 1, xsegs[2].y1 = 1; + xsegs[2].x2 = 1, xsegs[2].y2 = dy - 1; + xsegs[3].x1 = 1, xsegs[3].y1 = 1; + xsegs[3].x2 = dx - 1, xsegs[3].y2 = 1; + XDrawSegments(dpy, item->header.win, gc_button, xsegs, 4); + if (item->choice.on) + XSetForeground(dpy, gc_button, colors[c_itemhi]); + else + XSetForeground(dpy, gc_button, colors[c_itemlo]); + xsegs[0].x1 = 1, xsegs[0].y1 = dy; + xsegs[0].x2 = dx, xsegs[0].y2 = dy; + xsegs[1].x1 = 2, xsegs[1].y1 = dy - 1; + xsegs[1].x2 = dx, xsegs[1].y2 = dy - 1; + xsegs[2].x1 = dx, xsegs[2].y1 = 1; + xsegs[2].x2 = dx, xsegs[2].y2 = dy; + xsegs[3].x1 = dx - 1, xsegs[3].y1 = 2; + xsegs[3].x2 = dx - 1, xsegs[3].y2 = dy; + XDrawSegments(dpy, item->header.win, gc_button, xsegs, 4); + break; + case I_BUTTON: + dx = item->header.size_x - 1; + dy = item->header.size_y - 1; + if (click) + XSetForeground(dpy, gc_button, colors[c_itemlo]); + else + XSetForeground(dpy, gc_button, colors[c_itemhi]); + xsegs[0].x1 = 0, xsegs[0].y1 = 0; + xsegs[0].x2 = 0, xsegs[0].y2 = dy; + xsegs[1].x1 = 0, xsegs[1].y1 = 0; + xsegs[1].x2 = dx, xsegs[1].y2 = 0; + xsegs[2].x1 = 1, xsegs[2].y1 = 1; + xsegs[2].x2 = 1, xsegs[2].y2 = dy - 1; + xsegs[3].x1 = 1, xsegs[3].y1 = 1; + xsegs[3].x2 = dx - 1, xsegs[3].y2 = 1; + XDrawSegments(dpy, item->header.win, gc_button, xsegs, 4); + if (click) + XSetForeground(dpy, gc_button, colors[c_itemhi]); + else + XSetForeground(dpy, gc_button, colors[c_itemlo]); + xsegs[0].x1 = 1, xsegs[0].y1 = dy; + xsegs[0].x2 = dx, xsegs[0].y2 = dy; + xsegs[1].x1 = 2, xsegs[1].y1 = dy - 1; + xsegs[1].x2 = dx, xsegs[1].y2 = dy - 1; + xsegs[2].x1 = dx, xsegs[2].y1 = 1; + xsegs[2].x2 = dx, xsegs[2].y2 = dy; + xsegs[3].x1 = dx - 1, xsegs[3].y1 = 2; + xsegs[3].x2 = dx - 1, xsegs[3].y2 = dy; + XDrawSegments(dpy, item->header.win, gc_button, xsegs, 4); + XSetForeground(dpy, gc_button, colors[c_itemfore]); + XDrawImageString(dpy, item->header.win, gc_button, + BOX_SPC + TEXT_SPC, + BOX_SPC + TEXT_SPC + xfs[f_button]->ascent, + item->button.text, item->button.len); + break; + } + XFlush(dpy); } -void ToggleChoice (Item *item) +void +ToggleChoice(Item *item) { - int i; - Item *sel = item->choice.sel; - - if (sel->select.key == IS_SINGLE) { - if (!item->choice.on) { - for (i = 0; i < sel->select.n; i++) { - if (sel->select.choices[i]->choice.on) { - sel->select.choices[i]->choice.on = 0; - RedrawItem(sel->select.choices[i], 0); + int i; + Item *sel = item->choice.sel; + + if (sel->select.key == IS_SINGLE) { + if (!item->choice.on) { + for (i = 0; i < sel->select.n; i++) { + if (sel->select.choices[i]->choice.on) { + sel->select.choices[i]->choice.on = 0; + RedrawItem(sel->select.choices[i], 0); + } + } + item->choice.on = 1; + RedrawItem(item, 0); + } + } else { /* IS_MULTIPLE */ + item->choice.on = !item->choice.on; + RedrawItem(item, 0); } - } - item->choice.on = 1; - RedrawItem(item, 0); - } - } else { /* IS_MULTIPLE */ - item->choice.on = !item->choice.on; - RedrawItem(item, 0); - } } /* do var substitution for command string */ -void ParseCommand (int dn, char *sp, char end, int *dn1, char **sp1) -#define AddChar(chr) { if (dn >= N) { N *= 2; buf = (char *)realloc(buf, N); } buf[dn++] = (chr); } -{ - static char var[256]; - char c, x, *wp, *cp, *vp; - int i, j, dn2; - Item *item; - - while (1) { - c = *(sp++); - if (c == '\0' || c == end) { /* end of substitution */ - *dn1 = dn; - *sp1 = sp; - return; - } if (c == '\\') { /* escape char */ - AddChar('\\'); - AddChar(*(sp++)); - goto next_loop; - } - if (c == '$') { /* variable */ - if (*sp != '(') - goto normal_char; - wp = ++sp; - vp = var; - while (1) { - x = *(sp++); - if (x == '\\') { - *(vp++) = '\\'; - *(vp++) = *(sp++); - } - else if (x == ')' || x == '?' || x == '!') { - *(vp++) = '\0'; - break; +void +ParseCommand(int dn, char *sp, char end, int *dn1, char **sp1) +#define AddChar(chr) \ + { \ + if (dn >= N) { \ + N *= 2; \ + buf = (char *)realloc(buf, N); \ + } \ + buf[dn++] = (chr); \ } - else if (!isspace(x)) - *(vp++) = x; - } - for (i = 0; i < n_items; i++) { - item = items + i; - if (strcmp(var, item->header.name) == 0) { - switch (item->type) { - case I_INPUT: - if (x == ')') { - for (cp = item->input.value; *cp != '\0'; cp++) { - if (*cp == '\"' || *cp == '\'' || *cp == '\\') - AddChar('\\'); - AddChar(*cp); - } - } else { - ParseCommand(dn, sp, ')', &dn2, &sp); - if ((x == '?' && strlen(item->input.value) > 0) || - (x == '!' && strlen(item->input.value) == 0)) - dn = dn2; - } - break; - case I_CHOICE: - if (x == ')') { - for (cp = item->choice.value; *cp != '\0'; cp++) - AddChar(*cp); - } else { - ParseCommand(dn, sp, ')', &dn2, &sp); - if ((x == '?' && item->choice.on) || - (x == '!' && !item->choice.on)) - dn = dn2; - } - break; - case I_SELECT: - if (x != ')') - ParseCommand(dn, sp, ')', &dn2, &sp); - AddChar(' '); - for (j = 0; j < item->select.n; j++) { - if (item->select.choices[j]->choice.on) { - for (cp = item->select.choices[j]->choice.value; - *cp != '\0'; cp++) - AddChar(*cp); - AddChar(' '); - } - } - break; - } - goto next_loop; +{ + static char var[256]; + char c, x, *wp, *cp, *vp; + int i, j, dn2; + Item *item; + + while (1) { + c = *(sp++); + if (c == '\0' || c == end) { /* end of substitution */ + *dn1 = dn; + *sp1 = sp; + return; + } + if (c == '\\') { /* escape char */ + AddChar('\\'); + AddChar(*(sp++)); + goto next_loop; + } + if (c == '$') { /* variable */ + if (*sp != '(') + goto normal_char; + wp = ++sp; + vp = var; + while (1) { + x = *(sp++); + if (x == '\\') { + *(vp++) = '\\'; + *(vp++) = *(sp++); + } else if (x == ')' || x == '?' || x == '!') { + *(vp++) = '\0'; + break; + } else if (!isspace(x)) + *(vp++) = x; + } + for (i = 0; i < n_items; i++) { + item = items + i; + if (strcmp(var, item->header.name) == 0) { + switch (item->type) { + case I_INPUT: + if (x == ')') { + for (cp = item->input + .value; + *cp != '\0'; cp++) { + if (*cp == + '\"' || + *cp == + '\'' || + *cp == '\\') + AddChar( + '\\'); + AddChar(*cp); + } + } else { + ParseCommand(dn, sp, + ')', &dn2, &sp); + if ((x == '?' && + strlen( + item->input + .value) > + 0) || + (x == '!' && + strlen( + item->input + .value) == + 0)) + dn = dn2; + } + break; + case I_CHOICE: + if (x == ')') { + for (cp = item->choice + .value; + *cp != '\0'; cp++) + AddChar(*cp); + } else { + ParseCommand(dn, sp, + ')', &dn2, &sp); + if ((x == '?' && + item->choice + .on) || + (x == '!' && + !item->choice + .on)) + dn = dn2; + } + break; + case I_SELECT: + if (x != ')') + ParseCommand(dn, sp, + ')', &dn2, &sp); + AddChar(' '); + for (j = 0; j < item->select.n; + j++) { + if (item->select + .choices[j] + ->choice.on) { + for (cp = item + ->select + .choices + [j] + ->choice + .value; + *cp != '\0'; + cp++) + AddChar( + *cp); + AddChar(' '); + } + } + break; + } + goto next_loop; + } + } + goto next_loop; + } + normal_char: + AddChar(c); + next_loop: ; } - } - goto next_loop; - } - normal_char: - AddChar(c); - next_loop: - ; - } } /* execute a command */ -void DoCommand (Item *cmd) +void +DoCommand(Item *cmd) { - int i, k, dn, len; - char *sp; - - /* pre-command */ - if (cmd->button.key == IB_QUIT) - XWithdrawWindow(dpy, frame, screen); - - for (k = 0; k < cmd->button.n; k++) { - /* construct command */ - ParseCommand(0, cmd->button.commands[k], '\0', &dn, &sp); - AddChar('\0'); - fprintf(fp_err, "Final command[%d]: [%s]\n", k, buf); - - /* send command */ - write(fd_out, &ref, sizeof(Window)); - len = strlen(buf); - write(fd_out, &len, sizeof(int)); - write(fd_out, buf, len); - len = 1; - write(fd_out, &len, sizeof(int)); - } - - /* post-command */ - if (cmd->button.key == IB_QUIT) { - if (grab_server) - XUngrabServer(dpy); - exit(0); - } - if (cmd->button.key == IB_RESTART) { - Restart(); - for (i = 0; i < n_items; i++) { - if (items[i].type == I_INPUT) { - XClearWindow(dpy, items[i].header.win); - RedrawItem(items + i, 0); - } - if (items[i].type == I_CHOICE) - RedrawItem(items + i, 0); - } - } + int i, k, dn, len; + char *sp; + + /* pre-command */ + if (cmd->button.key == IB_QUIT) + XWithdrawWindow(dpy, frame, screen); + + for (k = 0; k < cmd->button.n; k++) { + /* construct command */ + ParseCommand(0, cmd->button.commands[k], '\0', &dn, &sp); + AddChar('\0'); + fprintf(fp_err, "Final command[%d]: [%s]\n", k, buf); + + /* send command */ + write(fd_out, &ref, sizeof(Window)); + len = strlen(buf); + write(fd_out, &len, sizeof(int)); + write(fd_out, buf, len); + len = 1; + write(fd_out, &len, sizeof(int)); + } + + /* post-command */ + if (cmd->button.key == IB_QUIT) { + if (grab_server) + XUngrabServer(dpy); + exit(0); + } + if (cmd->button.key == IB_RESTART) { + Restart(); + for (i = 0; i < n_items; i++) { + if (items[i].type == I_INPUT) { + XClearWindow(dpy, items[i].header.win); + RedrawItem(items + i, 0); + } + if (items[i].type == I_CHOICE) + RedrawItem(items + i, 0); + } + } } /* open the windows */ -void OpenWindows () +void +OpenWindows() { - int i, x, y; - Item *item; - static XColor xcf, xcb; - static XSetWindowAttributes xswa; - static XGCValues xgcv; - static XWMHints wmh = { InputHint, True }; - static XSizeHints sh = { PPosition | PSize | USPosition | USSize }; - static int xgcv_mask = GCBackground | GCForeground | GCFont; - - xc_ibeam = XCreateFontCursor(dpy, XC_xterm); - xc_hand = XCreateFontCursor(dpy, XC_hand2); - xcf.pixel = WhitePixel(dpy, screen); - XQueryColor(dpy, d_cmap, &xcf); - xcb.pixel = colors[c_itemback]; - XQueryColor(dpy, d_cmap, &xcb); - XRecolorCursor(dpy, xc_ibeam, &xcf, &xcb); - - /* the frame window first */ - if (geom) { - if (gx >= 0) - x = gx; - else - x = DisplayWidth(dpy, screen) - max_width + gx; - if (gy >= 0) - y = gy; - else - y = DisplayHeight(dpy, screen) - total_height + gy; - } else { - x = (DisplayWidth(dpy, screen) - max_width) / 2; - y = (DisplayHeight(dpy, screen) - total_height) / 2; - } - frame = XCreateSimpleWindow(dpy, root, x, y, max_width, total_height, - 0, BlackPixel(dpy, screen), colors[c_back]); - XSelectInput(dpy, frame, KeyPressMask | ExposureMask); - XStoreName(dpy, frame, prog_name); - XSetWMHints(dpy, frame, &wmh); - sh.x = x, sh.y = y; - sh.width = max_width, sh.height = total_height; - XSetWMNormalHints(dpy, frame, &sh); - - xgcv.foreground = colors[c_fore]; - xgcv.background = colors[c_back]; - xgcv.font = fonts[f_text]; - gc_text = XCreateGC(dpy, frame, xgcv_mask, &xgcv); - xgcv.background = colors[c_itemback]; - xgcv.foreground = colors[c_itemfore]; - xgcv.font = fonts[f_input]; - gc_input = XCreateGC(dpy, frame, xgcv_mask, &xgcv); - xgcv.font = fonts[f_button]; - gc_button = XCreateGC(dpy, frame, xgcv_mask, &xgcv); - - for (i = 0; i < n_items; i++) { - item = items + i; - switch (item->type) { - case I_INPUT: - item->header.win = - XCreateSimpleWindow(dpy, frame, + int i, x, y; + Item *item; + static XColor xcf, xcb; + static XSetWindowAttributes xswa; + static XGCValues xgcv; + static XWMHints wmh = {InputHint, True}; + static XSizeHints sh = {PPosition | PSize | USPosition | USSize}; + static int xgcv_mask = GCBackground | GCForeground | GCFont; + + xc_ibeam = XCreateFontCursor(dpy, XC_xterm); + xc_hand = XCreateFontCursor(dpy, XC_hand2); + xcf.pixel = WhitePixel(dpy, screen); + XQueryColor(dpy, d_cmap, &xcf); + xcb.pixel = colors[c_itemback]; + XQueryColor(dpy, d_cmap, &xcb); + XRecolorCursor(dpy, xc_ibeam, &xcf, &xcb); + + /* the frame window first */ + if (geom) { + if (gx >= 0) + x = gx; + else + x = DisplayWidth(dpy, screen) - max_width + gx; + if (gy >= 0) + y = gy; + else + y = DisplayHeight(dpy, screen) - total_height + gy; + } else { + x = (DisplayWidth(dpy, screen) - max_width) / 2; + y = (DisplayHeight(dpy, screen) - total_height) / 2; + } + frame = XCreateSimpleWindow(dpy, root, x, y, max_width, total_height, 0, + BlackPixel(dpy, screen), colors[c_back]); + XSelectInput(dpy, frame, KeyPressMask | ExposureMask); + XStoreName(dpy, frame, prog_name); + XSetWMHints(dpy, frame, &wmh); + sh.x = x, sh.y = y; + sh.width = max_width, sh.height = total_height; + XSetWMNormalHints(dpy, frame, &sh); + + xgcv.foreground = colors[c_fore]; + xgcv.background = colors[c_back]; + xgcv.font = fonts[f_text]; + gc_text = XCreateGC(dpy, frame, xgcv_mask, &xgcv); + xgcv.background = colors[c_itemback]; + xgcv.foreground = colors[c_itemfore]; + xgcv.font = fonts[f_input]; + gc_input = XCreateGC(dpy, frame, xgcv_mask, &xgcv); + xgcv.font = fonts[f_button]; + gc_button = XCreateGC(dpy, frame, xgcv_mask, &xgcv); + + for (i = 0; i < n_items; i++) { + item = items + i; + switch (item->type) { + case I_INPUT: + item->header.win = XCreateSimpleWindow(dpy, frame, item->header.pos_x, item->header.pos_y, - item->header.size_x, item->header.size_y, - 0, colors[c_back], colors[c_itemback]); - XSelectInput(dpy, item->header.win, ButtonPressMask | ExposureMask); - xswa.cursor = xc_ibeam; - XChangeWindowAttributes(dpy, item->header.win, CWCursor, &xswa); - break; - case I_CHOICE: - item->header.win = - XCreateSimpleWindow(dpy, frame, + item->header.size_x, item->header.size_y, 0, + colors[c_back], colors[c_itemback]); + XSelectInput(dpy, item->header.win, + ButtonPressMask | ExposureMask); + xswa.cursor = xc_ibeam; + XChangeWindowAttributes( + dpy, item->header.win, CWCursor, &xswa); + break; + case I_CHOICE: + item->header.win = XCreateSimpleWindow(dpy, frame, item->header.pos_x, item->header.pos_y, - item->header.size_y, item->header.size_y, - 0, colors[c_back], colors[c_itemback]); - XSelectInput(dpy, item->header.win, ButtonPressMask | ExposureMask); - xswa.cursor = xc_hand; - XChangeWindowAttributes(dpy, item->header.win, CWCursor, &xswa); - break; - case I_BUTTON: - item->header.win = - XCreateSimpleWindow(dpy, frame, + item->header.size_y, item->header.size_y, 0, + colors[c_back], colors[c_itemback]); + XSelectInput(dpy, item->header.win, + ButtonPressMask | ExposureMask); + xswa.cursor = xc_hand; + XChangeWindowAttributes( + dpy, item->header.win, CWCursor, &xswa); + break; + case I_BUTTON: + item->header.win = XCreateSimpleWindow(dpy, frame, item->header.pos_x, item->header.pos_y, - item->header.size_x, item->header.size_y, - 0, colors[c_back], colors[c_itemback]); - XSelectInput(dpy, item->header.win, - ButtonPressMask | ExposureMask); - xswa.cursor = xc_hand; - XChangeWindowAttributes(dpy, item->header.win, CWCursor, &xswa); - break; - } - } - Restart(); - XMapRaised(dpy, frame); - XMapSubwindows(dpy, frame); - if (warp_pointer) { - XWarpPointer(dpy, None, frame, 0, 0, 0, 0, - max_width / 2, total_height - 1); - } - DoCommand(&def_button); + item->header.size_x, item->header.size_y, 0, + colors[c_back], colors[c_itemback]); + XSelectInput(dpy, item->header.win, + ButtonPressMask | ExposureMask); + xswa.cursor = xc_hand; + XChangeWindowAttributes( + dpy, item->header.win, CWCursor, &xswa); + break; + } + } + Restart(); + XMapRaised(dpy, frame); + XMapSubwindows(dpy, frame); + if (warp_pointer) { + XWarpPointer(dpy, None, frame, 0, 0, 0, 0, max_width / 2, + total_height - 1); + } + DoCommand(&def_button); } /* read something from Fvwm */ -void ReadFvwm () +void +ReadFvwm() { - static char buffer[32]; - int n; - - n = read(fd_in, buffer, 32); - if (n == 0) { - if (grab_server) - XUngrabServer(dpy); - exit(0); - } + static char buffer[32]; + int n; + + n = read(fd_in, buffer, 32); + if (n == 0) { + if (grab_server) + XUngrabServer(dpy); + exit(0); + } } /* read an X event */ -void ReadXServer () +void +ReadXServer() { - static XEvent event; - int i, old_cursor, keypress; - Item *item, *old_item; - KeySym ks; - char *sp, *dp, *ep; - static unsigned char buf[10], n; - - while (XEventsQueued(dpy, QueuedAfterReading)) { - XNextEvent(dpy, &event); - if (event.xany.window == frame) { - switch (event.type) { - case Expose: - RedrawFrame(); - if (grab_server && !server_grabbed) { - if (GrabSuccess == - XGrabPointer(dpy, frame, True, 0, GrabModeAsync, GrabModeAsync, - None, None, CurrentTime)) - server_grabbed = 1; - } - break; - case KeyPress: /* we do text input here */ - n = XLookupString(&event.xkey, buf, 10, &ks, NULL); - keypress = buf[0]; - fprintf(fp_err, "Keypress [%s]\n", buf); - if (n == 0) { /* not a regular key, translate it into one */ - switch (ks) { - case XK_Home: - case XK_Begin: - buf[0] = '\001'; /* ^A */ - break; - case XK_End: - buf[0] = '\005'; /* ^E */ - break; - case XK_Left: - buf[0] = '\002'; /* ^B */ - break; - case XK_Right: - buf[0] = '\006'; /* ^F */ - break; - case XK_Up: - buf[0] = '\020'; /* ^P */ - break; - case XK_Down: - buf[0] = '\016'; /* ^N */ - break; - default: - if (ks >= XK_F1 && ks <= XK_F35) { - buf[0] = '\0'; - keypress = 257 + ks - XK_F1; - } else - goto no_redraw; /* no action for this event */ - } - } - if (!cur_text) { /* no text input fields */ - for (i = 0; i < n_items; i++) { - item = items + i; - fprintf(fp_err, "Button[%d], keypress==%d\n", i, - item->button.keypress); - if (item->type == I_BUTTON && item->button.keypress == buf[0]) { - RedrawItem(item, 1); - sleep(1); - RedrawItem(item, 0); - DoCommand(item); - goto no_redraw; - } - } - break; - } - switch (buf[0]) { - case '\001': /* ^A */ - old_cursor = abs_cursor; - rel_cursor = 0; - abs_cursor = 0; - cur_text->input.left = 0; - goto redraw_newcursor; - break; - case '\005': /* ^E */ - old_cursor = abs_cursor; - rel_cursor = cur_text->input.n; - if ((cur_text->input.left = rel_cursor - cur_text->input.size) < 0) - cur_text->input.left = 0; - abs_cursor = rel_cursor - cur_text->input.left; - goto redraw_newcursor; - break; - case '\002': /* ^B */ - old_cursor = abs_cursor; - if (rel_cursor > 0) { - rel_cursor--; - abs_cursor--; - if (abs_cursor <= 0 && rel_cursor > 0) { - abs_cursor++; - cur_text->input.left--; - } - } - goto redraw_newcursor; - break; - case '\006': /* ^F */ - old_cursor = abs_cursor; - if (rel_cursor < cur_text->input.n) { - rel_cursor++; - abs_cursor++; - if (abs_cursor >= cur_text->input.size && - rel_cursor < cur_text->input.n) { - abs_cursor--; - cur_text->input.left++; - } - } - goto redraw_newcursor; - break; - case '\010': /* ^H */ - old_cursor = abs_cursor; - if (rel_cursor > 0) { - sp = cur_text->input.value + rel_cursor; - dp = sp - 1; - for (; *dp = *sp, *sp != '\0'; dp++, sp++); - cur_text->input.n--; - rel_cursor--; - if (rel_cursor < abs_cursor) { - abs_cursor--; - if (abs_cursor <= 0 && rel_cursor > 0) { - abs_cursor++; - cur_text->input.left--; - } - } else - cur_text->input.left--; - } - goto redraw_newcursor; - break; - case '\177': /* DEL */ - case '\004': /* ^D */ - if (rel_cursor < cur_text->input.n) { - sp = cur_text->input.value + rel_cursor + 1; - dp = sp - 1; - for (; *dp = *sp, *sp != '\0'; dp++, sp++); - cur_text->input.n--; - goto redraw; - } - break; - case '\013': /* ^K */ - cur_text->input.value[rel_cursor] = '\0'; - cur_text->input.n = rel_cursor; - goto redraw; - case '\025': /* ^U */ - old_cursor = abs_cursor; - cur_text->input.value[0] = '\0'; - cur_text->input.n = cur_text->input.left = 0; - rel_cursor = abs_cursor = 0; - goto redraw_newcursor; - case '\t': - case '\n': - case '\015': - case '\016': /* LINEFEED, TAB, RETURN, ^N, jump to the next field */ - for (i = (cur_text - items) + 1; i < n_items; i++) { - item = items + i; - if (item->type == I_INPUT) { - old_item = cur_text; - old_item->input.o_cursor = rel_cursor; - cur_text = item; - RedrawItem(old_item, 1); - rel_cursor = item->input.o_cursor; - abs_cursor = rel_cursor - item->input.left; - goto redraw; - } - } - /* end of all text input fields, check for buttons */ - for (i = 0; i < n_items; i++) { - item = items + i; - fprintf(fp_err, "Button[%d], keypress==%d\n", i, - item->button.keypress); - if (item->type == I_BUTTON && item->button.keypress == buf[0]) { - RedrawItem(item, 1); - sleep(1); - RedrawItem(item, 0); - DoCommand(item); - goto no_redraw; - } - } - /* goto the first text input field */ - for (i = 0; i < n_items; i++) { - item = items + i; - if (item->type == I_INPUT) { - old_item = cur_text; - old_item->input.o_cursor = rel_cursor; - cur_text = item; - RedrawItem(old_item, 1); - rel_cursor = item->input.o_cursor; - abs_cursor = rel_cursor - item->input.left; - goto redraw; - } - } - break; - default: - old_cursor = abs_cursor; - if((buf[0] >= ' ' && - buf[0] < '\177') || - (buf[0] >= 160)) { /* regular or intl char */ - if (++(cur_text->input.n) >= cur_text->input.buf) { - cur_text->input.buf += cur_text->input.size; - cur_text->input.value = - (char *)realloc(cur_text->input.value, - cur_text->input.buf); - } - dp = cur_text->input.value + cur_text->input.n; - sp = dp - 1; - ep = cur_text->input.value + rel_cursor; - for (; *dp = *sp, sp != ep; sp--, dp--); - *ep = buf[0]; - rel_cursor++; - abs_cursor++; - if (abs_cursor >= cur_text->input.size) { - if (rel_cursor < cur_text->input.n) - abs_cursor = cur_text->input.size - 1; - else - abs_cursor = cur_text->input.size; - cur_text->input.left = rel_cursor - abs_cursor; - } - goto redraw_newcursor; - } - /* unrecognized key press, check for buttons */ - for (i = 0; i < n_items; i++) { - item = items + i; - fprintf(fp_err, "Button[%d], keypress==%d\n", i, - item->button.keypress); - if (item->type == I_BUTTON && item->button.keypress == keypress) { - RedrawItem(item, 1); - sleep(1); /* .5 seconds */ - RedrawItem(item, 0); - DoCommand(item); - goto no_redraw; - } - } - break; - } - redraw_newcursor: - { - int x, dy; - x = BOX_SPC + TEXT_SPC + FontWidth(xfs[f_input]) * old_cursor - 1; - dy = cur_text->header.size_y - 1; - XSetForeground(dpy, gc_button, colors[c_itemback]); - XDrawLine(dpy, cur_text->header.win, gc_button, - x, BOX_SPC, x, dy - BOX_SPC); - } - redraw: - { - int len, x, dy; - len = cur_text->input.n - cur_text->input.left; - if (len > cur_text->input.size) - len = cur_text->input.size; - else - XDrawImageString(dpy, cur_text->header.win, gc_input, - BOX_SPC + TEXT_SPC + - FontWidth(xfs[f_input]) * len, - BOX_SPC + TEXT_SPC + xfs[f_input]->ascent, - cur_text->input.blanks, - cur_text->input.size - len); - XDrawImageString(dpy, cur_text->header.win, gc_input, - BOX_SPC + TEXT_SPC, - BOX_SPC + TEXT_SPC + xfs[f_input]->ascent, - cur_text->input.value + cur_text->input.left, len); - x = BOX_SPC + TEXT_SPC + FontWidth(xfs[f_input]) * abs_cursor - 1; - dy = cur_text->header.size_y - 1; - XDrawLine(dpy, cur_text->header.win, gc_input, - x, BOX_SPC, x, dy - BOX_SPC); - } - no_redraw: - break; /* end of case KeyPress */ - } /* end of switch (event.type) */ - continue; - } /* end of if (event.xany.window == frame) */ - for (i = 0; i < n_items; i++) { - item = items + i; - if (event.xany.window == item->header.win) { - switch (event.type) { - case Expose: - RedrawItem(item, 0); - break; - case ButtonPress: - if (item->type == I_INPUT) { - old_item = cur_text; - old_item->input.o_cursor = rel_cursor; - cur_text = item; - RedrawItem(old_item, 1); - abs_cursor = (event.xbutton.x - BOX_SPC - - TEXT_SPC + FontWidth(xfs[f_input]) / 2) - / FontWidth(xfs[f_input]); - if (abs_cursor < 0) - abs_cursor = 0; - if (abs_cursor > item->input.size) - abs_cursor = item->input.size; - rel_cursor = abs_cursor + item->input.left; - if (rel_cursor < 0) - rel_cursor = 0; - if (rel_cursor > item->input.n) - rel_cursor = item->input.n; - if (rel_cursor > 0 && rel_cursor == item->input.left) - item->input.left--; - if (rel_cursor < item->input.n && - rel_cursor == item->input.left + item->input.size) - item->input.left++; - abs_cursor = rel_cursor - item->input.left; - RedrawItem(item, 0); - } - if (item->type == I_CHOICE) - ToggleChoice(item); - if (item->type == I_BUTTON) { - RedrawItem(item, 1); - XGrabPointer(dpy, item->header.win, False, ButtonReleaseMask, - GrabModeAsync, GrabModeAsync, - None, None, CurrentTime); - } - break; - case ButtonRelease: - RedrawItem(item, 0); - if (grab_server && server_grabbed) { - XGrabPointer(dpy, frame, True, 0, GrabModeAsync, GrabModeAsync, - None, None, CurrentTime); - XFlush(dpy); - } else { - XUngrabPointer(dpy, CurrentTime); - XFlush(dpy); - } - if (event.xbutton.x >= 0 && - event.xbutton.x < item->header.size_x && - event.xbutton.y >= 0 && - event.xbutton.y < item->header.size_y) { - DoCommand(item); - } - break; - } - } - } /* end of for (i = 0 */ - } /* while loop */ + static XEvent event; + int i, old_cursor, keypress; + Item *item, *old_item; + KeySym ks; + char *sp, *dp, *ep; + static unsigned char buf[10], n; + + while (XEventsQueued(dpy, QueuedAfterReading)) { + XNextEvent(dpy, &event); + if (event.xany.window == frame) { + switch (event.type) { + case Expose: + RedrawFrame(); + if (grab_server && !server_grabbed) { + if (GrabSuccess == + XGrabPointer(dpy, frame, True, 0, + GrabModeAsync, GrabModeAsync, + None, None, CurrentTime)) + server_grabbed = 1; + } + break; + case KeyPress: /* we do text input here */ + n = XLookupString( + &event.xkey, buf, 10, &ks, NULL); + keypress = buf[0]; + fprintf(fp_err, "Keypress [%s]\n", buf); + if (n == 0) { /* not a regular key, translate it + into one */ + switch (ks) { + case XK_Home: + case XK_Begin: + buf[0] = '\001'; /* ^A */ + break; + case XK_End: + buf[0] = '\005'; /* ^E */ + break; + case XK_Left: + buf[0] = '\002'; /* ^B */ + break; + case XK_Right: + buf[0] = '\006'; /* ^F */ + break; + case XK_Up: + buf[0] = '\020'; /* ^P */ + break; + case XK_Down: + buf[0] = '\016'; /* ^N */ + break; + default: + if (ks >= XK_F1 && + ks <= XK_F35) { + buf[0] = '\0'; + keypress = + 257 + ks - XK_F1; + } else + goto no_redraw; /* no + action + for + this + event + */ + } + } + if (!cur_text) { /* no text input fields */ + for (i = 0; i < n_items; i++) { + item = items + i; + fprintf(fp_err, + "Button[%d], " + "keypress==%d\n", + i, item->button.keypress); + if (item->type == I_BUTTON && + item->button.keypress == + buf[0]) { + RedrawItem(item, 1); + sleep(1); + RedrawItem(item, 0); + DoCommand(item); + goto no_redraw; + } + } + break; + } + switch (buf[0]) { + case '\001': /* ^A */ + old_cursor = abs_cursor; + rel_cursor = 0; + abs_cursor = 0; + cur_text->input.left = 0; + goto redraw_newcursor; + break; + case '\005': /* ^E */ + old_cursor = abs_cursor; + rel_cursor = cur_text->input.n; + if ((cur_text->input.left = + rel_cursor - + cur_text->input.size) < 0) + cur_text->input.left = 0; + abs_cursor = + rel_cursor - cur_text->input.left; + goto redraw_newcursor; + break; + case '\002': /* ^B */ + old_cursor = abs_cursor; + if (rel_cursor > 0) { + rel_cursor--; + abs_cursor--; + if (abs_cursor <= 0 && + rel_cursor > 0) { + abs_cursor++; + cur_text->input.left--; + } + } + goto redraw_newcursor; + break; + case '\006': /* ^F */ + old_cursor = abs_cursor; + if (rel_cursor < cur_text->input.n) { + rel_cursor++; + abs_cursor++; + if (abs_cursor >= + cur_text->input.size && + rel_cursor < + cur_text->input.n) { + abs_cursor--; + cur_text->input.left++; + } + } + goto redraw_newcursor; + break; + case '\010': /* ^H */ + old_cursor = abs_cursor; + if (rel_cursor > 0) { + sp = cur_text->input.value + + rel_cursor; + dp = sp - 1; + for (; *dp = *sp, *sp != '\0'; + dp++, sp++) + ; + cur_text->input.n--; + rel_cursor--; + if (rel_cursor < abs_cursor) { + abs_cursor--; + if (abs_cursor <= 0 && + rel_cursor > 0) { + abs_cursor++; + cur_text->input + .left--; + } + } else + cur_text->input.left--; + } + goto redraw_newcursor; + break; + case '\177': /* DEL */ + case '\004': /* ^D */ + if (rel_cursor < cur_text->input.n) { + sp = cur_text->input.value + + rel_cursor + 1; + dp = sp - 1; + for (; *dp = *sp, *sp != '\0'; + dp++, sp++) + ; + cur_text->input.n--; + goto redraw; + } + break; + case '\013': /* ^K */ + cur_text->input.value[rel_cursor] = + '\0'; + cur_text->input.n = rel_cursor; + goto redraw; + case '\025': /* ^U */ + old_cursor = abs_cursor; + cur_text->input.value[0] = '\0'; + cur_text->input.n = + cur_text->input.left = 0; + rel_cursor = abs_cursor = 0; + goto redraw_newcursor; + case '\t': + case '\n': + case '\015': + case '\016': /* LINEFEED, TAB, RETURN, ^N, jump + to the next field */ + for (i = (cur_text - items) + 1; + i < n_items; i++) { + item = items + i; + if (item->type == I_INPUT) { + old_item = cur_text; + old_item->input + .o_cursor = + rel_cursor; + cur_text = item; + RedrawItem(old_item, 1); + rel_cursor = + item->input + .o_cursor; + abs_cursor = + rel_cursor - + item->input.left; + goto redraw; + } + } + /* end of all text input fields, check + * for buttons */ + for (i = 0; i < n_items; i++) { + item = items + i; + fprintf(fp_err, + "Button[%d], " + "keypress==%d\n", + i, item->button.keypress); + if (item->type == I_BUTTON && + item->button.keypress == + buf[0]) { + RedrawItem(item, 1); + sleep(1); + RedrawItem(item, 0); + DoCommand(item); + goto no_redraw; + } + } + /* goto the first text input field */ + for (i = 0; i < n_items; i++) { + item = items + i; + if (item->type == I_INPUT) { + old_item = cur_text; + old_item->input + .o_cursor = + rel_cursor; + cur_text = item; + RedrawItem(old_item, 1); + rel_cursor = + item->input + .o_cursor; + abs_cursor = + rel_cursor - + item->input.left; + goto redraw; + } + } + break; + default: + old_cursor = abs_cursor; + if ((buf[0] >= ' ' && + buf[0] < '\177') || + (buf[0] >= 160)) { /* regular or + intl char */ + if (++(cur_text->input.n) >= + cur_text->input.buf) { + cur_text->input.buf += + cur_text->input + .size; + cur_text->input.value = + (char *)realloc( + cur_text->input + .value, + cur_text->input + .buf); + } + dp = cur_text->input.value + + cur_text->input.n; + sp = dp - 1; + ep = cur_text->input.value + + rel_cursor; + for (; *dp = *sp, sp != ep; + sp--, dp--) + ; + *ep = buf[0]; + rel_cursor++; + abs_cursor++; + if (abs_cursor >= + cur_text->input.size) { + if (rel_cursor < + cur_text->input.n) + abs_cursor = + cur_text + ->input + .size - + 1; + else + abs_cursor = + cur_text + ->input + .size; + cur_text->input.left = + rel_cursor - + abs_cursor; + } + goto redraw_newcursor; + } + /* unrecognized key press, check for + * buttons */ + for (i = 0; i < n_items; i++) { + item = items + i; + fprintf(fp_err, + "Button[%d], " + "keypress==%d\n", + i, item->button.keypress); + if (item->type == I_BUTTON && + item->button.keypress == + keypress) { + RedrawItem(item, 1); + sleep( + 1); /* .5 seconds */ + RedrawItem(item, 0); + DoCommand(item); + goto no_redraw; + } + } + break; + } + redraw_newcursor: { + int x, dy; + x = BOX_SPC + TEXT_SPC + + FontWidth(xfs[f_input]) * + old_cursor - 1; + dy = cur_text->header.size_y - 1; + XSetForeground( + dpy, gc_button, colors[c_itemback]); + XDrawLine(dpy, cur_text->header.win, + gc_button, x, BOX_SPC, x, + dy - BOX_SPC); + } + redraw: { + int len, x, dy; + len = cur_text->input.n - + cur_text->input.left; + if (len > cur_text->input.size) + len = cur_text->input.size; + else + XDrawImageString(dpy, + cur_text->header.win, + gc_input, + BOX_SPC + TEXT_SPC + + FontWidth(xfs[f_input]) * + len, + BOX_SPC + TEXT_SPC + + xfs[f_input]->ascent, + cur_text->input.blanks, + cur_text->input.size - len); + XDrawImageString(dpy, + cur_text->header.win, gc_input, + BOX_SPC + TEXT_SPC, + BOX_SPC + TEXT_SPC + + xfs[f_input]->ascent, + cur_text->input.value + + cur_text->input.left, len); + x = BOX_SPC + TEXT_SPC + + FontWidth(xfs[f_input]) * + abs_cursor - 1; + dy = cur_text->header.size_y - 1; + XDrawLine(dpy, cur_text->header.win, + gc_input, x, BOX_SPC, x, + dy - BOX_SPC); + } + no_redraw: + break; /* end of case KeyPress */ + } /* end of switch (event.type) */ + continue; + } /* end of if (event.xany.window == frame) */ + for (i = 0; i < n_items; i++) { + item = items + i; + if (event.xany.window == item->header.win) { + switch (event.type) { + case Expose: + RedrawItem(item, 0); + break; + case ButtonPress: + if (item->type == I_INPUT) { + old_item = cur_text; + old_item->input.o_cursor = + rel_cursor; + cur_text = item; + RedrawItem(old_item, 1); + abs_cursor = + (event.xbutton.x - BOX_SPC - + TEXT_SPC + + FontWidth( + xfs[f_input]) / + 2) / + FontWidth(xfs[f_input]); + if (abs_cursor < 0) + abs_cursor = 0; + if (abs_cursor > + item->input.size) + abs_cursor = + item->input.size; + rel_cursor = abs_cursor + + item->input.left; + if (rel_cursor < 0) + rel_cursor = 0; + if (rel_cursor > item->input.n) + rel_cursor = + item->input.n; + if (rel_cursor > 0 && + rel_cursor == + item->input.left) + item->input.left--; + if (rel_cursor < + item->input.n && + rel_cursor == + item->input.left + + item->input.size) + item->input.left++; + abs_cursor = rel_cursor - + item->input.left; + RedrawItem(item, 0); + } + if (item->type == I_CHOICE) + ToggleChoice(item); + if (item->type == I_BUTTON) { + RedrawItem(item, 1); + XGrabPointer(dpy, + item->header.win, False, + ButtonReleaseMask, + GrabModeAsync, + GrabModeAsync, None, None, + CurrentTime); + } + break; + case ButtonRelease: + RedrawItem(item, 0); + if (grab_server && server_grabbed) { + XGrabPointer(dpy, frame, True, + 0, GrabModeAsync, + GrabModeAsync, None, None, + CurrentTime); + XFlush(dpy); + } else { + XUngrabPointer( + dpy, CurrentTime); + XFlush(dpy); + } + if (event.xbutton.x >= 0 && + event.xbutton.x < + item->header.size_x && + event.xbutton.y >= 0 && + event.xbutton.y < + item->header.size_y) { + DoCommand(item); + } + break; + } + } + } /* end of for (i = 0 */ + } /* while loop */ } /* main event loop */ -void MainLoop () +void +MainLoop() { - fd_set fds; - - while (1) { - FD_ZERO(&fds); - FD_SET(fd_in, &fds); - FD_SET(fd_x, &fds); - - XFlush(dpy); - if (select(32, &fds, NULL, NULL, NULL) > 0) { - if (FD_ISSET(fd_in, &fds)) - ReadFvwm(); - if (FD_ISSET(fd_x, &fds)) - ReadXServer(); - } - } + fd_set fds; + + while (1) { + FD_ZERO(&fds); + FD_SET(fd_in, &fds); + FD_SET(fd_x, &fds); + + XFlush(dpy); + if (select(32, &fds, NULL, NULL, NULL) > 0) { + if (FD_ISSET(fd_in, &fds)) + ReadFvwm(); + if (FD_ISSET(fd_x, &fds)) + ReadXServer(); + } + } } - /* main procedure */ -int main (int argc, char **argv) +int +main(int argc, char **argv) { - FILE *fdopen(); - int i; + int i; - buf = (char *)malloc(N); /* some kludge */ + buf = (char *)malloc(N); /* some kludge */ #ifdef DEBUG - fd_err = open(".FvwmFormErrors", O_WRONLY | O_CREAT, 0777); - fp_err = fdopen(fd_err, "w"); + fd_err = open(".FvwmFormErrors", O_WRONLY | O_CREAT, 0777); + fp_err = fdopen(fd_err, "w"); #else - fd_err = open("/dev/null", O_WRONLY); - fp_err = fdopen(fd_err, "w"); + fd_err = open("/dev/null", O_WRONLY); + fp_err = fdopen(fd_err, "w"); #endif - /* we get rid of the path from program name */ - prog_name = argv[0]; - i = strlen(prog_name); - while (prog_name[--i] != '/' && i > 0); - if (i > 0) - prog_name = prog_name + (i + 1); - fprintf(fp_err, "%s started...\n", prog_name); + /* we get rid of the path from program name */ + prog_name = argv[0]; + i = strlen(prog_name); + while (prog_name[--i] != '/' && i > 0) + ; + if (i > 0) + prog_name = prog_name + (i + 1); + fprintf(fp_err, "%s started...\n", prog_name); - if (argc < 6) { + if (argc < 6) { #ifndef DEBUG - fprintf(fp_err, "%s must be started by Fvwm.\n", prog_name); - exit(1); + fprintf(fp_err, "%s must be started by Fvwm.\n", prog_name); + exit(1); #else - fd_out = 1; - fd_in = 0; - ref = None; + fd_out = 1; + fd_in = 0; + ref = None; #endif - } else { - if(argc==7) - prog_name = argv[6]; - fd_out = atoi(argv[1]); - fd_in = atoi(argv[2]); - ref = strtol(argv[4], NULL, 16); - if (ref == 0) ref = None; + } else { + if (argc == 7) + prog_name = argv[6]; + fd_out = atoi(argv[1]); + fd_in = atoi(argv[2]); + ref = strtol(argv[4], NULL, 16); + if (ref == 0) + ref = None; #ifdef DEBUG - fprintf(fp_err, "ref == %d\n", ref); + fprintf(fp_err, "ref == %d\n", ref); #endif - } + } - fd[0]=fd_out; - fd[1]=fd_in; + fd[0] = fd_out; + fd[1] = fd_in; - if (!(dpy = XOpenDisplay(NULL))) { - fprintf(fp_err, "%s: can't open display.\n", prog_name); - exit(1); - } - fd_x = XConnectionNumber(dpy); + if (!(dpy = XOpenDisplay(NULL))) { + fprintf(fp_err, "%s: can't open display.\n", prog_name); + exit(1); + } + fd_x = XConnectionNumber(dpy); - screen = DefaultScreen(dpy); - root = RootWindow(dpy, screen); - scr_depth = DefaultDepth(dpy, screen); - d_cmap = DefaultColormap(dpy, screen); + screen = DefaultScreen(dpy); + root = RootWindow(dpy, screen); + scr_depth = DefaultDepth(dpy, screen); + d_cmap = DefaultColormap(dpy, screen); - ReadConfig(); + ReadConfig(); - GetColors(); + GetColors(); - OpenWindows(); + OpenWindows(); - MainLoop(); + MainLoop(); - return 0; + return 0; } - -void DeadPipe(int nonsense) +void +DeadPipe(int nonsense) { - exit(0); + exit(0); } Index: fvwm/modules/FvwmIconBox/FvwmIconBox.1 =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIconBox/FvwmIconBox.1,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIconBox/FvwmIconBox.1 --- fvwm/modules/FvwmIconBox/FvwmIconBox.1 +++ fvwm/modules/FvwmIconBox/FvwmIconBox.1 @@ -1,86 +1,76 @@ .\" $OpenBSD: FvwmIconBox.1,v 1.1.1.1 2006/11/26 10:53:47 matthieu Exp $ .\" t -.\" @(#)FvwmIconBox.1 6/20/94 -.TH FvwmIconBox 1 "Jun 24 1994" 0.64 +.\" @(#)FvwmIconBox.1 6/20/94 +.TH FVWMICONBOX 1 "June 24, 1994" "0.64" "FVWM Modules" .UC .SH NAME FvwmIconBox \- the FVWM iconbox module .SH SYNOPSIS FvwmIconBox is spawned by fvwm, so no command line invocation will work. - .SH DESCRIPTION -The FvwmIconBox module provides an icon manager. The user can do -operations, like iconify and deiconify, for each icon shown in the -module via mouse and keyboard. - -FvwmIconBox reads the same .fvwmrc file as fvwm reads when it starts up, +The FvwmIconBox module provides an icon manager. +The user can do operations, like iconify and deiconify, for each icon +shown in the module via mouse and keyboard. +.PP +FvwmIconBox reads the same .fvwmrc file as fvwm reads when it starts up and looks for lines similar to "*FvwmIconBoxFore green". - .SH COPYRIGHTS The FvwmIconBox program is original work of Nobutaka Suzuki. - -Copyright 1994, Nobutaka Suzuki. No guarantees or warranties or anything -are provided or implied in any way whatsoever. Use this program at your -own risk. Permission to use this program for any purpose is given, -as long as the copyright is kept intact. - - +.PP +Copyright 1994, Nobutaka Suzuki. +No guarantees or warranties or anything are provided or implied in any +way whatsoever. +Use this program at your own risk. +Permission to use this program for any purpose is given, as long as the +copyright is kept intact. .SH INITIALIZATION -During initialization, \fIFvwmIconBox\fP will eventually search a -configuration file. The configuration file is the same file that fvwm -used during initialization. - +During initialization, \fIFvwmIconBox\fP will eventually search a +configuration file. +The configuration file is the same file that fvwm used during +initialization. +.PP If the FvwmIconBox executable is linked to another name, ie ln -s FvwmIconBox MoreIconBox, then another module called MoreIconBox can be started, with a completely different configuration than FvwmIconBox, -simply by changing the keyword FvwmIconBox to MoreIconBox. This way -multiple clutter-reduction programs can be used. - +simply by changing the keyword FvwmIconBox to MoreIconBox. +This way multiple clutter-reduction programs can be used. .SH INVOCATION -FvwmIconBox can be invoked by binding the action 'Module -FvwmIconBox' to a menu or key-stroke in the .fvwmrc file. -Fvwm will search directory specified in the ModulePath configuration -option to attempt to locate FvwmIconBox. - +FvwmIconBox can be invoked by binding the action 'Module FvwmIconBox' +to a menu or key-stroke in the .fvwmrc file. +Fvwm will search the directory specified in the ModulePath +configuration option to attempt to locate FvwmIconBox. .SH CONFIGURATION OPTIONS -FvwmIconBox shows icons only if NoIcon is applied. Note that the -NoIcon attribute should be set after the Icon attribute specification. +FvwmIconBox shows icons only if NoIcon is applied. +Note that the NoIcon attribute should be set after the Icon attribute +specification. Otherwise the icon-box module might become nothing but an empty-box -module. The module reads the same .fvwmrc file as fvwm reads when it -starts up, and looks for lines as listed below: - +module. +The module reads the same .fvwmrc file as fvwm reads when it starts up +and looks for lines as listed below: .IP "*FvwmIconBoxFore \fIcolor\fP" Tells the module to use \fIcolor\fP instead of white for the window foreground. This option affects only the foreground color of background_bitmap specified in *FvwmIconBoxPixmap option described -below. - +below. .IP "*FvwmIconBoxBack \fIcolor\fP" Tells the module to use \fIcolor\fP instead of black for the window background. - .IP "*FvwmIconBoxIconFore \fIcolor\fP" Tells the module to use \fIcolor\fP instead of black for non-selected -icon text. - +icon text. .IP "*FvwmIconBoxIconBack \fIcolor\fP" Tells the module to use \fIcolor\fP instead of white for the non-selected icon background. - .IP "*FvwmIconBoxIconHiFore \fIcolor\fP" Tells the module to use \fIcolor\fP instead of black for selected icon -text. - +text. .IP "*FvwmIconBoxIconHiBack \fIcolor\fP" Tells the module to use \fIcolor\fP instead of white for the selected icon background. - .IP "*FvwmIconBoxPixmap \fIpixmap\fP" Tells the module to use \fIpixmap\fP for the window background_pixmap. - .IP "*FvwmIconBoxFont \fIfontname\fP" Tells the module to use \fIfontname\fP instead of fixed for text. - .IP "*FvwmIconBoxSortIcons \fIoption\fP" Tells the module to sort all icons in iconbox in alphabetical order. \fIoption\fP can be \fIWindowName\fP, \fIIconName\fP, \fIResClass\fP, @@ -88,21 +78,17 @@ and \fIResName\fP. For example, specifying \fIResClass\fP means that icons are sorted by using their resource-class strings. If \fIoption\fP is \fIResClass\fP or \fIResName\fP, an icon having no XA_WM_CLASS property is considered to be the "smallest" element. - .IP "*FvwmIconBoxPadding \fInumber\fP" Specifies the number of pixels between icons. The default value is 5. - .IP "*FvwmIconBoxSBWidth \fInumber\fP" Specifies the width of horizontal and vertical scrollbars. The default -value is 9. - +value is 9. .IP "*FvwmIconBoxPlacement \fIprimary\fP \fIsecondary\fP" Specifies icon placement policy. \fIprimary\fP and \fIsecondary\fP can -be \fITop\fP, \fIBottom\fP, \fILeft\fP and \fIRight\fP. The following -eight combinations are available: +be \fITop\fP, \fIBottom\fP, \fILeft\fP and \fIRight\fP. +The following eight combinations are available: .nf -.sp -\fIprimary\fP \fIsecondary\fP +\fIprimary\fP \fIsecondary\fP Left Top Left Bottom @@ -116,119 +102,112 @@ eight combinations are available: .fi .B "\fITop\fP:" Icons are placed from top to bottom. - .B "\fIBottom\fP:" Icons are placed from bottom to top. - .B "\fILeft\fP:" Icons are placed from left to right. - .B "\fIRight\fP:" Icons are placed from right to left. - +.PP For example, when the placement is "Left Top", icons are placed from left to right, and new rows are added from top to bottom. The default -vale is "Left Bottom". - +value is "Left Bottom". .IP "*FvwmIconBoxLines" Specifies the number of icons placed in a line. If \fIprimary\fP is -Left or Right, this value specifies the number of columns. +Left or Right, this value specifies the number of columns. If \fIprimary\fP is Top or Bottom, this value specifies the number of -rows. For example, seven icons are placed in a row if -*FvwmIconBoxLines is 7 and *FvwmIconBoxPlacement is "Left Top". -The default value is 6. - +rows. +For example, seven icons are placed in a row if *FvwmIconBoxLines is 7 +and *FvwmIconBoxPlacement is "Left Top". +The default value is 6. .IP "*FvwmIconBoxHideSC \fIdirection\fP" -Specifies the undisplayed scroll bar . \fIDirection\fP can be -either \fIHorizontal\fP or \fIVertical\fP. - +Specifies the undisplayed scroll bar. +\fIDirection\fP can be either \fIHorizontal\fP or \fIVertical\fP. .IP "*FvwmIconBoxGeometry \fIx{+-}{+-}\fP" -Specifies the location and/or size of FvwmIconBox. -\fIwidth\fP and \fIheight\fP are measured in icons, not pixels. -The default value is 6x1+0+0. - +Specifies the location and/or size of FvwmIconBox. +\fIwidth\fP and \fIheight\fP are measured in icons, not pixels. +The default value is 6x1+0+0. .IP "*FvwmIconBoxMaxIconSize \fIx\fP" Specifies the maximum size of icon bitmap. A bitmap larger than -this size is clipped to this size. The default value is 48x48. In -particular, if the height is 0, then icon bitmaps are not displayed and -only icon labels are drawn. - +this size is clipped to this size. +The default value is 48x48. +In particular, if the height is 0, then icon bitmaps are not displayed +and only icon labels are drawn. .IP "*FvwmIconBoxMouse \fIButton\fP \fIAction\fP \fIResponse[, Response]\fP" Tells the module to do \fIResponse\fP when \fIAction\fP is done on button \fIButton\fP. Available \fIResponse\fPes are built-in commands -in Fvwm (e.g. Iconify, Delete, Focus) and available \fIAction\fPs -are Click and DoubleClick. - +in Fvwm (e.g. Iconify, Delete, Focus) and available \fIAction\fPs are +Click and DoubleClick. .IP "*FvwmIconBoxKey \fIKey\fP \fIResponse[, Response]\fP" Tells the module to do \fIResponse\fP when \fIKey\fP is pressed. -Available \fIResponse\fPes are, besides Fvwm built-in commands, the -following six FvwmIconBox built-in commands: \fINext\fP, \fIPrev\fP, -\fILeft\fP, \fIRight\fP, \fIUp\fP, and \fIDown\fP. - -.B "\fINext\fP:" -Change the hilited-icon to the next. - -.B "\fIPrev\fP:" +Available \fIResponse\fPes are, besides Fvwm built-in commands, the +following six FvwmIconBox built-in commands: \fINext\fP, \fIPrev\fP, +\fILeft\fP, \fIRight\fP, \fIUp\fP, and \fIDown\fP. +.RS +.TP 8 +.B \fINext\fP +Change the hilited-icon to the next. +.TP 8 +.B \fIPrev\fP Change the hilited-icon to the previous. - -.B "\fILeft\fP:" -Move the slider of the horizontal scrollbar to left. Icons move -to right accordingly. - -.B "\fIRight\fP:" -Move the slider of the horizontal scrollbar to right. Icons move -to left accordingly. - -.B "\fIUp\fP:" -Move the slider of the vertical scrollbar to up. Icons move to -down accordingly. - -.B "\fIDown\fP:" -Move the slider of the vertical scrollbar to down. Icons move to -up accordingly. - -.IP "*FvwmIconBox \fIwindowname\fP \fIbitmap-file\fP" +.TP 8 +.B \fILeft\fP +Move the slider of the horizontal scrollbar to left. +Icons move to right accordingly. +.TP 8 +.B \fIRight\fP +Move the slider of the horizontal scrollbar to right. +Icons move to left accordingly. +.TP 8 +.B \fIUp\fP +Move the slider of the vertical scrollbar to up. +Icons move down accordingly. +.TP 8 +.B \fIDown\fP +Move the slider of the vertical scrollbar to down. +Icons move up accordingly. +.RE +.IP "*FvwmIconBox \fIwindowname\fP \fIbitmap-file\fP" Specifies the bitmap to be displayed in iconbox for \fIwindowname\fP. This option "overrides" bitmap files specified in Style command. \fIWindowname\fP can be window name, class name, or resource name. -\fIWindowname\fP can contain "*" and "?" like Fvwm configuration -file. The \fIbitmap-file\fP is either the full path name to a bitmap -file, or a file in the IconPath or PixmapPath. If \fIbitmap-file\fP is -specified to be "-", the icon for a window corresponding to -\fIwindowname\fP is not shown in the iconbox. - +\fIWindowname\fP can contain "*" and "?" like Fvwm configuration +file. +The \fIbitmap-file\fP is either the full path name to a bitmap file, or +a file in the IconPath or PixmapPath. +If \fIbitmap-file\fP is specified to be "-", the icon for a window +corresponding to \fIwindowname\fP is not shown in the iconbox. .IP "*FvwmIconBoxSetWMIconSize" -Tells the module to set XA_WM_ICON_SIZE property of the root window -at the size which the module want icon windows to have. If you show -icon windows on not the root window but the module, it would be -better to specify this option. - +Tells the module to set XA_WM_ICON_SIZE property of the root window at +the size which the module wants icon windows to have. +If you show icon windows on the module instead of the root window, it +is better to specify this option. .IP "*FvwmIconBoxHilightFocusWin" Tells the module to hilight the icon of the window which has the -keyboard focus. The fore/back colors of the hilighted icon are those -specified in the *FvwmIconBoxIconHiFore and *FvwmIconBoxIconHiBack -commands, respectively. - +keyboard focus. +The fore/back colors of the hilighted icon are those specified in the +*FvwmIconBoxIconHiFore and *FvwmIconBoxIconHiBack commands, +respectively. .IP "*FvwmIconBoxResolution \fIresolution\fP" If \fIresolution\fP is Desk, then the module shows only the icons on -the current desk. Currently, Desk is the only value \fIresolution\fP -can take :) - +the current desk. +Currently, Desk is the only value \fIresolution\fP can take :) .IP "*FvwmIconBoxFrameWidth \fIwidth1\fP \fIwidth2\fP" -Specifies the frame-width of the module. \fIWidth1\fP corresponds to -the width from the outer-border to the scroll-bar, and, \fIwidth2\fP -corresponds to the width from the scroll-bar to the internal-window -displaying icons. The default values are 8 and 6, respectively. - +Specifies the frame-width of the module. +\fIWidth1\fP corresponds to the width from the outer-border to the +scroll-bar, and \fIwidth2\fP corresponds to the width from the +scroll-bar to the internal-window displaying icons. +The default values are 8 and 6, respectively. .SH SAMPLE CONFIGURATION -The following are excepts from a .fvwmrc file which describe +The following are excerpts from a .fvwmrc file which describe FvwmIconBox initialization commands: +.PP +.RS .nf -.sp XCOMM########################################################### XCOMM Note that icons are shown in the module XCOMM only if NoIcon attribute is applied. -Style "*" NoIcon +Style "*" NoIcon XCOMM########################################################### *FvwmIconBoxIconBack #cfcfcf @@ -239,18 +218,18 @@ XCOMM*FvwmIconBoxFore blue *FvwmIconBoxGeometry 5x1+0+0 *FvwmIconBoxMaxIconSize 64x38 *FvwmIconBoxFont -adobe-helvetica-medium-r-*-*-12-*-*-*-*-*-*-* -*FvwmIconBoxSortIcons IconName -XCOMM*FvwmIconBoxSortIcons ResClass +*FvwmIconBoxSortIcons IconName +XCOMM*FvwmIconBoxSortIcons ResClass *FvwmIconBoxPadding 4 *FvwmIconBoxFrameWidth 9 7 *FvwmIconBoxLines 10 *FvwmIconBoxSBWidth 11 *FvwmIconBoxPlacement Left Top *FvwmIconBoxPixmap fvwm.xpm -XCOMM*FvwmIconBoxHideSC Horizontal +XCOMM*FvwmIconBoxHideSC Horizontal *FvwmIconBoxSetWMIconSize *FvwmIconBoxHilightFocusWin -XCOMM*FvwmIconBoxResolution Desk +XCOMM*FvwmIconBoxResolution Desk XCOMM XCOMM mouse bindings XCOMM @@ -274,15 +253,13 @@ XCOMM *FvwmIconBoxKey k Up *FvwmIconBoxKey l Right XCOMM -XCOMM Icon file specifications +XCOMM Icon file specifications XCOMM -XCOMM Mostly, you don't have to specify icon files, as FvwmIconBox now -XCOMM reads icon files specified in Style commands. +XCOMM Mostly, you don't have to specify icon files, as FvwmIconBox now +XCOMM reads icon files specified in Style commands. XCOMM *FvwmIconBox "Fvwm*" - -.sp .fi - +.RE .SH AUTHOR Nobutaka Suzuki (nobuta-s@is.aist-nara.ac.jp). - Index: fvwm/modules/FvwmIconBox/FvwmIconBox.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIconBox/FvwmIconBox.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIconBox/FvwmIconBox.c --- fvwm/modules/FvwmIconBox/FvwmIconBox.c +++ fvwm/modules/FvwmIconBox/FvwmIconBox.c @@ -18,32 +18,32 @@ #define HORIZONTAL 2 #include "config.h" +#include "../../fvwm/fvwm_sandbox.h" -#ifdef HAVE_SYS_BSDTYPES_H -#include /* Saul */ #endif -#include -#include +#include +#include + #include +#include +#include #include -#include -#include #if HAVE_SYS_SELECT_H #include #endif -#include +#include +#include +#include +#include +#include #include #include -#include "../../fvwm/module.h" +#include -#include -#include -#include -#include -#include +#include "../../fvwm/module.h" #ifdef SHAPE #include @@ -51,8 +51,8 @@ /* just as same as wild.c */ #ifndef TRUE -#define TRUE 1 -#define FALSE 0 +#define TRUE 1 +#define FALSE 0 #endif #include "FvwmIconBox.h" @@ -61,8 +61,8 @@ char *MyName; XFontStruct *font; -Display *dpy; /* which display are we talking to */ -int x_fd,fd_width; +Display *dpy; /* which display are we talking to */ +int x_fd, fd_width; Window Root; int screen; @@ -82,9 +82,10 @@ char NoResource[] = "NoResource"; Pixel fore_pix, hilite_pix, back_pix, shadow_pix; Pixel icon_fore_pix, icon_back_pix, icon_hilite_pix, icon_shadow_pix; -Pixel act_icon_fore_pix, act_icon_back_pix, act_icon_hilite_pix, act_icon_shadow_pix; +Pixel act_icon_fore_pix, act_icon_back_pix, act_icon_hilite_pix, + act_icon_shadow_pix; -GC NormalGC,ShadowGC,ReliefGC,IconShadowGC,IconReliefGC; +GC NormalGC, ShadowGC, ReliefGC, IconShadowGC, IconReliefGC; Window main_win; Window holder_win; Window icon_win; @@ -98,18 +99,21 @@ long CurrentDesk; int Width, Height; int UWidth, UHeight; -#define MW_EVENTS (KeyPressMask| ExposureMask | StructureNotifyMask|\ - ButtonReleaseMask | ButtonPressMask ) -#define SCROLL_EVENTS (ExposureMask | StructureNotifyMask|\ - ButtonReleaseMask |ButtonPressMask | PointerMotionMask) -#define BUTTON_EVENTS (ExposureMask | StructureNotifyMask|\ - ButtonReleaseMask | ButtonPressMask |\ - LeaveWindowMask | PointerMotionMask) - -unsigned long m_mask = M_CONFIGURE_WINDOW|M_ADD_WINDOW|M_DESTROY_WINDOW| - M_END_WINDOWLIST| M_ICONIFY|M_DEICONIFY|M_ICON_NAME| - M_RES_NAME|M_RES_CLASS|M_WINDOW_NAME|M_ICON_FILE| - M_DEFAULTICON|M_CONFIG_INFO|M_END_CONFIG_INFO; +#define MW_EVENTS \ + (KeyPressMask | ExposureMask | StructureNotifyMask | \ + ButtonReleaseMask | ButtonPressMask) +#define SCROLL_EVENTS \ + (ExposureMask | StructureNotifyMask | ButtonReleaseMask | \ + ButtonPressMask | PointerMotionMask) +#define BUTTON_EVENTS \ + (ExposureMask | StructureNotifyMask | ButtonReleaseMask | \ + ButtonPressMask | LeaveWindowMask | PointerMotionMask) + +unsigned long m_mask = M_CONFIGURE_WINDOW | M_ADD_WINDOW | M_DESTROY_WINDOW | + M_END_WINDOWLIST | M_ICONIFY | M_DEICONIFY | + M_ICON_NAME | M_RES_NAME | M_RES_CLASS | M_WINDOW_NAME | + M_ICON_FILE | M_DEFAULTICON | M_CONFIG_INFO | + M_END_CONFIG_INFO; struct icon_info *Hilite; int main_width, main_height; @@ -117,11 +121,10 @@ int num_icons = 0; int num_rows = 1; int num_columns = 6; int Lines = 6; -int max_icon_width = 48,max_icon_height = 48; -int ButtonWidth,ButtonHeight; -int x= -100000,y= -100000,w= -1,h= -1,gravity = NorthWestGravity; -int icon_win_x = 0, icon_win_y = 0, icon_win_width = 100, -icon_win_height = 100; +int max_icon_width = 48, max_icon_height = 48; +int ButtonWidth, ButtonHeight; +int x = -100000, y = -100000, w = -1, h = -1, gravity = NorthWestGravity; +int icon_win_x = 0, icon_win_y = 0, icon_win_width = 100, icon_win_height = 100; int interval = 8; int motion = NONE; int primary = LEFT, secondary = BOTTOM; @@ -160,383 +163,448 @@ int ready = 0; unsigned long local_flags = 0; int sortby = UNSORT; -int save_color_limit; /* color limit from config */ +int save_color_limit; /* color limit from config */ /************************************************************************ Main Based on main() from GoodStuff: - Copyright 1993, Robert Nation. + Copyright 1993, Robert Nation. ************************************************************************/ -int main(int argc, char **argv) +int +main(int argc, char **argv) { - char *display_name = NULL; - char *temp, *s; - XIconSize* size; - - temp = argv[0]; + char *display_name = NULL; + char *temp, *s; + XIconSize *size; - s=strrchr(argv[0], '/'); - if (s != NULL) - temp = s + 1; + temp = argv[0]; + s = strrchr(argv[0], '/'); + if (s != NULL) + temp = s + 1; - MyName = safemalloc(strlen(temp)+1); - strcpy(MyName, temp); + { + size_t name_len = strlen(temp) + 1; + MyName = xmalloc(name_len); + strlcpy(MyName, temp, name_len); + } - signal (SIGPIPE, DeadPipe); + signal(SIGPIPE, DeadPipe); - if((argc != 6)&&(argc != 7)) - { - fprintf(stderr,"%s Version %s should only be executed by fvwm!\n",MyName, - VERSION); - exit(1); - } + if ((argc != 6) && (argc != 7)) { + fprintf(stderr, + "%s Version %s should only be executed by fvwm!\n", MyName, + VERSION); + exit(1); + } - fd[0] = atoi(argv[1]); - fd[1] = atoi(argv[2]); + fd[0] = atoi(argv[1]); + fd[1] = atoi(argv[2]); - if (!(dpy = XOpenDisplay(display_name))) - { - fprintf(stderr,"%s: can't open display %s", MyName, - XDisplayName(display_name)); - exit (1); - } - x_fd = XConnectionNumber(dpy); + if (!(dpy = XOpenDisplay(display_name))) { + fprintf(stderr, "%s: can't open display %s", MyName, + XDisplayName(display_name)); + exit(1); + } + x_fd = XConnectionNumber(dpy); - fd_width = GetFdWidth(); + fd_width = GetFdWidth(); - screen= DefaultScreen(dpy); - Root = RootWindow(dpy, screen); - if(Root == None) - { - fprintf(stderr,"%s: Screen %d is not valid ", MyName, screen); - exit(1); - } - InitPictureCMap(dpy,Root); /* store the root cmap */ - d_depth = DefaultDepth(dpy, screen); + screen = DefaultScreen(dpy); + Root = RootWindow(dpy, screen); + if (Root == None) { + fprintf(stderr, "%s: Screen %d is not valid ", MyName, screen); + exit(1); + } + InitPictureCMap(dpy, Root); /* store the root cmap */ + d_depth = DefaultDepth(dpy, screen); - XSetErrorHandler((XErrorHandler)myErrorHandler); + XSetErrorHandler((XErrorHandler)myErrorHandler); - ParseOptions(); + ParseOptions(); - SetMessageMask(fd, m_mask); + SetMessageMask(fd, m_mask); - if ((local_flags & SETWMICONSIZE) && (size = XAllocIconSize()) != NULL){ - size->max_width = size->min_width = max_icon_width + icon_relief; - size->max_height = size->min_height = max_icon_height + icon_relief; - size->width_inc = size->height_inc = 0; - XSetIconSizes(dpy, Root, size, 1); - XFree(size); - } + if ((local_flags & SETWMICONSIZE) && + (size = XAllocIconSize()) != NULL) { + size->max_width = size->min_width = + max_icon_width + icon_relief; + size->max_height = size->min_height = + max_icon_height + icon_relief; + size->width_inc = size->height_inc = 0; + XSetIconSizes(dpy, Root, size, 1); + XFree(size); + } - CreateWindow(); + CreateWindow(); - SendFvwmPipe(fd,"Send_WindowList",0); + SendFvwmPipe(fd, "Send_WindowList", 0); - Loop(); - return 0; + Loop(); + return 0; } - - /************************************************************************ Loop Based on Loop() from GoodStuff: Copyright 1993, Robert Nation. ************************************************************************/ -void Loop(void) +void +Loop(void) { - Window root; - struct icon_info *tmp, *exhilite; - int x,y,border_width,depth; - int i, hr = icon_relief/2; - XEvent Event; - int tw,th; - int diffx, diffy; - int oldw, oldh; - - while(1) - { - if(My_XNextEvent(dpy,&Event)) - { - switch(Event.type) - { - case Expose: - if(Event.xexpose.count == 0){ - if (Event.xany.window == main_win){ - RedrawWindow(); - }else{ - tmp = Head; - while(tmp != NULL){ - if (Event.xany.window == tmp->icon_pixmap_w){ - RedrawIcon(tmp, 1); - break; - }else if(Event.xany.window == tmp->IconWin){ - RedrawIcon(tmp, 2); - break; - } - tmp = tmp->next; - } - } - } - break; - - case ConfigureNotify: - XGetGeometry(dpy,main_win,&root,&x,&y, - (unsigned int *)&tw,(unsigned int *)&th, - (unsigned int *)&border_width, - (unsigned int *)&depth); - if (ready && (tw != main_width || th != main_height)){ - main_width = tw; - main_height= th; - oldw = Width; - oldh = Height; - num_columns = (tw - h_margin - interval + 1) / UWidth; - num_rows = (th - v_margin - interval + 1) / UHeight; - Width = UWidth * num_columns + interval - 1; - Height = UHeight * num_rows + interval -1; - XMoveResizeWindow(dpy, holder_win, margin1+2, - margin1+2, - tw - h_margin, th - v_margin); - if (!(local_flags & HIDE_H)) - XResizeWindow(dpy, h_scroll_bar, - Width - bar_width*2, bar_width); - if (!(local_flags & HIDE_V)) - XResizeWindow(dpy ,v_scroll_bar, - bar_width, Height - bar_width*2); - GetIconwinSize(&diffx, &diffy); - if (primary == BOTTOM || secondary == BOTTOM) - icon_win_y -= Height - oldh; - if (primary == RIGHT || secondary == RIGHT) - icon_win_x -= Width - oldw; - if (icon_win_x < 0) - icon_win_x = 0; - if (icon_win_y < 0) - icon_win_y = 0; - if (icon_win_x + Width > icon_win_width) - icon_win_x = icon_win_width - Width; - if (icon_win_y + Height > icon_win_height) - icon_win_y = icon_win_height - Height; - XMoveResizeWindow(dpy, icon_win, -icon_win_x, - -icon_win_y, icon_win_width, - icon_win_height); - AdjustIconWindows(); - XClearWindow(dpy,main_win); - RedrawWindow(); - } - break; - case KeyPress: - ExecuteKey(Event); - break; - case ButtonPress: - if (!(local_flags & HIDE_H)){ - if (Event.xbutton.window == h_scroll_bar) - motion = HORIZONTAL; - else if (Event.xbutton.window == l_button){ - Pressed = l_button; - RedrawLeftButton(ShadowGC, ReliefGC); - } - else if (Event.xbutton.window == r_button){ - Pressed = r_button; - RedrawRightButton(ShadowGC, ReliefGC); - } - } - if (!(local_flags & HIDE_V)){ - if (Event.xbutton.window == v_scroll_bar) - motion = VERTICAL; - else if (Event.xbutton.window == t_button){ - Pressed = t_button; - RedrawTopButton(ShadowGC, ReliefGC); - } - else if (Event.xbutton.window == b_button){ - Pressed = b_button; - RedrawBottomButton(ShadowGC, ReliefGC); - } - } - if ((tmp = Search(Event.xbutton.window)) != NULL) - ExecuteAction(Event.xbutton.x, Event.xbutton.y, tmp); - break; - - case ButtonRelease: - if (!(local_flags & HIDE_H)){ - if (Event.xbutton.window == h_scroll_bar && motion == - HORIZONTAL) - HScroll(Event.xbutton.x * icon_win_width / Width); - else if (Event.xbutton.window == l_button && Pressed == - l_button){ - Pressed = None; - RedrawLeftButton(ReliefGC, ShadowGC); - HScroll(icon_win_x - UWidth); - } - else if (Event.xbutton.window == r_button && Pressed == - r_button){ - Pressed = None; - RedrawRightButton(ReliefGC, ShadowGC); - HScroll(icon_win_x + UWidth); - } - } - if (!(local_flags & HIDE_V)){ - if (Event.xbutton.window == v_scroll_bar && motion - == VERTICAL) - VScroll(Event.xbutton.y * icon_win_height / Height); - else if (Event.xbutton.window == t_button && Pressed == - t_button){ - Pressed = None; - RedrawTopButton(ReliefGC, ShadowGC); - VScroll(icon_win_y - UHeight); - } - else if (Event.xbutton.window == b_button && Pressed == - b_button){ - Pressed = None; - RedrawBottomButton(ReliefGC, ShadowGC); - VScroll(icon_win_y + UHeight); - } - } - motion = NONE; - break; - - case MotionNotify: - if (motion == VERTICAL){ - VScroll(Event.xbutton.y * icon_win_height / Height); - }else if (motion == HORIZONTAL){ - HScroll(Event.xbutton.x * icon_win_width / Width); - } - break; - case EnterNotify: - if ((tmp = Search(Event.xcrossing.window)) != NULL) - if ((exhilite = Hilite) != tmp){ - Hilite = tmp; - if (exhilite != NULL) - RedrawIcon(exhilite, redraw_flag); - RedrawIcon(tmp, redraw_flag); - } - break; - - case LeaveNotify: - if ((tmp = Search(Event.xcrossing.window)) != NULL && - tmp == Hilite){ - Hilite = NULL; - RedrawIcon(tmp, redraw_flag); - } - if (!(local_flags & HIDE_H) && Event.xbutton.window == - l_button && Pressed == l_button){ - Pressed = None; - RedrawLeftButton(ReliefGC, ShadowGC); - } - else if (!(local_flags & HIDE_H) && Event.xbutton.window == - r_button && Pressed == r_button){ - Pressed = None; - RedrawRightButton(ReliefGC, ShadowGC); - } - else if (!(local_flags & HIDE_V) && Event.xbutton.window == - t_button && Pressed == t_button){ - Pressed = None; - RedrawTopButton(ReliefGC, ShadowGC); - } - else if (!(local_flags & HIDE_V) && Event.xbutton.window == - b_button && Pressed == b_button){ - Pressed = None; - RedrawBottomButton(ReliefGC, ShadowGC); - } - break; - case ClientMessage: - if ((Event.xclient.format==32) && - (Event.xclient.data.l[0]==wm_del_win)) - DeadPipe(1); - break; - case PropertyNotify: - switch (Event.xproperty.atom){ - case XA_WM_HINTS: - if (Event.xproperty.state == PropertyDelete) - break; - tmp = Head; - i=0; - while(tmp != NULL){ - if (Event.xproperty.window == tmp->id) - break; - tmp = tmp->next; - ++i; - } - if (tmp == NULL || tmp->wmhints == NULL || !(tmp->extra_flags & DEFAULTICON)) - break; - if (tmp->wmhints) - XFree (tmp->wmhints); - tmp->wmhints = XGetWMHints(dpy, tmp->id); - if (tmp->wmhints && (tmp->wmhints->flags & IconPixmapHint)){ + Window root; + struct icon_info *tmp, *exhilite; + int x, y, border_width, depth; + int i, hr = icon_relief / 2; + XEvent Event; + int tw, th; + int diffx, diffy; + int oldw, oldh; + + sandbox_x11_only("FvwmIconBox"); + + while (1) { + if (My_XNextEvent(dpy, &Event)) { + switch (Event.type) { + case Expose: + if (Event.xexpose.count == 0) { + if (Event.xany.window == main_win) { + RedrawWindow(); + } else { + tmp = Head; + while (tmp != NULL) { + if (Event.xany.window == + tmp->icon_pixmap_w) { + RedrawIcon( + tmp, 1); + break; + } else if (Event.xany.window == + tmp->IconWin) { + RedrawIcon( + tmp, 2); + break; + } + tmp = tmp->next; + } + } + } + break; + + case ConfigureNotify: + XGetGeometry(dpy, main_win, &root, &x, &y, + (unsigned int *)&tw, (unsigned int *)&th, + (unsigned int *)&border_width, + (unsigned int *)&depth); + if (ready && + (tw != main_width || th != main_height)) { + main_width = tw; + main_height = th; + oldw = Width; + oldh = Height; + num_columns = + (tw - h_margin - interval + 1) / + UWidth; + num_rows = + (th - v_margin - interval + 1) / + UHeight; + Width = + UWidth * num_columns + interval - 1; + Height = + UHeight * num_rows + interval - 1; + XMoveResizeWindow(dpy, holder_win, + margin1 + 2, margin1 + 2, + tw - h_margin, th - v_margin); + if (!(local_flags & HIDE_H)) + XResizeWindow(dpy, h_scroll_bar, + Width - bar_width * 2, + bar_width); + if (!(local_flags & HIDE_V)) + XResizeWindow(dpy, v_scroll_bar, + bar_width, + Height - bar_width * 2); + GetIconwinSize(&diffx, &diffy); + if (primary == BOTTOM || + secondary == BOTTOM) + icon_win_y -= Height - oldh; + if (primary == RIGHT || + secondary == RIGHT) + icon_win_x -= Width - oldw; + if (icon_win_x < 0) + icon_win_x = 0; + if (icon_win_y < 0) + icon_win_y = 0; + if (icon_win_x + Width > icon_win_width) + icon_win_x = + icon_win_width - Width; + if (icon_win_y + Height > + icon_win_height) + icon_win_y = + icon_win_height - Height; + XMoveResizeWindow(dpy, icon_win, + -icon_win_x, -icon_win_y, + icon_win_width, icon_win_height); + AdjustIconWindows(); + XClearWindow(dpy, main_win); + RedrawWindow(); + } + break; + case KeyPress: + ExecuteKey(Event); + break; + case ButtonPress: + if (!(local_flags & HIDE_H)) { + if (Event.xbutton.window == + h_scroll_bar) + motion = HORIZONTAL; + else if (Event.xbutton.window == + l_button) { + Pressed = l_button; + RedrawLeftButton( + ShadowGC, ReliefGC); + } else if (Event.xbutton.window == + r_button) { + Pressed = r_button; + RedrawRightButton( + ShadowGC, ReliefGC); + } + } + if (!(local_flags & HIDE_V)) { + if (Event.xbutton.window == + v_scroll_bar) + motion = VERTICAL; + else if (Event.xbutton.window == + t_button) { + Pressed = t_button; + RedrawTopButton( + ShadowGC, ReliefGC); + } else if (Event.xbutton.window == + b_button) { + Pressed = b_button; + RedrawBottomButton( + ShadowGC, ReliefGC); + } + } + if ((tmp = Search(Event.xbutton.window)) != + NULL) + ExecuteAction(Event.xbutton.x, + Event.xbutton.y, tmp); + break; + + case ButtonRelease: + if (!(local_flags & HIDE_H)) { + if (Event.xbutton.window == + h_scroll_bar && + motion == HORIZONTAL) + HScroll(Event.xbutton.x * + icon_win_width / Width); + else if (Event.xbutton.window == + l_button && + Pressed == l_button) { + Pressed = None; + RedrawLeftButton( + ReliefGC, ShadowGC); + HScroll(icon_win_x - UWidth); + } else if (Event.xbutton.window == + r_button && + Pressed == r_button) { + Pressed = None; + RedrawRightButton( + ReliefGC, ShadowGC); + HScroll(icon_win_x + UWidth); + } + } + if (!(local_flags & HIDE_V)) { + if (Event.xbutton.window == + v_scroll_bar && + motion == VERTICAL) + VScroll(Event.xbutton.y * + icon_win_height / + Height); + else if (Event.xbutton.window == + t_button && + Pressed == t_button) { + Pressed = None; + RedrawTopButton( + ReliefGC, ShadowGC); + VScroll(icon_win_y - UHeight); + } else if (Event.xbutton.window == + b_button && + Pressed == b_button) { + Pressed = None; + RedrawBottomButton( + ReliefGC, ShadowGC); + VScroll(icon_win_y + UHeight); + } + } + motion = NONE; + break; + + case MotionNotify: + if (motion == VERTICAL) { + VScroll(Event.xbutton.y * + icon_win_height / Height); + } else if (motion == HORIZONTAL) { + HScroll(Event.xbutton.x * + icon_win_width / Width); + } + break; + case EnterNotify: + if ((tmp = Search(Event.xcrossing.window)) != + NULL) + if ((exhilite = Hilite) != tmp) { + Hilite = tmp; + if (exhilite != NULL) + RedrawIcon(exhilite, + redraw_flag); + RedrawIcon(tmp, redraw_flag); + } + break; + + case LeaveNotify: + if ((tmp = Search(Event.xcrossing.window)) != + NULL && + tmp == Hilite) { + Hilite = NULL; + RedrawIcon(tmp, redraw_flag); + } + if (!(local_flags & HIDE_H) && + Event.xbutton.window == l_button && + Pressed == l_button) { + Pressed = None; + RedrawLeftButton(ReliefGC, ShadowGC); + } else if (!(local_flags & HIDE_H) && + Event.xbutton.window == r_button && + Pressed == r_button) { + Pressed = None; + RedrawRightButton(ReliefGC, ShadowGC); + } else if (!(local_flags & HIDE_V) && + Event.xbutton.window == t_button && + Pressed == t_button) { + Pressed = None; + RedrawTopButton(ReliefGC, ShadowGC); + } else if (!(local_flags & HIDE_V) && + Event.xbutton.window == b_button && + Pressed == b_button) { + Pressed = None; + RedrawBottomButton(ReliefGC, ShadowGC); + } + break; + case ClientMessage: + if ((Event.xclient.format == 32) && + (Event.xclient.data.l[0] == wm_del_win)) + DeadPipe(1); + break; + case PropertyNotify: + switch (Event.xproperty.atom) { + case XA_WM_HINTS: + if (Event.xproperty.state == + PropertyDelete) + break; + tmp = Head; + i = 0; + while (tmp != NULL) { + if (Event.xproperty.window == + tmp->id) + break; + tmp = tmp->next; + ++i; + } + if (tmp == NULL || + tmp->wmhints == NULL || + !(tmp->extra_flags & DEFAULTICON)) + break; + if (tmp->wmhints) + XFree(tmp->wmhints); + tmp->wmhints = + XGetWMHints(dpy, tmp->id); + if (tmp->wmhints && + (tmp->wmhints->flags & + IconPixmapHint)) { #ifdef SHAPE - /* turn off "old" shape mask */ - if (tmp->icon_maskPixmap != None) - XShapeCombineMask(dpy, tmp->icon_pixmap_w, - ShapeBounding, 0, 0, None, ShapeSet); + /* turn off "old" shape mask */ + if (tmp->icon_maskPixmap != + None) + XShapeCombineMask(dpy, + tmp->icon_pixmap_w, + ShapeBounding, 0, 0, + None, ShapeSet); #endif - if (tmp->iconPixmap != None) - XFreePixmap(dpy, tmp->iconPixmap); - GetIconBitmap(tmp); + if (tmp->iconPixmap != None) + XFreePixmap(dpy, + tmp->iconPixmap); + GetIconBitmap(tmp); #ifdef SHAPE - if (tmp->icon_maskPixmap != None) - XShapeCombineMask(dpy, tmp->icon_pixmap_w, - ShapeBounding, hr, hr, - tmp->icon_maskPixmap, ShapeSet); + if (tmp->icon_maskPixmap != + None) + XShapeCombineMask(dpy, + tmp->icon_pixmap_w, + ShapeBounding, hr, + hr, + tmp->icon_maskPixmap, + ShapeSet); #endif - AdjustIconWindow(tmp, i); - if (max_icon_height != 0) - RedrawIcon(tmp, 1); + AdjustIconWindow(tmp, i); + if (max_icon_height != 0) + RedrawIcon(tmp, 1); + } + break; + } + break; + + default: + break; + } } - break; - } - break; - - default: - break; - } } - } - return; + return; } -void HScroll(int x) +void +HScroll(int x) { - int oldx = icon_win_x; - - if (x + Width > icon_win_width) - x = icon_win_width - Width; - if (x < 0) - x = 0; - if (oldx != x){ - icon_win_x = x; - XMoveWindow(dpy,icon_win, -icon_win_x, -icon_win_y); - if (!(local_flags & HIDE_H)) - RedrawHScrollbar(); - } + int oldx = icon_win_x; + + if (x + Width > icon_win_width) + x = icon_win_width - Width; + if (x < 0) + x = 0; + if (oldx != x) { + icon_win_x = x; + XMoveWindow(dpy, icon_win, -icon_win_x, -icon_win_y); + if (!(local_flags & HIDE_H)) + RedrawHScrollbar(); + } } -void VScroll(int y) +void +VScroll(int y) { - int oldy = icon_win_y; - - if (y + Height > icon_win_height) - y = icon_win_height - Height; - if (y < 0) - y = 0; - if (oldy != y){ - icon_win_y = y; - XMoveWindow(dpy,icon_win, -icon_win_x, -icon_win_y); - if (!(local_flags & HIDE_V)) - RedrawVScrollbar(); - } + int oldy = icon_win_y; + + if (y + Height > icon_win_height) + y = icon_win_height - Height; + if (y < 0) + y = 0; + if (oldy != y) { + icon_win_y = y; + XMoveWindow(dpy, icon_win, -icon_win_x, -icon_win_y); + if (!(local_flags & HIDE_V)) + RedrawVScrollbar(); + } } -struct icon_info *Search(Window w) +struct icon_info * +Search(Window w) { - struct icon_info *tmp; + struct icon_info *tmp; - tmp = Head; - while (tmp != NULL){ - if (tmp->IconWin == w || tmp->icon_pixmap_w == w) - return tmp; - tmp = tmp->next; - } - return NULL; + tmp = Head; + while (tmp != NULL) { + if (tmp->IconWin == w || tmp->icon_pixmap_w == w) + return tmp; + tmp = tmp->next; + } + return NULL; } /************************************************************************ @@ -544,151 +612,156 @@ struct icon_info *Search(Window w) * Draw the window * ***********************************************************************/ -void RedrawWindow(void) +void +RedrawWindow(void) { - XEvent dummy; - - while (XCheckTypedWindowEvent (dpy, main_win, Expose, &dummy)); - - RelieveWindow(main_win, margin1, margin1, Width + 4, - Height + 4, ShadowGC,ReliefGC); - if (!(local_flags & HIDE_H)) - RelieveWindow(main_win, margin1, margin1 + 4 + Height + margin2, - Width + 4, bar_width+4, ShadowGC,ReliefGC); - if (!(local_flags & HIDE_V)) - RelieveWindow(main_win, margin1 + 4 + Width + margin2, margin1, - bar_width+4, Height + 4, ShadowGC,ReliefGC); - RelieveWindow(main_win, 0, 0, Width + h_margin, Height + v_margin, - ReliefGC, ShadowGC); - - /* scroll bar */ - if (!(local_flags & HIDE_H)) - RedrawHScrollbar(); - if (!(local_flags & HIDE_V)) - RedrawVScrollbar(); - - /* buttons */ - if (!(local_flags & HIDE_H)){ - RedrawLeftButton(ReliefGC, ShadowGC); - RedrawRightButton(ReliefGC, ShadowGC); - } - if (!(local_flags & HIDE_V)){ - RedrawTopButton(ReliefGC, ShadowGC); - RedrawBottomButton(ReliefGC, ShadowGC); - } + XEvent dummy; - /* icons */ - RedrawIcons(); + while (XCheckTypedWindowEvent(dpy, main_win, Expose, &dummy)) + ; + + RelieveWindow(main_win, margin1, margin1, Width + 4, Height + 4, + ShadowGC, ReliefGC); + if (!(local_flags & HIDE_H)) + RelieveWindow(main_win, margin1, margin1 + 4 + Height + margin2, + Width + 4, bar_width + 4, ShadowGC, ReliefGC); + if (!(local_flags & HIDE_V)) + RelieveWindow(main_win, margin1 + 4 + Width + margin2, margin1, + bar_width + 4, Height + 4, ShadowGC, ReliefGC); + RelieveWindow(main_win, 0, 0, Width + h_margin, Height + v_margin, + ReliefGC, ShadowGC); + + /* scroll bar */ + if (!(local_flags & HIDE_H)) + RedrawHScrollbar(); + if (!(local_flags & HIDE_V)) + RedrawVScrollbar(); + + /* buttons */ + if (!(local_flags & HIDE_H)) { + RedrawLeftButton(ReliefGC, ShadowGC); + RedrawRightButton(ReliefGC, ShadowGC); + } + if (!(local_flags & HIDE_V)) { + RedrawTopButton(ReliefGC, ShadowGC); + RedrawBottomButton(ReliefGC, ShadowGC); + } + + /* icons */ + RedrawIcons(); } -void RedrawIcons(void) +void +RedrawIcons(void) { - struct icon_info *tmp; + struct icon_info *tmp; - tmp = Head; - while(tmp != NULL){ - if (desk_cond(tmp)) - RedrawIcon(tmp, redraw_flag); - tmp = tmp->next; - } + tmp = Head; + while (tmp != NULL) { + if (desk_cond(tmp)) + RedrawIcon(tmp, redraw_flag); + tmp = tmp->next; + } } -void RedrawIcon(struct icon_info *item, int f) +void +RedrawIcon(struct icon_info *item, int f) { - unsigned long plane = 1; - int hr, len; - int diff, lm ,w, h, tw; - char label[256]; - - hr = icon_relief/2; - - if (Hilite == item){ - XSetForeground(dpy, NormalGC, act_icon_fore_pix); - XSetBackground(dpy, NormalGC, act_icon_back_pix); - XSetForeground(dpy, IconReliefGC, act_icon_hilite_pix); - XSetForeground(dpy, IconShadowGC, act_icon_shadow_pix); - - if (max_icon_height != 0 && (item->flags & ICON_OURS)) - XSetWindowBackground(dpy, item->icon_pixmap_w, act_icon_back_pix); - XSetWindowBackground(dpy, item->IconWin, act_icon_back_pix); - } + unsigned long plane = 1; + int hr, len; + int diff, lm, w, h, tw; + char label[256]; + + hr = icon_relief / 2; + + if (Hilite == item) { + XSetForeground(dpy, NormalGC, act_icon_fore_pix); + XSetBackground(dpy, NormalGC, act_icon_back_pix); + XSetForeground(dpy, IconReliefGC, act_icon_hilite_pix); + XSetForeground(dpy, IconShadowGC, act_icon_shadow_pix); + + if (max_icon_height != 0 && (item->flags & ICON_OURS)) + XSetWindowBackground( + dpy, item->icon_pixmap_w, act_icon_back_pix); + XSetWindowBackground(dpy, item->IconWin, act_icon_back_pix); + } - /* icon pixmap */ - if ((f & 1) && (item->flags & ICON_OURS)){ - if (item->iconPixmap != None && item->icon_pixmap_w != None){ - if (item->icon_depth != d_depth) - XCopyPlane(dpy, item->iconPixmap, item->icon_pixmap_w, NormalGC, - 0, 0, item->icon_w, item->icon_h, - hr, hr, plane); - else - XCopyArea(dpy, item->iconPixmap, item->icon_pixmap_w, NormalGC, - 0, 0, item->icon_w, item->icon_h, hr, hr); - } - if (!(item->flags & SHAPED_ICON)){ - if (item->icon_w > 0 && item->icon_h > 0) - RelieveWindow(item->icon_pixmap_w, 0, 0, item->icon_w - +icon_relief, - item->icon_h + icon_relief, IconReliefGC, - IconShadowGC); - else - RelieveWindow(item->icon_pixmap_w, 0, 0, max_icon_width - +icon_relief, - max_icon_height + icon_relief, IconReliefGC, - IconShadowGC); - } - } + /* icon pixmap */ + if ((f & 1) && (item->flags & ICON_OURS)) { + if (item->iconPixmap != None && item->icon_pixmap_w != None) { + if (item->icon_depth != d_depth) + XCopyPlane(dpy, item->iconPixmap, + item->icon_pixmap_w, NormalGC, 0, 0, + item->icon_w, item->icon_h, hr, hr, plane); + else + XCopyArea(dpy, item->iconPixmap, + item->icon_pixmap_w, NormalGC, 0, 0, + item->icon_w, item->icon_h, hr, hr); + } + if (!(item->flags & SHAPED_ICON)) { + if (item->icon_w > 0 && item->icon_h > 0) + RelieveWindow(item->icon_pixmap_w, 0, 0, + item->icon_w + icon_relief, + item->icon_h + icon_relief, IconReliefGC, + IconShadowGC); + else + RelieveWindow(item->icon_pixmap_w, 0, 0, + max_icon_width + icon_relief, + max_icon_height + icon_relief, IconReliefGC, + IconShadowGC); + } + } - /* label */ - if (f & 2){ - w = max_icon_width + icon_relief; - h = max_icon_height + icon_relief; - - if (item->flags & ICONIFIED){ - sprintf(label, "(%s)", item->name); - }else - strcpy(label, item->name); - - len = strlen(label); - tw = XTextWidth(font, label, len); - diff = max_icon_width + icon_relief - tw; - lm = diff/2; - lm = lm > 4 ? lm : 4; - - if (Hilite == item){ - XRaiseWindow(dpy, item->IconWin); - XMoveResizeWindow(dpy, item->IconWin, - item->x + min(0, (diff - 8))/2, - item->y + h, - max(tw + 8, w), 6 + font->ascent + - font->descent); - XClearWindow(dpy, item->IconWin); - XDrawString(dpy, item->IconWin, NormalGC, lm, 3 + font->ascent, - label, len); - RelieveWindow(item->IconWin, 0, 0, - max(tw + 8, w), 6 + font->ascent + - font->descent, IconReliefGC, IconShadowGC); - }else{ - XMoveResizeWindow(dpy, item->IconWin, item->x, item->y + h, - w, 6 + font->ascent + font->descent); - XClearWindow(dpy, item->IconWin); - XDrawString(dpy, item->IconWin, NormalGC, lm, 3 + font->ascent, - label, len); - RelieveWindow(item->IconWin, 0, 0, - w, 6 + font->ascent + font->descent, - IconReliefGC, IconShadowGC); - } - } + /* label */ + if (f & 2) { + w = max_icon_width + icon_relief; + h = max_icon_height + icon_relief; + + if (item->flags & ICONIFIED) { + snprintf(label, sizeof(label), "(%s)", item->name); + } else + strlcpy(label, item->name, sizeof(label)); + + len = strlen(label); + tw = XTextWidth(font, label, len); + diff = max_icon_width + icon_relief - tw; + lm = diff / 2; + lm = lm > 4 ? lm : 4; + + if (Hilite == item) { + XRaiseWindow(dpy, item->IconWin); + XMoveResizeWindow(dpy, item->IconWin, + item->x + min(0, (diff - 8)) / 2, item->y + h, + max(tw + 8, w), 6 + font->ascent + font->descent); + XClearWindow(dpy, item->IconWin); + XDrawString(dpy, item->IconWin, NormalGC, lm, + 3 + font->ascent, label, len); + RelieveWindow(item->IconWin, 0, 0, max(tw + 8, w), + 6 + font->ascent + font->descent, IconReliefGC, + IconShadowGC); + } else { + XMoveResizeWindow(dpy, item->IconWin, item->x, + item->y + h, w, 6 + font->ascent + font->descent); + XClearWindow(dpy, item->IconWin); + XDrawString(dpy, item->IconWin, NormalGC, lm, + 3 + font->ascent, label, len); + RelieveWindow(item->IconWin, 0, 0, w, + 6 + font->ascent + font->descent, IconReliefGC, + IconShadowGC); + } + } - if (Hilite == item){ - XSetForeground(dpy, NormalGC, icon_fore_pix); - XSetBackground(dpy, NormalGC, icon_back_pix); - XSetForeground(dpy, IconReliefGC, icon_hilite_pix); - XSetForeground(dpy, IconShadowGC, icon_shadow_pix); + if (Hilite == item) { + XSetForeground(dpy, NormalGC, icon_fore_pix); + XSetBackground(dpy, NormalGC, icon_back_pix); + XSetForeground(dpy, IconReliefGC, icon_hilite_pix); + XSetForeground(dpy, IconShadowGC, icon_shadow_pix); - if (max_icon_height != 0 && (item->flags & ICON_OURS)) - XSetWindowBackground(dpy, item->icon_pixmap_w, icon_back_pix); - XSetWindowBackground(dpy, item->IconWin, icon_back_pix); - } + if (max_icon_height != 0 && (item->flags & ICON_OURS)) + XSetWindowBackground( + dpy, item->icon_pixmap_w, icon_back_pix); + XSetWindowBackground(dpy, item->IconWin, icon_back_pix); + } } /*********************************************************************** @@ -696,14 +769,15 @@ void RedrawIcon(struct icon_info *item, int f) * Based on part of Loop() of GrabWindow.c in FvwmScroll: * Copyright 1994, Robert Nation. ***********************************************************************/ -void RedrawHScrollbar(void) +void +RedrawHScrollbar(void) { - int x,width; + int x, width; - x = (Width - bar_width*2) * icon_win_x / icon_win_width; - width = (Width - bar_width*2) * Width / icon_win_width; - XClearArea(dpy, h_scroll_bar, 0, 0, Width, bar_width,False); - RelieveWindow(h_scroll_bar, x, 0, width, bar_width, ReliefGC, ShadowGC); + x = (Width - bar_width * 2) * icon_win_x / icon_win_width; + width = (Width - bar_width * 2) * Width / icon_win_width; + XClearArea(dpy, h_scroll_bar, 0, 0, Width, bar_width, False); + RelieveWindow(h_scroll_bar, x, 0, width, bar_width, ReliefGC, ShadowGC); } /*********************************************************************** @@ -711,123 +785,177 @@ void RedrawHScrollbar(void) * Based on part of Loop() of GrabWindow.c in FvwmScroll: * Copyright 1994, Robert Nation. ***********************************************************************/ -void RedrawVScrollbar(void) +void +RedrawVScrollbar(void) { - int y, height; + int y, height; - y = (Height - bar_width*2) * icon_win_y / icon_win_height; - height = (Height - bar_width*2)* Height / icon_win_height; - XClearArea(dpy, v_scroll_bar, 0, 0, bar_width, Height,False); - RelieveWindow(v_scroll_bar, 0, y, bar_width, height, ReliefGC, ShadowGC); + y = (Height - bar_width * 2) * icon_win_y / icon_win_height; + height = (Height - bar_width * 2) * Height / icon_win_height; + XClearArea(dpy, v_scroll_bar, 0, 0, bar_width, Height, False); + RelieveWindow( + v_scroll_bar, 0, y, bar_width, height, ReliefGC, ShadowGC); } -void RedrawLeftButton(GC rgc, GC sgc) +void +RedrawLeftButton(GC rgc, GC sgc) { - XSegment seg[4]; - int i=0; - - seg[i].x1 = 1; seg[i].y1 = bar_width/2; - seg[i].x2 = bar_width - 2; seg[i++].y2 = 1; - - seg[i].x1 = 0; seg[i].y1 = bar_width/2; - seg[i].x2 = bar_width - 1; seg[i++].y2 = 0; - XDrawSegments(dpy, l_button, rgc, seg, i); - - i = 0; - seg[i].x1 = 1; seg[i].y1 = bar_width/2; - seg[i].x2 = bar_width - 2; seg[i++].y2 = bar_width - 2; - - seg[i].x1 = 0; seg[i].y1 = bar_width/2; - seg[i].x2 = bar_width - 1; seg[i++].y2 = bar_width - 1; - - seg[i].x1 = bar_width - 2; seg[i].y1 = 1; - seg[i].x2 = bar_width - 2; seg[i++].y2 = bar_width - 2; - - seg[i].x1 = bar_width - 1; seg[i].y1 = 0; - seg[i].x2 = bar_width - 1; seg[i++].y2 = bar_width - 1; - XDrawSegments(dpy, l_button, sgc, seg, i); + XSegment seg[4]; + int i = 0; + + seg[i].x1 = 1; + seg[i].y1 = bar_width / 2; + seg[i].x2 = bar_width - 2; + seg[i++].y2 = 1; + + seg[i].x1 = 0; + seg[i].y1 = bar_width / 2; + seg[i].x2 = bar_width - 1; + seg[i++].y2 = 0; + XDrawSegments(dpy, l_button, rgc, seg, i); + + i = 0; + seg[i].x1 = 1; + seg[i].y1 = bar_width / 2; + seg[i].x2 = bar_width - 2; + seg[i++].y2 = bar_width - 2; + + seg[i].x1 = 0; + seg[i].y1 = bar_width / 2; + seg[i].x2 = bar_width - 1; + seg[i++].y2 = bar_width - 1; + + seg[i].x1 = bar_width - 2; + seg[i].y1 = 1; + seg[i].x2 = bar_width - 2; + seg[i++].y2 = bar_width - 2; + + seg[i].x1 = bar_width - 1; + seg[i].y1 = 0; + seg[i].x2 = bar_width - 1; + seg[i++].y2 = bar_width - 1; + XDrawSegments(dpy, l_button, sgc, seg, i); } -void RedrawRightButton(GC rgc, GC sgc) +void +RedrawRightButton(GC rgc, GC sgc) { - XSegment seg[4]; - int i=0; - - seg[i].x1 = 1; seg[i].y1 = 1; - seg[i].x2 = 1; seg[i++].y2 = bar_width - 2; - - seg[i].x1 = 0; seg[i].y1 = 0; - seg[i].x2 = 0; seg[i++].y2 = bar_width - 1; - - seg[i].x1 = 1; seg[i].y1 = 1; - seg[i].x2 = bar_width - 2; seg[i++].y2 = bar_width/2; - - seg[i].x1 = 0; seg[i].y1 = 0; - seg[i].x2 = bar_width - 1; seg[i++].y2 = bar_width/2; - - XDrawSegments(dpy, r_button, rgc, seg, i); - - i = 0; - seg[i].x1 = 1; seg[i].y1 = bar_width - 2; - seg[i].x2 = bar_width - 2; seg[i++].y2 = bar_width/2; - - seg[i].x1 = 0; seg[i].y1 = bar_width - 1; - seg[i].x2 = bar_width - 1; seg[i++].y2 = bar_width/2; - XDrawSegments(dpy, r_button, sgc, seg, i); + XSegment seg[4]; + int i = 0; + + seg[i].x1 = 1; + seg[i].y1 = 1; + seg[i].x2 = 1; + seg[i++].y2 = bar_width - 2; + + seg[i].x1 = 0; + seg[i].y1 = 0; + seg[i].x2 = 0; + seg[i++].y2 = bar_width - 1; + + seg[i].x1 = 1; + seg[i].y1 = 1; + seg[i].x2 = bar_width - 2; + seg[i++].y2 = bar_width / 2; + + seg[i].x1 = 0; + seg[i].y1 = 0; + seg[i].x2 = bar_width - 1; + seg[i++].y2 = bar_width / 2; + + XDrawSegments(dpy, r_button, rgc, seg, i); + + i = 0; + seg[i].x1 = 1; + seg[i].y1 = bar_width - 2; + seg[i].x2 = bar_width - 2; + seg[i++].y2 = bar_width / 2; + + seg[i].x1 = 0; + seg[i].y1 = bar_width - 1; + seg[i].x2 = bar_width - 1; + seg[i++].y2 = bar_width / 2; + XDrawSegments(dpy, r_button, sgc, seg, i); } -void RedrawTopButton(GC rgc, GC sgc) +void +RedrawTopButton(GC rgc, GC sgc) { - XSegment seg[4]; - int i=0; - - seg[i].x1 = bar_width/2; seg[i].y1 = 1; - seg[i].x2 = 1; seg[i++].y2 = bar_width - 2; - - seg[i].x1 = bar_width/2; seg[i].y1 = 0; - seg[i].x2 = 0; seg[i++].y2 = bar_width - 1; - XDrawSegments(dpy, t_button, rgc, seg, i); - - i = 0; - seg[i].x1 = bar_width/2; seg[i].y1 = 1; - seg[i].x2 = bar_width - 2; seg[i++].y2 = bar_width - 2; - - seg[i].x1 = bar_width/2; seg[i].y1 = 0; - seg[i].x2 = bar_width - 1; seg[i++].y2 = bar_width - 1; - - seg[i].x1 = 1; seg[i].y1 = bar_width - 2; - seg[i].x2 = bar_width - 2; seg[i++].y2 = bar_width - 2; - - seg[i].x1 = 0; seg[i].y1 = bar_width - 1; - seg[i].x2 = bar_width - 1; seg[i++].y2 = bar_width - 1; - XDrawSegments(dpy, t_button, sgc, seg, i); + XSegment seg[4]; + int i = 0; + + seg[i].x1 = bar_width / 2; + seg[i].y1 = 1; + seg[i].x2 = 1; + seg[i++].y2 = bar_width - 2; + + seg[i].x1 = bar_width / 2; + seg[i].y1 = 0; + seg[i].x2 = 0; + seg[i++].y2 = bar_width - 1; + XDrawSegments(dpy, t_button, rgc, seg, i); + + i = 0; + seg[i].x1 = bar_width / 2; + seg[i].y1 = 1; + seg[i].x2 = bar_width - 2; + seg[i++].y2 = bar_width - 2; + + seg[i].x1 = bar_width / 2; + seg[i].y1 = 0; + seg[i].x2 = bar_width - 1; + seg[i++].y2 = bar_width - 1; + + seg[i].x1 = 1; + seg[i].y1 = bar_width - 2; + seg[i].x2 = bar_width - 2; + seg[i++].y2 = bar_width - 2; + + seg[i].x1 = 0; + seg[i].y1 = bar_width - 1; + seg[i].x2 = bar_width - 1; + seg[i++].y2 = bar_width - 1; + XDrawSegments(dpy, t_button, sgc, seg, i); } -void RedrawBottomButton(GC rgc, GC sgc) +void +RedrawBottomButton(GC rgc, GC sgc) { - XSegment seg[4]; - int i=0; - - seg[i].x1 = 1; seg[i].y1 = 1; - seg[i].x2 = bar_width/2; seg[i++].y2 = bar_width - 2; - - seg[i].x1 = 0; seg[i].y1 = 0; - seg[i].x2 = bar_width/2; seg[i++].y2 = bar_width - 1; - - seg[i].x1 = 1; seg[i].y1 = 1; - seg[i].x2 = bar_width - 2; seg[i++].y2 = 1; - - seg[i].x1 = 0; seg[i].y1 = 0; - seg[i].x2 = bar_width - 1; seg[i++].y2 = 0; - XDrawSegments(dpy, b_button, rgc, seg, i); - - i = 0; - seg[i].x1 = bar_width - 2; seg[i].y1 = 1; - seg[i].x2 = bar_width/2; seg[i++].y2 = bar_width - 2; - - seg[i].x1 = bar_width - 1; seg[i].y1 = 0; - seg[i].x2 = bar_width/2; seg[i++].y2 = bar_width - 1; - XDrawSegments(dpy, b_button, sgc, seg, i); + XSegment seg[4]; + int i = 0; + + seg[i].x1 = 1; + seg[i].y1 = 1; + seg[i].x2 = bar_width / 2; + seg[i++].y2 = bar_width - 2; + + seg[i].x1 = 0; + seg[i].y1 = 0; + seg[i].x2 = bar_width / 2; + seg[i++].y2 = bar_width - 1; + + seg[i].x1 = 1; + seg[i].y1 = 1; + seg[i].x2 = bar_width - 2; + seg[i++].y2 = 1; + + seg[i].x1 = 0; + seg[i].y1 = 0; + seg[i].x2 = bar_width - 1; + seg[i++].y2 = 0; + XDrawSegments(dpy, b_button, rgc, seg, i); + + i = 0; + seg[i].x1 = bar_width - 2; + seg[i].y1 = 1; + seg[i].x2 = bar_width / 2; + seg[i++].y2 = bar_width - 2; + + seg[i].x1 = bar_width - 1; + seg[i].y1 = 0; + seg[i].x2 = bar_width / 2; + seg[i++].y2 = bar_width - 1; + XDrawSegments(dpy, b_button, sgc, seg, i); } /************************************************************************ @@ -835,44 +963,61 @@ void RedrawBottomButton(GC rgc, GC sgc) Original work from GoodStuff: Copyright 1993, Robert Nation. ************************************************************************/ -void RelieveWindow(Window win,int x,int y,int w,int h, GC rgc,GC sgc) +void +RelieveWindow(Window win, int x, int y, int w, int h, GC rgc, GC sgc) { - XSegment seg[4]; - int i; - - i=0; - seg[i].x1 = x; seg[i].y1 = y; - seg[i].x2 = w+x-1; seg[i++].y2 = y; - - seg[i].x1 = x; seg[i].y1 = y; - seg[i].x2 = x; seg[i++].y2 = h+y-1; - - seg[i].x1 = x+1; seg[i].y1 = y+1; - seg[i].x2 = x+w-2; seg[i++].y2 = y+1; - - seg[i].x1 = x+1; seg[i].y1 = y+1; - seg[i].x2 = x+1; seg[i++].y2 = y+h-2; - XDrawSegments(dpy, win, rgc, seg, i); - - i=0; - seg[i].x1 = x; seg[i].y1 = y+h-1; - seg[i].x2 = w+x-1; seg[i++].y2 = y+h-1; - - seg[i].x1 = x+w-1; seg[i].y1 = y; - seg[i].x2 = x+w-1; seg[i++].y2 = y+h-1; - if(d_depth<2) - XDrawSegments(dpy, win, ShadowGC, seg, i); - else - XDrawSegments(dpy, win, sgc, seg, i); - - i=0; - seg[i].x1 = x+1; seg[i].y1 = y+h-2; - seg[i].x2 = x+w-2; seg[i++].y2 = y+h-2; - - seg[i].x1 = x+w-2; seg[i].y1 = y+1; - seg[i].x2 = x+w-2; seg[i++].y2 = y+h-2; - - XDrawSegments(dpy, win, sgc, seg, i); + XSegment seg[4]; + int i; + + i = 0; + seg[i].x1 = x; + seg[i].y1 = y; + seg[i].x2 = w + x - 1; + seg[i++].y2 = y; + + seg[i].x1 = x; + seg[i].y1 = y; + seg[i].x2 = x; + seg[i++].y2 = h + y - 1; + + seg[i].x1 = x + 1; + seg[i].y1 = y + 1; + seg[i].x2 = x + w - 2; + seg[i++].y2 = y + 1; + + seg[i].x1 = x + 1; + seg[i].y1 = y + 1; + seg[i].x2 = x + 1; + seg[i++].y2 = y + h - 2; + XDrawSegments(dpy, win, rgc, seg, i); + + i = 0; + seg[i].x1 = x; + seg[i].y1 = y + h - 1; + seg[i].x2 = w + x - 1; + seg[i++].y2 = y + h - 1; + + seg[i].x1 = x + w - 1; + seg[i].y1 = y; + seg[i].x2 = x + w - 1; + seg[i++].y2 = y + h - 1; + if (d_depth < 2) + XDrawSegments(dpy, win, ShadowGC, seg, i); + else + XDrawSegments(dpy, win, sgc, seg, i); + + i = 0; + seg[i].x1 = x + 1; + seg[i].y1 = y + h - 2; + seg[i].x2 = x + w - 2; + seg[i++].y2 = y + h - 2; + + seg[i].x1 = x + w - 2; + seg[i].y1 = y + 1; + seg[i].x2 = x + w - 2; + seg[i++].y2 = y + h - 2; + + XDrawSegments(dpy, win, sgc, seg, i); } /************************************************************************ @@ -880,257 +1025,236 @@ void RelieveWindow(Window win,int x,int y,int w,int h, GC rgc,GC sgc) * Based on CreateWindow() from GoodStuff: * Copyright 1993, Robert Nation. ***********************************************************************/ -void CreateWindow(void) +void +CreateWindow(void) { - XGCValues gcv; - unsigned long gcm; - unsigned long mask; - char *list[2]; - XSetWindowAttributes attributes; - XSizeHints mysizehints; - XTextProperty name; - XClassHint class_hints; - - h_margin = margin1*2 + bar_width + margin2 + 8; - v_margin = margin1*2 + bar_width + margin2 + 8; - - wm_del_win = XInternAtom(dpy,"WM_DELETE_WINDOW",False); - _XA_WM_PROTOCOLS = XInternAtom (dpy, "WM_PROTOCOLS", False); - - /* load the font */ - if ((font = XLoadQueryFont(dpy, font_string)) == NULL) - { - if ((font = XLoadQueryFont(dpy, "fixed")) == NULL) - { - fprintf(stderr,"%s: No fonts available\n",MyName); - exit(1); - } - }; - - if ((local_flags & HIDE_H)) - v_margin -= bar_width + margin2 + 4; - if ((local_flags & HIDE_V)) - h_margin -= bar_width + margin2 + 4; - - UWidth = max_icon_width + icon_relief + interval; - UHeight = font->ascent + font->descent + max_icon_height + - icon_relief + 6 + interval; - Width = UWidth * num_columns + interval -1; - Height = UHeight * num_rows + interval -1; - - mysizehints.flags = PWinGravity| PResizeInc | PMinSize; - - /* subtract one for the right/bottom border */ - mysizehints.min_width = UWidth + interval - 1 + h_margin; - main_width = mysizehints.width = Width + h_margin; - mysizehints.min_height = UHeight + interval - 1 + v_margin; - main_height = mysizehints.height = Height + v_margin; - mysizehints.width_inc = UWidth; - mysizehints.height_inc = UHeight; - - if(x > -100000) - { - if (xneg) - { - mysizehints.x = DisplayWidth(dpy,screen) + x - mysizehints.width; - gravity = NorthEastGravity; + XGCValues gcv; + unsigned long gcm; + unsigned long mask; + char *list[2]; + XSetWindowAttributes attributes; + XSizeHints mysizehints; + XTextProperty name; + XClassHint class_hints; + + h_margin = margin1 * 2 + bar_width + margin2 + 8; + v_margin = margin1 * 2 + bar_width + margin2 + 8; + + wm_del_win = XInternAtom(dpy, "WM_DELETE_WINDOW", False); + _XA_WM_PROTOCOLS = XInternAtom(dpy, "WM_PROTOCOLS", False); + + /* load the font */ + if ((font = XLoadQueryFont(dpy, font_string)) == NULL) { + if ((font = XLoadQueryFont(dpy, "fixed")) == NULL) { + fprintf(stderr, "%s: No fonts available\n", MyName); + exit(1); + } } - else - mysizehints.x = x; - if (yneg) - { - mysizehints.y = DisplayHeight(dpy,screen) + y - mysizehints.height; - gravity = SouthWestGravity; - } - else - mysizehints.y = y; - - if((xneg) && (yneg)) - gravity = SouthEastGravity; - - mysizehints.flags |= USPosition; - } - - mysizehints.win_gravity = gravity; - - if(d_depth < 2) - { - back_pix = icon_back_pix = act_icon_fore_pix = GetColor("white"); - fore_pix = icon_fore_pix = act_icon_back_pix = GetColor("black"); - hilite_pix = icon_hilite_pix = act_icon_shadow_pix = icon_back_pix; - shadow_pix = icon_shadow_pix = act_icon_hilite_pix = icon_fore_pix; - } - else - { - fore_pix = GetColor(Fore); - back_pix = GetColor(Back); - icon_back_pix = GetColor(IconBack); - icon_fore_pix = GetColor(IconFore); - icon_hilite_pix = GetHilite(icon_back_pix); - icon_shadow_pix = GetShadow(icon_back_pix); - act_icon_back_pix = GetColor(ActIconBack); - act_icon_fore_pix = GetColor(ActIconFore); - act_icon_hilite_pix = GetHilite(act_icon_back_pix); - act_icon_shadow_pix = GetShadow(act_icon_back_pix); - hilite_pix = GetHilite(back_pix); - shadow_pix = GetShadow(back_pix); - } - - main_win = XCreateSimpleWindow(dpy,Root,mysizehints.x,mysizehints.y, - mysizehints.width,mysizehints.height, - 0,fore_pix,back_pix); - XSetWMProtocols(dpy,main_win,&wm_del_win,1); - XSelectInput(dpy,main_win,MW_EVENTS); - - /* set normal_hits, wm_hints, and, class_hints */ - list[0]=MyName; - list[1]=NULL; - if (XStringListToTextProperty(list,1,&name) == 0) - { - fprintf(stderr,"%s: cannot allocate window name",MyName); - return; - } - class_hints.res_name = MyName; - class_hints.res_class = "FvwmIconBox"; - XSetWMProperties(dpy,main_win,&name,&name, - NULL,0,&mysizehints,NULL,&class_hints); - XFree(name.value); - - mysizehints.width -= h_margin; - mysizehints.height -= v_margin; - holder_win = XCreateSimpleWindow(dpy,main_win,margin1+2, - margin1+2, - mysizehints.width, - mysizehints.height, - 0,fore_pix,back_pix); - - icon_win = XCreateSimpleWindow(dpy,holder_win,-icon_win_x,-icon_win_y, - icon_win_width, - icon_win_height, - 0,fore_pix,back_pix); - - gcm = GCForeground|GCBackground; - gcv.foreground = hilite_pix; - gcv.background = back_pix; - ReliefGC = XCreateGC(dpy, Root, gcm, &gcv); - - gcm = GCForeground|GCBackground; - gcv.foreground = shadow_pix; - gcv.background = back_pix; - ShadowGC = XCreateGC(dpy, Root, gcm, &gcv); - - gcm = GCForeground|GCBackground; - gcv.foreground = icon_hilite_pix; - gcv.background = icon_back_pix; - IconReliefGC = XCreateGC(dpy, Root, gcm, &gcv); - - gcm = GCForeground|GCBackground; - gcv.foreground = icon_shadow_pix; - gcv.background = icon_back_pix; - IconShadowGC = XCreateGC(dpy, Root, gcm, &gcv); - - gcm = GCForeground|GCBackground|GCFont; - gcv.foreground = fore_pix; - gcv.background = back_pix; - gcv.font = font->fid; - NormalGC = XCreateGC(dpy, Root, gcm, &gcv); - - - /* icon_win's background */ - if (GetBackPixmap() == True){ - XSetWindowBackgroundPixmap(dpy, icon_win, IconwinPixmap); - /* special thanks to Dave Goldberg - for his helpful information */ - XFreePixmap(dpy, IconwinPixmap); - } - XSetForeground(dpy, NormalGC, icon_fore_pix); - XSetBackground(dpy, NormalGC, icon_back_pix); - - /* scroll bars */ - mask = CWWinGravity | CWBackPixel; - attributes.background_pixel = back_pix; - if (!(local_flags & HIDE_H)){ - attributes.win_gravity = SouthWestGravity; - h_scroll_bar = XCreateWindow(dpy ,main_win, margin1 + 2 + - bar_width, - margin1 + 6 + Height + margin2, - Width - bar_width*2, bar_width, - 0, CopyFromParent, - InputOutput, CopyFromParent, - mask, &attributes); - XSelectInput(dpy,h_scroll_bar,SCROLL_EVENTS); - } - if (!(local_flags & HIDE_V)){ - attributes.win_gravity = NorthEastGravity; - v_scroll_bar = XCreateWindow(dpy ,main_win, margin1 + 6 + - Width + margin2, - margin1 + 2 + bar_width, - bar_width, Height - bar_width*2, - 0, CopyFromParent, - InputOutput, CopyFromParent, - mask, &attributes); - XSelectInput(dpy,v_scroll_bar,SCROLL_EVENTS); - } + if ((local_flags & HIDE_H)) + v_margin -= bar_width + margin2 + 4; + if ((local_flags & HIDE_V)) + h_margin -= bar_width + margin2 + 4; + + UWidth = max_icon_width + icon_relief + interval; + UHeight = font->ascent + font->descent + max_icon_height + icon_relief + + 6 + interval; + Width = UWidth * num_columns + interval - 1; + Height = UHeight * num_rows + interval - 1; + + mysizehints.flags = PWinGravity | PResizeInc | PMinSize; + + /* subtract one for the right/bottom border */ + mysizehints.min_width = UWidth + interval - 1 + h_margin; + main_width = mysizehints.width = Width + h_margin; + mysizehints.min_height = UHeight + interval - 1 + v_margin; + main_height = mysizehints.height = Height + v_margin; + mysizehints.width_inc = UWidth; + mysizehints.height_inc = UHeight; + + if (x > -100000) { + if (xneg) { + mysizehints.x = + DisplayWidth(dpy, screen) + x - mysizehints.width; + gravity = NorthEastGravity; + } else + mysizehints.x = x; + if (yneg) { + mysizehints.y = + DisplayHeight(dpy, screen) + y - mysizehints.height; + gravity = SouthWestGravity; + } else + mysizehints.y = y; + + if ((xneg) && (yneg)) + gravity = SouthEastGravity; + + mysizehints.flags |= USPosition; + } - /* buttons */ - if (!(local_flags & HIDE_H)){ - attributes.win_gravity = SouthWestGravity; - l_button = XCreateWindow(dpy, main_win, margin1 + 2, - margin1 + 6 + Height + margin2, - bar_width, bar_width, - 0, CopyFromParent, - InputOutput, CopyFromParent, - mask, &attributes); - attributes.win_gravity = SouthEastGravity; - r_button = XCreateWindow(dpy, main_win, margin1 + 2 + Width - - bar_width, - margin1 + 6 + Height + margin2, - bar_width, bar_width, - 0, CopyFromParent, - InputOutput, CopyFromParent, - mask, &attributes); - XSelectInput(dpy,l_button,BUTTON_EVENTS); - XSelectInput(dpy,r_button,BUTTON_EVENTS); - } - if (!(local_flags & HIDE_V)){ - attributes.win_gravity = NorthEastGravity; - t_button = XCreateWindow(dpy, main_win, margin1 + 6 + - Width + margin2, margin1 + 2, - bar_width, bar_width, - 0, CopyFromParent, - InputOutput, CopyFromParent, - mask, &attributes); - attributes.win_gravity = SouthEastGravity; - b_button = XCreateWindow(dpy, main_win, margin1 + 6 + - Width + margin2, - margin1 + 2 + Height - bar_width, - bar_width, bar_width, - 0, CopyFromParent, - InputOutput, CopyFromParent, - mask, &attributes); - XSelectInput(dpy,t_button,BUTTON_EVENTS); - XSelectInput(dpy,b_button,BUTTON_EVENTS); - } + mysizehints.win_gravity = gravity; + + if (d_depth < 2) { + back_pix = icon_back_pix = act_icon_fore_pix = + GetColor("white"); + fore_pix = icon_fore_pix = act_icon_back_pix = + GetColor("black"); + hilite_pix = icon_hilite_pix = act_icon_shadow_pix = + icon_back_pix; + shadow_pix = icon_shadow_pix = act_icon_hilite_pix = + icon_fore_pix; + } else { + fore_pix = GetColor(Fore); + back_pix = GetColor(Back); + icon_back_pix = GetColor(IconBack); + icon_fore_pix = GetColor(IconFore); + icon_hilite_pix = GetHilite(icon_back_pix); + icon_shadow_pix = GetShadow(icon_back_pix); + act_icon_back_pix = GetColor(ActIconBack); + act_icon_fore_pix = GetColor(ActIconFore); + act_icon_hilite_pix = GetHilite(act_icon_back_pix); + act_icon_shadow_pix = GetShadow(act_icon_back_pix); + hilite_pix = GetHilite(back_pix); + shadow_pix = GetShadow(back_pix); + } + + main_win = XCreateSimpleWindow(dpy, Root, mysizehints.x, mysizehints.y, + mysizehints.width, mysizehints.height, 0, fore_pix, back_pix); + XSetWMProtocols(dpy, main_win, &wm_del_win, 1); + XSelectInput(dpy, main_win, MW_EVENTS); + + /* set normal_hits, wm_hints, and, class_hints */ + list[0] = MyName; + list[1] = NULL; + if (XStringListToTextProperty(list, 1, &name) == 0) { + fprintf(stderr, "%s: cannot allocate window name", MyName); + return; + } + class_hints.res_name = MyName; + class_hints.res_class = "FvwmIconBox"; + XSetWMProperties(dpy, main_win, &name, &name, NULL, 0, &mysizehints, + NULL, &class_hints); + XFree(name.value); + + mysizehints.width -= h_margin; + mysizehints.height -= v_margin; + holder_win = + XCreateSimpleWindow(dpy, main_win, margin1 + 2, margin1 + 2, + mysizehints.width, mysizehints.height, 0, fore_pix, back_pix); + + icon_win = + XCreateSimpleWindow(dpy, holder_win, -icon_win_x, -icon_win_y, + icon_win_width, icon_win_height, 0, fore_pix, back_pix); + + gcm = GCForeground | GCBackground; + gcv.foreground = hilite_pix; + gcv.background = back_pix; + ReliefGC = XCreateGC(dpy, Root, gcm, &gcv); + + gcm = GCForeground | GCBackground; + gcv.foreground = shadow_pix; + gcv.background = back_pix; + ShadowGC = XCreateGC(dpy, Root, gcm, &gcv); + + gcm = GCForeground | GCBackground; + gcv.foreground = icon_hilite_pix; + gcv.background = icon_back_pix; + IconReliefGC = XCreateGC(dpy, Root, gcm, &gcv); + + gcm = GCForeground | GCBackground; + gcv.foreground = icon_shadow_pix; + gcv.background = icon_back_pix; + IconShadowGC = XCreateGC(dpy, Root, gcm, &gcv); + + gcm = GCForeground | GCBackground | GCFont; + gcv.foreground = fore_pix; + gcv.background = back_pix; + gcv.font = font->fid; + NormalGC = XCreateGC(dpy, Root, gcm, &gcv); + + /* icon_win's background */ + if (GetBackPixmap() == True) { + XSetWindowBackgroundPixmap(dpy, icon_win, IconwinPixmap); + /* special thanks to Dave Goldberg + for his helpful information */ + XFreePixmap(dpy, IconwinPixmap); + } + + XSetForeground(dpy, NormalGC, icon_fore_pix); + XSetBackground(dpy, NormalGC, icon_back_pix); + + /* scroll bars */ + mask = CWWinGravity | CWBackPixel; + attributes.background_pixel = back_pix; + if (!(local_flags & HIDE_H)) { + attributes.win_gravity = SouthWestGravity; + h_scroll_bar = XCreateWindow(dpy, main_win, + margin1 + 2 + bar_width, margin1 + 6 + Height + margin2, + Width - bar_width * 2, bar_width, 0, CopyFromParent, + InputOutput, CopyFromParent, mask, &attributes); + XSelectInput(dpy, h_scroll_bar, SCROLL_EVENTS); + } + if (!(local_flags & HIDE_V)) { + attributes.win_gravity = NorthEastGravity; + v_scroll_bar = XCreateWindow(dpy, main_win, + margin1 + 6 + Width + margin2, margin1 + 2 + bar_width, + bar_width, Height - bar_width * 2, 0, CopyFromParent, + InputOutput, CopyFromParent, mask, &attributes); + XSelectInput(dpy, v_scroll_bar, SCROLL_EVENTS); + } + + /* buttons */ + if (!(local_flags & HIDE_H)) { + attributes.win_gravity = SouthWestGravity; + l_button = XCreateWindow(dpy, main_win, margin1 + 2, + margin1 + 6 + Height + margin2, bar_width, bar_width, 0, + CopyFromParent, InputOutput, CopyFromParent, mask, + &attributes); + attributes.win_gravity = SouthEastGravity; + r_button = XCreateWindow(dpy, main_win, + margin1 + 2 + Width - bar_width, + margin1 + 6 + Height + margin2, bar_width, bar_width, 0, + CopyFromParent, InputOutput, CopyFromParent, mask, + &attributes); + XSelectInput(dpy, l_button, BUTTON_EVENTS); + XSelectInput(dpy, r_button, BUTTON_EVENTS); + } + if (!(local_flags & HIDE_V)) { + attributes.win_gravity = NorthEastGravity; + t_button = + XCreateWindow(dpy, main_win, margin1 + 6 + Width + margin2, + margin1 + 2, bar_width, bar_width, 0, CopyFromParent, + InputOutput, CopyFromParent, mask, &attributes); + attributes.win_gravity = SouthEastGravity; + b_button = + XCreateWindow(dpy, main_win, margin1 + 6 + Width + margin2, + margin1 + 2 + Height - bar_width, bar_width, bar_width, + 0, CopyFromParent, InputOutput, CopyFromParent, mask, + &attributes); + XSelectInput(dpy, t_button, BUTTON_EVENTS); + XSelectInput(dpy, b_button, BUTTON_EVENTS); + } } -void GetIconwinSize(int *dx, int *dy) +void +GetIconwinSize(int *dx, int *dy) { - *dx = icon_win_width; - *dy = icon_win_height; - - if (primary == LEFT || primary == RIGHT){ - icon_win_width = max(Width, UWidth * Lines + interval - 1); - icon_win_height = max(Height, UHeight * (max(0, - (num_icons-1))/Lines - + 1) - 1 + interval); - }else{ - icon_win_width = max(Width, UWidth * (max(0,num_icons-1) / Lines + - 1) + interval - 1); - icon_win_height = max(Height, UHeight * Lines - 1 + interval); - } - *dx = icon_win_width - *dx; - *dy = icon_win_height - *dy; + *dx = icon_win_width; + *dy = icon_win_height; + + if (primary == LEFT || primary == RIGHT) { + icon_win_width = max(Width, UWidth * Lines + interval - 1); + icon_win_height = max( + Height, UHeight * (max(0, (num_icons - 1)) / Lines + 1) - + 1 + interval); + } else { + icon_win_width = + max(Width, UWidth * (max(0, num_icons - 1) / Lines + 1) + + interval - 1); + icon_win_height = max(Height, UHeight * Lines - 1 + interval); + } + *dx = icon_win_width - *dx; + *dy = icon_win_height - *dy; } /************************************************************************ @@ -1138,33 +1262,31 @@ void GetIconwinSize(int *dx, int *dy) * Original work from GoodStuff: * Copyright 1993, Robert Nation. ***********************************************************************/ -void nocolor(char *a, char *b) +void +nocolor(char *a, char *b) { - fprintf(stderr,"%s: can't %s %s\n", MyName, a,b); + fprintf(stderr, "%s: can't %s %s\n", MyName, a, b); } - /************************************************************************ * GetColor * Original work from GoodStuff: * Copyright 1993, Robert Nation. ***********************************************************************/ -Pixel GetColor(char *name) +Pixel +GetColor(char *name) { - XColor color; - XWindowAttributes attributes; - - XGetWindowAttributes(dpy,Root,&attributes); - color.pixel = 0; - if (!XParseColor (dpy, attributes.colormap, name, &color)) - { - nocolor("parse",name); - } - else if(!XAllocColor (dpy, attributes.colormap, &color)) - { - nocolor("alloc",name); - } - return color.pixel; + XColor color; + XWindowAttributes attributes; + + XGetWindowAttributes(dpy, Root, &attributes); + color.pixel = 0; + if (!XParseColor(dpy, attributes.colormap, name, &color)) { + nocolor("parse", name); + } else if (!XAllocColor(dpy, attributes.colormap, &color)) { + nocolor("alloc", name); + } + return color.pixel; } /************************************************************************ @@ -1172,152 +1294,158 @@ Pixel GetColor(char *name) Original work from FvwmWinList: Copyright 1994, Mike Finger. ************************************************************************/ -void SendFvwmPipe(int *fd, char *message,unsigned long window) +void +SendFvwmPipe(int *fd, char *message, unsigned long window) { - int w; - char *hold,*temp,*temp_msg; - hold=message; - - while(1) { - temp=strchr(hold,','); - if (temp!=NULL) { - temp_msg=malloc(temp-hold+1); - strncpy(temp_msg,hold,(temp-hold)); - temp_msg[(temp-hold)]='\0'; - hold=temp+1; - } else temp_msg=hold; - - if (!ExecIconBoxFunction(temp_msg)){ - write(fd[0],&window, sizeof(unsigned long)); - - w=strlen(temp_msg); - write(fd[0],&w,sizeof(int)); - write(fd[0],temp_msg,w); - - /* keep going */ - w=1; - write(fd[0],&w,sizeof(int)); - - } - if(temp_msg!=hold) free(temp_msg); - else break; - } + int w; + char *hold, *temp, *temp_msg; + hold = message; + + while (1) { + temp = strchr(hold, ','); + if (temp != NULL) { + temp_msg = malloc(temp - hold + 1); + strncpy(temp_msg, hold, (temp - hold)); + temp_msg[(temp - hold)] = '\0'; + hold = temp + 1; + } else + temp_msg = hold; + + if (!ExecIconBoxFunction(temp_msg)) { + write(fd[0], &window, sizeof(unsigned long)); + + w = strlen(temp_msg); + write(fd[0], &w, sizeof(int)); + write(fd[0], temp_msg, w); + + /* keep going */ + w = 1; + write(fd[0], &w, sizeof(int)); + } + if (temp_msg != hold) + free(temp_msg); + else + break; + } } -Bool ExecIconBoxFunction(char *msg) +Bool +ExecIconBoxFunction(char *msg) { - if (strncasecmp(msg, "Next", 4) == 0){ - Next(); - return True; - }else if (strncasecmp(msg, "Prev", 4) == 0){ - Prev(); - return True; - }else if (strncasecmp(msg, "Left", 4) == 0){ - HScroll(icon_win_x - UWidth); - return True; - }else if (strncasecmp(msg, "Right", 5) == 0){ - HScroll(icon_win_x + UWidth); - return True; - }else if (strncasecmp(msg, "Up", 2) == 0){ - VScroll(icon_win_y - UHeight); - return True; - }else if (strncasecmp(msg, "Down", 4) == 0){ - VScroll(icon_win_y + UHeight); - return True; - } - return False; + if (strncasecmp(msg, "Next", 4) == 0) { + Next(); + return True; + } else if (strncasecmp(msg, "Prev", 4) == 0) { + Prev(); + return True; + } else if (strncasecmp(msg, "Left", 4) == 0) { + HScroll(icon_win_x - UWidth); + return True; + } else if (strncasecmp(msg, "Right", 5) == 0) { + HScroll(icon_win_x + UWidth); + return True; + } else if (strncasecmp(msg, "Up", 2) == 0) { + VScroll(icon_win_y - UHeight); + return True; + } else if (strncasecmp(msg, "Down", 4) == 0) { + VScroll(icon_win_y + UHeight); + return True; + } + return False; } -void Next(void) +void +Next(void) { - struct icon_info *new, *old; - int i; - - old = new = Hilite; - - if (new != NULL) - new = new->next; - - if (new != NULL) - Hilite = new; - else - new = Hilite = Head; - - if (new == NULL) - return; - - if (old != NULL) - RedrawIcon(old, redraw_flag); - if (new != NULL) - RedrawIcon(new, redraw_flag); - - i=0; - if (new->x < icon_win_x){ - while (new->x + UWidth * ++i < icon_win_x) - ; - HScroll(icon_win_x - UWidth*i); - }else if (new->x > icon_win_x + Width){ - while (new->x - UWidth * ++i > icon_win_x + Width) - ; - HScroll(icon_win_x + UWidth*i); - } + struct icon_info *new, *old; + int i; + + old = new = Hilite; + + if (new != NULL) + new = new->next; + + if (new != NULL) + Hilite = new; + else + new = Hilite = Head; + + if (new == NULL) + return; + + if (old != NULL) + RedrawIcon(old, redraw_flag); + if (new != NULL) + RedrawIcon(new, redraw_flag); + + i = 0; + if (new->x < icon_win_x) { + while (new->x + UWidth * ++i < icon_win_x) + ; + HScroll(icon_win_x - UWidth * i); + } else if (new->x > icon_win_x + Width) { + while (new->x - UWidth * ++i > icon_win_x + Width) + ; + HScroll(icon_win_x + UWidth * i); + } - i=0; - if (new->y < icon_win_y){ - while (new->y + UHeight * ++i < icon_win_y) - ; - VScroll(icon_win_y - UHeight*i); - }else if (new->y > icon_win_y + Height){ - while (new->y - UHeight * ++i > icon_win_y + Height) - ; - VScroll(icon_win_y + UHeight*i); - } + i = 0; + if (new->y < icon_win_y) { + while (new->y + UHeight * ++i < icon_win_y) + ; + VScroll(icon_win_y - UHeight * i); + } else if (new->y > icon_win_y + Height) { + while (new->y - UHeight * ++i > icon_win_y + Height) + ; + VScroll(icon_win_y + UHeight * i); + } } -void Prev(void) +void +Prev(void) { - struct icon_info *new, *old; - int i; - - old = new = Hilite; - - if (new != NULL) - new = new->prev; - - if (new != NULL) - Hilite = new; - else - new = Hilite = Tail; - - if (new == NULL) - return; - - if (old != NULL) - RedrawIcon(old, redraw_flag); - if (new != NULL) - RedrawIcon(new, redraw_flag); - - i=0; - if (new->x < icon_win_x){ - while (new->x + UWidth * ++i < icon_win_x) - ; - HScroll(icon_win_x - UWidth*i); - }else if (new->x > icon_win_x + Width){ - while (new->x - UWidth * ++i > icon_win_x + Width) - ; - HScroll(icon_win_x + UWidth*i); - } + struct icon_info *new, *old; + int i; + + old = new = Hilite; + + if (new != NULL) + new = new->prev; + + if (new != NULL) + Hilite = new; + else + new = Hilite = Tail; + + if (new == NULL) + return; + + if (old != NULL) + RedrawIcon(old, redraw_flag); + if (new != NULL) + RedrawIcon(new, redraw_flag); + + i = 0; + if (new->x < icon_win_x) { + while (new->x + UWidth * ++i < icon_win_x) + ; + HScroll(icon_win_x - UWidth * i); + } else if (new->x > icon_win_x + Width) { + while (new->x - UWidth * ++i > icon_win_x + Width) + ; + HScroll(icon_win_x + UWidth * i); + } - i=0; - if (new->y < icon_win_y){ - while (new->y + UHeight * ++i < icon_win_y) - ; - VScroll(icon_win_y - UHeight*i); - }else if (new->y > icon_win_y + Height){ - while (new->y - UHeight * ++i > icon_win_y + Height) - ; - VScroll(icon_win_y + UHeight*i); - } + i = 0; + if (new->y < icon_win_y) { + while (new->y + UHeight * ++i < icon_win_y) + ; + VScroll(icon_win_y - UHeight * i); + } else if (new->y > icon_win_y + Height) { + while (new->y - UHeight * ++i > icon_win_y + Height) + ; + VScroll(icon_win_y + UHeight * i); + } } /************************************************************************ @@ -1325,425 +1453,438 @@ void Prev(void) * Based on DeadPipe() from GoodStuff: * Copyright 1993, Robert Nation. ***********************************************************************/ -void DeadPipe(int nonsense) +void +DeadPipe(int nonsense) { -#if 0 /* can't do X or malloc stuff in a signal handler, so just exit */ - struct icon_info *tmpi, *tmpi2; - struct mousefunc *tmpm, *tmpm2; - struct keyfunc *tmpk, *tmpk2; - struct iconfile *tmpf, *tmpf2; - - if (FvwmDefaultIcon != NULL) - free(FvwmDefaultIcon); - - tmpm = MouseActions; - while(tmpm != NULL){ - tmpm2 = tmpm; - tmpm = tmpm->next; - free(tmpm2->action); - free(tmpm2); - } - - tmpk = KeyActions; - while(tmpk != NULL){ - tmpk2 = tmpk; - tmpk = tmpk->next; - free(tmpk2->action); - free(tmpk2->name); - free(tmpk2); - } - - tmpf = IconListHead; - while(tmpf != NULL){ - tmpf2 = tmpf; - tmpf = tmpf->next; - free(tmpf2->name); - free(tmpf2->iconfile); - free(tmpf2); - } - - tmpi = Head; - while(tmpi != NULL){ - tmpi2 = tmpi; - tmpi = tmpi->next; - freeitem(tmpi2, 0); - } - if ((local_flags & SETWMICONSIZE)) - XDeleteProperty(dpy, Root, XA_WM_ICON_SIZE); - XSync(dpy,0); -#endif /* 0 */ - exit(0); + exit(0); } - /************************************************************************ * ParseOptions * Based on ParseConfig() from FvwmWinList: * Copyright 1994, Mike Finger. ***********************************************************************/ -void ParseOptions(void) +void +ParseOptions(void) { - char *tline= NULL,*tmp; - int Clength; - - Clength = strlen(MyName); - - GetConfigLine(fd,&tline); - - while(tline != NULL) - { - int g_x, g_y, flags; - unsigned width,height; - - if(strlen(&tline[0])>1){ - if (strncasecmp(tline,CatString3("*", MyName, - "Geometry"),Clength+9)==0){ - tmp = &tline[Clength+9]; - while(((isspace(*tmp))&&(*tmp != '\n'))&&(*tmp != 0)) - tmp++; - tmp[strlen(tmp)-1] = 0; - flags = XParseGeometry(tmp,&g_x,&g_y,&width,&height); - if (flags & WidthValue) - num_columns = width; - if (flags & HeightValue) - num_rows = height; - if (flags & XValue) - x = g_x; - if (flags & YValue) - y = g_y; - if (flags & XNegative) - xneg = 1; - if (flags & YNegative) - yneg = 1; - } else if (strncasecmp(tline,CatString3("*", MyName, - "MaxIconSize"),Clength+12)==0){ - tmp = &tline[Clength+12]; - while(((isspace(*tmp))&&(*tmp != '\n'))&&(*tmp != 0)) - tmp++; - tmp[strlen(tmp)-1] = 0; - - flags = XParseGeometry(tmp,&g_x,&g_y,&width,&height); - if (flags & WidthValue) - max_icon_width = width; - if (flags & HeightValue) - max_icon_height = height; - if (height == 0){ - icon_relief = 0; - redraw_flag = 2; - max_icon_width += 4; - } - }else if - (strncasecmp(tline,CatString3("*",MyName,"Font"),Clength+5)==0) - CopyString(&font_string,&tline[Clength+5]); - else if - (strncasecmp(tline,CatString3("*",MyName,"IconFore"),Clength+9)==0) - CopyString(&IconFore,&tline[Clength+9]); - else if - (strncasecmp(tline,CatString3("*",MyName,"IconBack"),Clength+9)==0) - CopyString(&IconBack,&tline[Clength+9]); - else if - (strncasecmp(tline,CatString3("*",MyName,"IconHiFore"),Clength+11)==0) - CopyString(&ActIconFore,&tline[Clength+11]); - else if - (strncasecmp(tline,CatString3("*",MyName,"IconHiBack"),Clength+11)==0) - CopyString(&ActIconBack,&tline[Clength+11]); - else if (strncasecmp(tline,CatString3("*",MyName, - "Fore"),Clength+5)==0) - CopyString(&Fore,&tline[Clength+5]); - else if (strncasecmp(tline,CatString3("*",MyName, - "Back"),Clength+5)==0) - CopyString(&Back,&tline[Clength+5]); - else if (strncasecmp(tline,CatString3("*",MyName, - "Pixmap"),Clength+7)==0) - CopyString(&IconwinPixmapFile,&tline[Clength+7]); - else if (strncasecmp(tline,CatString3("*",MyName, - "Padding"),Clength+8)==0) - interval = max(0,atoi(&tline[Clength+8])); - else if (strncasecmp(tline,CatString3("*",MyName, - "FrameWidth"),Clength+11)==0){ - sscanf(&tline[Clength+11], "%d %d", &margin1, &margin2); - margin1 = max(0, margin1); - margin2 = max(0, margin2); - }else if (strncasecmp(tline,CatString3("*",MyName, - "Lines"),Clength+6)==0) - Lines = max(1,atoi(&tline[Clength+6])); - else if (strncasecmp(tline,CatString3("*",MyName, - "SBWidth"),Clength+8)==0) - bar_width = max(5,atoi(&tline[Clength+8])); - else if (strncasecmp(tline,CatString3("*",MyName, - "Placement"),Clength+10)==0) - parseplacement(&tline[Clength+10]); - else if (strncasecmp(tline,CatString3("*",MyName, - "SetWMIconSize"),Clength+14)==0) - local_flags |= SETWMICONSIZE; - else if (strncasecmp(tline,CatString3("*",MyName, - "HilightFocusWin"),Clength+16)==0) - m_mask |= M_FOCUS_CHANGE; - else if (strncasecmp(tline,CatString3("*",MyName, - "Resolution"),Clength+11)==0){ - tmp = &tline[Clength+11]; - while(((isspace(*tmp))&&(*tmp != '\n'))&&(*tmp != 0)) - tmp++; - if (strncasecmp(tmp, "Desk", 4) == 0){ - m_mask |= M_NEW_DESK; - local_flags |= CURRENT_ONLY; - } - }else if (strncasecmp(tline,CatString3("*",MyName, - "Mouse"),Clength+6)==0) - parsemouse(&tline[Clength + 6]); - else if (strncasecmp(tline,CatString3("*",MyName, - "Key"),Clength+4)==0) - parsekey(&tline[Clength + 4]); - else if (strncasecmp(tline,CatString3("*",MyName, - "SortIcons"),Clength+10)==0){ - tmp = &tline[Clength+10]; - while(((isspace(*tmp))&&(*tmp != '\n'))&&(*tmp != 0)) - tmp++; - if (strlen(tmp) == 0){ /* the case where no argument is given */ - sortby = ICONNAME; - return; - } - if (strncasecmp(tmp, "WindowName", 10) == 0) - sortby = WINDOWNAME; - else if (strncasecmp(tmp, "IconName", 8) == 0) - sortby = ICONNAME; - else if (strncasecmp(tmp, "ResClass", 8) == 0) - sortby = RESCLASS; - else if (strncasecmp(tmp, "ResName", 7) == 0) - sortby = RESNAME; - }else if (strncasecmp(tline,CatString3("*",MyName, - "HideSC"),Clength+7)==0){ - tmp = &tline[Clength+7]; - while(((isspace(*tmp))&&(*tmp != '\n'))&&(*tmp != 0)) - tmp++; - if (strncasecmp(tmp, "Horizontal", 10) == 0) - local_flags |= HIDE_H; - else if (strncasecmp(tmp, "Vertical", 8) == 0) - local_flags |= HIDE_V; - }else if (strncasecmp(tline,CatString3("*",MyName, - ""),Clength+1)==0) - parseicon(&tline[Clength + 1]); - else if (strncasecmp(tline,"IconPath",8)==0) - CopyString(&iconPath,&tline[8]); - else if (strncasecmp(tline,"PixmapPath",10)==0) - CopyString(&pixmapPath,&tline[10]); - else if (strncasecmp(tline,"ClickTime",9)==0) - ClickTime = atoi(&tline[9]); - else if (strncasecmp(tline,"ColorLimit",10)==0) { - save_color_limit = atoi(&tline[10]); - } - } - GetConfigLine(fd,&tline); - } - - return; + char *tline = NULL, *tmp; + int Clength; + + Clength = strlen(MyName); + + GetConfigLine(fd, &tline); + + while (tline != NULL) { + int g_x, g_y, flags; + unsigned width, height; + + if (strlen(&tline[0]) > 1) { + if (strncasecmp(tline, + CatString3("*", MyName, "Geometry"), + Clength + 9) == 0) { + tmp = &tline[Clength + 9]; + while (((isspace(*tmp)) && (*tmp != '\n')) && + (*tmp != 0)) + tmp++; + tmp[strlen(tmp) - 1] = 0; + flags = XParseGeometry( + tmp, &g_x, &g_y, &width, &height); + if (flags & WidthValue) + num_columns = width; + if (flags & HeightValue) + num_rows = height; + if (flags & XValue) + x = g_x; + if (flags & YValue) + y = g_y; + if (flags & XNegative) + xneg = 1; + if (flags & YNegative) + yneg = 1; + } else if (strncasecmp(tline, + CatString3("*", MyName, "MaxIconSize"), + Clength + 12) == 0) { + tmp = &tline[Clength + 12]; + while (((isspace(*tmp)) && (*tmp != '\n')) && + (*tmp != 0)) + tmp++; + tmp[strlen(tmp) - 1] = 0; + + flags = XParseGeometry( + tmp, &g_x, &g_y, &width, &height); + if (flags & WidthValue) + max_icon_width = width; + if (flags & HeightValue) + max_icon_height = height; + if (height == 0) { + icon_relief = 0; + redraw_flag = 2; + max_icon_width += 4; + } + } else if (strncasecmp(tline, + CatString3("*", MyName, "Font"), + Clength + 5) == 0) + CopyString(&font_string, &tline[Clength + 5]); + else if (strncasecmp(tline, + CatString3("*", MyName, "IconFore"), + Clength + 9) == 0) + CopyString(&IconFore, &tline[Clength + 9]); + else if (strncasecmp(tline, + CatString3("*", MyName, "IconBack"), + Clength + 9) == 0) + CopyString(&IconBack, &tline[Clength + 9]); + else if (strncasecmp(tline, + CatString3("*", MyName, "IconHiFore"), + Clength + 11) == 0) + CopyString(&ActIconFore, &tline[Clength + 11]); + else if (strncasecmp(tline, + CatString3("*", MyName, "IconHiBack"), + Clength + 11) == 0) + CopyString(&ActIconBack, &tline[Clength + 11]); + else if (strncasecmp(tline, + CatString3("*", MyName, "Fore"), + Clength + 5) == 0) + CopyString(&Fore, &tline[Clength + 5]); + else if (strncasecmp(tline, + CatString3("*", MyName, "Back"), + Clength + 5) == 0) + CopyString(&Back, &tline[Clength + 5]); + else if (strncasecmp(tline, + CatString3("*", MyName, "Pixmap"), + Clength + 7) == 0) + CopyString( + &IconwinPixmapFile, &tline[Clength + 7]); + else if (strncasecmp(tline, + CatString3("*", MyName, "Padding"), + Clength + 8) == 0) + interval = max(0, atoi(&tline[Clength + 8])); + else if (strncasecmp(tline, + CatString3("*", MyName, "FrameWidth"), + Clength + 11) == 0) { + sscanf(&tline[Clength + 11], "%d %d", &margin1, + &margin2); + margin1 = max(0, margin1); + margin2 = max(0, margin2); + } else if (strncasecmp(tline, + CatString3("*", MyName, "Lines"), + Clength + 6) == 0) + Lines = max(1, atoi(&tline[Clength + 6])); + else if (strncasecmp(tline, + CatString3("*", MyName, "SBWidth"), + Clength + 8) == 0) + bar_width = max(5, atoi(&tline[Clength + 8])); + else if (strncasecmp(tline, + CatString3("*", MyName, "Placement"), + Clength + 10) == 0) + parseplacement(&tline[Clength + 10]); + else if (strncasecmp(tline, + CatString3("*", MyName, "SetWMIconSize"), + Clength + 14) == 0) + local_flags |= SETWMICONSIZE; + else if (strncasecmp(tline, + CatString3("*", MyName, "HilightFocusWin"), + Clength + 16) == 0) + m_mask |= M_FOCUS_CHANGE; + else if (strncasecmp(tline, + CatString3("*", MyName, "Resolution"), + Clength + 11) == 0) { + tmp = &tline[Clength + 11]; + while (((isspace(*tmp)) && (*tmp != '\n')) && + (*tmp != 0)) + tmp++; + if (strncasecmp(tmp, "Desk", 4) == 0) { + m_mask |= M_NEW_DESK; + local_flags |= CURRENT_ONLY; + } + } else if (strncasecmp(tline, + CatString3("*", MyName, "Mouse"), + Clength + 6) == 0) + parsemouse(&tline[Clength + 6]); + else if (strncasecmp(tline, + CatString3("*", MyName, "Key"), + Clength + 4) == 0) + parsekey(&tline[Clength + 4]); + else if (strncasecmp(tline, + CatString3("*", MyName, "SortIcons"), + Clength + 10) == 0) { + tmp = &tline[Clength + 10]; + while (((isspace(*tmp)) && (*tmp != '\n')) && + (*tmp != 0)) + tmp++; + if (strlen(tmp) == 0) { /* the case where no + argument is given */ + sortby = ICONNAME; + return; + } + if (strncasecmp(tmp, "WindowName", 10) == 0) + sortby = WINDOWNAME; + else if (strncasecmp(tmp, "IconName", 8) == 0) + sortby = ICONNAME; + else if (strncasecmp(tmp, "ResClass", 8) == 0) + sortby = RESCLASS; + else if (strncasecmp(tmp, "ResName", 7) == 0) + sortby = RESNAME; + } else if (strncasecmp(tline, + CatString3("*", MyName, "HideSC"), + Clength + 7) == 0) { + tmp = &tline[Clength + 7]; + while (((isspace(*tmp)) && (*tmp != '\n')) && + (*tmp != 0)) + tmp++; + if (strncasecmp(tmp, "Horizontal", 10) == 0) + local_flags |= HIDE_H; + else if (strncasecmp(tmp, "Vertical", 8) == 0) + local_flags |= HIDE_V; + } else if (strncasecmp(tline, + CatString3("*", MyName, ""), + Clength + 1) == 0) + parseicon(&tline[Clength + 1]); + else if (strncasecmp(tline, "IconPath", 8) == 0) + CopyString(&iconPath, &tline[8]); + else if (strncasecmp(tline, "PixmapPath", 10) == 0) + CopyString(&pixmapPath, &tline[10]); + else if (strncasecmp(tline, "ClickTime", 9) == 0) + ClickTime = atoi(&tline[9]); + else if (strncasecmp(tline, "ColorLimit", 10) == 0) { + save_color_limit = atoi(&tline[10]); + } + } + GetConfigLine(fd, &tline); + } + + return; } -void parseicon(char *tline) +void +parseicon(char *tline) { - int len; - struct iconfile *tmp; - char *ptr, *start, *end; - - tmp = (struct iconfile *)safemalloc(sizeof(struct iconfile)); - - - /* windowname */ - tmp->name = stripcpy2(tline); - if(tmp->name == NULL){ - free(tmp); - return; - } - - /* skip windowname, based on strpcpy3 of configure.c */ - while((*tline != '"')&&(tline != NULL)) - tline++; - if(*tline != 0) - tline++; - while((*tline != '"')&&(tline != NULL)) - tline++; - if(*tline == 0){ - free(tmp); - return; - } - tline++; - - /* file */ - /* skip spaces */ - while(isspace(*tline)&&(*tline != '\n')&&(*tline != 0)) - tline++; - start = tline; - end = tline; - while(!isspace(*end)&&(*end != '\n')&&(*end != 0)) - end++; - len = end - start; - ptr = safemalloc(len+1); - strncpy(ptr, start, len); - ptr[len] = 0; - tmp->iconfile = ptr; - - if (strcmp(tmp->name, "*") == 0) - DefaultIcon = tmp; - - tmp->next = NULL; - - if (IconListHead == NULL) - IconListHead = IconListTail = tmp; - else{ - IconListTail->next = tmp; - IconListTail = tmp; - } + int len; + struct iconfile *tmp; + char *ptr, *start, *end; + + tmp = (struct iconfile *)xmalloc(sizeof(struct iconfile)); + + /* windowname */ + tmp->name = stripcpy2(tline); + if (tmp->name == NULL) { + free(tmp); + return; + } + + /* skip windowname, based on strpcpy3 of configure.c */ + while ((*tline != '"') && (tline != NULL)) + tline++; + if (*tline != 0) + tline++; + while ((*tline != '"') && (tline != NULL)) + tline++; + if (*tline == 0) { + free(tmp); + return; + } + tline++; + + /* file */ + /* skip spaces */ + while (isspace(*tline) && (*tline != '\n') && (*tline != 0)) + tline++; + start = tline; + end = tline; + while (!isspace(*end) && (*end != '\n') && (*end != 0)) + end++; + len = end - start; + ptr = xmalloc(len + 1); + strncpy(ptr, start, len); + ptr[len] = 0; + tmp->iconfile = ptr; + + if (strcmp(tmp->name, "*") == 0) + DefaultIcon = tmp; + + tmp->next = NULL; + + if (IconListHead == NULL) + IconListHead = IconListTail = tmp; + else { + IconListTail->next = tmp; + IconListTail = tmp; + } } -void parseplacement(char *tline) +void +parseplacement(char *tline) { - char p[240], s[240]; - - sscanf(tline, "%s %s", p, s); - - if (strncasecmp(p, "Left", 4) == 0) - primary = LEFT; - else if (strncasecmp(p, "Right", 5) == 0) - primary = RIGHT; - else if (strncasecmp(p, "Top", 3) == 0) - primary = TOP; - else if (strncasecmp(p, "Bottom", 6) == 0) - primary = BOTTOM; - - if (strncasecmp(s, "Left", 4) == 0) - secondary = LEFT; - else if (strncasecmp(s, "Right", 5) == 0) - secondary = RIGHT; - else if (strncasecmp(s, "Top", 3) == 0) - secondary = TOP; - else if (strncasecmp(s, "Bottom", 6) == 0) - secondary = BOTTOM; + char p[240], s[240]; + + sscanf(tline, "%s %s", p, s); + + if (strncasecmp(p, "Left", 4) == 0) + primary = LEFT; + else if (strncasecmp(p, "Right", 5) == 0) + primary = RIGHT; + else if (strncasecmp(p, "Top", 3) == 0) + primary = TOP; + else if (strncasecmp(p, "Bottom", 6) == 0) + primary = BOTTOM; + + if (strncasecmp(s, "Left", 4) == 0) + secondary = LEFT; + else if (strncasecmp(s, "Right", 5) == 0) + secondary = RIGHT; + else if (strncasecmp(s, "Top", 3) == 0) + secondary = TOP; + else if (strncasecmp(s, "Bottom", 6) == 0) + secondary = BOTTOM; } -void parsemouse(char *tline) +void +parsemouse(char *tline) { - struct mousefunc *f = NULL; - int len; - char *ptr,*start,*end,*tmp; - - f = (struct mousefunc *)safemalloc(sizeof(struct mousefunc)); - f->next = NULL; - f->mouse = 0; - - /* skip spaces */ - while(isspace(*tline)&&(*tline != '\n')&&(*tline != 0)) - tline++; - start = tline; - end = tline; - while((!isspace(*end))&&(*end!='\n')&&(*end!=0)) - end++; - if (strncasecmp(start, "1", 1) == 0) - f->mouse = Button1; - else if (strncasecmp(start, "2", 1) == 0) - f->mouse = Button2; - else if (strncasecmp(start, "3", 1) == 0) - f->mouse = Button3; - /* click or doubleclick */ - tline = end; - /* skip spaces */ - while(isspace(*tline)&&(*tline != '\n')&&(*tline != 0)) - tline++; - start = tline; - end = tline; - while((!isspace(*end))&&(*end!='\n')&&(*end!=0)) - end++; - if (strncasecmp(start, "Click", 5) == 0) - f->type = CLICK; - else if (strncasecmp(start, "DoubleClick", 11) == 0) - f->type = DOUBLE_CLICK; - - /* actions */ - tline = end; - /* skip spaces */ - while(isspace(*tline)&&(*tline != '\n')&&(*tline != 0)) - tline++; - start = tline; - end = tline; - tmp = tline; - while((*tmp!='\n')&&(*tmp!=0)){ - if (!isspace(*tmp)) - end = tmp; - tmp++; - } - end++; - len = end - start; - ptr = safemalloc(len+1); - strncpy(ptr, start, len); - ptr[len] = 0; - f->action = ptr; - f->next = MouseActions; - MouseActions = f; + struct mousefunc *f = NULL; + int len; + char *ptr, *start, *end, *tmp; + + f = (struct mousefunc *)xmalloc(sizeof(struct mousefunc)); + f->next = NULL; + f->mouse = 0; + + /* skip spaces */ + while (isspace(*tline) && (*tline != '\n') && (*tline != 0)) + tline++; + start = tline; + end = tline; + while ((!isspace(*end)) && (*end != '\n') && (*end != 0)) + end++; + if (strncasecmp(start, "1", 1) == 0) + f->mouse = Button1; + else if (strncasecmp(start, "2", 1) == 0) + f->mouse = Button2; + else if (strncasecmp(start, "3", 1) == 0) + f->mouse = Button3; + /* click or doubleclick */ + tline = end; + /* skip spaces */ + while (isspace(*tline) && (*tline != '\n') && (*tline != 0)) + tline++; + start = tline; + end = tline; + while ((!isspace(*end)) && (*end != '\n') && (*end != 0)) + end++; + if (strncasecmp(start, "Click", 5) == 0) + f->type = CLICK; + else if (strncasecmp(start, "DoubleClick", 11) == 0) + f->type = DOUBLE_CLICK; + + /* actions */ + tline = end; + /* skip spaces */ + while (isspace(*tline) && (*tline != '\n') && (*tline != 0)) + tline++; + start = tline; + end = tline; + tmp = tline; + while ((*tmp != '\n') && (*tmp != 0)) { + if (!isspace(*tmp)) + end = tmp; + tmp++; + } + end++; + len = end - start; + ptr = xmalloc(len + 1); + strncpy(ptr, start, len); + ptr[len] = 0; + f->action = ptr; + f->next = MouseActions; + MouseActions = f; } /*********************************************************************** parsekey - Based on part of AddFunckey() of configure.c in Fvwm. - Copyright 1988, Evans and Sutherland Computer Corporation, - Copyright 1989, Massachusetts Institute of Technology, - Copyright 1993, Robert Nation. + Based on part of AddFunckey() of configure.c in Fvwm. + Copyright 1988, Evans and Sutherland Computer Corporation, + Copyright 1989, Massachusetts Institute of Technology, + Copyright 1993, Robert Nation. ***********************************************************************/ -void parsekey(char *tline) +void +parsekey(char *tline) { - struct keyfunc *k; - int nlen, alen; - char *nptr, *aptr, *start, *end, *tmp; - int i, kmin, kmax; - KeySym keysym; - - /* skip spaces */ - while(isspace(*tline)&&(*tline != '\n')&&(*tline != 0)) - tline++; - start = tline; - end = tline; - while((!isspace(*end))&&(*end!='\n')&&(*end!=0)) - end++; - nlen = end - start; - nptr = safemalloc(nlen+1); - strncpy(nptr, start, nlen); - nptr[nlen] = 0; - - /* actions */ - tline = end; - /* skip spaces */ - while(isspace(*tline)&&(*tline != '\n')&&(*tline != 0)) - tline++; - start = tline; - end = tline; - tmp = tline; - while((*tmp!='\n')&&(*tmp!=0)){ - if (!isspace(*tmp)) - end = tmp; - tmp++; - } - end++; - alen = end - start; - aptr = safemalloc(alen+1); - strncpy(aptr, start, alen); - aptr[alen] = 0; - - if ((keysym = XStringToKeysym(nptr)) == NoSymbol || - XKeysymToKeycode(dpy, keysym) == 0){ - free(nptr); - free(aptr); - return; - } + struct keyfunc *k; + int nlen, alen; + char *nptr, *aptr, *start, *end, *tmp; + int i, kmin, kmax; + KeySym keysym; + + /* skip spaces */ + while (isspace(*tline) && (*tline != '\n') && (*tline != 0)) + tline++; + start = tline; + end = tline; + while ((!isspace(*end)) && (*end != '\n') && (*end != 0)) + end++; + nlen = end - start; + nptr = xmalloc(nlen + 1); + strncpy(nptr, start, nlen); + nptr[nlen] = 0; + + /* actions */ + tline = end; + /* skip spaces */ + while (isspace(*tline) && (*tline != '\n') && (*tline != 0)) + tline++; + start = tline; + end = tline; + tmp = tline; + while ((*tmp != '\n') && (*tmp != 0)) { + if (!isspace(*tmp)) + end = tmp; + tmp++; + } + end++; + alen = end - start; + aptr = xmalloc(alen + 1); + strncpy(aptr, start, alen); + aptr[alen] = 0; + + if ((keysym = XStringToKeysym(nptr)) == NoSymbol || + XKeysymToKeycode(dpy, keysym) == 0) { + free(nptr); + free(aptr); + return; + } - XDisplayKeycodes(dpy, &kmin, &kmax); - for (i=kmin; i<=kmax; i++) - if (XKeycodeToKeysym(dpy, i, 0) == keysym) - { - k = (struct keyfunc *)safemalloc(sizeof(struct keyfunc)); - k->name = nptr; - k->keycode = i; - k->action = aptr; - k->next = KeyActions; - KeyActions = k; - } + XDisplayKeycodes(dpy, &kmin, &kmax); + { + Bool matched = False; + + for (i = kmin; i <= kmax; i++) { + KeySym *mapping; + int width; + + mapping = XGetKeyboardMapping(dpy, i, 1, &width); + if (mapping == NULL) + continue; + + for (int col = 0; col < width; col++) { + if (mapping[col] == keysym) { + k = (struct keyfunc *)xmalloc( + sizeof(struct keyfunc)); + k->name = nptr; + k->keycode = i; + k->action = aptr; + k->next = KeyActions; + KeyActions = k; + matched = True; + break; + } + } + XFree(mapping); + } + + if (!matched) { + free(nptr); + free(aptr); + } + } } /*********************************************************************** @@ -1751,18 +1892,18 @@ void parsekey(char *tline) * Original work from GoodStuff: * Copyright 1993, Robert Nation. ***********************************************************************/ -void change_window_name(char *str) +void +change_window_name(char *str) { - XTextProperty name; - - if (XStringListToTextProperty(&str,1,&name) == 0) - { - fprintf(stderr,"%s: cannot allocate window name",MyName); - return; - } - XSetWMName(dpy,main_win,&name); - XSetWMIconName(dpy,main_win,&name); - XFree(name.value); + XTextProperty name; + + if (XStringListToTextProperty(&str, 1, &name) == 0) { + fprintf(stderr, "%s: cannot allocate window name", MyName); + return; + } + XSetWMName(dpy, main_win, &name); + XSetWMIconName(dpy, main_win, &name); + XFree(name.value); } /*********************************************************************** @@ -1770,48 +1911,43 @@ void change_window_name(char *str) * Original work from GoodStuff: * Copyright 1993, Robert Nation. ***********************************************************************/ -int My_XNextEvent(Display *dpy, XEvent *event) +int +My_XNextEvent(Display *dpy, XEvent *event) { - fd_set in_fdset; - unsigned long header[HEADER_SIZE]; - static int miss_counter = 0; - unsigned long *body; - - if(XPending(dpy)) - { - XNextEvent(dpy,event); - return 1; - } - - FD_ZERO(&in_fdset); - FD_SET(x_fd,&in_fdset); - FD_SET(fd[1],&in_fdset); - - select(fd_width,SELECT_TYPE_ARG234 &in_fdset, 0, 0, NULL); - - if(FD_ISSET(x_fd, &in_fdset)) - { - if(XPending(dpy)) - { - XNextEvent(dpy,event); - miss_counter = 0; - return 1; - } - else - miss_counter++; - if(miss_counter > 100) - DeadPipe(0); - } - - if(FD_ISSET(fd[1], &in_fdset)) - { - if(ReadFvwmPacket(fd[1],header,&body) > 0) - { - process_message(header[1],body); - free(body); + fd_set in_fdset; + unsigned long header[HEADER_SIZE]; + static int miss_counter = 0; + unsigned long *body; + + if (XPending(dpy)) { + XNextEvent(dpy, event); + return 1; + } + + FD_ZERO(&in_fdset); + FD_SET(x_fd, &in_fdset); + FD_SET(fd[1], &in_fdset); + + select(fd_width, SELECT_TYPE_ARG234 & in_fdset, 0, 0, NULL); + + if (FD_ISSET(x_fd, &in_fdset)) { + if (XPending(dpy)) { + XNextEvent(dpy, event); + miss_counter = 0; + return 1; + } else + miss_counter++; + if (miss_counter > 100) + DeadPipe(0); + } + + if (FD_ISSET(fd[1], &in_fdset)) { + if (ReadFvwmPacket(fd[1], header, &body) > 0) { + process_message(header[1], body); + free(body); + } } - } - return 0; + return 0; } /************************************************************************** @@ -1820,275 +1956,329 @@ int My_XNextEvent(Display *dpy, XEvent *event) * Copyright 1994, Mike Finger. *************************************************************************/ int diffx, diffy; -void process_message(unsigned long type, unsigned long *body) +void +process_message(unsigned long type, unsigned long *body) { - struct icon_info *tmp, *old; - char *str; - long olddesk; - - switch(type){ - case M_CONFIGURE_WINDOW: - if (ready){ - if (!(local_flags & CURRENT_ONLY)) break; - tmp = Head; - while(tmp != NULL){ - if (tmp->id == body[0]){ - if ((tmp->desk != body[7]) && !(tmp->flags & STICKY)){ - olddesk = tmp->desk; - tmp->desk = body[7]; - if (olddesk == CurrentDesk || tmp->desk == CurrentDesk){ - if (tmp->desk == CurrentDesk && sortby != UNSORT) - SortItem(NULL); - num_icons = AdjustIconWindows(); - GetIconwinSize(&diffx, &diffy); - if (diffy && (primary == BOTTOM || secondary == BOTTOM)) - icon_win_y += diffy; - if (diffx && (primary == RIGHT || secondary == RIGHT)) - icon_win_x += diffx; - if (icon_win_y < 0) - icon_win_y = 0; - if (icon_win_x < 0) - icon_win_x = 0; - if (icon_win_x + Width > icon_win_width) - icon_win_x = icon_win_width - Width; - if (icon_win_y + Height > icon_win_height) - icon_win_y = icon_win_height - Height; - XMoveResizeWindow(dpy, icon_win, -icon_win_x, -icon_win_y, - icon_win_width, icon_win_height); - if (tmp->desk == CurrentDesk){ - XMapWindow(dpy, tmp->IconWin); - if (max_icon_height != 0) - XMapWindow(dpy, tmp->icon_pixmap_w); - }else{ - XUnmapWindow(dpy, tmp->IconWin); - if (max_icon_height != 0) - XUnmapWindow(dpy, tmp->icon_pixmap_w); - } - if (!(local_flags & HIDE_H) && diffx) - RedrawHScrollbar(); - if (!(local_flags & HIDE_V) && diffy) - RedrawVScrollbar(); - } - }else if ((body[8] & STICKY) && !(tmp->flags & STICKY)) /* stick */ - tmp->flags |= STICKY; - else if (!(body[8] & STICKY) && (tmp->flags & STICKY)){ /* unstick */ - tmp->flags &= ~STICKY; - tmp->desk = body[7]; - } - return; - } - tmp = tmp->next; - } - break; - } - case M_ADD_WINDOW: - if (AddItem(body[0], body[7], body[8]) == True && ready){ - GetIconwinSize(&diffx, &diffy); - if (diffy && (primary == BOTTOM || secondary == BOTTOM)) - icon_win_y += diffy; - if (diffx && (primary == RIGHT || secondary == RIGHT)) - icon_win_x += diffx; - XMoveResizeWindow(dpy, icon_win, -icon_win_x, -icon_win_y, - icon_win_width, icon_win_height); - } - break; - case M_DESTROY_WINDOW: - if (DeleteItem(body[0]) && ready){ - GetIconwinSize(&diffx, &diffy); - if (diffy && (primary == BOTTOM || secondary == BOTTOM)) - icon_win_y += diffy; - if (diffx && (primary == RIGHT || secondary == RIGHT)) - icon_win_x += diffx; - if (icon_win_y < 0) - icon_win_y = 0; - if (icon_win_x < 0) - icon_win_x = 0; - if (icon_win_x + Width > icon_win_width) - icon_win_x = icon_win_width - Width; - if (icon_win_y + Height > icon_win_height) - icon_win_y = icon_win_height - Height; - XMoveResizeWindow(dpy, icon_win, -icon_win_x, -icon_win_y, - icon_win_width, icon_win_height); - AdjustIconWindows(); - if (!(local_flags & HIDE_H) && diffx) - RedrawHScrollbar(); - if (!(local_flags & HIDE_V) && diffy) - RedrawVScrollbar(); - } - break; - case M_ICON_FILE: - case M_RES_CLASS: - UpdateItem(type, body[0], (char *)&body[3]); - break; - case M_WINDOW_NAME: - tmp = UpdateItem(type, body[0], (char *)&body[3]); - if (!ready || tmp == NULL) - break; - if (sortby == WINDOWNAME && tmp->IconWin != None - && desk_cond(tmp) && SortItem(tmp) == True) - AdjustIconWindows(); - break; - case M_RES_NAME: - if ((tmp = UpdateItem(type, body[0], (char *)&body[3])) == NULL) - break; - if (LookInList(tmp) && ready){ - if (sortby != UNSORT) - SortItem(tmp); - CreateIconWindow(tmp); - ConfigureIconWindow(tmp); - AdjustIconWindows(); - if (desk_cond(tmp)){ - if (max_icon_height != 0) - XMapWindow(dpy, tmp->icon_pixmap_w); - XMapWindow(dpy, tmp->IconWin); - if (!(local_flags & HIDE_H)) - RedrawHScrollbar(); - if (!(local_flags & HIDE_V)) - RedrawVScrollbar(); - } - } - break; - case M_ICON_NAME: - tmp = UpdateItem(type, body[0], (char *)&body[3]); - if (!ready || tmp == NULL) - break; - if (sortby != UNSORT && tmp->IconWin != None - && desk_cond(tmp) && SortItem(tmp) == True) - AdjustIconWindows(); - if (tmp->IconWin != None && desk_cond(tmp)) - RedrawIcon(tmp, 2); - break; - case M_DEFAULTICON: - str = (char *)safemalloc(strlen((char *)&body[3])+1); - strcpy(str, (char *)&body[3]); - FvwmDefaultIcon = str; - break; - case M_ICONIFY: - case M_DEICONIFY: - if (ready && (tmp = SetFlag(body[0], type)) != NULL) - RedrawIcon(tmp, 2); - break; - case M_FOCUS_CHANGE: - if (!ready) - break; - tmp = Head; - while(tmp != NULL){ - if (tmp->id == body[0]) break; - tmp = tmp->next; - } - old = Hilite; - Hilite = tmp; - if (old != NULL) - RedrawIcon(old, redraw_flag); - if (tmp != NULL) - RedrawIcon(tmp, redraw_flag); - break; - case M_NEW_DESK: - if (CurrentDesk != body[0]){ - CurrentDesk = body[0]; - if (body[0] != 10000 && ready){ /* 10000 is a "magic" number used in FvwmPager */ - if (sortby != UNSORT) - SortItem(NULL); - num_icons = AdjustIconWindows(); - GetIconwinSize(&diffx, &diffy); - icon_win_x = icon_win_y = 0; - if (primary == BOTTOM || secondary == BOTTOM) - icon_win_y = icon_win_height - Height; - if (primary == RIGHT || secondary == RIGHT) - icon_win_x = icon_win_width - Width; - XMoveResizeWindow(dpy, icon_win, -icon_win_x, -icon_win_y, - icon_win_width, icon_win_height); - XUnmapSubwindows(dpy, icon_win); - mapicons(); - if (!(local_flags & HIDE_H)) - RedrawHScrollbar(); - if (!(local_flags & HIDE_V)) - RedrawVScrollbar(); - } - } - break; - case M_END_WINDOWLIST: - GetIconwinSize(&diffx, &diffy); - tmp = Head; - while(tmp != NULL){ - CreateIconWindow(tmp); - ConfigureIconWindow(tmp); - tmp = tmp->next; - } - if (sortby != UNSORT) - SortItem(NULL); - if (primary == BOTTOM || secondary == BOTTOM) - icon_win_y = icon_win_height - Height; - if (primary == RIGHT || secondary == RIGHT) - icon_win_x = icon_win_width - Width; - XMoveResizeWindow(dpy, icon_win, -icon_win_x, -icon_win_y, - icon_win_width, icon_win_height); - AdjustIconWindows(); - XMapWindow(dpy,main_win); - XMapSubwindows(dpy, main_win); - XMapWindow(dpy, icon_win); - mapicons(); - ready = 1; - break; - default: - break; - } + struct icon_info *tmp, *old; + char *str; + long olddesk; + + switch (type) { + case M_CONFIGURE_WINDOW: + if (ready) { + if (!(local_flags & CURRENT_ONLY)) + break; + tmp = Head; + while (tmp != NULL) { + if (tmp->id == body[0]) { + if ((tmp->desk != body[7]) && + !(tmp->flags & STICKY)) { + olddesk = tmp->desk; + tmp->desk = body[7]; + if (olddesk == CurrentDesk || + tmp->desk == CurrentDesk) { + if (tmp->desk == + CurrentDesk && + sortby != UNSORT) + SortItem(NULL); + num_icons = + AdjustIconWindows(); + GetIconwinSize( + &diffx, &diffy); + if (diffy && + (primary == + BOTTOM || + secondary == + BOTTOM)) + icon_win_y += + diffy; + if (diffx && + (primary == RIGHT || + secondary == + RIGHT)) + icon_win_x += + diffx; + if (icon_win_y < 0) + icon_win_y = 0; + if (icon_win_x < 0) + icon_win_x = 0; + if (icon_win_x + Width > + icon_win_width) + icon_win_x = + icon_win_width - + Width; + if (icon_win_y + + Height > + icon_win_height) + icon_win_y = + icon_win_height - + Height; + XMoveResizeWindow(dpy, + icon_win, + -icon_win_x, + -icon_win_y, + icon_win_width, + icon_win_height); + if (tmp->desk == + CurrentDesk) { + XMapWindow(dpy, + tmp->IconWin); + if (max_icon_height != + 0) + XMapWindow( + dpy, + tmp->icon_pixmap_w); + } else { + XUnmapWindow( + dpy, + tmp->IconWin); + if (max_icon_height != + 0) + XUnmapWindow( + dpy, + tmp->icon_pixmap_w); + } + if (!(local_flags & + HIDE_H) && + diffx) + RedrawHScrollbar(); + if (!(local_flags & + HIDE_V) && + diffy) + RedrawVScrollbar(); + } + } else if ((body[8] & STICKY) && + !(tmp->flags & + STICKY)) /* stick */ + tmp->flags |= STICKY; + else if (!(body[8] & STICKY) && + (tmp->flags & + STICKY)) { /* unstick */ + tmp->flags &= ~STICKY; + tmp->desk = body[7]; + } + return; + } + tmp = tmp->next; + } + break; + } + case M_ADD_WINDOW: + if (AddItem(body[0], body[7], body[8]) == True && ready) { + GetIconwinSize(&diffx, &diffy); + if (diffy && (primary == BOTTOM || secondary == BOTTOM)) + icon_win_y += diffy; + if (diffx && (primary == RIGHT || secondary == RIGHT)) + icon_win_x += diffx; + XMoveResizeWindow(dpy, icon_win, -icon_win_x, + -icon_win_y, icon_win_width, icon_win_height); + } + break; + case M_DESTROY_WINDOW: + if (DeleteItem(body[0]) && ready) { + GetIconwinSize(&diffx, &diffy); + if (diffy && (primary == BOTTOM || secondary == BOTTOM)) + icon_win_y += diffy; + if (diffx && (primary == RIGHT || secondary == RIGHT)) + icon_win_x += diffx; + if (icon_win_y < 0) + icon_win_y = 0; + if (icon_win_x < 0) + icon_win_x = 0; + if (icon_win_x + Width > icon_win_width) + icon_win_x = icon_win_width - Width; + if (icon_win_y + Height > icon_win_height) + icon_win_y = icon_win_height - Height; + XMoveResizeWindow(dpy, icon_win, -icon_win_x, + -icon_win_y, icon_win_width, icon_win_height); + AdjustIconWindows(); + if (!(local_flags & HIDE_H) && diffx) + RedrawHScrollbar(); + if (!(local_flags & HIDE_V) && diffy) + RedrawVScrollbar(); + } + break; + case M_ICON_FILE: + case M_RES_CLASS: + UpdateItem(type, body[0], (char *)&body[3]); + break; + case M_WINDOW_NAME: + tmp = UpdateItem(type, body[0], (char *)&body[3]); + if (!ready || tmp == NULL) + break; + if (sortby == WINDOWNAME && tmp->IconWin != None && + desk_cond(tmp) && SortItem(tmp) == True) + AdjustIconWindows(); + break; + case M_RES_NAME: + if ((tmp = UpdateItem(type, body[0], (char *)&body[3])) == NULL) + break; + if (LookInList(tmp) && ready) { + if (sortby != UNSORT) + SortItem(tmp); + CreateIconWindow(tmp); + ConfigureIconWindow(tmp); + AdjustIconWindows(); + if (desk_cond(tmp)) { + if (max_icon_height != 0) + XMapWindow(dpy, tmp->icon_pixmap_w); + XMapWindow(dpy, tmp->IconWin); + if (!(local_flags & HIDE_H)) + RedrawHScrollbar(); + if (!(local_flags & HIDE_V)) + RedrawVScrollbar(); + } + } + break; + case M_ICON_NAME: + tmp = UpdateItem(type, body[0], (char *)&body[3]); + if (!ready || tmp == NULL) + break; + if (sortby != UNSORT && tmp->IconWin != None && + desk_cond(tmp) && SortItem(tmp) == True) + AdjustIconWindows(); + if (tmp->IconWin != None && desk_cond(tmp)) + RedrawIcon(tmp, 2); + break; + case M_DEFAULTICON: + str = (char *)xmalloc(strlen((char *)&body[3]) + 1); + strlcpy(str, (char *)&body[3], strlen((char *)&body[3]) + 1); + FvwmDefaultIcon = str; + break; + case M_ICONIFY: + case M_DEICONIFY: + if (ready && (tmp = SetFlag(body[0], type)) != NULL) + RedrawIcon(tmp, 2); + break; + case M_FOCUS_CHANGE: + if (!ready) + break; + tmp = Head; + while (tmp != NULL) { + if (tmp->id == body[0]) + break; + tmp = tmp->next; + } + old = Hilite; + Hilite = tmp; + if (old != NULL) + RedrawIcon(old, redraw_flag); + if (tmp != NULL) + RedrawIcon(tmp, redraw_flag); + break; + case M_NEW_DESK: + if (CurrentDesk != body[0]) { + CurrentDesk = body[0]; + if (body[0] != 10000 && + ready) { /* 10000 is a "magic" number used in + FvwmPager */ + if (sortby != UNSORT) + SortItem(NULL); + num_icons = AdjustIconWindows(); + GetIconwinSize(&diffx, &diffy); + icon_win_x = icon_win_y = 0; + if (primary == BOTTOM || secondary == BOTTOM) + icon_win_y = icon_win_height - Height; + if (primary == RIGHT || secondary == RIGHT) + icon_win_x = icon_win_width - Width; + XMoveResizeWindow(dpy, icon_win, -icon_win_x, + -icon_win_y, icon_win_width, + icon_win_height); + XUnmapSubwindows(dpy, icon_win); + mapicons(); + if (!(local_flags & HIDE_H)) + RedrawHScrollbar(); + if (!(local_flags & HIDE_V)) + RedrawVScrollbar(); + } + } + break; + case M_END_WINDOWLIST: + GetIconwinSize(&diffx, &diffy); + tmp = Head; + while (tmp != NULL) { + CreateIconWindow(tmp); + ConfigureIconWindow(tmp); + tmp = tmp->next; + } + if (sortby != UNSORT) + SortItem(NULL); + if (primary == BOTTOM || secondary == BOTTOM) + icon_win_y = icon_win_height - Height; + if (primary == RIGHT || secondary == RIGHT) + icon_win_x = icon_win_width - Width; + XMoveResizeWindow(dpy, icon_win, -icon_win_x, -icon_win_y, + icon_win_width, icon_win_height); + AdjustIconWindows(); + XMapWindow(dpy, main_win); + XMapSubwindows(dpy, main_win); + XMapWindow(dpy, icon_win); + mapicons(); + ready = 1; + break; + default: + break; + } } -struct icon_info *SetFlag(unsigned long id, int t) +struct icon_info * +SetFlag(unsigned long id, int t) { - struct icon_info *tmp; - tmp = Head; - - while(tmp != NULL){ - if (tmp->id == id){ - if (t == M_ICONIFY) - tmp->flags |= ICONIFIED; - else - tmp->flags ^= ICONIFIED; - return tmp; - } - tmp = tmp->next; - } - return NULL; + struct icon_info *tmp; + tmp = Head; + + while (tmp != NULL) { + if (tmp->id == id) { + if (t == M_ICONIFY) + tmp->flags |= ICONIFIED; + else + tmp->flags ^= ICONIFIED; + return tmp; + } + tmp = tmp->next; + } + return NULL; } -void mapicons(void) +void +mapicons(void) { - struct icon_info *tmp; - tmp = Head; - - while(tmp != NULL){ - if (desk_cond(tmp)){ - XMapWindow(dpy, tmp->IconWin); - if (max_icon_height != 0) - XMapWindow(dpy, tmp->icon_pixmap_w); - } - tmp = tmp->next; - } + struct icon_info *tmp; + tmp = Head; + + while (tmp != NULL) { + if (desk_cond(tmp)) { + XMapWindow(dpy, tmp->IconWin); + if (max_icon_height != 0) + XMapWindow(dpy, tmp->icon_pixmap_w); + } + tmp = tmp->next; + } } -int AdjustIconWindows(void) +int +AdjustIconWindows(void) { - struct icon_info *tmp; - int i = 0; - tmp = Head; - - while(tmp != NULL){ - if (desk_cond(tmp) && tmp->IconWin != None) - AdjustIconWindow(tmp, i++); - tmp = tmp->next; - } - return i; + struct icon_info *tmp; + int i = 0; + tmp = Head; + + while (tmp != NULL) { + if (desk_cond(tmp) && tmp->IconWin != None) + AdjustIconWindow(tmp, i++); + tmp = tmp->next; + } + return i; } -int desk_cond(struct icon_info *item) +int +desk_cond(struct icon_info *item) { - if (!(local_flags & CURRENT_ONLY) || - (item->flags & STICKY) || (item->desk == CurrentDesk)) - return 1; + if (!(local_flags & CURRENT_ONLY) || (item->flags & STICKY) || + (item->desk == CurrentDesk)) + return 1; - return 0; + return 0; } /************************************************************************ @@ -2096,64 +2286,66 @@ int desk_cond(struct icon_info *item) * Skeleton based on AddItem() from FvwmWinList: * Copyright 1994, Mike Finger. ***********************************************************************/ -Bool AddItem(unsigned long id, long desk, unsigned long flags) +Bool +AddItem(unsigned long id, long desk, unsigned long flags) { - struct icon_info *new, *tmp; - tmp = Head; - - if (id == main_win || (flags & TRANSIENT) || !(flags & SUPPRESSICON)) - return False; + struct icon_info *new, *tmp; + tmp = Head; + + if (id == main_win || (flags & TRANSIENT) || !(flags & SUPPRESSICON)) + return False; + + while (tmp != NULL) { + if (tmp->id == id || + (tmp->wmhints && (tmp->wmhints->flags & IconWindowHint) && + tmp->wmhints->icon_window == id)) + return False; + tmp = tmp->next; + } - while (tmp != NULL){ - if (tmp->id == id || - (tmp->wmhints && (tmp->wmhints->flags & IconWindowHint) && - tmp->wmhints->icon_window == id)) - return False; - tmp = tmp->next; - } + new = (struct icon_info *)xmalloc(sizeof(struct icon_info)); + new->name = NULL; + new->window_name = NULL; + new->res_class = NULL; + new->res_name = NULL; + new->action = NULL; + new->icon_file = NULL; + new->icon_w = 0; + new->icon_h = 0; + new->IconWin = None; + new->iconPixmap = None; + new->icon_maskPixmap = None; + new->icon_pixmap_w = None; + new->icon_depth = 0; + new->desk = desk; + new->id = id; + new->extra_flags = DEFAULTICON; + new->flags = flags | ICON_OURS; + new->wmhints = NULL; + + /* add new item to the head of the list + + new->prev = NULL; + new->next = Head; + if (Head != NULL) + Head->prev = new; + else + Tail = new; + Head = new; */ + + /* add new item to the tail of the list */ + new->prev = Tail; + new->next = NULL; + if (Tail != NULL) + Tail->next = new; + else + Head = new; + Tail = new; + + if (desk_cond(new)) + num_icons++; - new = (struct icon_info *)safemalloc(sizeof(struct icon_info)); - new->name = NULL; - new->window_name = NULL; - new->res_class = NULL; - new->res_name = NULL; - new->action = NULL; - new->icon_file = NULL; - new->icon_w = 0; - new->icon_h = 0; - new->IconWin = None; - new->iconPixmap = None; - new->icon_maskPixmap = None; - new->icon_pixmap_w = None; - new->icon_depth = 0; - new->desk = desk; - new->id = id; - new->extra_flags = DEFAULTICON; - new->flags = flags | ICON_OURS; - new->wmhints = NULL; - -/* add new item to the head of the list - - new->prev = NULL; - new->next = Head; - if (Head != NULL) - Head->prev = new; - else - Tail = new; - Head = new; */ - -/* add new item to the tail of the list */ - new->prev = Tail; - new->next = NULL; - if (Tail != NULL) - Tail->next = new; - else - Head = new; - Tail = new; - - if (desk_cond(new)) num_icons++; - - return True; + return True; } /************************************************************************ @@ -2161,39 +2353,41 @@ Bool AddItem(unsigned long id, long desk, unsigned long flags) * Skeleton based on DeleteItem() from FvwmWinList: * Copyright 1994, Mike Finger. ***********************************************************************/ -Bool DeleteItem(unsigned long id) +Bool +DeleteItem(unsigned long id) { - struct icon_info *tmp = Head; - - while(tmp != NULL){ - if (tmp->id == id){ - if (desk_cond(tmp)) - num_icons--; - if (Hilite == tmp) - Hilite = NULL; - if ((tmp->icon_pixmap_w != None) && (tmp->flags & ICON_OURS)) - XDestroyWindow(dpy, tmp->icon_pixmap_w); - if (tmp->IconWin != None) - XDestroyWindow(dpy, tmp->IconWin); - if (tmp == Head){ - Head = tmp->next; - if (Head != NULL) - Head->prev = NULL; - else - Tail = NULL; - }else { - if (Tail == tmp) - Tail = tmp->prev; - tmp->prev->next = tmp->next; - if (tmp->next != NULL) - tmp->next->prev = tmp->prev; - } - freeitem(tmp, 1); - return True; - } - tmp = tmp->next; - } - return False; + struct icon_info *tmp = Head; + + while (tmp != NULL) { + if (tmp->id == id) { + if (desk_cond(tmp)) + num_icons--; + if (Hilite == tmp) + Hilite = NULL; + if ((tmp->icon_pixmap_w != None) && + (tmp->flags & ICON_OURS)) + XDestroyWindow(dpy, tmp->icon_pixmap_w); + if (tmp->IconWin != None) + XDestroyWindow(dpy, tmp->IconWin); + if (tmp == Head) { + Head = tmp->next; + if (Head != NULL) + Head->prev = NULL; + else + Tail = NULL; + } else { + if (Tail == tmp) + Tail = tmp->prev; + tmp->prev->next = tmp->next; + if (tmp->next != NULL) + tmp->next->prev = tmp->prev; + } + freeitem(tmp, 1); + return True; + } + tmp = tmp->next; + } + return False; } /************************************************************************ @@ -2201,184 +2395,192 @@ Bool DeleteItem(unsigned long id) * Skeleton based on UpdateItem() from FvwmWinList: * Copyright 1994, Mike Finger. ***********************************************************************/ -struct icon_info *UpdateItem(unsigned long type, unsigned long id, char *item) +struct icon_info * +UpdateItem(unsigned long type, unsigned long id, char *item) { - struct icon_info *tmp; - char *str; - XClassHint classhint; - int ret; - - tmp = Head; - while (tmp != NULL){ - if (tmp->id == id){ - str = (char *)safemalloc(strlen(item)+1); - strcpy(str, item); - - switch (type){ - case M_ICON_NAME: - if (tmp->name != NULL) - free(tmp->name); - tmp->name = str; - return tmp; - case M_ICON_FILE: - tmp->icon_file = str; - tmp->extra_flags &= ~DEFAULTICON; - return tmp; - case M_WINDOW_NAME: - if (tmp->window_name != NULL) - free(tmp->window_name); - tmp->window_name = str; - return tmp; - case M_RES_CLASS: - tmp->res_class = str; - ret = 0; - if (sortby == RESCLASS && strcmp(NoClass, str) == 0 - && !(ret = XGetClassHint(dpy, tmp->id, &classhint))){ - tmp->extra_flags |= NOCLASS; - } - if (ret){ - if (classhint.res_class != NULL) - XFree(classhint.res_class); - if (classhint.res_name != NULL) - XFree(classhint.res_name); - } - return tmp; - case M_RES_NAME: - tmp->res_name = str; - ret = 0; - if (sortby == RESNAME && strcmp(NoResource, str) == 0 - && !(ret = XGetClassHint(dpy, tmp->id, &classhint))) - tmp->extra_flags |= NONAME; - if (ret){ - if (classhint.res_class != NULL) - XFree(classhint.res_class); - if (classhint.res_name != NULL) - XFree(classhint.res_name); - } - return tmp; - } - } - tmp = tmp->next; - } - return NULL; + struct icon_info *tmp; + char *str; + XClassHint classhint; + int ret; + + tmp = Head; + while (tmp != NULL) { + if (tmp->id == id) { + size_t item_len = strlen(item) + 1; + str = (char *)xmalloc(item_len); + strlcpy(str, item, item_len); + + switch (type) { + case M_ICON_NAME: + if (tmp->name != NULL) + free(tmp->name); + tmp->name = str; + return tmp; + case M_ICON_FILE: + tmp->icon_file = str; + tmp->extra_flags &= ~DEFAULTICON; + return tmp; + case M_WINDOW_NAME: + if (tmp->window_name != NULL) + free(tmp->window_name); + tmp->window_name = str; + return tmp; + case M_RES_CLASS: + tmp->res_class = str; + ret = 0; + if (sortby == RESCLASS && + strcmp(NoClass, str) == 0 && + !(ret = XGetClassHint( + dpy, tmp->id, &classhint))) { + tmp->extra_flags |= NOCLASS; + } + if (ret) { + if (classhint.res_class != NULL) + XFree(classhint.res_class); + if (classhint.res_name != NULL) + XFree(classhint.res_name); + } + return tmp; + case M_RES_NAME: + tmp->res_name = str; + ret = 0; + if (sortby == RESNAME && + strcmp(NoResource, str) == 0 && + !(ret = XGetClassHint( + dpy, tmp->id, &classhint))) + tmp->extra_flags |= NONAME; + if (ret) { + if (classhint.res_class != NULL) + XFree(classhint.res_class); + if (classhint.res_name != NULL) + XFree(classhint.res_name); + } + return tmp; + } + } + tmp = tmp->next; + } + return NULL; } -Bool SortItem(struct icon_info *item) +Bool +SortItem(struct icon_info *item) { - struct icon_info *tmp1=Head, *a, *b, *tmp2; - - if (tmp1 == NULL) - return False; - - if (item != NULL && - ((itemcmp(item->prev, item) <= 0) && - (itemcmp(item->next, item) >= 0))) - return False; - - while (tmp1->next != NULL){ - tmp2 = MinItem(tmp1); - if (tmp1 == tmp2){ - tmp1 = tmp1->next; - continue; - } - if (tmp1 == Head) - Head = tmp2; - a = tmp1->prev; - b = tmp1->next; - if (tmp1->prev != NULL) - tmp1->prev->next = tmp2; - if (b != tmp2) - tmp1->next->prev = tmp2; - if (b != tmp2) - tmp2->prev->next = tmp1; - if (tmp2->next != NULL) - tmp2->next->prev = tmp1; - if (b == tmp2){ - tmp1->prev = tmp2; - tmp1->next = tmp2->next; - tmp2->prev = a; - tmp2->next = tmp1; - }else{ - tmp1->prev = tmp2->prev; - tmp1->next = tmp2->next; - tmp2->prev = a; - tmp2->next = b; - } - tmp1 = b; - } - Tail = tmp1; + struct icon_info *tmp1 = Head, *a, *b, *tmp2; + + if (tmp1 == NULL) + return False; + + if (item != NULL && ((itemcmp(item->prev, item) <= 0) && + (itemcmp(item->next, item) >= 0))) + return False; - return True; + while (tmp1->next != NULL) { + tmp2 = MinItem(tmp1); + if (tmp1 == tmp2) { + tmp1 = tmp1->next; + continue; + } + if (tmp1 == Head) + Head = tmp2; + a = tmp1->prev; + b = tmp1->next; + if (tmp1->prev != NULL) + tmp1->prev->next = tmp2; + if (b != tmp2) + tmp1->next->prev = tmp2; + if (b != tmp2) + tmp2->prev->next = tmp1; + if (tmp2->next != NULL) + tmp2->next->prev = tmp1; + if (b == tmp2) { + tmp1->prev = tmp2; + tmp1->next = tmp2->next; + tmp2->prev = a; + tmp2->next = tmp1; + } else { + tmp1->prev = tmp2->prev; + tmp1->next = tmp2->next; + tmp2->prev = a; + tmp2->next = b; + } + tmp1 = b; + } + Tail = tmp1; + + return True; } -struct icon_info *MinItem(struct icon_info *head) +struct icon_info * +MinItem(struct icon_info *head) { - struct icon_info *tmp, *i_min; + struct icon_info *tmp, *i_min; - if (head == NULL) - return NULL; + if (head == NULL) + return NULL; - i_min = head; - tmp = head->next; - while (tmp != NULL){ - if (itemcmp(i_min, tmp) > 0) - i_min = tmp; - tmp = tmp->next; - } - return i_min; + i_min = head; + tmp = head->next; + while (tmp != NULL) { + if (itemcmp(i_min, tmp) > 0) + i_min = tmp; + tmp = tmp->next; + } + return i_min; } -int itemcmp(struct icon_info *item1, struct icon_info *item2) +int +itemcmp(struct icon_info *item1, struct icon_info *item2) { - int ret1, ret2; - - if (item1 == NULL){ - if (item2 == NULL) - return 0; - else - return -1; - } else if (item2 == NULL) - return 1; - - /* skip items not on the current desk */ - ret1 = desk_cond(item1); - ret2 = desk_cond(item2); - if (!ret1 || !ret2) - return (ret1 - ret2); - - ret1 = 0; - ret2 = strcmp(item1->name, item2->name); - - switch(sortby){ - case WINDOWNAME: - ret1 = strcmp(item1->window_name, item2->window_name); - break; - case RESCLASS: - if ((item1->extra_flags & NOCLASS)){ - if ((item2->extra_flags & NOCLASS)) - ret1 = 0; - else if (!(item2->extra_flags & NOCLASS)) - ret1 = -1; - }else if ((item2->extra_flags & NOCLASS)) - ret1 = 1; - else - ret1 = strcmp(item1->res_class, item2->res_class); - break; - case RESNAME: - if ((item1->extra_flags & NOCLASS)){ - if ((item2->extra_flags & NOCLASS)) - ret1 = 0; - else if (!(item2->extra_flags & NOCLASS)) - ret1 = -1; - }else if ((item2->extra_flags & NOCLASS)) - ret1 = 1; - else - ret1 = strcmp(item1->res_name, item2->res_name); - break; - default: - break; - } - return (ret1 != 0 ? ret1 : ret2); + int ret1, ret2; + + if (item1 == NULL) { + if (item2 == NULL) + return 0; + else + return -1; + } else if (item2 == NULL) + return 1; + + /* skip items not on the current desk */ + ret1 = desk_cond(item1); + ret2 = desk_cond(item2); + if (!ret1 || !ret2) + return (ret1 - ret2); + + ret1 = 0; + ret2 = strcmp(item1->name, item2->name); + + switch (sortby) { + case WINDOWNAME: + ret1 = strcmp(item1->window_name, item2->window_name); + break; + case RESCLASS: + if ((item1->extra_flags & NOCLASS)) { + if ((item2->extra_flags & NOCLASS)) + ret1 = 0; + else if (!(item2->extra_flags & NOCLASS)) + ret1 = -1; + } else if ((item2->extra_flags & NOCLASS)) + ret1 = 1; + else + ret1 = strcmp(item1->res_class, item2->res_class); + break; + case RESNAME: + if ((item1->extra_flags & NOCLASS)) { + if ((item2->extra_flags & NOCLASS)) + ret1 = 0; + else if (!(item2->extra_flags & NOCLASS)) + ret1 = -1; + } else if ((item2->extra_flags & NOCLASS)) + ret1 = 1; + else + ret1 = strcmp(item1->res_name, item2->res_name); + break; + default: + break; + } + return (ret1 != 0 ? ret1 : ret2); } /* @@ -2390,9 +2592,9 @@ void ShowItem(struct icon_info *head) tmp = head; while (tmp != NULL){ fprintf(stderr, "id:%x name:%s resname:%s class%s iconfile:%s\n", - tmp->id, - tmp->name == NULL ? "NULL" : tmp->name, tmp->res_name, - tmp->res_class, tmp->icon_file); + tmp->id, + tmp->name == NULL ? "NULL" : tmp->name, tmp->res_name, + tmp->res_class, tmp->icon_file); tmp = tmp->next; } } @@ -2404,7 +2606,7 @@ void ShowAction(void) tmp = MouseActions; while (tmp != NULL){ fprintf(stderr, "mouse:%d type %d action:%s\n", tmp->mouse, - tmp->type, tmp->action); + tmp->type, tmp->action); tmp = tmp->next; } } @@ -2416,246 +2618,262 @@ void ShowKAction(void) tmp = KeyActions; while (tmp != NULL){ fprintf(stderr, "key:%s keycode:%d action:%s\n", tmp->name, - tmp->keycode, tmp->action); + tmp->keycode, tmp->action); tmp = tmp->next; } } */ -void freeitem(struct icon_info *item, int d) +void +freeitem(struct icon_info *item, int d) { - if (item == NULL) - return; - - if (!(item->flags & ICON_OURS)){ - if (max_icon_height != 0) - XUnmapWindow(dpy, item->icon_pixmap_w); - if (d == 0) - XReparentWindow(dpy, item->icon_pixmap_w, Root, 0, 0); - } + if (item == NULL) + return; - if (item->name != NULL) - free(item->name); - if (item->window_name != NULL) - free(item->window_name); - if (item->res_name != NULL) - free(item->res_name); - if (item->res_class != NULL) - free(item->res_class); - if (item->wmhints != NULL) - XFree(item->wmhints); - if (item->iconPixmap != None) - XFreePixmap(dpy, item->iconPixmap); - if (item->icon_maskPixmap != None && - (item->wmhints == NULL || - !(item->wmhints->flags & (IconPixmapHint|IconWindowHint)))) - XFreePixmap(dpy, item->icon_maskPixmap); - - free(item); -} + if (!(item->flags & ICON_OURS)) { + if (max_icon_height != 0) + XUnmapWindow(dpy, item->icon_pixmap_w); + if (d == 0) + XReparentWindow(dpy, item->icon_pixmap_w, Root, 0, 0); + } + if (item->name != NULL) + free(item->name); + if (item->window_name != NULL) + free(item->window_name); + if (item->res_name != NULL) + free(item->res_name); + if (item->res_class != NULL) + free(item->res_class); + if (item->wmhints != NULL) + XFree(item->wmhints); + if (item->iconPixmap != None) + XFreePixmap(dpy, item->iconPixmap); + if (item->icon_maskPixmap != None && + (item->wmhints == NULL || + !(item->wmhints->flags & (IconPixmapHint | IconWindowHint)))) + XFreePixmap(dpy, item->icon_maskPixmap); + + free(item); +} /************************************************************************ IsClick - Based on functions.c from Fvwm: - Copyright 1988, Evans and Sutherland Computer Corporation, - Copyright 1989, Massachusetts Institute of Technology, - Copyright 1993, Robert Nation. + Based on functions.c from Fvwm: + Copyright 1988, Evans and Sutherland Computer Corporation, + Copyright 1989, Massachusetts Institute of Technology, + Copyright 1993, Robert Nation. ***********************************************************************/ -Bool IsClick(int x,int y,unsigned EndMask, XEvent *d) +Bool +IsClick(int x, int y, unsigned EndMask, XEvent *d) { - int xcurrent,ycurrent,total = 0; - - xcurrent = x; - ycurrent = y; - while((total < ClickTime)&& - (x - xcurrent < 5)&&(x - xcurrent > -5)&& - (y - ycurrent < 5)&&(y - ycurrent > -5)) - { - usleep(10000); - total+=10; - if(XCheckMaskEvent (dpy,EndMask, d)) - return True; - if(XCheckMaskEvent (dpy,ButtonMotionMask|PointerMotionMask, d)) - { - xcurrent = d->xmotion.x_root; - ycurrent = d->xmotion.y_root; - } - } - return False; + int xcurrent, ycurrent, total = 0; + + xcurrent = x; + ycurrent = y; + while ((total < ClickTime) && (x - xcurrent < 5) && + (x - xcurrent > -5) && (y - ycurrent < 5) && + (y - ycurrent > -5)) { + usleep(10000); + total += 10; + if (XCheckMaskEvent(dpy, EndMask, d)) + return True; + if (XCheckMaskEvent( + dpy, ButtonMotionMask | PointerMotionMask, d)) { + xcurrent = d->xmotion.x_root; + ycurrent = d->xmotion.y_root; + } + } + return False; } /************************************************************************ * ExecuteAction * Based on part of ComplexFunction() of functions.c from fvwm: - Copyright 1988, Evans and Sutherland Computer Corporation, - Copyright 1989, Massachusetts Institute of Technology, - Copyright 1993, Robert Nation. + Copyright 1988, Evans and Sutherland Computer Corporation, + Copyright 1989, Massachusetts Institute of Technology, + Copyright 1993, Robert Nation. ***********************************************************************/ -void ExecuteAction(int x, int y, struct icon_info *item) +void +ExecuteAction(int x, int y, struct icon_info *item) { - int type = NO_CLICK; - XEvent *ev; - XEvent d; - struct mousefunc *tmp; + int type = NO_CLICK; + XEvent *ev; + XEvent d; + struct mousefunc *tmp; + + /* Wait and see if we have a click, or a move */ + /* wait 100 msec, see if the used releases the button */ + if (IsClick(x, y, ButtonReleaseMask, &d)) { + type = CLICK; + ev = &d; + } - /* Wait and see if we have a click, or a move */ - /* wait 100 msec, see if the used releases the button */ - if(IsClick(x,y,ButtonReleaseMask,&d)) - { - type = CLICK; - ev = &d; - } - - /* If it was a click, wait to see if its a double click */ - if((type == CLICK) && (IsClick(x,y,ButtonPressMask, &d))) - { - type = ONE_AND_A_HALF_CLICKS; - ev = &d; - } - if((type == ONE_AND_A_HALF_CLICKS) && - (IsClick(x,y,ButtonReleaseMask, &d))) - { - type = DOUBLE_CLICK; - ev = &d; - } - tmp = MouseActions; + /* If it was a click, wait to see if its a double click */ + if ((type == CLICK) && (IsClick(x, y, ButtonPressMask, &d))) { + type = ONE_AND_A_HALF_CLICKS; + ev = &d; + } + if ((type == ONE_AND_A_HALF_CLICKS) && + (IsClick(x, y, ButtonReleaseMask, &d))) { + type = DOUBLE_CLICK; + ev = &d; + } + tmp = MouseActions; - while (tmp != NULL){ - if (tmp->mouse == d.xbutton.button && tmp->type == type){ - SendFvwmPipe(fd, tmp->action, item->id); - return; - } - tmp = tmp->next; - } + while (tmp != NULL) { + if (tmp->mouse == d.xbutton.button && tmp->type == type) { + SendFvwmPipe(fd, tmp->action, item->id); + return; + } + tmp = tmp->next; + } } -void ExecuteKey(XEvent event) +void +ExecuteKey(XEvent event) { - struct icon_info *item; - struct keyfunc *tmp; + struct icon_info *item; + struct keyfunc *tmp; - if ((item = Hilite) == NULL) - if ((item = Head) == NULL) - return; + if ((item = Hilite) == NULL) + if ((item = Head) == NULL) + return; - tmp = KeyActions; - event.xkey.keycode = - XKeysymToKeycode(dpy,XKeycodeToKeysym(dpy,event.xkey.keycode,0)); - while (tmp != NULL){ - if (tmp->keycode == event.xkey.keycode){ - SendFvwmPipe(fd, tmp->action, item->id); - return; - } - tmp = tmp->next; - } + tmp = KeyActions; + { + KeySym *mapping; + int width; + + mapping = + XGetKeyboardMapping(dpy, event.xkey.keycode, 1, &width); + if (mapping != NULL) { + KeySym primary = width > 0 ? mapping[0] : NoSymbol; + KeyCode canonical = (primary != NoSymbol) ? + XKeysymToKeycode(dpy, primary) : + 0; + if (canonical != 0) + event.xkey.keycode = canonical; + XFree(mapping); + } + } + while (tmp != NULL) { + if (tmp->keycode == event.xkey.keycode) { + SendFvwmPipe(fd, tmp->action, item->id); + return; + } + tmp = tmp->next; + } } /*********************************************************************** LookInList - Based on part of LookInList() of add_window.c from fvwm: - Copyright 1988, Evans and Sutherland Computer Corporation, - Copyright 1989, Massachusetts Institute of Technology, - Copyright 1993, Robert Nation. + Based on part of LookInList() of add_window.c from fvwm: + Copyright 1988, Evans and Sutherland Computer Corporation, + Copyright 1989, Massachusetts Institute of Technology, + Copyright 1993, Robert Nation. ***********************************************************************/ -int LookInList(struct icon_info *item) +int +LookInList(struct icon_info *item) { - int isdefault=1; - char *value=NULL; - struct iconfile *nptr; - - if (IconListHead == NULL) { - if ((item->extra_flags & DEFAULTICON) && (FvwmDefaultIcon != NULL)) - item->icon_file = FvwmDefaultIcon; - return 1; - } - + int isdefault = 1; + char *value = NULL; + struct iconfile *nptr; + + if (IconListHead == NULL) { + if ((item->extra_flags & DEFAULTICON) && + (FvwmDefaultIcon != NULL)) + item->icon_file = FvwmDefaultIcon; + return 1; + } - for (nptr = IconListHead; nptr != NULL; nptr = nptr->next){ - if (nptr == DefaultIcon) - isdefault = 1; + for (nptr = IconListHead; nptr != NULL; nptr = nptr->next) { + if (nptr == DefaultIcon) + isdefault = 1; - if (matchWildcards(nptr->name, item->res_class) == TRUE){ - value = nptr->iconfile; - if (nptr != DefaultIcon) - isdefault = 0; - } + if (matchWildcards(nptr->name, item->res_class) == TRUE) { + value = nptr->iconfile; + if (nptr != DefaultIcon) + isdefault = 0; + } - if (matchWildcards(nptr->name, item->res_name) == TRUE){ - value = nptr->iconfile; - if (nptr != DefaultIcon) - isdefault = 0; - } + if (matchWildcards(nptr->name, item->res_name) == TRUE) { + value = nptr->iconfile; + if (nptr != DefaultIcon) + isdefault = 0; + } - if (matchWildcards(nptr->name, item->window_name) == TRUE){ - value = nptr->iconfile; - if (nptr != DefaultIcon) - isdefault = 0; - } - } + if (matchWildcards(nptr->name, item->window_name) == TRUE) { + value = nptr->iconfile; + if (nptr != DefaultIcon) + isdefault = 0; + } + } - if (!isdefault){ - item->icon_file = value; - item->extra_flags &= ~DEFAULTICON; - }else if ((item->extra_flags & DEFAULTICON)){ - if (DefaultIcon != NULL) - item->icon_file = DefaultIcon->iconfile; - else if (FvwmDefaultIcon != NULL) - item->icon_file = FvwmDefaultIcon; - } + if (!isdefault) { + item->icon_file = value; + item->extra_flags &= ~DEFAULTICON; + } else if ((item->extra_flags & DEFAULTICON)) { + if (DefaultIcon != NULL) + item->icon_file = DefaultIcon->iconfile; + else if (FvwmDefaultIcon != NULL) + item->icon_file = FvwmDefaultIcon; + } - /* Icon is not shown if "-" is specified */ - if (item->icon_file != NULL && (strcmp(item->icon_file, "-") == 0)){ - DeleteItem(item->id); - return 0; - } - return 1; + /* Icon is not shown if "-" is specified */ + if (item->icon_file != NULL && (strcmp(item->icon_file, "-") == 0)) { + DeleteItem(item->id); + return 0; + } + return 1; } /*********************************************************************** strcpy - Based on stripcpy2() of configure.c from Fvwm: - Copyright 1988, Evans and Sutherland Computer Corporation, - Copyright 1989, Massachusetts Institute of Technology, - Copyright 1993, Robert Nation. + Based on stripcpy2() of configure.c from Fvwm: + Copyright 1988, Evans and Sutherland Computer Corporation, + Copyright 1989, Massachusetts Institute of Technology, + Copyright 1993, Robert Nation. ***********************************************************************/ -char *stripcpy2(char *source) +char * +stripcpy2(char *source) { - char *ptr; - int count = 0; - while((*source != '"')&&(*source != 0)) - source++; - if(*source == 0) - return 0; - - source++; - ptr = source; - while((*ptr!='"')&&(*ptr != 0)){ - ptr++; - count++; - } - ptr = safemalloc(count+1); - strncpy(ptr,source,count); - ptr[count]=0; - return ptr; + char *ptr; + int count = 0; + while ((*source != '"') && (*source != 0)) + source++; + if (*source == 0) + return 0; + + source++; + ptr = source; + while ((*ptr != '"') && (*ptr != 0)) { + ptr++; + count++; + } + ptr = xmalloc(count + 1); + strncpy(ptr, source, count); + ptr[count] = 0; + return ptr; } /*********************************************************************** Error handler ***********************************************************************/ -XErrorHandler myErrorHandler(Display *dpy, XErrorEvent *event) +XErrorHandler +myErrorHandler(Display *dpy, XErrorEvent *event) { - char msg[256]; + char msg[256]; - if (event->error_code == BadWindow) - return 0; + if (event->error_code == BadWindow) + return 0; - XGetErrorText(dpy, event->error_code, msg, 256); + XGetErrorText(dpy, event->error_code, msg, 256); - fprintf(stderr, "Error in %s: %s \n", MyName, msg); - fprintf(stderr, "Major opcode of failed request: %d \n", - event->request_code); - fprintf(stderr, "Resource id of failed request: 0x%lx \n", - event->resourceid); - return 0; + fprintf(stderr, "Error in %s: %s \n", MyName, msg); + fprintf(stderr, "Major opcode of failed request: %d \n", + event->request_code); + fprintf(stderr, "Resource id of failed request: 0x%lx \n", + event->resourceid); + return 0; } Index: fvwm/modules/FvwmIconBox/FvwmIconBox.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIconBox/FvwmIconBox.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIconBox/FvwmIconBox.h --- fvwm/modules/FvwmIconBox/FvwmIconBox.h +++ fvwm/modules/FvwmIconBox/FvwmIconBox.h @@ -6,32 +6,33 @@ #include "../../libs/fvwmlib.h" struct icon_info; Bool ExecIconBoxFunction(char *msg); -extern void CreateWindow(void); -extern Pixel GetColor(char *name); -extern Pixel GetHilite(Pixel background); -extern Pixel GetShadow(Pixel background); -extern void nocolor(char *a, char *b); -extern void RedrawWindow(void); -extern void match_string(char *tline); -extern void Loop(void); -extern void ParseOptions(void); -extern char *safemalloc(int length); -extern int My_XNextEvent(Display *dpy, XEvent *event); -extern void CopyString(char **dest, char *source); -extern void RelieveWindow(Window win,int x,int y,int w,int h,GC rGC,GC sGC); -extern void SendFvwmPipe(int *,char *text, unsigned long window); -extern void DeadPipe(int nonsense); -extern void CreateIconWindow(struct icon_info *item); -extern void ConfigureIconWindow(struct icon_info *item); -extern void DrawIconWindow(struct icon_info *item); -extern void GetBitmapFile(struct icon_info *item); -extern void GetXPMFile(struct icon_info *item); +extern void CreateWindow(void); +extern Pixel GetColor(char *name); +extern Pixel GetHilite(Pixel background); +extern Pixel GetShadow(Pixel background); +extern void nocolor(char *a, char *b); +extern void RedrawWindow(void); +extern void match_string(char *tline); +extern void Loop(void); +extern void ParseOptions(void); +extern int My_XNextEvent(Display *dpy, XEvent *event); +extern void CopyString(char **dest, char *source); +extern void RelieveWindow( + Window win, int x, int y, int w, int h, GC rGC, GC sGC); +extern void SendFvwmPipe(int *, char *text, unsigned long window); +extern void DeadPipe(int nonsense); +extern void CreateIconWindow(struct icon_info *item); +extern void ConfigureIconWindow(struct icon_info *item); +extern void DrawIconWindow(struct icon_info *item); +extern void GetBitmapFile(struct icon_info *item); +extern void GetXPMFile(struct icon_info *item); extern void GetIconWindow(struct icon_info *item); extern void GetIconBitmap(struct icon_info *item); -extern void process_message(unsigned long type,unsigned long *body); +extern void process_message(unsigned long type, unsigned long *body); extern Bool AddItem(unsigned long id, long desk, unsigned long flags); extern Bool DeleteItem(unsigned long id); -extern struct icon_info *UpdateItem(unsigned long type, unsigned long id, char *item); +extern struct icon_info *UpdateItem( + unsigned long type, unsigned long id, char *item); extern void freeitem(struct icon_info *item, int d); extern void RedrawHScrollbar(void); extern void RedrawVScrollbar(void); @@ -70,8 +71,7 @@ extern int desk_cond(struct icon_info *item); extern int itemcmp(struct icon_info *item1, struct icon_info *item2); extern XErrorHandler myErrorHandler(Display *dpy, XErrorEvent *event); - -extern Display *dpy; /* which display are we talking to */ +extern Display *dpy; /* which display are we talking to */ extern Window Root; extern Window main_win; extern Window holder_win; @@ -79,9 +79,9 @@ extern Window icon_win; extern int screen; extern int d_depth; extern Pixel fore_pix, back_pix, icon_fore_pix, icon_back_pix; -extern GC NormalGC; -extern GC ReliefGC; -extern int ButtonWidth,ButtonHeight; +extern GC NormalGC; +extern GC ReliefGC; +extern int ButtonWidth, ButtonHeight; extern XFontStruct *font; extern int num_rows; extern int num_columns; @@ -94,53 +94,49 @@ extern int icon_win_width, icon_win_height; extern Pixmap IconwinPixmap; extern char *IconwinPixmapFile; -struct icon_info -{ - char *action; - char *name; - char *window_name; - char *res_class; - char *res_name; - char *icon_file; - int x; - int y; - int icon_w; - int icon_h; - Pixmap iconPixmap; /* pixmap for the icon */ - Pixmap icon_maskPixmap; - Window IconWin; - Window icon_pixmap_w; - XWMHints *wmhints; - int icon_depth; - long id; - long desk; - long flags; - long extra_flags; - struct icon_info *next; - struct icon_info *prev; +struct icon_info { + char *action; + char *name; + char *window_name; + char *res_class; + char *res_name; + char *icon_file; + int x; + int y; + int icon_w; + int icon_h; + Pixmap iconPixmap; /* pixmap for the icon */ + Pixmap icon_maskPixmap; + Window IconWin; + Window icon_pixmap_w; + XWMHints *wmhints; + int icon_depth; + long id; + long desk; + long flags; + long extra_flags; + struct icon_info *next; + struct icon_info *prev; }; -struct iconfile -{ - char *name; - char *iconfile; - struct iconfile *next; +struct iconfile { + char *name; + char *iconfile; + struct iconfile *next; }; -struct mousefunc -{ - int mouse; - int type; - char *action; - struct mousefunc *next; +struct mousefunc { + int mouse; + int type; + char *action; + struct mousefunc *next; }; -struct keyfunc -{ - char *name; - KeyCode keycode; - char *action; - struct keyfunc *next; +struct keyfunc { + char *name; + KeyCode keycode; + char *action; + struct keyfunc *next; }; extern struct icon_info *Head; @@ -154,8 +150,6 @@ extern char *pixmapPath; extern int icon_relief; - - #define NOPLACE -1 #define LEFT 0 #define RIGHT 1 @@ -170,19 +164,18 @@ extern int icon_relief; #define DOUBLE_CLICK 2 /* sorting */ -#define UNSORT 0 +#define UNSORT 0 #define WINDOWNAME 1 -#define ICONNAME 2 -#define RESNAME 3 -#define RESCLASS 4 +#define ICONNAME 2 +#define RESNAME 3 +#define RESCLASS 4 /* local flags */ -#define HIDE_H (1<<0) -#define HIDE_V (1<<1) -#define SETWMICONSIZE (1<<2) -#define CURRENT_ONLY (1<<3) - -#define DEFAULTICON (1<<0) -#define NONAME (1<<1) -#define NOCLASS (1<<2) - +#define HIDE_H (1 << 0) +#define HIDE_V (1 << 1) +#define SETWMICONSIZE (1 << 2) +#define CURRENT_ONLY (1 << 3) + +#define DEFAULTICON (1 << 0) +#define NONAME (1 << 1) +#define NOCLASS (1 << 2) Index: fvwm/modules/FvwmIconBox/icons.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIconBox/icons.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIconBox/icons.c --- fvwm/modules/FvwmIconBox/icons.c +++ fvwm/modules/FvwmIconBox/icons.c @@ -9,28 +9,25 @@ * own risk. Permission to use this program for any purpose is given, * as long as the copyright is kept intact. */ - /*********************************************************************** * * Derived from fvwm icon code * ***********************************************************************/ -#include "config.h" - -#include -#include -#include -#include -#include - +#include +#include #include -#include #include -#include -#include +#include +#include +#include +#include +#include +#include #include "../../fvwm/module.h" +#include "config.h" #ifdef HAVE_FCNTL_H #include @@ -48,42 +45,39 @@ extern int save_color_limit; -#define ICON_EVENTS (ExposureMask |\ -ButtonReleaseMask | ButtonPressMask | EnterWindowMask | LeaveWindowMask) +#define ICON_EVENTS \ + (ExposureMask | ButtonReleaseMask | ButtonPressMask | \ + EnterWindowMask | LeaveWindowMask) /**************************************************************************** * * Creates an Icon Window * ****************************************************************************/ -void CreateIconWindow(struct icon_info *item) +void +CreateIconWindow(struct icon_info *item) { - unsigned long valuemask; /* mask for create windows */ - XSetWindowAttributes attributes; /* attributes for create windows */ - - attributes.background_pixel = icon_back_pix; - attributes.event_mask = ExposureMask; - valuemask = CWEventMask | CWBackPixel; - - /* pixmap */ - if (max_icon_height != 0){ - item->icon_pixmap_w = - XCreateWindow(dpy, icon_win, 0, 0, - max(max_icon_width,item->icon_w), - max(max_icon_height,item->icon_h), - 0,CopyFromParent,CopyFromParent, - CopyFromParent,valuemask,&attributes); - XSelectInput(dpy, item->icon_pixmap_w, ICON_EVENTS); - } - - /* label */ - item->IconWin = - XCreateWindow(dpy, icon_win, 0, 0, - max_icon_width, - max_icon_height + 10, - 0,CopyFromParent,CopyFromParent, - CopyFromParent,valuemask,&attributes); - XSelectInput(dpy, item->IconWin, ICON_EVENTS); + unsigned long valuemask; /* mask for create windows */ + XSetWindowAttributes attributes; /* attributes for create windows */ + + attributes.background_pixel = icon_back_pix; + attributes.event_mask = ExposureMask; + valuemask = CWEventMask | CWBackPixel; + + /* pixmap */ + if (max_icon_height != 0) { + item->icon_pixmap_w = XCreateWindow(dpy, icon_win, 0, 0, + max(max_icon_width, item->icon_w), + max(max_icon_height, item->icon_h), 0, CopyFromParent, + CopyFromParent, CopyFromParent, valuemask, &attributes); + XSelectInput(dpy, item->icon_pixmap_w, ICON_EVENTS); + } + + /* label */ + item->IconWin = XCreateWindow(dpy, icon_win, 0, 0, max_icon_width, + max_icon_height + 10, 0, CopyFromParent, CopyFromParent, + CopyFromParent, valuemask, &attributes); + XSelectInput(dpy, item->IconWin, ICON_EVENTS); } /**************************************************************************** @@ -91,108 +85,108 @@ void CreateIconWindow(struct icon_info *item) * Loads an icon file and combines icon shape masks after a resize * ****************************************************************************/ -void ConfigureIconWindow(struct icon_info *item) +void +ConfigureIconWindow(struct icon_info *item) { - Pixmap temp; - int hr = icon_relief/2; - - XSelectInput(dpy, item->id, PropertyChangeMask); - item->wmhints = XGetWMHints(dpy, item->id); - - if (max_icon_height == 0) - return; - - if (item->icon_file != NULL && (!(item->extra_flags & DEFAULTICON) || !(item->wmhints && - item->wmhints->flags & - (IconPixmapHint|IconWindowHint)))){ - /* monochrome bitmap */ - GetBitmapFile(item); - - /* color pixmap */ - if((item->icon_w == 0)&&(item->icon_h == 0)) - GetXPMFile(item); - } - - /* special thanks to Rich Neitzel - for his patch to handle icon windows */ - if((item->icon_h == 0)&&(item->icon_w == 0)&& - (item->wmhints) && (item->wmhints->flags & IconWindowHint)) - GetIconWindow(item); - - /* icon bitmap from the application */ - if((item->icon_h == 0)&&(item->icon_w == 0)&& - (item->wmhints)&&(item->wmhints->flags & IconPixmapHint)) - GetIconBitmap(item); + Pixmap temp; + int hr = icon_relief / 2; + + XSelectInput(dpy, item->id, PropertyChangeMask); + item->wmhints = XGetWMHints(dpy, item->id); + + if (max_icon_height == 0) + return; + + if (item->icon_file != NULL && + (!(item->extra_flags & DEFAULTICON) || + !(item->wmhints && item->wmhints->flags & + (IconPixmapHint | IconWindowHint)))) { + /* monochrome bitmap */ + GetBitmapFile(item); + + /* color pixmap */ + if ((item->icon_w == 0) && (item->icon_h == 0)) + GetXPMFile(item); + } + + /* special thanks to Rich Neitzel + for his patch to handle icon windows */ + if ((item->icon_h == 0) && (item->icon_w == 0) && (item->wmhints) && + (item->wmhints->flags & IconWindowHint)) + GetIconWindow(item); + + /* icon bitmap from the application */ + if ((item->icon_h == 0) && (item->icon_w == 0) && (item->wmhints) && + (item->wmhints->flags & IconPixmapHint)) + GetIconBitmap(item); #ifdef XPM #ifdef SHAPE - if (item->icon_maskPixmap != None) - { - XShapeCombineMask(dpy, item->icon_pixmap_w, ShapeBounding, - hr, hr, item->icon_maskPixmap, ShapeSet); - } + if (item->icon_maskPixmap != None) { + XShapeCombineMask(dpy, item->icon_pixmap_w, ShapeBounding, hr, + hr, item->icon_maskPixmap, ShapeSet); + } #endif #endif - if(item->icon_depth == -1) - { - temp = item->iconPixmap; - item->iconPixmap = - XCreatePixmap(dpy, Root, item->icon_w, - item->icon_h,d_depth); - XCopyPlane(dpy,temp,item->iconPixmap,NormalGC, - 0,0,item->icon_w,item->icon_h,0,0,1); - } + if (item->icon_depth == -1) { + temp = item->iconPixmap; + item->iconPixmap = XCreatePixmap( + dpy, Root, item->icon_w, item->icon_h, d_depth); + XCopyPlane(dpy, temp, item->iconPixmap, NormalGC, 0, 0, + item->icon_w, item->icon_h, 0, 0, 1); + } } -void AdjustIconWindow(struct icon_info *item, int n) +void +AdjustIconWindow(struct icon_info *item, int n) { - int x=0,y=0,w,h,h2,h3,w3; - - w3 = w = max_icon_width + icon_relief; - h3 = h2 = max_icon_height + icon_relief; - h = h2 + 6 + font->ascent + font->descent; - - switch (primary){ - case LEFT: - case RIGHT: - if (secondary == BOTTOM) - y = icon_win_height - (n / Lines + 1)*(h + interval); - else if (secondary == TOP) - y = (n / Lines)*(h + interval) + interval; - - if (primary == LEFT) - x = (n % Lines)*(w + interval) + interval; - else - x = icon_win_width - (n % Lines + 1)*(w + interval); - break; - case TOP: - case BOTTOM: - if (secondary == RIGHT) - x = icon_win_width - (n / Lines + 1)*(w + interval); - else if (secondary == LEFT) - x = (n / Lines)*(w + interval) + interval; - - if (primary == TOP) - y = (n % Lines)*(h + interval) + interval; - else - y = icon_win_height - (n % Lines + 1)*(h + interval); - break; - default: - break; - } - - item->x = x; - item->y = y; - - if (item->icon_w > 0 && item->icon_h > 0){ - w3 = min(max_icon_width, item->icon_w) + icon_relief; - h3 = min(max_icon_height, item->icon_h) + icon_relief; - } - if (max_icon_height != 0) - XMoveResizeWindow(dpy, item->icon_pixmap_w, x + (w - w3)/2, - y + (h2 - h3)/2,w3,h3); - XMoveResizeWindow(dpy, item->IconWin, x,y + h2,w,h - h2); + int x = 0, y = 0, w, h, h2, h3, w3; + + w3 = w = max_icon_width + icon_relief; + h3 = h2 = max_icon_height + icon_relief; + h = h2 + 6 + font->ascent + font->descent; + + switch (primary) { + case LEFT: + case RIGHT: + if (secondary == BOTTOM) + y = icon_win_height - (n / Lines + 1) * (h + interval); + else if (secondary == TOP) + y = (n / Lines) * (h + interval) + interval; + + if (primary == LEFT) + x = (n % Lines) * (w + interval) + interval; + else + x = icon_win_width - (n % Lines + 1) * (w + interval); + break; + case TOP: + case BOTTOM: + if (secondary == RIGHT) + x = icon_win_width - (n / Lines + 1) * (w + interval); + else if (secondary == LEFT) + x = (n / Lines) * (w + interval) + interval; + + if (primary == TOP) + y = (n % Lines) * (h + interval) + interval; + else + y = icon_win_height - (n % Lines + 1) * (h + interval); + break; + default: + break; + } + + item->x = x; + item->y = y; + + if (item->icon_w > 0 && item->icon_h > 0) { + w3 = min(max_icon_width, item->icon_w) + icon_relief; + h3 = min(max_icon_height, item->icon_h) + icon_relief; + } + if (max_icon_height != 0) + XMoveResizeWindow(dpy, item->icon_pixmap_w, x + (w - w3) / 2, + y + (h2 - h3) / 2, w3, h3); + XMoveResizeWindow(dpy, item->IconWin, x, y + h2, w, h - h2); } /*************************************************************************** @@ -200,215 +194,215 @@ void AdjustIconWindow(struct icon_info *item, int n) * Looks for a monochrome icon bitmap file * **************************************************************************/ -void GetBitmapFile(struct icon_info *item) +void +GetBitmapFile(struct icon_info *item) { - char *path = NULL; - int HotX,HotY; - - path = findIconFile(item->icon_file, iconPath,R_OK); - if(path == NULL)return; - - if(XReadBitmapFile (dpy, Root,path,(unsigned int *)&item->icon_w, - (unsigned int *)&item->icon_h, - &item->iconPixmap, - (int *)&HotX, - (int *)&HotY) != BitmapSuccess) - { - item->icon_w = 0; - item->icon_h = 0; - } - else - item->icon_depth = 1; - - item->icon_w = min(max_icon_width, item->icon_w); - item->icon_h = min(max_icon_height, item->icon_h); - item->icon_maskPixmap = None; - free(path); + char *path = NULL; + int HotX, HotY; + + path = findIconFile(item->icon_file, iconPath, R_OK); + if (path == NULL) + return; + + if (XReadBitmapFile(dpy, Root, path, (unsigned int *)&item->icon_w, + (unsigned int *)&item->icon_h, &item->iconPixmap, (int *)&HotX, + (int *)&HotY) != BitmapSuccess) { + item->icon_w = 0; + item->icon_h = 0; + } else + item->icon_depth = 1; + + item->icon_w = min(max_icon_width, item->icon_w); + item->icon_h = min(max_icon_height, item->icon_h); + item->icon_maskPixmap = None; + free(path); } - /**************************************************************************** * * Looks for a color XPM icon file * ****************************************************************************/ -void GetXPMFile(struct icon_info *item) +void +GetXPMFile(struct icon_info *item) { #ifdef XPM - XWindowAttributes root_attr; - XpmAttributes xpm_attributes; - char *path = NULL; - int rc; - XpmImage my_image; - - path = findIconFile(item->icon_file, pixmapPath,R_OK); - if(path == NULL)return; - - XGetWindowAttributes(dpy,Root,&root_attr); - xpm_attributes.colormap = root_attr.colormap; - xpm_attributes.closeness = 40000; /* same closeness used elsewhere */ - xpm_attributes.valuemask = XpmSize|XpmReturnPixels|XpmColormap|XpmCloseness; - rc = XpmReadFileToXpmImage(path, &my_image, NULL); - if (rc != XpmSuccess) { - fprintf(stderr, "Problem reading pixmap %s, rc %d\n", path, rc); - free(path); - return; - } - color_reduce_pixmap(&my_image,save_color_limit); - rc = XpmCreatePixmapFromXpmImage(dpy,Root, &my_image, - &item->iconPixmap, - &item->icon_maskPixmap, - &xpm_attributes); - if (rc != XpmSuccess) { - fprintf(stderr, "Problem creating pixmap from image, rc %d\n", rc); - free(path); - return; - } - item->icon_w = min(max_icon_width, my_image.width); - item->icon_h = min(max_icon_height, my_image.height); - item->icon_depth = d_depth; - free(path); + XWindowAttributes root_attr; + XpmAttributes xpm_attributes; + char *path = NULL; + int rc; + XpmImage my_image; + + path = findIconFile(item->icon_file, pixmapPath, R_OK); + if (path == NULL) + return; + + XGetWindowAttributes(dpy, Root, &root_attr); + xpm_attributes.colormap = root_attr.colormap; + xpm_attributes.closeness = 40000; /* same closeness used elsewhere */ + xpm_attributes.valuemask = + XpmSize | XpmReturnPixels | XpmColormap | XpmCloseness; + rc = XpmReadFileToXpmImage(path, &my_image, NULL); + if (rc != XpmSuccess) { + fprintf(stderr, "Problem reading pixmap %s, rc %d\n", path, rc); + free(path); + return; + } + color_reduce_pixmap(&my_image, save_color_limit); + rc = XpmCreatePixmapFromXpmImage(dpy, Root, &my_image, + &item->iconPixmap, &item->icon_maskPixmap, &xpm_attributes); + if (rc != XpmSuccess) { + fprintf( + stderr, "Problem creating pixmap from image, rc %d\n", rc); + free(path); + return; + } + item->icon_w = min(max_icon_width, my_image.width); + item->icon_h = min(max_icon_height, my_image.height); + item->icon_depth = d_depth; + free(path); #endif /* XPM */ } /*************************************************************************** -* + * * * Looks for an application supplied icon window * *************************************************************************** -*/ -void GetIconWindow(struct icon_info *item) + */ +void +GetIconWindow(struct icon_info *item) { - int x, y; - unsigned int bw; - Window Junkroot; + int x, y; + unsigned int bw; + Window Junkroot; - if(!XGetGeometry(dpy, item->wmhints->icon_window, &Junkroot, - &x, &y, (unsigned int *)&item->icon_w, - (unsigned int *)&item->icon_h, - &bw, (unsigned int *)&item->icon_depth)) - return; + if (!XGetGeometry(dpy, item->wmhints->icon_window, &Junkroot, &x, &y, + (unsigned int *)&item->icon_w, (unsigned int *)&item->icon_h, + &bw, (unsigned int *)&item->icon_depth)) + return; - XDestroyWindow(dpy, item->icon_pixmap_w); - item->icon_pixmap_w = item->wmhints->icon_window; + XDestroyWindow(dpy, item->icon_pixmap_w); + item->icon_pixmap_w = item->wmhints->icon_window; #ifdef SHAPE - if (item->wmhints->flags & IconMaskHint) - { - item->flags |= SHAPED_ICON; - item->icon_maskPixmap = item->wmhints->icon_mask; - } + if (item->wmhints->flags & IconMaskHint) { + item->flags |= SHAPED_ICON; + item->icon_maskPixmap = item->wmhints->icon_mask; + } #endif - item->icon_w = min(max_icon_width + icon_relief, item->icon_w); - item->icon_h = min(max_icon_height + icon_relief, item->icon_h); + item->icon_w = min(max_icon_width + icon_relief, item->icon_w); + item->icon_h = min(max_icon_height + icon_relief, item->icon_h); - XReparentWindow(dpy, item->icon_pixmap_w, icon_win, 0, 0); - XSetWindowBorderWidth(dpy, item->icon_pixmap_w, 0); - item->flags &= ~ICON_OURS; + XReparentWindow(dpy, item->icon_pixmap_w, icon_win, 0, 0); + XSetWindowBorderWidth(dpy, item->icon_pixmap_w, 0); + item->flags &= ~ICON_OURS; } /*************************************************************************** -* + * * * Looks for an application supplied bitmap or pixmap * *************************************************************************** -*/ -void GetIconBitmap(struct icon_info *item) + */ +void +GetIconBitmap(struct icon_info *item) { - int x, y; - unsigned int bw, depth; - Window Junkroot; - GC gc; - - if (!XGetGeometry(dpy, item->wmhints->icon_pixmap, &Junkroot, &x, &y, - (unsigned int *)&item->icon_w, - (unsigned int *)&item->icon_h, &bw, &depth)) - return; - - item->icon_depth = depth; - item->icon_file = NULL; - item->icon_maskPixmap = None; + int x, y; + unsigned int bw, depth; + Window Junkroot; + GC gc; + + if (!XGetGeometry(dpy, item->wmhints->icon_pixmap, &Junkroot, &x, &y, + (unsigned int *)&item->icon_w, (unsigned int *)&item->icon_h, + &bw, &depth)) + return; + + item->icon_depth = depth; + item->icon_file = NULL; + item->icon_maskPixmap = None; #ifdef SHAPE - if (item->wmhints->flags & IconMaskHint) - { - item->flags |= SHAPED_ICON; - item->icon_maskPixmap = item->wmhints->icon_mask; - } + if (item->wmhints->flags & IconMaskHint) { + item->flags |= SHAPED_ICON; + item->icon_maskPixmap = item->wmhints->icon_mask; + } #endif - item->icon_w = min(max_icon_width, item->icon_w); - item->icon_h = min(max_icon_height, item->icon_h); + item->icon_w = min(max_icon_width, item->icon_w); + item->icon_h = min(max_icon_height, item->icon_h); - item->iconPixmap = XCreatePixmap(dpy, Root, item->icon_w, - item->icon_h, depth); - gc = XCreateGC(dpy, item->iconPixmap, 0, NULL); - XCopyArea(dpy, item->wmhints->icon_pixmap, item->iconPixmap, - gc, 0, 0, item->icon_w, item->icon_h, 0, 0); - XFreeGC(dpy, gc); + item->iconPixmap = + XCreatePixmap(dpy, Root, item->icon_w, item->icon_h, depth); + gc = XCreateGC(dpy, item->iconPixmap, 0, NULL); + XCopyArea(dpy, item->wmhints->icon_pixmap, item->iconPixmap, gc, 0, 0, + item->icon_w, item->icon_h, 0, 0); + XFreeGC(dpy, gc); } -Bool GetBackPixmap(void) +Bool +GetBackPixmap(void) { - XWindowAttributes root_attr; + XWindowAttributes root_attr; #ifdef XPM - XpmAttributes xpm_attributes; - XpmImage my_image; + XpmAttributes xpm_attributes; + XpmImage my_image; #endif - char *path = NULL; - Pixmap tmp_bitmap, maskPixmap; - int x, y, w=0, h=0, rc; - - if (IconwinPixmapFile == NULL) - return False; - - if ((path = findIconFile(IconwinPixmapFile, iconPath,R_OK)) != NULL){ - if (XReadBitmapFile(dpy, Root,path,(unsigned int *)&w, - (unsigned int *)&h, &tmp_bitmap, - (int *)&x, (int *)&y)!= BitmapSuccess) - w = h = 0; - else{ - IconwinPixmap = XCreatePixmap(dpy, Root, w, h, d_depth); - XCopyPlane(dpy, tmp_bitmap, IconwinPixmap, NormalGC, 0, 0, w, h, - 0, 0, 1); - XFreePixmap(dpy, tmp_bitmap); - } - free(path); - } - + char *path = NULL; + Pixmap tmp_bitmap, maskPixmap; + int x, y, w = 0, h = 0, rc; + + if (IconwinPixmapFile == NULL) + return False; + + if ((path = findIconFile(IconwinPixmapFile, iconPath, R_OK)) != NULL) { + if (XReadBitmapFile(dpy, Root, path, (unsigned int *)&w, + (unsigned int *)&h, &tmp_bitmap, (int *)&x, + (int *)&y) != BitmapSuccess) + w = h = 0; + else { + IconwinPixmap = XCreatePixmap(dpy, Root, w, h, d_depth); + XCopyPlane(dpy, tmp_bitmap, IconwinPixmap, NormalGC, 0, + 0, w, h, 0, 0, 1); + XFreePixmap(dpy, tmp_bitmap); + } + free(path); + } + #ifdef XPM - if ( w == 0 && h == 0 && (path = findIconFile(IconwinPixmapFile, - pixmapPath,R_OK)) != NULL) - { - XGetWindowAttributes(dpy,Root,&root_attr); - xpm_attributes.colormap = root_attr.colormap; - xpm_attributes.closeness = 40000; /* same closeness used elsewhere */ - xpm_attributes.valuemask = XpmSize|XpmReturnPixels|XpmColormap| - XpmCloseness; - rc = XpmReadFileToXpmImage(path, &my_image, NULL); - if (rc != XpmSuccess) { - fprintf(stderr, "Problem reading pixmap %s, rc %d\n", path, rc); - free(path); - return False; - } - color_reduce_pixmap(&my_image,save_color_limit); - rc = XpmCreatePixmapFromXpmImage(dpy,Root, &my_image, - &IconwinPixmap, - &maskPixmap, - &xpm_attributes); - if (rc != XpmSuccess) { - fprintf(stderr, "Problem creating pixmap from image, rc %d\n", rc); - free(path); - return False; - } - w = my_image.width; - h = my_image.height; - free(path); - } + if (w == 0 && h == 0 && + (path = findIconFile(IconwinPixmapFile, pixmapPath, R_OK)) != + NULL) { + XGetWindowAttributes(dpy, Root, &root_attr); + xpm_attributes.colormap = root_attr.colormap; + xpm_attributes.closeness = + 40000; /* same closeness used elsewhere */ + xpm_attributes.valuemask = + XpmSize | XpmReturnPixels | XpmColormap | XpmCloseness; + rc = XpmReadFileToXpmImage(path, &my_image, NULL); + if (rc != XpmSuccess) { + fprintf(stderr, "Problem reading pixmap %s, rc %d\n", + path, rc); + free(path); + return False; + } + color_reduce_pixmap(&my_image, save_color_limit); + rc = XpmCreatePixmapFromXpmImage(dpy, Root, &my_image, + &IconwinPixmap, &maskPixmap, &xpm_attributes); + if (rc != XpmSuccess) { + fprintf(stderr, + "Problem creating pixmap from image, rc %d\n", rc); + free(path); + return False; + } + w = my_image.width; + h = my_image.height; + free(path); + } #endif - if (w != 0 && h != 0) - return True; - return False; + if (w != 0 && h != 0) + return True; + return False; } Index: fvwm/modules/FvwmIconMan/FvwmIconMan.1 =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIconMan/FvwmIconMan.1,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIconMan/FvwmIconMan.1 --- fvwm/modules/FvwmIconMan/FvwmIconMan.1 +++ fvwm/modules/FvwmIconMan/FvwmIconMan.1 @@ -1,6 +1,6 @@ .\" $OpenBSD: FvwmIconMan.1,v 1.1.1.1 2006/11/26 10:53:49 matthieu Exp $ .\" t -.\" @(#)FvwmIconMan.1 6/17/1998 +.\" @(#)FvwmIconMan.1 6/17/1998 .de EX \"Begin example .ne 5 .if n .sp 1 @@ -14,15 +14,14 @@ .if n .sp 1 .if t .sp .5 .. -.TH FvwmIconMan 1 "June 17, 1998" 1.3 +.TH FVWMICONMAN 1 "June 17, 1998" "1.3" "FVWM Modules" .UC .SH NAME FvwmIconMan \- an Fvwm Icon Manager .SH SYNOPSIS FvwmIconMan is spawned by fvwm, so no command line invocation will work. - .SH DESCRIPTION -FvwmIconMan is an icon manager modeled after the TWM icon manager. The user +FvwmIconMan is an icon manager modeled after the TWM icon manager. The user may have multiple icon managers, each of which armed with a list of window types which it manages. For example, the user may have one manager which lists only emacs windows, and another which lists everything else. You may also @@ -35,16 +34,15 @@ maximum number of rows (and then grows horizontally), or stay at a fixed size, and adjust the size of the window buttons to fit (think win95's Taskbar). And when support is compiled in for the X Shape extension, then the manager windows may be shaped. - +.PP You can specify actions to be run when mouse, or key events are received. For example, you could bind the first mouse button to iconify the selected window, and make bindings for the arrow keys to navigate the manager window without the mouse. - +.PP FvwmIconMan can be set to display which window currently has the keyboard focus, and by binding the select event (see below) to the fvwm Focus function, you can emulate the TWM icon manager's behavior. - .SH INITIALIZATION During initialization, FvwmIconMan searches though the fvwm configuration file for the options which are described below. It is highly recommended that you @@ -52,34 +50,34 @@ make FvwmIconMan be a sticky window. And if you want to make use of the followfocus option, and/or binding an action to Focus, then you should make FvwmIconMan clicktofocus. Also, when using the Shape option, it's recommended that the FvwmIconMan window not be decorated at all by fvwm. - .SH INVOCATION -FvwmIconMan can be invoked by inserting the line 'Module FvwmIconMan' in the .fvwmrc file. If FvwmIconMan is to be spawned during fvwm's initialization, +FvwmIconMan can be invoked by inserting the line 'Module FvwmIconMan' in the +\&.fvwmrc file. +If FvwmIconMan is to be spawned during fvwm's initialization, then this line should be placed in the InitFunction and ResetFunction declarations, or it can be bound to a menu, mouse button, or keystroke to invoke it later. FvwmIconMan should be placed in the ModulePath (defined in the .fvwmrc file) in order for fvwm to find it. - +.PP If you wish to run FvwmIconMan in a transient mode, such as with the built in -window list, then pass Transient as an argument. The invocation "Module -FvwmIconMan Transient" will do nicely. In this mode, FvwmIconMan will pop up -one manager window directly under the cursor. When the mouse button is -released, it will execute the appropriate action, and then exit. Things are -somewhat complicated by the fact that you can specify that FvwmIconMan create -multiple manager windows, behavior which is unsuitable when running -transiently. So, when running transiently, FvwmIconMan will only create one -manager window. Use the manager id 'transient' to specify options for this -manager window. - +window list, then pass Transient as an argument. +The invocation "Module FvwmIconMan Transient" will do nicely. +In this mode, FvwmIconMan will pop up one manager window directly under the +cursor. +When the mouse button is released, it will execute the appropriate action, and +then exit. +Things are somewhat complicated by the fact that you can specify that +FvwmIconMan create multiple manager windows, behavior which is unsuitable when +running transiently. +So, when running transiently, FvwmIconMan will only create one manager window. +Use the manager id 'transient' to specify options for this manager window. .SH CONFIGURATION OPTIONS REFERENCE CHART FvwmIconMan has acquired quite a few options. I assume others share my dislike of paging though a long manpage, so here is a terse reference chart describing the available options. They are described in more detail in the next section. - -.ft C \" Courier +.PP .nf Name Description Default -.ft P action binds command to event Mouse 0 N sendcommand Iconify background default background gray @@ -106,13 +104,11 @@ titlebutton style for title button raisededge black grey usewinlist honor WinListSkip? true .fi - .SH CONFIGURATION OPTIONS With the exception of the nummanagers option, all of the options may be defined on a per-manager basis. So, for example, the user may have his emacs manager with a red foreground, and his xterm manager with a blue one. A configuration line may therefore have one of two forms: - .IP "*FvwmIconMan*optionname optionvalue" To specify that the \fIoptionname\fP takes the value \fIoptionvalue\fP for all managers. @@ -122,61 +118,49 @@ for manager \fImanagerid\fP. \fIMangerid\fP may either be a positive integer, or the string "transient". An integral id refers to managers which FvwmIconMan creates when running normally, and an id of "transient" refers to the single manager which FvwmIconMan creates when running transiently. - -.PP The following options may be specified: - .IP "*FvwmIconMan*nummanagers \fInum\fP" \fInum\fP is a positive integer specifying the total number of icon managers. Since FvwmIconMan would like to know how many managers there are before handling any manager specific options, this should come first. The default is 1. - .IP "*FvwmIconMan*[id*]action \fItype\fP \fIbinding\fP" Binds an FvwmIconMan command to an event. \fIType\fP may be one of the values: Key, Mouse, or Select. Actions are described in the following section ACTIONS. - .IP "*FvwmIconMan*[id*]background \fIbackground\fP" Specifies the default background color. - .IP "*FvwmIconMan*[id*]buttongeometry \fIgeometry\fP" Specifies the initial geometry of an individual button in pixels. If the specified height is 0, then the button height is determined from the font size. X and Y coordinates are ignored. - .IP "*FvwmIconMan*[id*]drawicons \fIvalue\fP" If your version of fvwm2 is capable of using MiniIcons, then this option determines if FvwmIconMan displays the MiniIcons. Otherwise, it generates an error message. "true" means that MiniIcons are shown for iconified windows, "false" that MiniIcons are never shown, and "always" that MiniIcons are shown for all windows. - -.IP "*FvwmIconMan*[id*]focusbutton \fIstyle\fP [\fIforecolor\fP \fIbackcolor\fP]" +.IP "*FvwmIconMan*[id*]focusbutton \fIstyle\fP" +Optional \fIforecolor\fP and \fIbackcolor\fP values may follow. Same as the plainbutton option, but specifies the look of buttons whose windows have the keyboard focus. - -.IP "*FvwmIconMan*[id*]focusandselectbutton \fIstyle\fP [\fIforecolor\fP \fIbackcolor\fP]" +.IP "*FvwmIconMan*[id*]focusandselectbutton \fIstyle\fP" +Optional \fIforecolor\fP and \fIbackcolor\fP values may follow. Same as the plainbutton option, but specifies the look of buttons which are both selected, and have the keyboard focus. - .IP "*FvwmIconMan*[id*]font \fIfont\fP" Specifies the font to be used for labeling the buttons. The default is 8x13. - .IP "*FvwmIconMan*[id*]foreground \fIforeground\fP" Specifies the default foreground color. - .IP "*FvwmIconMan*[id*]format \fIformatstring\fP" A printf like format string which describes the string to be printed in the manager window for each managed window. Possible flags are: %t, %i, %c, and %r for the window's title, icon, class, or resource name, respectively. The default is "%c: %i". \fBWarning\fP: m4 reserves the word \fIformat\fP, so if you use m4, take appropriate action. - .IP "*FvwmIconMan*[id*]iconname \fIiconstring\fP" Specifies the window icon name for that manager window. \fIIconstring\fP may either be a single word, or a string enclosed in quotes. The default is "FvwmIconMan". - .IP "*FvwmIconMan*[id*]managergeometry \fIgeometry\fP" Specifies the initial geometry of the manager, in units of buttons. If \fIheight\fP is 0, then the manager will use \fIwidth\fP columns, and will @@ -186,14 +170,13 @@ both are nonzero, then the manager window will be exactly that size, and stay that way. As columns are created, the buttons will narrow to accommodate. If the geometry is specified with a negative y coordinate, then the window manager will grow upwards. Otherwise, it will grow downwards. - -.IP "*FvwmIconMan*[id*]plainbutton \fIstyle\fP [\fIforecolor\fP \fIbackcolor\fP]" +.IP "*FvwmIconMan*[id*]plainbutton \fIstyle\fP" +Optional \fIforecolor\fP and \fIbackcolor\fP values may follow. Specifies how normal buttons look. \fIstyle\fP may be one of \fIflat\fP, \fIup\fP, \fIdown\fP, \fIraisededge\fP, or \fIsunkedge\fP, and describes how the button is drawn. The color options are both optional, and if not set, then the default colors are used. If on a monochrome screen, then the \fIstyle\fP option is ignored, but must still be set. - .IP "*FvwmIconMan*[id*]resolution \fIresolution\fP" Specifies when the manager will display an entry for a certain window. \fIresolution\fP may take one of the following values: global, desk, @@ -201,30 +184,27 @@ or page. If global, then all windows of the appropriate type (see the show and dontshow options below) will be shown. If desk, then only those windows on the current desk will be down. And if page, then only those windows on the current page will be shown. The default is global. - -.IP "*FvwmIconMan*[id*]selectbutton \fIstyle\fP [\fIforecolor\fP \fIbackcolor\fP]" +.IP "*FvwmIconMan*[id*]selectbutton \fIstyle\fP" +Optional \fIforecolor\fP and \fIbackcolor\fP values may follow. Same as the plainbutton option, but specifies the look of buttons when the mouse is over them. - .IP "*FvwmIconMan*[id*]shape \fIboolean\fP" -If \fITrue\fP, then use make the window shaped. Probably only useful if you +If \fITrue\fP, then make the window shaped. Probably only useful if you have multiple columns or rows. If FvwmIconMan wasn't compiled to support the Shape extension, this generates an error message. When using shaped windows, it's recommended that a fvwm style is made for FvwmIconMan that has no borders. Otherwise, fvwm will get confused. - .IP "*FvwmIconMan*[id*]title \fItitlestring\fP" Specifies the window title string for that manager window. \fITitlestring\fP may either be a single word, or a string enclosed in quotes. The default is "FvwmIconMan". This will be drawn in the titlebar of the manager window, if any, and in the title button, which is the button drawn when the manager is empty. - -.IP "*FvwmIconMan*[id*]titlebutton \fIstyle\fP [\fIforecolor\fP \fIbackcolor\fP]" +.IP "*FvwmIconMan*[id*]titlebutton \fIstyle\fP" +Optional \fIforecolor\fP and \fIbackcolor\fP values may follow. Same as the plainbutton option, but specifies the look of the title button (the button drawn when the manager is empty). The manager's title is drawn in the title button. - .PP The two following options control which windows get handled by which managers. A manager can get two lists, one of windows to show, and one of @@ -240,35 +220,29 @@ the same format used in the fvwm style command (minimalistic shell pattern matching). Quotes around the pattern will be taken as part of the expression. If a window could be handled by more than one manager, then the manager with the lowest id gets it. - .IP "*FvwmIconMan*[id*]show \fIpattern list\fP" If a window matches one of the patterns in the list, then it may be handled by this manager. - .IP "*FvwmIconMan*[id*]dontshow \fIpattern list\fP" If a window matches one of the patterns in the list, then it may not be handled by this manager. - .IP "*FvwmIconMan*[id*]usewinlist \fIboolean\fP" If \fItrue\fP, then honor the WinListSkip style flag. Otherwise, all windows are subject to possible management according to the show and dontshow lists. - .IP "*FvwmIconMan*[id*]followfocus \fIboolean\fP" If \fItrue\fP, then the button appearance reflects which window currently has focus. Default is false. - .IP "*FvwmIconMan*[id*]sort \fIvalue\fP" If \fIname\fP, then the manager list is sorted by name. If \fInamewithcase\fP, then it is sorted by name sensitive to case. If \fIid\fP, then the manager list is sorted by the window id, which never changes after the window is created. Or it can be set to \fInone\fP, which results in no sorting. Default is \fIname\fP. - .SH ACTIONS Actions are commands which may be bound to an event of the type: a keypress, a mouse click, or the mouse entering a window manager button - denoted by the action types \fIKey\fP, \fIMouse\fP, and \fISelect\fP. - +.PP Normally, actions bound to a mouse click are executed when the button is pressed. In transient mode, the action is executed when the button is released, since it is assumed that FvwmIconMan was bound to some mouse @@ -277,39 +251,35 @@ any modifier keys in this case, so if you bind FvwmIconMan to say, meta-button3, then it would be wise to ensure that the action you want to execute will be executed when the meta-button3 event occurs (which would be the button release, assuming you kept your finger on the meta key). - +.PP The syntax for actions are: - .IP "\fBKey actions\fP: Key \fIKeysym\fP \fIModifiers\fP \fIFunctionList\fP" \fIKeysym\fP and \fIModifiers\fP are exactly the same as for the fvwm \fIKey\fP command. - .IP "\fBMouse actions\fP: Mouse \fIButton\fP \fIModifiers\fP \fIFunctionList\fP" \fIButton\fP and \fIModifiers\fP are exactly the same as for the fvwm \fIMouse\fP command. - .IP "\fBSelect actions\fP: Select \fIFunctionList\fP" - .PP A \fIFunctionList\fP is a sequence of commands separated by commas. They are executed in left to right order, in one shared context - which currently only contains a pointer to the "current" button. If a button is selected (typically by the mouse pointer sitting on it) when the action is executed, then the current button is initialized to that button. Otherwise, it points to nothing. - +.PP Most of the available commands then modify this "current" button, either by moving it around, making it become the selected button, or sending commands to fvwm acting on the window represented by that button. Note that while this current button is initialized to be the selected button, the selected button does not implicitly follow it around. This way, the user can send commands to various windows, without changing which button is selected. - +.PP Commands take five types of arguments: \fIInteger\fP, \fIManager\fP, \fIWindow\fP, \fIButton\fP, and \fIString\fP. A \fIString\fP is a string specified exactly as for fvwm - either in quotes or as a single word not in quotes. Again, you may bind a sequence of commands to an event, by listing them separated by commas. - +.PP \fIWindow\fP and \fIButton\fP types look exactly the same in the .fvwmrc file, but are interpreted as either specifying a managed window, or a FvwmIconMan button representing a window. They can either be an integer (which @@ -325,11 +295,11 @@ manager after or before the current button, allowing navigation of the one dimensional list of windows which is drawn in the manager window. If the manager is sorted, \fINext\fP and \fIPrev\fP move through the windows in the sorted order. - +.PP The \fIManager\fP type can either be an integer, \fINext\fP, or \fIPrev\fP. The meaning is analogous to that of the \fIButton\fP type, but in terms of the integral index of the managers, restricted to managers which are nonempty. - +.PP The following functions are currently defined: .IP "bif \fIButton\fP \fIInteger/String\fP" A relative branch instruction. If \fIButton\fP is \fISelect\fP or \fIFocus\fP, @@ -339,53 +309,41 @@ then take the branch if there is a selected button or a focused button. If taken when the current button can move in that direction. If the branch is taken, then \fIInteger\fP commands are skipped. No backwards branches are allowed. - .IP "bifn \fIButton\fP \fIInteger/String\fP" The complement of bif. The branch is taken if \fIButton\fP evaluates to false, by the criteria listed for bif. - .IP "gotobutton \fIButton\fP" Sets current button to \fIButton\fP. If \fIButton\fP is an integer, then the current button is set to \fIButton\fP modulo the number of buttons, in the whichever manager contains the selected button, if any. - .IP "gotomanager \fIManager\fP" Sets button to button 0 of \fIManager\fP. This will only go to a visible, nonempty manager. So an integral argument is taken modulo the number of such managers. - .IP "jmp \fIInteger/String\fP" Executes a relative jump of \fIInteger\fP instructions. Backwards jumps are not allowed. The jump is computed relative to the instruction following the jmp. - .IP "label \fIString\fP" Provides a label that previous instructions can jump to. It will not be visible to subsequent jump instructions, and the same label can be used multiple times in the same instruction list (though it would be perverse to do so.) - .IP "print \fIString\fP" Prints \fIString\fP to the console. Useful for debugging actions. - .IP "quit" Quits FvwmIconMan. - .IP "ret" Stop executing the entire action. - .IP "select" Selects the current button, if any. If a select action has been specified, it will then be run. Therefore, it is considered unwise to set the select button in the select action. - .IP "sendcommand \fICommand\fP" Sends the fvwm command \fICommand\fP to the window represented by the current button, if any. - .IP "warp" Warps cursor to current button, if any. - .PP .B Examples: .EX @@ -394,63 +352,55 @@ gotobutton select, gotobutton Down, select Selects the button below the currently selected button. Since the current button is already initialized to the selected button, this may be shortened to "gotobutton Down , select". - .EX gotobutton Up, select .EE Selects the button above the currently selected button. - .EX gotobutton 0, select .EE Selects the first button of the current manager. If there is no current manager, which is the case when no button is selected, then this does nothing. - .EX gotobutton -1, select .EE Selects the last button of the current manager. - .EX gotobutton focus, select .EE Selects the button corresponding to the focused window. - .EX gotobutton focus, Iconify .EE Sends the fvwm command Iconify to the focused window. Note that this does not change the selected button. - .EX bif Next 3, gotobutton 0, select, ret, gotobutton Next, select .EE If a button is selected, and it's the last button, go to button 0. If it's not the last button, go to the next button. Otherwise, do nothing. Basically, this action cycles through all buttons in the current manager. - .EX -bif select 7, bif focus 3, gotomanager 0, select, ret, gotobutton focus, select, ret, gotobutton down, select +bif select 7, bif focus 3, gotomanager 0, select, ret, +gotobutton focus, select, ret, gotobutton down, select .EE This is good for sending to FvwmIconMan with a SendToModule command. If there is a selected button, it moves down. Otherwise, if there is a focused button, it is selected. Otherwise, button 0 of manager 0 gets selected. - .EX -bif select Select, bif focus Focus, gotomanager 0, select, ret, label Focus, gotobutton focus, select, ret, label Select, gotobutton down, select +bif select Select, bif focus Focus, gotomanager 0, select, ret, +label Focus, gotobutton focus, select, ret, label Select, +gotobutton down, select .EE Same as previous, but using the label instruction. - .PP In addition to being bound to keys and mice, actions can be sent from fvwm to FvwmIconMan via the SendToModule command. Don't quote the command when using SendToModule. Also, due to a bug in the current version of fvwm2, don't quote FvwmIconMan either. - .SH SAMPLE CONFIGURATIONS This first example is of a the simplest invocation of FvwmIconMan, which only has one manager, and handles all windows: - .nf .sp XCOMM############################################################## @@ -477,22 +427,26 @@ XCOMM Definitions used by the modules *FvwmIconMan*managergeometry 1x0-0+0 .sp .fi - This example is the Reader's Digest version of my personal configuration. It has two managers, one for emacs and one for everything else, minus things with no icon title. Only windows on the current page are displayed. The use of the \fIdrawicons\fP and \fIshape\fP options requires that fvwm and FvwmIconMan we compiled with the correct options. Note how the geometry and show options are specified per manager, and the others are common to all: - .nf .sp Style "FvwmIconMan" NoTitle, Sticky, WindowListSkip, BorderWidth 0 Style "FvwmIconMan" HandleWidth 0 -Key F8 A N SendToModule FvwmIconMan bif select Select, bif focus Focus, gotomanager 0, select, sendcommand WarpToWindow, ret, label Focus, gotobutton focus, select, sendcommand WarpToWindow, ret, label Select, gotobutton prev, select, sendcommand WarpToWindow -Key F9 A N SendToModule FvwmIconMan bif select Select, bif focus Focus, gotomanager 0, select, sendcommand WarpToWindow, ret, label Focus, gotobutton focus, select, sendcommand WarpToWindow, ret, label Select, gotobutton next, select, sendcommand WarpToWindow +Key F8 A N SendToModule FvwmIconMan bif select Select, bif focus Focus,\c + gotomanager 0, select, sendcommand WarpToWindow, ret, label Focus,\c + gotobutton focus, select, sendcommand WarpToWindow, ret, label Select,\c + gotobutton prev, select, sendcommand WarpToWindow +Key F9 A N SendToModule FvwmIconMan bif select Select, bif focus Focus,\c + gotomanager 0, select, sendcommand WarpToWindow, ret, label Focus,\c + gotobutton focus, select, sendcommand WarpToWindow, ret, label Select,\c + gotobutton next, select, sendcommand WarpToWindow *FvwmIconMan*numManagers 2 *FvwmIconMan*Resolution page @@ -501,9 +455,9 @@ Key F9 A N SendToModule FvwmIconMan bif select Select, bif focus Focus, gotomana *FvwmIconMan*font 7x13 *FvwmIconMan*usewinlist true *FvwmIconMan*drawicons true -*FvwmIconMan*shape true +*FvwmIconMan*shape true *FvwmIconMan*followfocus true -*FvwmIconMan*sort name +*FvwmIconMan*sort name *FvwmIconMan*plainbutton up white steelblue *FvwmIconMan*selectbutton down white steelblue *FvwmIconMan*focusbutton up white brown @@ -528,38 +482,28 @@ Key F9 A N SendToModule FvwmIconMan bif select Select, bif focus Focus, gotomana *FvwmIconMan*transient*dontshow icon=Untitled *FvwmIconMan*transient*action Mouse 0 A sendcommand select select Iconify -*FvwmIconMan*action Mouse 1 N sendcommand Iconify -*FvwmIconMan*action Mouse 2 N sendcommand WarpToWindow -*FvwmIconMan*action Mouse 3 N sendcommand "Module FvwmIdent FvwmIdent" -*FvwmIconMan*action Key Left N gotobutton Left, select -*FvwmIconMan*action Key Right N gotobutton Right, select -*FvwmIconMan*action Key Up N gotobutton Up, select -*FvwmIconMan*action Key Down N gotobutton Down, select -*FvwmIconMan*action Key q N quit +*FvwmIconMan*action Mouse 1 N sendcommand Iconify +*FvwmIconMan*action Mouse 2 N sendcommand WarpToWindow +*FvwmIconMan*action Mouse 3 N sendcommand "Module FvwmIdent FvwmIdent" +*FvwmIconMan*action Key Left N gotobutton Left, select +*FvwmIconMan*action Key Right N gotobutton Right, select +*FvwmIconMan*action Key Up N gotobutton Up, select +*FvwmIconMan*action Key Down N gotobutton Down, select +*FvwmIconMan*action Key q N quit .sp .fi - -.SH UNFINISHED BUSINESS -There is one bug that I know of. A honest to goodness solution to this would -be appreciated. When an icon manager is set to grow upwards or leftwards, on -some machines it may wander occasionally. - -It doesn't handle windows without resource names as gracefully as it should. - .SH AUTHOR Brady Montz (bradym@cs.arizona.edu). - .SH THANKS .nf Thanks to: - David Berson , - Gren Klanderman , - David Goldberg , - Pete Forman , - Neil Moore , - Josh M. Osborne , - Chris Siebenmann , - Bjorn Victor . - + David Berson , + Gren Klanderman , + David Goldberg , + Pete Forman , + Neil Moore , + Josh M. Osborne , + Chris Siebenmann , + Bjorn Victor . for contributing either code or truly keen ideas. Index: fvwm/modules/FvwmIconMan/FvwmIconMan.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIconMan/FvwmIconMan.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIconMan/FvwmIconMan.c --- fvwm/modules/FvwmIconMan/FvwmIconMan.c +++ fvwm/modules/FvwmIconMan/FvwmIconMan.c @@ -3,261 +3,229 @@ * for any purpose. */ -#include -#include -#include -#include #include "FvwmIconMan.h" + +#include +#include +#include +#include +#include + +#include "../../fvwm/module.h" #include "readconfig.h" #include "x.h" #include "xmanager.h" -#include "../../fvwm/module.h" - - static int fd_width; static volatile sig_atomic_t isTerminated = False; static char *IM_VERSION = "1.3"; static char const rcsid[] = - "$Id: FvwmIconMan.c,v 1.1.1.1 2006/11/26 10:53:49 matthieu Exp $"; - + "$Id: FvwmIconMan.c,v 1.1.1.1 2006/11/26 10:53:49 matthieu Exp $"; -static RETSIGTYPE TerminateHandler(int); +static void TerminateHandler(int); -char *copy_string (char **target, char *src) +char * +copy_string(char **target, char *src) { - int len = strlen (src); - ConsoleDebug (CORE, "copy_string: 1: 0x%lx\n", (unsigned long)*target); + int len = strlen(src); + ConsoleDebug(CORE, "copy_string: 1: 0x%lx\n", (unsigned long)*target); - if (*target) - Free (*target); + if (*target) + Free(*target); - ConsoleDebug (CORE, "copy_string: 2\n"); - *target = (char *)safemalloc ((len + 1) * sizeof (char)); - strcpy (*target, src); - ConsoleDebug (CORE, "copy_string: 3\n"); - return *target; + ConsoleDebug(CORE, "copy_string: 2\n"); + *target = (char *)xmalloc((len + 1) * sizeof(char)); + strlcpy(*target, src, len + 1); + ConsoleDebug(CORE, "copy_string: 3\n"); + return *target; } -#ifdef TRACE_MEMUSE - -long MemUsed = 0; - -void Free (void *p) +void +Free(void *p) { - struct malloc_header *head = (struct malloc_header *)p; - - if (p != NULL) { - head--; - if (head->magic != MALLOC_MAGIC) { - fprintf (stderr, "Corrupted memory found in Free\n"); - abort(); - return; - } - if (head->len > MemUsed) { - fprintf (stderr, "Free block too big\n"); - return; - } - MemUsed -= head->len; - free (head); - } + if (p != NULL) + free(p); } -void PrintMemuse (void) -{ - ConsoleDebug (CORE, "Memory used: %d\n", MemUsed); -} - -#else - -void Free (void *p) -{ - if (p != NULL) - free (p); -} - -void PrintMemuse (void) -{ -} - -#endif - - -static RETSIGTYPE +static void TerminateHandler(int sig) { - isTerminated = True; + isTerminated = True; } - -void ShutMeDown (int flag) +void +ShutMeDown(int flag) { - ConsoleDebug (CORE, "Bye Bye\n"); - exit (flag); + ConsoleDebug(CORE, "Bye Bye\n"); + exit(flag); } -void DeadPipe (int nothing) +void +DeadPipe(int nothing) { - ShutMeDown(0); + ShutMeDown(0); } -void SendFvwmPipe (char *message,unsigned long window) +void +SendFvwmPipe(char *message, unsigned long window) { - char *hold,*temp,*temp_msg; - hold=message; - - while(1) { - temp=strchr(hold,','); - if (temp!=NULL) { - temp_msg= (char *)safemalloc(temp-hold+1); - strncpy(temp_msg,hold,(temp-hold)); - temp_msg[(temp-hold)]='\0'; - hold=temp+1; - } else temp_msg=hold; - - SendText(Fvwm_fd, temp_msg, window); - - if(temp_msg!=hold) Free(temp_msg); - else break; - } + char *hold, *temp, *temp_msg; + hold = message; + + sandbox_x11_config("FvwmIconMan"); + + while (1) { + temp = strchr(hold, ','); + if (temp != NULL) { + temp_msg = (char *)xmalloc(temp - hold + 1); + strncpy(temp_msg, hold, (temp - hold)); + temp_msg[(temp - hold)] = '\0'; + hold = temp + 1; + } else + temp_msg = hold; + + SendText(Fvwm_fd, temp_msg, window); + + if (temp_msg != hold) + Free(temp_msg); + else + break; + } } -static void main_loop (void) +static void +main_loop(void) { - fd_set readset, saveset; - - FD_ZERO (&saveset); - FD_SET (Fvwm_fd[1], &saveset); - FD_SET (x_fd, &saveset); - - while( !isTerminated ) { - /* Check the pipes for anything to read, and block if - * there is nothing there yet ... - */ - readset = saveset; - if (select(fd_width,&readset,NULL,NULL,NULL) < 0) { - ConsoleMessage ("Internal error with select: errno=%d\n",errno); - } - else { - - if (FD_ISSET (x_fd, &readset) || XPending (theDisplay)) { - xevent_loop(); - } - if (FD_ISSET(Fvwm_fd[1],&readset)) { - ReadFvwmPipe(); - } - - } - } /* while */ + fd_set readset, saveset; + + FD_ZERO(&saveset); + FD_SET(Fvwm_fd[1], &saveset); + FD_SET(x_fd, &saveset); + + sandbox_x11_config("FvwmIconMan"); + while (!isTerminated) { + /* Check the pipes for anything to read, and block if + * there is nothing there yet ... + */ + readset = saveset; + if (select(fd_width, &readset, NULL, NULL, NULL) < 0) { + ConsoleMessage( + "Internal error with select: errno=%d\n", errno); + } else { + if (FD_ISSET(x_fd, &readset) || XPending(theDisplay)) { + xevent_loop(); + } + if (FD_ISSET(Fvwm_fd[1], &readset)) { + ReadFvwmPipe(); + } + } + } /* while */ } -int main (int argc, char **argv) +int +main(int argc, char **argv) { - char *temp, *s; - int i; + char *temp, *s; + int i; #ifdef ELECTRIC_FENCE - extern int EF_PROTECT_BELOW, EF_PROTECT_FREE; + extern int EF_PROTECT_BELOW, EF_PROTECT_FREE; - EF_PROTECT_BELOW = 1; - EF_PROTECT_FREE = 1; + EF_PROTECT_BELOW = 1; + EF_PROTECT_FREE = 1; #endif #ifdef DEBUG_ATTACH - { - char buf[256]; - sprintf (buf, "%d", getpid()); - if (fork() == 0) { - chdir ("/home/bradym/src/FvwmIconMan"); - execl ("/usr/local/bin/ddd", "/usr/local/bin/ddd", "FvwmIconMan", - buf, NULL); - } - else { - int i, done = 0; - for (i = 0; i < (1 << 27) && !done; i++) ; - } - } + { + char buf[256]; + sprintf(buf, "%d", getpid()); + if (fork() == 0) { + chdir("/home/bradym/src/FvwmIconMan"); + execl("/usr/local/bin/ddd", "/usr/local/bin/ddd", + "FvwmIconMan", buf, NULL); + } else { + int i, done = 0; + for (i = 0; i < (1 << 27) && !done; i++) + ; + } + } #endif - OpenConsole(OUTPUT_FILE); + OpenConsole(OUTPUT_FILE); -#if 0 - ConsoleMessage ("PID = %d\n", getpid()); - ConsoleMessage ("Waiting for GDB to attach\n"); - sleep (10); -#endif + init_globals(); + init_winlists(); - init_globals(); - init_winlists(); + temp = argv[0]; + s = strrchr(argv[0], '/'); + if (s != NULL) + temp = s + 1; - temp = argv[0]; - s = strrchr (argv[0], '/'); - if (s != NULL) - temp = s + 1; + if ((argc != 6) && (argc != 7)) { + fprintf(stderr, + "%s Version %s should only be executed by fvwm!\n", Module, + IM_VERSION); + ShutMeDown(1); + } + if (argc == 7 && !strcasecmp(argv[6], "Transient")) + globals.transient = 1; - if((argc != 6) && (argc != 7)) { - fprintf(stderr,"%s Version %s should only be executed by fvwm!\n",Module, - IM_VERSION); - ShutMeDown (1); - } - if (argc == 7 && !strcasecmp (argv[6], "Transient")) - globals.transient = 1; - - Fvwm_fd[0] = atoi(argv[1]); - Fvwm_fd[1] = atoi(argv[2]); - init_display(); - init_boxes(); + Fvwm_fd[0] = atoi(argv[1]); + Fvwm_fd[1] = atoi(argv[2]); + init_display(); + init_boxes(); #ifdef HAVE_SIGACTION - { - struct sigaction sigact; - - sigemptyset(&sigact.sa_mask); -# ifdef SA_INTERRUPT - sigact.sa_flags = SA_INTERRUPT; -# else - sigact.sa_flags = 0; -# endif - sigact.sa_handler = TerminateHandler; - - sigaction(SIGPIPE, &sigact, NULL); - sigaction(SIGINT, &sigact, NULL); - sigaction(SIGHUP, &sigact, NULL); - sigaction(SIGTERM, &sigact, NULL); - sigaction(SIGQUIT, &sigact, NULL); - } + { + struct sigaction sigact; + + sigemptyset(&sigact.sa_mask); +#ifdef SA_INTERRUPT + sigact.sa_flags = SA_INTERRUPT; +#else + sigact.sa_flags = 0; +#endif + sigact.sa_handler = TerminateHandler; + + sigaction(SIGPIPE, &sigact, NULL); + sigaction(SIGINT, &sigact, NULL); + sigaction(SIGHUP, &sigact, NULL); + sigaction(SIGTERM, &sigact, NULL); + sigaction(SIGQUIT, &sigact, NULL); + } #else - /* We don't have sigaction(), so fall back to less robust methods. */ - signal(SIGPIPE, TerminateHandler); - signal(SIGINT, TerminateHandler); - signal(SIGHUP, TerminateHandler); - signal(SIGTERM, TerminateHandler); - signal(SIGQUIT, TerminateHandler); + /* We don't have sigaction(), so fall back to less robust methods. */ + signal(SIGPIPE, TerminateHandler); + signal(SIGINT, TerminateHandler); + signal(SIGHUP, TerminateHandler); + signal(SIGTERM, TerminateHandler); + signal(SIGQUIT, TerminateHandler); #endif - read_in_resources (argv[3]); + read_in_resources(argv[3]); - for (i = 0; i < globals.num_managers; i++) { - X_init_manager (i); - } + for (i = 0; i < globals.num_managers; i++) { + X_init_manager(i); + } - assert (globals.managers); - fd_width = GetFdWidth(); + assert(globals.managers); + fd_width = GetFdWidth(); - SetMessageMask(Fvwm_fd,M_CONFIGURE_WINDOW | M_RES_CLASS | M_RES_NAME | - M_ADD_WINDOW | M_DESTROY_WINDOW | M_ICON_NAME | - M_DEICONIFY | M_ICONIFY | M_END_WINDOWLIST | - M_NEW_DESK | M_NEW_PAGE | M_FOCUS_CHANGE | M_WINDOW_NAME | + SetMessageMask(Fvwm_fd, M_CONFIGURE_WINDOW | M_RES_CLASS | M_RES_NAME | + M_ADD_WINDOW | M_DESTROY_WINDOW | + M_ICON_NAME | M_DEICONIFY | M_ICONIFY | + M_END_WINDOWLIST | M_NEW_DESK | M_NEW_PAGE | + M_FOCUS_CHANGE | M_WINDOW_NAME | #ifdef MINI_ICONS - M_MINI_ICON | + M_MINI_ICON | #endif - M_STRING); + M_STRING); - SendInfo (Fvwm_fd, "Send_WindowList", 0); + SendInfo(Fvwm_fd, "Send_WindowList", 0); - main_loop(); + main_loop(); - return 0; + return 0; } Index: fvwm/modules/FvwmIconMan/FvwmIconMan.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIconMan/FvwmIconMan.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIconMan/FvwmIconMan.h --- fvwm/modules/FvwmIconMan/FvwmIconMan.h +++ fvwm/modules/FvwmIconMan/FvwmIconMan.h @@ -1,12 +1,14 @@ -#include "config.h" - -#include -#include +#ifndef FVWMICONMAN_H +#define FVWMICONMAN_H #include -#include #include +#include +#include +#include + +#include "config.h" #ifndef FVWM_VERSION #define FVWM_VERSION 2 @@ -28,311 +30,290 @@ #define DEFAULT_ACTION "Iconify" #endif -#define RECTANGLES_INTERSECT(x1,y1,w1,h1,x2,y2,w2,h2) \ - (((x1) + (w1) > (x2) && (x1) < (x2) + (w2)) && \ - ((y1) + (h1) > (y2) && (y1) < (y2) + (h2))) +#define RECTANGLES_INTERSECT(x1, y1, w1, h1, x2, y2, w2, h2) \ + (((x1) + (w1) > (x2) && (x1) < (x2) + (w2)) && \ + ((y1) + (h1) > (y2) && (y1) < (y2) + (h2))) #define MAX_ARGS 3 -#ifdef TRACE_MEMUSE +#define SET_BIT(field, bit) ((field) |= (bit)) +#define CLEAR_BIT(field, bit) ((field) &= ~(bit)) -#define MALLOC_MAGIC 0xdeadbeaf - -#define SET_BIT(field,bit) ((field) |= (bit)) -#define CLEAR_BIT(field,bit) ((field) &= ~(bit)) - -#define SET_BIT_TO_VAL(field,bit,val) ((val) ? SET_BIT (field,bit) : CLEAR_BIT (field, bit)) - -extern long MemUsed; - -struct malloc_header { - unsigned long magic, len; -}; - -#endif +#define SET_BIT_TO_VAL(field, bit, val) \ + ((val) ? SET_BIT(field, bit) : CLEAR_BIT(field, bit)) #ifdef DMALLOC /* What the heck is this?? */ #include #endif -extern void PrintMemuse (void); +extern void PrintMemuse(void); typedef unsigned long Ulong; typedef unsigned char Uchar; typedef signed char Schar; -typedef enum { - SHOW_GLOBAL = 0, - SHOW_DESKTOP = 1, - SHOW_PAGE = 2 -} Resolution; +typedef enum { SHOW_GLOBAL = 0, SHOW_DESKTOP = 1, SHOW_PAGE = 2 } Resolution; typedef enum { - BUTTON_FLAT, - BUTTON_UP, - BUTTON_DOWN, - BUTTON_EDGEUP, - BUTTON_EDGEDOWN + BUTTON_FLAT, + BUTTON_UP, + BUTTON_DOWN, + BUTTON_EDGEUP, + BUTTON_EDGEDOWN } ButtonState; /* The clicks must be the first three elements in this type, X callbacks - depend on it! */ -typedef enum { - SELECT, - MOUSE, - KEYPRESS, - NUM_ACTIONS -} Action; + depend on it! */ +typedef enum { SELECT, MOUSE, KEYPRESS, NUM_ACTIONS } Action; typedef enum { - PLAIN_CONTEXT = 0, - FOCUS_CONTEXT = 1, - SELECT_CONTEXT = 2, - FOCUS_SELECT_CONTEXT = 3, /* had better be FOCUS_CONTEXT | SELECT_CONTEXT */ - TITLE_CONTEXT = 4, - NUM_CONTEXTS + PLAIN_CONTEXT = 0, + FOCUS_CONTEXT = 1, + SELECT_CONTEXT = 2, + FOCUS_SELECT_CONTEXT = + 3, /* had better be FOCUS_CONTEXT | SELECT_CONTEXT */ + TITLE_CONTEXT = 4, + NUM_CONTEXTS } Contexts; typedef enum { - NO_NAME = 0, - TITLE_NAME = 1, - ICON_NAME = 2, - RESOURCE_NAME = 4, - CLASS_NAME = 8, - ALL_NAME = 15 + NO_NAME = 0, + TITLE_NAME = 1, + ICON_NAME = 2, + RESOURCE_NAME = 4, + CLASS_NAME = 8, + ALL_NAME = 15 } NameType; typedef struct win_list { - int n; - struct win_data *head, *tail; + int n; + struct win_data *head, *tail; } WinList; typedef struct string_list { - NameType type; - char *string; - struct string_list *next; + NameType type; + char *string; + struct string_list *next; } StringEl; typedef struct { - Uchar mask; - StringEl *list; + Uchar mask; + StringEl *list; } StringList; typedef enum { - NoArg, - IntArg, - StringArg, - ButtonArg, - WindowArg, - ManagerArg, - JmpArg + NoArg, + IntArg, + StringArg, + ButtonArg, + WindowArg, + ManagerArg, + JmpArg } BuiltinArgType; typedef enum { - NoButton, - SelectButton, - FocusButton, - AbsoluteButton, - UpButton, - DownButton, - LeftButton, - RightButton, - NextButton, - PrevButton + NoButton, + SelectButton, + FocusButton, + AbsoluteButton, + UpButton, + DownButton, + LeftButton, + RightButton, + NextButton, + PrevButton } ButtonType; /* doubles for manager too */ typedef struct { - int offset; - ButtonType base; + int offset; + ButtonType base; } ButtonValue; typedef struct builtin_arg { - BuiltinArgType type; - union { - char *string_value; - ButtonValue button_value; - int int_value; - } value; + BuiltinArgType type; + union { + char *string_value; + ButtonValue button_value; + int int_value; + } value; } BuiltinArg; typedef struct Function { - int (*func)(int numargs, BuiltinArg *args); - int numargs; - BuiltinArg args[MAX_ARGS]; - struct Function *next; - struct Function *prev; + int (*func)(int numargs, BuiltinArg *args); + int numargs; + BuiltinArg args[MAX_ARGS]; + struct Function *next; + struct Function *prev; } Function; -typedef struct Binding -{ - char IsMouse; /* Is it a mouse or key binding 1= mouse; */ - int Button_Key; /* Mouse Button number of Keycode */ - char *key_name; /* In case of keycode, give the key_name too */ - int Modifier; /* Modifiers for keyboard state */ - char *Action; /* What to do? */ - Function *Function; - struct Binding *NextBinding, *LastBinding; +typedef struct Binding { + char IsMouse; /* Is it a mouse or key binding 1= mouse; */ + int Button_Key; /* Mouse Button number of Keycode */ + char *key_name; /* In case of keycode, give the key_name too */ + int Modifier; /* Modifiers for keyboard state */ + char *Action; /* What to do? */ + Function *Function; + struct Binding *NextBinding, *LastBinding; } Binding; typedef struct win_data { - struct button *button; - /* stuff shadowed in the Button structure */ + struct button *button; + /* stuff shadowed in the Button structure */ #ifdef MINI_ICONS - FvwmPicture pic; + FvwmPicture pic; #endif - char *display_string; /* what gets shown in the manager window */ - Uchar iconified, state; - - Ulong desknum; - long x, y, width, height; - Ulong app_id; - Ulong fvwm_flags; - char *resname; - char *classname; - char *titlename; - char *iconname; - struct win_data *win_prev, *win_next; - struct win_manager *manager; - int app_id_set : 1; - int geometry_set : 1; - Uchar complete; + char *display_string; /* what gets shown in the manager window */ + Uchar iconified, state; + + Ulong desknum; + long x, y, width, height; + Ulong app_id; + Ulong fvwm_flags; + char *resname; + char *classname; + char *titlename; + char *iconname; + struct win_data *win_prev, *win_next; + struct win_manager *manager; + unsigned int app_id_set:1; + unsigned int geometry_set:1; + Uchar complete; } WinData; typedef struct button { - int index; /* index into button array */ - int x, y, w, h; /* current coords of button */ - struct { - int dirty_flags; + int index; /* index into button array */ + int x, y, w, h; /* current coords of button */ + struct { + int dirty_flags; #ifdef MINI_ICONS - FvwmPicture pic; + FvwmPicture pic; #endif - WinData *win; - char *display_string; - int x, y, w, h; - Uchar iconified, state; - } drawn_state; + WinData *win; + char *display_string; + int x, y, w, h; + Uchar iconified, state; + } drawn_state; } Button; typedef struct button_array { - int dirty_flags; - int num_buttons, drawn_num_buttons; /* size of buttons array */ - int num_windows, drawn_num_windows; /* number of windows with buttons */ - Button **buttons; + int dirty_flags; + int num_buttons, drawn_num_buttons; /* size of buttons array */ + int num_windows, drawn_num_windows; /* number of windows with buttons */ + Button **buttons; } ButtonArray; typedef enum { - GROW_HORIZ = 1, - GROW_VERT = 2, - GROW_UP = 4, - GROW_DOWN = 8, - GROW_LEFT = 16, - GROW_RIGHT = 32, - GROW_FIXED = 64 + GROW_HORIZ = 1, + GROW_VERT = 2, + GROW_UP = 4, + GROW_DOWN = 8, + GROW_LEFT = 16, + GROW_RIGHT = 32, + GROW_FIXED = 64 } GrowDirection; typedef struct { - /* Things which we can change go in here. - This like border width go in WinManager */ - int x, y, width, height; - int gravity_x, gravity_y; /* anchor point for window's gravity */ - int rows, cols; - int boxheight, boxwidth; - GrowDirection dir; + /* Things which we can change go in here. + This like border width go in WinManager */ + int x, y, width, height; + int gravity_x, gravity_y; /* anchor point for window's gravity */ + int rows, cols; + int boxheight, boxwidth; + GrowDirection dir; } ManGeometry; typedef struct { - int num_rects; - XRectangle rects[2]; + int num_rects; + XRectangle rects[2]; } ShapeState; typedef enum { - SortNone, /* no sorting */ - SortId, /* sort by window id */ - SortName, /* case insensitive name sorting */ - SortNameCase /* case sensitive name sorting */ + SortNone, /* no sorting */ + SortId, /* sort by window id */ + SortName, /* case insensitive name sorting */ + SortNameCase /* case sensitive name sorting */ } SortType; typedef struct win_manager { - unsigned int magic; - int index; - - /* .fvwm2rc options or things set as a result of options */ - Resolution res; - Pixel backcolor[NUM_CONTEXTS], forecolor[NUM_CONTEXTS]; - Pixel hicolor[NUM_CONTEXTS], shadowcolor[NUM_CONTEXTS]; - GC hiContext[NUM_CONTEXTS], backContext[NUM_CONTEXTS], - reliefContext[NUM_CONTEXTS]; - GC shadowContext[NUM_CONTEXTS], flatContext[NUM_CONTEXTS]; - XFontStruct *ButtonFont; + unsigned int magic; + int index; + + /* .fvwm2rc options or things set as a result of options */ + Resolution res; + Pixel backcolor[NUM_CONTEXTS], forecolor[NUM_CONTEXTS]; + Pixel hicolor[NUM_CONTEXTS], shadowcolor[NUM_CONTEXTS]; + GC hiContext[NUM_CONTEXTS], backContext[NUM_CONTEXTS], + reliefContext[NUM_CONTEXTS]; + GC shadowContext[NUM_CONTEXTS], flatContext[NUM_CONTEXTS]; + XFontStruct *ButtonFont; #ifdef MINI_ICONS - int draw_icons; + int draw_icons; #endif - int shaped; - StringList show; - StringList dontshow; - Binding *bindings[NUM_ACTIONS]; - char *fontname; - char *backColorName[NUM_CONTEXTS]; - char *foreColorName[NUM_CONTEXTS]; - ButtonState buttonState[NUM_CONTEXTS]; - char *geometry_str, *button_geometry_str; - char *titlename, *iconname; - char *formatstring; - NameType format_depend; - Uchar followFocus; - Uchar usewinlist; - SortType sort; - - /* X11 state */ - Window theWindow, theFrame; - long sizehints_flags; - int gravity; - int fontheight, fontwidth; - int win_title, win_border; - int off_x, off_y; - Uchar cursor_in_window; - Uchar window_up; - Uchar can_draw; /* = 0 until we get our first ConfigureNotify */ - - /* button state */ - int dirty_flags; - ManGeometry geometry, drawn_geometry; - Button *select_button, *focus_button; - Uchar window_mapped, drawn_mapping; + int shaped; + StringList show; + StringList dontshow; + Binding *bindings[NUM_ACTIONS]; + char *fontname; + char *backColorName[NUM_CONTEXTS]; + char *foreColorName[NUM_CONTEXTS]; + ButtonState buttonState[NUM_CONTEXTS]; + char *geometry_str, *button_geometry_str; + char *titlename, *iconname; + char *formatstring; + NameType format_depend; + Uchar followFocus; + Uchar usewinlist; + SortType sort; + + /* X11 state */ + Window theWindow, theFrame; + long sizehints_flags; + int gravity; + int fontheight, fontwidth; + int win_title, win_border; + int off_x, off_y; + Uchar cursor_in_window; + Uchar window_up; + Uchar can_draw; /* = 0 until we get our first ConfigureNotify */ + + /* button state */ + int dirty_flags; + ManGeometry geometry, drawn_geometry; + Button *select_button, *focus_button; + Uchar window_mapped, drawn_mapping; #ifdef SHAPE - ShapeState shape, drawn_shape; + ShapeState shape, drawn_shape; #endif - ButtonArray buttons; + ButtonArray buttons; - /* Fvwm state */ - int we_are_drawing, configures_expected; + /* Fvwm state */ + int we_are_drawing, configures_expected; } WinManager; #define MANAGER_EMPTY(man) ((man)->buttons.num_windows == 0) typedef struct { - Ulong desknum; - Ulong x, y; /* of the view window */ - long screenx, screeny; /* screen dimensions */ - WinManager *managers; - int num_managers; - int transient; - WinData *focus_win; - WinData *select_win; - int shapes_supported; - int got_window_list; + Ulong desknum; + Ulong x, y; /* of the view window */ + long screenx, screeny; /* screen dimensions */ + WinManager *managers; + int num_managers; + int transient; + WinData *focus_win; + WinData *select_win; + int shapes_supported; + int got_window_list; } GlobalData; typedef struct { - char *name; - ButtonState state; - char *forecolor[2]; /* 0 is mono, 1 is color */ - char *backcolor[2]; /* 0 is mono, 1 is color */ + char *name; + ButtonState state; + char *forecolor[2]; /* 0 is mono, 1 is color */ + char *backcolor[2]; /* 0 is mono, 1 is color */ } ContextDefaults; - extern char *contextNames[NUM_CONTEXTS]; extern GlobalData globals; @@ -344,30 +325,32 @@ extern int ModuleLen; extern ContextDefaults contextDefaults[]; extern void ReadFvwmPipe(void); -extern void *Malloc (size_t size); -extern void Free (void *p); -extern void ShutMeDown (int flag) __attribute__ ((__noreturn__)); -extern void DeadPipe (int nothing) __attribute__ ((__noreturn__)); +extern void *Malloc(size_t size); +extern void Free(void *p); +extern void ShutMeDown(int flag) __attribute__((__noreturn__)); +extern void DeadPipe(int nothing) __attribute__((__noreturn__)); extern void SendFvwmPipe(char *message, unsigned long window); -extern char *copy_string (char **target, char *src); - -extern void init_globals (void); -extern int allocate_managers (int num); - -extern WinData *new_windata (void); -extern void free_windata (WinData *p); -extern int check_win_complete (WinData *p); -extern WinManager *figure_win_manager (WinData *win, Uchar mask); -extern void init_winlists (void); -extern void delete_win_hashtab (WinData *win); -extern void insert_win_hashtab (WinData *win); -extern WinData *find_win_hashtab (Ulong id); -extern void walk_hashtab (void (*func)(void *)); -extern int accumulate_walk_hashtab (int (*func)(void *)); -extern void print_stringlist (StringList *list); -extern void add_to_stringlist (StringList *list, char *s); -extern void update_window_stuff (WinManager *man); -extern void print_managers (void); - -extern WinManager *find_windows_manager (Window win); -extern int win_in_viewport (WinData *win); +extern char *copy_string(char **target, char *src); + +extern void init_globals(void); +extern int allocate_managers(int num); + +extern WinData *new_windata(void); +extern void free_windata(WinData *p); +extern int check_win_complete(WinData *p); +extern WinManager *figure_win_manager(WinData *win, Uchar mask); +extern void init_winlists(void); +extern void delete_win_hashtab(WinData *win); +extern void insert_win_hashtab(WinData *win); +extern WinData *find_win_hashtab(Ulong id); +extern void walk_hashtab(void (*func)(void *)); +extern int accumulate_walk_hashtab(int (*func)(void *)); +extern void print_stringlist(StringList *list); +extern void add_to_stringlist(StringList *list, char *s); +extern void update_window_stuff(WinManager *man); +extern void print_managers(void); + +extern WinManager *find_windows_manager(Window win); +extern int win_in_viewport(WinData *win); + +#endif /* FVWMICONMAN_H */ Index: fvwm/modules/FvwmIconMan/debug.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIconMan/debug.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIconMan/debug.c --- fvwm/modules/FvwmIconMan/debug.c +++ fvwm/modules/FvwmIconMan/debug.c @@ -1,55 +1,54 @@ -#include #include +#include #include "FvwmIconMan.h" - #include "debuglevels.h" static char const rcsid[] = - "$Id: debug.c,v 1.1.1.1 2006/11/26 10:53:49 matthieu Exp $"; + "$Id: debug.c,v 1.1.1.1 2006/11/26 10:53:49 matthieu Exp $"; static FILE *console = NULL; void ConsoleMessage(const char *fmt, ...) { - va_list args; + va_list args; - assert(console != NULL); + assert(console != NULL); - fputs("FvwmIconMan: ", console); + fputs("FvwmIconMan: ", console); - va_start(args, fmt); - vfprintf(console, fmt, args); - va_end(args); + va_start(args, fmt); + vfprintf(console, fmt, args); + va_end(args); } int OpenConsole(const char *filenm) { - if (!filenm) - console = stderr; - else if ((console = fopen(filenm, "w")) == NULL) { - fprintf(stderr,"%s: cannot open %s\n", Module, filenm); - return 0; - } - - return 1; + if (!filenm) + console = stderr; + else if ((console = fopen(filenm, "w")) == NULL) { + fprintf(stderr, "%s: cannot open %s\n", Module, filenm); + return 0; + } + + return 1; } void ConsoleDebug(int flag, const char *fmt, ...) { - assert(console != NULL); + assert(console != NULL); #ifdef PRINT_DEBUG - if (flag) { - va_list args; - - va_start(args, fmt); - vfprintf(console, fmt, args); - fflush(console); - va_end(args); - } + if (flag) { + va_list args; + + va_start(args, fmt); + vfprintf(console, fmt, args); + fflush(console); + va_end(args); + } #endif } Index: fvwm/modules/FvwmIconMan/debug.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIconMan/debug.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIconMan/debug.h --- fvwm/modules/FvwmIconMan/debug.h +++ fvwm/modules/FvwmIconMan/debug.h @@ -2,21 +2,20 @@ #define IN_DEBUG_H #if 0 -# define PRINT_DEBUG +#define PRINT_DEBUG #endif #if 0 -# define OUTPUT_FILE "/dev/console" +#define OUTPUT_FILE "/dev/console" #else -# define OUTPUT_FILE NULL +#define OUTPUT_FILE NULL #endif - extern int OpenConsole(const char *filenm); extern void ConsoleMessage(const char *fmt, ...) - __attribute__ ((__format__ (__printf__, 1, 2))); + __attribute__((__format__(__printf__, 1, 2))); extern void ConsoleDebug(int flag, const char *fmt, ...) - __attribute__ ((__format__ (__printf__, 2, 3))); + __attribute__((__format__(__printf__, 2, 3))); extern int CORE, FUNCTIONS, X11, FVWM, CONFIG, WINLIST, MEM; Index: fvwm/modules/FvwmIconMan/functions.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIconMan/functions.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIconMan/functions.c --- fvwm/modules/FvwmIconMan/functions.c +++ fvwm/modules/FvwmIconMan/functions.c @@ -3,517 +3,545 @@ #include "xmanager.h" static char const rcsid[] = - "$Id: functions.c,v 1.2 2021/01/24 09:21:21 matthieu Exp $"; + "$Id: functions.c,v 1.2 2021/01/24 09:21:21 matthieu Exp $"; -static Button *get_select_button (void); +static Button *get_select_button(void); static struct { - Button *current_button; - Function *fp; + Button *current_button; + Function *fp; } function_context; -static void init_function_context (Function *func) +static void +init_function_context(Function *func) { - function_context.current_button = get_select_button(); - function_context.fp = func; + function_context.current_button = get_select_button(); + function_context.fp = func; } -void run_function_list (Function *func) +void +run_function_list(Function *func) { - init_function_context (func); - - while (function_context.fp) { - function_context.fp->func (function_context.fp->numargs, - function_context.fp->args); - if (function_context.fp) - function_context.fp = function_context.fp->next; - } + init_function_context(func); + + while (function_context.fp) { + function_context.fp->func( + function_context.fp->numargs, function_context.fp->args); + if (function_context.fp) + function_context.fp = function_context.fp->next; + } } -static Button *get_select_button (void) +static Button * +get_select_button(void) { - if (globals.select_win) - return globals.select_win->button; - return NULL; + if (globals.select_win) + return globals.select_win->button; + return NULL; } -static Button *get_focus_button (void) +static Button * +get_focus_button(void) { - if (globals.focus_win) - return globals.focus_win->button; - return NULL; + if (globals.focus_win) + return globals.focus_win->button; + return NULL; } -static WinManager *get_current_man (void) +static WinManager * +get_current_man(void) { - Button *b = function_context.current_button; + Button *b = function_context.current_button; - if (globals.num_managers==1) - return globals.managers; - if (b && b->drawn_state.win) - return b->drawn_state.win->manager; - return NULL; + if (globals.num_managers == 1) + return globals.managers; + if (b && b->drawn_state.win) + return b->drawn_state.win->manager; + return NULL; } -static WinData *get_current_win (void) +static WinData * +get_current_win(void) { - Button *b = function_context.current_button; + Button *b = function_context.current_button; - if (b && b->drawn_state.win) - return b->drawn_state.win; - return NULL; + if (b && b->drawn_state.win) + return b->drawn_state.win; + return NULL; } -static Button *get_current_button (void) +static Button * +get_current_button(void) { - return function_context.current_button; + return function_context.current_button; } -static Button *button_move (ButtonValue *bv) +static Button * +button_move(ButtonValue *bv) { - Button *b = NULL, *cur; - WinManager *man; - int i; - - cur = get_current_button(); - - switch (bv->base) { - case NoButton: - ConsoleMessage ("gotobutton: need a button to change to\n"); - return cur; - - case SelectButton: - b = get_select_button(); - break; - - case FocusButton: - b = get_focus_button(); - break; - - case AbsoluteButton: - man = get_current_man(); - if (man && man->buttons.num_windows > 0) { - i = bv->offset % man->buttons.num_windows; - if (i < 0) - i += man->buttons.num_windows; - b = man->buttons.buttons[i]; - } - break; - - default: - man = get_current_man(); - if (!cur) { - ConsoleDebug (FUNCTIONS, "\tno current button, skipping\n"); - return NULL; - } - - switch (bv->base) { - case UpButton: - b = button_above (man, cur); - break; - - case DownButton: - b = button_below (man, cur); - break; - - case LeftButton: - b = button_left (man, cur); - break; - - case RightButton: - b = button_right (man, cur); - break; - - case NextButton: - b = button_next (man, cur); - break; - - case PrevButton: - b = button_prev (man, cur); - break; - - default: - ConsoleMessage ("Internal error in gotobutton\n"); - break; - } - } - - return b; + Button *b = NULL, *cur; + WinManager *man; + int i; + + cur = get_current_button(); + + switch (bv->base) { + case NoButton: + ConsoleMessage("gotobutton: need a button to change to\n"); + return cur; + + case SelectButton: + b = get_select_button(); + break; + + case FocusButton: + b = get_focus_button(); + break; + + case AbsoluteButton: + man = get_current_man(); + if (man && man->buttons.num_windows > 0) { + i = bv->offset % man->buttons.num_windows; + if (i < 0) + i += man->buttons.num_windows; + b = man->buttons.buttons[i]; + } + break; + + default: + man = get_current_man(); + if (!cur) { + ConsoleDebug( + FUNCTIONS, "\tno current button, skipping\n"); + return NULL; + } + + switch (bv->base) { + case UpButton: + b = button_above(man, cur); + break; + + case DownButton: + b = button_below(man, cur); + break; + + case LeftButton: + b = button_left(man, cur); + break; + + case RightButton: + b = button_right(man, cur); + break; + + case NextButton: + b = button_next(man, cur); + break; + + case PrevButton: + b = button_prev(man, cur); + break; + + default: + ConsoleMessage("Internal error in gotobutton\n"); + break; + } + } + + return b; } -int builtin_gotobutton (int numargs, BuiltinArg *args) +int +builtin_gotobutton(int numargs, BuiltinArg *args) { - Button *b; - ButtonValue *bv; + Button *b; + ButtonValue *bv; - ConsoleDebug (FUNCTIONS, "gotobutton: "); - print_args (numargs, args); + ConsoleDebug(FUNCTIONS, "gotobutton: "); + print_args(numargs, args); - bv = &args[0].value.button_value; + bv = &args[0].value.button_value; - b = button_move (bv); + b = button_move(bv); - if (b) - function_context.current_button = b; + if (b) + function_context.current_button = b; - return 0; + return 0; } -int builtin_gotomanager (int numargs, BuiltinArg *args) +int +builtin_gotomanager(int numargs, BuiltinArg *args) { - ButtonValue *bv; - WinManager *man, *new; - int i; + ButtonValue *bv; + WinManager *man, *new; + int i; - ConsoleDebug (FUNCTIONS, "gotomanager: "); - print_args (numargs, args); + ConsoleDebug(FUNCTIONS, "gotomanager: "); + print_args(numargs, args); - bv = &args[0].value.button_value; + bv = &args[0].value.button_value; - new = man = get_current_man(); + new = man = get_current_man(); - switch (bv->base) { - case NoButton: - ConsoleMessage ("gotomanager: need a manager argument\n"); - return 1; + switch (bv->base) { + case NoButton: + ConsoleMessage("gotomanager: need a manager argument\n"); + return 1; - case SelectButton: - case FocusButton: - ConsoleMessage ("gotomanger: \"select\" or \"focus\" does not specify" + case SelectButton: + case FocusButton: + ConsoleMessage( + "gotomanger: \"select\" or \"focus\" does not specify" " a manager\n"); - break; - - case AbsoluteButton: - { - /* Now we find the manager modulo the VISIBLE managers */ - static WinManager **wa = NULL; - int i, num_mapped, n; - - n = globals.num_managers; - if (n) { - if (wa == NULL) { - wa = (WinManager **)safemalloc (n * sizeof (WinManager *)); - } - for (i = 0, num_mapped = 0; i < n; i++) { - if (globals.managers[i].buttons.num_windows > 0 && - globals.managers[i].window_mapped) { - wa[num_mapped++] = &globals.managers[i]; + break; + + case AbsoluteButton: { + /* Now we find the manager modulo the VISIBLE managers */ + static WinManager **wa = NULL; + int i, num_mapped, n; + + n = globals.num_managers; + if (n) { + if (wa == NULL) { + wa = (WinManager **)xmalloc( + n * sizeof(WinManager *)); + } + for (i = 0, num_mapped = 0; i < n; i++) { + if (globals.managers[i].buttons.num_windows > + 0 && + globals.managers[i].window_mapped) { + wa[num_mapped++] = &globals.managers[i]; + } + } + if (num_mapped) { + i = bv->offset % num_mapped; + if (i < 0) + i += num_mapped; + new = wa[i]; + } else { + new = NULL; + } + } + } + break; + + case NextButton: + if (man) { + for (i = man->index + 1, new = man + 1; + i < globals.num_managers && new->buttons + .num_windows == + 0; + i++, new++) + ; + if (i == globals.num_managers) + new = man; + } + break; + + case PrevButton: + if (man) { + for (i = man->index - 1, new = man - 1; + i > -1 && new->buttons.num_windows == 0; + i--, new--) + ; + if (i == -1) + new = man; + } + break; + + default: + ConsoleMessage("gotomanager: bad argument\n"); + break; + } + + if (new && new != man && new->buttons.num_windows > 0) { + function_context.current_button = new->buttons.buttons[0]; } - } - if (num_mapped) { - i = bv->offset % num_mapped; - if (i < 0) - i += num_mapped; - new = wa[i]; - } - else { - new = NULL; - } - } - } - break; - - case NextButton: - if (man) { - for (i = man->index + 1, new = man + 1; - i < globals.num_managers && new->buttons.num_windows == 0; - i++, new++) - ; - if (i == globals.num_managers) - new = man; - } - break; - - case PrevButton: - if (man) { - for (i = man->index - 1, new = man - 1; - i > -1 && new->buttons.num_windows == 0; - i--, new--) - ; - if (i == -1) - new = man; - } - break; - - default: - ConsoleMessage ("gotomanager: bad argument\n"); - break; - } - - if (new && new != man && new->buttons.num_windows > 0) { - function_context.current_button = new->buttons.buttons[0]; - } - - return 0; -} + return 0; +} -int builtin_select (int numargs, BuiltinArg *args) +int +builtin_select(int numargs, BuiltinArg *args) { - WinManager *man = get_current_man(); - if (man) { - move_highlight (man, get_current_button()); - if (get_current_button()) - run_binding (man, SELECT); - } - return 0; + WinManager *man = get_current_man(); + if (man) { + move_highlight(man, get_current_button()); + if (get_current_button()) + run_binding(man, SELECT); + } + return 0; } -int builtin_sendcommand (int numargs, BuiltinArg *args) +int +builtin_sendcommand(int numargs, BuiltinArg *args) { - WinData *win = get_current_win(); + WinData *win = get_current_win(); - if (!win) { - return 0; - } + if (!win) { + return 0; + } - SendFvwmPipe (args[0].value.string_value, win->app_id); + SendFvwmPipe(args[0].value.string_value, win->app_id); - return 0; + return 0; } -int builtin_printdebug (int numargs, BuiltinArg *args) +int +builtin_printdebug(int numargs, BuiltinArg *args) { - int i; - - for (i = 0; i < globals.num_managers; i++) { - ConsoleDebug (FUNCTIONS, "Manager %d\n---------\n", i); - ConsoleDebug (FUNCTIONS, "Keys:\n"); - print_bindings (globals.managers[i].bindings[KEYPRESS]); - ConsoleDebug (FUNCTIONS, "Mice:\n"); - print_bindings (globals.managers[i].bindings[MOUSE]); - ConsoleDebug (FUNCTIONS, "Select:\n"); - print_bindings (globals.managers[i].bindings[SELECT]); - ConsoleDebug (FUNCTIONS, "\n"); - } - - return 0; + int i; + + for (i = 0; i < globals.num_managers; i++) { + ConsoleDebug(FUNCTIONS, "Manager %d\n---------\n", i); + ConsoleDebug(FUNCTIONS, "Keys:\n"); + print_bindings(globals.managers[i].bindings[KEYPRESS]); + ConsoleDebug(FUNCTIONS, "Mice:\n"); + print_bindings(globals.managers[i].bindings[MOUSE]); + ConsoleDebug(FUNCTIONS, "Select:\n"); + print_bindings(globals.managers[i].bindings[SELECT]); + ConsoleDebug(FUNCTIONS, "\n"); + } + + return 0; } -int builtin_quit (int numargs, BuiltinArg *args) +int +builtin_quit(int numargs, BuiltinArg *args) { - ConsoleDebug (FUNCTIONS, "quit: "); - print_args (numargs, args); - ShutMeDown (0); - return 0; + ConsoleDebug(FUNCTIONS, "quit: "); + print_args(numargs, args); + ShutMeDown(0); + return 0; } -static void do_jmp (int off) +static void +do_jmp(int off) { - int i; - ConsoleDebug (FUNCTIONS, "jmp: %d\n", off); - - if (off < 0) { - ConsoleMessage ("Can't have a negative relative jump offset\n"); - return; - } - for (i = 0; i < off; i++) { - if (function_context.fp) - function_context.fp = function_context.fp->next; - } + int i; + ConsoleDebug(FUNCTIONS, "jmp: %d\n", off); + + if (off < 0) { + ConsoleMessage("Can't have a negative relative jump offset\n"); + return; + } + for (i = 0; i < off; i++) { + if (function_context.fp) + function_context.fp = function_context.fp->next; + } } -static int eval_if (ButtonValue *bv) +static int +eval_if(ButtonValue *bv) { - Button *cur; - WinManager *man; - - switch (bv->base) { - case NoButton: - ConsoleMessage ("Internal error in eval_if: 1\n"); - break; - - case SelectButton: - if (get_select_button()) - return 1; - break; - - case FocusButton: - if (get_focus_button()) - return 1; - break; - - case AbsoluteButton: - if (bv->offset != 0) - return 1; - break; - - default: - cur = get_current_button(); - man = get_current_man(); - if (!cur || !man) { - return 0; - } - - switch (bv->base) { - case UpButton: - return (button_above (man, cur) != cur); - - case DownButton: - return (button_below (man, cur) != cur); - - case LeftButton: - return (button_left (man, cur) != cur); - - case RightButton: - return (button_right (man, cur) != cur); - - case NextButton: - return (button_next (man, cur) != cur); - - case PrevButton: - return (button_prev (man, cur) != cur); - - default: - ConsoleMessage ("Internal error in eval_if: 2\n"); - break; - } - } - - return 0; + Button *cur; + WinManager *man; + + switch (bv->base) { + case NoButton: + ConsoleMessage("Internal error in eval_if: 1\n"); + break; + + case SelectButton: + if (get_select_button()) + return 1; + break; + + case FocusButton: + if (get_focus_button()) + return 1; + break; + + case AbsoluteButton: + if (bv->offset != 0) + return 1; + break; + + default: + cur = get_current_button(); + man = get_current_man(); + if (!cur || !man) { + return 0; + } + + switch (bv->base) { + case UpButton: + return (button_above(man, cur) != cur); + + case DownButton: + return (button_below(man, cur) != cur); + + case LeftButton: + return (button_left(man, cur) != cur); + + case RightButton: + return (button_right(man, cur) != cur); + + case NextButton: + return (button_next(man, cur) != cur); + + case PrevButton: + return (button_prev(man, cur) != cur); + + default: + ConsoleMessage("Internal error in eval_if: 2\n"); + break; + } + } + + return 0; } -int builtin_bif (int numargs, BuiltinArg *args) +int +builtin_bif(int numargs, BuiltinArg *args) { - int off = args[1].value.int_value; - ConsoleDebug (FUNCTIONS, "bif: off = %d\n", off); + int off = args[1].value.int_value; + ConsoleDebug(FUNCTIONS, "bif: off = %d\n", off); - if (eval_if (&args[0].value.button_value)) { - do_jmp (off); - } + if (eval_if(&args[0].value.button_value)) { + do_jmp(off); + } - return 0; + return 0; } -int builtin_bifn (int numargs, BuiltinArg *args) +int +builtin_bifn(int numargs, BuiltinArg *args) { - int off = args[1].value.int_value; - ConsoleDebug (FUNCTIONS, "bifn: off = %d\n", off); + int off = args[1].value.int_value; + ConsoleDebug(FUNCTIONS, "bifn: off = %d\n", off); - if (eval_if (&args[0].value.button_value) == 0) { - do_jmp (off); - } + if (eval_if(&args[0].value.button_value) == 0) { + do_jmp(off); + } - return 0; + return 0; } -int builtin_jmp (int numargs, BuiltinArg *args) +int +builtin_jmp(int numargs, BuiltinArg *args) { - int off = args[0].value.int_value; - ConsoleDebug (FUNCTIONS, "jmp: off = %d\n", off); + int off = args[0].value.int_value; + ConsoleDebug(FUNCTIONS, "jmp: off = %d\n", off); - do_jmp (off); - return 0; + do_jmp(off); + return 0; } -int builtin_ret (int numargs, BuiltinArg *args) +int +builtin_ret(int numargs, BuiltinArg *args) { - function_context.fp = NULL; - return 0; + function_context.fp = NULL; + return 0; } -int builtin_print (int numargs, BuiltinArg *args) +int +builtin_print(int numargs, BuiltinArg *args) { - char *s; + char *s; - ConsoleDebug (FUNCTIONS, "print: %s\n", args[0].value.string_value); + ConsoleDebug(FUNCTIONS, "print: %s\n", args[0].value.string_value); - s = args[0].value.string_value; - if (strlen (s) > 250) { - ConsoleMessage ("String too long\n"); - } - else { - ConsoleMessage ("%s\n", s); - } + s = args[0].value.string_value; + if (strlen(s) > 250) { + ConsoleMessage("String too long\n"); + } else { + ConsoleMessage("%s\n", s); + } - return 0; + return 0; } -int builtin_searchforward (int numargs, BuiltinArg *args) +int +builtin_searchforward(int numargs, BuiltinArg *args) { - char *s; - Button *b, *cur; - WinManager *man; - - s = args[0].value.string_value; - - ConsoleDebug (FUNCTIONS, "searchforward: %s\n", s); - - cur = get_current_button(); - man = get_current_man(); - b = cur; - if (cur) { - while (1) { - if (cur->drawn_state.display_string && - matchWildcards (s, cur->drawn_state.display_string)) - break; - b = button_next (man, cur); - if (b == cur) { - cur = NULL; - break; - } - cur = b; - } - } - if (cur) - function_context.current_button = cur; - - return 0; -} + char *s; + Button *b, *cur; + WinManager *man; + + s = args[0].value.string_value; + + ConsoleDebug(FUNCTIONS, "searchforward: %s\n", s); + + cur = get_current_button(); + man = get_current_man(); + b = cur; + if (cur) { + while (1) { + if (cur->drawn_state.display_string && + matchWildcards(s, cur->drawn_state.display_string)) + break; + b = button_next(man, cur); + if (b == cur) { + cur = NULL; + break; + } + cur = b; + } + } + if (cur) + function_context.current_button = cur; -int builtin_searchback (int numargs, BuiltinArg *args) -{ - char *s; - Button *b, *cur; - WinManager *man; - - s = args[0].value.string_value; - - ConsoleDebug (FUNCTIONS, "searchback: %s\n", s); - - cur = get_current_button(); - man = get_current_man(); - b = cur; - if (cur) { - while (1) { - if (cur->drawn_state.display_string && - matchWildcards (s, cur->drawn_state.display_string)) - break; - b = button_prev (man, cur); - if (b == cur) { - cur = NULL; - break; - } - cur = b; - } - } - if (cur) - function_context.current_button = cur; - - return 0; + return 0; } -int builtin_warp (int numargs, BuiltinArg *args) +int +builtin_searchback(int numargs, BuiltinArg *args) { - Button *cur; - WinManager *man; - int x, y; + char *s; + Button *b, *cur; + WinManager *man; + + s = args[0].value.string_value; + + ConsoleDebug(FUNCTIONS, "searchback: %s\n", s); + + cur = get_current_button(); + man = get_current_man(); + b = cur; + if (cur) { + while (1) { + if (cur->drawn_state.display_string && + matchWildcards(s, cur->drawn_state.display_string)) + break; + b = button_prev(man, cur); + if (b == cur) { + cur = NULL; + break; + } + cur = b; + } + } + if (cur) + function_context.current_button = cur; - ConsoleDebug (FUNCTIONS, "warp\n"); + return 0; +} - cur = get_current_button(); - if (cur) { - man = get_current_man(); - x = cur->x + cur->w / 2; - y = cur->y + cur->h / 2; - XWarpPointer (theDisplay, None, man->theWindow, 0, 0, 0, 0, x, y); - } +int +builtin_warp(int numargs, BuiltinArg *args) +{ + Button *cur; + WinManager *man; + int x, y; + + ConsoleDebug(FUNCTIONS, "warp\n"); + + cur = get_current_button(); + if (cur) { + man = get_current_man(); + x = cur->x + cur->w / 2; + y = cur->y + cur->h / 2; + XWarpPointer( + theDisplay, None, man->theWindow, 0, 0, 0, 0, x, y); + } - return 0; + return 0; } -int builtin_refresh (int numargs, BuiltinArg *args) +int +builtin_refresh(int numargs, BuiltinArg *args) { - draw_managers(); - return 0; + draw_managers(); + return 0; } Index: fvwm/modules/FvwmIconMan/fvwm.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIconMan/fvwm.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIconMan/fvwm.c --- fvwm/modules/FvwmIconMan/fvwm.c +++ fvwm/modules/FvwmIconMan/fvwm.c @@ -1,575 +1,595 @@ -#include "config.h" +#include "../fvwm/fvwm.h" +#include "../fvwm/module.h" #include "FvwmIconMan.h" +#include "config.h" #include "x.h" #include "xmanager.h" -#include "../fvwm/fvwm.h" -#include "../fvwm/module.h" - static char const rcsid[] = - "$Id: fvwm.c,v 1.1.1.1 2006/11/26 10:53:49 matthieu Exp $"; + "$Id: fvwm.c,v 1.1.1.1 2006/11/26 10:53:49 matthieu Exp $"; typedef struct { - Ulong paging_enabled; + Ulong paging_enabled; } m_toggle_paging_data; typedef struct { - Ulong desknum; + Ulong desknum; } m_new_desk_data; typedef struct { - Ulong app_id; - Ulong frame_id; - Ulong dbase_entry; - Ulong xpos; - Ulong ypos; - Ulong width; - Ulong height; - Ulong desknum; - Ulong windows_flags; - Ulong window_title_height; - Ulong window_border_width; - Ulong window_base_width; - Ulong window_base_height; - Ulong window_resize_width_inc; - Ulong window_resize_height_inc; - Ulong window_min_width; - Ulong window_min_height; - Ulong window_max_width_inc; - Ulong window_max_height_inc; - Ulong icon_label_id; - Ulong icon_pixmap_id; - Ulong window_gravity; + Ulong app_id; + Ulong frame_id; + Ulong dbase_entry; + Ulong xpos; + Ulong ypos; + Ulong width; + Ulong height; + Ulong desknum; + Ulong windows_flags; + Ulong window_title_height; + Ulong window_border_width; + Ulong window_base_width; + Ulong window_base_height; + Ulong window_resize_width_inc; + Ulong window_resize_height_inc; + Ulong window_min_width; + Ulong window_min_height; + Ulong window_max_width_inc; + Ulong window_max_height_inc; + Ulong icon_label_id; + Ulong icon_pixmap_id; + Ulong window_gravity; } m_add_config_data; typedef struct { - Ulong x, y, desknum; + Ulong x, y, desknum; } m_new_page_data; typedef struct { - Ulong app_id, frame_id, dbase_entry; + Ulong app_id, frame_id, dbase_entry; } m_minimal_data; typedef struct { - Ulong app_id, frame_id, dbase_entry; - Ulong xpos, ypos, icon_width, icon_height; + Ulong app_id, frame_id, dbase_entry; + Ulong xpos, ypos, icon_width, icon_height; } m_icon_data; typedef struct { - Ulong app_id, frame_id, dbase_entry; - union { - Ulong name_long[1]; - Uchar name[4]; - } name; + Ulong app_id, frame_id, dbase_entry; + union { + Ulong name_long[1]; + Uchar name[4]; + } name; } m_name_data; #ifdef MINI_ICONS typedef struct { - Ulong app_id, frame_id, dbase_entry; - Ulong width, height, depth, picture, mask; - union { - Ulong name_long[1]; - Uchar name[4]; - } name; + Ulong app_id, frame_id, dbase_entry; + Ulong width, height, depth, picture, mask; + union { + Ulong name_long[1]; + Uchar name[4]; + } name; } m_mini_icon_data; #endif typedef struct { - Ulong start, type, len, time /* in fvwm 2 only */; + Ulong start, type, len, time /* in fvwm 2 only */; } FvwmPacketHeader; typedef union { - m_toggle_paging_data toggle_paging_data; - m_new_desk_data new_desk_data; - m_add_config_data add_config_data; - m_new_page_data new_page_data; - m_minimal_data minimal_data; - m_icon_data icon_data; - m_name_data name_data; + m_toggle_paging_data toggle_paging_data; + m_new_desk_data new_desk_data; + m_add_config_data add_config_data; + m_new_page_data new_page_data; + m_minimal_data minimal_data; + m_icon_data icon_data; + m_name_data name_data; #ifdef MINI_ICONS - m_mini_icon_data mini_icon_data; + m_mini_icon_data mini_icon_data; #endif } FvwmPacketBody; /* only used by count_nonsticky_in_hashtab */ static WinManager *the_manager; -static int count_nonsticky_in_hashtab (void *arg) +static int +count_nonsticky_in_hashtab(void *arg) { - WinData *win = (WinData *)arg; - WinManager *man = the_manager; + WinData *win = (WinData *)arg; + WinManager *man = the_manager; - if (!(win->fvwm_flags & STICKY) && win->complete && win->manager == man) - return 1; - return 0; + if (!(win->fvwm_flags & STICKY) && win->complete && win->manager == man) + return 1; + return 0; } -static void set_draw_mode (WinManager *man, int flag) +static void +set_draw_mode(WinManager *man, int flag) { - int num; - - if (!man) - return; - - if (man->we_are_drawing == 0 && flag) { - draw_manager (man); - } - else if (man->we_are_drawing && !flag) { - the_manager = man; - num = accumulate_walk_hashtab (count_nonsticky_in_hashtab); - ConsoleDebug (FVWM, "SetDrawMode on 0x%lx, num = %d\n", - (unsigned long)man, num); - - if (num == 0) - return; - man->configures_expected = num; - } - man->we_are_drawing = flag; + int num; + + if (!man) + return; + + if (man->we_are_drawing == 0 && flag) { + draw_manager(man); + } else if (man->we_are_drawing && !flag) { + the_manager = man; + num = accumulate_walk_hashtab(count_nonsticky_in_hashtab); + ConsoleDebug(FVWM, "SetDrawMode on 0x%lx, num = %d\n", + (unsigned long)man, num); + + if (num == 0) + return; + man->configures_expected = num; + } + man->we_are_drawing = flag; } -static int drawing (WinManager *man) +static int +drawing(WinManager *man) { - if (!man) - return 1; + if (!man) + return 1; - return man->we_are_drawing; + return man->we_are_drawing; } -static void got_configure (WinManager *man) +static void +got_configure(WinManager *man) { - if (man && !man->we_are_drawing) { - man->configures_expected--; - ConsoleDebug (FVWM, "got_configure on 0x%lx, num_expected now = %d\n", - (unsigned long) man, man->configures_expected); - if (man->configures_expected <= 0) - set_draw_mode (man, 1); - } + if (man && !man->we_are_drawing) { + man->configures_expected--; + ConsoleDebug(FVWM, + "got_configure on 0x%lx, num_expected now = %d\n", + (unsigned long)man, man->configures_expected); + if (man->configures_expected <= 0) + set_draw_mode(man, 1); + } } -int win_in_viewport (WinData *win) +int +win_in_viewport(WinData *win) { - WinManager *manager = win->manager; - int flag = 0; - - assert (manager); - - switch (manager->res) { - case SHOW_GLOBAL: - flag = 1; - break; - - case SHOW_DESKTOP: - if ((win->fvwm_flags & STICKY) || win->desknum == globals.desknum) - flag = 1; - break; - - case SHOW_PAGE: - if (win->fvwm_flags & STICKY) { - flag = 1; - } else if (win->desknum == globals.desknum) { - /* win and screen intersect if they are not disjoint in x and y */ - flag = RECTANGLES_INTERSECT (win->x, win->y, win->width, win->height, - 0, 0, globals.screenx, globals.screeny); - } - break; - } - return flag; + WinManager *manager = win->manager; + int flag = 0; + + assert(manager); + + switch (manager->res) { + case SHOW_GLOBAL: + flag = 1; + break; + + case SHOW_DESKTOP: + if ((win->fvwm_flags & STICKY) || + win->desknum == globals.desknum) + flag = 1; + break; + + case SHOW_PAGE: + if (win->fvwm_flags & STICKY) { + flag = 1; + } else if (win->desknum == globals.desknum) { + /* win and screen intersect if they are not disjoint in + * x and y */ + flag = RECTANGLES_INTERSECT(win->x, win->y, win->width, + win->height, 0, 0, globals.screenx, + globals.screeny); + } + break; + } + return flag; } - -static WinData *id_to_win (Ulong id) +static WinData * +id_to_win(Ulong id) { - WinData *win; - win = find_win_hashtab (id); - if (win == NULL) { - win = new_windata (); - win->app_id = id; - win->app_id_set = 1; - insert_win_hashtab (win); - } - return win; + WinData *win; + win = find_win_hashtab(id); + if (win == NULL) { + win = new_windata(); + win->app_id = id; + win->app_id_set = 1; + insert_win_hashtab(win); + } + return win; } -static void set_win_configuration (WinData *win, FvwmPacketBody *body) +static void +set_win_configuration(WinData *win, FvwmPacketBody *body) { - win->desknum = body->add_config_data.desknum; - win->x = body->add_config_data.xpos; - win->y = body->add_config_data.ypos; - win->width = body->add_config_data.width; - win->height = body->add_config_data.height; - win->geometry_set = 1; - win->fvwm_flags = body->add_config_data.windows_flags; + win->desknum = body->add_config_data.desknum; + win->x = body->add_config_data.xpos; + win->y = body->add_config_data.ypos; + win->width = body->add_config_data.width; + win->height = body->add_config_data.height; + win->geometry_set = 1; + win->fvwm_flags = body->add_config_data.windows_flags; } -static void configure_window (FvwmPacketBody *body) +static void +configure_window(FvwmPacketBody *body) { - Ulong app_id = body->add_config_data.app_id; - WinData *win; - ConsoleDebug (FVWM, "configure_window: %ld\n", app_id); + Ulong app_id = body->add_config_data.app_id; + WinData *win; + ConsoleDebug(FVWM, "configure_window: %ld\n", app_id); - win = id_to_win (app_id); + win = id_to_win(app_id); - set_win_configuration (win, body); + set_win_configuration(win, body); - check_win_complete (win); - check_in_window (win); - got_configure (win->manager); + check_win_complete(win); + check_in_window(win); + got_configure(win->manager); } -static void focus_change (FvwmPacketBody *body) +static void +focus_change(FvwmPacketBody *body) { - Ulong app_id = body->minimal_data.app_id; - WinData *win = id_to_win (app_id); - - ConsoleDebug (FVWM, "Focus Change\n"); - ConsoleDebug (FVWM, "\tID: %ld\n", app_id); - - if (globals.focus_win) { - del_win_state (globals.focus_win, FOCUS_CONTEXT); - if (globals.focus_win->manager && globals.focus_win->manager->focus_button) - globals.focus_win->manager->focus_button = NULL; - globals.focus_win = NULL; - } - - - if (win->complete && - win->button && - win->manager && - win->manager->window_up && - win->manager->followFocus) { - win->manager->focus_button = win->button; - add_win_state (win, FOCUS_CONTEXT); - } - - globals.focus_win = win; - ConsoleDebug (FVWM, "leaving focus_change\n"); + Ulong app_id = body->minimal_data.app_id; + WinData *win = id_to_win(app_id); + + ConsoleDebug(FVWM, "Focus Change\n"); + ConsoleDebug(FVWM, "\tID: %ld\n", app_id); + + if (globals.focus_win) { + del_win_state(globals.focus_win, FOCUS_CONTEXT); + if (globals.focus_win->manager && + globals.focus_win->manager->focus_button) + globals.focus_win->manager->focus_button = NULL; + globals.focus_win = NULL; + } + + if (win->complete && win->button && win->manager && + win->manager->window_up && win->manager->followFocus) { + win->manager->focus_button = win->button; + add_win_state(win, FOCUS_CONTEXT); + } + + globals.focus_win = win; + ConsoleDebug(FVWM, "leaving focus_change\n"); } -static void res_name (FvwmPacketBody *body) +static void +res_name(FvwmPacketBody *body) { - Ulong app_id = body->name_data.app_id; - Uchar *name = body->name_data.name.name; - WinData *win; + Ulong app_id = body->name_data.app_id; + Uchar *name = body->name_data.name.name; + WinData *win; - ConsoleDebug (FVWM, "In res_name\n"); + ConsoleDebug(FVWM, "In res_name\n"); - win = id_to_win (app_id); + win = id_to_win(app_id); - copy_string (&win->resname, (char *)name); - change_windows_manager (win); + copy_string(&win->resname, (char *)name); + change_windows_manager(win); - ConsoleDebug (FVWM, "Exiting res_name\n"); + ConsoleDebug(FVWM, "Exiting res_name\n"); } -static void class_name (FvwmPacketBody *body) +static void +class_name(FvwmPacketBody *body) { - Ulong app_id = body->name_data.app_id; - Uchar *name = body->name_data.name.name; - WinData *win; + Ulong app_id = body->name_data.app_id; + Uchar *name = body->name_data.name.name; + WinData *win; - ConsoleDebug (FVWM, "In class_name\n"); + ConsoleDebug(FVWM, "In class_name\n"); - win = id_to_win (app_id); + win = id_to_win(app_id); - copy_string (&win->classname, (char *)name); - change_windows_manager (win); + copy_string(&win->classname, (char *)name); + change_windows_manager(win); - ConsoleDebug (FVWM, "Exiting class_name\n"); + ConsoleDebug(FVWM, "Exiting class_name\n"); } -static void icon_name (FvwmPacketBody *body) +static void +icon_name(FvwmPacketBody *body) { - WinData *win; - Ulong app_id; - Uchar *name = body->name_data.name.name; + WinData *win; + Ulong app_id; + Uchar *name = body->name_data.name.name; - ConsoleDebug (FVWM, "In icon_name\n"); + ConsoleDebug(FVWM, "In icon_name\n"); - app_id = body->name_data.app_id; + app_id = body->name_data.app_id; - win = id_to_win (app_id); + win = id_to_win(app_id); - if (win->iconname && !strcmp (win->iconname, name)) { - ConsoleDebug (FVWM, "No icon change: %s %s\n", win->iconname, name); - return; - } + if (win->iconname && !strcmp(win->iconname, name)) { + ConsoleDebug( + FVWM, "No icon change: %s %s\n", win->iconname, name); + return; + } - copy_string (&win->iconname, (char *)name); - ConsoleDebug (FVWM, "new icon name: %s\n", win->iconname); - if (change_windows_manager (win) == 0 && win->button && - (win->manager->format_depend & ICON_NAME)) { - if (win->manager->sort) { - resort_windows_button (win); - } - } + copy_string(&win->iconname, (char *)name); + ConsoleDebug(FVWM, "new icon name: %s\n", win->iconname); + if (change_windows_manager(win) == 0 && win->button && + (win->manager->format_depend & ICON_NAME)) { + if (win->manager->sort) { + resort_windows_button(win); + } + } - ConsoleDebug (FVWM, "Exiting icon_name\n"); + ConsoleDebug(FVWM, "Exiting icon_name\n"); } -static void window_name (FvwmPacketBody *body) +static void +window_name(FvwmPacketBody *body) { - WinData *win; - Ulong app_id; - Uchar *name = body->name_data.name.name; - - ConsoleDebug (FVWM, "In window_name\n"); - - app_id = body->name_data.app_id; - - win = id_to_win (app_id); - - /* This is necessary because bash seems to update the window title on - every keystroke regardless of whether anything changes */ - if (win->titlename && !strcmp (win->titlename, name)) { - ConsoleDebug (FVWM, "No name change: %s %s\n", win->titlename, name); - return; - } - - copy_string (&win->titlename, (char *)name); - if (change_windows_manager (win) == 0 && win->button && - (win->manager->format_depend & TITLE_NAME)) { - if (win->manager->sort) { - resort_windows_button (win); - } - } - ConsoleDebug (FVWM, "Exiting window_name\n"); + WinData *win; + Ulong app_id; + Uchar *name = body->name_data.name.name; + + ConsoleDebug(FVWM, "In window_name\n"); + + app_id = body->name_data.app_id; + + win = id_to_win(app_id); + + /* This is necessary because bash seems to update the window title on + every keystroke regardless of whether anything changes */ + if (win->titlename && !strcmp(win->titlename, name)) { + ConsoleDebug( + FVWM, "No name change: %s %s\n", win->titlename, name); + return; + } + + copy_string(&win->titlename, (char *)name); + if (change_windows_manager(win) == 0 && win->button && + (win->manager->format_depend & TITLE_NAME)) { + if (win->manager->sort) { + resort_windows_button(win); + } + } + ConsoleDebug(FVWM, "Exiting window_name\n"); } -static void new_window (FvwmPacketBody *body) +static void +new_window(FvwmPacketBody *body) { - WinData *win; - - win = new_windata(); - if (!(body->add_config_data.windows_flags & TRANSIENT)) { - win->app_id = body->add_config_data.app_id; - win->app_id_set = 1; - set_win_configuration (win, body); - - insert_win_hashtab (win); - check_win_complete (win); - check_in_window (win); - } + WinData *win; + + win = new_windata(); + if (!(body->add_config_data.windows_flags & TRANSIENT)) { + win->app_id = body->add_config_data.app_id; + win->app_id_set = 1; + set_win_configuration(win, body); + + insert_win_hashtab(win); + check_win_complete(win); + check_in_window(win); + } } -static void destroy_window (FvwmPacketBody *body) +static void +destroy_window(FvwmPacketBody *body) { - WinData *win; - Ulong app_id; - - app_id = body->minimal_data.app_id; - win = id_to_win (app_id); - if (win == globals.focus_win) - globals.focus_win = NULL; - delete_win_hashtab (win); - if (win->button) { - ConsoleDebug (FVWM, "destroy_window: deleting windows_button\n"); - delete_windows_button (win); - } - free_windata (win); + WinData *win; + Ulong app_id; + + app_id = body->minimal_data.app_id; + win = id_to_win(app_id); + if (win == globals.focus_win) + globals.focus_win = NULL; + delete_win_hashtab(win); + if (win->button) { + ConsoleDebug(FVWM, "destroy_window: deleting windows_button\n"); + delete_windows_button(win); + } + free_windata(win); } #ifdef MINI_ICONS -static void mini_icon (FvwmPacketBody *body) +static void +mini_icon(FvwmPacketBody *body) { - Ulong app_id = body->mini_icon_data.app_id; - WinData *win; - - win = id_to_win (app_id); - set_win_picture (win, body->mini_icon_data.picture, - body->mini_icon_data.mask, body->mini_icon_data.depth, - body->mini_icon_data.width, body->mini_icon_data.height); + Ulong app_id = body->mini_icon_data.app_id; + WinData *win; + win = id_to_win(app_id); + set_win_picture(win, body->mini_icon_data.picture, + body->mini_icon_data.mask, body->mini_icon_data.depth, + body->mini_icon_data.width, body->mini_icon_data.height); - ConsoleDebug (FVWM, "mini_icon: 0x%lx 0x%lx %dx%dx%d\n", - (unsigned long) win->pic.picture, - (unsigned long) win->pic.mask, - win->pic.width, win->pic.height, win->pic.depth); + ConsoleDebug(FVWM, "mini_icon: 0x%lx 0x%lx %dx%dx%d\n", + (unsigned long)win->pic.picture, (unsigned long)win->pic.mask, + win->pic.width, win->pic.height, win->pic.depth); } #endif -static void iconify (FvwmPacketBody *body, int dir) +static void +iconify(FvwmPacketBody *body, int dir) { - Ulong app_id = body->minimal_data.app_id; - WinData *win; + Ulong app_id = body->minimal_data.app_id; + WinData *win; - win = id_to_win (app_id); + win = id_to_win(app_id); - set_win_iconified (win, dir); + set_win_iconified(win, dir); - check_win_complete (win); - check_in_window (win); + check_win_complete(win); + check_in_window(win); } /* only used by new_desk */ -static void update_win_in_hashtab (void *arg) +static void +update_win_in_hashtab(void *arg) { - WinData *p = (WinData *)arg; - check_in_window (p); + WinData *p = (WinData *)arg; + check_in_window(p); } -static void new_desk (FvwmPacketBody *body) +static void +new_desk(FvwmPacketBody *body) { - globals.desknum = body->new_desk_data.desknum; - walk_hashtab (update_win_in_hashtab); + globals.desknum = body->new_desk_data.desknum; + walk_hashtab(update_win_in_hashtab); - draw_managers (); + draw_managers(); } -static void sendtomodule (FvwmPacketBody *body) +static void +sendtomodule(FvwmPacketBody *body) { - extern void execute_function (char *); - Uchar *string = body->name_data.name.name; + extern void execute_function(char *); + Uchar *string = body->name_data.name.name; - ConsoleDebug (FVWM, "Got string: %s\n", string); + ConsoleDebug(FVWM, "Got string: %s\n", string); - execute_function (string); + execute_function(string); } -static void ProcessMessage (Ulong type, FvwmPacketBody *body) +static void +ProcessMessage(Ulong type, FvwmPacketBody *body) { - int i; + int i; - ConsoleDebug (FVWM, "FVWM Message type: %ld\n", type); + ConsoleDebug(FVWM, "FVWM Message type: %ld\n", type); - switch(type) { - case M_CONFIGURE_WINDOW: - ConsoleDebug (FVWM, "DEBUG::M_CONFIGURE_WINDOW\n"); - configure_window (body); - break; + switch (type) { + case M_CONFIGURE_WINDOW: + ConsoleDebug(FVWM, "DEBUG::M_CONFIGURE_WINDOW\n"); + configure_window(body); + break; - case M_FOCUS_CHANGE: - ConsoleDebug (FVWM, "DEBUG::M_FOCUS_CHANGE\n"); - focus_change (body); - break; + case M_FOCUS_CHANGE: + ConsoleDebug(FVWM, "DEBUG::M_FOCUS_CHANGE\n"); + focus_change(body); + break; - case M_RES_NAME: - ConsoleDebug (FVWM, "DEBUG::M_RES_NAME\n"); - res_name (body); - break; + case M_RES_NAME: + ConsoleDebug(FVWM, "DEBUG::M_RES_NAME\n"); + res_name(body); + break; - case M_RES_CLASS: - ConsoleDebug (FVWM, "DEBUG::M_RES_CLASS\n"); - class_name (body); - break; + case M_RES_CLASS: + ConsoleDebug(FVWM, "DEBUG::M_RES_CLASS\n"); + class_name(body); + break; - case M_MAP: - ConsoleDebug (FVWM, "DEBUG::M_MAP\n"); - break; + case M_MAP: + ConsoleDebug(FVWM, "DEBUG::M_MAP\n"); + break; - case M_ADD_WINDOW: - ConsoleDebug (FVWM, "DEBUG::M_ADD_WINDOW\n"); - new_window (body); - break; + case M_ADD_WINDOW: + ConsoleDebug(FVWM, "DEBUG::M_ADD_WINDOW\n"); + new_window(body); + break; - case M_DESTROY_WINDOW: - ConsoleDebug (FVWM, "DEBUG::M_DESTROY_WINDOW\n"); - destroy_window (body); - break; + case M_DESTROY_WINDOW: + ConsoleDebug(FVWM, "DEBUG::M_DESTROY_WINDOW\n"); + destroy_window(body); + break; #ifdef MINI_ICONS - case M_MINI_ICON: - ConsoleDebug (FVWM, "DEBUG::M_MINI_ICON\n"); - mini_icon (body); - break; + case M_MINI_ICON: + ConsoleDebug(FVWM, "DEBUG::M_MINI_ICON\n"); + mini_icon(body); + break; #endif - case M_WINDOW_NAME: - ConsoleDebug (FVWM, "DEBUG::M_WINDOW_NAME\n"); - window_name (body); - break; - - case M_ICON_NAME: - ConsoleDebug (FVWM, "DEBUG::M_ICON_NAME\n"); - icon_name (body); - break; - - case M_DEICONIFY: - ConsoleDebug (FVWM, "DEBUG::M_DEICONIFY\n"); - iconify (body, 0); - break; - - case M_ICONIFY: - ConsoleDebug (FVWM, "DEBUG::M_ICONIFY\n"); - iconify (body, 1); - break; - - case M_END_WINDOWLIST: - ConsoleDebug (FVWM, "DEBUG::M_END_WINDOWLIST\n"); - ConsoleDebug (FVWM, - ">>>>>>>>>>>>>>>>>>>>>>>End window list<<<<<<<<<<<<<<<\n"); - if (globals.focus_win && globals.focus_win->button) { - globals.focus_win->manager->focus_button = globals.focus_win->button; - } - globals.got_window_list = 1; - for (i = 0; i < globals.num_managers; i++) { - create_manager_window (i); - } - break; - - case M_NEW_DESK: - ConsoleDebug (FVWM, "DEBUG::M_NEW_DESK\n"); - new_desk (body); - break; - - case M_NEW_PAGE: - ConsoleDebug (FVWM, "DEBUG::M_NEW_PAGE\n"); - if (globals.x == body->new_page_data.x && - globals.y == body->new_page_data.y && - globals.desknum == body->new_page_data.desknum) { - ConsoleDebug (FVWM, "Useless NEW_PAGE received\n"); - break; - } - globals.x = body->new_page_data.x; - globals.y = body->new_page_data.y; - globals.desknum = body->new_page_data.desknum; - for (i = 0; i < globals.num_managers; i++) { - set_draw_mode (&globals.managers[i], 0); - } - break; - - case M_STRING: - ConsoleDebug (FVWM, "DEBUG::M_STRING\n"); - sendtomodule (body); - break; - - default: - break; - } - - check_managers_consistency(); - - for (i = 0; i < globals.num_managers; i++) { - if (drawing (&globals.managers[i])) - draw_manager (&globals.managers[i]); - } - - check_managers_consistency(); + case M_WINDOW_NAME: + ConsoleDebug(FVWM, "DEBUG::M_WINDOW_NAME\n"); + window_name(body); + break; + + case M_ICON_NAME: + ConsoleDebug(FVWM, "DEBUG::M_ICON_NAME\n"); + icon_name(body); + break; + + case M_DEICONIFY: + ConsoleDebug(FVWM, "DEBUG::M_DEICONIFY\n"); + iconify(body, 0); + break; + + case M_ICONIFY: + ConsoleDebug(FVWM, "DEBUG::M_ICONIFY\n"); + iconify(body, 1); + break; + + case M_END_WINDOWLIST: + ConsoleDebug(FVWM, "DEBUG::M_END_WINDOWLIST\n"); + ConsoleDebug(FVWM, + ">>>>>>>>>>>>>>>>>>>>>>>End window list<<<<<<<<<<<<<<<\n"); + if (globals.focus_win && globals.focus_win->button) { + globals.focus_win->manager->focus_button = + globals.focus_win->button; + } + globals.got_window_list = 1; + for (i = 0; i < globals.num_managers; i++) { + create_manager_window(i); + } + break; + + case M_NEW_DESK: + ConsoleDebug(FVWM, "DEBUG::M_NEW_DESK\n"); + new_desk(body); + break; + + case M_NEW_PAGE: + ConsoleDebug(FVWM, "DEBUG::M_NEW_PAGE\n"); + if (globals.x == body->new_page_data.x && + globals.y == body->new_page_data.y && + globals.desknum == body->new_page_data.desknum) { + ConsoleDebug(FVWM, "Useless NEW_PAGE received\n"); + break; + } + globals.x = body->new_page_data.x; + globals.y = body->new_page_data.y; + globals.desknum = body->new_page_data.desknum; + for (i = 0; i < globals.num_managers; i++) { + set_draw_mode(&globals.managers[i], 0); + } + break; + + case M_STRING: + ConsoleDebug(FVWM, "DEBUG::M_STRING\n"); + sendtomodule(body); + break; + + default: + break; + } + + check_managers_consistency(); + + for (i = 0; i < globals.num_managers; i++) { + if (drawing(&globals.managers[i])) + draw_manager(&globals.managers[i]); + } + + check_managers_consistency(); } -void ReadFvwmPipe (void) +void +ReadFvwmPipe(void) { - int body_length; - FvwmPacketHeader header; - FvwmPacketBody *body; - - PrintMemuse(); - - ConsoleDebug(FVWM, "DEBUG: entering ReadFvwmPipe\n"); - body_length = ReadFvwmPacket(Fvwm_fd[1], (unsigned long *) &header, - (unsigned long **)&body); - body_length -= HEADER_SIZE; - if (header.start == START_FLAG) { - ProcessMessage (header.type, body); - if (body_length) { - Free (body); - } - } - else { - DeadPipe (1); - } - ConsoleDebug(FVWM, "DEBUG: leaving ReadFvwmPipe\n"); + int body_length; + FvwmPacketHeader header; + FvwmPacketBody *body; + + PrintMemuse(); + + ConsoleDebug(FVWM, "DEBUG: entering ReadFvwmPipe\n"); + body_length = ReadFvwmPacket( + Fvwm_fd[1], (unsigned long *)&header, (unsigned long **)&body); + body_length -= HEADER_SIZE; + if (header.start == START_FLAG) { + ProcessMessage(header.type, body); + if (body_length) { + Free(body); + } + } else { + DeadPipe(1); + } + ConsoleDebug(FVWM, "DEBUG: leaving ReadFvwmPipe\n"); } Index: fvwm/modules/FvwmIconMan/globals.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIconMan/globals.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIconMan/globals.c --- fvwm/modules/FvwmIconMan/globals.c +++ fvwm/modules/FvwmIconMan/globals.c @@ -1,155 +1,151 @@ #include + #include "FvwmIconMan.h" -#include "xmanager.h" #include "readconfig.h" +#include "xmanager.h" #define DEFAULT_MOUSE "0 N sendcommand Iconify" static char const rcsid[] = - "$Id: globals.c,v 1.1.1.1 2006/11/26 10:53:49 matthieu Exp $"; + "$Id: globals.c,v 1.1.1.1 2006/11/26 10:53:49 matthieu Exp $"; GlobalData globals; ContextDefaults contextDefaults[] = { - { "plain", BUTTON_UP, { "black", "black" }, { "white", "gray"} }, - { "focus", BUTTON_UP, { "white", "gray" }, { "black", "black" } }, - { "select", BUTTON_FLAT, { "black", "black" }, { "white", "gray" } }, - { "focusandselect", BUTTON_FLAT, { "white", "gray" }, { "black", "black" } }, - { "title", BUTTON_EDGEUP, { "black", "black"}, {"white", "gray"} } -}; + {"plain", BUTTON_UP, {"black", "black"}, {"white", "gray"}}, + {"focus", BUTTON_UP, {"white", "gray"}, {"black", "black"}}, + {"select", BUTTON_FLAT, {"black", "black"}, {"white", "gray"}}, + {"focusandselect", BUTTON_FLAT, {"white", "gray"}, {"black", "black"}}, + {"title", BUTTON_EDGEUP, {"black", "black"}, {"white", "gray"}}}; int Fvwm_fd[2]; int x_fd; char *Module = "*FvwmIconMan"; int ModuleLen = 12; -/* This is solely so that we can turn a string constant into something - which can be freed */ - -static char *alloc_string (char *string) +static void +init_win_manager(int id) { - int len = strlen (string); - char *ret = (char *)safemalloc ((len + 1) * sizeof (char)); - strcpy (ret, string); - return ret; -} - -static void init_win_manager (int id) -{ - int i; + int i; - globals.managers[id].magic = 0x12344321; - globals.managers[id].index = id; + globals.managers[id].magic = 0x12344321; + globals.managers[id].index = id; #ifdef MINI_ICONS - globals.managers[id].draw_icons = 0; + globals.managers[id].draw_icons = 0; #endif - globals.managers[id].res = SHOW_PAGE; - globals.managers[id].window_up = 0; - globals.managers[id].can_draw = 0; - globals.managers[id].window_mapped = 0; - globals.managers[id].fontname = NULL; - globals.managers[id].titlename = alloc_string ("FvwmIconMan"); - globals.managers[id].iconname = alloc_string ("FvwmIconMan"); - globals.managers[id].formatstring = alloc_string ("%c: %i"); - globals.managers[id].format_depend = CLASS_NAME | ICON_NAME; - globals.managers[id].geometry.dir = 0; - globals.managers[id].geometry.boxwidth = 0; + globals.managers[id].res = SHOW_PAGE; + globals.managers[id].window_up = 0; + globals.managers[id].can_draw = 0; + globals.managers[id].window_mapped = 0; + globals.managers[id].fontname = NULL; + globals.managers[id].titlename = xstrdup("FvwmIconMan"); + globals.managers[id].iconname = xstrdup("FvwmIconMan"); + globals.managers[id].formatstring = xstrdup("%c: %i"); + globals.managers[id].format_depend = CLASS_NAME | ICON_NAME; + globals.managers[id].geometry.dir = 0; + globals.managers[id].geometry.boxwidth = 0; #ifdef SHAPE - globals.managers[id].shape.num_rects = 0; + globals.managers[id].shape.num_rects = 0; #endif - globals.managers[id].shaped = 0; - init_button_array (&globals.managers[id].buttons); - - for ( i = 0; i < NUM_CONTEXTS; i++ ) { - globals.managers[id].backColorName[i] = NULL; - globals.managers[id].foreColorName[i] = NULL; - globals.managers[id].buttonState[i] = contextDefaults[i].state; - } - globals.managers[id].geometry_str = NULL; - globals.managers[id].button_geometry_str = NULL; - globals.managers[id].show.list = NULL; - globals.managers[id].show.mask = ALL_NAME; - globals.managers[id].dontshow.list = NULL; - globals.managers[id].dontshow.mask = ALL_NAME; - globals.managers[id].followFocus = 0; - globals.managers[id].usewinlist = 1; - globals.managers[id].sort = SortName; - globals.managers[id].focus_button = NULL; - globals.managers[id].select_button = NULL; - globals.managers[id].bindings[MOUSE] = ParseMouseEntry (DEFAULT_MOUSE); - globals.managers[id].bindings[KEYPRESS] = NULL; - globals.managers[id].bindings[SELECT] = NULL; - globals.managers[id].we_are_drawing = 1; - globals.managers[id].configures_expected = 0; + globals.managers[id].shaped = 0; + init_button_array(&globals.managers[id].buttons); + + for (i = 0; i < NUM_CONTEXTS; i++) { + globals.managers[id].backColorName[i] = NULL; + globals.managers[id].foreColorName[i] = NULL; + globals.managers[id].buttonState[i] = contextDefaults[i].state; + } + globals.managers[id].geometry_str = NULL; + globals.managers[id].button_geometry_str = NULL; + globals.managers[id].show.list = NULL; + globals.managers[id].show.mask = ALL_NAME; + globals.managers[id].dontshow.list = NULL; + globals.managers[id].dontshow.mask = ALL_NAME; + globals.managers[id].followFocus = 0; + globals.managers[id].usewinlist = 1; + globals.managers[id].sort = SortName; + globals.managers[id].focus_button = NULL; + globals.managers[id].select_button = NULL; + globals.managers[id].bindings[MOUSE] = ParseMouseEntry(DEFAULT_MOUSE); + globals.managers[id].bindings[KEYPRESS] = NULL; + globals.managers[id].bindings[SELECT] = NULL; + globals.managers[id].we_are_drawing = 1; + globals.managers[id].configures_expected = 0; } -void print_managers (void) +void +print_managers(void) { #ifdef PRINT_DEBUG - int i; - - for (i = 0; i < globals.num_managers; i++) { - ConsoleDebug (CORE, "Manager %d:\n", i + 1); - if (globals.managers[i].res == SHOW_GLOBAL) - ConsoleDebug (CORE, "ShowGlobal\n"); - else if (globals.managers[i].res == SHOW_DESKTOP) - ConsoleDebug (CORE, "ShowDesktop\n"); - else if (globals.managers[i].res == SHOW_PAGE) - ConsoleDebug (CORE, "ShowPage\n"); - - ConsoleDebug (CORE, "DontShow:\n"); - print_stringlist (&globals.managers[i].dontshow); - ConsoleDebug (CORE, "Show:\n"); - print_stringlist (&globals.managers[i].show); - - ConsoleDebug (CORE, "Font: %s\n", (globals.managers[i].fontname)? - globals.managers[i].fontname : "(NULL)"); - ConsoleDebug (CORE, "Geometry: %s\n", globals.managers[i].geometry_str); - ConsoleDebug (CORE, "Button geometry: %s\n", - (globals.managers[i].button_geometry_str)? - globals.managers[i].button_geometry_str : "(NULL)"); - ConsoleDebug (CORE, "\n"); - } + int i; + + for (i = 0; i < globals.num_managers; i++) { + ConsoleDebug(CORE, "Manager %d:\n", i + 1); + if (globals.managers[i].res == SHOW_GLOBAL) + ConsoleDebug(CORE, "ShowGlobal\n"); + else if (globals.managers[i].res == SHOW_DESKTOP) + ConsoleDebug(CORE, "ShowDesktop\n"); + else if (globals.managers[i].res == SHOW_PAGE) + ConsoleDebug(CORE, "ShowPage\n"); + + ConsoleDebug(CORE, "DontShow:\n"); + print_stringlist(&globals.managers[i].dontshow); + ConsoleDebug(CORE, "Show:\n"); + print_stringlist(&globals.managers[i].show); + + ConsoleDebug(CORE, "Font: %s\n", + (globals.managers[i].fontname) ? + globals.managers[i].fontname : + "(NULL)"); + ConsoleDebug( + CORE, "Geometry: %s\n", globals.managers[i].geometry_str); + ConsoleDebug(CORE, "Button geometry: %s\n", + (globals.managers[i].button_geometry_str) ? + globals.managers[i].button_geometry_str : + "(NULL)"); + ConsoleDebug(CORE, "\n"); + } #endif - } -int allocate_managers (int num) +int +allocate_managers(int num) { - int i; + int i; - if (globals.managers) { - ConsoleMessage ("Already have set the number of managers\n"); - return 0; - } + if (globals.managers) { + ConsoleMessage("Already have set the number of managers\n"); + return 0; + } - if (num < 1) { - ConsoleMessage ("Can't have %d managers\n", num); - return 0; - } + if (num < 1) { + ConsoleMessage("Can't have %d managers\n", num); + return 0; + } - globals.num_managers = num; - globals.managers = (WinManager *)safemalloc (num * sizeof (WinManager)); + globals.num_managers = num; + globals.managers = (WinManager *)xmalloc(num * sizeof(WinManager)); - for (i = 0; i < num; i++) { - init_win_manager (i); - } + for (i = 0; i < num; i++) { + init_win_manager(i); + } - return 1; + return 1; } -void init_globals (void) +void +init_globals(void) { - globals.desknum = ULONG_MAX; - globals.x = ULONG_MAX; - globals.y = ULONG_MAX; - globals.screenx = 0; - globals.screeny = 0; - globals.num_managers = 1; - globals.managers = NULL; - globals.focus_win = NULL; - globals.select_win = NULL; - globals.transient = 0; - globals.shapes_supported = 0; - globals.got_window_list = 0; + globals.desknum = ULONG_MAX; + globals.x = ULONG_MAX; + globals.y = ULONG_MAX; + globals.screenx = 0; + globals.screeny = 0; + globals.num_managers = 1; + globals.managers = NULL; + globals.focus_win = NULL; + globals.select_win = NULL; + globals.transient = 0; + globals.shapes_supported = 0; + globals.got_window_list = 0; } Index: fvwm/modules/FvwmIconMan/readconfig.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIconMan/readconfig.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIconMan/readconfig.c --- fvwm/modules/FvwmIconMan/readconfig.c +++ fvwm/modules/FvwmIconMan/readconfig.c @@ -1,10 +1,12 @@ +#include "readconfig.h" + #include #include + #include "FvwmIconMan.h" -#include "readconfig.h" static char const rcsid[] = - "$Id: readconfig.c,v 1.1.1.1 2006/11/26 10:53:50 matthieu Exp $"; + "$Id: readconfig.c,v 1.1.1.1 2006/11/26 10:53:50 matthieu Exp $"; /************************************************************************ * @@ -12,262 +14,251 @@ static char const rcsid[] = * ************************************************************************/ -extern int builtin_quit (int numargs, BuiltinArg *args); -extern int builtin_printdebug (int numargs, BuiltinArg *args); -extern int builtin_gotobutton (int numargs, BuiltinArg *args); -extern int builtin_gotomanager (int numargs, BuiltinArg *args); -extern int builtin_refresh (int numargs, BuiltinArg *args); -extern int builtin_select (int numargs, BuiltinArg *args); -extern int builtin_sendcommand (int numargs, BuiltinArg *args); -extern int builtin_bif (int numargs, BuiltinArg *args); -extern int builtin_bifn (int numargs, BuiltinArg *args); -extern int builtin_print (int numargs, BuiltinArg *args); -extern int builtin_jmp (int numargs, BuiltinArg *args); -extern int builtin_ret (int numargs, BuiltinArg *args); -extern int builtin_searchforward (int numargs, BuiltinArg *args); -extern int builtin_searchback (int numargs, BuiltinArg *args); -extern int builtin_warp (int numargs, BuiltinArg *args); +extern int builtin_quit(int numargs, BuiltinArg *args); +extern int builtin_printdebug(int numargs, BuiltinArg *args); +extern int builtin_gotobutton(int numargs, BuiltinArg *args); +extern int builtin_gotomanager(int numargs, BuiltinArg *args); +extern int builtin_refresh(int numargs, BuiltinArg *args); +extern int builtin_select(int numargs, BuiltinArg *args); +extern int builtin_sendcommand(int numargs, BuiltinArg *args); +extern int builtin_bif(int numargs, BuiltinArg *args); +extern int builtin_bifn(int numargs, BuiltinArg *args); +extern int builtin_print(int numargs, BuiltinArg *args); +extern int builtin_jmp(int numargs, BuiltinArg *args); +extern int builtin_ret(int numargs, BuiltinArg *args); +extern int builtin_searchforward(int numargs, BuiltinArg *args); +extern int builtin_searchback(int numargs, BuiltinArg *args); +extern int builtin_warp(int numargs, BuiltinArg *args); /* compiler pseudo-functions */ -static int builtin_label (int numargs, BuiltinArg *args); +static int builtin_label(int numargs, BuiltinArg *args); typedef struct { - char *name; - int (*func)(int numargs, BuiltinArg *args); - int numargs; - BuiltinArgType args[MAX_ARGS]; + char *name; + int (*func)(int numargs, BuiltinArg *args); + int numargs; + BuiltinArgType args[MAX_ARGS]; } FunctionType; /* * these are now sorted so we can use bsearch on them. */ FunctionType builtin_functions[] = { - { "bif", builtin_bif, 2, { ButtonArg, JmpArg } }, - { "bifn", builtin_bifn, 2, { ButtonArg, JmpArg } }, - { "gotobutton", builtin_gotobutton, 1, { ButtonArg } }, - { "gotomanager", builtin_gotomanager, 1, { ManagerArg } }, - { "jmp", builtin_jmp, 1, { JmpArg } }, - { "label", builtin_label, 1, { StringArg } }, - { "print", builtin_print, 1, { StringArg } }, - { "printdebug", builtin_printdebug, 0 }, - { "quit", builtin_quit, 0 }, - { "refresh", builtin_refresh, 0 }, - { "ret", builtin_ret, 0 }, - { "searchback", builtin_searchback, 1, { StringArg } }, - { "searchforward", builtin_searchforward, 1, { StringArg } }, - { "select", builtin_select, 0 }, - { "sendcommand", builtin_sendcommand, 1, { StringArg } }, - { "warp", builtin_warp, 0 } -}; - -static int num_builtins = sizeof (builtin_functions) / sizeof (FunctionType); + {"bif", builtin_bif, 2, {ButtonArg, JmpArg}}, + {"bifn", builtin_bifn, 2, {ButtonArg, JmpArg}}, + {"gotobutton", builtin_gotobutton, 1, {ButtonArg}}, + {"gotomanager", builtin_gotomanager, 1, {ManagerArg}}, + {"jmp", builtin_jmp, 1, {JmpArg}}, {"label", builtin_label, 1, {StringArg}}, + {"print", builtin_print, 1, {StringArg}}, + {"printdebug", builtin_printdebug, 0}, {"quit", builtin_quit, 0}, + {"refresh", builtin_refresh, 0}, {"ret", builtin_ret, 0}, + {"searchback", builtin_searchback, 1, {StringArg}}, + {"searchforward", builtin_searchforward, 1, {StringArg}}, + {"select", builtin_select, 0}, + {"sendcommand", builtin_sendcommand, 1, {StringArg}}, + {"warp", builtin_warp, 0}}; + +static int num_builtins = sizeof(builtin_functions) / sizeof(FunctionType); /************************************************************************/ - -struct charstring -{ - char key; - int value; +struct charstring { + char key; + int value; }; -struct charstring key_modifiers[]= -{ - {'s',ShiftMask}, - {'c',ControlMask}, - {'m',Mod1Mask}, - {'1',Mod1Mask}, - {'2',Mod2Mask}, - {'3',Mod3Mask}, - {'4',Mod4Mask}, - {'5',Mod5Mask}, - {'a',AnyModifier}, - {'n',0}, - {0,0} -}; +struct charstring key_modifiers[] = {{'s', ShiftMask}, {'c', ControlMask}, + {'m', Mod1Mask}, {'1', Mod1Mask}, {'2', Mod2Mask}, {'3', Mod3Mask}, + {'4', Mod4Mask}, {'5', Mod5Mask}, {'a', AnyModifier}, {'n', 0}, {0, 0}}; #if FVWM_VERSION == 1 static FILE *config_fp = NULL; #endif - /* This is only used for printing out the .fvwmrc line if an error occured */ #define PRINT_LINE_LENGTH 80 static char current_line[PRINT_LINE_LENGTH]; -static void save_current_line (char *s) +static void +save_current_line(char *s) { - char *p = current_line; - - while (*s && p < current_line + PRINT_LINE_LENGTH - 1) { - if (*s == '\n') { - *p = '\0'; - return; - } - else { - *p++ = *s++; - } - } - *p = '\0'; + char *p = current_line; + + while (*s && p < current_line + PRINT_LINE_LENGTH - 1) { + if (*s == '\n') { + *p = '\0'; + return; + } else { + *p++ = *s++; + } + } + *p = '\0'; } -void print_args (int numargs, BuiltinArg *args) +void +print_args(int numargs, BuiltinArg *args) { #ifdef PRINT_DEBUG - int i; - - for (i = 0; i < numargs; i++) { - switch (args[i].type) { - case NoArg: - ConsoleDebug (CONFIG, "NoArg "); - break; - - case IntArg: - ConsoleDebug (CONFIG, "Int: %d ", args[i].value.int_value); - break; - - case StringArg: - ConsoleDebug (CONFIG, "String: %s ", args[i].value.string_value); - break; - - case ButtonArg: - ConsoleDebug (CONFIG, "Button: %d %d ", - args[i].value.button_value.offset, - args[i].value.button_value.base); - break; - - case WindowArg: - ConsoleDebug (CONFIG, "Window: %d %d ", - args[i].value.button_value.offset, - args[i].value.button_value.base); - break; - - case ManagerArg: - ConsoleDebug (CONFIG, "Manager: %d %d ", - args[i].value.button_value.offset, - args[i].value.button_value.base); - break; - - case JmpArg: - ConsoleDebug (CONFIG, "Unprocessed Label Jump: %s ", - args[i].value.string_value); - break; - - default: - ConsoleDebug (CONFIG, "bad "); - break; - } - } - ConsoleDebug (CONFIG, "\n"); + int i; + + for (i = 0; i < numargs; i++) { + switch (args[i].type) { + case NoArg: + ConsoleDebug(CONFIG, "NoArg "); + break; + + case IntArg: + ConsoleDebug( + CONFIG, "Int: %d ", args[i].value.int_value); + break; + + case StringArg: + ConsoleDebug( + CONFIG, "String: %s ", args[i].value.string_value); + break; + + case ButtonArg: + ConsoleDebug(CONFIG, "Button: %d %d ", + args[i].value.button_value.offset, + args[i].value.button_value.base); + break; + + case WindowArg: + ConsoleDebug(CONFIG, "Window: %d %d ", + args[i].value.button_value.offset, + args[i].value.button_value.base); + break; + + case ManagerArg: + ConsoleDebug(CONFIG, "Manager: %d %d ", + args[i].value.button_value.offset, + args[i].value.button_value.base); + break; + + case JmpArg: + ConsoleDebug(CONFIG, "Unprocessed Label Jump: %s ", + args[i].value.string_value); + break; + + default: + ConsoleDebug(CONFIG, "bad "); + break; + } + } + ConsoleDebug(CONFIG, "\n"); #endif } #ifdef PRINT_DEBUG -static void print_binding (Binding *binding) +static void +print_binding(Binding *binding) { - int i; - Function *func; - - if (binding->IsMouse) { - ConsoleDebug (CONFIG, "\tMouse: %d\n", binding->Button_Key); - } - else { - ConsoleDebug (CONFIG, "\tKey or action: %d %s\n", binding->Button_Key, - binding->key_name); - } - - ConsoleDebug (CONFIG, "\tModifiers: %d\n", binding->Modifier); - ConsoleDebug (CONFIG, "\tAction: %s\n", binding->Action); - ConsoleDebug (CONFIG, "\tFunction struct: %p\n", binding->Function); - func = binding->Function; - while (func) { - for (i = 0; i < num_builtins; i++) { - if (func->func == builtin_functions[i].func) { - ConsoleDebug (CONFIG, "\tFunction: %s %p ", - builtin_functions[i].name, func->func); - break; - } - } - if (i > num_builtins) { - ConsoleDebug (CONFIG, "\tFunction: not found %p ", func->func); - } - print_args (func->numargs, func->args); - func = func->next; - } + int i; + Function *func; + + if (binding->IsMouse) { + ConsoleDebug(CONFIG, "\tMouse: %d\n", binding->Button_Key); + } else { + ConsoleDebug(CONFIG, "\tKey or action: %d %s\n", + binding->Button_Key, binding->key_name); + } + + ConsoleDebug(CONFIG, "\tModifiers: %d\n", binding->Modifier); + ConsoleDebug(CONFIG, "\tAction: %s\n", binding->Action); + ConsoleDebug(CONFIG, "\tFunction struct: %p\n", binding->Function); + func = binding->Function; + while (func) { + for (i = 0; i < num_builtins; i++) { + if (func->func == builtin_functions[i].func) { + ConsoleDebug(CONFIG, "\tFunction: %s %p ", + builtin_functions[i].name, func->func); + break; + } + } + if (i > num_builtins) { + ConsoleDebug( + CONFIG, "\tFunction: not found %p ", func->func); + } + print_args(func->numargs, func->args); + func = func->next; + } } -#endif +#endif -void print_bindings (Binding *list) +void +print_bindings(Binding *list) { #ifdef PRINT_DEBUG - ConsoleDebug (CONFIG, "binding list:\n"); - while (list != NULL) { - print_binding (list); - ConsoleDebug (CONFIG, "\n"); - list = list->NextBinding; - } + ConsoleDebug(CONFIG, "binding list:\n"); + while (list != NULL) { + print_binding(list); + ConsoleDebug(CONFIG, "\n"); + list = list->NextBinding; + } #endif } -static int iswhite (char c) +static int +iswhite(char c) { - if (c == ' ' || c == '\t' || c == '\0') - return 1; - return 0; + if (c == ' ' || c == '\t' || c == '\0') + return 1; + return 0; } -static void skip_space (char **p) +static void +skip_space(char **p) { - while (**p == ' ' || **p == '\t') - (*p)++; + while (**p == ' ' || **p == '\t') + (*p)++; } -static void add_to_binding (Binding **list, Binding *binding) +static void +add_to_binding(Binding **list, Binding *binding) { - ConsoleDebug (CONFIG, "In add_to_binding:\n"); - - if (*list == NULL) { - *list = binding; - } - else { - binding->LastBinding->NextBinding = *list; - *list = binding; - } + ConsoleDebug(CONFIG, "In add_to_binding:\n"); + + if (*list == NULL) { + *list = binding; + } else { + binding->LastBinding->NextBinding = *list; + *list = binding; + } } -static int extract_int (char *p, int *n) +static int +extract_int(char *p, int *n) { - char *s; - int sign = 1; - - while (isspace (*p) && *p) - p++; - - if (*p == '-') { - sign = -1; - p++; - } - else if (*p == '+') { - sign = 1; - p++; - } - - if (*p == '\0') { - return 0; - } - - for (s = p; *s; s++) { - if (*s < '0' || *s > '9') { - return 0; - } - } - - *n = atoi (p) * sign; - - return 1; -} + char *s; + int sign = 1; + + while (isspace(*p) && *p) + p++; + + if (*p == '-') { + sign = -1; + p++; + } else if (*p == '+') { + sign = 1; + p++; + } + + if (*p == '\0') { + return 0; + } + + for (s = p; *s; s++) { + if (*s < '0' || *s > '9') { + return 0; + } + } + + *n = atoi(p) * sign; + + return 1; +} /**************************************************************************** * @@ -275,1315 +266,1449 @@ static int extract_int (char *p, int *n) * "word" is a string with no spaces, or a qouted string. * Return value is ptr to indata,updated to point to text after the word * which is extracted. - * token is the extracted word, which is copied into a malloced - * space, and must be freed after use. + * The token is the extracted word, which is copied into a malloced + * space, and must be freed after use. * **************************************************************************/ -static void find_context(char *string, int *output, struct charstring *table, - char *tline) +static void +find_context(char *string, int *output, struct charstring *table, char *tline) { - int i=0,j=0; - Bool matched; - char tmp1; - - *output=0; - i=0; - while(itype = ButtonArg; - bv = &arg->value.button_value; - bv->offset = 0; - bv->base = AbsoluteButton; - - rest = DoGetNextToken (string, &token, NULL, ",", pstop_char); - if (token == NULL) { - bv->base = NoButton; - *flag = 0; - Free(token); - return NULL; - } - if (!strcasecmp (token, "focus")) { - bv->base = FocusButton; - } - else if (!strcasecmp (token, "select")) { - bv->base = SelectButton; - } - else if (!strcasecmp (token, "up")) { - bv->base = UpButton; - } - else if (!strcasecmp (token, "down")) { - bv->base = DownButton; - } - else if (!strcasecmp (token, "left")) { - bv->base = LeftButton; - } - else if (!strcasecmp (token, "right")) { - bv->base = RightButton; - } - else if (!strcasecmp (token, "next")) { - bv->base = NextButton; - } - else if (!strcasecmp (token, "prev")) { - bv->base = PrevButton; - } - else if (extract_int (token, &n)) { - bv->base = AbsoluteButton; - bv->offset = n; - } - else { - ConsoleMessage ("Bad button: %s\n", token); - bv->base = NoButton; - Free (token); - *flag = 0; - return NULL; - } - - Free (token); - return rest; + char *rest, *token; + ButtonValue *bv; + int n; + + ConsoleDebug(CONFIG, "parse_term: %s\n", string); + + *flag = 1; + + arg->type = ButtonArg; + bv = &arg->value.button_value; + bv->offset = 0; + bv->base = AbsoluteButton; + + rest = DoGetNextToken(string, &token, NULL, ",", pstop_char); + if (token == NULL) { + bv->base = NoButton; + *flag = 0; + Free(token); + return NULL; + } + if (!strcasecmp(token, "focus")) { + bv->base = FocusButton; + } else if (!strcasecmp(token, "select")) { + bv->base = SelectButton; + } else if (!strcasecmp(token, "up")) { + bv->base = UpButton; + } else if (!strcasecmp(token, "down")) { + bv->base = DownButton; + } else if (!strcasecmp(token, "left")) { + bv->base = LeftButton; + } else if (!strcasecmp(token, "right")) { + bv->base = RightButton; + } else if (!strcasecmp(token, "next")) { + bv->base = NextButton; + } else if (!strcasecmp(token, "prev")) { + bv->base = PrevButton; + } else if (extract_int(token, &n)) { + bv->base = AbsoluteButton; + bv->offset = n; + } else { + ConsoleMessage("Bad button: %s\n", token); + bv->base = NoButton; + Free(token); + *flag = 0; + return NULL; + } + + Free(token); + return rest; } -static void free_function_list (Function *func) +static void +free_function_list(Function *func) { - int i; - Function *fp = func; - - while (fp) { - for (i = 0; i < fp->numargs; i++) { - if (fp->args[i].type == StringArg) - Free (fp->args[i].value.string_value); - } - func = fp; - fp = fp->next; - Free (func); - } + int i; + Function *fp = func; + + while (fp) { + for (i = 0; i < fp->numargs; i++) { + if (fp->args[i].type == StringArg) + Free(fp->args[i].value.string_value); + } + func = fp; + fp = fp->next; + Free(func); + } } - -static int funccasecmp(const void *key /* actually char* */, - const void *member /* actually FunctionType* */) + +static int +funccasecmp(const void *key /* actually char* */, + const void *member /* actually FunctionType* */) { - return strcasecmp((char *)key, ((FunctionType *)member)->name); + return strcasecmp((char *)key, ((FunctionType *)member)->name); } /* * The label function. Should never be called, but we need a pointer to it, * and it's useful for debugging purposes to have it defined. */ -static int builtin_label (int numargs, BuiltinArg *args) { - int j; - /* we should _never_ be called */ - ConsoleMessage ( "label" ); - for (j=0; jfunc = builtin_functions_i->func; - ftype->numargs = builtin_functions_i->numargs; - ftype->next = NULL; - - for (j = 0; j < builtin_functions_i->numargs && *pstop_char != ','; j++) { - ftype->args[j].type = builtin_functions_i->args[j]; - switch (builtin_functions_i->args[j]) { - case IntArg: - ptr = DoGetNextToken (ptr, &tok, NULL, ",", pstop_char); - if (!tok) { - ConsoleMessage ("%s: too few arguments\n", - builtin_functions_i->name); - Free(ftype); - *line = NULL; - return NULL; - } - if (extract_int (tok, &ftype->args[j].value.int_value) == 0) { - ConsoleMessage ("%s: expect integer argument: %s\n", - builtin_functions_i->name, tok); - Free (tok); - Free(ftype); - *line = NULL; - return NULL; - } - Free (tok); - break; - - case StringArg: - ptr = DoGetNextToken (ptr, &ftype->args[j].value.string_value,NULL, - ",", pstop_char); - if (!ftype->args[j].value.string_value) { - ConsoleMessage ("%s: too few arguments\n", - builtin_functions_i->name); - *line = NULL; - Free(ftype->args[j].value.string_value); - Free(ftype); - return NULL; - } - ftype->args[j].type = builtin_functions_i->args[j]; - break; - - case ButtonArg: - case WindowArg: - case ManagerArg: - ptr = parse_button (ptr, &ftype->args[j], &flag, pstop_char); - if (!flag) { - ConsoleMessage ("%s: too few arguments\n", - builtin_functions_i->name); - Free(ftype); - *line = NULL; - return NULL; - } - ftype->args[j].type = builtin_functions_i->args[j]; - break; - - /* JmpArg can be a string or an int. However, if 'JmpArg' - * is recorded as the argument type in the argument array - * for a command, it means it is a string; the code for - * 'IntArg' is used instead for numbers. Note also that - * if the C function recieves a 'JmpArg' argument it means something - * went wrong, since they should all be translated to integer - * jump offsets at compile time. - */ - case JmpArg: - ptr = DoGetNextToken (ptr, &tok, NULL, ",", pstop_char); - if (!tok) { - ConsoleMessage ("%s: too few arguments\n", - builtin_functions_i->name); - Free(tok); - Free(ftype); - *line=NULL; - return NULL; - } - if (extract_int(tok, &ftype->args[j].value.int_value) == 0) { - ftype->args[j].value.string_value=tok; - ftype->args[j].type = JmpArg; - ++JmpArgs; - } else { - ftype->args[j].type = IntArg; - Free(tok); - } - break; - - default: - ConsoleMessage ("internal error in parse_function\n"); - Free(ftype); + Function *ftype = (Function *)xmalloc(sizeof(Function)); + char *ptr, *name, *tok; + int j, flag; + FunctionType *builtin_functions_i; + + ConsoleDebug(CONFIG, "in parse_function\n"); + + ptr = DoGetNextToken(*line, &name, NULL, ",", pstop_char); + if (name == NULL) { + Free(ftype); + *line = NULL; + return NULL; + } + + builtin_functions_i = bsearch((void *)name, (void *)builtin_functions, + num_builtins, sizeof(FunctionType), funccasecmp); + if (builtin_functions_i) { + Free(name); + ftype->func = builtin_functions_i->func; + ftype->numargs = builtin_functions_i->numargs; + ftype->next = NULL; + + for (j = 0; + j < builtin_functions_i->numargs && *pstop_char != ','; + j++) { + ftype->args[j].type = builtin_functions_i->args[j]; + switch (builtin_functions_i->args[j]) { + case IntArg: + ptr = DoGetNextToken( + ptr, &tok, NULL, ",", pstop_char); + if (!tok) { + ConsoleMessage( + "%s: too few arguments\n", + builtin_functions_i->name); + Free(ftype); + *line = NULL; + return NULL; + } + if (extract_int(tok, + &ftype->args[j].value.int_value) == 0) { + ConsoleMessage( + "%s: expect integer argument: %s\n", + builtin_functions_i->name, tok); + Free(tok); + Free(ftype); + *line = NULL; + return NULL; + } + Free(tok); + break; + + case StringArg: + ptr = DoGetNextToken(ptr, + &ftype->args[j].value.string_value, NULL, + ",", pstop_char); + if (!ftype->args[j].value.string_value) { + ConsoleMessage( + "%s: too few arguments\n", + builtin_functions_i->name); + *line = NULL; + Free(ftype->args[j].value.string_value); + Free(ftype); + return NULL; + } + ftype->args[j].type = + builtin_functions_i->args[j]; + break; + + case ButtonArg: + case WindowArg: + case ManagerArg: + ptr = parse_button( + ptr, &ftype->args[j], &flag, pstop_char); + if (!flag) { + ConsoleMessage( + "%s: too few arguments\n", + builtin_functions_i->name); + Free(ftype); + *line = NULL; + return NULL; + } + ftype->args[j].type = + builtin_functions_i->args[j]; + break; + + /* JmpArg can be a string or an int. However, if + * 'JmpArg' is recorded as the argument type in + * the argument array for a command, it means it + * is a string; the code for 'IntArg' is used + * instead for numbers. Note also that if the C + * function recieves a 'JmpArg' argument it + * means something went wrong, since they should + * all be translated to integer jump offsets at + * compile time. + */ + case JmpArg: + ptr = DoGetNextToken( + ptr, &tok, NULL, ",", pstop_char); + if (!tok) { + ConsoleMessage( + "%s: too few arguments\n", + builtin_functions_i->name); + Free(tok); + Free(ftype); + *line = NULL; + return NULL; + } + if (extract_int(tok, + &ftype->args[j].value.int_value) == 0) { + ftype->args[j].value.string_value = tok; + ftype->args[j].type = JmpArg; + ++JmpArgs; + } else { + ftype->args[j].type = IntArg; + Free(tok); + } + break; + + default: + ConsoleMessage( + "internal error in parse_function\n"); + Free(ftype); + *line = NULL; + return NULL; + } + } + + if (j != builtin_functions_i->numargs) { + ConsoleMessage("%s: too few arguments\n", + builtin_functions_i->name); + Free(ftype); + *line = NULL; + return NULL; + } + + *line = ptr; + return ftype; + } + + ConsoleMessage("Unknown function: %s\n", name); + Free(name); + *line = NULL; return NULL; - } - } - - if (j != builtin_functions_i->numargs) { - ConsoleMessage ("%s: too few arguments\n", builtin_functions_i->name); - Free(ftype); - *line = NULL; - return NULL; - } - - *line = ptr; - return ftype; - } - - ConsoleMessage ("Unknown function: %s\n", name); - Free (name); - - *line = NULL; - return NULL; } - /* This is O(N^2) where N = number of instructions. Seems we could do better. We'll see how this addition settles before monkeying with it */ -static Function *parse_function_list (char *line) +static Function * +parse_function_list(char *line) { - Function *ret = NULL, *tail = NULL, *f, *i; - char *token; - int jump_count, j; - char stop_char; - char c; - - JmpArgs=0; - while (line && (f = parse_function(&line, &stop_char))) { - ConsoleDebug (CONFIG, "parse_function: %p\n", f->func); - /* extra code to check for and remove a 'label' pseudo-function */ - if (f->func==builtin_label) { - /* scan backwards to fix up references */ - jump_count=0; - for (i=tail; i!=NULL; i=i->prev) { - /* scan the command arguments for a 'JmpArg' type */ - for (j=0; j<(i->numargs); ++j) { - if (i->args[j].type==JmpArg) { - /* we have a winner! */ - if (!strcasecmp(f->args[0].value.string_value, - i->args[j].value.string_value)) { - /* the label matches it, so replace with the jump_count */ - i->args[j].type = IntArg; - i->args[j].value.int_value = jump_count; - --JmpArgs; - } - } - } - ++jump_count; - } - Free(f); /* label pseudo-functions never get added to the chain */ - } else { - if (tail) - tail->next = f; - else - ret = f; - f->prev=tail; - tail = f; - } - DoGetNextToken (line, &token, NULL, ",", &c); - if (token && stop_char != ',') { - ConsoleMessage ("Bad function list, comma expected\n"); - Free (token); - return NULL; - } - stop_char = c; - Free(token); - } - - if (JmpArgs!=0) { - /* someone made a typo and we need to scan to find out what it - * was. - */ - for (f=tail; f; f=f->prev) { - for (j=0; j<(f->numargs); ++j) { - if (f->args[j].type==JmpArg) { - ConsoleMessage ("Attempt to jump to non-existant label %s; " - "aborting function list.\n", - f->args[j].value.string_value); - --JmpArgs; - } - } - } - if (JmpArgs!=0) - ConsoleMessage ( "Internal Error: JmpArgs %d not accounted for!\n", - JmpArgs ); - tail=NULL; - f=NULL; - free_function_list(ret); - ret=NULL; - return NULL; - } - if (ret == NULL) - ConsoleMessage ("No function defined\n"); - return ret; + Function *ret = NULL, *tail = NULL, *f, *i; + char *token; + int jump_count, j; + char stop_char; + char c; + + JmpArgs = 0; + while (line && (f = parse_function(&line, &stop_char))) { + ConsoleDebug(CONFIG, "parse_function: %p\n", f->func); + /* extra code to check for and remove a 'label' pseudo-function + */ + if (f->func == builtin_label) { + /* scan backwards to fix up references */ + jump_count = 0; + for (i = tail; i != NULL; i = i->prev) { + /* scan the command arguments for a 'JmpArg' + * type */ + for (j = 0; j < (i->numargs); ++j) { + if (i->args[j].type == JmpArg) { + /* we have a winner! */ + if (!strcasecmp( + f->args[0] + .value.string_value, + i->args[j] + .value + .string_value)) { + /* the label matches it, + * so replace with the + * jump_count */ + i->args[j].type = + IntArg; + i->args[j] + .value.int_value = + jump_count; + --JmpArgs; + } + } + } + ++jump_count; + } + Free(f); /* label pseudo-functions never get added to + the chain */ + } else { + if (tail) + tail->next = f; + else + ret = f; + f->prev = tail; + tail = f; + } + DoGetNextToken(line, &token, NULL, ",", &c); + if (token && stop_char != ',') { + ConsoleMessage("Bad function list, comma expected\n"); + Free(token); + return NULL; + } + stop_char = c; + Free(token); + } + + if (JmpArgs != 0) { + /* someone made a typo and we need to scan to find out what it + * was. + */ + for (f = tail; f; f = f->prev) { + for (j = 0; j < (f->numargs); ++j) { + if (f->args[j].type == JmpArg) { + ConsoleMessage( + "Attempt to jump to non-existant " + "label %s; " + "aborting function list.\n", + f->args[j].value.string_value); + --JmpArgs; + } + } + } + if (JmpArgs != 0) + ConsoleMessage( + "Internal Error: JmpArgs %d not accounted for!\n", + JmpArgs); + tail = NULL; + f = NULL; + free_function_list(ret); + ret = NULL; + return NULL; + } + if (ret == NULL) + ConsoleMessage("No function defined\n"); + return ret; } - -Binding *ParseMouseEntry (char *tline) +Binding * +ParseMouseEntry(char *tline) { - char modifiers[20],*action,*token; - Binding *new; - int button; - int n1=0,n2=0; - int mods; - - /* tline points after the key word "key" */ - action = DoGetNextToken(tline,&token, NULL, ",", NULL); - if(token != NULL) { - n1 = sscanf(token,"%d",&button); - Free(token); - } - - action = DoGetNextToken(action,&token, NULL, ",", NULL); - if(token != NULL) { - n2 = sscanf(token,"%19s",modifiers); - Free(token); - } - if((n1 != 1)||(n2 != 1)) - ConsoleMessage ("Mouse binding: Syntax error"); - - find_context(modifiers,&mods,key_modifiers,tline); - if((mods & AnyModifier)&&(mods&(~AnyModifier))) { - ConsoleMessage ("Binding specified AnyModifier and other modifers too. Excess modifiers will be ignored."); - } - - new = (Binding *)safemalloc(sizeof(Binding)); - new->IsMouse = 1; - new->Button_Key = button; - new->key_name = NULL; - new->Modifier = mods; - new->Action = stripcpy(action); - new->Function = parse_function_list (action); - new->NextBinding = NULL; - new->LastBinding = new; - - if (!new->Function) { - ConsoleMessage ("Bad action: %s\n", action); - Free (new->Action); - Free (new); - return NULL; - } - - ConsoleDebug (CONFIG, "Mouse: %d %d %s\n", new->Button_Key, - new->Modifier, new->Action); - - return new; + char modifiers[20], *action, *token; + Binding *new; + int button; + int n1 = 0, n2 = 0; + int mods; + + /* tline points after the key word "key" */ + action = DoGetNextToken(tline, &token, NULL, ",", NULL); + if (token != NULL) { + n1 = sscanf(token, "%d", &button); + Free(token); + } + + action = DoGetNextToken(action, &token, NULL, ",", NULL); + if (token != NULL) { + n2 = sscanf(token, "%19s", modifiers); + Free(token); + } + if ((n1 != 1) || (n2 != 1)) + ConsoleMessage("Mouse binding: Syntax error"); + + find_context(modifiers, &mods, key_modifiers, tline); + if ((mods & AnyModifier) && (mods & (~AnyModifier))) { + ConsoleMessage( + "Binding specified AnyModifier and other modifers " + "too. Excess modifiers will be ignored."); + } + + new = (Binding *)xmalloc(sizeof(Binding)); + new->IsMouse = 1; + new->Button_Key = button; + new->key_name = NULL; + new->Modifier = mods; + new->Action = stripcpy(action); + new->Function = parse_function_list(action); + new->NextBinding = NULL; + new->LastBinding = new; + + if (!new->Function) { + ConsoleMessage("Bad action: %s\n", action); + Free(new->Action); + Free(new); + return NULL; + } + + ConsoleDebug(CONFIG, "Mouse: %d %d %s\n", new->Button_Key, + new->Modifier, new->Action); + + return new; } -static Binding *ParseKeyEntry (char *tline) +static Binding * +ParseKeyEntry(char *tline) { - char *action,modifiers[20],key[20],*ptr, *token, *actionstring, *keystring; - Binding *new = NULL, *temp, *last = NULL; - Function *func = NULL; - int i,min,max; - int n1=0,n2=0; - KeySym keysym; - int mods; - - /* tline points after the key word "key" */ - ptr = tline; - - ptr = DoGetNextToken(ptr,&token, NULL, ",", NULL); - if(token != NULL) { - n1 = sscanf(token,"%19s",key); - Free(token); - } - - action = DoGetNextToken(ptr,&token, NULL, ",", NULL); - if(token != NULL) { - n2 = sscanf(token,"%19s",modifiers); - Free(token); - } - - if((n1 != 1)||(n2 != 1)) - ConsoleMessage ("Syntax error in line %s",tline); - - find_context(modifiers,&mods,key_modifiers,tline); - if((mods & AnyModifier)&&(mods&(~AnyModifier))) { - ConsoleMessage ("Binding specified AnyModifier and other modifers too. Excess modifiers will be ignored."); - } - - /* - * Don't let a 0 keycode go through, since that means AnyKey to the - * XGrabKey call in GrabKeys(). - */ - if ((keysym = XStringToKeysym(key)) == NoSymbol || - XKeysymToKeycode(theDisplay, keysym) == 0) { - ConsoleMessage ("Can't find keysym: %s\n", key); - return NULL; - } - - - XDisplayKeycodes(theDisplay, &min, &max); - for (i=min; i<=max; i++) { - if (XKeycodeToKeysym(theDisplay, i, 0) == keysym) { - if (!func) { - func = parse_function_list (action); - if (!func) { - ConsoleMessage ("Bad action: %s\n", action); - return NULL; + char *action, modifiers[20], key[20], *ptr, *token, *actionstring, + *keystring; + Binding *new = NULL, *temp, *last = NULL; + Function *func = NULL; + int i, min, max; + int n1 = 0, n2 = 0; + KeySym keysym; + int mods; + + /* tline points after the key word "key" */ + ptr = tline; + + ptr = DoGetNextToken(ptr, &token, NULL, ",", NULL); + if (token != NULL) { + n1 = sscanf(token, "%19s", key); + Free(token); + } + + action = DoGetNextToken(ptr, &token, NULL, ",", NULL); + if (token != NULL) { + n2 = sscanf(token, "%19s", modifiers); + Free(token); + } + + if ((n1 != 1) || (n2 != 1)) + ConsoleMessage("Syntax error in line %s", tline); + + find_context(modifiers, &mods, key_modifiers, tline); + if ((mods & AnyModifier) && (mods & (~AnyModifier))) { + ConsoleMessage( + "Binding specified AnyModifier and other modifers " + "too. Excess modifiers will be ignored."); + } + + /* + * Don't let a 0 keycode go through, since that means AnyKey to the + * XGrabKey call in GrabKeys(). + */ + if ((keysym = XStringToKeysym(key)) == NoSymbol || + XKeysymToKeycode(theDisplay, keysym) == 0) { + ConsoleMessage("Can't find keysym: %s\n", key); + return NULL; } - actionstring = stripcpy(action); - keystring = stripcpy(key); - } - temp = new; - new = (Binding *)safemalloc(sizeof(Binding)); - new->IsMouse = 0; - new->Button_Key = i; - new->key_name = keystring; - new->Modifier = mods; - new->Action = actionstring; - new->Function = func; - new->NextBinding = temp; - if (!last) { - last = new; - } - new->LastBinding = last; - - ConsoleDebug (CONFIG, "Key: %d %s %d %s\n", i, new->key_name, - mods, new->Action); - } - } - return new; + + XDisplayKeycodes(theDisplay, &min, &max); + { + Bool matched = False; + + for (i = min; i <= max; i++) { + KeySym *mapping; + int width; + + mapping = XGetKeyboardMapping(theDisplay, i, 1, &width); + if (mapping == NULL) + continue; + + for (int col = 0; col < width; col++) { + if (mapping[col] == keysym) { + if (!func) { + func = + parse_function_list(action); + if (!func) { + XFree(mapping); + ConsoleMessage( + "Bad action: %s\n", + action); + return NULL; + } + actionstring = stripcpy(action); + keystring = stripcpy(key); + } + temp = new; + new = (Binding *)xmalloc( + sizeof(Binding)); + new->IsMouse = 0; + new->Button_Key = i; + new->key_name = keystring; + new->Modifier = mods; + new->Action = actionstring; + new->Function = func; + new->NextBinding = temp; + if (!last) { + last = new; + } + new->LastBinding = last; + + ConsoleDebug(CONFIG, + "Key: %d %s %d %s\n", i, + new->key_name, mods, new->Action); + matched = True; + break; + } + } + XFree(mapping); + } + + if (!matched && func) { + Free(actionstring); + Free(keystring); + free_function_list(func); + func = NULL; + } + } + return new; } -static Binding *ParseSimpleEntry (char *tline) +static Binding * +ParseSimpleEntry(char *tline) { - Binding *new; - Function *func; - - func = parse_function_list (tline); - if (func == NULL) - return NULL; - - new = (Binding *)safemalloc (sizeof (Binding)); - new->IsMouse = 0; - new->Button_Key = 0; - new->key_name = "select"; - new->Modifier = 0; - new->Action = stripcpy (tline); - new->Function = func; - new->NextBinding = NULL; - new->LastBinding = new; - - return new; + Binding *new; + Function *func; + + func = parse_function_list(tline); + if (func == NULL) + return NULL; + + new = (Binding *)xmalloc(sizeof(Binding)); + new->IsMouse = 0; + new->Button_Key = 0; + new->key_name = "select"; + new->Modifier = 0; + new->Action = stripcpy(tline); + new->Function = func; + new->NextBinding = NULL; + new->LastBinding = new; + + return new; } -void run_binding (WinManager *man, Action action) +void +run_binding(WinManager *man, Action action) { - Binding *binding = man->bindings[action]; - ConsoleDebug (CONFIG, "run_binding:\n"); - print_bindings (binding); + Binding *binding = man->bindings[action]; + ConsoleDebug(CONFIG, "run_binding:\n"); + print_bindings(binding); - if (binding && binding->Function && binding->Function->func) { - run_function_list (binding->Function); - } + if (binding && binding->Function && binding->Function->func) { + run_function_list(binding->Function); + } } -void execute_function (char *string) +void +execute_function(char *string) { - Function *func = parse_function_list (string); - if (func == NULL) { - return; - } - else { - run_function_list (func); - free_function_list (func); - } + Function *func = parse_function_list(string); + if (func == NULL) { + return; + } else { + run_function_list(func); + free_function_list(func); + } } -static int GetConfigLineWrapper (int *fd, char **tline) +static int +GetConfigLineWrapper(int *fd, char **tline) { #if FVWM_VERSION == 1 - static char buffer[1024]; - char *temp; - - if (fgets (buffer, 1024, config_fp)) { - *tline = buffer; - temp = strchr (*tline, '\n'); - if (temp) { - *temp = '\0'; - } - else { - ConsoleMessage (stderr, "line too long\n"); - exit (1); - } - return 1; - } + static char buffer[1024]; + char *temp; + + if (fgets(buffer, 1024, config_fp)) { + *tline = buffer; + temp = strchr(*tline, '\n'); + if (temp) { + *temp = '\0'; + } else { + ConsoleMessage(stderr, "line too long\n"); + exit(1); + } + return 1; + } #else - char *temp; + char *temp; - GetConfigLine (fd, tline); - if (*tline) { - temp = strchr (*tline, '\n'); - if (temp) { - *temp = '\0'; - } - return 1; - } + GetConfigLine(fd, tline); + if (*tline) { + temp = strchr(*tline, '\n'); + if (temp) { + *temp = '\0'; + } + return 1; + } #endif - return 0; + return 0; } -static char *read_next_cmd (ReadOption flag) +static char * +read_next_cmd(ReadOption flag) { - static ReadOption status; - static char *buffer; - static char *retstring, displaced, *cur_pos; - - retstring = NULL; - if (flag != READ_LINE && !(flag & status)) - return NULL; - - switch (flag) { - case READ_LINE: - while (GetConfigLineWrapper (Fvwm_fd, &buffer)) { - cur_pos = buffer; - skip_space (&cur_pos); - if (!strncasecmp (Module, cur_pos, ModuleLen)) { - retstring = cur_pos; - cur_pos += ModuleLen; - displaced = *cur_pos; - if (displaced == '*') - status = READ_OPTION; - else if (displaced == '\0') - status = READ_LINE; - else if (iswhite (displaced)) - status = READ_ARG; - else - status = READ_LINE; - break; - } - } - break; - - case READ_OPTION: - *cur_pos = displaced; - retstring = ++cur_pos; - while (*cur_pos != '*' && !iswhite (*cur_pos)) - cur_pos++; - displaced = *cur_pos; - *cur_pos = '\0'; - if (displaced == '*') - status = READ_OPTION; - else if (displaced == '\0') - status = READ_LINE; - else if (iswhite (displaced)) - status = READ_ARG; - else - status = READ_LINE; - break; - - case READ_ARG: - *cur_pos = displaced; - skip_space (&cur_pos); - retstring = cur_pos; - while (!iswhite (*cur_pos)) - cur_pos++; - displaced = *cur_pos; - *cur_pos = '\0'; - if (displaced == '\0') - status = READ_LINE; - else if (iswhite (displaced)) - status = READ_ARG; - else - status = READ_LINE; - break; - - case READ_REST_OF_LINE: - status = READ_LINE; - *cur_pos = displaced; - skip_space (&cur_pos); - retstring = cur_pos; - break; - } - - if (retstring && retstring[0] == '\0') - retstring = NULL; - - return retstring; + static ReadOption status; + static char *buffer; + static char *retstring, displaced, *cur_pos; + + retstring = NULL; + if (flag != READ_LINE && !(flag & status)) + return NULL; + + switch (flag) { + case READ_LINE: + while (GetConfigLineWrapper(Fvwm_fd, &buffer)) { + cur_pos = buffer; + skip_space(&cur_pos); + if (!strncasecmp(Module, cur_pos, ModuleLen)) { + retstring = cur_pos; + cur_pos += ModuleLen; + displaced = *cur_pos; + if (displaced == '*') + status = READ_OPTION; + else if (displaced == '\0') + status = READ_LINE; + else if (iswhite(displaced)) + status = READ_ARG; + else + status = READ_LINE; + break; + } + } + break; + + case READ_OPTION: + *cur_pos = displaced; + retstring = ++cur_pos; + while (*cur_pos != '*' && !iswhite(*cur_pos)) + cur_pos++; + displaced = *cur_pos; + *cur_pos = '\0'; + if (displaced == '*') + status = READ_OPTION; + else if (displaced == '\0') + status = READ_LINE; + else if (iswhite(displaced)) + status = READ_ARG; + else + status = READ_LINE; + break; + + case READ_ARG: + *cur_pos = displaced; + skip_space(&cur_pos); + retstring = cur_pos; + while (!iswhite(*cur_pos)) + cur_pos++; + displaced = *cur_pos; + *cur_pos = '\0'; + if (displaced == '\0') + status = READ_LINE; + else if (iswhite(displaced)) + status = READ_ARG; + else + status = READ_LINE; + break; + + case READ_REST_OF_LINE: + status = READ_LINE; + *cur_pos = displaced; + skip_space(&cur_pos); + retstring = cur_pos; + break; + } + + if (retstring && retstring[0] == '\0') + retstring = NULL; + + return retstring; } -static char *conditional_copy_string (char **s1, char *s2) +static char * +conditional_copy_string(char **s1, char *s2) { - if (*s1) - return *s1; - else - return copy_string (s1, s2); + if (*s1) + return *s1; + else + return copy_string(s1, s2); } -static NameType parse_format_dependencies (char *format) +static NameType +parse_format_dependencies(char *format) { - NameType flags = NO_NAME; - - ConsoleDebug (CONFIG, "Parsing format: %s\n", format); - - while (*format) { - if (*format != '%') { - format++; - } - else { - format++; - if (*format == 'i') - flags |= ICON_NAME; - else if (*format == 't') - flags |= TITLE_NAME; - else if (*format == 'c') - flags |= CLASS_NAME; - else if (*format == 'r') - flags |= RESOURCE_NAME; - else if (*format != '%') - ConsoleMessage ("Bad format string: %s\n", format); - } - } + NameType flags = NO_NAME; + + ConsoleDebug(CONFIG, "Parsing format: %s\n", format); + + while (*format) { + if (*format != '%') { + format++; + } else { + format++; + if (*format == 'i') + flags |= ICON_NAME; + else if (*format == 't') + flags |= TITLE_NAME; + else if (*format == 'c') + flags |= CLASS_NAME; + else if (*format == 'r') + flags |= RESOURCE_NAME; + else if (*format != '%') + ConsoleMessage( + "Bad format string: %s\n", format); + } + } #ifdef PRINT_DEBUG - ConsoleDebug (CONFIG, "Format depends on: "); - if (flags & ICON_NAME) - ConsoleDebug (CONFIG, "Icon "); - if (flags & TITLE_NAME) - ConsoleDebug (CONFIG, "Title "); - if (flags & CLASS_NAME) - ConsoleDebug (CONFIG, "Class "); - if (flags & RESOURCE_NAME) - ConsoleDebug (CONFIG, "Resource "); - ConsoleDebug (CONFIG, "\n"); + ConsoleDebug(CONFIG, "Format depends on: "); + if (flags & ICON_NAME) + ConsoleDebug(CONFIG, "Icon "); + if (flags & TITLE_NAME) + ConsoleDebug(CONFIG, "Title "); + if (flags & CLASS_NAME) + ConsoleDebug(CONFIG, "Class "); + if (flags & RESOURCE_NAME) + ConsoleDebug(CONFIG, "Resource "); + ConsoleDebug(CONFIG, "\n"); #endif - return flags; + return flags; } -#define SET_MANAGER(manager,field,value) \ - do { \ - int id = manager; \ - if (id == -1) { \ - for (id = 0; id < globals.num_managers; id++) { \ - globals.managers[id].field = value; \ - } \ - } \ - else if (id < globals.num_managers) { \ - globals.managers[id].field = value; \ - } \ - else { \ - ConsoleMessage ("Internal error in SET_MANAGER: %d\n", id); \ - } \ - } while (0) - -static void handle_button_config (int manager, int context, char *option) +#define SET_MANAGER(manager, field, value) \ + do { \ + int id = manager; \ + if (id == -1) { \ + for (id = 0; id < globals.num_managers; id++) { \ + globals.managers[id].field = value; \ + } \ + } else if (id < globals.num_managers) { \ + globals.managers[id].field = value; \ + } else { \ + ConsoleMessage( \ + "Internal error in SET_MANAGER: %d\n", id); \ + } \ + } while (0) + +static void +handle_button_config(int manager, int context, char *option) { - char *p; - ButtonState state; - - p = read_next_cmd (READ_ARG); - if (!p) { - ConsoleMessage ("Bad line: %s\n", current_line); - ConsoleMessage ("Need argument to %s\n", option); - return; - } - else if (!strcasecmp (p, "flat")) { - state = BUTTON_FLAT; - } - else if (!strcasecmp (p, "up")) { - state = BUTTON_UP; - } - else if (!strcasecmp (p, "down")) { - state = BUTTON_DOWN; - } - else if (!strcasecmp (p, "raisededge")) { - state = BUTTON_EDGEUP; - } - else if (!strcasecmp (p, "sunkedge")) { - state = BUTTON_EDGEDOWN; - } - else { - ConsoleMessage ("Bad line: %s\n", current_line); - ConsoleMessage ("This isn't a valid button state: %s\n", p); - return; - } - ConsoleDebug (CONFIG, "Setting buttonState[%s] to %s\n", - contextDefaults[context].name, p); - SET_MANAGER (manager, buttonState[context], state); - - /* check for optional fore color */ - p = read_next_cmd (READ_ARG); - if ( !p ) - return; - - SET_MANAGER (manager, foreColorName[context], - copy_string (&globals.managers[id].foreColorName[context], p)); - - /* check for optional back color */ - p = read_next_cmd (READ_ARG); - if ( !p ) - return; - - ConsoleDebug (CONFIG, "Setting backColorName[%s] to %s\n", - contextDefaults[context].name, p); - SET_MANAGER (manager, backColorName[context], - copy_string (&globals.managers[id].backColorName[context], p)); -} - -void read_in_resources (char *file) -{ - char *p, *q; - int i, n, manager; - char *option1; - Binding *binding; - Resolution r; - - if (!init_config_file (file)) - return; - - while ((p = read_next_cmd (READ_LINE))) { - ConsoleDebug (CONFIG, "line: %s\n", p); - save_current_line (p); - - option1 = read_next_cmd (READ_OPTION); - if (option1 == NULL) - continue; - - ConsoleDebug (CONFIG, "option1: %s\n", option1); - if (!strcasecmp (option1, "nummanagers")) { - /* If in transient mode, just use the default of 1 manager */ - if (!globals.transient) { - p = read_next_cmd (READ_ARG); - if (!p) { - ConsoleMessage ("Bad line: %s\n", current_line); - continue; - } - if (extract_int (p, &n) == 0) { - ConsoleMessage ("This is not a number: %s\n", p); - ConsoleMessage ("Bad line: %s\n", current_line); - continue; - } - if (n > 0) { - allocate_managers (n); - ConsoleDebug (CONFIG, "num managers: %d\n", n); - } - else { - ConsoleMessage ("Bad line: %s\n", current_line); - ConsoleMessage ("You can't have zero managers. " - "I'll give you one.\n"); - allocate_managers (1); - } - } - } - else { - /* these all can specify a specific manager */ - - if (globals.managers == NULL) { - ConsoleDebug (CONFIG, "I'm assuming you only want one manager\n"); - allocate_managers (1); - } - - manager = 0; - - if (option1[0] >= '0' && option1[0] <= '9') { - if (globals.transient) { - ConsoleDebug (CONFIG, "In transient mode. Ignoring this line\n"); - continue; - } - if (extract_int (option1, &manager) == 0 || - manager <= 0 || manager > globals.num_managers) { - ConsoleMessage ("Bad line: %s\n", current_line); - ConsoleMessage ("This is not a valid manager: %s.\n", option1); - manager = 0; - } - option1 = read_next_cmd (READ_OPTION); - if (!option1) { - ConsoleMessage ("Bad line: %s\n", current_line); - continue; - } - } - else if (!strcasecmp (option1, "transient")) { - if (globals.transient) { - ConsoleDebug (CONFIG, "Transient manager config line\n"); - manager = 1; - option1 = read_next_cmd (READ_OPTION); - if (!option1) { - ConsoleMessage ("Bad line: %s\n", current_line); - continue; - } - } - else { - ConsoleDebug (CONFIG, "Not in transient mode. Ignoring this line\n"); - continue; - } - } - - manager--; /* -1 means global */ - - ConsoleDebug (CONFIG, "Applying %s to manager %d\n", option1, manager); - - if (!strcasecmp (option1, "action")) { - p = read_next_cmd (READ_ARG); - if (!p) { - ConsoleMessage ("Bad line: %s\n", current_line); - continue; - } - - if (!strcasecmp (p, "mouse")) { - i = MOUSE; - } - else if (!strcasecmp (p, "key")) { - i = KEYPRESS; - } - else if (!strcasecmp (p, "select")) { - i = SELECT; - } - else { - ConsoleMessage ("Bad line: %s\n", current_line); - ConsoleMessage ("This isn't a valid action name: %s\n", p); - continue; - } + char *p; + ButtonState state; - q = read_next_cmd (READ_REST_OF_LINE); - if (!q) { - ConsoleMessage ("Bad line: %s\n", current_line); - ConsoleMessage ("Need an action\n"); - continue; - } - - switch (i) { - case MOUSE: - binding = ParseMouseEntry (q); - break; - - case KEYPRESS: - binding = ParseKeyEntry (q); - break; - - case SELECT: - binding = ParseSimpleEntry (q); - break; - } - - if (binding == NULL) { - ConsoleMessage ("Offending line: %s\n", current_line); - ConsoleMessage ("Bad action\n"); - continue; - } - - if (manager == -1) { - int j; - for (j = 0; j < globals.num_managers; j++) { - add_to_binding (&globals.managers[j].bindings[i], binding); - } - } - else if (manager < globals.num_managers) { - add_to_binding (&globals.managers[manager].bindings[i], binding); - } - else { - ConsoleMessage ("Bad line: %s\n", current_line); - ConsoleMessage ("There's no manager %d\n", manager); - } - } - else if (!strcasecmp (option1, "background")) { - p = read_next_cmd (READ_ARG); + p = read_next_cmd(READ_ARG); if (!p) { - ConsoleMessage ("Bad line: %s\n", current_line); - continue; - } - ConsoleDebug (CONFIG, "default background: %s\n", p); - - for ( i = 0; i < NUM_CONTEXTS; i++ ) - SET_MANAGER (manager, backColorName[i], - conditional_copy_string (&globals.managers[id].backColorName[i], - p)); - } - else if (!strcasecmp (option1, "buttongeometry")) { - p = read_next_cmd (READ_ARG); - if (!p) { - ConsoleMessage ("Bad line: %s\n", current_line); - continue; - } + ConsoleMessage("Bad line: %s\n", current_line); + ConsoleMessage("Need argument to %s\n", option); + return; + } else if (!strcasecmp(p, "flat")) { + state = BUTTON_FLAT; + } else if (!strcasecmp(p, "up")) { + state = BUTTON_UP; + } else if (!strcasecmp(p, "down")) { + state = BUTTON_DOWN; + } else if (!strcasecmp(p, "raisededge")) { + state = BUTTON_EDGEUP; + } else if (!strcasecmp(p, "sunkedge")) { + state = BUTTON_EDGEDOWN; + } else { + ConsoleMessage("Bad line: %s\n", current_line); + ConsoleMessage("This isn't a valid button state: %s\n", p); + return; + } + ConsoleDebug(CONFIG, "Setting buttonState[%s] to %s\n", + contextDefaults[context].name, p); + SET_MANAGER(manager, buttonState[context], state); + + /* check for optional fore color */ + p = read_next_cmd(READ_ARG); + if (!p) + return; + + SET_MANAGER(manager, foreColorName[context], + copy_string(&globals.managers[id].foreColorName[context], p)); + + /* check for optional back color */ + p = read_next_cmd(READ_ARG); + if (!p) + return; + + ConsoleDebug(CONFIG, "Setting backColorName[%s] to %s\n", + contextDefaults[context].name, p); + SET_MANAGER(manager, backColorName[context], + copy_string(&globals.managers[id].backColorName[context], p)); +} - SET_MANAGER (manager, button_geometry_str, - copy_string (&globals.managers[id].button_geometry_str, p)); - } - else if (!strcasecmp (option1, "dontshow")) { - char *token = NULL; - p = read_next_cmd (READ_REST_OF_LINE); - if (!p) { - ConsoleMessage ("Bad line: %s\n", current_line); - continue; - } - p = DoGetNextToken (p, &token, NULL, ",", NULL); - if (!token) { - ConsoleMessage ("Bad line: %s\n", current_line); - continue; - } - do { - ConsoleDebug (CONFIG, "dont show: %s\n", token); - if (manager == -1) { - int i; - for (i = 0; i < globals.num_managers; i++) - add_to_stringlist (&globals.managers[i].dontshow, token); - } - else { - add_to_stringlist (&globals.managers[manager].dontshow, token); - } - Free (token); - p = DoGetNextToken (p, &token, NULL, ",", NULL); - } while (token); - if (token) - Free(token); - } - else if (!strcasecmp (option1, "drawicons")) { +void +read_in_resources(char *file) +{ + char *p, *q; + int i, n, manager; + char *option1; + Binding *binding; + Resolution r; + + if (!init_config_file(file)) + return; + + while ((p = read_next_cmd(READ_LINE))) { + ConsoleDebug(CONFIG, "line: %s\n", p); + save_current_line(p); + + option1 = read_next_cmd(READ_OPTION); + if (option1 == NULL) + continue; + + ConsoleDebug(CONFIG, "option1: %s\n", option1); + if (!strcasecmp(option1, "nummanagers")) { + /* If in transient mode, just use the default of 1 + * manager */ + if (!globals.transient) { + p = read_next_cmd(READ_ARG); + if (!p) { + ConsoleMessage( + "Bad line: %s\n", current_line); + continue; + } + if (extract_int(p, &n) == 0) { + ConsoleMessage( + "This is not a number: %s\n", p); + ConsoleMessage( + "Bad line: %s\n", current_line); + continue; + } + if (n > 0) { + allocate_managers(n); + ConsoleDebug( + CONFIG, "num managers: %d\n", n); + } else { + ConsoleMessage( + "Bad line: %s\n", current_line); + ConsoleMessage( + "You can't have zero managers. " + "I'll give you one.\n"); + allocate_managers(1); + } + } + } else { + /* these all can specify a specific manager */ + + if (globals.managers == NULL) { + ConsoleDebug(CONFIG, + "I'm assuming you only want one manager\n"); + allocate_managers(1); + } + + manager = 0; + + if (option1[0] >= '0' && option1[0] <= '9') { + if (globals.transient) { + ConsoleDebug(CONFIG, + "In transient mode. " + "Ignoring this line\n"); + continue; + } + if (extract_int(option1, &manager) == 0 || + manager <= 0 || + manager > globals.num_managers) { + ConsoleMessage( + "Bad line: %s\n", current_line); + ConsoleMessage("This is not a valid " + "manager: %s.\n", + option1); + manager = 0; + } + option1 = read_next_cmd(READ_OPTION); + if (!option1) { + ConsoleMessage( + "Bad line: %s\n", current_line); + continue; + } + } else if (!strcasecmp(option1, "transient")) { + if (globals.transient) { + ConsoleDebug(CONFIG, + "Transient manager config line\n"); + manager = 1; + option1 = read_next_cmd(READ_OPTION); + if (!option1) { + ConsoleMessage("Bad line: %s\n", + current_line); + continue; + } + } else { + ConsoleDebug(CONFIG, + "Not in transient mode. " + "Ignoring this line\n"); + continue; + } + } + + manager--; /* -1 means global */ + + ConsoleDebug(CONFIG, "Applying %s to manager %d\n", + option1, manager); + + if (!strcasecmp(option1, "action")) { + p = read_next_cmd(READ_ARG); + if (!p) { + ConsoleMessage( + "Bad line: %s\n", current_line); + continue; + } + + if (!strcasecmp(p, "mouse")) { + i = MOUSE; + } else if (!strcasecmp(p, "key")) { + i = KEYPRESS; + } else if (!strcasecmp(p, "select")) { + i = SELECT; + } else { + ConsoleMessage( + "Bad line: %s\n", current_line); + ConsoleMessage("This isn't a valid " + "action name: %s\n", + p); + continue; + } + + q = read_next_cmd(READ_REST_OF_LINE); + if (!q) { + ConsoleMessage( + "Bad line: %s\n", current_line); + ConsoleMessage("Need an action\n"); + continue; + } + + switch (i) { + case MOUSE: + binding = ParseMouseEntry(q); + break; + + case KEYPRESS: + binding = ParseKeyEntry(q); + break; + + case SELECT: + binding = ParseSimpleEntry(q); + break; + } + + if (binding == NULL) { + ConsoleMessage("Offending line: %s\n", + current_line); + ConsoleMessage("Bad action\n"); + continue; + } + + if (manager == -1) { + int j; + for (j = 0; j < globals.num_managers; + j++) { + add_to_binding( + &globals.managers[j] + .bindings[i], + binding); + } + } else if (manager < globals.num_managers) { + add_to_binding( + &globals.managers[manager] + .bindings[i], + binding); + } else { + ConsoleMessage( + "Bad line: %s\n", current_line); + ConsoleMessage( + "There's no manager %d\n", manager); + } + } else if (!strcasecmp(option1, "background")) { + p = read_next_cmd(READ_ARG); + if (!p) { + ConsoleMessage( + "Bad line: %s\n", current_line); + continue; + } + ConsoleDebug( + CONFIG, "default background: %s\n", p); + + for (i = 0; i < NUM_CONTEXTS; i++) + SET_MANAGER(manager, backColorName[i], + conditional_copy_string( + &globals.managers[id] + .backColorName[i], + p)); + } else if (!strcasecmp(option1, "buttongeometry")) { + p = read_next_cmd(READ_ARG); + if (!p) { + ConsoleMessage( + "Bad line: %s\n", current_line); + continue; + } + + SET_MANAGER(manager, button_geometry_str, + copy_string(&globals.managers[id] + .button_geometry_str, + p)); + } else if (!strcasecmp(option1, "dontshow")) { + char *token = NULL; + p = read_next_cmd(READ_REST_OF_LINE); + if (!p) { + ConsoleMessage( + "Bad line: %s\n", current_line); + continue; + } + p = DoGetNextToken(p, &token, NULL, ",", NULL); + if (!token) { + ConsoleMessage( + "Bad line: %s\n", current_line); + continue; + } + do { + ConsoleDebug( + CONFIG, "dont show: %s\n", token); + if (manager == -1) { + int i; + for (i = 0; + i < globals.num_managers; + i++) + add_to_stringlist( + &globals.managers[i] + .dontshow, + token); + } else { + add_to_stringlist( + &globals.managers[manager] + .dontshow, + token); + } + Free(token); + p = DoGetNextToken( + p, &token, NULL, ",", NULL); + } while (token); + if (token) + Free(token); + } else if (!strcasecmp(option1, "drawicons")) { #ifdef MINI_ICONS - p = read_next_cmd (READ_ARG); - if (!p) { - ConsoleMessage ("Bad line: %s\n", current_line); - ConsoleMessage ("Need argument to drawicons\n"); - continue; - } - if (!strcasecmp (p, "true")) { - i = 1; - } - /* [NFM 3 Dec 97] added support for FvwmIconMan*drawicons "always" */ - else if (!strcasecmp (p, "always")) { - i = 2; - } - else if (!strcasecmp (p, "false")) { - i = 0; - } - else { - ConsoleMessage ("Bad line: %s\n", current_line); - ConsoleMessage ("What is this: %s?\n", p); - continue; - } - ConsoleDebug (CONFIG, "Setting drawicons to: %d\n", i); - SET_MANAGER (manager, draw_icons, i); + p = read_next_cmd(READ_ARG); + if (!p) { + ConsoleMessage( + "Bad line: %s\n", current_line); + ConsoleMessage( + "Need argument to drawicons\n"); + continue; + } + if (!strcasecmp(p, "true")) { + i = 1; + } + /* [NFM 3 Dec 97] added support for + FvwmIconMan*drawicons "always" */ + else if (!strcasecmp(p, "always")) { + i = 2; + } else if (!strcasecmp(p, "false")) { + i = 0; + } else { + ConsoleMessage( + "Bad line: %s\n", current_line); + ConsoleMessage( + "What is this: %s?\n", p); + continue; + } + ConsoleDebug( + CONFIG, "Setting drawicons to: %d\n", i); + SET_MANAGER(manager, draw_icons, i); #else - ConsoleMessage ("DrawIcons support not compiled in\n"); + ConsoleMessage( + "DrawIcons support not compiled in\n"); #endif - } - else if (!strcasecmp (option1, "followfocus")) { - p = read_next_cmd (READ_ARG); - if (!p) { - ConsoleMessage ("Bad line: %s\n", current_line); - ConsoleMessage ("Need argument to followfocus\n"); - continue; - } - if (!strcasecmp (p, "true")) { - i = 1; - } - else if (!strcasecmp (p, "false")) { - i = 0; - } - else { - ConsoleMessage ("Bad line: %s\n", current_line); - ConsoleMessage ("What is this: %s?\n", p); - continue; - } - ConsoleDebug (CONFIG, "Setting followfocus to: %d\n", i); - SET_MANAGER (manager, followFocus, i); - } - else if (!strcasecmp (option1, "font")) { - p = read_next_cmd (READ_ARG); - if (!p) { - ConsoleMessage ("Bad line: %s\n", current_line); - continue; - } - ConsoleDebug (CONFIG, "font: %s\n", p); - - SET_MANAGER (manager, fontname, - copy_string (&globals.managers[id].fontname, p)); - } - else if (!strcasecmp (option1, "foreground")) { - p = read_next_cmd (READ_ARG); - if (!p) { - ConsoleMessage ("Bad line: %s\n", current_line); - continue; - } - ConsoleDebug (CONFIG, "default foreground: %s\n", p); - - for ( i = 0; i < NUM_CONTEXTS; i++ ) - SET_MANAGER (manager, foreColorName[i], - conditional_copy_string (&globals.managers[id].foreColorName[i], - p)); - } - else if (!strcasecmp (option1, "format")) { - char *token; - NameType flags; - - p = read_next_cmd (READ_REST_OF_LINE); - if (!p) { - ConsoleMessage ("Bad line: %s\n", current_line); - continue; - } - DoGetNextToken (p, &token, NULL, ",", NULL); - if (!token) - { - token = (char *)safemalloc(1); - *token = 0; - } - - SET_MANAGER (manager, formatstring, - copy_string (&globals.managers[id].formatstring, token)); - flags = parse_format_dependencies (token); - SET_MANAGER (manager, format_depend, flags); - Free (token); - } - else if (!strcasecmp (option1, "geometry")) { - ConsoleMessage ("Geometry option no longer supported.\n"); - ConsoleMessage ("Use ManagerGeometry and ButtonGeometry.\n"); - } - else if (!strcasecmp (option1, "iconname")) { - char *token; - p = read_next_cmd (READ_REST_OF_LINE); - if (!p) { - ConsoleMessage ("Bad line: %s\n", current_line); - continue; - } - DoGetNextToken (p, &token, NULL, ",", NULL); - if (!token) - { - token = (char *)safemalloc(1); - *token = 0; - } - - SET_MANAGER (manager, iconname, - copy_string (&globals.managers[id].iconname, token)); - Free (token); - } - else if (!strcasecmp (option1, "managergeometry")) { - p = read_next_cmd (READ_ARG); - if (!p) { - ConsoleMessage ("Bad line: %s\n", current_line); - continue; - } - - SET_MANAGER (manager, geometry_str, - copy_string (&globals.managers[id].geometry_str, p)); - } - else if (!strcasecmp (option1, "resolution")) { - p = read_next_cmd (READ_ARG); - if (!p) { - ConsoleMessage ("Bad line: %s\n", current_line); - continue; - } - ConsoleDebug (CONFIG, "resolution: %s\n", p); - if (!strcasecmp (p, "global")) - r = SHOW_GLOBAL; - else if (!strcasecmp (p, "desk")) - r = SHOW_DESKTOP; - else if (!strcasecmp (p, "page")) - r = SHOW_PAGE; - else { - ConsoleMessage ("Bad line: %s\n", current_line); - ConsoleMessage ("What kind of resolution is this?\n"); - continue; - } - - SET_MANAGER (manager, res, r); - } - else if (!strcasecmp (option1, "shape")) { - p = read_next_cmd (READ_ARG); - if (!p) { - ConsoleMessage ("Bad line: %s\n", current_line); - ConsoleMessage ("Need argument to followfocus\n"); - continue; - } - if (!strcasecmp (p, "true")) { - i = 1; - } - else if (!strcasecmp (p, "false")) { - i = 0; - } - else { - ConsoleMessage ("Bad line: %s\n", current_line); - ConsoleMessage ("What is this: %s?\n", p); - continue; - } - if (i && globals.shapes_supported == 0) { - ConsoleMessage ("Shape support not compiled in\n"); - continue; - } - ConsoleDebug (CONFIG, "Setting shape to: %d\n", i); - SET_MANAGER (manager, shaped, i); - } - else if (!strcasecmp (option1, "show")) { - char *token = NULL; - p = read_next_cmd (READ_REST_OF_LINE); - if (!p) { - ConsoleMessage ("Bad line: %s\n", current_line); - continue; - } - p = DoGetNextToken (p, &token, NULL, ",", NULL); - if (!token) { - ConsoleMessage ("Bad line: %s\n", current_line); - continue; - } - do { - ConsoleDebug (CONFIG, "show: %s\n", token); - if (manager == -1) { - int i; - for (i = 0; i < globals.num_managers; i++) - add_to_stringlist (&globals.managers[i].show, token); - } - else { - add_to_stringlist (&globals.managers[manager].show, token); - } - Free (token); - p = DoGetNextToken (p, &token, NULL, ",", NULL); - } while (token); - if (token) - Free(token); - } - else if (!strcasecmp (option1, "showtitle")) { - ConsoleMessage ("Bad line: %s\n", current_line); - ConsoleMessage ("showtitle is no longer an option. Use format\n"); - continue; - } - else if (!strcasecmp (option1, "sort")) { - p = read_next_cmd (READ_ARG); - if (!p) { - ConsoleMessage ("Bad line: %s\n", current_line); - ConsoleMessage ("Need argument to sort\n"); - continue; - } - if (!strcasecmp (p, "name")) { - i = SortName; - } - else if (!strcasecmp (p, "namewithcase")) { - i = SortNameCase; - } - else if (!strcasecmp (p, "id")) { - i = SortId; - } - else if (!strcasecmp (p, "none")) { - i = SortNone; - } - else if (!strcasecmp (p, "false") || !strcasecmp (p, "true")) { - /* Old options */ - ConsoleMessage ("FvwmIconMan*sort option no longer takes " - "true or false value\n" - "Please read the latest manpage\n"); - continue; - } - else { - ConsoleMessage ("Bad line: %s\n", current_line); - ConsoleMessage ("What is this: %s?\n", p); - continue; - } - ConsoleDebug (CONFIG, "Setting sort to: %d\n", i); - SET_MANAGER (manager, sort, i); - } - else if (!strcasecmp (option1, "title")) { - char *token; - p = read_next_cmd (READ_REST_OF_LINE); - if (!p) { - ConsoleMessage ("Bad line: %s\n", current_line); - continue; - } - DoGetNextToken (p, &token, NULL, ",", NULL); - if (!token) - { - token = (char *)safemalloc(1); - *token = 0; - } - - SET_MANAGER (manager, titlename, - copy_string (&globals.managers[id].titlename, token)); - Free (token); - } - else if (!strcasecmp (option1, "plainButton")) { - handle_button_config (manager, PLAIN_CONTEXT, option1); - } - else if (!strcasecmp (option1, "selectButton")) { - handle_button_config (manager, SELECT_CONTEXT, option1); - } - else if (!strcasecmp (option1, "focusButton")) { - handle_button_config (manager, FOCUS_CONTEXT, option1); - } - else if (!strcasecmp (option1, "focusandselectButton")) { - handle_button_config (manager, FOCUS_SELECT_CONTEXT, option1); - } - else if (!strcasecmp (option1, "titlebutton")) { - handle_button_config (manager, TITLE_CONTEXT, option1); - } - else if (!strcasecmp (option1, "usewinlist")) { - p = read_next_cmd (READ_ARG); - if (!p) { - ConsoleMessage ("Bad line: %s\n", current_line); - ConsoleMessage ("Need argument to usewinlist\n"); - continue; - } - if (!strcasecmp (p, "true")) { - i = 1; - } - else if (!strcasecmp (p, "false")) { - i = 0; - } - else { - ConsoleMessage ("Bad line: %s\n", current_line); - ConsoleMessage ("What is this: %s?\n", p); - continue; - } - ConsoleDebug (CONFIG, "Setting usewinlist to: %d\n", i); - SET_MANAGER (manager, usewinlist, i); - } - else { - ConsoleMessage ("Bad line: %s\n", current_line); - ConsoleMessage ("Unknown option: %s\n", p); - } - } - } - - if (globals.managers == NULL) { - ConsoleDebug (CONFIG, "I'm assuming you only want one manager\n"); - allocate_managers (1); - } - print_managers(); - close_config_file(); + } else if (!strcasecmp(option1, "followfocus")) { + p = read_next_cmd(READ_ARG); + if (!p) { + ConsoleMessage( + "Bad line: %s\n", current_line); + ConsoleMessage( + "Need argument to followfocus\n"); + continue; + } + if (!strcasecmp(p, "true")) { + i = 1; + } else if (!strcasecmp(p, "false")) { + i = 0; + } else { + ConsoleMessage( + "Bad line: %s\n", current_line); + ConsoleMessage( + "What is this: %s?\n", p); + continue; + } + ConsoleDebug( + CONFIG, "Setting followfocus to: %d\n", i); + SET_MANAGER(manager, followFocus, i); + } else if (!strcasecmp(option1, "font")) { + p = read_next_cmd(READ_ARG); + if (!p) { + ConsoleMessage( + "Bad line: %s\n", current_line); + continue; + } + ConsoleDebug(CONFIG, "font: %s\n", p); + + SET_MANAGER(manager, fontname, + copy_string( + &globals.managers[id].fontname, p)); + } else if (!strcasecmp(option1, "foreground")) { + p = read_next_cmd(READ_ARG); + if (!p) { + ConsoleMessage( + "Bad line: %s\n", current_line); + continue; + } + ConsoleDebug( + CONFIG, "default foreground: %s\n", p); + + for (i = 0; i < NUM_CONTEXTS; i++) + SET_MANAGER(manager, foreColorName[i], + conditional_copy_string( + &globals.managers[id] + .foreColorName[i], + p)); + } else if (!strcasecmp(option1, "format")) { + char *token; + NameType flags; + + p = read_next_cmd(READ_REST_OF_LINE); + if (!p) { + ConsoleMessage( + "Bad line: %s\n", current_line); + continue; + } + DoGetNextToken(p, &token, NULL, ",", NULL); + if (!token) { + token = (char *)xmalloc(1); + *token = 0; + } + + SET_MANAGER(manager, formatstring, + copy_string( + &globals.managers[id].formatstring, + token)); + flags = parse_format_dependencies(token); + SET_MANAGER(manager, format_depend, flags); + Free(token); + } else if (!strcasecmp(option1, "geometry")) { + ConsoleMessage( + "Geometry option no longer supported.\n"); + ConsoleMessage("Use ManagerGeometry and " + "ButtonGeometry.\n"); + } else if (!strcasecmp(option1, "iconname")) { + char *token; + p = read_next_cmd(READ_REST_OF_LINE); + if (!p) { + ConsoleMessage( + "Bad line: %s\n", current_line); + continue; + } + DoGetNextToken(p, &token, NULL, ",", NULL); + if (!token) { + token = (char *)xmalloc(1); + *token = 0; + } + + SET_MANAGER(manager, iconname, + copy_string( + &globals.managers[id].iconname, token)); + Free(token); + } else if (!strcasecmp(option1, "managergeometry")) { + p = read_next_cmd(READ_ARG); + if (!p) { + ConsoleMessage( + "Bad line: %s\n", current_line); + continue; + } + + SET_MANAGER(manager, geometry_str, + copy_string( + &globals.managers[id].geometry_str, p)); + } else if (!strcasecmp(option1, "resolution")) { + p = read_next_cmd(READ_ARG); + if (!p) { + ConsoleMessage( + "Bad line: %s\n", current_line); + continue; + } + ConsoleDebug(CONFIG, "resolution: %s\n", p); + if (!strcasecmp(p, "global")) + r = SHOW_GLOBAL; + else if (!strcasecmp(p, "desk")) + r = SHOW_DESKTOP; + else if (!strcasecmp(p, "page")) + r = SHOW_PAGE; + else { + ConsoleMessage( + "Bad line: %s\n", current_line); + ConsoleMessage("What kind of " + "resolution is this?\n"); + continue; + } + + SET_MANAGER(manager, res, r); + } else if (!strcasecmp(option1, "shape")) { + p = read_next_cmd(READ_ARG); + if (!p) { + ConsoleMessage( + "Bad line: %s\n", current_line); + ConsoleMessage( + "Need argument to followfocus\n"); + continue; + } + if (!strcasecmp(p, "true")) { + i = 1; + } else if (!strcasecmp(p, "false")) { + i = 0; + } else { + ConsoleMessage( + "Bad line: %s\n", current_line); + ConsoleMessage( + "What is this: %s?\n", p); + continue; + } + if (i && globals.shapes_supported == 0) { + ConsoleMessage( + "Shape support not compiled in\n"); + continue; + } + ConsoleDebug( + CONFIG, "Setting shape to: %d\n", i); + SET_MANAGER(manager, shaped, i); + } else if (!strcasecmp(option1, "show")) { + char *token = NULL; + p = read_next_cmd(READ_REST_OF_LINE); + if (!p) { + ConsoleMessage( + "Bad line: %s\n", current_line); + continue; + } + p = DoGetNextToken(p, &token, NULL, ",", NULL); + if (!token) { + ConsoleMessage( + "Bad line: %s\n", current_line); + continue; + } + do { + ConsoleDebug( + CONFIG, "show: %s\n", token); + if (manager == -1) { + int i; + for (i = 0; + i < globals.num_managers; + i++) + add_to_stringlist( + &globals.managers[i] + .show, + token); + } else { + add_to_stringlist( + &globals.managers[manager] + .show, + token); + } + Free(token); + p = DoGetNextToken( + p, &token, NULL, ",", NULL); + } while (token); + if (token) + Free(token); + } else if (!strcasecmp(option1, "showtitle")) { + ConsoleMessage("Bad line: %s\n", current_line); + ConsoleMessage("showtitle is no longer an " + "option. Use format\n"); + continue; + } else if (!strcasecmp(option1, "sort")) { + p = read_next_cmd(READ_ARG); + if (!p) { + ConsoleMessage( + "Bad line: %s\n", current_line); + ConsoleMessage( + "Need argument to sort\n"); + continue; + } + if (!strcasecmp(p, "name")) { + i = SortName; + } else if (!strcasecmp(p, "namewithcase")) { + i = SortNameCase; + } else if (!strcasecmp(p, "id")) { + i = SortId; + } else if (!strcasecmp(p, "none")) { + i = SortNone; + } else if (!strcasecmp(p, "false") || + !strcasecmp(p, "true")) { + /* Old options */ + ConsoleMessage( + "FvwmIconMan*sort option no longer " + "takes " + "true or false value\n" + "Please read the latest manpage\n"); + continue; + } else { + ConsoleMessage( + "Bad line: %s\n", current_line); + ConsoleMessage( + "What is this: %s?\n", p); + continue; + } + ConsoleDebug( + CONFIG, "Setting sort to: %d\n", i); + SET_MANAGER(manager, sort, i); + } else if (!strcasecmp(option1, "title")) { + char *token; + p = read_next_cmd(READ_REST_OF_LINE); + if (!p) { + ConsoleMessage( + "Bad line: %s\n", current_line); + continue; + } + DoGetNextToken(p, &token, NULL, ",", NULL); + if (!token) { + token = (char *)xmalloc(1); + *token = 0; + } + + SET_MANAGER(manager, titlename, + copy_string(&globals.managers[id].titlename, + token)); + Free(token); + } else if (!strcasecmp(option1, "plainButton")) { + handle_button_config( + manager, PLAIN_CONTEXT, option1); + } else if (!strcasecmp(option1, "selectButton")) { + handle_button_config( + manager, SELECT_CONTEXT, option1); + } else if (!strcasecmp(option1, "focusButton")) { + handle_button_config( + manager, FOCUS_CONTEXT, option1); + } else if (!strcasecmp( + option1, "focusandselectButton")) { + handle_button_config( + manager, FOCUS_SELECT_CONTEXT, option1); + } else if (!strcasecmp(option1, "titlebutton")) { + handle_button_config( + manager, TITLE_CONTEXT, option1); + } else if (!strcasecmp(option1, "usewinlist")) { + p = read_next_cmd(READ_ARG); + if (!p) { + ConsoleMessage( + "Bad line: %s\n", current_line); + ConsoleMessage( + "Need argument to usewinlist\n"); + continue; + } + if (!strcasecmp(p, "true")) { + i = 1; + } else if (!strcasecmp(p, "false")) { + i = 0; + } else { + ConsoleMessage( + "Bad line: %s\n", current_line); + ConsoleMessage( + "What is this: %s?\n", p); + continue; + } + ConsoleDebug( + CONFIG, "Setting usewinlist to: %d\n", i); + SET_MANAGER(manager, usewinlist, i); + } else { + ConsoleMessage("Bad line: %s\n", current_line); + ConsoleMessage("Unknown option: %s\n", p); + } + } + } + + if (globals.managers == NULL) { + ConsoleDebug( + CONFIG, "I'm assuming you only want one manager\n"); + allocate_managers(1); + } + print_managers(); + close_config_file(); } - Index: fvwm/modules/FvwmIconMan/readconfig.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIconMan/readconfig.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIconMan/readconfig.h --- fvwm/modules/FvwmIconMan/readconfig.h +++ fvwm/modules/FvwmIconMan/readconfig.h @@ -1,18 +1,25 @@ +#ifndef READCONFIG_H +#define READCONFIG_H + +#include "FvwmIconMan.h" + typedef enum { - READ_LINE = 1, - READ_OPTION = 2, - READ_ARG = 4, - READ_REST_OF_LINE = 12 + READ_LINE = 1, + READ_OPTION = 2, + READ_ARG = 4, + READ_REST_OF_LINE = 12 } ReadOption; -extern void read_in_resources (char *file); -extern void print_bindings (Binding *list); -extern void print_args (int numargs, BuiltinArg *args); -extern Binding *ParseMouseEntry (char *tline); +extern void read_in_resources(char *file); +extern void print_bindings(Binding *list); +extern void print_args(int numargs, BuiltinArg *args); +extern Binding *ParseMouseEntry(char *tline); -extern void run_function_list (Function *func); -extern void run_binding (WinManager *man, Action action); +extern void run_function_list(Function *func); +extern void run_binding(WinManager *man, Action action); -#define MODS_USED (ShiftMask | ControlMask | Mod1Mask | \ - Mod2Mask| Mod3Mask| Mod4Mask| Mod5Mask) +#define MODS_USED \ + (ShiftMask | ControlMask | Mod1Mask | Mod2Mask | Mod3Mask | Mod4Mask |\ + Mod5Mask) +#endif /* READCONFIG_H */ Index: fvwm/modules/FvwmIconMan/winlist.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIconMan/winlist.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIconMan/winlist.c --- fvwm/modules/FvwmIconMan/winlist.c +++ fvwm/modules/FvwmIconMan/winlist.c @@ -1,378 +1,424 @@ #include +#include + #include "FvwmIconMan.h" static char const rcsid[] = - "$Id: winlist.c,v 1.1.1.1 2006/11/26 10:53:50 matthieu Exp $"; + "$Id: winlist.c,v 1.1.1.1 2006/11/26 10:53:50 matthieu Exp $"; #define HASHTAB_SIZE 257 typedef WinList HashTab[HASHTAB_SIZE]; static HashTab hash_tab; -void print_stringlist (StringList *list) +void +print_stringlist(StringList *list) { - StringEl *p; - char *s; - - ConsoleDebug (WINLIST, "\tmask = 0x%x\n", list->mask); - for (p = list->list; p; p = p->next) { - switch (p->type) { - case ALL_NAME: - s = "all"; - break; - - case TITLE_NAME: - s = "title"; - break; - - case ICON_NAME: - s = "icon"; - break; - - case RESOURCE_NAME: - s = "resource"; - break; - - case CLASS_NAME: - s = "class"; - break; - - default: - s = "unknown type"; - } - ConsoleDebug (WINLIST, "\t%s = %s\n", s, p->string); - } + StringEl *p; + char *s; + + ConsoleDebug(WINLIST, "\tmask = 0x%x\n", list->mask); + for (p = list->list; p; p = p->next) { + switch (p->type) { + case ALL_NAME: + s = "all"; + break; + + case TITLE_NAME: + s = "title"; + break; + + case ICON_NAME: + s = "icon"; + break; + + case RESOURCE_NAME: + s = "resource"; + break; + + case CLASS_NAME: + s = "class"; + break; + + default: + s = "unknown type"; + } + ConsoleDebug(WINLIST, "\t%s = %s\n", s, p->string); + } } -void add_to_stringlist (StringList *list, char *s) +void +add_to_stringlist(StringList *list, char *s) { - StringEl *new; - NameType type; - char *pat; - - ConsoleDebug (WINLIST, "In add_to_stringlist: %s\n", s); - - pat = strchr (s, '='); - if (pat) { - *pat++ = '\0'; - if (!strcasecmp (s, "icon")) - type = ICON_NAME; - else if (!strcasecmp (s, "title")) - type = TITLE_NAME; - else if (!strcasecmp (s, "resource")) - type = RESOURCE_NAME; - else if (!strcasecmp (s, "class")) - type = CLASS_NAME; - else { - ConsoleMessage ("Bad element in show/dontshow list: %s\n", s); - return; - } - } - else { - pat = s; - type = ALL_NAME; - } - - ConsoleDebug (WINLIST, "add_to_stringlist: %s %s\n", - type == ALL_NAME ? "all" : s, pat); - - new = (StringEl *)safemalloc (sizeof (StringEl)); - new->string = (char *)safemalloc ((strlen (pat) + 1) * sizeof (char)); - new->type = type; - - strcpy (new->string, pat); - new->next = list->list; - if (list->list) - list->mask |= type; - else - list->mask = type; - list->list = new; - - ConsoleDebug (WINLIST, "Exiting add_to_stringlist\n"); + StringEl *new; + NameType type; + char *pat; + + ConsoleDebug(WINLIST, "In add_to_stringlist: %s\n", s); + + pat = strchr(s, '='); + if (pat) { + *pat++ = '\0'; + if (!strcasecmp(s, "icon")) + type = ICON_NAME; + else if (!strcasecmp(s, "title")) + type = TITLE_NAME; + else if (!strcasecmp(s, "resource")) + type = RESOURCE_NAME; + else if (!strcasecmp(s, "class")) + type = CLASS_NAME; + else { + ConsoleMessage( + "Bad element in show/dontshow list: %s\n", s); + return; + } + } else { + pat = s; + type = ALL_NAME; + } + + ConsoleDebug(WINLIST, "add_to_stringlist: %s %s\n", + type == ALL_NAME ? "all" : s, pat); + + new = (StringEl *)xmalloc(sizeof(StringEl)); + size_t pat_len = strlen(pat); + new->string = (char *)xmalloc((pat_len + 1) * sizeof(char)); + new->type = type; + + strlcpy(new->string, pat, pat_len + 1); + new->next = list->list; + if (list->list) + list->mask |= type; + else + list->mask = type; + list->list = new; + + ConsoleDebug(WINLIST, "Exiting add_to_stringlist\n"); } -static int matches_string (NameType type, char *pattern, char *tname, - char *iname, char *rname, char *cname) +static int +stringlist_requires_name(const StringList *list, NameType type) { - int ans = 0; - - ConsoleDebug (WINLIST, "matches_string: type: 0x%x pattern: %s\n", - type, pattern); - ConsoleDebug (WINLIST, "\tstrings: %s:%s %s:%s\n", tname, iname, - rname, cname); - - if (tname && (type == ALL_NAME || type == TITLE_NAME)) { - ans |= matchWildcards (pattern, tname); - } - if (iname && (type == ALL_NAME || type == ICON_NAME)) { - ans |= matchWildcards (pattern, iname); - } - if (rname && (type == ALL_NAME || type == RESOURCE_NAME)) { - ans |= matchWildcards (pattern, rname); - } - if (cname && (type == ALL_NAME || type == CLASS_NAME)) { - ans |= matchWildcards (pattern, cname); - } - - ConsoleDebug (WINLIST, "\tmatches_string: %d\n", ans); - return ans; + StringEl *p; + + if (!list) + return 0; + + for (p = list->list; p; p = p->next) { + if (p->type == type) + return 1; + } + + return 0; } -static int iconmanager_show (WinManager *man, char *tname, char *iname, - char *rname, char *cname) +static int +matches_string(NameType type, char *pattern, char *tname, char *iname, + char *rname, char *cname) { - StringEl *string; - int in_showlist = 0, in_dontshowlist = 0; + int ans = 0; + + ConsoleDebug( + WINLIST, "matches_string: type: 0x%x pattern: %s\n", type, pattern); + ConsoleDebug( + WINLIST, "\tstrings: %s:%s %s:%s\n", tname, iname, rname, cname); + + if (tname && (type == ALL_NAME || type == TITLE_NAME)) { + ans |= matchWildcards(pattern, tname); + } + if (iname && (type == ALL_NAME || type == ICON_NAME)) { + ans |= matchWildcards(pattern, iname); + } + if (rname && (type == ALL_NAME || type == RESOURCE_NAME)) { + ans |= matchWildcards(pattern, rname); + } + if (cname && (type == ALL_NAME || type == CLASS_NAME)) { + ans |= matchWildcards(pattern, cname); + } - assert (man); + ConsoleDebug(WINLIST, "\tmatches_string: %d\n", ans); + return ans; +} + +static int +iconmanager_show( + WinManager *man, char *tname, char *iname, char *rname, char *cname) +{ + StringEl *string; + int in_showlist = 0, in_dontshowlist = 0; + + assert(man); #ifdef PRINT_DEBUG - ConsoleDebug (WINLIST, "In iconmanager_show: %s:%s : %s %s\n", tname, iname, - rname, cname); - ConsoleDebug (WINLIST, "dontshow:\n"); - print_stringlist (&man->dontshow); - ConsoleDebug (WINLIST, "show:\n"); - print_stringlist (&man->show); + ConsoleDebug(WINLIST, "In iconmanager_show: %s:%s : %s %s\n", tname, + iname, rname, cname); + ConsoleDebug(WINLIST, "dontshow:\n"); + print_stringlist(&man->dontshow); + ConsoleDebug(WINLIST, "show:\n"); + print_stringlist(&man->show); #endif /*PRINT_DEBUG*/ - for (string = man->dontshow.list; string; string = string->next) { - ConsoleDebug (WINLIST, "Matching: %s\n", string->string); - if (matches_string (string->type, string->string, tname, iname, - rname, cname)) { - ConsoleDebug (WINLIST, "Dont show\n"); - in_dontshowlist = 1; - break; - } - } - - if (!in_dontshowlist) { - if (man->show.list == NULL) { - in_showlist = 1; - } - else { - for (string = man->show.list; string; string = string->next) { - ConsoleDebug (WINLIST, "Matching: %s\n", string->string); - if (matches_string (string->type, string->string, tname, iname, - rname, cname)) { - ConsoleDebug (WINLIST, "Show\n"); - in_showlist = 1; - break; + for (string = man->dontshow.list; string; string = string->next) { + ConsoleDebug(WINLIST, "Matching: %s\n", string->string); + if (matches_string(string->type, string->string, tname, iname, + rname, cname)) { + ConsoleDebug(WINLIST, "Dont show\n"); + in_dontshowlist = 1; + break; + } + } + + if (!in_dontshowlist) { + if (man->show.list == NULL) { + in_showlist = 1; + } else { + for (string = man->show.list; string; + string = string->next) { + ConsoleDebug( + WINLIST, "Matching: %s\n", string->string); + if (matches_string(string->type, string->string, + tname, iname, rname, cname)) { + ConsoleDebug(WINLIST, "Show\n"); + in_showlist = 1; + break; + } + } + } } - } - } - } - ConsoleDebug (WINLIST, "returning: %d %d %d\n", in_dontshowlist, - in_showlist, !in_dontshowlist && in_showlist); + ConsoleDebug(WINLIST, "returning: %d %d %d\n", in_dontshowlist, + in_showlist, !in_dontshowlist && in_showlist); - return (!in_dontshowlist && in_showlist); + return (!in_dontshowlist && in_showlist); } -WinData *new_windata (void) +WinData * +new_windata(void) { - WinData *new = (WinData *)safemalloc (sizeof (WinData)); - new->desknum = ULONG_MAX; - new->x = ULONG_MAX; - new->y = ULONG_MAX; - new->geometry_set = 0; - new->app_id = ULONG_MAX; - new->app_id_set = 0; - new->resname = NULL; - new->classname = NULL; - new->iconname = NULL; - new->titlename = NULL; - new->display_string = NULL; - new->manager = NULL; - new->win_prev = new->win_next = NULL; - new->iconified = 0; - new->button = NULL; - new->state = 0; - new->complete = 0; - new->fvwm_flags = 0; + WinData *new = (WinData *)xmalloc(sizeof(WinData)); + new->desknum = ULONG_MAX; + new->x = ULONG_MAX; + new->y = ULONG_MAX; + new->geometry_set = 0; + new->app_id = ULONG_MAX; + new->app_id_set = 0; + new->resname = NULL; + new->classname = NULL; + new->iconname = NULL; + new->titlename = NULL; + new->display_string = NULL; + new->manager = NULL; + new->win_prev = new->win_next = NULL; + new->iconified = 0; + new->button = NULL; + new->state = 0; + new->complete = 0; + new->fvwm_flags = 0; #ifdef MINI_ICONS - new->pic.picture = 0; + new->pic.picture = 0; #endif - return new; + return new; } -void free_windata (WinData *p) +void +free_windata(WinData *p) { - if (globals.select_win == p) { - ConsoleMessage ("Internal error in free_windata\n"); - globals.select_win = NULL; - abort(); - } - - Free (p->resname); - Free (p->classname); - Free (p->iconname); - Free (p); -} + if (globals.select_win == p) { + ConsoleMessage("Internal error in free_windata\n"); + globals.select_win = NULL; + abort(); + } + Free(p->resname); + Free(p->classname); + Free(p->iconname); + Free(p); +} /* This ALWAYS gets called when one of the name strings changes */ -WinManager *figure_win_manager (WinData *win, Uchar name_mask) +WinManager * +figure_win_manager(WinData *win, Uchar name_mask) { - int i; - char *tname = win->titlename; - char *iname = win->iconname; - char *rname = win->resname; - char *cname = win->classname; - WinManager *man; - - assert (tname || iname || rname || cname); - ConsoleDebug (WINLIST, "set_win_manager: %s %s %s %s\n", tname, iname, rname, cname); - - for (i = 0, man = &globals.managers[0]; i < globals.num_managers; - i++, man++) { - if (iconmanager_show (man, tname, iname, rname, cname)) { - if (man != win->manager) { - assert (man->magic == 0x12344321); - } - return man; - } - } - - /* No manager wants this window */ - return NULL; + int i; + char *tname = win->titlename; + char *iname = win->iconname; + char *rname = win->resname; + char *cname = win->classname; + WinManager *man; + + assert(tname || iname || rname || cname); + ConsoleDebug(WINLIST, "set_win_manager: %s %s %s %s\n", tname, iname, + rname, cname); + + for (i = 0, man = &globals.managers[0]; i < globals.num_managers; + i++, man++) { + if (iconmanager_show(man, tname, iname, rname, cname)) { + if (man != win->manager) { + assert(man->magic == 0x12344321); + } + return man; + } + } + + /* No manager wants this window */ + return NULL; } -int check_win_complete (WinData *p) +int +check_win_complete(WinData *p) { - if (p->complete) - return 1; - - ConsoleDebug (WINLIST, "Checking completeness:\n"); - ConsoleDebug (WINLIST, "\ttitlename: %s\n", - (p->titlename ? p->titlename : "No Title name")); - ConsoleDebug (WINLIST, "\ticonname: %s\n", - (p->iconname ? p->iconname : "No Icon name")); - ConsoleDebug (WINLIST, "\tres: %s\n", - (p->resname ? p->resname : "No p->resname")); - ConsoleDebug (WINLIST, "\tclass: %s\n", - (p->classname ? p->classname : "No p->classname")); - ConsoleDebug (WINLIST, "\tdisplaystring: %s\n", - (p->display_string ? p->display_string : - "No p->display_string")); - ConsoleDebug (WINLIST, "\t(x, y): (%ld, %ld)\n", p->x, p->y); - ConsoleDebug (WINLIST, "\tapp_id: 0x%lx %d\n", p->app_id, p->app_id_set); - ConsoleDebug (WINLIST, "\tdesknum: %ld\n", p->desknum); - ConsoleDebug (WINLIST, "\tmanager: 0x%lx\n", (unsigned long)p->manager); - - if (p->geometry_set && - p->resname && - p->classname && - p->iconname && - p->titlename && - p->manager && - p->app_id_set) { - p->complete = 1; - ConsoleDebug (WINLIST, "\tcomplete: 1\n\n"); - return 1; - } - - ConsoleDebug (WINLIST, "\tcomplete: 0\n\n"); - return 0; + int need_resname = 0; + int have_required_names = 0; + + if (p->complete) + return 1; + + if (p->manager) { + if (p->manager->format_depend & RESOURCE_NAME) + need_resname = 1; + else if (stringlist_requires_name( + &p->manager->show, RESOURCE_NAME)) + need_resname = 1; + else if (stringlist_requires_name( + &p->manager->dontshow, RESOURCE_NAME)) + need_resname = 1; + } + + ConsoleDebug(WINLIST, "Checking completeness:\n"); + ConsoleDebug(WINLIST, "\ttitlename: %s\n", + (p->titlename ? p->titlename : "No Title name")); + ConsoleDebug(WINLIST, "\ticonname: %s\n", + (p->iconname ? p->iconname : "No Icon name")); + ConsoleDebug(WINLIST, "\tres: %s\n", + (p->resname ? p->resname : "No p->resname")); + ConsoleDebug(WINLIST, "\tclass: %s\n", + (p->classname ? p->classname : "No p->classname")); + ConsoleDebug(WINLIST, "\tdisplaystring: %s\n", + (p->display_string ? p->display_string : "No p->display_string")); + ConsoleDebug(WINLIST, "\t(x, y): (%ld, %ld)\n", p->x, p->y); + ConsoleDebug(WINLIST, "\tapp_id: 0x%lx %d\n", p->app_id, p->app_id_set); + ConsoleDebug(WINLIST, "\tdesknum: %ld\n", p->desknum); + ConsoleDebug(WINLIST, "\tmanager: 0x%lx\n", (unsigned long)p->manager); + ConsoleDebug(WINLIST, "\tneed_resname: %d\n", need_resname); + + have_required_names = (!need_resname || p->resname) && p->classname && + p->iconname && p->titlename; + + if (p->geometry_set && have_required_names && p->manager && + p->app_id_set) { + p->complete = 1; + ConsoleDebug(WINLIST, "\tcomplete: 1\n\n"); + return 1; + } + + ConsoleDebug(WINLIST, "\tcomplete: 0\n\n"); + return 0; } - -void init_winlists (void) + +void +init_winlists(void) { - int i; - for (i = 0; i < HASHTAB_SIZE; i++) { - hash_tab[i].n = 0; - hash_tab[i].head = NULL; - hash_tab[i].tail = NULL; - } + int i; + for (i = 0; i < HASHTAB_SIZE; i++) { + hash_tab[i].n = 0; + hash_tab[i].head = NULL; + hash_tab[i].tail = NULL; + } } -void delete_win_hashtab (WinData *win) +void +delete_win_hashtab(WinData *win) { - int entry; - WinList *list; - - entry = win->app_id & 0xff; - list = &hash_tab[entry]; - - if (win->win_prev) - win->win_prev->win_next = win->win_next; - else - list->head = win->win_next; - if (win->win_next) - win->win_next->win_prev = win->win_prev; - else - list->tail = win->win_prev; - list->n--; -} - -void insert_win_hashtab (WinData *win) + int entry; + WinList *list; + + entry = win->app_id & 0xff; + list = &hash_tab[entry]; + + if (win->win_prev) + win->win_prev->win_next = win->win_next; + else + list->head = win->win_next; + if (win->win_next) + win->win_next->win_prev = win->win_prev; + else + list->tail = win->win_prev; + list->n--; +} + +void +insert_win_hashtab(WinData *win) { - int entry; - WinList *list; - WinData *p; - - entry = win->app_id & 0xff; - list = &hash_tab[entry]; - - for (p = list->head; p && win->app_id > p->app_id; - p = p->win_next); - - if (p) { - /* insert win before p */ - win->win_next = p; - win->win_prev = p->win_prev; - if (p->win_prev) - p->win_prev->win_next = win; - else - list->head = win; - p->win_prev = win; - } - else { - /* put win at end of list */ - win->win_next = NULL; - win->win_prev = list->tail; - if (list->tail) - list->tail->win_next = win; - else - list->head = win; - list->tail = win; - } - list->n++; + int entry; + WinList *list; + WinData *p; + + entry = win->app_id & 0xff; + list = &hash_tab[entry]; + + for (p = list->head; p && win->app_id > p->app_id; p = p->win_next) + ; + + if (p) { + /* insert win before p */ + win->win_next = p; + win->win_prev = p->win_prev; + if (p->win_prev) + p->win_prev->win_next = win; + else + list->head = win; + p->win_prev = win; + } else { + /* put win at end of list */ + win->win_next = NULL; + win->win_prev = list->tail; + if (list->tail) + list->tail->win_next = win; + else + list->head = win; + list->tail = win; + } + list->n++; } -WinData *find_win_hashtab (Ulong id) +WinData * +find_win_hashtab(Ulong id) { - WinList *list; - int entry = id & 0xff; - WinData *p; + WinList *list; + int entry = id & 0xff; + WinData *p; - list = &hash_tab[entry]; + list = &hash_tab[entry]; - for (p = list->head; p && p->app_id != id; p = p->win_next); + for (p = list->head; p && p->app_id != id; p = p->win_next) + ; - return p; + return p; } -void walk_hashtab (void (*func)(void *)) +void +walk_hashtab(void (*func)(void *)) { - int i; - WinData *p; + int i; + WinData *p; - for (i = 0; i < HASHTAB_SIZE; i++) { - for (p = hash_tab[i].head; p; p = p->win_next) - func (p); - } + for (i = 0; i < HASHTAB_SIZE; i++) { + for (p = hash_tab[i].head; p; p = p->win_next) + func(p); + } } -int accumulate_walk_hashtab (int (*func)(void *)) +int +accumulate_walk_hashtab(int (*func)(void *)) { - int i, ret = 0; - WinData *p; + int i, ret = 0; + WinData *p; - for (i = 0; i < HASHTAB_SIZE; i++) { - for (p = hash_tab[i].head; p; p = p->win_next) - ret += func (p); - } + for (i = 0; i < HASHTAB_SIZE; i++) { + for (p = hash_tab[i].head; p; p = p->win_next) + ret += func(p); + } - return ret; + return ret; } Index: fvwm/modules/FvwmIconMan/x.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIconMan/x.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIconMan/x.c --- fvwm/modules/FvwmIconMan/x.c +++ fvwm/modules/FvwmIconMan/x.c @@ -1,13 +1,16 @@ -#include "config.h" +#include "x.h" + #include "FvwmIconMan.h" +#include "config.h" #include "readconfig.h" -#include "x.h" #include "xmanager.h" static char const rcsid[] = - "$Id: x.c,v 1.1.1.1 2006/11/26 10:53:50 matthieu Exp $"; + "$Id: x.c,v 1.1.1.1 2006/11/26 10:53:50 matthieu Exp $"; -#define GRAB_EVENTS (ButtonPressMask|ButtonReleaseMask|ButtonMotionMask|EnterWindowMask|LeaveWindowMask) +#define GRAB_EVENTS \ + (ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | \ + EnterWindowMask | LeaveWindowMask) #ifdef SHAPE static int shapeEventBase, shapeErrorBase; @@ -18,130 +21,139 @@ Window theRoot; int theDepth, theScreen; static enum { - NOT_GRABBED = 0, - NEED_TO_GRAB = 1, - HAVE_GRABBED = 2 + NOT_GRABBED = 0, + NEED_TO_GRAB = 1, + HAVE_GRABBED = 2 } grab_state = NOT_GRABBED; -static void reparentnotify_event (WinManager *man, XEvent *ev); +static void reparentnotify_event(WinManager *man, XEvent *ev); -static void grab_pointer (WinManager *man) +static void +grab_pointer(WinManager *man) { - /* This should only be called after we get our EXPOSE event */ - if (grab_state == NEED_TO_GRAB) { - if (XGrabPointer (theDisplay, man->theWindow, True, GRAB_EVENTS, - GrabModeAsync, GrabModeAsync, None, - None, CurrentTime) != GrabSuccess) { - ConsoleMessage ("Couldn't grab pointer\n"); - ShutMeDown (0); - } - grab_state = HAVE_GRABBED; - } + /* This should only be called after we get our EXPOSE event */ + if (grab_state == NEED_TO_GRAB) { + if (XGrabPointer(theDisplay, man->theWindow, True, GRAB_EVENTS, + GrabModeAsync, GrabModeAsync, None, None, + CurrentTime) != GrabSuccess) { + ConsoleMessage("Couldn't grab pointer\n"); + ShutMeDown(0); + } + grab_state = HAVE_GRABBED; + } } -static int lookup_color (char *name, Pixel *ans) +static int +lookup_color(char *name, Pixel *ans) { - XColor color; - XWindowAttributes attributes; - - XGetWindowAttributes(theDisplay, theRoot, &attributes); - color.pixel = 0; - if (!XParseColor (theDisplay, attributes.colormap, name, &color)) { - ConsoleDebug(X11, "Could not parse color '%s'\n", name); - return 0; - } - else if(!XAllocColor (theDisplay, attributes.colormap, &color)) { - ConsoleDebug(X11, "Could not allocate color '%s'\n", name); - return 0; - } - *ans = color.pixel; - return 1; + XColor color; + XWindowAttributes attributes; + + XGetWindowAttributes(theDisplay, theRoot, &attributes); + color.pixel = 0; + if (!XParseColor(theDisplay, attributes.colormap, name, &color)) { + ConsoleDebug(X11, "Could not parse color '%s'\n", name); + return 0; + } else if (!XAllocColor(theDisplay, attributes.colormap, &color)) { + ConsoleDebug(X11, "Could not allocate color '%s'\n", name); + return 0; + } + *ans = color.pixel; + return 1; } - -WinManager *find_windows_manager (Window win) +WinManager * +find_windows_manager(Window win) { - int i; - - for (i = 0; i < globals.num_managers; i++) { - if (globals.managers[i].theWindow == win) - return &globals.managers[i]; - } - -/* ConsoleMessage ("error in find_windows_manager:\n"); - ConsoleMessage ("Window: %x\n", win); - for (i = 0; i < globals.num_managers; i++) { - ConsoleMessage ("manager: %d %x\n", i, globals.managers[i].theWindow); - } -*/ - return NULL; + int i; + + for (i = 0; i < globals.num_managers; i++) { + if (globals.managers[i].theWindow == win) + return &globals.managers[i]; + } + + /* ConsoleMessage ("error in find_windows_manager:\n"); + ConsoleMessage ("Window: %x\n", win); + for (i = 0; i < globals.num_managers; i++) { + ConsoleMessage ("manager: %d %x\n", i, globals.managers[i].theWindow); + } + */ + return NULL; } -static void handle_buttonevent (XEvent *theEvent, WinManager *man) +static void +handle_buttonevent(XEvent *theEvent, WinManager *man) { - Button *b; - WinData *win; - unsigned int modifier; - Binding *MouseEntry; - - b = xy_to_button (man, theEvent->xbutton.x, theEvent->xbutton.y); - if (b && theEvent->xbutton.button >= 1 && theEvent->xbutton.button <= 3) { - win = b->drawn_state.win; - if (win != NULL) { - ConsoleDebug (X11, "Found the window:\n"); - ConsoleDebug (X11, "\tid: %ld\n", win->app_id); - ConsoleDebug (X11, "\tdesknum: %ld\n", win->desknum); - ConsoleDebug (X11, "\tx, y: %ld %ld\n", win->x, win->y); - ConsoleDebug (X11, "\ticon: %p\n", win->iconname); - ConsoleDebug (X11, "\ticonified: %d\n", win->iconified); - ConsoleDebug (X11, "\tcomplete: %d\n", win->complete); - - modifier = (theEvent->xbutton.state & MODS_USED); - /* need to search for an appropriate mouse binding */ - for (MouseEntry = man->bindings[MOUSE]; MouseEntry != NULL; - MouseEntry= MouseEntry->NextBinding) { - if(((MouseEntry->Button_Key == theEvent->xbutton.button)|| - (MouseEntry->Button_Key == 0))&& - ((MouseEntry->Modifier == AnyModifier)|| - (MouseEntry->Modifier == (modifier& (~LockMask))))) - { - Function *ftype = MouseEntry->Function; - ConsoleDebug (X11, "\tgot a mouse binding\n"); - if (ftype && ftype->func) { - run_function_list (ftype); - draw_managers(); - } - break; + Button *b; + WinData *win; + unsigned int modifier; + Binding *MouseEntry; + + b = xy_to_button(man, theEvent->xbutton.x, theEvent->xbutton.y); + if (b && theEvent->xbutton.button >= 1 && + theEvent->xbutton.button <= 3) { + win = b->drawn_state.win; + if (win != NULL) { + ConsoleDebug(X11, "Found the window:\n"); + ConsoleDebug(X11, "\tid: %ld\n", win->app_id); + ConsoleDebug(X11, "\tdesknum: %ld\n", win->desknum); + ConsoleDebug( + X11, "\tx, y: %ld %ld\n", win->x, win->y); + ConsoleDebug(X11, "\ticon: %p\n", win->iconname); + ConsoleDebug(X11, "\ticonified: %d\n", win->iconified); + ConsoleDebug(X11, "\tcomplete: %d\n", win->complete); + + modifier = (theEvent->xbutton.state & MODS_USED); + /* need to search for an appropriate mouse binding */ + for (MouseEntry = man->bindings[MOUSE]; + MouseEntry != NULL; + MouseEntry = MouseEntry->NextBinding) { + if (((MouseEntry->Button_Key == + theEvent->xbutton.button) || + (MouseEntry->Button_Key == 0)) && + ((MouseEntry->Modifier == AnyModifier) || + (MouseEntry->Modifier == + (modifier & (~LockMask))))) { + Function *ftype = MouseEntry->Function; + ConsoleDebug( + X11, "\tgot a mouse binding\n"); + if (ftype && ftype->func) { + run_function_list(ftype); + draw_managers(); + } + break; + } + } + } } - } - } - } } -Window find_frame_window (Window win, int *off_x, int *off_y) +Window +find_frame_window(Window win, int *off_x, int *off_y) { - Window root, parent, *junkw; - int junki; - XWindowAttributes attr; - - ConsoleDebug (X11, "In find_frame_window: 0x%x\n", (unsigned int)win); - - while (1) { - XQueryTree (theDisplay, win, &root, &parent, &junkw, &junki); - if (junkw) - XFree (junkw); - if (parent == root) - break; - XGetWindowAttributes (theDisplay, win, &attr); - ConsoleDebug (X11, "Adding (%d, %d) += (%d, %d)\n", - *off_x, *off_y, attr.x + attr.border_width, - attr.y + attr.border_width); - *off_x += attr.x + attr.border_width; - *off_y += attr.y + attr.border_width; - win = parent; - } - - return win; + Window root, parent, *junkw; + int junki; + XWindowAttributes attr; + + ConsoleDebug(X11, "In find_frame_window: 0x%x\n", (unsigned int)win); + + while (1) { + junkw = NULL; + if (XQueryTree(theDisplay, win, &root, &parent, &junkw, + &junki) && junkw) + XFree(junkw); + if (parent == root) + break; + XGetWindowAttributes(theDisplay, win, &attr); + ConsoleDebug(X11, "Adding (%d, %d) += (%d, %d)\n", *off_x, + *off_y, attr.x + attr.border_width, + attr.y + attr.border_width); + *off_x += attr.x + attr.border_width; + *off_y += attr.y + attr.border_width; + win = parent; + } + + return win; } /***************************************************************************/ @@ -149,665 +161,616 @@ Window find_frame_window (Window win, int *off_x, int *off_y) /* everything which has its own routine can be processed recursively */ /***************************************************************************/ -static void reparentnotify_event (WinManager *man, XEvent *ev) +static void +reparentnotify_event(WinManager *man, XEvent *ev) { - ConsoleDebug (X11, "XEVENT: ReparentNotify\n"); -#if 0 - ConsoleMessage ("seen %d expected %d\n", num_reparents_seen, - num_reparents_expected); - man->off_x = ev->xreparent.x; - man->off_y = ev->xreparent.y; - ConsoleDebug (X11, "reparent: off = (%d, %d)\n",man->off_x, man->off_y); - man->theFrame = find_frame_window (ev->xany.window, - &man->off_x, &man->off_y); - ConsoleMessage ("\twin = 0x%x, frame = 0x%x\n", man->theWindow, - man->theFrame); -#endif - if (man->can_draw == 0) { - man->can_draw = 1; - force_manager_redraw (man); - } + ConsoleDebug(X11, "XEVENT: ReparentNotify\n"); + if (man->can_draw == 0) { + man->can_draw = 1; + force_manager_redraw(man); + } } -void xevent_loop (void) +void +xevent_loop(void) { - XEvent theEvent; - unsigned int modifier; - Binding *key; - Button *b; - static int flag = 0; - WinManager *man; - - if (flag == 0) { - flag = 1; - ConsoleDebug (X11, "A virgin event loop\n"); - } - while (XPending (theDisplay)) { - XNextEvent (theDisplay, &theEvent); - if (theEvent.type == MappingNotify) { - ConsoleDebug (X11, "XEVENT: MappingNotify\n"); - continue; - } - - man = find_windows_manager (theEvent.xany.window); - if (!man) { - ConsoleDebug (X11, "Event doesn't belong to a manager\n"); - continue; - } - - switch (theEvent.type) { - case ReparentNotify: - reparentnotify_event (man, &theEvent); - break; - - case KeyPress: - ConsoleDebug (X11, "XEVENT: KeyPress\n"); - /* 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. */ - theEvent.xkey.keycode = - XKeysymToKeycode (theDisplay, - XKeycodeToKeysym(theDisplay, - theEvent.xkey.keycode,0)); - modifier = (theEvent.xkey.state & MODS_USED); - ConsoleDebug (X11, "\tKeyPress: %d\n", theEvent.xkey.keycode); - - for (key = man->bindings[KEYPRESS]; key != NULL; key = key->NextBinding) - { - if ((key->Button_Key == theEvent.xkey.keycode) && - ((key->Modifier == (modifier&(~LockMask)))|| - (key->Modifier == AnyModifier))) - { - Function *ftype = key->Function; - if (ftype && ftype->func) { - run_function_list (ftype); - draw_managers(); - } - break; - } - } - break; - - case Expose: - ConsoleDebug (X11, "XEVENT: Expose\n"); - if (theEvent.xexpose.count == 0) { - man_exposed (man, &theEvent); - draw_manager (man); - if (globals.transient) { - grab_pointer (man); - } - } - break; - - case ButtonPress: - ConsoleDebug (X11, "XEVENT: ButtonPress\n"); - if (!globals.transient) - handle_buttonevent (&theEvent, man); - break; - - case ButtonRelease: - ConsoleDebug (X11, "XEVENT: ButtonRelease\n"); - if (globals.transient) { - handle_buttonevent (&theEvent, man); - ShutMeDown (0); - } - break; - - case EnterNotify: - ConsoleDebug (X11, "XEVENT: EnterNotify\n"); - man->cursor_in_window = 1; - b = xy_to_button (man, theEvent.xcrossing.x, theEvent.xcrossing.y); - move_highlight (man, b); - run_binding (man, SELECT); - draw_managers(); - break; - - case LeaveNotify: - ConsoleDebug (X11, "XEVENT: LeaveNotify\n"); - move_highlight (man, NULL); - break; - - case ConfigureNotify: - ConsoleDebug (X11, "XEVENT: Configure Notify: %d %d %d %d\n", - theEvent.xconfigure.x, theEvent.xconfigure.y, - theEvent.xconfigure.width, theEvent.xconfigure.height); - ConsoleDebug (X11, "\tcurrent geometry: %d %d %d %d\n", - man->geometry.x, man->geometry.y, - man->geometry.width, man->geometry.height); - ConsoleDebug (X11, "\tborderwidth = %d\n", - theEvent.xconfigure.border_width); - ConsoleDebug (X11, "\tsendevent = %d\n", theEvent.xconfigure.send_event); -#if 0 - set_manager_width (man, theEvent.xconfigure.width); - ConsoleDebug (X11, "\tboxwidth = %d\n", man->geometry.boxwidth); - draw_manager (man); - - /* pointer may not be in the same box as before */ - if (XQueryPointer (theDisplay, man->theWindow, &root, &child, &glob_x, - &glob_y, - &x, &y, &mask)) { - b = xy_to_button (man, x, y); - if (b != man->select_button) { - move_highlight (man, b); - run_binding (man, SELECT); - draw_managers(); + XEvent theEvent; + unsigned int modifier; + Binding *key; + Button *b; + static int flag = 0; + WinManager *man; + + if (flag == 0) { + flag = 1; + ConsoleDebug(X11, "A virgin event loop\n"); } - } - else { - if (man->select_button != NULL) - move_highlight (NULL, NULL); - } -#endif - break; - - case MotionNotify: - /* ConsoleDebug (X11, "XEVENT: MotionNotify\n"); */ - b = xy_to_button (man, theEvent.xmotion.x, theEvent.xmotion.y); - if (b != man->select_button) { - ConsoleDebug (X11, "\tmoving select\n"); - move_highlight (man, b); - run_binding (man, SELECT); - draw_managers(); - } - break; - - case MapNotify: - ConsoleDebug (X11, "XEVENT: MapNotify\n"); - force_manager_redraw (man); - break; - - case UnmapNotify: - ConsoleDebug (X11, "XEVENT: UnmapNotify\n"); - break; - - case DestroyNotify: - ConsoleDebug(X11, "XEVENT: DestroyNotify\n"); - DeadPipe(0); - break; - - default: + while (XPending(theDisplay)) { + XNextEvent(theDisplay, &theEvent); + if (theEvent.type == MappingNotify) { + ConsoleDebug(X11, "XEVENT: MappingNotify\n"); + continue; + } + + man = find_windows_manager(theEvent.xany.window); + if (!man) { + ConsoleDebug( + X11, "Event doesn't belong to a manager\n"); + continue; + } + + switch (theEvent.type) { + case ReparentNotify: + reparentnotify_event(man, &theEvent); + break; + + case KeyPress: + ConsoleDebug(X11, "XEVENT: KeyPress\n"); + /* 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. */ + { + KeySym *mapping; + int width; + + mapping = XGetKeyboardMapping(theDisplay, + theEvent.xkey.keycode, 1, &width); + if (mapping != NULL) { + KeySym primary = + (width > 0) ? mapping[0] : NoSymbol; + KeyCode canonical = + (primary != NoSymbol) ? + XKeysymToKeycode( + theDisplay, primary) : + 0; + if (canonical != 0) + theEvent.xkey.keycode = + canonical; + XFree(mapping); + } + } + modifier = (theEvent.xkey.state & MODS_USED); + ConsoleDebug( + X11, "\tKeyPress: %d\n", theEvent.xkey.keycode); + + for (key = man->bindings[KEYPRESS]; key != NULL; + key = key->NextBinding) { + if ((key->Button_Key == + theEvent.xkey.keycode) && + ((key->Modifier == + (modifier & (~LockMask))) || + (key->Modifier == AnyModifier))) { + Function *ftype = key->Function; + if (ftype && ftype->func) { + run_function_list(ftype); + draw_managers(); + } + break; + } + } + break; + + case Expose: + ConsoleDebug(X11, "XEVENT: Expose\n"); + if (theEvent.xexpose.count == 0) { + man_exposed(man, &theEvent); + draw_manager(man); + if (globals.transient) { + grab_pointer(man); + } + } + break; + + case ButtonPress: + ConsoleDebug(X11, "XEVENT: ButtonPress\n"); + if (!globals.transient) + handle_buttonevent(&theEvent, man); + break; + + case ButtonRelease: + ConsoleDebug(X11, "XEVENT: ButtonRelease\n"); + if (globals.transient) { + handle_buttonevent(&theEvent, man); + ShutMeDown(0); + } + break; + + case EnterNotify: + ConsoleDebug(X11, "XEVENT: EnterNotify\n"); + man->cursor_in_window = 1; + b = xy_to_button( + man, theEvent.xcrossing.x, theEvent.xcrossing.y); + move_highlight(man, b); + run_binding(man, SELECT); + draw_managers(); + break; + + case LeaveNotify: + ConsoleDebug(X11, "XEVENT: LeaveNotify\n"); + move_highlight(man, NULL); + break; + + case ConfigureNotify: + ConsoleDebug(X11, + "XEVENT: Configure Notify: %d %d %d %d\n", + theEvent.xconfigure.x, theEvent.xconfigure.y, + theEvent.xconfigure.width, + theEvent.xconfigure.height); + ConsoleDebug(X11, "\tcurrent geometry: %d %d %d %d\n", + man->geometry.x, man->geometry.y, + man->geometry.width, man->geometry.height); + ConsoleDebug(X11, "\tborderwidth = %d\n", + theEvent.xconfigure.border_width); + ConsoleDebug(X11, "\tsendevent = %d\n", + theEvent.xconfigure.send_event); + break; + + case MotionNotify: + /* ConsoleDebug (X11, "XEVENT: MotionNotify\n"); */ + b = xy_to_button( + man, theEvent.xmotion.x, theEvent.xmotion.y); + if (b != man->select_button) { + ConsoleDebug(X11, "\tmoving select\n"); + move_highlight(man, b); + run_binding(man, SELECT); + draw_managers(); + } + break; + + case MapNotify: + ConsoleDebug(X11, "XEVENT: MapNotify\n"); + force_manager_redraw(man); + break; + + case UnmapNotify: + ConsoleDebug(X11, "XEVENT: UnmapNotify\n"); + break; + + case DestroyNotify: + ConsoleDebug(X11, "XEVENT: DestroyNotify\n"); + DeadPipe(0); + break; + + default: #ifdef SHAPE - if (theEvent.type == shapeEventBase + ShapeNotify) { - XShapeEvent *xev = (XShapeEvent *)&theEvent; - ConsoleDebug (X11, "XEVENT: ShapeNotify\n"); - ConsoleDebug (X11, "\tx, y, w, h = %d, %d, %d, %d\n", - xev->x, xev->y, xev->width, xev->height); - break; - } + if (theEvent.type == shapeEventBase + ShapeNotify) { + XShapeEvent *xev = (XShapeEvent *)&theEvent; + ConsoleDebug(X11, "XEVENT: ShapeNotify\n"); + ConsoleDebug(X11, + "\tx, y, w, h = %d, %d, %d, %d\n", xev->x, + xev->y, xev->width, xev->height); + break; + } #endif - ConsoleDebug (X11, "XEVENT: unknown\n"); - break; - } - } - check_managers_consistency(); - XFlush (theDisplay); + ConsoleDebug(X11, "XEVENT: unknown\n"); + break; + } + } + check_managers_consistency(); + XFlush(theDisplay); } -static void set_window_properties (Window win, char *name, char *icon, - XSizeHints *sizehints) +static void +set_window_properties(Window win, char *name, char *icon, XSizeHints *sizehints) { - XTextProperty win_name; - XTextProperty win_icon; - XClassHint class; - XWMHints wmhints = {0}; - - wmhints.initial_state = NormalState; - wmhints.flags = StateHint; + XTextProperty win_name; + XTextProperty win_icon; + XClassHint class; + XWMHints wmhints = {0}; - if (XStringListToTextProperty (&name, 1, &win_name) == 0) { - ConsoleMessage ("%s: cannot allocate window name.\n",Module); - return; - } - if (XStringListToTextProperty (&icon, 1, &win_icon) == 0) { - ConsoleMessage ("%s: cannot allocate window icon.\n",Module); - return; - } + wmhints.initial_state = NormalState; + wmhints.flags = StateHint; - class.res_name = Module + 1; - class.res_class = "FvwmModule"; + if (XStringListToTextProperty(&name, 1, &win_name) == 0) { + ConsoleMessage("%s: cannot allocate window name.\n", Module); + return; + } + if (XStringListToTextProperty(&icon, 1, &win_icon) == 0) { + ConsoleMessage("%s: cannot allocate window icon.\n", Module); + return; + } + class.res_name = Module + 1; + class.res_class = "FvwmModule"; - XSetWMProperties (theDisplay, win, &win_name, &win_icon, NULL, 0, - sizehints, &wmhints, &class); + XSetWMProperties(theDisplay, win, &win_name, &win_icon, NULL, 0, + sizehints, &wmhints, &class); - XFree (win_name.value); - XFree (win_icon.value); + XFree(win_name.value); + XFree(win_icon.value); } -static int load_default_context_fore (WinManager *man, int i) +static int +load_default_context_fore(WinManager *man, int i) { - int j = 0; + int j = 0; - if (theDepth > 2) - j = 1; + if (theDepth > 2) + j = 1; - ConsoleDebug (X11, "Loading: %s\n", contextDefaults[i].backcolor[j]); + ConsoleDebug(X11, "Loading: %s\n", contextDefaults[i].backcolor[j]); - return lookup_color (contextDefaults[i].forecolor[j], &man->forecolor[i]); + return lookup_color( + contextDefaults[i].forecolor[j], &man->forecolor[i]); } -static int load_default_context_back (WinManager *man, int i) +static int +load_default_context_back(WinManager *man, int i) { - int j = 0; + int j = 0; - if (theDepth > 2) - j = 1; + if (theDepth > 2) + j = 1; - ConsoleDebug (X11, "Loading: %s\n", contextDefaults[i].backcolor[j]); + ConsoleDebug(X11, "Loading: %s\n", contextDefaults[i].backcolor[j]); - return lookup_color (contextDefaults[i].backcolor[j], &man->backcolor[i]); + return lookup_color( + contextDefaults[i].backcolor[j], &man->backcolor[i]); } -void map_manager (WinManager *man) +void +map_manager(WinManager *man) { - if (man->window_mapped == 0 && man->geometry.height > 0) { - XMapWindow (theDisplay, man->theWindow); - set_manager_window_mapping (man, 1); - XFlush (theDisplay); - if (globals.transient) { - /* wait for an expose event to actually do the grab */ - grab_state = NEED_TO_GRAB; - } - } + if (man->window_mapped == 0 && man->geometry.height > 0) { + XMapWindow(theDisplay, man->theWindow); + set_manager_window_mapping(man, 1); + XFlush(theDisplay); + if (globals.transient) { + /* wait for an expose event to actually do the grab */ + grab_state = NEED_TO_GRAB; + } + } } -void unmap_manager (WinManager *man) +void +unmap_manager(WinManager *man) { - if (man->window_mapped == 1) { - XUnmapWindow (theDisplay, man->theWindow); - set_manager_window_mapping (man, 0); - XFlush (theDisplay); - } + if (man->window_mapped == 1) { + XUnmapWindow(theDisplay, man->theWindow); + set_manager_window_mapping(man, 0); + XFlush(theDisplay); + } } -#if 0 -void read_all_reparent_events (WinManager *man, int block) +void +X_init_manager(int man_id) { - XEvent evs[2]; - int i = 0, got_one = 0, the_event; - - /* We're going to be junking ConfigureNotify events, but that's ok, - since this is only going to be called from resize_manager() */ - /* This shouldn't slow things down terribly, since we'd just have to read - these events anyway */ - - assert (man->can_draw); - - if (block) { - while (1) { - XWindowEvent (theDisplay, man->theWindow, StructureNotifyMask, &evs[0]); - if (evs[0].type == ReparentNotify) { - the_event = 0; - got_one = 1; - break; - } - } - } - else { - while (XCheckWindowEvent (theDisplay, man->theWindow, StructureNotifyMask, - &evs[i])) { - if (evs[i].type == ReparentNotify) { - got_one = 1; - the_event = i; - i ^= 1; - } - } - } - if (got_one) { - reparentnotify_event (man, &evs[the_event]); - } -} -#endif + WinManager *man; + int width, height; + int i, x, y, geometry_mask; + ConsoleDebug(X11, "In X_init_manager\n"); -void X_init_manager (int man_id) -{ - WinManager *man; - int width, height; - int i, x, y, geometry_mask; - ConsoleDebug (X11, "In X_init_manager\n"); - - man = &globals.managers[man_id]; - - man->geometry.cols = DEFAULT_NUM_COLS; - man->geometry.rows = DEFAULT_NUM_ROWS; - man->geometry.x = 0; - man->geometry.y = 0; - man->gravity = NorthWestGravity; - - man->select_button = NULL; - man->cursor_in_window = 0; - man->sizehints_flags = 0; - - ConsoleDebug (X11, "boxwidth = %d\n", man->geometry.boxwidth); - - if (man->fontname) { - man->ButtonFont = XLoadQueryFont (theDisplay, man->fontname); - if (!man->ButtonFont) { - if (!(man->ButtonFont = XLoadQueryFont (theDisplay, FONT_STRING))) { - ConsoleMessage ("Can't get font\n"); - ShutMeDown (1); - } - } - } - else { - if (!(man->ButtonFont = XLoadQueryFont (theDisplay, FONT_STRING))) { - ConsoleMessage ("Can't get font\n"); - ShutMeDown (1); - } - } - - for ( i = 0; i < NUM_CONTEXTS; i++ ) { - if (man->backColorName[i]) { - if (!lookup_color (man->backColorName[i], &man->backcolor[i])) { - if (!load_default_context_back (man, i)) { - ConsoleMessage ("Can't load %s background color\n", - contextDefaults[i].name); - } - } - } - else if (!load_default_context_back (man, i)) { - ConsoleMessage ("Can't load %s background color\n", - contextDefaults[i].name); - } - - if (man->foreColorName[i]) { - if (!lookup_color (man->foreColorName[i], &man->forecolor[i])) { - if (!load_default_context_fore (man, i)) { - ConsoleMessage ("Can't load %s foreground color\n", - contextDefaults[i].name); - } - } - } - else if (!load_default_context_fore (man, i)) { - ConsoleMessage ("Can't load %s foreground color\n", - contextDefaults[i].name); - } - - if (theDepth > 2) { - man->shadowcolor[i] = GetShadow(man->backcolor[i]); - man->hicolor[i] = GetHilite(man->backcolor[i]); -#if 0 - /* thing about message id bg vs fg */ - if (!lookup_shadow_color (man->backcolor[i], &man->shadowcolor[i])) { - ConsoleMessage ("Can't load %s shadow color\n", - contextDefaults[i].name); - } - if (!lookup_hilite_color (man->backcolor[i], &man->hicolor[i])) { - ConsoleMessage ("Can't load %s hilite color\n", - contextDefaults[i].name); - } -#endif - } - } - - man->fontheight = man->ButtonFont->ascent + - man->ButtonFont->descent; - - /* silly hack to guess the minimum char width of the font - doesn't have to be perfect. */ - - man->fontwidth = XTextWidth (man->ButtonFont, ".", 1); - - /* First: get button geometry - Second: get geometry from geometry string - Third: determine the final width and height - Fourth: determine final x, y coords */ - - man->geometry.boxwidth = DEFAULT_BUTTON_WIDTH; - man->geometry.boxheight = man->fontheight + 4;; - man->geometry.dir = 0; - - geometry_mask = 0; - - if (man->button_geometry_str) { - int val; - val = XParseGeometry (man->button_geometry_str, &x, &y, &width, &height); - ConsoleDebug (X11, "button x, y, w, h = %d %d %d %d\n", x, y, width, - height); - if (val & WidthValue) - man->geometry.boxwidth = width; - if (val & HeightValue) - man->geometry.boxheight = max (man->geometry.boxheight, height); - } - if (man->geometry_str) { - geometry_mask = XParseGeometry (man->geometry_str, &man->geometry.x, - &man->geometry.y, &man->geometry.cols, - &man->geometry.rows); - - if ((geometry_mask & XValue) || (geometry_mask & YValue)) { - man->sizehints_flags |= USPosition; - if (geometry_mask & XNegative) - man->geometry.dir |= GROW_LEFT; - else - man->geometry.dir |= GROW_RIGHT; - if (geometry_mask & YNegative) - man->geometry.dir |= GROW_UP; - else - man->geometry.dir |= GROW_DOWN; - } - } - - if (man->geometry.rows == 0) { - if (man->geometry.cols == 0) { - ConsoleMessage ("You specified a 0x0 window\n"); - ShutMeDown (0); - } - else { - man->geometry.dir |= GROW_VERT; - } - man->geometry.rows = 1; - } - else { - if (man->geometry.cols == 0) { - man->geometry.dir |= GROW_HORIZ; - man->geometry.cols = 1; - } - else { - man->geometry.dir |= GROW_HORIZ | GROW_FIXED; - } - } - - man->geometry.width = man->geometry.cols * man->geometry.boxwidth; - man->geometry.height = man->geometry.rows * man->geometry.boxheight; - - if ((geometry_mask & XValue) && (geometry_mask & XNegative)) - man->geometry.x += globals.screenx - man->geometry.width; - if ((geometry_mask & YValue) && (geometry_mask & YNegative)) - man->geometry.y += globals.screeny - man->geometry.height; - - if (globals.transient) { - Window dummyroot, dummychild; - int junk; - - XQueryPointer(theDisplay, theRoot, &dummyroot, &dummychild, - &man->geometry.x, - &man->geometry.y, &junk, &junk, &junk); - man->geometry.dir |= GROW_DOWN | GROW_RIGHT; - man->sizehints_flags |= USPosition; - } - - if (man->sizehints_flags & USPosition) { - if (man->geometry.dir & GROW_DOWN) { - if (man->geometry.dir & GROW_RIGHT) + man = &globals.managers[man_id]; + + man->geometry.cols = DEFAULT_NUM_COLS; + man->geometry.rows = DEFAULT_NUM_ROWS; + man->geometry.x = 0; + man->geometry.y = 0; man->gravity = NorthWestGravity; - else if (man->geometry.dir & GROW_LEFT) - man->gravity = NorthEastGravity; - else - ConsoleMessage ("Internal error in X_init_manager\n"); - } - else if (man->geometry.dir & GROW_UP) { - if (man->geometry.dir & GROW_RIGHT) - man->gravity = SouthWestGravity; - else if (man->geometry.dir & GROW_LEFT) - man->gravity = SouthEastGravity; - else - ConsoleMessage ("Internal error in X_init_manager\n"); - } - else { - ConsoleMessage ("Internal error in X_init_manager\n"); - } - } - else { - man->geometry.dir |= GROW_DOWN | GROW_RIGHT; - man->gravity = NorthWestGravity; - } + + man->select_button = NULL; + man->cursor_in_window = 0; + man->sizehints_flags = 0; + + ConsoleDebug(X11, "boxwidth = %d\n", man->geometry.boxwidth); + + if (man->fontname) { + man->ButtonFont = XLoadQueryFont(theDisplay, man->fontname); + if (!man->ButtonFont) { + if (!(man->ButtonFont = + XLoadQueryFont(theDisplay, FONT_STRING))) { + ConsoleMessage("Can't get font\n"); + ShutMeDown(1); + } + } + } else { + if (!(man->ButtonFont = + XLoadQueryFont(theDisplay, FONT_STRING))) { + ConsoleMessage("Can't get font\n"); + ShutMeDown(1); + } + } + + for (i = 0; i < NUM_CONTEXTS; i++) { + if (man->backColorName[i]) { + if (!lookup_color( + man->backColorName[i], &man->backcolor[i])) { + if (!load_default_context_back(man, i)) { + ConsoleMessage( + "Can't load %s background color\n", + contextDefaults[i].name); + } + } + } else if (!load_default_context_back(man, i)) { + ConsoleMessage("Can't load %s background color\n", + contextDefaults[i].name); + } + + if (man->foreColorName[i]) { + if (!lookup_color( + man->foreColorName[i], &man->forecolor[i])) { + if (!load_default_context_fore(man, i)) { + ConsoleMessage( + "Can't load %s foreground color\n", + contextDefaults[i].name); + } + } + } else if (!load_default_context_fore(man, i)) { + ConsoleMessage("Can't load %s foreground color\n", + contextDefaults[i].name); + } + + if (theDepth > 2) { + man->shadowcolor[i] = GetShadow(man->backcolor[i]); + man->hicolor[i] = GetHilite(man->backcolor[i]); + } + } + + man->fontheight = man->ButtonFont->ascent + man->ButtonFont->descent; + + /* Silly hack to guess the minimum char width of the font + doesn't have to be perfect. */ + + man->fontwidth = XTextWidth(man->ButtonFont, ".", 1); + + /* First: get button geometry + Second: get geometry from geometry string + Third: determine the final width and height + Fourth: determine final x, y coords */ + + man->geometry.boxwidth = DEFAULT_BUTTON_WIDTH; + man->geometry.boxheight = man->fontheight + 4; + ; + man->geometry.dir = 0; + + geometry_mask = 0; + + if (man->button_geometry_str) { + int val; + val = XParseGeometry( + man->button_geometry_str, &x, &y, &width, &height); + ConsoleDebug(X11, "button x, y, w, h = %d %d %d %d\n", x, y, + width, height); + if (val & WidthValue) + man->geometry.boxwidth = width; + if (val & HeightValue) + man->geometry.boxheight = + max(man->geometry.boxheight, height); + } + if (man->geometry_str) { + geometry_mask = XParseGeometry(man->geometry_str, + &man->geometry.x, &man->geometry.y, &man->geometry.cols, + &man->geometry.rows); + + if ((geometry_mask & XValue) || (geometry_mask & YValue)) { + man->sizehints_flags |= USPosition; + if (geometry_mask & XNegative) + man->geometry.dir |= GROW_LEFT; + else + man->geometry.dir |= GROW_RIGHT; + if (geometry_mask & YNegative) + man->geometry.dir |= GROW_UP; + else + man->geometry.dir |= GROW_DOWN; + } + } + + if (man->geometry.rows == 0) { + if (man->geometry.cols == 0) { + ConsoleMessage("You specified a 0x0 window\n"); + ShutMeDown(0); + } else { + man->geometry.dir |= GROW_VERT; + } + man->geometry.rows = 1; + } else { + if (man->geometry.cols == 0) { + man->geometry.dir |= GROW_HORIZ; + man->geometry.cols = 1; + } else { + man->geometry.dir |= GROW_HORIZ | GROW_FIXED; + } + } + + man->geometry.width = man->geometry.cols * man->geometry.boxwidth; + man->geometry.height = man->geometry.rows * man->geometry.boxheight; + + if ((geometry_mask & XValue) && (geometry_mask & XNegative)) + man->geometry.x += globals.screenx - man->geometry.width; + if ((geometry_mask & YValue) && (geometry_mask & YNegative)) + man->geometry.y += globals.screeny - man->geometry.height; + + if (globals.transient) { + Window dummyroot, dummychild; + int junk; + + XQueryPointer(theDisplay, theRoot, &dummyroot, &dummychild, + &man->geometry.x, &man->geometry.y, &junk, &junk, &junk); + man->geometry.dir |= GROW_DOWN | GROW_RIGHT; + man->sizehints_flags |= USPosition; + } + + if (man->sizehints_flags & USPosition) { + if (man->geometry.dir & GROW_DOWN) { + if (man->geometry.dir & GROW_RIGHT) + man->gravity = NorthWestGravity; + else if (man->geometry.dir & GROW_LEFT) + man->gravity = NorthEastGravity; + else + ConsoleMessage( + "Internal error in X_init_manager\n"); + } else if (man->geometry.dir & GROW_UP) { + if (man->geometry.dir & GROW_RIGHT) + man->gravity = SouthWestGravity; + else if (man->geometry.dir & GROW_LEFT) + man->gravity = SouthEastGravity; + else + ConsoleMessage( + "Internal error in X_init_manager\n"); + } else { + ConsoleMessage("Internal error in X_init_manager\n"); + } + } else { + man->geometry.dir |= GROW_DOWN | GROW_RIGHT; + man->gravity = NorthWestGravity; + } } -void create_manager_window (int man_id) +void +create_manager_window(int man_id) { - XSizeHints sizehints; - XGCValues gcval; - unsigned long gcmask = 0; - unsigned long winattrmask = CWBackPixel| CWBorderPixel | CWEventMask | - CWBackingStore | CWBitGravity; - XSetWindowAttributes winattr; - unsigned int line_width = 1; - int line_style = LineSolid; - int cap_style = CapRound; - int join_style = JoinRound; - int i; - WinManager *man; - ConsoleDebug (X11, "In create_manager_window\n"); - - man = &globals.managers[man_id]; - - if (man->window_up) - return; - - size_manager (man); - - sizehints.flags = man->sizehints_flags; - - - sizehints.base_width = sizehints.width = man->geometry.width; - sizehints.base_height = sizehints.height = man->geometry.height; - sizehints.min_width = 0; - sizehints.max_width = globals.screenx; - sizehints.min_height = man->geometry.height; - sizehints.max_height = man->geometry.height; - sizehints.win_gravity = man->gravity; - sizehints.flags |= PBaseSize | PMinSize | PMaxSize | PWinGravity; - sizehints.x = man->geometry.x; - sizehints.y = man->geometry.y; - - - ConsoleDebug (X11, "hints: x, y, w, h = %d %d %d %d)\n", - sizehints.x, sizehints.y, - sizehints.base_width, sizehints.base_height); - ConsoleDebug (X11, "gravity: %d %d\n", sizehints.win_gravity, man->gravity); - - - winattr.background_pixel = man->backcolor[PLAIN_CONTEXT]; - winattr.border_pixel = man->forecolor[PLAIN_CONTEXT]; - winattr.backing_store = WhenMapped; - winattr.bit_gravity = man->gravity; - winattr.event_mask = ExposureMask | PointerMotionMask | EnterWindowMask | - LeaveWindowMask | KeyPressMask | StructureNotifyMask; - - if (globals.transient) - winattr.event_mask |= ButtonReleaseMask; - else - winattr.event_mask |= ButtonPressMask; - - man->theWindow = XCreateWindow (theDisplay, theRoot, sizehints.x, - sizehints.y, man->geometry.width, - man->geometry.height, - 0, CopyFromParent, InputOutput, - (Visual *)CopyFromParent, winattrmask, - &winattr); + XSizeHints sizehints; + XGCValues gcval; + unsigned long gcmask = 0; + unsigned long winattrmask = CWBackPixel | CWBorderPixel | CWEventMask | + CWBackingStore | CWBitGravity; + XSetWindowAttributes winattr; + unsigned int line_width = 1; + int line_style = LineSolid; + int cap_style = CapRound; + int join_style = JoinRound; + int i; + WinManager *man; + ConsoleDebug(X11, "In create_manager_window\n"); + + man = &globals.managers[man_id]; + + if (man->window_up) + return; + + size_manager(man); + + sizehints.flags = man->sizehints_flags; + + sizehints.base_width = sizehints.width = man->geometry.width; + sizehints.base_height = sizehints.height = man->geometry.height; + sizehints.min_width = 0; + sizehints.max_width = globals.screenx; + sizehints.min_height = man->geometry.height; + sizehints.max_height = man->geometry.height; + sizehints.win_gravity = man->gravity; + sizehints.flags |= PBaseSize | PMinSize | PMaxSize | PWinGravity; + sizehints.x = man->geometry.x; + sizehints.y = man->geometry.y; + + ConsoleDebug(X11, "hints: x, y, w, h = %d %d %d %d)\n", sizehints.x, + sizehints.y, sizehints.base_width, sizehints.base_height); + ConsoleDebug( + X11, "gravity: %d %d\n", sizehints.win_gravity, man->gravity); + + winattr.background_pixel = man->backcolor[PLAIN_CONTEXT]; + winattr.border_pixel = man->forecolor[PLAIN_CONTEXT]; + winattr.backing_store = WhenMapped; + winattr.bit_gravity = man->gravity; + winattr.event_mask = ExposureMask | PointerMotionMask | + EnterWindowMask | LeaveWindowMask | KeyPressMask | + StructureNotifyMask; + + if (globals.transient) + winattr.event_mask |= ButtonReleaseMask; + else + winattr.event_mask |= ButtonPressMask; + + man->theWindow = + XCreateWindow(theDisplay, theRoot, sizehints.x, sizehints.y, + man->geometry.width, man->geometry.height, 0, CopyFromParent, + InputOutput, (Visual *)CopyFromParent, winattrmask, &winattr); #ifdef SHAPE - XShapeSelectInput (theDisplay, man->theWindow, ShapeNotifyMask); + XShapeSelectInput(theDisplay, man->theWindow, ShapeNotifyMask); #endif - /* We really want the bit gravity to be NorthWest, so that can minimize - redraws. But, we had to have an appropriate bit gravity when creating - the window so that fvwm would place the window correctly if it has - a border. I don't know if I should wait until an event is received - before doing this. Sigh */ - winattr.bit_gravity = NorthWestGravity; - XChangeWindowAttributes (theDisplay, man->theWindow, - CWBitGravity, &winattr); - set_shape (man); - - man->theFrame = man->theWindow; - man->off_x = 0; - man->off_y = 0; - - for (i = 0; i < NUM_CONTEXTS; i++) { - man->backContext[i] = - XCreateGC (theDisplay, man->theWindow, gcmask, &gcval); - XSetForeground (theDisplay, man->backContext[i], man->backcolor[i]); - XSetLineAttributes (theDisplay, man->backContext[i], line_width, - line_style, cap_style, - join_style); - - man->hiContext[i] = - XCreateGC (theDisplay, man->theWindow, gcmask, &gcval); - XSetFont (theDisplay, man->hiContext[i], man->ButtonFont->fid); - XSetForeground (theDisplay, man->hiContext[i], man->forecolor[i]); - - gcmask = GCForeground | GCBackground; - gcval.foreground = man->backcolor[i]; - gcval.background = man->forecolor[i]; - man->flatContext[i] = XCreateGC (theDisplay, man->theWindow, - gcmask, &gcval); - if (theDepth > 2) { - gcmask = GCForeground | GCBackground; - gcval.foreground = man->hicolor[i]; - gcval.background = man->backcolor[i]; - man->reliefContext[i] = XCreateGC (theDisplay, man->theWindow, - gcmask, &gcval); - - gcmask = GCForeground | GCBackground; - gcval.foreground = man->shadowcolor[i]; - gcval.background = man->backcolor[i]; - man->shadowContext[i] = XCreateGC (theDisplay, man->theWindow, - gcmask, &gcval); - } - } - - set_window_properties (man->theWindow, man->titlename, - man->iconname, &sizehints); - man->window_up = 1; - map_manager (man); + /* We really want the bit gravity to be NorthWest, so that can minimize + redraws. But, we had to have an appropriate bit gravity when creating + the window so that fvwm would place the window correctly if it has + a border. I don't know if I should wait until an event is received + before doing this. Sigh */ + winattr.bit_gravity = NorthWestGravity; + XChangeWindowAttributes( + theDisplay, man->theWindow, CWBitGravity, &winattr); + set_shape(man); + + man->theFrame = man->theWindow; + man->off_x = 0; + man->off_y = 0; + + for (i = 0; i < NUM_CONTEXTS; i++) { + man->backContext[i] = + XCreateGC(theDisplay, man->theWindow, gcmask, &gcval); + XSetForeground( + theDisplay, man->backContext[i], man->backcolor[i]); + XSetLineAttributes(theDisplay, man->backContext[i], line_width, + line_style, cap_style, join_style); + + man->hiContext[i] = + XCreateGC(theDisplay, man->theWindow, gcmask, &gcval); + XSetFont(theDisplay, man->hiContext[i], man->ButtonFont->fid); + XSetForeground( + theDisplay, man->hiContext[i], man->forecolor[i]); + + gcmask = GCForeground | GCBackground; + gcval.foreground = man->backcolor[i]; + gcval.background = man->forecolor[i]; + man->flatContext[i] = + XCreateGC(theDisplay, man->theWindow, gcmask, &gcval); + if (theDepth > 2) { + gcmask = GCForeground | GCBackground; + gcval.foreground = man->hicolor[i]; + gcval.background = man->backcolor[i]; + man->reliefContext[i] = XCreateGC( + theDisplay, man->theWindow, gcmask, &gcval); + + gcmask = GCForeground | GCBackground; + gcval.foreground = man->shadowcolor[i]; + gcval.background = man->backcolor[i]; + man->shadowContext[i] = XCreateGC( + theDisplay, man->theWindow, gcmask, &gcval); + } + } + + set_window_properties( + man->theWindow, man->titlename, man->iconname, &sizehints); + man->window_up = 1; + map_manager(man); } -static int handle_error (Display *d, XErrorEvent *ev) +static int +handle_error(Display *d, XErrorEvent *ev) { - ConsoleMessage ("X Error:\n"); - ConsoleMessage (" error code: %d\n", ev->error_code); - ConsoleMessage (" request code: %d\n", ev->request_code); - ConsoleMessage (" minor code: %d\n", ev->minor_code); - ConsoleMessage ("Leaving a core dump now\n"); - abort(); - return 0; + ConsoleMessage("X Error:\n"); + ConsoleMessage(" error code: %d\n", ev->error_code); + ConsoleMessage(" request code: %d\n", ev->request_code); + ConsoleMessage(" minor code: %d\n", ev->minor_code); + ConsoleMessage("Leaving a core dump now\n"); + abort(); + return 0; } -void init_display (void) +void +init_display(void) { - theDisplay = XOpenDisplay (""); - if (theDisplay == NULL) { - ConsoleMessage ("Can't open display: %s\n", XDisplayName ("")); - ShutMeDown (1); - } - XSetErrorHandler (handle_error); - x_fd = XConnectionNumber (theDisplay); - theScreen = DefaultScreen (theDisplay); - theRoot = RootWindow (theDisplay, theScreen); - theDepth = DefaultDepth (theDisplay, theScreen); + theDisplay = XOpenDisplay(""); + if (theDisplay == NULL) { + ConsoleMessage("Can't open display: %s\n", XDisplayName("")); + ShutMeDown(1); + } + XSetErrorHandler(handle_error); + x_fd = XConnectionNumber(theDisplay); + theScreen = DefaultScreen(theDisplay); + theRoot = RootWindow(theDisplay, theScreen); + theDepth = DefaultDepth(theDisplay, theScreen); #ifdef TEST_MONO - theDepth = 2; + theDepth = 2; #endif - globals.screenx = DisplayWidth (theDisplay, theScreen); - globals.screeny = DisplayHeight (theDisplay, theScreen); + globals.screenx = DisplayWidth(theDisplay, theScreen); + globals.screeny = DisplayHeight(theDisplay, theScreen); #ifdef SHAPE - globals.shapes_supported = XShapeQueryExtension (theDisplay, &shapeEventBase, - &shapeErrorBase); + globals.shapes_supported = + XShapeQueryExtension(theDisplay, &shapeEventBase, &shapeErrorBase); #endif - InitPictureCMap (theDisplay, theRoot); + InitPictureCMap(theDisplay, theRoot); - ConsoleDebug (X11, "screen width: %ld\n", globals.screenx); - ConsoleDebug (X11, "screen height: %ld\n", globals.screeny); + ConsoleDebug(X11, "screen width: %ld\n", globals.screenx); + ConsoleDebug(X11, "screen height: %ld\n", globals.screeny); } Index: fvwm/modules/FvwmIconMan/x.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIconMan/x.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIconMan/x.h --- fvwm/modules/FvwmIconMan/x.h +++ fvwm/modules/FvwmIconMan/x.h @@ -1,6 +1,10 @@ #ifndef IN_X_H #define IN_X_H +#include + +#include "FvwmIconMan.h" + #ifdef SHAPE #include #endif @@ -9,14 +13,14 @@ extern Display *theDisplay; extern Window theRoot; extern int theDepth, theScreen; -extern void unmap_manager (WinManager *man); -extern void map_manager (WinManager *man); +extern void unmap_manager(WinManager *man); +extern void map_manager(WinManager *man); -extern Window find_frame_window (Window win, int *off_x, int *off_y); +extern Window find_frame_window(Window win, int *off_x, int *off_y); -extern void init_display (void); -extern void xevent_loop (void); -extern void create_manager_window (int man_id); -extern void X_init_manager (int man_id); +extern void init_display(void); +extern void xevent_loop(void); +extern void create_manager_window(int man_id); +extern void X_init_manager(int man_id); #endif Index: fvwm/modules/FvwmIconMan/xmanager.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIconMan/xmanager.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIconMan/xmanager.c --- fvwm/modules/FvwmIconMan/xmanager.c +++ fvwm/modules/FvwmIconMan/xmanager.c @@ -1,12 +1,14 @@ -#include "config.h" +#include "xmanager.h" #include +#include + #include "FvwmIconMan.h" +#include "config.h" #include "x.h" -#include "xmanager.h" static char const rcsid[] = - "$Id: xmanager.c,v 1.1.1.1 2006/11/26 10:53:51 matthieu Exp $"; + "$Id: xmanager.c,v 1.1.1.1 2006/11/26 10:53:51 matthieu Exp $"; #ifdef SHAPE #include @@ -19,1432 +21,1497 @@ static char const rcsid[] = #endif /* button dirty bits: */ -#define ICON_STATE_CHANGED 1 -#define STATE_CHANGED 2 -#define PICTURE_CHANGED 4 -#define WINDOW_CHANGED 8 -#define STRING_CHANGED 16 -#define REDRAW_BUTTON 32 -#define GEOMETRY_CHANGED 64 +#define ICON_STATE_CHANGED 1 +#define STATE_CHANGED 2 +#define PICTURE_CHANGED 4 +#define WINDOW_CHANGED 8 +#define STRING_CHANGED 16 +#define REDRAW_BUTTON 32 +#define GEOMETRY_CHANGED 64 /* manager dirty bits: */ /* GEOMETRY_CHANGED 64 same as with button */ -#define MAPPING_CHANGED 2 -#define SHAPE_CHANGED 4 -#define REDRAW_MANAGER 8 +#define MAPPING_CHANGED 2 +#define SHAPE_CHANGED 4 +#define REDRAW_MANAGER 8 /* ButtonArray dirty bits: */ #define NUM_BUTTONS_CHANGED 1 #define NUM_WINDOWS_CHANGED 2 -#define ALL_CHANGED 0x7f /* high bit is special */ +#define ALL_CHANGED 0x7f /* high bit is special */ typedef struct { - int button_x, button_y, button_h, button_w; /* dim's of the whole button */ - int icon_x, icon_y, icon_h, icon_w; /* what denotes icon state */ - int text_x, text_y, text_h, text_w; /* text field */ - int text_base; /* text baseline */ + int button_x, button_y, button_h, + button_w; /* dim's of the whole button */ + int icon_x, icon_y, icon_h, icon_w; /* what denotes icon state */ + int text_x, text_y, text_h, text_w; /* text field */ + int text_base; /* text baseline */ } ButtonGeometry; -static void print_button_info (Button *b); -static void insert_windows_button (WinData *win); +static void print_button_info(Button *b); +static void insert_windows_button(WinData *win); /***************************************************************************/ /* Utility leaf functions */ /***************************************************************************/ -static int selected_button_in_man (WinManager *man) +static int +selected_button_in_man(WinManager *man) { - assert (man); - ConsoleDebug (X11, "selected_button_in_man: %p\n", - globals.select_win); - if (globals.select_win && globals.select_win->button && - globals.select_win->manager == man) { - return globals.select_win->button->index; - } - return -1; + assert(man); + ConsoleDebug(X11, "selected_button_in_man: %p\n", globals.select_win); + if (globals.select_win && globals.select_win->button && + globals.select_win->manager == man) { + return globals.select_win->button->index; + } + return -1; } -static void ClipRectangle (WinManager *man, int context, - int x, int y, int w, int h) +static void +ClipRectangle(WinManager *man, int context, int x, int y, int w, int h) { - XRectangle r; + XRectangle r; - r.x = x; - r.y = y; - r.width = w; - r.height = h; + r.x = x; + r.y = y; + r.width = w; + r.height = h; - XSetClipRectangles(theDisplay, man->hiContext[context], 0, 0, &r, 1, - YXBanded); + XSetClipRectangles( + theDisplay, man->hiContext[context], 0, 0, &r, 1, YXBanded); } -static int num_visible_rows (int n, int cols) +static int +num_visible_rows(int n, int cols) { - return (n - 1) / cols + 1; + return (n - 1) / cols + 1; } -static int first_row_len (int n, int cols) +static int +first_row_len(int n, int cols) { - int ret = n % cols; - if (ret == 0) - ret = cols; - return ret; + int ret = n % cols; + if (ret == 0) + ret = cols; + return ret; } -static int index_to_box (WinManager *man, int index) +static int +index_to_box(WinManager *man, int index) { - int first_len, n, cols; + int first_len, n, cols; - if (man->geometry.dir & GROW_DOWN) { - return index; - } - else { - n = man->buttons.num_windows; - cols = man->geometry.cols; - first_len = first_row_len (n, cols); - if (index >= first_len) - index += cols - first_len; - index += (man->geometry.rows - num_visible_rows (n, cols)) * cols; - return index; - } + if (man->geometry.dir & GROW_DOWN) { + return index; + } else { + n = man->buttons.num_windows; + cols = man->geometry.cols; + first_len = first_row_len(n, cols); + if (index >= first_len) + index += cols - first_len; + index += + (man->geometry.rows - num_visible_rows(n, cols)) * cols; + return index; + } } -static int box_to_index (WinManager *man, int box) +static int +box_to_index(WinManager *man, int box) { - int first_len, n, cols; + int first_len, n, cols; - if (man->geometry.dir & GROW_DOWN) { - return box; - } - else { - n = man->buttons.num_windows; - cols = man->geometry.cols; - first_len = first_row_len (n, cols); + if (man->geometry.dir & GROW_DOWN) { + return box; + } else { + n = man->buttons.num_windows; + cols = man->geometry.cols; + first_len = first_row_len(n, cols); - box -= (man->geometry.rows - num_visible_rows (n, cols)) * cols; - if (!((box >= 0 && box < first_len) || box >= cols)) - return -1; - if (box >= first_len) - box -= cols - first_len; - return box; - } + box -= (man->geometry.rows - num_visible_rows(n, cols)) * cols; + if (!((box >= 0 && box < first_len) || box >= cols)) + return -1; + if (box >= first_len) + box -= cols - first_len; + return box; + } } -static int index_to_row (WinManager *man, int index) +static int +index_to_row(WinManager *man, int index) { - int row; + int row; - row = index_to_box (man, index) / man->geometry.cols; + row = index_to_box(man, index) / man->geometry.cols; - return row; + return row; } -static int index_to_col (WinManager *man, int index) +static int +index_to_col(WinManager *man, int index) { - int col; + int col; - col = index_to_box (man, index) % man->geometry.cols; + col = index_to_box(man, index) % man->geometry.cols; - return col; + return col; } -static int rects_equal (XRectangle *x, XRectangle *y) +static int +rects_equal(XRectangle *x, XRectangle *y) { - return (x->x == y->x) && (x->y == y->y) && (x->width == y->width) && - (x->height == y->height); + return (x->x == y->x) && (x->y == y->y) && (x->width == y->width) && + (x->height == y->height); } -static int top_y_coord (WinManager *man) +static int +top_y_coord(WinManager *man) { - if (man->buttons.num_windows > 0 && (man->geometry.dir & GROW_UP)) { - return index_to_row (man, 0) * man->geometry.boxheight; - } - else { - return 0; - } + if (man->buttons.num_windows > 0 && (man->geometry.dir & GROW_UP)) { + return index_to_row(man, 0) * man->geometry.boxheight; + } else { + return 0; + } } -static ManGeometry *figure_geometry (WinManager *man) +static ManGeometry * +figure_geometry(WinManager *man) { - /* Given the number of wins in icon_list and width x height, compute - new geometry. */ - /* if GROW_FIXED is set, don't change window geometry */ + /* Given the number of wins in icon_list and width x height, compute + new geometry. */ + /* if GROW_FIXED is set, don't change window geometry */ - static ManGeometry ret; - ManGeometry *g = &man->geometry; - int n = man->buttons.num_windows; + static ManGeometry ret; + ManGeometry *g = &man->geometry; + int n = man->buttons.num_windows; - ret = *g; + ret = *g; - ConsoleDebug (X11, "figure_geometry: %s: %d, %d %d %d %d\n", - man->titlename, n, - ret.width, ret.height, ret.cols, ret.rows); + ConsoleDebug(X11, "figure_geometry: %s: %d, %d %d %d %d\n", + man->titlename, n, ret.width, ret.height, ret.cols, ret.rows); - if (n == 0) { - n = 1; - } + if (n == 0) { + n = 1; + } - if (man->geometry.dir & GROW_FIXED) { - ret.cols = num_visible_rows (n, g->rows); - ret.boxwidth = ret.width / ret.cols; - } - else { - if (man->geometry.dir & GROW_VERT) { - if (g->cols) { - ret.rows = num_visible_rows (n, g->cols); - } - else { - ConsoleMessage ("Internal error in figure_geometry\n"); - ret.rows = 1; - } - ret.height = ret.rows * g->boxheight; - ret.width = ret.cols * g->boxwidth; - } - else { - /* need to set resize inc */ - if (g->rows) { - ret.cols = num_visible_rows (n, g->rows); - } - else { - ConsoleMessage ("Internal error in figure_geometry\n"); - ret.cols = 1; - } - ret.height = ret.rows * g->boxheight; - ret.width = ret.cols * g->boxwidth; - } - } + if (man->geometry.dir & GROW_FIXED) { + ret.cols = num_visible_rows(n, g->rows); + ret.boxwidth = ret.width / ret.cols; + } else { + if (man->geometry.dir & GROW_VERT) { + if (g->cols) { + ret.rows = num_visible_rows(n, g->cols); + } else { + ConsoleMessage( + "Internal error in figure_geometry\n"); + ret.rows = 1; + } + ret.height = ret.rows * g->boxheight; + ret.width = ret.cols * g->boxwidth; + } else { + /* need to set resize inc */ + if (g->rows) { + ret.cols = num_visible_rows(n, g->rows); + } else { + ConsoleMessage( + "Internal error in figure_geometry\n"); + ret.cols = 1; + } + ret.height = ret.rows * g->boxheight; + ret.width = ret.cols * g->boxwidth; + } + } - ConsoleDebug (X11, "figure_geometry: %d %d %d %d %d\n", - n, ret.width, ret.height, ret.cols, ret.rows); + ConsoleDebug(X11, "figure_geometry: %d %d %d %d %d\n", n, ret.width, + ret.height, ret.cols, ret.rows); - return &ret; + return &ret; } -static ManGeometry *query_geometry (WinManager *man) +static ManGeometry * +query_geometry(WinManager *man) { - XWindowAttributes frame_attr, win_attr; - int off_x, off_y; - static ManGeometry g; + XWindowAttributes frame_attr, win_attr; + int off_x, off_y; + static ManGeometry g; - assert (man->window_mapped); + assert(man->window_mapped); - off_x = 0; - off_y = 0; - man->theFrame = find_frame_window (man->theWindow, &off_x, &off_y); - XGetWindowAttributes (theDisplay, man->theFrame, &frame_attr); - g.x = frame_attr.x + off_x + frame_attr.border_width; - g.y = frame_attr.y + off_y + frame_attr.border_width; - XGetWindowAttributes (theDisplay, man->theWindow, &win_attr); - g.width = win_attr.width; - g.height = win_attr.height; + off_x = 0; + off_y = 0; + man->theFrame = find_frame_window(man->theWindow, &off_x, &off_y); + XGetWindowAttributes(theDisplay, man->theFrame, &frame_attr); + g.x = frame_attr.x + off_x + frame_attr.border_width; + g.y = frame_attr.y + off_y + frame_attr.border_width; + XGetWindowAttributes(theDisplay, man->theWindow, &win_attr); + g.width = win_attr.width; + g.height = win_attr.height; - return &g; + return &g; } -static void fix_manager_size (WinManager *man, int w, int h) +static void +fix_manager_size(WinManager *man, int w, int h) { - XSizeHints size; - long mask; + XSizeHints size; + long mask = 0; + + if (!XGetWMNormalHints(theDisplay, man->theWindow, &size, &mask)) { + memset(&size, 0, sizeof(size)); + size.flags = 0; + } - XGetWMNormalHints (theDisplay, man->theWindow, &size, &mask); - size.min_width = w; - size.max_width = w; - size.min_height = h; - size.max_height = h; - XSetWMNormalHints (theDisplay, man->theWindow, &size); + size.flags |= PMinSize | PMaxSize | PBaseSize | PWinGravity; + size.min_width = w; + size.max_width = w; + size.min_height = h; + size.max_height = h; + size.base_width = w; + size.base_height = h; + size.win_gravity = man->gravity; + + XSetWMNormalHints(theDisplay, man->theWindow, &size); } /* Like XMoveResizeWindow(), but can move in arbitary directions */ -static void resize_window (WinManager *man) -{ - ManGeometry *g; - int x_changed, y_changed, dir; - - dir = man->geometry.dir; - fix_manager_size (man, man->geometry.width, man->geometry.height); - - if ((dir & GROW_DOWN) && (dir & GROW_RIGHT)) { - XResizeWindow (theDisplay, man->theWindow, man->geometry.width, - man->geometry.height); - } - else { - MyXGrabServer (theDisplay); - g = query_geometry (man); - x_changed = y_changed = 0; - if (dir & GROW_LEFT) { - man->geometry.x = g->x + g->width - man->geometry.width; - x_changed = 1; - } - else { - man->geometry.x = g->x; - } - if (dir & GROW_UP) { - man->geometry.y = g->y + g->height - man->geometry.height; - y_changed = 1; - } - else { - man->geometry.y = g->y; - } - - ConsoleDebug (X11, "queried: y: %d, h: %d, queried: %d\n", g->y, - man->geometry.height, g->height); - - if (x_changed || y_changed) { - XMoveResizeWindow (theDisplay, man->theWindow, - man->geometry.x, - man->geometry.y, - man->geometry.width, man->geometry.height); - } - else { - XResizeWindow (theDisplay, man->theWindow, man->geometry.width, - man->geometry.height); - } - MyXUngrabServer (theDisplay); - } -} - -static char *make_display_string (WinData *win, char *format, int len) +static void +resize_window(WinManager *man) +{ + ManGeometry *g; + int x_changed, y_changed, dir; + + dir = man->geometry.dir; + fix_manager_size(man, man->geometry.width, man->geometry.height); + + if ((dir & GROW_DOWN) && (dir & GROW_RIGHT)) { + XResizeWindow(theDisplay, man->theWindow, man->geometry.width, + man->geometry.height); + } else { + MyXGrabServer(theDisplay); + g = query_geometry(man); + x_changed = y_changed = 0; + if (dir & GROW_LEFT) { + man->geometry.x = g->x + g->width - man->geometry.width; + x_changed = 1; + } else { + man->geometry.x = g->x; + } + if (dir & GROW_UP) { + man->geometry.y = + g->y + g->height - man->geometry.height; + y_changed = 1; + } else { + man->geometry.y = g->y; + } + + ConsoleDebug(X11, "queried: y: %d, h: %d, queried: %d\n", g->y, + man->geometry.height, g->height); + + if (x_changed || y_changed) { + XMoveResizeWindow(theDisplay, man->theWindow, + man->geometry.x, man->geometry.y, + man->geometry.width, man->geometry.height); + } else { + XResizeWindow(theDisplay, man->theWindow, + man->geometry.width, man->geometry.height); + } + MyXUngrabServer(theDisplay); + } +} + +static char * +make_display_string(WinData *win, char *format, int len) { #define MAX_DISPLAY_SIZE 1024 -#define COPY(field) \ - temp_p = win->field; \ - if (temp_p) \ - while (*temp_p && out_p - buf < len - 1) \ - *out_p++ = *temp_p++; \ - in_p++; - - static char buf[MAX_DISPLAY_SIZE]; - char *string, *in_p, *out_p, *temp_p; - - in_p = format; - out_p = buf; - - if (len > MAX_DISPLAY_SIZE || len <= 0) - len = MAX_DISPLAY_SIZE; - - while (*in_p && out_p - buf < len - 1) { - if (*in_p == '%') { - switch (*(++in_p)) { - case 'i': - COPY (iconname); - break; - - case 't': - COPY (titlename); - break; - - case 'r': - COPY (resname); - break; - - case 'c': - COPY (classname); - break; - - default: - *out_p++ = *in_p++; - break; - } - } - else { - *out_p++ = *in_p++; - } - } - - *out_p++ = '\0'; - - string = buf; - return string; +#define COPY(field) \ + temp_p = win->field; \ + if (temp_p) \ + while (*temp_p && out_p - buf < len - 1) \ + *out_p++ = *temp_p++; \ + in_p++; + + static char buf[MAX_DISPLAY_SIZE]; + char *string, *in_p, *out_p, *temp_p; + + in_p = format; + out_p = buf; + + if (len > MAX_DISPLAY_SIZE || len <= 0) + len = MAX_DISPLAY_SIZE; + + while (*in_p && out_p - buf < len - 1) { + if (*in_p == '%') { + switch (*(++in_p)) { + case 'i': + COPY(iconname); + break; + + case 't': + COPY(titlename); + break; + + case 'r': + COPY(resname); + break; + + case 'c': + COPY(classname); + break; + + default: + *out_p++ = *in_p++; + break; + } + } else { + *out_p++ = *in_p++; + } + } + + *out_p++ = '\0'; + + string = buf; + return string; #undef COPY #undef MAX_DISPLAY_SIZE } -Button *button_above (WinManager *man, Button *b) +Button * +button_above(WinManager *man, Button *b) { - int n = man->buttons.num_windows, cols = man->geometry.cols; - int i = -1; + int n = man->buttons.num_windows, cols = man->geometry.cols; + int i = -1; - if (b) { - i = box_to_index (man, index_to_box (man, b->index) - cols); - } - if (i < 0 || i >= n) - return b; - else - return man->buttons.buttons[i]; + if (b) { + i = box_to_index(man, index_to_box(man, b->index) - cols); + } + if (i < 0 || i >= n) + return b; + else + return man->buttons.buttons[i]; } -Button *button_below (WinManager *man, Button *b) +Button * +button_below(WinManager *man, Button *b) { - int n = man->buttons.num_windows; - int i = -1; + int n = man->buttons.num_windows; + int i = -1; - if (b) { - i = box_to_index (man, index_to_box (man, b->index) + man->geometry.cols); - } - if (i < 0 || i >= n) - return b; - else - return man->buttons.buttons[i]; + if (b) { + i = box_to_index( + man, index_to_box(man, b->index) + man->geometry.cols); + } + if (i < 0 || i >= n) + return b; + else + return man->buttons.buttons[i]; } -Button *button_right (WinManager *man, Button *b) +Button * +button_right(WinManager *man, Button *b) { - int i = 0; + int i = 0; - if (index_to_col (man, b->index) < man->geometry.cols - 1) { - i = box_to_index (man, index_to_box (man, b->index) + 1); - } + if (index_to_col(man, b->index) < man->geometry.cols - 1) { + i = box_to_index(man, index_to_box(man, b->index) + 1); + } - if (i < 0 || i >= man->buttons.num_windows) - return b; - else - return man->buttons.buttons[i]; + if (i < 0 || i >= man->buttons.num_windows) + return b; + else + return man->buttons.buttons[i]; } -Button *button_left (WinManager *man, Button *b) +Button * +button_left(WinManager *man, Button *b) { - int i; - if (index_to_col (man, b->index) > 0) { - i = box_to_index (man, index_to_box (man, b->index) - 1); - } + int i; + if (index_to_col(man, b->index) > 0) { + i = box_to_index(man, index_to_box(man, b->index) - 1); + } - if (i < 0 || i >= man->buttons.num_windows) - return b; - else - return man->buttons.buttons[i]; + if (i < 0 || i >= man->buttons.num_windows) + return b; + else + return man->buttons.buttons[i]; } -Button *button_next (WinManager *man, Button *b) +Button * +button_next(WinManager *man, Button *b) { - int i = b->index + 1; + int i = b->index + 1; - if (i >= 0 && i < man->buttons.num_windows) - return man->buttons.buttons[i]; - else - return b; + if (i >= 0 && i < man->buttons.num_windows) + return man->buttons.buttons[i]; + else + return b; } -Button *button_prev (WinManager *man, Button *b) +Button * +button_prev(WinManager *man, Button *b) { - int i = b->index - 1; + int i = b->index - 1; - if (i >= 0 && i < man->buttons.num_windows) - return man->buttons.buttons[i]; - else - return b; + if (i >= 0 && i < man->buttons.num_windows) + return man->buttons.buttons[i]; + else + return b; } -Button *xy_to_button (WinManager *man, int x, int y) +Button * +xy_to_button(WinManager *man, int x, int y) { - int row = y / man->geometry.boxheight; - int col = x / man->geometry.boxwidth; - int box, index; + int row = y / man->geometry.boxheight; + int col = x / man->geometry.boxwidth; + int box, index; - if (x >= 0 && x <= man->geometry.width && - y >= 0 && y <= man->geometry.height) { - box = row * man->geometry.cols + col; - index = box_to_index (man, box); - if (index >= 0 && index < man->buttons.num_windows) - return man->buttons.buttons[index]; - } + if (x >= 0 && x <= man->geometry.width && y >= 0 && + y <= man->geometry.height) { + box = row * man->geometry.cols + col; + index = box_to_index(man, box); + if (index >= 0 && index < man->buttons.num_windows) + return man->buttons.buttons[index]; + } - return NULL; + return NULL; } /***************************************************************************/ /* Routines which change dirtyable state */ /***************************************************************************/ -static void set_button_geometry (WinManager *man, Button *box) +static void +set_button_geometry(WinManager *man, Button *box) { - box->x = index_to_col (man, box->index) * man->geometry.boxwidth; - box->y = index_to_row (man, box->index) * man->geometry.boxheight; - box->w = man->geometry.boxwidth; - box->h = man->geometry.boxheight; - box->drawn_state.dirty_flags |= GEOMETRY_CHANGED; + box->x = index_to_col(man, box->index) * man->geometry.boxwidth; + box->y = index_to_row(man, box->index) * man->geometry.boxheight; + box->w = man->geometry.boxwidth; + box->h = man->geometry.boxheight; + box->drawn_state.dirty_flags |= GEOMETRY_CHANGED; } -static void clear_button (Button *b) +static void +clear_button(Button *b) { - assert (b); - b->drawn_state.win = NULL; - b->drawn_state.dirty_flags = REDRAW_BUTTON; + assert(b); + b->drawn_state.win = NULL; + b->drawn_state.dirty_flags = REDRAW_BUTTON; } -static void set_window_button (WinData *win, int index) +static void +set_window_button(WinData *win, int index) { - Button *b; + Button *b; - assert (win->manager && index < win->manager->buttons.num_buttons); + assert(win->manager && index < win->manager->buttons.num_buttons); - b = win->manager->buttons.buttons[index]; + b = win->manager->buttons.buttons[index]; - /* Can optimize here */ + /* Can optimize here */ #ifdef MINI_ICONS - b->drawn_state.pic = win->pic; + b->drawn_state.pic = win->pic; #endif - b->drawn_state.win = win; - b->drawn_state.display_string = win->display_string; - b->drawn_state.iconified = win->iconified; - b->drawn_state.state = win->state; - b->drawn_state.dirty_flags = ALL_CHANGED; - - win->button = b; -} + b->drawn_state.win = win; + b->drawn_state.display_string = win->display_string; + b->drawn_state.iconified = win->iconified; + b->drawn_state.state = win->state; + b->drawn_state.dirty_flags = ALL_CHANGED; -static void *Realloc (void *ptr, int size) -{ - if (ptr == NULL) - return safemalloc (size); - else - return realloc (ptr, size); + win->button = b; } -static void set_num_buttons (ButtonArray *buttons, int n) +static void +set_num_buttons(ButtonArray *buttons, int n) { - int i; + int i; - ConsoleDebug (X11, "set_num_buttons: %d %d\n", buttons->num_buttons, n); + ConsoleDebug(X11, "set_num_buttons: %d %d\n", buttons->num_buttons, n); - if (n > buttons->num_buttons) { - buttons->dirty_flags |= NUM_BUTTONS_CHANGED; - buttons->buttons = (Button **)Realloc (buttons->buttons, - n * sizeof (Button *)); - if (buttons->buttons == NULL) { - ConsoleMessage ("Realloc failed! Bailing out\n"); - ShutMeDown(1); - } + if (n > buttons->num_buttons) { + buttons->dirty_flags |= NUM_BUTTONS_CHANGED; + buttons->buttons = + (Button **)xreallocarray(buttons->buttons, n, + sizeof(Button *)); - for (i = buttons->num_buttons; i < n; i++) { - buttons->buttons[i] = (Button *)safemalloc (sizeof (Button)); - buttons->buttons[i]->index = i; - buttons->buttons[i]->drawn_state.dirty_flags = 0; - buttons->buttons[i]->drawn_state.w = 0; - buttons->buttons[i]->drawn_state.h = 0; - buttons->buttons[i]->drawn_state.win = NULL; - } + for (i = buttons->num_buttons; i < n; i++) { + buttons->buttons[i] = + (Button *)xmalloc(sizeof(Button)); + buttons->buttons[i]->index = i; + buttons->buttons[i]->drawn_state.dirty_flags = 0; + buttons->buttons[i]->drawn_state.w = 0; + buttons->buttons[i]->drawn_state.h = 0; + buttons->buttons[i]->drawn_state.win = NULL; + } - buttons->dirty_flags |= NUM_BUTTONS_CHANGED; - buttons->num_buttons = n; - } + buttons->dirty_flags |= NUM_BUTTONS_CHANGED; + buttons->num_buttons = n; + } } -static void increase_num_windows (ButtonArray *buttons, int off) +static void +increase_num_windows(ButtonArray *buttons, int off) { - int n; + int n; - if (off != 0) { - buttons->num_windows += off; - buttons->dirty_flags |= NUM_WINDOWS_CHANGED; + if (off != 0) { + buttons->num_windows += off; + buttons->dirty_flags |= NUM_WINDOWS_CHANGED; - if (buttons->num_windows > buttons->num_buttons) { - n = buttons->num_windows + 10; - set_num_buttons (buttons, n); - } - } + if (buttons->num_windows > buttons->num_buttons) { + n = buttons->num_windows + 10; + set_num_buttons(buttons, n); + } + } } -static void set_man_gravity_origin (WinManager *man) +static void +set_man_gravity_origin(WinManager *man) { - if (man->gravity == NorthWestGravity || man->gravity == NorthEastGravity) - man->geometry.gravity_y = 0; - else - man->geometry.gravity_y = man->geometry.height; - if (man->gravity == NorthWestGravity || man->gravity == SouthWestGravity) - man->geometry.gravity_x = 0; - else - man->geometry.gravity_x = man->geometry.width; + if (man->gravity == NorthWestGravity || + man->gravity == NorthEastGravity) + man->geometry.gravity_y = 0; + else + man->geometry.gravity_y = man->geometry.height; + if (man->gravity == NorthWestGravity || + man->gravity == SouthWestGravity) + man->geometry.gravity_x = 0; + else + man->geometry.gravity_x = man->geometry.width; } -static void set_man_geometry (WinManager *man, ManGeometry *new) +static void +set_man_geometry(WinManager *man, ManGeometry *new) { - int n; + int n; - if (man->geometry.width != new->width || - man->geometry.height != new->height || - man->geometry.rows != new->rows || - man->geometry.cols != new->cols || - man->geometry.boxheight != new->boxheight || - man->geometry.boxwidth != new->boxwidth) { - man->dirty_flags |= GEOMETRY_CHANGED; - } + if (man->geometry.width != new->width || + man->geometry.height != new->height || + man->geometry.rows != new->rows || + man->geometry.cols != new->cols || + man->geometry.boxheight != new->boxheight || + man->geometry.boxwidth != new->boxwidth) { + man->dirty_flags |= GEOMETRY_CHANGED; + } - man->geometry = *new; - set_man_gravity_origin (man); - n = man->geometry.rows * man->geometry.cols; - if (man->buttons.num_buttons < n) - set_num_buttons (&man->buttons, n + 10); + man->geometry = *new; + set_man_gravity_origin(man); + n = man->geometry.rows * man->geometry.cols; + if (man->buttons.num_buttons < n) + set_num_buttons(&man->buttons, n + 10); } -void set_manager_width (WinManager *man, int width) +void +set_manager_width(WinManager *man, int width) { - if (width != man->geometry.width) { - ConsoleDebug (X11, "set_manager_width: %d -> %d, %d -> %d\n", - man->geometry.width, width, man->geometry.boxwidth, - width / man->geometry.cols); - man->geometry.width = width; - man->geometry.boxwidth = width / man->geometry.cols; - man->dirty_flags |= GEOMETRY_CHANGED; - } + if (width != man->geometry.width) { + ConsoleDebug(X11, "set_manager_width: %d -> %d, %d -> %d\n", + man->geometry.width, width, man->geometry.boxwidth, + width / man->geometry.cols); + man->geometry.width = width; + man->geometry.boxwidth = width / man->geometry.cols; + man->dirty_flags |= GEOMETRY_CHANGED; + } } -void force_manager_redraw (WinManager *man) +void +force_manager_redraw(WinManager *man) { - man->dirty_flags |= REDRAW_MANAGER; - draw_manager (man); + man->dirty_flags |= REDRAW_MANAGER; + draw_manager(man); } #ifdef MINI_ICONS -void set_win_picture (WinData *win, Pixmap picture, Pixmap mask, - unsigned int depth, unsigned int width, - unsigned int height) +void +set_win_picture(WinData *win, Pixmap picture, Pixmap mask, unsigned int depth, + unsigned int width, unsigned int height) { - if (win->button) - win->button->drawn_state.dirty_flags |= PICTURE_CHANGED; - win->pic.picture = picture; - win->pic.mask = mask; - win->pic.width = width; - win->pic.height = height; - win->pic.depth = depth; + if (win->button) + win->button->drawn_state.dirty_flags |= PICTURE_CHANGED; + win->pic.picture = picture; + win->pic.mask = mask; + win->pic.width = width; + win->pic.height = height; + win->pic.depth = depth; } #endif -void set_win_iconified (WinData *win, int iconified) +void +set_win_iconified(WinData *win, int iconified) { - if (win->button && win->iconified != iconified) - win->button->drawn_state.dirty_flags |= ICON_STATE_CHANGED; - win->iconified = iconified; + if (win->button && win->iconified != iconified) + win->button->drawn_state.dirty_flags |= ICON_STATE_CHANGED; + win->iconified = iconified; } -void set_win_state (WinData *win, int state) +void +set_win_state(WinData *win, int state) { - if (win->button && win->state != state) - win->button->drawn_state.dirty_flags |= STATE_CHANGED; - win->state = state; + if (win->button && win->state != state) + win->button->drawn_state.dirty_flags |= STATE_CHANGED; + win->state = state; } -void add_win_state (WinData *win, int flag) +void +add_win_state(WinData *win, int flag) { - if (win->button && (win->state & flag) == 0) - win->button->drawn_state.dirty_flags |= STATE_CHANGED; - win->state |= flag; - ConsoleDebug (X11, "add_win_state: %s 0x%x\n", win->titlename, flag); + if (win->button && (win->state & flag) == 0) + win->button->drawn_state.dirty_flags |= STATE_CHANGED; + win->state |= flag; + ConsoleDebug(X11, "add_win_state: %s 0x%x\n", win->titlename, flag); } -void del_win_state (WinData *win, int flag) +void +del_win_state(WinData *win, int flag) { - if (win->button && (win->state & flag)) - win->button->drawn_state.dirty_flags |= STATE_CHANGED; - win->state &= ~flag; - ConsoleDebug (X11, "del_win_state: %s 0x%x\n", win->titlename, flag); + if (win->button && (win->state & flag)) + win->button->drawn_state.dirty_flags |= STATE_CHANGED; + win->state &= ~flag; + ConsoleDebug(X11, "del_win_state: %s 0x%x\n", win->titlename, flag); } -void set_win_displaystring (WinData *win) +void +set_win_displaystring(WinData *win) { - WinManager *man = win->manager; - int maxlen; + WinManager *man = win->manager; + int maxlen; + int used_resource_placeholder = 0; - if (!man || ((man->format_depend & CLASS_NAME) && !win->classname) - || ((man->format_depend & ICON_NAME) && !win->iconname) - || ((man->format_depend & TITLE_NAME) && !win->titlename) - || ((man->format_depend & RESOURCE_NAME) && !win->resname)) { - return; - } + if (!man || ((man->format_depend & CLASS_NAME) && !win->classname) || + ((man->format_depend & ICON_NAME) && !win->iconname) || + ((man->format_depend & TITLE_NAME) && !win->titlename)) { + return; + } - if (man->window_up) { - assert (man->geometry.width && man->fontwidth); - maxlen = man->geometry.width / man->fontwidth + 2 /* fudge factor */; - } - else { - maxlen = 0; - } - copy_string (&win->display_string, - make_display_string (win, man->formatstring, maxlen)); - if (win->button) - win->button->drawn_state.dirty_flags |= STRING_CHANGED; + if ((man->format_depend & RESOURCE_NAME) && !win->resname) { + win->resname = ""; + used_resource_placeholder = 1; + } + + if (man->window_up) { + assert(man->geometry.width && man->fontwidth); + maxlen = + man->geometry.width / man->fontwidth + 2 /* fudge factor */; + } else { + maxlen = 0; + } + copy_string(&win->display_string, + make_display_string(win, man->formatstring, maxlen)); + if (used_resource_placeholder) + win->resname = NULL; + if (win->button) + win->button->drawn_state.dirty_flags |= STRING_CHANGED; } /* This function is here and not with the other static utility functions because it basically is the inverse of set_shape() */ -static void clear_empty_region (WinManager *man) -{ - XRectangle rects[2]; - int num_rects = 0, n = man->buttons.num_windows, cols = man->geometry.cols; - int rows = man->geometry.rows; - int boxheight = man->geometry.boxheight; - - if (man->shaped) - return; - - rects[1].x = rects[1].y = rects[1].width = rects[1].height = 0; - - if (n == 0 || rows * cols == 0 /* just be to safe */) { - rects[0].x = 0; - rects[0].y = 0; - rects[0].width = man->geometry.width; - rects[0].height = man->geometry.height; - num_rects = 1; - } - else if (man->geometry.dir & GROW_DOWN) { - assert (cols); - if (n % cols == 0) { - rects[0].x = 0; - rects[0].y = num_visible_rows (n, cols) * man->geometry.boxheight; - rects[0].width = man->geometry.width; - rects[0].height = man->geometry.height - rects[0].y; - num_rects = 1; - } - else { - rects[0].x = (n % cols) * man->geometry.boxwidth; - rects[0].y = (num_visible_rows (n, cols) - 1) * man->geometry.boxheight; - rects[0].width = man->geometry.width - rects[0].y; - rects[0].height = boxheight; - rects[1].x = 0; - rects[1].y = rects[0].y + rects[0].height; - rects[1].width = man->geometry.width; - rects[1].height = man->geometry.height - rects[0].y; - num_rects = 2; - } - } - else { - assert (cols); - /* for shaped windows, we won't see this part of the window */ - if (n % cols == 0) { - rects[0].x = 0; - rects[0].y = 0; - rects[0].width = man->geometry.width; - rects[0].height = top_y_coord (man); - num_rects = 1; - } - else { - rects[0].x = 0; - rects[0].y = 0; - rects[0].width = man->geometry.width; - rects[0].height = top_y_coord (man); - rects[1].x = (n % cols) * man->geometry.boxwidth; - rects[1].y = rects[0].height; - rects[1].width = man->geometry.width - rects[1].x; - rects[1].height = boxheight; - num_rects = 2; - } - } - - ConsoleDebug (X11, "Clearing: %d: (%d, %d, %d, %d) + (%d, %d, %d, %d)\n", - num_rects, - rects[0].x, rects[0].y, rects[0].width, rects[0].height, - rects[1].x, rects[1].y, rects[1].width, rects[1].height); - - XFillRectangles (theDisplay, man->theWindow, - man->backContext[PLAIN_CONTEXT], rects, num_rects); -} - -void set_shape (WinManager *man) +static void +clear_empty_region(WinManager *man) +{ + XRectangle rects[2]; + int num_rects = 0, n = man->buttons.num_windows, + cols = man->geometry.cols; + int rows = man->geometry.rows; + int boxheight = man->geometry.boxheight; + + if (man->shaped) + return; + + rects[1].x = rects[1].y = rects[1].width = rects[1].height = 0; + + if (n == 0 || rows * cols == 0 /* just be to safe */) { + rects[0].x = 0; + rects[0].y = 0; + rects[0].width = man->geometry.width; + rects[0].height = man->geometry.height; + num_rects = 1; + } else if (man->geometry.dir & GROW_DOWN) { + assert(cols); + if (n % cols == 0) { + rects[0].x = 0; + rects[0].y = + num_visible_rows(n, cols) * man->geometry.boxheight; + rects[0].width = man->geometry.width; + rects[0].height = man->geometry.height - rects[0].y; + num_rects = 1; + } else { + rects[0].x = (n % cols) * man->geometry.boxwidth; + rects[0].y = (num_visible_rows(n, cols) - 1) * + man->geometry.boxheight; + rects[0].width = man->geometry.width - rects[0].y; + rects[0].height = boxheight; + rects[1].x = 0; + rects[1].y = rects[0].y + rects[0].height; + rects[1].width = man->geometry.width; + rects[1].height = man->geometry.height - rects[0].y; + num_rects = 2; + } + } else { + assert(cols); + /* for shaped windows, we won't see this part of the window */ + if (n % cols == 0) { + rects[0].x = 0; + rects[0].y = 0; + rects[0].width = man->geometry.width; + rects[0].height = top_y_coord(man); + num_rects = 1; + } else { + rects[0].x = 0; + rects[0].y = 0; + rects[0].width = man->geometry.width; + rects[0].height = top_y_coord(man); + rects[1].x = (n % cols) * man->geometry.boxwidth; + rects[1].y = rects[0].height; + rects[1].width = man->geometry.width - rects[1].x; + rects[1].height = boxheight; + num_rects = 2; + } + } + + ConsoleDebug(X11, "Clearing: %d: (%d, %d, %d, %d) + (%d, %d, %d, %d)\n", + num_rects, rects[0].x, rects[0].y, rects[0].width, rects[0].height, + rects[1].x, rects[1].y, rects[1].width, rects[1].height); + + XFillRectangles(theDisplay, man->theWindow, + man->backContext[PLAIN_CONTEXT], rects, num_rects); +} + +void +set_shape(WinManager *man) { #ifdef SHAPE - int n; - XRectangle rects[2]; - int cols = man->geometry.cols; - - if (!globals.shapes_supported || man->shaped == 0) - return; - - ConsoleDebug (X11, "in set_shape: %s\n", man->titlename); - - n = man->buttons.num_windows; - if (n == 0) - n = 1; - - if (cols == 0 || n % cols == 0) { - rects[0].x = 0; - rects[0].y = top_y_coord (man); - rects[0].width = man->geometry.width; - rects[0].height = num_visible_rows (n, cols) * man->geometry.boxheight; - if (man->shape.num_rects != 1 || !rects_equal (rects, man->shape.rects)) { - man->dirty_flags |= SHAPE_CHANGED; - } - man->shape.num_rects = 1; - man->shape.rects[0] = rects[0]; - } - else { - if (man->geometry.dir & GROW_DOWN) { - rects[0].x = 0; - rects[0].y = 0; - rects[0].width = man->geometry.width; - rects[0].height = - (num_visible_rows (n, cols) - 1) * man->geometry.boxheight; - rects[1].x = 0; - rects[1].y = rects[0].height; - rects[1].width = (n % cols) * man->geometry.boxwidth; - rects[1].height = man->geometry.boxheight; - } - else { - rects[0].x = 0; - rects[0].y = top_y_coord (man); - rects[0].width = (n % cols) * man->geometry.boxwidth; - rects[0].height = man->geometry.boxheight; - rects[1].x = 0; - rects[1].y = rects[0].y + rects[0].height; - rects[1].width = man->geometry.width; - rects[1].height = (num_visible_rows (n, cols) - 1) * - man->geometry.boxheight; - } - if (man->shape.num_rects != 2 || - !rects_equal (rects, man->shape.rects) || - !rects_equal (rects + 1, man->shape.rects + 1)) { - man->dirty_flags |= SHAPE_CHANGED; - } - man->shape.num_rects = 2; - man->shape.rects[0] = rects[0]; - man->shape.rects[1] = rects[1]; - } + int n; + XRectangle rects[2]; + int cols = man->geometry.cols; + + if (!globals.shapes_supported || man->shaped == 0) + return; + + ConsoleDebug(X11, "in set_shape: %s\n", man->titlename); + + n = man->buttons.num_windows; + if (n == 0) + n = 1; + + if (cols == 0 || n % cols == 0) { + rects[0].x = 0; + rects[0].y = top_y_coord(man); + rects[0].width = man->geometry.width; + rects[0].height = + num_visible_rows(n, cols) * man->geometry.boxheight; + if (man->shape.num_rects != 1 || + !rects_equal(rects, man->shape.rects)) { + man->dirty_flags |= SHAPE_CHANGED; + } + man->shape.num_rects = 1; + man->shape.rects[0] = rects[0]; + } else { + if (man->geometry.dir & GROW_DOWN) { + rects[0].x = 0; + rects[0].y = 0; + rects[0].width = man->geometry.width; + rects[0].height = (num_visible_rows(n, cols) - 1) * + man->geometry.boxheight; + rects[1].x = 0; + rects[1].y = rects[0].height; + rects[1].width = (n % cols) * man->geometry.boxwidth; + rects[1].height = man->geometry.boxheight; + } else { + rects[0].x = 0; + rects[0].y = top_y_coord(man); + rects[0].width = (n % cols) * man->geometry.boxwidth; + rects[0].height = man->geometry.boxheight; + rects[1].x = 0; + rects[1].y = rects[0].y + rects[0].height; + rects[1].width = man->geometry.width; + rects[1].height = (num_visible_rows(n, cols) - 1) * + man->geometry.boxheight; + } + if (man->shape.num_rects != 2 || + !rects_equal(rects, man->shape.rects) || + !rects_equal(rects + 1, man->shape.rects + 1)) { + man->dirty_flags |= SHAPE_CHANGED; + } + man->shape.num_rects = 2; + man->shape.rects[0] = rects[0]; + man->shape.rects[1] = rects[1]; + } #endif } -void set_manager_window_mapping (WinManager *man, int flag) +void +set_manager_window_mapping(WinManager *man, int flag) { - if (flag != man->window_mapped) { - man->window_mapped = flag; - man->dirty_flags |= MAPPING_CHANGED; - } + if (flag != man->window_mapped) { + man->window_mapped = flag; + man->dirty_flags |= MAPPING_CHANGED; + } } /***************************************************************************/ /* Major exported functions */ /***************************************************************************/ -void init_boxes (void) +void +init_boxes(void) { } -void init_button_array (ButtonArray *array) +void +init_button_array(ButtonArray *array) { - array->num_buttons = 0; - array->num_windows = 0; - array->buttons = NULL; + array->num_buttons = 0; + array->num_windows = 0; + array->buttons = NULL; } /* Pretty much like resize_manager, but used only to figure the correct size when creating the window */ -void size_manager (WinManager *man) +void +size_manager(WinManager *man) { - ManGeometry *new; - int oldwidth, oldheight, w, h; - - new = figure_geometry (man); - - assert (new->width && new->height); - - w = new->width; - h = new->height; + ManGeometry *new; + int oldwidth, oldheight, w, h; - oldwidth = man->geometry.width; - oldheight = man->geometry.height; + new = figure_geometry(man); - set_man_geometry (man, new); + assert(new->width && new->height); - if (oldheight != h || oldwidth != w) { - if (man->geometry.dir & GROW_UP) - man->geometry.y -= h - oldheight; - if (man->geometry.dir & GROW_LEFT) - man->geometry.x -= w - oldwidth; - } + w = new->width; + h = new->height; - ConsoleDebug (X11, "size_manager %s: %d %d %d %d\n", man->titlename, - man->geometry.x, man->geometry.y, man->geometry.width, - man->geometry.height); -} - -static void resize_manager (WinManager *man, int force) -{ - ManGeometry *new; - int oldwidth, oldheight, oldrows, oldcols; - int dir; + oldwidth = man->geometry.width; + oldheight = man->geometry.height; - if (man->can_draw == 0) - return; + set_man_geometry(man, new); - oldwidth = man->geometry.width; - oldheight = man->geometry.height; - oldrows = man->geometry.rows; - oldcols = man->geometry.cols; - dir = man->geometry.dir; + if (oldheight != h || oldwidth != w) { + if (man->geometry.dir & GROW_UP) + man->geometry.y -= h - oldheight; + if (man->geometry.dir & GROW_LEFT) + man->geometry.x -= w - oldwidth; + } - if (dir & GROW_FIXED) { - new = figure_geometry (man); - set_man_geometry (man, new); - set_shape (man); - if (force || oldrows != new->rows || oldcols != new->cols || - oldwidth != new->width || oldheight != new->height) { - man->dirty_flags |= GEOMETRY_CHANGED; - } - } - else { - new = figure_geometry (man); - set_man_geometry (man, new); - set_shape (man); - if (force || oldrows != new->rows || oldcols != new->cols || - oldwidth != new->width || oldheight != new->height) { - resize_window (man); - } - } + ConsoleDebug(X11, "size_manager %s: %d %d %d %d\n", man->titlename, + man->geometry.x, man->geometry.y, man->geometry.width, + man->geometry.height); +} + +static void +resize_manager(WinManager *man, int force) +{ + ManGeometry *new; + int oldwidth, oldheight, oldrows, oldcols; + int dir; + + if (man->can_draw == 0) + return; + + oldwidth = man->geometry.width; + oldheight = man->geometry.height; + oldrows = man->geometry.rows; + oldcols = man->geometry.cols; + dir = man->geometry.dir; + + if (dir & GROW_FIXED) { + new = figure_geometry(man); + set_man_geometry(man, new); + set_shape(man); + if (force || oldrows != new->rows || oldcols != new->cols || + oldwidth != new->width || oldheight != new->height) { + man->dirty_flags |= GEOMETRY_CHANGED; + } + } else { + new = figure_geometry(man); + set_man_geometry(man, new); + set_shape(man); + if (force || oldrows != new->rows || oldcols != new->cols || + oldwidth != new->width || oldheight != new->height) { + resize_window(man); + } + } } -static int center_padding (int h1, int h2) +static int +center_padding(int h1, int h2) { - return (h2 - h1) / 2; + return (h2 - h1) / 2; } -static void get_title_geometry (WinManager *man, ButtonGeometry *g) +static void +get_title_geometry(WinManager *man, ButtonGeometry *g) { - int text_pad; - assert (man); - g->button_x = 0; - g->button_y = 0; - g->button_w = man->geometry.boxwidth; - g->button_h = man->geometry.boxheight; - g->text_x = g->button_x + g->button_h / 2; - g->text_w = g->button_w - 4 - (g->text_x - g->button_x); - g->text_h = man->fontheight; - text_pad = center_padding (man->fontheight, g->button_h); + int text_pad; + assert(man); + g->button_x = 0; + g->button_y = 0; + g->button_w = man->geometry.boxwidth; + g->button_h = man->geometry.boxheight; + g->text_x = g->button_x + g->button_h / 2; + g->text_w = g->button_w - 4 - (g->text_x - g->button_x); + g->text_h = man->fontheight; + text_pad = center_padding(man->fontheight, g->button_h); - g->text_y = g->button_y + text_pad; - g->text_base = g->text_y + man->ButtonFont->ascent; + g->text_y = g->button_y + text_pad; + g->text_base = g->text_y + man->ButtonFont->ascent; } -static void get_button_geometry (WinManager *man, Button *button, - ButtonGeometry *g) +static void +get_button_geometry(WinManager *man, Button *button, ButtonGeometry *g) { - int icon_pad, text_pad; - WinData *win; + int icon_pad, text_pad; + WinData *win; - assert (man); + assert(man); - win = button->drawn_state.win; + win = button->drawn_state.win; - g->button_x = button->x; - g->button_y = button->y; + g->button_x = button->x; + g->button_y = button->y; - g->button_w = button->w; - g->button_h = button->h; + g->button_w = button->w; + g->button_h = button->h; /* [BV 16-Apr-97] Mini Icons work on black-and-white too */ #ifdef MINI_ICONS - if (man->draw_icons && win && win->pic.picture) { - /* If no window, then icon_* aren't used, so doesn't matter what - they are */ - g->icon_w = min (win->pic.width, g->button_h); - g->icon_h = min (g->button_h - 4, win->pic.height); - icon_pad = center_padding (g->icon_h, g->button_h); - g->icon_x = g->button_x + 4; - g->icon_y = g->button_y + icon_pad; - } - else { + if (man->draw_icons && win && win->pic.picture) { + /* If no window, then icon_* aren't used, so doesn't matter what + they are */ + g->icon_w = min(win->pic.width, g->button_h); + g->icon_h = min(g->button_h - 4, win->pic.height); + icon_pad = center_padding(g->icon_h, g->button_h); + g->icon_x = g->button_x + 4; + g->icon_y = g->button_y + icon_pad; + } else { #endif - g->icon_h = man->geometry.boxheight - 8; - g->icon_w = g->icon_h; + g->icon_h = man->geometry.boxheight - 8; + g->icon_w = g->icon_h; - icon_pad = center_padding (g->icon_h, g->button_h); - g->icon_x = g->button_x + icon_pad; - g->icon_y = g->button_y + icon_pad; + icon_pad = center_padding(g->icon_h, g->button_h); + g->icon_x = g->button_x + icon_pad; + g->icon_y = g->button_y + icon_pad; #ifdef MINI_ICONS - } + } #endif - g->text_x = g->icon_x + g->icon_w + 2; - g->text_w = g->button_w - 4 - (g->text_x - g->button_x); - g->text_h = man->fontheight; - - text_pad = center_padding (man->fontheight, g->button_h); - - g->text_y = g->button_y + text_pad; - g->text_base = g->text_y + man->ButtonFont->ascent; + g->text_x = g->icon_x + g->icon_w + 2; + g->text_w = g->button_w - 4 - (g->text_x - g->button_x); + g->text_h = man->fontheight; + + text_pad = center_padding(man->fontheight, g->button_h); + + g->text_y = g->button_y + text_pad; + g->text_base = g->text_y + man->ButtonFont->ascent; +} + +static void +draw_3d_square(WinManager *man, int x, int y, int w, int h, GC rgc, GC sgc) +{ + int i; + XSegment seg[4]; + + i = 0; + seg[i].x1 = x; + seg[i].y1 = y; + seg[i].x2 = w + x - 1; + seg[i++].y2 = y; + + seg[i].x1 = x; + seg[i].y1 = y; + seg[i].x2 = x; + seg[i++].y2 = h + y - 1; + + seg[i].x1 = x + 1; + seg[i].y1 = y + 1; + seg[i].x2 = x + w - 2; + seg[i++].y2 = y + 1; + + seg[i].x1 = x + 1; + seg[i].y1 = y + 1; + seg[i].x2 = x + 1; + seg[i++].y2 = y + h - 2; + XDrawSegments(theDisplay, man->theWindow, rgc, seg, i); + + i = 0; + seg[i].x1 = x; + seg[i].y1 = y + h - 1; + seg[i].x2 = w + x - 1; + seg[i++].y2 = y + h - 1; + + seg[i].x1 = x + w - 1; + seg[i].y1 = y; + seg[i].x2 = x + w - 1; + seg[i++].y2 = y + h - 1; + XDrawSegments(theDisplay, man->theWindow, sgc, seg, i); + + i = 0; + seg[i].x1 = x + 1; + seg[i].y1 = y + h - 2; + seg[i].x2 = x + w - 2; + seg[i++].y2 = y + h - 2; + + seg[i].x1 = x + w - 2; + seg[i].y1 = y + 1; + seg[i].x2 = x + w - 2; + seg[i++].y2 = y + h - 2; + + XDrawSegments(theDisplay, man->theWindow, sgc, seg, i); +} + +static void +draw_3d_icon(WinManager *man, int box, ButtonGeometry *g, int iconified, + int dir, Contexts contextId) +{ + if (iconified == 0) { + draw_3d_square(man, g->icon_x, g->icon_y, g->icon_w, g->icon_h, + man->flatContext[contextId], man->flatContext[contextId]); + } else { + if (dir == 1) { + draw_3d_square(man, g->icon_x, g->icon_y, g->icon_w, + g->icon_h, man->reliefContext[contextId], + man->shadowContext[contextId]); + } else { + draw_3d_square(man, g->icon_x, g->icon_y, g->icon_w, + g->icon_h, man->shadowContext[contextId], + man->reliefContext[contextId]); + } + } } -static void draw_3d_square (WinManager *man, int x, int y, int w, int h, - GC rgc, GC sgc) +/* this routine should only be called from draw_button() */ +static void +iconify_box(WinManager *man, WinData *win, int box, ButtonGeometry *g, + int iconified, Contexts contextId, int button_already_cleared) { - int i; - XSegment seg[4]; +#ifdef MINI_ICONS + XGCValues gcv; + unsigned long gcm; +#endif - i=0; - seg[i].x1 = x; seg[i].y1 = y; - seg[i].x2 = w+x-1; seg[i++].y2 = y; + if (!man->window_up) + return; - seg[i].x1 = x; seg[i].y1 = y; - seg[i].x2 = x; seg[i++].y2 = h+y-1; +/* [BV 16-Apr-97] Mini Icons work on black-and-white too */ +#ifdef MINI_ICONS + if (man->draw_icons && win->pic.picture) { + if (iconified == 0 && man->draw_icons != 2) { + if (!button_already_cleared) { + XFillRectangle(theDisplay, man->theWindow, + man->backContext[contextId], g->icon_x, + g->icon_y, g->icon_w, g->icon_h); + } + } else { + gcm = GCClipMask | GCClipXOrigin | GCClipYOrigin; + gcv.clip_mask = win->pic.mask; + gcv.clip_x_origin = g->icon_x; + gcv.clip_y_origin = g->icon_y; + XChangeGC( + theDisplay, man->hiContext[contextId], gcm, &gcv); + + XCopyArea(theDisplay, win->pic.picture, man->theWindow, + man->hiContext[contextId], 0, 0, g->icon_w, + g->icon_h, g->icon_x, g->icon_y); + gcm = GCClipMask; + gcv.clip_mask = None; + XChangeGC( + theDisplay, man->hiContext[contextId], gcm, &gcv); + } + } else { +#endif + if (theDepth > 2) { + draw_3d_icon(man, box, g, iconified, 1, contextId); + } else { + if (iconified == 0) { + XFillArc(theDisplay, man->theWindow, + man->backContext[contextId], g->icon_x, + g->icon_y, g->icon_w, g->icon_h, 0, + 360 * 64); + } else { + XFillArc(theDisplay, man->theWindow, + man->hiContext[contextId], g->icon_x, + g->icon_y, g->icon_w, g->icon_h, 0, + 360 * 64); + } + } +#ifdef MINI_ICONS + } +#endif +} - seg[i].x1 = x+1; seg[i].y1 = y+1; - seg[i].x2 = x+w-2; seg[i++].y2 = y+1; +int +change_windows_manager(WinData *win) +{ + WinManager *oldman; + WinManager *newman; - seg[i].x1 = x+1; seg[i].y1 = y+1; - seg[i].x2 = x+1; seg[i++].y2 = y+h-2; - XDrawSegments(theDisplay, man->theWindow, rgc, seg, i); + ConsoleDebug(X11, "change_windows_manager: %s\n", win->titlename); - i=0; - seg[i].x1 = x; seg[i].y1 = y+h-1; - seg[i].x2 = w+x-1; seg[i++].y2 = y+h-1; + oldman = win->manager; + newman = figure_win_manager(win, ALL_NAME); + if (oldman && newman != oldman && win->button) { + delete_windows_button(win); + } + win->manager = newman; + set_win_displaystring(win); + check_win_complete(win); + check_in_window(win); + ConsoleDebug( + X11, "change_windows_manager: returning %d\n", newman != oldman); + return (newman != oldman); +} + +void +check_in_window(WinData *win) +{ + int in_viewport; + + if (win->manager && win->complete && + !(win->manager->usewinlist && (win->fvwm_flags & WINDOWLISTSKIP))) { + in_viewport = win_in_viewport(win); + if (win->button == NULL && in_viewport) { + insert_windows_button(win); + if (win->manager->window_up == 0 && + globals.got_window_list) + create_manager_window(win->manager->index); + } else if (win->button && !in_viewport) { + delete_windows_button(win); + } + } +} - seg[i].x1 = x+w-1; seg[i].y1 = y; - seg[i].x2 = x+w-1; seg[i++].y2 = y+h-1; - XDrawSegments(theDisplay, man->theWindow, sgc, seg, i); +static void +get_gcs(WinManager *man, int state, GC *context1, GC *context2) +{ + switch (man->buttonState[state]) { + case BUTTON_FLAT: + *context1 = man->flatContext[state]; + *context2 = man->flatContext[state]; + break; - i=0; - seg[i].x1 = x+1; seg[i].y1 = y+h-2; - seg[i].x2 = x+w-2; seg[i++].y2 = y+h-2; + case BUTTON_UP: + case BUTTON_EDGEUP: + *context1 = man->reliefContext[state]; + *context2 = man->shadowContext[state]; + break; - seg[i].x1 = x+w-2; seg[i].y1 = y+1; - seg[i].x2 = x+w-2; seg[i++].y2 = y+h-2; + case BUTTON_DOWN: + case BUTTON_EDGEDOWN: + *context1 = man->shadowContext[state]; + *context2 = man->reliefContext[state]; + break; - XDrawSegments(theDisplay, man->theWindow, sgc, seg, i); + default: + ConsoleMessage("Internal error in draw_button\n"); + break; + } } -static void draw_3d_icon (WinManager *man, int box, ButtonGeometry *g, - int iconified, int dir, Contexts contextId) +static void +draw_relief(WinManager *man, int button_state, ButtonGeometry *g, GC context1, + GC context2) { - if (iconified == 0) { - draw_3d_square (man, g->icon_x, g->icon_y, g->icon_w, g->icon_h, - man->flatContext[contextId], - man->flatContext[contextId]); - } - else { - if (dir == 1) { - draw_3d_square (man, g->icon_x, g->icon_y, g->icon_w, g->icon_h, - man->reliefContext[contextId], - man->shadowContext[contextId]); - } - else { - draw_3d_square (man, g->icon_x, g->icon_y, g->icon_w, g->icon_h, - man->shadowContext[contextId], - man->reliefContext[contextId]); - } - } -} + int state; + state = man->buttonState[button_state]; + if (state == BUTTON_EDGEUP || state == BUTTON_EDGEDOWN) { + draw_3d_square(man, g->button_x, g->button_y, g->button_w, + g->button_h, context1, context2); + draw_3d_square(man, g->button_x + 2, g->button_y + 2, + g->button_w - 4, g->button_h - 4, context2, context1); + } else { + draw_3d_square(man, g->button_x, g->button_y, g->button_w, + g->button_h, context1, context2); + } +} - /* this routine should only be called from draw_button() */ -static void iconify_box (WinManager *man, WinData *win, int box, - ButtonGeometry *g, int iconified, - Contexts contextId, int button_already_cleared) +static void +draw_button(WinManager *man, int button, int force) { -#ifdef MINI_ICONS - XGCValues gcv; - unsigned long gcm; -#endif + Button *b; + WinData *win; + ButtonGeometry g, old_g; + GC context1, context2; + Contexts button_state; + int cleared_button = 0, dirty; + int draw_background = 0, draw_icon = 0, draw_string = 0, + clear_old_pic = 0; - if (!man->window_up) - return; + assert(man); -/* [BV 16-Apr-97] Mini Icons work on black-and-white too */ -#ifdef MINI_ICONS - if (man->draw_icons && win->pic.picture) { - if (iconified == 0 && man->draw_icons != 2) { - if (!button_already_cleared) { - XFillRectangle (theDisplay, man->theWindow, - man->backContext[contextId], g->icon_x, g->icon_y, - g->icon_w, g->icon_h); - } - } - else { - gcm = GCClipMask|GCClipXOrigin|GCClipYOrigin; - gcv.clip_mask = win->pic.mask; - gcv.clip_x_origin = g->icon_x; - gcv.clip_y_origin = g->icon_y; - XChangeGC (theDisplay, man->hiContext[contextId], gcm, &gcv); - - XCopyArea(theDisplay, win->pic.picture, man->theWindow, - man->hiContext[contextId], 0, 0, g->icon_w, g->icon_h, - g->icon_x, g->icon_y); - gcm = GCClipMask; - gcv.clip_mask = None; - XChangeGC(theDisplay, man->hiContext[contextId], gcm, &gcv); - } - } - else { -#endif - if (theDepth > 2) { - draw_3d_icon (man, box, g, iconified, 1, contextId); - } - else { - if (iconified == 0) { - XFillArc (theDisplay, man->theWindow, man->backContext[contextId], - g->icon_x, g->icon_y, g->icon_w, g->icon_h, 0, 360 * 64); - } - else { - XFillArc (theDisplay, man->theWindow, man->hiContext[contextId], - g->icon_x, g->icon_y, g->icon_w, g->icon_h, 0, 360 * 64); - } - } + if (!man->window_up) { + ConsoleMessage("draw_button: manager not up yet\n"); + return; + } + + b = man->buttons.buttons[button]; + win = b->drawn_state.win; + dirty = b->drawn_state.dirty_flags; + + if (win && win->button != b) { + ConsoleMessage("Internal error in draw_button.\n"); + return; + } + + if (!win) { + return; + } + + if (force || (dirty & REDRAW_BUTTON)) { + ConsoleDebug(X11, "draw_button: %d forced\n", b->index); + draw_background = 1; + draw_icon = 1; + draw_string = 1; + } + /* figure out what we have to draw */ + if (dirty) { + ConsoleDebug(X11, "draw_button: %d dirty\n", b->index); + if (win) { + if (dirty & GEOMETRY_CHANGED) { + ConsoleDebug(X11, "\tGeometry changed\n"); + /* Determine if geometry has changed relative to + the window gravity */ + if (b->w != b->drawn_state.w || + b->h != b->drawn_state.h || + b->x - man->geometry.gravity_x != + b->drawn_state.x - + man->drawn_geometry.gravity_x || + b->y - man->geometry.gravity_y != + b->drawn_state.y - + man->drawn_geometry.gravity_y) { + draw_background = 1; + draw_icon = 1; + draw_string = 1; + } + } + if (dirty & STATE_CHANGED) { + ConsoleDebug(X11, "\tState changed\n"); + b->drawn_state.state = win->state; + draw_background = 1; + draw_icon = 1; + draw_string = 1; + } #ifdef MINI_ICONS - } + if (dirty & PICTURE_CHANGED) { + ConsoleDebug(X11, "\tPicture changed\n"); + get_button_geometry(man, b, &old_g); + b->drawn_state.pic = win->pic; + draw_icon = 1; + draw_string = 1; + clear_old_pic = 1; + } #endif + if ((dirty & ICON_STATE_CHANGED) && + b->drawn_state.iconified != win->iconified) { + ConsoleDebug(X11, "\tIcon changed\n"); + b->drawn_state.iconified = win->iconified; + draw_icon = 1; + } + if (dirty & STRING_CHANGED) { + ConsoleDebug(X11, "\tString changed: %s\n", + win->display_string); + b->drawn_state.display_string = + win->display_string; + assert(b->drawn_state.display_string); + draw_string = 1; + } + } + } + + if (win && (draw_background || draw_icon || draw_string)) { + get_button_geometry(man, b, &g); + ConsoleDebug(X11, "\tgeometry: %d %d %d %d\n", g.button_x, + g.button_y, g.button_w, g.button_h); + button_state = b->drawn_state.state; + if (draw_background) { + ConsoleDebug(X11, "\tDrawing background\n"); + XFillRectangle(theDisplay, man->theWindow, + man->backContext[button_state], g.button_x, + g.button_y, g.button_w, g.button_h); + cleared_button = 1; + + if (theDepth > 2) { + get_gcs( + man, button_state, &context1, &context2); + draw_relief( + man, button_state, &g, context1, context2); + } else if (button_state & SELECT_CONTEXT) { + XDrawRectangle(theDisplay, man->theWindow, + man->hiContext[button_state], + g.button_x + 2, g.button_y + 1, + g.button_w - 4, g.button_h - 2); + } + } + if (clear_old_pic) { + ConsoleDebug(X11, "\tClearing old picture\n"); + if (!cleared_button) { + XFillRectangle(theDisplay, man->theWindow, + man->backContext[PLAIN_CONTEXT], + old_g.icon_x, old_g.icon_y, + old_g.icon_w + 2, old_g.icon_h); + } + } + if (draw_icon) { + ConsoleDebug(X11, "\tDrawing icon\n"); + iconify_box(man, win, button, &g, win->iconified, + button_state, cleared_button); + } + if (draw_string) { + ConsoleDebug(X11, "\tDrawing text: %s\n", + b->drawn_state.display_string); + ClipRectangle(man, button_state, g.text_x, g.text_y, + g.text_w, g.text_h); + if (!cleared_button) { + XFillRectangle(theDisplay, man->theWindow, + man->backContext[button_state], g.text_x, + g.text_y, g.text_w, g.text_h); + } + XDrawString(theDisplay, man->theWindow, + man->hiContext[button_state], g.text_x, g.text_base, + b->drawn_state.display_string, + strlen(b->drawn_state.display_string)); + XSetClipMask( + theDisplay, man->hiContext[button_state], None); + } + } + + b->drawn_state.dirty_flags = 0; + b->drawn_state.x = b->x; + b->drawn_state.y = b->y; + b->drawn_state.w = b->w; + b->drawn_state.h = b->h; + XFlush(theDisplay); +} +void +draw_managers(void) +{ + int i; + for (i = 0; i < globals.num_managers; i++) + draw_manager(&globals.managers[i]); } -int change_windows_manager (WinData *win) +static void +draw_empty_manager(WinManager *man) { - WinManager *oldman; - WinManager *newman; + GC context1, context2; + int state = TITLE_CONTEXT; + ButtonGeometry g; - ConsoleDebug (X11, "change_windows_manager: %s\n", win->titlename); + ConsoleDebug(X11, "draw_empty_manager\n"); + get_title_geometry(man, &g); - oldman = win->manager; - newman = figure_win_manager (win, ALL_NAME); - if (oldman && newman != oldman && win->button) { - delete_windows_button (win); - } - win->manager = newman; - set_win_displaystring (win); - check_win_complete (win); - check_in_window (win); - ConsoleDebug (X11, "change_windows_manager: returning %d\n", - newman != oldman); - return (newman != oldman); -} - -void check_in_window (WinData *win) -{ - int in_viewport; - - if (win->manager && win->complete && - !(win->manager->usewinlist && (win->fvwm_flags & WINDOWLISTSKIP))) { - in_viewport = win_in_viewport (win); - if (win->button == NULL && in_viewport) { - insert_windows_button (win); - if (win->manager->window_up == 0 && globals.got_window_list) - create_manager_window (win->manager->index); - } - else if (win->button && !in_viewport) { - delete_windows_button (win); - } - } -} - -static void get_gcs (WinManager *man, int state, GC *context1, GC *context2) -{ - switch (man->buttonState[state]) { - case BUTTON_FLAT: - *context1 = man->flatContext[state]; - *context2 = man->flatContext[state]; - break; - - case BUTTON_UP: - case BUTTON_EDGEUP: - *context1 = man->reliefContext[state]; - *context2 = man->shadowContext[state]; - break; - - case BUTTON_DOWN: - case BUTTON_EDGEDOWN: - *context1 = man->shadowContext[state]; - *context2 = man->reliefContext[state]; - break; - - default: - ConsoleMessage ("Internal error in draw_button\n"); - break; - } -} - -static void draw_relief (WinManager *man, int button_state, ButtonGeometry *g, - GC context1, GC context2) -{ - int state; - state = man->buttonState[button_state]; - - if (state == BUTTON_EDGEUP || state == BUTTON_EDGEDOWN) { - draw_3d_square (man, g->button_x, g->button_y, g->button_w, g->button_h, - context1, context2); - draw_3d_square (man, g->button_x + 2, g->button_y + 2, g->button_w - 4, - g->button_h - 4, context2, context1); - } - else { - draw_3d_square (man, g->button_x, g->button_y, g->button_w, g->button_h, - context1, context2); - } -} - -static void draw_button (WinManager *man, int button, int force) -{ - Button *b; - WinData *win; - ButtonGeometry g, old_g; - GC context1, context2; - Contexts button_state; - int cleared_button = 0, dirty; - int draw_background = 0, draw_icon = 0, draw_string = 0, clear_old_pic = 0; - - assert (man); - - if (!man->window_up) { - ConsoleMessage ("draw_button: manager not up yet\n"); - return; - } - - b = man->buttons.buttons[button]; - win = b->drawn_state.win; - dirty = b->drawn_state.dirty_flags; - - if (win && win->button != b) { - ConsoleMessage ("Internal error in draw_button.\n"); - return; - } - - if (!win) { - return; - } - - if (force || (dirty & REDRAW_BUTTON)) { - ConsoleDebug (X11, "draw_button: %d forced\n", b->index); - draw_background = 1; - draw_icon = 1; - draw_string = 1; - } - /* figure out what we have to draw */ - if (dirty) { - ConsoleDebug (X11, "draw_button: %d dirty\n", b->index); - if (win) { - if (dirty & GEOMETRY_CHANGED) { - ConsoleDebug (X11, "\tGeometry changed\n"); - /* Determine if geometry has changed relative to the - window gravity */ - if (b->w != b->drawn_state.w || b->h != b->drawn_state.h || - b->x - man->geometry.gravity_x != - b->drawn_state.x - man->drawn_geometry.gravity_x || - b->y - man->geometry.gravity_y != - b->drawn_state.y - man->drawn_geometry.gravity_y) { - draw_background = 1; - draw_icon = 1; - draw_string = 1; + XFillRectangle(theDisplay, man->theWindow, man->backContext[state], + g.button_x, g.button_y, g.button_w, g.button_h); + if (theDepth > 2) { + get_gcs(man, state, &context1, &context2); + draw_relief(man, state, &g, context1, context2); + } else { + } + ClipRectangle(man, state, g.text_x, g.text_y, g.text_w, g.text_h); + XDrawString(theDisplay, man->theWindow, man->hiContext[state], g.text_x, + g.text_base, man->titlename, strlen(man->titlename)); + XSetClipMask(theDisplay, man->hiContext[state], None); +} + +void +draw_manager(WinManager *man) +{ + int i, force_draw = 0, update_geometry = 0, redraw_all = 0; + int shape_changed = 0; + + assert(man->buttons.num_buttons >= 0 && man->buttons.num_windows >= 0); + + if (!man->window_up) + return; + + ConsoleDebug(X11, "Drawing Manager: %s\n", man->titlename); + redraw_all = man->dirty_flags & REDRAW_MANAGER; + + if (redraw_all || (man->buttons.dirty_flags & NUM_WINDOWS_CHANGED)) { + ConsoleDebug(X11, "\tresizing manager\n"); + resize_manager(man, redraw_all); + clear_empty_region(man); + update_geometry = 1; + force_draw = 1; + } + + if (redraw_all || (man->dirty_flags & MAPPING_CHANGED)) { + force_draw = 1; + ConsoleDebug( + X11, "manager %s: mapping changed\n", man->titlename); } - } - if (dirty & STATE_CHANGED) { - ConsoleDebug (X11, "\tState changed\n"); - b->drawn_state.state = win->state; - draw_background = 1; - draw_icon = 1; - draw_string = 1; - } -#ifdef MINI_ICONS - if (dirty & PICTURE_CHANGED) { - ConsoleDebug (X11, "\tPicture changed\n"); - get_button_geometry (man, b, &old_g); - b->drawn_state.pic = win->pic; - draw_icon = 1; - draw_string = 1; - clear_old_pic = 1; - } -#endif - if ((dirty & ICON_STATE_CHANGED) && - b->drawn_state.iconified != win->iconified) { - ConsoleDebug (X11, "\tIcon changed\n"); - b->drawn_state.iconified = win->iconified; - draw_icon = 1; - } - if (dirty & STRING_CHANGED) { - ConsoleDebug (X11, "\tString changed: %s\n", win->display_string); - b->drawn_state.display_string = win->display_string; - assert (b->drawn_state.display_string); - draw_string = 1; - } - } - } - - if (win && (draw_background || draw_icon || draw_string)) { - get_button_geometry (man, b, &g); - ConsoleDebug (X11, "\tgeometry: %d %d %d %d\n", g.button_x, g.button_y, - g.button_w, g.button_h); - button_state = b->drawn_state.state; - if (draw_background) { - ConsoleDebug (X11, "\tDrawing background\n"); - XFillRectangle (theDisplay, man->theWindow, - man->backContext[button_state], g.button_x, - g.button_y, g.button_w, g.button_h); - cleared_button = 1; - - if (theDepth > 2) { - get_gcs (man, button_state, &context1, &context2); - draw_relief (man, button_state, &g, context1, context2); - } - else if (button_state & SELECT_CONTEXT) { - XDrawRectangle (theDisplay, man->theWindow, - man->hiContext[button_state], - g.button_x + 2, g.button_y + 1, - g.button_w - 4, g.button_h - 2); - } - } - if (clear_old_pic) { - ConsoleDebug (X11, "\tClearing old picture\n"); - if (!cleared_button) { - XFillRectangle (theDisplay, man->theWindow, - man->backContext[PLAIN_CONTEXT], - old_g.icon_x, old_g.icon_y, - old_g.icon_w + 2, old_g.icon_h); - } - } - if (draw_icon) { - ConsoleDebug (X11, "\tDrawing icon\n"); - iconify_box (man, win, button, &g, win->iconified, button_state, - cleared_button); - } - if (draw_string) { - ConsoleDebug (X11, "\tDrawing text: %s\n", - b->drawn_state.display_string); - ClipRectangle (man, button_state, g.text_x, g.text_y, g.text_w, - g.text_h); - if (!cleared_button) { - XFillRectangle (theDisplay, man->theWindow, - man->backContext[button_state], - g.text_x, g.text_y, g.text_w, g.text_h); - } - XDrawString (theDisplay, man->theWindow, - man->hiContext[button_state], - g.text_x, g.text_base, b->drawn_state.display_string, - strlen (b->drawn_state.display_string)); - XSetClipMask (theDisplay, man->hiContext[button_state], None); - } - } - - b->drawn_state.dirty_flags = 0; - b->drawn_state.x = b->x; - b->drawn_state.y = b->y; - b->drawn_state.w = b->w; - b->drawn_state.h = b->h; - XFlush (theDisplay); -} - -void draw_managers (void) -{ - int i; - for (i = 0; i < globals.num_managers; i++) - draw_manager (&globals.managers[i]); -} - -static void draw_empty_manager (WinManager *man) -{ - GC context1, context2; - int state = TITLE_CONTEXT; - ButtonGeometry g; - - ConsoleDebug (X11, "draw_empty_manager\n"); - get_title_geometry (man, &g); - - XFillRectangle (theDisplay, man->theWindow, man->backContext[state], - g.button_x, g.button_y, g.button_w, g.button_h); - if (theDepth > 2) { - get_gcs (man, state, &context1, &context2); - draw_relief (man, state, &g, context1, context2); - } - else { - } - ClipRectangle (man, state, g.text_x, g.text_y, g.text_w, g.text_h); - XDrawString (theDisplay, man->theWindow, man->hiContext[state], - g.text_x, g.text_base, man->titlename, strlen (man->titlename)); - XSetClipMask (theDisplay, man->hiContext[state], None); -} - -void draw_manager (WinManager *man) -{ - int i, force_draw = 0, update_geometry = 0, redraw_all = 0; - int shape_changed = 0; - - assert (man->buttons.num_buttons >= 0 && man->buttons.num_windows >= 0); - - if (!man->window_up) - return; - - ConsoleDebug (X11, "Drawing Manager: %s\n", man->titlename); - redraw_all = man->dirty_flags & REDRAW_MANAGER; - - if (redraw_all || (man->buttons.dirty_flags & NUM_WINDOWS_CHANGED)) { - ConsoleDebug (X11, "\tresizing manager\n"); - resize_manager (man, redraw_all); - clear_empty_region (man); - update_geometry = 1; - force_draw = 1; - } - - - if (redraw_all || (man->dirty_flags & MAPPING_CHANGED)) { - force_draw = 1; - ConsoleDebug (X11, "manager %s: mapping changed\n", man->titlename); - } #ifdef SHAPE - if (man->shaped && (redraw_all || (man->dirty_flags & SHAPE_CHANGED) )){ - /* This little piggie waits until past resize requests get processed */ - XSync (theDisplay, False); - XShapeCombineRectangles (theDisplay, man->theWindow, ShapeBounding, - 0, 0, man->shape.rects, man->shape.num_rects, - ShapeSet, Unsorted); - XShapeCombineRectangles (theDisplay, man->theWindow, ShapeClip, - 0, 0, man->shape.rects, man->shape.num_rects, - ShapeSet, Unsorted); - shape_changed = 1; - update_geometry = 1; - /* And this little piggie waits for shape to get processed before - drawing buttons */ - XSync (theDisplay, False); - } + if (man->shaped && (redraw_all || (man->dirty_flags & SHAPE_CHANGED))) { + /* This little piggie waits until past resize requests get + * processed */ + XSync(theDisplay, False); + XShapeCombineRectangles(theDisplay, man->theWindow, + ShapeBounding, 0, 0, man->shape.rects, man->shape.num_rects, + ShapeSet, Unsorted); + XShapeCombineRectangles(theDisplay, man->theWindow, ShapeClip, + 0, 0, man->shape.rects, man->shape.num_rects, ShapeSet, + Unsorted); + shape_changed = 1; + update_geometry = 1; + /* And this little piggie waits for shape to get processed + before drawing buttons */ + XSync(theDisplay, False); + } #endif - if (redraw_all || (man->dirty_flags & GEOMETRY_CHANGED)) { - ConsoleDebug (X11, "\tredrawing all buttons\n"); - update_geometry = 1; - } - - if (update_geometry) { - for (i = 0; i < man->buttons.num_windows; i++) - set_button_geometry (man, man->buttons.buttons[i]); - } - - man->dirty_flags = 0; - man->buttons.dirty_flags = 0; - man->buttons.drawn_num_buttons = man->buttons.num_buttons; - man->buttons.drawn_num_windows = man->buttons.num_windows; - - if (man->buttons.num_windows == 0) { - if (force_draw) - draw_empty_manager (man); - } - else { - /* I was having the problem where when the shape changed the manager - wouldn't get redrawn. It appears we weren't getting the expose. - How can I tell when I am going to reliably get an expose event? */ - - if (1 || !shape_changed) { - /* if shape changed, we'll catch it on the expose */ - for (i = 0; i < man->buttons.num_buttons; i++) { - draw_button (man, i, force_draw); - } - } - } - man->drawn_geometry = man->geometry; - XFlush (theDisplay); -} - - -static int compare_windows(SortType type, WinData *a, WinData *b) -{ - if (type == SortId) { - return a->app_id - b->app_id; - } - else if (type == SortName) { - return strcasecmp (a->display_string, b->display_string); - } - else if (type == SortNameCase) { - return strcmp (a->display_string, b->display_string); - } - else { - ConsoleMessage ("Internal error in compare_windows\n"); - return 0; - } + if (redraw_all || (man->dirty_flags & GEOMETRY_CHANGED)) { + ConsoleDebug(X11, "\tredrawing all buttons\n"); + update_geometry = 1; + } + + if (update_geometry) { + for (i = 0; i < man->buttons.num_windows; i++) + set_button_geometry(man, man->buttons.buttons[i]); + } + + man->dirty_flags = 0; + man->buttons.dirty_flags = 0; + man->buttons.drawn_num_buttons = man->buttons.num_buttons; + man->buttons.drawn_num_windows = man->buttons.num_windows; + + if (man->buttons.num_windows == 0) { + if (force_draw) + draw_empty_manager(man); + } else { + /* I was having the problem where when the shape changed the + manager wouldn't get redrawn. It appears we weren't getting + the expose. How can I tell when I am going to reliably get an + expose event? */ + + if (1 || !shape_changed) { + /* if shape changed, we'll catch it on the expose */ + for (i = 0; i < man->buttons.num_buttons; i++) { + draw_button(man, i, force_draw); + } + } + } + man->drawn_geometry = man->geometry; + XFlush(theDisplay); +} + +static int +compare_windows(SortType type, WinData *a, WinData *b) +{ + if (type == SortId) { + return a->app_id - b->app_id; + } else if (type == SortName) { + return strcasecmp(a->display_string, b->display_string); + } else if (type == SortNameCase) { + return strcmp(a->display_string, b->display_string); + } else { + ConsoleMessage("Internal error in compare_windows\n"); + return 0; + } } /* find_windows_spot: returns index of button to stick the window in. @@ -1453,351 +1520,366 @@ static int compare_windows(SortType type, WinData *a, WinData *b) * if it were. */ -static int find_windows_spot (WinData *win) -{ - WinManager *man = win->manager; - int num_windows = man->buttons.num_windows; - - if (man->sort != SortNone) { - int i, cur, start, finish, cmp_dir, correction; - Button **bp; - - bp = man->buttons.buttons; - if (win->button) { - /* start search from our current location */ - cur = win->button->index; - - if (cur - 1 >= 0 && - compare_windows (man->sort, - win, bp[cur - 1]->drawn_state.win) < 0) { - start = cur - 1; - finish = -1; - cmp_dir = -1; - correction = 1; - } - else if (cur < num_windows - 1 && - compare_windows (man->sort, - win, bp[cur + 1]->drawn_state.win) > 0) { - start = cur + 1; - finish = num_windows; - cmp_dir = 1; - correction = -1; - } - else { - return cur; - } - } - else { - start = 0; - finish = num_windows; - cmp_dir = 1; - correction = 0; - } - for (i = start; i != finish && bp[i]->drawn_state.win && cmp_dir * - compare_windows (man->sort, win, bp[i]->drawn_state.win) > 0; - i = i + cmp_dir) - ; - i += correction; - ConsoleDebug (X11, "find_windows_spot: %s %d\n", win->display_string, i); - return i; - } - else { - if (win->button) { - /* already have a perfectly fine spot */ - return win->button->index; - } - else { - return num_windows; - } - } - - /* shouldn't get here */ - return -1; -} - -static void move_window_buttons (WinManager *man, int start, int finish, - int offset) -{ - int n = man->buttons.num_buttons, i; - Button **bp; - - ConsoleDebug (X11, "move_window_buttons: %s(%d): (%d, %d) + %d\n", - man->titlename, n, start, finish, offset); - - if (finish >= n || finish + offset >= n || start < 0 || start + offset < 0) { - ConsoleMessage ("Internal error in move_window_buttons\n"); - ConsoleMessage ("\tn = %d, start = %d, finish = %d, offset = %d\n", - n, start, finish, offset); - return; - } - - bp = man->buttons.buttons; - - if (offset > 0) { - for (i = finish; i >= start; i--) { - if (bp[i]->drawn_state.win) - bp[i]->drawn_state.win->button = bp[i + offset]; - bp[i + offset]->drawn_state = bp[i]->drawn_state; - bp[i + offset]->drawn_state.dirty_flags = ALL_CHANGED; - } - } - else if (offset < 0) { - for (i = start; i <= finish; i++) { - if (bp[i]->drawn_state.win) - bp[i]->drawn_state.win->button = bp[i + offset]; - bp[i + offset]->drawn_state = bp[i]->drawn_state; - bp[i + offset]->drawn_state.dirty_flags = ALL_CHANGED; - } - } -} - -static void insert_windows_button (WinData *win) -{ - int spot; - int selected_index = -1; - WinManager *man = win->manager; - ButtonArray *buttons; - - ConsoleDebug (X11, "insert_windows_button: %s\n", win->titlename); - - assert (man); - selected_index = selected_button_in_man (man); - - if (win->button) { - ConsoleDebug (X11, "insert_windows_button: POSSIBLE BUG: " - "already have a button\n"); - return; - } - - if (!win || !win->complete || !man) { - ConsoleMessage ("Internal error in insert_windows_button\n"); - ShutMeDown (1); - } - - buttons = &man->buttons; - - spot = find_windows_spot (win); - - increase_num_windows (buttons, 1); - move_window_buttons (man, spot, buttons->num_windows - 2, 1); - - set_window_button (win, spot); - if (selected_index >= 0) { - ConsoleDebug (X11, "insert_windows_button: selected_index = %d, moving\n", - selected_index); - move_highlight (man, man->buttons.buttons[selected_index]); - } -} - -void delete_windows_button (WinData *win) +static int +find_windows_spot(WinData *win) +{ + WinManager *man = win->manager; + int num_windows = man->buttons.num_windows; + + if (man->sort != SortNone) { + int i, cur, start, finish, cmp_dir, correction; + Button **bp; + + bp = man->buttons.buttons; + if (win->button) { + /* start search from our current location */ + cur = win->button->index; + + if (cur - 1 >= 0 && + compare_windows(man->sort, win, + bp[cur - 1]->drawn_state.win) < 0) { + start = cur - 1; + finish = -1; + cmp_dir = -1; + correction = 1; + } else if (cur < num_windows - 1 && + compare_windows(man->sort, win, + bp[cur + 1]->drawn_state.win) > 0) { + start = cur + 1; + finish = num_windows; + cmp_dir = 1; + correction = -1; + } else { + return cur; + } + } else { + start = 0; + finish = num_windows; + cmp_dir = 1; + correction = 0; + } + for (i = start; i != finish && bp[i]->drawn_state.win && + cmp_dir * compare_windows(man->sort, win, + bp[i]->drawn_state.win) > + 0; + i = i + cmp_dir) + ; + i += correction; + ConsoleDebug( + X11, "find_windows_spot: %s %d\n", win->display_string, i); + return i; + } else { + if (win->button) { + /* already have a perfectly fine spot */ + return win->button->index; + } else { + return num_windows; + } + } + + /* shouldn't get here */ + return -1; +} + +static void +move_window_buttons(WinManager *man, int start, int finish, int offset) +{ + int n = man->buttons.num_buttons, i; + Button **bp; + + ConsoleDebug(X11, "move_window_buttons: %s(%d): (%d, %d) + %d\n", + man->titlename, n, start, finish, offset); + + if (finish >= n || finish + offset >= n || start < 0 || + start + offset < 0) { + ConsoleMessage("Internal error in move_window_buttons\n"); + ConsoleMessage( + "\tn = %d, start = %d, finish = %d, offset = %d\n", n, + start, finish, offset); + return; + } + + bp = man->buttons.buttons; + + if (offset > 0) { + for (i = finish; i >= start; i--) { + if (bp[i]->drawn_state.win) + bp[i]->drawn_state.win->button = bp[i + offset]; + bp[i + offset]->drawn_state = bp[i]->drawn_state; + bp[i + offset]->drawn_state.dirty_flags = ALL_CHANGED; + } + } else if (offset < 0) { + for (i = start; i <= finish; i++) { + if (bp[i]->drawn_state.win) + bp[i]->drawn_state.win->button = bp[i + offset]; + bp[i + offset]->drawn_state = bp[i]->drawn_state; + bp[i + offset]->drawn_state.dirty_flags = ALL_CHANGED; + } + } +} + +static void +insert_windows_button(WinData *win) { - int spot; - int selected_index = -1; - WinManager *man = (win->manager); - ButtonArray *buttons; + int spot; + int selected_index = -1; + WinManager *man = win->manager; + ButtonArray *buttons; - ConsoleDebug (X11, "delete_windows_button: %s\n", win->titlename); + ConsoleDebug(X11, "insert_windows_button: %s\n", win->titlename); - assert (man); + if (!win || !win->complete || !man) { + ConsoleMessage("Internal error in insert_windows_button\n"); + ShutMeDown(1); + } + + if (win->button) { + ConsoleDebug(X11, "insert_windows_button: POSSIBLE BUG: " + "already have a button\n"); + return; + } - buttons = &win->manager->buttons; + assert(man); + selected_index = selected_button_in_man(man); - assert (win->button); - assert (buttons->buttons); + buttons = &man->buttons; - selected_index = selected_button_in_man (man); - ConsoleDebug (X11, "delete_windows_button: selected_index = %d\n", - selected_index); + spot = find_windows_spot(win); - spot = win->button->index; + increase_num_windows(buttons, 1); + move_window_buttons(man, spot, buttons->num_windows - 2, 1); - move_window_buttons (win->manager, spot + 1, buttons->num_windows - 1, -1); - clear_button (buttons->buttons[buttons->num_windows - 1]); - increase_num_windows (buttons, -1); - win->button = NULL; - if (globals.focus_win == win) { - globals.focus_win = NULL; - } - if (selected_index >= 0) { - ConsoleDebug (X11, "delete_windows_button: selected_index = %d, moving\n", - selected_index); - move_highlight (man, man->buttons.buttons[selected_index]); - } - win->state = 0; + set_window_button(win, spot); + if (selected_index >= 0) { + ConsoleDebug(X11, + "insert_windows_button: selected_index = %d, moving\n", + selected_index); + move_highlight(man, man->buttons.buttons[selected_index]); + } } -void resort_windows_button (WinData *win) +void +delete_windows_button(WinData *win) { - int new_spot, cur_spot; - int selected_index = -1; - WinManager *man = win->manager; + int spot; + int selected_index = -1; + WinManager *man = (win->manager); + ButtonArray *buttons; - assert (win->button && man); + ConsoleDebug(X11, "delete_windows_button: %s\n", win->titlename); - ConsoleDebug (X11, "In resort_windows_button: %s\n", win->resname); + assert(man); - selected_index = selected_button_in_man (man); + buttons = &win->manager->buttons; - new_spot = find_windows_spot (win); - cur_spot = win->button->index; + assert(win->button); + assert(buttons->buttons); - print_button_info (win->button); + selected_index = selected_button_in_man(man); + ConsoleDebug(X11, "delete_windows_button: selected_index = %d\n", + selected_index); - if (new_spot != cur_spot) { - ConsoleDebug (X11, "resort_windows_button: win moves from %d to %d\n", - cur_spot, new_spot); - if (new_spot < cur_spot) { - move_window_buttons (man, new_spot, cur_spot - 1, +1); - } - else { - move_window_buttons (man, cur_spot + 1, new_spot, -1); - } - set_window_button (win, new_spot); + spot = win->button->index; - if (selected_index >= 0) { - move_highlight (man, man->buttons.buttons[selected_index]); - } - } + move_window_buttons( + win->manager, spot + 1, buttons->num_windows - 1, -1); + clear_button(buttons->buttons[buttons->num_windows - 1]); + increase_num_windows(buttons, -1); + win->button = NULL; + if (globals.focus_win == win) { + globals.focus_win = NULL; + } + if (selected_index >= 0) { + ConsoleDebug(X11, + "delete_windows_button: selected_index = %d, moving\n", + selected_index); + move_highlight(man, man->buttons.buttons[selected_index]); + } + win->state = 0; } -void move_highlight (WinManager *man, Button *b) +void +resort_windows_button(WinData *win) { - WinData *old; + int new_spot, cur_spot; + int selected_index = -1; + WinManager *man = win->manager; + + assert(win->button && man); - assert (man); + ConsoleDebug(X11, "In resort_windows_button: %s\n", win->resname); - ConsoleDebug (X11, "move_highlight\n"); + selected_index = selected_button_in_man(man); - old = globals.select_win; + new_spot = find_windows_spot(win); + cur_spot = win->button->index; - if (old && old->button) { - del_win_state (old, SELECT_CONTEXT); - old->manager->select_button = NULL; - draw_button (old->manager, old->button->index, 0); - } - if (b && b->drawn_state.win) { - add_win_state (b->drawn_state.win, SELECT_CONTEXT); - draw_button (man, b->index, 0); - globals.select_win = b->drawn_state.win; - } - else { - globals.select_win = NULL; - } + print_button_info(win->button); - man->select_button = b; + if (new_spot != cur_spot) { + ConsoleDebug(X11, + "resort_windows_button: win moves from %d to %d\n", + cur_spot, new_spot); + if (new_spot < cur_spot) { + move_window_buttons(man, new_spot, cur_spot - 1, +1); + } else { + move_window_buttons(man, cur_spot + 1, new_spot, -1); + } + set_window_button(win, new_spot); + + if (selected_index >= 0) { + move_highlight( + man, man->buttons.buttons[selected_index]); + } + } } -void man_exposed (WinManager *man, XEvent *theEvent) +void +move_highlight(WinManager *man, Button *b) { - int x1, y1, w1, h1; - int x2, y2, w2, h2; - int i; - Button **bp; + WinData *old; + + assert(man); + + ConsoleDebug(X11, "move_highlight\n"); + + old = globals.select_win; - ConsoleDebug (X11, "manager: %s, got expose\n", man->titlename); + if (old && old->button) { + del_win_state(old, SELECT_CONTEXT); + old->manager->select_button = NULL; + draw_button(old->manager, old->button->index, 0); + } + if (b && b->drawn_state.win) { + add_win_state(b->drawn_state.win, SELECT_CONTEXT); + draw_button(man, b->index, 0); + globals.select_win = b->drawn_state.win; + } else { + globals.select_win = NULL; + } - x1 = theEvent->xexpose.x; - y1 = theEvent->xexpose.y; - w1 = theEvent->xexpose.width; - h1 = theEvent->xexpose.height; + man->select_button = b; +} + +void +man_exposed(WinManager *man, XEvent *theEvent) +{ + int x1, y1, w1, h1; + int x2, y2, w2, h2; + int i; + Button **bp; - w2 = man->geometry.boxwidth; - h2 = man->geometry.boxheight; + ConsoleDebug(X11, "manager: %s, got expose\n", man->titlename); - bp = man->buttons.buttons; + x1 = theEvent->xexpose.x; + y1 = theEvent->xexpose.y; + w1 = theEvent->xexpose.width; + h1 = theEvent->xexpose.height; + + w2 = man->geometry.boxwidth; + h2 = man->geometry.boxheight; + + bp = man->buttons.buttons; #ifdef SHAPE - /* There's some weird problem where if we change window shapes, we can't - draw into buttons in the area NewShape intersect (not OldShape) until - we get our Expose event. So, for now, just redraw everything when we - get Expose events. This has the disadvantage of drawing buttons twice, - but avoids having to match which expose event results from which shape - change */ - - if (man->buttons.num_windows) { - for (i = 0; i < man->buttons.num_windows; i++) { - bp[i]->drawn_state.dirty_flags |= REDRAW_BUTTON; - } - } - else { - draw_empty_manager (man); - } - - return; + /* There's some weird problem where if we change window shapes, we can't + draw into buttons in the area NewShape intersect (not OldShape) until + we get our Expose event. So, for now, just redraw everything when we + get Expose events. This has the disadvantage of drawing buttons + twice, but avoids having to match which expose event results from + which shape change */ + + if (man->buttons.num_windows) { + for (i = 0; i < man->buttons.num_windows; i++) { + bp[i]->drawn_state.dirty_flags |= REDRAW_BUTTON; + } + } else { + draw_empty_manager(man); + } + + return; #endif - if (man->buttons.num_windows) { - for (i = 0; i < man->buttons.num_windows; i++) { - x2 = index_to_col (man, i) * w2; - y2 = index_to_row (man, i) * h2; - if (RECTANGLES_INTERSECT (x1, y1, w1, h1, x2, y2, w2, h2)) { - bp[i]->drawn_state.dirty_flags |= REDRAW_BUTTON; - } - } - } - else { - draw_empty_manager (man); - } + if (man->buttons.num_windows) { + for (i = 0; i < man->buttons.num_windows; i++) { + x2 = index_to_col(man, i) * w2; + y2 = index_to_row(man, i) * h2; + if (RECTANGLES_INTERSECT( + x1, y1, w1, h1, x2, y2, w2, h2)) { + bp[i]->drawn_state.dirty_flags |= REDRAW_BUTTON; + } + } + } else { + draw_empty_manager(man); + } } /***************************************************************************/ /* Debugging routines */ /***************************************************************************/ -void check_managers_consistency (void) +void +check_managers_consistency(void) { #ifdef PRINT_DEBUG - int i, j; - Button **b; - - for (i = 0; i < globals.num_managers; i++) { - for (j = 0, b = globals.managers[i].buttons.buttons; - j < globals.managers[i].buttons.num_buttons; j++, b++) { - if ((*b)->drawn_state.win && (*b)->drawn_state.win->button != *b) { - ConsoleMessage ("manager %d, button %d is confused\n", i, j); - abort (); - } - else if ((*b)->drawn_state.win && - j >= globals.managers[i].buttons.num_windows) { - ConsoleMessage ("manager %d: button %d has window and shouldn't\n", - i, j); - abort (); - } - } - } + int i, j; + Button **b; + + for (i = 0; i < globals.num_managers; i++) { + for (j = 0, b = globals.managers[i].buttons.buttons; + j < globals.managers[i].buttons.num_buttons; j++, b++) { + if ((*b)->drawn_state.win && + (*b)->drawn_state.win->button != *b) { + ConsoleMessage( + "manager %d, button %d is confused\n", i, + j); + abort(); + } else if ((*b)->drawn_state.win && + j >= globals.managers[i] + .buttons.num_windows) { + ConsoleMessage("manager %d: button %d has " + "window and shouldn't\n", + i, j); + abort(); + } + } + } #endif } -static void print_button_info (Button *b) +static void +print_button_info(Button *b) { #ifdef PRINT_DEBUG - ConsoleMessage ("button: %d\n", b->index); - ConsoleMessage ("win: 0x%x\n", b->drawn_state.win); - ConsoleMessage ("dirty: 0x%x\n", b->drawn_state.dirty_flags); - if (b->drawn_state.win) { - ConsoleMessage ("name: %s\n", b->drawn_state.display_string); - ConsoleMessage ("iconified: %d state %d\n", b->drawn_state.iconified, - b->drawn_state.state); - ConsoleMessage ("win->button: 0x%x\n", b->drawn_state.win->button); - } + ConsoleMessage("button: %d\n", b->index); + ConsoleMessage("win: 0x%x\n", b->drawn_state.win); + ConsoleMessage("dirty: 0x%x\n", b->drawn_state.dirty_flags); + if (b->drawn_state.win) { + ConsoleMessage("name: %s\n", b->drawn_state.display_string); + ConsoleMessage("iconified: %d state %d\n", + b->drawn_state.iconified, b->drawn_state.state); + ConsoleMessage( + "win->button: 0x%x\n", b->drawn_state.win->button); + } #endif } #ifdef PRINT_DEBUG -static void print_buttons (WinManager *man) +static void +print_buttons(WinManager *man) { - int i; - Button *b; + int i; + Button *b; - ConsoleMessage ("Buttons for manager: %s\n", man->titlename); + ConsoleMessage("Buttons for manager: %s\n", man->titlename); - for (i = 0; i < man->buttons.num_buttons; i++) { - b = man->buttons.buttons[i]; - ConsoleMessage ("Button: %d, index = %d\n", i, b->index); - ConsoleMessage ("\tdirty flags: 0x%x\n", b->drawn_state.dirty_flags); - ConsoleMessage ("\twin: 0x%x\n", b->drawn_state.win); - } + for (i = 0; i < man->buttons.num_buttons; i++) { + b = man->buttons.buttons[i]; + ConsoleMessage("Button: %d, index = %d\n", i, b->index); + ConsoleMessage( + "\tdirty flags: 0x%x\n", b->drawn_state.dirty_flags); + ConsoleMessage("\twin: 0x%x\n", b->drawn_state.win); + } } #endif - Index: fvwm/modules/FvwmIconMan/xmanager.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIconMan/xmanager.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIconMan/xmanager.h --- fvwm/modules/FvwmIconMan/xmanager.h +++ fvwm/modules/FvwmIconMan/xmanager.h @@ -4,49 +4,50 @@ #define FONT_STRING "8x13" #define DEFAULT_BUTTON_WIDTH 200 #define DEFAULT_BUTTON_HEIGHT 17 -#define DEFAULT_NUM_COLS 1 +#define DEFAULT_NUM_COLS 1 #define DEFAULT_NUM_ROWS 0 -extern void draw_managers (void); -extern void draw_manager (WinManager *man); +#include "FvwmIconMan.h" -extern int which_box (WinManager *man, int x, int y); -extern Button *xy_to_button (WinManager *man, int x, int y); +extern void draw_managers(void); +extern void draw_manager(WinManager *man); -extern void delete_windows_button (WinData *win); -extern void resort_windows_button (WinData *win); +extern int which_box(WinManager *man, int x, int y); +extern Button *xy_to_button(WinManager *man, int x, int y); -extern void size_manager (WinManager *man); -extern void init_button_array (ButtonArray *array); -extern void init_boxes (void); -extern void set_shape (WinManager *man); -extern void draw_added_icon (WinManager *man); -extern void draw_deleted_icon (WinManager *man); -extern void move_highlight (WinManager *man, Button *button); +extern void delete_windows_button(WinData *win); +extern void resort_windows_button(WinData *win); + +extern void size_manager(WinManager *man); +extern void init_button_array(ButtonArray *array); +extern void init_boxes(void); +extern void set_shape(WinManager *man); +extern void draw_added_icon(WinManager *man); +extern void draw_deleted_icon(WinManager *man); +extern void move_highlight(WinManager *man, Button *button); #ifdef MINI_ICONS -extern void set_win_picture (WinData *win, Pixmap picture, Pixmap mask, - unsigned int depth, unsigned int width, - unsigned int height); +extern void set_win_picture(WinData *win, Pixmap picture, Pixmap mask, + unsigned int depth, unsigned int width, unsigned int height); #endif -extern void set_win_iconified (WinData *win, int iconified); -extern void set_win_state (WinData *win, int state); -extern void add_win_state (WinData *win, int flag); -extern void del_win_state (WinData *win, int flag); -extern void set_win_displaystring (WinData *win); -extern void set_manager_width (WinManager *man, int width); -extern int change_windows_manager (WinData *win); -extern void check_in_window (WinData *win); -extern void set_manager_window_mapping (WinManager *man, int flag); -extern void man_exposed (WinManager *man, XEvent *theEvent); -extern void force_manager_redraw (WinManager *man); - -extern Button *button_above (WinManager *man, Button *b); -extern Button *button_below (WinManager *man, Button *b); -extern Button *button_right (WinManager *man, Button *b); -extern Button *button_left (WinManager *man, Button *b); -extern Button *button_next (WinManager *man, Button *b); -extern Button *button_prev (WinManager *man, Button *b); - -extern void check_managers_consistency (void); +extern void set_win_iconified(WinData *win, int iconified); +extern void set_win_state(WinData *win, int state); +extern void add_win_state(WinData *win, int flag); +extern void del_win_state(WinData *win, int flag); +extern void set_win_displaystring(WinData *win); +extern void set_manager_width(WinManager *man, int width); +extern int change_windows_manager(WinData *win); +extern void check_in_window(WinData *win); +extern void set_manager_window_mapping(WinManager *man, int flag); +extern void man_exposed(WinManager *man, XEvent *theEvent); +extern void force_manager_redraw(WinManager *man); + +extern Button *button_above(WinManager *man, Button *b); +extern Button *button_below(WinManager *man, Button *b); +extern Button *button_right(WinManager *man, Button *b); +extern Button *button_left(WinManager *man, Button *b); +extern Button *button_next(WinManager *man, Button *b); +extern Button *button_prev(WinManager *man, Button *b); + +extern void check_managers_consistency(void); #endif Index: fvwm/modules/FvwmIdent/FvwmIdent.1 =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIdent/FvwmIdent.1,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIdent/FvwmIdent.1 --- fvwm/modules/FvwmIdent/FvwmIdent.1 +++ fvwm/modules/FvwmIdent/FvwmIdent.1 @@ -1,69 +1,56 @@ .\" $OpenBSD: FvwmIdent.1,v 1.1.1.1 2006/11/26 10:53:51 matthieu Exp $ .\" t -.\" @(#)FvwmIdent.1 1/12/94 -.TH FvwmIdent 1 "Jan 28 1994" 1.20 +.\" @(#)FvwmIdent.1 1/12/94 +.TH FVWMIDENT 1 "January 28, 1994" "1.20" "FVWM Modules" .UC .SH NAME FvwmIdent \- the FVWM identify-window module .SH SYNOPSIS FvwmIdent is spawned by fvwm, so no command line invocation will work. - .SH DESCRIPTION -The FvwmIdent module questions the user to select a target window, if -the module was not launched from within a window context in Fvwm. -After that, it pops up a window with information about the window -which was selected. - -FvwmIdent reads the same .fvwmrc file as fvwm reads when it starts up, -and looks for lines similar to "*FvwmIdentFore green". - +The FvwmIdent module questions the user to select a target window if the +module was not launched from within a window context in Fvwm. +.PP +After that, it pops up a window with information about the window which +was selected. +.PP +FvwmIdent reads the same .fvwmrc file as fvwm reads when it starts up and +looks for lines similar to "*FvwmIdentFore green". .SH COPYRIGHTS -The FvwmIdent program, and the concept for -interfacing this module to the Window Manager, are all original work -by Robert Nation Nobutaka Suzuki. - +The FvwmIdent program, and the concept for interfacing this module to the +Window Manager, are original work by Robert Nation and Nobutaka Suzuki. +.PP Copyright 1994, Robert Nation and Nobutaka Suzuki. No guarantees or -warranties or anything -are provided or implied in any way whatsoever. Use this program at your -own risk. Permission to use this program for any purpose is given, -as long as the copyright is kept intact. - - +warranties or anything are provided or implied in any way whatsoever. +.PP +Use this program at your own risk. Permission to use this program for any +purpose is given, as long as the copyright is kept intact. .SH INITIALIZATION -During initialization, \fIFvwmIdent\fP will eventually search a -configuration file which describes the colors and font to use. -The configuration file is the same file that fvwm used during initialization. - +During initialization, \fIFvwmIdent\fP will search a configuration file +which describes the colors and font to use. The configuration file is the +same file that fvwm used during initialization. +.PP If the FvwmIdent executable is linked to another name, ie ln -s FvwmIdent MoreIdentify, then another module called MoreIdentify can be started, with a completely different configuration than FvwmIdent, -simply by changing the keyword FvwmIdent to MoreIdentify. This way multiple -clutter-reduction programs can be used. - +simply by changing the keyword FvwmIdent to MoreIdentify. This way +multiple clutter-reduction programs can be used. .SH INVOCATION -FvwmIdent can be invoked by binding the action 'Module -FvwmIdent' to a menu or key-stroke in the .fvwmrc file. -Fvwm will search -directory specified in the ModulePath configuration option to attempt -to locate FvwmIdent. Although nothing keeps you from launching -FvwmIdent at start-up time, you probably don't want to. - +FvwmIdent can be invoked by binding the action "Module FvwmIdent" to a +menu or key-stroke in the .fvwmrc file. +.PP +Fvwm will search the directory specified in the ModulePath configuration +option to locate FvwmIdent. Although nothing keeps you from launching +FvwmIdent at start-up time, you probably do not want to. .SH CONFIGURATION OPTIONS -FvwmIdent reads the same .fvwmrc file as fvwm reads when it starts up, -and looks for lines as listed below: - +FvwmIdent reads the same .fvwmrc file as fvwm reads when it starts up and +looks for lines as listed below: .IP "*FvwmIdentFore \fIcolor\fP" Tells the module to use \fIcolor\fP instead of black for text. - .IP "*FvwmIdentBack \fIcolor\fP" Tells the module to use \fIcolor\fP instead of white for the window background. - .IP "*FvwmIdentFont \fIfontname\fP" Tells the module to use \fIfontname\fP instead of fixed for text. - - .SH AUTHOR -Robert Nation and and Nobutaka -Suzuki (nobuta-s@is.aist-nara.ac.jp). - +Robert Nation and Nobutaka Suzuki (nobuta-s@is.aist-nara.ac.jp). Index: fvwm/modules/FvwmIdent/FvwmIdent.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIdent/FvwmIdent.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIdent/FvwmIdent.c --- fvwm/modules/FvwmIdent/FvwmIdent.c +++ fvwm/modules/FvwmIdent/FvwmIdent.c @@ -12,30 +12,32 @@ #define FALSE #define YES "Yes" -#define NO "No" +#define NO "No" -#include "config.h" +#include +#include -#include -#include #include +#include +#include #include -#include -#include + +#include "config.h" +#include "../../fvwm/fvwm_sandbox.h" #if HAVE_SYS_SELECT_H #include #endif -#include -#include -#include +#include +#include #include -#include #include -#include -#include +#include #include +#include +#include +#include #include "../../fvwm/module.h" #include "FvwmIdent.h" @@ -44,7 +46,7 @@ char *MyName; int fd_width; int fd[2]; -Display *dpy; /* which display are we talking to */ +Display *dpy; /* which display are we talking to */ Window Root; int screen; int x_fd; @@ -56,23 +58,23 @@ char *ForeColor = "black"; char *font_string = "fixed"; Pixel back_pix, fore_pix; -GC NormalGC; +GC NormalGC; Window main_win; Window app_win; XFontStruct *font; -int Width, Height,win_x,win_y; +int Width, Height, win_x, win_y; -#define MW_EVENTS (ExposureMask | ButtonReleaseMask | KeyReleaseMask) +#define MW_EVENTS (ExposureMask | ButtonReleaseMask | KeyReleaseMask) static Atom wm_del_win; struct target_struct target; -int found=0; +int found = 0; -static int ListSize=0; +static int ListSize = 0; -struct Item* itemlistRoot = NULL; +struct Item *itemlistRoot = NULL; int max_col1, max_col2; char id[15], desktop[10], swidth[10], sheight[10], borderw[10], geometry[30]; char mymin_aspect[11], max_aspect[11]; @@ -83,97 +85,94 @@ char mymin_aspect[11], max_aspect[11]; * main - start of module * ***********************************************************************/ -int main(int argc, char **argv) +int +main(int argc, char **argv) { - char *temp, *s; - char *display_name = NULL; - int Clength; - char *tline; - - /* Save the program name for error messages and config parsing */ - temp = argv[0]; - s=strrchr(argv[0], '/'); - if (s != NULL) - temp = s + 1; - - MyName = safemalloc(strlen(temp)+2); - strcpy(MyName,"*"); - strcat(MyName, temp); - Clength = strlen(MyName); - - if((argc != 6)&&(argc != 7)) - { - fprintf(stderr,"%s Version %s should only be executed by fvwm!\n",MyName, - VERSION); - exit(1); - } - - /* Dead pipe == dead fvwm */ - signal (SIGPIPE, DeadPipe); - - fd[0] = atoi(argv[1]); - fd[1] = atoi(argv[2]); - - /* An application window may have already been selected - look for it */ - sscanf(argv[4],"%x",(unsigned int *)&app_win); - - /* Open the Display */ - if (!(dpy = XOpenDisplay(display_name))) - { - fprintf(stderr,"%s: can't open display %s", MyName, - XDisplayName(display_name)); - exit (1); - } - x_fd = XConnectionNumber(dpy); - screen= DefaultScreen(dpy); - Root = RootWindow(dpy, screen); - d_depth = DefaultDepth(dpy, screen); - - ScreenHeight = DisplayHeight(dpy,screen); - ScreenWidth = DisplayWidth(dpy,screen); - - SetMessageMask(fd,M_CONFIGURE_WINDOW|M_WINDOW_NAME|M_ICON_NAME| - M_RES_CLASS| M_RES_NAME| M_END_WINDOWLIST|M_CONFIG_INFO| - M_END_CONFIG_INFO); - /* scan config file for set-up parameters */ - /* Colors and fonts */ - - GetConfigLine(fd,&tline); - - while(tline != (char *)0) - { - if(strlen(tline)>1) - { - if(strncasecmp(tline, CatString3(MyName,"Font",""),Clength+4)==0) - { - CopyString(&font_string,&tline[Clength+4]); - } - else if(strncasecmp(tline,CatString3(MyName,"Fore",""), - Clength+4)==0) - { - CopyString(&ForeColor,&tline[Clength+4]); - } - else if(strncasecmp(tline,CatString3(MyName, "Back",""), - Clength+4)==0) - { - CopyString(&BackColor,&tline[Clength+4]); - } + char *temp, *s; + char *display_name = NULL; + int Clength; + char *tline; + + /* Save the program name for error messages and config parsing */ + temp = argv[0]; + s = strrchr(argv[0], '/'); + if (s != NULL) + temp = s + 1; + + size_t name_len = strlen(temp); + MyName = xmalloc(name_len + 2); + strlcpy(MyName, "*", name_len + 2); + strlcat(MyName, temp, name_len + 2); + Clength = strlen(MyName); + + if ((argc != 6) && (argc != 7)) { + fprintf(stderr, + "%s Version %s should only be executed by fvwm!\n", MyName, + VERSION); + exit(1); + } + + /* Dead pipe == dead fvwm */ + signal(SIGPIPE, DeadPipe); + + fd[0] = atoi(argv[1]); + fd[1] = atoi(argv[2]); + + /* An application window may have already been selected - look for it */ + sscanf(argv[4], "%x", (unsigned int *)&app_win); + + /* Open the Display */ + if (!(dpy = XOpenDisplay(display_name))) { + fprintf(stderr, "%s: can't open display %s", MyName, + XDisplayName(display_name)); + exit(1); + } + x_fd = XConnectionNumber(dpy); + screen = DefaultScreen(dpy); + Root = RootWindow(dpy, screen); + d_depth = DefaultDepth(dpy, screen); + + ScreenHeight = DisplayHeight(dpy, screen); + ScreenWidth = DisplayWidth(dpy, screen); + + SetMessageMask(fd, M_CONFIGURE_WINDOW | M_WINDOW_NAME | M_ICON_NAME | + M_RES_CLASS | M_RES_NAME | M_END_WINDOWLIST | + M_CONFIG_INFO | M_END_CONFIG_INFO); + /* scan config file for set-up parameters */ + /* Colors and fonts */ + + GetConfigLine(fd, &tline); + + while (tline != (char *)0) { + if (strlen(tline) > 1) { + if (strncasecmp(tline, CatString3(MyName, "Font", ""), + Clength + 4) == 0) { + CopyString(&font_string, &tline[Clength + 4]); + } else if (strncasecmp(tline, + CatString3(MyName, "Fore", ""), + Clength + 4) == 0) { + CopyString(&ForeColor, &tline[Clength + 4]); + } else if (strncasecmp(tline, + CatString3(MyName, "Back", ""), + Clength + 4) == 0) { + CopyString(&BackColor, &tline[Clength + 4]); + } + } + GetConfigLine(fd, &tline); } - GetConfigLine(fd,&tline); - } - if(app_win == 0) - GetTargetWindow(&app_win); + if (app_win == 0) + GetTargetWindow(&app_win); - fd_width = GetFdWidth(); + fd_width = GetFdWidth(); - /* Create a list of all windows */ - /* Request a list of all windows, - * wait for ConfigureWindow packets */ - SendInfo(fd,"Send_WindowList",0); + /* Create a list of all windows */ + /* Request a list of all windows, + * wait for ConfigureWindow packets */ + SendInfo(fd, "Send_WindowList", 0); - Loop(fd); - return 0; + Loop(fd); + return 0; } /************************************************************************** @@ -181,66 +180,64 @@ int main(int argc, char **argv) * Read the entire window list from fvwm * *************************************************************************/ -void Loop(int *fd) +void +Loop(int *fd) { - unsigned long header[4], *body; + unsigned long header[4], *body; - while(1) - { - if(ReadFvwmPacket(fd[1],header,&body) > 0) - { - process_message(header[1],body); - free(body); + sandbox_x11_only("FvwmIdent"); + sandbox_x11_only("FvwmIdent"); + + while (1) { + if (ReadFvwmPacket(fd[1], header, &body) > 0) { + process_message(header[1], body); + free(body); + } } - } } - /************************************************************************** * * Process window list messages * *************************************************************************/ -void process_message(unsigned long type,unsigned long *body) +void +process_message(unsigned long type, unsigned long *body) { - switch(type) - { - case M_CONFIGURE_WINDOW: - list_configure(body); - break; - case M_WINDOW_NAME: - list_window_name(body); - break; - case M_ICON_NAME: - list_icon_name(body); - break; - case M_RES_CLASS: - list_class(body); - break; - case M_RES_NAME: - list_res_name(body); - break; - case M_END_WINDOWLIST: - list_end(); - break; - default: - break; - - } + switch (type) { + case M_CONFIGURE_WINDOW: + list_configure(body); + break; + case M_WINDOW_NAME: + list_window_name(body); + break; + case M_ICON_NAME: + list_icon_name(body); + break; + case M_RES_CLASS: + list_class(body); + break; + case M_RES_NAME: + list_res_name(body); + break; + case M_END_WINDOWLIST: + list_end(); + break; + default: + break; + } } - - - /*********************************************************************** * * Detected a broken pipe - time to exit * **********************************************************************/ -void DeadPipe(int nonsense) +void +DeadPipe(int nonsense) { - freelist(); - exit(0); + freelist(); + exit(0); } /*********************************************************************** @@ -248,31 +245,30 @@ void DeadPipe(int nonsense) * Got window configuration info - if its our window, safe data * ***********************************************************************/ -void list_configure(unsigned long *body) +void +list_configure(unsigned long *body) { - if((app_win == (Window)body[1])||(app_win == (Window)body[0]) - ||((body[19] != 0)&&(app_win == (Window)body[19])) - ||((body[19] != 0)&&(app_win == (Window)body[20]))) - { - app_win = body[1]; - target.id = body[0]; - target.frame = body[1]; - target.frame_x = body[3]; - target.frame_y = body[4]; - target.frame_w = body[5]; - target.frame_h = body[6]; - target.desktop = body[7]; - target.flags = body[8]; - target.title_h = body[9]; - target.border_w = body[10]; - target.base_w = body[11]; - target.base_h = body[12]; - target.width_inc = body[13]; - target.height_inc = body[14]; - target.gravity = body[21]; - found = 1; - } - + if ((app_win == (Window)body[1]) || (app_win == (Window)body[0]) || + ((body[19] != 0) && (app_win == (Window)body[19])) || + ((body[19] != 0) && (app_win == (Window)body[20]))) { + app_win = body[1]; + target.id = body[0]; + target.frame = body[1]; + target.frame_x = body[3]; + target.frame_y = body[4]; + target.frame_w = body[5]; + target.frame_h = body[6]; + target.desktop = body[7]; + target.flags = body[8]; + target.title_h = body[9]; + target.border_w = body[10]; + target.base_w = body[11]; + target.base_h = body[12]; + target.width_inc = body[13]; + target.height_inc = body[14]; + target.gravity = body[21]; + found = 1; + } } /************************************************************************* @@ -280,12 +276,12 @@ void list_configure(unsigned long *body) * Capture Window name info * ************************************************************************/ -void list_window_name(unsigned long *body) +void +list_window_name(unsigned long *body) { - if((app_win == (Window)body[1])||(app_win == (Window)body[0])) - { - strncpy(target.name,(char *)&body[3],255); - } + if ((app_win == (Window)body[1]) || (app_win == (Window)body[0])) { + strncpy(target.name, (char *)&body[3], 255); + } } /************************************************************************* @@ -293,178 +289,162 @@ void list_window_name(unsigned long *body) * Capture Window Icon name info * ************************************************************************/ -void list_icon_name(unsigned long *body) +void +list_icon_name(unsigned long *body) { - if((app_win == (Window)body[1])||(app_win == (Window)body[0])) - { - strncat(target.icon_name,(char *)&body[3],255); - } + if ((app_win == (Window)body[1]) || (app_win == (Window)body[0])) { + strncat(target.icon_name, (char *)&body[3], 255); + } } - /************************************************************************* * * Capture Window class name info * ************************************************************************/ -void list_class(unsigned long *body) +void +list_class(unsigned long *body) { - if((app_win == (Window)body[1])||(app_win == (Window)body[0])) - { - strncat(target.class,(char *)&body[3],255); - } + if ((app_win == (Window)body[1]) || (app_win == (Window)body[0])) { + strncat(target.class, (char *)&body[3], 255); + } } - /************************************************************************* * * Capture Window resource info * ************************************************************************/ -void list_res_name(unsigned long *body) +void +list_res_name(unsigned long *body) { - if((app_win == (Window)body[1])||(app_win == (Window)body[0])) - { - strncat(target.res,(char *)&body[3],255); - } + if ((app_win == (Window)body[1]) || (app_win == (Window)body[0])) { + strncat(target.res, (char *)&body[3], 255); + } } - /************************************************************************* * * End of window list, open an x window and display data in it * ************************************************************************/ XSizeHints mysizehints; -void list_end(void) +void +list_end(void) { - XGCValues gcv; - unsigned long gcm; - int lmax,height; - XEvent Event; - Window JunkRoot, JunkChild; - int JunkX, JunkY; - unsigned int JunkMask; - int x,y; - - if(!found) - { -/* fprintf(stderr,"%s: Couldn't find app window\n",MyName); */ - exit(0); - } - - close(fd[0]); - close(fd[1]); - - /* load the font */ - if ((font = XLoadQueryFont(dpy, font_string)) == NULL) - { - if ((font = XLoadQueryFont(dpy, "fixed")) == NULL) - exit(1); - }; - - /* make window infomation list */ - MakeList(); - - /* size and create the window */ - lmax = max_col1 + max_col2 + 15; - - height = ListSize*(font->ascent+font->descent); - - mysizehints.flags= - USSize|USPosition|PWinGravity|PResizeInc|PBaseSize|PMinSize|PMaxSize; - /* subtract one for the right/bottom border */ - mysizehints.width = lmax+10; - mysizehints.height=height+10; - mysizehints.width_inc = 1; - mysizehints.height_inc = 1; - mysizehints.base_height = mysizehints.height; - mysizehints.base_width = mysizehints.width; - mysizehints.min_height = mysizehints.height; - mysizehints.min_width = mysizehints.width; - mysizehints.max_height = mysizehints.height; - mysizehints.max_width = mysizehints.width; - XQueryPointer( dpy, Root, &JunkRoot, &JunkChild, - &x, &y, &JunkX, &JunkY, &JunkMask); - mysizehints.win_gravity = NorthWestGravity; - - if((y+height+100)>ScreenHeight) - { - y = ScreenHeight - height - 10; - mysizehints.win_gravity = SouthWestGravity; - } - - if((x+lmax+100)>ScreenWidth) - { - x = ScreenWidth - lmax - 10; - if((y+height+100)>ScreenHeight) - mysizehints.win_gravity = SouthEastGravity; - else - mysizehints.win_gravity = NorthEastGravity; - } - mysizehints.x = x; - mysizehints.y = y; - - - - if(d_depth < 2) - { - back_pix = GetColor("white"); - fore_pix = GetColor("black"); - } - else - { - back_pix = GetColor(BackColor); - fore_pix = GetColor(ForeColor); - - } - - main_win = XCreateSimpleWindow(dpy,Root,mysizehints.x,mysizehints.y, - mysizehints.width,mysizehints.height, - 0,fore_pix,back_pix); - XSetTransientForHint(dpy,main_win,app_win); - wm_del_win = XInternAtom(dpy,"WM_DELETE_WINDOW",False); - XSetWMProtocols(dpy,main_win,&wm_del_win,1); - - XSetWMNormalHints(dpy,main_win,&mysizehints); - XSelectInput(dpy,main_win,MW_EVENTS); - change_window_name(&MyName[1]); - - gcm = GCForeground|GCBackground|GCFont; - gcv.foreground = fore_pix; - gcv.background = back_pix; - gcv.font = font->fid; - NormalGC = XCreateGC(dpy, Root, gcm, &gcv); - XMapWindow(dpy,main_win); - - /* Window is created. Display it until the user clicks or deletes it. */ - while(1) - { - XNextEvent(dpy,&Event); - switch(Event.type) - { - case Expose: - if(Event.xexpose.count == 0) - RedrawWindow(); - break; - case KeyRelease: - case ButtonRelease: - freelist(); - exit(0); - case ClientMessage: - if (Event.xclient.format==32 && Event.xclient.data.l[0]==wm_del_win) - { - freelist(); - exit(0); - } - default: - break; + XGCValues gcv; + unsigned long gcm; + int lmax, height; + XEvent Event; + Window JunkRoot, JunkChild; + int JunkX, JunkY; + unsigned int JunkMask; + int x, y; + + if (!found) { + /* fprintf(stderr,"%s: Couldn't find app window\n",MyName); + */ + exit(0); } - } -} + close(fd[0]); + close(fd[1]); + + /* load the font */ + if ((font = XLoadQueryFont(dpy, font_string)) == NULL) { + if ((font = XLoadQueryFont(dpy, "fixed")) == NULL) + exit(1); + } + + /* make window infomation list */ + MakeList(); + + /* size and create the window */ + lmax = max_col1 + max_col2 + 15; + + height = ListSize * (font->ascent + font->descent); + + mysizehints.flags = USSize | USPosition | PWinGravity | PResizeInc | + PBaseSize | PMinSize | PMaxSize; + /* subtract one for the right/bottom border */ + mysizehints.width = lmax + 10; + mysizehints.height = height + 10; + mysizehints.width_inc = 1; + mysizehints.height_inc = 1; + mysizehints.base_height = mysizehints.height; + mysizehints.base_width = mysizehints.width; + mysizehints.min_height = mysizehints.height; + mysizehints.min_width = mysizehints.width; + mysizehints.max_height = mysizehints.height; + mysizehints.max_width = mysizehints.width; + XQueryPointer(dpy, Root, &JunkRoot, &JunkChild, &x, &y, &JunkX, &JunkY, + &JunkMask); + mysizehints.win_gravity = NorthWestGravity; + + if ((y + height + 100) > ScreenHeight) { + y = ScreenHeight - height - 10; + mysizehints.win_gravity = SouthWestGravity; + } + if ((x + lmax + 100) > ScreenWidth) { + x = ScreenWidth - lmax - 10; + if ((y + height + 100) > ScreenHeight) + mysizehints.win_gravity = SouthEastGravity; + else + mysizehints.win_gravity = NorthEastGravity; + } + mysizehints.x = x; + mysizehints.y = y; + + if (d_depth < 2) { + back_pix = GetColor("white"); + fore_pix = GetColor("black"); + } else { + back_pix = GetColor(BackColor); + fore_pix = GetColor(ForeColor); + } + main_win = XCreateSimpleWindow(dpy, Root, mysizehints.x, mysizehints.y, + mysizehints.width, mysizehints.height, 0, fore_pix, back_pix); + XSetTransientForHint(dpy, main_win, app_win); + wm_del_win = XInternAtom(dpy, "WM_DELETE_WINDOW", False); + XSetWMProtocols(dpy, main_win, &wm_del_win, 1); + + XSetWMNormalHints(dpy, main_win, &mysizehints); + XSelectInput(dpy, main_win, MW_EVENTS); + change_window_name(&MyName[1]); + + gcm = GCForeground | GCBackground | GCFont; + gcv.foreground = fore_pix; + gcv.background = back_pix; + gcv.font = font->fid; + NormalGC = XCreateGC(dpy, Root, gcm, &gcv); + XMapWindow(dpy, main_win); + + /* Window is created. Display it until the user clicks or deletes it. */ + sandbox_x11_only("FvwmIdent"); + while (1) { + XNextEvent(dpy, &Event); + switch (Event.type) { + case Expose: + if (Event.xexpose.count == 0) + RedrawWindow(); + break; + case KeyRelease: + case ButtonRelease: + freelist(); + exit(0); + case ClientMessage: + if (Event.xclient.format == 32 && + Event.xclient.data.l[0] == wm_del_win) { + freelist(); + exit(0); + } + default: + break; + } + } +} /********************************************************************** * @@ -472,36 +452,32 @@ void list_end(void) * the user to select one * *********************************************************************/ -void GetTargetWindow(Window *app_win) +void +GetTargetWindow(Window *app_win) { - XEvent eventp; - int val = -10,trials; - - trials = 0; - while((trials <100)&&(val != GrabSuccess)) - { - val=XGrabPointer(dpy, Root, True, - ButtonReleaseMask, - GrabModeAsync, GrabModeAsync, Root, - XCreateFontCursor(dpy,XC_crosshair), - CurrentTime); - if(val != GrabSuccess) - { - usleep(1000); + XEvent eventp; + int val = -10, trials; + + trials = 0; + while ((trials < 100) && (val != GrabSuccess)) { + val = XGrabPointer(dpy, Root, True, ButtonReleaseMask, + GrabModeAsync, GrabModeAsync, Root, + XCreateFontCursor(dpy, XC_crosshair), CurrentTime); + if (val != GrabSuccess) { + usleep(1000); + } + trials++; } - trials++; - } - if(val != GrabSuccess) - { - fprintf(stderr,"%s: Couldn't grab the cursor!\n",MyName); - exit(1); - } - XMaskEvent(dpy, ButtonReleaseMask,&eventp); - XUngrabPointer(dpy,CurrentTime); - XSync(dpy,0); - *app_win = eventp.xany.window; - if(eventp.xbutton.subwindow != None) - *app_win = eventp.xbutton.subwindow; + if (val != GrabSuccess) { + fprintf(stderr, "%s: Couldn't grab the cursor!\n", MyName); + exit(1); + } + XMaskEvent(dpy, ButtonReleaseMask, &eventp); + XUngrabPointer(dpy, CurrentTime); + XSync(dpy, 0); + *app_win = eventp.xany.window; + if (eventp.xbutton.subwindow != None) + *app_win = eventp.xbutton.subwindow; } /************************************************************************ @@ -509,297 +485,277 @@ void GetTargetWindow(Window *app_win) * Draw the window * ***********************************************************************/ -void RedrawWindow(void) +void +RedrawWindow(void) { - int fontheight,i=0; - struct Item *cur = itemlistRoot; - - fontheight = font->ascent + font->descent; - - while(cur != NULL) - { - /* first column */ - XDrawString(dpy,main_win,NormalGC,5,5+font->ascent+i*fontheight, - cur->col1,strlen(cur->col1)); - /* second column */ - XDrawString(dpy,main_win,NormalGC,10+max_col1,5+font->ascent+i*fontheight, - cur->col2,strlen(cur->col2)); - ++i; - cur = cur->next; - } + int fontheight, i = 0; + struct Item *cur = itemlistRoot; + + fontheight = font->ascent + font->descent; + + while (cur != NULL) { + /* first column */ + XDrawString(dpy, main_win, NormalGC, 5, + 5 + font->ascent + i * fontheight, cur->col1, + strlen(cur->col1)); + /* second column */ + XDrawString(dpy, main_win, NormalGC, 10 + max_col1, + 5 + font->ascent + i * fontheight, cur->col2, + strlen(cur->col2)); + ++i; + cur = cur->next; + } } /************************************************************************** * Change the window name displayed in the title bar. **************************************************************************/ -void change_window_name(char *str) +void +change_window_name(char *str) { - XTextProperty name; - - if (XStringListToTextProperty(&str,1,&name) == 0) - { - fprintf(stderr,"%s: cannot allocate window name",MyName); - return; - } - XSetWMName(dpy,main_win,&name); - XSetWMIconName(dpy,main_win,&name); - XFree(name.value); -} + XTextProperty name; + if (XStringListToTextProperty(&str, 1, &name) == 0) { + fprintf(stderr, "%s: cannot allocate window name", MyName); + return; + } + XSetWMName(dpy, main_win, &name); + XSetWMIconName(dpy, main_win, &name); + XFree(name.value); +} /************************************************************************** -* -* Add s1(string at first column) and s2(string at second column) to itemlist -* + * + * Add s1(string at first column) and s2(string at second column) to itemlist + * *************************************************************************/ -void AddToList(char *s1, char* s2) +void +AddToList(char *s1, char *s2) { - int tw1, tw2; - struct Item* item, *cur = itemlistRoot; - - tw1 = XTextWidth(font, s1, strlen(s1)); - tw2 = XTextWidth(font, s2, strlen(s2)); - max_col1 = max_col1 > tw1 ? max_col1 : tw1; - max_col2 = max_col2 > tw2 ? max_col2 : tw2; - - item = (struct Item*)safemalloc(sizeof(struct Item)); - - item->col1 = s1; - item->col2 = s2; - item->next = NULL; - - if (cur == NULL) - itemlistRoot = item; - else { - while(cur->next != NULL) - cur = cur->next; - cur->next = item; - } - ListSize++; + int tw1, tw2; + struct Item *item, *cur = itemlistRoot; + + tw1 = XTextWidth(font, s1, strlen(s1)); + tw2 = XTextWidth(font, s2, strlen(s2)); + max_col1 = max_col1 > tw1 ? max_col1 : tw1; + max_col2 = max_col2 > tw2 ? max_col2 : tw2; + + item = (struct Item *)xmalloc(sizeof(struct Item)); + + item->col1 = s1; + item->col2 = s2; + item->next = NULL; + + if (cur == NULL) + itemlistRoot = item; + else { + while (cur->next != NULL) + cur = cur->next; + cur->next = item; + } + ListSize++; } -void MakeList(void) +void +MakeList(void) { - int bw,width,height,x1,y1,x2,y2; - char loc[20]; - static char xstr[6],ystr[6]; - - ListSize = 0; - - bw = 2*target.border_w; - width = target.frame_w - bw; - height = target.frame_h - target.title_h - bw; - - sprintf(desktop, "%ld", target.desktop); - sprintf(id, "0x%x", (unsigned int)target.id); - sprintf(swidth, "%d", width); - sprintf(sheight, "%d", height); - sprintf(borderw, "%ld", target.border_w); - sprintf(xstr, "%ld", target.frame_x); - sprintf(ystr, "%ld", target.frame_y); - - AddToList("Name:", target.name); - AddToList("Icon Name:", target.icon_name); - AddToList("Class:", target.class); - AddToList("Resource:", target.res); - AddToList("Window ID:", id); - AddToList("Desk:", desktop); - AddToList("Width:", swidth); - AddToList("Height:", sheight); - AddToList("X (current page):", xstr); - AddToList("Y (current page):", ystr); - AddToList("Boundary Width:", borderw); - AddToList("Sticky:", (target.flags & STICKY ? YES : NO)); - AddToList("Ontop:", (target.flags & ONTOP ? YES : NO)); - AddToList("NoTitle:", (target.flags & TITLE ? NO : YES)); - AddToList("Iconified:", (target.flags & ICONIFIED ? YES : NO)); - AddToList("Transient:", (target.flags & TRANSIENT ? YES : NO)); - - switch(target.gravity) - { - case ForgetGravity: - AddToList("Gravity:", "Forget"); - break; - case NorthWestGravity: - AddToList("Gravity:", "NorthWest"); - break; - case NorthGravity: - AddToList("Gravity:", "North"); - break; - case NorthEastGravity: - AddToList("Gravity:", "NorthEast"); - break; - case WestGravity: - AddToList("Gravity:", "West"); - break; - case CenterGravity: - AddToList("Gravity:", "Center"); - break; - case EastGravity: - AddToList("Gravity:", "East"); - break; - case SouthWestGravity: - AddToList("Gravity:", "SouthWest"); - break; - case SouthGravity: - AddToList("Gravity:", "South"); - break; - case SouthEastGravity: - AddToList("Gravity:", "SouthEast"); - break; - case StaticGravity: - AddToList("Gravity:", "Static"); - break; - default: - AddToList("Gravity:", "Unknown"); - break; - } - x1 = target.frame_x; - if(x1 < 0) - x1 = 0; - x2 = ScreenWidth - x1 - target.frame_w; - if(x2 < 0) - x2 = 0; - y1 = target.frame_y; - if(y1 < 0) - y1 = 0; - y2 = ScreenHeight - y1 - target.frame_h; - if(y2 < 0) - y2 = 0; - width = (width - target.base_w)/target.width_inc; - height = (height - target.base_h)/target.height_inc; - - sprintf(loc,"%dx%d",width,height); - strcpy(geometry, loc); - - if ((target.gravity == EastGravity) ||(target.gravity == NorthEastGravity)|| - (target.gravity == SouthEastGravity)) - sprintf(loc,"-%d",x2); - else - sprintf(loc,"+%d",x1); - strcat(geometry, loc); - - if((target.gravity == SouthGravity)||(target.gravity == SouthEastGravity)|| - (target.gravity == SouthWestGravity)) - sprintf(loc,"-%d",y2); - else - sprintf(loc,"+%d",y1); - strcat(geometry, loc); - AddToList("Geometry:", geometry); - -#if 0 - { - char tmp[20], *foo; - sprintf(tmp,"%d", target.base_w); - foo = strdup(tmp); - AddToList(" - base_w:", foo); - sprintf(tmp,"%d", target.width_inc); - foo = strdup(tmp); - AddToList(" - width_inc:", foo); - sprintf(tmp,"%d", target.base_h); - foo = strdup(tmp); - AddToList(" - base_h:", foo); - sprintf(tmp,"%d", target.height_inc); - foo = strdup(tmp); - AddToList(" - height_inc:", foo); - } -#endif + int bw, width, height, x1, y1, x2, y2; + char loc[20]; + static char xstr[6], ystr[6]; + + ListSize = 0; + + bw = 2 * target.border_w; + width = target.frame_w - bw; + height = target.frame_h - target.title_h - bw; + + snprintf(desktop, sizeof(desktop), "%ld", target.desktop); + snprintf(id, sizeof(id), "0x%x", (unsigned int)target.id); + snprintf(swidth, sizeof(swidth), "%d", width); + snprintf(sheight, sizeof(sheight), "%d", height); + snprintf(borderw, sizeof(borderw), "%ld", target.border_w); + snprintf(xstr, sizeof(xstr), "%ld", target.frame_x); + snprintf(ystr, sizeof(ystr), "%ld", target.frame_y); + + AddToList("Name:", target.name); + AddToList("Icon Name:", target.icon_name); + AddToList("Class:", target.class); + AddToList("Resource:", target.res); + AddToList("Window ID:", id); + AddToList("Desk:", desktop); + AddToList("Width:", swidth); + AddToList("Height:", sheight); + AddToList("X (current page):", xstr); + AddToList("Y (current page):", ystr); + AddToList("Boundary Width:", borderw); + AddToList("Sticky:", (target.flags & STICKY ? YES : NO)); + AddToList("Ontop:", (target.flags & ONTOP ? YES : NO)); + AddToList("NoTitle:", (target.flags & TITLE ? NO : YES)); + AddToList("Iconified:", (target.flags & ICONIFIED ? YES : NO)); + AddToList("Transient:", (target.flags & TRANSIENT ? YES : NO)); + + switch (target.gravity) { + case ForgetGravity: + AddToList("Gravity:", "Forget"); + break; + case NorthWestGravity: + AddToList("Gravity:", "NorthWest"); + break; + case NorthGravity: + AddToList("Gravity:", "North"); + break; + case NorthEastGravity: + AddToList("Gravity:", "NorthEast"); + break; + case WestGravity: + AddToList("Gravity:", "West"); + break; + case CenterGravity: + AddToList("Gravity:", "Center"); + break; + case EastGravity: + AddToList("Gravity:", "East"); + break; + case SouthWestGravity: + AddToList("Gravity:", "SouthWest"); + break; + case SouthGravity: + AddToList("Gravity:", "South"); + break; + case SouthEastGravity: + AddToList("Gravity:", "SouthEast"); + break; + case StaticGravity: + AddToList("Gravity:", "Static"); + break; + default: + AddToList("Gravity:", "Unknown"); + break; + } + x1 = target.frame_x; + if (x1 < 0) + x1 = 0; + x2 = ScreenWidth - x1 - target.frame_w; + if (x2 < 0) + x2 = 0; + y1 = target.frame_y; + if (y1 < 0) + y1 = 0; + y2 = ScreenHeight - y1 - target.frame_h; + if (y2 < 0) + y2 = 0; + width = (width - target.base_w) / target.width_inc; + height = (height - target.base_h) / target.height_inc; + + snprintf(loc, sizeof(loc), "%dx%d", width, height); + strlcpy(geometry, loc, sizeof(geometry)); + + if ((target.gravity == EastGravity) || + (target.gravity == NorthEastGravity) || + (target.gravity == SouthEastGravity)) + snprintf(loc, sizeof(loc), "-%d", x2); + else + snprintf(loc, sizeof(loc), "+%d", x1); + strlcat(geometry, loc, sizeof(geometry)); + + if ((target.gravity == SouthGravity) || + (target.gravity == SouthEastGravity) || + (target.gravity == SouthWestGravity)) + snprintf(loc, sizeof(loc), "-%d", y2); + else + snprintf(loc, sizeof(loc), "+%d", y1); + strlcat(geometry, loc, sizeof(geometry)); + AddToList("Geometry:", geometry); - { - Atom *protocols = NULL, *ap; - Atom _XA_WM_TAKE_FOCUS = XInternAtom(dpy, "WM_TAKE_FOCUS", False); - XWMHints *wmhintsp = XGetWMHints(dpy,target.id); - int i,n; - Boolean HasTakeFocus=False,InputField=True; - char *focus_policy="",*ifstr="",*tfstr=""; - - if (wmhintsp) - { - InputField=wmhintsp->input; - ifstr=InputField?"True":"False"; - XFree(wmhintsp); - } - else - { - ifstr="XWMHints missing"; - } - if (XGetWMProtocols(dpy,target.id,&protocols,&n)) - { - for (i = 0, ap = protocols; i < n; i++, ap++) - { - if (*ap == (Atom)_XA_WM_TAKE_FOCUS) - HasTakeFocus = True; - } - tfstr=HasTakeFocus?"Present":"Absent"; - XFree(protocols); - } - else - { - tfstr="XGetWMProtocols failed"; - } - if (HasTakeFocus) - { - if (InputField) - { - focus_policy = "Locally Active"; - } - else - { - focus_policy = "Globally Active"; - } - } - else - { - if (InputField) - { - focus_policy = "Passive"; - } - else - { - focus_policy = "No Input"; - } - } - AddToList("Focus Policy:",focus_policy); - AddToList(" - Input Field:",ifstr); - AddToList(" - WM_TAKE_FOCUS:",tfstr); - { - long supplied_return; /* flags, hints that were supplied */ - int getrc; - XSizeHints *size_hints = XAllocSizeHints(); /* the size hints */ - if ((getrc = XGetWMSizeHints(dpy,target.id, /* get size hints */ - size_hints, /* Hints */ - &supplied_return, - XA_WM_ZOOM_HINTS))) { - if (supplied_return & PAspect) { /* if window has a aspect ratio */ - sprintf(mymin_aspect, "%d/%d", size_hints->min_aspect.x, - size_hints->min_aspect.y); - AddToList("Minimum aspect ratio:",mymin_aspect); - sprintf(max_aspect, "%d/%d", size_hints->max_aspect.x, - size_hints->max_aspect.y); - AddToList("Maximum aspect ratio:",max_aspect); - } /* end aspect ratio */ - XFree(size_hints); - } /* end getsizehints worked */ - } - } + { + Atom *protocols = NULL, *ap; + Atom _XA_WM_TAKE_FOCUS = + XInternAtom(dpy, "WM_TAKE_FOCUS", False); + XWMHints *wmhintsp = XGetWMHints(dpy, target.id); + int i, n; + Boolean HasTakeFocus = False, InputField = True; + char *focus_policy = "", *ifstr = "", *tfstr = ""; + + if (wmhintsp) { + InputField = wmhintsp->input; + ifstr = InputField ? "True" : "False"; + XFree(wmhintsp); + } else { + ifstr = "XWMHints missing"; + } + if (XGetWMProtocols(dpy, target.id, &protocols, &n)) { + for (i = 0, ap = protocols; i < n; i++, ap++) { + if (*ap == (Atom)_XA_WM_TAKE_FOCUS) + HasTakeFocus = True; + } + tfstr = HasTakeFocus ? "Present" : "Absent"; + XFree(protocols); + } else { + tfstr = "XGetWMProtocols failed"; + } + if (HasTakeFocus) { + if (InputField) { + focus_policy = "Locally Active"; + } else { + focus_policy = "Globally Active"; + } + } else { + if (InputField) { + focus_policy = "Passive"; + } else { + focus_policy = "No Input"; + } + } + AddToList("Focus Policy:", focus_policy); + AddToList(" - Input Field:", ifstr); + AddToList(" - WM_TAKE_FOCUS:", tfstr); + { + long supplied_return; /* flags, hints that were supplied + */ + int getrc; + XSizeHints *size_hints = + XAllocSizeHints(); /* the size hints */ + if ((getrc = XGetWMSizeHints(dpy, + target.id, /* get size hints */ + size_hints, /* Hints */ + &supplied_return, XA_WM_ZOOM_HINTS))) { + if (supplied_return & + PAspect) { /* if window has a aspect ratio + */ + snprintf(mymin_aspect, + sizeof(mymin_aspect), "%d/%d", + size_hints->min_aspect.x, + size_hints->min_aspect.y); + AddToList("Minimum aspect ratio:", + mymin_aspect); + snprintf(max_aspect, sizeof(max_aspect), + "%d/%d", size_hints->max_aspect.x, + size_hints->max_aspect.y); + AddToList("Maximum aspect ratio:", + max_aspect); + } /* end aspect ratio */ + XFree(size_hints); + } /* end getsizehints worked */ + } + } } -void freelist(void) +void +freelist(void) { - struct Item* cur = itemlistRoot, *cur2; - - while(cur != NULL) - { - cur2 = cur; - cur = cur->next; - free(cur2); - } -} + struct Item *cur = itemlistRoot, *cur2; + while (cur != NULL) { + cur2 = cur; + cur = cur->next; + free(cur2); + } +} -void nocolor(char *a, char *b) +void +nocolor(char *a, char *b) { - fprintf(stderr,"FvwmInitBanner: can't %s %s\n", a,b); + fprintf(stderr, "FvwmInitBanner: can't %s %s\n", a, b); } /**************************************************************************** @@ -807,25 +763,18 @@ void nocolor(char *a, char *b) * Loads a single color * ****************************************************************************/ -Pixel GetColor(char *name) +Pixel +GetColor(char *name) { - XColor color; - XWindowAttributes attributes; - - XGetWindowAttributes(dpy,Root,&attributes); - color.pixel = 0; - if (!XParseColor (dpy, attributes.colormap, name, &color)) - { - nocolor("parse",name); - } - else if(!XAllocColor (dpy, attributes.colormap, &color)) - { - nocolor("alloc",name); - } - return color.pixel; + XColor color; + XWindowAttributes attributes; + + XGetWindowAttributes(dpy, Root, &attributes); + color.pixel = 0; + if (!XParseColor(dpy, attributes.colormap, name, &color)) { + nocolor("parse", name); + } else if (!XAllocColor(dpy, attributes.colormap, &color)) { + nocolor("alloc", name); + } + return color.pixel; } - - - - - Index: fvwm/modules/FvwmIdent/FvwmIdent.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIdent/FvwmIdent.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIdent/FvwmIdent.h --- fvwm/modules/FvwmIdent/FvwmIdent.h +++ fvwm/modules/FvwmIdent/FvwmIdent.h @@ -1,50 +1,47 @@ -#include "../../libs/fvwmlib.h" -#define STICKY (1<<2) /* Does window stick to glass? */ -#define ONTOP (1<<1) /* does window stay on top */ -#define BORDER (1<<13) /* Is this decorated with border*/ -#define TITLE (1<<14) /* Is this decorated with title */ -#define ICONIFIED (1<<16) /* is it an icon now? */ -#define TRANSIENT (1<<17) /* is it a transient window? */ -struct target_struct -{ - char res[256]; - char class[256]; - char name[256]; - char icon_name[256]; - unsigned long id; - unsigned long frame; - long frame_x; - long frame_y; - long frame_w; - long frame_h; - long base_w; - long base_h; - long width_inc; - long height_inc; - long desktop; - unsigned long gravity; - unsigned long flags; - long title_h; - long border_w; +#include "../../libs/fvwmlib.h" +#define STICKY (1 << 2) /* Does window stick to glass? */ +#define ONTOP (1 << 1) /* does window stay on top */ +#define BORDER (1 << 13) /* Is this decorated with border*/ +#define TITLE (1 << 14) /* Is this decorated with title */ +#define ICONIFIED (1 << 16) /* is it an icon now? */ +#define TRANSIENT (1 << 17) /* is it a transient window? */ +struct target_struct { + char res[256]; + char class[256]; + char name[256]; + char icon_name[256]; + unsigned long id; + unsigned long frame; + long frame_x; + long frame_y; + long frame_w; + long frame_h; + long base_w; + long base_h; + long width_inc; + long height_inc; + long desktop; + unsigned long gravity; + unsigned long flags; + long title_h; + long border_w; }; -struct Item -{ - char* col1; - char* col2; - struct Item* next; +struct Item { + char *col1; + char *col2; + struct Item *next; }; /************************************************************************* * * Subroutine Prototypes - * + * *************************************************************************/ void Loop(int *fd); -void SendInfo(int *fd,char *message,unsigned long window); -char *safemalloc(int length); +void SendInfo(int *fd, char *message, unsigned long window); void DeadPipe(int nonsense); -void process_message(unsigned long type,unsigned long *body); +void process_message(unsigned long type, unsigned long *body); void GetTargetWindow(Window *app_win); void RedrawWindow(void); void change_window_name(char *str); @@ -62,4 +59,3 @@ void list_icon_name(unsigned long *body); void list_class(unsigned long *body); void list_res_name(unsigned long *body); void list_end(void); - Index: fvwm/modules/FvwmM4/FvwmM4.1 =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmM4/FvwmM4.1,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmM4/FvwmM4.1 --- fvwm/modules/FvwmM4/FvwmM4.1 +++ fvwm/modules/FvwmM4/FvwmM4.1 @@ -14,70 +14,56 @@ .if n .sp 1 .if t .sp .5 .. -.TH FvwmM4 1 12/12/94 2.0 +.TH FVWMM4 1 "December 12, 1994" "2.0" "FVWM Modules" .UC .SH NAME FvwmM4 \- the FVWM M4 pre-processor .SH SYNOPSIS FvwmM4 is spawned by fvwm, so no command line invocation will work. - .SH DESCRIPTION When called, this module will attempt to have M4 pre-process the file specified in its invocation, and then have fvwm read the resulting file. - .SH INVOCATION -FvwmM4 can be invoked by inserting the line 'FvwmM4' in -the .fvwmrc file. It can also be called from a menu or mouse binding. +FvwmM4 can be invoked by inserting the line "FvwmM4" in the .fvwmrc file. +It can also be called from a menu or mouse binding. If the user wants his entire .fvwmrc file pre-processed with FvwmM4, then fvwm should be invoked as: - .EX fvwm2 -cmd "FvwmM4 .fvwmrc" .EE - -Note that the argument to the option "-cmd" should be enclosed -in quotes, and no other quoting should be used. For example, a -typical invocation might be: - +.PP +Note that the argument to the option "-cmd" should be enclosed in quotes, +and no other quoting should be used. For example, a typical invocation might be: .EX fvwm2 -cmd "FvwmM4 -m4-squote { -m4-equote } .fvwmrc" .EE - +.PP Some options can be specified on the command line: .IP -m4-prefix I think this makes all the m4 directives require the prefix "m4_". - .TP -m4opt \fIoption\fP Lets you pass an option to the m4 program. Not really needed as any unknown options will be passed on automatically. - .TP -m4-squote \fIcharacter\fP Lets you change the m4 start-of-quote character to \fIcharacter\fP. - .TP -m4-equote \fIcharacter\fP Lets you change the m4 end-of-quote character to \fIcharacter\fP. - .TP -m4prog \fIname\fP Instead of invoking "m4", fvwm will invoke \fIname\fP. - .TP -outfile \fIfilename\fP Instead of creating a random unique name for the temporary file for the preprocessed rc file, this option will let you specify the name of the temporary file it will create. - .IP -debug -Causes the temporary file create by m4 to -be retained. This file is usually called "/tmp/fvwmrcXXXXXXXXXX" - - +Causes the temporary file create by m4 to be retained. +This file is usually called "/tmp/fvwmrcXXXXXXXXXX". .SH CONFIGURATION OPTIONS FvwmM4 defines some values for use in the pre-processor file: - .IP TWM_TYPE Always set to "fvwm". .IP SERVERHOST @@ -107,7 +93,7 @@ Some distance/pixel measurement for the horizontal direction, I think. .IP Y_RESOLUTION Some distance/pixel measurement for the vertical direction, I think. .IP PLANES -Number of color planes for the X server display +Number of color planes for the X server display. .IP BITS_PER_RGB Number of bits in each rgb triplet. .IP CLASS @@ -122,9 +108,7 @@ configure.h at compile time. .IP FVWM_MODULEDIR The directory where fvwm looks for .fvwmrc and modules by default, as determined at compile time. - .SH EXAMPLE PROLOG - .EX define(TWM_TYPE,``fvwm'')dnl define(SERVERHOST,``spx20'')dnl @@ -149,7 +133,6 @@ define(FVWM_VERSION,``1.24l'')dnl define(OPTIONS,``SHAPE XPM M4 '')dnl define(FVWM_MODULEDIR,``/local/homes/dsp/nation/modules'')dnl .EE - .SH AUTHOR FvwmM4 is the result of a random bit mutation on a hard disk, -presumably a result of a cosmic-ray or some such thing. +presumably a result of a cosmic-ray or some such thing. Index: fvwm/modules/FvwmM4/FvwmM4.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmM4/FvwmM4.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmM4/FvwmM4.c --- fvwm/modules/FvwmM4/FvwmM4.c +++ fvwm/modules/FvwmM4/FvwmM4.c @@ -3,43 +3,43 @@ * by Robert Nation * * Copyright 1994, Robert Nation - * No guarantees or warantees or anything + * No guarantees or warantees or anything * are provided or implied in any way whatsoever. Use this program at your * own risk. Permission to use this program for any purpose is given, * as long as the copyright is kept intact. */ #define TRUE 1 -#define FALSE 0 +#define FALSE 0 -#include "config.h" +#include "FvwmM4.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include -#include #include -#include +#include +#include +#include +#include +#include +#include +#include #include -#include #include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "../../fvwm/module.h" - -#include "FvwmM4.h" #include "../../libs/fvwmlib.h" -#include -#include +#include "config.h" +#include "../../fvwm/fvwm_sandbox.h" #define Resolution(pixels, mm) ((((pixels) * 100000 / (mm)) + 50) / 100) char *MyName; @@ -49,20 +49,21 @@ int ScreenWidth, ScreenHeight; int Mscreen; long Vx, Vy; -static char *MkDef(char *name, char *def); -static char *MkNum(char *name,int def); -static char *m4_defs(Display *display, const char *host, char *m4_options, char *config_file); +static char *MkDef(const char *name, const char *def); +static char *MkNum(const char *name, int def); +static char *m4_defs( + Display *display, const char *host, char *m4_options, char *config_file); #define MAXHOSTNAME 255 #define EXTRA 50 -int m4_enable; /* use m4? */ -int m4_prefix; /* Do GNU m4 prefixing (-P) */ -char m4_options[BUFSIZ]; /* Command line options to m4 */ -char m4_outfile[BUFSIZ] = ""; /* The output filename for m4 */ -char *m4_prog = "m4"; /* Name of the m4 program */ -int m4_default_quotes; /* Use default m4 quotes */ -char *m4_startquote = "`"; /* Left quote characters for m4 */ -char *m4_endquote = "'"; /* Right quote characters for m4 */ +int m4_enable; /* use m4? */ +int m4_prefix; /* Do GNU m4 prefixing (-P) */ +char m4_options[BUFSIZ]; /* Command line options to m4 */ +char m4_outfile[BUFSIZ] = ""; /* The output filename for m4 */ +char *m4_prog = "m4"; /* Name of the m4 program */ +int m4_default_quotes; /* Use default m4 quotes */ +char *m4_startquote = "`"; /* Left quote characters for m4 */ +char *m4_endquote = "'"; /* Right quote characters for m4 */ /*********************************************************************** * @@ -71,323 +72,303 @@ char *m4_endquote = "'"; /* Right quote characters for m4 */ * main - start of module * ***********************************************************************/ -int main(int argc, char **argv) +int +main(int argc, char **argv) { - Display *dpy; /* which display are we talking to */ - char *temp, *s; - char *display_name = NULL; - char *filename = NULL; - char *tmp_file, read_string[80],delete_string[80]; - int i,m4_debug = 0; - - m4_enable = TRUE; - m4_prefix = FALSE; - strcpy(m4_options,""); - m4_default_quotes = 1; - - /* Record the program name for error messages */ - temp = argv[0]; - - s=strrchr(argv[0], '/'); - if (s != NULL) - temp = s + 1; - - MyName = safemalloc(strlen(temp)+2); - strcpy(MyName,"*"); - strcat(MyName, temp); - - if(argc < 6) - { - fprintf(stderr,"%s Version %s should only be executed by fvwm!\n",MyName, - VERSION); - fprintf(stderr,"Wanted argc == 6. Got %d\n",argc); - exit(1); - } - - /* Open the X display */ - if (!(dpy = XOpenDisplay(display_name))) - { - fprintf(stderr,"%s: can't open display %s", MyName, - XDisplayName(display_name)); - exit (1); - } - - - Mscreen= DefaultScreen(dpy); - ScreenHeight = DisplayHeight(dpy,Mscreen); - ScreenWidth = DisplayWidth(dpy,Mscreen); - - /* We should exit if our fvwm pipes die */ - signal (SIGPIPE, DeadPipe); - - fd[0] = atoi(argv[1]); - fd[1] = atoi(argv[2]); - - for(i=6;i %s\n", m4_prog, m4_options, + tmp_name); + else + snprintf(options, sizeof(options), "%s %s > %s\n", m4_prog, + m4_options, tmp_name); + tmpf = popen(options, "w"); + if (tmpf == NULL) { + perror("Cannot open pipe to m4"); + exit(0377); + } + gethostname(client, MAXHOSTNAME); -static char *m4_defs(Display *display, const char *host, char *m4_options, char *config_file) -{ - Screen *screen; - Visual *visual; - char client[MAXHOSTNAME], server[MAXHOSTNAME], *colon; - char ostype[BUFSIZ]; - char options[BUFSIZ]; - static char tmp_name[BUFSIZ]; - struct hostent *hostname; - char *vc; /* Visual Class */ - FILE *tmpf; - int fd; - struct passwd *pwent; - /* Generate a temporary filename. Honor the TMPDIR environment variable, - if set. Hope nobody deletes this file! */ - - if (strlen(m4_outfile) == 0) { - if ((vc=getenv("TMPDIR"))) { - strlcpy(tmp_name, vc, sizeof(tmp_name)); - } else { - strlcpy(tmp_name, "/tmp",sizeof(tmp_name)); - } - strlcat(tmp_name, "/fvwmrcXXXXXXXXXX",sizeof(tmp_name)); - mktemp(tmp_name); - } else { - strlcpy(tmp_name,m4_outfile,sizeof(tmp_name)); - } - - if (*tmp_name == '\0') - { - perror("mktemp failed in m4_defs"); - exit(0377); - } - - /* - ** check to make sure it doesn't exist already, to prevent security hole - */ - if ((fd = open(tmp_name, O_WRONLY|O_EXCL|O_CREAT, 0600)) < 0) - { - perror("exclusive open for output file failed in m4_defs"); - exit(0377); - } - close(fd); - - /* - * Create the appropriate command line to run m4, and - * open a pipe to the command. - */ - - if(m4_prefix) - sprintf(options, "%s --prefix-builtins %s > %s\n", - m4_prog, - m4_options, tmp_name); - else - sprintf(options, "%s %s > %s\n", - m4_prog, - m4_options, tmp_name); - tmpf = popen(options, "w"); - if (tmpf == NULL) { - perror("Cannot open pipe to m4"); - exit(0377); - } - - gethostname(client,MAXHOSTNAME); - - getostype (ostype, sizeof ostype); - - /* Change the quoting characters, if specified */ - - if (!m4_default_quotes) - { - fprintf(tmpf, "%schangequote(%s, %s)%sdnl\n", - (m4_prefix) ? "m4_" : "", - m4_startquote, m4_endquote, - (m4_prefix) ? "m4_" : ""); - } - - hostname = gethostbyname(client); - strlcpy(server, XDisplayName(host),sizeof(server)); - colon = strchr(server, ':'); - if (colon != NULL) *colon = '\0'; - if ((server[0] == '\0') || (!strcmp(server, "unix"))) - strlcpy(server, client, sizeof(server)); /* must be connected to :0 or unix:0 */ - - /* TWM_TYPE is fvwm, for completeness */ - - fputs(MkDef("TWM_TYPE", "fvwm"), tmpf); - - /* The machine running the X server */ - fputs(MkDef("SERVERHOST", server), tmpf); - /* The machine running the window manager process */ - fputs(MkDef("CLIENTHOST", client), tmpf); - if (hostname) - fputs(MkDef("HOSTNAME", (char *)hostname->h_name), tmpf); - else - fputs(MkDef("HOSTNAME", (char *)client), tmpf); - - fputs(MkDef("OSTYPE", ostype), tmpf); - - pwent=getpwuid(geteuid()); - fputs(MkDef("USER", pwent->pw_name), tmpf); - - fputs(MkDef("HOME", getenv("HOME")), tmpf); - fputs(MkNum("VERSION", ProtocolVersion(display)), tmpf); - fputs(MkNum("REVISION", ProtocolRevision(display)), tmpf); - fputs(MkDef("VENDOR", ServerVendor(display)), tmpf); - fputs(MkNum("RELEASE", VendorRelease(display)), tmpf); - screen = ScreenOfDisplay(display, Mscreen); - visual = DefaultVisualOfScreen(screen); - fputs(MkNum("WIDTH", DisplayWidth(display,Mscreen)), tmpf); - fputs(MkNum("HEIGHT", DisplayHeight(display,Mscreen)), tmpf); - - fputs(MkNum("X_RESOLUTION",Resolution(screen->width,screen->mwidth)),tmpf); - fputs(MkNum("Y_RESOLUTION",Resolution(screen->height,screen->mheight)),tmpf); - fputs(MkNum("PLANES",DisplayPlanes(display, Mscreen)), tmpf); - - fputs(MkNum("BITS_PER_RGB", visual->bits_per_rgb), tmpf); - fputs(MkNum("SCREEN", Mscreen), tmpf); - - switch(visual->class) - { - case(StaticGray): - vc = "StaticGray"; - break; - case(GrayScale): - vc = "GrayScale"; - break; - case(StaticColor): - vc = "StaticColor"; - break; - case(PseudoColor): - vc = "PseudoColor"; - break; - case(TrueColor): - vc = "TrueColor"; - break; - case(DirectColor): - vc = "DirectColor"; - break; - default: - vc = "NonStandard"; - break; - } - - fputs(MkDef("CLASS", vc), tmpf); - if (visual->class != StaticGray && visual->class != GrayScale) - fputs(MkDef("COLOR", "Yes"), tmpf); - else - fputs(MkDef("COLOR", "No"), tmpf); - fputs(MkDef("FVWM_VERSION", VERSION), tmpf); - - /* Add options together */ - *options = '\0'; -#ifdef SHAPE - strcat(options, "SHAPE "); -#endif -#ifdef XPM - strcat(options, "XPM "); -#endif + getostype(ostype, sizeof ostype); - strcat(options, "M4 "); + /* Change the quoting characters, if specified */ -#ifdef NO_SAVEUNDERS - strcat(options, "NO_SAVEUNDERS "); -#endif + if (!m4_default_quotes) { + fprintf(tmpf, "%schangequote(%s, %s)%sdnl\n", + (m4_prefix) ? "m4_" : "", m4_startquote, m4_endquote, + (m4_prefix) ? "m4_" : ""); + } - fputs(MkDef("OPTIONS", options), tmpf); + hostname = gethostbyname(client); + strlcpy(server, XDisplayName(host), sizeof(server)); + colon = strchr(server, ':'); + if (colon != NULL) + *colon = '\0'; + if ((server[0] == '\0') || (!strcmp(server, "unix"))) + strlcpy(server, client, + sizeof(server)); /* must be connected to :0 or unix:0 */ + + /* TWM_TYPE is fvwm, for completeness */ + + fputs(MkDef("TWM_TYPE", "fvwm"), tmpf); + + /* The machine running the X server */ + fputs(MkDef("SERVERHOST", server), tmpf); + /* The machine running the window manager process */ + fputs(MkDef("CLIENTHOST", client), tmpf); + if (hostname) + fputs(MkDef("HOSTNAME", (char *)hostname->h_name), tmpf); + else + fputs(MkDef("HOSTNAME", (char *)client), tmpf); + + fputs(MkDef("OSTYPE", ostype), tmpf); + + pwent = getpwuid(geteuid()); + fputs(MkDef("USER", pwent->pw_name), tmpf); + + fputs(MkDef("HOME", getenv("HOME")), tmpf); + fputs(MkNum("VERSION", ProtocolVersion(display)), tmpf); + fputs(MkNum("REVISION", ProtocolRevision(display)), tmpf); + fputs(MkDef("VENDOR", ServerVendor(display)), tmpf); + fputs(MkNum("RELEASE", VendorRelease(display)), tmpf); + screen = ScreenOfDisplay(display, Mscreen); + visual = DefaultVisualOfScreen(screen); + fputs(MkNum("WIDTH", DisplayWidth(display, Mscreen)), tmpf); + fputs(MkNum("HEIGHT", DisplayHeight(display, Mscreen)), tmpf); + + fputs(MkNum("X_RESOLUTION", Resolution(screen->width, screen->mwidth)), + tmpf); + fputs( + MkNum("Y_RESOLUTION", Resolution(screen->height, screen->mheight)), + tmpf); + fputs(MkNum("PLANES", DisplayPlanes(display, Mscreen)), tmpf); + + fputs(MkNum("BITS_PER_RGB", visual->bits_per_rgb), tmpf); + fputs(MkNum("SCREEN", Mscreen), tmpf); + + switch (visual->class) { + case (StaticGray): + vc = "StaticGray"; + break; + case (GrayScale): + vc = "GrayScale"; + break; + case (StaticColor): + vc = "StaticColor"; + break; + case (PseudoColor): + vc = "PseudoColor"; + break; + case (TrueColor): + vc = "TrueColor"; + break; + case (DirectColor): + vc = "DirectColor"; + break; + default: + vc = "NonStandard"; + break; + } - fputs(MkDef("FVWM_MODULEDIR", FVWM_MODULEDIR), tmpf); - fputs(MkDef("FVWM_CONFIGDIR", FVWM_CONFIGDIR), tmpf); + fputs(MkDef("CLASS", vc), tmpf); + if (visual->class != StaticGray && visual->class != GrayScale) + fputs(MkDef("COLOR", "Yes"), tmpf); + else + fputs(MkDef("COLOR", "No"), tmpf); + fputs(MkDef("FVWM_VERSION", VERSION), tmpf); + + /* Add options together */ + options[0] = '\0'; +#ifdef SHAPE + strlcat(options, "SHAPE ", sizeof(options)); +#endif +#ifdef XPM + strlcat(options, "XPM ", sizeof(options)); +#endif - /* - * At this point, we've sent the definitions to m4. Just include - * the fvwmrc file now. - */ + strlcat(options, "M4 ", sizeof(options)); - fprintf(tmpf, "%sinclude(%s%s%s)\n", - (m4_prefix) ? "m4_": "", - m4_startquote, - config_file, - m4_endquote); +#ifdef NO_SAVEUNDERS + strlcat(options, "NO_SAVEUNDERS ", sizeof(options)); +#endif - pclose(tmpf); - return(tmp_name); -} + fputs(MkDef("OPTIONS", options), tmpf); + fputs(MkDef("FVWM_MODULEDIR", FVWM_MODULEDIR), tmpf); + fputs(MkDef("FVWM_CONFIGDIR", FVWM_CONFIGDIR), tmpf); + /* + * At this point, we've sent the definitions to m4. Just include + * the fvwmrc file now. + */ + fprintf(tmpf, "%sinclude(%s%s%s)\n", (m4_prefix) ? "m4_" : "", + m4_startquote, config_file, m4_endquote); + pclose(tmpf); + return (tmp_name); +} /*********************************************************************** * @@ -395,77 +376,56 @@ static char *m4_defs(Display *display, const char *host, char *m4_options, char * SIGPIPE handler - SIGPIPE means fvwm is dying * ***********************************************************************/ -void DeadPipe(int nonsense) +void +DeadPipe(int nonsense) { - exit(0); + exit(0); } - - -static char *MkDef(char *name, char *def) +static char * +MkDef(const char *name, const char *def) { - static char *cp = NULL; - static int maxsize = 0; - int n; - - /* The char * storage only lasts for 1 call... */ - - /* Get space to hold everything, if needed */ - - n = EXTRA + strlen(name) + strlen(def); - if (n > maxsize) { - maxsize = n; - if (cp == NULL) { - cp = malloc(n); - } else { - cp = realloc(cp, n); + static char *cp = NULL; + static int maxsize = 0; + int needed; + const char *prefix = m4_prefix ? "m4_define" : "define"; + const char *suffix = m4_prefix ? "m4_" : ""; + + needed = snprintf(NULL, 0, "%s(%s,%s%s%s%s%s)%sdnl\n", prefix, name, + m4_startquote, m4_startquote, def, m4_endquote, m4_endquote, + suffix); + if (needed < 0) { + perror("MkDef failed to calculate length"); + exit(0377); + } + needed += 1; /* account for terminating null */ + if (needed > maxsize) { + char *tmp = realloc(cp, needed); + if (tmp == NULL) { + perror("MkDef can't allocate enough space for a macro " + "definition"); + free(cp); + exit(0377); + } + cp = tmp; + maxsize = needed; } - } - - if (cp == NULL) { - perror("MkDef can't allocate enough space for a macro definition"); - exit(0377); - } - - /* Create the macro definition, using the appropriate prefix, if any */ - - if (m4_prefix) - { - strcpy(cp, "m4_define("); - } - else - strcpy(cp, "define("); - - strcat(cp, name); - - /* Tack on "," and 2 sets of starting quotes */ - strcat(cp, ","); - strcat(cp, m4_startquote); - strcat(cp, m4_startquote); - - /* The definition itself */ - strcat(cp, def); - - /* Add 2 sets of closing quotes */ - strcat(cp, m4_endquote); - strcat(cp, m4_endquote); - - /* End the definition, appropriately */ - strcat(cp, ")"); - if (m4_prefix) - { - strcat(cp, "m4_"); - } - strcat(cp, "dnl\n"); + if (snprintf(cp, maxsize, "%s(%s,%s%s%s%s%s)%sdnl\n", prefix, name, + m4_startquote, m4_startquote, def, m4_endquote, m4_endquote, + suffix) < 0) { + perror("MkDef failed to build macro definition"); + exit(0377); + } - return(cp); + return (cp); } -static char *MkNum(char *name,int def) +static char * +MkNum(const char *name, int def) { - char num[20]; + char num[20]; - sprintf(num, "%d", def); - return(MkDef(name, num)); + snprintf(num, sizeof(num), "%d", def); + return (MkDef(name, num)); } Index: fvwm/modules/FvwmM4/FvwmM4.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmM4/FvwmM4.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmM4/FvwmM4.h --- fvwm/modules/FvwmM4/FvwmM4.h +++ fvwm/modules/FvwmM4/FvwmM4.h @@ -3,10 +3,6 @@ /************************************************************************* * * Subroutine Prototypes - * + * *************************************************************************/ void DeadPipe(int nonsense); - - - - Index: fvwm/modules/FvwmPager/FvwmPager.1 =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmPager/FvwmPager.1,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmPager/FvwmPager.1 --- fvwm/modules/FvwmPager/FvwmPager.1 +++ fvwm/modules/FvwmPager/FvwmPager.1 @@ -1,25 +1,28 @@ .\" $OpenBSD: FvwmPager.1,v 1.1.1.1 2006/11/26 10:53:52 matthieu Exp $ .\" t -.\" @(#)FvwmPager.1 1/12/94 -.TH FvwmPager 1 "Mar 16 1994" 1.20 +.\" @(#)FvwmPager.1 1/12/94 +.TH FVWMPAGER 1 "March 16, 1994" "1.20" "FVWM Modules" .UC .SH NAME FvwmPager \- the FVWM Pager module .SH SYNOPSIS FvwmPager is spawned by fvwm, so no command line invocation will work. +.PP From within the .fvwmrc file, FvwmPager is spawned as follows: .nf .sp Module FvwmPager 0 3 .sp .fi -or +.PP +Alternatively: .nf .sp Module FvwmPager * * .sp .fi -or from within an fvwm pop-up menu: +.PP +From within an fvwm pop-up menu: .nf .sp AddToMenu Module-Popup "Modules" Title @@ -31,47 +34,45 @@ AddToMenu Module-Popup "Modules" Title + "Pager" Module FvwmPager 0 3 .sp .fi -or +.PP +Alternatively: .nf .sp + "Pager" Module FvwmPager * * .sp .fi -where "0" is the first desktop to show, and "3" is the last and -"*" is the current dektop. In the second format (with two asterisks) -the current desk is always visible in the pager (and it is also the -only one). - +.PP +Here, "0" is the first desktop to show, and "3" is the last and "*" +is the current dektop. In the second format (with two asterisks) the +current desk is always visible in the pager (and it is also the only one). .SH DESCRIPTION The FvwmPager module shows a miniature view of the Fvwm desktops which are specified in the command line. This is a useful reminder of where your active windows are. Windows in the pager are shown in the same -color as their fvwm decorations. - -The pager can be used to change your viewport into the current -desktop, to change desktops, or to move windows around. - -Pressing mouse button 1 in the pager will cause you viewport to -change to the selected page of the selected desk. If you click with -button 1 in the desk-label area, you will switch desks but not -pages within the desk. - -Dragging mouse button 2 on a miniature view of a window will cause -that window to be move to the location where you release the mouse -button, but your viewport will not change. If you drag the window -out of the pager and onto your desktop, a full size image of -the window will appear for you to place. There is no way to -pick up a full size image of the window and move it into the pager, -however. Since some mice do not have button 2, I have made provisions to drag -windows in the pager by using pressing modifier-1 (usually Alt) and dragging -with button 3. - -Clicking mouse button 3 on a location will cause the viewport to move -to the selected location and switch desks if necessary, but will not -align the viewport to a page boundary. Dragging button 3 will -cause the viewport to move as you drag but not switch desktops, even -if the pointer moves to another desktop. - +color as their fvwm decorations. +.PP +The pager can be used to change your viewport into the current desktop, +to change desktops, or to move windows around. +.PP +Pressing mouse button 1 in the pager will cause you viewport to change +to the selected page of the selected desk. If you click with button 1 in +the desk-label area, you will switch desks but not pages within the desk. +.PP +Dragging mouse button 2 on a miniature view of a window will cause that +window to be move to the location where you release the mouse button, +but your viewport will not change. If you drag the window out of the +pager and onto your desktop, a full size image of the window will appear +for you to place. There is no way to pick up a full size image of the +window and move it into the pager, however. Since some mice do not have +button 2, I have made provisions to drag windows in the pager by pressing +modifier-1 (usually Alt) and dragging with button 3. +.PP +Clicking mouse button 3 on a location will cause the viewport to move to +the selected location and switch desks if necessary, but will not align +the viewport to a page boundary. Dragging button 3 will cause the +viewport to move as you drag but not switch desktops, even if the pointer +moves to another desktop. +.PP When iconified, the pager will work as a fully functional current page only pager. Windows and viewports can be moved within the icon of the pager. Users will want to make sure that they have no lines similar to @@ -81,92 +82,71 @@ Icon "Fvwm Pager" whatever .sp .fi in their .fvwmrc files. - - .SH COPYRIGHTS -The FvwmPager program, and the concept for -interfacing this module to the Window Manager, are all original work -by Robert Nation. - -Copyright 1994, Robert Nation. No guarantees or warranties or anything -are provided or implied in any way whatsoever. Use this program at your -own risk. Permission to use this program for any purpose is given, -as long as the copyright is kept intact. - - +The FvwmPager program, and the concept for interfacing this module to the +Window Manager, are original work by Robert Nation. +.PP +Copyright 1994, Robert Nation. No guarantees or warranties or anything are +provided or implied in any way whatsoever. Use this program at your own risk. +Permission to use this program for any purpose is given, as long as the +copyright is kept intact. .SH INITIALIZATION -During initialization, \fIFvwmPager\fP will eventually search a -configuration file which describes the time-outs and actions to take. -The configuration file is the same file that fvwm used during initialization. - -If the FvwmPager executable is linked to another name, ie ln -s -FvwmPager OtherPager, then another module called OtherPager can be -started, with a completely different configuration than FvwmPager, -simply by changing the keyword FvwmPager to OtherPager. This way multiple -pager programs can be used. - +During initialization, \fIFvwmPager\fP will eventually search a configuration +file which describes the time-outs and actions to take. The configuration file +is the same file that fvwm used during initialization. +.PP +If the FvwmPager executable is linked to another name, ie ln -s FvwmPager +OtherPager, then another module called OtherPager can be started, with a +completely different configuration than FvwmPager, simply by changing the +keyword FvwmPager to OtherPager. This way multiple pager programs can be used. .SH KEYBOARD FOCUS CONTROL -You can direct the keyboard focus to any window on the current desktop -by clicking with button 2 on its image in the pager. The window does -not need to be visible, but it does need to be on the current page. - +You can direct the keyboard focus to any window on the current desktop by +clicking with button 2 on its image in the pager. The window does not need to +be visible, but it does need to be on the current page. .SH INVOCATION -The invocation method was shown in the synopsis section - +The invocation method was shown in the synopsis section. .SH CONFIGURATION OPTIONS -FvwmPager reads the same .fvwmrc file as fvwm reads when it starts up, -and looks for certain configuration options: - +FvwmPager reads the same .fvwmrc file as fvwm reads when it starts up, and +looks for certain configuration options: .IP "*FvwmPagerGeometry \fIgeometry\fP" Completely or partially specifies the pager windows location and -geometry, in standard X11 notation. +geometry, in standard X11 notation. In order to maintain an undistorted aspect ratio, you might want to leave out either the width or height dimension of the geometry specification - .IP "*FvwmPagerRows \fIrows\fP" Tells fvwm how many rows of desks to use when laying out the pager window. - .IP "*FvwmPagerColumns \fIcolumns\fP" Tells fvwm how many columnss of desks to use when laying out the pager window. - .IP "*FvwmPagerIconGeometry \fIgeometry\fP" -Specifies a size (optional) and location (optional) for the pager's icon +Specifies a size (optional) and location (optional) for the pager's icon window. Since there is no easy way for FvwmPager to determine the height of the icon's label, you will have to make an allowance for the icon label height when using negative y-coordinates in the icon location specification (used to specify a location relative to the bottom instead of the top of the screen). - .IP "*FvwmPagerStartIconic" -Causes the pager to start iconified. - +Causes the pager to start iconified. .IP "*FvwmPagerNoStartIconic" Causes the pager to start normally. Useful for cancelling the effect of the \fIStartIconic\fP option. - .IP "*FvwmPagerFont \fIfont-name\fP" Specified a font to use to label the desktops. If \fIfont_name\fP is "none" then no desktop labels will be displayed. - .IP "*FvwmPagerSmallFont \fIfont-name\fP" Specified a font to use to label the window names in the pager. If not specified, the window labels will be omitted. Window labels seem to be fairly useless for desktop scales of 32 or greater. If \fIfont_name\fP is "none" then no window names will be displayed. - .IP "*FvwmPagerFore \fIcolor\fP" Specifies the color to use to write the desktop labels, and to draw the page-grid lines. - .IP "*FvwmPagerBack \fIcolor\fP" Specifies the background color for the window. - .IP "*FvwmPagerHilight \fIcolor\fP" The active page and desk label will be highlighted by using this background pattern instead of the normal background. - .IP "*FvwmPagerWindowColors \fIfore back hiFore hiBack\fP" Change the normal/highlight colors of the windows. \fIfore\fP and \fIhiFore\fP specify the colors as used for the font inside the windows. @@ -182,26 +162,22 @@ to desktops, i.e. *FvwmPagerLabel * Matlab .sp .fi - .IP "*FvwmPagerDeskColor \fIdesk color\fP" Assigns the color \fIcolor\fP to desk \fIdesk\fP (or the current desk if desk is "*") in the pager window. This replaces the background color for -the particular \fIdesk\fP. This only works when the pager is full sized. -When Iconified, the pager uses the color specified by *FvwmPagerBack. +the particular \fIdesk\fP. This only works when the pager is full sized. +When iconified, the pager uses the color specified by *FvwmPagerBack. .sp -\fBTIP:\fP Try using *FvwmPagerDeskColor in conjunction with +\fBTIP:\fP Try using *FvwmPagerDeskColor in conjunction with FvwmCpp (or FvwmM4) and FvwmBacker to assign identical colors to your various desktops and the pager representations. - .IP "*FvwmPagerDeskTopScale \fInumber\fP" If the geometry is not specified, then a desktop reduction factor is used to calculate the pager's size. Things in the pager window are shown at 1/\fInumber\fP of the actual size. - .IP "*FvwmPagerMiniIcons" Allow the pager to display a window's mini icon in the pager, if it has one, instead of showing the window's name. - .IP "*FvwmPagerBalloons [\fItype\fP]" Show a balloon describing the window when the pointer is moved into a window in the pager. Currently only the window's icon name is shown. @@ -209,24 +185,18 @@ If \fItype\fP is \fIPager\fP balloons are just shown for an uniconified pager; if \fItype\fP is \fIIcon\fP balloons are just shown for an iconified pager. If \fItype\fP is anything else (or null) balloons are always shown. - .IP "*FvwmPagerBalloonFore \fIcolor\fP" Specifies the color for text in the balloon window. If omitted it defaults to the foreground color for the window being described. - .IP "*FvwmPagerBalloonBack \fIcolor\fP" Specifies the background color for the balloon window. If omitted it defaults to the background color for the window being described. - .IP "*FvwmPagerBalloonFont \fIfont-name\fP" Specifies a font to use for the balloon text. Defaults to \fIfixed\fP. - .IP "*FvwmPagerBalloonBorderWidth \fInumber\fP" Sets the width of the balloon window's border. Defaults to 1. - .IP "*FvwmPagerBalloonBorderColor \fIcolor\fP" Sets the color of the balloon window's border. Defaults to black. - .IP "*FvwmPagerBalloonYOffset \fInumber\fP" The balloon window is positioned to be horizontally centered against the pager window it is describing. The vertical position may be @@ -236,10 +206,8 @@ pixels above the pager window, positive offsets of \fI+n\fP are placed direct transit from pager window to balloon window, causing an event loop. Defaults to +2. The offset will change sign automatically, as needed, to keep the balloon on the screen. - - .SH AUTHOR -Robert Nation +Robert Nation .br DeskColor patch contributed by Alan Wild .br Index: fvwm/modules/FvwmPager/FvwmPager.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmPager/FvwmPager.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmPager/FvwmPager.c --- fvwm/modules/FvwmPager/FvwmPager.c +++ fvwm/modules/FvwmPager/FvwmPager.c @@ -10,38 +10,37 @@ #define TRUE 1 #define FALSE 0 -#include "config.h" +#include +#include -#include -#include +#include +#include #include +#include +#include #include -#include -#include #include -#include -#include -#ifdef HAVE_SYS_BSDTYPES_H -#include /* Saul */ -#endif /* Saul */ +#include "config.h" +#include "../../fvwm/fvwm_sandbox.h" + +#endif /* Saul */ #include #if HAVE_SYS_SELECT_H #include #endif +#include +#include #include -#include #include -#include -#include +#include +#include "../../fvwm/fvwm.h" #include "../../fvwm/module.h" - #include "../../libs/fvwmlib.h" #include "FvwmPager.h" -#include "../../fvwm/fvwm.h" char *MyName; int fd_width; @@ -59,8 +58,8 @@ ScreenInfo Scr; PagerWindow *Start = NULL; PagerWindow *FocusWin = NULL; -Display *dpy; /* which display are we talking to */ -int x_fd,fd_width; +Display *dpy; /* which display are we talking to */ +int x_fd, fd_width; char *PagerFore = NULL; char *PagerBack = NULL; @@ -81,27 +80,27 @@ char *BalloonBorderColor = NULL; int BalloonBorderWidth = 1; int BalloonYOffset = 2; -int window_w=0, window_h=0, window_x=0, window_y=0; -int icon_x=-10000, icon_y=-10000, icon_w=0, icon_h=0; -int usposition = 0,uselabel = 1; +int window_w = 0, window_h = 0, window_x = 0, window_y = 0; +int icon_x = -10000, icon_y = -10000, icon_w = 0, icon_h = 0; +int usposition = 0, uselabel = 1; int xneg = 0, yneg = 0; extern DeskInfo *Desks; int StartIconic = 0; int MiniIcons = 0; int Rows = -1, Columns = -1; -int desk1=0, desk2 =0; +int desk1 = 0, desk2 = 0; int ndesks = 0; Pixel win_back_pix = -1; Pixel win_fore_pix = -1; Pixel win_hi_back_pix = -1; Pixel win_hi_fore_pix = -1; char fAlwaysCurrentDesk = 0; -PagerStringList string_list = { NULL, 0, NULL, NULL }; +PagerStringList string_list = {NULL, 0, NULL, NULL}; Bool error_occured = False; static volatile sig_atomic_t isTerminated = False; -static RETSIGTYPE TerminateHandler(int); +static void TerminateHandler(int); /*********************************************************************** * @@ -109,167 +108,158 @@ static RETSIGTYPE TerminateHandler(int); * main - start of module * ***********************************************************************/ -int main(int argc, char **argv) +int +main(int argc, char **argv) { - char *temp, *s; - char *display_name = NULL; - int itemp,i; - char line[100]; - - /* Save our program name - for error messages */ - temp = argv[0]; - s=strrchr(argv[0], '/'); - if (s != NULL) - temp = s + 1; - - MyName = safemalloc(strlen(temp)+2); - strcpy(MyName, temp); - - if(argc < 6) - { - fprintf(stderr,"%s Version %s should only be executed by fvwm!\n",MyName, - VERSION); - exit(1); - } - if(argc < 8) - { - fprintf(stderr,"%s Version %s requires two arguments: %s n m\n", - MyName,VERSION,MyName); - fprintf(stderr," where desktops n through m are displayed\n"); - fprintf(stderr, - " if n and m are \"*\" the current desktop is displayed\n"); - exit(1); - } + char *temp, *s; + char *display_name = NULL; + int itemp, i; + char line[100]; + + /* Save our program name - for error messages */ + temp = argv[0]; + s = strrchr(argv[0], '/'); + if (s != NULL) + temp = s + 1; + + { + size_t name_len = strlen(temp) + 1; + MyName = xmalloc(name_len); + strlcpy(MyName, temp, name_len); + } + + if (argc < 6) { + fprintf(stderr, + "%s Version %s should only be executed by fvwm!\n", MyName, + VERSION); + exit(1); + } + if (argc < 8) { + fprintf(stderr, + "%s Version %s requires two arguments: %s n m\n", MyName, + VERSION, MyName); + fprintf( + stderr, " where desktops n through m are displayed\n"); + fprintf(stderr, " if n and m are \"*\" the current desktop " + "is displayed\n"); + exit(1); + } #ifdef HAVE_SIGACTION - { - struct sigaction sigact; - - sigemptyset(&sigact.sa_mask); -# ifdef SA_INTERRUPT - sigact.sa_flags = SA_INTERRUPT; -# else - sigact.sa_flags = 0; -# endif - sigact.sa_handler = TerminateHandler; - - sigaction(SIGPIPE, &sigact, NULL); - sigaction(SIGTERM, &sigact, NULL); - sigaction(SIGQUIT, &sigact, NULL); - sigaction(SIGINT, &sigact, NULL); - sigaction(SIGHUP, &sigact, NULL); - } + { + struct sigaction sigact; + + sigemptyset(&sigact.sa_mask); +#ifdef SA_INTERRUPT + sigact.sa_flags = SA_INTERRUPT; #else - /* We don't have sigaction(), so fall back to less robust methods. */ - signal(SIGPIPE, TerminateHandler); - signal(SIGTERM, TerminateHandler); - signal(SIGQUIT, TerminateHandler); - signal(SIGINT, TerminateHandler); - signal(SIGHUP, TerminateHandler); + sigact.sa_flags = 0; #endif + sigact.sa_handler = TerminateHandler; - fd[0] = atoi(argv[1]); - fd[1] = atoi(argv[2]); - - fd_width = GetFdWidth(); - - desk1 = atoi(argv[6]); - desk2 = atoi(argv[7]); - - if(desk2 < desk1) - { - itemp = desk1; - desk1 = desk2; - desk2 = itemp; - } - ndesks = desk2 - desk1 + 1; - if (StrEquals(argv[6], "*") && StrEquals(argv[7], "*")) - { - desk1 = Scr.CurrentDesk; - desk2 = Scr.CurrentDesk; - fAlwaysCurrentDesk = 1; - } - - PagerFore = strdup("black"); - PagerBack = strdup("white"); - font_string = strdup("fixed"); - HilightC = strdup("black"); - BalloonFont = strdup("fixed"); - BalloonBorderColor = strdup("black"); - Desks = (DeskInfo *)safemalloc(ndesks*sizeof(DeskInfo)); - for(i=0;inext); - t = t->next; - i++; - } - *prev = (PagerWindow *)safemalloc(sizeof(PagerWindow)); - (*prev)->w = body[0]; - (*prev)->t = (char *)body[2]; - (*prev)->frame = body[1]; - (*prev)->x = body[3]; - (*prev)->y = body[4]; - (*prev)->width = body[5]; - (*prev)->height = body[6]; - (*prev)->desk = body[7]; - (*prev)->next = NULL; - (*prev)->flags = body[8]; - (*prev)->pager_view_width = 0; - (*prev)->pager_view_height = 0; - (*prev)->icon_view_width = 0; - (*prev)->icon_view_height = 0; - (*prev)->icon_name = NULL; - (*prev)->mini_icon.picture = 0; - (*prev)->title_height = body[9]; - (*prev)->border_width = body[10]; - (*prev)->icon_w = body[19]; - (*prev)->icon_pixmap_w = body[20]; - if ((win_fore_pix != -1) && (win_back_pix != -1)) - { - (*prev)->text = win_fore_pix; - (*prev)->back = win_back_pix; - } - else - { - (*prev)->text = body[22]; - (*prev)->back = body[23]; - } - AddNewWindow(*prev); + PagerWindow *t, **prev; + int i = 0; + + t = Start; + prev = &Start; + while (t != NULL) { + prev = &(t->next); + t = t->next; + i++; + } + *prev = (PagerWindow *)xmalloc(sizeof(PagerWindow)); + (*prev)->w = body[0]; + (*prev)->t = (char *)body[2]; + (*prev)->frame = body[1]; + (*prev)->x = body[3]; + (*prev)->y = body[4]; + (*prev)->width = body[5]; + (*prev)->height = body[6]; + (*prev)->desk = body[7]; + (*prev)->next = NULL; + (*prev)->flags = body[8]; + (*prev)->pager_view_width = 0; + (*prev)->pager_view_height = 0; + (*prev)->icon_view_width = 0; + (*prev)->icon_view_height = 0; + (*prev)->icon_name = NULL; + (*prev)->mini_icon.picture = 0; + (*prev)->title_height = body[9]; + (*prev)->border_width = body[10]; + (*prev)->icon_w = body[19]; + (*prev)->icon_pixmap_w = body[20]; + if ((win_fore_pix != -1) && (win_back_pix != -1)) { + (*prev)->text = win_fore_pix; + (*prev)->back = win_back_pix; + } else { + (*prev)->text = body[22]; + (*prev)->back = body[23]; + } + AddNewWindow(*prev); } /*********************************************************************** @@ -437,75 +421,62 @@ void list_add(unsigned long *body) * list_configure - displays packet contents to stderr * ***********************************************************************/ -void list_configure(unsigned long *body) +void +list_configure(unsigned long *body) { - PagerWindow *t; - Window target_w; - - target_w = body[0]; - t = Start; - while((t!= NULL)&&(t->w != target_w)) - { - t = t->next; - } - if(t== NULL) - { - list_add(body); - } - else - { - t->t = (char *)body[2]; - t->frame = body[1]; - t->frame_x = body[3]; - t->frame_y = body[4]; - t->frame_width = body[5]; - t->frame_height = body[6]; - t->title_height = body[9]; - t->border_width = body[10]; - t->flags = body[8]; - t->icon_w = body[19]; - t->icon_pixmap_w = body[20]; - if ((win_fore_pix != -1) && (win_back_pix != -1)) - { - t->text = win_fore_pix; - t->back = win_back_pix; - } - else - { - t->text = body[22]; - t->back = body[23]; - } - if(t->flags & ICONIFIED) - { - t->x = t->icon_x; - t->y = t->icon_y; - t->width = t->icon_width; - t->height = t->icon_height; - if(t->flags & SUPPRESSICON) - { - t->x = -10000; - t->y = -10000; - } - } - else - { - t->x = t->frame_x; - t->y = t->frame_y; - t->width = t->frame_width; - t->height = t->frame_height; + PagerWindow *t; + Window target_w; + + target_w = body[0]; + t = Start; + while ((t != NULL) && (t->w != target_w)) { + t = t->next; } - if(t->desk != body[7]) - { - ChangeDeskForWindow(t,body[7]); + if (t == NULL) { + list_add(body); + } else { + t->t = (char *)body[2]; + t->frame = body[1]; + t->frame_x = body[3]; + t->frame_y = body[4]; + t->frame_width = body[5]; + t->frame_height = body[6]; + t->title_height = body[9]; + t->border_width = body[10]; + t->flags = body[8]; + t->icon_w = body[19]; + t->icon_pixmap_w = body[20]; + if ((win_fore_pix != -1) && (win_back_pix != -1)) { + t->text = win_fore_pix; + t->back = win_back_pix; + } else { + t->text = body[22]; + t->back = body[23]; + } + if (t->flags & ICONIFIED) { + t->x = t->icon_x; + t->y = t->icon_y; + t->width = t->icon_width; + t->height = t->icon_height; + if (t->flags & SUPPRESSICON) { + t->x = -10000; + t->y = -10000; + } + } else { + t->x = t->frame_x; + t->y = t->frame_y; + t->width = t->frame_width; + t->height = t->frame_height; + } + if (t->desk != body[7]) { + ChangeDeskForWindow(t, body[7]); + } else + MoveResizePagerView(t); + if (FocusWin == t) + Hilight(t, ON); + else + Hilight(t, OFF); } - - else - MoveResizePagerView(t); - if(FocusWin == t) - Hilight(t,ON); - else - Hilight(t,OFF); - } } /*********************************************************************** @@ -514,32 +485,31 @@ void list_configure(unsigned long *body) * list_destroy - displays packet contents to stderr * ***********************************************************************/ -void list_destroy(unsigned long *body) +void +list_destroy(unsigned long *body) { - PagerWindow *t,**prev; - Window target_w; - - target_w = body[0]; - t = Start; - prev = &Start; - while((t!= NULL)&&(t->w != target_w)) - { - prev = &(t->next); - t = t->next; - } - if(t!= NULL) - { - if(prev != NULL) - *prev = t->next; - /* remove window from the chain */ - if(t->PagerView != None) - XDestroyWindow(dpy,t->PagerView); - XDestroyWindow(dpy,t->IconView); - if(FocusWin == t) - FocusWin = NULL; - - free(t); - } + PagerWindow *t, **prev; + Window target_w; + + target_w = body[0]; + t = Start; + prev = &Start; + while ((t != NULL) && (t->w != target_w)) { + prev = &(t->next); + t = t->next; + } + if (t != NULL) { + if (prev != NULL) + *prev = t->next; + /* remove window from the chain */ + if (t->PagerView != None) + XDestroyWindow(dpy, t->PagerView); + XDestroyWindow(dpy, t->IconView); + if (FocusWin == t) + FocusWin = NULL; + + free(t); + } } /*********************************************************************** @@ -548,38 +518,34 @@ void list_destroy(unsigned long *body) * list_focus - displays packet contents to stderr * ***********************************************************************/ -void list_focus(unsigned long *body) +void +list_focus(unsigned long *body) { - PagerWindow *t,*temp; - Window target_w; - extern Pixel focus_pix, focus_fore_pix; - target_w = body[0]; - - if ((win_hi_fore_pix != -1) && (win_hi_back_pix != -1)) - { - focus_pix = win_hi_back_pix; - focus_fore_pix = win_hi_fore_pix; - } - else - { - focus_pix = body[4]; - focus_fore_pix = body[3]; - } - t = Start; - while((t!= NULL)&&(t->w != target_w)) - { - t = t->next; - } - if(t != FocusWin) - { - temp = FocusWin; - FocusWin = t; - - if(temp != NULL) - Hilight(temp,OFF); - if(FocusWin != NULL) - Hilight(FocusWin,ON); - } + PagerWindow *t, *temp; + Window target_w; + extern Pixel focus_pix, focus_fore_pix; + target_w = body[0]; + + if ((win_hi_fore_pix != -1) && (win_hi_back_pix != -1)) { + focus_pix = win_hi_back_pix; + focus_fore_pix = win_hi_fore_pix; + } else { + focus_pix = body[4]; + focus_fore_pix = body[3]; + } + t = Start; + while ((t != NULL) && (t->w != target_w)) { + t = t->next; + } + if (t != FocusWin) { + temp = FocusWin; + FocusWin = t; + + if (temp != NULL) + Hilight(temp, OFF); + if (FocusWin != NULL) + Hilight(FocusWin, ON); + } } /*********************************************************************** @@ -588,21 +554,21 @@ void list_focus(unsigned long *body) * list_new_page - displays packet contents to stderr * ***********************************************************************/ -void list_new_page(unsigned long *body) +void +list_new_page(unsigned long *body) { - Scr.Vx = (long)body[0]; - Scr.Vy = (long)body[1]; - Scr.CurrentDesk = (long)body[2]; - if((Scr.VxMax != body[3])||(Scr.VyMax != body[4])) - { - Scr.VxMax = body[3]; - Scr.VyMax = body[4]; - ReConfigure(); - } - MovePage(); - MoveStickyWindows(); - Hilight(FocusWin,OFF); - Hilight(FocusWin,ON); + Scr.Vx = (long)body[0]; + Scr.Vy = (long)body[1]; + Scr.CurrentDesk = (long)body[2]; + if ((Scr.VxMax != body[3]) || (Scr.VyMax != body[4])) { + Scr.VxMax = body[3]; + Scr.VyMax = body[4]; + ReConfigure(); + } + MovePage(); + MoveStickyWindows(); + Hilight(FocusWin, OFF); + Hilight(FocusWin, ON); } /*********************************************************************** @@ -611,67 +577,59 @@ void list_new_page(unsigned long *body) * list_new_desk - displays packet contents to stderr * ***********************************************************************/ -void list_new_desk(unsigned long *body) +void +list_new_desk(unsigned long *body) { - int oldDesk; - - oldDesk = Scr.CurrentDesk; - Scr.CurrentDesk = (long)body[0]; - if (fAlwaysCurrentDesk && oldDesk != Scr.CurrentDesk) - { - PagerWindow *t; - PagerStringList *item; - char line[100]; - - desk1 = Scr.CurrentDesk; - desk2 = Scr.CurrentDesk; - for (t = Start; t != NULL; t = t->next) - { - if (t->desk == oldDesk || t->desk == Scr.CurrentDesk) - ChangeDeskForWindow(t, t->desk); - } - item = FindDeskStrings(Scr.CurrentDesk); - if (Desks[0].label != NULL) - { - free(Desks[0].label); - Desks[0].label = NULL; - } - if (item->next != NULL && item->next->label != NULL) - { - CopyString(&Desks[0].label, item->next->label); - } - else - { - sprintf(line, "Desk %d", desk1); - CopyString(&Desks[0].label, line); - } - XStoreName(dpy, Scr.Pager_w, Desks[0].label); - XSetIconName(dpy, Scr.Pager_w, Desks[0].label); - if (Desks[0].Dcolor != NULL) - { - free(Desks[0].Dcolor); - Desks[0].Dcolor = NULL; - } - if (item->next != NULL && item->next->Dcolor != NULL) - { - CopyString(&Desks[0].Dcolor, item->next->Dcolor); - } - else - { - /* Use default title if not specified by user. */ - CopyString(&Desks[0].Dcolor, PagerBack); + int oldDesk; + + oldDesk = Scr.CurrentDesk; + Scr.CurrentDesk = (long)body[0]; + if (fAlwaysCurrentDesk && oldDesk != Scr.CurrentDesk) { + PagerWindow *t; + PagerStringList *item; + char line[100]; + + desk1 = Scr.CurrentDesk; + desk2 = Scr.CurrentDesk; + for (t = Start; t != NULL; t = t->next) { + if (t->desk == oldDesk || t->desk == Scr.CurrentDesk) + ChangeDeskForWindow(t, t->desk); + } + item = FindDeskStrings(Scr.CurrentDesk); + if (Desks[0].label != NULL) { + free(Desks[0].label); + Desks[0].label = NULL; + } + if (item->next != NULL && item->next->label != NULL) { + CopyString(&Desks[0].label, item->next->label); + } else { + snprintf(line, sizeof(line), "Desk %d", desk1); + CopyString(&Desks[0].label, line); + } + XStoreName(dpy, Scr.Pager_w, Desks[0].label); + XSetIconName(dpy, Scr.Pager_w, Desks[0].label); + if (Desks[0].Dcolor != NULL) { + free(Desks[0].Dcolor); + Desks[0].Dcolor = NULL; + } + if (item->next != NULL && item->next->Dcolor != NULL) { + CopyString(&Desks[0].Dcolor, item->next->Dcolor); + } else { + /* Use default title if not specified by user. */ + CopyString(&Desks[0].Dcolor, PagerBack); + } + XSetWindowBackground( + dpy, Desks[0].w, GetColor(Desks[0].Dcolor)); + XClearWindow(dpy, Desks[0].w); } - XSetWindowBackground(dpy, Desks[0].w, GetColor(Desks[0].Dcolor)); - XClearWindow(dpy, Desks[0].w); - } - MovePage(); + MovePage(); - DrawGrid(oldDesk - desk1,1); - DrawGrid(Scr.CurrentDesk - desk1,1); - MoveStickyWindows(); - Hilight(FocusWin,OFF); - Hilight(FocusWin,ON); + DrawGrid(oldDesk - desk1, 1); + DrawGrid(Scr.CurrentDesk - desk1, 1); + MoveStickyWindows(); + Hilight(FocusWin, OFF); + Hilight(FocusWin, ON); } /*********************************************************************** @@ -680,25 +638,23 @@ void list_new_desk(unsigned long *body) * list_raise - displays packet contents to stderr * ***********************************************************************/ -void list_raise(unsigned long *body) +void +list_raise(unsigned long *body) { - PagerWindow *t; - Window target_w; - - target_w = body[0]; - t = Start; - while((t!= NULL)&&(t->w != target_w)) - { - t = t->next; - } - if(t!= NULL) - { - if(t->PagerView != None) - XRaiseWindow(dpy,t->PagerView); - XRaiseWindow(dpy,t->IconView); - } -} + PagerWindow *t; + Window target_w; + target_w = body[0]; + t = Start; + while ((t != NULL) && (t->w != target_w)) { + t = t->next; + } + if (t != NULL) { + if (t->PagerView != None) + XRaiseWindow(dpy, t->PagerView); + XRaiseWindow(dpy, t->IconView); + } +} /*********************************************************************** * @@ -706,27 +662,25 @@ void list_raise(unsigned long *body) * list_lower - displays packet contents to stderr * ***********************************************************************/ -void list_lower(unsigned long *body) +void +list_lower(unsigned long *body) { - PagerWindow *t; - Window target_w; - - target_w = body[0]; - t = Start; - while((t!= NULL)&&(t->w != target_w)) - { - t = t->next; - } - if(t!= NULL) - { - if(t->PagerView != None) - XLowerWindow(dpy,t->PagerView); - if((t->desk - desk1>=0)&&(t->desk - desk1desk - desk1].CPagerWin); - XLowerWindow(dpy,t->IconView); - } -} + PagerWindow *t; + Window target_w; + target_w = body[0]; + t = Start; + while ((t != NULL) && (t->w != target_w)) { + t = t->next; + } + if (t != NULL) { + if (t->PagerView != None) + XLowerWindow(dpy, t->PagerView); + if ((t->desk - desk1 >= 0) && (t->desk - desk1 < ndesks)) + XLowerWindow(dpy, Desks[t->desk - desk1].CPagerWin); + XLowerWindow(dpy, t->IconView); + } +} /*********************************************************************** * @@ -734,9 +688,10 @@ void list_lower(unsigned long *body) * list_unknow - handles an unrecognized packet. * ***********************************************************************/ -void list_unknown(unsigned long *body) +void +list_unknown(unsigned long *body) { - /* fprintf(stderr,"Unknown packet type\n");*/ + /* fprintf(stderr,"Unknown packet type\n");*/ } /*********************************************************************** @@ -745,49 +700,44 @@ void list_unknown(unsigned long *body) * list_iconify - displays packet contents to stderr * ***********************************************************************/ -void list_iconify(unsigned long *body) +void +list_iconify(unsigned long *body) { - PagerWindow *t; - Window target_w; - - target_w = body[0]; - t = Start; - while((t!= NULL)&&(t->w != target_w)) - { - t = t->next; - } - if(t== NULL) - { - return; - } - else - { - t->t = (char *)body[2]; - t->frame = body[1]; - t->icon_x = body[3]; - t->icon_y = body[4]; - t->icon_width = body[5]; - t->icon_height = body[6]; - t->flags |= ICONIFIED; - t->x = t->icon_x; - t->y = t->icon_y; - if(t->flags & SUPPRESSICON) - { - t->x = -10000; - t->y = -10000; + PagerWindow *t; + Window target_w; + + target_w = body[0]; + t = Start; + while ((t != NULL) && (t->w != target_w)) { + t = t->next; } - t->width = t->icon_width; - t->height = t->icon_height; + if (t == NULL) { + return; + } else { + t->t = (char *)body[2]; + t->frame = body[1]; + t->icon_x = body[3]; + t->icon_y = body[4]; + t->icon_width = body[5]; + t->icon_height = body[6]; + t->flags |= ICONIFIED; + t->x = t->icon_x; + t->y = t->icon_y; + if (t->flags & SUPPRESSICON) { + t->x = -10000; + t->y = -10000; + } + t->width = t->icon_width; + t->height = t->icon_height; - /* if iconifying main pager window turn balloons on or off */ - if ( t->w == Scr.Pager_w ) - ShowBalloons = ShowIconBalloons; + /* if iconifying main pager window turn balloons on or off */ + if (t->w == Scr.Pager_w) + ShowBalloons = ShowIconBalloons; - MoveResizePagerView(t); - } + MoveResizePagerView(t); + } } - /*********************************************************************** * * Procedure: @@ -795,41 +745,37 @@ void list_iconify(unsigned long *body) * ***********************************************************************/ -void list_deiconify(unsigned long *body) +void +list_deiconify(unsigned long *body) { - PagerWindow *t; - Window target_w; - - target_w = body[0]; - t = Start; - while((t!= NULL)&&(t->w != target_w)) - { - t = t->next; - } - if(t== NULL) - { - return; - } - else - { - t->flags &= ~ICONIFIED; - t->x = t->frame_x; - t->y = t->frame_y; - t->width = t->frame_width; - t->height = t->frame_height; - - /* if deiconifying main pager window turn balloons on or off */ - if ( t->w == Scr.Pager_w ) - ShowBalloons = ShowPagerBalloons; - - MoveResizePagerView(t); - if(FocusWin == t) - Hilight(t,ON); - else - Hilight(t,OFF); - } -} + PagerWindow *t; + Window target_w; + target_w = body[0]; + t = Start; + while ((t != NULL) && (t->w != target_w)) { + t = t->next; + } + if (t == NULL) { + return; + } else { + t->flags &= ~ICONIFIED; + t->x = t->frame_x; + t->y = t->frame_y; + t->width = t->frame_width; + t->height = t->frame_height; + + /* if deiconifying main pager window turn balloons on or off */ + if (t->w == Scr.Pager_w) + ShowBalloons = ShowPagerBalloons; + + MoveResizePagerView(t); + if (FocusWin == t) + Hilight(t, ON); + else + Hilight(t, OFF); + } +} /*********************************************************************** * @@ -837,529 +783,430 @@ void list_deiconify(unsigned long *body) * list_icon_name - displays packet contents to stderr * ***********************************************************************/ -void list_icon_name(unsigned long *body) +void +list_icon_name(unsigned long *body) { - PagerWindow *t; - Window target_w; - - target_w = body[0]; - t = Start; - while((t!= NULL)&&(t->w != target_w)) - { - t = t->next; - } - if(t!= NULL) - { - if(t->icon_name != NULL) - free(t->icon_name); - CopyString(&t->icon_name,(char *)(&body[3])); - LabelWindow(t); - LabelIconWindow(t); - } -} + PagerWindow *t; + Window target_w; + target_w = body[0]; + t = Start; + while ((t != NULL) && (t->w != target_w)) { + t = t->next; + } + if (t != NULL) { + if (t->icon_name != NULL) + free(t->icon_name); + CopyString(&t->icon_name, (char *)(&body[3])); + LabelWindow(t); + LabelIconWindow(t); + } +} -void list_mini_icon(unsigned long *body) +void +list_mini_icon(unsigned long *body) { - PagerWindow *t; - Window target_w; - target_w = body[0]; - t = Start; - while (t && (t->w != target_w)) - t = t->next; - if (t) - { - t->mini_icon.width = body[3]; - t->mini_icon.height = body[4]; - t->mini_icon.depth = body[5]; - t->mini_icon.picture = body[6]; - t->mini_icon.mask = body[7]; - PictureWindow (t); - PictureIconWindow (t); - } + PagerWindow *t; + Window target_w; + target_w = body[0]; + t = Start; + while (t && (t->w != target_w)) + t = t->next; + if (t) { + t->mini_icon.width = body[3]; + t->mini_icon.height = body[4]; + t->mini_icon.depth = body[5]; + t->mini_icon.picture = body[6]; + t->mini_icon.mask = body[7]; + PictureWindow(t); + PictureIconWindow(t); + } } - /*********************************************************************** * * Procedure: * list_end - displays packet contents to stderr * ***********************************************************************/ -void list_end(void) +void +list_end(void) { - unsigned int nchildren,i; - Window root, parent, *children; - PagerWindow *ptr; - - if(!XQueryTree(dpy, Scr.Root, &root, &parent, &children, &nchildren)) - return; - - for(i=0; iframe == children[i])||(ptr->icon_w == children[i])|| - (ptr->icon_pixmap_w == children[i])) - { - if(ptr->PagerView != None) - XRaiseWindow(dpy,ptr->PagerView); - XRaiseWindow(dpy,ptr->IconView); - } - ptr = ptr->next; + unsigned int nchildren, i; + Window root, parent, *children; + PagerWindow *ptr; + + if (!XQueryTree(dpy, Scr.Root, &root, &parent, &children, &nchildren)) + return; + + for (i = 0; i < nchildren; i++) { + ptr = Start; + while (ptr != NULL) { + if ((ptr->frame == children[i]) || + (ptr->icon_w == children[i]) || + (ptr->icon_pixmap_w == children[i])) { + if (ptr->PagerView != None) + XRaiseWindow(dpy, ptr->PagerView); + XRaiseWindow(dpy, ptr->IconView); + } + ptr = ptr->next; + } } - } - - if(nchildren > 0) - XFree((char *)children); + if (nchildren > 0) + XFree((char *)children); } - - - /*************************************************************************** * * Waits for next X event, or for an auto-raise timeout. * ****************************************************************************/ -int My_XNextEvent(Display *dpy, XEvent *event) +int +My_XNextEvent(Display *dpy, XEvent *event) { - fd_set in_fdset; - unsigned long header[HEADER_SIZE]; - static int miss_counter = 0; - unsigned long *body; - - if(XPending(dpy)) - { - XNextEvent(dpy,event); - return 1; - } - - FD_ZERO(&in_fdset); - FD_SET(x_fd,&in_fdset); - FD_SET(fd[1],&in_fdset); - - if (select(fd_width,SELECT_TYPE_ARG234 &in_fdset, 0, 0, NULL) > 0) - { - if(FD_ISSET(x_fd, &in_fdset)) - { - if(XPending(dpy)) - { - XNextEvent(dpy,event); - miss_counter = 0; - return 1; + fd_set in_fdset; + unsigned long header[HEADER_SIZE]; + static int miss_counter = 0; + unsigned long *body; + + if (XPending(dpy)) { + XNextEvent(dpy, event); + return 1; } - miss_counter++; - if(miss_counter > 100) - DeadPipe(0); - } - - if(FD_ISSET(fd[1], &in_fdset)) - { - if(ReadFvwmPacket(fd[1],header,&body) > 0) - { - process_message(header[1],body); - free(body); - } - } - } - return 0; -} + FD_ZERO(&in_fdset); + FD_SET(x_fd, &in_fdset); + FD_SET(fd[1], &in_fdset); + + if (select(fd_width, SELECT_TYPE_ARG234 & in_fdset, 0, 0, NULL) > 0) { + if (FD_ISSET(x_fd, &in_fdset)) { + if (XPending(dpy)) { + XNextEvent(dpy, event); + miss_counter = 0; + return 1; + } + miss_counter++; + if (miss_counter > 100) + DeadPipe(0); + } + if (FD_ISSET(fd[1], &in_fdset)) { + if (ReadFvwmPacket(fd[1], header, &body) > 0) { + process_message(header[1], body); + free(body); + } + } + } + return 0; +} /***************************************************************************** * * This routine is responsible for reading and parsing the config file * ****************************************************************************/ -void ParseOptions(void) +void +ParseOptions(void) { - char *tline= NULL; - int Clength,n,desk; - - Scr.FvwmRoot = NULL; - Scr.Hilite = NULL; - Scr.VScale = 32; - - Scr.MyDisplayWidth = DisplayWidth(dpy, Scr.screen); - Scr.MyDisplayHeight = DisplayHeight(dpy, Scr.screen); - - Scr.VxMax = 3*Scr.MyDisplayWidth - Scr.MyDisplayWidth; - Scr.VyMax = 3*Scr.MyDisplayHeight - Scr.MyDisplayHeight; - if(Scr.VxMax <0) - Scr.VxMax = 0; - if(Scr.VyMax <0) - Scr.VyMax = 0; - Scr.Vx = 0; - Scr.Vy = 0; - - Clength = strlen(MyName); - - for (GetConfigLine(fd,&tline); tline != NULL; GetConfigLine(fd,&tline)) - { - int g_x, g_y, flags; - unsigned width,height; - char *resource; - char *resource_string; - char *arg1; - char *arg2; - char *tline2; - - resource_string = arg1 = arg2 = NULL; - tline2 = GetModuleResource(tline, &resource, MyName); - if (!resource) - continue; - tline2 = GetNextToken(tline2, &arg1); - if (!arg1) - { - arg1 = (char *)safemalloc(1); - arg1[0] = 0; - } - tline2 = GetNextToken(tline2, &arg2); - if (!arg2) - { - arg2 = (char *)safemalloc(1); - arg2[0] = 0; - } - - if (StrEquals(resource, "Geometry")) - { - flags = XParseGeometry(arg1,&g_x,&g_y,&width,&height); - if (flags & WidthValue) - { - window_w = width; - } - if (flags & HeightValue) - { - window_h = height; - } - if (flags & XValue) - { - window_x = g_x; - usposition = 1; - } - if (flags & YValue) - { - window_y = g_y; - usposition = 1; - } - if (flags & XNegative) - { - xneg = 1; - } - if (flags & YNegative) - { - window_y = g_y; - yneg = 1; - } - } - else if (StrEquals(resource, "IconGeometry")) - { - flags = XParseGeometry(arg1,&g_x,&g_y,&width,&height); - if (flags & WidthValue) - icon_w = width; - if (flags & HeightValue) - icon_h = height; - if (flags & XValue) - { - icon_x = g_x; - } - if (flags & YValue) - { - icon_y = g_y; - } - } - else if (StrEquals(resource, "Label")) - { - if (StrEquals(arg1, "*")) - { - desk = Scr.CurrentDesk; - } - else - { - desk = desk1; - sscanf(arg1,"%d",&desk); - } - if (fAlwaysCurrentDesk) - { - PagerStringList *item; - - item = FindDeskStrings(desk); - if (item->next != NULL) - { - /* replace label */ - if (item->next->label != NULL) - { - free(item->next->label); - item->next->label = NULL; - } - CopyString(&(item->next->label), arg2); + char *tline = NULL; + int Clength, n, desk; + + Scr.FvwmRoot = NULL; + Scr.Hilite = NULL; + Scr.VScale = 32; + + Scr.MyDisplayWidth = DisplayWidth(dpy, Scr.screen); + Scr.MyDisplayHeight = DisplayHeight(dpy, Scr.screen); + + Scr.VxMax = 3 * Scr.MyDisplayWidth - Scr.MyDisplayWidth; + Scr.VyMax = 3 * Scr.MyDisplayHeight - Scr.MyDisplayHeight; + if (Scr.VxMax < 0) + Scr.VxMax = 0; + if (Scr.VyMax < 0) + Scr.VyMax = 0; + Scr.Vx = 0; + Scr.Vy = 0; + + Clength = strlen(MyName); + + for (GetConfigLine(fd, &tline); tline != NULL; + GetConfigLine(fd, &tline)) { + int g_x, g_y, flags; + unsigned width, height; + char *resource; + char *resource_string; + char *arg1; + char *arg2; + char *tline2; + + resource_string = arg1 = arg2 = NULL; + tline2 = GetModuleResource(tline, &resource, MyName); + if (!resource) + continue; + tline2 = GetNextToken(tline2, &arg1); + if (!arg1) { + arg1 = (char *)xmalloc(1); + arg1[0] = 0; } - else - { - /* new Dcolor and desktop */ - item = NewPagerStringItem(item, desk); - CopyString(&(item->label), arg2); + tline2 = GetNextToken(tline2, &arg2); + if (!arg2) { + arg2 = (char *)xmalloc(1); + arg2[0] = 0; } - if (desk == Scr.CurrentDesk) - { - free(Desks[0].label); - CopyString(&Desks[0].label, arg2); - } - } - else if((desk >= desk1)&&(desk <=desk2)) - { - free(Desks[desk - desk1].label); - CopyString(&Desks[desk - desk1].label, arg2); - } - } - else if (StrEquals(resource, "Font")) - { - if (font_string) - free(font_string); - CopyString(&font_string,arg1); - if(strncasecmp(font_string,"none",4) == 0) - uselabel = 0; - } - else if (StrEquals(resource, "Fore")) - { - if(Scr.d_depth > 1) - { - if (PagerFore) - free(PagerFore); - CopyString(&PagerFore,arg1); - } - } - else if (StrEquals(resource, "Back")) - { - if(Scr.d_depth > 1) - { - if (PagerBack) - free(PagerBack); - CopyString(&PagerBack,arg1); - for (n=0;nnext != NULL) { + /* replace label */ + if (item->next->label != NULL) { + free(item->next->label); + item->next->label = NULL; + } + CopyString(&(item->next->label), arg2); + } else { + /* new Dcolor and desktop */ + item = NewPagerStringItem(item, desk); + CopyString(&(item->label), arg2); + } + if (desk == Scr.CurrentDesk) { + free(Desks[0].label); + CopyString(&Desks[0].label, arg2); + } + } else if ((desk >= desk1) && (desk <= desk2)) { + free(Desks[desk - desk1].label); + CopyString(&Desks[desk - desk1].label, arg2); + } + } else if (StrEquals(resource, "Font")) { + if (font_string) + free(font_string); + CopyString(&font_string, arg1); + if (strncasecmp(font_string, "none", 4) == 0) + uselabel = 0; + } else if (StrEquals(resource, "Fore")) { + if (Scr.d_depth > 1) { + if (PagerFore) + free(PagerFore); + CopyString(&PagerFore, arg1); + } + } else if (StrEquals(resource, "Back")) { + if (Scr.d_depth > 1) { + if (PagerBack) + free(PagerBack); + CopyString(&PagerBack, arg1); + for (n = 0; n < ndesks; n++) { + free(Desks[n].Dcolor); + CopyString(&Desks[n].Dcolor, PagerBack); #ifdef DEBUG - fprintf(stderr, - "[ParseOptions]: Back Desks[%d].Dcolor == %s\n", - n,Desks[n].Dcolor); + fprintf(stderr, + "[ParseOptions]: Back " + "Desks[%d].Dcolor == %s\n", + n, Desks[n].Dcolor); #endif + } + } + } else if (StrEquals(resource, "DeskColor")) { + if (StrEquals(arg1, "*")) { + desk = Scr.CurrentDesk; + } else { + desk = desk1; + sscanf(arg1, "%d", &desk); + } + if (fAlwaysCurrentDesk) { + PagerStringList *item; + + item = FindDeskStrings(desk); + if (item->next != NULL) { + /* replace Dcolor */ + if (item->next->Dcolor != NULL) { + free(item->next->Dcolor); + item->next->Dcolor = NULL; + } + CopyString(&(item->next->Dcolor), arg2); + } else { + /* new Dcolor and desktop */ + item = NewPagerStringItem(item, desk); + CopyString(&(item->Dcolor), arg2); + } + if (desk == Scr.CurrentDesk) { + free(Desks[0].Dcolor); + CopyString(&Desks[0].Dcolor, arg2); + } + } else if ((desk >= desk1) && (desk <= desk2)) { + free(Desks[desk - desk1].Dcolor); + CopyString(&Desks[desk - desk1].Dcolor, arg2); + } + } else if (StrEquals(resource, "Hilight")) { + if (Scr.d_depth > 1) { + if (HilightC) + free(HilightC); + CopyString(&HilightC, arg1); + } + } else if (StrEquals(resource, "SmallFont")) { + if (smallFont) + free(smallFont); + CopyString(&smallFont, arg1); + if (strncasecmp(smallFont, "none", 4) == 0) { + free(smallFont); + smallFont = NULL; + } + } else if (StrEquals(resource, "MiniIcons")) { + MiniIcons = 1; + } else if (StrEquals(resource, "StartIconic")) { + StartIconic = 1; + } else if (StrEquals(resource, "Rows")) { + sscanf(arg1, "%d", &Rows); + } else if (StrEquals(resource, "Columns")) { + sscanf(arg1, "%d", &Columns); + } else if (StrEquals(resource, "DeskTopScale")) { + sscanf(arg1, "%d", &Scr.VScale); + } else if (StrEquals(resource, "WindowColors")) { + if (Scr.d_depth > 1) { + if (WindowFore) + free(WindowFore); + if (WindowBack) + free(WindowBack); + if (WindowHiFore) + free(WindowHiFore); + if (WindowHiBack) + free(WindowHiBack); + CopyString(&WindowFore, arg1); + CopyString(&WindowBack, arg2); + tline2 = GetNextToken(tline2, &WindowHiFore); + GetNextToken(tline2, &WindowHiBack); + } } - } - } - else if (StrEquals(resource, "DeskColor")) - { - if (StrEquals(arg1, "*")) - { - desk = Scr.CurrentDesk; - } - else - { - desk = desk1; - sscanf(arg1,"%d",&desk); - } - if (fAlwaysCurrentDesk) - { - PagerStringList *item; - - item = FindDeskStrings(desk); - if (item->next != NULL) - { - /* replace Dcolor */ - if (item->next->Dcolor != NULL) - { - free(item->next->Dcolor); - item->next->Dcolor = NULL; - } - CopyString(&(item->next->Dcolor), arg2); - } - else - { - /* new Dcolor and desktop */ - item = NewPagerStringItem(item, desk); - CopyString(&(item->Dcolor), arg2); - } - if (desk == Scr.CurrentDesk) - { - free(Desks[0].Dcolor); - CopyString(&Desks[0].Dcolor, arg2); - } - } - else if((desk >= desk1)&&(desk <=desk2)) - { - free(Desks[desk - desk1].Dcolor); - CopyString(&Desks[desk - desk1].Dcolor, arg2); - } - } - else if (StrEquals(resource, "Hilight")) - { - if(Scr.d_depth > 1) - { - if (HilightC) - free(HilightC); - CopyString(&HilightC,arg1); - } - } - else if (StrEquals(resource, "SmallFont")) - { - if (smallFont) - free(smallFont); - CopyString(&smallFont,arg1); - if(strncasecmp(smallFont,"none",4) == 0) - { - free(smallFont); - smallFont = NULL; - } - } - else if (StrEquals(resource, "MiniIcons")) - { - MiniIcons = 1; - } - else if (StrEquals(resource, "StartIconic")) - { - StartIconic = 1; - } - else if (StrEquals(resource, "Rows")) - { - sscanf(arg1,"%d",&Rows); - } - else if (StrEquals(resource, "Columns")) - { - sscanf(arg1,"%d",&Columns); - } - else if (StrEquals(resource, "DeskTopScale")) - { - sscanf(arg1,"%d",&Scr.VScale); - } - else if (StrEquals(resource, "WindowColors")) - { - if (Scr.d_depth > 1) - { - if (WindowFore) - free(WindowFore); - if (WindowBack) - free(WindowBack); - if (WindowHiFore) - free(WindowHiFore); - if (WindowHiBack) - free(WindowHiBack); - CopyString(&WindowFore, arg1); - CopyString(&WindowBack, arg2); - tline2 = GetNextToken(tline2, &WindowHiFore); - GetNextToken(tline2, &WindowHiBack); - } - } + /* ... and get Balloon config options ... + -- ric@giccs.georgetown.edu */ + else if (StrEquals(resource, "Balloons")) { + if (BalloonTypeString) + free(BalloonTypeString); + CopyString(&BalloonTypeString, arg1); + + if (strncasecmp(BalloonTypeString, "Pager", 5) == 0) { + ShowPagerBalloons = 1; + ShowIconBalloons = 0; + } else if (strncasecmp(BalloonTypeString, "Icon", 4) == + 0) { + ShowPagerBalloons = 0; + ShowIconBalloons = 1; + } else { + ShowPagerBalloons = 1; + ShowIconBalloons = 1; + } + + /* turn this on initially so balloon window is created; + later this variable is changed to match + ShowPagerBalloons or ShowIconBalloons whenever we + receive iconify or deiconify packets */ + ShowBalloons = 1; + } else if (StrEquals(resource, "BalloonBack")) { + if (Scr.d_depth > 1) { + if (BalloonBack) + free(BalloonBack); + CopyString(&BalloonBack, arg1); + } + } else if (StrEquals(resource, "BalloonFore")) { + if (Scr.d_depth > 1) { + if (BalloonFore) + free(BalloonFore); + CopyString(&BalloonFore, arg1); + } + } else if (StrEquals(resource, "BalloonFont")) { + if (BalloonFont) + free(BalloonFont); + CopyString(&BalloonFont, arg1); + } else if (StrEquals(resource, "BalloonBorderColor")) { + if (BalloonBorderColor) + free(BalloonBorderColor); + CopyString(&BalloonBorderColor, arg1); + } else if (StrEquals(resource, "BalloonBorderWidth")) { + sscanf(arg1, "%d", &BalloonBorderWidth); + } else if (StrEquals(resource, "BalloonYOffset")) { + sscanf(arg1, "%d", &BalloonYOffset); + } - /* ... and get Balloon config options ... - -- ric@giccs.georgetown.edu */ - else if (StrEquals(resource, "Balloons")) - { - if (BalloonTypeString) - free(BalloonTypeString); - CopyString(&BalloonTypeString, arg1); - - if ( strncasecmp(BalloonTypeString, "Pager", 5) == 0 ) { - ShowPagerBalloons = 1; - ShowIconBalloons = 0; - } - else if ( strncasecmp(BalloonTypeString, "Icon", 4) == 0 ) { - ShowPagerBalloons = 0; - ShowIconBalloons = 1; - } - else { - ShowPagerBalloons = 1; - ShowIconBalloons = 1; - } - - /* turn this on initially so balloon window is created; later this - variable is changed to match ShowPagerBalloons or ShowIconBalloons - whenever we receive iconify or deiconify packets */ - ShowBalloons = 1; - } - - else if (StrEquals(resource, "BalloonBack")) - { - if (Scr.d_depth > 1) - { - if (BalloonBack) - free(BalloonBack); - CopyString(&BalloonBack, arg1); - } - } - - else if (StrEquals(resource, "BalloonFore")) - { - if (Scr.d_depth > 1) - { - if (BalloonFore) - free(BalloonFore); - CopyString(&BalloonFore, arg1); - } - } - - else if (StrEquals(resource, "BalloonFont")) - { - if (BalloonFont) - free(BalloonFont); - CopyString(&BalloonFont, arg1); - } - - else if (StrEquals(resource, "BalloonBorderColor")) - { - if (BalloonBorderColor) - free(BalloonBorderColor); - CopyString(&BalloonBorderColor, arg1); - } - - else if (StrEquals(resource, "BalloonBorderWidth")) - { - sscanf(arg1, "%d", &BalloonBorderWidth); - } - - else if (StrEquals(resource, "BalloonYOffset")) - { - sscanf(arg1, "%d", &BalloonYOffset); + free(resource); + free(arg1); + free(arg2); } - - free(resource); - free(arg1); - free(arg2); - } - return; + return; } /* Returns the item in the sring list that has item->next->desk == desk or * the last item (item->next == NULL) if no entry matches the desk number. */ -PagerStringList *FindDeskStrings(int desk) +PagerStringList * +FindDeskStrings(int desk) { - PagerStringList *item; - - item = &string_list; - while (item->next != NULL) - { - if (item->next->desk == desk) - break; - item = item->next; - } - return item; + PagerStringList *item; + + item = &string_list; + while (item->next != NULL) { + if (item->next->desk == desk) + break; + item = item->next; + } + return item; } -PagerStringList *NewPagerStringItem(PagerStringList *last, int desk) +PagerStringList * +NewPagerStringItem(PagerStringList *last, int desk) { - PagerStringList *newitem; + PagerStringList *newitem; - newitem = (PagerStringList *)safemalloc(sizeof(PagerStringList)); - last->next = newitem; - newitem->desk = desk; - newitem->next = NULL; - newitem->label = NULL; - newitem->Dcolor = NULL; + newitem = (PagerStringList *)xmalloc(sizeof(PagerStringList)); + last->next = newitem; + newitem->desk = desk; + newitem->next = NULL; + newitem->label = NULL; + newitem->Dcolor = NULL; - return newitem; + return newitem; } Index: fvwm/modules/FvwmPager/FvwmPager.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmPager/FvwmPager.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmPager/FvwmPager.h --- fvwm/modules/FvwmPager/FvwmPager.h +++ fvwm/modules/FvwmPager/FvwmPager.h @@ -1,101 +1,93 @@ -typedef struct ScreenInfo -{ - unsigned long screen; - int d_depth; /* copy of DefaultDepth(dpy, screen) */ - int MyDisplayWidth; /* my copy of DisplayWidth(dpy, screen) */ - int MyDisplayHeight; /* my copy of DisplayHeight(dpy, screen) */ - - char *FvwmRoot; /* the head of the fvwm window list */ - Window Root; /* the root window */ - - Window Pager_w; - - Font PagerFont; /* font struct for window labels in pager (optional)*/ - - GC NormalGC; /* normal GC for menus, pager, resize window */ - - char *Hilite; /* the fvwm window that is highlighted - * except for networking delays, this is the - * window which REALLY has the focus */ - unsigned VScale; /* Panner scale factor */ - int VxMax; /* Max location for top left of virt desk*/ - int VyMax; - int Vx; /* Current loc for top left of virt desk */ - int Vy; - int CurrentDesk; - Pixmap sticky_gray_pixmap; - Pixmap light_gray_pixmap; - Pixmap gray_pixmap; - +typedef struct ScreenInfo { + unsigned long screen; + int d_depth; /* copy of DefaultDepth(dpy, screen) */ + int MyDisplayWidth; /* my copy of DisplayWidth(dpy, screen) */ + int MyDisplayHeight; /* my copy of DisplayHeight(dpy, screen) */ + + char *FvwmRoot; /* the head of the fvwm window list */ + Window Root; /* the root window */ + + Window Pager_w; + + Font PagerFont; /* font struct for window labels in pager (optional)*/ + + GC NormalGC; /* normal GC for menus, pager, resize window */ + + char *Hilite; /* the fvwm window that is highlighted + * except for networking delays, this is the + * window which REALLY has the focus */ + unsigned VScale; /* Panner scale factor */ + int VxMax; /* Max location for top left of virt desk*/ + int VyMax; + int Vx; /* Current loc for top left of virt desk */ + int Vy; + int CurrentDesk; + Pixmap sticky_gray_pixmap; + Pixmap light_gray_pixmap; + Pixmap gray_pixmap; } ScreenInfo; -typedef struct pager_window -{ - char *t; - Window w; - Window frame; - int x; - int y; - int width; - int height; - int desk; - int frame_x; - int frame_y; - int frame_width; - int frame_height; - int title_height; - int border_width; - int icon_x; - int icon_y; - int icon_width; - int icon_height; - Pixel text; - Pixel back; - unsigned long flags; - Window icon_w; - Window icon_pixmap_w; - char *icon_name; - FvwmPicture mini_icon; - int pager_view_width; - int pager_view_height; - int icon_view_width; - int icon_view_height; - - Window PagerView; - Window IconView; - - struct pager_window *next; +typedef struct pager_window { + char *t; + Window w; + Window frame; + int x; + int y; + int width; + int height; + int desk; + int frame_x; + int frame_y; + int frame_width; + int frame_height; + int title_height; + int border_width; + int icon_x; + int icon_y; + int icon_width; + int icon_height; + Pixel text; + Pixel back; + unsigned long flags; + Window icon_w; + Window icon_pixmap_w; + char *icon_name; + FvwmPicture mini_icon; + int pager_view_width; + int pager_view_height; + int icon_view_width; + int icon_view_height; + + Window PagerView; + Window IconView; + + struct pager_window *next; } PagerWindow; - -typedef struct balloon_window -{ - Window w; /* ID of balloon window */ - PagerWindow *pw; /* pager window it's associated with */ - XFontStruct *font; - int height; /* height of balloon window based on font */ - int border; /* border width */ - int yoffset; /* pixels above (<0) or below (>0) pager win */ +typedef struct balloon_window { + Window w; /* ID of balloon window */ + PagerWindow *pw; /* pager window it's associated with */ + XFontStruct *font; + int height; /* height of balloon window based on font */ + int border; /* border width */ + int yoffset; /* pixels above (<0) or below (>0) pager win */ } BalloonWindow; - -typedef struct desk_info -{ - Window w; - Window title_w; - Window CPagerWin; - int x; - int y; - char *Dcolor; - char *label; +typedef struct desk_info { + Window w; + Window title_w; + Window CPagerWin; + int x; + int y; + char *Dcolor; + char *label; } DeskInfo; -typedef struct pager_string_list -{ - struct pager_string_list *next; - int desk; - char *Dcolor; - char *label; +typedef struct pager_string_list { + struct pager_string_list *next; + int desk; + char *Dcolor; + char *label; } PagerStringList; #define ON 1 @@ -106,12 +98,11 @@ typedef struct pager_string_list * Subroutine Prototypes * *************************************************************************/ -char *GetNextToken(char *indata,char **token); +char *GetNextToken(char *indata, char **token); void Loop(int *fd); -void SendInfo(int *fd,char *message,unsigned long window); -char *safemalloc(int length); +void SendInfo(int *fd, char *message, unsigned long window); void DeadPipe(int nonsense); -void process_message(unsigned long type,unsigned long *body); +void process_message(unsigned long type, unsigned long *body); void ParseOptions(void); void list_add(unsigned long *body); @@ -142,13 +133,13 @@ void DispatchEvent(XEvent *Event); void ReConfigure(void); void ReConfigureAll(void); void MovePage(void); -void DrawGrid(int i,int erase); +void DrawGrid(int i, int erase); void DrawIconGrid(int erase); void SwitchToDesk(int Desk); void SwitchToDeskAndPage(int Desk, XEvent *Event); void AddNewWindow(PagerWindow *prev); void MoveResizePagerView(PagerWindow *t); -void ChangeDeskForWindow(PagerWindow *t,long newdesk); +void ChangeDeskForWindow(PagerWindow *t, long newdesk); void MoveStickyWindow(void); void Hilight(PagerWindow *, int); void Scroll(int window_w, int window_h, int x, int y, int Desk); @@ -159,13 +150,9 @@ void PictureWindow(PagerWindow *t); void PictureIconWindow(PagerWindow *t); void ReConfigureIcons(void); void IconSwitchPage(XEvent *Event); -void IconMoveWindow(XEvent *Event,PagerWindow *t); +void IconMoveWindow(XEvent *Event, PagerWindow *t); void HandleExpose(XEvent *Event); void MoveStickyWindows(void); void MapBalloonWindow(XEvent *); void UnmapBalloonWindow(void); void DrawInBalloonWindow(void); - - - - Index: fvwm/modules/FvwmPager/x_pager.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmPager/x_pager.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmPager/x_pager.c --- fvwm/modules/FvwmPager/x_pager.c +++ fvwm/modules/FvwmPager/x_pager.c @@ -8,21 +8,19 @@ * ***********************************************************************/ -#include "config.h" - -#include -#include -#include - +#include +#include #include -#include #include -#include -#include +#include +#include +#include +#include -#include "../../libs/fvwmlib.h" #include "../../fvwm/fvwm.h" +#include "../../libs/fvwmlib.h" #include "FvwmPager.h" +#include "config.h" extern ScreenInfo Scr; extern Display *dpy; @@ -31,7 +29,8 @@ Pixel back_pix, fore_pix, hi_pix; Pixel focus_pix; Pixel focus_fore_pix; extern Pixel win_back_pix, win_fore_pix, win_hi_back_pix, win_hi_fore_pix; -extern int window_w, window_h,window_x,window_y,usposition,uselabel,xneg,yneg; +extern int window_w, window_h, window_x, window_y, usposition, uselabel, xneg, + yneg; extern int StartIconic; extern int MiniIcons; extern int ShowBalloons, ShowPagerBalloons, ShowIconBalloons; @@ -39,7 +38,7 @@ extern int ShowBalloons, ShowPagerBalloons, ShowIconBalloons; extern int icon_w, icon_h, icon_x, icon_y; XFontStruct *font, *windowFont; -GC NormalGC,DashedGC,HiliteGC,rvGC; +GC NormalGC, DashedGC, HiliteGC, rvGC; GC StdGC; GC MiniIconGC; GC BalloonGC; @@ -51,7 +50,7 @@ static Atom wm_del_win; extern char *MyName; extern int desk1, desk2, ndesks; -extern int Rows,Columns; +extern int Rows, Columns; extern int fd[2]; int desk_w = 0; @@ -62,7 +61,6 @@ DeskInfo *Desks; int Wait = 0; XErrorHandler FvwmErrorHandler(Display *, XErrorEvent *); - /* assorted gray bitmaps for decorative borders */ #define g_width 2 #define g_height 2 @@ -76,9 +74,8 @@ static char l_g_bits[] = {0x08, 0x02}; #define s_g_height 4 static char s_g_bits[] = {0x01, 0x02, 0x04, 0x08}; - -Window icon_win; /* icon window */ -BalloonWindow balloon; /* balloon window */ +Window icon_win; /* icon window */ +BalloonWindow balloon; /* balloon window */ /*********************************************************************** * @@ -90,437 +87,395 @@ BalloonWindow balloon; /* balloon window */ * ***********************************************************************/ char *pager_name = "Fvwm Pager"; -XSizeHints sizehints = -{ - (PMinSize | PResizeInc | PBaseSize | PWinGravity), - 0, 0, 100, 100, /* x, y, width and height */ - 1, 1, /* Min width and height */ - 0, 0, /* Max width and height */ - 1, 1, /* Width and height increments */ - {0, 0}, {0, 0}, /* Aspect ratio - not used */ - 1, 1, /* base size */ - (NorthWestGravity) /* gravity */ +XSizeHints sizehints = { + (PMinSize | PResizeInc | PBaseSize | PWinGravity), 0, 0, 100, + 100, /* x, y, width and height */ + 1, 1, /* Min width and height */ + 0, 0, /* Max width and height */ + 1, 1, /* Width and height increments */ + {0, 0}, {0, 0}, /* Aspect ratio - not used */ + 1, 1, /* base size */ + (NorthWestGravity) /* gravity */ }; -void initialize_pager(void) +void +initialize_pager(void) { - XWMHints wmhints; - XClassHint class1; - - XTextProperty name; - unsigned long valuemask; - XSetWindowAttributes attributes; - extern char *PagerFore, *PagerBack, *HilightC; - extern char *WindowBack, *WindowFore, *WindowHiBack, *WindowHiFore; - extern char *BalloonFore, *BalloonBack, *BalloonFont; - extern char *BalloonBorderColor; - extern int BalloonBorderWidth, BalloonYOffset; - extern char *font_string, *smallFont; - int n,m,w,h,i,x,y; - XGCValues gcv; - unsigned long gcm; + XWMHints wmhints; + XClassHint class1; + + XTextProperty name; + unsigned long valuemask; + XSetWindowAttributes attributes; + extern char *PagerFore, *PagerBack, *HilightC; + extern char *WindowBack, *WindowFore, *WindowHiBack, *WindowHiFore; + extern char *BalloonFore, *BalloonBack, *BalloonFont; + extern char *BalloonBorderColor; + extern int BalloonBorderWidth, BalloonYOffset; + extern char *font_string, *smallFont; + int n, m, w, h, i, x, y; + XGCValues gcv; + unsigned long gcm; #if 1 - /* I don't think that this is necessary - just let pager die */ - /* domivogt (07-mar-1999): But it is! A window being moved in the pager - * might die at any moment causing the Xlib calls to generate BadMatch - * errors. Without an error handler the pager will die! */ - XSetErrorHandler((XErrorHandler)FvwmErrorHandler); + /* I don't think that this is necessary - just let pager die */ + /* domivogt (07-mar-1999): But it is! A window being moved in the pager + * might die at any moment causing the Xlib calls to generate BadMatch + * errors. Without an error handler the pager will die! */ + XSetErrorHandler((XErrorHandler)FvwmErrorHandler); #endif /* 1 */ - wm_del_win = XInternAtom(dpy,"WM_DELETE_WINDOW",False); + wm_del_win = XInternAtom(dpy, "WM_DELETE_WINDOW", False); - /* load the font */ - if (!uselabel || ((font = XLoadQueryFont(dpy, font_string)) == NULL)) - { - if ((font = XLoadQueryFont(dpy, "fixed")) == NULL) - { - fprintf(stderr,"%s: No fonts available\n",MyName); - exit(1); + /* load the font */ + if (!uselabel || ((font = XLoadQueryFont(dpy, font_string)) == NULL)) { + if ((font = XLoadQueryFont(dpy, "fixed")) == NULL) { + fprintf(stderr, "%s: No fonts available\n", MyName); + exit(1); + } } - }; - if(uselabel) - label_h = font->ascent + font->descent+2; - else - label_h = 0; - - - if(smallFont!= NULL) - { - windowFont= XLoadQueryFont(dpy, smallFont); - } - else - windowFont= NULL; - - /* Load the colors */ - fore_pix = GetColor(PagerFore); - back_pix = GetColor(PagerBack); - hi_pix = GetColor(HilightC); - - if (WindowBack && WindowFore && WindowHiBack && WindowHiFore) - { - win_back_pix = GetColor (WindowBack); - win_fore_pix = GetColor (WindowFore); - win_hi_back_pix = GetColor (WindowHiBack); - win_hi_fore_pix = GetColor (WindowHiFore); - } - /* Load pixmaps for mono use */ - if(Scr.d_depth<2) - { - Scr.gray_pixmap = - XCreatePixmapFromBitmapData(dpy,Scr.Root,g_bits, g_width,g_height, - fore_pix,back_pix,Scr.d_depth); - Scr.light_gray_pixmap = - XCreatePixmapFromBitmapData(dpy,Scr.Root,l_g_bits,l_g_width,l_g_height, - fore_pix,back_pix,Scr.d_depth); - Scr.sticky_gray_pixmap = - XCreatePixmapFromBitmapData(dpy,Scr.Root,s_g_bits,s_g_width,s_g_height, - fore_pix,back_pix,Scr.d_depth); - } - - - n = Scr.VxMax/Scr.MyDisplayWidth; - m = Scr.VyMax/Scr.MyDisplayHeight; - - /* Size the window */ - if(Rows < 0) - { - if(Columns < 0) - { - Columns = ndesks; - Rows = 1; + if (uselabel) + label_h = font->ascent + font->descent + 2; + else + label_h = 0; + + if (smallFont != NULL) { + windowFont = XLoadQueryFont(dpy, smallFont); + } else + windowFont = NULL; + + /* Load the colors */ + fore_pix = GetColor(PagerFore); + back_pix = GetColor(PagerBack); + hi_pix = GetColor(HilightC); + + if (WindowBack && WindowFore && WindowHiBack && WindowHiFore) { + win_back_pix = GetColor(WindowBack); + win_fore_pix = GetColor(WindowFore); + win_hi_back_pix = GetColor(WindowHiBack); + win_hi_fore_pix = GetColor(WindowHiFore); } - else - { - Rows = ndesks/Columns; - if(Rows*Columns < ndesks) - Rows++; + /* Load pixmaps for mono use */ + if (Scr.d_depth < 2) { + Scr.gray_pixmap = XCreatePixmapFromBitmapData(dpy, Scr.Root, + g_bits, g_width, g_height, fore_pix, back_pix, Scr.d_depth); + Scr.light_gray_pixmap = + XCreatePixmapFromBitmapData(dpy, Scr.Root, l_g_bits, + l_g_width, l_g_height, fore_pix, back_pix, Scr.d_depth); + Scr.sticky_gray_pixmap = + XCreatePixmapFromBitmapData(dpy, Scr.Root, s_g_bits, + s_g_width, s_g_height, fore_pix, back_pix, Scr.d_depth); } - } - if(Columns < 0) - { - if (Rows == 0) - Rows = 1; - Columns = ndesks/Rows; - if(Rows*Columns < ndesks) - Columns++; - } - - if(Rows*Columns < ndesks) - { - if (Columns == 0) - Columns = 1; - Rows = ndesks/Columns; - if (Rows*Columns < ndesks) - Rows++; - } - if(window_w > 0) - { - window_w = ((window_w - n)/(n+1))*(n+1)+n; - Scr.VScale = Columns*(Scr.VxMax + Scr.MyDisplayWidth)/ - (window_w-Columns+1-Columns*n); - } - if(window_h > 0) - { - window_h = ((window_h - m)/(m+1))*(m+1)+m; - Scr.VScale = Rows*(Scr.VyMax + Scr.MyDisplayHeight)/ - (window_h+2-Rows*(label_h -m-1)); - } - if(window_w <= 0) - window_w = Columns*((Scr.VxMax + Scr.MyDisplayWidth)/Scr.VScale + n) + - Columns-1; - if(window_h <= 0) - { - window_h = Rows*((Scr.VyMax + Scr.MyDisplayHeight)/Scr.VScale - + m + label_h + 1)-2; - } - - if(xneg) - { - sizehints.win_gravity = NorthEastGravity; - window_x = Scr.MyDisplayWidth - window_w + window_x -2; - } - - if(yneg) - { - window_y = Scr.MyDisplayHeight - window_h + window_y -2; - if(sizehints.win_gravity == NorthEastGravity) - sizehints.win_gravity = SouthEastGravity; - else - sizehints.win_gravity = SouthWestGravity; - } - - if(usposition) - sizehints.flags |= USPosition; - - valuemask = (CWBackPixel | CWBorderPixel | CWEventMask); - attributes.background_pixel = back_pix; - attributes.border_pixel = fore_pix; - attributes.event_mask = (StructureNotifyMask); - sizehints.width = window_w; - sizehints.height = window_h; - sizehints.x = window_x; - sizehints.y = window_y; - sizehints.width_inc = Columns*(n+1); - sizehints.height_inc = Rows*(m+1); - sizehints.base_width = Columns * n + Columns - 1; - sizehints.base_height = Rows*(m + label_h+1) -2; - sizehints.min_width = Columns * n + Columns - 1; - sizehints.min_height = Rows*(m + label_h+1) -2; - - Scr.Pager_w = XCreateWindow (dpy, Scr.Root, window_x, window_y, window_w, - window_h, (unsigned int) 1, - CopyFromParent, InputOutput, - (Visual *) CopyFromParent, - valuemask, &attributes); - XSetWMProtocols(dpy,Scr.Pager_w,&wm_del_win,1); - XSetWMNormalHints(dpy,Scr.Pager_w,&sizehints); - - if((desk1==desk2)&&(Desks[0].label != NULL)) - XStringListToTextProperty(&Desks[0].label,1,&name); - else - XStringListToTextProperty(&pager_name,1,&name); - - attributes.event_mask = (StructureNotifyMask| ExposureMask); - if(icon_w < 1) - icon_w = (window_w - Columns+1)/Columns; - if(icon_h < 1) - icon_h = (window_h - Rows* label_h - Rows + 1)/Rows; - - icon_w = (icon_w / (n+1)) *(n+1)+n; - icon_h = (icon_h / (m+1)) *(m+1)+m; - icon_win = XCreateWindow (dpy, Scr.Root, window_x, window_y, - icon_w,icon_h, - (unsigned int) 1, - CopyFromParent, InputOutput, - (Visual *) CopyFromParent, - valuemask, &attributes); - XGrabButton(dpy, 1, AnyModifier, icon_win, - True, ButtonPressMask | ButtonReleaseMask|ButtonMotionMask, - GrabModeAsync, GrabModeAsync, None, - None); - XGrabButton(dpy, 2, AnyModifier, icon_win, - True, ButtonPressMask | ButtonReleaseMask|ButtonMotionMask, - GrabModeAsync, GrabModeAsync, None, - None); - XGrabButton(dpy, 3, AnyModifier, icon_win, - True, ButtonPressMask | ButtonReleaseMask|ButtonMotionMask, - GrabModeAsync, GrabModeAsync, None, - None); - if(!StartIconic) - wmhints.initial_state = NormalState; - else - wmhints.initial_state = IconicState; - wmhints.flags = 0; - if(icon_x > -10000) - { - if(icon_x < 0) - icon_x = Scr.MyDisplayWidth + icon_x - icon_w; - if(icon_y > -10000) - { - if(icon_y < 0) - icon_y = Scr.MyDisplayHeight + icon_y - icon_h; + + n = Scr.VxMax / Scr.MyDisplayWidth; + m = Scr.VyMax / Scr.MyDisplayHeight; + + /* Size the window */ + if (Rows < 0) { + if (Columns < 0) { + Columns = ndesks; + Rows = 1; + } else { + Rows = ndesks / Columns; + if (Rows * Columns < ndesks) + Rows++; + } + } + if (Columns < 0) { + if (Rows == 0) + Rows = 1; + Columns = ndesks / Rows; + if (Rows * Columns < ndesks) + Columns++; + } + + if (Rows * Columns < ndesks) { + if (Columns == 0) + Columns = 1; + Rows = ndesks / Columns; + if (Rows * Columns < ndesks) + Rows++; + } + if (window_w > 0) { + window_w = ((window_w - n) / (n + 1)) * (n + 1) + n; + Scr.VScale = Columns * (Scr.VxMax + Scr.MyDisplayWidth) / + (window_w - Columns + 1 - Columns * n); + } + if (window_h > 0) { + window_h = ((window_h - m) / (m + 1)) * (m + 1) + m; + Scr.VScale = Rows * (Scr.VyMax + Scr.MyDisplayHeight) / + (window_h + 2 - Rows * (label_h - m - 1)); + } + if (window_w <= 0) + window_w = + Columns * + ((Scr.VxMax + Scr.MyDisplayWidth) / Scr.VScale + n) + + Columns - 1; + if (window_h <= 0) { + window_h = + Rows * ((Scr.VyMax + Scr.MyDisplayHeight) / Scr.VScale + m + + label_h + 1) - + 2; + } + + if (xneg) { + sizehints.win_gravity = NorthEastGravity; + window_x = Scr.MyDisplayWidth - window_w + window_x - 2; + } + + if (yneg) { + window_y = Scr.MyDisplayHeight - window_h + window_y - 2; + if (sizehints.win_gravity == NorthEastGravity) + sizehints.win_gravity = SouthEastGravity; + else + sizehints.win_gravity = SouthWestGravity; } - else - icon_y = 0; - wmhints.icon_x = icon_x; - wmhints.icon_y = icon_y; - wmhints.flags = IconPositionHint; - } - wmhints.icon_window = icon_win; - wmhints.input = False; - - wmhints.flags |= InputHint | StateHint | IconWindowHint; - - class1.res_name = MyName; - class1.res_class = "FvwmModule"; - - XSetWMProperties(dpy,Scr.Pager_w,&name,&name,NULL,0, - &sizehints,&wmhints,&class1); - XFree((char *)name.value); - - for(i=0;ifid; - NormalGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); - MiniIconGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); - - gcv.foreground = hi_pix; - if(Scr.d_depth < 2) - { - gcv.foreground = fore_pix; - gcv.background = back_pix; - } - HiliteGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); - - if((Scr.d_depth < 2)||(fore_pix == hi_pix)) - gcv.foreground = back_pix; - else - gcv.foreground = fore_pix; - rvGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); - - if(windowFont != NULL) - { - /* Create GC's for doing window labels */ - gcv.foreground = focus_fore_pix; - gcv.background = focus_pix; - gcv.font = windowFont->fid; - StdGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); - } - - gcm = gcm | GCLineStyle; - gcv.foreground = fore_pix; - gcv.background = back_pix; - gcv.line_style = LineOnOffDash; - DashedGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); - - - /* create balloon window - -- ric@giccs.georgetown.edu */ - if ( ShowBalloons ) { - - valuemask = CWOverrideRedirect | CWEventMask | CWBackPixel | CWBorderPixel; - - /* tell WM to ignore this window */ - attributes.override_redirect = True; - - attributes.event_mask = ExposureMask; - attributes.border_pixel = GetColor(BalloonBorderColor); - - /* if given in config set this now, otherwise it'll be set for each - pager window when drawn later */ - attributes.background_pixel = - (BalloonBack == NULL) ? 0 : GetColor(BalloonBack); - - /* get font for balloon */ - if ( (balloon.font = XLoadQueryFont(dpy, BalloonFont)) == NULL ) { - if ( (balloon.font = XLoadQueryFont(dpy, "fixed")) == NULL ) { - fprintf(stderr,"%s: No fonts available.\n", MyName); - exit(1); - } - fprintf(stderr, "%s: Can't find font '%s', using fixed.\n", - MyName, BalloonFont); - } - - balloon.height = balloon.font->ascent + balloon.font->descent + 1; - - /* this may have been set in config */ - balloon.border = BalloonBorderWidth; - - - /* we don't allow yoffset of 0 because it allows direct transit - from pager window to balloon window, setting up a - LeaveNotify/EnterNotify event loop */ - if ( BalloonYOffset ) - balloon.yoffset = BalloonYOffset; - else { - fprintf(stderr, - "%s: Warning: you're not allowed BalloonYOffset 0; defaulting to +2\n", - MyName); - balloon.yoffset = 2; - } - - /* now create the window */ - balloon.w = XCreateWindow(dpy, Scr.Root, - 0, 0, /* coords set later */ - 1, /* width set later */ - balloon.height, - balloon.border, - CopyFromParent, - InputOutput, - CopyFromParent, - valuemask, - &attributes); - - /* set font */ - gcv.font = balloon.font->fid; - - /* if fore given in config set now, otherwise it'll be set later */ - gcv.foreground = (BalloonFore == NULL) ? 0 : GetColor(BalloonFore); - - BalloonGC = XCreateGC(dpy, balloon.w, GCFont | GCForeground, &gcv); - - /* Make sure we don't get balloons initially with the Icon option. */ - ShowBalloons = ShowPagerBalloons; - } /* ShowBalloons */ -} + if (usposition) + sizehints.flags |= USPosition; + + valuemask = (CWBackPixel | CWBorderPixel | CWEventMask); + attributes.background_pixel = back_pix; + attributes.border_pixel = fore_pix; + attributes.event_mask = (StructureNotifyMask); + sizehints.width = window_w; + sizehints.height = window_h; + sizehints.x = window_x; + sizehints.y = window_y; + sizehints.width_inc = Columns * (n + 1); + sizehints.height_inc = Rows * (m + 1); + sizehints.base_width = Columns * n + Columns - 1; + sizehints.base_height = Rows * (m + label_h + 1) - 2; + sizehints.min_width = Columns * n + Columns - 1; + sizehints.min_height = Rows * (m + label_h + 1) - 2; + + Scr.Pager_w = XCreateWindow(dpy, Scr.Root, window_x, window_y, window_w, + window_h, (unsigned int)1, CopyFromParent, InputOutput, + (Visual *)CopyFromParent, valuemask, &attributes); + XSetWMProtocols(dpy, Scr.Pager_w, &wm_del_win, 1); + XSetWMNormalHints(dpy, Scr.Pager_w, &sizehints); + + if ((desk1 == desk2) && (Desks[0].label != NULL)) + XStringListToTextProperty(&Desks[0].label, 1, &name); + else + XStringListToTextProperty(&pager_name, 1, &name); + + attributes.event_mask = (StructureNotifyMask | ExposureMask); + if (icon_w < 1) + icon_w = (window_w - Columns + 1) / Columns; + if (icon_h < 1) + icon_h = (window_h - Rows * label_h - Rows + 1) / Rows; + + icon_w = (icon_w / (n + 1)) * (n + 1) + n; + icon_h = (icon_h / (m + 1)) * (m + 1) + m; + icon_win = XCreateWindow(dpy, Scr.Root, window_x, window_y, icon_w, + icon_h, (unsigned int)1, CopyFromParent, InputOutput, + (Visual *)CopyFromParent, valuemask, &attributes); + XGrabButton(dpy, 1, AnyModifier, icon_win, True, + ButtonPressMask | ButtonReleaseMask | ButtonMotionMask, + GrabModeAsync, GrabModeAsync, None, None); + XGrabButton(dpy, 2, AnyModifier, icon_win, True, + ButtonPressMask | ButtonReleaseMask | ButtonMotionMask, + GrabModeAsync, GrabModeAsync, None, None); + XGrabButton(dpy, 3, AnyModifier, icon_win, True, + ButtonPressMask | ButtonReleaseMask | ButtonMotionMask, + GrabModeAsync, GrabModeAsync, None, None); + if (!StartIconic) + wmhints.initial_state = NormalState; + else + wmhints.initial_state = IconicState; + wmhints.flags = 0; + if (icon_x > -10000) { + if (icon_x < 0) + icon_x = Scr.MyDisplayWidth + icon_x - icon_w; + if (icon_y > -10000) { + if (icon_y < 0) + icon_y = Scr.MyDisplayHeight + icon_y - icon_h; + } else + icon_y = 0; + wmhints.icon_x = icon_x; + wmhints.icon_y = icon_y; + wmhints.flags = IconPositionHint; + } + wmhints.icon_window = icon_win; + wmhints.input = False; + + wmhints.flags |= InputHint | StateHint | IconWindowHint; + + class1.res_name = MyName; + class1.res_class = "FvwmModule"; + + XSetWMProperties(dpy, Scr.Pager_w, &name, &name, NULL, 0, &sizehints, + &wmhints, &class1); + XFree((char *)name.value); + + for (i = 0; i < ndesks; i++) { + w = window_w / ndesks; + h = window_h; + x = w * i; + y = 0; + + valuemask = (CWBackPixel | CWBorderPixel | CWEventMask); + attributes.background_pixel = GetColor(Desks[i].Dcolor); + attributes.border_pixel = fore_pix; + attributes.event_mask = (ExposureMask | ButtonReleaseMask); + Desks[i].title_w = XCreateWindow(dpy, Scr.Pager_w, x, y, w, h, + 1, CopyFromParent, InputOutput, CopyFromParent, valuemask, + &attributes); + attributes.event_mask = (ExposureMask | ButtonReleaseMask | + ButtonPressMask | ButtonMotionMask); + desk_h = window_h - label_h; + Desks[i].w = XCreateWindow(dpy, Desks[i].title_w, x, y, w, + desk_h, 1, CopyFromParent, InputOutput, CopyFromParent, + valuemask, &attributes); + + attributes.event_mask = 0; + attributes.background_pixel = hi_pix; + + w = (window_w - n) / (n + 1); + h = (window_h - label_h - m) / (m + 1); + Desks[i].CPagerWin = XCreateWindow(dpy, Desks[i].w, -1000, + -1000, w, h, 0, CopyFromParent, InputOutput, CopyFromParent, + valuemask, &attributes); + XMapRaised(dpy, Desks[i].CPagerWin); + XMapRaised(dpy, Desks[i].w); + XMapRaised(dpy, Desks[i].title_w); + } + XMapRaised(dpy, Scr.Pager_w); + + gcm = GCForeground | GCBackground | GCFont; + gcv.foreground = fore_pix; + gcv.background = back_pix; + + gcv.font = font->fid; + NormalGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); + MiniIconGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); + + gcv.foreground = hi_pix; + if (Scr.d_depth < 2) { + gcv.foreground = fore_pix; + gcv.background = back_pix; + } + HiliteGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); + + if ((Scr.d_depth < 2) || (fore_pix == hi_pix)) + gcv.foreground = back_pix; + else + gcv.foreground = fore_pix; + rvGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); + + if (windowFont != NULL) { + /* Create GC's for doing window labels */ + gcv.foreground = focus_fore_pix; + gcv.background = focus_pix; + gcv.font = windowFont->fid; + StdGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); + } + + gcm = gcm | GCLineStyle; + gcv.foreground = fore_pix; + gcv.background = back_pix; + gcv.line_style = LineOnOffDash; + DashedGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); + + /* create balloon window + -- ric@giccs.georgetown.edu */ + if (ShowBalloons) { + valuemask = CWOverrideRedirect | CWEventMask | CWBackPixel | + CWBorderPixel; + + /* tell WM to ignore this window */ + attributes.override_redirect = True; + + attributes.event_mask = ExposureMask; + attributes.border_pixel = GetColor(BalloonBorderColor); + + /* if given in config set this now, otherwise it'll be set for + each pager window when drawn later */ + attributes.background_pixel = + (BalloonBack == NULL) ? 0 : GetColor(BalloonBack); + + /* get font for balloon */ + if ((balloon.font = XLoadQueryFont(dpy, BalloonFont)) == NULL) { + if ((balloon.font = XLoadQueryFont(dpy, "fixed")) == + NULL) { + fprintf(stderr, "%s: No fonts available.\n", + MyName); + exit(1); + } + fprintf(stderr, + "%s: Can't find font '%s', using fixed.\n", MyName, + BalloonFont); + } + + balloon.height = + balloon.font->ascent + balloon.font->descent + 1; + + /* this may have been set in config */ + balloon.border = BalloonBorderWidth; + + /* we don't allow yoffset of 0 because it allows direct transit + from pager window to balloon window, setting up a + LeaveNotify/EnterNotify event loop */ + if (BalloonYOffset) + balloon.yoffset = BalloonYOffset; + else { + fprintf(stderr, + "%s: Warning: you're not allowed BalloonYOffset 0; " + "defaulting to +2\n", + MyName); + balloon.yoffset = 2; + } + /* now create the window */ + balloon.w = + XCreateWindow(dpy, Scr.Root, 0, 0, /* coords set later */ + 1, /* width set later */ + balloon.height, balloon.border, CopyFromParent, + InputOutput, CopyFromParent, valuemask, &attributes); + + /* set font */ + gcv.font = balloon.font->fid; + + /* if fore given in config set now, otherwise it'll be set later + */ + gcv.foreground = + (BalloonFore == NULL) ? 0 : GetColor(BalloonFore); + + BalloonGC = + XCreateGC(dpy, balloon.w, GCFont | GCForeground, &gcv); + + /* Make sure we don't get balloons initially with the Icon + * option. */ + ShowBalloons = ShowPagerBalloons; + } /* ShowBalloons */ +} /**************************************************************************** * * Loads a single color * ****************************************************************************/ -Pixel GetColor(char *name) +Pixel +GetColor(char *name) { - XColor color; - XWindowAttributes attributes; - - XGetWindowAttributes(dpy,Scr.Root,&attributes); - color.pixel = 0; - if (!XParseColor (dpy, attributes.colormap, name, &color)) - { - nocolor("parse",name); - } - else if(!XAllocColor (dpy, attributes.colormap, &color)) - { - nocolor("alloc",name); - } - return color.pixel; + XColor color; + XWindowAttributes attributes; + + XGetWindowAttributes(dpy, Scr.Root, &attributes); + color.pixel = 0; + if (!XParseColor(dpy, attributes.colormap, name, &color)) { + nocolor("parse", name); + } else if (!XAllocColor(dpy, attributes.colormap, &color)) { + nocolor("alloc", name); + } + return color.pixel; } - -void nocolor(char *a, char *b) +void +nocolor(char *a, char *b) { - fprintf(stderr,"%s: can't %s %s\n", MyName, a,b); + fprintf(stderr, "%s: can't %s %s\n", MyName, a, b); } /**************************************************************************** @@ -528,335 +483,318 @@ void nocolor(char *a, char *b) * Decide what to do about received X events * ****************************************************************************/ -void DispatchEvent(XEvent *Event) +void +DispatchEvent(XEvent *Event) { - int i,x,y; - Window JunkRoot, JunkChild; - int JunkX, JunkY; - unsigned JunkMask; - - switch(Event->xany.type) - { - case EnterNotify: - if ( ShowBalloons ) - MapBalloonWindow(Event); - break; - case LeaveNotify: - if ( ShowBalloons ) - UnmapBalloonWindow(); - break; - case ConfigureNotify: - ReConfigure(); - break; - case Expose: - HandleExpose(Event); - break; - case ButtonRelease: - if((Event->xbutton.button == 1)|| - (Event->xbutton.button == 2)) - { - for(i=0;ixany.window == Desks[i].w) - SwitchToDeskAndPage(i,Event); - if(Event->xany.window == Desks[i].title_w) - SwitchToDesk(i); - } - if(Event->xany.window == icon_win) - { - IconSwitchPage(Event); - } - } - else if (Event->xbutton.button == 3) - { - for(i=0;ixany.window == Desks[i].w) - { - XQueryPointer(dpy, Desks[i].w, &JunkRoot, &JunkChild, - &JunkX, &JunkY,&x, &y, &JunkMask); - Scroll(desk_w, desk_h, x, y, i); + int i, x, y; + Window JunkRoot, JunkChild; + int JunkX, JunkY; + unsigned JunkMask; + + switch (Event->xany.type) { + case EnterNotify: + if (ShowBalloons) + MapBalloonWindow(Event); + break; + case LeaveNotify: + if (ShowBalloons) + UnmapBalloonWindow(); + break; + case ConfigureNotify: + ReConfigure(); + break; + case Expose: + HandleExpose(Event); + break; + case ButtonRelease: + if ((Event->xbutton.button == 1) || + (Event->xbutton.button == 2)) { + for (i = 0; i < ndesks; i++) { + if (Event->xany.window == Desks[i].w) + SwitchToDeskAndPage(i, Event); + if (Event->xany.window == Desks[i].title_w) + SwitchToDesk(i); + } + if (Event->xany.window == icon_win) { + IconSwitchPage(Event); + } + } else if (Event->xbutton.button == 3) { + for (i = 0; i < ndesks; i++) { + if (Event->xany.window == Desks[i].w) { + XQueryPointer(dpy, Desks[i].w, + &JunkRoot, &JunkChild, &JunkX, + &JunkY, &x, &y, &JunkMask); + Scroll(desk_w, desk_h, x, y, i); + } + } + if (Event->xany.window == icon_win) { + XQueryPointer(dpy, icon_win, &JunkRoot, + &JunkChild, &JunkX, &JunkY, &x, &y, + &JunkMask); + Scroll(icon_w, icon_h, x, y, -1); + } } - } - if(Event->xany.window == icon_win) - { - XQueryPointer(dpy, icon_win, &JunkRoot, &JunkChild, - &JunkX, &JunkY,&x, &y, &JunkMask); - Scroll(icon_w, icon_h, x, y, -1); - } - } - break; - case ButtonPress: - if ( ShowBalloons ) - UnmapBalloonWindow(); - if (((Event->xbutton.button == 2)|| - ((Event->xbutton.button == 3)&& - (Event->xbutton.state & Mod1Mask)))&& - (Event->xbutton.subwindow != None)) - { - MoveWindow(Event); - } - else if (Event->xbutton.button == 3) - { - for(i=0;ixany.window == Desks[i].w) - { - if (Scr.CurrentDesk != i + desk1) - { - SwitchToDeskAndPage(i,Event); - Scr.CurrentDesk = i + desk1; - Wait = 0; - } - XQueryPointer(dpy, Desks[i].w, &JunkRoot, &JunkChild, - &JunkX, &JunkY,&x, &y, &JunkMask); - Scroll(desk_w, desk_h, x, y, i); - break; + break; + case ButtonPress: + if (ShowBalloons) + UnmapBalloonWindow(); + if (((Event->xbutton.button == 2) || + ((Event->xbutton.button == 3) && + (Event->xbutton.state & Mod1Mask))) && + (Event->xbutton.subwindow != None)) { + MoveWindow(Event); + } else if (Event->xbutton.button == 3) { + for (i = 0; i < ndesks; i++) { + if (Event->xany.window == Desks[i].w) { + if (Scr.CurrentDesk != i + desk1) { + SwitchToDeskAndPage(i, Event); + Scr.CurrentDesk = i + desk1; + Wait = 0; + } + XQueryPointer(dpy, Desks[i].w, + &JunkRoot, &JunkChild, &JunkX, + &JunkY, &x, &y, &JunkMask); + Scroll(desk_w, desk_h, x, y, i); + break; + } + } + if (Event->xany.window == icon_win) { + XQueryPointer(dpy, icon_win, &JunkRoot, + &JunkChild, &JunkX, &JunkY, &x, &y, + &JunkMask); + Scroll(icon_w, icon_h, x, y, -1); + } } - } - if(Event->xany.window == icon_win) - { - XQueryPointer(dpy, icon_win, &JunkRoot, &JunkChild, - &JunkX, &JunkY,&x, &y, &JunkMask); - Scroll(icon_w, icon_h, x, y, -1); - } - } - break; - case MotionNotify: - while(XCheckMaskEvent(dpy, PointerMotionMask | ButtonMotionMask,Event)); - - if(Event->xmotion.state == Button3MotionMask) - { - for(i=0;ixany.window == Desks[i].w) - { - XQueryPointer(dpy, Desks[i].w, &JunkRoot, &JunkChild, - &JunkX, &JunkY,&x, &y, &JunkMask); - Scroll(desk_w, desk_h, x, y, i); + break; + case MotionNotify: + while (XCheckMaskEvent( + dpy, PointerMotionMask | ButtonMotionMask, Event)) + ; + + if (Event->xmotion.state == Button3MotionMask) { + for (i = 0; i < ndesks; i++) { + if (Event->xany.window == Desks[i].w) { + XQueryPointer(dpy, Desks[i].w, + &JunkRoot, &JunkChild, &JunkX, + &JunkY, &x, &y, &JunkMask); + Scroll(desk_w, desk_h, x, y, i); + } + } + if (Event->xany.window == icon_win) { + XQueryPointer(dpy, icon_win, &JunkRoot, + &JunkChild, &JunkX, &JunkY, &x, &y, + &JunkMask); + Scroll(icon_w, icon_h, x, y, -1); + } } - } - if(Event->xany.window == icon_win) - { - XQueryPointer(dpy, icon_win, &JunkRoot, &JunkChild, - &JunkX, &JunkY,&x, &y, &JunkMask); - Scroll(icon_w, icon_h, x, y, -1); - } + break; + case ClientMessage: + if ((Event->xclient.format == 32) && + (Event->xclient.data.l[0] == wm_del_win)) { + exit(0); + } + break; } - break; - - case ClientMessage: - if ((Event->xclient.format==32) && - (Event->xclient.data.l[0]==wm_del_win)) - { - exit(0); - } - break; - } } -void HandleExpose(XEvent *Event) +void +HandleExpose(XEvent *Event) { - int i; - PagerWindow *t; - - /* ric@giccs.georgetown.edu */ - if ( Event->xany.window == balloon.w ) { - DrawInBalloonWindow(); - return; - } - - for(i=0;ixany.window == Desks[i].w) - ||(Event->xany.window == Desks[i].title_w)) - DrawGrid(i,0); - } - if(Event->xany.window == icon_win) - DrawIconGrid(0); - - t = Start; - while(t!= NULL) - { - if(t->PagerView == Event->xany.window) - { - LabelWindow(t); - PictureWindow(t); + int i; + PagerWindow *t; + + /* ric@giccs.georgetown.edu */ + if (Event->xany.window == balloon.w) { + DrawInBalloonWindow(); + return; } - else if(t->IconView == Event->xany.window) - { - LabelIconWindow(t); - PictureIconWindow(t); + + for (i = 0; i < ndesks; i++) { + if ((Event->xany.window == Desks[i].w) || + (Event->xany.window == Desks[i].title_w)) + DrawGrid(i, 0); } + if (Event->xany.window == icon_win) + DrawIconGrid(0); + + t = Start; + while (t != NULL) { + if (t->PagerView == Event->xany.window) { + LabelWindow(t); + PictureWindow(t); + } else if (t->IconView == Event->xany.window) { + LabelIconWindow(t); + PictureIconWindow(t); + } - t = t->next; - } + t = t->next; + } } - /**************************************************************************** * * Respond to a change in window geometry. * ****************************************************************************/ -void ReConfigure(void) +void +ReConfigure(void) { - Window root; - unsigned border_width, depth; - int n,m,w,h,n1,m1,x,y,i,j,k; - - - XGetGeometry(dpy,Scr.Pager_w,&root,&x,&y, - (unsigned *)&window_w,(unsigned *)&window_h, - &border_width,&depth); - - - n1 = Scr.Vx/Scr.MyDisplayWidth; - m1 = Scr.Vy/Scr.MyDisplayHeight; - n = (Scr.VxMax)/Scr.MyDisplayWidth; - m = (Scr.VyMax)/Scr.MyDisplayHeight; - desk_w = (window_w - Columns + 1)/Columns; - desk_h = (window_h - Rows*label_h - Rows + 2)/Rows; - w = (desk_w - n)/(n+1); - h = (desk_h - m)/(m+1); - - sizehints.width_inc = Columns*(n+1); - sizehints.height_inc = Rows*(m+1); - sizehints.base_width = Columns * n + Columns - 1; - sizehints.base_height = Rows*(m + label_h+1) -2; - sizehints.min_width = Columns * n + Columns - 1; - sizehints.min_height = Rows*(m + label_h+1) -2; - - XSetWMNormalHints(dpy,Scr.Pager_w,&sizehints); - - x = (desk_w-n)* Scr.Vx/(Scr.VxMax+Scr.MyDisplayWidth) +n1; - y = (desk_h-m)*Scr.Vy/(Scr.VyMax+Scr.MyDisplayHeight) +m1; - - for(k=0;k= desk1)&&(Scr.CurrentDesk <=desk2)) - sptr = Desks[Scr.CurrentDesk -desk1].label; - else - { - sprintf(str,"Desk %d",Scr.CurrentDesk); - sptr = &str[0]; + int n1, m1, x, y, n, m, i; + XTextProperty name; + char str[100], *sptr; + static int icon_desk_shown = -1000; + + Wait = 0; + n1 = Scr.Vx / Scr.MyDisplayWidth; + m1 = Scr.Vy / Scr.MyDisplayHeight; + n = (Scr.VxMax) / Scr.MyDisplayWidth; + m = (Scr.VyMax) / Scr.MyDisplayHeight; + + x = (desk_w - n) * Scr.Vx / (Scr.VxMax + Scr.MyDisplayWidth) + n1; + y = (desk_h - m) * Scr.Vy / (Scr.VyMax + Scr.MyDisplayHeight) + m1; + for (i = 0; i < ndesks; i++) { + if (i == Scr.CurrentDesk - desk1) { + XMoveWindow(dpy, Desks[i].CPagerWin, x, y); + XLowerWindow(dpy, Desks[i].CPagerWin); + } else + XMoveWindow(dpy, Desks[i].CPagerWin, -1000, -1000); } - if (XStringListToTextProperty(&sptr,1,&name) == 0) - { - fprintf(stderr,"%s: cannot allocate window name",MyName); - return; + DrawIconGrid(1); + + ReConfigureIcons(); + + if (Scr.CurrentDesk != icon_desk_shown) { + icon_desk_shown = Scr.CurrentDesk; + + if ((Scr.CurrentDesk >= desk1) && (Scr.CurrentDesk <= desk2)) + sptr = Desks[Scr.CurrentDesk - desk1].label; + else { + snprintf(str, sizeof(str), "Desk %d", Scr.CurrentDesk); + sptr = &str[0]; + } + if (XStringListToTextProperty(&sptr, 1, &name) == 0) { + fprintf( + stderr, "%s: cannot allocate window name", MyName); + return; + } + XSetWMIconName(dpy, Scr.Pager_w, &name); } - XSetWMIconName(dpy,Scr.Pager_w,&name); - } } -void ReConfigureAll(void) +void +ReConfigureAll(void) { - PagerWindow *t; - - t = Start; - while(t!= NULL) - { - MoveResizePagerView(t); - t = t->next; - } + PagerWindow *t; + + t = Start; + while (t != NULL) { + MoveResizePagerView(t); + t = t->next; + } } -void ReConfigureIcons(void) +void +ReConfigureIcons(void) { - PagerWindow *t; - int x,y,w,h,n,m,n1,m1; - - n = (Scr.VxMax)/Scr.MyDisplayWidth; - m = (Scr.VyMax)/Scr.MyDisplayHeight; - - t = Start; - while(t!= NULL) - { - n1 = (Scr.Vx+t->x)/Scr.MyDisplayWidth; - m1 = (Scr.Vy+t->y)/Scr.MyDisplayHeight; - x = (Scr.Vx + t->x)*(icon_w-n)/(Scr.VxMax + Scr.MyDisplayWidth) +n1; - y = (Scr.Vy + t->y)*(icon_h-m)/(Scr.VyMax + Scr.MyDisplayHeight)+m1; - w = (Scr.Vx + t->x + t->width+2)*(icon_w-n)/ - (Scr.VxMax + Scr.MyDisplayWidth) - 2 - x + n1; - h = (Scr.Vy + t->y + t->height+2)*(icon_h-m)/ - (Scr.VyMax + Scr.MyDisplayHeight) -2 - y +m1; - - if (w < 1) - w = 1; - if (h < 1) - h = 1; - - t->icon_view_width = w; - t->icon_view_height = h; - if(Scr.CurrentDesk == t->desk) - XMoveResizeWindow(dpy,t->IconView,x,y,w,h); - else - XMoveResizeWindow(dpy,t->IconView,-1000,-1000,w,h); - t = t->next; - } + PagerWindow *t; + int x, y, w, h, n, m, n1, m1; + + n = (Scr.VxMax) / Scr.MyDisplayWidth; + m = (Scr.VyMax) / Scr.MyDisplayHeight; + + t = Start; + while (t != NULL) { + n1 = (Scr.Vx + t->x) / Scr.MyDisplayWidth; + m1 = (Scr.Vy + t->y) / Scr.MyDisplayHeight; + x = (Scr.Vx + t->x) * (icon_w - n) / + (Scr.VxMax + Scr.MyDisplayWidth) + + n1; + y = (Scr.Vy + t->y) * (icon_h - m) / + (Scr.VyMax + Scr.MyDisplayHeight) + + m1; + w = (Scr.Vx + t->x + t->width + 2) * (icon_w - n) / + (Scr.VxMax + Scr.MyDisplayWidth) - + 2 - x + n1; + h = (Scr.Vy + t->y + t->height + 2) * (icon_h - m) / + (Scr.VyMax + Scr.MyDisplayHeight) - + 2 - y + m1; + + if (w < 1) + w = 1; + if (h < 1) + h = 1; + + t->icon_view_width = w; + t->icon_view_height = h; + if (Scr.CurrentDesk == t->desk) + XMoveResizeWindow(dpy, t->IconView, x, y, w, h); + else + XMoveResizeWindow(dpy, t->IconView, -1000, -1000, w, h); + t = t->next; + } } /**************************************************************************** @@ -864,1177 +802,1110 @@ void ReConfigureIcons(void) * Draw grid lines for desk #i * ****************************************************************************/ -void DrawGrid(int i, int erase) +void +DrawGrid(int i, int erase) { - int y, y1, y2, x, x1, x2,d,hor_off,w; - int MaxW,MaxH; - char str[15], *ptr; - - if((i < 0 ) ||(i >= ndesks)) - return; - - MaxW = (Scr.VxMax + Scr.MyDisplayWidth); - MaxH = Scr.VyMax + Scr.MyDisplayHeight; - - x = Scr.MyDisplayWidth; - y1 = 0; - y2 = desk_h; - while(x < MaxW) - { - x1 = x*desk_w/MaxW; - XDrawLine(dpy,Desks[i].w,DashedGC,x1,y1,x1,y2); - x += Scr.MyDisplayWidth; - } - - y = Scr.MyDisplayHeight; - x1 = 0; - x2 = desk_w; - while(y < MaxH) - { - y1 = y*(desk_h)/MaxH; - XDrawLine(dpy,Desks[i].w,DashedGC,x1,y1,x2,y1); - y += Scr.MyDisplayHeight; - } - if((Scr.CurrentDesk - desk1) == i) - { - if(uselabel) - XFillRectangle(dpy,Desks[i].title_w,HiliteGC, - 0,0,desk_w,label_h -1); - } - else - { - if(uselabel && erase) - XClearArea(dpy,Desks[i].title_w, - 0,0,desk_w,label_h - 1,False); - } - - d = desk1+i; - ptr = Desks[i].label; - w=XTextWidth(font,ptr,strlen(ptr)); - if( w > desk_w) - { - sprintf(str,"%d",d); - ptr = str; - w=XTextWidth(font,ptr,strlen(ptr)); - } - if((w<= desk_w)&&(uselabel)) - { - hor_off = (desk_w -w)/2; - if(i == (Scr.CurrentDesk - desk1)) - XDrawString (dpy, Desks[i].title_w,rvGC,hor_off,font->ascent +1 , - ptr, strlen(ptr)); - else - XDrawString (dpy, Desks[i].title_w,NormalGC,hor_off,font->ascent+1 , - ptr, strlen(ptr)); - } -} + int y, y1, y2, x, x1, x2, d, hor_off, w; + int MaxW, MaxH; + char str[15], *ptr; + + if ((i < 0) || (i >= ndesks)) + return; + + MaxW = (Scr.VxMax + Scr.MyDisplayWidth); + MaxH = Scr.VyMax + Scr.MyDisplayHeight; + + x = Scr.MyDisplayWidth; + y1 = 0; + y2 = desk_h; + while (x < MaxW) { + x1 = x * desk_w / MaxW; + XDrawLine(dpy, Desks[i].w, DashedGC, x1, y1, x1, y2); + x += Scr.MyDisplayWidth; + } + y = Scr.MyDisplayHeight; + x1 = 0; + x2 = desk_w; + while (y < MaxH) { + y1 = y * (desk_h) / MaxH; + XDrawLine(dpy, Desks[i].w, DashedGC, x1, y1, x2, y1); + y += Scr.MyDisplayHeight; + } + if ((Scr.CurrentDesk - desk1) == i) { + if (uselabel) + XFillRectangle(dpy, Desks[i].title_w, HiliteGC, 0, 0, + desk_w, label_h - 1); + } else { + if (uselabel && erase) + XClearArea(dpy, Desks[i].title_w, 0, 0, desk_w, + label_h - 1, False); + } -void DrawIconGrid(int erase) + d = desk1 + i; + ptr = Desks[i].label; + w = XTextWidth(font, ptr, strlen(ptr)); + if (w > desk_w) { + snprintf(str, sizeof(str), "%d", d); + ptr = str; + w = XTextWidth(font, ptr, strlen(ptr)); + } + if ((w <= desk_w) && (uselabel)) { + hor_off = (desk_w - w) / 2; + if (i == (Scr.CurrentDesk - desk1)) + XDrawString(dpy, Desks[i].title_w, rvGC, hor_off, + font->ascent + 1, ptr, strlen(ptr)); + else + XDrawString(dpy, Desks[i].title_w, NormalGC, hor_off, + font->ascent + 1, ptr, strlen(ptr)); + } +} + +void +DrawIconGrid(int erase) { - int y, y1, y2, x, x1, x2,w,h,n,m,n1,m1; - int MaxW,MaxH; - - MaxW = (Scr.VxMax + Scr.MyDisplayWidth); - MaxH = Scr.VyMax + Scr.MyDisplayHeight; - - if(erase) - XClearWindow(dpy,icon_win); - x = Scr.MyDisplayWidth; - y1 = 0; - y2 = icon_h; - while(x < MaxW) - { - x1 = x*icon_w/MaxW; - XDrawLine(dpy,icon_win,DashedGC,x1,y1,x1,y2); - x += Scr.MyDisplayWidth; - } - - y = Scr.MyDisplayHeight; - x1 = 0; - x2 = icon_w; - while(y < MaxH) - { - y1 = y*(icon_h)/MaxH; - XDrawLine(dpy,icon_win,DashedGC,x1,y1,x2,y1); - y += Scr.MyDisplayHeight; - } - n1 = Scr.Vx/Scr.MyDisplayWidth; - m1 = Scr.Vy/Scr.MyDisplayHeight; - n = (Scr.VxMax)/Scr.MyDisplayWidth; - m = (Scr.VyMax)/Scr.MyDisplayHeight; - w = (icon_w - n)/(n+1); - h = (icon_h - m)/(m+1); - - x = (icon_w-n)* Scr.Vx/(Scr.VxMax+Scr.MyDisplayWidth) +n1; - y = (icon_h-m)*Scr.Vy/(Scr.VyMax+Scr.MyDisplayHeight) +m1; - - XFillRectangle(dpy,icon_win,HiliteGC, - x,y,w,h); + int y, y1, y2, x, x1, x2, w, h, n, m, n1, m1; + int MaxW, MaxH; + + MaxW = (Scr.VxMax + Scr.MyDisplayWidth); + MaxH = Scr.VyMax + Scr.MyDisplayHeight; + + if (erase) + XClearWindow(dpy, icon_win); + x = Scr.MyDisplayWidth; + y1 = 0; + y2 = icon_h; + while (x < MaxW) { + x1 = x * icon_w / MaxW; + XDrawLine(dpy, icon_win, DashedGC, x1, y1, x1, y2); + x += Scr.MyDisplayWidth; + } -} + y = Scr.MyDisplayHeight; + x1 = 0; + x2 = icon_w; + while (y < MaxH) { + y1 = y * (icon_h) / MaxH; + XDrawLine(dpy, icon_win, DashedGC, x1, y1, x2, y1); + y += Scr.MyDisplayHeight; + } + n1 = Scr.Vx / Scr.MyDisplayWidth; + m1 = Scr.Vy / Scr.MyDisplayHeight; + n = (Scr.VxMax) / Scr.MyDisplayWidth; + m = (Scr.VyMax) / Scr.MyDisplayHeight; + w = (icon_w - n) / (n + 1); + h = (icon_h - m) / (m + 1); + x = (icon_w - n) * Scr.Vx / (Scr.VxMax + Scr.MyDisplayWidth) + n1; + y = (icon_h - m) * Scr.Vy / (Scr.VyMax + Scr.MyDisplayHeight) + m1; -void SwitchToDesk(int Desk) + XFillRectangle(dpy, icon_win, HiliteGC, x, y, w, h); +} + +void +SwitchToDesk(int Desk) { - char command[256]; + char command[256]; - sprintf(command,"Desk 0 %d\n",Desk+desk1); + snprintf(command, sizeof(command), "Desk 0 %d\n", Desk + desk1); - SendInfo(fd,command,0); + SendInfo(fd, command, 0); } - -void SwitchToDeskAndPage(int Desk, XEvent *Event) +void +SwitchToDeskAndPage(int Desk, XEvent *Event) { #ifndef NON_VIRTUAL - char command[256]; - - if (Scr.CurrentDesk != (Desk+desk1)) - { - int vx, vy; - SendInfo(fd,"Desk 0 10000\n",0); - /* patch to let mouse button 3 change desks and do not cling to a page */ - vx = Event->xbutton.x*(Scr.VxMax+Scr.MyDisplayWidth)/ - (desk_w*Scr.MyDisplayWidth); - vy = Event->xbutton.y*(Scr.VyMax+Scr.MyDisplayHeight)/ - (desk_h*Scr.MyDisplayHeight); - Scr.Vx = vx * Scr.MyDisplayWidth; - Scr.Vy = vy * Scr.MyDisplayHeight; - sprintf(command,"GotoPage %d %d\n", vx, vy); - SendInfo(fd,command,0); - sprintf(command,"Desk 0 %d\n",Desk+desk1); - SendInfo(fd,command,0); - - } - else - { - sprintf(command,"GotoPage %d %d\n", - Event->xbutton.x*(Scr.VxMax+Scr.MyDisplayWidth)/ - (desk_w*Scr.MyDisplayWidth), - Event->xbutton.y*(Scr.VyMax+Scr.MyDisplayHeight)/ - (desk_h*Scr.MyDisplayHeight)); - SendInfo(fd,command,0); - } + char command[256]; + + if (Scr.CurrentDesk != (Desk + desk1)) { + int vx, vy; + SendInfo(fd, "Desk 0 10000\n", 0); + /* patch to let mouse button 3 change desks and do not cling to + * a page */ + vx = Event->xbutton.x * (Scr.VxMax + Scr.MyDisplayWidth) / + (desk_w * Scr.MyDisplayWidth); + vy = Event->xbutton.y * (Scr.VyMax + Scr.MyDisplayHeight) / + (desk_h * Scr.MyDisplayHeight); + Scr.Vx = vx * Scr.MyDisplayWidth; + Scr.Vy = vy * Scr.MyDisplayHeight; + snprintf(command, sizeof(command), "GotoPage %d %d\n", vx, vy); + SendInfo(fd, command, 0); + snprintf(command, sizeof(command), "Desk 0 %d\n", Desk + desk1); + SendInfo(fd, command, 0); + } else { + snprintf(command, sizeof(command), "GotoPage %d %d\n", + Event->xbutton.x * (Scr.VxMax + Scr.MyDisplayWidth) / + (desk_w * Scr.MyDisplayWidth), + Event->xbutton.y * (Scr.VyMax + Scr.MyDisplayHeight) / + (desk_h * Scr.MyDisplayHeight)); + SendInfo(fd, command, 0); + } #endif - Wait = 1; + Wait = 1; } -void IconSwitchPage(XEvent *Event) +void +IconSwitchPage(XEvent *Event) { #ifndef NON_VIRTUAL - char command[256]; - - sprintf(command,"GotoPage %d %d\n", - Event->xbutton.x*(Scr.VxMax+Scr.MyDisplayWidth)/ - (icon_w*Scr.MyDisplayWidth), - Event->xbutton.y*(Scr.VyMax+Scr.MyDisplayHeight)/ - (icon_h*Scr.MyDisplayHeight)); - SendInfo(fd,command,0); + char command[256]; + + snprintf(command, sizeof(command), "GotoPage %d %d\n", + Event->xbutton.x * (Scr.VxMax + Scr.MyDisplayWidth) / + (icon_w * Scr.MyDisplayWidth), + Event->xbutton.y * (Scr.VyMax + Scr.MyDisplayHeight) / + (icon_h * Scr.MyDisplayHeight)); + SendInfo(fd, command, 0); #endif - Wait = 1; + Wait = 1; } - -void AddNewWindow(PagerWindow *t) +void +AddNewWindow(PagerWindow *t) { - unsigned long valuemask; - XSetWindowAttributes attributes; - int i,x,y,w,h,n,m,n1,m1; - - i = t->desk - desk1; - n = (Scr.VxMax)/Scr.MyDisplayWidth; - m = (Scr.VyMax)/Scr.MyDisplayHeight; - n1 = (Scr.Vx+t->x)/Scr.MyDisplayWidth; - m1 = (Scr.Vy+t->y)/Scr.MyDisplayHeight; - x = (Scr.Vx + t->x)*(desk_w-n)/(Scr.VxMax + Scr.MyDisplayWidth) +n1; - y = (Scr.Vy + t->y)*(desk_h-m)/(Scr.VyMax + Scr.MyDisplayHeight)+m1; - w = (Scr.Vx + t->x + t->width+2)*(desk_w-n)/ - (Scr.VxMax + Scr.MyDisplayWidth) - 2 - x + n1; - h = (Scr.Vy + t->y + t->height+2)*(desk_h-m)/ - (Scr.VyMax + Scr.MyDisplayHeight) -2 - y +m1; - if(w<1) - w = 1; - if(h<1) - h = 1; - - t->pager_view_width = w; - t->pager_view_height = h; - valuemask = (CWBackPixel | CWBorderPixel | CWEventMask); - attributes.background_pixel = t->back; - attributes.border_pixel = fore_pix; - attributes.event_mask = (ExposureMask); - - /* ric@giccs.georgetown.edu -- added Enter and Leave events for - popping up balloon window */ - attributes.event_mask = (ExposureMask | EnterWindowMask | LeaveWindowMask); - - if((i >= 0)&& (i PagerView = XCreateWindow(dpy,Desks[i].w, x, y, w, h,1, - CopyFromParent, - InputOutput,CopyFromParent, - valuemask,&attributes); - - XMapRaised(dpy,t->PagerView); - } - else - t->PagerView = None; - - - x = (Scr.Vx + t->x)*(icon_w-n)/(Scr.VxMax + Scr.MyDisplayWidth) +n1; - y = (Scr.Vy + t->y)*(icon_h-m)/(Scr.VyMax + Scr.MyDisplayHeight)+m1; - w = (Scr.Vx + t->x + t->width+2)*(icon_w-n)/ - (Scr.VxMax + Scr.MyDisplayWidth) - 2 - x + n1; - h = (Scr.Vy + t->y + t->height+2)*(icon_h-m)/ - (Scr.VyMax + Scr.MyDisplayHeight) -2 - y +m1; - if(w<1) - w = 1; - if(h<1) - h = 1; - - t->icon_view_width = w; - t->icon_view_height = h; - if(Scr.CurrentDesk == t->desk) - { - t->IconView = XCreateWindow(dpy,icon_win, x, y, w, h,1, - CopyFromParent, - InputOutput,CopyFromParent, - valuemask,&attributes); - XGrabButton(dpy, 2, AnyModifier, t->IconView, - True, ButtonPressMask | ButtonReleaseMask|ButtonMotionMask, - GrabModeAsync, GrabModeAsync, None, - None); - XMapRaised(dpy,t->IconView); - } - else - { - t->IconView = XCreateWindow(dpy,icon_win, -1000, -1000, w, h,1, - CopyFromParent, - InputOutput,CopyFromParent, - valuemask,&attributes); - XMapRaised(dpy,t->IconView); - } - Hilight(t,OFF); + unsigned long valuemask; + XSetWindowAttributes attributes; + int i, x, y, w, h, n, m, n1, m1; + + i = t->desk - desk1; + n = (Scr.VxMax) / Scr.MyDisplayWidth; + m = (Scr.VyMax) / Scr.MyDisplayHeight; + n1 = (Scr.Vx + t->x) / Scr.MyDisplayWidth; + m1 = (Scr.Vy + t->y) / Scr.MyDisplayHeight; + x = (Scr.Vx + t->x) * (desk_w - n) / (Scr.VxMax + Scr.MyDisplayWidth) + + n1; + y = (Scr.Vy + t->y) * (desk_h - m) / (Scr.VyMax + Scr.MyDisplayHeight) + + m1; + w = (Scr.Vx + t->x + t->width + 2) * (desk_w - n) / + (Scr.VxMax + Scr.MyDisplayWidth) - + 2 - x + n1; + h = (Scr.Vy + t->y + t->height + 2) * (desk_h - m) / + (Scr.VyMax + Scr.MyDisplayHeight) - + 2 - y + m1; + if (w < 1) + w = 1; + if (h < 1) + h = 1; + + t->pager_view_width = w; + t->pager_view_height = h; + valuemask = (CWBackPixel | CWBorderPixel | CWEventMask); + attributes.background_pixel = t->back; + attributes.border_pixel = fore_pix; + attributes.event_mask = (ExposureMask); + + /* ric@giccs.georgetown.edu -- added Enter and Leave events for + popping up balloon window */ + attributes.event_mask = + (ExposureMask | EnterWindowMask | LeaveWindowMask); + + if ((i >= 0) && (i < ndesks)) { + t->PagerView = XCreateWindow(dpy, Desks[i].w, x, y, w, h, 1, + CopyFromParent, InputOutput, CopyFromParent, valuemask, + &attributes); + + XMapRaised(dpy, t->PagerView); + } else + t->PagerView = None; + + x = (Scr.Vx + t->x) * (icon_w - n) / (Scr.VxMax + Scr.MyDisplayWidth) + + n1; + y = (Scr.Vy + t->y) * (icon_h - m) / (Scr.VyMax + Scr.MyDisplayHeight) + + m1; + w = (Scr.Vx + t->x + t->width + 2) * (icon_w - n) / + (Scr.VxMax + Scr.MyDisplayWidth) - + 2 - x + n1; + h = (Scr.Vy + t->y + t->height + 2) * (icon_h - m) / + (Scr.VyMax + Scr.MyDisplayHeight) - + 2 - y + m1; + if (w < 1) + w = 1; + if (h < 1) + h = 1; + + t->icon_view_width = w; + t->icon_view_height = h; + if (Scr.CurrentDesk == t->desk) { + t->IconView = + XCreateWindow(dpy, icon_win, x, y, w, h, 1, CopyFromParent, + InputOutput, CopyFromParent, valuemask, &attributes); + XGrabButton(dpy, 2, AnyModifier, t->IconView, True, + ButtonPressMask | ButtonReleaseMask | ButtonMotionMask, + GrabModeAsync, GrabModeAsync, None, None); + XMapRaised(dpy, t->IconView); + } else { + t->IconView = XCreateWindow(dpy, icon_win, -1000, -1000, w, h, + 1, CopyFromParent, InputOutput, CopyFromParent, valuemask, + &attributes); + XMapRaised(dpy, t->IconView); + } + Hilight(t, OFF); } +void +ChangeDeskForWindow(PagerWindow *t, long newdesk) +{ + int i, x, y, w, h, n, m, n1, m1; + i = newdesk - desk1; -void ChangeDeskForWindow(PagerWindow *t,long newdesk) -{ - int i,x,y,w,h,n,m,n1,m1; - - i = newdesk - desk1; - - if(t->PagerView == None) - { - t->desk = newdesk; - XDestroyWindow(dpy,t->IconView); - AddNewWindow( t); - return; - } - - n = (Scr.VxMax)/Scr.MyDisplayWidth; - m = (Scr.VyMax)/Scr.MyDisplayHeight; - n1 = (Scr.Vx+t->x)/Scr.MyDisplayWidth; - m1 = (Scr.Vy+t->y)/Scr.MyDisplayHeight; - x = (Scr.Vx + t->x)*(desk_w-n)/(Scr.VxMax + Scr.MyDisplayWidth) +n1; - y = (Scr.Vy + t->y)*(desk_h-m)/(Scr.VyMax + Scr.MyDisplayHeight)+m1; - w = (Scr.Vx + t->x + t->width+2)*(desk_w-n) / - (Scr.VxMax + Scr.MyDisplayWidth) - 2 - x + n1; - h = (Scr.Vy + t->y + t->height+2)*(desk_h-m) / - (Scr.VyMax + Scr.MyDisplayHeight) -2 - y +m1; - if (w < 1) - w = 1; - if (h < 1) - h = 1; - t->pager_view_width = w; - t->pager_view_height = h; - if((i >= 0)&&(i < ndesks)) - { - XReparentWindow(dpy, t->PagerView, Desks[i].w, x,y); - XResizeWindow(dpy,t->PagerView,w,h); - } - else - { - XDestroyWindow(dpy,t->PagerView); - t->PagerView = None; - } - t->desk = i+desk1; - - x = (Scr.Vx + t->x)*(icon_w-n)/(Scr.VxMax + Scr.MyDisplayWidth) +n1; - y = (Scr.Vy + t->y)*(icon_h-m)/(Scr.VyMax + Scr.MyDisplayHeight)+m1; - w = (Scr.Vx + t->x + t->width+2)*(icon_w-n) / - (Scr.VxMax + Scr.MyDisplayWidth) - 2 - x + n1; - h = (Scr.Vy + t->y + t->height+2)*(icon_h-m) / - (Scr.VyMax + Scr.MyDisplayHeight) -2 - y +m1; - if (w < 1) - w = 1; - if (h < 1) - h = 1; - t->icon_view_width = w; - t->icon_view_height = h; - if(Scr.CurrentDesk == t->desk) - XMoveResizeWindow(dpy,t->IconView,x,y,w,h); - else - XMoveResizeWindow(dpy,t->IconView,-1000,-1000,w,h); + if (t->PagerView == None) { + t->desk = newdesk; + XDestroyWindow(dpy, t->IconView); + AddNewWindow(t); + return; + } + + n = (Scr.VxMax) / Scr.MyDisplayWidth; + m = (Scr.VyMax) / Scr.MyDisplayHeight; + n1 = (Scr.Vx + t->x) / Scr.MyDisplayWidth; + m1 = (Scr.Vy + t->y) / Scr.MyDisplayHeight; + x = (Scr.Vx + t->x) * (desk_w - n) / (Scr.VxMax + Scr.MyDisplayWidth) + + n1; + y = (Scr.Vy + t->y) * (desk_h - m) / (Scr.VyMax + Scr.MyDisplayHeight) + + m1; + w = (Scr.Vx + t->x + t->width + 2) * (desk_w - n) / + (Scr.VxMax + Scr.MyDisplayWidth) - + 2 - x + n1; + h = (Scr.Vy + t->y + t->height + 2) * (desk_h - m) / + (Scr.VyMax + Scr.MyDisplayHeight) - + 2 - y + m1; + if (w < 1) + w = 1; + if (h < 1) + h = 1; + t->pager_view_width = w; + t->pager_view_height = h; + if ((i >= 0) && (i < ndesks)) { + XReparentWindow(dpy, t->PagerView, Desks[i].w, x, y); + XResizeWindow(dpy, t->PagerView, w, h); + } else { + XDestroyWindow(dpy, t->PagerView); + t->PagerView = None; + } + t->desk = i + desk1; + + x = (Scr.Vx + t->x) * (icon_w - n) / (Scr.VxMax + Scr.MyDisplayWidth) + + n1; + y = (Scr.Vy + t->y) * (icon_h - m) / (Scr.VyMax + Scr.MyDisplayHeight) + + m1; + w = (Scr.Vx + t->x + t->width + 2) * (icon_w - n) / + (Scr.VxMax + Scr.MyDisplayWidth) - + 2 - x + n1; + h = (Scr.Vy + t->y + t->height + 2) * (icon_h - m) / + (Scr.VyMax + Scr.MyDisplayHeight) - + 2 - y + m1; + if (w < 1) + w = 1; + if (h < 1) + h = 1; + t->icon_view_width = w; + t->icon_view_height = h; + if (Scr.CurrentDesk == t->desk) + XMoveResizeWindow(dpy, t->IconView, x, y, w, h); + else + XMoveResizeWindow(dpy, t->IconView, -1000, -1000, w, h); } -void MoveResizePagerView(PagerWindow *t) +void +MoveResizePagerView(PagerWindow *t) { - int x,y,w,h,n,m,n1,m1; - - n = (Scr.VxMax)/Scr.MyDisplayWidth; - m = (Scr.VyMax)/Scr.MyDisplayHeight; - n1 = (Scr.Vx+t->x)/Scr.MyDisplayWidth; - m1 = (Scr.Vy+t->y)/Scr.MyDisplayHeight; - x = (Scr.Vx + t->x)*(desk_w-n)/(Scr.VxMax + Scr.MyDisplayWidth) +n1; - y = (Scr.Vy + t->y)*(desk_h-m)/(Scr.VyMax + Scr.MyDisplayHeight)+m1; - w = (Scr.Vx + t->x + t->width+2)*(desk_w-n)/ - (Scr.VxMax + Scr.MyDisplayWidth) - 2 - x + n1; - h = (Scr.Vy + t->y + t->height+2)*(desk_h-m)/ - (Scr.VyMax + Scr.MyDisplayHeight) -2 - y +m1; - - if (w < 1) - w = 1; - if (h < 1) - h = 1; - t->pager_view_width = w; - t->pager_view_height = h; - if(t->PagerView != None) - XMoveResizeWindow(dpy,t->PagerView,x,y,w,h); - else if((t->desk >= desk1)&&(t->desk <= desk2)) - { - XDestroyWindow(dpy,t->IconView); - AddNewWindow(t); - return; - } - - x = (Scr.Vx + t->x)*(icon_w-n)/(Scr.VxMax + Scr.MyDisplayWidth) +n1; - y = (Scr.Vy + t->y)*(icon_h-m)/(Scr.VyMax + Scr.MyDisplayHeight)+m1; - w = (Scr.Vx + t->x + t->width+2)*(icon_w-n)/ - (Scr.VxMax + Scr.MyDisplayWidth) - 2 - x + n1; - h = (Scr.Vy + t->y + t->height+2)*(icon_h-m)/ - (Scr.VyMax + Scr.MyDisplayHeight) -2 - y +m1; - - if (w < 1) - w = 1; - if (h < 1) - h = 1; - t->icon_view_width = w; - t->icon_view_height = h; - if(Scr.CurrentDesk == t->desk) - XMoveResizeWindow(dpy,t->IconView,x,y,w,h); - else - XMoveResizeWindow(dpy,t->IconView,-1000,-1000,w,h); -} + int x, y, w, h, n, m, n1, m1; + + n = (Scr.VxMax) / Scr.MyDisplayWidth; + m = (Scr.VyMax) / Scr.MyDisplayHeight; + n1 = (Scr.Vx + t->x) / Scr.MyDisplayWidth; + m1 = (Scr.Vy + t->y) / Scr.MyDisplayHeight; + x = (Scr.Vx + t->x) * (desk_w - n) / (Scr.VxMax + Scr.MyDisplayWidth) + + n1; + y = (Scr.Vy + t->y) * (desk_h - m) / (Scr.VyMax + Scr.MyDisplayHeight) + + m1; + w = (Scr.Vx + t->x + t->width + 2) * (desk_w - n) / + (Scr.VxMax + Scr.MyDisplayWidth) - + 2 - x + n1; + h = (Scr.Vy + t->y + t->height + 2) * (desk_h - m) / + (Scr.VyMax + Scr.MyDisplayHeight) - + 2 - y + m1; + + if (w < 1) + w = 1; + if (h < 1) + h = 1; + t->pager_view_width = w; + t->pager_view_height = h; + if (t->PagerView != None) + XMoveResizeWindow(dpy, t->PagerView, x, y, w, h); + else if ((t->desk >= desk1) && (t->desk <= desk2)) { + XDestroyWindow(dpy, t->IconView); + AddNewWindow(t); + return; + } + x = (Scr.Vx + t->x) * (icon_w - n) / (Scr.VxMax + Scr.MyDisplayWidth) + + n1; + y = (Scr.Vy + t->y) * (icon_h - m) / (Scr.VyMax + Scr.MyDisplayHeight) + + m1; + w = (Scr.Vx + t->x + t->width + 2) * (icon_w - n) / + (Scr.VxMax + Scr.MyDisplayWidth) - + 2 - x + n1; + h = (Scr.Vy + t->y + t->height + 2) * (icon_h - m) / + (Scr.VyMax + Scr.MyDisplayHeight) - + 2 - y + m1; + + if (w < 1) + w = 1; + if (h < 1) + h = 1; + t->icon_view_width = w; + t->icon_view_height = h; + if (Scr.CurrentDesk == t->desk) + XMoveResizeWindow(dpy, t->IconView, x, y, w, h); + else + XMoveResizeWindow(dpy, t->IconView, -1000, -1000, w, h); +} -void MoveStickyWindows(void) +void +MoveStickyWindows(void) { - PagerWindow *t; - - t = Start; - while(t!= NULL) - { - if(((t->flags & ICONIFIED)&&(t->flags & StickyIcon))|| - (t->flags & STICKY)) - { - if(t->desk != Scr.CurrentDesk) - { - ChangeDeskForWindow(t,Scr.CurrentDesk); - } - else - { - MoveResizePagerView(t); - - } + PagerWindow *t; + + t = Start; + while (t != NULL) { + if (((t->flags & ICONIFIED) && (t->flags & StickyIcon)) || + (t->flags & STICKY)) { + if (t->desk != Scr.CurrentDesk) { + ChangeDeskForWindow(t, Scr.CurrentDesk); + } else { + MoveResizePagerView(t); + } + } + t = t->next; } - t = t->next; - } } -void Hilight(PagerWindow *t, int on) +void +Hilight(PagerWindow *t, int on) { - if(!t)return; - - if(Scr.d_depth < 2) - { - if(on) - { - if(t->PagerView != None) - XSetWindowBackgroundPixmap(dpy,t->PagerView,Scr.gray_pixmap); - XSetWindowBackgroundPixmap(dpy,t->IconView,Scr.gray_pixmap); - } - else - { - if(t->flags & STICKY) - { - if(t->PagerView != None) - XSetWindowBackgroundPixmap(dpy,t->PagerView, - Scr.sticky_gray_pixmap); - XSetWindowBackgroundPixmap(dpy,t->IconView, - Scr.sticky_gray_pixmap); - } - else - { - if(t->PagerView != None) - XSetWindowBackgroundPixmap(dpy,t->PagerView, - Scr.light_gray_pixmap); - XSetWindowBackgroundPixmap(dpy,t->IconView, - Scr.light_gray_pixmap); - } - } - } - else - { - if(on) - { - if(t->PagerView != None) - XSetWindowBackground(dpy,t->PagerView,focus_pix); - XSetWindowBackground(dpy,t->IconView,focus_pix); - } - else - { - if(t->PagerView != None) - XSetWindowBackground(dpy,t->PagerView,t->back); - XSetWindowBackground(dpy,t->IconView,t->back); + if (!t) + return; + + if (Scr.d_depth < 2) { + if (on) { + if (t->PagerView != None) + XSetWindowBackgroundPixmap( + dpy, t->PagerView, Scr.gray_pixmap); + XSetWindowBackgroundPixmap( + dpy, t->IconView, Scr.gray_pixmap); + } else { + if (t->flags & STICKY) { + if (t->PagerView != None) + XSetWindowBackgroundPixmap(dpy, + t->PagerView, + Scr.sticky_gray_pixmap); + XSetWindowBackgroundPixmap( + dpy, t->IconView, Scr.sticky_gray_pixmap); + } else { + if (t->PagerView != None) + XSetWindowBackgroundPixmap(dpy, + t->PagerView, + Scr.light_gray_pixmap); + XSetWindowBackgroundPixmap( + dpy, t->IconView, Scr.light_gray_pixmap); + } + } + } else { + if (on) { + if (t->PagerView != None) + XSetWindowBackground( + dpy, t->PagerView, focus_pix); + XSetWindowBackground(dpy, t->IconView, focus_pix); + } else { + if (t->PagerView != None) + XSetWindowBackground( + dpy, t->PagerView, t->back); + XSetWindowBackground(dpy, t->IconView, t->back); + } } - } - if(t->PagerView != None) - XClearWindow(dpy,t->PagerView); - XClearWindow(dpy,t->IconView); - LabelWindow(t); - LabelIconWindow(t); - PictureWindow(t); - PictureIconWindow(t); + if (t->PagerView != None) + XClearWindow(dpy, t->PagerView); + XClearWindow(dpy, t->IconView); + LabelWindow(t); + LabelIconWindow(t); + PictureWindow(t); + PictureIconWindow(t); } /* Use Desk == -1 to scroll the icon window */ -void Scroll(int window_w, int window_h, int x, int y, int Desk) +void +Scroll(int window_w, int window_h, int x, int y, int Desk) { #ifndef NON_VIRTUAL - char command[256]; - int sx, sy; - if(Wait == 0) - { - /* Desk < 0 means we want to scroll an icon window */ - if(Desk >= 0 && Desk + desk1 != Scr.CurrentDesk) - { - return; - } + char command[256]; + int sx, sy; + if (Wait == 0) { + /* Desk < 0 means we want to scroll an icon window */ + if (Desk >= 0 && Desk + desk1 != Scr.CurrentDesk) { + return; + } - if(x < 0) - x = 0; - if(y < 0) - y = 0; - - if(x > window_w) - x = window_w; - if(y > window_h) - y = window_h; - - sx = (100*(x*(Scr.VxMax+Scr.MyDisplayWidth)/window_w- Scr.Vx)) / - Scr.MyDisplayWidth; - sy = (100*(y*(Scr.VyMax+Scr.MyDisplayHeight)/window_h - Scr.Vy)) / - Scr.MyDisplayHeight; - /* Make sure we don't get stuck a few pixels fromt the top/left border. - * Since sx/sy are ints, values between 0 and 1 are rounded down. */ - if(sx == 0 && x == 0 && Scr.Vx != 0) sx = -1; - if(sy == 0 && y == 0 && Scr.Vy != 0) sy = -1; - - sprintf(command,"Scroll %d %d\n",sx,sy); - SendInfo(fd,command,0); - Wait = 1; - } + if (x < 0) + x = 0; + if (y < 0) + y = 0; + + if (x > window_w) + x = window_w; + if (y > window_h) + y = window_h; + + sx = (100 * (x * (Scr.VxMax + Scr.MyDisplayWidth) / window_w - + Scr.Vx)) / + Scr.MyDisplayWidth; + sy = (100 * (y * (Scr.VyMax + Scr.MyDisplayHeight) / window_h - + Scr.Vy)) / + Scr.MyDisplayHeight; + /* Make sure we don't get stuck a few pixels fromt the top/left + * border. Since sx/sy are ints, values between 0 and 1 are + * rounded down. */ + if (sx == 0 && x == 0 && Scr.Vx != 0) + sx = -1; + if (sy == 0 && y == 0 && Scr.Vy != 0) + sy = -1; + + snprintf(command, sizeof(command), "Scroll %d %d\n", sx, sy); + SendInfo(fd, command, 0); + Wait = 1; + } #endif } -void MoveWindow(XEvent *Event) +void +MoveWindow(XEvent *Event) { - char command[100]; - int x1,y1,finished = 0,wx,wy,n,x,y,xi=0,yi=0,wx1,wy1,x2,y2; - Window dumwin; - PagerWindow *t; - int m,n1,m1; - int NewDesk,KeepMoving = 0; - int moved = 0; - int row,column; - - t = Start; - while ((t != NULL)&&(t->PagerView != Event->xbutton.subwindow)) - t= t->next; - - if(t==NULL) - { - t = Start; - while ((t != NULL)&&(t->IconView != Event->xbutton.subwindow)) - t= t->next; - if(t!=NULL) - { - IconMoveWindow(Event,t); - return; - } - } - - if(t == NULL) - return; - - NewDesk = t->desk - desk1; - if((NewDesk < 0)||(NewDesk >= ndesks)) - return; - - n = (Scr.VxMax)/Scr.MyDisplayWidth; - m = (Scr.VyMax)/Scr.MyDisplayHeight; - n1 = (Scr.Vx+t->x)/Scr.MyDisplayWidth; - m1 = (Scr.Vy+t->y)/Scr.MyDisplayHeight; - wx = (Scr.Vx + t->x)*(desk_w-n)/(Scr.VxMax + Scr.MyDisplayWidth) +n1; - wy = (Scr.Vy + t->y)*(desk_h-m)/(Scr.VyMax + Scr.MyDisplayHeight)+m1; - wx1 = wx+(desk_w+1)*(NewDesk%Columns); - wy1 = wy + label_h + (desk_h+label_h+1)*(NewDesk/Columns); - - XReparentWindow(dpy, t->PagerView, Scr.Pager_w,wx1,wy1); - XRaiseWindow(dpy,t->PagerView); - - XTranslateCoordinates(dpy, Event->xany.window, t->PagerView, - Event->xbutton.x, Event->xbutton.y, &x1, &y1, &dumwin); - xi = x1; - yi = y1; - while(!finished) - { - XMaskEvent(dpy,ButtonReleaseMask | ButtonMotionMask|ExposureMask,Event); - - if(Event->type == MotionNotify) - { - XTranslateCoordinates(dpy, Event->xany.window, Scr.Pager_w, - Event->xmotion.x, Event->xmotion.y, &x, &y, - &dumwin); - if(moved == 0) - { - xi = x; - yi = y; - moved = 1; - } - if((x < -5)||(y<-5)||(x>window_w+5)||(y>window_h+5)) - { - KeepMoving = 1; - finished = 1; - } - XMoveWindow(dpy,t->PagerView, x - (x1), - y - (y1)); - } - else if(Event->type == ButtonRelease) - { - XTranslateCoordinates(dpy, Event->xany.window, Scr.Pager_w, - Event->xbutton.x, Event->xbutton.y, &x, &y, - &dumwin); - XMoveWindow(dpy,t->PagerView, x - (x1), - y - (y1)); - finished = 1; - } - else if (Event->type == Expose) - { - HandleExpose(Event); - } - } - - if(moved) - { - if((x - xi < 3)&&(y - yi < 3)&& - (x - xi > -3)&&(y -yi > -3)) - moved = 0; - } - if(KeepMoving) - { - NewDesk = Scr.CurrentDesk; - if(NewDesk != t->desk) - { - XMoveWindow(dpy,t->w,Scr.MyDisplayWidth+Scr.VxMax, - Scr.MyDisplayHeight+Scr.VyMax); - XSync(dpy,0); - sprintf(command,"MoveToDesk 0 %d", NewDesk); - SendInfo(fd,command,t->w); - t->desk = NewDesk; - } - if((NewDesk>=desk1)&&(NewDesk<=desk2)) - XReparentWindow(dpy, t->PagerView, Desks[NewDesk-desk1].w,0,0); - else - { - XDestroyWindow(dpy,t->PagerView); - t->PagerView = None; - } - XTranslateCoordinates(dpy, Scr.Pager_w, Scr.Root, - x, y, &x1, &y1, &dumwin); - XUngrabPointer(dpy,CurrentTime); - XSync(dpy,0); - sprintf(command, "Move %dp %dp", x, y); - SendInfo(fd,command,t->w); - SendInfo(fd,"Raise",t->w); - SendInfo(fd,"Move",t->w); - return; - } - else - { - column = (x/(desk_w+1)); - row = (y/(desk_h+ label_h+1)); - NewDesk = column + (row)*Columns; - if((NewDesk <0)||(NewDesk >=ndesks)) - { - NewDesk = Scr.CurrentDesk - desk1; - x = xi; - y = yi; - moved = 0; - } - XTranslateCoordinates(dpy, Scr.Pager_w,Desks[NewDesk].w, - x-x1, y-y1, &x2,&y2,&dumwin); - - n1 = x2*(Scr.VxMax + Scr.MyDisplayWidth)/(desk_w * Scr.MyDisplayWidth); - m1 = y2*(Scr.VyMax + Scr.MyDisplayHeight)/(desk_h * Scr.MyDisplayHeight); - x = (x2-n1)* - (Scr.VxMax + Scr.MyDisplayWidth)/(desk_w-n) - Scr.Vx; - y = (y2-m1)* - (Scr.VyMax + Scr.MyDisplayHeight)/(desk_h-m) - Scr.Vy; - if(x + t->frame_width + Scr.Vx < 0 ) - x = -Scr.Vx; - if(y+t->frame_height + Scr.Vy< 0) - y = -Scr.Vy; - if(x + Scr.Vx > Scr.MyDisplayWidth+Scr.VxMax) - x = Scr.MyDisplayWidth + Scr.VxMax - t->frame_width - Scr.Vx; - if(y +Scr.Vy> Scr.MyDisplayHeight+Scr.VyMax) - y = Scr.MyDisplayHeight+ Scr.VyMax - t->frame_height - Scr.Vy; - if(((t->flags & ICONIFIED)&&(t->flags & StickyIcon))|| - (t->flags & STICKY)) - { - NewDesk = Scr.CurrentDesk - desk1; - if(x > Scr.MyDisplayWidth -16) - x = Scr.MyDisplayWidth - 16; - if(y > Scr.MyDisplayHeight-16) - y = Scr.MyDisplayHeight - 16; - if(x + t->width < 16) - x = 16 - t->width; - if(y + t->height < 16) - y = 16 - t->height; + char command[100]; + int x1, y1, finished = 0, wx, wy, n, x, y, xi = 0, yi = 0, wx1, wy1, x2, + y2; + Window dumwin; + PagerWindow *t; + int m, n1, m1; + int NewDesk, KeepMoving = 0; + int moved = 0; + int row, column; + + t = Start; + while ((t != NULL) && (t->PagerView != Event->xbutton.subwindow)) + t = t->next; + + if (t == NULL) { + t = Start; + while ((t != NULL) && (t->IconView != Event->xbutton.subwindow)) + t = t->next; + if (t != NULL) { + IconMoveWindow(Event, t); + return; + } } - if(NewDesk +desk1 != t->desk) - { - if(((t->flags & ICONIFIED)&&(t->flags & StickyIcon))|| - (t->flags & STICKY)) - { - NewDesk = Scr.CurrentDesk - desk1; - if(t->desk != Scr.CurrentDesk) - ChangeDeskForWindow(t,Scr.CurrentDesk); - } - else - { - sprintf(command,"MoveToDesk 0 %d", NewDesk + desk1); - SendInfo(fd,command,t->w); - t->desk = NewDesk + desk1; - } + + if (t == NULL) + return; + + NewDesk = t->desk - desk1; + if ((NewDesk < 0) || (NewDesk >= ndesks)) + return; + + n = (Scr.VxMax) / Scr.MyDisplayWidth; + m = (Scr.VyMax) / Scr.MyDisplayHeight; + n1 = (Scr.Vx + t->x) / Scr.MyDisplayWidth; + m1 = (Scr.Vy + t->y) / Scr.MyDisplayHeight; + wx = (Scr.Vx + t->x) * (desk_w - n) / (Scr.VxMax + Scr.MyDisplayWidth) + + n1; + wy = + (Scr.Vy + t->y) * (desk_h - m) / (Scr.VyMax + Scr.MyDisplayHeight) + + m1; + wx1 = wx + (desk_w + 1) * (NewDesk % Columns); + wy1 = wy + label_h + (desk_h + label_h + 1) * (NewDesk / Columns); + + XReparentWindow(dpy, t->PagerView, Scr.Pager_w, wx1, wy1); + XRaiseWindow(dpy, t->PagerView); + + XTranslateCoordinates(dpy, Event->xany.window, t->PagerView, + Event->xbutton.x, Event->xbutton.y, &x1, &y1, &dumwin); + xi = x1; + yi = y1; + while (!finished) { + XMaskEvent(dpy, + ButtonReleaseMask | ButtonMotionMask | ExposureMask, Event); + + if (Event->type == MotionNotify) { + XTranslateCoordinates(dpy, Event->xany.window, + Scr.Pager_w, Event->xmotion.x, Event->xmotion.y, &x, + &y, &dumwin); + if (moved == 0) { + xi = x; + yi = y; + moved = 1; + } + if ((x < -5) || (y < -5) || (x > window_w + 5) || + (y > window_h + 5)) { + KeepMoving = 1; + finished = 1; + } + XMoveWindow(dpy, t->PagerView, x - (x1), y - (y1)); + } else if (Event->type == ButtonRelease) { + XTranslateCoordinates(dpy, Event->xany.window, + Scr.Pager_w, Event->xbutton.x, Event->xbutton.y, &x, + &y, &dumwin); + XMoveWindow(dpy, t->PagerView, x - (x1), y - (y1)); + finished = 1; + } else if (Event->type == Expose) { + HandleExpose(Event); + } } - if((NewDesk >= 0)&&(NewDesk < ndesks)) - { - XReparentWindow(dpy, t->PagerView, Desks[NewDesk].w,x,y); - if(moved) - { - if(t->flags & ICONIFIED) - XMoveWindow(dpy,t->icon_w,x,y); - else - XMoveWindow(dpy,t->w,x+t->border_width, - y+t->title_height+t->border_width); - XSync(dpy,0); - } - else - MoveResizePagerView(t); - SendInfo(fd,"Raise",t->w); + if (moved) { + if ((x - xi < 3) && (y - yi < 3) && (x - xi > -3) && + (y - yi > -3)) + moved = 0; } - if(Scr.CurrentDesk == t->desk) - { - XSync(dpy,0); - usleep(5000); - XSync(dpy,0); - if(t->flags & ICONIFIED) - { -/* - RBW - reverting to old code for 2.2... - The new handling causes an unwanted viewport change whenever Button2 - is used; the old handling causes focus to be sent to No Input windows - regardless of the Lenience setting. After 2.2 we will revisit this issue. - I suspect it will involve expanding the module message to include wmhints - and such. -*/ -#if 0 - SendInfo(fd, "Focus", t->icon_w); -#else - XSetInputFocus (dpy, t->icon_w, RevertToParent, - Event->xbutton.time); -#endif - } - else - { -#if 0 - SendInfo(fd, "Focus", t->w); -#else - XSetInputFocus (dpy, t->w, RevertToParent, - Event->xbutton.time); -#endif - } + if (KeepMoving) { + NewDesk = Scr.CurrentDesk; + if (NewDesk != t->desk) { + XMoveWindow(dpy, t->w, Scr.MyDisplayWidth + Scr.VxMax, + Scr.MyDisplayHeight + Scr.VyMax); + XSync(dpy, 0); + snprintf(command, sizeof(command), "MoveToDesk 0 %d", + NewDesk); + SendInfo(fd, command, t->w); + t->desk = NewDesk; + } + if ((NewDesk >= desk1) && (NewDesk <= desk2)) + XReparentWindow( + dpy, t->PagerView, Desks[NewDesk - desk1].w, 0, 0); + else { + XDestroyWindow(dpy, t->PagerView); + t->PagerView = None; + } + XTranslateCoordinates( + dpy, Scr.Pager_w, Scr.Root, x, y, &x1, &y1, &dumwin); + XUngrabPointer(dpy, CurrentTime); + XSync(dpy, 0); + snprintf(command, sizeof(command), "Move %dp %dp", x, y); + SendInfo(fd, command, t->w); + SendInfo(fd, "Raise", t->w); + SendInfo(fd, "Move", t->w); + return; + } else { + column = (x / (desk_w + 1)); + row = (y / (desk_h + label_h + 1)); + NewDesk = column + (row)*Columns; + if ((NewDesk < 0) || (NewDesk >= ndesks)) { + NewDesk = Scr.CurrentDesk - desk1; + x = xi; + y = yi; + moved = 0; + } + XTranslateCoordinates(dpy, Scr.Pager_w, Desks[NewDesk].w, + x - x1, y - y1, &x2, &y2, &dumwin); + + n1 = x2 * (Scr.VxMax + Scr.MyDisplayWidth) / + (desk_w * Scr.MyDisplayWidth); + m1 = y2 * (Scr.VyMax + Scr.MyDisplayHeight) / + (desk_h * Scr.MyDisplayHeight); + x = (x2 - n1) * (Scr.VxMax + Scr.MyDisplayWidth) / + (desk_w - n) - + Scr.Vx; + y = (y2 - m1) * (Scr.VyMax + Scr.MyDisplayHeight) / + (desk_h - m) - + Scr.Vy; + if (x + t->frame_width + Scr.Vx < 0) + x = -Scr.Vx; + if (y + t->frame_height + Scr.Vy < 0) + y = -Scr.Vy; + if (x + Scr.Vx > Scr.MyDisplayWidth + Scr.VxMax) + x = Scr.MyDisplayWidth + Scr.VxMax - t->frame_width - + Scr.Vx; + if (y + Scr.Vy > Scr.MyDisplayHeight + Scr.VyMax) + y = Scr.MyDisplayHeight + Scr.VyMax - t->frame_height - + Scr.Vy; + if (((t->flags & ICONIFIED) && (t->flags & StickyIcon)) || + (t->flags & STICKY)) { + NewDesk = Scr.CurrentDesk - desk1; + if (x > Scr.MyDisplayWidth - 16) + x = Scr.MyDisplayWidth - 16; + if (y > Scr.MyDisplayHeight - 16) + y = Scr.MyDisplayHeight - 16; + if (x + t->width < 16) + x = 16 - t->width; + if (y + t->height < 16) + y = 16 - t->height; + } + if (NewDesk + desk1 != t->desk) { + if (((t->flags & ICONIFIED) && + (t->flags & StickyIcon)) || + (t->flags & STICKY)) { + NewDesk = Scr.CurrentDesk - desk1; + if (t->desk != Scr.CurrentDesk) + ChangeDeskForWindow(t, Scr.CurrentDesk); + } else { + snprintf(command, sizeof(command), + "MoveToDesk 0 %d", NewDesk + desk1); + SendInfo(fd, command, t->w); + t->desk = NewDesk + desk1; + } + } + + if ((NewDesk >= 0) && (NewDesk < ndesks)) { + XReparentWindow( + dpy, t->PagerView, Desks[NewDesk].w, x, y); + if (moved) { + if (t->flags & ICONIFIED) + XMoveWindow(dpy, t->icon_w, x, y); + else + XMoveWindow(dpy, t->w, + x + t->border_width, + y + t->title_height + + t->border_width); + XSync(dpy, 0); + } else + MoveResizePagerView(t); + SendInfo(fd, "Raise", t->w); + } + if (Scr.CurrentDesk == t->desk) { + XSync(dpy, 0); + usleep(5000); + XSync(dpy, 0); + if (t->flags & ICONIFIED) { + /* + RBW - reverting to old code for 2.2... + The new handling causes an unwanted viewport + change whenever Button2 is used; the old + handling causes focus to be sent to No Input + windows regardless of the Lenience setting. + After 2.2 we will revisit this issue. I + suspect it will involve expanding the module + message to include wmhints and such. + */ + XSetInputFocus(dpy, t->icon_w, RevertToParent, + Event->xbutton.time); + } else { + XSetInputFocus(dpy, t->w, RevertToParent, + Event->xbutton.time); + } + } } - } } - - - - - /*********************************************************************** * * Procedure: * FvwmErrorHandler - displays info on internal errors * ************************************************************************/ -XErrorHandler FvwmErrorHandler(Display *dpy, XErrorEvent *event) +XErrorHandler +FvwmErrorHandler(Display *dpy, XErrorEvent *event) { -#if 1 - extern Bool error_occured; - error_occured = True; - return 0; -#else - /* really should just exit here... */ - /* domivogt (07-mar-1999): No, not really. See comment above. */ - fprintf(stderr,"%s: XError! Bagging out!\n",MyName); - exit(0); -#endif /* 1 */ + extern Bool error_occured; + error_occured = True; + return 0; } - -void LabelWindow(PagerWindow *t) +void +LabelWindow(PagerWindow *t) { - XGCValues Globalgcv; - unsigned long Globalgcm; - - if(windowFont == NULL) - { - return; - } - if (MiniIcons && t->mini_icon.picture && (t->PagerView != None)) - { - return; /* will draw picture instead... */ - } - if(t->icon_name == NULL) - { - return; - } - if(t == FocusWin) - { - Globalgcv.foreground = focus_fore_pix; - Globalgcv.background = focus_pix; - Globalgcm = GCForeground|GCBackground; - XChangeGC(dpy, StdGC,Globalgcm,&Globalgcv); - } - else - { - Globalgcv.foreground = t->text; - Globalgcv.background = t->back; - Globalgcm = GCForeground|GCBackground; - XChangeGC(dpy, StdGC,Globalgcm,&Globalgcv); - - } - if(t->PagerView != None) - { - XClearWindow(dpy, t->PagerView); - XDrawString (dpy, t->PagerView,StdGC,2,windowFont->ascent+2 , - t->icon_name, strlen(t->icon_name)); - } -} + XGCValues Globalgcv; + unsigned long Globalgcm; + if (windowFont == NULL) { + return; + } + if (MiniIcons && t->mini_icon.picture && (t->PagerView != None)) { + return; /* will draw picture instead... */ + } + if (t->icon_name == NULL) { + return; + } + if (t == FocusWin) { + Globalgcv.foreground = focus_fore_pix; + Globalgcv.background = focus_pix; + Globalgcm = GCForeground | GCBackground; + XChangeGC(dpy, StdGC, Globalgcm, &Globalgcv); + } else { + Globalgcv.foreground = t->text; + Globalgcv.background = t->back; + Globalgcm = GCForeground | GCBackground; + XChangeGC(dpy, StdGC, Globalgcm, &Globalgcv); + } + if (t->PagerView != None) { + XClearWindow(dpy, t->PagerView); + XDrawString(dpy, t->PagerView, StdGC, 2, windowFont->ascent + 2, + t->icon_name, strlen(t->icon_name)); + } +} -void LabelIconWindow(PagerWindow *t) +void +LabelIconWindow(PagerWindow *t) { - XGCValues Globalgcv; - unsigned long Globalgcm; - - if(windowFont == NULL) - { - return; - } - if (MiniIcons && t->mini_icon.picture && (t->PagerView != None)) - { - return; /* will draw picture instead... */ - } - if(t->icon_name == NULL) - { - return; - } - - if(t == FocusWin) - { - Globalgcv.foreground = focus_fore_pix; - Globalgcv.background = focus_pix; - Globalgcm = GCForeground|GCBackground; - XChangeGC(dpy,StdGC,Globalgcm,&Globalgcv); - } - else - { - Globalgcv.foreground = t->text; - Globalgcv.background = t->back; - Globalgcm = GCForeground|GCBackground; - XChangeGC(dpy,StdGC,Globalgcm,&Globalgcv); - - } - XClearWindow(dpy, t->IconView); - XDrawString (dpy, t->IconView,StdGC,2,windowFont->ascent+2 , - t->icon_name, strlen(t->icon_name)); + XGCValues Globalgcv; + unsigned long Globalgcm; + + if (windowFont == NULL) { + return; + } + if (MiniIcons && t->mini_icon.picture && (t->PagerView != None)) { + return; /* will draw picture instead... */ + } + if (t->icon_name == NULL) { + return; + } + if (t == FocusWin) { + Globalgcv.foreground = focus_fore_pix; + Globalgcv.background = focus_pix; + Globalgcm = GCForeground | GCBackground; + XChangeGC(dpy, StdGC, Globalgcm, &Globalgcv); + } else { + Globalgcv.foreground = t->text; + Globalgcv.background = t->back; + Globalgcm = GCForeground | GCBackground; + XChangeGC(dpy, StdGC, Globalgcm, &Globalgcv); + } + XClearWindow(dpy, t->IconView); + XDrawString(dpy, t->IconView, StdGC, 2, windowFont->ascent + 2, + t->icon_name, strlen(t->icon_name)); } -void PictureWindow (PagerWindow *t) + +void +PictureWindow(PagerWindow *t) { - XGCValues Globalgcv; - unsigned long Globalgcm; - int iconX; - int iconY; - if (MiniIcons) - { - if (t->mini_icon.picture && (t->PagerView != None)) - { - if (t->pager_view_width > t->mini_icon.width) - iconX = (t->pager_view_width - t->mini_icon.width) / 2; - else if (t->pager_view_width < t->mini_icon.width) - iconX = -((t->mini_icon.width - t->pager_view_width) / 2); - else - iconX = 0; - if (t->pager_view_height > t->mini_icon.height) - iconY = (t->pager_view_height - t->mini_icon.height) / 2; - else if (t->pager_view_height < t->mini_icon.height) - iconY = -((t->mini_icon.height - t->pager_view_height) / 2); - else - iconY = 0; - Globalgcm = GCForeground | GCBackground | GCClipMask | - GCClipXOrigin | GCClipYOrigin; - Globalgcv.clip_mask = t->mini_icon.mask; - Globalgcv.clip_x_origin = iconX; - Globalgcv.clip_y_origin = iconY; - if (t == FocusWin) - { - Globalgcv.foreground = focus_fore_pix; - Globalgcv.background = focus_pix; - } - else - { - Globalgcv.foreground = t->text; - Globalgcv.background = t->back; - } - XChangeGC (dpy, MiniIconGC, Globalgcm, &Globalgcv); - XClearWindow (dpy, t->PagerView); - XCopyArea (dpy, t->mini_icon.picture, t->PagerView, MiniIconGC, - 0, 0, t->mini_icon.width, t->mini_icon.height, iconX, - iconY); + XGCValues Globalgcv; + unsigned long Globalgcm; + int iconX; + int iconY; + if (MiniIcons) { + if (t->mini_icon.picture && (t->PagerView != None)) { + if (t->pager_view_width > t->mini_icon.width) + iconX = + (t->pager_view_width - t->mini_icon.width) / + 2; + else if (t->pager_view_width < t->mini_icon.width) + iconX = -( + (t->mini_icon.width - t->pager_view_width) / + 2); + else + iconX = 0; + if (t->pager_view_height > t->mini_icon.height) + iconY = (t->pager_view_height - + t->mini_icon.height) / + 2; + else if (t->pager_view_height < t->mini_icon.height) + iconY = -((t->mini_icon.height - + t->pager_view_height) / + 2); + else + iconY = 0; + Globalgcm = GCForeground | GCBackground | GCClipMask | + GCClipXOrigin | GCClipYOrigin; + Globalgcv.clip_mask = t->mini_icon.mask; + Globalgcv.clip_x_origin = iconX; + Globalgcv.clip_y_origin = iconY; + if (t == FocusWin) { + Globalgcv.foreground = focus_fore_pix; + Globalgcv.background = focus_pix; + } else { + Globalgcv.foreground = t->text; + Globalgcv.background = t->back; + } + XChangeGC(dpy, MiniIconGC, Globalgcm, &Globalgcv); + XClearWindow(dpy, t->PagerView); + XCopyArea(dpy, t->mini_icon.picture, t->PagerView, + MiniIconGC, 0, 0, t->mini_icon.width, + t->mini_icon.height, iconX, iconY); + } } - } } -void PictureIconWindow (PagerWindow *t) + +void +PictureIconWindow(PagerWindow *t) { - XGCValues Globalgcv; - unsigned long Globalgcm; - int iconX; - int iconY; - if (MiniIcons) - { - if (t->mini_icon.picture && (t->IconView != None)) - { - if (t->icon_view_width > t->mini_icon.width) - iconX = (t->icon_view_width - t->mini_icon.width) / 2; - else if (t->icon_view_width < t->mini_icon.width) - iconX = -((t->mini_icon.width - t->icon_view_width) / 2); - else - iconX = 0; - if (t->icon_view_height > t->mini_icon.height) - iconY = (t->icon_view_height - t->mini_icon.height) / 2; - else if (t->icon_view_height < t->mini_icon.height) - iconY = -((t->mini_icon.height - t->icon_view_height) / 2); - else - iconY = 0; - Globalgcm = GCForeground | GCBackground | GCClipMask | - GCClipXOrigin | GCClipYOrigin; - Globalgcv.clip_mask = t->mini_icon.mask; - Globalgcv.clip_x_origin = iconX; - Globalgcv.clip_y_origin = iconY; - if (t == FocusWin) - { - Globalgcv.foreground = focus_fore_pix; - Globalgcv.background = focus_pix; - } - else - { - Globalgcv.foreground = t->text; - Globalgcv.background = t->back; - } - XChangeGC (dpy, MiniIconGC, Globalgcm, &Globalgcv); - XClearWindow (dpy, t->IconView); - XCopyArea (dpy, t->mini_icon.picture, t->IconView, MiniIconGC, - 0, 0, t->mini_icon.width, t->mini_icon.height, iconX, - iconY); + XGCValues Globalgcv; + unsigned long Globalgcm; + int iconX; + int iconY; + if (MiniIcons) { + if (t->mini_icon.picture && (t->IconView != None)) { + if (t->icon_view_width > t->mini_icon.width) + iconX = + (t->icon_view_width - t->mini_icon.width) / + 2; + else if (t->icon_view_width < t->mini_icon.width) + iconX = -( + (t->mini_icon.width - t->icon_view_width) / + 2); + else + iconX = 0; + if (t->icon_view_height > t->mini_icon.height) + iconY = (t->icon_view_height - + t->mini_icon.height) / + 2; + else if (t->icon_view_height < t->mini_icon.height) + iconY = -((t->mini_icon.height - + t->icon_view_height) / + 2); + else + iconY = 0; + Globalgcm = GCForeground | GCBackground | GCClipMask | + GCClipXOrigin | GCClipYOrigin; + Globalgcv.clip_mask = t->mini_icon.mask; + Globalgcv.clip_x_origin = iconX; + Globalgcv.clip_y_origin = iconY; + if (t == FocusWin) { + Globalgcv.foreground = focus_fore_pix; + Globalgcv.background = focus_pix; + } else { + Globalgcv.foreground = t->text; + Globalgcv.background = t->back; + } + XChangeGC(dpy, MiniIconGC, Globalgcm, &Globalgcv); + XClearWindow(dpy, t->IconView); + XCopyArea(dpy, t->mini_icon.picture, t->IconView, + MiniIconGC, 0, 0, t->mini_icon.width, + t->mini_icon.height, iconX, iconY); + } } - } } -void IconMoveWindow(XEvent *Event,PagerWindow *t) +void +IconMoveWindow(XEvent *Event, PagerWindow *t) { - char command[100]; - int x1,y1,finished = 0,wx,wy,n,x=0,y=0,xi=0,yi=0; - Window dumwin; - int m,n1,m1; - int moved = 0; - int KeepMoving = 0; - - if(t==NULL) - return; - - n = (Scr.VxMax)/Scr.MyDisplayWidth; - m = (Scr.VyMax)/Scr.MyDisplayHeight; - n1 = (Scr.Vx+t->x)/Scr.MyDisplayWidth; - m1 = (Scr.Vy+t->y)/Scr.MyDisplayHeight; - wx = (Scr.Vx + t->x)*(icon_w-n)/(Scr.VxMax + Scr.MyDisplayWidth) +n1; - wy = (Scr.Vy + t->y)*(icon_h-m)/(Scr.VyMax + Scr.MyDisplayHeight)+m1; - - XRaiseWindow(dpy,t->IconView); - - XTranslateCoordinates(dpy, Event->xany.window, t->IconView, - Event->xbutton.x, Event->xbutton.y, &x1, &y1, &dumwin); - while(!finished) - { - XMaskEvent(dpy,ButtonReleaseMask | ButtonMotionMask|ExposureMask,Event); - - if(Event->type == MotionNotify) - { - x = Event->xbutton.x; - y = Event->xbutton.y; - if(moved == 0) - { - xi = x; - yi = y; - moved = 1; - } - - XMoveWindow(dpy,t->IconView, x - (x1), - y - (y1)); - if((x < -5)||(y < -5)||(x>icon_w+5)||(y>icon_h+5)) - { - finished = 1; - KeepMoving = 1; - } + char command[100]; + int x1, y1, finished = 0, wx, wy, n, x = 0, y = 0, xi = 0, yi = 0; + Window dumwin; + int m, n1, m1; + int moved = 0; + int KeepMoving = 0; + + if (t == NULL) + return; + + n = (Scr.VxMax) / Scr.MyDisplayWidth; + m = (Scr.VyMax) / Scr.MyDisplayHeight; + n1 = (Scr.Vx + t->x) / Scr.MyDisplayWidth; + m1 = (Scr.Vy + t->y) / Scr.MyDisplayHeight; + wx = (Scr.Vx + t->x) * (icon_w - n) / (Scr.VxMax + Scr.MyDisplayWidth) + + n1; + wy = + (Scr.Vy + t->y) * (icon_h - m) / (Scr.VyMax + Scr.MyDisplayHeight) + + m1; + + XRaiseWindow(dpy, t->IconView); + + XTranslateCoordinates(dpy, Event->xany.window, t->IconView, + Event->xbutton.x, Event->xbutton.y, &x1, &y1, &dumwin); + while (!finished) { + XMaskEvent(dpy, + ButtonReleaseMask | ButtonMotionMask | ExposureMask, Event); + + if (Event->type == MotionNotify) { + x = Event->xbutton.x; + y = Event->xbutton.y; + if (moved == 0) { + xi = x; + yi = y; + moved = 1; + } + + XMoveWindow(dpy, t->IconView, x - (x1), y - (y1)); + if ((x < -5) || (y < -5) || (x > icon_w + 5) || + (y > icon_h + 5)) { + finished = 1; + KeepMoving = 1; + } + } else if (Event->type == ButtonRelease) { + x = Event->xbutton.x; + y = Event->xbutton.y; + XMoveWindow(dpy, t->PagerView, x - (x1), y - (y1)); + finished = 1; + } else if (Event->type == Expose) { + HandleExpose(Event); + } } - else if(Event->type == ButtonRelease) - { - x = Event->xbutton.x; - y = Event->xbutton.y; - XMoveWindow(dpy,t->PagerView, x - (x1),y - (y1)); - finished = 1; + + if (moved) { + if ((x - xi < 3) && (y - yi < 3) && (x - xi > -3) && + (y - yi > -3)) + moved = 0; } - else if (Event->type == Expose) - { - HandleExpose(Event); + + if (KeepMoving) { + XTranslateCoordinates( + dpy, t->IconView, Scr.Root, x, y, &x1, &y1, &dumwin); + XUngrabPointer(dpy, CurrentTime); + XSync(dpy, 0); + snprintf(command, sizeof(command), "Move %dp %dp", x, y); + SendInfo(fd, command, t->w); + SendInfo(fd, "Raise", t->w); + SendInfo(fd, "Move", t->w); + } else { + x = x - x1; + y = y - y1; + n1 = x * (Scr.VxMax + Scr.MyDisplayWidth) / + (icon_w * Scr.MyDisplayWidth); + m1 = y * (Scr.VyMax + Scr.MyDisplayHeight) / + (icon_h * Scr.MyDisplayHeight); + x = (x - n1) * (Scr.VxMax + Scr.MyDisplayWidth) / (icon_w - n) - + Scr.Vx; + y = (y - m1) * (Scr.VyMax + Scr.MyDisplayHeight) / + (icon_h - m) - + Scr.Vy; + + if (((t->flags & ICONIFIED) && (t->flags & StickyIcon)) || + (t->flags & STICKY)) { + if (x > Scr.MyDisplayWidth - 16) + x = Scr.MyDisplayWidth - 16; + if (y > Scr.MyDisplayHeight - 16) + y = Scr.MyDisplayHeight - 16; + if (x + t->width < 16) + x = 16 - t->width; + if (y + t->height < 16) + y = 16 - t->height; + } + if (moved) { + if (t->flags & ICONIFIED) + XMoveWindow(dpy, t->icon_w, x, y); + else + XMoveWindow(dpy, t->w, x, y); + XSync(dpy, 0); + } else { + MoveResizePagerView(t); + } + SendInfo(fd, "Raise", t->w); + + if (t->flags & ICONIFIED) { + /* + RBW - reverting to old code for 2.2...temporarily. See + note above, in MoveWindow. + */ + XSetInputFocus(dpy, t->icon_w, RevertToParent, + Event->xbutton.time); + } else { + XSetInputFocus( + dpy, t->w, RevertToParent, Event->xbutton.time); + } } - } - - if(moved) - { - if((x - xi < 3)&&(y - yi < 3)&& - (x - xi > -3)&&(y -yi > -3)) - moved = 0; - } - - if(KeepMoving) - { - XTranslateCoordinates(dpy, t->IconView, Scr.Root, - x, y, &x1, &y1, &dumwin); - XUngrabPointer(dpy,CurrentTime); - XSync(dpy,0); - sprintf(command, "Move %dp %dp", x, y); - SendInfo(fd,command,t->w); - SendInfo(fd,"Raise",t->w); - SendInfo(fd,"Move",t->w); - } - else - { - x = x - x1; - y = y - y1; - n1 = x*(Scr.VxMax + Scr.MyDisplayWidth)/(icon_w * Scr.MyDisplayWidth); - m1 = y*(Scr.VyMax + Scr.MyDisplayHeight)/(icon_h * Scr.MyDisplayHeight); - x = (x-n1)* - (Scr.VxMax + Scr.MyDisplayWidth)/(icon_w-n) - Scr.Vx; - y = (y-m1)* - (Scr.VyMax + Scr.MyDisplayHeight)/(icon_h-m) - Scr.Vy; - - if(((t->flags & ICONIFIED)&&(t->flags & StickyIcon))|| - (t->flags & STICKY)) - { - if(x > Scr.MyDisplayWidth -16) - x = Scr.MyDisplayWidth - 16; - if(y > Scr.MyDisplayHeight-16) - y = Scr.MyDisplayHeight - 16; - if(x + t->width < 16) - x = 16 - t->width; - if(y + t->height < 16) - y = 16 - t->height; +} + +/* Just maps window ... draw stuff in it later after Expose event + -- ric@giccs.georgetown.edu */ +void +MapBalloonWindow(XEvent *event) +{ + PagerWindow *t; + XWindowChanges window_changes; + Window view, dummy; + int view_width, view_height; + int matched_window = 0; + int x, y; + extern char *BalloonBack; + + /* is this the best way to match X event window ID to PagerWindow ID? */ + t = Start; + + while (!matched_window) { + if (t == NULL) { + return; + } else if (t->PagerView == event->xcrossing.window) { + view = t->PagerView; + view_width = t->pager_view_width; + view_height = t->pager_view_height; + matched_window = 1; + } else if (t->IconView == event->xcrossing.window) { + view = t->IconView; + view_width = t->icon_view_width; + view_height = t->icon_view_height; + matched_window = 1; + } else { + t = t->next; + } } - if(moved) - { - if(t->flags & ICONIFIED) - XMoveWindow(dpy,t->icon_w,x,y); - else - XMoveWindow(dpy,t->w,x,y); - XSync(dpy,0); + + /* associate balloon with its pager window */ + balloon.pw = t; + + /* calculate window width to accommodate string */ + window_changes.width = + 4 + XTextWidth(balloon.font, t->icon_name, strlen(t->icon_name)); + + /* get x and y coords relative to pager window */ + x = (view_width / 2) - (window_changes.width / 2) - balloon.border; + + if (balloon.yoffset > 0) + y = view_height + balloon.yoffset; + else + y = balloon.yoffset - balloon.height - (2 * balloon.border); + + /* balloon is a top-level window, therefore need to + translate pager window coords to root window coords */ + XTranslateCoordinates(dpy, view, Scr.Root, x, y, &window_changes.x, + &window_changes.y, &dummy); + + /* make sure balloon doesn't go off screen + (actually 2 pixels from edge rather than 0 just to be pretty :-) */ + + /* too close to left */ + if (window_changes.x < 2) + window_changes.x = 2; + + /* too close to right */ + else if (window_changes.x + window_changes.width > + Scr.MyDisplayWidth - (2 * balloon.border) - 2) + window_changes.x = Scr.MyDisplayWidth - window_changes.width - + (2 * balloon.border) - 2; + + /* too close to top ... make yoffset +ve */ + if (window_changes.y < 2) { + y = -balloon.yoffset + view_height; + XTranslateCoordinates(dpy, view, Scr.Root, x, y, + &window_changes.x, &window_changes.y, &dummy); } - else - { - MoveResizePagerView(t); + + /* too close to bottom ... make yoffset -ve */ + else if (window_changes.y + balloon.height > + Scr.MyDisplayHeight - (2 * balloon.border) - 2) { + y = -balloon.yoffset - balloon.height - (2 * balloon.border); + XTranslateCoordinates(dpy, view, Scr.Root, x, y, + &window_changes.x, &window_changes.y, &dummy); } - SendInfo(fd,"Raise",t->w); - - if(t->flags & ICONIFIED) - { -/* - RBW - reverting to old code for 2.2...temporarily. See note above, in - MoveWindow. -*/ -#if 0 - SendInfo(fd, "Focus", t->icon_w); -#else - XSetInputFocus (dpy, t->icon_w, RevertToParent, Event->xbutton.time); -#endif - } - else - { -#if 0 - SendInfo(fd, "Focus", t->w); -#else - XSetInputFocus (dpy, t->w, RevertToParent, Event->xbutton.time); -#endif - } - } -} + /* make changes to window */ + XConfigureWindow(dpy, balloon.w, CWX | CWY | CWWidth, &window_changes); + /* if background not set in config make it match pager window */ + if (BalloonBack == NULL) + XSetWindowBackground(dpy, balloon.w, t->back); -/* Just maps window ... draw stuff in it later after Expose event - -- ric@giccs.georgetown.edu */ -void MapBalloonWindow (XEvent *event) -{ - PagerWindow *t; - XWindowChanges window_changes; - Window view, dummy; - int view_width, view_height; - int matched_window = 0; - int x, y; - extern char *BalloonBack; - - /* is this the best way to match X event window ID to PagerWindow ID? */ - t = Start; - - while ( ! matched_window ) { - if (t == NULL) { - return; - } - else if ( t->PagerView == event->xcrossing.window ) { - view = t->PagerView; - view_width = t->pager_view_width; - view_height = t->pager_view_height; - matched_window = 1; - } - else if ( t->IconView == event->xcrossing.window ) { - view = t->IconView; - view_width = t->icon_view_width; - view_height = t->icon_view_height; - matched_window = 1; - } - else { - t = t->next; - } - } - - /* associate balloon with its pager window */ - balloon.pw = t; - - /* calculate window width to accommodate string */ - window_changes.width = 4 + XTextWidth(balloon.font, t->icon_name, - strlen(t->icon_name)); - - /* get x and y coords relative to pager window */ - x = (view_width / 2) - (window_changes.width / 2) - balloon.border; - - if ( balloon.yoffset > 0 ) - y = view_height + balloon.yoffset; - else - y = balloon.yoffset - balloon.height - (2 * balloon.border); - - - /* balloon is a top-level window, therefore need to - translate pager window coords to root window coords */ - XTranslateCoordinates(dpy, view, Scr.Root, x, y, - &window_changes.x, &window_changes.y, &dummy); - - - /* make sure balloon doesn't go off screen - (actually 2 pixels from edge rather than 0 just to be pretty :-) */ - - /* too close to left */ - if ( window_changes.x < 2 ) - window_changes.x = 2; - - /* too close to right */ - else if ( window_changes.x + window_changes.width > - Scr.MyDisplayWidth - (2 * balloon.border) - 2 ) - window_changes.x = Scr.MyDisplayWidth - window_changes.width - - (2 * balloon.border) - 2; - - /* too close to top ... make yoffset +ve */ - if ( window_changes.y < 2 ) { - y = - balloon.yoffset + view_height; - XTranslateCoordinates(dpy, view, Scr.Root, x, y, - &window_changes.x, &window_changes.y, &dummy); - } - - /* too close to bottom ... make yoffset -ve */ - else if ( window_changes.y + balloon.height > - Scr.MyDisplayHeight - (2 * balloon.border) - 2 ) { - y = - balloon.yoffset - balloon.height - (2 * balloon.border); - XTranslateCoordinates(dpy, view, Scr.Root, x, y, - &window_changes.x, &window_changes.y, &dummy); - } - - - /* make changes to window */ - XConfigureWindow(dpy, balloon.w, CWX | CWY | CWWidth, &window_changes); - - /* if background not set in config make it match pager window */ - if ( BalloonBack == NULL ) - XSetWindowBackground(dpy, balloon.w, t->back); - - XMapRaised(dpy, balloon.w); + XMapRaised(dpy, balloon.w); } - /* -- ric@giccs.georgetown.edu */ -void UnmapBalloonWindow (void) +void +UnmapBalloonWindow(void) { - XUnmapWindow(dpy, balloon.w); + XUnmapWindow(dpy, balloon.w); } - /* Draws string in balloon window -- call after it's received Expose event -- ric@giccs.georgetown.edu */ -void DrawInBalloonWindow (void) +void +DrawInBalloonWindow(void) { - extern char *BalloonFore; + extern char *BalloonFore; - /* if foreground not set in config make it match pager window */ - if ( BalloonFore == NULL ) - XSetForeground(dpy, BalloonGC, balloon.pw->text); + /* if foreground not set in config make it match pager window */ + if (BalloonFore == NULL) + XSetForeground(dpy, BalloonGC, balloon.pw->text); - XDrawString(dpy, balloon.w, BalloonGC, - 2, balloon.font->ascent, - balloon.pw->icon_name, strlen(balloon.pw->icon_name)); + XDrawString(dpy, balloon.w, BalloonGC, 2, balloon.font->ascent, + balloon.pw->icon_name, strlen(balloon.pw->icon_name)); } Index: fvwm/modules/FvwmSave/FvwmSave.1 =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmSave/FvwmSave.1,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmSave/FvwmSave.1 --- fvwm/modules/FvwmSave/FvwmSave.1 +++ fvwm/modules/FvwmSave/FvwmSave.1 @@ -1,65 +1,59 @@ .\" $OpenBSD: FvwmSave.1,v 1.1.1.1 2006/11/26 10:53:53 matthieu Exp $ .\" t .\" @(#)FvwmSave.1 1/28/94 -.TH FvwmSave 1 "Jan 28 1994" 1.20 +.TH FVWMSAVE 1 "January 28, 1994" "1.20" "FVWM Modules" .UC .SH NAME FvwmSave \- the FVWM desktop-layout saving module .SH SYNOPSIS FvwmSave is spawned by fvwm, so no command line invocation will work. - .SH DESCRIPTION -When called, this module will attempt to save your current desktop -layout into a file called new.xinitrc. Ideally, this file will look just -like .xinitrc, but in reality, you will have to edit it to get a -useable configuration, so be sure to keep a backup of your old .xinitrc. - -Your applications must supply certain hints to the X window system. -Emacs, for example, does not, so FvwmSave can't get any -information from it. - -Also, FvwmSave assumes that certain command line options are -globally accepted by applications, which may not be the case. - +When called, this module attempts to save your current desktop layout into a +file called new.xinitrc. Ideally, this file will look just like .xinitrc, but +in practice you will have to edit it to get a usable configuration, so keep a +backup of your existing .xinitrc. +.PP +Applications must supply certain hints to the X Window System. Emacs, for +example, does not, so FvwmSave cannot obtain any information from it. +.PP +FvwmSave also assumes that certain command line options are globally accepted +by applications, which may not be the case. .SH COPYRIGHTS -The NoClutter program, and the concept for -interfacing this module to the Window Manager, are all original work -by Robert Nation - -Copyright 1994, Robert Nation. No guarantees or warranties or anything -are provided or implied in any way whatsoever. Use this program at your -own risk. Permission to use this program for any purpose is given, -as long as the copyright is kept intact. - - +The NoClutter program, and the concept for interfacing this module to the +window manager, are all original work by Robert Nation. +.PP +Copyright 1994, Robert Nation. No guarantees or warranties or anything are +provided or implied in any way whatsoever. Use this program at your own risk. +Permission to use this program for any purpose is given, as long as the +copyright is kept intact. .SH INITIALIZATION -During initialization, \fINoClutter\fP will eventually search a -configuration file which describes the time-outs and actions to take. -The configuration file is the same file that fvwm used during initialization. - -If the NoClutter executable is linked to another name, ie ln -s -NoClutter OtherClutter, then another module called OtherClutter can be -started, with a completely different configuration than NoClutter, -simply by changing the keyword NoClutter to OtherClutter. This way multiple -clutter-reduction programs can be used. - +During initialization, \fINoClutter\fP searches a configuration file that +describes the time-outs and actions to take. The configuration file is the same +one that fvwm reads during its own initialization. +.PP +If the NoClutter executable is linked to another name, for example `ln -s +NoClutter OtherClutter`, then another module called OtherClutter can be +started with a completely different configuration. This is achieved by changing +the keyword NoClutter to OtherClutter so multiple clutter-reduction programs +can be used. +.PP +FvwmSave follows the same configuration pattern. .SH INVOCATION -NoClutter can be invoked by inserting the line 'Module NoClutter' in -the .fvwmrc file. This can be placed on a line by itself, if NoClutter -is to be spawned during fvwm's initialization, or can be bound to a -menu or mouse button or keystroke to invoke it later. Fvwm will search -directory specified in the ModulePath configuration option to attempt -to locate NoClutter. - +NoClutter can be invoked by inserting the line `Module NoClutter` in the +\&.fvwmrc file. This can be placed on a line by itself if NoClutter is to be +spawned during fvwm's initialization, or it can be bound to a menu, mouse +button, or keystroke to invoke it later. Fvwm searches the directory specified +in the ModulePath configuration option to locate NoClutter. +.PP +FvwmSave is launched by fvwm in the same fashion. .SH CONFIGURATION OPTIONS -NoClutter reads the same .fvwmrc file as fvwm reads when it starts up, -and looks for lines similar to "*NoClutter 3600 Iconify". The format -of these lines is "*NoClutter [time] [command]", where command is any -fvwm built-in command, and time is the time in seconds between when a -window looses focus and when the command is executed. At most 3 -actions can be specified. - - +NoClutter reads the same .fvwmrc file as fvwm reads when it starts up and looks +for lines similar to "*NoClutter 3600 Iconify". The format of these lines is +"*NoClutter [time] [command]", where command is any fvwm built-in command, and +time is the interval in seconds between when a window loses focus and when the +command is executed. At most three actions can be specified. +.PP +FvwmSave recognises the analogous "*FvwmSave" syntax. .SH AUTHOR Robert Nation and Mr. Per Persson (Omnion on IRC) Index: fvwm/modules/FvwmSave/FvwmSave.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmSave/FvwmSave.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmSave/FvwmSave.c --- fvwm/modules/FvwmSave/FvwmSave.c +++ fvwm/modules/FvwmSave/FvwmSave.c @@ -3,38 +3,39 @@ * by Robert Nation and Mr. Per Persson * * Copyright 1994, Robert Nation and Mr. Per Persson. - * No guarantees or warantees or anything + * No guarantees or warantees or anything * are provided or implied in any way whatsoever. Use this program at your * own risk. Permission to use this program for any purpose is given, * as long as the copyright is kept intact. */ -#include "config.h" +#include "FvwmSave.h" -#include -#include -#include -#include -#include #include -#include -#include -#include +#include + +#include +#include #include -#include #include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include #include "../../fvwm/module.h" - -#include "FvwmSave.h" +#include "config.h" +#include "../../fvwm/fvwm_sandbox.h" char *MyName; int fd[2]; struct list *list_root = NULL; -Display *dpy; /* which display are we talking to */ +Display *dpy; /* which display are we talking to */ int ScreenWidth, ScreenHeight; int screen; @@ -46,55 +47,55 @@ long Vx, Vy; * main - start of module * ***********************************************************************/ -int main(int argc, char **argv) +int +main(int argc, char **argv) { - char *temp, *s; - char *display_name = NULL; - - /* Record the program name for error messages */ - temp = argv[0]; - - s=strrchr(argv[0], '/'); - if (s != NULL) - temp = s + 1; - - MyName = safemalloc(strlen(temp)+2); - strcpy(MyName,"*"); - strcat(MyName, temp); - - if((argc != 6)&&(argc != 7)) - { - fprintf(stderr,"%s Version %s should only be executed by fvwm!\n",MyName, - VERSION); - exit(1); - } - - /* Open the X display */ - if (!(dpy = XOpenDisplay(display_name))) - { - fprintf(stderr,"%s: can't open display %s", MyName, - XDisplayName(display_name)); - exit (1); - } - screen= DefaultScreen(dpy); - ScreenHeight = DisplayHeight(dpy,screen); - ScreenWidth = DisplayWidth(dpy,screen); - - /* We should exit if our fvwm pipes die */ - signal (SIGPIPE, DeadPipe); - - fd[0] = atoi(argv[1]); - fd[1] = atoi(argv[2]); - - /* Create a list of all windows */ - /* Request a list of all windows, - * wait for ConfigureWindow packets */ - SendInfo(fd,"Send_WindowList",0); - - Loop(fd); - return 0; -} + char *temp, *s; + char *display_name = NULL; + + /* Record the program name for error messages */ + temp = argv[0]; + + s = strrchr(argv[0], '/'); + if (s != NULL) + temp = s + 1; + + size_t name_len = strlen(temp); + MyName = xmalloc(name_len + 2); + strlcpy(MyName, "*", name_len + 2); + strlcat(MyName, temp, name_len + 2); + + if ((argc != 6) && (argc != 7)) { + fprintf(stderr, + "%s Version %s should only be executed by fvwm!\n", MyName, + VERSION); + exit(1); + } + + /* Open the X display */ + if (!(dpy = XOpenDisplay(display_name))) { + fprintf(stderr, "%s: can't open display %s", MyName, + XDisplayName(display_name)); + exit(1); + } + screen = DefaultScreen(dpy); + ScreenHeight = DisplayHeight(dpy, screen); + ScreenWidth = DisplayWidth(dpy, screen); + /* We should exit if our fvwm pipes die */ + signal(SIGPIPE, DeadPipe); + + fd[0] = atoi(argv[1]); + fd[1] = atoi(argv[2]); + + /* Create a list of all windows */ + /* Request a list of all windows, + * wait for ConfigureWindow packets */ + SendInfo(fd, "Send_WindowList", 0); + + Loop(fd); + return 0; +} /*********************************************************************** * @@ -102,132 +103,129 @@ int main(int argc, char **argv) * Loop - wait for data to process * ***********************************************************************/ -void Loop(int *fd) +void +Loop(int *fd) { - unsigned long header[HEADER_SIZE], *body; - int count; - - while(1) - { - /* read a packet */ - if((count = ReadFvwmPacket(fd[1],header, &body)) > 0) - { - /* dispense with the new packet */ - process_message(header[1],body); - free(body); + unsigned long header[HEADER_SIZE], *body; + int count; + + unveil_home_write("FvwmSave"); + unveil(NULL, NULL); + sandbox_save_state("FvwmSave"); + + while (1) { + /* read a packet */ + if ((count = ReadFvwmPacket(fd[1], header, &body)) > 0) { + /* dispense with the new packet */ + process_message(header[1], body); + free(body); + } } - } } - /*********************************************************************** * * Procedure: * Process message - examines packet types, and takes appropriate action * ***********************************************************************/ -void process_message(unsigned long type,unsigned long *body) +void +process_message(unsigned long type, unsigned long *body) { - switch(type) - { - case M_CONFIGURE_WINDOW: - if(!find_window(body[0])) - add_window(body[0],body); - break; - case M_NEW_PAGE: - list_new_page(body); - break; - case M_END_WINDOWLIST: - do_save(); - break; - default: - break; - } + switch (type) { + case M_CONFIGURE_WINDOW: + if (!find_window(body[0])) + add_window(body[0], body); + break; + case M_NEW_PAGE: + list_new_page(body); + break; + case M_END_WINDOWLIST: + do_save(); + break; + default: + break; + } } - - - - /*********************************************************************** * * Procedure: * find_window - find a window in the current window list * ***********************************************************************/ -struct list *find_window(unsigned long id) +struct list * +find_window(unsigned long id) { - struct list *l; + struct list *l; - if(list_root == NULL) - return NULL; + if (list_root == NULL) + return NULL; - for(l = list_root; l!= NULL; l= l->next) - { - if(l->id == id) - return l; - } - return NULL; + for (l = list_root; l != NULL; l = l->next) { + if (l->id == id) + return l; + } + return NULL; } - - /*********************************************************************** * * Procedure: * add_window - add a new window in the current window list * ***********************************************************************/ -void add_window(unsigned long new_win, unsigned long *body) +void +add_window(unsigned long new_win, unsigned long *body) { - struct list *t; - - if(new_win == 0) - return; - - t = (struct list *)safemalloc(sizeof(struct list)); - t->id = new_win; - t->next = list_root; - t->frame_height = (int)body[6]; - t->frame_width = (int)body[5]; - t->base_width = (int)body[11]; - t->base_height = (int)body[12]; - t->width_inc = (int)body[13]; - t->height_inc = (int)body[14]; - t->frame_x = (int)body[3]; - t->frame_y = (int)body[4];; - t->title_height = (int)body[9];; - t->boundary_width = (int)body[10]; - t->flags = (unsigned long)body[8]; - t->gravity = body[21]; - list_root = t; + struct list *t; + + if (new_win == 0) + return; + + t = (struct list *)xmalloc(sizeof(struct list)); + t->id = new_win; + t->next = list_root; + t->frame_height = (int)body[6]; + t->frame_width = (int)body[5]; + t->base_width = (int)body[11]; + t->base_height = (int)body[12]; + t->width_inc = (int)body[13]; + t->height_inc = (int)body[14]; + t->frame_x = (int)body[3]; + t->frame_y = (int)body[4]; + t->title_height = (int)body[9]; + t->boundary_width = (int)body[10]; + t->flags = (unsigned long)body[8]; + t->gravity = body[21]; + list_root = t; } - - /*********************************************************************** * * Procedure: * list_new_page - capture new-page info * ***********************************************************************/ -void list_new_page(unsigned long *body) +void +list_new_page(unsigned long *body) { - Vx = (long)body[0]; - Vy = (long)body[1]; + Vx = (long)body[0]; + Vy = (long)body[1]; } + /*********************************************************************** * * Procedure: * SIGPIPE handler - SIGPIPE means fvwm is dying * ***********************************************************************/ -void DeadPipe(int nonsense) +void +DeadPipe(int nonsense) { - exit(0); + exit(0); } - /*********************************************************************** * * Procedure: @@ -235,40 +233,35 @@ void DeadPipe(int nonsense) * checks for qoutes and stuff * ***********************************************************************/ -void write_string(FILE *out, char *line) +void +write_string(FILE *out, char *line) { - int len,space = 0, qoute = 0,i; - - len = strlen(line); - - for(i=0;inext) - { - tname[0]=0; - - x1 = t->frame_x; - x2 = ScreenWidth - x1 - t->frame_width - 2; - if(x2 < 0) - x2 = 0; - y1 = t->frame_y; - y2 = ScreenHeight - y1 - t->frame_height - 2; - if(y2 < 0) - y2 = 0; - dheight = t->frame_height - t->title_height - 2*t->boundary_width; - dwidth = t->frame_width - 2*t->boundary_width; - dwidth -= t->base_width ; - dheight -= t->base_height ; - dwidth /= t->width_inc; - dheight /= t->height_inc; - - if ( t->flags & STICKY ) - { - tVx = 0; - tVy = 0; - } - else - { - tVx = Vx; - tVy = Vy; + struct list *t; + char tname[200], loc[30]; + FILE *out; + char **command_list; + int dwidth, dheight, xtermline = 0; + int x1, x2, y1, y2, i, command_count; + long tVx, tVy; + + snprintf(tname, sizeof(tname), "%s/new.xinitrc", + getenv("HOME") ? getenv("HOME") : "."); + out = fopen(tname, "w+"); + if (out == NULL) { + fprintf(stderr, "%s: couldn't open %s for writing\n", + Myname, tname); + return; } - sprintf(tname,"%dx%d",dwidth,dheight); - if ((t->gravity == EastGravity) || - (t->gravity == NorthEastGravity) || - (t->gravity == SouthEastGravity)) - sprintf(loc,"-%d",x2); - else - sprintf(loc,"+%d",x1+(int)tVx); - strcat(tname, loc); - - if((t->gravity == SouthGravity)|| - (t->gravity == SouthEastGravity)|| - (t->gravity == SouthWestGravity)) - sprintf(loc,"-%d",y2); - else - sprintf(loc,"+%d",y1+(int)tVy); - strcat(tname, loc); - - if ( XGetCommand( dpy, t->id, &command_list, &command_count ) ) - { - for (i=0; i < command_count; i++) - { - if ( strncmp( "-geo", command_list[i], 4) == 0) - { - i++; - continue; - } - if ( strncmp( "-ic", command_list[i], 3) == 0) - continue; - if ( strncmp( "-display", command_list[i], 8) == 0) - { - i++; - continue; - } - write_string(out,command_list[i]); - if(strstr(command_list[i], "xterm")) - { - fprintf( out, "-geometry %s ", tname ); - if ( t->flags & ICONIFIED ) - fprintf(out, "-ic "); - xtermline = 1; + for (t = list_root; t != NULL; t = t->next) { + tname[0] = 0; + + x1 = t->frame_x; + x2 = ScreenWidth - x1 - t->frame_width - 2; + if (x2 < 0) + x2 = 0; + y1 = t->frame_y; + y2 = ScreenHeight - y1 - t->frame_height - 2; + if (y2 < 0) + y2 = 0; + dheight = + t->frame_height - t->title_height - 2 * t->boundary_width; + dwidth = t->frame_width - 2 * t->boundary_width; + dwidth -= t->base_width; + dheight -= t->base_height; + if (t->width_inc != 0) + dwidth /= t->width_inc; + if (t->height_inc != 0) + dheight /= t->height_inc; + + if (t->flags & STICKY) { + tVx = 0; + tVy = 0; + } else { + tVx = Vx; + tVy = Vy; } - } - if ( command_count > 0 ) - { - if ( xtermline == 0 ) - { - if ( t->flags & ICONIFIED ) - fprintf(out, "-ic "); - fprintf( out, "-geometry %s &\n", tname ); + snprintf(tname, sizeof(tname), "%dx%d", dwidth, dheight); + if ((t->gravity == EastGravity) || + (t->gravity == NorthEastGravity) || + (t->gravity == SouthEastGravity)) + snprintf(loc, sizeof(loc), "-%d", x2); + else + snprintf(loc, sizeof(loc), "+%d", x1 + (int)tVx); + strlcat(tname, loc, sizeof(tname)); + + if ((t->gravity == SouthGravity) || + (t->gravity == SouthEastGravity) || + (t->gravity == SouthWestGravity)) + snprintf(loc, sizeof(loc), "-%d", y2); + else + snprintf(loc, sizeof(loc), "+%d", y1 + (int)tVy); + strlcat(tname, loc, sizeof(tname)); + + if (XGetCommand(dpy, t->id, &command_list, &command_count)) { + for (i = 0; i < command_count; i++) { + if (strncmp("-geo", command_list[i], 4) == 0) { + i++; + continue; + } + if (strncmp("-ic", command_list[i], 3) == 0) + continue; + if (strncmp("-display", command_list[i], 8) == + 0) { + i++; + continue; + } + write_string(out, command_list[i]); + if (strstr(command_list[i], "xterm")) { + fprintf(out, "-geometry %s ", tname); + if (t->flags & ICONIFIED) + fprintf(out, "-ic "); + xtermline = 1; + } + } + if (command_count > 0) { + if (xtermline == 0) { + if (t->flags & ICONIFIED) + fprintf(out, "-ic "); + fprintf(out, "-geometry %s &\n", tname); + } else { + fprintf(out, "&\n"); + } + } + XFreeStringList(command_list); + xtermline = 0; } - else - { - fprintf( out, "&\n"); - } - } - XFreeStringList( command_list ); - xtermline = 0; } - } - fprintf(out, "fvwm\n"); - fclose( out ); - exit(0); - + fprintf(out, "fvwm\n"); + fclose(out); + exit(0); } - Index: fvwm/modules/FvwmSave/FvwmSave.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmSave/FvwmSave.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmSave/FvwmSave.h --- fvwm/modules/FvwmSave/FvwmSave.h +++ fvwm/modules/FvwmSave/FvwmSave.h @@ -1,38 +1,35 @@ -#include "fvwmlib.h" +#include "fvwmlib.h" #define STICKY 1 -#define ICONIFIED 32 /* is it an icon now? */ +#define ICONIFIED 32 /* is it an icon now? */ -struct list -{ - unsigned long id; - int frame_height; - int frame_width; - int base_width; - int base_height; - int width_inc; - int height_inc; - int frame_x; - int frame_y; - int title_height; - int boundary_width; - unsigned long flags; - unsigned long gravity; - struct list *next; +struct list { + unsigned long id; + int frame_height; + int frame_width; + int base_width; + int base_height; + int width_inc; + int height_inc; + int frame_x; + int frame_y; + int title_height; + int boundary_width; + unsigned long flags; + unsigned long gravity; + struct list *next; }; /************************************************************************* * * Subroutine Prototypes - * + * *************************************************************************/ void Loop(int *fd); -void SendInfo(int *fd,char *message,unsigned long window); -char *safemalloc(int length); +void SendInfo(int *fd, char *message, unsigned long window); struct list *find_window(unsigned long id); void add_window(unsigned long new_win, unsigned long *body); void DeadPipe(int nonsense); -void process_message(unsigned long type,unsigned long *body); +void process_message(unsigned long type, unsigned long *body); void do_save(void); void list_new_page(unsigned long *body); - Index: fvwm/modules/FvwmSaveDesk/FvwmSaveDesk.1 =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmSaveDesk/FvwmSaveDesk.1,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmSaveDesk/FvwmSaveDesk.1 --- fvwm/modules/FvwmSaveDesk/FvwmSaveDesk.1 +++ fvwm/modules/FvwmSaveDesk/FvwmSaveDesk.1 @@ -1,93 +1,86 @@ .\" $OpenBSD: FvwmSaveDesk.1,v 1.2 2007/04/16 16:32:01 jmc Exp $ .\" t -.\" @(#)FvwmSaveDesk.1 6/6/96 -.TH FvwmSaveDesk 1 "Jul 6 1996" 2.0 +.\" @(#)FvwmSaveDesk.1 6/6/96 +.TH FVWMSAVEDESK 1 "July 6, 1996" "2.0" "FVWM Modules" .UC .SH NAME FvwmSaveDesk \- another FVWM desktop-layout saving module .SH SYNOPSIS FvwmSaveDesk is spawned by fvwm, so no command line invocation will work. - .SH DESCRIPTION -When called, this module will attempt to save your current desktop -layout as a definition of extra lines for the function InitFunction -into the file -.I .fvwm2desk -in your home directory. As explain in the other documation, this -function is called at startup of fvwm2. -You have to include this file in -.I .fvwmrc -after the definition of the Function Initfunction. -You can do this by using the module -.I FvwmM4 -or -.I FvwmCpp. - -Your applications must supply certain hints to the X window system. -.I Emacs -and -.I Netscape -, for example, does not, so FvwmSaveDesk can't get any -information from it. - -Also, FvwmSaveDesk assumes that certain command line options are -globally accepted by applications, which may not be the case. - +FvwmSaveDesk saves the current desktop layout as additional lines for the +function InitFunction in the file \fI.fvwm2desk\fP that is created in the +user's home directory. As explained in the other documentation, InitFunction +is executed when fvwm starts. The generated file must therefore be included in +\fI.fvwmrc\fP after the definition of InitFunction. Modules such as FvwmM4 or +FvwmCpp can insert the file automatically. +.PP +Client applications must supply the usual hints to the X Window System. +Programs like Emacs and Netscape do not, so FvwmSaveDesk cannot extract any +information from them. +.PP +FvwmSaveDesk also assumes that certain command line options are accepted by +applications, which may not always be true. .SH SETUP USING FVWMM4 MODULE -The M4 Macro processor substitutes its macros even in the middle of a -word. Because of that you may have problems with predefined macros -such as include or define. To avoid this the GNU M4 has an extra -option to prefix all builtins with 'm4_'. FvwmM4 can be called with -option -m4-prefix and then will provide the option -P to M4. -I personally use the FvwmM4 module this way. - +The M4 macro processor substitutes its macros even in the middle of a word. +Because of that you may have problems with predefined macros such as +`include` or `define`. To avoid this, GNU M4 provides an option to prefix all +built-ins with `m4_`. FvwmM4 accepts the option \-m4-prefix and then passes +\-P to M4. A typical invocation looks like this: +.PP +.EX fvwm2 -f "FvwmM4 -m4-prefix -m4opt -I$HOME $HOME/.fvwmrc" - -Simply add the following line to the end of .fvwmrc: - -m4_include(`.fvwm2desk') . - +.EE +.PP +Add the following line to the end of \fI.fvwmrc\fP: +.PP +.EX +m4_include(`.fvwm2desk') +.EE .SH SETUP USING FVWMCPP MODULE -With the FVWMCPP you may have the problem that the preprocessor -directives starts with the comment charakter '#' and will -complain about unknown directives, if you have comments in your .fvwmrc. - -fvwm2 -f "FvwmCpp -C-I$HOME $HOME/.fvwmrc" - -Simply add the following line to the end of .fvwmrc: - +With FVWMCPP you may encounter problems because preprocessor directives start +with the comment character `#` and may be treated as comments. If this happens +you can invoke fvwm like this: +.PP +.EX +fvwm2 -f "FvwmCpp -C -I$HOME $HOME/.fvwmrc" +.EE +.PP +Then append the following line to the end of \fI.fvwmrc\fP: +.PP +.EX #include ".fvwm2desk" - +.EE .SH INVOCATION -FvwmSaveDesk can be invoked by adding it to a menu or binding it to a -mouse button or keystoke in -the -.I .fvwmrc -file. -Fvwm2 will search directory specified in the ModulePath -configuration option to locate FvwmSaveDesk. - -To insert it to a menu, add the line - -+ "Save Desktop" Module FvwmSaveDesk - -to the menu definition. -I thing binding it to a mouse button is not very useful, but you can -do that, by adding for example this line. - -Mouse 3 R CS Module FvwmSaveDesk - -Than FvwmSaveDesk will be called if you hit the right mouse button -on the root window while holding the shift and control button down. - -You can bind FvwmSaveDesk to a function key F10 for example you have -to insert the following line: - -Key F10 A Module FvwmSaveDesk - -I personally add it as a Button to the module FvwmButtons: - -*FvwmButtons SaveDesc desk.xpm Module FvwmSaveDesk - +FvwmSaveDesk can be invoked by adding it to a menu or by binding it to a mouse +button or keystroke in the \fI.fvwmrc\fP file. Fvwm searches the directory +listed in the ModulePath configuration option to locate FvwmSaveDesk. +.PP +To insert it into a menu, add the line: +.PP +.EX ++ "Save Desktop" Module FvwmSaveDesk +.EE +.PP +Binding the module to a mouse button is less common, but can be done with: +.PP +.EX +Mouse 3 R CS Module FvwmSaveDesk +.EE +.PP +This calls FvwmSaveDesk when you press the right mouse button on the root +window while holding Shift and Control. +.PP +To bind the module to the function key F10, add: +.PP +.EX +Key F10 A Module FvwmSaveDesk +.EE +.PP +You can also place it on a FvwmButtons panel: +.PP +.EX +*FvwmButtons SaveDesc desk.xpm Module FvwmSaveDesk +.EE .SH AUTHOR Carsten Paeth (calle@calle.in-berlin.de) Index: fvwm/modules/FvwmSaveDesk/FvwmSaveDesk.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmSaveDesk/FvwmSaveDesk.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmSaveDesk/FvwmSaveDesk.c --- fvwm/modules/FvwmSaveDesk/FvwmSaveDesk.c +++ fvwm/modules/FvwmSaveDesk/FvwmSaveDesk.c @@ -6,13 +6,13 @@ * is from Carsten Paeth * * Copyright 1994, Robert Nation and Mr. Per Persson. - * No guarantees or warantees or anything + * No guarantees or warantees or anything * are provided or implied in any way whatsoever. Use this program at your * own risk. Permission to use this program for any purpose is given, * as long as the copyright is kept intact. * * Copyright 1995, Carsten Paeth. - * No guarantees or warantees or anything + * No guarantees or warantees or anything * are provided or implied in any way whatsoever. Use this program at your * own risk. Permission to use this program for any purpose is given, * as long as the copyright is kept intact. @@ -22,39 +22,40 @@ #define TRUE 1 #define FALSE 0 -#include "config.h" +#include "FvwmSaveDesk.h" -#include -#include -#include -#include -#include #include -#include -#include -#include +#include + +#include +#include #include -#include #include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include #include "../../fvwm/module.h" - -#include "FvwmSaveDesk.h" +#include "config.h" +#include "../../fvwm/fvwm_sandbox.h" char *MyName; int fd[2]; struct list *list_root = NULL; -Display *dpy; /* which display are we talking to */ +Display *dpy; /* which display are we talking to */ int ScreenWidth, ScreenHeight; int screen; long Vx, Vy; -long CurDesk = 1; /* actual Desktop while being called */ +long CurDesk = 1; /* actual Desktop while being called */ /*********************************************************************** * @@ -62,56 +63,55 @@ long CurDesk = 1; /* actual Desktop while being called */ * main - start of module * ***********************************************************************/ -int main(int argc, char **argv) +int +main(int argc, char **argv) { - char *temp, *s; - char *display_name = NULL; - - /* Record the program name for error messages */ - temp = argv[0]; - - s=strrchr(argv[0], '/'); - if (s != NULL) - temp = s + 1; - - MyName = safemalloc(strlen(temp)+2); - strcpy(MyName,"*"); - strcat(MyName, temp); - - if((argc != 6)&&(argc != 7)) - { - fprintf(stderr,"%s Version %s should only be executed by fvwm!\n",MyName, - VERSION); - exit(1); - } - - /* Open the X display */ - if (!(dpy = XOpenDisplay(display_name))) - { - fprintf(stderr,"%s: can't open display %s", MyName, - XDisplayName(display_name)); - exit (1); - } - screen= DefaultScreen(dpy); - ScreenHeight = DisplayHeight(dpy,screen); - ScreenWidth = DisplayWidth(dpy,screen); - - /* We should exit if our fvwm pipes die */ - signal (SIGPIPE, DeadPipe); - - fd[0] = atoi(argv[1]); - fd[1] = atoi(argv[2]); - - /* Create a list of all windows */ - /* Request a list of all windows, - * wait for ConfigureWindow packets */ - SendInfo(fd,"Send_WindowList",0); - - Loop(fd); - return 0; -} + char *temp, *s; + char *display_name = NULL; + + /* Record the program name for error messages */ + temp = argv[0]; + + s = strrchr(argv[0], '/'); + if (s != NULL) + temp = s + 1; + + size_t name_len = strlen(temp); + MyName = xmalloc(name_len + 2); + strlcpy(MyName, "*", name_len + 2); + strlcat(MyName, temp, name_len + 2); + + if ((argc != 6) && (argc != 7)) { + fprintf(stderr, + "%s Version %s should only be executed by fvwm!\n", MyName, + VERSION); + exit(1); + } + /* Open the X display */ + if (!(dpy = XOpenDisplay(display_name))) { + fprintf(stderr, "%s: can't open display %s", MyName, + XDisplayName(display_name)); + exit(1); + } + screen = DefaultScreen(dpy); + ScreenHeight = DisplayHeight(dpy, screen); + ScreenWidth = DisplayWidth(dpy, screen); + /* We should exit if our fvwm pipes die */ + signal(SIGPIPE, DeadPipe); + + fd[0] = atoi(argv[1]); + fd[1] = atoi(argv[2]); + + /* Create a list of all windows */ + /* Request a list of all windows, + * wait for ConfigureWindow packets */ + SendInfo(fd, "Send_WindowList", 0); + + Loop(fd); + return 0; +} /*********************************************************************** * @@ -119,144 +119,144 @@ int main(int argc, char **argv) * Loop - wait for data to process * ***********************************************************************/ -void Loop(int *fd) +void +Loop(int *fd) { - unsigned long header[HEADER_SIZE], *body; - int count; - - while(1) - { - /* read a packet */ - if((count = ReadFvwmPacket(fd[1],header,&body)) > 0) - { - /* dispense with the new packet */ - process_message(header[1],body); - free(body); + unsigned long header[HEADER_SIZE], *body; + int count; + + unveil_home_write("FvwmSaveDesk"); + unveil(NULL, NULL); + sandbox_save_state("FvwmSaveDesk"); + + while (1) { + /* read a packet */ + if ((count = ReadFvwmPacket(fd[1], header, &body)) > 0) { + /* dispense with the new packet */ + process_message(header[1], body); + free(body); + } } - } } - /*********************************************************************** * * Procedure: * Process message - examines packet types, and takes appropriate action * ***********************************************************************/ -void process_message(unsigned long type,unsigned long *body) +void +process_message(unsigned long type, unsigned long *body) { - switch(type) - { - case M_CONFIGURE_WINDOW: - if(!find_window(body[0])) - add_window(body[0],body); - break; - case M_WINDOW_NAME: - { - struct list *l; - if ((l = find_window(body[0])) != 0) { - l->name = (char *)safemalloc(strlen((char *)&body[3])+1); - strcpy(l->name,(char *)&body[3]); + switch (type) { + case M_CONFIGURE_WINDOW: + if (!find_window(body[0])) + add_window(body[0], body); + break; + case M_WINDOW_NAME: { + struct list *l; + if ((l = find_window(body[0])) != 0) { + size_t name_len = strlen((char *)&body[3]); + free(l->name); + l->name = (char *)xmalloc(name_len + 1); + strlcpy(l->name, (char *)&body[3], name_len + 1); + } + } + break; + case M_NEW_PAGE: + list_new_page(body); + break; + case M_NEW_DESK: + CurDesk = (long)body[0]; + break; + case M_END_WINDOWLIST: + do_save(); + break; + default: + break; } - } - break; - case M_NEW_PAGE: - list_new_page(body); - break; - case M_NEW_DESK: - CurDesk = (long)body[0]; - break; - case M_END_WINDOWLIST: - do_save(); - break; - default: - break; - } } - - /*********************************************************************** * * Procedure: * find_window - find a window in the current window list * ***********************************************************************/ -struct list *find_window(unsigned long id) +struct list * +find_window(unsigned long id) { - struct list *l; + struct list *l; - if(list_root == NULL) - return NULL; + if (list_root == NULL) + return NULL; - for(l = list_root; l!= NULL; l= l->next) - { - if(l->id == id) - return l; - } - return NULL; + for (l = list_root; l != NULL; l = l->next) { + if (l->id == id) + return l; + } + return NULL; } - - /*********************************************************************** * * Procedure: * add_window - add a new window in the current window list * ***********************************************************************/ -void add_window(unsigned long new_win, unsigned long *body) +void +add_window(unsigned long new_win, unsigned long *body) { - struct list *t; - - if(new_win == 0) - return; - - t = (struct list *)safemalloc(sizeof(struct list)); - t->id = new_win; - t->next = list_root; - t->frame_height = (int)body[6]; - t->frame_width = (int)body[5]; - t->base_width = (int)body[11]; - t->base_height = (int)body[12]; - t->width_inc = (int)body[13]; - t->height_inc = (int)body[14]; - t->frame_x = (int)body[3]; - t->frame_y = (int)body[4];; - t->title_height = (int)body[9];; - t->boundary_width = (int)body[10]; - t->flags = (unsigned long)body[8]; - t->gravity = body[21]; - t->desk = body[7]; - t->name = 0; - list_root = t; + struct list *t; + + if (new_win == 0) + return; + + t = (struct list *)xmalloc(sizeof(struct list)); + t->id = new_win; + t->next = list_root; + t->frame_height = (int)body[6]; + t->frame_width = (int)body[5]; + t->base_width = (int)body[11]; + t->base_height = (int)body[12]; + t->width_inc = (int)body[13]; + t->height_inc = (int)body[14]; + t->frame_x = (int)body[3]; + t->frame_y = (int)body[4]; + t->title_height = (int)body[9]; + t->boundary_width = (int)body[10]; + t->flags = (unsigned long)body[8]; + t->gravity = body[21]; + t->desk = body[7]; + t->name = 0; + list_root = t; } - - /*********************************************************************** * * Procedure: * list_new_page - capture new-page info * ***********************************************************************/ -void list_new_page(unsigned long *body) +void +list_new_page(unsigned long *body) { - Vx = (long)body[0]; - Vy = (long)body[1]; + Vx = (long)body[0]; + Vy = (long)body[1]; } + /*********************************************************************** * * Procedure: * SIGPIPE handler - SIGPIPE means fvwm is dying * ***********************************************************************/ -void DeadPipe(int nonsense) +void +DeadPipe(int nonsense) { - exit(0); + exit(0); } - /*********************************************************************** * * Procedure: @@ -264,155 +264,144 @@ void DeadPipe(int nonsense) * checks for qoutes and stuff * ***********************************************************************/ -void write_string(FILE *out, char *line) +void +write_string(FILE *out, char *line) { - int len,space = 0, qoute = 0,i; - - len = strlen(line); - - for(i=0;iframe_x; - x2 = ScreenWidth - x1 - t->frame_width - 2; - if(x2 < 0) - x2 = 0; - y1 = t->frame_y; - y2 = ScreenHeight - y1 - t->frame_height - 2; - if(y2 < 0) - y2 = 0; - dheight = t->frame_height - t->title_height - 2*t->boundary_width; - dwidth = t->frame_width - 2*t->boundary_width; - dwidth -= t->base_width ; - dheight -= t->base_height ; - dwidth /= t->width_inc; - dheight /= t->height_inc; - - if ( t->flags & STICKY ) - { - tVx = 0; - tVy = 0; - } - else - { - tVx = Vx; - tVy = Vy; - } - sprintf(tname,"%dx%d",dwidth,dheight); - if ((t->gravity == EastGravity) || - (t->gravity == NorthEastGravity) || - (t->gravity == SouthEastGravity)) - sprintf(loc,"-%d",x2); - else - sprintf(loc,"+%d",x1+(int)tVx); - strcat(tname, loc); - - if((t->gravity == SouthGravity)|| - (t->gravity == SouthEastGravity)|| - (t->gravity == SouthWestGravity)) - sprintf(loc,"-%d",y2); - else - sprintf(loc,"+%d",y1+(int)tVy); - strcat(tname, loc); - - if ( XGetCommand( dpy, t->id, &command_list, &command_count ) ) - { - if (*curdesk != t->desk) - { - fprintf( out, "%s\t\"I\" Desk 0 %ld\n", *isfirstline ? "" : "+", t->desk); - fflush ( out ); - if (*isfirstline) *isfirstline = 0; - *curdesk = t->desk; - } - - fprintf( out, "%s\t\t\"I\" Exec ", *isfirstline ? "" : "+"); - if (*isfirstline) *isfirstline = 0; - fflush ( out ); - for (i=0; i < command_count; i++) - { - if ( strncmp( "-geo", command_list[i], 4) == 0) - { - i++; - continue; - } - if ( strncmp( "-ic", command_list[i], 3) == 0) - continue; - if ( strncmp( "-display", command_list[i], 8) == 0) - { - i++; - continue; - } - write_string(out,command_list[i]); - fflush ( out ); - if(strstr(command_list[i], "xterm")) - { - fprintf( out, "-geometry %s ", tname ); - if ( t->flags & ICONIFIED ) - fprintf(out, "-ic "); - xtermline = 1; - fflush ( out ); - } - } - if ( command_count > 0 ) - { - if ( xtermline == 0 ) - { - if ( t->flags & ICONIFIED ) - fprintf(out, "-ic "); - fprintf( out, "-geometry %s &\n", tname); - } - else - { - fprintf( out, "&\n"); - } - } - if (emit_wait) { - if (t->name) - fprintf( out, "+\t\t\"I\" Wait %s\n", t->name); - else fprintf( out, "+\t\t\"I\" Wait %s\n", command_list[0]); - fflush( out ); - } - XFreeStringList( command_list ); - xtermline = 0; - } + char tname[200], loc[30]; + char **command_list; + int dwidth, dheight, xtermline = 0; + int x1, x2, y1, y2, i, command_count; + long tVx, tVy; + + tname[0] = 0; + + x1 = t->frame_x; + x2 = ScreenWidth - x1 - t->frame_width - 2; + if (x2 < 0) + x2 = 0; + y1 = t->frame_y; + y2 = ScreenHeight - y1 - t->frame_height - 2; + if (y2 < 0) + y2 = 0; + dheight = t->frame_height - t->title_height - 2 * t->boundary_width; + dwidth = t->frame_width - 2 * t->boundary_width; + dwidth -= t->base_width; + dheight -= t->base_height; + if (t->width_inc != 0) + dwidth /= t->width_inc; + if (t->height_inc != 0) + dheight /= t->height_inc; + + if (t->flags & STICKY) { + tVx = 0; + tVy = 0; + } else { + tVx = Vx; + tVy = Vy; + } + snprintf(tname, sizeof(tname), "%dx%d", dwidth, dheight); + if ((t->gravity == EastGravity) || (t->gravity == NorthEastGravity) || + (t->gravity == SouthEastGravity)) + snprintf(loc, sizeof(loc), "-%d", x2); + else + snprintf(loc, sizeof(loc), "+%d", x1 + (int)tVx); + strlcat(tname, loc, sizeof(tname)); + + if ((t->gravity == SouthGravity) || (t->gravity == SouthEastGravity) || + (t->gravity == SouthWestGravity)) + snprintf(loc, sizeof(loc), "-%d", y2); + else + snprintf(loc, sizeof(loc), "+%d", y1 + (int)tVy); + strlcat(tname, loc, sizeof(tname)); + + if (XGetCommand(dpy, t->id, &command_list, &command_count)) { + if (*curdesk != t->desk) { + fprintf(out, "%s\t\"I\" Desk 0 %ld\n", + *isfirstline ? "" : "+", t->desk); + fflush(out); + if (*isfirstline) + *isfirstline = 0; + *curdesk = t->desk; + } + + fprintf(out, "%s\t\t\"I\" Exec ", *isfirstline ? "" : "+"); + if (*isfirstline) + *isfirstline = 0; + fflush(out); + for (i = 0; i < command_count; i++) { + if (strncmp("-geo", command_list[i], 4) == 0) { + i++; + continue; + } + if (strncmp("-ic", command_list[i], 3) == 0) + continue; + if (strncmp("-display", command_list[i], 8) == 0) { + i++; + continue; + } + write_string(out, command_list[i]); + fflush(out); + if (strstr(command_list[i], "xterm")) { + fprintf(out, "-geometry %s ", tname); + if (t->flags & ICONIFIED) + fprintf(out, "-ic "); + xtermline = 1; + fflush(out); + } + } + if (command_count > 0) { + if (xtermline == 0) { + if (t->flags & ICONIFIED) + fprintf(out, "-ic "); + fprintf(out, "-geometry %s &\n", tname); + } else { + fprintf(out, "&\n"); + } + } + if (emit_wait) { + if (t->name) + fprintf(out, "+\t\t\"I\" Wait %s\n", t->name); + else if (command_count > 0) + fprintf(out, "+\t\t\"I\" Wait %s\n", + command_list[0]); + fflush(out); + } + XFreeStringList(command_list); + xtermline = 0; + } } - /*********************************************************************** * * Procedure: @@ -420,52 +409,55 @@ void do_save_command(FILE *out, struct list *t, int *curdesk, * finds time for next action to be performed. * ***********************************************************************/ -void do_save(void) +void +do_save(void) { - struct list *t; - char fnbuf[200]; - FILE *out; - int maxdesk = 0; - int actdesk = -1; - int curdesk; - int isfirstline = 1; - - for (t = list_root; t != NULL; t = t->next) - if (t->desk > maxdesk) - maxdesk = t->desk; - - sprintf(fnbuf, "%s/.fvwm2desk", getenv( "HOME" ) ); - out = fopen( fnbuf, "w" ); - - fprintf( out, "AddToFunc InitFunction"); - fflush ( out ); - - /* - * Generate all Desks except 'CurDesk' - */ - for (curdesk = 0; curdesk <= maxdesk; curdesk++) - { - for (t = list_root; t != NULL; t = t->next) - { - if (t->desk != CurDesk && curdesk == t->desk) - do_save_command(out, t, &actdesk, 1, &isfirstline); - } - } - /* - * Generate 'CurDesk' - */ - for (t = list_root; t != NULL; t = t->next) - { - if (t->desk == CurDesk) - do_save_command(out, t, &actdesk, 0, &isfirstline); - } - - if (actdesk != CurDesk) - fprintf( out, "+\t\"I\" Desk 0 %ld\n", CurDesk); - - fflush( out ); - fclose( out ); - exit(0); + struct list *t; + char fnbuf[200]; + FILE *out; + int maxdesk = 0; + int actdesk = -1; + int curdesk; + int isfirstline = 1; + + for (t = list_root; t != NULL; t = t->next) + if (t->desk > maxdesk) + maxdesk = t->desk; + + snprintf(fnbuf, sizeof(fnbuf), "%s/.fvwm2desk", + getenv("HOME") ? getenv("HOME") : "."); + out = fopen(fnbuf, "w"); + if (out == NULL) { + fprintf(stderr, "%s: couldn't open %s for writing\n", + Myname, fnbuf); + return; + } -} + fprintf(out, "AddToFunc InitFunction"); + fflush(out); + + /* + * Generate all Desks except 'CurDesk' + */ + for (curdesk = 0; curdesk <= maxdesk; curdesk++) { + for (t = list_root; t != NULL; t = t->next) { + if (t->desk != CurDesk && curdesk == t->desk) + do_save_command( + out, t, &actdesk, 1, &isfirstline); + } + } + /* + * Generate 'CurDesk' + */ + for (t = list_root; t != NULL; t = t->next) { + if (t->desk == CurDesk) + do_save_command(out, t, &actdesk, 0, &isfirstline); + } + + if (actdesk != CurDesk) + fprintf(out, "+\t\"I\" Desk 0 %ld\n", CurDesk); + fflush(out); + fclose(out); + exit(0); +} Index: fvwm/modules/FvwmSaveDesk/FvwmSaveDesk.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmSaveDesk/FvwmSaveDesk.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmSaveDesk/FvwmSaveDesk.h --- fvwm/modules/FvwmSaveDesk/FvwmSaveDesk.h +++ fvwm/modules/FvwmSaveDesk/FvwmSaveDesk.h @@ -1,40 +1,37 @@ -#include "fvwmlib.h" +#include "fvwmlib.h" #define STICKY 1 -#define ICONIFIED 32 /* is it an icon now? */ +#define ICONIFIED 32 /* is it an icon now? */ -struct list -{ - unsigned long id; - int frame_height; - int frame_width; - int base_width; - int base_height; - int width_inc; - int height_inc; - int frame_x; - int frame_y; - int title_height; - int boundary_width; - unsigned long flags; - unsigned long gravity; - long desk; - struct list *next; - char *name; +struct list { + unsigned long id; + int frame_height; + int frame_width; + int base_width; + int base_height; + int width_inc; + int height_inc; + int frame_x; + int frame_y; + int title_height; + int boundary_width; + unsigned long flags; + unsigned long gravity; + long desk; + struct list *next; + char *name; }; /************************************************************************* * * Subroutine Prototypes - * + * *************************************************************************/ void Loop(int *fd); -void SendInfo(int *fd,char *message,unsigned long window); -char *safemalloc(int length); +void SendInfo(int *fd, char *message, unsigned long window); struct list *find_window(unsigned long id); void add_window(unsigned long new_win, unsigned long *body); void DeadPipe(int nonsense); -void process_message(unsigned long type,unsigned long *body); +void process_message(unsigned long type, unsigned long *body); void do_save(void); void list_new_page(unsigned long *body); - Index: fvwm/modules/FvwmScroll/FvwmScroll.1 =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmScroll/FvwmScroll.1,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmScroll/FvwmScroll.1 --- fvwm/modules/FvwmScroll/FvwmScroll.1 +++ fvwm/modules/FvwmScroll/FvwmScroll.1 @@ -1,77 +1,53 @@ .\" $OpenBSD: FvwmScroll.1,v 1.1.1.1 2006/11/26 10:53:54 matthieu Exp $ .\" t -.\" @(#)FvwmScroll.1 4/14/94 -.TH FvwmScroll 1 "April 14 1994" 1.20 +.\" @(#)FvwmScroll.1 4/14/94 +.TH FVWMSCROLL 1 "April 14, 1994" "1.20" "FVWM Modules" .UC .SH NAME FvwmScroll \- the FVWM scroll-bar module .SH SYNOPSIS FvwmScroll is spawned by fvwm, so no command line invocation will work. - .SH DESCRIPTION -The FvwmScroll module questions the user to select a target window, if -the module was not launched from within a window context in Fvwm. -After that, it adds scroll bars to the selected window, to reduce the -total desktop space consumed by the window. - - -FvwmScroll reads the same .fvwmrc file as fvwm reads when it starts up, -and looks for lines similar to "*FvwmScrollFore green". - -FvwmScroll should not be used with windows which move or resize -themselves, nor should it be used with windows which set the -WM_COLORMAP_WINDOWS property. Operation is fine with windows that have -a private colormap. - +FvwmScroll questions the user to select a target window if the module was not +launched from within a window context in fvwm. After the selection it adds +scroll bars to the chosen window to reduce the desktop space the client +occupies. +.PP +The module reads the same .fvwmrc file as fvwm at start-up and looks for +entries such as "*FvwmScrollFore green". +.PP +FvwmScroll should not be used with windows that move or resize themselves, nor +with clients that set the WM_COLORMAP_WINDOWS property. It works correctly with +windows that own a private colormap. .SH COPYRIGHTS -The FvwmScroll program, and the concept for -interfacing this module to the Window Manager, are all original work -by Robert Nation. - -Copyright 1994, Robert Nation. No guarantees or -warranties or anything -are provided or implied in any way whatsoever. Use this program at your -own risk. Permission to use this program for any purpose is given, -as long as the copyright is kept intact. - - +The FvwmScroll program, and the concept for interfacing this module to the +window manager, are original work by Robert Nation. +.PP +Copyright 1994, Robert Nation. No guarantees or warranties are provided or +implied. Use this program at your own risk. Permission to use this program for +any purpose is granted, provided the copyright notice remains intact. .SH INITIALIZATION -During initialization, \fIFvwmScroll\fP will eventually search a -configuration file which describes the colors to use. -The configuration file is the same file that fvwm used during initialization. - -If the FvwmScroll executable is linked to another name, ie ln -s -FvwmScroll MoreScroll, then another module called MoreScroll can be -started, with a completely different configuration than FvwmScroll, -simply by changing the keyword FvwmScroll to MoreScroll. - +During initialization, \fIFvwmScroll\fP searches a configuration file that +describes the colors to use. The configuration file is the same one fvwm reads +when it starts. +.PP +If the FvwmScroll executable is linked to another name, for example `ln -s +FvwmScroll MoreScroll`, you can start a module called MoreScroll with a +different configuration simply by changing the keyword FvwmScroll to +MoreScroll. .SH INVOCATION -FvwmScroll can be invoked by binding the action 'Module -FvwmScroll x y' to a menu or key-stroke in the .fvwmrc file. -The parameter x and y are integers, which describe the horizontal and -vertical window size reduction. -Fvwm will search -directory specified in the ModulePath configuration option to attempt -to locate FvwmScroll. Although nothing keeps you from launching -FvwmScroll at start-up time, you probably don't want to. - +FvwmScroll can be invoked by binding the action `Module FvwmScroll x y` to a +menu entry or keystroke in the .fvwmrc file. The parameters \fIx\fP and \fIy\fP +are integers that describe the horizontal and vertical window size reductions. +Fvwm searches the directory specified by the ModulePath option to locate the +module. While you can start FvwmScroll during fvwm initialization, it is +rarely desirable. .SH CONFIGURATION OPTIONS -FvwmScroll reads the same .fvwmrc file as fvwm reads when it starts up, -and looks for lines as listed below: - +FvwmScroll reads the same .fvwmrc file as fvwm at start-up and understands the +following directives: .IP "*FvwmScrollFore \fIcolor\fP" -Tells the module to use \fIcolor\fP instead of grey for scroll bars -themselves. - +Use \fIcolor\fP instead of grey for the scroll bars themselves. .IP "*FvwmScrollBack \fIcolor\fP" -Tells the module to use \fIcolor\fP instead of black for the window -background. - -.SH BUGS -When the scroll bars are removed by clicking on the button in the -lower right corner, the window does not restore its location -correctly. - +Use \fIcolor\fP instead of black for the window background. .SH AUTHOR -Robert Nation - +Robert Nation Index: fvwm/modules/FvwmScroll/FvwmScroll.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmScroll/FvwmScroll.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmScroll/FvwmScroll.c --- fvwm/modules/FvwmScroll/FvwmScroll.c +++ fvwm/modules/FvwmScroll/FvwmScroll.c @@ -11,28 +11,30 @@ #define TRUE 1 #define FALSE 0 -#include "config.h" +#include +#include -#include -#include #include +#include +#include #include -#include -#include + +#include "config.h" +#include "../../fvwm/fvwm_sandbox.h" #if HAVE_SYS_SELECT_H #include #endif -#include -#include -#include +#include +#include #include -#include #include -#include -#include +#include #include +#include +#include +#include #include "../../fvwm/module.h" #include "FvwmScroll.h" @@ -41,7 +43,7 @@ char *MyName; int fd_width; int fd[2]; -Display *dpy; /* which display are we talking to */ +Display *dpy; /* which display are we talking to */ Window Root; int screen; int x_fd; @@ -52,8 +54,7 @@ char *BackColor = "black"; Window app_win; -#define MW_EVENTS (ExposureMask | ButtonReleaseMask | KeyReleaseMask) - +#define MW_EVENTS (ExposureMask | ButtonReleaseMask | KeyReleaseMask) /*********************************************************************** * @@ -61,211 +62,197 @@ Window app_win; * main - start of module * ***********************************************************************/ -int main(int argc, char **argv) +int +main(int argc, char **argv) { - char *temp, *s; - char *display_name = NULL; - int Clength; - char *tline; - - /* Save the program name for error messages and config parsing */ - temp = argv[0]; - s=strrchr(argv[0], '/'); - if (s != NULL) - temp = s + 1; - - MyName = safemalloc(strlen(temp)+2); - strcpy(MyName,"*"); - strcat(MyName, temp); - Clength = strlen(MyName); - - if(argc < 6) - { - fprintf(stderr,"%s Version %s should only be executed by fvwm!\n",MyName, - VERSION); - exit(1); - } - - if(argc >= 7) - { - extern int Reduction_H; - Reduction_H = atoi(argv[6]); - } - - if(argc >= 8) - { - extern int Reduction_V; - Reduction_V = atoi(argv[7]); - } - - /* Dead pipe == dead fvwm */ - signal (SIGPIPE, DeadPipe); - - fd[0] = atoi(argv[1]); - fd[1] = atoi(argv[2]); - - /* An application window may have already been selected - look for it */ - sscanf(argv[4],"%x",(unsigned int *)&app_win); - - /* Open the Display */ - if (!(dpy = XOpenDisplay(display_name))) - { - fprintf(stderr,"%s: can't open display %s", MyName, - XDisplayName(display_name)); - exit (1); - } - x_fd = XConnectionNumber(dpy); - screen= DefaultScreen(dpy); - Root = RootWindow(dpy, screen); - d_depth = DefaultDepth(dpy, screen); - - ScreenHeight = DisplayHeight(dpy,screen); - ScreenWidth = DisplayWidth(dpy,screen); - - /* scan config file for set-up parameters */ - /* Colors and fonts */ - GetConfigLine(fd,&tline); - - while(tline != (char *)0) - { - if(strlen(tline)>1) - { - if(strncasecmp(tline,CatString3(MyName, "Back",""), - Clength+4)==0) - { - CopyString(&BackColor,&tline[Clength+4]); - } + char *temp, *s; + char *display_name = NULL; + int Clength; + char *tline; + + /* Save the program name for error messages and config parsing */ + temp = argv[0]; + s = strrchr(argv[0], '/'); + if (s != NULL) + temp = s + 1; + + size_t name_len = strlen(temp); + MyName = xmalloc(name_len + 2); + strlcpy(MyName, "*", name_len + 2); + strlcat(MyName, temp, name_len + 2); + Clength = strlen(MyName); + + if (argc < 6) { + fprintf(stderr, + "%s Version %s should only be executed by fvwm!\n", MyName, + VERSION); + exit(1); } - GetConfigLine(fd,&tline); - } - /* sever our connection with fvwm */ - close(fd[0]); - close(fd[1]); - if(app_win == 0) - GetTargetWindow(&app_win); + if (argc >= 7) { + extern int Reduction_H; + Reduction_H = atoi(argv[6]); + } - if(app_win == 0) - return 0; + if (argc >= 8) { + extern int Reduction_V; + Reduction_V = atoi(argv[7]); + } - fd_width = GetFdWidth(); + /* Dead pipe == dead fvwm */ + signal(SIGPIPE, DeadPipe); - GrabWindow(app_win); - Loop(app_win); - return 0; -} + fd[0] = atoi(argv[1]); + fd[1] = atoi(argv[2]); + + /* An application window may have already been selected - look for it */ + sscanf(argv[4], "%x", (unsigned int *)&app_win); + + /* Open the Display */ + if (!(dpy = XOpenDisplay(display_name))) { + fprintf(stderr, "%s: can't open display %s", MyName, + XDisplayName(display_name)); + exit(1); + } + x_fd = XConnectionNumber(dpy); + screen = DefaultScreen(dpy); + Root = RootWindow(dpy, screen); + d_depth = DefaultDepth(dpy, screen); + + ScreenHeight = DisplayHeight(dpy, screen); + ScreenWidth = DisplayWidth(dpy, screen); + + /* scan config file for set-up parameters */ + /* Colors and fonts */ + GetConfigLine(fd, &tline); + + while (tline != (char *)0) { + if (strlen(tline) > 1) { + if (strncasecmp(tline, CatString3(MyName, "Back", ""), + Clength + 4) == 0) { + CopyString(&BackColor, &tline[Clength + 4]); + } + } + GetConfigLine(fd, &tline); + } + + /* sever our connection with fvwm */ + sandbox_x11_only("FvwmScroll"); + close(fd[0]); + close(fd[1]); + if (app_win == 0) + GetTargetWindow(&app_win); + if (app_win == 0) + return 0; + + fd_width = GetFdWidth(); + + GrabWindow(app_win); + Loop(app_win); + return 0; +} /*********************************************************************** * * Detected a broken pipe - time to exit * **********************************************************************/ -void DeadPipe(int nonsense) +void +DeadPipe(int nonsense) { - extern Atom wm_del_win; + extern Atom wm_del_win; - XReparentWindow(dpy,app_win,Root,0,0); - send_clientmessage (dpy, app_win, wm_del_win, CurrentTime); - XSync(dpy,0); - exit(0); + XReparentWindow(dpy, app_win, Root, 0, 0); + send_clientmessage(dpy, app_win, wm_del_win, CurrentTime); + XSync(dpy, 0); + exit(0); } - /********************************************************************** * * If no application window was indicated on the command line, question * the user to select one * *********************************************************************/ -void GetTargetWindow(Window *app_win) +void +GetTargetWindow(Window *app_win) { - XEvent eventp; - int val = -10,trials; - Window target_win; - - trials = 0; - while((trials <100)&&(val != GrabSuccess)) - { - val=XGrabPointer(dpy, Root, True, - ButtonReleaseMask, - GrabModeAsync, GrabModeAsync, Root, - XCreateFontCursor(dpy,XC_crosshair), - CurrentTime); - if(val != GrabSuccess) - { - usleep(1000); + XEvent eventp; + int val = -10, trials; + Window target_win; + + trials = 0; + while ((trials < 100) && (val != GrabSuccess)) { + val = XGrabPointer(dpy, Root, True, ButtonReleaseMask, + GrabModeAsync, GrabModeAsync, Root, + XCreateFontCursor(dpy, XC_crosshair), CurrentTime); + if (val != GrabSuccess) { + usleep(1000); + } + trials++; + } + if (val != GrabSuccess) { + fprintf(stderr, "%s: Couldn't grab the cursor!\n", MyName); + exit(1); } - trials++; - } - if(val != GrabSuccess) - { - fprintf(stderr,"%s: Couldn't grab the cursor!\n",MyName); - exit(1); - } - XMaskEvent(dpy, ButtonReleaseMask,&eventp); - XUngrabPointer(dpy,CurrentTime); - XSync(dpy,0); - *app_win = eventp.xany.window; - if(eventp.xbutton.subwindow != None) - *app_win = eventp.xbutton.subwindow; - - target_win = ClientWindow(*app_win); - if(target_win != None) - *app_win = target_win; + XMaskEvent(dpy, ButtonReleaseMask, &eventp); + XUngrabPointer(dpy, CurrentTime); + XSync(dpy, 0); + *app_win = eventp.xany.window; + if (eventp.xbutton.subwindow != None) + *app_win = eventp.xbutton.subwindow; + + target_win = ClientWindow(*app_win); + if (target_win != None) + *app_win = target_win; } - -void nocolor(char *a, char *b) +void +nocolor(char *a, char *b) { - fprintf(stderr,"FvwmInitBanner: can't %s %s\n", a,b); + fprintf(stderr, "FvwmInitBanner: can't %s %s\n", a, b); } - - /**************************************************************************** * * Find the actual application * ***************************************************************************/ -Window ClientWindow(Window input) +Window +ClientWindow(Window input) { - Atom _XA_WM_STATE; - unsigned int nchildren; - Window root, parent, *children,target; - unsigned long nitems, bytesafter; - unsigned char *prop; - Atom atype; - int aformat; - int i; - - _XA_WM_STATE = XInternAtom (dpy, "WM_STATE", False); - - if (XGetWindowProperty (dpy,input, _XA_WM_STATE , 0L, - 3L , False, _XA_WM_STATE,&atype, - &aformat, &nitems, &bytesafter, - &prop) == Success) - { - if(prop != NULL) - { - XFree(prop); - return input; + Atom _XA_WM_STATE; + unsigned int nchildren; + Window root, parent, *children, target; + unsigned long nitems, bytesafter; + unsigned char *prop; + Atom atype; + int aformat; + int i; + + _XA_WM_STATE = XInternAtom(dpy, "WM_STATE", False); + + if (XGetWindowProperty(dpy, input, _XA_WM_STATE, 0L, 3L, False, + _XA_WM_STATE, &atype, &aformat, &nitems, &bytesafter, + &prop) == Success) { + if (prop != NULL) { + XFree(prop); + return input; + } } - } - - if(!XQueryTree(dpy, input, &root, &parent, &children, &nchildren)) - return None; - - for (i = 0; i < nchildren; i++) - { - target = ClientWindow(children[i]); - if(target != None) - { - XFree((char *)children); - return target; + + if (!XQueryTree(dpy, input, &root, &parent, &children, &nchildren)) + return None; + + for (i = 0; i < nchildren; i++) { + target = ClientWindow(children[i]); + if (target != None) { + XFree((char *)children); + return target; + } } - } - XFree((char *)children); - return None; + XFree((char *)children); + return None; } Index: fvwm/modules/FvwmScroll/FvwmScroll.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmScroll/FvwmScroll.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmScroll/FvwmScroll.h --- fvwm/modules/FvwmScroll/FvwmScroll.h +++ fvwm/modules/FvwmScroll/FvwmScroll.h @@ -1,13 +1,12 @@ -#include "fvwmlib.h" +#include "fvwmlib.h" extern Display *dpy; extern char *MyName; extern Window Root; extern int screen; extern int d_depth; -extern int x_fd,fd_width; +extern int x_fd, fd_width; -char *safemalloc(int length); void DeadPipe(int nonsense); void GetTargetWindow(Window *app_win); void CopyString(char **dest, char *source); @@ -16,19 +15,18 @@ void nocolor(char *a, char *b); char *CatString3(char *a, char *b, char *c); Window ClientWindow(Window input); -void RelieveWindow(Window win,int x,int y,int w,int h, GC rgc,GC sgc); -void CreateWindow(int x, int y,int w, int h); +void RelieveWindow(Window win, int x, int y, int w, int h, GC rgc, GC sgc); +void CreateWindow(int x, int y, int w, int h); Pixel GetShadow(Pixel background); Pixel GetHilite(Pixel background); Pixel GetColor(char *name); void Loop(Window target); void RedrawWindow(Window target); void change_window_name(char *str); -extern void send_clientmessage (Display *disp, Window w, Atom a, Time timestamp); +extern void send_clientmessage(Display *disp, Window w, Atom a, Time timestamp); void GrabWindow(Window target); void change_icon_name(char *str); -void RedrawLeftButton(GC rgc, GC sgc,int x1,int y1); -void RedrawRightButton(GC rgc, GC sgc,int x1,int y1); -void RedrawTopButton(GC rgc, GC sgc,int x1,int y1); -void RedrawBottomButton(GC rgc, GC sgc,int x1,int y1); - +void RedrawLeftButton(GC rgc, GC sgc, int x1, int y1); +void RedrawRightButton(GC rgc, GC sgc, int x1, int y1); +void RedrawTopButton(GC rgc, GC sgc, int x1, int y1); +void RedrawBottomButton(GC rgc, GC sgc, int x1, int y1); Index: fvwm/modules/FvwmScroll/GrabWindow.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmScroll/GrabWindow.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmScroll/GrabWindow.c --- fvwm/modules/FvwmScroll/GrabWindow.c +++ fvwm/modules/FvwmScroll/GrabWindow.c @@ -13,34 +13,31 @@ #include "config.h" -#ifdef HAVE_SYS_BSDTYPES_H -#include /* Saul */ #endif -#include -#include +#include +#include + #include +#include +#include #include -#include -#include #if HAVE_SYS_SELECT_H #include #endif -#include -#include -#include -#include "../../fvwm/module.h" - +#include +#include #include -#include #include -#include -#include +#include +#include +#include +#include +#include "../../fvwm/module.h" #include "FvwmScroll.h" - int Width = 300, Height = 300; int target_width, target_height; int target_x_offset = 0, target_y_offset = 0; @@ -54,13 +51,14 @@ int Reduction_V = 2; #define PAD_WIDTH2 3 #define PAD_WIDTH3 5 -Window main_win,holder_win; -Pixel back_pix, fore_pix, hilite_pix,shadow_pix; +Window main_win, holder_win; +Pixel back_pix, fore_pix, hilite_pix, shadow_pix; GC ReliefGC, ShadowGC; extern char *BackColor; -#define MW_EVENTS (ExposureMask | StructureNotifyMask| ButtonReleaseMask |\ - ButtonPressMask | ButtonMotionMask | FocusChangeMask) +#define MW_EVENTS \ + (ExposureMask | StructureNotifyMask | ButtonReleaseMask | \ + ButtonPressMask | ButtonMotionMask | FocusChangeMask) Atom wm_del_win; static Atom _XA_WM_PROTOCOLS; @@ -71,146 +69,155 @@ static Atom _XA_WM_COLORMAP_WINDOWS; * Draws the relief pattern around a window * ****************************************************************************/ -void RelieveWindow(Window win,int x,int y,int w,int h, - GC rgc,GC sgc) +void +RelieveWindow(Window win, int x, int y, int w, int h, GC rgc, GC sgc) { - XSegment seg[4]; - int i; - - i=0; - seg[i].x1 = x; seg[i].y1 = y; - seg[i].x2 = w+x-1; seg[i++].y2 = y; - - seg[i].x1 = x; seg[i].y1 = y; - seg[i].x2 = x; seg[i++].y2 = h+y-1; - - seg[i].x1 = x+1; seg[i].y1 = y+1; - seg[i].x2 = x+w-2; seg[i++].y2 = y+1; - - seg[i].x1 = x+1; seg[i].y1 = y+1; - seg[i].x2 = x+1; seg[i++].y2 = y+h-2; - XDrawSegments(dpy, win, rgc, seg, i); - - i=0; - seg[i].x1 = x; seg[i].y1 = y+h-1; - seg[i].x2 = w+x-1; seg[i++].y2 = y+h-1; - - seg[i].x1 = x+w-1; seg[i].y1 = y; - seg[i].x2 = x+w-1; seg[i++].y2 = y+h-1; - if(d_depth<2) - XDrawSegments(dpy, win, ShadowGC, seg, i); - else - XDrawSegments(dpy, win, sgc, seg, i); - - i=0; - seg[i].x1 = x+1; seg[i].y1 = y+h-2; - seg[i].x2 = x+w-2; seg[i++].y2 = y+h-2; - - seg[i].x1 = x+w-2; seg[i].y1 = y+1; - seg[i].x2 = x+w-2; seg[i++].y2 = y+h-2; - - XDrawSegments(dpy, win, sgc, seg, i); + XSegment seg[4]; + int i; + + i = 0; + seg[i].x1 = x; + seg[i].y1 = y; + seg[i].x2 = w + x - 1; + seg[i++].y2 = y; + + seg[i].x1 = x; + seg[i].y1 = y; + seg[i].x2 = x; + seg[i++].y2 = h + y - 1; + + seg[i].x1 = x + 1; + seg[i].y1 = y + 1; + seg[i].x2 = x + w - 2; + seg[i++].y2 = y + 1; + + seg[i].x1 = x + 1; + seg[i].y1 = y + 1; + seg[i].x2 = x + 1; + seg[i++].y2 = y + h - 2; + XDrawSegments(dpy, win, rgc, seg, i); + + i = 0; + seg[i].x1 = x; + seg[i].y1 = y + h - 1; + seg[i].x2 = w + x - 1; + seg[i++].y2 = y + h - 1; + + seg[i].x1 = x + w - 1; + seg[i].y1 = y; + seg[i].x2 = x + w - 1; + seg[i++].y2 = y + h - 1; + if (d_depth < 2) + XDrawSegments(dpy, win, ShadowGC, seg, i); + else + XDrawSegments(dpy, win, sgc, seg, i); + + i = 0; + seg[i].x1 = x + 1; + seg[i].y1 = y + h - 2; + seg[i].x2 = x + w - 2; + seg[i++].y2 = y + h - 2; + + seg[i].x1 = x + w - 2; + seg[i].y1 = y + 1; + seg[i].x2 = x + w - 2; + seg[i++].y2 = y + h - 2; + + XDrawSegments(dpy, win, sgc, seg, i); } /************************************************************************ * - * Sizes and creates the window + * Sizes and creates the window * ***********************************************************************/ XSizeHints mysizehints; -void CreateWindow(int x,int y, int w, int h) +void +CreateWindow(int x, int y, int w, int h) { - XGCValues gcv; - unsigned long gcm; - - - wm_del_win = XInternAtom(dpy,"WM_DELETE_WINDOW",False); - _XA_WM_PROTOCOLS = XInternAtom (dpy, "WM_PROTOCOLS", False); - - mysizehints.flags = PWinGravity| PResizeInc | PBaseSize | - PMaxSize | PMinSize | USSize | USPosition; - /* subtract one for the right/bottom border */ - mysizehints.width_inc = 1; - mysizehints.height_inc = 1; - mysizehints.base_height = BAR_WIDTH+PAD_WIDTH3; - mysizehints.base_width = BAR_WIDTH+PAD_WIDTH3; - - Width = w/Reduction_H + BAR_WIDTH + PAD_WIDTH3; - Height = h/Reduction_V + BAR_WIDTH + PAD_WIDTH3; - target_width = w; - target_height = h; - mysizehints.width = Width; - mysizehints.height = Height; - mysizehints.x = x; - mysizehints.y = y; - mysizehints.max_width = w + BAR_WIDTH + PAD_WIDTH3; - mysizehints.max_height = h + BAR_WIDTH + PAD_WIDTH3; - - mysizehints.win_gravity = NorthWestGravity; - - if(d_depth < 2) - { - back_pix = GetColor("black"); - fore_pix = GetColor("white"); - hilite_pix = fore_pix; - shadow_pix = back_pix; - } - else - { - back_pix = GetColor(BackColor); - hilite_pix = GetHilite(back_pix); - shadow_pix = GetShadow(back_pix); - - } - - main_win = XCreateSimpleWindow(dpy,Root,mysizehints.x,mysizehints.y, - mysizehints.width,mysizehints.height, - 0,fore_pix,back_pix); - XSetWMProtocols(dpy,main_win,&wm_del_win,1); - - XSetWMNormalHints(dpy,main_win,&mysizehints); - XSelectInput(dpy,main_win,MW_EVENTS); - change_window_name(MyName); - - holder_win = XCreateSimpleWindow(dpy,main_win,PAD_WIDTH3,PAD_WIDTH3, - mysizehints.width-BAR_WIDTH -PAD_WIDTH3, - mysizehints.height-BAR_WIDTH-PAD_WIDTH3, - 0,fore_pix,back_pix); - XMapWindow(dpy,holder_win); - gcm = GCForeground|GCBackground; - gcv.foreground = hilite_pix; - gcv.background = hilite_pix; - ReliefGC = XCreateGC(dpy, Root, gcm, &gcv); - - gcm = GCForeground|GCBackground; - gcv.foreground = shadow_pix; - gcv.background = shadow_pix; - ShadowGC = XCreateGC(dpy, Root, gcm, &gcv); - - _XA_WM_COLORMAP_WINDOWS = XInternAtom (dpy, "WM_COLORMAP_WINDOWS", False); - } + XGCValues gcv; + unsigned long gcm; + + wm_del_win = XInternAtom(dpy, "WM_DELETE_WINDOW", False); + _XA_WM_PROTOCOLS = XInternAtom(dpy, "WM_PROTOCOLS", False); + + mysizehints.flags = PWinGravity | PResizeInc | PBaseSize | PMaxSize | + PMinSize | USSize | USPosition; + /* subtract one for the right/bottom border */ + mysizehints.width_inc = 1; + mysizehints.height_inc = 1; + mysizehints.base_height = BAR_WIDTH + PAD_WIDTH3; + mysizehints.base_width = BAR_WIDTH + PAD_WIDTH3; + + Width = w / Reduction_H + BAR_WIDTH + PAD_WIDTH3; + Height = h / Reduction_V + BAR_WIDTH + PAD_WIDTH3; + target_width = w; + target_height = h; + mysizehints.width = Width; + mysizehints.height = Height; + mysizehints.x = x; + mysizehints.y = y; + mysizehints.max_width = w + BAR_WIDTH + PAD_WIDTH3; + mysizehints.max_height = h + BAR_WIDTH + PAD_WIDTH3; + + mysizehints.win_gravity = NorthWestGravity; + + if (d_depth < 2) { + back_pix = GetColor("black"); + fore_pix = GetColor("white"); + hilite_pix = fore_pix; + shadow_pix = back_pix; + } else { + back_pix = GetColor(BackColor); + hilite_pix = GetHilite(back_pix); + shadow_pix = GetShadow(back_pix); + } + + main_win = XCreateSimpleWindow(dpy, Root, mysizehints.x, mysizehints.y, + mysizehints.width, mysizehints.height, 0, fore_pix, back_pix); + XSetWMProtocols(dpy, main_win, &wm_del_win, 1); + + XSetWMNormalHints(dpy, main_win, &mysizehints); + XSelectInput(dpy, main_win, MW_EVENTS); + change_window_name(MyName); + + holder_win = XCreateSimpleWindow(dpy, main_win, PAD_WIDTH3, PAD_WIDTH3, + mysizehints.width - BAR_WIDTH - PAD_WIDTH3, + mysizehints.height - BAR_WIDTH - PAD_WIDTH3, 0, fore_pix, back_pix); + XMapWindow(dpy, holder_win); + gcm = GCForeground | GCBackground; + gcv.foreground = hilite_pix; + gcv.background = hilite_pix; + ReliefGC = XCreateGC(dpy, Root, gcm, &gcv); + + gcm = GCForeground | GCBackground; + gcv.foreground = shadow_pix; + gcv.background = shadow_pix; + ShadowGC = XCreateGC(dpy, Root, gcm, &gcv); + + _XA_WM_COLORMAP_WINDOWS = + XInternAtom(dpy, "WM_COLORMAP_WINDOWS", False); +} /**************************************************************************** - * + * * Loads a single color * - ****************************************************************************/ -Pixel GetColor(char *name) + ****************************************************************************/ +Pixel +GetColor(char *name) { - XColor color; - XWindowAttributes attributes; - - XGetWindowAttributes(dpy,Root,&attributes); - color.pixel = 0; - if (!XParseColor (dpy, attributes.colormap, name, &color)) - { - nocolor("parse",name); - } - else if(!XAllocColor (dpy, attributes.colormap, &color)) - { - nocolor("alloc",name); - } - return color.pixel; + XColor color; + XWindowAttributes attributes; + + XGetWindowAttributes(dpy, Root, &attributes); + color.pixel = 0; + if (!XParseColor(dpy, attributes.colormap, name, &color)) { + nocolor("parse", name); + } else if (!XAllocColor(dpy, attributes.colormap, &color)) { + nocolor("alloc", name); + } + return color.pixel; } /*********************************************************************** @@ -229,660 +236,763 @@ Pixel GetColor(char *name) #define NONE 0 int motion = NONE; -void Loop(Window target) +void +Loop(Window target) { - Window root; - int x,y,border_width,depth; - XEvent Event; - int tw,th; - char *temp; - char *prop = NULL; - Atom actual = None; - int actual_format; - unsigned long nitems, bytesafter; - - while(1) - { - XNextEvent(dpy,&Event); - switch(Event.type) - { - case Expose: - exposed = 1; - RedrawWindow(target); - break; - - case ConfigureNotify: - XGetGeometry(dpy,main_win,&root,&x,&y, - (unsigned int *)&tw,(unsigned int *)&th, - (unsigned int *)&border_width, - (unsigned int *)&depth); - if((tw != Width)||(th!= Height)) - { - XResizeWindow(dpy,holder_win,tw-BAR_WIDTH-PAD_WIDTH3, - th-BAR_WIDTH-PAD_WIDTH3); - Width = tw; - Height = th; - if(target_y_offset + Height - BAR_WIDTH > target_height) - target_y_offset = target_height - Height + BAR_WIDTH; - if(target_y_offset < 0) - target_y_offset = 0; - if(target_x_offset < 0) - target_x_offset = 0; - if(target_x_offset + Width - BAR_WIDTH > target_width) - target_x_offset = target_width - Width + BAR_WIDTH; - - XMoveWindow(dpy,target,-target_x_offset, -target_y_offset); - exposed = 1; - RedrawWindow(target); - } - break; - - case ButtonPress: - if((Event.xbutton.y > Height-BAR_WIDTH) && - (Event.xbutton.x < SCROLL_BAR_WIDTH+PAD_WIDTH3)) - { - motion = LEFT; - exposed = 2; - RedrawWindow(target); - } - else if((Event.xbutton.y > Height-BAR_WIDTH) && - (Event.xbutton.x > Width-BAR_WIDTH-SCROLL_BAR_WIDTH-2) && - (Event.xbutton.x < Width-BAR_WIDTH)) - { - motion = RIGHT; - exposed = 2; - RedrawWindow(target); - } - else if((Event.xbutton.y < SCROLL_BAR_WIDTH+PAD_WIDTH3) && - (Event.xbutton.x > Width-BAR_WIDTH)) - { - motion = TOP; - exposed = 2; - RedrawWindow(target); - } - else if((Event.xbutton.y > Height-BAR_WIDTH-SCROLL_BAR_WIDTH-2) && - (Event.xbutton.y < Height-BAR_WIDTH)&& - (Event.xbutton.x > Width-BAR_WIDTH)) - { - motion = BOTTOM; - exposed = 2; - RedrawWindow(target); - } - else if((Event.xbutton.x > Width - BAR_WIDTH)&& - (Event.xbutton.y < Height- BAR_WIDTH)) - { - - motion = VERTICAL; - target_y_offset=(Event.xbutton.y-PAD_WIDTH3-SCROLL_BAR_WIDTH)* - target_height/ - (Height-BAR_WIDTH-PAD_WIDTH3 - 2*SCROLL_BAR_WIDTH); - if(target_y_offset+Height-BAR_WIDTH -PAD_WIDTH3 > target_height) - target_y_offset = target_height - Height+BAR_WIDTH+PAD_WIDTH3; - if(target_y_offset < 0) - target_y_offset = 0; - XMoveWindow(dpy,target,-target_x_offset, -target_y_offset); - RedrawWindow(target); - } - else if((Event.xbutton.y > Height- BAR_WIDTH ) && - (Event.xbutton.x < Width- BAR_WIDTH)) - { - motion=HORIZONTAL; - target_x_offset=(Event.xbutton.x -PAD_WIDTH3-SCROLL_BAR_WIDTH)* - target_width/ - (Width-BAR_WIDTH-PAD_WIDTH3-2*SCROLL_BAR_WIDTH); - if(target_x_offset < 0) - target_x_offset = 0; - - if(target_x_offset + Width - BAR_WIDTH -PAD_WIDTH3> target_width) - target_x_offset = target_width - Width + BAR_WIDTH+PAD_WIDTH3; - XMoveWindow(dpy,target,-target_x_offset, -target_y_offset); - RedrawWindow(target); - } - else if((Event.xbutton.y > Height- BAR_WIDTH ) && - (Event.xbutton.x > Width- BAR_WIDTH)) - { - exposed = 2; - motion=QUIT; - } - RedrawWindow(target); - break; - - case ButtonRelease: - if((Event.xbutton.y > Height- BAR_WIDTH ) && - (Event.xbutton.x > Width- BAR_WIDTH)&& - (motion==QUIT)) - { - XUnmapWindow(dpy,main_win); - XReparentWindow(dpy,target,Root,x,y); - XSync(dpy,0); - exit(0); - } - if((motion == LEFT)&&(Event.xbutton.y > Height-BAR_WIDTH) && - (Event.xbutton.x < SCROLL_BAR_WIDTH+PAD_WIDTH3)) - { - target_x_offset -= (Width-BAR_WIDTH-PAD_WIDTH2); - if(target_x_offset < 0) - target_x_offset = 0; - XMoveWindow(dpy,target,-target_x_offset, -target_y_offset); - motion = NONE; - exposed = 2; - } - else if((motion == RIGHT)&&(Event.xbutton.y > Height-BAR_WIDTH) && - (Event.xbutton.x > Width-BAR_WIDTH-SCROLL_BAR_WIDTH-2) && - (Event.xbutton.x < Width-BAR_WIDTH)) - { - target_x_offset += (Width-BAR_WIDTH-PAD_WIDTH2); - if(target_x_offset+Width-BAR_WIDTH -PAD_WIDTH3 > target_width) - target_x_offset = target_width - Width+BAR_WIDTH+PAD_WIDTH3; - XMoveWindow(dpy,target,-target_x_offset, -target_y_offset); - motion = NONE; - exposed = 2; - } - else if((motion == TOP)&& - (Event.xbutton.y Width-BAR_WIDTH)) - { - target_y_offset -= (Height-BAR_WIDTH-PAD_WIDTH2); - if(target_y_offset < 0) - target_y_offset = 0; - XMoveWindow(dpy,target,-target_x_offset, -target_y_offset); - motion = NONE; - exposed = 2; - } - else if((motion == BOTTOM)&& - (Event.xbutton.y > Height-BAR_WIDTH-SCROLL_BAR_WIDTH-2) && - (Event.xbutton.y < Height-BAR_WIDTH)&& - (Event.xbutton.x > Width-BAR_WIDTH)) - { - target_y_offset += (Height-BAR_WIDTH-PAD_WIDTH2); - if(target_y_offset+Height-BAR_WIDTH -PAD_WIDTH3 > target_height) - target_y_offset = target_height - Height+BAR_WIDTH+PAD_WIDTH3; - XMoveWindow(dpy,target,-target_x_offset, -target_y_offset); - motion = NONE; - exposed = 2; - } - if(motion == VERTICAL) - { - target_y_offset=(Event.xbutton.y-PAD_WIDTH3-SCROLL_BAR_WIDTH)*target_height/ - (Height-BAR_WIDTH-PAD_WIDTH3 - 2*SCROLL_BAR_WIDTH); - if(target_y_offset+Height-BAR_WIDTH -PAD_WIDTH3 > target_height) - target_y_offset = target_height - Height+BAR_WIDTH+PAD_WIDTH3; - if(target_y_offset < 0) - target_y_offset = 0; - XMoveWindow(dpy,target,-target_x_offset, -target_y_offset); - } - if(motion == HORIZONTAL) - { - target_x_offset=(Event.xbutton.x -PAD_WIDTH3-SCROLL_BAR_WIDTH)* target_width/ - (Width-BAR_WIDTH-PAD_WIDTH3-2*SCROLL_BAR_WIDTH); - if(target_x_offset < 0) - target_x_offset = 0; - - if(target_x_offset + Width - BAR_WIDTH -PAD_WIDTH3> target_width) - target_x_offset = target_width - Width + BAR_WIDTH+PAD_WIDTH3; - XMoveWindow(dpy,target,-target_x_offset, -target_y_offset); - } - RedrawWindow(target); - motion = NONE; - break; - - case MotionNotify: - if((motion == LEFT)&&((Event.xmotion.y < Height-BAR_WIDTH) || - (Event.xmotion.x > SCROLL_BAR_WIDTH+PAD_WIDTH3))) - { - motion = NONE; - exposed = 2; - } - else if((motion == RIGHT)&&((Event.xmotion.y < Height-BAR_WIDTH) || - (Event.xmotion.x < Width-BAR_WIDTH-SCROLL_BAR_WIDTH-2) || - (Event.xmotion.x > Width-BAR_WIDTH))) - { - motion = NONE; - exposed = 2; - } - else if((motion == TOP)&& - ((Event.xmotion.y>SCROLL_BAR_WIDTH+PAD_WIDTH3)|| - (Event.xmotion.x < Width-BAR_WIDTH))) - { - motion = NONE; - exposed = 2; - } - else if((motion == BOTTOM)&& - ((Event.xmotion.y < Height-BAR_WIDTH-SCROLL_BAR_WIDTH-2) || - (Event.xmotion.y > Height-BAR_WIDTH)|| - (Event.xmotion.x < Width-BAR_WIDTH))) - { - motion = NONE; - exposed = 2; - } - if(motion == VERTICAL) - { - target_y_offset=(Event.xmotion.y-PAD_WIDTH3-SCROLL_BAR_WIDTH)* - target_height/ - (Height-BAR_WIDTH-PAD_WIDTH3-2*SCROLL_BAR_WIDTH); - if(target_y_offset+Height-BAR_WIDTH -PAD_WIDTH3 > target_height) - target_y_offset = target_height - Height+BAR_WIDTH+PAD_WIDTH3; - if(target_y_offset < 0) - target_y_offset = 0; - XMoveWindow(dpy,target,-target_x_offset, -target_y_offset); - } - if(motion == HORIZONTAL) - { - target_x_offset=(Event.xmotion.x -PAD_WIDTH3-SCROLL_BAR_WIDTH)* - target_width/ - (Width-BAR_WIDTH-PAD_WIDTH3-2*SCROLL_BAR_WIDTH); - if(target_x_offset < 0) - target_x_offset = 0; - - if(target_x_offset + Width - BAR_WIDTH -PAD_WIDTH3> target_width) - target_x_offset = target_width - Width + BAR_WIDTH+PAD_WIDTH3; - XMoveWindow(dpy,target,-target_x_offset, -target_y_offset); - } - if((motion == QUIT)&& - ((Event.xbutton.y < Height- BAR_WIDTH )|| - (Event.xbutton.x < Width- BAR_WIDTH))) - { - motion = NONE; - exposed = 2; - } - RedrawWindow(target); - break; - case ClientMessage: - if ((Event.xclient.format==32) && - (Event.xclient.data.l[0]==wm_del_win)) - { - DeadPipe(1); - } - break; - case PropertyNotify: - if(Event.xproperty.atom == XA_WM_NAME) - { - if(XFetchName(dpy, target, &temp)==0) - temp = NULL; - change_window_name(temp); - } - else if (Event.xproperty.atom == XA_WM_ICON_NAME) - { - if (XGetWindowProperty (dpy, - target, Event.xproperty.atom, 0, - MAX_ICON_NAME_LEN, False, XA_STRING, - &actual,&actual_format, &nitems, - &bytesafter, (unsigned char **) &prop) - == Success && (prop != NULL)) - change_icon_name(prop); - } - else if(Event.xproperty.atom == XA_WM_HINTS) - { - XWMHints *wmhints; - - wmhints = XGetWMHints(dpy,target); - XSetWMHints(dpy,main_win, wmhints); - XFree(wmhints); - } - else if(Event.xproperty.atom == XA_WM_NORMAL_HINTS) - { - /* don't do Normal Hints. They alter the size of the window */ - } - else if (Event.xproperty.atom == _XA_WM_COLORMAP_WINDOWS) - { - } - break; - - case DestroyNotify: - DeadPipe(1); - break; - - case UnmapNotify: - break; - - case MapNotify: - XMapWindow(dpy,main_win); - break; - case FocusIn: - XSetInputFocus(dpy,target,RevertToParent,CurrentTime); - break; - case ColormapNotify: - { - XWindowAttributes xwa; - if(XGetWindowAttributes(dpy,target, &xwa) != 0) - { - XSetWindowColormap(dpy,main_win,xwa.colormap); - } - } - break; - default: - break; + Window root; + int x, y, border_width, depth; + XEvent Event; + int tw, th; + char *temp; + char *prop = NULL; + Atom actual = None; + int actual_format; + unsigned long nitems, bytesafter; + + while (1) { + XNextEvent(dpy, &Event); + switch (Event.type) { + case Expose: + exposed = 1; + RedrawWindow(target); + break; + + case ConfigureNotify: + XGetGeometry(dpy, main_win, &root, &x, &y, + (unsigned int *)&tw, (unsigned int *)&th, + (unsigned int *)&border_width, + (unsigned int *)&depth); + if ((tw != Width) || (th != Height)) { + XResizeWindow(dpy, holder_win, + tw - BAR_WIDTH - PAD_WIDTH3, + th - BAR_WIDTH - PAD_WIDTH3); + Width = tw; + Height = th; + if (target_y_offset + Height - BAR_WIDTH > + target_height) + target_y_offset = + target_height - Height + BAR_WIDTH; + if (target_y_offset < 0) + target_y_offset = 0; + if (target_x_offset < 0) + target_x_offset = 0; + if (target_x_offset + Width - BAR_WIDTH > + target_width) + target_x_offset = + target_width - Width + BAR_WIDTH; + + XMoveWindow(dpy, target, -target_x_offset, + -target_y_offset); + exposed = 1; + RedrawWindow(target); + } + break; + + case ButtonPress: + if ((Event.xbutton.y > Height - BAR_WIDTH) && + (Event.xbutton.x < SCROLL_BAR_WIDTH + PAD_WIDTH3)) { + motion = LEFT; + exposed = 2; + RedrawWindow(target); + } else if ((Event.xbutton.y > Height - BAR_WIDTH) && + (Event.xbutton.x > Width - BAR_WIDTH - + SCROLL_BAR_WIDTH - + 2) && + (Event.xbutton.x < Width - BAR_WIDTH)) { + motion = RIGHT; + exposed = 2; + RedrawWindow(target); + } else if ((Event.xbutton.y < + SCROLL_BAR_WIDTH + PAD_WIDTH3) && + (Event.xbutton.x > Width - BAR_WIDTH)) { + motion = TOP; + exposed = 2; + RedrawWindow(target); + } else if ((Event.xbutton.y > Height - BAR_WIDTH - + SCROLL_BAR_WIDTH - + 2) && + (Event.xbutton.y < Height - BAR_WIDTH) && + (Event.xbutton.x > Width - BAR_WIDTH)) { + motion = BOTTOM; + exposed = 2; + RedrawWindow(target); + } else if ((Event.xbutton.x > Width - BAR_WIDTH) && + (Event.xbutton.y < Height - BAR_WIDTH)) { + motion = VERTICAL; + target_y_offset = + (Event.xbutton.y - PAD_WIDTH3 - + SCROLL_BAR_WIDTH) * + target_height / + (Height - BAR_WIDTH - PAD_WIDTH3 - + 2 * SCROLL_BAR_WIDTH); + if (target_y_offset + Height - BAR_WIDTH - + PAD_WIDTH3 > + target_height) + target_y_offset = target_height - + Height + BAR_WIDTH + + PAD_WIDTH3; + if (target_y_offset < 0) + target_y_offset = 0; + XMoveWindow(dpy, target, -target_x_offset, + -target_y_offset); + RedrawWindow(target); + } else if ((Event.xbutton.y > Height - BAR_WIDTH) && + (Event.xbutton.x < Width - BAR_WIDTH)) { + motion = HORIZONTAL; + target_x_offset = + (Event.xbutton.x - PAD_WIDTH3 - + SCROLL_BAR_WIDTH) * + target_width / + (Width - BAR_WIDTH - PAD_WIDTH3 - + 2 * SCROLL_BAR_WIDTH); + if (target_x_offset < 0) + target_x_offset = 0; + + if (target_x_offset + Width - BAR_WIDTH - + PAD_WIDTH3 > + target_width) + target_x_offset = target_width - Width + + BAR_WIDTH + + PAD_WIDTH3; + XMoveWindow(dpy, target, -target_x_offset, + -target_y_offset); + RedrawWindow(target); + } else if ((Event.xbutton.y > Height - BAR_WIDTH) && + (Event.xbutton.x > Width - BAR_WIDTH)) { + exposed = 2; + motion = QUIT; + } + RedrawWindow(target); + break; + + case ButtonRelease: + if ((Event.xbutton.y > Height - BAR_WIDTH) && + (Event.xbutton.x > Width - BAR_WIDTH) && + (motion == QUIT)) { + XUnmapWindow(dpy, main_win); + { + int root_x, root_y; + Window dummy; + if (XTranslateCoordinates(dpy, main_win, + Root, 0, 0, &root_x, &root_y, + &dummy)) { + XReparentWindow(dpy, target, + Root, root_x, root_y); + } else { + XReparentWindow( + dpy, target, Root, x, y); + } + } + XSync(dpy, 0); + exit(0); + } + if ((motion == LEFT) && + (Event.xbutton.y > Height - BAR_WIDTH) && + (Event.xbutton.x < SCROLL_BAR_WIDTH + PAD_WIDTH3)) { + target_x_offset -= + (Width - BAR_WIDTH - PAD_WIDTH2); + if (target_x_offset < 0) + target_x_offset = 0; + XMoveWindow(dpy, target, -target_x_offset, + -target_y_offset); + motion = NONE; + exposed = 2; + } else if ((motion == RIGHT) && + (Event.xbutton.y > Height - BAR_WIDTH) && + (Event.xbutton.x > Width - BAR_WIDTH - + SCROLL_BAR_WIDTH - + 2) && + (Event.xbutton.x < Width - BAR_WIDTH)) { + target_x_offset += + (Width - BAR_WIDTH - PAD_WIDTH2); + if (target_x_offset + Width - BAR_WIDTH - + PAD_WIDTH3 > + target_width) + target_x_offset = target_width - Width + + BAR_WIDTH + + PAD_WIDTH3; + XMoveWindow(dpy, target, -target_x_offset, + -target_y_offset); + motion = NONE; + exposed = 2; + } else if ((motion == TOP) && + (Event.xbutton.y < + SCROLL_BAR_WIDTH + PAD_WIDTH3) && + (Event.xbutton.x > Width - BAR_WIDTH)) { + target_y_offset -= + (Height - BAR_WIDTH - PAD_WIDTH2); + if (target_y_offset < 0) + target_y_offset = 0; + XMoveWindow(dpy, target, -target_x_offset, + -target_y_offset); + motion = NONE; + exposed = 2; + } else if ((motion == BOTTOM) && + (Event.xbutton.y > Height - BAR_WIDTH - + SCROLL_BAR_WIDTH - + 2) && + (Event.xbutton.y < Height - BAR_WIDTH) && + (Event.xbutton.x > Width - BAR_WIDTH)) { + target_y_offset += + (Height - BAR_WIDTH - PAD_WIDTH2); + if (target_y_offset + Height - BAR_WIDTH - + PAD_WIDTH3 > + target_height) + target_y_offset = target_height - + Height + BAR_WIDTH + + PAD_WIDTH3; + XMoveWindow(dpy, target, -target_x_offset, + -target_y_offset); + motion = NONE; + exposed = 2; + } + if (motion == VERTICAL) { + target_y_offset = + (Event.xbutton.y - PAD_WIDTH3 - + SCROLL_BAR_WIDTH) * + target_height / + (Height - BAR_WIDTH - PAD_WIDTH3 - + 2 * SCROLL_BAR_WIDTH); + if (target_y_offset + Height - BAR_WIDTH - + PAD_WIDTH3 > + target_height) + target_y_offset = target_height - + Height + BAR_WIDTH + + PAD_WIDTH3; + if (target_y_offset < 0) + target_y_offset = 0; + XMoveWindow(dpy, target, -target_x_offset, + -target_y_offset); + } + if (motion == HORIZONTAL) { + target_x_offset = + (Event.xbutton.x - PAD_WIDTH3 - + SCROLL_BAR_WIDTH) * + target_width / + (Width - BAR_WIDTH - PAD_WIDTH3 - + 2 * SCROLL_BAR_WIDTH); + if (target_x_offset < 0) + target_x_offset = 0; + + if (target_x_offset + Width - BAR_WIDTH - + PAD_WIDTH3 > + target_width) + target_x_offset = target_width - Width + + BAR_WIDTH + + PAD_WIDTH3; + XMoveWindow(dpy, target, -target_x_offset, + -target_y_offset); + } + RedrawWindow(target); + motion = NONE; + break; + + case MotionNotify: + if ((motion == LEFT) && + ((Event.xmotion.y < Height - BAR_WIDTH) || + (Event.xmotion.x > + SCROLL_BAR_WIDTH + PAD_WIDTH3))) { + motion = NONE; + exposed = 2; + } else if ((motion == RIGHT) && + ((Event.xmotion.y < Height - BAR_WIDTH) || + (Event.xmotion.x < Width - BAR_WIDTH - + SCROLL_BAR_WIDTH - + 2) || + (Event.xmotion.x > Width - BAR_WIDTH))) { + motion = NONE; + exposed = 2; + } else if ((motion == TOP) && + ((Event.xmotion.y > + SCROLL_BAR_WIDTH + PAD_WIDTH3) || + (Event.xmotion.x < Width - BAR_WIDTH))) { + motion = NONE; + exposed = 2; + } else if ((motion == BOTTOM) && + ((Event.xmotion.y < Height - BAR_WIDTH - + SCROLL_BAR_WIDTH - + 2) || + (Event.xmotion.y > Height - BAR_WIDTH) || + (Event.xmotion.x < Width - BAR_WIDTH))) { + motion = NONE; + exposed = 2; + } + if (motion == VERTICAL) { + target_y_offset = + (Event.xmotion.y - PAD_WIDTH3 - + SCROLL_BAR_WIDTH) * + target_height / + (Height - BAR_WIDTH - PAD_WIDTH3 - + 2 * SCROLL_BAR_WIDTH); + if (target_y_offset + Height - BAR_WIDTH - + PAD_WIDTH3 > + target_height) + target_y_offset = target_height - + Height + BAR_WIDTH + + PAD_WIDTH3; + if (target_y_offset < 0) + target_y_offset = 0; + XMoveWindow(dpy, target, -target_x_offset, + -target_y_offset); + } + if (motion == HORIZONTAL) { + target_x_offset = + (Event.xmotion.x - PAD_WIDTH3 - + SCROLL_BAR_WIDTH) * + target_width / + (Width - BAR_WIDTH - PAD_WIDTH3 - + 2 * SCROLL_BAR_WIDTH); + if (target_x_offset < 0) + target_x_offset = 0; + + if (target_x_offset + Width - BAR_WIDTH - + PAD_WIDTH3 > + target_width) + target_x_offset = target_width - Width + + BAR_WIDTH + + PAD_WIDTH3; + XMoveWindow(dpy, target, -target_x_offset, + -target_y_offset); + } + if ((motion == QUIT) && + ((Event.xbutton.y < Height - BAR_WIDTH) || + (Event.xbutton.x < Width - BAR_WIDTH))) { + motion = NONE; + exposed = 2; + } + RedrawWindow(target); + break; + case ClientMessage: + if ((Event.xclient.format == 32) && + (Event.xclient.data.l[0] == wm_del_win)) { + DeadPipe(1); + } + break; + case PropertyNotify: + if (Event.xproperty.atom == XA_WM_NAME) { + if (XFetchName(dpy, target, &temp) == 0) + temp = NULL; + change_window_name(temp); + } else if (Event.xproperty.atom == XA_WM_ICON_NAME) { + if (XGetWindowProperty(dpy, target, + Event.xproperty.atom, 0, + MAX_ICON_NAME_LEN, False, XA_STRING, + &actual, &actual_format, &nitems, + &bytesafter, + (unsigned char **)&prop) == Success && + (prop != NULL)) { + change_icon_name(prop); + XFree(prop); + } + } else if (Event.xproperty.atom == XA_WM_HINTS) { + XWMHints *wmhints; + + wmhints = XGetWMHints(dpy, target); + if (wmhints != NULL) { + XSetWMHints(dpy, main_win, wmhints); + XFree(wmhints); + } + } else if (Event.xproperty.atom == XA_WM_NORMAL_HINTS) { + /* don't do Normal Hints. They alter the size of + * the window */ + } else if (Event.xproperty.atom == + _XA_WM_COLORMAP_WINDOWS) { + } + break; + + case DestroyNotify: + DeadPipe(1); + break; + + case UnmapNotify: + break; + + case MapNotify: + XMapWindow(dpy, main_win); + break; + case FocusIn: + XSetInputFocus( + dpy, target, RevertToParent, CurrentTime); + break; + case ColormapNotify: { + XWindowAttributes xwa; + if (XGetWindowAttributes(dpy, target, &xwa) != 0) { + XSetWindowColormap(dpy, main_win, xwa.colormap); + } + } + break; + default: + break; + } } - } - return; + return; } - - /************************************************************************ * - * Draw the window + * Draw the window * ***********************************************************************/ -void RedrawWindow(Window target) +void +RedrawWindow(Window target) { - static int xv= 0,yv= 0,hv=0,wv=0; - static int xh=0,yh=0,hh=0,wh=0; - int x,y,w,h; - XEvent dummy; - - while (XCheckTypedWindowEvent (dpy, main_win, Expose, &dummy)) - exposed |= 1; - - XSetWindowBorderWidth(dpy,target,0); - - RelieveWindow(main_win,PAD_WIDTH3-2,PAD_WIDTH3-2, - Width-BAR_WIDTH-PAD_WIDTH3+4, - Height-BAR_WIDTH-PAD_WIDTH3+4,ShadowGC,ReliefGC); - - y = (Height-BAR_WIDTH-PAD_WIDTH3-2*SCROLL_BAR_WIDTH)* - target_y_offset/target_height - + PAD_WIDTH2 + 2 + SCROLL_BAR_WIDTH; - x = Width-SCROLL_BAR_WIDTH- PAD_WIDTH2-2; - w = SCROLL_BAR_WIDTH; - h = (Height-BAR_WIDTH-PAD_WIDTH3-2*SCROLL_BAR_WIDTH)* - (Height-BAR_WIDTH-PAD_WIDTH3)/ - target_height; - if((y!=yv)||(x != xv)||(w != wv)||(h != hv)||(exposed & 1)) - { - yv = y; - xv = x; - wv = w; - hv = h; - XClearArea(dpy,main_win,x,PAD_WIDTH3+SCROLL_BAR_WIDTH, - w,Height-BAR_WIDTH-PAD_WIDTH3-2*SCROLL_BAR_WIDTH,False); - - RelieveWindow(main_win,x,y,w,h,ReliefGC,ShadowGC); - } - if(exposed & 1) - RelieveWindow(main_win,x-2,PAD_WIDTH2, - w+4,Height-BAR_WIDTH-PAD_WIDTH2+2,ShadowGC,ReliefGC); - if(exposed) - { - if(motion == TOP) - RedrawTopButton(ShadowGC,ReliefGC,x,PAD_WIDTH3); - else - RedrawTopButton(ReliefGC,ShadowGC,x,PAD_WIDTH3); - if(motion == BOTTOM) - RedrawBottomButton(ShadowGC,ReliefGC,x, - Height-BAR_WIDTH-SCROLL_BAR_WIDTH); - else - RedrawBottomButton(ReliefGC,ShadowGC,x, - Height-BAR_WIDTH-SCROLL_BAR_WIDTH); - } - - x = (Width-BAR_WIDTH-PAD_WIDTH3-2*SCROLL_BAR_WIDTH)*target_x_offset/ - target_width+PAD_WIDTH2+2 + SCROLL_BAR_WIDTH; - y = Height-SCROLL_BAR_WIDTH-PAD_WIDTH2-2; - w = (Width-BAR_WIDTH-PAD_WIDTH3-2*SCROLL_BAR_WIDTH)* - (Width-BAR_WIDTH-PAD_WIDTH3)/target_width; - h = SCROLL_BAR_WIDTH; - if((y!=yh)||(x != xh)||(w != wh)||(h != hh)||(exposed & 1)) - { - yh = y; - xh = x; - wh = w; - hh = h; - XClearArea(dpy,main_win,PAD_WIDTH3+SCROLL_BAR_WIDTH,y, - Width-BAR_WIDTH-PAD_WIDTH3-2*SCROLL_BAR_WIDTH,h,False); - RelieveWindow(main_win,x,y,w,h,ReliefGC,ShadowGC); - } - if(exposed& 1) - { - RelieveWindow(main_win,PAD_WIDTH2,y-2,Width-BAR_WIDTH-PAD_WIDTH2+2,h+4, - ShadowGC,ReliefGC); - } - if(exposed) - { - if(motion == LEFT) - RedrawLeftButton(ShadowGC,ReliefGC,PAD_WIDTH3,y); - else - RedrawLeftButton(ReliefGC,ShadowGC,PAD_WIDTH3,y); - if(motion ==RIGHT) - RedrawRightButton(ShadowGC,ReliefGC, - Width-BAR_WIDTH-SCROLL_BAR_WIDTH,y); - else - RedrawRightButton(ReliefGC,ShadowGC, - Width-BAR_WIDTH-SCROLL_BAR_WIDTH,y); - } - - if(exposed) - { - XClearArea(dpy,main_win,Width-BAR_WIDTH+2, - Height-BAR_WIDTH+2,BAR_WIDTH-3,BAR_WIDTH-3,False); - if(motion == QUIT) - RelieveWindow(main_win,Width-SCROLL_BAR_WIDTH-PAD_WIDTH2-4, - Height-SCROLL_BAR_WIDTH-PAD_WIDTH2-4, - SCROLL_BAR_WIDTH+4,SCROLL_BAR_WIDTH+4, - ShadowGC,ReliefGC); - else - RelieveWindow(main_win,Width-SCROLL_BAR_WIDTH-PAD_WIDTH2-4, - Height-SCROLL_BAR_WIDTH-PAD_WIDTH2-4, - SCROLL_BAR_WIDTH+4,SCROLL_BAR_WIDTH+4, - ReliefGC,ShadowGC); - } - exposed = 0; -} + static int xv = 0, yv = 0, hv = 0, wv = 0; + static int xh = 0, yh = 0, hh = 0, wh = 0; + int x, y, w, h; + XEvent dummy; + + while (XCheckTypedWindowEvent(dpy, main_win, Expose, &dummy)) + exposed |= 1; + + XSetWindowBorderWidth(dpy, target, 0); + + RelieveWindow(main_win, PAD_WIDTH3 - 2, PAD_WIDTH3 - 2, + Width - BAR_WIDTH - PAD_WIDTH3 + 4, + Height - BAR_WIDTH - PAD_WIDTH3 + 4, ShadowGC, ReliefGC); + + y = (Height - BAR_WIDTH - PAD_WIDTH3 - 2 * SCROLL_BAR_WIDTH) * + target_y_offset / target_height + + PAD_WIDTH2 + 2 + SCROLL_BAR_WIDTH; + x = Width - SCROLL_BAR_WIDTH - PAD_WIDTH2 - 2; + w = SCROLL_BAR_WIDTH; + h = (Height - BAR_WIDTH - PAD_WIDTH3 - 2 * SCROLL_BAR_WIDTH) * + (Height - BAR_WIDTH - PAD_WIDTH3) / target_height; + if ((y != yv) || (x != xv) || (w != wv) || (h != hv) || (exposed & 1)) { + yv = y; + xv = x; + wv = w; + hv = h; + XClearArea(dpy, main_win, x, PAD_WIDTH3 + SCROLL_BAR_WIDTH, w, + Height - BAR_WIDTH - PAD_WIDTH3 - 2 * SCROLL_BAR_WIDTH, + False); + + RelieveWindow(main_win, x, y, w, h, ReliefGC, ShadowGC); + } + if (exposed & 1) + RelieveWindow(main_win, x - 2, PAD_WIDTH2, w + 4, + Height - BAR_WIDTH - PAD_WIDTH2 + 2, ShadowGC, ReliefGC); + if (exposed) { + if (motion == TOP) + RedrawTopButton(ShadowGC, ReliefGC, x, PAD_WIDTH3); + else + RedrawTopButton(ReliefGC, ShadowGC, x, PAD_WIDTH3); + if (motion == BOTTOM) + RedrawBottomButton(ShadowGC, ReliefGC, x, + Height - BAR_WIDTH - SCROLL_BAR_WIDTH); + else + RedrawBottomButton(ReliefGC, ShadowGC, x, + Height - BAR_WIDTH - SCROLL_BAR_WIDTH); + } + x = (Width - BAR_WIDTH - PAD_WIDTH3 - 2 * SCROLL_BAR_WIDTH) * + target_x_offset / target_width + + PAD_WIDTH2 + 2 + SCROLL_BAR_WIDTH; + y = Height - SCROLL_BAR_WIDTH - PAD_WIDTH2 - 2; + w = (Width - BAR_WIDTH - PAD_WIDTH3 - 2 * SCROLL_BAR_WIDTH) * + (Width - BAR_WIDTH - PAD_WIDTH3) / target_width; + h = SCROLL_BAR_WIDTH; + if ((y != yh) || (x != xh) || (w != wh) || (h != hh) || (exposed & 1)) { + yh = y; + xh = x; + wh = w; + hh = h; + XClearArea(dpy, main_win, PAD_WIDTH3 + SCROLL_BAR_WIDTH, y, + Width - BAR_WIDTH - PAD_WIDTH3 - 2 * SCROLL_BAR_WIDTH, h, + False); + RelieveWindow(main_win, x, y, w, h, ReliefGC, ShadowGC); + } + if (exposed & 1) { + RelieveWindow(main_win, PAD_WIDTH2, y - 2, + Width - BAR_WIDTH - PAD_WIDTH2 + 2, h + 4, ShadowGC, + ReliefGC); + } + if (exposed) { + if (motion == LEFT) + RedrawLeftButton(ShadowGC, ReliefGC, PAD_WIDTH3, y); + else + RedrawLeftButton(ReliefGC, ShadowGC, PAD_WIDTH3, y); + if (motion == RIGHT) + RedrawRightButton(ShadowGC, ReliefGC, + Width - BAR_WIDTH - SCROLL_BAR_WIDTH, y); + else + RedrawRightButton(ReliefGC, ShadowGC, + Width - BAR_WIDTH - SCROLL_BAR_WIDTH, y); + } + + if (exposed) { + XClearArea(dpy, main_win, Width - BAR_WIDTH + 2, + Height - BAR_WIDTH + 2, BAR_WIDTH - 3, BAR_WIDTH - 3, + False); + if (motion == QUIT) + RelieveWindow(main_win, + Width - SCROLL_BAR_WIDTH - PAD_WIDTH2 - 4, + Height - SCROLL_BAR_WIDTH - PAD_WIDTH2 - 4, + SCROLL_BAR_WIDTH + 4, SCROLL_BAR_WIDTH + 4, + ShadowGC, ReliefGC); + else + RelieveWindow(main_win, + Width - SCROLL_BAR_WIDTH - PAD_WIDTH2 - 4, + Height - SCROLL_BAR_WIDTH - PAD_WIDTH2 - 4, + SCROLL_BAR_WIDTH + 4, SCROLL_BAR_WIDTH + 4, + ReliefGC, ShadowGC); + } + exposed = 0; +} /************************************************************************** * Change the window name displayed in the title bar. **************************************************************************/ -void change_window_name(char *str) +void +change_window_name(char *str) { - XTextProperty name; - - if(str == NULL) - return; - - if (XStringListToTextProperty(&str,1,&name) == 0) - { - fprintf(stderr,"%s: cannot allocate window name",MyName); - return; - } - XSetWMName(dpy,main_win,&name); - XFree(name.value); -} + XTextProperty name; + + if (str == NULL) + return; + if (XStringListToTextProperty(&str, 1, &name) == 0) { + fprintf(stderr, "%s: cannot allocate window name", MyName); + return; + } + XSetWMName(dpy, main_win, &name); + XFree(name.value); +} /************************************************************************** * Change the window name displayed in the icon. **************************************************************************/ -void change_icon_name(char *str) +void +change_icon_name(char *str) { - XTextProperty name; - - if(str == NULL)return; - if (XStringListToTextProperty(&str,1,&name) == 0) - { - fprintf(stderr,"%s: cannot allocate window name",MyName); - return; - } - XSetWMIconName(dpy,main_win,&name); - XFree(name.value); -} - + XTextProperty name; -void GrabWindow(Window target) -{ - char *temp; - Window Junk,root; - unsigned int tw,th,border_width,depth; - int x,y; - char *prop = NULL; - Atom actual = None; - int actual_format; - unsigned long nitems, bytesafter; - - XUnmapWindow(dpy,target); - XSync(dpy,0); - XGetGeometry(dpy,target,&root,&x,&y, - (unsigned int *)&tw,(unsigned int *)&th, - (unsigned int *)&border_width, - (unsigned int *)&depth); - XSync(dpy,0); - - XTranslateCoordinates(dpy, target, Root, 0, 0, &x,&y, &Junk); - - InitPictureCMap(dpy,Root); /* store the window cmap for GetShadow */ - - CreateWindow(x,y,tw,th); - XSetWindowBorderWidth(dpy,target,0); - XReparentWindow(dpy,target, holder_win,0,0); - XMapWindow(dpy,target); - XSelectInput(dpy,target, PropertyChangeMask|StructureNotifyMask| - ColormapChangeMask); - if(XFetchName(dpy, target, &temp)==0) - temp = NULL; - if (XGetWindowProperty (dpy, - target, XA_WM_ICON_NAME, 0, - MAX_ICON_NAME_LEN, False, XA_STRING, - &actual,&actual_format, &nitems, - &bytesafter, (unsigned char **) &prop) - == Success && (prop != NULL)) - { - change_icon_name(prop); - XFree(prop); - } - change_window_name(temp); - { - XWMHints *wmhints; - - wmhints = XGetWMHints(dpy,target); - if(wmhints != NULL) - { - XSetWMHints(dpy,main_win, wmhints); - XFree(wmhints); - } - } - { - XWindowAttributes xwa; - if(XGetWindowAttributes(dpy,target, &xwa) != 0) - { - XSetWindowColormap(dpy,main_win,xwa.colormap); - } - } - - XMapWindow(dpy,main_win); - RedrawWindow(target); - XFree(temp); + if (str == NULL) + return; + if (XStringListToTextProperty(&str, 1, &name) == 0) { + fprintf(stderr, "%s: cannot allocate window name", MyName); + return; + } + XSetWMIconName(dpy, main_win, &name); + XFree(name.value); } - - - - -void RedrawLeftButton(GC rgc, GC sgc,int x1,int y1) +void +GrabWindow(Window target) { - XSegment seg[4]; - int i=0; - - seg[i].x1 = x1+1; seg[i].y1 = y1+SCROLL_BAR_WIDTH/2; - seg[i].x2 = x1+SCROLL_BAR_WIDTH - 2; seg[i++].y2 = y1+1; - - seg[i].x1 = x1; seg[i].y1 = y1+SCROLL_BAR_WIDTH/2; - seg[i].x2 = x1+SCROLL_BAR_WIDTH - 1; seg[i++].y2 = y1; - XDrawSegments(dpy, main_win, rgc, seg, i); - - i = 0; - seg[i].x1 = x1+1; seg[i].y1 =y1+ SCROLL_BAR_WIDTH/2; - seg[i].x2 = x1+SCROLL_BAR_WIDTH - 2; seg[i++].y2 =y1+ SCROLL_BAR_WIDTH - 2; - - seg[i].x1 = x1; seg[i].y1 = y1+SCROLL_BAR_WIDTH/2; - seg[i].x2 = x1+SCROLL_BAR_WIDTH - 1; seg[i++].y2 = y1+SCROLL_BAR_WIDTH - 1; + char *temp; + Window Junk, root; + unsigned int tw, th, border_width, depth; + int x, y; + char *prop = NULL; + Atom actual = None; + int actual_format; + unsigned long nitems, bytesafter; + + XUnmapWindow(dpy, target); + XSync(dpy, 0); + XGetGeometry(dpy, target, &root, &x, &y, (unsigned int *)&tw, + (unsigned int *)&th, (unsigned int *)&border_width, + (unsigned int *)&depth); + XSync(dpy, 0); + + XTranslateCoordinates(dpy, target, Root, 0, 0, &x, &y, &Junk); + + InitPictureCMap(dpy, Root); /* store the window cmap for GetShadow */ + + CreateWindow(x, y, tw, th); + XSetWindowBorderWidth(dpy, target, 0); + XReparentWindow(dpy, target, holder_win, 0, 0); + XMapWindow(dpy, target); + XSelectInput(dpy, target, + PropertyChangeMask | StructureNotifyMask | ColormapChangeMask); + if (XFetchName(dpy, target, &temp) == 0) + temp = NULL; + if (XGetWindowProperty(dpy, target, XA_WM_ICON_NAME, 0, + MAX_ICON_NAME_LEN, False, XA_STRING, &actual, &actual_format, + &nitems, &bytesafter, (unsigned char **)&prop) == Success && + (prop != NULL)) { + change_icon_name(prop); + XFree(prop); + } + change_window_name(temp); + { + XWMHints *wmhints; - seg[i].x1 = x1+SCROLL_BAR_WIDTH - 2; seg[i].y1 = y1+1; - seg[i].x2 = x1+SCROLL_BAR_WIDTH - 2; seg[i++].y2 = y1+SCROLL_BAR_WIDTH - 2; + wmhints = XGetWMHints(dpy, target); + if (wmhints != NULL) { + XSetWMHints(dpy, main_win, wmhints); + XFree(wmhints); + } + } + { + XWindowAttributes xwa; + if (XGetWindowAttributes(dpy, target, &xwa) != 0) { + XSetWindowColormap(dpy, main_win, xwa.colormap); + } + } - seg[i].x1 = x1+SCROLL_BAR_WIDTH - 1; seg[i].y1 = y1; - seg[i].x2 = x1+SCROLL_BAR_WIDTH - 1; seg[i++].y2 = y1+SCROLL_BAR_WIDTH - 1; - XDrawSegments(dpy,main_win, sgc, seg, i); + XMapWindow(dpy, main_win); + RedrawWindow(target); + XFree(temp); } -void RedrawRightButton(GC rgc, GC sgc,int x1,int y1) +void +RedrawLeftButton(GC rgc, GC sgc, int x1, int y1) { - XSegment seg[4]; - int i=0; - - seg[i].x1 = x1+1; seg[i].y1 = y1+1; - seg[i].x2 = x1+1; seg[i++].y2 = y1+SCROLL_BAR_WIDTH - 2; - - seg[i].x1 = x1; seg[i].y1 = y1; - seg[i].x2 = x1; seg[i++].y2 = y1+SCROLL_BAR_WIDTH - 1; - - seg[i].x1 = x1+1; seg[i].y1 = y1+1; - seg[i].x2 = x1+SCROLL_BAR_WIDTH - 2; seg[i++].y2 = y1+SCROLL_BAR_WIDTH/2; - - seg[i].x1 = x1; seg[i].y1 = y1; - seg[i].x2 = x1+SCROLL_BAR_WIDTH - 1; seg[i++].y2 = y1+SCROLL_BAR_WIDTH/2; - - XDrawSegments(dpy, main_win, rgc, seg, i); - - i = 0; - seg[i].x1 = x1; seg[i].y1 = y1+SCROLL_BAR_WIDTH - 2; - seg[i].x2 = x1+SCROLL_BAR_WIDTH - 2; seg[i++].y2 = y1+SCROLL_BAR_WIDTH/2; - - seg[i].x1 = x1; seg[i].y1 = y1+SCROLL_BAR_WIDTH - 1; - seg[i].x2 = x1+SCROLL_BAR_WIDTH - 1; seg[i++].y2 = y1+SCROLL_BAR_WIDTH/2; - XDrawSegments(dpy,main_win, sgc, seg, i); + XSegment seg[4]; + int i = 0; + + seg[i].x1 = x1 + 1; + seg[i].y1 = y1 + SCROLL_BAR_WIDTH / 2; + seg[i].x2 = x1 + SCROLL_BAR_WIDTH - 2; + seg[i++].y2 = y1 + 1; + + seg[i].x1 = x1; + seg[i].y1 = y1 + SCROLL_BAR_WIDTH / 2; + seg[i].x2 = x1 + SCROLL_BAR_WIDTH - 1; + seg[i++].y2 = y1; + XDrawSegments(dpy, main_win, rgc, seg, i); + + i = 0; + seg[i].x1 = x1 + 1; + seg[i].y1 = y1 + SCROLL_BAR_WIDTH / 2; + seg[i].x2 = x1 + SCROLL_BAR_WIDTH - 2; + seg[i++].y2 = y1 + SCROLL_BAR_WIDTH - 2; + + seg[i].x1 = x1; + seg[i].y1 = y1 + SCROLL_BAR_WIDTH / 2; + seg[i].x2 = x1 + SCROLL_BAR_WIDTH - 1; + seg[i++].y2 = y1 + SCROLL_BAR_WIDTH - 1; + + seg[i].x1 = x1 + SCROLL_BAR_WIDTH - 2; + seg[i].y1 = y1 + 1; + seg[i].x2 = x1 + SCROLL_BAR_WIDTH - 2; + seg[i++].y2 = y1 + SCROLL_BAR_WIDTH - 2; + + seg[i].x1 = x1 + SCROLL_BAR_WIDTH - 1; + seg[i].y1 = y1; + seg[i].x2 = x1 + SCROLL_BAR_WIDTH - 1; + seg[i++].y2 = y1 + SCROLL_BAR_WIDTH - 1; + XDrawSegments(dpy, main_win, sgc, seg, i); } -void RedrawTopButton(GC rgc, GC sgc,int x1,int y1) +void +RedrawRightButton(GC rgc, GC sgc, int x1, int y1) { - XSegment seg[4]; - int i=0; - - seg[i].x1 = x1+SCROLL_BAR_WIDTH/2; seg[i].y1 = y1+1; - seg[i].x2 = x1+1; seg[i++].y2 = y1+SCROLL_BAR_WIDTH - 2; - - seg[i].x1 = x1+SCROLL_BAR_WIDTH/2; seg[i].y1 = y1; - seg[i].x2 = x1+0; seg[i++].y2 = y1+SCROLL_BAR_WIDTH - 1; - XDrawSegments(dpy, main_win, rgc, seg, i); - - i = 0; - seg[i].x1 = x1+SCROLL_BAR_WIDTH/2; seg[i].y1 = y1+1; - seg[i].x2 = x1+SCROLL_BAR_WIDTH - 2; seg[i++].y2 = y1+SCROLL_BAR_WIDTH - 2; - - seg[i].x1 = x1+SCROLL_BAR_WIDTH/2; seg[i].y1 = y1; - seg[i].x2 = x1+SCROLL_BAR_WIDTH - 1; seg[i++].y2 = y1+SCROLL_BAR_WIDTH - 1; - - seg[i].x1 = x1+1; seg[i].y1 = y1+SCROLL_BAR_WIDTH - 2; - seg[i].x2 = x1+SCROLL_BAR_WIDTH - 2; seg[i++].y2 = y1+SCROLL_BAR_WIDTH - 2; - - seg[i].x1 = x1+0; seg[i].y1 = y1+SCROLL_BAR_WIDTH - 1; - seg[i].x2 = x1+SCROLL_BAR_WIDTH - 1; seg[i++].y2 = y1+SCROLL_BAR_WIDTH - 1; - XDrawSegments(dpy,main_win, sgc, seg, i); + XSegment seg[4]; + int i = 0; + + seg[i].x1 = x1 + 1; + seg[i].y1 = y1 + 1; + seg[i].x2 = x1 + 1; + seg[i++].y2 = y1 + SCROLL_BAR_WIDTH - 2; + + seg[i].x1 = x1; + seg[i].y1 = y1; + seg[i].x2 = x1; + seg[i++].y2 = y1 + SCROLL_BAR_WIDTH - 1; + + seg[i].x1 = x1 + 1; + seg[i].y1 = y1 + 1; + seg[i].x2 = x1 + SCROLL_BAR_WIDTH - 2; + seg[i++].y2 = y1 + SCROLL_BAR_WIDTH / 2; + + seg[i].x1 = x1; + seg[i].y1 = y1; + seg[i].x2 = x1 + SCROLL_BAR_WIDTH - 1; + seg[i++].y2 = y1 + SCROLL_BAR_WIDTH / 2; + + XDrawSegments(dpy, main_win, rgc, seg, i); + + i = 0; + seg[i].x1 = x1; + seg[i].y1 = y1 + SCROLL_BAR_WIDTH - 2; + seg[i].x2 = x1 + SCROLL_BAR_WIDTH - 2; + seg[i++].y2 = y1 + SCROLL_BAR_WIDTH / 2; + + seg[i].x1 = x1; + seg[i].y1 = y1 + SCROLL_BAR_WIDTH - 1; + seg[i].x2 = x1 + SCROLL_BAR_WIDTH - 1; + seg[i++].y2 = y1 + SCROLL_BAR_WIDTH / 2; + XDrawSegments(dpy, main_win, sgc, seg, i); } -void RedrawBottomButton(GC rgc, GC sgc,int x1, int y1) +void +RedrawTopButton(GC rgc, GC sgc, int x1, int y1) { - XSegment seg[4]; - int i=0; - - seg[i].x1 = x1+1; seg[i].y1 = y1+1; - seg[i].x2 = x1+SCROLL_BAR_WIDTH/2; seg[i++].y2 = y1+SCROLL_BAR_WIDTH - 2; - - seg[i].x1 = x1; seg[i].y1 = y1+0; - seg[i].x2 = x1+SCROLL_BAR_WIDTH/2; seg[i++].y2 = y1+SCROLL_BAR_WIDTH - 1; - - seg[i].x1 = x1+1; seg[i].y1 = y1+1; - seg[i].x2 = x1+SCROLL_BAR_WIDTH - 2; seg[i++].y2 = y1+1; - - seg[i].x1 = x1; seg[i].y1 = y1+0; - seg[i].x2 = x1+SCROLL_BAR_WIDTH - 1; seg[i++].y2 = y1+0; - XDrawSegments(dpy,main_win, rgc, seg, i); - - i = 0; - seg[i].x1 = x1+SCROLL_BAR_WIDTH - 2; seg[i].y1 = y1+1; - seg[i].x2 = x1+SCROLL_BAR_WIDTH/2; seg[i++].y2 = y1+SCROLL_BAR_WIDTH - 2; + XSegment seg[4]; + int i = 0; + + seg[i].x1 = x1 + SCROLL_BAR_WIDTH / 2; + seg[i].y1 = y1 + 1; + seg[i].x2 = x1 + 1; + seg[i++].y2 = y1 + SCROLL_BAR_WIDTH - 2; + + seg[i].x1 = x1 + SCROLL_BAR_WIDTH / 2; + seg[i].y1 = y1; + seg[i].x2 = x1 + 0; + seg[i++].y2 = y1 + SCROLL_BAR_WIDTH - 1; + XDrawSegments(dpy, main_win, rgc, seg, i); + + i = 0; + seg[i].x1 = x1 + SCROLL_BAR_WIDTH / 2; + seg[i].y1 = y1 + 1; + seg[i].x2 = x1 + SCROLL_BAR_WIDTH - 2; + seg[i++].y2 = y1 + SCROLL_BAR_WIDTH - 2; + + seg[i].x1 = x1 + SCROLL_BAR_WIDTH / 2; + seg[i].y1 = y1; + seg[i].x2 = x1 + SCROLL_BAR_WIDTH - 1; + seg[i++].y2 = y1 + SCROLL_BAR_WIDTH - 1; + + seg[i].x1 = x1 + 1; + seg[i].y1 = y1 + SCROLL_BAR_WIDTH - 2; + seg[i].x2 = x1 + SCROLL_BAR_WIDTH - 2; + seg[i++].y2 = y1 + SCROLL_BAR_WIDTH - 2; + + seg[i].x1 = x1 + 0; + seg[i].y1 = y1 + SCROLL_BAR_WIDTH - 1; + seg[i].x2 = x1 + SCROLL_BAR_WIDTH - 1; + seg[i++].y2 = y1 + SCROLL_BAR_WIDTH - 1; + XDrawSegments(dpy, main_win, sgc, seg, i); +} - seg[i].x1 = x1+SCROLL_BAR_WIDTH - 1; seg[i].y1 = y1+0; - seg[i].x2 = x1+SCROLL_BAR_WIDTH/2; seg[i++].y2 = y1+SCROLL_BAR_WIDTH - 1; - XDrawSegments(dpy, main_win, sgc, seg, i); +void +RedrawBottomButton(GC rgc, GC sgc, int x1, int y1) +{ + XSegment seg[4]; + int i = 0; + + seg[i].x1 = x1 + 1; + seg[i].y1 = y1 + 1; + seg[i].x2 = x1 + SCROLL_BAR_WIDTH / 2; + seg[i++].y2 = y1 + SCROLL_BAR_WIDTH - 2; + + seg[i].x1 = x1; + seg[i].y1 = y1 + 0; + seg[i].x2 = x1 + SCROLL_BAR_WIDTH / 2; + seg[i++].y2 = y1 + SCROLL_BAR_WIDTH - 1; + + seg[i].x1 = x1 + 1; + seg[i].y1 = y1 + 1; + seg[i].x2 = x1 + SCROLL_BAR_WIDTH - 2; + seg[i++].y2 = y1 + 1; + + seg[i].x1 = x1; + seg[i].y1 = y1 + 0; + seg[i].x2 = x1 + SCROLL_BAR_WIDTH - 1; + seg[i++].y2 = y1 + 0; + XDrawSegments(dpy, main_win, rgc, seg, i); + + i = 0; + seg[i].x1 = x1 + SCROLL_BAR_WIDTH - 2; + seg[i].y1 = y1 + 1; + seg[i].x2 = x1 + SCROLL_BAR_WIDTH / 2; + seg[i++].y2 = y1 + SCROLL_BAR_WIDTH - 2; + + seg[i].x1 = x1 + SCROLL_BAR_WIDTH - 1; + seg[i].y1 = y1 + 0; + seg[i].x2 = x1 + SCROLL_BAR_WIDTH / 2; + seg[i++].y2 = y1 + SCROLL_BAR_WIDTH - 1; + XDrawSegments(dpy, main_win, sgc, seg, i); } - Index: fvwm/modules/FvwmTalk/FvwmTalk.1 =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmTalk/FvwmTalk.1,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmTalk/FvwmTalk.1 --- fvwm/modules/FvwmTalk/FvwmTalk.1 +++ fvwm/modules/FvwmTalk/FvwmTalk.1 @@ -1,47 +1,36 @@ .\" $OpenBSD: FvwmTalk.1,v 1.1.1.1 2006/11/26 10:53:55 matthieu Exp $ .\" t -.\" @(#)FvwmTalk.1 1/12/94 -.TH FvwmTalk 1 "Jan 28 1994" 1.20 +.\" @(#)FvwmTalk.1 1/12/94 +.TH FVWMTALK 1 "January 28, 1994" "1.20" "FVWM Modules" .UC .SH NAME FvwmTalk \- the FVWM command line interface .SH SYNOPSIS FvwmTalk is spawned by fvwm, so no command line invocation will work. - .SH DESCRIPTION -The FvwmTalk allows the user to type fvwm commands into a window, and -have them executed immediately. These commands are usually specfified -in the .fvwmrc file, or are bound to menu/mouse items as specified -in that file. This tools is particularly useful for testing new -configuration ideas, or for implementing temporary changes to your +FvwmTalk allows the user to type fvwm commands into a window and execute them +immediately. These commands are usually specified in the .fvwmrc file or are +bound to menu or mouse items defined there. The tool is particularly useful for +testing new configuration ideas or implementing temporary changes to the environment. - .SH COPYRIGHTS -The FvwmTalk program, and the concept for -interfacing this module to the Window Manager, are all original work -by Robert Nation - -Copyright 1994, Robert Nation. No guarantees or warranties or anything -are provided or implied in any way whatsoever. Use this program at your -own risk. Permission to use this program for any purpose is given, -as long as the copyright is kept intact. - - +The FvwmTalk program, and the concept for interfacing this module to the window +manager, are original work by Robert Nation. +.PP +Copyright 1994, Robert Nation. No guarantees or warranties are provided or +implied. Use this program at your own risk. Permission to use this program for +any purpose is granted, provided the copyright notice remains intact. .SH INITIALIZATION -So kill me, I can't remember what goes on. - +FvwmTalk does not require explicit initialization beyond fvwm's own module +startup sequence. .SH INVOCATION -FvwmTalk can be invoked by inserting the line 'Module FvwmTalk' in -the .fvwmrc file. This can be placed on a line by itself, if FvwmTalk -is to be spawned during fvwm's initialization, or can be bound to a -menu or mouse button or keystroke to invoke it later. Fvwm will search -directory specified in the ModulePath configuration option to attempt -to locate FvwmTalk. - +FvwmTalk can be invoked by inserting the line `Module FvwmTalk` in the .fvwmrc +file. This can be placed on its own line if FvwmTalk is to be spawned during +fvwm initialization, or it can be bound to a menu, mouse button, or keystroke +to launch it later. Fvwm searches the directory specified in the ModulePath +option to locate the module. .SH CONFIGURATION OPTIONS -I plead ignorance here. Read the code. - - +FvwmTalk accepts the standard fvwm module command-line options. Consult the +source code for the complete list of supported arguments. .SH AUTHOR Robert Nation - Index: fvwm/modules/FvwmTalk/FvwmTalk.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmTalk/FvwmTalk.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmTalk/FvwmTalk.c --- fvwm/modules/FvwmTalk/FvwmTalk.c +++ fvwm/modules/FvwmTalk/FvwmTalk.c @@ -15,39 +15,37 @@ #define PROP_SIZE 1024 #include "config.h" +#include "../../fvwm/fvwm_sandbox.h" -#ifdef HAVE_SYS_BSDTYPES_H -#include /* Saul */ #endif -#include -#include +#include +#include + #include +#include +#include #include -#include -#include #if HAVE_SYS_SELECT_H #include #endif -#include -#include -#include +#include +#include #include -#include - -#include #include -#include -#include +#include +#include +#include +#include +#include #include "../../fvwm/module.h" - #include "FvwmTalk.h" char *MyName; -int fd_width,screen, d_depth; +int fd_width, screen, d_depth; int fd[2]; int x_fd; @@ -60,26 +58,25 @@ char *BackColor = "black"; char *display_name = NULL; XFontStruct *font; -Pixel fore_pix,back_pix; +Pixel fore_pix, back_pix; static Atom wm_del_win; unsigned long valuemask; XSetWindowAttributes attributes; XWMHints wmhints; Window window; -char last_error[256],previous_line[256]; +char last_error[256], previous_line[256]; char Text[256]; int pos = 0; -XSizeHints sizehints = -{ - (PMinSize | PResizeInc | PBaseSize | PWinGravity | PMaxSize), - 0, 0, 100, 100, /* x, y, width and height */ - 1, 1, /* Min width and height */ - 0, 0, /* Max width and height */ - 1, 1, /* Width and height increments */ - {0, 0}, {0, 0}, /* Aspect ratio - not used */ - 1, 1, /* base size */ - (NorthWestGravity) /* gravity */ +XSizeHints sizehints = { + (PMinSize | PResizeInc | PBaseSize | PWinGravity | PMaxSize), 0, 0, 100, + 100, /* x, y, width and height */ + 1, 1, /* Min width and height */ + 0, 0, /* Max width and height */ + 1, 1, /* Width and height increments */ + {0, 0}, {0, 0}, /* Aspect ratio - not used */ + 1, 1, /* base size */ + (NorthWestGravity) /* gravity */ }; Pixel GetColor(char *name); @@ -88,7 +85,7 @@ XGCValues gcv; GC myGC; int My_XNextEvent(Display *dpy, XEvent *event); void DrawWindow(int mode); -void paste_primary(int window,int property,int Delete); +void paste_primary(int window, int property, int Delete); void request_selection(int time); /*********************************************************************** @@ -97,124 +94,120 @@ void request_selection(int time); * main - start of module * ***********************************************************************/ -int main(int argc, char **argv) +int +main(int argc, char **argv) { - char *temp, *s; - XWMHints wm_hints; - XClassHint class_hints; - XTextProperty window_name; - - /* Save the program name - its used for error messages and option parsing */ - temp = argv[0]; - - s=strrchr(argv[0], '/'); - if (s != NULL) - temp = s + 1; - - MyName = safemalloc(strlen(temp)+2); - strcpy(MyName,"*"); - strcat(MyName, temp); - - if((argc != 6)&&(argc != 7)) - { - fprintf(stderr,"%s Version %s should only be executed by fvwm!\n",MyName, - VERSION); - exit(1); - } - - /* Dead pipes mean fvwm died */ - signal (SIGPIPE, DeadPipe); - - fd[0] = atoi(argv[1]); - fd[1] = atoi(argv[2]); - - /* Initialize X connection */ - if (!(dpy = XOpenDisplay(display_name))) - { - fprintf(stderr,"%s: can't open display %s", MyName, - XDisplayName(display_name)); - exit (1); - } - x_fd = XConnectionNumber(dpy); - - screen= DefaultScreen(dpy); - Root = RootWindow(dpy, screen); - if(Root == None) - { - fprintf(stderr,"%s: Screen %d is not valid ", MyName, (int)screen); - exit(1); - } - d_depth = DefaultDepth(dpy, screen); - - fd_width = GetFdWidth(); - - wm_del_win = XInternAtom(dpy,"WM_DELETE_WINDOW",False); - - /* load the font */ - if ((font = XLoadQueryFont(dpy, font_string)) == NULL) - { - if ((font = XLoadQueryFont(dpy, "fixed")) == NULL) - { - fprintf(stderr,"%s: No fonts available\n",MyName); - exit(1); + char *temp, *s; + XWMHints wm_hints; + XClassHint class_hints; + XTextProperty window_name; + + /* Save the program name - its used for error messages and option + * parsing */ + temp = argv[0]; + + s = strrchr(argv[0], '/'); + if (s != NULL) + temp = s + 1; + + size_t name_len = strlen(temp); + MyName = xmalloc(name_len + 2); + strlcpy(MyName, "*", name_len + 2); + strlcat(MyName, temp, name_len + 2); + + if ((argc != 6) && (argc != 7)) { + fprintf(stderr, + "%s Version %s should only be executed by fvwm!\n", MyName, + VERSION); + exit(1); } - }; - - - fore_pix = GetColor(ForeColor); - back_pix = GetColor(BackColor); - - valuemask = (CWBackPixel | CWBorderPixel | CWEventMask); - attributes.background_pixel = back_pix; - attributes.border_pixel = fore_pix; - attributes.event_mask = KeyPressMask | ExposureMask | ButtonPressMask; - - sizehints.width = 8*XTextWidth(font,"MMMMMMMMMM",10); - sizehints.height = 3*(font->ascent+font->descent+2)+2; - sizehints.x = 0; - sizehints.y = 0; - sizehints.width_inc = 0.1*XTextWidth(font,"MMMMMMMMMM",10); - sizehints.height_inc = 3*(font->ascent+font->descent+2)+2; - sizehints.base_width = 1; - sizehints.base_height = 3*(font->ascent+font->descent+2)+2; - sizehints.min_width = 1; - sizehints.min_height = 3*(font->ascent+font->descent+2)+2; - sizehints.max_height = 3*(font->ascent+font->descent+2)+2; - sizehints.max_width = 26*XTextWidth(font,"MMMMMMMMMM",10); - - window = XCreateWindow (dpy, Root, 0, 0, sizehints.width,sizehints.height, - (unsigned int) 1, - CopyFromParent, InputOutput, - (Visual *) CopyFromParent, - valuemask, &attributes); - - class_hints.res_name = "FvwmTalk"; - class_hints.res_class = "FvwmTalk"; - - wm_hints.flags = InputHint; - wm_hints.input = True;; - - XSetWMProtocols(dpy,window,&wm_del_win,1); - XSetWMNormalHints(dpy,window,&sizehints); - /* XStringListToTextProperty(&(argv[0]), 1, &window_name); */ - XStringListToTextProperty(&temp, 1, &window_name); - XSetWMProperties(dpy, window, &window_name, &window_name, - argv, argc, &sizehints, &wm_hints, &class_hints); - - gcv.foreground = fore_pix; - gcv.background = back_pix; - gcv.font = font->fid; - myGC = XCreateGC(dpy,window,GCForeground|GCBackground|GCFont,&gcv); - - - previous_line[0] = 0; - last_error[0] = 0; - XMapWindow(dpy,window); - Loop(fd); - return 0; -} + /* Dead pipes mean fvwm died */ + signal(SIGPIPE, DeadPipe); + fd[0] = atoi(argv[1]); + fd[1] = atoi(argv[2]); + + /* Initialize X connection */ + if (!(dpy = XOpenDisplay(display_name))) { + fprintf(stderr, "%s: can't open display %s", MyName, + XDisplayName(display_name)); + exit(1); + } + x_fd = XConnectionNumber(dpy); + + screen = DefaultScreen(dpy); + Root = RootWindow(dpy, screen); + if (Root == None) { + fprintf( + stderr, "%s: Screen %d is not valid ", MyName, (int)screen); + exit(1); + } + d_depth = DefaultDepth(dpy, screen); + + fd_width = GetFdWidth(); + + wm_del_win = XInternAtom(dpy, "WM_DELETE_WINDOW", False); + + /* load the font */ + if ((font = XLoadQueryFont(dpy, font_string)) == NULL) { + if ((font = XLoadQueryFont(dpy, "fixed")) == NULL) { + fprintf(stderr, "%s: No fonts available\n", MyName); + exit(1); + } + } + + fore_pix = GetColor(ForeColor); + back_pix = GetColor(BackColor); + + valuemask = (CWBackPixel | CWBorderPixel | CWEventMask); + attributes.background_pixel = back_pix; + attributes.border_pixel = fore_pix; + attributes.event_mask = KeyPressMask | ExposureMask | ButtonPressMask; + + sizehints.width = 8 * XTextWidth(font, "MMMMMMMMMM", 10); + sizehints.height = 3 * (font->ascent + font->descent + 2) + 2; + sizehints.x = 0; + sizehints.y = 0; + sizehints.width_inc = 0.1 * XTextWidth(font, "MMMMMMMMMM", 10); + sizehints.height_inc = 3 * (font->ascent + font->descent + 2) + 2; + sizehints.base_width = 1; + sizehints.base_height = 3 * (font->ascent + font->descent + 2) + 2; + sizehints.min_width = 1; + sizehints.min_height = 3 * (font->ascent + font->descent + 2) + 2; + sizehints.max_height = 3 * (font->ascent + font->descent + 2) + 2; + sizehints.max_width = 26 * XTextWidth(font, "MMMMMMMMMM", 10); + + window = XCreateWindow(dpy, Root, 0, 0, sizehints.width, + sizehints.height, (unsigned int)1, CopyFromParent, InputOutput, + (Visual *)CopyFromParent, valuemask, &attributes); + + class_hints.res_name = "FvwmTalk"; + class_hints.res_class = "FvwmTalk"; + + wm_hints.flags = InputHint; + wm_hints.input = True; + ; + + XSetWMProtocols(dpy, window, &wm_del_win, 1); + XSetWMNormalHints(dpy, window, &sizehints); + /* XStringListToTextProperty(&(argv[0]), 1, &window_name); */ + XStringListToTextProperty(&temp, 1, &window_name); + XSetWMProperties(dpy, window, &window_name, &window_name, argv, argc, + &sizehints, &wm_hints, &class_hints); + + gcv.foreground = fore_pix; + gcv.background = back_pix; + gcv.font = font->fid; + myGC = + XCreateGC(dpy, window, GCForeground | GCBackground | GCFont, &gcv); + + previous_line[0] = 0; + last_error[0] = 0; + XMapWindow(dpy, window); + Loop(fd); + return 0; +} /*********************************************************************** * @@ -222,260 +215,244 @@ int main(int argc, char **argv) * Loop - wait for data to process * ***********************************************************************/ -void Loop(int *fd) +void +Loop(int *fd) { - KeySym keysym; - static XComposeStatus compose = {NULL,0}; - XEvent event; - char kbuf[100]; - int count; - - pos = 0; - Text[0] = 0; - - while(1) - { - if(My_XNextEvent(dpy, &event)) - { - switch(event.type) - { - case KeyPress: - count = XLookupString(&(event.xkey),kbuf,99,&keysym,&compose); - kbuf[count] = (unsigned char)0; - if((keysym == XK_BackSpace )||(keysym == XK_Delete)) - { - if(pos > 0) - Text[--pos] = 0; - } - else if((keysym == XK_Return)||(keysym == XK_KP_Enter)) - { - SendText(fd,Text,0); - last_error[0] = 0; - strncpy(previous_line,Text,255); - previous_line[255] = 0; - pos = 0; - Text[pos] = 0; - DrawWindow(ALL); + KeySym keysym; + static XComposeStatus compose = {NULL, 0}; + XEvent event; + char kbuf[100]; + int count; + + pos = 0; + Text[0] = 0; + + sandbox_x11_only("FvwmTalk"); + sandbox_x11_only("FvwmTalk"); + + while (1) { + if (My_XNextEvent(dpy, &event)) { + switch (event.type) { + case KeyPress: + count = XLookupString( + &(event.xkey), kbuf, 99, &keysym, &compose); + kbuf[count] = (unsigned char)0; + if ((keysym == XK_BackSpace) || + (keysym == XK_Delete)) { + if (pos > 0) + Text[--pos] = 0; + } else if ((keysym == XK_Return) || + (keysym == XK_KP_Enter)) { + SendText(fd, Text, 0); + last_error[0] = 0; + strncpy(previous_line, Text, 255); + previous_line[255] = 0; + pos = 0; + Text[pos] = 0; + DrawWindow(ALL); + } else { + if (pos + count < 255) { + strlcat( + Text, kbuf, sizeof(Text)); + pos += count; + } else + XBell(dpy, 0); + } + DrawWindow(UPDATE_ONLY); + break; + case ButtonPress: + if (event.xbutton.button == 2) + request_selection(event.xbutton.time); + break; + case Expose: + DrawWindow(ALL); + break; + case ClientMessage: + if ((event.xclient.format == 32) && + (event.xclient.data.l[0] == wm_del_win)) { + exit(0); + } + break; + case SelectionNotify: + paste_primary(event.xselection.requestor, + event.xselection.property, True); + default: + break; + } } - else - { - if(pos + count < 255) - { - strcat(Text,kbuf); - pos += count; - } - else - XBell(dpy,0); - } - DrawWindow(UPDATE_ONLY); - break; - case ButtonPress: - if(event.xbutton.button == 2) - request_selection(event.xbutton.time); - break; - case Expose: - DrawWindow(ALL); - break; - case ClientMessage: - if ((event.xclient.format==32) && - (event.xclient.data.l[0]==wm_del_win)) - { - exit(0); - } - break; - case SelectionNotify: - paste_primary(event.xselection.requestor, - event.xselection.property,True); - default: - break; - } } - } } - /*********************************************************************** * * Procedure: * SIGPIPE handler - SIGPIPE means fvwm is dying * ***********************************************************************/ -void DeadPipe(int nonsense) +void +DeadPipe(int nonsense) { - fprintf(stderr,"FvwmTalk: dead pipe\n"); - exit(0); + fprintf(stderr, "FvwmTalk: dead pipe\n"); + exit(0); } - - /**************************************************************************** * * Loads a single color * ****************************************************************************/ -Pixel GetColor(char *name) +Pixel +GetColor(char *name) { - XColor color; - XWindowAttributes attributes; - - XGetWindowAttributes(dpy, Root,&attributes); - color.pixel = 0; - if (!XParseColor (dpy, attributes.colormap, name, &color)) - { - nocolor("parse",name); - } - else if(!XAllocColor (dpy, attributes.colormap, &color)) - { - nocolor("alloc",name); - } - return color.pixel; + XColor color; + XWindowAttributes attributes; + + XGetWindowAttributes(dpy, Root, &attributes); + color.pixel = 0; + if (!XParseColor(dpy, attributes.colormap, name, &color)) { + nocolor("parse", name); + } else if (!XAllocColor(dpy, attributes.colormap, &color)) { + nocolor("alloc", name); + } + return color.pixel; } - -void nocolor(char *a, char *b) +void +nocolor(char *a, char *b) { - fprintf(stderr,"%s: can't %s %s\n", MyName, a,b); - + fprintf(stderr, "%s: can't %s %s\n", MyName, a, b); } - /*************************************************************************** * * Waits for next X event, or for an auto-raise timeout. * ****************************************************************************/ -int My_XNextEvent(Display *dpy, XEvent *event) +int +My_XNextEvent(Display *dpy, XEvent *event) { - fd_set in_fdset; - unsigned long header[HEADER_SIZE]; - int count; - static int miss_counter = 0; - unsigned long *body; - - if(XPending(dpy)) - { - XNextEvent(dpy,event); - return 1; - } - - FD_ZERO(&in_fdset); - FD_SET(x_fd,&in_fdset); - FD_SET(fd[1],&in_fdset); - - select(fd_width,SELECT_TYPE_ARG234 &in_fdset, 0, 0, NULL); - - if(FD_ISSET(x_fd, &in_fdset)) - { - if(XPending(dpy)) - { - XNextEvent(dpy,event); - miss_counter = 0; - return 1; + fd_set in_fdset; + unsigned long header[HEADER_SIZE]; + int count; + static int miss_counter = 0; + unsigned long *body; + + if (XPending(dpy)) { + XNextEvent(dpy, event); + return 1; } - else - miss_counter++; - if(miss_counter > 100) - DeadPipe(0); - } - - if(FD_ISSET(fd[1], &in_fdset)) - { - if((count = ReadFvwmPacket(fd[1],header,&body)) > 0) - { - if(header[1] == M_ERROR || header[1] == M_STRING) - { - strncpy(last_error,(char *)(&body[3]),255); - /*last_error[strlen(last_error)-1] = 0;*/ - last_error[strlen(last_error)] = 0; - last_error[255] = 0; - XClearArea(dpy,window,0,0,10000,10000,1); - } - - free(body); - } - } - return 0; -} + FD_ZERO(&in_fdset); + FD_SET(x_fd, &in_fdset); + FD_SET(fd[1], &in_fdset); + + select(fd_width, SELECT_TYPE_ARG234 & in_fdset, 0, 0, NULL); + + if (FD_ISSET(x_fd, &in_fdset)) { + if (XPending(dpy)) { + XNextEvent(dpy, event); + miss_counter = 0; + return 1; + } else + miss_counter++; + if (miss_counter > 100) + DeadPipe(0); + } + if (FD_ISSET(fd[1], &in_fdset)) { + if ((count = ReadFvwmPacket(fd[1], header, &body)) > 0) { + if (header[1] == M_ERROR || header[1] == M_STRING) { + strncpy(last_error, (char *)(&body[3]), 255); + /*last_error[strlen(last_error)-1] = 0;*/ + last_error[strlen(last_error)] = 0; + last_error[255] = 0; + XClearArea(dpy, window, 0, 0, 10000, 10000, 1); + } + + free(body); + } + } + return 0; +} -void request_selection(int time) +void +request_selection(int time) { - Atom sel_property; - - if (XGetSelectionOwner(dpy,XA_PRIMARY) == None) - { - /* No primary selection so use the cut buffer. - */ - paste_primary(DefaultRootWindow(dpy),XA_CUT_BUFFER0,False); - return; - } - sel_property = XInternAtom(dpy,"VT_SELECTION",False); - XConvertSelection(dpy,XA_PRIMARY,XA_STRING,sel_property,window,time); + Atom sel_property; + + if (XGetSelectionOwner(dpy, XA_PRIMARY) == None) { + /* No primary selection so use the cut buffer. */ + paste_primary(DefaultRootWindow(dpy), XA_CUT_BUFFER0, False); + return; + } + sel_property = XInternAtom(dpy, "VT_SELECTION", False); + XConvertSelection( + dpy, XA_PRIMARY, XA_STRING, sel_property, window, time); } -void paste_primary(int window,int property,int Delete) +void +paste_primary(int window, int property, int Delete) { - Atom actual_type; - int actual_format,i; - unsigned long nitems, bytes_after, nread; - unsigned char *data, *data2; - - if (property == None) - return; - - nread = 0; - do - { - if (XGetWindowProperty(dpy,window,property,nread/4,PROP_SIZE,Delete, - AnyPropertyType,&actual_type,&actual_format, - &nitems,&bytes_after,(unsigned char **)&data) - != Success) - return; - if (actual_type != XA_STRING) - return; - - data2 = data; - /* want to make a \n to \r mapping for cut and paste only */ - for(i=0;i 0) - { - strncat(Text,(char *)data2,255-pos-nitems); - pos = strlen(Text); - DrawWindow(UPDATE_ONLY); - } - nread += nitems; - XFree(data2); - } while (bytes_after > 0); + Atom actual_type; + int actual_format, i; + unsigned long nitems, bytes_after, nread; + unsigned char *data, *data2; + + if (property == None) + return; + + nread = 0; + do { + if (XGetWindowProperty(dpy, window, property, nread / 4, + PROP_SIZE, Delete, AnyPropertyType, &actual_type, + &actual_format, &nitems, &bytes_after, + (unsigned char **)&data) != Success) + return; + if (actual_type != XA_STRING) + return; + + data2 = data; + /* want to make a \n to \r mapping for cut and paste only */ + for (i = 0; i < nitems; i++) { + if (*data == '\n') + *data = '\r'; + data++; + } + + if (255 - pos > 0) { + if (pos + (int)nitems < 255) + strncat(Text, (char *)data2, + 255 - pos - (int)nitems); + pos = strlen(Text); + DrawWindow(UPDATE_ONLY); + } + nread += nitems; + XFree(data2); + } while (bytes_after > 0); } -void DrawWindow(int mode) +void +DrawWindow(int mode) { - int w; - - if(mode == ALL) - { - XClearWindow(dpy,window); - XDrawImageString(dpy,window,myGC,2,(font->ascent+font->descent+2)+ - font->ascent+2,last_error,strlen(last_error)); - XDrawImageString(dpy,window,myGC,2, font->ascent+2, - previous_line,strlen(previous_line)); - } - else - { - XClearArea(dpy,window,0, - 2*(font->ascent+font->descent+2),10000,10000,0); - } - XDrawImageString(dpy,window,myGC,2,2*(font->ascent+font->descent+2)+ - font->ascent+2,Text,pos); - w=XTextWidth(font,Text,pos); - XDrawLine(dpy,window,myGC,4+w,2*(font->ascent+font->descent+2)+2, - 4+w,2*(font->ascent+font->descent+2)+ - font->ascent+font->descent); + int w; + + if (mode == ALL) { + XClearWindow(dpy, window); + XDrawImageString(dpy, window, myGC, 2, + (font->ascent + font->descent + 2) + font->ascent + 2, + last_error, strlen(last_error)); + XDrawImageString(dpy, window, myGC, 2, font->ascent + 2, + previous_line, strlen(previous_line)); + } else { + XClearArea(dpy, window, 0, + 2 * (font->ascent + font->descent + 2), 10000, 10000, 0); + } + XDrawImageString(dpy, window, myGC, 2, + 2 * (font->ascent + font->descent + 2) + font->ascent + 2, Text, + pos); + w = XTextWidth(font, Text, pos); + XDrawLine(dpy, window, myGC, 4 + w, + 2 * (font->ascent + font->descent + 2) + 2, 4 + w, + 2 * (font->ascent + font->descent + 2) + font->ascent + + font->descent); } Index: fvwm/modules/FvwmTalk/FvwmTalk.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmTalk/FvwmTalk.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmTalk/FvwmTalk.h --- fvwm/modules/FvwmTalk/FvwmTalk.h +++ fvwm/modules/FvwmTalk/FvwmTalk.h @@ -1,30 +1,27 @@ -#include "fvwmlib.h" +#include "fvwmlib.h" #define ACTION1 1 #define ACTION2 2 #define ACTION3 4 -struct list -{ - unsigned long id; - unsigned long last_focus_time; - unsigned long actions; - struct list *next; +struct list { + unsigned long id; + unsigned long last_focus_time; + unsigned long actions; + struct list *next; }; /************************************************************************* * * Subroutine Prototypes - * + * *************************************************************************/ void Loop(int *fd); -void SendInfo(int *fd,char *message,unsigned long window); -char *safemalloc(int length); +void SendInfo(int *fd, char *message, unsigned long window); struct list *find_window(unsigned long id); void remove_window(unsigned long id); void add_window(unsigned long new_win); void update_focus(struct list *l, unsigned long); void DeadPipe(int nonsense); void find_next_event_time(void); -void process_message(unsigned long type,unsigned long *body); - +void process_message(unsigned long type, unsigned long *body); Index: fvwm/modules/FvwmWinList/ButtonArray.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmWinList/ButtonArray.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmWinList/ButtonArray.c --- fvwm/modules/FvwmWinList/ButtonArray.c +++ fvwm/modules/FvwmWinList/ButtonArray.c @@ -9,34 +9,29 @@ * whatsoever. Use this program at your own risk. Permission to use this * program for any purpose is given, as long as the copyright is kept intact. * - * Things to do: Convert to C++ (In Progress) */ -#include "config.h" +#include "ButtonArray.h" -#include -#include #include #include +#include +#include #include "../../libs/fvwmlib.h" - #include "FvwmWinList.h" -#include "ButtonArray.h" -#include "Mallocs.h" - +#include "config.h" extern XFontStruct *ButtonFont; extern Display *dpy; extern Window win; -extern GC shadow[MAX_COLOUR_SETS],hilite[MAX_COLOUR_SETS]; -extern GC graph[MAX_COLOUR_SETS],background[MAX_COLOUR_SETS]; +extern GC shadow[MAX_COLOUR_SETS], hilite[MAX_COLOUR_SETS]; +extern GC graph[MAX_COLOUR_SETS], background[MAX_COLOUR_SETS]; extern int LeftJustify, TruncateLeft, ShowFocus; extern long CurrentDesk; extern int ShowCurrentDesk; - /************************************************************************* * * * Button handling functions and procedures * @@ -46,457 +41,454 @@ extern int ShowCurrentDesk; /* ------------------------------------------------------------------------- ButtonNew - Allocates and fills a new button structure ------------------------------------------------------------------------- */ -Button *ButtonNew(char *title, FvwmPicture *p, int up) +Button * +ButtonNew(char *title, FvwmPicture *p, int up) { - Button *new; - - new = (Button *)safemalloc(sizeof(Button)); - new->title = safemalloc(strlen(title)+1); - strcpy(new->title, title); - if (p != NULL) - { - new->p.picture = p->picture; - new->p.mask = p->mask; - new->p.width = p->width; - new->p.height = p->height; - new->p.depth = p->depth; - } - else - - new->p.picture = 0; - - new->up = up; - new->next = NULL; - new->needsupdate = 1; - - return new; + Button *new; + + new = (Button *)xmalloc(sizeof(Button)); + size_t title_len = strlen(title); + new->title = xmalloc(title_len + 1); + strlcpy(new->title, title, title_len + 1); + if (p != NULL) { + new->p.picture = p->picture; + new->p.mask = p->mask; + new->p.width = p->width; + new->p.height = p->height; + new->p.depth = p->depth; + } else + + new->p.picture = 0; + + new->up = up; + new->next = NULL; + new->needsupdate = 1; + + return new; } /****************************************************************************** InitArray - Initialize the arrary of buttons ******************************************************************************/ -void InitArray(ButtonArray *array,int x,int y,int w,int h) +void +InitArray(ButtonArray *array, int x, int y, int w, int h) { - array->count=0; - array->head=array->tail=NULL; - array->x=x; - array->y=y; - array->w=w; - array->h=h; + array->count = 0; + array->head = array->tail = NULL; + array->x = x; + array->y = y; + array->w = w; + array->h = h; } /****************************************************************************** UpdateArray - Update the array specifics. x,y, width, height ******************************************************************************/ -void UpdateArray(ButtonArray *array,int x,int y,int w, int h) +void +UpdateArray(ButtonArray *array, int x, int y, int w, int h) { - Button *temp; - - if (x!=-1) array->x=x; - if (y!=-1) array->y=y; - if (w!=-1) array->w=w; - if (h!=-1) array->h=h; - for(temp=array->head;temp!=NULL;temp=temp->next) temp->needsupdate=1; + Button *temp; + + if (x != -1) + array->x = x; + if (y != -1) + array->y = y; + if (w != -1) + array->w = w; + if (h != -1) + array->h = h; + for (temp = array->head; temp != NULL; temp = temp->next) + temp->needsupdate = 1; } /****************************************************************************** AddButton - Allocate space for and add the button to the bottom ******************************************************************************/ -int AddButton(ButtonArray *array, char *title, FvwmPicture *p, int up) +int +AddButton(ButtonArray *array, char *title, FvwmPicture *p, int up) { - Button *new; - - new = ButtonNew(title, p, up); - if (array->head == NULL) - { - array->head = array->tail = new; - } - else - { - array->tail->next = new; - array->tail = new; - } - array->count++; - -/* in Taskbar this replaces below ArrangeButtonArray (array); -*/ - - new->tw=XTextWidth(ButtonFont,title,strlen(title)); - new->truncatewidth=0; - new->next=NULL; - new->needsupdate=1; - new->set=0; - - return (array->count-1); + Button *new; + + new = ButtonNew(title, p, up); + if (array->head == NULL) { + array->head = array->tail = new; + } else { + array->tail->next = new; + array->tail = new; + } + array->count++; + + /* in Taskbar this replaces below ArrangeButtonArray (array); + */ + + new->tw = XTextWidth(ButtonFont, title, strlen(title)); + new->truncatewidth = 0; + new->next = NULL; + new->needsupdate = 1; + new->set = 0; + + return (array->count - 1); } /****************************************************************************** UpdateButton - Change the name/stae of a button ******************************************************************************/ -int UpdateButton(ButtonArray *array, int butnum, char *title, int up) +int +UpdateButton(ButtonArray *array, int butnum, char *title, int up) { - Button *temp; - - temp=find_n(array,butnum); - if (temp!=NULL) - { - if (title!=NULL) - { - temp->title=(char *)saferealloc(temp->title,strlen(title)+1); - strcpy(temp->title,title); - temp->tw=XTextWidth(ButtonFont,title,strlen(title)); - temp->truncatewidth = 0; - } - if (up!=-1) temp->up=up; - } else return -1; - temp->needsupdate=1; - return 1; + Button *temp; + + temp = find_n(array, butnum); + if (temp != NULL) { + if (title != NULL) { + size_t title_len = strlen(title); + temp->title = + (char *)xrealloc(temp->title, title_len + 1); + strlcpy(temp->title, title, title_len + 1); + temp->tw = XTextWidth(ButtonFont, title, strlen(title)); + temp->truncatewidth = 0; + } + if (up != -1) + temp->up = up; + } else + return -1; + temp->needsupdate = 1; + return 1; } /* ------------------------------------------------------------------------- UpdateButtonPicture - Change the picture of a button ------------------------------------------------------------------------- */ -int UpdateButtonPicture(ButtonArray *array, int butnum, FvwmPicture *p) +int +UpdateButtonPicture(ButtonArray *array, int butnum, FvwmPicture *p) { - Button *temp; - temp=find_n(array,butnum); - if (temp == NULL) return -1; - if (temp->p.picture != p->picture || temp->p.mask != p->mask) - { - temp->p.picture = p->picture; - temp->p.mask = p->mask; - temp->p.width = p->width; - temp->p.height = p->height; - temp->p.depth = p->depth; - temp->needsupdate = 1; - } - return 1; + Button *temp; + temp = find_n(array, butnum); + if (temp == NULL) + return -1; + if (temp->p.picture != p->picture || temp->p.mask != p->mask) { + temp->p.picture = p->picture; + temp->p.mask = p->mask; + temp->p.width = p->width; + temp->p.height = p->height; + temp->p.depth = p->depth; + temp->needsupdate = 1; + } + return 1; } /****************************************************************************** UpdateButtonSet - Change colour set of a button between odd and even ******************************************************************************/ -int UpdateButtonSet(ButtonArray *array, int butnum, int set) +int +UpdateButtonSet(ButtonArray *array, int butnum, int set) { - Button *btn; - - btn=find_n(array, butnum); - if (btn != NULL) - { - if ((btn->set & 1) != set) - { - btn->set = (btn->set & 2) | set; - btn->needsupdate = 1; - } - } else return -1; - return 1; + Button *btn; + + btn = find_n(array, butnum); + if (btn != NULL) { + if ((btn->set & 1) != set) { + btn->set = (btn->set & 2) | set; + btn->needsupdate = 1; + } + } else + return -1; + return 1; } /****************************************************************************** UpdateButtonDesk - Change desk of a button ******************************************************************************/ -int UpdateButtonDesk(ButtonArray *array, int butnum, long desk ) +int +UpdateButtonDesk(ButtonArray *array, int butnum, long desk) { - Button *btn; - - btn = find_n(array, butnum); - if (btn != NULL) - { - btn->desk = desk; - } else return -1; - return 1; + Button *btn; + + btn = find_n(array, butnum); + if (btn != NULL) { + btn->desk = desk; + } else + return -1; + return 1; } - /****************************************************************************** RemoveButton - Delete a button from the list ******************************************************************************/ -void RemoveButton(ButtonArray *array, int butnum) +void +RemoveButton(ButtonArray *array, int butnum) { - Button *temp,*temp2; - - if (butnum==0) - { - temp2=array->head; - temp=array->head=array->head->next; - } - else - { - temp=find_n(array,butnum-1); - if (temp==NULL) return; - temp2=temp->next; - temp->next=temp2->next; - } - - if (array->tail==temp2) array->tail=temp; - - FreeButton(temp2); - - if (temp!=array->head) temp=temp->next; - for(;temp!=NULL;temp=temp->next) temp->needsupdate=1; + Button *temp, *temp2; + + if (butnum == 0) { + temp2 = array->head; + temp = array->head = array->head->next; + } else { + temp = find_n(array, butnum - 1); + if (temp == NULL) + return; + temp2 = temp->next; + temp->next = temp2->next; + } + + if (array->tail == temp2) + array->tail = temp; + + FreeButton(temp2); + + if (temp != array->head) + temp = temp->next; + for (; temp != NULL; temp = temp->next) + temp->needsupdate = 1; } /****************************************************************************** find_n - Find the nth button in the list (Use internally) ******************************************************************************/ -Button *find_n(ButtonArray *array, int n) +Button * +find_n(ButtonArray *array, int n) { - Button *temp; - int i; + Button *temp; + int i; - temp=array->head; - for(i=0;inext); - return temp; + temp = array->head; + for (i = 0; i < n && temp != NULL; i++, temp = temp->next) + ; + return temp; } /****************************************************************************** FreeButton - Free space allocated to a button ******************************************************************************/ -void FreeButton(Button *ptr) +void +FreeButton(Button *ptr) { - if (ptr != NULL) { - if (ptr->title!=NULL) free(ptr->title); - free(ptr); - } + if (ptr != NULL) { + if (ptr->title != NULL) + free(ptr->title); + free(ptr); + } } /****************************************************************************** FreeAllButtons - Free the whole array of buttons ******************************************************************************/ -void FreeAllButtons(ButtonArray *array) +void +FreeAllButtons(ButtonArray *array) { -Button *temp,*temp2; - for(temp=array->head;temp!=NULL;) - { - temp2=temp; - temp=temp->next; - FreeButton(temp2); - } + Button *temp, *temp2; + for (temp = array->head; temp != NULL;) { + temp2 = temp; + temp = temp->next; + FreeButton(temp2); + } } /****************************************************************************** DoButton - Draw the specified button. (Used internally) ******************************************************************************/ -void DoButton(Button *button, int x, int y, int w, int h) +void +DoButton(Button *button, int x, int y, int w, int h) { - int up,Fontheight,newx,set; - GC topgc; - GC bottomgc; - char *string; - XGCValues gcv; - unsigned long gcm; - XFontStruct *font; - - up=button->up; - set=button->set; - topgc = up ? hilite[set] : shadow[set]; - bottomgc = up ? shadow[set] : hilite[set]; - font = ButtonFont; - - gcm = GCFont; - gcv.font = font->fid; - XChangeGC(dpy, graph[set], gcm, &gcv); - - - Fontheight=ButtonFont->ascent+ButtonFont->descent; - - /*? XClearArea(dpy,win,x,y,w,h,False);*/ - XFillRectangle(dpy,win,background[set],x,y,w,h+1); - - if ((button->p.picture != 0)/* && + int up, Fontheight, newx, set; + GC topgc; + GC bottomgc; + char *string; + XGCValues gcv; + unsigned long gcm; + XFontStruct *font; + + up = button->up; + set = button->set; + topgc = up ? hilite[set] : shadow[set]; + bottomgc = up ? shadow[set] : hilite[set]; + font = ButtonFont; + + gcm = GCFont; + gcv.font = font->fid; + XChangeGC(dpy, graph[set], gcm, &gcv); + + Fontheight = ButtonFont->ascent + ButtonFont->descent; + + /*? XClearArea(dpy,win,x,y,w,h,False);*/ + XFillRectangle(dpy, win, background[set], x, y, w, h + 1); + + if ((button->p.picture != 0)/* && (w + button->p.width + w3p + 3 > MIN_BUTTON_SIZE)*/) { - - gcm = GCClipMask|GCClipXOrigin|GCClipYOrigin; - gcv.clip_mask = button->p.mask; - gcv.clip_x_origin = x + 4; - gcv.clip_y_origin = y + ((h-button->p.height) >> 1); - XChangeGC(dpy, hilite[set], gcm, &gcv); - XCopyArea(dpy, button->p.picture, win, hilite[set], 0, 0, - button->p.width, button->p.height, - gcv.clip_x_origin, gcv.clip_y_origin); - gcm = GCClipMask; - gcv.clip_mask = None; - XChangeGC(dpy, hilite[set], gcm, &gcv); - - newx = button->p.width+6; - } - else - { - if (LeftJustify) - newx=4; - else - newx=max((w-button->tw)/2,4); - } - - string=button->title; - - if (!LeftJustify) { - if (TruncateLeft && (w-button->tw)/2 < 4) { - if (button->truncatewidth == w) - string=button->truncate_title; - else { - string=button->title; - while(*string && (w-XTextWidth(ButtonFont,string,strlen(string)))/2 < 4) - string++; - button->truncatewidth = w; - button->truncate_title=string; - } - } - } - XDrawString(dpy,win,graph[set],x+newx,y+3+ButtonFont->ascent,string,strlen(string)); - button->needsupdate=0; - - /* Draw relief last, don't forget that XDrawLine doesn't do the last pixel */ - XDrawLine(dpy,win,topgc,x,y,x+w-1,y); - XDrawLine(dpy,win,topgc,x+1,y+1,x+w-2,y+1); - XDrawLine(dpy,win,topgc,x,y+1,x,y+h+1); - XDrawLine(dpy,win,topgc,x+1,y+2,x+1,y+h); - XDrawLine(dpy,win,bottomgc,x+1,y+h,x+w,y+h); - XDrawLine(dpy,win,bottomgc,x+2,y+h-1,x+w-1,y+h-1); - XDrawLine(dpy,win,bottomgc,x+w-1,y,x+w-1,y+h); - XDrawLine(dpy,win,bottomgc,x+w-2,y+1,x+w-2,y+h-1); - + gcm = GCClipMask | GCClipXOrigin | GCClipYOrigin; + gcv.clip_mask = button->p.mask; + gcv.clip_x_origin = x + 4; + gcv.clip_y_origin = y + ((h - button->p.height) >> 1); + XChangeGC(dpy, hilite[set], gcm, &gcv); + XCopyArea(dpy, button->p.picture, win, hilite[set], 0, 0, + button->p.width, button->p.height, gcv.clip_x_origin, + gcv.clip_y_origin); + gcm = GCClipMask; + gcv.clip_mask = None; + XChangeGC(dpy, hilite[set], gcm, &gcv); + + newx = button->p.width + 6; + } else { + if (LeftJustify) + newx = 4; + else + newx = max((w - button->tw) / 2, 4); + } + + string = button->title; + + if (!LeftJustify) { + if (TruncateLeft && (w - button->tw) / 2 < 4) { + if (button->truncatewidth == w) + string = button->truncate_title; + else { + string = button->title; + while (*string && + (w - XTextWidth(ButtonFont, string, + strlen(string))) / + 2 < + 4) + string++; + button->truncatewidth = w; + button->truncate_title = string; + } + } + } + XDrawString(dpy, win, graph[set], x + newx, y + 3 + ButtonFont->ascent, + string, strlen(string)); + button->needsupdate = 0; + + /* Draw relief last, don't forget that XDrawLine doesn't do the last + * pixel */ + XDrawLine(dpy, win, topgc, x, y, x + w - 1, y); + XDrawLine(dpy, win, topgc, x + 1, y + 1, x + w - 2, y + 1); + XDrawLine(dpy, win, topgc, x, y + 1, x, y + h + 1); + XDrawLine(dpy, win, topgc, x + 1, y + 2, x + 1, y + h); + XDrawLine(dpy, win, bottomgc, x + 1, y + h, x + w, y + h); + XDrawLine(dpy, win, bottomgc, x + 2, y + h - 1, x + w - 1, y + h - 1); + XDrawLine(dpy, win, bottomgc, x + w - 1, y, x + w - 1, y + h); + XDrawLine(dpy, win, bottomgc, x + w - 2, y + 1, x + w - 2, y + h - 1); } /****************************************************************************** DrawButtonArray - Draw the whole array (all=1), or only those that need. ******************************************************************************/ -void DrawButtonArray(ButtonArray *barray, int all) +void +DrawButtonArray(ButtonArray *barray, int all) { - Button *btn; - int i = 0; /* buttons displayed */ - - for(btn = barray->head; btn != NULL; btn = btn->next) - { - if((!ShowCurrentDesk) || ( btn->desk == CurrentDesk ) ) - { - if (btn->needsupdate || all) - { - DoButton - ( - btn,barray->x, - barray->y+(i*(barray->h+1)), - barray->w,barray->h - ); - } - i++; - } - } + Button *btn; + int i = 0; /* buttons displayed */ + + for (btn = barray->head; btn != NULL; btn = btn->next) { + if ((!ShowCurrentDesk) || (btn->desk == CurrentDesk)) { + if (btn->needsupdate || all) { + DoButton(btn, barray->x, + barray->y + (i * (barray->h + 1)), + barray->w, barray->h); + } + i++; + } + } } /****************************************************************************** SwitchButton - Alternate the state of a button ******************************************************************************/ -void SwitchButton(ButtonArray *array, int butnum) +void +SwitchButton(ButtonArray *array, int butnum) { - Button *btn; + Button *btn; - btn = find_n(array, butnum); - btn->up =!btn->up; - btn->needsupdate=1; - DrawButtonArray(array, 0); + btn = find_n(array, butnum); + btn->up = !btn->up; + btn->needsupdate = 1; + DrawButtonArray(array, 0); } /* ------------------------------------------------------------------------- RadioButton - Enable button i and verify all others are disabled ------------------------------------------------------------------------- */ -void RadioButton(ButtonArray *array, int butnum) +void +RadioButton(ButtonArray *array, int butnum) { - Button *temp; - int i; - - for(temp=array->head,i=0; temp!=NULL; temp=temp->next,i++) - { - if (i == butnum) - { - if (ShowFocus && temp->up) - { - temp->up = 0; - temp->needsupdate=1; - } - if (!(temp->set & 2)) - { - temp->set |= 2; - temp->needsupdate=1; - } - } - else - { - if (ShowFocus && !temp->up) - { - temp->up = 1; - temp->needsupdate = 1; - } - if (temp->set & 2) - { - temp->set &= 1; - temp->needsupdate = 1; - } - } - } + Button *temp; + int i; + + for (temp = array->head, i = 0; temp != NULL; temp = temp->next, i++) { + if (i == butnum) { + if (ShowFocus && temp->up) { + temp->up = 0; + temp->needsupdate = 1; + } + if (!(temp->set & 2)) { + temp->set |= 2; + temp->needsupdate = 1; + } + } else { + if (ShowFocus && !temp->up) { + temp->up = 1; + temp->needsupdate = 1; + } + if (temp->set & 2) { + temp->set &= 1; + temp->needsupdate = 1; + } + } + } } /****************************************************************************** WhichButton - Based on x,y which button was pressed ******************************************************************************/ -int WhichButton(ButtonArray *array,int x, int y) +int +WhichButton(ButtonArray *array, int x, int y) { - int num; - - num=y/(array->h+1); - if (xx || x>array->x+array->w || num<0 || num>array->count-1) num=-1; - - /* Current Desk Hack */ - - if(ShowCurrentDesk) - { - Button *temp; - int i, n; - - temp=array->head; - for(i=0, n = 0;n < (num + 1) && temp != NULL;temp=temp->next, i++) - { - if(temp->desk == CurrentDesk) - n++; - } - num = i-1; - } - return(num); + int num; + + num = y / (array->h + 1); + if (x < array->x || x > array->x + array->w || num < 0 || + num > array->count - 1) + num = -1; + + /* Current Desk Hack */ + + if (ShowCurrentDesk) { + Button *temp; + int i, n; + + temp = array->head; + for (i = 0, n = 0; n < (num + 1) && temp != NULL; + temp = temp->next, i++) { + if (temp->desk == CurrentDesk) + n++; + } + num = i - 1; + } + return (num); } /****************************************************************************** ButtonName - Return the name of the button ******************************************************************************/ -char *ButtonName(ButtonArray *array, int butnum) +char * +ButtonName(ButtonArray *array, int butnum) { - Button *temp; + Button *temp; - temp=find_n(array,butnum); - return temp->title; + temp = find_n(array, butnum); + return temp->title; } /****************************************************************************** PrintButtons - Print the array of button names to the console. (Debugging) ******************************************************************************/ -void PrintButtons(ButtonArray *array) +void +PrintButtons(ButtonArray *array) { - Button *temp; - - ConsoleMessage("List of Buttons:\n"); - for(temp=array->head;temp!=NULL;temp=temp->next) - ConsoleMessage(" %s is %s\n",temp->title,(temp->up) ? "Up":"Down"); -} + Button *temp; -#if 0 -/****************************************************************************** - ButtonArrayMaxWidth - Calculate the width needed for the widest title -******************************************************************************/ -int ButtonArrayMaxWidth(ButtonArray *array) -{ -Button *temp; -int x=0; - for(temp=array->head;temp!=NULL;temp=temp->next) - x=max(temp->tw,x); - return x; + ConsoleMessage("List of Buttons:\n"); + for (temp = array->head; temp != NULL; temp = temp->next) + ConsoleMessage( + " %s is %s\n", temp->title, (temp->up) ? "Up" : "Down"); } -#endif Index: fvwm/modules/FvwmWinList/ButtonArray.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmWinList/ButtonArray.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmWinList/ButtonArray.h --- fvwm/modules/FvwmWinList/ButtonArray.h +++ fvwm/modules/FvwmWinList/ButtonArray.h @@ -1,42 +1,44 @@ -/* FvwmWinList Module for Fvwm. +/* FvwmWinList Module for Fvwm. * * Copyright 1994, Mike Finger (mfinger@mermaid.micro.umn.edu or * Mike_Finger@atk.com) * * The functions in this header file that are the original work of Mike Finger. - * + * * No guarantees or warantees or anything are provided or implied in any way * whatsoever. Use this program at your own risk. Permission to use this * program for any purpose is given, as long as the copyright is kept intact. * - * Things to do: Convert to C++ (In Progress) */ +#ifndef BUTTONARRAY_H +#define BUTTONARRAY_H + +#include "../../libs/fvwmlib.h" + /* Struct definitions */ -typedef struct button -{ - char *title; - char *truncate_title; /* valid only if truncatewidth > 0 */ - int up, needsupdate, tw, set, truncatewidth; - struct button *next; - FvwmPicture p; - long desk; +typedef struct button { + char *title; + char *truncate_title; /* valid only if truncatewidth > 0 */ + int up, needsupdate, tw, set, truncatewidth; + struct button *next; + FvwmPicture p; + long desk; } Button; -typedef struct -{ - int count; - Button *head,*tail; - int x,y,w,h; +typedef struct { + int count; + Button *head, *tail; + int x, y, w, h; } ButtonArray; #define MAX_COLOUR_SETS 4 /* Function Prototypes */ Button *ButtonNew(char *title, FvwmPicture *p, int up); -void InitArray(ButtonArray *array,int x,int y,int w,int h); -void UpdateArray(ButtonArray *array,int x,int y,int w, int h); -int AddButton(ButtonArray *array, char *title, FvwmPicture *p,int up); +void InitArray(ButtonArray *array, int x, int y, int w, int h); +void UpdateArray(ButtonArray *array, int x, int y, int w, int h); +int AddButton(ButtonArray *array, char *title, FvwmPicture *p, int up); int UpdateButton(ButtonArray *array, int butnum, char *title, int up); int UpdateButtonPicture(ButtonArray *array, int butnum, FvwmPicture *p); int UpdateButtonSet(ButtonArray *array, int butnum, int set); @@ -47,7 +49,9 @@ void FreeButton(Button *ptr); void FreeAllButtons(ButtonArray *array); void DoButton(Button *ptr, int x, int y, int w, int h); void DrawButtonArray(ButtonArray *array, int all); -void SwitchButton(ButtonArray *array,int butnum); +void SwitchButton(ButtonArray *array, int butnum); void RadioButton(ButtonArray *array, int butnum); -int WhichButton(ButtonArray *array,int x, int y); +int WhichButton(ButtonArray *array, int x, int y); void PrintButtons(ButtonArray *array); + +#endif /* BUTTONARRAY_H */ Index: fvwm/modules/FvwmWinList/Colors.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmWinList/Colors.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmWinList/Colors.c --- fvwm/modules/FvwmWinList/Colors.c +++ fvwm/modules/FvwmWinList/Colors.c @@ -1,4 +1,4 @@ -/* Part of the FvwmWinList Module for Fvwm. +/* Part of the FvwmWinList Module for Fvwm. * * Copyright 1994, Mike Finger (mfinger@mermaid.micro.umn.edu or * Mike_Finger@atk.com) @@ -16,34 +16,36 @@ * own risk. Permission to use this program for any purpose is given, * as long as the copyright is kept intact. */ -#include "config.h" -#include -#include #include "Colors.h" +#include +#include + +#include "config.h" extern Display *dpy; extern Window Root; /**************************************************************************** Loads a single color -*****************************************************************************/ -Pixel GetColor(char *name) +*****************************************************************************/ +Pixel +GetColor(char *name) { - XColor color; - XWindowAttributes attributes; - - XGetWindowAttributes(dpy,Root,&attributes); - color.pixel = 0; - if (!XParseColor (dpy, attributes.colormap, name, &color)) - nocolor("parse",name); - else if(!XAllocColor (dpy, attributes.colormap, &color)) - nocolor("alloc",name); - return color.pixel; + XColor color; + XWindowAttributes attributes; + + XGetWindowAttributes(dpy, Root, &attributes); + color.pixel = 0; + if (!XParseColor(dpy, attributes.colormap, name, &color)) + nocolor("parse", name); + else if (!XAllocColor(dpy, attributes.colormap, &color)) + nocolor("alloc", name); + return color.pixel; } - -void nocolor(char *a, char *b) +void +nocolor(char *a, char *b) { - fprintf(stderr,"FvwmWinList: can't %s %s\n", a,b); + fprintf(stderr, "FvwmWinList: can't %s %s\n", a, b); } Index: fvwm/modules/FvwmWinList/Colors.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmWinList/Colors.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmWinList/Colors.h --- fvwm/modules/FvwmWinList/Colors.h +++ fvwm/modules/FvwmWinList/Colors.h @@ -1,4 +1,4 @@ -/* Part of the FvwmWinList Module for Fvwm. +/* Part of the FvwmWinList Module for Fvwm. * * The functions in this header file were originally part of the GoodStuff * and FvwmIdent modules for Fvwm, so there copyrights are listed: @@ -16,4 +16,3 @@ Pixel GetColor(char *name); Pixel GetHilite(Pixel background); Pixel GetShadow(Pixel background); void nocolor(char *a, char *b); - Index: fvwm/modules/FvwmWinList/FvwmWinList.1 =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmWinList/FvwmWinList.1,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmWinList/FvwmWinList.1 --- fvwm/modules/FvwmWinList/FvwmWinList.1 +++ fvwm/modules/FvwmWinList/FvwmWinList.1 @@ -1,139 +1,94 @@ .\" $OpenBSD: FvwmWinList.1,v 1.1.1.1 2006/11/26 10:53:55 matthieu Exp $ .\" t -.\" @(#)FvwmWinList.1 1995.5.27 -.TH FvwmWinList 1 "May 27th, 1995" 0.4h +.\" @(#)FvwmWinList.1 1995.5.27 +.TH FVWMWINLIST 1 "May 27, 1995" "0.4" "FVWM Modules" .UC .SH NAME FvwmWinList \- the FVWM window list module .SH SYNOPSIS FvwmWinList is spawned by fvwm, so no command line invocation will work. - .SH DESCRIPTION -The FvwmWinList module provides a window list made up of buttons, each -corresponding to a window that FVWM is managing. Clicking on the buttons -with any of the three mouse buttons will either do a default action or -can be user configured. Like the other modules, FvwmWinList only works -when fvwm is used as the window manager. - +FvwmWinList provides a window list composed of buttons, each corresponding to a +client managed by fvwm. Clicking any mouse button performs either the default +action or a user-configured command. Like other modules, FvwmWinList only works +when fvwm is the window manager. .SH COPYRIGHTS The FvwmWinList module is the original work of Mike Finger. - Copyright 1994, Mike Finger. The author makes no guarantees or warranties of -any kind about the use of this module. Use this modules at your own risk. -You may freely use this module or any portion of it for any purpose as long -as the copyright is kept intact. - +any kind about the use of this module. Use this module at your own risk. You +may freely use this module or any portion of it for any purpose as long as the +copyright is kept intact. .SH INITIALIZATION -During initialization, \fIFvwmWinList\fP will scan the same configuration file -that FVWM used during startup to find the options that pertain to it. These -options are discussed in a later section. - +During initialization, \fIFvwmWinList\fP scans the same configuration file that +fvwm reads at startup to locate its options. These options are discussed in a +later section. .SH INVOCATION -FvwmWinList can be invoked by fvwm during initialization by inserting the -line 'Module FvwmWinList' in the .fvwmrc file. - -FvwmWinList can also be bound to a keystroke, mouse button, or menu option to -be invoked later, in this case using 'Transient' as an argument will cause -FvwmWinList to resemble the built in window list. - -FvwmWinList must reside in a directory that is listed in the ModulePath option -of FVWM for it to be executed by FVWM. - +FvwmWinList can be launched during initialization by inserting the line `Module +FvwmWinList` in the .fvwmrc file. +It can also be bound to a keystroke, mouse button, or menu entry for later +invocation. Supplying the argument `Transient` makes FvwmWinList resemble the +built-in window list. +FvwmWinList must reside in a directory listed in fvwm's ModulePath option in +order to be executed. .SH CONFIGURATION OPTIONS -The following options can be placed in the .fvwmrc file - +Add the following directives to the .fvwmrc file to configure FvwmWinList. .IP "*FvwmWinListGeometry \fI{+-}{+-}\fP" -Specifies the location and gravity of the FvwmWinList window. At the current -time, size is not supported and FvwmWinList will resize itself as buttons are -added. If the NoAnchor option is not specified then the windows gravity -corner will be anchored, and the window will grow in the opposite direction. -(i.e. If the geometry is specified -5-5, that is SoutEastGravity. This will -cause the window to draw up and to the left as windows are added) - +Specify the location and gravity of the FvwmWinList window. Size is not +configurable; the window resizes as buttons are added. If NoAnchor is not set, +the gravity corner is anchored and the window grows in the opposite direction. +For example, `-5-5` selects SouthEastGravity so the window expands upward and to +the left as buttons appear. .IP "*FvwmWinListFont \fIfont\fP" -Specifies the font to be used for labeling the buttons. - +Specify the font used for button labels. .IP "*FvwmWinListFore \fIcolor\fP" -Specifies the color to use for the button names. - +Specify the color used for button labels. .IP "*FvwmWinListBack \fIcolor\fP" -Specifies the color for the buttons. - +Specify the background color of the buttons. .IP "*FvwmWinListFocusFore \fIcolor\fP" -Specifies the color to use for the button names for the window that -has the input focus. If omitted, the color from \fBFvwmWinListFore\fP -is used. - +Specify the label color for the button representing the window with input +focus. If omitted, \fBFvwmWinListFore\fP is used. .IP "*FvwmWinListFocusBack \fIcolor\fP" -Specifies the color to use for the button for the window that -has the input focus. If omitted, the color from \fBFvwmWinListBack\fP -is used. - +Specify the button color for the focused window. If omitted, +\fBFvwmWinListBack\fP is used. .IP "*FvwmWinListIconFore \fIcolor\fP" -Specifies the color to use for the button names for windows that -are iconified. If omitted, the color from \fBFvwmWinListFore\fP -is used. - +Specify the label color for iconified windows. If omitted, +\fBFvwmWinListFore\fP is used. .IP "*FvwmWinListIconBack \fIcolor\fP" -Specifies the color to use for the button for windows that -are iconified. If omitted, the color from \fBFvwmWinListBack\fP -is used. - +Specify the button color for iconified windows. If omitted, +\fBFvwmWinListBack\fP is used. .IP "*FvwmWinListDontDepressFocus" -By default FvwmWinlist will show the button for the window that has the -input focus as pressed in. This option disables that feature. - -.IP "*FvwmWinListUseSkipList -Tells FvwmWinList to not show the windows that are listed on a WindowListSkip -line if the configuration file. - -.IP "*FvwmWinListNoAnchor -By default, FvwmWinList will anchor the gravity corner so the window will grow -in the opposite direction. This undoes that option. - -.IP "*FvwmWinListUseIconNames -Tells FvwmWinList to use the icon name of the window instead of the full window -name. This is useful to keep the width of the window small. - -.IP "*FvwmWinListLeftJustify -By default, FvwmWinList will center the icon text in the icon. This option -causes it to be justified flush with the left edge of the icon. This option is -turned on when MiniIcons are used. - +Do not display the focused window's button as pressed. +.IP "*FvwmWinListUseSkipList" +Hide windows listed with the WindowListSkip style option. +.IP "*FvwmWinListNoAnchor" +Disable gravity anchoring so the window no longer grows away from the anchor +corner. +.IP "*FvwmWinListUseIconNames" +Display icon names instead of full window titles to keep the window narrow. +.IP "*FvwmWinListLeftJustify" +Left-justify label text instead of centering it. This option is enabled +automatically when MiniIcons are used. .IP "*FvwmWinListMinWidth \fIwidth\fP" .IP "*FvwmWinListMaxWidth \fIwidth\fP" -Specify the minimum and maximum widths that the buttons will shrink or grow -to. The buttons will normally size to fit the longest name, but certain -applications produce icon titles that can easily fill the screen. Setting -these parameters constrains the size of the buttons to be between the two -values. Setting them identically will fix the size of the buttons. -Setting Max < Min will have unpredictable results. - +Set the minimum and maximum button widths. Buttons normally size to the longest +name, but some applications produce extremely long titles. +These limits constrain the size range; identical values fix the width. +Using a maximum smaller than the minimum yields undefined results. .IP "*FvwmWinListTruncateLeft" -If names get truncated because of the setting of \fBFvwmWinListMaxWidth\fP, -they will normally get truncated on the right, so only the start of the names -are visible. Setting this resource will cause them to get truncated on the left, -so that the end of names are visible. This is useful when the window title -contains a directory and file name, for example. - -.IP "*FvwmWinListAction \fIaction response[,reponse...]\fP" -Tells FvwmWinList to do \fIresponse\fP when \fIaction\fP is done. The -currently supported \fIaction\fPs are: Click1, Click2, Click3. The currently -supported \fIresponse\fPs are any fvwm built-in commands, including modules -and functions. - +When titles are truncated because of \fBFvwmWinListMaxWidth\fP, remove +characters from the start rather than the end. +This is useful when titles contain directory paths or filenames. +.IP "*FvwmWinListAction \fIaction response[,response...]\fP" +Execute \fIresponse\fP when \fIaction\fP occurs. Supported actions are Click1, +Click2, and Click3. Responses may be any fvwm built-in commands, including +modules and functions. .SH SAMPLE CONFIGURATION -The following are excepts from a .fvwmrc file which describe FvwmWinList -initialization commands: - +The following snippets illustrate typical configuration commands: .nf -.sp -XCOMM####### -XCOMM Pop up the window list in tranient mode on button 3 press & hold - +XCOMM Pop up the window list in transient mode on button 3 press & hold Mouse 3 R A Module "FvwmWinList" FvwmWinList Transient -XCOMM######################### Window-Lister ############################### +XCOMM Window-Lister *FvwmWinListBack DarkOliveGreen *FvwmWinListFore PaleGoldenRod *FvwmWinListFont -*-new century schoolbook-bold-r-*-*-*-120-*-*-*-*-*-* @@ -147,12 +102,9 @@ XCOMM######################### Window-Lister ############################### *FvwmWinListMaxWidth 120 XCOMM I prefer the text centered XCOMM*FvwmWinListLeftJustify -XCOMM I like it achored +XCOMM I like it anchored XCOMM*FvwmWinListNoAnchor - -.sp .fi - .SH AUTHOR Mike Finger (mfinger@mermaid.micro.umn.edu) (Mike_Finger@atk.com) Index: fvwm/modules/FvwmWinList/FvwmWinList.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmWinList/FvwmWinList.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmWinList/FvwmWinList.c --- fvwm/modules/FvwmWinList/FvwmWinList.c +++ fvwm/modules/FvwmWinList/FvwmWinList.c @@ -21,14 +21,9 @@ * Modifications Done to Add Pixmaps, focus highlighting and Current Desk Only * By Don Mahurin, 1996, Some of this Code was taken from FvwmTaskBar - * Bug Notes:(Don Mahurin) - - * Moving a window doesnt send M_CONFIGURE, as I thought it should. Desktop - * for that button is not updated. - */ -#define TRUE 1 +#define TRUE 1 #define FALSE 0 #ifndef NO_CONSOLE @@ -36,48 +31,49 @@ #endif #define YES "Yes" -#define NO "No" +#define NO "No" -#include "config.h" +#include +#include -#include -#include #include -#include -#include -#include +#include #include +#include +#include + +#include "config.h" +#include "../../fvwm/fvwm_sandbox.h" #if HAVE_SYS_SELECT_H #include #endif -#include #include +#include -#ifdef HAVE_SYS_BSDTYPES_H -#include /* Saul */ #endif -#include +#include +#include #include -#include #include -#include -#include +#include #include +#include #include "../../fvwm/module.h" - -#include "FvwmWinList.h" #include "ButtonArray.h" -#include "List.h" #include "Colors.h" -#include "Mallocs.h" +#include "FvwmWinList.h" +#include "List.h" -#define GRAB_EVENTS (ButtonPressMask|ButtonReleaseMask|ButtonMotionMask|EnterWindowMask|LeaveWindowMask) +#define GRAB_EVENTS \ + (ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | \ + EnterWindowMask | LeaveWindowMask) -#define SomeButtonDown(a) ((a)&Button1Mask||(a)&Button2Mask||(a)&Button3Mask) +#define SomeButtonDown(a) \ + ((a) & Button1Mask || (a) & Button2Mask || (a) & Button3Mask) /* File type information */ FILE *console; @@ -88,10 +84,10 @@ int x_fd; /* X related things */ Display *dpy; Window Root, win; -int screen,d_depth,ScreenWidth,ScreenHeight; +int screen, d_depth, ScreenWidth, ScreenHeight; Pixel back[MAX_COLOUR_SETS], fore[MAX_COLOUR_SETS]; -GC graph[MAX_COLOUR_SETS],shadow[MAX_COLOUR_SETS],hilite[MAX_COLOUR_SETS]; -GC background[MAX_COLOUR_SETS]; +GC graph[MAX_COLOUR_SETS], shadow[MAX_COLOUR_SETS], hilite[MAX_COLOUR_SETS]; +GC background[MAX_COLOUR_SETS]; XFontStruct *ButtonFont; int fontheight; static Atom wm_del_win; @@ -99,40 +95,42 @@ Atom MwmAtom = None; /* Module related information */ char *Module; -int WindowIsUp=0,win_width=5,win_height=5,win_grav,win_x,win_y,win_title,win_border; -int Clength,Transient=0,Pressed=0,ButPressed,Checked=0; -int MinWidth=DEFMINWIDTH,MaxWidth=DEFMAXWIDTH; +int WindowIsUp = 0, win_width = 5, win_height = 5, win_grav, win_x, win_y, + win_title, win_border; +int Clength, Transient = 0, Pressed = 0, ButPressed, Checked = 0; +int MinWidth = DEFMINWIDTH, MaxWidth = DEFMAXWIDTH; ButtonArray buttons; List windows; -char *ClickAction[3]={"Iconify -1,Raise","Iconify","Lower"},*EnterAction, - *BackColor[MAX_COLOUR_SETS] = { "white" }, - *ForeColor[MAX_COLOUR_SETS] = { "black" }, - *geometry=""; +char *ClickAction[3] = {"Iconify -1,Raise", "Iconify", "Lower"}, *EnterAction, + *BackColor[MAX_COLOUR_SETS] = {"white"}, + *ForeColor[MAX_COLOUR_SETS] = {"black"}, *geometry = ""; char *font_string = "fixed"; -int UseSkipList=0,Anchor=1,UseIconNames=0,LeftJustify=0,TruncateLeft=0,ShowFocus=1; +int UseSkipList = 0, Anchor = 1, UseIconNames = 0, LeftJustify = 0, + TruncateLeft = 0, ShowFocus = 1; long CurrentDesk = 0; int ShowCurrentDesk = 0; static volatile sig_atomic_t isTerminated = False; -static RETSIGTYPE TerminateHandler(int sig); +static void TerminateHandler(int sig); /*************************************************************************** * TerminateHandler - reentrant signal handler that ends the main event loop ***************************************************************************/ -static RETSIGTYPE TerminateHandler(int sig) +static void +TerminateHandler(int sig) { - isTerminated = True; + isTerminated = True; } -int ItemCountD(List *list ) +int +ItemCountD(List *list) { - if(!ShowCurrentDesk) + if (!ShowCurrentDesk) return ItemCount(list); /* else */ return ItemCountDesk(list, CurrentDesk); - } /****************************************************************************** @@ -140,121 +138,130 @@ int ItemCountD(List *list ) Based on main() from FvwmIdent: Copyright 1994, Robert Nation and Nobutaka Suzuki. ******************************************************************************/ -int main(int argc, char **argv) +int +main(int argc, char **argv) { - char *temp, *s; + char *temp, *s; #ifdef HAVE_SIGACTION - struct sigaction sigact; + struct sigaction sigact; #endif - /* Save the program name for error messages and config parsing */ - temp = argv[0]; - s=strrchr(argv[0], '/'); - if (s != NULL) - temp = s + 1; - - /* Setup my name */ - Module = safemalloc(strlen(temp)+2); - strcpy(Module,"*"); - strcat(Module, temp); - Clength = strlen(Module); - - /* Open the console for messages */ - OpenConsole(); - - if((argc != 6)&&(argc != 7)) { - fprintf(stderr,"%s Version %s should only be executed by fvwm!\n",Module, - VERSION); - ConsoleMessage("%s Version %s should only be executed by fvwm!\n",Module, - VERSION); - exit(1); - } - + /* Save the program name for error messages and config parsing */ + temp = argv[0]; + s = strrchr(argv[0], '/'); + if (s != NULL) + temp = s + 1; + + /* Setup my name */ + size_t name_len = strlen(temp); + Module = xmalloc(name_len + 2); + strlcpy(Module, "*", name_len + 2); + strlcat(Module, temp, name_len + 2); + Clength = strlen(Module); + + /* Open the console for messages */ + OpenConsole(); + + if ((argc != 6) && (argc != 7)) { + fprintf(stderr, + "%s Version %s should only be executed by fvwm!\n", Module, + VERSION); + ConsoleMessage( + "%s Version %s should only be executed by fvwm!\n", Module, + VERSION); + exit(1); + } - if ((argc==7)&&(!strcasecmp(argv[6],"Transient"))) Transient=1; + if ((argc == 7) && (!strcasecmp(argv[6], "Transient"))) + Transient = 1; - Fvwm_fd[0] = atoi(argv[1]); - Fvwm_fd[1] = atoi(argv[2]); + Fvwm_fd[0] = atoi(argv[1]); + Fvwm_fd[1] = atoi(argv[2]); #ifdef HAVE_SIGACTION #ifdef SA_INTERRUPT - sigact.sa_flags = SA_INTERRUPT; + sigact.sa_flags = SA_INTERRUPT; #else - sigact.sa_flags = 0; + sigact.sa_flags = 0; #endif - sigemptyset(&sigact.sa_mask); - sigact.sa_handler = TerminateHandler; - sigaction(SIGPIPE, &sigact, NULL); - sigaction(SIGTERM, &sigact, NULL); + sigemptyset(&sigact.sa_mask); + sigact.sa_handler = TerminateHandler; + sigaction(SIGPIPE, &sigact, NULL); + sigaction(SIGTERM, &sigact, NULL); #else - signal(SIGPIPE, TerminateHandler); - signal(SIGTERM, TerminateHandler); + signal(SIGPIPE, TerminateHandler); + signal(SIGTERM, TerminateHandler); #ifdef HAVE_SIGINTERRUPT - siginterrupt(SIGPIPE, True); - siginterrupt(SIGTERM, True); + siginterrupt(SIGPIPE, True); + siginterrupt(SIGTERM, True); #endif #endif - /* Parse the config file */ - ParseConfig(); + /* Parse the config file */ + ParseConfig(); - /* Setup the XConnection */ - StartMeUp(); - XSetErrorHandler(ErrorHandler); + /* Setup the XConnection */ + StartMeUp(); + XSetErrorHandler(ErrorHandler); - InitPictureCMap(dpy, Root); + InitPictureCMap(dpy, Root); - InitArray(&buttons,0,0,win_width, fontheight+6); - InitList(&windows); + InitArray(&buttons, 0, 0, win_width, fontheight + 6); + InitList(&windows); - fd_width = GetFdWidth(); + fd_width = GetFdWidth(); - /* Request a list of all windows, - * wait for ConfigureWindow packets */ + /* Request a list of all windows, + * wait for ConfigureWindow packets */ - SetMessageMask(Fvwm_fd,M_CONFIGURE_WINDOW | M_RES_CLASS | M_RES_NAME | - M_ADD_WINDOW | M_DESTROY_WINDOW | M_ICON_NAME | - M_DEICONIFY | M_ICONIFY | M_END_WINDOWLIST | - M_NEW_DESK | M_NEW_PAGE | M_FOCUS_CHANGE | M_WINDOW_NAME | + SetMessageMask(Fvwm_fd, M_CONFIGURE_WINDOW | M_RES_CLASS | M_RES_NAME | + M_ADD_WINDOW | M_DESTROY_WINDOW | + M_ICON_NAME | M_DEICONIFY | M_ICONIFY | + M_END_WINDOWLIST | M_NEW_DESK | M_NEW_PAGE | + M_FOCUS_CHANGE | M_WINDOW_NAME | #ifdef MINI_ICONS - M_MINI_ICON | + M_MINI_ICON | #endif - M_STRING); + M_STRING); - SendFvwmPipe("Send_WindowList",0); + SendFvwmPipe("Send_WindowList", 0); - /* Recieve all messages from Fvwm */ - atexit(ShutMeDown); - MainEventLoop(); - return 0; + /* Recieve all messages from Fvwm */ + atexit(ShutMeDown); + MainEventLoop(); + return 0; } - /****************************************************************************** MainEventLoop - Read and redraw until we die, blocking when can't read ******************************************************************************/ -void MainEventLoop(void) +void +MainEventLoop(void) { -fd_set readset; - - while( !isTerminated ) { - FD_ZERO(&readset); - FD_SET(Fvwm_fd[1],&readset); - FD_SET(x_fd,&readset); - - /* This code restyled after FvwmIconMan, which is simpler. - * The biggest advantage over the original approach is - * having one fewer select statements - */ - XFlush(dpy); - if (select(fd_width,SELECT_TYPE_ARG234 &readset,NULL,NULL,NULL) > 0) { - - if (FD_ISSET(x_fd,&readset) || XPending(dpy)) LoopOnEvents(); - if (FD_ISSET(Fvwm_fd[1],&readset)) ReadFvwmPipe(); - - } - - } /* while */ + fd_set readset; + + sandbox_x11_only("FvwmWinList"); + sandbox_x11_only("FvwmWinList"); + + while (!isTerminated) { + FD_ZERO(&readset); + FD_SET(Fvwm_fd[1], &readset); + FD_SET(x_fd, &readset); + + /* This code restyled after FvwmIconMan, which is simpler. + * The biggest advantage over the original approach is + * having one fewer select statements + */ + XFlush(dpy); + if (select(fd_width, SELECT_TYPE_ARG234 & readset, NULL, NULL, + NULL) > 0) { + if (FD_ISSET(x_fd, &readset) || XPending(dpy)) + LoopOnEvents(); + if (FD_ISSET(Fvwm_fd[1], &readset)) + ReadFvwmPipe(); + } + + } /* while */ } /****************************************************************************** @@ -262,15 +269,15 @@ fd_set readset; Originally Loop() from FvwmIdent: Copyright 1994, Robert Nation and Nobutaka Suzuki. ******************************************************************************/ -void ReadFvwmPipe(void) +void +ReadFvwmPipe(void) { - unsigned long header[HEADER_SIZE],*body; + unsigned long header[HEADER_SIZE], *body; - if(ReadFvwmPacket(Fvwm_fd[1],header,&body) > 0) - { - ProcessMessage(header[1],body); - free(body); - } + if (ReadFvwmPacket(Fvwm_fd[1], header, &body) > 0) { + ProcessMessage(header[1], body); + free(body); + } } /****************************************************************************** @@ -278,119 +285,129 @@ void ReadFvwmPipe(void) Skeleton based on processmessage() from FvwmIdent: Copyright 1994, Robert Nation and Nobutaka Suzuki. ******************************************************************************/ -void ProcessMessage(unsigned long type,unsigned long *body) +void +ProcessMessage(unsigned long type, unsigned long *body) { - int redraw=0,i; - long flags; - char *name,*string; - static int current_focus=-1; - - FvwmPicture p; - - switch(type) - { - case M_ADD_WINDOW: - case M_CONFIGURE_WINDOW: - if ((i = FindItem(&windows,body[0]))!=-1) - { - if(UpdateItemDesk(&windows, i, body[7]) > 0) - { - AdjustWindow(); - RedrawWindow(1); - } - break; - } - - if (!(body[8]&WINDOWLISTSKIP) || !UseSkipList) - AddItem(&windows,body[0],body[8], body[7] /* desk */); - break; - case M_DESTROY_WINDOW: - if ((i=DeleteItem(&windows,body[0]))==-1) break; - RemoveButton(&buttons,i); - if (WindowIsUp) - AdjustWindow(); - - redraw=1; - break; + int redraw = 0, i; + long flags; + char *name, *string; + static int current_focus = -1; + + FvwmPicture p; + + switch (type) { + case M_ADD_WINDOW: + case M_CONFIGURE_WINDOW: + if ((i = FindItem(&windows, body[0])) != -1) { + if (UpdateItemDesk(&windows, body[0], body[7]) > 0) { + UpdateButtonDesk(&buttons, i, body[7]); + AdjustWindow(); + RedrawWindow(1); + } + break; + } + + if (!(body[8] & WINDOWLISTSKIP) || !UseSkipList) + AddItem(&windows, body[0], body[8], body[7] /* desk */); + break; + case M_DESTROY_WINDOW: + if ((i = DeleteItem(&windows, body[0])) == -1) + break; + RemoveButton(&buttons, i); + if (WindowIsUp) + AdjustWindow(); + + redraw = 1; + break; #ifdef MINI_ICONS - case M_MINI_ICON: - if ((i=FindItem(&windows,body[0]))==-1) break; - - if (UpdateButton(&buttons,i,NULL,-1)!=-1) - { - p.width = body[3]; - p.height = body[4]; - p.depth = body[5]; - p.picture = body[6]; - p.mask = body[7]; - - UpdateButtonPicture(&buttons, i, &p); - redraw = 0; - } - break; + case M_MINI_ICON: + if ((i = FindItem(&windows, body[0])) == -1) + break; + + if (UpdateButton(&buttons, i, NULL, -1) != -1) { + p.width = body[3]; + p.height = body[4]; + p.depth = body[5]; + p.picture = body[6]; + p.mask = body[7]; + + UpdateButtonPicture(&buttons, i, &p); + redraw = 0; + } + break; #endif - case M_WINDOW_NAME: - case M_ICON_NAME: - if ((type==M_ICON_NAME && !UseIconNames) || - (type==M_WINDOW_NAME && UseIconNames)) break; - if ((i=UpdateItemName(&windows,body[0],(char *)&body[3]))==-1) break; - string=(char *)&body[3]; - name=makename(string,ItemFlags(&windows,body[0])); - if (UpdateButton(&buttons,i,name,-1)==-1) - { - AddButton(&buttons, name, NULL, 1); - UpdateButtonSet(&buttons,i,ItemFlags(&windows,body[0])&ICONIFIED?1:0); - UpdateButtonDesk(&buttons,i,ItemDesk(&windows, body[0])); - } - free(name); - if (WindowIsUp) AdjustWindow(); - redraw=1; - break; - case M_DEICONIFY: - case M_ICONIFY: - if ((i=FindItem(&windows,body[0]))==-1) break; - flags=ItemFlags(&windows,body[0]); - if (type==M_DEICONIFY && !(flags&ICONIFIED)) break; - if (type==M_ICONIFY && flags&ICONIFIED) break; - flags^=ICONIFIED; - UpdateItemFlags(&windows,body[0],flags); - string=ItemName(&windows,i); - name=makename(string,flags); - if (UpdateButton(&buttons,i,name,-1)!=-1) redraw=1; - if (i!=current_focus||(flags&ICONIFIED)) - if (UpdateButtonSet(&buttons,i,(flags&ICONIFIED) ? 1 : 0)!=-1) redraw=1; - free(name); - break; - case M_FOCUS_CHANGE: - if ((i=FindItem(&windows,body[0]))!=-1) - { - flags=ItemFlags(&windows,body[0]); - UpdateItemFlags(&windows,body[0],flags); - RadioButton(&buttons,i); - } - else - RadioButton(&buttons,-1); - redraw = 1; - break; - case M_END_WINDOWLIST: - if (!WindowIsUp) MakeMeWindow(); - redraw = 1; - break; - case M_NEW_DESK: - CurrentDesk = body[0]; - if(ShowCurrentDesk) - { - AdjustWindow(); - RedrawWindow(1); - } - break; - case M_NEW_PAGE: - break; - } - - if (redraw && WindowIsUp==1) RedrawWindow(0); + case M_WINDOW_NAME: + case M_ICON_NAME: + if ((type == M_ICON_NAME && !UseIconNames) || + (type == M_WINDOW_NAME && UseIconNames)) + break; + if ((i = UpdateItemName(&windows, body[0], (char *)&body[3])) == + -1) + break; + string = (char *)&body[3]; + name = makename(string, ItemFlags(&windows, body[0])); + if (UpdateButton(&buttons, i, name, -1) == -1) { + AddButton(&buttons, name, NULL, 1); + UpdateButtonSet(&buttons, i, + ItemFlags(&windows, body[0]) & ICONIFIED ? 1 : 0); + UpdateButtonDesk( + &buttons, i, ItemDesk(&windows, body[0])); + } + free(name); + if (WindowIsUp) + AdjustWindow(); + redraw = 1; + break; + case M_DEICONIFY: + case M_ICONIFY: + if ((i = FindItem(&windows, body[0])) == -1) + break; + flags = ItemFlags(&windows, body[0]); + if (type == M_DEICONIFY && !(flags & ICONIFIED)) + break; + if (type == M_ICONIFY && flags & ICONIFIED) + break; + flags ^= ICONIFIED; + UpdateItemFlags(&windows, body[0], flags); + string = ItemName(&windows, i); + name = makename(string, flags); + if (UpdateButton(&buttons, i, name, -1) != -1) + redraw = 1; + if (i != current_focus || (flags & ICONIFIED)) + if (UpdateButtonSet( + &buttons, i, (flags & ICONIFIED) ? 1 : 0) != -1) + redraw = 1; + free(name); + break; + case M_FOCUS_CHANGE: + if ((i = FindItem(&windows, body[0])) != -1) { + flags = ItemFlags(&windows, body[0]); + UpdateItemFlags(&windows, body[0], flags); + RadioButton(&buttons, i); + } else + RadioButton(&buttons, -1); + redraw = 1; + break; + case M_END_WINDOWLIST: + if (!WindowIsUp) + MakeMeWindow(); + redraw = 1; + break; + case M_NEW_DESK: + CurrentDesk = body[0]; + if (ShowCurrentDesk) { + AdjustWindow(); + RedrawWindow(1); + } + break; + case M_NEW_PAGE: + break; + } + + if (redraw && WindowIsUp == 1) + RedrawWindow(0); } /****************************************************************************** @@ -398,37 +415,39 @@ void ProcessMessage(unsigned long type,unsigned long *body) Based on SendInfo() from FvwmIdent: Copyright 1994, Robert Nation and Nobutaka Suzuki. ******************************************************************************/ -void SendFvwmPipe(char *message,unsigned long window) +void +SendFvwmPipe(char *message, unsigned long window) { - int w; - char *hold,*temp,*temp_msg; - - hold=message; - - while(1) - { - temp=strchr(hold,','); - if (temp!=NULL) - { - temp_msg=safemalloc(temp-hold+1); - strncpy(temp_msg,hold,(temp-hold)); - temp_msg[(temp-hold)]='\0'; - hold=temp+1; - } else temp_msg=hold; - - write(Fvwm_fd[0],&window, sizeof(unsigned long)); - - w=strlen(temp_msg); - write(Fvwm_fd[0],&w,sizeof(int)); - write(Fvwm_fd[0],temp_msg,w); - - /* keep going */ - w=1; - write(Fvwm_fd[0],&w,sizeof(int)); - - if(temp_msg!=hold) free(temp_msg); - else break; - } + int w; + char *hold, *temp, *temp_msg; + + hold = message; + + while (1) { + temp = strchr(hold, ','); + if (temp != NULL) { + temp_msg = xmalloc(temp - hold + 1); + strncpy(temp_msg, hold, (temp - hold)); + temp_msg[(temp - hold)] = '\0'; + hold = temp + 1; + } else + temp_msg = hold; + + write(Fvwm_fd[0], &window, sizeof(unsigned long)); + + w = strlen(temp_msg); + write(Fvwm_fd[0], &w, sizeof(int)); + write(Fvwm_fd[0], temp_msg, w); + + /* keep going */ + w = 1; + write(Fvwm_fd[0], &w, sizeof(int)); + + if (temp_msg != hold) + free(temp_msg); + else + break; + } } /*********************************************************************** @@ -436,88 +455,92 @@ void SendFvwmPipe(char *message,unsigned long window) Based on DeadPipe() from FvwmIdent: Copyright 1994, Robert Nation and Nobutaka Suzuki. **********************************************************************/ -void DeadPipe(int nonsense) +void +DeadPipe(int nonsense) { - /* ShutMeDown(1); */ - /* - * do not call ShutMeDown, it may make X calls which are not allowed - * in a signal hander. - * - * THIS IS NO LONGER A SIGNAL HANDLER - we may now shut down gracefully - * NOTE: ShutMeDown will now be called automatically by exit(). - */ - exit(1); + /* ShutMeDown(1); */ + /* + * do not call ShutMeDown, it may make X calls which are not allowed + * in a signal hander. + * + * THIS IS NO LONGER A SIGNAL HANDLER - we may now shut down gracefully + * NOTE: ShutMeDown will now be called automatically by exit(). + */ + exit(1); } /****************************************************************************** WaitForExpose - Used to wait for expose event so we don't draw too early ******************************************************************************/ -void WaitForExpose(void) +void +WaitForExpose(void) { - XEvent Event; - - while(1) - { - /* - * Temporary solution to stop the process blocking - * in XNextEvent once we have been asked to quit. - * There is still a small race condition between - * checking the flag and calling the X-Server, but - * we can fix that ... - */ - if (isTerminated) - { - /* Just exit - the installed exit-procedure will clean up */ - exit(0); - } - /**/ - - XNextEvent(dpy,&Event); - if (Event.type==Expose) - { - if (Event.xexpose.count==0) break; - } - } + XEvent Event; + + while (1) { + if (isTerminated) { + exit(0); + } + + if (XCheckTypedEvent(dpy, Expose, &Event)) { + if (Event.xexpose.count == 0) + break; + } else if (isTerminated) { + exit(0); + } else { + XNextEvent(dpy, &Event); + if (Event.type == Expose) { + if (Event.xexpose.count == 0) + break; + } + } + } } /****************************************************************************** RedrawWindow - Update the needed lines and erase any old ones ******************************************************************************/ -void RedrawWindow(int force) +void +RedrawWindow(int force) { - DrawButtonArray(&buttons, force); - if (XQLength(dpy) && !force) LoopOnEvents(); + DrawButtonArray(&buttons, force); + if (XQLength(dpy) && !force) + LoopOnEvents(); } /****************************************************************************** ConsoleMessage - Print a message on the console. Works like printf. ******************************************************************************/ -void ConsoleMessage(const char *fmt, ...) +void +ConsoleMessage(const char *fmt, ...) { #ifndef NO_CONSOLE - va_list args; - FILE *filep; - - if (console==NULL) filep=stderr; - else filep=console; - va_start(args,fmt); - vfprintf(filep,fmt,args); - va_end(args); + va_list args; + FILE *filep; + + if (console == NULL) + filep = stderr; + else + filep = console; + va_start(args, fmt); + vfprintf(filep, fmt, args); + va_end(args); #endif } /****************************************************************************** OpenConsole - Open the console as a way of sending messages ******************************************************************************/ -int OpenConsole(void) +int +OpenConsole(void) { #ifndef NO_CONSOLE - if ((console=fopen("/dev/console","w"))==NULL) { - fprintf(stderr,"%s: cannot open console\n",Module); - return 0; - } + if ((console = fopen("/dev/console", "w")) == NULL) { + fprintf(stderr, "%s: cannot open console\n", Module); + return 0; + } #endif - return 1; + return 1; } /****************************************************************************** @@ -525,486 +548,536 @@ int OpenConsole(void) Based on part of main() from FvwmIdent: Copyright 1994, Robert Nation and Nobutaka Suzuki. ******************************************************************************/ -void ParseConfig(void) +void +ParseConfig(void) { - char *tline; - - GetConfigLine(Fvwm_fd,&tline); - while(tline != (char *)0) - { - if(strlen(tline)>1) - { - if(strncasecmp(tline, CatString3(Module, "Font",""),Clength+4)==0) - CopyString(&font_string,&tline[Clength+4]); - else if(strncasecmp(tline,CatString3(Module,"Fore",""), Clength+4)==0) - CopyString(&ForeColor[0],&tline[Clength+4]); - else if(strncasecmp(tline,CatString3(Module,"IconFore",""), Clength+8)==0) - CopyString(&ForeColor[1],&tline[Clength+8]); - else if(strncasecmp(tline,CatString3(Module,"FocusFore",""), Clength+9)==0) - { - CopyString(&ForeColor[2],&tline[Clength+9]); - CopyString(&ForeColor[3],&tline[Clength+9]); - } - else if(strncasecmp(tline,CatString3(Module, "Geometry",""), Clength+8)==0) - CopyString(&geometry,&tline[Clength+8]); - else if(strncasecmp(tline,CatString3(Module, "Back",""), Clength+4)==0) - CopyString(&BackColor[0],&tline[Clength+4]); - else if(strncasecmp(tline,CatString3(Module,"IconBack",""), Clength+8)==0) - CopyString(&BackColor[1],&tline[Clength+8]); - else if(strncasecmp(tline,CatString3(Module,"FocusBack",""), Clength+9)==0) - { - CopyString(&BackColor[2],&tline[Clength+9]); - CopyString(&BackColor[3],&tline[Clength+9]); - } - else if(strncasecmp(tline,CatString3(Module, "NoAnchor",""), - Clength+8)==0) Anchor=0; - else if(strncasecmp(tline,CatString3(Module, "Action",""), Clength+6)==0) - LinkAction(&tline[Clength+6]); - else if(strncasecmp(tline,CatString3(Module, "UseSkipList",""), - Clength+11)==0) UseSkipList=1; - else if(strncasecmp(tline,CatString3(Module, "UseIconNames",""), - Clength+12)==0) UseIconNames=1; - else if(strncasecmp(tline,CatString3(Module, "ShowCurrentDesk",""), - Clength+15)==0) ShowCurrentDesk=1; - else if(strncasecmp(tline,CatString3(Module, "LeftJustify",""), - Clength+11)==0) LeftJustify=1; - else if(strncasecmp(tline,CatString3(Module, "TruncateLeft",""), - Clength+12)==0) TruncateLeft=1; - else if(strncasecmp(tline,CatString3(Module, "MinWidth",""), - Clength+8)==0) MinWidth=atoi(&tline[Clength+8]); - else if(strncasecmp(tline,CatString3(Module, "MaxWidth",""), - Clength+8)==0) MaxWidth=atoi(&tline[Clength+8]); - else if(strncasecmp(tline,CatString3(Module, "DontDepressFocus",""), - Clength+16)==0) ShowFocus=0; + char *tline; + + GetConfigLine(Fvwm_fd, &tline); + while (tline != (char *)0) { + if (strlen(tline) > 1) { + if (strncasecmp(tline, CatString3(Module, "Font", ""), + Clength + 4) == 0) + CopyString(&font_string, &tline[Clength + 4]); + else if (strncasecmp(tline, + CatString3(Module, "Fore", ""), + Clength + 4) == 0) + CopyString(&ForeColor[0], &tline[Clength + 4]); + else if (strncasecmp(tline, + CatString3(Module, "IconFore", ""), + Clength + 8) == 0) + CopyString(&ForeColor[1], &tline[Clength + 8]); + else if (strncasecmp(tline, + CatString3(Module, "FocusFore", ""), + Clength + 9) == 0) { + CopyString(&ForeColor[2], &tline[Clength + 9]); + CopyString(&ForeColor[3], &tline[Clength + 9]); + } else if (strncasecmp(tline, + CatString3(Module, "Geometry", ""), + Clength + 8) == 0) + CopyString(&geometry, &tline[Clength + 8]); + else if (strncasecmp(tline, + CatString3(Module, "Back", ""), + Clength + 4) == 0) + CopyString(&BackColor[0], &tline[Clength + 4]); + else if (strncasecmp(tline, + CatString3(Module, "IconBack", ""), + Clength + 8) == 0) + CopyString(&BackColor[1], &tline[Clength + 8]); + else if (strncasecmp(tline, + CatString3(Module, "FocusBack", ""), + Clength + 9) == 0) { + CopyString(&BackColor[2], &tline[Clength + 9]); + CopyString(&BackColor[3], &tline[Clength + 9]); + } else if (strncasecmp(tline, + CatString3(Module, "NoAnchor", ""), + Clength + 8) == 0) + Anchor = 0; + else if (strncasecmp(tline, + CatString3(Module, "Action", ""), + Clength + 6) == 0) + LinkAction(&tline[Clength + 6]); + else if (strncasecmp(tline, + CatString3(Module, "UseSkipList", ""), + Clength + 11) == 0) + UseSkipList = 1; + else if (strncasecmp(tline, + CatString3(Module, "UseIconNames", ""), + Clength + 12) == 0) + UseIconNames = 1; + else if (strncasecmp(tline, + CatString3(Module, "ShowCurrentDesk", ""), + Clength + 15) == 0) + ShowCurrentDesk = 1; + else if (strncasecmp(tline, + CatString3(Module, "LeftJustify", ""), + Clength + 11) == 0) + LeftJustify = 1; + else if (strncasecmp(tline, + CatString3(Module, "TruncateLeft", ""), + Clength + 12) == 0) + TruncateLeft = 1; + else if (strncasecmp(tline, + CatString3(Module, "MinWidth", ""), + Clength + 8) == 0) + MinWidth = atoi(&tline[Clength + 8]); + else if (strncasecmp(tline, + CatString3(Module, "MaxWidth", ""), + Clength + 8) == 0) + MaxWidth = atoi(&tline[Clength + 8]); + else if (strncasecmp(tline, + CatString3(Module, "DontDepressFocus", ""), + Clength + 16) == 0) + ShowFocus = 0; + } + GetConfigLine(Fvwm_fd, &tline); } - GetConfigLine(Fvwm_fd,&tline); - } } /****************************************************************************** LoopOnEvents - Process all the X events we get ******************************************************************************/ -void LoopOnEvents(void) +void +LoopOnEvents(void) { - int num; - char buffer[10]; - XEvent Event; - Window dummyroot,dummychild; - int x,x1,y,y1; - unsigned int dummy1; - - if (Transient && !Checked) - { - XQueryPointer(dpy,win,&dummyroot,&dummychild,&x1,&y1,&x,&y,&dummy1); - num=WhichButton(&buttons,x,y); - if (num!=-1) - { - Pressed=1; - ButPressed=num; - SwitchButton(&buttons,num); - } else Pressed=0; - Checked=1; - } - - while(XPending(dpy)) - { - XNextEvent(dpy,&Event); - - switch(Event.type) - { - case ButtonRelease: - if (Pressed) - { - num=WhichButton(&buttons,Event.xbutton.x,Event.xbutton.y); - if (num!=-1) - { - SendFvwmPipe(ClickAction[(Transient) ? 0:Event.xbutton.button-1], - ItemID(&windows,num)); - SwitchButton(&buttons,num); - } - } - if (Transient) exit(0); - Pressed=0; - ButPressed=-1; - break; - case ButtonPress: - num=WhichButton(&buttons,Event.xbutton.x,Event.xbutton.y); - if (num != -1) - { - SwitchButton(&buttons,num); - ButPressed=num; - } else ButPressed=-1; - Pressed=1; - break; - case Expose: - if (Event.xexpose.count==0) - RedrawWindow(1); - break; - case KeyPress: - num=XLookupString(&Event.xkey,buffer,10,NULL,0); - if (num==1) - { - if (buffer[0]=='q' || buffer[0]=='Q') exit(0); - else if (buffer[0]=='i' || buffer[0]=='I') PrintList(&windows); - else if (buffer[0]=='b' || buffer[0]=='B') PrintButtons(&buttons); - } - break; - case ClientMessage: - if ((Event.xclient.format==32) && (Event.xclient.data.l[0]==wm_del_win)) - exit(0); - case EnterNotify: - if (!SomeButtonDown(Event.xcrossing.state)) break; - num=WhichButton(&buttons,Event.xcrossing.x,Event.xcrossing.y); - if (num!=-1) - { - SwitchButton(&buttons,num); - ButPressed=num; - } else ButPressed=-1; - Pressed=1; - break; - case LeaveNotify: - if (!SomeButtonDown(Event.xcrossing.state)) break; - if (ButPressed!=-1) SwitchButton(&buttons,ButPressed); - Pressed=0; - break; - case MotionNotify: - if (!Pressed) break; - num=WhichButton(&buttons,Event.xmotion.x,Event.xmotion.y); - if (num==ButPressed) break; - if (ButPressed!=-1) SwitchButton(&buttons,ButPressed); - if (num!=-1) - { - SwitchButton(&buttons,num); - ButPressed=num; - } - else ButPressed=-1; - - break; - } - } -} + int num; + char buffer[10]; + XEvent Event; + Window dummyroot, dummychild; + int x, x1, y, y1; + unsigned int dummy1; + + if (Transient && !Checked) { + XQueryPointer(dpy, win, &dummyroot, &dummychild, &x1, &y1, &x, + &y, &dummy1); + num = WhichButton(&buttons, x, y); + if (num != -1) { + Pressed = 1; + ButPressed = num; + SwitchButton(&buttons, num); + } else + Pressed = 0; + Checked = 1; + } + while (XPending(dpy)) { + XNextEvent(dpy, &Event); + + switch (Event.type) { + case ButtonRelease: + if (Pressed) { + num = WhichButton( + &buttons, Event.xbutton.x, Event.xbutton.y); + if (num != -1) { + SendFvwmPipe( + ClickAction[(Transient) ? + 0 : + Event.xbutton + .button - + 1], + ItemID(&windows, num)); + SwitchButton(&buttons, num); + } + } + if (Transient) + exit(0); + Pressed = 0; + ButPressed = -1; + break; + case ButtonPress: + num = WhichButton( + &buttons, Event.xbutton.x, Event.xbutton.y); + if (num != -1) { + SwitchButton(&buttons, num); + ButPressed = num; + } else + ButPressed = -1; + Pressed = 1; + break; + case Expose: + if (Event.xexpose.count == 0) + RedrawWindow(1); + break; + case KeyPress: + num = XLookupString(&Event.xkey, buffer, 10, NULL, 0); + if (num == 1) { + if (buffer[0] == 'q' || buffer[0] == 'Q') + exit(0); + else if (buffer[0] == 'i' || buffer[0] == 'I') + PrintList(&windows); + else if (buffer[0] == 'b' || buffer[0] == 'B') + PrintButtons(&buttons); + } + break; + case ClientMessage: + if ((Event.xclient.format == 32) && + (Event.xclient.data.l[0] == wm_del_win)) + exit(0); + case EnterNotify: + if (!SomeButtonDown(Event.xcrossing.state)) + break; + num = WhichButton( + &buttons, Event.xcrossing.x, Event.xcrossing.y); + if (num != -1) { + SwitchButton(&buttons, num); + ButPressed = num; + } else + ButPressed = -1; + Pressed = 1; + break; + case LeaveNotify: + if (!SomeButtonDown(Event.xcrossing.state)) + break; + if (ButPressed != -1) + SwitchButton(&buttons, ButPressed); + Pressed = 0; + break; + case MotionNotify: + if (!Pressed) + break; + num = WhichButton( + &buttons, Event.xmotion.x, Event.xmotion.y); + if (num == ButPressed) + break; + if (ButPressed != -1) + SwitchButton(&buttons, ButPressed); + if (num != -1) { + SwitchButton(&buttons, num); + ButPressed = num; + } else + ButPressed = -1; + + break; + } + } +} /****************************************************************************** find_frame_window - looks for ancestor that is a child of the root Cribbed from FvwmIconMan/x.c - maybe should be in a library Returns the root-child and fills in off_x, off_y to give offset ******************************************************************************/ -Window find_frame_window (Window win, int *off_x, int *off_y) +Window +find_frame_window(Window win, int *off_x, int *off_y) { - Window root, parent, *junkw; - int junki; - XWindowAttributes attr; - - while (1) { - XQueryTree (dpy, win, &root, &parent, &junkw, &junki); - if (junkw) - XFree (junkw); - if (parent == root) - break; - XGetWindowAttributes (dpy, win, &attr); - *off_x += attr.x + attr.border_width; - *off_y += attr.y + attr.border_width; - win = parent; - } - - return win; + Window root, parent, *junkw; + int junki; + XWindowAttributes attr; + + while (1) { + junkw = NULL; + if (XQueryTree(dpy, win, &root, &parent, &junkw, &junki) && + junkw) + XFree(junkw); + if (parent == root) + break; + XGetWindowAttributes(dpy, win, &attr); + *off_x += attr.x + attr.border_width; + *off_y += attr.y + attr.border_width; + win = parent; + } + + return win; } /****************************************************************************** AdjustWindow - Resize the window according to maxwidth by number of buttons ******************************************************************************/ -void AdjustWindow(void) +void +AdjustWindow(void) { - int new_width=0,new_height=0,tw,i,total,off_x,off_y; - char *temp; - Window frame; - XWindowAttributes win_attr, frame_attr; - - total = ItemCountD(&windows ); - if (!total) - { - if (WindowIsUp==1) - { - XUnmapWindow(dpy,win); - WindowIsUp=2; - } - return; - } - for(i=0;i0) win_height = new_height; - if (new_width>0) win_width = new_width; - if (WindowIsUp==2) - { - XMapWindow(dpy,win); - WindowIsUp=1; - WaitForExpose(); - } + new_width = max(new_width, tw); + } + } + new_width = max(new_width, MinWidth); + new_width = min(new_width, MaxWidth); + new_height = (total * (fontheight + 6 + 1)); + if (WindowIsUp && + (new_height != win_height || new_width != win_width)) { + if (Anchor) { + off_x = off_y = 0; + MyXGrabServer(dpy); + frame = find_frame_window(win, &off_x, &off_y); + XGetWindowAttributes(dpy, frame, &frame_attr); + XGetWindowAttributes(dpy, win, &win_attr); + win_x = frame_attr.x + frame_attr.border_width + off_x; + win_y = frame_attr.y + frame_attr.border_width + off_y; + + if (win_grav == SouthEastGravity || + win_grav == NorthEastGravity) + win_x += win_attr.width - new_width; + if (win_grav == SouthEastGravity || + win_grav == SouthWestGravity) + win_y += win_attr.height - new_height; + + XMoveResizeWindow( + dpy, win, win_x, win_y, new_width, new_height); + MyXUngrabServer(dpy); + } else + XResizeWindow(dpy, win, new_width, new_height); + } + UpdateArray(&buttons, -1, -1, new_width, -1); + if (new_height > 0) + win_height = new_height; + if (new_width > 0) + win_width = new_width; + if (WindowIsUp == 2) { + XMapWindow(dpy, win); + WindowIsUp = 1; + WaitForExpose(); + } } /****************************************************************************** makename - Based on the flags return me '(name)' or 'name' ******************************************************************************/ -char *makename(const char *string,long flags) +char * +makename(const char *string, long flags) { -char *ptr; - ptr=safemalloc(strlen(string)+3); - *ptr = '\0'; - if (flags&ICONIFIED) strcpy(ptr,"("); - strcat(ptr,string); - if (flags&ICONIFIED) strcat(ptr,")"); - return ptr; + char *ptr; + size_t name_len = strlen(string); + size_t extra = (flags & ICONIFIED) ? 2 : 1; + ptr = xmalloc(name_len + extra); + ptr[0] = '\0'; + if (flags & ICONIFIED) + strlcpy(ptr, "(", name_len + extra); + strlcat(ptr, string, name_len + extra); + if (flags & ICONIFIED) + strlcat(ptr, ")", name_len + extra); + return ptr; } /****************************************************************************** LinkAction - Link an response to a users action ******************************************************************************/ -void LinkAction(char *string) +void +LinkAction(char *string) { -char *temp; - temp=string; - while(isspace(*temp)) temp++; - if(strncasecmp(temp, "Click1", 6)==0) - CopyString(&ClickAction[0],&temp[6]); - else if(strncasecmp(temp, "Click2", 6)==0) - CopyString(&ClickAction[1],&temp[6]); - else if(strncasecmp(temp, "Click3", 6)==0) - CopyString(&ClickAction[2],&temp[6]); - else if(strncasecmp(temp, "Enter", 5)==0) - CopyString(&EnterAction,&temp[5]); + char *temp; + temp = string; + while (isspace(*temp)) + temp++; + if (strncasecmp(temp, "Click1", 6) == 0) + CopyString(&ClickAction[0], &temp[6]); + else if (strncasecmp(temp, "Click2", 6) == 0) + CopyString(&ClickAction[1], &temp[6]); + else if (strncasecmp(temp, "Click3", 6) == 0) + CopyString(&ClickAction[2], &temp[6]); + else if (strncasecmp(temp, "Enter", 5) == 0) + CopyString(&EnterAction, &temp[5]); } /****************************************************************************** MakeMeWindow - Create and setup the window we will need ******************************************************************************/ -void MakeMeWindow(void) +void +MakeMeWindow(void) { - XSizeHints hints; - XGCValues gcval; - unsigned long gcmask; - unsigned int dummy1, dummy2; - int x, y, ret, count; - Window dummyroot, dummychild; - int i; - - - if ((count = ItemCountD(&windows))==0 && Transient) exit(0); - AdjustWindow(); - - hints.width=win_width; - hints.height=win_height; - hints.win_gravity=NorthWestGravity; - hints.flags=PSize|PWinGravity|PResizeInc; - hints.width_inc=0; - hints.height_inc=0; - - if (geometry!= NULL) - { - ret=XParseGeometry(geometry,&x,&y,&dummy1,&dummy2); - - if (ret&XValue && ret &YValue) - { - hints.x=x; - if (ret&XNegative) - hints.x+=XDisplayWidth(dpy,screen)-win_width; - - hints.y=y; - if (ret&YNegative) - hints.y+=XDisplayHeight(dpy,screen)-win_height; - - hints.flags|=USPosition; - } - - if (ret&XNegative) - { - if (ret&YNegative) hints.win_gravity=SouthEastGravity; - else hints.win_gravity=NorthEastGravity; - } - else - { - if (ret&YNegative) hints.win_gravity=SouthWestGravity; - else hints.win_gravity=NorthWestGravity; - } - - } - - if (Transient) - { - XQueryPointer(dpy,Root,&dummyroot,&dummychild,&hints.x,&hints.y,&x,&y,&dummy1); - hints.win_gravity=NorthWestGravity; - hints.flags |= USPosition; - } - win_grav=hints.win_gravity; - win_x=hints.x; - win_y=hints.y; - - - for (i = 0; i != MAX_COLOUR_SETS; i++) - if(d_depth < 2) - { - back[i] = GetColor("white"); - fore[i] = GetColor("black"); - } - else - { - back[i] = GetColor(BackColor[i] == NULL ? BackColor[0] : BackColor[i]); - fore[i] = GetColor(ForeColor[i] == NULL ? ForeColor[0] : ForeColor[i]); - } - - win=XCreateSimpleWindow(dpy,Root,hints.x,hints.y,hints.width,hints.height,0, - fore[0],back[0]); - - wm_del_win=XInternAtom(dpy,"WM_DELETE_WINDOW",False); - XSetWMProtocols(dpy,win,&wm_del_win,1); - - XSetWMNormalHints(dpy,win,&hints); - - if (!Transient) - { - XGrabButton(dpy,1,AnyModifier,win,True,GRAB_EVENTS,GrabModeAsync, - GrabModeAsync,None,None); - XGrabButton(dpy,2,AnyModifier,win,True,GRAB_EVENTS,GrabModeAsync, - GrabModeAsync,None,None); - XGrabButton(dpy,3,AnyModifier,win,True,GRAB_EVENTS,GrabModeAsync, - GrabModeAsync,None,None); - SetMwmHints(MWM_DECOR_ALL|MWM_DECOR_RESIZEH|MWM_DECOR_MAXIMIZE|MWM_DECOR_MINIMIZE, - MWM_FUNC_ALL|MWM_FUNC_RESIZE|MWM_FUNC_MAXIMIZE|MWM_FUNC_MINIMIZE, - MWM_INPUT_MODELESS); - } - else - { - SetMwmHints(0,MWM_FUNC_ALL,MWM_INPUT_MODELESS); - } - - for (i = 0; i != MAX_COLOUR_SETS; i++) - { - gcval.foreground=fore[i]; - gcval.background=back[i]; - gcval.font=ButtonFont->fid; - gcmask=GCForeground|GCBackground|GCFont; - graph[i]=XCreateGC(dpy,Root,gcmask,&gcval); - - if(d_depth < 2) - gcval.foreground=GetShadow(fore[i]); - else - gcval.foreground=GetShadow(back[i]); - gcval.background=back[i]; - gcmask=GCForeground|GCBackground; - shadow[i]=XCreateGC(dpy,Root,gcmask,&gcval); - - gcval.foreground=GetHilite(back[i]); - gcval.background=back[i]; - gcmask=GCForeground|GCBackground; - hilite[i]=XCreateGC(dpy,Root,gcmask,&gcval); - - gcval.foreground=back[i]; - gcmask=GCForeground; - background[i]=XCreateGC(dpy,Root,gcmask,&gcval); - } - - XSelectInput(dpy,win,(ExposureMask | KeyPressMask)); - - ChangeWindowName(&Module[1]); - - if (ItemCountD(&windows) > 0) - { - XMapRaised(dpy,win); - WaitForExpose(); - WindowIsUp=1; - } else WindowIsUp=2; - - if (Transient) - { - if ( XGrabPointer(dpy,win,True,GRAB_EVENTS,GrabModeAsync,GrabModeAsync, - None,None,CurrentTime)!=GrabSuccess) exit(1); - XQueryPointer(dpy,Root,&dummyroot,&dummychild,&hints.x,&hints.y,&x,&y,&dummy1); - if (!SomeButtonDown(dummy1)) exit(0); - } + XSizeHints hints; + XGCValues gcval; + unsigned long gcmask; + unsigned int dummy1, dummy2; + int x, y, ret, count; + Window dummyroot, dummychild; + int i; + + if ((count = ItemCountD(&windows)) == 0 && Transient) + exit(0); + AdjustWindow(); + + hints.width = win_width; + hints.height = win_height; + hints.win_gravity = NorthWestGravity; + hints.flags = PSize | PWinGravity | PResizeInc; + hints.width_inc = 0; + hints.height_inc = 0; + + if (geometry != NULL) { + ret = XParseGeometry(geometry, &x, &y, &dummy1, &dummy2); + + if (ret & XValue && ret & YValue) { + hints.x = x; + if (ret & XNegative) + hints.x += + XDisplayWidth(dpy, screen) - win_width; + + hints.y = y; + if (ret & YNegative) + hints.y += + XDisplayHeight(dpy, screen) - win_height; + + hints.flags |= USPosition; + } + + if (ret & XNegative) { + if (ret & YNegative) + hints.win_gravity = SouthEastGravity; + else + hints.win_gravity = NorthEastGravity; + } else { + if (ret & YNegative) + hints.win_gravity = SouthWestGravity; + else + hints.win_gravity = NorthWestGravity; + } + } + if (Transient) { + XQueryPointer(dpy, Root, &dummyroot, &dummychild, &hints.x, + &hints.y, &x, &y, &dummy1); + hints.win_gravity = NorthWestGravity; + hints.flags |= USPosition; + } + win_grav = hints.win_gravity; + win_x = hints.x; + win_y = hints.y; + + for (i = 0; i != MAX_COLOUR_SETS; i++) + if (d_depth < 2) { + back[i] = GetColor("white"); + fore[i] = GetColor("black"); + } else { + back[i] = GetColor( + BackColor[i] == NULL ? BackColor[0] : BackColor[i]); + fore[i] = GetColor( + ForeColor[i] == NULL ? ForeColor[0] : ForeColor[i]); + } + + win = XCreateSimpleWindow(dpy, Root, hints.x, hints.y, hints.width, + hints.height, 0, fore[0], back[0]); + + wm_del_win = XInternAtom(dpy, "WM_DELETE_WINDOW", False); + XSetWMProtocols(dpy, win, &wm_del_win, 1); + + XSetWMNormalHints(dpy, win, &hints); + + if (!Transient) { + XGrabButton(dpy, 1, AnyModifier, win, True, GRAB_EVENTS, + GrabModeAsync, GrabModeAsync, None, None); + XGrabButton(dpy, 2, AnyModifier, win, True, GRAB_EVENTS, + GrabModeAsync, GrabModeAsync, None, None); + XGrabButton(dpy, 3, AnyModifier, win, True, GRAB_EVENTS, + GrabModeAsync, GrabModeAsync, None, None); + SetMwmHints(MWM_DECOR_ALL | MWM_DECOR_RESIZEH | + MWM_DECOR_MAXIMIZE | MWM_DECOR_MINIMIZE, + MWM_FUNC_ALL | MWM_FUNC_RESIZE | MWM_FUNC_MAXIMIZE | + MWM_FUNC_MINIMIZE, + MWM_INPUT_MODELESS); + } else { + SetMwmHints(0, MWM_FUNC_ALL, MWM_INPUT_MODELESS); + } + + for (i = 0; i != MAX_COLOUR_SETS; i++) { + gcval.foreground = fore[i]; + gcval.background = back[i]; + gcval.font = ButtonFont->fid; + gcmask = GCForeground | GCBackground | GCFont; + graph[i] = XCreateGC(dpy, Root, gcmask, &gcval); + + if (d_depth < 2) + gcval.foreground = GetShadow(fore[i]); + else + gcval.foreground = GetShadow(back[i]); + gcval.background = back[i]; + gcmask = GCForeground | GCBackground; + shadow[i] = XCreateGC(dpy, Root, gcmask, &gcval); + + gcval.foreground = GetHilite(back[i]); + gcval.background = back[i]; + gcmask = GCForeground | GCBackground; + hilite[i] = XCreateGC(dpy, Root, gcmask, &gcval); + + gcval.foreground = back[i]; + gcmask = GCForeground; + background[i] = XCreateGC(dpy, Root, gcmask, &gcval); + } + + XSelectInput(dpy, win, (ExposureMask | KeyPressMask)); + + ChangeWindowName(&Module[1]); + + if (ItemCountD(&windows) > 0) { + XMapRaised(dpy, win); + WaitForExpose(); + WindowIsUp = 1; + } else + WindowIsUp = 2; + + if (Transient) { + if (XGrabPointer(dpy, win, True, GRAB_EVENTS, GrabModeAsync, + GrabModeAsync, None, None, CurrentTime) != GrabSuccess) + exit(1); + XQueryPointer(dpy, Root, &dummyroot, &dummychild, &hints.x, + &hints.y, &x, &y, &dummy1); + if (!SomeButtonDown(dummy1)) + exit(0); + } } /****************************************************************************** StartMeUp - Do X initialization things ******************************************************************************/ -void StartMeUp(void) +void +StartMeUp(void) { - if (!(dpy = XOpenDisplay(""))) - { - fprintf(stderr,"%s: can't open display %s", Module, - XDisplayName("")); - exit (1); - } - x_fd = XConnectionNumber(dpy); - screen= DefaultScreen(dpy); - Root = RootWindow(dpy, screen); - d_depth = DefaultDepth(dpy, screen); - - ScreenHeight = DisplayHeight(dpy,screen); - ScreenWidth = DisplayWidth(dpy,screen); + if (!(dpy = XOpenDisplay(""))) { + fprintf(stderr, "%s: can't open display %s", Module, + XDisplayName("")); + exit(1); + } + x_fd = XConnectionNumber(dpy); + screen = DefaultScreen(dpy); + Root = RootWindow(dpy, screen); + d_depth = DefaultDepth(dpy, screen); - if ((ButtonFont=XLoadQueryFont(dpy,font_string))==NULL) - { - if ((ButtonFont=XLoadQueryFont(dpy,"fixed"))==NULL) exit(1); - } + ScreenHeight = DisplayHeight(dpy, screen); + ScreenWidth = DisplayWidth(dpy, screen); - fontheight = ButtonFont->ascent+ButtonFont->descent; + if ((ButtonFont = XLoadQueryFont(dpy, font_string)) == NULL) { + if ((ButtonFont = XLoadQueryFont(dpy, "fixed")) == NULL) + exit(1); + } - win_width=XTextWidth(ButtonFont,"XXXXXXXXXXXXXXX",10); + fontheight = ButtonFont->ascent + ButtonFont->descent; + win_width = XTextWidth(ButtonFont, "XXXXXXXXXXXXXXX", 10); } /****************************************************************************** ShutMeDown - Do X client cleanup ******************************************************************************/ -void ShutMeDown(void) +void +ShutMeDown(void) { - FreeList(&windows); - FreeAllButtons(&buttons); -/* XFreeGC(dpy,graph);*/ - if (WindowIsUp) XDestroyWindow(dpy,win); - XCloseDisplay(dpy); + FreeList(&windows); + FreeAllButtons(&buttons); + /* XFreeGC(dpy,graph);*/ + if (WindowIsUp) + XDestroyWindow(dpy, win); + XCloseDisplay(dpy); } /****************************************************************************** @@ -1012,16 +1085,17 @@ void ShutMeDown(void) Original work from FvwmIdent: Copyright 1994, Robert Nation and Nobutaka Suzuki. ******************************************************************************/ -void ChangeWindowName(char *str) +void +ChangeWindowName(char *str) { -XTextProperty name; - if (XStringListToTextProperty(&str,1,&name) == 0) { - fprintf(stderr,"%s: cannot allocate window name.\n",Module); - return; - } - XSetWMName(dpy,win,&name); - XSetWMIconName(dpy,win,&name); - XFree(name.value); + XTextProperty name; + if (XStringListToTextProperty(&str, 1, &name) == 0) { + fprintf(stderr, "%s: cannot allocate window name.\n", Module); + return; + } + XSetWMName(dpy, win, &name); + XSetWMIconName(dpy, win, &name); + XFree(name.value); } /************************************************************************** @@ -1035,42 +1109,39 @@ XTextProperty name; * Never check for MWM_RUNNING property.May be considered bad. */ -void SetMwmHints(unsigned int value, unsigned int funcs, unsigned int input) +void +SetMwmHints(unsigned int value, unsigned int funcs, unsigned int input) { -PropMwmHints prop; - - if (MwmAtom==None) - { - MwmAtom=XInternAtom(dpy,"_MOTIF_WM_HINTS",False); - } - if (MwmAtom!=None) - { - /* sh->mwm.decorations contains OR of the MWM_DECOR_XXXXX */ - prop.decorations= value; - prop.functions = funcs; - prop.inputMode = input; - prop.flags = MWM_HINTS_DECORATIONS| MWM_HINTS_FUNCTIONS | MWM_HINTS_INPUT_MODE; - - /* HOP - LA! */ - XChangeProperty (dpy,win, - MwmAtom, MwmAtom, - 32, PropModeReplace, - (unsigned char *)&prop, - PROP_MWM_HINTS_ELEMENTS); - } + PropMwmHints prop; + + if (MwmAtom == None) { + MwmAtom = XInternAtom(dpy, "_MOTIF_WM_HINTS", False); + } + if (MwmAtom != None) { + /* sh->mwm.decorations contains OR of the MWM_DECOR_XXXXX */ + prop.decorations = value; + prop.functions = funcs; + prop.inputMode = input; + prop.flags = MWM_HINTS_DECORATIONS | MWM_HINTS_FUNCTIONS | + MWM_HINTS_INPUT_MODE; + + /* HOP - LA! */ + XChangeProperty(dpy, win, MwmAtom, MwmAtom, 32, PropModeReplace, + (unsigned char *)&prop, PROP_MWM_HINTS_ELEMENTS); + } } /************************************************************************ X Error Handler ************************************************************************/ -int ErrorHandler(Display *d, XErrorEvent *event) +int +ErrorHandler(Display *d, XErrorEvent *event) { - char errmsg[256]; - - XGetErrorText(d, event->error_code, errmsg, sizeof(errmsg)); - ConsoleMessage("%s failed request: %s\n", Module, errmsg); - ConsoleMessage("Major opcode: 0x%x, resource id: 0x%x\n", - event->request_code, (unsigned int)event->resourceid); - return 0; -} + char errmsg[256]; + XGetErrorText(d, event->error_code, errmsg, sizeof(errmsg)); + ConsoleMessage("%s failed request: %s\n", Module, errmsg); + ConsoleMessage("Major opcode: 0x%x, resource id: 0x%x\n", + event->request_code, (unsigned int)event->resourceid); + return 0; +} Index: fvwm/modules/FvwmWinList/FvwmWinList.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmWinList/FvwmWinList.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmWinList/FvwmWinList.h --- fvwm/modules/FvwmWinList/FvwmWinList.h +++ fvwm/modules/FvwmWinList/FvwmWinList.h @@ -1,6 +1,11 @@ -#include "fvwmlib.h" +#ifndef FVWM_WINLIST_H +#define FVWM_WINLIST_H -/* FvwmWinList Module for Fvwm. +#include + +#include "fvwmlib.h" + +/* FvwmWinList Module for Fvwm. * * Copyright 1994, Mike Finger (mfinger@mermaid.micro.umn.edu or * Mike_Finger@atk.com) @@ -20,55 +25,54 @@ * own risk. Permission to use this program for any purpose is given, * as long as the copyright is kept intact. */ -#define STICKY (1<<2) /* Does window stick to glass? */ -#define ONTOP (1<<1) /* does window stay on top */ -#define BORDER (1<<13) /* Is this decorated with border*/ -#define TITLE (1<<14) /* Is this decorated with title */ -#define ICONIFIED (1<<16) /* is it an icon now? */ -#define TRANSIENT (1<<17) /* is it a transient window? */ -#define WINDOWLISTSKIP (1<<3) +#define STICKY (1 << 2) /* Does window stick to glass? */ +#define ONTOP (1 << 1) /* does window stay on top */ +#define BORDER (1 << 13) /* Is this decorated with border*/ +#define TITLE (1 << 14) /* Is this decorated with title */ +#define ICONIFIED (1 << 16) /* is it an icon now? */ +#define TRANSIENT (1 << 17) /* is it a transient window? */ +#define WINDOWLISTSKIP (1 << 3) /* Motif window hints */ -typedef struct -{ - CARD32 flags; - CARD32 functions; - CARD32 decorations; - INT32 inputMode; +typedef struct { + CARD32 flags; + CARD32 functions; + CARD32 decorations; + INT32 inputMode; } PropMotifWmHints; -typedef PropMotifWmHints PropMwmHints; +typedef PropMotifWmHints PropMwmHints; /* Motif window hints */ -#define MWM_HINTS_FUNCTIONS (1L << 0) -#define MWM_HINTS_DECORATIONS (1L << 1) -#define MWM_HINTS_INPUT_MODE (1L << 2) +#define MWM_HINTS_FUNCTIONS (1L << 0) +#define MWM_HINTS_DECORATIONS (1L << 1) +#define MWM_HINTS_INPUT_MODE (1L << 2) /* bit definitions for MwmHints.functions */ -#define MWM_FUNC_ALL (1L << 0) -#define MWM_FUNC_RESIZE (1L << 1) -#define MWM_FUNC_MOVE (1L << 2) -#define MWM_FUNC_MINIMIZE (1L << 3) -#define MWM_FUNC_MAXIMIZE (1L << 4) -#define MWM_FUNC_CLOSE (1L << 5) +#define MWM_FUNC_ALL (1L << 0) +#define MWM_FUNC_RESIZE (1L << 1) +#define MWM_FUNC_MOVE (1L << 2) +#define MWM_FUNC_MINIMIZE (1L << 3) +#define MWM_FUNC_MAXIMIZE (1L << 4) +#define MWM_FUNC_CLOSE (1L << 5) /* values for MwmHints.input_mode */ -#define MWM_INPUT_MODELESS 0 -#define MWM_INPUT_PRIMARY_APPLICATION_MODAL 1 -#define MWM_INPUT_SYSTEM_MODAL 2 -#define MWM_INPUT_FULL_APPLICATION_MODAL 3 +#define MWM_INPUT_MODELESS 0 +#define MWM_INPUT_PRIMARY_APPLICATION_MODAL 1 +#define MWM_INPUT_SYSTEM_MODAL 2 +#define MWM_INPUT_FULL_APPLICATION_MODAL 3 /* bit definitions for MwmHints.decorations */ -#define MWM_DECOR_ALL (1L << 0) -#define MWM_DECOR_BORDER (1L << 1) -#define MWM_DECOR_RESIZEH (1L << 2) -#define MWM_DECOR_TITLE (1L << 3) -#define MWM_DECOR_MENU (1L << 4) -#define MWM_DECOR_MINIMIZE (1L << 5) -#define MWM_DECOR_MAXIMIZE (1L << 6) +#define MWM_DECOR_ALL (1L << 0) +#define MWM_DECOR_BORDER (1L << 1) +#define MWM_DECOR_RESIZEH (1L << 2) +#define MWM_DECOR_TITLE (1L << 3) +#define MWM_DECOR_MENU (1L << 4) +#define MWM_DECOR_MINIMIZE (1L << 5) +#define MWM_DECOR_MAXIMIZE (1L << 6) -#define PROP_MOTIF_WM_HINTS_ELEMENTS 4 -#define PROP_MWM_HINTS_ELEMENTS PROP_MOTIF_WM_HINTS_ELEMENTS +#define PROP_MOTIF_WM_HINTS_ELEMENTS 4 +#define PROP_MWM_HINTS_ELEMENTS PROP_MOTIF_WM_HINTS_ELEMENTS /* default values for configuration parameters */ #define DEFMAXWIDTH 10000 @@ -79,26 +83,28 @@ typedef PropMotifWmHints PropMwmHints; **************************************************************************/ void MainEventLoop(void); void ReadFvwmPipe(void); -void ProcessMessage(unsigned long type,unsigned long *body); -void SendFvwmPipe(char *message,unsigned long window); +void ProcessMessage(unsigned long type, unsigned long *body); +void SendFvwmPipe(char *message, unsigned long window); void DeadPipe(int nonsense) __attribute__((noreturn)); void MakeMeWindow(void); void WaitForExpose(void); void RedrawWindow(int force); void StartMeUp(void); void ShutMeDown(void); -void ConsoleMessage(const char *fmt,...) __attribute__((format(printf,1,2))); +void ConsoleMessage(const char *fmt, ...) __attribute__((format(printf, 1, 2))); int OpenConsole(void); void ParseConfig(void); void LoopOnEvents(void); void AdjustWindow(void); -char *makename(const char *string,long flags); +char *makename(const char *string, long flags); void ChangeWindowName(char *str); void LinkAction(char *string); void AddToSkipList(char *string); int InSkipList(char *string); void PrintSkipList(void); void FvwmNameMessage(long *body); -void SetMwmHints(unsigned int value,unsigned int funcs,unsigned int input); +void SetMwmHints(unsigned int value, unsigned int funcs, unsigned int input); int ErrorHandler(Display *d, XErrorEvent *event); + +#endif /* FVWM_WINLIST_H */ Index: fvwm/modules/FvwmWinList/List.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmWinList/List.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmWinList/List.c --- fvwm/modules/FvwmWinList/List.c +++ fvwm/modules/FvwmWinList/List.c @@ -1,325 +1,388 @@ -/* FvwmWinList Module for Fvwm. +/* FvwmWinList Module for Fvwm. * * Copyright 1994, Mike Finger (mfinger@mermaid.micro.umn.edu or * Mike_Finger@atk.com) * * The functions in this source file are the original work of Mike Finger. - * + * * No guarantees or warantees or anything are provided or implied in any way * whatsoever. Use this program at your own risk. Permission to use this * program for any purpose is given, as long as the copyright is kept intact. * - * Things to do: Convert to C++ (In Progress) */ -#include "config.h" -#include -#include #include "List.h" -#include "Mallocs.h" -#include "../../fvwm/module.h" #include +#include +#include + +#include "../../fvwm/module.h" #include "FvwmWinList.h" +#include "config.h" + +static void +UpdateString(char **string, char *value) +{ + size_t value_len; + + if (value == NULL) + return; + value_len = strlen(value); + if (*string == NULL) + *string = xmalloc(value_len + 1); + else + *string = xrealloc(*string, value_len + 1); + strlcpy(*string, value, value_len + 1); +} /****************************************************************************** InitList - Initialize the list ******************************************************************************/ -void InitList(List *list) +void +InitList(List *list) { - list->head=list->tail=NULL; - list->count=0; + list->head = list->tail = NULL; + list->count = 0; } /****************************************************************************** AddItem - Allocates spaces for and appends an item to the list ******************************************************************************/ -void AddItem(List *list, long id,long flags, long desk) +void +AddItem(List *list, long id, long flags, long desk) { -Item *new; - new=(Item *)safemalloc(sizeof(Item)); - new->id=id; - new->name=NULL; - new->flags=flags; - new->desk=desk; - new->next=NULL; - - if (list->tail==NULL) list->head=list->tail=new; - else { - list->tail->next=new; - list->tail=new; - } - list->count++; + Item *new; + new = (Item *)xmalloc(sizeof(Item)); + new->id = id; + new->name = NULL; + new->flags = flags; + new->desk = desk; + new->next = NULL; + + if (list->tail == NULL) + list->head = list->tail = new; + else { + list->tail->next = new; + list->tail = new; + } + list->count++; } /****************************************************************************** FindItem - Find the item in the list matching the id ******************************************************************************/ -int FindItem(List *list, long id) +int +FindItem(List *list, long id) { - Item *temp; - int i; - - for(i=0,temp=list->head;temp!=NULL && temp->id!=id;i++,temp=temp->next); - if (temp==NULL) return -1; - return i; + Item *temp; + int i; + + for (i = 0, temp = list->head; temp != NULL && temp->id != id; + i++, temp = temp->next) + ; + if (temp == NULL) + return -1; + return i; } - + /****************************************************************************** FindItemDesk - Find the item in the list matching the id, and desk id ******************************************************************************/ -int FindItemDesk(List *list, long id, long desk) +int +FindItemDesk(List *list, long id, long desk) { - Item *temp; - int i; - - for(i=0,temp=list->head;temp!=NULL && (temp->id!=id || temp->desk != desk) ;i++,temp=temp->next); - if (temp==NULL) return -1; - return i; + Item *temp; + int i; + + for (i = 0, temp = list->head; + temp != NULL && (temp->id != id || temp->desk != desk); + i++, temp = temp->next) + ; + if (temp == NULL) + return -1; + return i; } - /****************************************************************************** UpdateItem - Update the item in the list, setting name & flags as necessary. ******************************************************************************/ -int UpdateItemName(List *list, long id, char *string) +int +UpdateItemName(List *list, long id, char *string) { - Item *temp; - int i; - - for(i=0,temp=list->head;temp!=NULL && id!=temp->id;i++,temp=temp->next); - if (temp==NULL) return -1; - UpdateString(&temp->name, string); - return i; + Item *temp; + int i; + + for (i = 0, temp = list->head; temp != NULL && id != temp->id; + i++, temp = temp->next) + ; + if (temp == NULL) + return -1; + UpdateString(&temp->name, string); + return i; } /****************************************************************************** UpdateItemDesk - Update the item in the list, setting desk as necessary. - returns 1 if desk was updated, - returns 0, if not changed + returns 1 if desk was updated, + returns 0, if not changed returns -1 if not found ******************************************************************************/ -int UpdateItemDesk(List *list, long id, long desk) +int +UpdateItemDesk(List *list, long id, long desk) { - Item *temp; - int i; - - for(i=0,temp=list->head;temp != NULL && temp->id != id ;i++,temp=temp->next); -/* printf("sk=%ld %ld \n", id, temp->id); -*/ - if (temp ==NULL ) return -1; - -/* printf("dsk=%d\n", temp->desk); -*/ - if(temp->desk != desk) - { -/* printf("got a nonmatch\n"); -*/ - temp->desk = desk; - return 1; - } - - return 0; + Item *temp; + int i; + + for (i = 0, temp = list->head; temp != NULL && temp->id != id; + i++, temp = temp->next) + ; + /* printf("sk=%ld %ld \n", id, temp->id); + */ + if (temp == NULL) + return -1; + + /* printf("dsk=%d\n", temp->desk); + */ + if (temp->desk != desk) { + /* printf("got a nonmatch\n"); + */ + temp->desk = desk; + return 1; + } + + return 0; } -int UpdateItemFlags(List *list, long id, long flags) +int +UpdateItemFlags(List *list, long id, long flags) { -Item *temp; -int i; - for(i=0,temp=list->head;temp!=NULL && id!=temp->id;i++,temp=temp->next); - if (temp==NULL) return -1; - if (flags!=-1) temp->flags=flags; - return i; + Item *temp; + int i; + for (i = 0, temp = list->head; temp != NULL && id != temp->id; + i++, temp = temp->next) + ; + if (temp == NULL) + return -1; + if (flags != -1) + temp->flags = flags; + return i; } - + /****************************************************************************** FreeItem - Frees allocated space for an Item ******************************************************************************/ -void FreeItem(Item *ptr) +void +FreeItem(Item *ptr) { - if (ptr != NULL) { - if (ptr->name!=NULL) free(ptr->name); - free(ptr); - } + if (ptr != NULL) { + if (ptr->name != NULL) + free(ptr->name); + free(ptr); + } } /****************************************************************************** DeleteItem - Deletes an item from the list ******************************************************************************/ -int DeleteItem(List *list,long id) +int +DeleteItem(List *list, long id) { - Item *temp,*temp2; - int i; - - if (list->head==NULL) return -1; - if (list->head->id==id) - { - temp2=list->head; - temp=list->head=list->head->next; - i=-1; - } - else - { - for(i=0,temp=list->head;temp->next!=NULL && temp->next->id!=id; - i++,temp=temp->next); - if (temp->next==NULL) return -1; - temp2=temp->next; - temp->next=temp2->next; - } - - if (temp2==list->tail) list->tail=temp; - - FreeItem(temp2); - list->count--; - return i+1; + Item *temp, *temp2; + int i; + + if (list->head == NULL) + return -1; + if (list->head->id == id) { + temp2 = list->head; + temp = list->head = list->head->next; + i = -1; + } else { + for (i = 0, temp = list->head; + temp->next != NULL && temp->next->id != id; + i++, temp = temp->next) + ; + if (temp->next == NULL) + return -1; + temp2 = temp->next; + temp->next = temp2->next; + } + + if (temp2 == list->tail) + list->tail = temp; + + FreeItem(temp2); + list->count--; + return i + 1; } /****************************************************************************** FreeList - Free the entire list of Items ******************************************************************************/ -void FreeList(List *list) +void +FreeList(List *list) { - Item *temp,*temp2; - - for(temp=list->head;temp!=NULL;) - { - temp2=temp; - temp=temp->next; - FreeItem(temp2); - } - list->count=0; + Item *temp, *temp2; + + for (temp = list->head; temp != NULL;) { + temp2 = temp; + temp = temp->next; + FreeItem(temp2); + } + list->count = 0; } /****************************************************************************** PrintList - Print the list of item on the console. (Debugging) ******************************************************************************/ -void PrintList(List *list) +void +PrintList(List *list) { -Item *temp; - ConsoleMessage("List of Items:\n"); - ConsoleMessage(" %10s %-15s %-15s %-15s %-15s Flgs\n","ID","Name","I-Name", - "R-Name","R-Class"); - ConsoleMessage(" ---------- --------------- --------------- --------------- --------------- ----\n"); - for(temp=list->head;temp!=NULL;temp=temp->next) { - ConsoleMessage(" %10ld %-15.15s %4ld\n",temp->id, - (temp->name==NULL) ? "" : temp->name, - temp->flags); - } + Item *temp; + ConsoleMessage("List of Items:\n"); + ConsoleMessage(" %10s %-15s %-15s %-15s %-15s Flgs\n", "ID", "Name", + "I-Name", "R-Name", "R-Class"); + ConsoleMessage(" ---------- --------------- --------------- " + "--------------- --------------- ----\n"); + for (temp = list->head; temp != NULL; temp = temp->next) { + ConsoleMessage(" %10ld %-15.15s %4ld\n", temp->id, + (temp->name == NULL) ? "" : temp->name, temp->flags); + } } /****************************************************************************** ItemName - Return the name of an Item ******************************************************************************/ -char *ItemName(List *list, int n) +char * +ItemName(List *list, int n) { - Item *temp; - int i; - - for(i=0,temp=list->head;temp!=NULL && inext); - if (temp==NULL) return NULL; - return temp->name; + Item *temp; + int i; + + for (i = 0, temp = list->head; temp != NULL && i < n; + i++, temp = temp->next) + ; + if (temp == NULL) + return NULL; + return temp->name; } /****************************************************************************** ItemFlags - Return the flags for an item ******************************************************************************/ -long ItemFlags(List *list, long id) +long +ItemFlags(List *list, long id) { - Item *temp; + Item *temp; - for(temp=list->head; temp != NULL && id!=temp->id; temp=temp->next); - if (temp==NULL) - return -1; + for (temp = list->head; temp != NULL && id != temp->id; + temp = temp->next) + ; + if (temp == NULL) + return -1; - else return temp->flags; + else + return temp->flags; } /****************************************************************************** ItemDesk - Return the desk for an item ******************************************************************************/ -long ItemDesk(List *list, long id) +long +ItemDesk(List *list, long id) { - Item *temp; + Item *temp; - for(temp=list->head;temp!=NULL && id!=temp->id;temp=temp->next); + for (temp = list->head; temp != NULL && id != temp->id; + temp = temp->next) + ; - if (temp==NULL) return -1; - else return temp->desk; + if (temp == NULL) + return -1; + else + return temp->desk; } - /****************************************************************************** XorFlags - Exclusive of the flags with the specified value. ******************************************************************************/ -long XorFlags(List *list, int n, long value) +long +XorFlags(List *list, int n, long value) { - Item *temp; - int i; - long ret; - - for(i=0,temp=list->head;temp!=NULL && inext) - if (temp==NULL) return -1; - ret=temp->flags; - temp->flags^=value; - return ret; + Item *temp; + int i; + long ret; + + for (i = 0, temp = list->head; temp != NULL && i < n; + i++, temp = temp->next) + if (temp == NULL) + return -1; + ret = temp->flags; + temp->flags ^= value; + return ret; } /****************************************************************************** ItemCount - Return the number of items inthe list ******************************************************************************/ -int ItemCount(List *list) +int +ItemCount(List *list) { - return list->count; + return list->count; } /****************************************************************************** ItemCountDesk - Return the number of items inthe list, with desk desk ******************************************************************************/ -int ItemCountDesk(List *list, long desk) +int +ItemCountDesk(List *list, long desk) { - Item *temp; - int count=0; + Item *temp; + int count = 0; -/*return list->count;*/ + /*return list->count;*/ - for(temp=list->head; - temp != NULL; - temp = temp->next - ) - { - if(temp->desk == desk) - count++; - } + for (temp = list->head; temp != NULL; temp = temp->next) { + if (temp->desk == desk) + count++; + } - return count; + return count; } /****************************************************************************** ItemID - Return the ID of the item in the list. ******************************************************************************/ -long ItemID(List *list, int n) +long +ItemID(List *list, int n) { - Item *temp; - int i; - - for(i=0,temp=list->head;temp!=NULL && inext); - if (temp==NULL) return -1; - return temp->id; + Item *temp; + int i; + + for (i = 0, temp = list->head; temp != NULL && i < n; + i++, temp = temp->next) + ; + if (temp == NULL) + return -1; + return temp->id; } /****************************************************************************** CopyItem - Copy an item from one list to another ******************************************************************************/ -void CopyItem(List *dest, List *source, int n) +void +CopyItem(List *dest, List *source, int n) { - Item *temp; - int i; - - for(i=0,temp=source->head;temp!=NULL && inext); - if (temp==NULL) return; - AddItem(dest,temp->id,temp->flags, temp->desk); - UpdateItemName(dest,temp->id,temp->name); - DeleteItem(source,temp->id); + Item *temp; + int i; + + for (i = 0, temp = source->head; temp != NULL && i < n; + i++, temp = temp->next) + ; + if (temp == NULL) + return; + AddItem(dest, temp->id, temp->flags, temp->desk); + UpdateItemName(dest, temp->id, temp->name); + DeleteItem(source, temp->id); } - Index: fvwm/modules/FvwmWinList/List.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmWinList/List.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmWinList/List.h --- fvwm/modules/FvwmWinList/List.h +++ fvwm/modules/FvwmWinList/List.h @@ -1,36 +1,33 @@ -/* FvwmWinList Module for Fvwm. +/* FvwmWinList Module for Fvwm. * * Copyright 1994, Mike Finger (mfinger@mermaid.micro.umn.edu or * Mike_Finger@atk.com) * * The functions in this source file that are the original work of Mike Finger. - * + * * No guarantees or warantees or anything are provided or implied in any way * whatsoever. Use this program at your own risk. Permission to use this * program for any purpose is given, as long as the copyright is kept intact. * - * Things to do: Convert to C++ (In Progress) */ /* Structure definitions */ -typedef struct item -{ - long id; - char *name; - long flags; - long desk; - struct item *next; +typedef struct item { + long id; + char *name; + long flags; + long desk; + struct item *next; } Item; -typedef struct -{ - Item *head,*tail; - int count; +typedef struct { + Item *head, *tail; + int count; } List; /* Function Prototypes */ void InitList(List *list); -void AddItem(List *list, long id, long flags, long desk ); +void AddItem(List *list, long id, long flags, long desk); int FindItem(List *list, long id); int FindItemDesk(List *list, long id, long desk); @@ -38,15 +35,15 @@ int UpdateItemName(List *list, long id, char *string); int UpdateItemDesk(List *list, long id, long desk); int UpdateItemFlags(List *list, long id, long flags); void FreeItem(Item *ptr); -int DeleteItem(List *list,long id); +int DeleteItem(List *list, long id); void FreeList(List *list); void PrintList(List *list); char *ItemName(List *list, int n); -long ItemFlags(List *list, long id ); -long ItemFlags(List *list, long id ); +long ItemFlags(List *list, long id); +long ItemFlags(List *list, long id); long ItemDesk(List *list, long id); long XorFlags(List *list, int n, long value); int ItemCount(List *list); int ItemCountDesk(List *list, long desk); long ItemID(List *list, int n); -void CopyItem(List *dest,List *source,int n); +void CopyItem(List *dest, List *source, int n); Index: fvwm/modules/FvwmWinList/Makefile =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmWinList/Makefile,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmWinList/Makefile --- fvwm/modules/FvwmWinList/Makefile +++ fvwm/modules/FvwmWinList/Makefile @@ -5,7 +5,7 @@ .PATH: ${DIST}/modules/FvwmWinList PROG= FvwmWinList -SRCS= ButtonArray.c Colors.c FvwmWinList.c List.c Mallocs.c +SRCS= ButtonArray.c Colors.c FvwmWinList.c List.c LDADD+= -lXpm ${XLIB} BINDIR= ${FVWMLIBDIR} Index: fvwm/modules/FvwmWinList/Mallocs.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmWinList/Mallocs.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmWinList/Mallocs.c --- fvwm/modules/FvwmWinList/Mallocs.c +++ /dev/null @@ -1,58 +0,0 @@ -/* FvwmWinList Module for Fvwm. - * - * Copyright 1994, Mike Finger (mfinger@mermaid.micro.umn.edu or - * Mike_Finger@atk.com) - * - * The author makes not guarantees or warantees, either express or - * implied. Feel free to use any contained here for any purpose, as long - * and this and any other applicible copyrights are kept intact. - - * The functions in this source file that are based on part of the FvwmIdent - * module for Fvwm are noted by a small copyright atop that function, all others - * are copyrighted by Mike Finger. For those functions modified/used, here is - * the full, original copyright: - * - * Copyright 1994, Robert Nation and Nobutaka Suzuki. - * No guarantees or warantees or anything - * are provided or implied in any way whatsoever. Use this program at your - * own risk. Permission to use this program for any purpose is given, - * as long as the copyright is kept intact. */ - -#include "config.h" - -#include -#include -#include -#include -#include -#include "../../libs/fvwmlib.h" - -extern char *Module; - -/****************************************************************************** - saferealloc - safely reallocate memory or exit if fails. (Doesn't work right) - (No kidding! Try it now ...) -******************************************************************************/ -char *saferealloc(char *ptr, size_t length) -{ -char *newptr; - - if(length <=0) length=1; - - /* If ptr is NULL then realloc does a malloc */ - newptr=realloc(ptr,length); - if (newptr == (char *)0) { - fprintf(stderr,"%s:realloc failed",Module); - exit(1); - } - return newptr; -} - -void UpdateString(char **string,const char *value) -{ - if (value==NULL) return; - *string = saferealloc(*string,strlen(value)+1); - strcpy(*string,value); -} - - Index: fvwm/modules/FvwmWinList/Mallocs.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmWinList/Mallocs.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmWinList/Mallocs.h --- fvwm/modules/FvwmWinList/Mallocs.h +++ /dev/null @@ -1,25 +0,0 @@ -/* FvwmWinList Module for Fvwm. - * - * Copyright 1994, Mike Finger (mfinger@mermaid.micro.umn.edu or - * Mike_Finger@atk.com) - * - * The author makes not guarantees or warantees, either express or - * implied. Feel free to use any contained here for any purpose, as long - * and this and any other applicible copyrights are kept intact. - - * The functions in this source file that are based on part of the FvwmIdent - * module for Fvwm are noted by a small copyright atop that function, all others - * are copyrighted by Mike Finger. For those functions modified/used, here is - * the full, original copyright: - * - * Copyright 1994, Robert Nation and Nobutaka Suzuki. - * No guarantees or warantees or anything - * are provided or implied in any way whatsoever. Use this program at your - * own risk. Permission to use this program for any purpose is given, - * as long as the copyright is kept intact. */ - -/* Function Prototypes */ -char *safemalloc(int length); -char *saferealloc(char *ptr, size_t length); -void UpdateString(char **string,const char *value); - Index: fvwm/modules/FvwmWinList/README =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmWinList/README,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmWinList/README --- fvwm/modules/FvwmWinList/README +++ fvwm/modules/FvwmWinList/README @@ -72,11 +72,8 @@ To do: (in no particular order) (ie. You make it wider you get 2 columns of buttons, etc.) - Fix the following: - - The function saferealloc, based on safemalloc by Rob Nation still doesn't - work correctly, I left it in the Mallocs.c file but I use the normal - realloc now. (Being lazy on this one) - - Make compile compatability for all systems - - Tune FvwmWinList to be more efficient (Low priority, right now) + - Make compile compatability for all systems + - Tune FvwmWinList to be more efficient (Low priority, right now) I am open to, actually I am trolling for, suggestions/improvments/ideas/rags on this. Index: fvwm/modules/Makefile.inc =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/Makefile.inc,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/Makefile.inc --- fvwm/modules/Makefile.inc +++ fvwm/modules/Makefile.inc @@ -7,7 +7,7 @@ FVWM_MAKEFILE_INC = done X11BASE?= /usr/X11R6 -CFLAGS+= -I${X11BASE}/include -I${.CURDIR}/../.. -I${.CURDIR}/../../libs +CFLAGS+= -std=c99 -I${X11BASE}/include -I${.CURDIR}/../.. -I${.CURDIR}/../../libs LDADD+= -L${X11BASE}/lib XLIB= -lX11 -lxcb -lXau -lXdmcp Index: fvwm/Makefile.inc =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/Makefile.inc,v retrieving revision 1.1 diff -u -r1.1 fvwm/Makefile.inc --- fvwm/Makefile.inc +++ fvwm/Makefile.inc @@ -5,7 +5,7 @@ FVWM_MAKEFILE_INC = done .include -CFLAGS+= -I${X11BASE}/include -I${.CURDIR} -I${.CURDIR}/.. \ +CFLAGS+= -std=c99 -I${X11BASE}/include -I${.CURDIR} -I${.CURDIR}/.. \ -I${.CURDIR}/../libs LDADD+= -L${X11BASE}/lib Index: fvwm/config.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/config.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/config.h --- fvwm/config.h +++ fvwm/config.h @@ -1,366 +1,42 @@ -/* config.h. Generated automatically by configure. */ -/* config.h.in. Generated automatically from configure.in by autoheader. */ -/** Compatibility stuff **/ +/* config.h -- OpenBSD fvwm configuration */ -/* Where to search for the fvwm icons. */ -#define FVWM_ICONDIR "/usr/include/X11/bitmaps:/usr/include/X11/pixmaps" +#define FVWM_ICONDIR "/usr/X11R6/lib/X11/fvwm/icons" -/* Define if Xpm library is used. */ #define XPM 1 - -/* Define if rplay library is used. */ -/* #undef HAVE_RPLAY */ - -/* Define if readline is available. */ -#define HAVE_READLINE 1 - -/* Define to disable motif applications ability to have modal dialogs. - * Use with care. */ -/* #undef MODALITY_IS_EVIL */ - -/* Tells the WM not to request save unders for pop-up - * menus. A quick test using monochrome X11 shows that save - * unders cost about 4Kbytes RAM, but saves a lot of - * window redraws if you have windows that take a while - * to refresh. For xcolor, I assume the cost is more like - * 4Kbytesx8 = 32kbytes (256 color). */ -/* #undef NO_SAVEUNDERS */ - -/* Define if you want the Shaped window extensions. - * Shaped window extensions seem to increase the window managers RSS - * by about 60 Kbytes. They provide for leaving a title-bar on the window - * without a border. - * If you don't use shaped window extension, you can either make your - * shaped windows undecorated, or live with a border and backdrop around - * all your shaped windows (oclock, xeyes) - * - * If you normally use a shaped window (xeyes or oclock), you might as - * well compile this extension in, since the memory cost is minimal in - * this case (The shaped window shared libs will be loaded anyway). If you - * don't normally use a shaped window, you have to decide for yourself. - * - * Note: if it is compiled in, run time detection is used to make sure that - * the currently running X server supports it. */ #define SHAPE 1 - -/* Enables the ActiveDown button state. This allows different button - * styles for pressed down buttons on active windows (also for the - * title-bar if EXTENDED_TITLESTYLE is enabled below). The man page - * refers to this button state as "ActiveDown." If not defined, the - * "ActiveUp" state is used instead. Disabling this reduces memory - * usage. */ #define ACTIVEDOWN_BTNS 1 - -/* Enables the Inactive button state. This allows different button - * styles for inactive windows (also for the title-bar if - * EXTENDED_TITLESTYLE is enabled below). The man page refers to this - * button state as "Inactive." If not defined, the "ActiveUp" state - * is used instead. Disabling this reduces memory usage. */ #define INACTIVE_BTNS 1 - -/* Enables the "MiniIcon" Style option to specify a small pixmap which - * can be used as one of the title-bar buttons, shown in window list, - * utilized by modules, etc. Requires PIXMAP_BUTTONS to be defined - * (see below). */ #define MINI_ICONS 1 - -/* Enables the vector button style. This button type is considered - * "standard," so it is recommended that you leave it in. */ #define VECTOR_BUTTONS 1 - -/* Enables the pixmap button style. You must have Xpm support to use - * color pixmaps. See the man page button style entries for "Pixmap" - * and "TiledPixmap" for usage information. */ #define PIXMAP_BUTTONS 1 - -/* Enables the gradient button style. See the man page button style - * entries for "HGradient" and "VGradient" for usage information. */ #define GRADIENT_BUTTONS 1 - -/* Enables stacked button styles (also for the title-bar if - * EXTENDED_TITLESTYLE is enabled below). There is a slight memory - * penalty for each additional style. See the man page entries for - * AddButtonStyle and AddTitleStyle for usage information. */ #define MULTISTYLE 1 - -/* Enables styled title-bars (specified with the TitleStyle command in - * a similar fashion to the ButtonStyle command). It also compiles in - * support to change the title-bar height. */ #define EXTENDED_TITLESTYLE 1 - -/* Enables the BorderStyle command. Not all button styles are - * available. See the man page entry for BorderStyle for usage - * information. If you are also using PIXMAP_BUTTONS, you can also - * texture your borders with tiled pixmaps. The BorderStyle command - * has Active and Inactive states, regardless of the -DACTIVEDOWN_BTNS - * and -DINACTIVE_BTNS defines. */ #define BORDERSTYLE 1 - -/* Enables tagged general decoration styles which can be assigned to - * windows using the UseDecor Style option, or dynamically updated - * with ChangeDecor. To create and destroy "decor" definitions, see - * the man page entries for AddToDecor and DestroyDecor. There is a - * slight memory penalty for each additionally defined decor. */ #define USEDECOR 1 - -/* Enables the WindowShade function. This function "rolls" the window - * up so only the title-bar remains. See the man page entry for - * "WindowShade" for more information. */ #define WINDOWSHADE 1 -/* Specify a type for sig_atomic_t if it's not available. */ -/* #undef sig_atomic_t */ - - - -/* Define to empty if the keyword does not work. */ -/* #undef const */ - -/* Define if you have the strftime function. */ -#define HAVE_STRFTIME 1 - -/* Define if you have that is POSIX.1 compatible. */ -#define HAVE_SYS_WAIT_H 1 - -/* Define as __inline if that's what the C compiler calls it. */ -#define inline __inline - -/* Define if on MINIX. */ -/* #undef _MINIX */ - -/* Define to `long' if doesn't define. */ -/* #undef off_t */ - -/* Define to `int' if doesn't define. */ -/* #undef pid_t */ - -/* Define if the system does not provide POSIX.1 features except - with this defined. */ -/* #undef _POSIX_1_SOURCE */ - -/* Define if you need to in order for stat and other things to work. */ -/* #undef _POSIX_SOURCE */ - -/* Define as the return type of signal handlers (int or void). */ -#define RETSIGTYPE void - -/* Define to the type of arg1 for select(). */ -#define SELECT_TYPE_ARG1 int - -/* Define to the type of args 2, 3 and 4 for select(). */ -#define SELECT_TYPE_ARG234 (fd_set *) - -/* Define to the type of arg5 for select(). */ -#define SELECT_TYPE_ARG5 (struct timeval *) - -/* Define if the setvbuf function takes the buffering type as its second - argument and the buffer pointer as the third, as on System V - before release 3. */ -/* #undef SETVBUF_REVERSED */ - -/* Define to `unsigned' if doesn't define. */ -/* #undef size_t */ - -/* Define if you have the ANSI C header files. */ -#define STDC_HEADERS 1 - -/* Define if the X Window System is missing or not being used. */ -/* #undef X_DISPLAY_MISSING */ - -/* Define if lex declares yytext as a char * by default, not a char[]. */ -#define YYTEXT_POINTER 1 - -/* -** if you would like to see lots of debug messages from fvwm, for debugging -** purposes, uncomment the next line -*/ -/* #undef FVWM_DEBUG_MSGS */ - -#ifdef FVWM_DEBUG_MSGS -# define DBUG(x,y) fvwm_msg(DBG,x,y) -#else -# define DBUG(x,y) /* no messages */ -#endif - -/* Define if you have the atexit function. */ -#define HAVE_ATEXIT 1 - -/* Define if you have the div function. */ -#define HAVE_DIV 1 - -/* Define if you have the gethostname function. */ -#define HAVE_GETHOSTNAME 1 - -/* Define if you have the gettimeofday function. */ -#define HAVE_GETTIMEOFDAY 1 - -/* Define if you have the memcpy function. */ -#define HAVE_MEMCPY 1 - -/* Define if you have the memmove function. */ -#define HAVE_MEMMOVE 1 - -/* Define if you have the mkfifo function. */ -#define HAVE_MKFIFO 1 - -/* Define if you have the on_exit function. */ -/* #undef HAVE_ON_EXIT */ - -/* Define if you have the putenv function. */ -#define HAVE_PUTENV 1 - -/* Define if you have the select function. */ -#define HAVE_SELECT 1 - -/* Define if you have the setvbuf function. */ -#define HAVE_SETVBUF 1 +#define PACKAGE "fvwm" +#define VERSION "2.2.5" -/* Define if you have the sigaction function. */ +#define HAVE_FCNTL_H 1 #define HAVE_SIGACTION 1 - -/* Define if you have the siginterrupt function. */ #define HAVE_SIGINTERRUPT 1 - -/* Define if you have the socket function. */ -#define HAVE_SOCKET 1 - -/* Define if you have the strcasecmp function. */ -#define HAVE_STRCASECMP 1 - -/* Define if you have the strchr function. */ -#define HAVE_STRCHR 1 - -/* Define if you have the strdup function. */ -#define HAVE_STRDUP 1 - -/* Define if you have the strerror function. */ -#define HAVE_STRERROR 1 - -/* Define if you have the strncasecmp function. */ -#define HAVE_STRNCASECMP 1 - -/* Define if you have the strstr function. */ -#define HAVE_STRSTR 1 - -/* Define if you have the strtol function. */ -#define HAVE_STRTOL 1 - -/* Define if you have the sysconf function. */ -#define HAVE_SYSCONF 1 - -/* Define if you have the uname function. */ -#define HAVE_UNAME 1 - -/* Define if you have the usleep function. */ -#define HAVE_USLEEP 1 - -/* Define if you have the vfprintf function. */ -#define HAVE_VFPRINTF 1 - -/* Define if you have the wait3 function. */ -/* #undef HAVE_WAIT3 */ - -/* Define if you have the wait4 function. */ -/* #undef HAVE_WAIT4 */ - -/* Define if you have the waitpid function. */ -#define HAVE_WAITPID 1 - -/* Define if you have the header file. */ -#define HAVE_FCNTL_H 1 - -/* Define if you have the header file. */ -/* #undef HAVE_GETOPT_H */ - -/* Define if you have the header file. */ -#define HAVE_LIMITS_H 1 - -/* Define if you have the header file. */ -/* #undef HAVE_MALLOC_H */ - -/* Define if you have the header file. */ -#define HAVE_MEMORY_H 1 - -/* Define if you have the header file. */ -#define HAVE_STDARG_H 1 - -/* Define if you have the header file. */ -#define HAVE_STDLIB_H 1 - -/* Define if you have the header file. */ -#define HAVE_STRING_H 1 - -/* Define if you have the header file. */ #define HAVE_SYS_SELECT_H 1 +#define HAVE_SYS_WAIT_H 1 +#define HAVE_WAITPID 1 -/* Define if you have the header file. */ -#define HAVE_SYS_SOCKET_H 1 - -/* Define if you have the header file. */ -/* #undef HAVE_SYS_SYSTEMINFO_H */ - -/* Define if you have the header file. */ -#define HAVE_SYS_TIME_H 1 - -/* Define if you have the header file. */ -#define HAVE_SYS_TYPES_H 1 - -/* Define if you have the header file. */ -#define HAVE_UNISTD_H 1 - -/* Name of package */ -#define PACKAGE "fvwm" - -/* Version number of package */ -#define VERSION "2.2.5" - - -#ifdef STDC_HEADERS -# include -# include -#else -# ifdef HAVE_STRING_H -# include -# else -# include -# endif -# ifdef HAVE_MEMORY_H -# include -# endif -# ifdef HAVE_STDLIB_H -# include -# endif -# ifdef HAVE_MALLOC_H -# include -# endif -# ifndef HAVE_STRCHR -# define strchr(_s,_c) index((_s),(_c)) -# define strrchr(_s,_c) rindex((_s),(_c)) -# endif -#endif - -#ifndef HAVE_MEMCPY -# define memcpy(_d,_s,_l) bcopy((_s),(_d),(_l)) -#endif -#ifndef HAVE_MEMMOVE -# define memmove(_d,_s,_l) bcopy((_s),(_d),(_l)) -#endif - -#if HAVE_SYS_TYPES_H -# include -#endif - -#if HAVE_UNISTD_H -# include -#endif +#include +#include +#include +#include #ifndef min -# define min(a,b) (((a)<(b)) ? (a) : (b)) +#define min(a, b) (((a) < (b)) ? (a) : (b)) #endif #ifndef max -# define max(a,b) (((a)>(b)) ? (a) : (b)) +#define max(a, b) (((a) > (b)) ? (a) : (b)) #endif #ifndef abs -# define abs(a) (((a)>=0)?(a):-(a)) +#define abs(a) (((a) >= 0) ? (a) : -(a)) #endif - Index: fvwm/docs/BUGS =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/docs/BUGS,v retrieving revision 1.1 diff -u -r1.1 fvwm/docs/BUGS --- fvwm/docs/BUGS +++ fvwm/docs/BUGS @@ -9,71 +9,17 @@ from our home page. ====================================================================== ====================================================================== - - No geometry can be specified for FvwmButtons panels. - Running fvwm2 on an XNest X server does not work well. - - FvwmSave and FvwmSaveDesk are not up to date. - The fvwm_convert script is not up to date. - - xscreensaver may not be able to allocate a private colormap - - FvwmButtons and possibly other modules may survive shutdown of the X - server. + - xscreensaver may not be able to allocate a private colormap. - AutoHide in FvwmTaskBar does not work well. See 'EdgeThickness' command in the manpage. - - DestroyMenu/DestroyFunc causes a coredump if a function/menu destroys - itself. - - Maximize does not work well when applied to a window that is not on - the current page. - - A piperead command may hang if used in .fvwm2rc (if the pipe is never - closed). - - StartsOnPage does not work as expected? Please read the manpage carefully. - ====================================================================== ====================================================================== -Configure remembers too many things, particularly with respect to the -optional libraries. If you ever need to re-run configure, using -different --with options, please remove "config.cache" file first. - ----------------------------------------------------------------------- - Binding a key to a window decoration but not to the window itself is discouraged because when the key-press event finally gets to the window it will be marked as SYNTHETIC and will be ignored by many applications. ----------------------------------------------------------------------- - -Sending DESTROY window manager options to applications is a bad way to -close them and should only be used as a last resort. Strange things -can happen. Please try DELETE and CLOSE first. - ----------------------------------------------------------------------- - -Some users have seen intermittent problems with XEmacs version 19.13 -not being refreshed correctly after a restart of fvwm2. If this -occurs, you should be able to open a new frame and delete the old one. -I can't debug this, as I don't see this problem. I don't know if the -problem is from XEmacs, fvwm2, or something specific to a few user's -setups. - ----------------------------------------------------------------------- - -Some users have been getting odd startup problems, like total lockups. -I cannot reproduce this, and have no idea why. Let me know if you see -this and find a way to consistently reproduce it. - -Actually, I've recently discovered that this is often from not having -a .fvwm2rc file, so check that first... But this is fixed in the -later versions. - ----------------------------------------------------------------------- - -Fvwm attempts to be ICCCM 1.1 compliant. In addition, ICCCM -states that it should be possible for applications to receive ANY -keystroke, which is not consistent with the keyboard shortcut approach -used in fvwm and most other window managers. In particular you -cannot have the same keyboard shortcuts working with your fvwm2 and -another fvwm2 running within Xnest (a nested X server). The same problem -exists with mouse bindings. - ----------------------------------------------------------------------- Index: fvwm/docs/TODO =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/docs/TODO,v retrieving revision 1.1 diff -u -r1.1 fvwm/docs/TODO --- fvwm/docs/TODO +++ fvwm/docs/TODO @@ -45,7 +45,6 @@ Bugfixes: - Change flags implementation to allow adding more Styles easily (bitfields?) - THE GREAT STYLE FLAG REWRITE (GSFR) - Rewrite VISIBLE/RAISED lags to do something comprehensible. - - Fix Restart to not pass original (fvwm specific) options to other wm's - Run profiling on FVWM to see if I can speed it up any more - Try to decrease memory usage a little more - clean up code duplication (esp in modules) - more stuff in @@ -57,19 +56,14 @@ Bugfixes: MotionThreshold not exceeded & ClickTime not exceeded -> DoubleClick - Make transient FvwmWinList reposition itself & pointer if popped up off the screen (like built in menus) - - Maximize XTerm, change font, UnMaximize, XTerm goes to wrong window size - (still unfixed on 28-Nov-1998) - Colormaps and xlock -install -mode blank (& swirl) interaction still isn't 100% correct? - bring back 'TogglePage'? - - Setting keys via FvwmTalk or Read requires Recapture to take effect? - System Modal dialogs bug - popup menus shouldn't be allowed?? I think this is ok, actually... - Fix FvwmDeskTopScale size calculation - Need to fix to work correctly under 24bit (TrueColor) displays - - Esc during moves, etc can result in windows being "lost" off desktop - Should also have way to make windows off desktop be recovered easier - - Transients of transients don't get raised correctly sometimes? ---------------------------------------------------------------------- Index: fvwm/docs/run_man2html.sh =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/docs/run_man2html.sh,v retrieving revision 1.1 diff -u -r1.1 fvwm/docs/run_man2html.sh --- fvwm/docs/run_man2html.sh +++ fvwm/docs/run_man2html.sh @@ -1,4 +1,4 @@ -#/bin/sh +#!/bin/sh # Modification History @@ -12,8 +12,8 @@ # If you run, run_man2html.sh fvwm2, this creates "fvwm2.html" in # the current directory. -name=`basename $1` -outfile=$name.html +name=$(basename "$1") +outfile="$name.html" # make header: echo " @@ -27,23 +27,23 @@ echo "

The Official FVWM Homepage - $name Man Page

-" > $outfile
+" >"$outfile"
 
 # Embed the text with some adjustment:
 # Italics are shown in yellow.  References, (if there were any)
 # would be shown in cyan.  Unfortunately bold stuff in man pages
 # is lost.  Maybe in the man command, maybe in man2html.
 # Output looks pretty good anyway (to my eyes).
-man $name | man2html -bare \
-  -uelem 'font color="yellow"'\
-  -belem 'font color="cyan"'\
-   >> $outfile
+man "$name" | man2html -bare \
+	-uelem 'font color="yellow"' \
+	-belem 'font color="cyan"' \
+	>>"$outfile"
 
 # make footer:
 echo "

+ on $(date) --> -" >> $outfile +" >>"$outfile" Index: fvwm/docs/txt2html.sh =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/docs/txt2html.sh,v retrieving revision 1.1 diff -u -r1.1 fvwm/docs/txt2html.sh --- fvwm/docs/txt2html.sh +++ fvwm/docs/txt2html.sh @@ -13,8 +13,8 @@ # This has to be run from the directory where the output file is wanted. # This is designed for the files, ChangeLog, TO-DO, FAQ -name=`basename $1` -outfile=$name.html +name=$(basename "$1") +outfile="$name.html" # make header: echo " @@ -28,18 +28,18 @@ echo "

The Official FVWM Homepage - $name Information

-" > $outfile
+" >"$outfile"
 
 # Embed the text with some adjustment:
 sed -e 's/&/\&/' \
-    -e 's//\>/' $1 >> $outfile
+	-e 's//\>/' "$1" >>"$outfile"
 
 # make footer:
 echo "

+ on $(date) --> -" >> $outfile +" >>"$outfile" Index: fvwm/utils/xpmroot.1 =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/utils/xpmroot.1,v retrieving revision 1.1 diff -u -r1.1 fvwm/utils/xpmroot.1 --- fvwm/utils/xpmroot.1 +++ fvwm/utils/xpmroot.1 @@ -1,7 +1,7 @@ .\" $OpenBSD: xpmroot.1,v 1.1.1.1 2006/11/26 10:53:57 matthieu Exp $ .\" t .\" @(#)xpmroot.1 1.01 8/10/93 -.TH XPMROOT 1 "13 August 1993" 1.01 +.TH XPMROOT 1 "August 13, 1993" "1.01" "FVWM Utilities" .UC .SH NAME xpmroot \- Sets the root window of the current X display to an Xpm pixmap @@ -10,8 +10,5 @@ xpmroot \- Sets the root window of the current X display to an Xpm pixmap .SH DESCRIPTION \fIxpmroot\fP reads the Xpm file specified in the command line and displays it in the root window. -.SH BUGS -Repeated use of xpmroot with different xpm pixmaps will use up slots in -your color table pretty darn fast. .SH AUTHOR Rob Nation Index: fvwm/utils/xpmroot.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/utils/xpmroot.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/utils/xpmroot.c --- fvwm/utils/xpmroot.c +++ fvwm/utils/xpmroot.c @@ -1,99 +1,152 @@ /**************************************************************************** * This is an all new program to set the root window to an Xpm pixmap. - * Copyright 1993, Rob Nation + * Copyright 1993, Rob Nation * You may use this file for anything you want, as long as the copyright * is kept intact. No guarantees of any sort are made in any way regarding * this program or anything related to it. ****************************************************************************/ -#include "config.h" - -#include -#include -#include -#include #include -#include "../libs/fvwmlib.h" +#include +#include #include /* Has to be after Intrinsic.h gets included */ +#include +#include +#include +#include + +#include "../libs/fvwmlib.h" +#include "config.h" +#include "../fvwm/fvwm_sandbox.h" -int save_colors = 0; Display *dpy; int screen; Window root; char *display_name = NULL; -void SetRootWindow(char *tline); +static void SetRootWindow( + char *tline, XWindowAttributes *root_attr, Atom colors_atom); +static void FreePreviousResources( + Atom pixmap_atom, Atom colors_atom, XWindowAttributes *root_attr); Pixmap rootXpm; -int main(int argc, char **argv) +int +main(int argc, char **argv) { - Atom prop, type; - int format; - unsigned long length, after; - unsigned char *data; - - if(argc != 2) - { - fprintf(stderr,"Xpmroot Version %s\n",VERSION); - fprintf(stderr,"Usage: xpmroot xpmfile\n"); - fprintf(stderr,"Try Again\n"); - exit(1); - } - dpy = XOpenDisplay(display_name); - if (!dpy) - { - fprintf(stderr, "Xpmroot: unable to open display '%s'\n", - XDisplayName (display_name)); - exit (2); - } - screen = DefaultScreen(dpy); - root = RootWindow(dpy, screen); - - SetRootWindow(argv[1]); - - prop = XInternAtom(dpy, "_XSETROOT_ID", False); - - (void)XGetWindowProperty(dpy, root, prop, 0L, 1L, True, AnyPropertyType, - &type, &format, &length, &after, &data); - if ((type == XA_PIXMAP) && (format == 32) && (length == 1) && (after == 0)) - XKillClient(dpy, *((Pixmap *)data)); - - XChangeProperty(dpy, root, prop, XA_PIXMAP, 32, PropModeReplace, - (unsigned char *) &rootXpm, 1); - XSetCloseDownMode(dpy, RetainPermanent); - XCloseDisplay(dpy); - return 0; + Atom prop, color_prop; + XWindowAttributes root_attr; + + if (argc != 2) { + fprintf(stderr, "Xpmroot Version %s\n", VERSION); + fprintf(stderr, "Usage: xpmroot xpmfile\n"); + fprintf(stderr, "Try Again\n"); + exit(1); + } + sandbox_xpmroot("xpmroot"); + dpy = XOpenDisplay(display_name); + if (!dpy) { + fprintf(stderr, "Xpmroot: unable to open display '%s'\n", + XDisplayName(display_name)); + exit(2); + } + screen = DefaultScreen(dpy); + root = RootWindow(dpy, screen); + XGetWindowAttributes(dpy, root, &root_attr); + + prop = XInternAtom(dpy, "_XSETROOT_ID", False); + color_prop = XInternAtom(dpy, "_XSETROOT_COLORS", False); + + FreePreviousResources(prop, color_prop, &root_attr); + + SetRootWindow(argv[1], &root_attr, color_prop); + + XChangeProperty(dpy, root, prop, XA_PIXMAP, 32, PropModeReplace, + (unsigned char *)&rootXpm, 1); + XSetCloseDownMode(dpy, RetainPermanent); + XCloseDisplay(dpy); + return 0; } +static void +SetRootWindow(char *tline, XWindowAttributes *root_attr, Atom colors_atom) +{ + XpmAttributes xpm_attributes; + Pixmap shapeMask; + int val; + + memset(&xpm_attributes, 0, sizeof(xpm_attributes)); + xpm_attributes.colormap = root_attr->colormap; + xpm_attributes.valuemask = XpmSize | XpmReturnAllocPixels | XpmColormap; + if ((val = XpmReadFileToPixmap(dpy, root, tline, &rootXpm, &shapeMask, + &xpm_attributes)) != XpmSuccess) { + if (val == XpmOpenFailed) + fprintf(stderr, "Couldn't open pixmap file\n"); + else if (val == XpmColorFailed) + fprintf(stderr, "Couldn't allocate required colors\n"); + else if (val == XpmFileInvalid) + fprintf(stderr, "Invalid Format for an Xpm File\n"); + else if (val == XpmColorError) + fprintf( + stderr, "Invalid Color specified in Xpm FIle\n"); + else if (val == XpmNoMemory) + fprintf(stderr, "Insufficient Memory\n"); + exit(1); + } -void SetRootWindow(char *tline) + if (shapeMask != None) + XFreePixmap(dpy, shapeMask); + + XSetWindowBackgroundPixmap(dpy, root, rootXpm); + XClearWindow(dpy, root); + + if ((xpm_attributes.valuemask & XpmReturnAllocPixels) && + xpm_attributes.nalloc_pixels > 0 && + xpm_attributes.alloc_pixels != NULL) { + XChangeProperty(dpy, root, colors_atom, XA_CARDINAL, 32, + PropModeReplace, + (unsigned char *)xpm_attributes.alloc_pixels, + (int)xpm_attributes.nalloc_pixels); + } else { + XDeleteProperty(dpy, root, colors_atom); + } + + XpmFreeAttributes(&xpm_attributes); +} + +static void +FreePreviousResources( + Atom pixmap_atom, Atom colors_atom, XWindowAttributes *root_attr) { - XWindowAttributes root_attr; - XpmAttributes xpm_attributes; - Pixmap shapeMask; - int val; - - XGetWindowAttributes(dpy,root,&root_attr); - xpm_attributes.colormap = root_attr.colormap; - xpm_attributes.valuemask = XpmSize | XpmReturnPixels|XpmColormap; - if((val = XpmReadFileToPixmap(dpy,root, tline, - &rootXpm, &shapeMask, - &xpm_attributes))!= XpmSuccess) - { - if(val == XpmOpenFailed) - fprintf(stderr, "Couldn't open pixmap file\n"); - else if(val == XpmColorFailed) - fprintf(stderr, "Couldn't allocate required colors\n"); - else if(val == XpmFileInvalid) - fprintf(stderr, "Invalid Format for an Xpm File\n"); - else if(val == XpmColorError) - fprintf(stderr, "Invalid Color specified in Xpm FIle\n"); - else if(val == XpmNoMemory) - fprintf(stderr, "Insufficient Memory\n"); - exit(1); - } - - XSetWindowBackgroundPixmap(dpy, root, rootXpm); - save_colors = 1; - XClearWindow(dpy,root); + Atom type; + int format; + unsigned long length, after; + unsigned char *data = NULL; + int visual_class = + (root_attr->visual != NULL) ? root_attr->visual->class : StaticGray; + Bool can_free_colors = + (visual_class == PseudoColor || visual_class == GrayScale || + visual_class == DirectColor); + + if (XGetWindowProperty(dpy, root, colors_atom, 0L, (~0L), True, + XA_CARDINAL, &type, &format, &length, &after, + &data) == Success) { + if (can_free_colors && type == XA_CARDINAL && format == 32 && + length > 0 && data != NULL) { + Pixel *pixels = (Pixel *)data; + XFreeColors( + dpy, root_attr->colormap, pixels, (int)length, 0); + } + if (data != NULL) + XFree(data); + } + data = NULL; + if (XGetWindowProperty(dpy, root, pixmap_atom, 0L, 1L, True, + AnyPropertyType, &type, &format, &length, &after, + &data) == Success) { + if ((type == XA_PIXMAP) && (format == 32) && (length == 1) && + data != NULL) + XKillClient(dpy, *((Pixmap *)data)); + if (data != NULL) + XFree(data); + } } Index: fvwm/modules/FvwmAuto/FvwmAuto.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmAuto/FvwmAuto.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmAuto/FvwmAuto.c --- fvwm/modules/FvwmAuto/FvwmAuto.c +++ fvwm/modules/FvwmAuto/FvwmAuto.c @@ -24,7 +24,6 @@ #include "config.h" #include "../fvwm/fvwm_sandbox.h" -#endif #include #include @@ -124,7 +123,7 @@ main(int argc, char **argv) delay->tv_sec = sec; delay->tv_usec = usec; } - select(fd_width, SELECT_TYPE_ARG234 & in_fdset, 0, 0, + select(fd_width, & in_fdset, 0, 0, (focus_win == last_win) ? NULL : delay); #ifdef DEBUG fprintf(stderr, Index: fvwm/modules/FvwmBacker/FvwmBacker.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmBacker/FvwmBacker.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmBacker/FvwmBacker.c --- fvwm/modules/FvwmBacker/FvwmBacker.c +++ fvwm/modules/FvwmBacker/FvwmBacker.c @@ -43,8 +43,6 @@ #include #include -#endif /* Saul */ - #include #include @@ -164,11 +162,11 @@ EndLessLoop() tv.tv_sec = 0; tv.tv_usec = 0; - if (!select(fd_width, SELECT_TYPE_ARG234 & readset, NULL, NULL, + if (!select(fd_width, & readset, NULL, NULL, &tv)) { FD_ZERO(&readset); FD_SET(Fvwm_fd[1], &readset); - select(fd_width, SELECT_TYPE_ARG234 & readset, NULL, + select(fd_width, & readset, NULL, NULL, NULL); } Index: fvwm/modules/FvwmBanner/FvwmBanner.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmBanner/FvwmBanner.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmBanner/FvwmBanner.c --- fvwm/modules/FvwmBanner/FvwmBanner.c +++ fvwm/modules/FvwmBanner/FvwmBanner.c @@ -7,7 +7,6 @@ #include "config.h" #include "../../fvwm/fvwm_sandbox.h" -#endif #include #include @@ -190,7 +189,7 @@ main(int argc, char **argv) FD_SET(x_fd, &in_fdset); if (!XPending(dpy)) - retval = select(fd_width, SELECT_TYPE_ARG234 & in_fdset, + retval = select(fd_width, & in_fdset, 0, 0, &value); if (retval == 0) { Index: fvwm/modules/FvwmButtons/FvwmButtons.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmButtons/FvwmButtons.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmButtons/FvwmButtons.c --- fvwm/modules/FvwmButtons/FvwmButtons.c +++ fvwm/modules/FvwmButtons/FvwmButtons.c @@ -16,7 +16,6 @@ #include "config.h" #include "../../fvwm/fvwm_sandbox.h" -#endif #include #include @@ -857,7 +856,7 @@ Loop(void) PanelIndex = MainPanel; while (PanelIndex && PanelIndex->uber != - btn->uber) + btn->parent) PanelIndex = PanelIndex->next; UberButton = CurrentPanel ? @@ -1668,7 +1667,7 @@ My_XNextEvent(Display *Dpy, XEvent *event) FD_SET(x_fd, &in_fdset); FD_SET(fd[1], &in_fdset); - if (select(fd_width, SELECT_TYPE_ARG234 & in_fdset, 0, 0, NULL) > 0) { + if (select(fd_width, & in_fdset, 0, 0, NULL) > 0) { if (FD_ISSET(x_fd, &in_fdset)) { if (XPending(Dpy)) { XNextEvent(Dpy, event); Index: fvwm/modules/FvwmButtons/draw.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmButtons/draw.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmButtons/draw.c --- fvwm/modules/FvwmButtons/draw.c +++ fvwm/modules/FvwmButtons/draw.c @@ -16,8 +16,6 @@ #include "config.h" -#endif - #include #include #include Index: fvwm/modules/FvwmIconBox/FvwmIconBox.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIconBox/FvwmIconBox.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIconBox/FvwmIconBox.c --- fvwm/modules/FvwmIconBox/FvwmIconBox.c +++ fvwm/modules/FvwmIconBox/FvwmIconBox.c @@ -20,7 +20,6 @@ #include "config.h" #include "../../fvwm/fvwm_sandbox.h" -#endif #include #include @@ -1928,7 +1927,7 @@ My_XNextEvent(Display *dpy, XEvent *event) FD_SET(x_fd, &in_fdset); FD_SET(fd[1], &in_fdset); - select(fd_width, SELECT_TYPE_ARG234 & in_fdset, 0, 0, NULL); + select(fd_width, & in_fdset, 0, 0, NULL); if (FD_ISSET(x_fd, &in_fdset)) { if (XPending(dpy)) { Index: fvwm/modules/FvwmIconMan/FvwmIconMan.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIconMan/FvwmIconMan.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIconMan/FvwmIconMan.c --- fvwm/modules/FvwmIconMan/FvwmIconMan.c +++ fvwm/modules/FvwmIconMan/FvwmIconMan.c @@ -12,6 +12,7 @@ #include #include "../../fvwm/module.h" +#include "../../fvwm/fvwm_sandbox.h" #include "readconfig.h" #include "x.h" #include "xmanager.h" Index: fvwm/modules/FvwmIconMan/FvwmIconMan.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIconMan/FvwmIconMan.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIconMan/FvwmIconMan.h --- fvwm/modules/FvwmIconMan/FvwmIconMan.h +++ fvwm/modules/FvwmIconMan/FvwmIconMan.h @@ -47,7 +47,6 @@ #include #endif -extern void PrintMemuse(void); typedef unsigned long Ulong; typedef unsigned char Uchar; Index: fvwm/modules/FvwmIconMan/fvwm.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIconMan/fvwm.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIconMan/fvwm.c --- fvwm/modules/FvwmIconMan/fvwm.c +++ fvwm/modules/FvwmIconMan/fvwm.c @@ -577,8 +577,6 @@ ReadFvwmPipe(void) FvwmPacketHeader header; FvwmPacketBody *body; - PrintMemuse(); - ConsoleDebug(FVWM, "DEBUG: entering ReadFvwmPipe\n"); body_length = ReadFvwmPacket( Fvwm_fd[1], (unsigned long *)&header, (unsigned long **)&body); Index: fvwm/modules/FvwmIconMan/globals.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmIconMan/globals.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmIconMan/globals.c --- fvwm/modules/FvwmIconMan/globals.c +++ fvwm/modules/FvwmIconMan/globals.c @@ -31,7 +31,6 @@ init_win_manager(int id) globals.managers[id].index = id; #ifdef MINI_ICONS globals.managers[id].draw_icons = 0; -#endif globals.managers[id].res = SHOW_PAGE; globals.managers[id].window_up = 0; globals.managers[id].can_draw = 0; @@ -71,6 +70,7 @@ init_win_manager(int id) globals.managers[id].we_are_drawing = 1; globals.managers[id].configures_expected = 0; } +#endif void print_managers(void) Index: fvwm/modules/FvwmPager/FvwmPager.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmPager/FvwmPager.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmPager/FvwmPager.c --- fvwm/modules/FvwmPager/FvwmPager.c +++ fvwm/modules/FvwmPager/FvwmPager.c @@ -24,8 +24,6 @@ #include "config.h" #include "../../fvwm/fvwm_sandbox.h" -#endif /* Saul */ - #include #if HAVE_SYS_SELECT_H #include @@ -879,7 +877,7 @@ My_XNextEvent(Display *dpy, XEvent *event) FD_SET(x_fd, &in_fdset); FD_SET(fd[1], &in_fdset); - if (select(fd_width, SELECT_TYPE_ARG234 & in_fdset, 0, 0, NULL) > 0) { + if (select(fd_width, & in_fdset, 0, 0, NULL) > 0) { if (FD_ISSET(x_fd, &in_fdset)) { if (XPending(dpy)) { XNextEvent(dpy, event); Index: fvwm/modules/FvwmRearrange/FvwmRearrange.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmRearrange/FvwmRearrange.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmRearrange/FvwmRearrange.c --- fvwm/modules/FvwmRearrange/FvwmRearrange.c +++ fvwm/modules/FvwmRearrange/FvwmRearrange.c @@ -29,7 +29,6 @@ #include "config.h" #include "../../fvwm/fvwm_sandbox.h" -#endif #if HAVE_SYS_SELECT_H #include Index: fvwm/modules/FvwmSave/FvwmSave.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmSave/FvwmSave.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmSave/FvwmSave.c --- fvwm/modules/FvwmSave/FvwmSave.c +++ fvwm/modules/FvwmSave/FvwmSave.c @@ -286,7 +286,7 @@ do_save(void) out = fopen(tname, "w+"); if (out == NULL) { fprintf(stderr, "%s: couldn't open %s for writing\n", - Myname, tname); + MyName, tname); return; } for (t = list_root; t != NULL; t = t->next) { Index: fvwm/modules/FvwmSaveDesk/FvwmSaveDesk.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmSaveDesk/FvwmSaveDesk.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmSaveDesk/FvwmSaveDesk.c --- fvwm/modules/FvwmSaveDesk/FvwmSaveDesk.c +++ fvwm/modules/FvwmSaveDesk/FvwmSaveDesk.c @@ -429,7 +429,7 @@ do_save(void) out = fopen(fnbuf, "w"); if (out == NULL) { fprintf(stderr, "%s: couldn't open %s for writing\n", - Myname, fnbuf); + MyName, fnbuf); return; } Index: fvwm/modules/FvwmScroll/GrabWindow.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmScroll/GrabWindow.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmScroll/GrabWindow.c --- fvwm/modules/FvwmScroll/GrabWindow.c +++ fvwm/modules/FvwmScroll/GrabWindow.c @@ -13,8 +13,6 @@ #include "config.h" -#endif - #include #include Index: fvwm/modules/FvwmTalk/FvwmTalk.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmTalk/FvwmTalk.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmTalk/FvwmTalk.c --- fvwm/modules/FvwmTalk/FvwmTalk.c +++ fvwm/modules/FvwmTalk/FvwmTalk.c @@ -17,7 +17,6 @@ #include "config.h" #include "../../fvwm/fvwm_sandbox.h" -#endif #include #include @@ -346,7 +345,7 @@ My_XNextEvent(Display *dpy, XEvent *event) FD_SET(x_fd, &in_fdset); FD_SET(fd[1], &in_fdset); - select(fd_width, SELECT_TYPE_ARG234 & in_fdset, 0, 0, NULL); + select(fd_width, & in_fdset, 0, 0, NULL); if (FD_ISSET(x_fd, &in_fdset)) { if (XPending(dpy)) { Index: fvwm/modules/FvwmWinList/FvwmWinList.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmWinList/FvwmWinList.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmWinList/FvwmWinList.c --- fvwm/modules/FvwmWinList/FvwmWinList.c +++ fvwm/modules/FvwmWinList/FvwmWinList.c @@ -28,7 +28,6 @@ #ifndef NO_CONSOLE #define NO_CONSOLE -#endif #define YES "Yes" #define NO "No" @@ -48,12 +47,11 @@ #if HAVE_SYS_SELECT_H #include #endif +#endif #include #include -#endif - #include #include #include @@ -253,7 +251,7 @@ MainEventLoop(void) * having one fewer select statements */ XFlush(dpy); - if (select(fd_width, SELECT_TYPE_ARG234 & readset, NULL, NULL, + if (select(fd_width, & readset, NULL, NULL, NULL) > 0) { if (FD_ISSET(x_fd, &readset) || XPending(dpy)) LoopOnEvents(); OpenBSD FVWM 2.2.5: Core Program + Libraries Rewrite (non-GPL changes) ======================================================================== All changes to the main fvwm program and shared library EXCEPT the GPL code replacement (which is in 0001-gpl-removal.patch). Major changes: - Removed all non-OpenBSD portability code (48 autoconf probes, Solaris #ifdefs, GCC compat, sys/bsdtypes.h, waitpid/wait3, etc.) - Removed custom allocation wrappers (safemalloc/saferealloc); replaced with xalloc.h inline helpers using err(3) - Added privilege separation: fvwm_exec helper via imsg(3)/socketpair(2) - Added per-process pledge(2) and unveil(2) via fvwm_sandbox.h - Fixed CRITICAL bugs: negative-size text[-1] write, gradient double-free, DestroyModConfig NULL ptr, infinite Read recursion - Fixed HIGH bugs: exit()->_exit() in forked children, pointer aliasing, putenv() leak, body_length underflow, wrong strlcpy size - Fixed MEDIUM bugs: uninit error buffer, style fixes throughout - Rewrote man page in semantic mdoc(7) - Removed CVS directories NEW: fvwm/fvwm/exec.c imsg(3) exec helper interface NEW: fvwm/fvwm/fvwm_exec.c Privilege-separated helper binary NEW: fvwm/fvwm/fvwm_sandbox.h Shared pledge(2)/unveil(2) helpers NEW: fvwm/fvwm/xalloc.h xmalloc/xrealloc/xcalloc/xstrdup (inline) DELETED: fvwm/libs/safemalloc.c Replaced by xalloc.h Apply after 0001-gpl-removal.patch To apply: cd && patch -p0 < this-file Index: fvwm/config.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/config.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/config.h --- fvwm/config.h +++ fvwm/config.h @@ -1,366 +1,42 @@ -/* config.h. Generated automatically by configure. */ -/* config.h.in. Generated automatically from configure.in by autoheader. */ -/** Compatibility stuff **/ +/* config.h -- OpenBSD fvwm configuration */ -/* Where to search for the fvwm icons. */ -#define FVWM_ICONDIR "/usr/include/X11/bitmaps:/usr/include/X11/pixmaps" +#define FVWM_ICONDIR "/usr/X11R6/lib/X11/fvwm/icons" -/* Define if Xpm library is used. */ #define XPM 1 - -/* Define if rplay library is used. */ -/* #undef HAVE_RPLAY */ - -/* Define if readline is available. */ -#define HAVE_READLINE 1 - -/* Define to disable motif applications ability to have modal dialogs. - * Use with care. */ -/* #undef MODALITY_IS_EVIL */ - -/* Tells the WM not to request save unders for pop-up - * menus. A quick test using monochrome X11 shows that save - * unders cost about 4Kbytes RAM, but saves a lot of - * window redraws if you have windows that take a while - * to refresh. For xcolor, I assume the cost is more like - * 4Kbytesx8 = 32kbytes (256 color). */ -/* #undef NO_SAVEUNDERS */ - -/* Define if you want the Shaped window extensions. - * Shaped window extensions seem to increase the window managers RSS - * by about 60 Kbytes. They provide for leaving a title-bar on the window - * without a border. - * If you don't use shaped window extension, you can either make your - * shaped windows undecorated, or live with a border and backdrop around - * all your shaped windows (oclock, xeyes) - * - * If you normally use a shaped window (xeyes or oclock), you might as - * well compile this extension in, since the memory cost is minimal in - * this case (The shaped window shared libs will be loaded anyway). If you - * don't normally use a shaped window, you have to decide for yourself. - * - * Note: if it is compiled in, run time detection is used to make sure that - * the currently running X server supports it. */ #define SHAPE 1 - -/* Enables the ActiveDown button state. This allows different button - * styles for pressed down buttons on active windows (also for the - * title-bar if EXTENDED_TITLESTYLE is enabled below). The man page - * refers to this button state as "ActiveDown." If not defined, the - * "ActiveUp" state is used instead. Disabling this reduces memory - * usage. */ #define ACTIVEDOWN_BTNS 1 - -/* Enables the Inactive button state. This allows different button - * styles for inactive windows (also for the title-bar if - * EXTENDED_TITLESTYLE is enabled below). The man page refers to this - * button state as "Inactive." If not defined, the "ActiveUp" state - * is used instead. Disabling this reduces memory usage. */ #define INACTIVE_BTNS 1 - -/* Enables the "MiniIcon" Style option to specify a small pixmap which - * can be used as one of the title-bar buttons, shown in window list, - * utilized by modules, etc. Requires PIXMAP_BUTTONS to be defined - * (see below). */ #define MINI_ICONS 1 - -/* Enables the vector button style. This button type is considered - * "standard," so it is recommended that you leave it in. */ #define VECTOR_BUTTONS 1 - -/* Enables the pixmap button style. You must have Xpm support to use - * color pixmaps. See the man page button style entries for "Pixmap" - * and "TiledPixmap" for usage information. */ #define PIXMAP_BUTTONS 1 - -/* Enables the gradient button style. See the man page button style - * entries for "HGradient" and "VGradient" for usage information. */ #define GRADIENT_BUTTONS 1 - -/* Enables stacked button styles (also for the title-bar if - * EXTENDED_TITLESTYLE is enabled below). There is a slight memory - * penalty for each additional style. See the man page entries for - * AddButtonStyle and AddTitleStyle for usage information. */ #define MULTISTYLE 1 - -/* Enables styled title-bars (specified with the TitleStyle command in - * a similar fashion to the ButtonStyle command). It also compiles in - * support to change the title-bar height. */ #define EXTENDED_TITLESTYLE 1 - -/* Enables the BorderStyle command. Not all button styles are - * available. See the man page entry for BorderStyle for usage - * information. If you are also using PIXMAP_BUTTONS, you can also - * texture your borders with tiled pixmaps. The BorderStyle command - * has Active and Inactive states, regardless of the -DACTIVEDOWN_BTNS - * and -DINACTIVE_BTNS defines. */ #define BORDERSTYLE 1 - -/* Enables tagged general decoration styles which can be assigned to - * windows using the UseDecor Style option, or dynamically updated - * with ChangeDecor. To create and destroy "decor" definitions, see - * the man page entries for AddToDecor and DestroyDecor. There is a - * slight memory penalty for each additionally defined decor. */ #define USEDECOR 1 - -/* Enables the WindowShade function. This function "rolls" the window - * up so only the title-bar remains. See the man page entry for - * "WindowShade" for more information. */ #define WINDOWSHADE 1 -/* Specify a type for sig_atomic_t if it's not available. */ -/* #undef sig_atomic_t */ - - - -/* Define to empty if the keyword does not work. */ -/* #undef const */ - -/* Define if you have the strftime function. */ -#define HAVE_STRFTIME 1 - -/* Define if you have that is POSIX.1 compatible. */ -#define HAVE_SYS_WAIT_H 1 - -/* Define as __inline if that's what the C compiler calls it. */ -#define inline __inline - -/* Define if on MINIX. */ -/* #undef _MINIX */ - -/* Define to `long' if doesn't define. */ -/* #undef off_t */ - -/* Define to `int' if doesn't define. */ -/* #undef pid_t */ - -/* Define if the system does not provide POSIX.1 features except - with this defined. */ -/* #undef _POSIX_1_SOURCE */ - -/* Define if you need to in order for stat and other things to work. */ -/* #undef _POSIX_SOURCE */ - -/* Define as the return type of signal handlers (int or void). */ -#define RETSIGTYPE void - -/* Define to the type of arg1 for select(). */ -#define SELECT_TYPE_ARG1 int - -/* Define to the type of args 2, 3 and 4 for select(). */ -#define SELECT_TYPE_ARG234 (fd_set *) - -/* Define to the type of arg5 for select(). */ -#define SELECT_TYPE_ARG5 (struct timeval *) - -/* Define if the setvbuf function takes the buffering type as its second - argument and the buffer pointer as the third, as on System V - before release 3. */ -/* #undef SETVBUF_REVERSED */ - -/* Define to `unsigned' if doesn't define. */ -/* #undef size_t */ - -/* Define if you have the ANSI C header files. */ -#define STDC_HEADERS 1 - -/* Define if the X Window System is missing or not being used. */ -/* #undef X_DISPLAY_MISSING */ - -/* Define if lex declares yytext as a char * by default, not a char[]. */ -#define YYTEXT_POINTER 1 - -/* -** if you would like to see lots of debug messages from fvwm, for debugging -** purposes, uncomment the next line -*/ -/* #undef FVWM_DEBUG_MSGS */ - -#ifdef FVWM_DEBUG_MSGS -# define DBUG(x,y) fvwm_msg(DBG,x,y) -#else -# define DBUG(x,y) /* no messages */ -#endif - -/* Define if you have the atexit function. */ -#define HAVE_ATEXIT 1 - -/* Define if you have the div function. */ -#define HAVE_DIV 1 - -/* Define if you have the gethostname function. */ -#define HAVE_GETHOSTNAME 1 - -/* Define if you have the gettimeofday function. */ -#define HAVE_GETTIMEOFDAY 1 - -/* Define if you have the memcpy function. */ -#define HAVE_MEMCPY 1 - -/* Define if you have the memmove function. */ -#define HAVE_MEMMOVE 1 - -/* Define if you have the mkfifo function. */ -#define HAVE_MKFIFO 1 - -/* Define if you have the on_exit function. */ -/* #undef HAVE_ON_EXIT */ - -/* Define if you have the putenv function. */ -#define HAVE_PUTENV 1 - -/* Define if you have the select function. */ -#define HAVE_SELECT 1 - -/* Define if you have the setvbuf function. */ -#define HAVE_SETVBUF 1 +#define PACKAGE "fvwm" +#define VERSION "2.2.5" -/* Define if you have the sigaction function. */ +#define HAVE_FCNTL_H 1 #define HAVE_SIGACTION 1 - -/* Define if you have the siginterrupt function. */ #define HAVE_SIGINTERRUPT 1 - -/* Define if you have the socket function. */ -#define HAVE_SOCKET 1 - -/* Define if you have the strcasecmp function. */ -#define HAVE_STRCASECMP 1 - -/* Define if you have the strchr function. */ -#define HAVE_STRCHR 1 - -/* Define if you have the strdup function. */ -#define HAVE_STRDUP 1 - -/* Define if you have the strerror function. */ -#define HAVE_STRERROR 1 - -/* Define if you have the strncasecmp function. */ -#define HAVE_STRNCASECMP 1 - -/* Define if you have the strstr function. */ -#define HAVE_STRSTR 1 - -/* Define if you have the strtol function. */ -#define HAVE_STRTOL 1 - -/* Define if you have the sysconf function. */ -#define HAVE_SYSCONF 1 - -/* Define if you have the uname function. */ -#define HAVE_UNAME 1 - -/* Define if you have the usleep function. */ -#define HAVE_USLEEP 1 - -/* Define if you have the vfprintf function. */ -#define HAVE_VFPRINTF 1 - -/* Define if you have the wait3 function. */ -/* #undef HAVE_WAIT3 */ - -/* Define if you have the wait4 function. */ -/* #undef HAVE_WAIT4 */ - -/* Define if you have the waitpid function. */ -#define HAVE_WAITPID 1 - -/* Define if you have the header file. */ -#define HAVE_FCNTL_H 1 - -/* Define if you have the header file. */ -/* #undef HAVE_GETOPT_H */ - -/* Define if you have the header file. */ -#define HAVE_LIMITS_H 1 - -/* Define if you have the header file. */ -/* #undef HAVE_MALLOC_H */ - -/* Define if you have the header file. */ -#define HAVE_MEMORY_H 1 - -/* Define if you have the header file. */ -#define HAVE_STDARG_H 1 - -/* Define if you have the header file. */ -#define HAVE_STDLIB_H 1 - -/* Define if you have the header file. */ -#define HAVE_STRING_H 1 - -/* Define if you have the header file. */ #define HAVE_SYS_SELECT_H 1 +#define HAVE_SYS_WAIT_H 1 +#define HAVE_WAITPID 1 -/* Define if you have the header file. */ -#define HAVE_SYS_SOCKET_H 1 - -/* Define if you have the header file. */ -/* #undef HAVE_SYS_SYSTEMINFO_H */ - -/* Define if you have the header file. */ -#define HAVE_SYS_TIME_H 1 - -/* Define if you have the header file. */ -#define HAVE_SYS_TYPES_H 1 - -/* Define if you have the header file. */ -#define HAVE_UNISTD_H 1 - -/* Name of package */ -#define PACKAGE "fvwm" - -/* Version number of package */ -#define VERSION "2.2.5" - - -#ifdef STDC_HEADERS -# include -# include -#else -# ifdef HAVE_STRING_H -# include -# else -# include -# endif -# ifdef HAVE_MEMORY_H -# include -# endif -# ifdef HAVE_STDLIB_H -# include -# endif -# ifdef HAVE_MALLOC_H -# include -# endif -# ifndef HAVE_STRCHR -# define strchr(_s,_c) index((_s),(_c)) -# define strrchr(_s,_c) rindex((_s),(_c)) -# endif -#endif - -#ifndef HAVE_MEMCPY -# define memcpy(_d,_s,_l) bcopy((_s),(_d),(_l)) -#endif -#ifndef HAVE_MEMMOVE -# define memmove(_d,_s,_l) bcopy((_s),(_d),(_l)) -#endif - -#if HAVE_SYS_TYPES_H -# include -#endif - -#if HAVE_UNISTD_H -# include -#endif +#include +#include +#include +#include #ifndef min -# define min(a,b) (((a)<(b)) ? (a) : (b)) +#define min(a, b) (((a) < (b)) ? (a) : (b)) #endif #ifndef max -# define max(a,b) (((a)>(b)) ? (a) : (b)) +#define max(a, b) (((a) > (b)) ? (a) : (b)) #endif #ifndef abs -# define abs(a) (((a)>=0)?(a):-(a)) +#define abs(a) (((a) >= 0) ? (a) : -(a)) #endif - Index: fvwm/fvwm/Makefile =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/Makefile,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/Makefile --- fvwm/fvwm/Makefile +++ fvwm/fvwm/Makefile @@ -5,7 +5,7 @@ PROG= fvwm SRCS= add_window.c bindings.c borders.c \ builtins.c colormaps.c colors.c complex.c decorations.c \ - events.c focus.c functions.c fvwm.c fvwmdebug.c icons.c \ + events.c exec.c focus.c functions.c fvwm.c fvwmdebug.c icons.c \ menus.c misc.c modconf.c module.c move.c \ placement.c read.c resize.c style.c \ virtual.c windows.c @@ -14,12 +14,20 @@ CPPFLAGS+= -DFVWM_MODULEDIR=\"$(FVWMLIBDIR)\" \ -DFVWMRC=\".fvwmrc\" \ -DFVWM_CONFIGDIR=\"$(FVWMLIBDIR)\" -LDADD+= -lXpm -lXt -lICE -lSM -lXext -lX11 -lxcb -lXdmcp -lXau +LDADD+= -lXpm -lXt -lICE -lSM -lXext -lX11 -lxcb -lXdmcp -lXau -lutil fvwm.1: fvwm2.1 sed -e "s,__projectroot__,${X11BASE}," ${.CURDIR}/fvwm2.1 > fvwm.1 CLEANFILES= fvwm.1 +SCRIPTS= fvwm_exec +SCRIPTSDIR= $(FVWMLIBDIR) + +.all: fvwm_exec + +fvwm_exec: fvwm_exec.c ${.CURDIR}/../config.h + ${CC} ${CFLAGS} ${CPPFLAGS} -o fvwm_exec fvwm_exec.c -lutil + .include .include Index: fvwm/fvwm/add_window.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/add_window.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/add_window.c --- fvwm/fvwm/add_window.c +++ fvwm/fvwm/add_window.c @@ -29,40 +29,40 @@ /** OR PERFORMANCE OF THIS SOFTWARE. **/ /*****************************************************************************/ - /********************************************************************** * * Add a new window, put the titlbar and other stuff around * the window * **********************************************************************/ -#include "config.h" - +#include #include -#include #include +#include + +#include "config.h" #include "fvwm.h" -#include -#include "screen.h" #include "misc.h" +#include "screen.h" #ifdef SHAPE -#include #include +#include #endif /* SHAPE */ #include "module.h" -/* Used to parse command line of clients for specific desk requests. */ -/* Todo: check for multiple desks. */ +/* Parse client command line for desktop hints (-workspace N, -xrm). + * Only a single desk resource is checked; multiple -workspace flags + * are not handled. */ static XrmDatabase db; -static XrmOptionDescRec table [] = { - /* Want to accept "-workspace N" or -xrm "fvwm*desk:N" as options - * to specify the desktop. I have to include dummy options that - * are meaningless since Xrm seems to allow -w to match -workspace - * if there would be no ambiguity. */ - {"-workspacf", "*junk", XrmoptionSepArg, (caddr_t) NULL}, - {"-workspace", "*desk", XrmoptionSepArg, (caddr_t) NULL}, - {"-xrn", NULL, XrmoptionResArg, (caddr_t) NULL}, - {"-xrm", NULL, XrmoptionResArg, (caddr_t) NULL}, +static XrmOptionDescRec table[] = { + /* Want to accept "-workspace N" or -xrm "fvwm*desk:N" as options + * to specify the desktop. I have to include dummy options that + * are meaningless since Xrm seems to allow -w to match -workspace + * if there would be no ambiguity. */ + {"-workspacf", "*junk", XrmoptionSepArg, (caddr_t)NULL}, + {"-workspace", "*desk", XrmoptionSepArg, (caddr_t)NULL}, + {"-xrn", NULL, XrmoptionResArg, (caddr_t)NULL}, + {"-xrm", NULL, XrmoptionResArg, (caddr_t)NULL}, }; extern char *IconPath; @@ -83,701 +83,672 @@ static void merge_styles(name_list *, name_list *); /* prototype */ * iconm - flag to tell if this is an icon manager window * ***********************************************************************/ -FvwmWindow *AddWindow(Window w) +FvwmWindow * +AddWindow(Window w) { - FvwmWindow *tmp_win; /* new fvwm window structure */ - unsigned long valuemask; /* mask for create windows */ + FvwmWindow *tmp_win; /* new fvwm window structure */ + unsigned long valuemask; /* mask for create windows */ #if defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE) - Pixmap TexturePixmap = None, TexturePixmapSave = None; + Pixmap TexturePixmap = None, TexturePixmapSave = None; #endif - unsigned long valuemask_save = 0; - XSetWindowAttributes attributes; /* attributes for create windows */ - name_list styles; /* area for merged styles */ - int i,width,height; - int a,b; -/* RBW - 11/02/1998 */ - int tmpno1 = -1, tmpno2 = -1, tmpno3 = -1, spargs = 0; -/**/ - extern Bool NeedToResizeToo; - extern FvwmWindow *colormap_win; - int client_argc; - char **client_argv = NULL, *str_type; - Bool status; - XrmValue rm_value; - XTextProperty text_prop; - extern Boolean PPosOverride; - - NeedToResizeToo = False; - /* allocate space for the fvwm window */ - tmp_win = (FvwmWindow *)calloc(1, sizeof(FvwmWindow)); - if (tmp_win == (FvwmWindow *)0) - { - return NULL; - } - tmp_win->flags = 0; - tmp_win->tmpflags.ViewportMoved = 0; - tmp_win->tmpflags.IconifiedByParent = 0; - tmp_win->w = w; - - tmp_win->cmap_windows = (Window *)NULL; + unsigned long valuemask_save = 0; + XSetWindowAttributes attributes; /* attributes for create windows */ + name_list styles; /* area for merged styles */ + int i, width, height; + int a, b; + /* RBW - 11/02/1998 */ + int tmpno1 = -1, tmpno2 = -1, tmpno3 = -1, spargs = 0; + /**/ + extern Bool NeedToResizeToo; + extern FvwmWindow *colormap_win; + int client_argc; + char **client_argv = NULL, *str_type; + Bool status; + XrmValue rm_value; + XTextProperty text_prop; + extern Boolean PPosOverride; + + NeedToResizeToo = False; + /* allocate space for the fvwm window */ + tmp_win = (FvwmWindow *)calloc(1, sizeof(FvwmWindow)); + if (tmp_win == (FvwmWindow *)0) { + return NULL; + } + tmp_win->flags = 0; + tmp_win->tmpflags.ViewportMoved = 0; + tmp_win->tmpflags.IconifiedByParent = 0; + tmp_win->w = w; + + tmp_win->cmap_windows = (Window *)NULL; #ifdef MINI_ICONS - tmp_win->mini_pixmap_file = NULL; - tmp_win->mini_icon = NULL; + tmp_win->mini_pixmap_file = NULL; + tmp_win->mini_icon = NULL; #endif - if(!PPosOverride) - if (XGetGeometry(dpy, tmp_win->w, &JunkRoot, &JunkX, &JunkY, - &JunkWidth, &JunkHeight, &JunkBW, &JunkDepth) == 0) - { - free((char *)tmp_win); - return(NULL); - } - if ( XGetWMName(dpy, tmp_win->w, &text_prop) != 0 ) - tmp_win->name = (char *)text_prop.value; - else - tmp_win->name = NoName; - - /* removing NoClass change for now... */ -#if 0 - tmp_win->class.res_name = tmp_win->class.res_class = NULL; -#else - tmp_win->class.res_name = NoResource; - tmp_win->class.res_class = NoClass; -#endif /* 0 */ - XGetClassHint(dpy, tmp_win->w, &tmp_win->class); + if (!PPosOverride) + if (XGetGeometry(dpy, tmp_win->w, &JunkRoot, &JunkX, &JunkY, + &JunkWidth, &JunkHeight, &JunkBW, &JunkDepth) == 0) { + free((char *)tmp_win); + return (NULL); + } + if (XGetWMName(dpy, tmp_win->w, &text_prop) != 0) + tmp_win->name = (char *)text_prop.value; + else + tmp_win->name = NoName; + + tmp_win->class.res_name = NoResource; + tmp_win->class.res_class = NoClass; + XGetClassHint(dpy, tmp_win->w, &tmp_win->class); #if 1 - if (tmp_win->class.res_name == NULL) - tmp_win->class.res_name = NoResource; - if (tmp_win->class.res_class == NULL) - tmp_win->class.res_class = NoClass; + if (tmp_win->class.res_name == NULL) + tmp_win->class.res_name = NoResource; + if (tmp_win->class.res_class == NULL) + tmp_win->class.res_class = NoClass; #endif /* 1 */ - FetchWmProtocols (tmp_win); - FetchWmColormapWindows (tmp_win); - if(!(XGetWindowAttributes(dpy,tmp_win->w,&(tmp_win->attr)))) - tmp_win->attr.colormap = Scr.FvwmRoot.attr.colormap; + FetchWmProtocols(tmp_win); + FetchWmColormapWindows(tmp_win); + if (!(XGetWindowAttributes(dpy, tmp_win->w, &(tmp_win->attr)))) + tmp_win->attr.colormap = Scr.FvwmRoot.attr.colormap; - tmp_win->wmhints = XGetWMHints(dpy, tmp_win->w); + tmp_win->wmhints = XGetWMHints(dpy, tmp_win->w); - if(XGetTransientForHint(dpy, tmp_win->w, &tmp_win->transientfor)) - tmp_win->flags |= TRANSIENT; - else - tmp_win->flags &= ~TRANSIENT; + if (XGetTransientForHint(dpy, tmp_win->w, &tmp_win->transientfor)) + tmp_win->flags |= TRANSIENT; + else + tmp_win->flags &= ~TRANSIENT; - tmp_win->old_bw = tmp_win->attr.border_width; + tmp_win->old_bw = tmp_win->attr.border_width; #ifdef SHAPE - if (ShapesSupported) - { - int xws, yws, xbs, ybs; - unsigned wws, hws, wbs, hbs; - int boundingShaped, clipShaped; - - XShapeSelectInput (dpy, tmp_win->w, ShapeNotifyMask); - XShapeQueryExtents (dpy, tmp_win->w, - &boundingShaped, &xws, &yws, &wws, &hws, - &clipShaped, &xbs, &ybs, &wbs, &hbs); - tmp_win->wShaped = boundingShaped; - } + if (ShapesSupported) { + int xws, yws, xbs, ybs; + unsigned wws, hws, wbs, hbs; + int boundingShaped, clipShaped; + + XShapeSelectInput(dpy, tmp_win->w, ShapeNotifyMask); + XShapeQueryExtents(dpy, tmp_win->w, &boundingShaped, &xws, &yws, + &wws, &hws, &clipShaped, &xbs, &ybs, &wbs, &hbs); + tmp_win->wShaped = boundingShaped; + } #endif /* SHAPE */ + /* if the window is in the NoTitle list, or is a transient, + * dont decorate it. + * If its a transient, and DecorateTransients was specified, + * decorate anyway + */ + /* Assume that we'll decorate */ + tmp_win->flags |= BORDER; + tmp_win->flags |= TITLE; - /* if the window is in the NoTitle list, or is a transient, - * dont decorate it. - * If its a transient, and DecorateTransients was specified, - * decorate anyway - */ - /* Assume that we'll decorate */ - tmp_win->flags |= BORDER; - tmp_win->flags |= TITLE; + LookInList(tmp_win, &styles); /* get merged styles */ - LookInList(tmp_win, &styles); /* get merged styles */ - - tmp_win->IconBoxes = styles.IconBoxes; /* copy iconboxes ptr (if any) */ - tmp_win->buttons = styles.on_buttons; /* on and off buttons combined. */ + tmp_win->IconBoxes = styles.IconBoxes; /* copy iconboxes ptr (if any) */ + tmp_win->buttons = styles.on_buttons; /* on and off buttons combined. */ #ifdef USEDECOR - /* search for a UseDecor tag in the Style */ - tmp_win->fl = NULL; - if (styles.Decor != NULL) { - FvwmDecor *fl = &Scr.DefaultDecor; - for (; fl; fl = fl->next) - if (strcasecmp(styles.Decor,fl->tag)==0) { - tmp_win->fl = fl; - break; - } - } - if (tmp_win->fl == NULL) - tmp_win->fl = &Scr.DefaultDecor; + /* search for a UseDecor tag in the Style */ + tmp_win->fl = NULL; + if (styles.Decor != NULL) { + FvwmDecor *fl = &Scr.DefaultDecor; + for (; fl; fl = fl->next) + if (strcasecmp(styles.Decor, fl->tag) == 0) { + tmp_win->fl = fl; + break; + } + } + if (tmp_win->fl == NULL) + tmp_win->fl = &Scr.DefaultDecor; #endif - tmp_win->title_height = GetDecor(tmp_win,TitleHeight) + tmp_win->bw; + tmp_win->title_height = GetDecor(tmp_win, TitleHeight) + tmp_win->bw; - GetMwmHints(tmp_win); - GetOlHints(tmp_win); + GetMwmHints(tmp_win); + GetOlHints(tmp_win); - SelectDecor(tmp_win,styles.on_flags,styles.border_width,styles.resize_width); + SelectDecor( + tmp_win, styles.on_flags, styles.border_width, styles.resize_width); #ifdef SHAPE - /* set boundary width to zero for shaped windows */ - if (tmp_win->wShaped) tmp_win->boundary_width = 0; + /* set boundary width to zero for shaped windows */ + if (tmp_win->wShaped) + tmp_win->boundary_width = 0; #endif /* SHAPE */ - tmp_win->flags |= styles.on_flags & ALL_COMMON_FLAGS; - /* find a suitable icon pixmap */ - if(styles.on_flags & ICON_FLAG) - { - /* an icon was specified */ - tmp_win->icon_bitmap_file = styles.value; - } - else if((tmp_win->wmhints) - &&(tmp_win->wmhints->flags & (IconWindowHint|IconPixmapHint))) - { - /* window has its own icon */ - tmp_win->icon_bitmap_file = NULL; - } - else - { - /* use default icon */ - tmp_win->icon_bitmap_file = Scr.DefaultIcon; - } + tmp_win->flags |= styles.on_flags & ALL_COMMON_FLAGS; + /* find a suitable icon pixmap */ + if (styles.on_flags & ICON_FLAG) { + /* an icon was specified */ + tmp_win->icon_bitmap_file = styles.value; + } else if ((tmp_win->wmhints) && + (tmp_win->wmhints->flags & + (IconWindowHint | IconPixmapHint))) { + /* window has its own icon */ + tmp_win->icon_bitmap_file = NULL; + } else { + /* use default icon */ + tmp_win->icon_bitmap_file = Scr.DefaultIcon; + } #ifdef MINI_ICONS - if (styles.on_flags & MINIICON_FLAG) { - tmp_win->mini_pixmap_file = styles.mini_value; - } - else { - tmp_win->mini_pixmap_file = NULL; - } + if (styles.on_flags & MINIICON_FLAG) { + tmp_win->mini_pixmap_file = styles.mini_value; + } else { + tmp_win->mini_pixmap_file = NULL; + } #endif - GetWindowSizeHints (tmp_win); - - /* Tentative size estimate */ - tmp_win->frame_width = tmp_win->attr.width+2*tmp_win->boundary_width; - tmp_win->frame_height = tmp_win->attr.height + tmp_win->title_height+ - 2*tmp_win->boundary_width; - - ConstrainSize(tmp_win, &tmp_win->frame_width, &tmp_win->frame_height, False, - 0, 0); - - /* Find out if the client requested a specific desk on the command line. */ - /* RBW - 11/20/1998 - allow a desk of -1 to work. */ - if (XGetCommand (dpy, tmp_win->w, &client_argv, &client_argc)) { - XrmParseCommand (&db, table, 4, "fvwm", &client_argc, client_argv); - XFreeStringList(client_argv); - status = XrmGetResource (db, "fvwm.desk", "Fvwm.Desk", - &str_type, &rm_value); - if ((status == True) && (rm_value.size != 0)) { - styles.Desk = atoi(rm_value.addr); - /* RBW - 11/20/1998 */ - if (styles.Desk > -1) - { - styles.Desk++; - } - /**/ - styles.on_flags |= STARTSONDESK_FLAG; - } -/* RBW - 11/02/1998 */ -/* RBW - 11/20/1998 - allow desk or page specs of -1 to work. */ - /* Handle the X Resource equivalent of StartsOnPage. */ - status = XrmGetResource (db, "fvwm.page", "Fvwm.Page", &str_type, - &rm_value); - if ((status == True) && (rm_value.size != 0)) { - spargs = sscanf (rm_value.addr, "%d %d %d", &tmpno1, &tmpno2, - &tmpno3); - switch (spargs) - { - case 1: - { - styles.on_flags |= STARTSONDESK_FLAG; - styles.Desk = (tmpno1 > -1) ? tmpno1 + 1 : tmpno1; - break; - } - case 2: - { - styles.on_flags |= STARTSONDESK_FLAG; - styles.PageX = (tmpno1 > -1) ? tmpno1 + 1 : tmpno1; - styles.PageY = (tmpno2 > -1) ? tmpno2 + 1 : tmpno2; - break; - } - case 3: - { - styles.on_flags |= STARTSONDESK_FLAG; - styles.Desk = (tmpno1 > -1) ? tmpno1 + 1 : tmpno1; - styles.PageX = (tmpno2 > -1) ? tmpno2 + 1 : tmpno2; - styles.PageY = (tmpno3 > -1) ? tmpno3 + 1 : tmpno3; - break; - } - default: - { - break; - } - } - } -/**/ - XrmDestroyDatabase (db); - db = NULL; - } - -/* RBW - 11/02/1998 */ - if(!PlaceWindow(tmp_win, styles.on_flags, styles.Desk, styles.PageX, styles.PageY)) - return NULL; - - /* - * Make sure the client window still exists. We don't want to leave an - * orphan frame window if it doesn't. Since we now have the server - * grabbed, the window can't disappear later without having been - * reparented, so we'll get a DestroyNotify for it. We won't have - * gotten one for anything up to here, however. - */ - MyXGrabServer(dpy); - if(XGetGeometry(dpy, w, &JunkRoot, &JunkX, &JunkY, - &JunkWidth, &JunkHeight, - &JunkBW, &JunkDepth) == 0) - { - free((char *)tmp_win); - MyXUngrabServer(dpy); - return(NULL); - } - - XSetWindowBorderWidth (dpy, tmp_win->w,0); - if (XGetWMIconName (dpy, tmp_win->w, &text_prop)) - tmp_win->icon_name = (char *)text_prop.value; - if(tmp_win->icon_name==(char *)NULL) - tmp_win->icon_name = tmp_win->name; - - tmp_win->flags &= ~ICONIFIED; - tmp_win->flags &= ~ICON_UNMAPPED; - tmp_win->flags &= ~MAXIMIZED; - - tmp_win->TextPixel = Scr.StdColors.fore; - tmp_win->ReliefPixel = Scr.StdRelief.fore; - tmp_win->ShadowPixel = Scr.StdRelief.back; - tmp_win->BackPixel = Scr.StdColors.back; - - if(styles.ForeColor != NULL) { - XColor color; - - if((XParseColor (dpy, Scr.FvwmRoot.attr.colormap, styles.ForeColor, &color)) - &&(XAllocColor (dpy, Scr.FvwmRoot.attr.colormap, &color))) - { - tmp_win->TextPixel = color.pixel; - } - } - if(styles.BackColor != NULL) { - XColor color; - - if((XParseColor (dpy, Scr.FvwmRoot.attr.colormap,styles.BackColor, &color)) - &&(XAllocColor (dpy, Scr.FvwmRoot.attr.colormap, &color))) - - { - tmp_win->BackPixel = color.pixel; - } - tmp_win->ShadowPixel = GetShadow(tmp_win->BackPixel); - tmp_win->ReliefPixel = GetHilite(tmp_win->BackPixel); - } - - - /* add the window to the end of the fvwm list */ - tmp_win->next = Scr.FvwmRoot.next; - tmp_win->prev = &Scr.FvwmRoot; - while (tmp_win->next != NULL) - { - tmp_win->prev = tmp_win->next; - tmp_win->next = tmp_win->next->next; - } - /* tmp_win->prev points to the last window in the list, tmp_win->next is NULL. - Now fix the last window to point to tmp_win */ - tmp_win->prev->next = tmp_win; - - /* - RBW - 11/13/1998 - add it into the stacking order chain also. - This chain is anchored at both ends on Scr.FvwmRoot, there are - no null pointers. - */ - tmp_win->stack_next = Scr.FvwmRoot.stack_next; - Scr.FvwmRoot.stack_next->stack_prev = tmp_win; - tmp_win->stack_prev = &Scr.FvwmRoot; - Scr.FvwmRoot.stack_next = tmp_win; - - - /* create windows */ - tmp_win->frame_x = tmp_win->attr.x + tmp_win->old_bw - tmp_win->bw; - tmp_win->frame_y = tmp_win->attr.y + tmp_win->old_bw - tmp_win->bw; - - tmp_win->frame_width = tmp_win->attr.width+2*tmp_win->boundary_width; - tmp_win->frame_height = tmp_win->attr.height + tmp_win->title_height+ - 2*tmp_win->boundary_width; - ConstrainSize(tmp_win, &tmp_win->frame_width, &tmp_win->frame_height, False, - 0, 0); - - valuemask = CWBorderPixel | CWCursor | CWEventMask; - if(Scr.d_depth < 2) - { - attributes.background_pixmap = Scr.light_gray_pixmap; - if(tmp_win->flags & STICKY) - attributes.background_pixmap = Scr.sticky_gray_pixmap; - valuemask |= CWBackPixmap; - } - else - { - attributes.background_pixmap = None; - attributes.background_pixel = tmp_win->BackPixel; - valuemask |= CWBackPixel; - } - - attributes.border_pixel = tmp_win->ShadowPixel; - - attributes.cursor = Scr.FvwmCursors[DEFAULT]; - attributes.event_mask = (SubstructureRedirectMask | ButtonPressMask | - ButtonReleaseMask | EnterWindowMask | - LeaveWindowMask | ExposureMask | - VisibilityChangeMask); + GetWindowSizeHints(tmp_win); + + /* Tentative size estimate */ + tmp_win->frame_width = + tmp_win->attr.width + 2 * tmp_win->boundary_width; + tmp_win->frame_height = tmp_win->attr.height + tmp_win->title_height + + 2 * tmp_win->boundary_width; + + ConstrainSize(tmp_win, &tmp_win->frame_width, &tmp_win->frame_height, + False, 0, 0); + + /* Find out if the client requested a specific desk on the command line. + */ + /* RBW - 11/20/1998 - allow a desk of -1 to work. */ + if (XGetCommand(dpy, tmp_win->w, &client_argv, &client_argc)) { + XrmParseCommand( + &db, table, 4, "fvwm", &client_argc, client_argv); + XFreeStringList(client_argv); + status = XrmGetResource( + db, "fvwm.desk", "Fvwm.Desk", &str_type, &rm_value); + if ((status == True) && (rm_value.size != 0)) { + styles.Desk = atoi(rm_value.addr); + /* RBW - 11/20/1998 */ + if (styles.Desk > -1) { + styles.Desk++; + } + /**/ + styles.on_flags |= STARTSONDESK_FLAG; + } + /* RBW - 11/02/1998 */ + /* RBW - 11/20/1998 - allow desk or page specs of -1 to work. + */ + /* Handle the X Resource equivalent of StartsOnPage. */ + status = XrmGetResource( + db, "fvwm.page", "Fvwm.Page", &str_type, &rm_value); + if ((status == True) && (rm_value.size != 0)) { + spargs = sscanf(rm_value.addr, "%d %d %d", &tmpno1, + &tmpno2, &tmpno3); + switch (spargs) { + case 1: { + styles.on_flags |= STARTSONDESK_FLAG; + styles.Desk = + (tmpno1 > -1) ? tmpno1 + 1 : tmpno1; + break; + } + case 2: { + styles.on_flags |= STARTSONDESK_FLAG; + styles.PageX = + (tmpno1 > -1) ? tmpno1 + 1 : tmpno1; + styles.PageY = + (tmpno2 > -1) ? tmpno2 + 1 : tmpno2; + break; + } + case 3: { + styles.on_flags |= STARTSONDESK_FLAG; + styles.Desk = + (tmpno1 > -1) ? tmpno1 + 1 : tmpno1; + styles.PageX = + (tmpno2 > -1) ? tmpno2 + 1 : tmpno2; + styles.PageY = + (tmpno3 > -1) ? tmpno3 + 1 : tmpno3; + break; + } + default: { + break; + } + } + } + /**/ + XrmDestroyDatabase(db); + db = NULL; + } + + /* RBW - 11/02/1998 */ + if (!PlaceWindow(tmp_win, styles.on_flags, styles.Desk, styles.PageX, + styles.PageY)) + return NULL; + + /* + * Make sure the client window still exists. We don't want to leave an + * orphan frame window if it doesn't. Since we now have the server + * grabbed, the window can't disappear later without having been + * reparented, so we'll get a DestroyNotify for it. We won't have + * gotten one for anything up to here, however. + */ + MyXGrabServer(dpy); + if (XGetGeometry(dpy, w, &JunkRoot, &JunkX, &JunkY, &JunkWidth, + &JunkHeight, &JunkBW, &JunkDepth) == 0) { + free((char *)tmp_win); + MyXUngrabServer(dpy); + return (NULL); + } + + XSetWindowBorderWidth(dpy, tmp_win->w, 0); + if (XGetWMIconName(dpy, tmp_win->w, &text_prop)) + tmp_win->icon_name = (char *)text_prop.value; + if (tmp_win->icon_name == (char *)NULL) + tmp_win->icon_name = tmp_win->name; + + tmp_win->flags &= ~ICONIFIED; + tmp_win->flags &= ~ICON_UNMAPPED; + tmp_win->flags &= ~MAXIMIZED; + + tmp_win->TextPixel = Scr.StdColors.fore; + tmp_win->ReliefPixel = Scr.StdRelief.fore; + tmp_win->ShadowPixel = Scr.StdRelief.back; + tmp_win->BackPixel = Scr.StdColors.back; + + if (styles.ForeColor != NULL) { + XColor color; + + if ((XParseColor(dpy, Scr.FvwmRoot.attr.colormap, + styles.ForeColor, &color)) && + (XAllocColor(dpy, Scr.FvwmRoot.attr.colormap, &color))) { + tmp_win->TextPixel = color.pixel; + } + } + if (styles.BackColor != NULL) { + XColor color; + + if ((XParseColor(dpy, Scr.FvwmRoot.attr.colormap, + styles.BackColor, &color)) && + (XAllocColor(dpy, Scr.FvwmRoot.attr.colormap, &color))) { + tmp_win->BackPixel = color.pixel; + } + tmp_win->ShadowPixel = GetShadow(tmp_win->BackPixel); + tmp_win->ReliefPixel = GetHilite(tmp_win->BackPixel); + } + + /* add the window to the end of the fvwm list */ + tmp_win->next = Scr.FvwmRoot.next; + tmp_win->prev = &Scr.FvwmRoot; + while (tmp_win->next != NULL) { + tmp_win->prev = tmp_win->next; + tmp_win->next = tmp_win->next->next; + } + /* tmp_win->prev points to the last window in the list, tmp_win->next is + NULL. Now fix the last window to point to tmp_win */ + tmp_win->prev->next = tmp_win; + + /* + RBW - 11/13/1998 - add it into the stacking order chain also. + This chain is anchored at both ends on Scr.FvwmRoot, there are + no null pointers. + */ + tmp_win->stack_next = Scr.FvwmRoot.stack_next; + Scr.FvwmRoot.stack_next->stack_prev = tmp_win; + tmp_win->stack_prev = &Scr.FvwmRoot; + Scr.FvwmRoot.stack_next = tmp_win; + + /* create windows */ + tmp_win->frame_x = tmp_win->attr.x + tmp_win->old_bw - tmp_win->bw; + tmp_win->frame_y = tmp_win->attr.y + tmp_win->old_bw - tmp_win->bw; + + tmp_win->frame_width = + tmp_win->attr.width + 2 * tmp_win->boundary_width; + tmp_win->frame_height = tmp_win->attr.height + tmp_win->title_height + + 2 * tmp_win->boundary_width; + ConstrainSize(tmp_win, &tmp_win->frame_width, &tmp_win->frame_height, + False, 0, 0); + + valuemask = CWBorderPixel | CWCursor | CWEventMask; + if (Scr.d_depth < 2) { + attributes.background_pixmap = Scr.light_gray_pixmap; + if (tmp_win->flags & STICKY) + attributes.background_pixmap = Scr.sticky_gray_pixmap; + valuemask |= CWBackPixmap; + } else { + attributes.background_pixmap = None; + attributes.background_pixel = tmp_win->BackPixel; + valuemask |= CWBackPixel; + } + + attributes.border_pixel = tmp_win->ShadowPixel; + + attributes.cursor = Scr.FvwmCursors[DEFAULT]; + attributes.event_mask = + (SubstructureRedirectMask | ButtonPressMask | ButtonReleaseMask | + EnterWindowMask | LeaveWindowMask | ExposureMask | + VisibilityChangeMask); #if defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE) - if ((GetDecor(tmp_win,BorderStyle.inactive.style) & ButtonFaceTypeMask) - == TiledPixmapButton) - TexturePixmap = GetDecor(tmp_win,BorderStyle.inactive.u.p->picture); - - if (TexturePixmap) { - TexturePixmapSave = attributes.background_pixmap; - attributes.background_pixmap = TexturePixmap; - valuemask_save = valuemask; - valuemask = (valuemask & ~CWBackPixel) | CWBackPixmap; - } + if ((GetDecor(tmp_win, BorderStyle.inactive.style) & + ButtonFaceTypeMask) == TiledPixmapButton) + TexturePixmap = + GetDecor(tmp_win, BorderStyle.inactive.u.p->picture); + + if (TexturePixmap) { + TexturePixmapSave = attributes.background_pixmap; + attributes.background_pixmap = TexturePixmap; + valuemask_save = valuemask; + valuemask = (valuemask & ~CWBackPixel) | CWBackPixmap; + } #endif - /* What the heck, we'll always reparent everything from now on! */ - tmp_win->frame = - XCreateWindow (dpy, Scr.Root, tmp_win->frame_x,tmp_win->frame_y, - tmp_win->frame_width, tmp_win->frame_height, - tmp_win->bw,CopyFromParent, InputOutput, - CopyFromParent, - valuemask, - &attributes); + /* What the heck, we'll always reparent everything from now on! */ + tmp_win->frame = XCreateWindow(dpy, Scr.Root, tmp_win->frame_x, + tmp_win->frame_y, tmp_win->frame_width, tmp_win->frame_height, + tmp_win->bw, CopyFromParent, InputOutput, CopyFromParent, valuemask, + &attributes); #if defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE) - if (TexturePixmap) { - attributes.background_pixmap = TexturePixmapSave; - valuemask = valuemask_save; - } + if (TexturePixmap) { + attributes.background_pixmap = TexturePixmapSave; + valuemask = valuemask_save; + } #endif - attributes.save_under = FALSE; - attributes.event_mask &= ~VisibilityChangeMask; - - /* Thats not all, we'll double-reparent the window ! */ - attributes.cursor = Scr.FvwmCursors[DEFAULT]; - - /* make sure this does not have a BackPixel or BackPixmap so that - that when the window dies there is no flash of BackPixel/BackPixmap */ - valuemask_save = valuemask; - valuemask = valuemask & ~CWBackPixel & ~CWBackPixmap; - tmp_win->Parent = - XCreateWindow (dpy, tmp_win->frame, - tmp_win->boundary_width, - tmp_win->boundary_width+tmp_win->title_height, - (tmp_win->frame_width - 2*tmp_win->boundary_width), - (tmp_win->frame_height - 2*tmp_win->boundary_width - - tmp_win->title_height),tmp_win->bw, CopyFromParent, - InputOutput,CopyFromParent, valuemask,&attributes); - valuemask = valuemask_save; - - attributes.event_mask = (ButtonPressMask|ButtonReleaseMask|ExposureMask| - EnterWindowMask|LeaveWindowMask); - tmp_win->title_x = tmp_win->title_y = 0; - tmp_win->title_w = 0; - tmp_win->title_width = tmp_win->frame_width - 2*tmp_win->corner_width - - 3 + tmp_win->bw; - if(tmp_win->title_width < 1) - tmp_win->title_width = 1; - if(tmp_win->flags & BORDER) - { + attributes.save_under = FALSE; + attributes.event_mask &= ~VisibilityChangeMask; + + /* Thats not all, we'll double-reparent the window ! */ + attributes.cursor = Scr.FvwmCursors[DEFAULT]; + + /* make sure this does not have a BackPixel or BackPixmap so that + that when the window dies there is no flash of BackPixel/BackPixmap + */ + valuemask_save = valuemask; + valuemask = valuemask & ~CWBackPixel & ~CWBackPixmap; + tmp_win->Parent = + XCreateWindow(dpy, tmp_win->frame, tmp_win->boundary_width, + tmp_win->boundary_width + tmp_win->title_height, + (tmp_win->frame_width - 2 * tmp_win->boundary_width), + (tmp_win->frame_height - 2 * tmp_win->boundary_width - + tmp_win->title_height), + tmp_win->bw, CopyFromParent, InputOutput, CopyFromParent, + valuemask, &attributes); + valuemask = valuemask_save; + + attributes.event_mask = + (ButtonPressMask | ButtonReleaseMask | ExposureMask | + EnterWindowMask | LeaveWindowMask); + tmp_win->title_x = tmp_win->title_y = 0; + tmp_win->title_w = 0; + tmp_win->title_width = + tmp_win->frame_width - 2 * tmp_win->corner_width - 3 + tmp_win->bw; + if (tmp_win->title_width < 1) + tmp_win->title_width = 1; + if (tmp_win->flags & BORDER) { #if defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE) - if (TexturePixmap) { - TexturePixmapSave = attributes.background_pixmap; - attributes.background_pixmap = TexturePixmap; - valuemask_save = valuemask; - valuemask = (valuemask & ~CWBackPixel) | CWBackPixmap; - } + if (TexturePixmap) { + TexturePixmapSave = attributes.background_pixmap; + attributes.background_pixmap = TexturePixmap; + valuemask_save = valuemask; + valuemask = (valuemask & ~CWBackPixel) | CWBackPixmap; + } #endif - /* Just dump the windows any old place and left SetupFrame take - * care of the mess */ - for(i=0;i<4;i++) - { - attributes.cursor = Scr.FvwmCursors[TOP_LEFT+i]; - tmp_win->corners[i] = - XCreateWindow (dpy, tmp_win->frame, 0,0, - tmp_win->corner_width, tmp_win->corner_width, - 0, CopyFromParent,InputOutput, - CopyFromParent, - valuemask, - &attributes); - } + /* Just dump the windows any old place and left SetupFrame take + * care of the mess */ + for (i = 0; i < 4; i++) { + attributes.cursor = Scr.FvwmCursors[TOP_LEFT + i]; + tmp_win->corners[i] = XCreateWindow(dpy, tmp_win->frame, + 0, 0, tmp_win->corner_width, tmp_win->corner_width, + 0, CopyFromParent, InputOutput, CopyFromParent, + valuemask, &attributes); + } #if defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE) - if (TexturePixmap) { - attributes.background_pixmap = TexturePixmapSave; - valuemask = valuemask_save; - } + if (TexturePixmap) { + attributes.background_pixmap = TexturePixmapSave; + valuemask = valuemask_save; + } #endif - } - - if (tmp_win->flags & TITLE) - { - tmp_win->title_x = tmp_win->boundary_width +tmp_win->title_height+1; - tmp_win->title_y = tmp_win->boundary_width; - attributes.cursor = Scr.FvwmCursors[TITLE_CURSOR]; - tmp_win->title_w = - XCreateWindow (dpy, tmp_win->frame, tmp_win->title_x, tmp_win->title_y, - tmp_win->title_width, tmp_win->title_height,0, - CopyFromParent, InputOutput, CopyFromParent, - valuemask,&attributes); - attributes.cursor = Scr.FvwmCursors[SYS]; - for(i=4;i>=0;i--) - { - if((ileft_w[i] > 0)) - { + } + + if (tmp_win->flags & TITLE) { + tmp_win->title_x = + tmp_win->boundary_width + tmp_win->title_height + 1; + tmp_win->title_y = tmp_win->boundary_width; + attributes.cursor = Scr.FvwmCursors[TITLE_CURSOR]; + tmp_win->title_w = XCreateWindow(dpy, tmp_win->frame, + tmp_win->title_x, tmp_win->title_y, tmp_win->title_width, + tmp_win->title_height, 0, CopyFromParent, InputOutput, + CopyFromParent, valuemask, &attributes); + attributes.cursor = Scr.FvwmCursors[SYS]; + for (i = 4; i >= 0; i--) { + if ((i < Scr.nr_left_buttons) && + (tmp_win->left_w[i] > 0)) { #if defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE) - if (TexturePixmap - && GetDecor(tmp_win,left_buttons[i].flags) & UseBorderStyle) { - TexturePixmapSave = attributes.background_pixmap; - attributes.background_pixmap = TexturePixmap; - valuemask_save = valuemask; - valuemask = (valuemask & ~CWBackPixel) | CWBackPixmap; - } + if (TexturePixmap && + GetDecor(tmp_win, left_buttons[i].flags) & + UseBorderStyle) { + TexturePixmapSave = + attributes.background_pixmap; + attributes.background_pixmap = + TexturePixmap; + valuemask_save = valuemask; + valuemask = (valuemask & ~CWBackPixel) | + CWBackPixmap; + } #endif - tmp_win->left_w[i] = - XCreateWindow (dpy, tmp_win->frame, tmp_win->title_height*i, 0, - tmp_win->title_height, tmp_win->title_height, 0, - CopyFromParent, InputOutput, - CopyFromParent, - valuemask, - &attributes); + tmp_win->left_w[i] = XCreateWindow(dpy, + tmp_win->frame, tmp_win->title_height * i, + 0, tmp_win->title_height, + tmp_win->title_height, 0, CopyFromParent, + InputOutput, CopyFromParent, valuemask, + &attributes); #if defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE) - if (TexturePixmap - && GetDecor(tmp_win,left_buttons[i].flags) & UseBorderStyle) { - attributes.background_pixmap = TexturePixmapSave; - valuemask = valuemask_save; - } + if (TexturePixmap && + GetDecor(tmp_win, left_buttons[i].flags) & + UseBorderStyle) { + attributes.background_pixmap = + TexturePixmapSave; + valuemask = valuemask_save; + } #endif - } - else - tmp_win->left_w[i] = None; + } else + tmp_win->left_w[i] = None; - if((iright_w[i] >0)) { + if ((i < Scr.nr_right_buttons) && + (tmp_win->right_w[i] > 0)) { #if defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE) - if (TexturePixmap - && GetDecor(tmp_win,right_buttons[i].flags) & UseBorderStyle) { - TexturePixmapSave = attributes.background_pixmap; - attributes.background_pixmap = TexturePixmap; - valuemask_save = valuemask; - valuemask = (valuemask & ~CWBackPixel) | CWBackPixmap; - } + if (TexturePixmap && + GetDecor(tmp_win, right_buttons[i].flags) & + UseBorderStyle) { + TexturePixmapSave = + attributes.background_pixmap; + attributes.background_pixmap = + TexturePixmap; + valuemask_save = valuemask; + valuemask = (valuemask & ~CWBackPixel) | + CWBackPixmap; + } #endif - tmp_win->right_w[i] = - XCreateWindow (dpy, tmp_win->frame, - tmp_win->title_width- - tmp_win->title_height*(i+1), - 0, tmp_win->title_height, - tmp_win->title_height, - 0, CopyFromParent, InputOutput, - CopyFromParent, - valuemask, - &attributes); + tmp_win->right_w[i] = + XCreateWindow(dpy, tmp_win->frame, + tmp_win->title_width - + tmp_win->title_height * (i + 1), + 0, tmp_win->title_height, + tmp_win->title_height, 0, + CopyFromParent, InputOutput, + CopyFromParent, valuemask, &attributes); #if defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE) - if (TexturePixmap - && GetDecor(tmp_win,right_buttons[i].flags) & UseBorderStyle) { - attributes.background_pixmap = TexturePixmapSave; - valuemask = valuemask_save; - } + if (TexturePixmap && + GetDecor(tmp_win, right_buttons[i].flags) & + UseBorderStyle) { + attributes.background_pixmap = + TexturePixmapSave; + valuemask = valuemask_save; + } #endif - } - else - tmp_win->right_w[i] = None; + } else + tmp_win->right_w[i] = None; + } } - } - if(tmp_win->flags & BORDER) - { + if (tmp_win->flags & BORDER) { #if defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE) - if (TexturePixmap) { - TexturePixmapSave = attributes.background_pixmap; - attributes.background_pixmap = TexturePixmap; - valuemask_save = valuemask; - valuemask = (valuemask & ~CWBackPixel) | CWBackPixmap; - } + if (TexturePixmap) { + TexturePixmapSave = attributes.background_pixmap; + attributes.background_pixmap = TexturePixmap; + valuemask_save = valuemask; + valuemask = (valuemask & ~CWBackPixel) | CWBackPixmap; + } #endif - for(i=0;i<4;i++) - { - attributes.cursor = Scr.FvwmCursors[TOP+i]; - tmp_win->sides[i] = - XCreateWindow (dpy, tmp_win->frame, 0, 0, tmp_win->boundary_width, - tmp_win->boundary_width, 0, CopyFromParent, - InputOutput, CopyFromParent, - valuemask, - &attributes); - } + for (i = 0; i < 4; i++) { + attributes.cursor = Scr.FvwmCursors[TOP + i]; + tmp_win->sides[i] = XCreateWindow(dpy, tmp_win->frame, + 0, 0, tmp_win->boundary_width, + tmp_win->boundary_width, 0, CopyFromParent, + InputOutput, CopyFromParent, valuemask, + &attributes); + } #if defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE) - if (TexturePixmap) { - attributes.background_pixmap = TexturePixmapSave; - valuemask = valuemask_save; - } + if (TexturePixmap) { + attributes.background_pixmap = TexturePixmapSave; + valuemask = valuemask_save; + } #endif - } - + } #ifdef MINI_ICONS - if (tmp_win->mini_pixmap_file) { - tmp_win->mini_icon = CachePicture (dpy, Scr.Root, - IconPath, - PixmapPath, - tmp_win->mini_pixmap_file, - Scr.ColorLimit); - } - else { - tmp_win->mini_icon = NULL; - } + if (tmp_win->mini_pixmap_file) { + tmp_win->mini_icon = CachePicture(dpy, Scr.Root, IconPath, + PixmapPath, tmp_win->mini_pixmap_file, Scr.ColorLimit); + } else { + tmp_win->mini_icon = NULL; + } #endif - XMapSubwindows (dpy, tmp_win->frame); - XRaiseWindow(dpy,tmp_win->Parent); - XReparentWindow(dpy, tmp_win->w, tmp_win->Parent,0,0); - - valuemask = (CWEventMask | CWDontPropagate); - attributes.event_mask = (StructureNotifyMask | PropertyChangeMask | - EnterWindowMask | LeaveWindowMask | - ColormapChangeMask | FocusChangeMask); - - attributes.do_not_propagate_mask = ButtonPressMask | ButtonReleaseMask; - - XChangeWindowAttributes (dpy, tmp_win->w, valuemask, &attributes); - - XAddToSaveSet(dpy, tmp_win->w); - - /* - * Reparenting generates an UnmapNotify event, followed by a MapNotify. - * Set the map state to FALSE to prevent a transition back to - * WithdrawnState in HandleUnmapNotify. Map state gets set correctly - * again in HandleMapNotify. - */ - tmp_win->flags &= ~MAPPED; - width = tmp_win->frame_width; - tmp_win->frame_width = 0; - height = tmp_win->frame_height; - tmp_win->frame_height = 0; - SetupFrame (tmp_win, tmp_win->frame_x, tmp_win->frame_y,width,height, True); - - /* wait until the window is iconified and the icon window is mapped - * before creating the icon window - */ - tmp_win->icon_w = None; - GrabButtons(tmp_win); - GrabKeys(tmp_win); - - XSaveContext(dpy, tmp_win->w, FvwmContext, (caddr_t) tmp_win); - XSaveContext(dpy, tmp_win->frame, FvwmContext, (caddr_t) tmp_win); - XSaveContext(dpy, tmp_win->Parent, FvwmContext, (caddr_t) tmp_win); - if (tmp_win->flags & TITLE) - { - XSaveContext(dpy, tmp_win->title_w, FvwmContext, (caddr_t) tmp_win); - for(i=0;ileft_w[i], FvwmContext, (caddr_t) tmp_win); - for(i=0;iright_w[i] != None) - XSaveContext(dpy, tmp_win->right_w[i], FvwmContext, - (caddr_t) tmp_win); - } - if (tmp_win->flags & BORDER) - { - for(i=0;i<4;i++) - { - XSaveContext(dpy, tmp_win->sides[i], FvwmContext, (caddr_t) tmp_win); - XSaveContext(dpy,tmp_win->corners[i],FvwmContext, (caddr_t) tmp_win); + XMapSubwindows(dpy, tmp_win->frame); + XRaiseWindow(dpy, tmp_win->Parent); + XReparentWindow(dpy, tmp_win->w, tmp_win->Parent, 0, 0); + + valuemask = (CWEventMask | CWDontPropagate); + attributes.event_mask = + (StructureNotifyMask | PropertyChangeMask | EnterWindowMask | + LeaveWindowMask | ColormapChangeMask | FocusChangeMask); + + attributes.do_not_propagate_mask = ButtonPressMask | ButtonReleaseMask; + + XChangeWindowAttributes(dpy, tmp_win->w, valuemask, &attributes); + + XAddToSaveSet(dpy, tmp_win->w); + + /* + * Reparenting generates an UnmapNotify event, followed by a MapNotify. + * Set the map state to FALSE to prevent a transition back to + * WithdrawnState in HandleUnmapNotify. Map state gets set correctly + * again in HandleMapNotify. + */ + tmp_win->flags &= ~MAPPED; + width = tmp_win->frame_width; + tmp_win->frame_width = 0; + height = tmp_win->frame_height; + tmp_win->frame_height = 0; + SetupFrame( + tmp_win, tmp_win->frame_x, tmp_win->frame_y, width, height, True); + + /* wait until the window is iconified and the icon window is mapped + * before creating the icon window + */ + tmp_win->icon_w = None; + GrabButtons(tmp_win); + GrabKeys(tmp_win); + + XSaveContext(dpy, tmp_win->w, FvwmContext, (caddr_t)tmp_win); + XSaveContext(dpy, tmp_win->frame, FvwmContext, (caddr_t)tmp_win); + XSaveContext(dpy, tmp_win->Parent, FvwmContext, (caddr_t)tmp_win); + if (tmp_win->flags & TITLE) { + XSaveContext( + dpy, tmp_win->title_w, FvwmContext, (caddr_t)tmp_win); + for (i = 0; i < Scr.nr_left_buttons; i++) + XSaveContext(dpy, tmp_win->left_w[i], FvwmContext, + (caddr_t)tmp_win); + for (i = 0; i < Scr.nr_right_buttons; i++) + if (tmp_win->right_w[i] != None) + XSaveContext(dpy, tmp_win->right_w[i], + FvwmContext, (caddr_t)tmp_win); } - } - RaiseWindow(tmp_win); - KeepOnTop(); - MyXUngrabServer(dpy); - - XGetGeometry(dpy, tmp_win->w, &JunkRoot, &JunkX, &JunkY, - &JunkWidth, &JunkHeight, &JunkBW, &JunkDepth); - XTranslateCoordinates(dpy,tmp_win->frame,Scr.Root,JunkX,JunkY, - &a,&b,&JunkChild); - tmp_win->xdiff -= a; - tmp_win->ydiff -= b; - if((tmp_win->flags & ClickToFocus) || Scr.MouseFocusClickRaises) - { - /* need to grab all buttons for window that we are about to - * unhighlight */ - for(i=1;i<=3;i++) - if(Scr.buttons2grab & (1<frame,True, - ButtonPressMask, GrabModeSync,GrabModeAsync,None, - Scr.FvwmCursors[SYS]); - XGrabButton(dpy,(i),LockMask,tmp_win->frame,True, - ButtonPressMask, GrabModeSync,GrabModeAsync,None, - Scr.FvwmCursors[SYS]); -#else - /* should we accept any modifier on this button? */ - /* domivogt (2-Jan-1999): No. Or at least not like this. In the - * present form no button presses go through to the title bar - * anymore. They are all swallowed by the frame window. */ - XGrabButton(dpy,(i),AnyModifier,tmp_win->frame,True, - ButtonPressMask, GrabModeSync,GrabModeAsync,None, - Scr.FvwmCursors[SYS]); -#endif - } - } - BroadcastConfig(M_ADD_WINDOW,tmp_win); - - BroadcastName(M_WINDOW_NAME,tmp_win->w,tmp_win->frame, - (unsigned long)tmp_win,tmp_win->name); - BroadcastName(M_ICON_NAME,tmp_win->w,tmp_win->frame, - (unsigned long)tmp_win,tmp_win->icon_name); - if (tmp_win->icon_bitmap_file != NULL && - tmp_win->icon_bitmap_file != Scr.DefaultIcon) - BroadcastName(M_ICON_FILE,tmp_win->w,tmp_win->frame, - (unsigned long)tmp_win,tmp_win->icon_bitmap_file); - BroadcastName(M_RES_CLASS,tmp_win->w,tmp_win->frame, - (unsigned long)tmp_win,tmp_win->class.res_class); - BroadcastName(M_RES_NAME,tmp_win->w,tmp_win->frame, - (unsigned long)tmp_win,tmp_win->class.res_name); + if (tmp_win->flags & BORDER) { + for (i = 0; i < 4; i++) { + XSaveContext(dpy, tmp_win->sides[i], FvwmContext, + (caddr_t)tmp_win); + XSaveContext(dpy, tmp_win->corners[i], FvwmContext, + (caddr_t)tmp_win); + } + } + RaiseWindow(tmp_win); + KeepOnTop(); + MyXUngrabServer(dpy); + + XGetGeometry(dpy, tmp_win->w, &JunkRoot, &JunkX, &JunkY, &JunkWidth, + &JunkHeight, &JunkBW, &JunkDepth); + XTranslateCoordinates( + dpy, tmp_win->frame, Scr.Root, JunkX, JunkY, &a, &b, &JunkChild); + tmp_win->xdiff -= a; + tmp_win->ydiff -= b; + if ((tmp_win->flags & ClickToFocus) || Scr.MouseFocusClickRaises) { + /* need to grab all buttons for window that we are about to + * unhighlight */ + for (i = 1; i <= 3; i++) + if (Scr.buttons2grab & (1 << i)) { + /* should we accept any modifier on this button? + */ + /* domivogt (2-Jan-1999): No. Or at least not + * like this. In the present form no button + * presses go through to the title bar anymore. + * They are all swallowed by the frame window. + */ + XGrabButton(dpy, (i), AnyModifier, + tmp_win->frame, True, ButtonPressMask, + GrabModeSync, GrabModeAsync, None, + Scr.FvwmCursors[SYS]); + } + } + BroadcastConfig(M_ADD_WINDOW, tmp_win); + + BroadcastName(M_WINDOW_NAME, tmp_win->w, tmp_win->frame, + (unsigned long)tmp_win, tmp_win->name); + BroadcastName(M_ICON_NAME, tmp_win->w, tmp_win->frame, + (unsigned long)tmp_win, tmp_win->icon_name); + if (tmp_win->icon_bitmap_file != NULL && + tmp_win->icon_bitmap_file != Scr.DefaultIcon) + BroadcastName(M_ICON_FILE, tmp_win->w, tmp_win->frame, + (unsigned long)tmp_win, tmp_win->icon_bitmap_file); + BroadcastName(M_RES_CLASS, tmp_win->w, tmp_win->frame, + (unsigned long)tmp_win, tmp_win->class.res_class); + BroadcastName(M_RES_NAME, tmp_win->w, tmp_win->frame, + (unsigned long)tmp_win, tmp_win->class.res_name); #ifdef MINI_ICONS - if (tmp_win->mini_icon != NULL) - BroadcastMiniIcon(M_MINI_ICON, - tmp_win->w, tmp_win->frame, (unsigned long)tmp_win, - tmp_win->mini_icon->width, - tmp_win->mini_icon->height, - tmp_win->mini_icon->depth, - tmp_win->mini_icon->picture, - tmp_win->mini_icon->mask, - tmp_win->mini_pixmap_file); + if (tmp_win->mini_icon != NULL) + BroadcastMiniIcon(M_MINI_ICON, tmp_win->w, tmp_win->frame, + (unsigned long)tmp_win, tmp_win->mini_icon->width, + tmp_win->mini_icon->height, tmp_win->mini_icon->depth, + tmp_win->mini_icon->picture, tmp_win->mini_icon->mask, + tmp_win->mini_pixmap_file); #endif - FetchWmProtocols (tmp_win); - FetchWmColormapWindows (tmp_win); - if(!(XGetWindowAttributes(dpy,tmp_win->w,&(tmp_win->attr)))) - tmp_win->attr.colormap = Scr.FvwmRoot.attr.colormap; - if(NeedToResizeToo) - { - XWarpPointer(dpy, Scr.Root, Scr.Root, 0, 0, Scr.MyDisplayWidth, - Scr.MyDisplayHeight, - tmp_win->frame_x + (tmp_win->frame_width>>1), - tmp_win->frame_y + (tmp_win->frame_height>>1)); - Event.xany.type = ButtonPress; - Event.xbutton.button = 1; - Event.xbutton.x_root = tmp_win->frame_x + (tmp_win->frame_width>>1); - Event.xbutton.y_root = tmp_win->frame_y + (tmp_win->frame_height>>1); - Event.xbutton.x = (tmp_win->frame_width>>1); - Event.xbutton.y = (tmp_win->frame_height>>1); - Event.xbutton.subwindow = None; - Event.xany.window = tmp_win->w; - resize_window(&Event , tmp_win->w, tmp_win, C_WINDOW, "", 0); - } - InstallWindowColormaps(colormap_win); - return (tmp_win); + FetchWmProtocols(tmp_win); + FetchWmColormapWindows(tmp_win); + if (!(XGetWindowAttributes(dpy, tmp_win->w, &(tmp_win->attr)))) + tmp_win->attr.colormap = Scr.FvwmRoot.attr.colormap; + if (NeedToResizeToo) { + XWarpPointer(dpy, Scr.Root, Scr.Root, 0, 0, Scr.MyDisplayWidth, + Scr.MyDisplayHeight, + tmp_win->frame_x + (tmp_win->frame_width >> 1), + tmp_win->frame_y + (tmp_win->frame_height >> 1)); + Event.xany.type = ButtonPress; + Event.xbutton.button = 1; + Event.xbutton.x_root = + tmp_win->frame_x + (tmp_win->frame_width >> 1); + Event.xbutton.y_root = + tmp_win->frame_y + (tmp_win->frame_height >> 1); + Event.xbutton.x = (tmp_win->frame_width >> 1); + Event.xbutton.y = (tmp_win->frame_height >> 1); + Event.xbutton.subwindow = None; + Event.xany.window = tmp_win->w; + resize_window(&Event, tmp_win->w, tmp_win, C_WINDOW, "", 0); + } + InstallWindowColormaps(colormap_win); + return (tmp_win); } /*********************************************************************** @@ -789,76 +760,71 @@ FvwmWindow *AddWindow(Window w) * tmp_win - the fvwm window structure to use * ***********************************************************************/ -void GrabButtons(FvwmWindow *tmp_win) +void +GrabButtons(FvwmWindow *tmp_win) { - Binding *MouseEntry; - - MouseEntry = Scr.AllBindings; - while(MouseEntry != (Binding *)0) - { - if((MouseEntry->Action != NULL)&&(MouseEntry->Context & C_WINDOW) - &&(MouseEntry->IsMouse == 1)) - { - if(MouseEntry->Button_Key >0) - { - XGrabButton(dpy, MouseEntry->Button_Key, MouseEntry->Modifier, - tmp_win->w, - True, ButtonPressMask | ButtonReleaseMask, - GrabModeAsync, GrabModeAsync, None, - Scr.FvwmCursors[DEFAULT]); - if(MouseEntry->Modifier != AnyModifier) - { - XGrabButton(dpy, MouseEntry->Button_Key, - (MouseEntry->Modifier | LockMask), - tmp_win->w, - True, ButtonPressMask | ButtonReleaseMask, - GrabModeAsync, GrabModeAsync, None, - Scr.FvwmCursors[DEFAULT]); - } - } - else - { - XGrabButton(dpy, 1, MouseEntry->Modifier, - tmp_win->w, - True, ButtonPressMask | ButtonReleaseMask, - GrabModeAsync, GrabModeAsync, None, - Scr.FvwmCursors[DEFAULT]); - XGrabButton(dpy, 2, MouseEntry->Modifier, - tmp_win->w, - True, ButtonPressMask | ButtonReleaseMask, - GrabModeAsync, GrabModeAsync, None, - Scr.FvwmCursors[DEFAULT]); - XGrabButton(dpy, 3, MouseEntry->Modifier, - tmp_win->w, - True, ButtonPressMask | ButtonReleaseMask, - GrabModeAsync, GrabModeAsync, None, - Scr.FvwmCursors[DEFAULT]); - if(MouseEntry->Modifier != AnyModifier) - { - XGrabButton(dpy, 1, - (MouseEntry->Modifier | LockMask), - tmp_win->w, - True, ButtonPressMask | ButtonReleaseMask, - GrabModeAsync, GrabModeAsync, None, - Scr.FvwmCursors[DEFAULT]); - XGrabButton(dpy, 2, - (MouseEntry->Modifier | LockMask), - tmp_win->w, - True, ButtonPressMask | ButtonReleaseMask, - GrabModeAsync, GrabModeAsync, None, - Scr.FvwmCursors[DEFAULT]); - XGrabButton(dpy, 3, - (MouseEntry->Modifier | LockMask), - tmp_win->w, - True, ButtonPressMask | ButtonReleaseMask, - GrabModeAsync, GrabModeAsync, None, - Scr.FvwmCursors[DEFAULT]); + Binding *MouseEntry; + + MouseEntry = Scr.AllBindings; + while (MouseEntry != (Binding *)0) { + if ((MouseEntry->Action != NULL) && + (MouseEntry->Context & C_WINDOW) && + (MouseEntry->IsMouse == 1)) { + if (MouseEntry->Button_Key > 0) { + XGrabButton(dpy, MouseEntry->Button_Key, + MouseEntry->Modifier, tmp_win->w, True, + ButtonPressMask | ButtonReleaseMask, + GrabModeAsync, GrabModeAsync, None, + Scr.FvwmCursors[DEFAULT]); + if (MouseEntry->Modifier != AnyModifier) { + XGrabButton(dpy, MouseEntry->Button_Key, + (MouseEntry->Modifier | LockMask), + tmp_win->w, True, + ButtonPressMask | ButtonReleaseMask, + GrabModeAsync, GrabModeAsync, None, + Scr.FvwmCursors[DEFAULT]); + } + } else { + XGrabButton(dpy, 1, MouseEntry->Modifier, + tmp_win->w, True, + ButtonPressMask | ButtonReleaseMask, + GrabModeAsync, GrabModeAsync, None, + Scr.FvwmCursors[DEFAULT]); + XGrabButton(dpy, 2, MouseEntry->Modifier, + tmp_win->w, True, + ButtonPressMask | ButtonReleaseMask, + GrabModeAsync, GrabModeAsync, None, + Scr.FvwmCursors[DEFAULT]); + XGrabButton(dpy, 3, MouseEntry->Modifier, + tmp_win->w, True, + ButtonPressMask | ButtonReleaseMask, + GrabModeAsync, GrabModeAsync, None, + Scr.FvwmCursors[DEFAULT]); + if (MouseEntry->Modifier != AnyModifier) { + XGrabButton(dpy, 1, + (MouseEntry->Modifier | LockMask), + tmp_win->w, True, + ButtonPressMask | ButtonReleaseMask, + GrabModeAsync, GrabModeAsync, None, + Scr.FvwmCursors[DEFAULT]); + XGrabButton(dpy, 2, + (MouseEntry->Modifier | LockMask), + tmp_win->w, True, + ButtonPressMask | ButtonReleaseMask, + GrabModeAsync, GrabModeAsync, None, + Scr.FvwmCursors[DEFAULT]); + XGrabButton(dpy, 3, + (MouseEntry->Modifier | LockMask), + tmp_win->w, True, + ButtonPressMask | ButtonReleaseMask, + GrabModeAsync, GrabModeAsync, None, + Scr.FvwmCursors[DEFAULT]); + } + } } - } + MouseEntry = MouseEntry->NextBinding; } - MouseEntry = MouseEntry->NextBinding; - } - return; + return; } /*********************************************************************** @@ -870,25 +836,24 @@ void GrabButtons(FvwmWindow *tmp_win) * tmp_win - the fvwm window structure to use * ***********************************************************************/ -void GrabKeys(FvwmWindow *tmp_win) +void +GrabKeys(FvwmWindow *tmp_win) { - Binding *tmp; - for (tmp = Scr.AllBindings; tmp != NULL; tmp = tmp->NextBinding) - { - if((tmp->Context & (C_WINDOW|C_TITLE|C_RALL|C_LALL|C_SIDEBAR))&& - (tmp->IsMouse == 0)) - { - XGrabKey(dpy, tmp->Button_Key, tmp->Modifier, tmp_win->frame, True, - GrabModeAsync, GrabModeAsync); - if(tmp->Modifier != AnyModifier) - { - XGrabKey(dpy, tmp->Button_Key, tmp->Modifier|LockMask, - tmp_win->frame, True, - GrabModeAsync, GrabModeAsync); - } + Binding *tmp; + for (tmp = Scr.AllBindings; tmp != NULL; tmp = tmp->NextBinding) { + if ((tmp->Context & + (C_WINDOW | C_TITLE | C_RALL | C_LALL | C_SIDEBAR)) && + (tmp->IsMouse == 0)) { + XGrabKey(dpy, tmp->Button_Key, tmp->Modifier, + tmp_win->frame, True, GrabModeAsync, GrabModeAsync); + if (tmp->Modifier != AnyModifier) { + XGrabKey(dpy, tmp->Button_Key, + tmp->Modifier | LockMask, tmp_win->frame, + True, GrabModeAsync, GrabModeAsync); + } + } } - } - return; + return; } /*********************************************************************** @@ -900,46 +865,48 @@ void GrabKeys(FvwmWindow *tmp_win) * tmp - the fvwm window structure to use * ***********************************************************************/ -void FetchWmProtocols (FvwmWindow *tmp) +void +FetchWmProtocols(FvwmWindow *tmp) { - unsigned long flags = 0L; - Atom *protocols = NULL, *ap; - int i, n; - Atom atype; - int aformat; - unsigned long bytes_remain,nitems; - - if(tmp == NULL) return; - /* First, try the Xlib function to read the protocols. - * This is what Twm uses. */ - if (XGetWMProtocols (dpy, tmp->w, &protocols, &n)) - { - for (i = 0, ap = protocols; i < n; i++, ap++) - { - if (*ap == (Atom)_XA_WM_TAKE_FOCUS) flags |= DoesWmTakeFocus; - if (*ap == (Atom)_XA_WM_DELETE_WINDOW) flags |= DoesWmDeleteWindow; - } - if (protocols) XFree ((char *) protocols); - } - else - { - /* Next, read it the hard way. mosaic from Coreldraw needs to - * be read in this way. */ - if ((XGetWindowProperty(dpy, tmp->w, _XA_WM_PROTOCOLS, 0L, 10L, False, - _XA_WM_PROTOCOLS, &atype, &aformat, &nitems, - &bytes_remain, - (unsigned char **)&protocols))==Success) - { - for (i = 0, ap = protocols; i < nitems; i++, ap++) - { - if (*ap == (Atom)_XA_WM_TAKE_FOCUS) flags |= DoesWmTakeFocus; - if (*ap == (Atom)_XA_WM_DELETE_WINDOW) flags |= DoesWmDeleteWindow; - } - if (protocols) XFree ((char *) protocols); + unsigned long flags = 0L; + Atom *protocols = NULL, *ap; + int i, n; + Atom atype; + int aformat; + unsigned long bytes_remain, nitems; + + if (tmp == NULL) + return; + /* First, try the Xlib function to read the protocols. + * This is what Twm uses. */ + if (XGetWMProtocols(dpy, tmp->w, &protocols, &n)) { + for (i = 0, ap = protocols; i < n; i++, ap++) { + if (*ap == (Atom)_XA_WM_TAKE_FOCUS) + flags |= DoesWmTakeFocus; + if (*ap == (Atom)_XA_WM_DELETE_WINDOW) + flags |= DoesWmDeleteWindow; + } + if (protocols) + XFree((char *)protocols); + } else { + /* Next, read it the hard way. mosaic from Coreldraw needs to + * be read in this way. */ + if ((XGetWindowProperty(dpy, tmp->w, _XA_WM_PROTOCOLS, 0L, 10L, + False, _XA_WM_PROTOCOLS, &atype, &aformat, &nitems, + &bytes_remain, (unsigned char **)&protocols)) == + Success) { + for (i = 0, ap = protocols; i < nitems; i++, ap++) { + if (*ap == (Atom)_XA_WM_TAKE_FOCUS) + flags |= DoesWmTakeFocus; + if (*ap == (Atom)_XA_WM_DELETE_WINDOW) + flags |= DoesWmDeleteWindow; + } + if (protocols) + XFree((char *)protocols); + } } - } - tmp->flags |= flags; - return; + tmp->flags |= flags; + return; } /*********************************************************************** @@ -951,108 +918,99 @@ void FetchWmProtocols (FvwmWindow *tmp) * tmp - the fvwm window structure to use * ***********************************************************************/ -void GetWindowSizeHints(FvwmWindow *tmp) +void +GetWindowSizeHints(FvwmWindow *tmp) { - long supplied = 0; - - if (!XGetWMNormalHints (dpy, tmp->w, &tmp->hints, &supplied)) - tmp->hints.flags = 0; - - /* Beat up our copy of the hints, so that all important field are - * filled in! */ - if (tmp->hints.flags & PResizeInc) - { - if (tmp->hints.width_inc == 0) tmp->hints.width_inc = 1; - if (tmp->hints.height_inc == 0) tmp->hints.height_inc = 1; - } - else - { - tmp->hints.width_inc = 1; - tmp->hints.height_inc = 1; - } - - /* - * ICCCM says that PMinSize is the default if no PBaseSize is given, - * and vice-versa. - */ - - if(!(tmp->hints.flags & PBaseSize)) - { - if(tmp->hints.flags & PMinSize) - { - tmp->hints.base_width = tmp->hints.min_width; - tmp->hints.base_height = tmp->hints.min_height; + long supplied = 0; + + if (!XGetWMNormalHints(dpy, tmp->w, &tmp->hints, &supplied)) + tmp->hints.flags = 0; + + /* Beat up our copy of the hints, so that all important field are + * filled in! */ + if (tmp->hints.flags & PResizeInc) { + if (tmp->hints.width_inc == 0) + tmp->hints.width_inc = 1; + if (tmp->hints.height_inc == 0) + tmp->hints.height_inc = 1; + } else { + tmp->hints.width_inc = 1; + tmp->hints.height_inc = 1; + } + + /* + * ICCCM says that PMinSize is the default if no PBaseSize is given, + * and vice-versa. + */ + + if (!(tmp->hints.flags & PBaseSize)) { + if (tmp->hints.flags & PMinSize) { + tmp->hints.base_width = tmp->hints.min_width; + tmp->hints.base_height = tmp->hints.min_height; + } else { + tmp->hints.base_width = 0; + tmp->hints.base_height = 0; + } + } + if (!(tmp->hints.flags & PMinSize)) { + tmp->hints.min_width = tmp->hints.base_width; + tmp->hints.min_height = tmp->hints.base_height; + } + if (!(tmp->hints.flags & PMaxSize)) { + tmp->hints.max_width = MAX_WINDOW_WIDTH; + tmp->hints.max_height = MAX_WINDOW_HEIGHT; } - else - { - tmp->hints.base_width = 0; - tmp->hints.base_height = 0; + if (tmp->hints.max_width < tmp->hints.min_width) + tmp->hints.max_width = MAX_WINDOW_WIDTH; + if (tmp->hints.max_height < tmp->hints.min_height) + tmp->hints.max_height = MAX_WINDOW_HEIGHT; + + /* Zero width/height windows are bad news! */ + if (tmp->hints.min_height <= 0) + tmp->hints.min_height = 1; + if (tmp->hints.min_width <= 0) + tmp->hints.min_width = 1; + + if (!(tmp->hints.flags & PWinGravity)) { + tmp->hints.win_gravity = NorthWestGravity; + tmp->hints.flags |= PWinGravity; } - } - if(!(tmp->hints.flags & PMinSize)) - { - tmp->hints.min_width = tmp->hints.base_width; - tmp->hints.min_height = tmp->hints.base_height; - } - if(!(tmp->hints.flags & PMaxSize)) - { - tmp->hints.max_width = MAX_WINDOW_WIDTH; - tmp->hints.max_height = MAX_WINDOW_HEIGHT; - } - if(tmp->hints.max_width < tmp->hints.min_width) - tmp->hints.max_width = MAX_WINDOW_WIDTH; - if(tmp->hints.max_height < tmp->hints.min_height) - tmp->hints.max_height = MAX_WINDOW_HEIGHT; - - /* Zero width/height windows are bad news! */ - if(tmp->hints.min_height <= 0) - tmp->hints.min_height = 1; - if(tmp->hints.min_width <= 0) - tmp->hints.min_width = 1; - - if(!(tmp->hints.flags & PWinGravity)) - { - tmp->hints.win_gravity = NorthWestGravity; - tmp->hints.flags |= PWinGravity; - } - - if (tmp->hints.flags & PAspect) - { - /* - ** check to make sure min/max aspect ratios look valid - */ + + if (tmp->hints.flags & PAspect) { + /* + ** check to make sure min/max aspect ratios look valid + */ #define maxAspectX tmp->hints.max_aspect.x #define maxAspectY tmp->hints.max_aspect.y #define minAspectX tmp->hints.min_aspect.x #define minAspectY tmp->hints.min_aspect.y - /* - ** The math looks like this: - ** - ** minAspectX maxAspectX - ** ---------- <= ---------- - ** minAspectY maxAspectY - ** - ** If that is multiplied out, this must be satisfied: - ** - ** minAspectX * maxAspectY <= maxAspectX * minAspectY - ** - ** So, what to do if this isn't met? Ignoring it entirely - ** seems safest. - ** - */ - if ((minAspectX * maxAspectY) > (maxAspectX * minAspectY)) - { - tmp->hints.flags &= ~PAspect; - fvwm_msg(WARN, - "GetWindowSizeHints", - "window id 0x%08x max_aspect ratio is < min_aspect ratio -> ignoring, but program displaying this window should be fixed!!!!", - tmp->w); - } - } + /* + ** The math looks like this: + ** + ** minAspectX maxAspectX + ** ---------- <= ---------- + ** minAspectY maxAspectY + ** + ** If that is multiplied out, this must be satisfied: + ** + ** minAspectX * maxAspectY <= maxAspectX * minAspectY + ** + ** So, what to do if this isn't met? Ignoring it entirely + ** seems safest. + ** + */ + if ((minAspectX * maxAspectY) > (maxAspectX * minAspectY)) { + tmp->hints.flags &= ~PAspect; + fvwm_msg(WARN, "GetWindowSizeHints", + "window id 0x%08x max_aspect ratio is < min_aspect " + "ratio -> ignoring, but program displaying this " + "window " + "should be fixed!!!!", + tmp->w); + } + } } - - /*********************************************************************** * * Procedure: @@ -1073,23 +1031,26 @@ void GetWindowSizeHints(FvwmWindow *tmp) * Point at iconboxes chain, not single iconboxes elements. * ***********************************************************************/ -void LookInList( FvwmWindow *tmp_win, name_list *styles) +void +LookInList(FvwmWindow *tmp_win, name_list *styles) { - name_list *nptr; - - memset(styles, 0, sizeof(name_list)); /* clear callers return area */ - /* look thru all styles in order defined. */ - for (nptr = Scr.TheList; nptr != NULL; nptr = nptr->next) { - /* If name/res_class/res_name match, merge */ - if (matchWildcards(nptr->name,tmp_win->class.res_class) == TRUE) { - merge_styles(styles, nptr); - } else if (matchWildcards(nptr->name,tmp_win->class.res_name) == TRUE) { - merge_styles(styles, nptr); - } else if (matchWildcards(nptr->name,tmp_win->name) == TRUE) { - merge_styles(styles, nptr); - } - } - return; + name_list *nptr; + + memset(styles, 0, sizeof(name_list)); /* clear callers return area */ + /* look thru all styles in order defined. */ + for (nptr = Scr.TheList; nptr != NULL; nptr = nptr->next) { + /* If name/res_class/res_name match, merge */ + if (matchWildcards(nptr->name, tmp_win->class.res_class) == + TRUE) { + merge_styles(styles, nptr); + } else if (matchWildcards( + nptr->name, tmp_win->class.res_name) == TRUE) { + merge_styles(styles, nptr); + } else if (matchWildcards(nptr->name, tmp_win->name) == TRUE) { + merge_styles(styles, nptr); + } + } + return; } /*********************************************************************** @@ -1110,37 +1071,42 @@ void LookInList( FvwmWindow *tmp_win, name_list *styles) * ***********************************************************************/ -static void merge_styles(name_list *styles, name_list *nptr) { - if(nptr->value != NULL) styles->value = nptr->value; +static void +merge_styles(name_list *styles, name_list *nptr) +{ + if (nptr->value != NULL) + styles->value = nptr->value; #ifdef MINI_ICONS - if(nptr->mini_value != NULL) styles->mini_value = nptr->mini_value; + if (nptr->mini_value != NULL) + styles->mini_value = nptr->mini_value; #endif #ifdef USEDECOR - if (nptr->Decor != NULL) styles->Decor = nptr->Decor; + if (nptr->Decor != NULL) + styles->Decor = nptr->Decor; #endif - if(nptr->off_flags & STARTSONDESK_FLAG) - /* RBW - 11/02/1998 */ - { - styles->Desk = nptr->Desk; - styles->PageX = nptr->PageX; - styles->PageY = nptr->PageY; - } - if(nptr->off_flags & BW_FLAG) - styles->border_width = nptr->border_width; - if(nptr->off_flags & FORE_COLOR_FLAG) - styles->ForeColor = nptr->ForeColor; - if(nptr->off_flags & BACK_COLOR_FLAG) - styles->BackColor = nptr->BackColor; - if(nptr->off_flags & NOBW_FLAG) - styles->resize_width = nptr->resize_width; - styles->on_flags |= nptr->off_flags; /* combine on and off flags */ - styles->on_flags &= ~(nptr->on_flags); - styles->on_buttons |= nptr->off_buttons; /* combine buttons */ - styles->on_buttons &= ~(nptr->on_buttons); - /* Note, only one style cmd can define a windows iconboxes, - the last one encountered. */ - if(nptr->IconBoxes != NULL) { /* If style has iconboxes */ - styles->IconBoxes = nptr->IconBoxes; /* copy it */ - } - return; /* return */ + if (nptr->off_flags & STARTSONDESK_FLAG) + /* RBW - 11/02/1998 */ + { + styles->Desk = nptr->Desk; + styles->PageX = nptr->PageX; + styles->PageY = nptr->PageY; + } + if (nptr->off_flags & BW_FLAG) + styles->border_width = nptr->border_width; + if (nptr->off_flags & FORE_COLOR_FLAG) + styles->ForeColor = nptr->ForeColor; + if (nptr->off_flags & BACK_COLOR_FLAG) + styles->BackColor = nptr->BackColor; + if (nptr->off_flags & NOBW_FLAG) + styles->resize_width = nptr->resize_width; + styles->on_flags |= nptr->off_flags; /* combine on and off flags */ + styles->on_flags &= ~(nptr->on_flags); + styles->on_buttons |= nptr->off_buttons; /* combine buttons */ + styles->on_buttons &= ~(nptr->on_buttons); + /* Note, only one style cmd can define a windows iconboxes, + the last one encountered. */ + if (nptr->IconBoxes != NULL) { /* If style has iconboxes */ + styles->IconBoxes = nptr->IconBoxes; /* copy it */ + } + return; /* return */ } Index: fvwm/fvwm/bindings.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/bindings.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/bindings.c --- fvwm/fvwm/bindings.c +++ fvwm/fvwm/bindings.c @@ -1,109 +1,87 @@ -#include "config.h" - -#include +#include +#include #include +#include #include -#include #include +#include "config.h" #include "fvwm.h" #include "misc.h" +#include "module.h" #include "parse.h" #include "screen.h" -#include "module.h" -#include -struct charstring -{ - char key; - int value; +struct charstring { + char key; + int value; }; - /* The keys musat be in lower case! */ -struct charstring win_contexts[]= -{ - {'w',C_WINDOW}, - {'t',C_TITLE}, - {'i',C_ICON}, - {'r',C_ROOT}, - {'f',C_FRAME}, - {'s',C_SIDEBAR}, - {'1',C_L1}, - {'2',C_R1}, - {'3',C_L2}, - {'4',C_R2}, - {'5',C_L3}, - {'6',C_R3}, - {'7',C_L4}, - {'8',C_R4}, - {'9',C_L5}, - {'0',C_R5}, - {'a',C_WINDOW|C_TITLE|C_ICON|C_ROOT|C_FRAME|C_SIDEBAR| - C_L1|C_L2|C_L3|C_L4|C_L5|C_R1|C_R2|C_R3|C_R4|C_R5}, - {0,0} -}; +struct charstring win_contexts[] = {{'w', C_WINDOW}, {'t', C_TITLE}, + {'i', C_ICON}, {'r', C_ROOT}, {'f', C_FRAME}, {'s', C_SIDEBAR}, {'1', C_L1}, + {'2', C_R1}, {'3', C_L2}, {'4', C_R2}, {'5', C_L3}, {'6', C_R3}, + {'7', C_L4}, {'8', C_R4}, {'9', C_L5}, {'0', C_R5}, + {'a', C_WINDOW | C_TITLE | C_ICON | C_ROOT | C_FRAME | C_SIDEBAR | C_L1 | + C_L2 | C_L3 | C_L4 | C_L5 | C_R1 | C_R2 | C_R3 | C_R4 | C_R5}, + {0, 0}}; /* The keys musat be in lower case! */ -struct charstring key_modifiers[]= +struct charstring key_modifiers[] = {{'s', ShiftMask}, {'c', ControlMask}, + {'m', Mod1Mask}, {'1', Mod1Mask}, {'2', Mod2Mask}, {'3', Mod3Mask}, + {'4', Mod4Mask}, {'5', Mod5Mask}, {'a', AnyModifier}, {'n', 0}, {0, 0}}; + +void find_context( + char *string, int *output, struct charstring *table, char *tline); + +static void +RegrabAllKeys(void) { - {'s',ShiftMask}, - {'c',ControlMask}, - {'m',Mod1Mask}, - {'1',Mod1Mask}, - {'2',Mod2Mask}, - {'3',Mod3Mask}, - {'4',Mod4Mask}, - {'5',Mod5Mask}, - {'a',AnyModifier}, - {'n',0}, - {0,0} -}; + FvwmWindow *t; -void find_context(char *string, int *output, struct charstring *table, - char *tline); + for (t = Scr.FvwmRoot.next; t != NULL; t = t->next) { + GrabKeys(t); + } +} /* ** to remove a binding from the global list (probably needs more processing ** for mouse binding lines though, like when context is a title bar button). */ -void remove_binding(int contexts, int mods, int button, KeySym keysym, - int mouse_binding) +void +remove_binding( + int contexts, int mods, int button, KeySym keysym, int mouse_binding) { - Binding *temp=Scr.AllBindings, *temp2, *prev=NULL; - KeyCode keycode = 0; - - if (!mouse_binding) - keycode=XKeysymToKeycode(dpy,keysym); - - while (temp) - { - temp2 = temp->NextBinding; - if (temp->IsMouse == mouse_binding) - { - if ((temp->Button_Key == ((mouse_binding)?(button):(keycode))) && - (temp->Context == contexts) && - (temp->Modifier == mods)) - { - /* we found it, remove it from list */ - if (prev) /* middle of list */ - { - prev->NextBinding = temp2; - } - else /* must have been first one, set new start */ - { - Scr.AllBindings = temp2; - } - free(temp->key_name); - free(temp->Action); - free(temp); - temp=NULL; - } - } - if (temp) - prev=temp; - temp=temp2; - } + Binding *temp = Scr.AllBindings, *temp2, *prev = NULL; + KeyCode keycode = 0; + + if (!mouse_binding) + keycode = XKeysymToKeycode(dpy, keysym); + + while (temp) { + temp2 = temp->NextBinding; + if (temp->IsMouse == mouse_binding) { + if ((temp->Button_Key == + ((mouse_binding) ? (button) : (keycode))) && + (temp->Context == contexts) && + (temp->Modifier == mods)) { + /* we found it, remove it from list */ + if (prev) { /* middle of list */ + prev->NextBinding = temp2; + } else /* must have been first one, set new + start */ { + Scr.AllBindings = temp2; + } + free(temp->key_name); + free(temp->Action); + free(temp); + temp = NULL; + } + } + if (temp) + prev = temp; + temp = temp2; + } } /**************************************************************************** @@ -111,175 +89,194 @@ void remove_binding(int contexts, int mods, int button, KeySym keysym, * Parses a mouse or key binding * ****************************************************************************/ -void ParseBindEntry(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long junk, char *tline,int* Module, Bool fKey) +void +ParseBindEntry(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long junk, char *tline, int *Module, Bool fKey) { - char *action,context[20],modifiers[20],key[20],*ptr, *token; - Binding *temp; - int button,i,min,max; - int n1=0,n2=0,n3=0; - KeySym keysym; - KeySym tkeysym; - int contexts; - int mods; - int maxmods; - int m; - - /* tline points after the key word "Mouse" or "Key" */ - ptr = GetNextToken(tline, &token); - if(token != NULL) - { - if (fKey) - n1 = sscanf(token,"%19s",key); - else - n1 = sscanf(token,"%d",&button); - free(token); - } - - ptr = GetNextToken(ptr,&token); - if(token != NULL) - { - n2 = sscanf(token,"%19s",context); - free(token); - } - - action = GetNextToken(ptr,&token); - if(token != NULL) - { - n3 = sscanf(token,"%19s",modifiers); - free(token); - } - - if((n1 != 1)||(n2 != 1)||(n3 != 1)) - { - fvwm_msg(ERR,"ParseBindEntry","Syntax error in line %s",tline); - return; - } - - find_context(context,&contexts,win_contexts,tline); - find_context(modifiers,&mods,key_modifiers,tline); - - if (fKey) - { - /* - * Don't let a 0 keycode go through, since that means AnyKey to the - * XGrabKey call in GrabKeys(). - */ - if ((keysym = XStringToKeysym(key)) == NoSymbol || - (XKeysymToKeycode(dpy, keysym)) == 0) - return; - } - - /* - ** strip leading whitespace from action if necessary - */ - while (*action && (*action == ' ' || *action == '\t')) - action++; - - /* - ** is this an unbind request? - */ - if (!action || action[0] == '-') - { - if (fKey) - remove_binding(contexts,mods,0,keysym,0); - else - remove_binding(contexts,mods,button,0,1); - return; - } - - if (!fKey) - { - int j; - - if((contexts != C_ALL) && (contexts & C_LALL)) - { - /* check for nr_left_buttons */ - i=0; - j=(contexts &C_LALL)/C_L1; - while(j>0) - { - i++; - j=j>>1; - } - if(Scr.nr_left_buttons 0) - { - i++; - j=j>>1; - } - if(Scr.nr_right_buttons IsMouse = !fKey; - Scr.AllBindings->Button_Key = i; - Scr.AllBindings->key_name = fKey ? stripcpy(key) : NULL; - Scr.AllBindings->Context = contexts; - Scr.AllBindings->Modifier = mods; - Scr.AllBindings->Action = stripcpy(action); - Scr.AllBindings->NextBinding = temp; - } - } - return; + + action = GetNextToken(ptr, &token); + if (token != NULL) { + n3 = sscanf(token, "%19s", modifiers); + free(token); + } + + if ((n1 != 1) || (n2 != 1) || (n3 != 1)) { + fvwm_msg( + ERR, "ParseBindEntry", "Syntax error in line %s", tline); + return; + } + + find_context(context, &contexts, win_contexts, tline); + find_context(modifiers, &mods, key_modifiers, tline); + + if (fKey) { + /* + * Don't let a 0 keycode go through, since that means AnyKey to + * the XGrabKey call in GrabKeys(). + */ + if ((keysym = XStringToKeysym(key)) == NoSymbol || + (XKeysymToKeycode(dpy, keysym)) == 0) + return; + } + + /* + ** strip leading whitespace from action if necessary + */ + while (*action && (*action == ' ' || *action == '\t')) + action++; + + /* + ** is this an unbind request? + */ + if (!action || action[0] == '-') { + if (fKey) + remove_binding(contexts, mods, 0, keysym, 0); + else + remove_binding(contexts, mods, button, 0, 1); + return; + } + + if (!fKey) { + int j; + + if ((contexts != C_ALL) && (contexts & C_LALL)) { + /* check for nr_left_buttons */ + i = 0; + j = (contexts & C_LALL) / C_L1; + while (j > 0) { + i++; + j = j >> 1; + } + if (Scr.nr_left_buttons < i) + Scr.nr_left_buttons = i; + } + if ((contexts != C_ALL) && (contexts & C_RALL)) { + /* check for nr_right_buttons */ + i = 0; + j = (contexts & C_RALL) / C_R1; + while (j > 0) { + i++; + j = j >> 1; + } + if (Scr.nr_right_buttons < i) + Scr.nr_right_buttons = i; + } + } + + if ((mods & AnyModifier) && (mods & (~AnyModifier))) { + fvwm_msg(WARN, "ParseBindEntry", + "Binding specified AnyModifier and other modifers too. " + "Excess modifiers will be ignored."); + mods &= AnyModifier; + } + + if ((!fKey) && (contexts & C_WINDOW) && + (((mods == 0) || mods == AnyModifier))) { + Scr.buttons2grab &= ~(1 << (button - 1)); + } + + /* + ** Unfortunately a keycode can be bound to multiple keysyms and a keysym + * can + ** be bound to multiple keycodes. Thus we have to check every keycode + * with + ** any single modifier. + */ + if (fKey) { + XDisplayKeycodes(dpy, &min, &max); + maxmods = 8; + } else { + min = button; + max = button; + maxmods = 0; + } + for (i = min; i <= max; i++) { + KeySym *mapping = NULL; + int mapping_width = 0; + int column_limit = maxmods; + + if (fKey) { + mapping = + XGetKeyboardMapping(dpy, i, 1, &mapping_width); + if (mapping == NULL || mapping_width <= 0) { + if (mapping) + XFree(mapping); + continue; + } + column_limit = mapping_width - 1; + if (column_limit > maxmods) + column_limit = maxmods; + } + + for (m = 0; m <= column_limit; m++) { + KeySym current = NoSymbol; + + if (fKey) { + current = mapping[m]; + if (current == NoSymbol) + break; + } + + if (!fKey || current == keysym) { + temp = Scr.AllBindings; + Scr.AllBindings = + (Binding *)xmalloc(sizeof(Binding)); + Scr.AllBindings->IsMouse = !fKey; + Scr.AllBindings->Button_Key = i; + Scr.AllBindings->key_name = + fKey ? stripcpy(key) : NULL; + Scr.AllBindings->Context = contexts; + Scr.AllBindings->Modifier = mods; + Scr.AllBindings->Action = stripcpy(action); + Scr.AllBindings->NextBinding = temp; + } + } + + if (mapping) + XFree(mapping); + } + if (fKey) + RegrabAllKeys(); + return; } -void ParseMouseEntry(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long junk, char *tline,int* Module) +void +ParseMouseEntry(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long junk, char *tline, int *Module) { - ParseBindEntry(eventp, w, tmp_win, junk, tline, Module, False); + ParseBindEntry(eventp, w, tmp_win, junk, tline, Module, False); } -void ParseKeyEntry(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long junk, char *tline,int* Module) +void +ParseKeyEntry(XEvent *eventp, Window w, FvwmWindow *tmp_win, unsigned long junk, + char *tline, int *Module) { - ParseBindEntry(eventp, w, tmp_win, junk, tline, Module, True); + ParseBindEntry(eventp, w, tmp_win, junk, tline, Module, True); } /**************************************************************************** @@ -288,42 +285,37 @@ void ParseKeyEntry(XEvent *eventp,Window w,FvwmWindow *tmp_win, * true/false values (bits) * ****************************************************************************/ -void find_context(char *string, int *output, struct charstring *table, - char *tline) +void +find_context(char *string, int *output, struct charstring *table, char *tline) { - int i=0,j=0; - Bool matched; - char tmp1; - - *output=0; - i=0; - while(i #include +#include #include +#include "config.h" #include "fvwm.h" #include "misc.h" +#include "module.h" #include "parse.h" #include "screen.h" -#include "module.h" #ifdef SHAPE #include #endif -void DrawButton(FvwmWindow *t, - Window win, - int W, - int H, - ButtonFace *bf, - GC ReliefGC, GC ShadowGC, - Boolean inverted, - int stateflags); +void DrawButton(FvwmWindow *t, Window win, int W, int H, ButtonFace *bf, + GC ReliefGC, GC ShadowGC, Boolean inverted, int stateflags); #ifdef VECTOR_BUTTONS -void DrawLinePattern(Window win, - GC ReliefGC, - GC ShadowGC, - struct vector_coords *coords, - int w, int h); +void DrawLinePattern(Window win, GC ReliefGC, GC ShadowGC, + struct vector_coords *coords, int w, int h); #endif /* macro rules to get button state */ #if defined(ACTIVEDOWN_BTNS) && defined(INACTIVE_BTNS) -#define GetButtonState(window) \ - (onoroff ? ((PressedW == (window)) ? ActiveDown : ActiveUp) \ - : Inactive) +#define GetButtonState(window) \ + (onoroff ? ((PressedW == (window)) ? ActiveDown : ActiveUp) : Inactive) #else #ifdef ACTIVEDOWN_BTNS -#define GetButtonState(window) \ - ((PressedW == (window)) ? ActiveDown : ActiveUp) +#define GetButtonState(window) ((PressedW == (window)) ? ActiveDown : ActiveUp) #endif #ifdef INACTIVE_BTNS #define GetButtonState(window) (onoroff ? ActiveUp : Inactive) @@ -66,13 +53,14 @@ void DrawLinePattern(Window win, #endif /* macro to change window background color/pixmap */ -#define ChangeWindowColor(window,valuemask) { \ - if(NewColor) \ - { \ - XChangeWindowAttributes(dpy,window,valuemask, &attributes); \ - XClearWindow(dpy,window); \ - } \ - } +#define ChangeWindowColor(window, valuemask) \ + { \ + if (NewColor) { \ + XChangeWindowAttributes( \ + dpy, window, valuemask, &attributes); \ + XClearWindow(dpy, window); \ + } \ + } extern Window PressedW; XGCValues Globalgcv; @@ -82,476 +70,547 @@ unsigned long Globalgcm; * Redraws the windows borders * ****************************************************************************/ -void SetBorder (FvwmWindow *t, Bool onoroff,Bool force,Bool Mapped, - Window expose_win) +void +SetBorder( + FvwmWindow *t, Bool onoroff, Bool force, Bool Mapped, Window expose_win) { - int y, i, x; - GC ReliefGC,ShadowGC; - Pixel BorderColor,BackColor; - Pixmap BackPixmap,TextColor; + int y, i, x; + GC ReliefGC, ShadowGC; + Pixel BorderColor, BackColor; + Pixmap BackPixmap, TextColor; #if defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE) - Pixmap TexturePixmap = None; - XSetWindowAttributes notex_attributes; - unsigned long notex_valuemask; + Pixmap TexturePixmap = None; + XSetWindowAttributes notex_attributes; + unsigned long notex_valuemask; #endif - Bool NewColor = False; - XSetWindowAttributes attributes; - unsigned long valuemask; - static unsigned int corners[4]; - Window w; + Bool NewColor = False; + XSetWindowAttributes attributes; + unsigned long valuemask; + static unsigned int corners[4]; + Window w; - corners[0] = TOP_HILITE | LEFT_HILITE; - corners[1] = TOP_HILITE | RIGHT_HILITE; - corners[2] = BOTTOM_HILITE | LEFT_HILITE; - corners[3] = BOTTOM_HILITE | RIGHT_HILITE; + corners[0] = TOP_HILITE | LEFT_HILITE; + corners[1] = TOP_HILITE | RIGHT_HILITE; + corners[2] = BOTTOM_HILITE | LEFT_HILITE; + corners[3] = BOTTOM_HILITE | RIGHT_HILITE; - if(!t) - return; + if (!t) + return; - if (onoroff) - { - /* don't re-draw just for kicks */ - if((!force)&&(Scr.Hilite == t)) - return; + if (onoroff) { + /* don't re-draw just for kicks */ + if ((!force) && (Scr.Hilite == t)) + return; - if(Scr.Hilite != t) - NewColor = True; + if (Scr.Hilite != t) + NewColor = True; - /* make sure that the previously highlighted window got unhighlighted */ - if((Scr.Hilite != t)&&(Scr.Hilite != NULL)) - SetBorder(Scr.Hilite,False,False,True,None); + /* make sure that the previously highlighted window got + * unhighlighted */ + if ((Scr.Hilite != t) && (Scr.Hilite != NULL)) + SetBorder(Scr.Hilite, False, False, True, None); #if defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE) - /* are we using textured borders? */ - if ((GetDecor(t,BorderStyle.active.style) - & ButtonFaceTypeMask) == TiledPixmapButton) - TexturePixmap = GetDecor(t,BorderStyle.active.u.p->picture); + /* are we using textured borders? */ + if ((GetDecor(t, BorderStyle.active.style) & + ButtonFaceTypeMask) == TiledPixmapButton) + TexturePixmap = + GetDecor(t, BorderStyle.active.u.p->picture); #endif - /* set the keyboard focus */ - if((Mapped)&&(t->flags&MAPPED)&&(Scr.Hilite != t)) - w = t->w; - else if((t->flags&ICONIFIED)&& - (Scr.Hilite !=t)&&(!(t->flags &SUPPRESSICON))) - w = t->icon_w; - Scr.Hilite = t; - - TextColor = GetDecor(t,HiColors.fore); - BackPixmap= Scr.gray_pixmap; - BackColor = GetDecor(t,HiColors.back); - ReliefGC = GetDecor(t,HiReliefGC); - ShadowGC = GetDecor(t,HiShadowGC); - BorderColor = GetDecor(t,HiRelief.back); - } - else - { - /* don't re-draw just for kicks */ - if((!force)&&(Scr.Hilite != t)) - return; - - if(Scr.Hilite == t) - { - Scr.Hilite = NULL; - NewColor = True; - } + /* set the keyboard focus */ + if ((Mapped) && (t->flags & MAPPED) && (Scr.Hilite != t)) + w = t->w; + else if ((t->flags & ICONIFIED) && (Scr.Hilite != t) && + (!(t->flags & SUPPRESSICON))) + w = t->icon_w; + Scr.Hilite = t; + + TextColor = GetDecor(t, HiColors.fore); + BackPixmap = Scr.gray_pixmap; + BackColor = GetDecor(t, HiColors.back); + ReliefGC = GetDecor(t, HiReliefGC); + ShadowGC = GetDecor(t, HiShadowGC); + BorderColor = GetDecor(t, HiRelief.back); + } else { + /* don't re-draw just for kicks */ + if ((!force) && (Scr.Hilite != t)) + return; + + if (Scr.Hilite == t) { + Scr.Hilite = NULL; + NewColor = True; + } #if defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE) - if ((GetDecor(t,BorderStyle.inactive.style) - & ButtonFaceTypeMask) == TiledPixmapButton) - TexturePixmap = GetDecor(t,BorderStyle.inactive.u.p->picture); + if ((GetDecor(t, BorderStyle.inactive.style) & + ButtonFaceTypeMask) == TiledPixmapButton) + TexturePixmap = + GetDecor(t, BorderStyle.inactive.u.p->picture); #endif - TextColor =t->TextPixel; - BackPixmap = Scr.light_gray_pixmap; - if(t->flags & STICKY) - BackPixmap = Scr.sticky_gray_pixmap; - BackColor = t->BackPixel; - Globalgcv.foreground = t->ReliefPixel; - Globalgcm = GCForeground; - XChangeGC(dpy,Scr.ScratchGC1,Globalgcm,&Globalgcv); - ReliefGC = Scr.ScratchGC1; - - Globalgcv.foreground = t->ShadowPixel; - XChangeGC(dpy,Scr.ScratchGC2,Globalgcm,&Globalgcv); - ShadowGC = Scr.ScratchGC2; - BorderColor = t->ShadowPixel; - } - - if(t->flags & ICONIFIED) - { - DrawIconWindow(t); - return; - } + TextColor = t->TextPixel; + BackPixmap = Scr.light_gray_pixmap; + if (t->flags & STICKY) + BackPixmap = Scr.sticky_gray_pixmap; + BackColor = t->BackPixel; + Globalgcv.foreground = t->ReliefPixel; + Globalgcm = GCForeground; + XChangeGC(dpy, Scr.ScratchGC1, Globalgcm, &Globalgcv); + ReliefGC = Scr.ScratchGC1; + + Globalgcv.foreground = t->ShadowPixel; + XChangeGC(dpy, Scr.ScratchGC2, Globalgcm, &Globalgcv); + ShadowGC = Scr.ScratchGC2; + BorderColor = t->ShadowPixel; + } + + if (t->flags & ICONIFIED) { + DrawIconWindow(t); + return; + } #if defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE) - valuemask = - notex_valuemask = - CWBorderPixel; - attributes.border_pixel = - notex_attributes.border_pixel = - BorderColor; + valuemask = notex_valuemask = CWBorderPixel; + attributes.border_pixel = notex_attributes.border_pixel = BorderColor; #else - valuemask = CWBorderPixel; - attributes.border_pixel = BorderColor; + valuemask = CWBorderPixel; + attributes.border_pixel = BorderColor; #endif #if defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE) - if (TexturePixmap) - { - attributes.background_pixmap = TexturePixmap; - valuemask |= CWBackPixmap; - if (Scr.d_depth < 2) { - notex_attributes.background_pixmap = BackPixmap; - notex_valuemask |= CWBackPixmap; - } else { - notex_attributes.background_pixel = BackColor; - notex_valuemask |= CWBackPixel; - } - } - else + if (TexturePixmap) { + attributes.background_pixmap = TexturePixmap; + valuemask |= CWBackPixmap; + if (Scr.d_depth < 2) { + notex_attributes.background_pixmap = BackPixmap; + notex_valuemask |= CWBackPixmap; + } else { + notex_attributes.background_pixel = BackColor; + notex_valuemask |= CWBackPixel; + } + } else #endif - if (Scr.d_depth < 2) - { - attributes.background_pixmap = BackPixmap; - valuemask |= CWBackPixmap; + if (Scr.d_depth < 2) { + attributes.background_pixmap = BackPixmap; + valuemask |= CWBackPixmap; #if defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE) - notex_attributes.background_pixmap = BackPixmap; - notex_valuemask |= CWBackPixmap; + notex_attributes.background_pixmap = BackPixmap; + notex_valuemask |= CWBackPixmap; #endif - } - else - { - attributes.background_pixel = BackColor; - valuemask |= CWBackPixel; + } else { + attributes.background_pixel = BackColor; + valuemask |= CWBackPixel; #if defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE) - notex_attributes.background_pixel = BackColor; - notex_valuemask |= CWBackPixel; + notex_attributes.background_pixel = BackColor; + notex_valuemask |= CWBackPixel; #endif - } - - if(t->flags & (TITLE|BORDER)) - { - XSetWindowBorder(dpy,t->Parent,BorderColor); - XSetWindowBorder(dpy,t->frame,BorderColor); - } - if(t->flags & TITLE) - { - ChangeWindowColor(t->title_w,valuemask); - for(i=0;ileft_w[i] != None) - { - enum ButtonState bs = GetButtonState(t->left_w[i]); - ButtonFace *bf = &GetDecor(t,left_buttons[i].state[bs]); + } + + if (t->flags & (TITLE | BORDER)) { + XSetWindowBorder(dpy, t->Parent, BorderColor); + XSetWindowBorder(dpy, t->frame, BorderColor); + } + if (t->flags & TITLE) { + ChangeWindowColor(t->title_w, valuemask); + for (i = 0; i < Scr.nr_left_buttons; ++i) { + if (t->left_w[i] != None) { + enum ButtonState bs = + GetButtonState(t->left_w[i]); + ButtonFace *bf = + &GetDecor(t, left_buttons[i].state[bs]); #if !(defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE)) - ChangeWindowColor(t->left_w[i],valuemask); + ChangeWindowColor(t->left_w[i], valuemask); #endif - if(flush_expose(t->left_w[i])||(expose_win == t->left_w[i])|| - (expose_win == None) + if (flush_expose(t->left_w[i]) || + (expose_win == t->left_w[i]) || + (expose_win == None) #if defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE) - || NewColor + || NewColor #endif - ) - { - int inverted = PressedW == t->left_w[i]; + ) { + int inverted = PressedW == t->left_w[i]; #if defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE) - if (bf->style & UseBorderStyle) - XChangeWindowAttributes(dpy, t->left_w[i], - valuemask, &attributes); - else - XChangeWindowAttributes(dpy, t->left_w[i], - notex_valuemask, ¬ex_attributes); - XClearWindow(dpy, t->left_w[i]); + if (bf->style & UseBorderStyle) + XChangeWindowAttributes(dpy, + t->left_w[i], valuemask, + &attributes); + else + XChangeWindowAttributes(dpy, + t->left_w[i], + notex_valuemask, + ¬ex_attributes); + XClearWindow(dpy, t->left_w[i]); #endif #ifdef EXTENDED_TITLESTYLE - if (bf->style & UseTitleStyle) { - ButtonFace *tsbf = &GetDecor(t,titlebar.state[bs]); + if (bf->style & UseTitleStyle) { + ButtonFace *tsbf = &GetDecor( + t, titlebar.state[bs]); #ifdef MULTISTYLE - for (; tsbf; tsbf = tsbf->next) + for (; tsbf; tsbf = tsbf->next) #endif - DrawButton(t, t->left_w[i], - t->title_height, t->title_height, - tsbf, ReliefGC, ShadowGC, - inverted, GetDecor(t,left_buttons[i].flags)); - } + DrawButton(t, + t->left_w[i], + t->title_height, + t->title_height, + tsbf, ReliefGC, + ShadowGC, inverted, + GetDecor(t, + left_buttons[i] + .flags)); + } #endif /* EXTENDED_TITLESTYLE */ #ifdef MULTISTYLE - for (; bf; bf = bf->next) + for (; bf; bf = bf->next) #endif - DrawButton(t, t->left_w[i], - t->title_height, t->title_height, - bf, ReliefGC, ShadowGC, - inverted, GetDecor(t,left_buttons[i].flags)); - - if (!(GetDecor(t,left_buttons[i].state[bs].style) & FlatButton)) { - if (GetDecor(t,left_buttons[i].state[bs].style) & SunkButton) - RelieveWindow(t,t->left_w[i],0,0, - t->title_height, t->title_height, - (inverted ? ReliefGC : ShadowGC), - (inverted ? ShadowGC : ReliefGC), - BOTTOM_HILITE); - else - RelieveWindow(t,t->left_w[i],0,0, - t->title_height, t->title_height, - (inverted ? ShadowGC : ReliefGC), - (inverted ? ReliefGC : ShadowGC), - BOTTOM_HILITE); + DrawButton(t, t->left_w[i], + t->title_height, + t->title_height, bf, + ReliefGC, ShadowGC, + inverted, + GetDecor(t, + left_buttons[i].flags)); + + if (!(GetDecor(t, left_buttons[i] + .state[bs] + .style) & + FlatButton)) { + if (GetDecor(t, left_buttons[i] + .state[bs] + .style) & + SunkButton) + RelieveWindow(t, + t->left_w[i], 0, 0, + t->title_height, + t->title_height, + (inverted ? + ReliefGC : + ShadowGC), + (inverted ? + ShadowGC : + ReliefGC), + BOTTOM_HILITE); + else + RelieveWindow(t, + t->left_w[i], 0, 0, + t->title_height, + t->title_height, + (inverted ? + ShadowGC : + ReliefGC), + (inverted ? + ReliefGC : + ShadowGC), + BOTTOM_HILITE); + } + } + } } - } - } - } - for(i=0;iright_w[i] != None) - { - enum ButtonState bs = GetButtonState(t->right_w[i]); - ButtonFace *bf = &GetDecor(t,right_buttons[i].state[bs]); + for (i = 0; i < Scr.nr_right_buttons; ++i) { + if (t->right_w[i] != None) { + enum ButtonState bs = + GetButtonState(t->right_w[i]); + ButtonFace *bf = + &GetDecor(t, right_buttons[i].state[bs]); #if !(defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE)) - ChangeWindowColor(t->right_w[i],valuemask); + ChangeWindowColor(t->right_w[i], valuemask); #endif - if(flush_expose(t->right_w[i])||(expose_win==t->right_w[i])|| - (expose_win == None) + if (flush_expose(t->right_w[i]) || + (expose_win == t->right_w[i]) || + (expose_win == None) #if defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE) - || NewColor + || NewColor #endif - ) - { - int inverted = PressedW == t->right_w[i]; + ) { + int inverted = + PressedW == t->right_w[i]; #if defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE) - if (bf->style & UseBorderStyle) - XChangeWindowAttributes(dpy, t->right_w[i], - valuemask, &attributes); - else - XChangeWindowAttributes(dpy, t->right_w[i], - notex_valuemask, ¬ex_attributes); - XClearWindow(dpy, t->right_w[i]); + if (bf->style & UseBorderStyle) + XChangeWindowAttributes(dpy, + t->right_w[i], valuemask, + &attributes); + else + XChangeWindowAttributes(dpy, + t->right_w[i], + notex_valuemask, + ¬ex_attributes); + XClearWindow(dpy, t->right_w[i]); #endif #ifdef EXTENDED_TITLESTYLE - if (bf->style & UseTitleStyle) { - ButtonFace *tsbf = &GetDecor(t,titlebar.state[bs]); + if (bf->style & UseTitleStyle) { + ButtonFace *tsbf = &GetDecor( + t, titlebar.state[bs]); #ifdef MULTISTYLE - for (; tsbf; tsbf = tsbf->next) + for (; tsbf; tsbf = tsbf->next) #endif - DrawButton(t, t->right_w[i], - t->title_height, t->title_height, - tsbf, ReliefGC, ShadowGC, - inverted, GetDecor(t,right_buttons[i].flags)); - } + DrawButton(t, + t->right_w[i], + t->title_height, + t->title_height, + tsbf, ReliefGC, + ShadowGC, inverted, + GetDecor(t, + right_buttons[i] + .flags)); + } #endif /* EXTENDED_TITLESTYLE */ #ifdef MULTISTYLE - for (; bf; bf = bf->next) + for (; bf; bf = bf->next) #endif - DrawButton(t, t->right_w[i], - t->title_height, t->title_height, - bf, ReliefGC, ShadowGC, - inverted, GetDecor(t,right_buttons[i].flags)); - - if (!(GetDecor(t,right_buttons[i].state[bs].style) & FlatButton)) { - if (GetDecor(t,right_buttons[i].state[bs].style) & SunkButton) - RelieveWindow(t,t->right_w[i],0,0, - t->title_height, t->title_height, - (inverted ? ReliefGC : ShadowGC), - (inverted ? ShadowGC : ReliefGC), - BOTTOM_HILITE); - else - RelieveWindow(t,t->right_w[i],0,0, - t->title_height, t->title_height, - (inverted ? ShadowGC : ReliefGC), - (inverted ? ReliefGC : ShadowGC), - BOTTOM_HILITE); + DrawButton(t, t->right_w[i], + t->title_height, + t->title_height, bf, + ReliefGC, ShadowGC, + inverted, + GetDecor(t, right_buttons[i] + .flags)); + + if (!(GetDecor(t, right_buttons[i] + .state[bs] + .style) & + FlatButton)) { + if (GetDecor(t, right_buttons[i] + .state[bs] + .style) & + SunkButton) + RelieveWindow(t, + t->right_w[i], 0, 0, + t->title_height, + t->title_height, + (inverted ? + ReliefGC : + ShadowGC), + (inverted ? + ShadowGC : + ReliefGC), + BOTTOM_HILITE); + else + RelieveWindow(t, + t->right_w[i], 0, 0, + t->title_height, + t->title_height, + (inverted ? + ShadowGC : + ReliefGC), + (inverted ? + ReliefGC : + ShadowGC), + BOTTOM_HILITE); + } + } + } } - } + SetTitleBar(t, onoroff, False); } - } - SetTitleBar(t,onoroff, False); - - } - if(t->flags & BORDER) - { - /* draw relief lines */ - y= t->frame_height - 2*t->corner_width; - x = t->frame_width- 2*t->corner_width +t->bw; + if (t->flags & BORDER) { + /* draw relief lines */ + y = t->frame_height - 2 * t->corner_width; + x = t->frame_width - 2 * t->corner_width + t->bw; - for(i=0;i<4;i++) - { - int vertical = i % 2; + for (i = 0; i < 4; i++) { + int vertical = i % 2; #ifdef BORDERSTYLE - int flags = onoroff - ? GetDecor(t,BorderStyle.active.style) - : GetDecor(t,BorderStyle.inactive.style); + int flags = + onoroff ? GetDecor(t, BorderStyle.active.style) : + GetDecor(t, BorderStyle.inactive.style); #endif /* BORDERSTYLE */ - ChangeWindowColor(t->sides[i],valuemask); - if((flush_expose (t->sides[i]))||(expose_win == t->sides[i])|| - (expose_win == None)) - { - GC sgc,rgc; - - sgc=ShadowGC; - rgc=ReliefGC; - if(!(t->flags & MWMButtons)&&(PressedW == t->sides[i])) - { - sgc = ReliefGC; - rgc = ShadowGC; - } - /* index side - * 0 TOP - * 1 RIGHT - * 2 BOTTOM - * 3 LEFT - */ + ChangeWindowColor(t->sides[i], valuemask); + if ((flush_expose(t->sides[i])) || + (expose_win == t->sides[i]) || + (expose_win == None)) { + GC sgc, rgc; + + sgc = ShadowGC; + rgc = ReliefGC; + if (!(t->flags & MWMButtons) && + (PressedW == t->sides[i])) { + sgc = ReliefGC; + rgc = ShadowGC; + } + /* index side + * 0 TOP + * 1 RIGHT + * 2 BOTTOM + * 3 LEFT + */ #ifdef BORDERSTYLE - if (flags&HiddenHandles) { - if (flags&NoInset) - RelieveWindowHH(t,t->sides[i],0,0, - ((vertical)?t->boundary_width:x), - ((vertical)?y:t->boundary_width), - rgc, sgc, vertical - ? (i == 3 ? LEFT_HILITE : RIGHT_HILITE) - : (i ? BOTTOM_HILITE : TOP_HILITE), - (0x0001<sides[i],0,0, - ((vertical)?t->boundary_width:x), - ((vertical)?y:t->boundary_width), - rgc, sgc, vertical - ? (LEFT_HILITE|RIGHT_HILITE) - : (TOP_HILITE|BOTTOM_HILITE), - (0x0001<sides[i], + 0, 0, + ((vertical) ? + t->boundary_width : + x), + ((vertical) ? + y : + t->boundary_width), + rgc, sgc, + vertical ? + (i == 3 ? LEFT_HILITE : + RIGHT_HILITE) : + (i ? BOTTOM_HILITE : + TOP_HILITE), + (0x0001 << i)); + else + RelieveWindowHH(t, t->sides[i], + 0, 0, + ((vertical) ? + t->boundary_width : + x), + ((vertical) ? + y : + t->boundary_width), + rgc, sgc, + vertical ? + (LEFT_HILITE | + RIGHT_HILITE) : + (TOP_HILITE | + BOTTOM_HILITE), + (0x0001 << i)); + } else #endif /* BORDERSTYLE */ - RelieveWindow(t,t->sides[i],0,0, - ((i%2)?t->boundary_width:x), - ((i%2)?y:t->boundary_width), - rgc, sgc, (0x0001<corners[i],valuemask); - if((flush_expose(t->corners[i]))||(expose_win==t->corners[i])|| - (expose_win == None)) - { - GC rgc,sgc; - - rgc = ReliefGC; - sgc = ShadowGC; - if(!(t->flags & MWMButtons)&&(PressedW == t->corners[i])) - { - sgc = ReliefGC; - rgc = ShadowGC; - } + RelieveWindow(t, t->sides[i], 0, 0, + ((i % 2) ? t->boundary_width : x), + ((i % 2) ? y : t->boundary_width), + rgc, sgc, (0x0001 << i)); + } + ChangeWindowColor(t->corners[i], valuemask); + if ((flush_expose(t->corners[i])) || + (expose_win == t->corners[i]) || + (expose_win == None)) { + GC rgc, sgc; + + rgc = ReliefGC; + sgc = ShadowGC; + if (!(t->flags & MWMButtons) && + (PressedW == t->corners[i])) { + sgc = ReliefGC; + rgc = ShadowGC; + } #ifdef BORDERSTYLE - if (flags&HiddenHandles) { - RelieveWindowHH(t,t->corners[i],0,0,t->corner_width, - ((i/2)?t->corner_width+t->bw:t->corner_width), - rgc,sgc, corners[i], corners[i]); - - if (!(flags&NoInset)) { - if (t->boundary_width > 1) - RelieveParts(t,i|HH_HILITE, - ((i/2)?rgc:sgc),(vertical?rgc:sgc)); - else - RelieveParts(t,i|HH_HILITE, - ((i/2)?sgc:sgc),(vertical?sgc:sgc)); - } - } else { + if (flags & HiddenHandles) { + RelieveWindowHH(t, t->corners[i], 0, 0, + t->corner_width, + ((i / 2) ? t->corner_width + t->bw : + t->corner_width), + rgc, sgc, corners[i], corners[i]); + + if (!(flags & NoInset)) { + if (t->boundary_width > 1) + RelieveParts(t, + i | HH_HILITE, + ((i / 2) ? rgc : + sgc), + (vertical ? rgc : + sgc)); + else + RelieveParts(t, + i | HH_HILITE, + ((i / 2) ? sgc : + sgc), + (vertical ? sgc : + sgc)); + } + } else { #endif /* ! BORDERSTYLE */ - RelieveWindow(t,t->corners[i],0,0,t->corner_width, - ((i/2)?t->corner_width+t->bw:t->corner_width), - rgc,sgc, corners[i]); - - if(t->boundary_width > 1) - RelieveParts(t,i,((i/2)?rgc:sgc),(vertical?rgc:sgc)); - else - RelieveParts(t,i,((i/2)?sgc:sgc),(vertical?sgc:sgc)); + RelieveWindow(t, t->corners[i], 0, 0, + t->corner_width, + ((i / 2) ? t->corner_width + t->bw : + t->corner_width), + rgc, sgc, corners[i]); + + if (t->boundary_width > 1) + RelieveParts(t, i, + ((i / 2) ? rgc : sgc), + (vertical ? rgc : sgc)); + else + RelieveParts(t, i, + ((i / 2) ? sgc : sgc), + (vertical ? sgc : sgc)); #ifdef BORDERSTYLE - } + } #endif - } - } - } - else /* no decorative border */ - { - /* for mono - put a black border on - * for color, make it the color of the decoration background */ - if(t->boundary_width < 2) - { - flush_expose (t->frame); - if(Scr.d_depth <2) - { - XSetWindowBorder(dpy,t->frame,TextColor); - XSetWindowBorder(dpy,t->Parent,TextColor); - XSetWindowBackgroundPixmap(dpy,t->frame,BackPixmap); - XClearWindow(dpy,t->frame); - XSetWindowBackgroundPixmap(dpy,t->Parent,BackPixmap); - XClearWindow(dpy,t->Parent); - } - else - { + } + } + } else /* no decorative border */ { + /* for mono - put a black border on + * for color, make it the color of the decoration background */ + if (t->boundary_width < 2) { + flush_expose(t->frame); + if (Scr.d_depth < 2) { + XSetWindowBorder(dpy, t->frame, TextColor); + XSetWindowBorder(dpy, t->Parent, TextColor); + XSetWindowBackgroundPixmap( + dpy, t->frame, BackPixmap); + XClearWindow(dpy, t->frame); + XSetWindowBackgroundPixmap( + dpy, t->Parent, BackPixmap); + XClearWindow(dpy, t->Parent); + } else { #if defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE) - XSetWindowBackgroundPixmap(dpy,t->frame,TexturePixmap); + XSetWindowBackgroundPixmap( + dpy, t->frame, TexturePixmap); #endif - XSetWindowBorder(dpy,t->frame,BorderColor); - XClearWindow(dpy,t->frame); - XSetWindowBackground(dpy,t->Parent,BorderColor); - XSetWindowBorder(dpy,t->Parent,BorderColor); - XClearWindow(dpy,t->Parent); - XSetWindowBorder(dpy,t->w,BorderColor); - } - } - else - { - GC rgc,sgc; - - XSetWindowBorder(dpy,t->Parent,BorderColor); - XSetWindowBorder(dpy,t->frame,BorderColor); - - rgc=ReliefGC; - sgc=ShadowGC; - if(!(t->flags & MWMButtons)&&(PressedW == t->frame)) - { - sgc=ReliefGC; - rgc=ShadowGC; - } - ChangeWindowColor(t->frame, valuemask); - if((flush_expose(t->frame))||(expose_win == t->frame)|| - (expose_win == None)) - { - if(t->boundary_width > 2) - { - RelieveWindow(t,t->frame,t->boundary_width-1 - t->bw, - t->boundary_width-1-t->bw, - t->frame_width- - (t->boundary_width<<1)+2+3*t->bw, - t->frame_height- - (t->boundary_width<<1)+2+3*t->bw, - sgc,rgc, - TOP_HILITE|LEFT_HILITE|RIGHT_HILITE| - BOTTOM_HILITE); - RelieveWindow(t,t->frame,0,0,t->frame_width+t->bw, - t->frame_height+t->bw,rgc,sgc, - TOP_HILITE|LEFT_HILITE|RIGHT_HILITE| - BOTTOM_HILITE); - } - else - { - RelieveWindow(t,t->frame,0,0,t->frame_width+t->bw, - t->frame_height+t->bw,rgc,rgc, - TOP_HILITE|LEFT_HILITE|RIGHT_HILITE| - BOTTOM_HILITE); - } - } - else - { - XSetWindowBackground(dpy,t->Parent,BorderColor); - } - } - } - /* Sync to make the border-color change look fast! */ - XSync(dpy,0); - + XSetWindowBorder(dpy, t->frame, BorderColor); + XClearWindow(dpy, t->frame); + XSetWindowBackground( + dpy, t->Parent, BorderColor); + XSetWindowBorder(dpy, t->Parent, BorderColor); + XClearWindow(dpy, t->Parent); + XSetWindowBorder(dpy, t->w, BorderColor); + } + } else { + GC rgc, sgc; + + XSetWindowBorder(dpy, t->Parent, BorderColor); + XSetWindowBorder(dpy, t->frame, BorderColor); + + rgc = ReliefGC; + sgc = ShadowGC; + if (!(t->flags & MWMButtons) && + (PressedW == t->frame)) { + sgc = ReliefGC; + rgc = ShadowGC; + } + ChangeWindowColor(t->frame, valuemask); + if ((flush_expose(t->frame)) || + (expose_win == t->frame) || (expose_win == None)) { + if (t->boundary_width > 2) { + RelieveWindow(t, t->frame, + t->boundary_width - 1 - t->bw, + t->boundary_width - 1 - t->bw, + t->frame_width - + (t->boundary_width << 1) + 2 + + 3 * t->bw, + t->frame_height - + (t->boundary_width << 1) + 2 + + 3 * t->bw, + sgc, rgc, + TOP_HILITE | LEFT_HILITE | + RIGHT_HILITE | BOTTOM_HILITE); + RelieveWindow(t, t->frame, 0, 0, + t->frame_width + t->bw, + t->frame_height + t->bw, rgc, sgc, + TOP_HILITE | LEFT_HILITE | + RIGHT_HILITE | BOTTOM_HILITE); + } else { + RelieveWindow(t, t->frame, 0, 0, + t->frame_width + t->bw, + t->frame_height + t->bw, rgc, rgc, + TOP_HILITE | LEFT_HILITE | + RIGHT_HILITE | BOTTOM_HILITE); + } + } else { + XSetWindowBackground( + dpy, t->Parent, BorderColor); + } + } + } + /* Sync to make the border-color change look fast! */ + XSync(dpy, 0); } /**************************************************************************** @@ -559,144 +618,145 @@ void SetBorder (FvwmWindow *t, Bool onoroff,Bool force,Bool Mapped, * Redraws buttons (veliaa@rpi.edu) * ****************************************************************************/ -void DrawButton(FvwmWindow *t, Window win, int w, int h, - ButtonFace *bf, GC ReliefGC, GC ShadowGC, - Boolean inverted, int stateflags) +void +DrawButton(FvwmWindow *t, Window win, int w, int h, ButtonFace *bf, GC ReliefGC, + GC ShadowGC, Boolean inverted, int stateflags) { - register int type = bf->style & ButtonFaceTypeMask; + register int type = bf->style & ButtonFaceTypeMask; #ifdef PIXMAP_BUTTONS - FvwmPicture *p; - int border = 0; - int width, height, x, y; + FvwmPicture *p; + int border = 0; + int width, height, x, y; #endif - switch (type) - { - case SimpleButton: - break; + switch (type) { + case SimpleButton: + break; - case SolidButton: - XSetWindowBackground(dpy, win, bf->u.back); - flush_expose(win); - XClearWindow(dpy,win); - break; + case SolidButton: + XSetWindowBackground(dpy, win, bf->u.back); + flush_expose(win); + XClearWindow(dpy, win); + break; #ifdef VECTOR_BUTTONS - case VectorButton: - if((t->flags & MWMButtons) - && (stateflags & MWMDecorMaximize) - && (t->flags & MAXIMIZED)) - DrawLinePattern(win, - ShadowGC, ReliefGC, - &bf->vector, - w, h); - else - DrawLinePattern(win, - ReliefGC, ShadowGC, - &bf->vector, - w, h); - break; + case VectorButton: + if ((t->flags & MWMButtons) && + (stateflags & MWMDecorMaximize) && (t->flags & MAXIMIZED)) + DrawLinePattern( + win, ShadowGC, ReliefGC, &bf->vector, w, h); + else + DrawLinePattern( + win, ReliefGC, ShadowGC, &bf->vector, w, h); + break; #endif /* VECTOR_BUTTONS */ #ifdef PIXMAP_BUTTONS #ifdef MINI_ICONS - case MiniIconButton: - case PixmapButton: - if (type == PixmapButton) - p = bf->u.p; - else { - if (!t->mini_icon) - break; - p = t->mini_icon; - } + case MiniIconButton: + case PixmapButton: + if (type == PixmapButton) + p = bf->u.p; + else { + if (!t->mini_icon) + break; + p = t->mini_icon; + } #else - case PixmapButton: - p = bf->u.p; + case PixmapButton: + p = bf->u.p; #endif /* MINI_ICONS */ - if (bf->style & FlatButton) - border = 0; - else - border = t->flags & MWMBorders ? 1 : 2; - width = w - border * 2; height = h - border * 2; - - x = border; - if (bf->style&HOffCenter) { - if (bf->style&HRight) - x += (int)(width - p->width); - } else - x += (int)(width - p->width) / 2; + if (bf->style & FlatButton) + border = 0; + else + border = t->flags & MWMBorders ? 1 : 2; + width = w - border * 2; + height = h - border * 2; + + x = border; + if (bf->style & HOffCenter) { + if (bf->style & HRight) + x += (int)(width - p->width); + } else + x += (int)(width - p->width) / 2; + + y = border; + if (bf->style & VOffCenter) { + if (bf->style & VBottom) + y += (int)(height - p->height); + } else + y += (int)(height - p->height) / 2; + + if (x < border) + x = border; + if (y < border) + y = border; + if (width > p->width) + width = p->width; + if (height > p->height) + height = p->height; + if (width > w - x - border) + width = w - x - border; + if (height > h - y - border) + height = h - y - border; + + XSetClipMask(dpy, Scr.TransMaskGC, p->mask); + XSetClipOrigin(dpy, Scr.TransMaskGC, x, y); + XCopyArea(dpy, p->picture, win, Scr.TransMaskGC, 0, 0, width, + height, x, y); + break; - y = border; - if (bf->style&VOffCenter) { - if (bf->style&VBottom) - y += (int)(height - p->height); - } else - y += (int)(height - p->height) / 2; - - if (x < border) x = border; - if (y < border) y = border; - if (width > p->width) width = p->width; - if (height > p->height) height = p->height; - if (width > w - x - border) width = w - x - border; - if (height > h - y - border) height = h - y - border; - - XSetClipMask(dpy, Scr.TransMaskGC, p->mask); - XSetClipOrigin(dpy, Scr.TransMaskGC, x, y); - XCopyArea(dpy, p->picture, win, Scr.TransMaskGC, - 0, 0, width, height, x, y); - break; - - case TiledPixmapButton: - XSetWindowBackgroundPixmap(dpy, win, bf->u.p->picture); - flush_expose(win); - XClearWindow(dpy,win); - break; + case TiledPixmapButton: + XSetWindowBackgroundPixmap(dpy, win, bf->u.p->picture); + flush_expose(win); + XClearWindow(dpy, win); + break; #endif /* PIXMAP_BUTTONS */ #ifdef GRADIENT_BUTTONS - case HGradButton: - case VGradButton: - { - XRectangle bounds; - bounds.x = bounds.y = 0; - bounds.width = w; - bounds.height = h; - flush_expose(win); + case HGradButton: + case VGradButton: { + XRectangle bounds; + bounds.x = bounds.y = 0; + bounds.width = w; + bounds.height = h; + flush_expose(win); #ifdef PIXMAP_BUTTONS - XSetClipMask(dpy, Scr.TransMaskGC, None); + XSetClipMask(dpy, Scr.TransMaskGC, None); #endif - if (type == HGradButton) { - register int i = 0, dw = bounds.width - / bf->u.grad.npixels + 1; - while (i < bf->u.grad.npixels) - { - unsigned short x = i * bounds.width / bf->u.grad.npixels; - XSetForeground(dpy, Scr.TransMaskGC, bf->u.grad.pixels[ i++ ]); - XFillRectangle(dpy, win, Scr.TransMaskGC, - bounds.x + x, bounds.y, - dw, bounds.height); - } - } else { - register int i = 0, dh = bounds.height - / bf->u.grad.npixels + 1; - while (i < bf->u.grad.npixels) - { - unsigned short y = i * bounds.height / bf->u.grad.npixels; - XSetForeground(dpy, Scr.TransMaskGC, bf->u.grad.pixels[ i++ ]); - XFillRectangle(dpy, win, Scr.TransMaskGC, - bounds.x, bounds.y + y, - bounds.width, dh); - } + if (type == HGradButton) { + register int i = 0, + dw = bounds.width / bf->u.grad.npixels + 1; + while (i < bf->u.grad.npixels) { + unsigned short x = + i * bounds.width / bf->u.grad.npixels; + XSetForeground(dpy, Scr.TransMaskGC, + bf->u.grad.pixels[i++]); + XFillRectangle(dpy, win, Scr.TransMaskGC, + bounds.x + x, bounds.y, dw, bounds.height); + } + } else { + register int i = 0, + dh = + bounds.height / bf->u.grad.npixels + 1; + while (i < bf->u.grad.npixels) { + unsigned short y = + i * bounds.height / bf->u.grad.npixels; + XSetForeground(dpy, Scr.TransMaskGC, + bf->u.grad.pixels[i++]); + XFillRectangle(dpy, win, Scr.TransMaskGC, + bounds.x, bounds.y + y, bounds.width, dh); + } + } } - } - break; + break; #endif /* GRADIENT_BUTTONS */ - default: - fvwm_msg(ERR,"DrawButton","unknown button type"); - break; - } + default: + fvwm_msg(ERR, "DrawButton", "unknown button type"); + break; + } } /**************************************************************************** @@ -704,252 +764,270 @@ void DrawButton(FvwmWindow *t, Window win, int w, int h, * Redraws just the title bar * ****************************************************************************/ -void SetTitleBar (FvwmWindow *t,Bool onoroff, Bool NewTitle) +void +SetTitleBar(FvwmWindow *t, Bool onoroff, Bool NewTitle) { - int hor_off, w, i; - enum ButtonState title_state; - ButtonFaceStyle tb_style; - int tb_flags; - GC ReliefGC, ShadowGC, tGC; - Pixel Forecolor, BackColor; - - if(!t) - return; - if(!(t->flags & TITLE)) - return; - - if (onoroff) - { - Forecolor = GetDecor(t,HiColors.fore); - BackColor = GetDecor(t,HiColors.back); - ReliefGC = GetDecor(t,HiReliefGC); - ShadowGC = GetDecor(t,HiShadowGC); - } - else - { - Forecolor =t->TextPixel; - BackColor = t->BackPixel; - Globalgcv.foreground = t->ReliefPixel; - Globalgcm = GCForeground; - XChangeGC(dpy,Scr.ScratchGC1,Globalgcm,&Globalgcv); - ReliefGC = Scr.ScratchGC1; - - Globalgcv.foreground = t->ShadowPixel; - XChangeGC(dpy,Scr.ScratchGC2,Globalgcm,&Globalgcv); - ShadowGC = Scr.ScratchGC2; - } - if(PressedW==t->title_w) - { - tGC = ShadowGC; - ShadowGC = ReliefGC; - ReliefGC = tGC; - } - flush_expose(t->title_w); - - if(t->name != (char *)NULL) - { - w=XTextWidth(GetDecor(t,WindowFont.font),t->name,strlen(t->name)); - if(w > t->title_width-12) - w = t->title_width-4; - if(w < 0) - w = 0; - } - else - w = 0; - - title_state = GetButtonState(t->title_w); - tb_style = GetDecor(t,titlebar.state[title_state].style); - tb_flags = GetDecor(t,titlebar.flags); - if (tb_flags & HOffCenter) { - if (tb_flags & HRight) - hor_off = t->title_width - w - 10; - else - hor_off = 10; - } else - hor_off = (t->title_width - w) / 2; - - NewFontAndColor(GetDecor(t,WindowFont.font->fid),Forecolor, BackColor); - - /* the next bit tries to minimize redraw based upon compilation options (veliaa@rpi.edu) */ + int hor_off, w, i; + enum ButtonState title_state; + ButtonFaceStyle tb_style; + int tb_flags; + GC ReliefGC, ShadowGC, tGC; + Pixel Forecolor, BackColor; + + if (!t) + return; + if (!(t->flags & TITLE)) + return; + + if (onoroff) { + Forecolor = GetDecor(t, HiColors.fore); + BackColor = GetDecor(t, HiColors.back); + ReliefGC = GetDecor(t, HiReliefGC); + ShadowGC = GetDecor(t, HiShadowGC); + } else { + Forecolor = t->TextPixel; + BackColor = t->BackPixel; + Globalgcv.foreground = t->ReliefPixel; + Globalgcm = GCForeground; + XChangeGC(dpy, Scr.ScratchGC1, Globalgcm, &Globalgcv); + ReliefGC = Scr.ScratchGC1; + + Globalgcv.foreground = t->ShadowPixel; + XChangeGC(dpy, Scr.ScratchGC2, Globalgcm, &Globalgcv); + ShadowGC = Scr.ScratchGC2; + } + if (PressedW == t->title_w) { + tGC = ShadowGC; + ShadowGC = ReliefGC; + ReliefGC = tGC; + } + flush_expose(t->title_w); + + if (t->name != (char *)NULL) { + w = XTextWidth( + GetDecor(t, WindowFont.font), t->name, strlen(t->name)); + if (w > t->title_width - 12) + w = t->title_width - 4; + if (w < 0) + w = 0; + } else + w = 0; + + title_state = GetButtonState(t->title_w); + tb_style = GetDecor(t, titlebar.state[title_state].style); + tb_flags = GetDecor(t, titlebar.flags); + if (tb_flags & HOffCenter) { + if (tb_flags & HRight) + hor_off = t->title_width - w - 10; + else + hor_off = 10; + } else + hor_off = (t->title_width - w) / 2; + + NewFontAndColor( + GetDecor(t, WindowFont.font->fid), Forecolor, BackColor); + + /* the next bit tries to minimize redraw based upon compilation options + * (veliaa@rpi.edu) */ #ifdef EXTENDED_TITLESTYLE #if defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE) - /* we need to check for UseBorderStyle for the titlebar */ - { - ButtonFace *bf = onoroff - ? &GetDecor(t,BorderStyle.active) - : &GetDecor(t,BorderStyle.inactive); - - if ((tb_style & UseBorderStyle) - && ((bf->style & ButtonFaceTypeMask) == TiledPixmapButton)) - XSetWindowBackgroundPixmap(dpy,t->title_w,bf->u.p->picture); - } + /* we need to check for UseBorderStyle for the titlebar */ + { + ButtonFace *bf = onoroff ? &GetDecor(t, BorderStyle.active) : + &GetDecor(t, BorderStyle.inactive); + + if ((tb_style & UseBorderStyle) && + ((bf->style & ButtonFaceTypeMask) == TiledPixmapButton)) + XSetWindowBackgroundPixmap( + dpy, t->title_w, bf->u.p->picture); + } #endif /* PIXMAP_BUTTONS && BORDERSTYLE */ - XClearWindow(dpy,t->title_w); -#else /* ! EXTENDED_TITLESTYLE */ - /* if no extended titlestyle, only clear when necessary */ - if (NewTitle) - XClearWindow(dpy,t->title_w); + XClearWindow(dpy, t->title_w); +#else /* ! EXTENDED_TITLESTYLE */ + /* if no extended titlestyle, only clear when necessary */ + if (NewTitle) + XClearWindow(dpy, t->title_w); #endif /* EXTENDED_TITLESTYLE */ - /* for mono, we clear an area in the title bar where the window - * title goes, so that its more legible. For color, no need */ - if(Scr.d_depth<2) - { - RelieveWindow(t,t->title_w,0,0,hor_off-2,t->title_height, - ReliefGC, ShadowGC, BOTTOM_HILITE); - RelieveWindow(t,t->title_w,hor_off+w+2,0, - t->title_width - w - hor_off-2,t->title_height, - ReliefGC, ShadowGC, BOTTOM_HILITE); - XFillRectangle(dpy,t->title_w, - (PressedW==t->title_w?ShadowGC:ReliefGC), - hor_off - 2, 0, w+4,t->title_height); - - XDrawLine(dpy,t->title_w,ShadowGC,hor_off+w+1,0,hor_off+w+1, - t->title_height); - if(t->name != (char *)NULL) - XDrawString (dpy, t->title_w,Scr.ScratchGC3,hor_off, - GetDecor(t,WindowFont.y)+1, - t->name, strlen(t->name)); - } - else - { + /* for mono, we clear an area in the title bar where the window + * title goes, so that its more legible. For color, no need */ + if (Scr.d_depth < 2) { + RelieveWindow(t, t->title_w, 0, 0, hor_off - 2, t->title_height, + ReliefGC, ShadowGC, BOTTOM_HILITE); + RelieveWindow(t, t->title_w, hor_off + w + 2, 0, + t->title_width - w - hor_off - 2, t->title_height, ReliefGC, + ShadowGC, BOTTOM_HILITE); + XFillRectangle(dpy, t->title_w, + (PressedW == t->title_w ? ShadowGC : ReliefGC), hor_off - 2, + 0, w + 4, t->title_height); + + XDrawLine(dpy, t->title_w, ShadowGC, hor_off + w + 1, 0, + hor_off + w + 1, t->title_height); + if (t->name != (char *)NULL) + XDrawString(dpy, t->title_w, Scr.ScratchGC3, hor_off, + GetDecor(t, WindowFont.y) + 1, t->name, + strlen(t->name)); + } else { #ifdef EXTENDED_TITLESTYLE - ButtonFace *bf = &GetDecor(t,titlebar.state[title_state]); - /* draw compound titlebar (veliaa@rpi.edu) */ - if (PressedW == t->title_w) { + ButtonFace *bf = &GetDecor(t, titlebar.state[title_state]); + /* draw compound titlebar (veliaa@rpi.edu) */ + if (PressedW == t->title_w) { #ifdef MULTISTYLE - for (; bf; bf = bf->next) + for (; bf; bf = bf->next) #endif - DrawButton(t, t->title_w, t->title_width, t->title_height, - bf, ShadowGC, ReliefGC, True, 0); - } else { + DrawButton(t, t->title_w, t->title_width, + t->title_height, bf, ShadowGC, ReliefGC, + True, 0); + } else { #ifdef MULTISTYLE - for (; bf; bf = bf->next) + for (; bf; bf = bf->next) #endif - DrawButton(t, t->title_w, t->title_width, t->title_height, - bf, ReliefGC, ShadowGC, False, 0); - } + DrawButton(t, t->title_w, t->title_width, + t->title_height, bf, ReliefGC, ShadowGC, + False, 0); + } #endif /* EXTENDED_TITLESTYLE */ - if (!(tb_style & FlatButton)) { - if (tb_style & SunkButton) - RelieveWindow(t,t->title_w,0,0,t->title_width,t->title_height, - ShadowGC, ReliefGC, BOTTOM_HILITE); - else - RelieveWindow(t,t->title_w,0,0,t->title_width,t->title_height, - ReliefGC, ShadowGC, BOTTOM_HILITE); - } - - if(t->name != (char *)NULL) - XDrawString (dpy, t->title_w,Scr.ScratchGC3,hor_off, - GetDecor(t,WindowFont.y)+1, - t->name, strlen(t->name)); - } - /* now, draw lines in title bar if it's a sticky window */ - if(t->flags & STICKY || Scr.StipledTitles) - { - for(i=0 ;i< t->title_height/2-3;i+=4) - { - XDrawLine(dpy,t->title_w,ShadowGC,4,t->title_height/2 - i-1, - hor_off-6,t->title_height/2-i-1); - XDrawLine(dpy,t->title_w,ShadowGC,6+hor_off+w,t->title_height/2 -i-1, - t->title_width-5,t->title_height/2- i-1); - XDrawLine(dpy,t->title_w,ReliefGC,4,t->title_height/2 - i, - hor_off-6,t->title_height/2 - i); - XDrawLine(dpy,t->title_w,ReliefGC,6+hor_off+w,t->title_height/2-i, - t->title_width-5,t->title_height/2 - i); - - XDrawLine(dpy,t->title_w,ShadowGC,4,t->title_height/2 + i-1, - hor_off-6,t->title_height/2+i-1); - XDrawLine(dpy,t->title_w,ShadowGC,6+hor_off+w,t->title_height/2+i-1, - t->title_width-5,t->title_height/2 + i-1); - XDrawLine(dpy,t->title_w,ReliefGC,4,t->title_height/2 + i, - hor_off-6,t->title_height/2 + i); - XDrawLine(dpy,t->title_w,ReliefGC,6+hor_off+w,t->title_height/2+i, - t->title_width-5,t->title_height/2 + i); - } - } - - - XFlush(dpy); -} - + if (!(tb_style & FlatButton)) { + if (tb_style & SunkButton) + RelieveWindow(t, t->title_w, 0, 0, + t->title_width, t->title_height, ShadowGC, + ReliefGC, BOTTOM_HILITE); + else + RelieveWindow(t, t->title_w, 0, 0, + t->title_width, t->title_height, ReliefGC, + ShadowGC, BOTTOM_HILITE); + } + if (t->name != (char *)NULL) + XDrawString(dpy, t->title_w, Scr.ScratchGC3, hor_off, + GetDecor(t, WindowFont.y) + 1, t->name, + strlen(t->name)); + } + /* now, draw lines in title bar if it's a sticky window */ + if (t->flags & STICKY || Scr.StipledTitles) { + for (i = 0; i < t->title_height / 2 - 3; i += 4) { + XDrawLine(dpy, t->title_w, ShadowGC, 4, + t->title_height / 2 - i - 1, hor_off - 6, + t->title_height / 2 - i - 1); + XDrawLine(dpy, t->title_w, ShadowGC, 6 + hor_off + w, + t->title_height / 2 - i - 1, t->title_width - 5, + t->title_height / 2 - i - 1); + XDrawLine(dpy, t->title_w, ReliefGC, 4, + t->title_height / 2 - i, hor_off - 6, + t->title_height / 2 - i); + XDrawLine(dpy, t->title_w, ReliefGC, 6 + hor_off + w, + t->title_height / 2 - i, t->title_width - 5, + t->title_height / 2 - i); + + XDrawLine(dpy, t->title_w, ShadowGC, 4, + t->title_height / 2 + i - 1, hor_off - 6, + t->title_height / 2 + i - 1); + XDrawLine(dpy, t->title_w, ShadowGC, 6 + hor_off + w, + t->title_height / 2 + i - 1, t->title_width - 5, + t->title_height / 2 + i - 1); + XDrawLine(dpy, t->title_w, ReliefGC, 4, + t->title_height / 2 + i, hor_off - 6, + t->title_height / 2 + i); + XDrawLine(dpy, t->title_w, ReliefGC, 6 + hor_off + w, + t->title_height / 2 + i, t->title_width - 5, + t->title_height / 2 + i); + } + } + XFlush(dpy); +} /**************************************************************************** * * Draws the relief pattern around a window * ****************************************************************************/ -void RelieveWindow(FvwmWindow *t,Window win, int x,int y,int w,int h, - GC ReliefGC, GC ShadowGC, int hilite) +void +RelieveWindow(FvwmWindow *t, Window win, int x, int y, int w, int h, + GC ReliefGC, GC ShadowGC, int hilite) { - XSegment seg[4]; - int i; - int edge; - - edge = 0; - if((win == t->sides[0])||(win == t->sides[1])|| - (win == t->sides[2])||(win == t->sides[3])) - edge = -1; - if(win == t->corners[0]) - edge = 1; - if(win == t->corners[1]) - edge = 2; - if(win == t->corners[2]) - edge = 3; - if(win == t->corners[3]) - edge = 4; - - i=0; - seg[i].x1 = x; seg[i].y1 = y; - seg[i].x2 = w+x-1; seg[i++].y2 = y; - - seg[i].x1 = x; seg[i].y1 = y; - seg[i].x2 = x; seg[i++].y2 = h+y-1; - - if(((t->boundary_width > 2)||(edge == 0))&& - ((t->boundary_width > 3)||(edge < 1))&& - (!(t->flags & MWMBorders)|| - (((edge==0)||(t->boundary_width > 3))&&(hilite & TOP_HILITE)))) - { - seg[i].x1 = x+1; seg[i].y1 = y+1; - seg[i].x2 = x+w-2; seg[i++].y2 = y+1; - } - if(((t->boundary_width > 2)||(edge == 0))&& - ((t->boundary_width > 3)||(edge < 1))&& - (!(t->flags & MWMBorders)|| - (((edge==0)||(t->boundary_width > 3))&&(hilite & LEFT_HILITE)))) - { - seg[i].x1 = x+1; seg[i].y1 = y+1; - seg[i].x2 = x+1; seg[i++].y2 = y+h-2; - } - XDrawSegments(dpy, win, ReliefGC, seg, i); - - i=0; - seg[i].x1 = x; seg[i].y1 = y+h-1; - seg[i].x2 = w+x-1; seg[i++].y2 = y+h-1; - - if(((t->boundary_width > 2)||(edge == 0))&& - (!(t->flags & MWMBorders)|| - (((edge==0)||(t->boundary_width > 3))&&(hilite & BOTTOM_HILITE)))) - { - seg[i].x1 = x+1; seg[i].y1 = y+h-2; - seg[i].x2 = x+w-2; seg[i++].y2 = y+h-2; - } - - seg[i].x1 = x+w-1; seg[i].y1 = y; - seg[i].x2 = x+w-1; seg[i++].y2 = y+h-1; - - if(((t->boundary_width > 2)||(edge == 0))&& - (!(t->flags & MWMBorders)|| - (((edge==0)||(t->boundary_width > 3))&&(hilite & RIGHT_HILITE)))) - { - seg[i].x1 = x+w-2; seg[i].y1 = y+1; - seg[i].x2 = x+w-2; seg[i++].y2 = y+h-2; - } - XDrawSegments(dpy, win, ShadowGC, seg, i); + XSegment seg[4]; + int i; + int edge; + + edge = 0; + if ((win == t->sides[0]) || (win == t->sides[1]) || + (win == t->sides[2]) || (win == t->sides[3])) + edge = -1; + if (win == t->corners[0]) + edge = 1; + if (win == t->corners[1]) + edge = 2; + if (win == t->corners[2]) + edge = 3; + if (win == t->corners[3]) + edge = 4; + + i = 0; + seg[i].x1 = x; + seg[i].y1 = y; + seg[i].x2 = w + x - 1; + seg[i++].y2 = y; + + seg[i].x1 = x; + seg[i].y1 = y; + seg[i].x2 = x; + seg[i++].y2 = h + y - 1; + + if (((t->boundary_width > 2) || (edge == 0)) && + ((t->boundary_width > 3) || (edge < 1)) && + (!(t->flags & MWMBorders) || + (((edge == 0) || (t->boundary_width > 3)) && + (hilite & TOP_HILITE)))) { + seg[i].x1 = x + 1; + seg[i].y1 = y + 1; + seg[i].x2 = x + w - 2; + seg[i++].y2 = y + 1; + } + if (((t->boundary_width > 2) || (edge == 0)) && + ((t->boundary_width > 3) || (edge < 1)) && + (!(t->flags & MWMBorders) || + (((edge == 0) || (t->boundary_width > 3)) && + (hilite & LEFT_HILITE)))) { + seg[i].x1 = x + 1; + seg[i].y1 = y + 1; + seg[i].x2 = x + 1; + seg[i++].y2 = y + h - 2; + } + XDrawSegments(dpy, win, ReliefGC, seg, i); + + i = 0; + seg[i].x1 = x; + seg[i].y1 = y + h - 1; + seg[i].x2 = w + x - 1; + seg[i++].y2 = y + h - 1; + + if (((t->boundary_width > 2) || (edge == 0)) && + (!(t->flags & MWMBorders) || + (((edge == 0) || (t->boundary_width > 3)) && + (hilite & BOTTOM_HILITE)))) { + seg[i].x1 = x + 1; + seg[i].y1 = y + h - 2; + seg[i].x2 = x + w - 2; + seg[i++].y2 = y + h - 2; + } + + seg[i].x1 = x + w - 1; + seg[i].y1 = y; + seg[i].x2 = x + w - 1; + seg[i++].y2 = y + h - 1; + + if (((t->boundary_width > 2) || (edge == 0)) && + (!(t->flags & MWMBorders) || + (((edge == 0) || (t->boundary_width > 3)) && + (hilite & RIGHT_HILITE)))) { + seg[i].x1 = x + w - 2; + seg[i].y1 = y + 1; + seg[i].x2 = x + w - 2; + seg[i++].y2 = y + h - 2; + } + XDrawSegments(dpy, win, ShadowGC, seg, i); } #ifdef BORDERSTYLE @@ -960,296 +1038,311 @@ void RelieveWindow(FvwmWindow *t,Window win, int x,int y,int w,int h, * (veliaa@rpi.edu) * ****************************************************************************/ -void RelieveWindowHH(FvwmWindow *t,Window win, int x,int y,int w,int h, - GC ReliefGC, GC ShadowGC, int draw, int hilite) +void +RelieveWindowHH(FvwmWindow *t, Window win, int x, int y, int w, int h, + GC ReliefGC, GC ShadowGC, int draw, int hilite) { - XSegment seg[4]; - int i = 0; - int edge = 0, a = 0, b = 0; - - if(win == t->sides[0]) { - edge = 5; - b = 1; - } - else if (win == t->sides[1]) { - a = 1; - edge = 6; - } - else if (win == t->sides[2]) { - edge = 7; - b = 1; - } - else if (win == t->sides[3]) { - edge = 8; - a = 1; - } else if (win == t->corners[0]) - edge = 1; - else if (win == t->corners[1]) - edge = 2; - else if (win == t->corners[2]) - edge = 3; - else if (win == t->corners[3]) - edge = 4; - - if (draw & TOP_HILITE) { - seg[i].x1 = x; seg[i].y1 = y; - seg[i].x2 = w+x-1; seg[i++].y2 = y; - - if(((t->boundary_width > 2)||(edge == 0))&& - ((t->boundary_width > 3)||(edge < 1))&& - (!(t->flags & MWMBorders)|| - (((edge==0)||(t->boundary_width > 3))&&(hilite & TOP_HILITE)))) - { - seg[i].x1 = x+((edge == 2)|| b ? 0 : 1); seg[i].y1 = y+1; - seg[i].x2 = x+w-1-((edge == 1)|| b ? 0 : 1); seg[i++].y2 = y+1; + XSegment seg[4]; + int i = 0; + int edge = 0, a = 0, b = 0; + + if (win == t->sides[0]) { + edge = 5; + b = 1; + } else if (win == t->sides[1]) { + a = 1; + edge = 6; + } else if (win == t->sides[2]) { + edge = 7; + b = 1; + } else if (win == t->sides[3]) { + edge = 8; + a = 1; + } else if (win == t->corners[0]) + edge = 1; + else if (win == t->corners[1]) + edge = 2; + else if (win == t->corners[2]) + edge = 3; + else if (win == t->corners[3]) + edge = 4; + + if (draw & TOP_HILITE) { + seg[i].x1 = x; + seg[i].y1 = y; + seg[i].x2 = w + x - 1; + seg[i++].y2 = y; + + if (((t->boundary_width > 2) || (edge == 0)) && + ((t->boundary_width > 3) || (edge < 1)) && + (!(t->flags & MWMBorders) || + (((edge == 0) || (t->boundary_width > 3)) && + (hilite & TOP_HILITE)))) { + seg[i].x1 = x + ((edge == 2) || b ? 0 : 1); + seg[i].y1 = y + 1; + seg[i].x2 = x + w - 1 - ((edge == 1) || b ? 0 : 1); + seg[i++].y2 = y + 1; + } } - } - - if (draw & LEFT_HILITE) { - seg[i].x1 = x; seg[i].y1 = y; - seg[i].x2 = x; seg[i++].y2 = h+y-1; - if(((t->boundary_width > 2)||(edge == 0))&& - ((t->boundary_width > 3)||(edge < 1))&& - (!(t->flags & MWMBorders)|| - (((edge==0)||(t->boundary_width > 3))&&(hilite & LEFT_HILITE)))) - { - seg[i].x1 = x+1; seg[i].y1 = y+((edge == 3)|| a ? 0 : 1); - seg[i].x2 = x+1; seg[i++].y2 = y+h-1-((edge == 1)|| a ? 0 : 1); + if (draw & LEFT_HILITE) { + seg[i].x1 = x; + seg[i].y1 = y; + seg[i].x2 = x; + seg[i++].y2 = h + y - 1; + + if (((t->boundary_width > 2) || (edge == 0)) && + ((t->boundary_width > 3) || (edge < 1)) && + (!(t->flags & MWMBorders) || + (((edge == 0) || (t->boundary_width > 3)) && + (hilite & LEFT_HILITE)))) { + seg[i].x1 = x + 1; + seg[i].y1 = y + ((edge == 3) || a ? 0 : 1); + seg[i].x2 = x + 1; + seg[i++].y2 = y + h - 1 - ((edge == 1) || a ? 0 : 1); + } } - } - XDrawSegments(dpy, win, ReliefGC, seg, i); - - i=0; - - if (draw & BOTTOM_HILITE) { - seg[i].x1 = x; seg[i].y1 = y+h-1; - seg[i].x2 = w+x-1; seg[i++].y2 = y+h-1; - - if(((t->boundary_width > 2)||(edge == 0))&& - (!(t->flags & MWMBorders)|| - (((edge==0)||(t->boundary_width > 3))&&(hilite & BOTTOM_HILITE)))) - { - seg[i].x1 = x+(b ||(edge == 4) ? 0 : 1); seg[i].y1 = y+h-2; - seg[i].x2 = x+w-((edge == 3) ? 0 : 1); seg[i++].y2 = y+h-2; + XDrawSegments(dpy, win, ReliefGC, seg, i); + + i = 0; + + if (draw & BOTTOM_HILITE) { + seg[i].x1 = x; + seg[i].y1 = y + h - 1; + seg[i].x2 = w + x - 1; + seg[i++].y2 = y + h - 1; + + if (((t->boundary_width > 2) || (edge == 0)) && + (!(t->flags & MWMBorders) || + (((edge == 0) || (t->boundary_width > 3)) && + (hilite & BOTTOM_HILITE)))) { + seg[i].x1 = x + (b || (edge == 4) ? 0 : 1); + seg[i].y1 = y + h - 2; + seg[i].x2 = x + w - ((edge == 3) ? 0 : 1); + seg[i++].y2 = y + h - 2; + } } - } - if (draw & RIGHT_HILITE) { - seg[i].x1 = x+w-1; seg[i].y1 = y; - seg[i].x2 = x+w-1; seg[i++].y2 = y+h-1; - - if(((t->boundary_width > 2)||(edge == 0))&& - (!(t->flags & MWMBorders)|| - (((edge==0)||(t->boundary_width > 3))&&(hilite & RIGHT_HILITE)))) - { - seg[i].x1 = x+w-2; seg[i].y1 = y+(a ||(edge == 4) ? 0 : 1); - seg[i].x2 = x+w-2; seg[i++].y2 = y+h-1-((edge == 2)|| a ? 0 : 1); + if (draw & RIGHT_HILITE) { + seg[i].x1 = x + w - 1; + seg[i].y1 = y; + seg[i].x2 = x + w - 1; + seg[i++].y2 = y + h - 1; + + if (((t->boundary_width > 2) || (edge == 0)) && + (!(t->flags & MWMBorders) || + (((edge == 0) || (t->boundary_width > 3)) && + (hilite & RIGHT_HILITE)))) { + seg[i].x1 = x + w - 2; + seg[i].y1 = y + (a || (edge == 4) ? 0 : 1); + seg[i].x2 = x + w - 2; + seg[i++].y2 = y + h - 1 - ((edge == 2) || a ? 0 : 1); + } } - } - XDrawSegments(dpy, win, ShadowGC, seg, i); + XDrawSegments(dpy, win, ShadowGC, seg, i); } #endif /* BORDERSTYLE */ -void RelieveParts(FvwmWindow *t,int i,GC hor, GC vert) +void +RelieveParts(FvwmWindow *t, int i, GC hor, GC vert) { - XSegment seg[2]; - int n = 0, hh = i & HH_HILITE; - i &= FULL_HILITE; - - if((t->flags & MWMBorders)||(t->boundary_width < 3)) - { - switch(i) - { - case 0: - seg[0].x1 = t->boundary_width-1; - seg[0].x2 = t->corner_width; - seg[0].y1 = t->boundary_width-1; - seg[0].y2 = t->boundary_width-1; - n=1; - break; - case 1: - seg[0].x1 = 0; - seg[0].x2 = t->corner_width - t->boundary_width /* -1*/ ; - seg[0].y1 = t->boundary_width-1; - seg[0].y2 = t->boundary_width-1; - n=1; - break; - case 2: - seg[0].x1 = t->boundary_width-1; - seg[0].x2 = t->corner_width - (hh ? 1 : 2); - seg[0].y1 = t->corner_width - t->boundary_width+t->bw; - seg[0].y2 = t->corner_width - t->boundary_width+t->bw; - n=1; - break; - case 3: - seg[0].x1 = 0; - seg[0].x2 = t->corner_width - t->boundary_width; - seg[0].y1 = t->corner_width - t->boundary_width+t->bw; - seg[0].y2 = t->corner_width - t->boundary_width+t->bw; - n=1; - break; - } - XDrawSegments(dpy, t->corners[i], hor, seg, n); - switch(i) - { - case 0: - seg[0].y1 = t->boundary_width-1; - seg[0].y2 = t->corner_width; - seg[0].x1 = t->boundary_width-1; - seg[0].x2 = t->boundary_width-1; - n=1; - break; - case 1: - seg[0].y1 = t->boundary_width -1; - seg[0].y2 = t->corner_width - (hh ? 0 : 2); - seg[0].x1 = t->corner_width - t->boundary_width; - seg[0].x2 = t->corner_width - t->boundary_width; - n=1; - break; - case 2: - seg[0].y1 = 0; - seg[0].y2 = t->corner_width - t->boundary_width; - seg[0].x1 = t->boundary_width-1; - seg[0].x2 = t->boundary_width-1; - n=1; - break; - case 3: - seg[0].y1 = 0; - seg[0].y2 = t->corner_width - t->boundary_width + t->bw; - seg[0].x1 = t->corner_width - t->boundary_width; - seg[0].x2 = t->corner_width - t->boundary_width; - n=1; - break; - } - XDrawSegments(dpy, t->corners[i], vert, seg, 1); - } - else - { - switch(i) - { - case 0: - seg[0].x1 = t->boundary_width-2; - seg[0].x2 = t->corner_width; - seg[0].y1 = t->boundary_width-2; - seg[0].y2 = t->boundary_width-2; - - seg[1].x1 = t->boundary_width-2; - seg[1].x2 = t->corner_width; - seg[1].y1 = t->boundary_width-1; - seg[1].y2 = t->boundary_width-1; - n=2; - break; - case 1: - seg[0].x1 = (hh ? 0 : 1); - seg[0].x2 = t->corner_width - t->boundary_width; - seg[0].y1 = t->boundary_width-2; - seg[0].y2 = t->boundary_width-2; - - seg[1].x1 = 0; - seg[1].x2 = t->corner_width - t->boundary_width-1; - seg[1].y1 = t->boundary_width-1; - seg[1].y2 = t->boundary_width-1; - n=2; - break; - case 2: - seg[0].x1 = t->boundary_width-1; - seg[0].x2 = t->corner_width - (hh ? 1 : 2); - seg[0].y1 = t->corner_width - t->boundary_width+1; - seg[0].y2 = t->corner_width - t->boundary_width+1; - n=1; - if(t->boundary_width > 3) - { - seg[1].x1 = t->boundary_width-2; - seg[1].x2 = t->corner_width - (hh ? 1 : 3); - seg[1].y1 = t->corner_width - t->boundary_width + 2; - seg[1].y2 = t->corner_width - t->boundary_width + 2; - n=2; - } - break; - case 3: - seg[0].x1 = 0; - seg[0].x2 = t->corner_width - t->boundary_width; - seg[0].y1 = t->corner_width - t->boundary_width+1; - seg[0].y2 = t->corner_width - t->boundary_width+1; - n=1; - if(t->boundary_width > 3) - { - seg[0].x2 = t->corner_width - t->boundary_width + 1; - - seg[1].x1 = 0; - seg[1].x2 = t->corner_width - t->boundary_width + 1; - seg[1].y1 = t->corner_width - t->boundary_width + 2; - seg[1].y2 = t->corner_width - t->boundary_width + 2; - n=2; - } - break; - } - XDrawSegments(dpy, t->corners[i], hor, seg, n); - switch(i) - { - case 0: - seg[0].y1 = t->boundary_width-2; - seg[0].y2 = t->corner_width; - seg[0].x1 = t->boundary_width-2; - seg[0].x2 = t->boundary_width-2; - - seg[1].y1 = t->boundary_width-2; - seg[1].y2 = t->corner_width; - seg[1].x1 = t->boundary_width-1; - seg[1].x2 = t->boundary_width-1; - n=2; - break; - case 1: - seg[0].y1 = t->boundary_width-1; - seg[0].y2 = t->corner_width - (hh ? 1 : 2); - seg[0].x1 = t->corner_width - t->boundary_width; - seg[0].x2 = t->corner_width - t->boundary_width; - n=1; - if(t->boundary_width > 3) - { - seg[1].y1 = t->boundary_width-2; - seg[1].y2 = t->corner_width - (hh ? 1 : 3); - seg[1].x1 = t->corner_width - t->boundary_width+1; - seg[1].x2 = t->corner_width - t->boundary_width+1; - n=2; - } - break; - case 2: - seg[0].y1 = (hh ? 0 : 1); - seg[0].y2 = t->corner_width - t->boundary_width+1; - seg[0].x1 = t->boundary_width-2; - seg[0].x2 = t->boundary_width-2; - n=1; - - if(t->boundary_width > 3) - { - seg[1].y1 = 0; - seg[1].y2 = t->corner_width - t->boundary_width; - seg[1].x1 = t->boundary_width-1; - seg[1].x2 = t->boundary_width-1; - } - break; - case 3: - seg[0].y1 = 0; - seg[0].y2 = t->corner_width - t->boundary_width + 1; - seg[0].x1 = t->corner_width - t->boundary_width; - seg[0].x2 = t->corner_width - t->boundary_width; - n=1; - - if(t->boundary_width > 3) - { - seg[0].y2 = t->corner_width - t->boundary_width + 2; - seg[1].y1 = 0; - seg[1].y2 = t->corner_width - t->boundary_width + 2; - seg[1].x1 = t->corner_width - t->boundary_width + 1; - seg[1].x2 = t->corner_width - t->boundary_width + 1; - n=2; - } - break; - } - XDrawSegments(dpy, t->corners[i], vert, seg, n); - } + XSegment seg[2]; + int n = 0, hh = i & HH_HILITE; + i &= FULL_HILITE; + + if ((t->flags & MWMBorders) || (t->boundary_width < 3)) { + switch (i) { + case 0: + seg[0].x1 = t->boundary_width - 1; + seg[0].x2 = t->corner_width; + seg[0].y1 = t->boundary_width - 1; + seg[0].y2 = t->boundary_width - 1; + n = 1; + break; + case 1: + seg[0].x1 = 0; + seg[0].x2 = t->corner_width - t->boundary_width /* -1*/; + seg[0].y1 = t->boundary_width - 1; + seg[0].y2 = t->boundary_width - 1; + n = 1; + break; + case 2: + seg[0].x1 = t->boundary_width - 1; + seg[0].x2 = t->corner_width - (hh ? 1 : 2); + seg[0].y1 = t->corner_width - t->boundary_width + t->bw; + seg[0].y2 = t->corner_width - t->boundary_width + t->bw; + n = 1; + break; + case 3: + seg[0].x1 = 0; + seg[0].x2 = t->corner_width - t->boundary_width; + seg[0].y1 = t->corner_width - t->boundary_width + t->bw; + seg[0].y2 = t->corner_width - t->boundary_width + t->bw; + n = 1; + break; + } + XDrawSegments(dpy, t->corners[i], hor, seg, n); + switch (i) { + case 0: + seg[0].y1 = t->boundary_width - 1; + seg[0].y2 = t->corner_width; + seg[0].x1 = t->boundary_width - 1; + seg[0].x2 = t->boundary_width - 1; + n = 1; + break; + case 1: + seg[0].y1 = t->boundary_width - 1; + seg[0].y2 = t->corner_width - (hh ? 0 : 2); + seg[0].x1 = t->corner_width - t->boundary_width; + seg[0].x2 = t->corner_width - t->boundary_width; + n = 1; + break; + case 2: + seg[0].y1 = 0; + seg[0].y2 = t->corner_width - t->boundary_width; + seg[0].x1 = t->boundary_width - 1; + seg[0].x2 = t->boundary_width - 1; + n = 1; + break; + case 3: + seg[0].y1 = 0; + seg[0].y2 = t->corner_width - t->boundary_width + t->bw; + seg[0].x1 = t->corner_width - t->boundary_width; + seg[0].x2 = t->corner_width - t->boundary_width; + n = 1; + break; + } + XDrawSegments(dpy, t->corners[i], vert, seg, 1); + } else { + switch (i) { + case 0: + seg[0].x1 = t->boundary_width - 2; + seg[0].x2 = t->corner_width; + seg[0].y1 = t->boundary_width - 2; + seg[0].y2 = t->boundary_width - 2; + + seg[1].x1 = t->boundary_width - 2; + seg[1].x2 = t->corner_width; + seg[1].y1 = t->boundary_width - 1; + seg[1].y2 = t->boundary_width - 1; + n = 2; + break; + case 1: + seg[0].x1 = (hh ? 0 : 1); + seg[0].x2 = t->corner_width - t->boundary_width; + seg[0].y1 = t->boundary_width - 2; + seg[0].y2 = t->boundary_width - 2; + + seg[1].x1 = 0; + seg[1].x2 = t->corner_width - t->boundary_width - 1; + seg[1].y1 = t->boundary_width - 1; + seg[1].y2 = t->boundary_width - 1; + n = 2; + break; + case 2: + seg[0].x1 = t->boundary_width - 1; + seg[0].x2 = t->corner_width - (hh ? 1 : 2); + seg[0].y1 = t->corner_width - t->boundary_width + 1; + seg[0].y2 = t->corner_width - t->boundary_width + 1; + n = 1; + if (t->boundary_width > 3) { + seg[1].x1 = t->boundary_width - 2; + seg[1].x2 = t->corner_width - (hh ? 1 : 3); + seg[1].y1 = + t->corner_width - t->boundary_width + 2; + seg[1].y2 = + t->corner_width - t->boundary_width + 2; + n = 2; + } + break; + case 3: + seg[0].x1 = 0; + seg[0].x2 = t->corner_width - t->boundary_width; + seg[0].y1 = t->corner_width - t->boundary_width + 1; + seg[0].y2 = t->corner_width - t->boundary_width + 1; + n = 1; + if (t->boundary_width > 3) { + seg[0].x2 = + t->corner_width - t->boundary_width + 1; + + seg[1].x1 = 0; + seg[1].x2 = + t->corner_width - t->boundary_width + 1; + seg[1].y1 = + t->corner_width - t->boundary_width + 2; + seg[1].y2 = + t->corner_width - t->boundary_width + 2; + n = 2; + } + break; + } + XDrawSegments(dpy, t->corners[i], hor, seg, n); + switch (i) { + case 0: + seg[0].y1 = t->boundary_width - 2; + seg[0].y2 = t->corner_width; + seg[0].x1 = t->boundary_width - 2; + seg[0].x2 = t->boundary_width - 2; + + seg[1].y1 = t->boundary_width - 2; + seg[1].y2 = t->corner_width; + seg[1].x1 = t->boundary_width - 1; + seg[1].x2 = t->boundary_width - 1; + n = 2; + break; + case 1: + seg[0].y1 = t->boundary_width - 1; + seg[0].y2 = t->corner_width - (hh ? 1 : 2); + seg[0].x1 = t->corner_width - t->boundary_width; + seg[0].x2 = t->corner_width - t->boundary_width; + n = 1; + if (t->boundary_width > 3) { + seg[1].y1 = t->boundary_width - 2; + seg[1].y2 = t->corner_width - (hh ? 1 : 3); + seg[1].x1 = + t->corner_width - t->boundary_width + 1; + seg[1].x2 = + t->corner_width - t->boundary_width + 1; + n = 2; + } + break; + case 2: + seg[0].y1 = (hh ? 0 : 1); + seg[0].y2 = t->corner_width - t->boundary_width + 1; + seg[0].x1 = t->boundary_width - 2; + seg[0].x2 = t->boundary_width - 2; + n = 1; + + if (t->boundary_width > 3) { + seg[1].y1 = 0; + seg[1].y2 = t->corner_width - t->boundary_width; + seg[1].x1 = t->boundary_width - 1; + seg[1].x2 = t->boundary_width - 1; + } + break; + case 3: + seg[0].y1 = 0; + seg[0].y2 = t->corner_width - t->boundary_width + 1; + seg[0].x1 = t->corner_width - t->boundary_width; + seg[0].x2 = t->corner_width - t->boundary_width; + n = 1; + + if (t->boundary_width > 3) { + seg[0].y2 = + t->corner_width - t->boundary_width + 2; + seg[1].y1 = 0; + seg[1].y2 = + t->corner_width - t->boundary_width + 2; + seg[1].x1 = + t->corner_width - t->boundary_width + 1; + seg[1].x2 = + t->corner_width - t->boundary_width + 1; + n = 2; + } + break; + } + XDrawSegments(dpy, t->corners[i], vert, seg, n); + } } #ifdef VECTOR_BUTTONS @@ -1258,26 +1351,19 @@ void RelieveParts(FvwmWindow *t,int i,GC hor, GC vert) * Draws a little pattern within a window (more complex) * ****************************************************************************/ -void DrawLinePattern(Window win, - GC ReliefGC, - GC ShadowGC, - struct vector_coords *coords, - int w, int h) +void +DrawLinePattern(Window win, GC ReliefGC, GC ShadowGC, + struct vector_coords *coords, int w, int h) { - int i = 1; - for (; i < coords->num; ++i) - { - XDrawLine(dpy,win, - coords->line_style[i] ? ReliefGC : ShadowGC, - w * coords->x[i-1]/100, - h * coords->y[i-1]/100, - w * coords->x[i]/100, - h * coords->y[i]/100); - } + int i = 1; + for (; i < coords->num; ++i) { + XDrawLine(dpy, win, coords->line_style[i] ? ReliefGC : ShadowGC, + w * coords->x[i - 1] / 100, h * coords->y[i - 1] / 100, + w * coords->x[i] / 100, h * coords->y[i] / 100); + } } #endif /* VECTOR_BUTTONS */ - /*********************************************************************** * * Procedure: @@ -1303,309 +1389,303 @@ void DrawLinePattern(Window win, * ************************************************************************/ -void SetupFrame(FvwmWindow *tmp_win,int x,int y,int w,int h,Bool sendEvent) +void +SetupFrame(FvwmWindow *tmp_win, int x, int y, int w, int h, Bool sendEvent) { - XEvent client_event; - XWindowChanges frame_wc, xwc; - unsigned long frame_mask, xwcm; - int cx,cy,i; - Bool Resized = False, Moved = False; - int xwidth,ywidth,left,right; + XEvent client_event; + XWindowChanges frame_wc, xwc; + unsigned long frame_mask, xwcm; + int cx, cy, i; + Bool Resized = False, Moved = False; + int xwidth, ywidth, left, right; #ifdef WINDOWSHADE - int shaded = tmp_win->buttons & WSHADE; + int shaded = tmp_win->buttons & WSHADE; #endif #ifdef FVWM_DEBUG_MSGS - fvwm_msg(DBG,"SetupFrame", - "Routine Entered (x == %d, y == %d, w == %d, h == %d)", - x, y, w, h); + fvwm_msg(DBG, "SetupFrame", + "Routine Entered (x == %d, y == %d, w == %d, h == %d)", x, y, w, h); #endif - /* if windows is not being maximized, save size in case of maximization */ - if (!(tmp_win->flags & MAXIMIZED) + /* if windows is not being maximized, save size in case of maximization + */ + if (!(tmp_win->flags & MAXIMIZED) #ifdef WINDOWSHADE - && !shaded + && !shaded #endif - ) - { - tmp_win->orig_x = x; - tmp_win->orig_y = y; - tmp_win->orig_wd = w; - tmp_win->orig_ht = h; - } - - if((w != tmp_win->frame_width) || (h != tmp_win->frame_height)) - Resized = True; - if ((x != tmp_win->frame_x || y != tmp_win->frame_y)) - Moved = True; - - /* - * According to the July 27, 1988 ICCCM draft, we should send a - * "synthetic" ConfigureNotify event to the client if the window - * was moved but not resized. - */ - if (Moved && !Resized) - sendEvent = True; - - if (Resized) - { - left = tmp_win->nr_left_buttons; - right = tmp_win->nr_right_buttons; - - if (tmp_win->flags & TITLE) - tmp_win->title_height = GetDecor(tmp_win,TitleHeight) + tmp_win->bw; - - tmp_win->title_width= w- - (left+right)*tmp_win->title_height - -2*tmp_win->boundary_width+tmp_win->bw; - - - if(tmp_win->title_width < 1) - tmp_win->title_width = 1; - - if (tmp_win->flags & TITLE) - { - xwcm = CWWidth | CWX | CWY | CWHeight; - tmp_win->title_x = tmp_win->boundary_width+ - (left)*tmp_win->title_height; - if(tmp_win->title_x >= w - tmp_win->boundary_width) - tmp_win->title_x = -10; - tmp_win->title_y = tmp_win->boundary_width; - - xwc.width = tmp_win->title_width; - - xwc.height = tmp_win->title_height; - xwc.x = tmp_win->title_x; - xwc.y = tmp_win->title_y; - XConfigureWindow(dpy, tmp_win->title_w, xwcm, &xwc); - - - xwcm = CWX | CWY | CWHeight | CWWidth; - xwc.height = tmp_win->title_height; - xwc.width = tmp_win->title_height; - - xwc.y = tmp_win->boundary_width; - xwc.x = tmp_win->boundary_width; - for(i=0;ileft_w[i] != None) - { - if(xwc.x + tmp_win->title_height < w-tmp_win->boundary_width) - XConfigureWindow(dpy, tmp_win->left_w[i], xwcm, &xwc); - else - { - xwc.x = -tmp_win->title_height; - XConfigureWindow(dpy, tmp_win->left_w[i], xwcm, &xwc); - } - xwc.x += tmp_win->title_height; - } - } - - xwc.x=w-tmp_win->boundary_width+tmp_win->bw; - for(i=0;iright_w[i] != None) - { - xwc.x -=tmp_win->title_height; - if(xwc.x > tmp_win->boundary_width) - XConfigureWindow(dpy, tmp_win->right_w[i], xwcm, &xwc); - else - { - xwc.x = -tmp_win->title_height; - XConfigureWindow(dpy, tmp_win->right_w[i], xwcm, &xwc); - } - } - } - } - - if(tmp_win->flags & BORDER) - { - tmp_win->corner_width = GetDecor(tmp_win,TitleHeight) + tmp_win->bw + - tmp_win->boundary_width ; - - if(w < 2*tmp_win->corner_width) - tmp_win->corner_width = w/3; - if((h < 2*tmp_win->corner_width) + ) { + tmp_win->orig_x = x; + tmp_win->orig_y = y; + tmp_win->orig_wd = w; + tmp_win->orig_ht = h; + } + + if ((w != tmp_win->frame_width) || (h != tmp_win->frame_height)) + Resized = True; + if ((x != tmp_win->frame_x || y != tmp_win->frame_y)) + Moved = True; + + /* + * According to the July 27, 1988 ICCCM draft, we should send a + * "synthetic" ConfigureNotify event to the client if the window + * was moved but not resized. + */ + if (Moved && !Resized) + sendEvent = True; + + if (Resized) { + left = tmp_win->nr_left_buttons; + right = tmp_win->nr_right_buttons; + + if (tmp_win->flags & TITLE) + tmp_win->title_height = + GetDecor(tmp_win, TitleHeight) + tmp_win->bw; + + tmp_win->title_width = + w - (left + right) * tmp_win->title_height - + 2 * tmp_win->boundary_width + tmp_win->bw; + + if (tmp_win->title_width < 1) + tmp_win->title_width = 1; + + if (tmp_win->flags & TITLE) { + xwcm = CWWidth | CWX | CWY | CWHeight; + tmp_win->title_x = tmp_win->boundary_width + + (left)*tmp_win->title_height; + if (tmp_win->title_x >= w - tmp_win->boundary_width) + tmp_win->title_x = -10; + tmp_win->title_y = tmp_win->boundary_width; + + xwc.width = tmp_win->title_width; + + xwc.height = tmp_win->title_height; + xwc.x = tmp_win->title_x; + xwc.y = tmp_win->title_y; + XConfigureWindow(dpy, tmp_win->title_w, xwcm, &xwc); + + xwcm = CWX | CWY | CWHeight | CWWidth; + xwc.height = tmp_win->title_height; + xwc.width = tmp_win->title_height; + + xwc.y = tmp_win->boundary_width; + xwc.x = tmp_win->boundary_width; + for (i = 0; i < Scr.nr_left_buttons; i++) { + if (tmp_win->left_w[i] != None) { + if (xwc.x + tmp_win->title_height < + w - tmp_win->boundary_width) + XConfigureWindow(dpy, + tmp_win->left_w[i], xwcm, + &xwc); + else { + xwc.x = -tmp_win->title_height; + XConfigureWindow(dpy, + tmp_win->left_w[i], xwcm, + &xwc); + } + xwc.x += tmp_win->title_height; + } + } + + xwc.x = w - tmp_win->boundary_width + tmp_win->bw; + for (i = 0; i < Scr.nr_right_buttons; i++) { + if (tmp_win->right_w[i] != None) { + xwc.x -= tmp_win->title_height; + if (xwc.x > tmp_win->boundary_width) + XConfigureWindow(dpy, + tmp_win->right_w[i], xwcm, + &xwc); + else { + xwc.x = -tmp_win->title_height; + XConfigureWindow(dpy, + tmp_win->right_w[i], xwcm, + &xwc); + } + } + } + } + + if (tmp_win->flags & BORDER) { + tmp_win->corner_width = GetDecor(tmp_win, TitleHeight) + + tmp_win->bw + + tmp_win->boundary_width; + + if (w < 2 * tmp_win->corner_width) + tmp_win->corner_width = w / 3; + if ((h < 2 * tmp_win->corner_width) #ifdef WINDOWSHADE - &&!shaded + && !shaded #endif - ) - tmp_win->corner_width = h/3; - xwidth = w - 2*tmp_win->corner_width+tmp_win->bw; - ywidth = h - 2*tmp_win->corner_width; - xwcm = CWWidth | CWHeight | CWX | CWY; - if(xwidth<2) - xwidth = 2; - if(ywidth<2) - ywidth = 2; - - for(i=0;i<4;i++) - { - if(i==0) - { - xwc.x = tmp_win->corner_width; - xwc.y = 0; - xwc.height = tmp_win->boundary_width; - xwc.width = xwidth; - } - else if (i==1) - { - xwc.x = w - tmp_win->boundary_width+tmp_win->bw; - xwc.y = tmp_win->corner_width; - xwc.width = tmp_win->boundary_width; - xwc.height = ywidth; - - } - else if(i==2) - { - xwc.x = tmp_win->corner_width; - xwc.y = h - tmp_win->boundary_width+tmp_win->bw; - xwc.height = tmp_win->boundary_width+tmp_win->bw; - xwc.width = xwidth; - } - else - { - xwc.x = 0; - xwc.y = tmp_win->corner_width; - xwc.width = tmp_win->boundary_width; - xwc.height = ywidth; - } + ) + tmp_win->corner_width = h / 3; + xwidth = w - 2 * tmp_win->corner_width + tmp_win->bw; + ywidth = h - 2 * tmp_win->corner_width; + xwcm = CWWidth | CWHeight | CWX | CWY; + if (xwidth < 2) + xwidth = 2; + if (ywidth < 2) + ywidth = 2; + + for (i = 0; i < 4; i++) { + if (i == 0) { + xwc.x = tmp_win->corner_width; + xwc.y = 0; + xwc.height = tmp_win->boundary_width; + xwc.width = xwidth; + } else if (i == 1) { + xwc.x = w - tmp_win->boundary_width + + tmp_win->bw; + xwc.y = tmp_win->corner_width; + xwc.width = tmp_win->boundary_width; + xwc.height = ywidth; + } else if (i == 2) { + xwc.x = tmp_win->corner_width; + xwc.y = h - tmp_win->boundary_width + + tmp_win->bw; + xwc.height = tmp_win->boundary_width + + tmp_win->bw; + xwc.width = xwidth; + } else { + xwc.x = 0; + xwc.y = tmp_win->corner_width; + xwc.width = tmp_win->boundary_width; + xwc.height = ywidth; + } #ifdef WINDOWSHADE - if (!shaded||(i!=2)) + if (!shaded || (i != 2)) #endif - XConfigureWindow(dpy, tmp_win->sides[i], xwcm, &xwc); - } - - xwcm = CWX|CWY|CWWidth|CWHeight; - xwc.width = tmp_win->corner_width; - xwc.height = tmp_win->corner_width; - for(i=0;i<4;i++) - { - if(i%2) - xwc.x = w - tmp_win->corner_width+tmp_win->bw; - else - xwc.x = 0; - - if(i/2) - xwc.y = h - tmp_win->corner_width; - else - xwc.y = 0; + XConfigureWindow( + dpy, tmp_win->sides[i], xwcm, &xwc); + } + + xwcm = CWX | CWY | CWWidth | CWHeight; + xwc.width = tmp_win->corner_width; + xwc.height = tmp_win->corner_width; + for (i = 0; i < 4; i++) { + if (i % 2) + xwc.x = w - tmp_win->corner_width + + tmp_win->bw; + else + xwc.x = 0; + + if (i / 2) + xwc.y = h - tmp_win->corner_width; + else + xwc.y = 0; #ifdef WINDOWSHADE - if (!shaded||(i==0)||(i==1)) + if (!shaded || (i == 0) || (i == 1)) #endif - XConfigureWindow(dpy, tmp_win->corners[i], xwcm, &xwc); - } - - } - } - tmp_win->attr.width = w - 2*tmp_win->boundary_width; - tmp_win->attr.height = h - tmp_win->title_height - - 2*tmp_win->boundary_width; - /* may need to omit the -1 for shaped windows, next two lines*/ - cx = tmp_win->boundary_width-tmp_win->bw; - cy = tmp_win->title_height + tmp_win->boundary_width-tmp_win->bw; + XConfigureWindow(dpy, + tmp_win->corners[i], xwcm, &xwc); + } + } + } + tmp_win->attr.width = w - 2 * tmp_win->boundary_width; + tmp_win->attr.height = + h - tmp_win->title_height - 2 * tmp_win->boundary_width; + /* may need to omit the -1 for shaped windows, next two lines*/ + cx = tmp_win->boundary_width - tmp_win->bw; + cy = tmp_win->title_height + tmp_win->boundary_width - tmp_win->bw; #ifdef WINDOWSHADE - if (!shaded) { + if (!shaded) { #endif - XResizeWindow(dpy, tmp_win->w, tmp_win->attr.width, - tmp_win->attr.height); - XMoveResizeWindow(dpy, tmp_win->Parent, cx,cy, - tmp_win->attr.width, tmp_win->attr.height); + XResizeWindow( + dpy, tmp_win->w, tmp_win->attr.width, tmp_win->attr.height); + XMoveResizeWindow(dpy, tmp_win->Parent, cx, cy, + tmp_win->attr.width, tmp_win->attr.height); #ifdef WINDOWSHADE - } + } #endif - /* - * fix up frame and assign size/location values in tmp_win - */ - frame_wc.x = tmp_win->frame_x = x; - frame_wc.y = tmp_win->frame_y = y; - frame_wc.width = tmp_win->frame_width = w; - frame_wc.height = tmp_win->frame_height = h; - frame_mask = (CWX | CWY | CWWidth | CWHeight); - XConfigureWindow (dpy, tmp_win->frame, frame_mask, &frame_wc); + /* + * fix up frame and assign size/location values in tmp_win + */ + frame_wc.x = tmp_win->frame_x = x; + frame_wc.y = tmp_win->frame_y = y; + frame_wc.width = tmp_win->frame_width = w; + frame_wc.height = tmp_win->frame_height = h; + frame_mask = (CWX | CWY | CWWidth | CWHeight); + XConfigureWindow(dpy, tmp_win->frame, frame_mask, &frame_wc); #ifdef FVWM_DEBUG_MSGS - fvwm_msg(DBG,"SetupFrame", - "New frame dimensions (x == %d, y == %d, w == %d, h == %d)", - frame_wc.x, frame_wc.y, frame_wc.width, frame_wc.height); + fvwm_msg(DBG, "SetupFrame", + "New frame dimensions (x == %d, y == %d, w == %d, h == %d)", + frame_wc.x, frame_wc.y, frame_wc.width, frame_wc.height); #endif #ifdef SHAPE - if (ShapesSupported) - { - if ((Resized)&&(tmp_win->wShaped)) - { - SetShape(tmp_win,w); - } - } + if (ShapesSupported) { + if ((Resized) && (tmp_win->wShaped)) { + SetShape(tmp_win, w); + } + } #endif /* SHAPE */ - XSync(dpy,0); - if (sendEvent + XSync(dpy, 0); + if (sendEvent #ifdef WINDOWSHADE - && !shaded + && !shaded #endif - ) - { - client_event.type = ConfigureNotify; - client_event.xconfigure.display = dpy; - client_event.xconfigure.event = tmp_win->w; - client_event.xconfigure.window = tmp_win->w; - - client_event.xconfigure.x = x + tmp_win->boundary_width; - client_event.xconfigure.y = y + tmp_win->title_height+ - tmp_win->boundary_width; - client_event.xconfigure.width = w-2*tmp_win->boundary_width; - client_event.xconfigure.height =h-2*tmp_win->boundary_width - - tmp_win->title_height; - - client_event.xconfigure.border_width =tmp_win->bw; - /* Real ConfigureNotify events say we're above title window, so ... */ - /* what if we don't have a title ????? */ - client_event.xconfigure.above = tmp_win->frame; - client_event.xconfigure.override_redirect = False; - XSendEvent(dpy, tmp_win->w, False, StructureNotifyMask, &client_event); + ) { + client_event.type = ConfigureNotify; + client_event.xconfigure.display = dpy; + client_event.xconfigure.event = tmp_win->w; + client_event.xconfigure.window = tmp_win->w; + + client_event.xconfigure.x = x + tmp_win->boundary_width; + client_event.xconfigure.y = + y + tmp_win->title_height + tmp_win->boundary_width; + client_event.xconfigure.width = w - 2 * tmp_win->boundary_width; + client_event.xconfigure.height = + h - 2 * tmp_win->boundary_width - tmp_win->title_height; + + client_event.xconfigure.border_width = tmp_win->bw; + /* Real ConfigureNotify events say we're above title window, so + * ... */ + /* what if we don't have a title ????? */ + client_event.xconfigure.above = tmp_win->frame; + client_event.xconfigure.override_redirect = False; + XSendEvent( + dpy, tmp_win->w, False, StructureNotifyMask, &client_event); #ifdef FVWM_DEBUG_MSGS - fvwm_msg(DBG,"SetupFrame","Sent ConfigureNotify (w == %d, h == %d)", - client_event.xconfigure.width,client_event.xconfigure.height); + fvwm_msg(DBG, "SetupFrame", + "Sent ConfigureNotify (w == %d, h == %d)", + client_event.xconfigure.width, + client_event.xconfigure.height); #endif - } - XSync(dpy,0); + } + XSync(dpy, 0); - BroadcastConfig(M_CONFIGURE_WINDOW,tmp_win); + BroadcastConfig(M_CONFIGURE_WINDOW, tmp_win); } - /**************************************************************************** * * Sets up the shaped window borders * ****************************************************************************/ -void SetShape(FvwmWindow *tmp_win, int w) +void +SetShape(FvwmWindow *tmp_win, int w) { #ifdef SHAPE - if (ShapesSupported) - { - XRectangle rect; - - XShapeCombineShape (dpy, tmp_win->frame, ShapeBounding, - tmp_win->boundary_width, - tmp_win->title_height+tmp_win->boundary_width, - tmp_win->w, - ShapeBounding, ShapeSet); - if (tmp_win->title_w) - { - /* windows w/ titles */ - rect.x = tmp_win->boundary_width; - rect.y = tmp_win->title_y; - rect.width = w - 2*tmp_win->boundary_width+tmp_win->bw; - rect.height = tmp_win->title_height; - - - XShapeCombineRectangles(dpy,tmp_win->frame,ShapeBounding, - 0,0,&rect,1,ShapeUnion,Unsorted); - } - } + if (ShapesSupported) { + XRectangle rect; + + XShapeCombineShape(dpy, tmp_win->frame, ShapeBounding, + tmp_win->boundary_width, + tmp_win->title_height + tmp_win->boundary_width, tmp_win->w, + ShapeBounding, ShapeSet); + if (tmp_win->title_w) { + /* windows w/ titles */ + rect.x = tmp_win->boundary_width; + rect.y = tmp_win->title_y; + rect.width = + w - 2 * tmp_win->boundary_width + tmp_win->bw; + rect.height = tmp_win->title_height; + + XShapeCombineRectangles(dpy, tmp_win->frame, + ShapeBounding, 0, 0, &rect, 1, ShapeUnion, + Unsorted); + } + } #endif } Index: fvwm/fvwm/builtins.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/builtins.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/builtins.c --- fvwm/fvwm/builtins.c +++ fvwm/fvwm/builtins.c @@ -6,36 +6,35 @@ * copyright remains in the source code and all documentation ****************************************************************************/ -#include "config.h" - +#include +#include +#include +#include #include #include -#include #include -#include #include -#include -#include +#include "config.h" #include "fvwm.h" #include "menus.h" #include "misc.h" +#include "module.h" #include "parse.h" #include "screen.h" -#include "module.h" static Boolean ReadMenuFace(char *s, MenuFace *mf, int verbose); static void FreeMenuFace(Display *dpy, MenuFace *mf); -static char *exec_shell_name="/bin/sh"; +static char *exec_shell_name = "/bin/sh"; /* button state strings must match the enumerated states */ -static char *button_states[MaxButtonState]={ - "ActiveUp", +static char *button_states[MaxButtonState] = { + "ActiveUp", #ifdef ACTIVEDOWN_BTNS - "ActiveDown", + "ActiveDown", #endif #ifdef INACTIVE_BTNS - "Inactive", + "Inactive", #endif }; @@ -49,264 +48,235 @@ static char *button_states[MaxButtonState]={ * eventp - pointer to XEvent to patch up * w - pointer to Window to patch up * tmp_win - pointer to FvwmWindow Structure to patch up - * context - the context in which the mouse button was pressed - * func - the function to defer - * cursor - the cursor to display while waiting + * context - the context in which the mouse button was pressed + * func - the function to defer + * cursor - the cursor to display while waiting * finishEvent - ButtonRelease or ButtonPress; tells what kind of event to * terminate on. * ***********************************************************************/ -int DeferExecution(XEvent *eventp, Window *w,FvwmWindow **tmp_win, - unsigned long *context, int cursor, int FinishEvent) - +int +DeferExecution(XEvent *eventp, Window *w, FvwmWindow **tmp_win, + unsigned long *context, int cursor, int FinishEvent) { - int done; - int finished = 0; - Window dummy; - Window original_w; - - original_w = *w; - - if((*context != C_ROOT)&&(*context != C_NO_CONTEXT)&&(tmp_win != NULL)) - { - if((FinishEvent == ButtonPress)||((FinishEvent == ButtonRelease) && - (eventp->type != ButtonPress))) - { - return FALSE; - } - } - if(!GrabEm(cursor)) - { - XBell(dpy, 0); - return True; - } - - while (!finished) - { - done = 0; - /* block until there is an event */ - XMaskEvent(dpy, ButtonPressMask | ButtonReleaseMask | - ExposureMask |KeyPressMask | VisibilityChangeMask | - ButtonMotionMask| PointerMotionMask/* | EnterWindowMask | - LeaveWindowMask*/, eventp); - StashEventTime(eventp); - - if(eventp->type == KeyPress) - Keyboard_shortcuts(eventp, NULL, FinishEvent); - if(eventp->type == FinishEvent) - finished = 1; - if(eventp->type == ButtonPress) - { - XAllowEvents(dpy,ReplayPointer,CurrentTime); - done = 1; - } - if(eventp->type == ButtonRelease) - done = 1; - if(eventp->type == KeyPress) - done = 1; - - if(!done) - { - DispatchEvent(); - } - - } - - - *w = eventp->xany.window; - if(((*w == Scr.Root)||(*w == Scr.NoFocusWin)) - && (eventp->xbutton.subwindow != (Window)0)) - { - *w = eventp->xbutton.subwindow; - eventp->xany.window = *w; - } - if (*w == Scr.Root) - { - *context = C_ROOT; - XBell(dpy, 0); - UngrabEm(); - return TRUE; - } - if (XFindContext (dpy, *w, FvwmContext, (caddr_t *)tmp_win) == XCNOENT) - { - *tmp_win = NULL; - XBell(dpy, 0); - UngrabEm(); - return (TRUE); - } - - if(*w == (*tmp_win)->Parent) - *w = (*tmp_win)->w; - - if(original_w == (*tmp_win)->Parent) - original_w = (*tmp_win)->w; - - /* this ugly mess attempts to ensure that the release and press - * are in the same window. */ - if((*w != original_w)&&(original_w != Scr.Root)&& - (original_w != None)&&(original_w != Scr.NoFocusWin)) - if(!((*w == (*tmp_win)->frame)&& - (original_w == (*tmp_win)->w))) - { - *context = C_ROOT; - XBell(dpy, 0); - UngrabEm(); - return TRUE; - } - - *context = GetContext(*tmp_win,eventp,&dummy); - - UngrabEm(); - return FALSE; -} + int done; + int finished = 0; + Window dummy; + Window original_w; + + original_w = *w; + + if ((*context != C_ROOT) && (*context != C_NO_CONTEXT) && + (tmp_win != NULL)) { + if ((FinishEvent == ButtonPress) || + ((FinishEvent == ButtonRelease) && + (eventp->type != ButtonPress))) { + return FALSE; + } + } + if (!GrabEm(cursor)) { + XBell(dpy, 0); + return True; + } + + while (!finished) { + done = 0; + /* block until there is an event */ + XMaskEvent(dpy, + ButtonPressMask | ButtonReleaseMask | ExposureMask | + KeyPressMask | VisibilityChangeMask | ButtonMotionMask | + PointerMotionMask /* | EnterWindowMask | + LeaveWindowMask*/ + , + eventp); + StashEventTime(eventp); + + if (eventp->type == KeyPress) + Keyboard_shortcuts(eventp, NULL, FinishEvent); + if (eventp->type == FinishEvent) + finished = 1; + if (eventp->type == ButtonPress) { + XAllowEvents(dpy, ReplayPointer, CurrentTime); + done = 1; + } + if (eventp->type == ButtonRelease) + done = 1; + if (eventp->type == KeyPress) + done = 1; + + if (!done) { + DispatchEvent(); + } + } + + *w = eventp->xany.window; + if (((*w == Scr.Root) || (*w == Scr.NoFocusWin)) && + (eventp->xbutton.subwindow != (Window)0)) { + *w = eventp->xbutton.subwindow; + eventp->xany.window = *w; + } + if (*w == Scr.Root) { + *context = C_ROOT; + XBell(dpy, 0); + UngrabEm(); + return TRUE; + } + if (XFindContext(dpy, *w, FvwmContext, (caddr_t *)tmp_win) == XCNOENT) { + *tmp_win = NULL; + XBell(dpy, 0); + UngrabEm(); + return (TRUE); + } + if (*w == (*tmp_win)->Parent) + *w = (*tmp_win)->w; + + if (original_w == (*tmp_win)->Parent) + original_w = (*tmp_win)->w; + + /* this ugly mess attempts to ensure that the release and press + * are in the same window. */ + if ((*w != original_w) && (original_w != Scr.Root) && + (original_w != None) && (original_w != Scr.NoFocusWin)) + if (!((*w == (*tmp_win)->frame) && + (original_w == (*tmp_win)->w))) { + *context = C_ROOT; + XBell(dpy, 0); + UngrabEm(); + return TRUE; + } + *context = GetContext(*tmp_win, eventp, &dummy); + UngrabEm(); + return FALSE; +} /************************************************************************** * * Moves focus to specified window * *************************************************************************/ -void FocusOn(FvwmWindow *t,Bool FocusByMouse) +void +FocusOn(FvwmWindow *t, Bool FocusByMouse) { #ifndef NON_VIRTUAL - int dx,dy; - int cx,cy; + int dx, dy; + int cx, cy; #endif - int x,y; + int x, y; - if(t == (FvwmWindow *)0) - return; + if (t == (FvwmWindow *)0) + return; - if(t->Desk != Scr.CurrentDesk) - { - changeDesks(t->Desk); - } + if (t->Desk != Scr.CurrentDesk) { + changeDesks(t->Desk); + } #ifndef NON_VIRTUAL - if(t->flags & ICONIFIED) - { - cx = t->icon_xl_loc + t->icon_w_width/2; - cy = t->icon_y_loc + t->icon_p_height + ICON_HEIGHT/2; - } - else - { - cx = t->frame_x + t->frame_width/2; - cy = t->frame_y + t->frame_height/2; - } - - dx = (cx + Scr.Vx)/Scr.MyDisplayWidth*Scr.MyDisplayWidth; - dy = (cy +Scr.Vy)/Scr.MyDisplayHeight*Scr.MyDisplayHeight; - - MoveViewport(dx,dy,True); -#endif + if (t->flags & ICONIFIED) { + cx = t->icon_xl_loc + t->icon_w_width / 2; + cy = t->icon_y_loc + t->icon_p_height + ICON_HEIGHT / 2; + } else { + cx = t->frame_x + t->frame_width / 2; + cy = t->frame_y + t->frame_height / 2; + } - if(t->flags & ICONIFIED) - { - x = t->icon_xl_loc + t->icon_w_width/2; - y = t->icon_y_loc + t->icon_p_height + ICON_HEIGHT/2; - } - else - { - x = t->frame_x; - y = t->frame_y; - } -#if 0 /* don't want to warp the pointer by default anymore */ - if(!(t->flags & ClickToFocus)) - XWarpPointer(dpy, None, Scr.Root, 0, 0, 0, 0, x+2,y+2); -#endif /* 0 */ -#if 0 /* don't want to raise anymore either */ - RaiseWindow(t); -#endif /* 0 */ - KeepOnTop(); - - /* If the window is still not visible, make it visible! */ - if(((t->frame_x + t->frame_height)< 0)||(t->frame_y + t->frame_width < 0)|| - (t->frame_x >Scr.MyDisplayWidth)||(t->frame_y>Scr.MyDisplayHeight)) - { - SetupFrame(t,0,0,t->frame_width, t->frame_height,False); - if(!(t->flags & ClickToFocus)) - XWarpPointer(dpy, None, Scr.Root, 0, 0, 0, 0, 2,2); - } - UngrabEm(); - SetFocus(t->w,t,FocusByMouse); -} + dx = (cx + Scr.Vx) / Scr.MyDisplayWidth * Scr.MyDisplayWidth; + dy = (cy + Scr.Vy) / Scr.MyDisplayHeight * Scr.MyDisplayHeight; + MoveViewport(dx, dy, True); +#endif + if (t->flags & ICONIFIED) { + x = t->icon_xl_loc + t->icon_w_width / 2; + y = t->icon_y_loc + t->icon_p_height + ICON_HEIGHT / 2; + } else { + x = t->frame_x; + y = t->frame_y; + } + KeepOnTop(); + + /* If the window is still not visible, make it visible! */ + if (((t->frame_x + t->frame_height) < 0) || + (t->frame_y + t->frame_width < 0) || + (t->frame_x > Scr.MyDisplayWidth) || + (t->frame_y > Scr.MyDisplayHeight)) { + SetupFrame(t, 0, 0, t->frame_width, t->frame_height, False); + if (!(t->flags & ClickToFocus)) + XWarpPointer(dpy, None, Scr.Root, 0, 0, 0, 0, 2, 2); + } + UngrabEm(); + SetFocus(t->w, t, FocusByMouse); +} /************************************************************************** * * Moves pointer to specified window * *************************************************************************/ -void WarpOn(FvwmWindow *t,int warp_x, int x_unit, int warp_y, int y_unit) +void +WarpOn(FvwmWindow *t, int warp_x, int x_unit, int warp_y, int y_unit) { #ifndef NON_VIRTUAL - int dx,dy; - int cx,cy; + int dx, dy; + int cx, cy; #endif - int x,y; + int x, y; - if(t == (FvwmWindow *)0 || (t->flags & ICONIFIED && t->icon_w == None)) - return; + if (t == (FvwmWindow *)0 || (t->flags & ICONIFIED && t->icon_w == None)) + return; - if(t->Desk != Scr.CurrentDesk) - { - changeDesks(t->Desk); - } + if (t->Desk != Scr.CurrentDesk) { + changeDesks(t->Desk); + } #ifndef NON_VIRTUAL - if(t->flags & ICONIFIED) - { - cx = t->icon_xl_loc + t->icon_w_width/2; - cy = t->icon_y_loc + t->icon_p_height + ICON_HEIGHT/2; - } - else - { - cx = t->frame_x + t->frame_width/2 + t->bw; - cy = t->frame_y + t->frame_height/2 + t->bw; - } - - dx = (cx + Scr.Vx)/Scr.MyDisplayWidth*Scr.MyDisplayWidth; - dy = (cy +Scr.Vy)/Scr.MyDisplayHeight*Scr.MyDisplayHeight; - - MoveViewport(dx,dy,True); -#endif + if (t->flags & ICONIFIED) { + cx = t->icon_xl_loc + t->icon_w_width / 2; + cy = t->icon_y_loc + t->icon_p_height + ICON_HEIGHT / 2; + } else { + cx = t->frame_x + t->frame_width / 2 + t->bw; + cy = t->frame_y + t->frame_height / 2 + t->bw; + } - if(t->flags & ICONIFIED) - { - x = t->icon_xl_loc + t->icon_w_width/2; - y = t->icon_y_loc + t->icon_p_height + ICON_HEIGHT/2; - } - else - { - if (x_unit != Scr.MyDisplayWidth) - x = t->frame_x + t->bw + warp_x; - else - x = t->frame_x + t->bw + (t->frame_width - 1) * warp_x / 100; - if (y_unit != Scr.MyDisplayHeight) - y = t->frame_y + t->bw + warp_y; - else - y = t->frame_y + t->bw + (t->frame_height - 1) * warp_y / 100; - } - if (warp_x >= 0 && warp_y >= 0) { - XWarpPointer(dpy, None, Scr.Root, 0, 0, 0, 0, x, y); - } - RaiseWindow(t); - KeepOnTop(); - - /* If the window is still not visible, make it visible! */ - if(((t->frame_x + t->frame_height)< 0)||(t->frame_y + t->frame_width < 0)|| - (t->frame_x >Scr.MyDisplayWidth)||(t->frame_y>Scr.MyDisplayHeight)) - { - SetupFrame(t,0,0,t->frame_width, t->frame_height,False); - XWarpPointer(dpy, None, Scr.Root, 0, 0, 0, 0, 2,2); - } - UngrabEm(); -} + dx = (cx + Scr.Vx) / Scr.MyDisplayWidth * Scr.MyDisplayWidth; + dy = (cy + Scr.Vy) / Scr.MyDisplayHeight * Scr.MyDisplayHeight; + MoveViewport(dx, dy, True); +#endif + if (t->flags & ICONIFIED) { + x = t->icon_xl_loc + t->icon_w_width / 2; + y = t->icon_y_loc + t->icon_p_height + ICON_HEIGHT / 2; + } else { + if (x_unit != Scr.MyDisplayWidth) + x = t->frame_x + t->bw + warp_x; + else + x = t->frame_x + t->bw + + (t->frame_width - 1) * warp_x / 100; + if (y_unit != Scr.MyDisplayHeight) + y = t->frame_y + t->bw + warp_y; + else + y = t->frame_y + t->bw + + (t->frame_height - 1) * warp_y / 100; + } + if (warp_x >= 0 && warp_y >= 0) { + XWarpPointer(dpy, None, Scr.Root, 0, 0, 0, 0, x, y); + } + RaiseWindow(t); + KeepOnTop(); + + /* If the window is still not visible, make it visible! */ + if (((t->frame_x + t->frame_height) < 0) || + (t->frame_y + t->frame_width < 0) || + (t->frame_x > Scr.MyDisplayWidth) || + (t->frame_y > Scr.MyDisplayHeight)) { + SetupFrame(t, 0, 0, t->frame_width, t->frame_height, False); + XWarpPointer(dpy, None, Scr.Root, 0, 0, 0, 0, 2, 2); + } + UngrabEm(); +} /*********************************************************************** * @@ -314,71 +284,100 @@ void WarpOn(FvwmWindow *t,int warp_x, int x_unit, int warp_y, int y_unit) * (Un)Maximize a window. * ***********************************************************************/ -void Maximize(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action, int *Module) +static int +virtual_page_origin(int coordinate, int span) +{ + int base; + + if (span <= 0) + return 0; + if (coordinate >= 0) + return (coordinate / span) * span; + + base = -((-coordinate) / span) * span; + if ((-coordinate) % span != 0) + base -= span; + return base; +} + +void +Maximize(XEvent *eventp, Window w, FvwmWindow *tmp_win, unsigned long context, + char *action, int *Module) { - int new_width, new_height,new_x,new_y; - int val1, val2, val1_unit,val2_unit,n; + int new_width, new_height, new_x, new_y; + int val1, val2, val1_unit, val2_unit, n; - if (DeferExecution(eventp,&w,&tmp_win,&context, SELECT,ButtonRelease)) - return; + if (DeferExecution( + eventp, &w, &tmp_win, &context, SELECT, ButtonRelease)) + return; - if(tmp_win == NULL) - return; + if (tmp_win == NULL) + return; - if(check_allowed_function2(F_MAXIMIZE,tmp_win) == 0 + if (check_allowed_function2(F_MAXIMIZE, tmp_win) == 0 #ifdef WINDOWSHADE - || (tmp_win->buttons & WSHADE) + || (tmp_win->buttons & WSHADE) +#endif + ) { + XBell(dpy, 0); + return; + } + n = GetTwoArguments(action, &val1, &val2, &val1_unit, &val2_unit); + if (n != 2) { + val1 = 100; + val2 = 100; + val1_unit = Scr.MyDisplayWidth; + val2_unit = Scr.MyDisplayHeight; + } + + if (tmp_win->flags & MAXIMIZED) { + int orig_wd = tmp_win->orig_wd; + int orig_ht = tmp_win->orig_ht; + + tmp_win->flags &= ~MAXIMIZED; + ConstrainSize(tmp_win, &orig_wd, &orig_ht, False, 0, 0); + SetupFrame(tmp_win, tmp_win->orig_x, tmp_win->orig_y, + orig_wd, orig_ht, TRUE); + SetBorder(tmp_win, True, True, True, None); + } else { + new_width = tmp_win->frame_width; + new_height = tmp_win->frame_height; + new_x = tmp_win->frame_x; + new_y = tmp_win->frame_y; +#ifndef NON_VIRTUAL + { + const int page_x = virtual_page_origin( + tmp_win->frame_x, Scr.MyDisplayWidth); + const int page_y = virtual_page_origin( + tmp_win->frame_y, Scr.MyDisplayHeight); +#else + { + const int page_x = 0; + const int page_y = 0; #endif - ) - { - XBell(dpy, 0); - return; - } - n = GetTwoArguments(action, &val1, &val2, &val1_unit, &val2_unit); - if(n != 2) - { - val1 = 100; - val2 = 100; - val1_unit = Scr.MyDisplayWidth; - val2_unit = Scr.MyDisplayHeight; - } - - if (tmp_win->flags & MAXIMIZED) - { - tmp_win->flags &= ~MAXIMIZED; - SetupFrame(tmp_win, tmp_win->orig_x, tmp_win->orig_y, tmp_win->orig_wd, - tmp_win->orig_ht,TRUE); - SetBorder(tmp_win,True,True,True,None); - } - else - { - new_width = tmp_win->frame_width; - new_height = tmp_win->frame_height; - new_x = tmp_win->frame_x; - new_y = tmp_win->frame_y; - if(val1 >0) - { - new_width = val1*val1_unit/100-2; - new_x = 0; - } - if(val2 >0) - { - new_height = val2*val2_unit/100-2; - new_y = 0; - } - if((val1==0)&&(val2==0)) - { - new_x = 0; - new_y = 0; - new_height = Scr.MyDisplayHeight-2; - new_width = Scr.MyDisplayWidth-2; - } - tmp_win->flags |= MAXIMIZED; - ConstrainSize (tmp_win, &new_width, &new_height, False, 0, 0); - SetupFrame(tmp_win,new_x,new_y,new_width,new_height,TRUE); - SetBorder(tmp_win,Scr.Hilite == tmp_win,True,True,None); - } + if (val1 > 0) { + new_width = val1 * val1_unit / 100 - 2; + new_x = page_x; + } + if (val2 > 0) { + new_height = val2 * val2_unit / 100 - 2; + new_y = page_y; + } + if ((val1 == 0) && (val2 == 0)) { + new_x = page_x; + new_y = page_y; + new_height = Scr.MyDisplayHeight - 2; + new_width = Scr.MyDisplayWidth - 2; + } + tmp_win->flags |= MAXIMIZED; + ConstrainSize( + tmp_win, &new_width, &new_height, False, 0, 0); + SetupFrame( + tmp_win, new_x, new_y, new_width, new_height, TRUE); + SetBorder( + tmp_win, Scr.Hilite == tmp_win, True, True, None); + } + } } #ifdef WINDOWSHADE @@ -389,973 +388,936 @@ void Maximize(XEvent *eventp,Window w,FvwmWindow *tmp_win, * Args: 1 -- force shade, 2 -- force unshade No Arg: toggle * ***********************************************************************/ -void WindowShade(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action, int *Module) +void +WindowShade(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - int n = 0; + int n = 0; - if (DeferExecution(eventp,&w,&tmp_win,&context, SELECT,ButtonRelease)) - return; + if (DeferExecution( + eventp, &w, &tmp_win, &context, SELECT, ButtonRelease)) + return; - if (!(tmp_win->flags & TITLE) || (tmp_win->flags & MAXIMIZED)) { - XBell(dpy, 0); - return; - } - while (isspace(*action))++action; - if (isdigit(*action)) - sscanf(action,"%d",&n); - - if (((tmp_win->buttons & WSHADE)||(n==2))&&(n!=1)) - { - tmp_win->buttons &= ~WSHADE; - SetupFrame(tmp_win, - tmp_win->frame_x, - tmp_win->frame_y, - tmp_win->orig_wd, - tmp_win->orig_ht, - True); - BroadcastPacket(M_DEWINDOWSHADE, 3, - tmp_win->w, tmp_win->frame, (unsigned long)tmp_win); - } - else - { - tmp_win->buttons |= WSHADE; - SetupFrame(tmp_win, - tmp_win->frame_x, - tmp_win->frame_y, - tmp_win->frame_width, - tmp_win->title_height + tmp_win->boundary_width - tmp_win->bw, - False); - BroadcastPacket(M_WINDOWSHADE, 3, - tmp_win->w, tmp_win->frame, (unsigned long)tmp_win); - } + if (!(tmp_win->flags & TITLE) || (tmp_win->flags & MAXIMIZED)) { + XBell(dpy, 0); + return; + } + while (isspace(*action)) + ++action; + if (isdigit(*action)) + sscanf(action, "%d", &n); + + if (((tmp_win->buttons & WSHADE) || (n == 2)) && (n != 1)) { + tmp_win->buttons &= ~WSHADE; + SetupFrame(tmp_win, tmp_win->frame_x, tmp_win->frame_y, + tmp_win->orig_wd, tmp_win->orig_ht, True); + BroadcastPacket(M_DEWINDOWSHADE, 3, tmp_win->w, tmp_win->frame, + (unsigned long)tmp_win); + } else { + tmp_win->buttons |= WSHADE; + SetupFrame(tmp_win, tmp_win->frame_x, tmp_win->frame_y, + tmp_win->frame_width, + tmp_win->title_height + tmp_win->boundary_width - + tmp_win->bw, + False); + BroadcastPacket(M_WINDOWSHADE, 3, tmp_win->w, tmp_win->frame, + (unsigned long)tmp_win); + } } #endif /* WINDOWSHADE */ /* For Ultrix 4.2 */ -#include #include +#include - -MenuRoot *FindPopup(char *action) +MenuRoot * +FindPopup(char *action) { - char *tmp; - MenuRoot *mr; - - GetNextToken(action,&tmp); - - if(tmp == NULL) - return NULL; - - mr = Scr.menus.all; - while(mr != NULL) - { - if(mr->name != NULL) - if(strcasecmp(tmp,mr->name)== 0) - { - free(tmp); - return mr; - } - mr = mr->next; - } - free(tmp); - return NULL; + char *tmp; + MenuRoot *mr; -} + GetNextToken(action, &tmp); + if (tmp == NULL) + return NULL; + mr = Scr.menus.all; + while (mr != NULL) { + if (mr->name != NULL) + if (strcasecmp(tmp, mr->name) == 0) { + free(tmp); + return mr; + } + mr = mr->next; + } + free(tmp); + return NULL; +} -void Bell(XEvent *eventp,Window w,FvwmWindow *tmp_win,unsigned long context, - char *action, int *Module) +void +Bell(XEvent *eventp, Window w, FvwmWindow *tmp_win, unsigned long context, + char *action, int *Module) { - XBell(dpy, 0); + XBell(dpy, 0); } - #ifdef USEDECOR static FvwmDecor *last_decor = NULL, *cur_decor = NULL; #endif -MenuRoot *last_menu=NULL; -void add_item_to_menu(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, - char *action, int *Module) +MenuRoot *last_menu = NULL; +void +add_item_to_menu(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - MenuRoot *mr; - MenuRoot *mrPrior; - char *token, *rest,*item; + MenuRoot *mr; + MenuRoot *mrPrior; + char *token, *rest, *item; #ifdef USEDECOR - last_decor = NULL; + last_decor = NULL; #endif - rest = GetNextToken(action,&token); - if (!token) - return; - mr = FollowMenuContinuations(FindPopup(token),&mrPrior); - if(mr == NULL) - mr = NewMenuRoot(token, False); - last_menu = mr; - - rest = GetNextToken(rest,&item); - AddToMenu(mr, item,rest,TRUE /* pixmap scan */, TRUE); - if (item) - free(item); - /* These lines are correct! We must not release token if the string is empty. - * It cannot be NULL! GetNextToken never returns an empty string! */ - if (*token) - free(token); - - MakeMenu(mr); - return; -} + rest = GetNextToken(action, &token); + if (!token) + return; + mr = FollowMenuContinuations(FindPopup(token), &mrPrior); + if (mr == NULL) + mr = NewMenuRoot(token, False); + last_menu = mr; + + rest = GetNextToken(rest, &item); + AddToMenu(mr, item, rest, TRUE /* pixmap scan */, TRUE); + if (item) + free(item); + /* These lines are correct! We must not release token if the string is + * empty. It cannot be NULL! GetNextToken never returns an empty string! + */ + if (*token) + free(token); + MakeMenu(mr); + return; +} -void add_another_item(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, - char *action, int *Module) +void +add_another_item(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { #ifdef USEDECOR - extern void AddToDecor(FvwmDecor *, char *); + extern void AddToDecor(FvwmDecor *, char *); #endif - MenuRoot *mr; - MenuRoot *mrPrior; - char *rest,*item; - - if (last_menu != NULL) { - mr = FollowMenuContinuations(last_menu,&mrPrior); - if(mr == NULL) - return; - rest = GetNextToken(action,&item); - AddToMenu(mr, item,rest,TRUE /* pixmap scan */, FALSE); - if (item) - free(item); - MakeMenu(mr); - } + MenuRoot *mr; + MenuRoot *mrPrior; + char *rest, *item; + + if (last_menu != NULL) { + mr = FollowMenuContinuations(last_menu, &mrPrior); + if (mr == NULL) + return; + rest = GetNextToken(action, &item); + AddToMenu(mr, item, rest, TRUE /* pixmap scan */, FALSE); + if (item) + free(item); + MakeMenu(mr); + } #ifdef USEDECOR - else if (last_decor != NULL) { - FvwmDecor *tmp = &Scr.DefaultDecor; - for (; tmp; tmp = tmp->next) - if (tmp == last_decor) - break; - if (!tmp) - return; - AddToDecor(tmp, action); - } + else if (last_decor != NULL) { + FvwmDecor *tmp = &Scr.DefaultDecor; + for (; tmp; tmp = tmp->next) + if (tmp == last_decor) + break; + if (!tmp) + return; + AddToDecor(tmp, action); + } #endif /* USEDECOR */ } -void destroy_menu(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, - char *action, int *Module) +void +destroy_menu(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - MenuRoot *mr; - MenuRoot *mrContinuation; - - char *token, *rest; - - rest = GetNextToken(action,&token); - if (!token) - return; - mr = FindPopup(token); - free(token); - while (mr) - { - mrContinuation = mr->continuation; /* save continuation before destroy */ - DestroyMenu(mr); - mr = mrContinuation; - } - return; + MenuRoot *mr; + MenuRoot *mrContinuation; + + char *token, *rest; + + rest = GetNextToken(action, &token); + if (!token) + return; + mr = FindPopup(token); + free(token); + while (mr) { + if (mr == last_menu) + last_menu = NULL; + mrContinuation = + mr->continuation; /* save continuation before destroy */ + DestroyMenu(mr); + mr = mrContinuation; + } + return; } -void add_item_to_func(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, - char *action, int *Module) +void +add_item_to_func(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - MenuRoot *mr; - - char *token, *rest,*item; - - rest = GetNextToken(action,&token); - if (!token) - return; - mr = FindPopup(token); - if(mr == NULL) - mr = NewMenuRoot(token, True); - last_menu = mr; - if (token) - free(token); - rest = GetNextToken(rest,&item); - AddToMenu(mr, item,rest,FALSE,FALSE); - if (item) - free(item); - - return; -} + MenuRoot *mr; + char *token, *rest, *item; -void Nop_func(XEvent *eventp, Window w, FvwmWindow *tmp_win, - unsigned long context, char *action, int *Module) -{ + rest = GetNextToken(action, &token); + if (!token) + return; + mr = FindPopup(token); + if (mr == NULL) + mr = NewMenuRoot(token, True); + last_menu = mr; + if (token) + free(token); + rest = GetNextToken(rest, &item); + AddToMenu(mr, item, rest, FALSE, FALSE); + if (item) + free(item); + return; } +void +Nop_func(XEvent *eventp, Window w, FvwmWindow *tmp_win, unsigned long context, + char *action, int *Module) +{ +} -void movecursor(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action, int *Module) +void +movecursor(XEvent *eventp, Window w, FvwmWindow *tmp_win, unsigned long context, + char *action, int *Module) { - int x = 0, y = 0; - int val1, val2, val1_unit, val2_unit; + int x = 0, y = 0; + int val1, val2, val1_unit, val2_unit; #ifndef NON_VIRTUAL - int virtual_x, virtual_y; - int pan_x, pan_y; - int x_pages, y_pages; + int virtual_x, virtual_y; + int pan_x, pan_y; + int x_pages, y_pages; #endif - if (GetTwoArguments(action, &val1, &val2, &val1_unit, &val2_unit) != 2) - { - fvwm_msg(ERR, "movecursor", "CursorMove needs 2 arguments"); - return; - } + if (GetTwoArguments(action, &val1, &val2, &val1_unit, &val2_unit) != + 2) { + fvwm_msg(ERR, "movecursor", "CursorMove needs 2 arguments"); + return; + } - XQueryPointer( dpy, Scr.Root, &JunkRoot, &JunkChild, - &x, &y, &JunkX, &JunkY, &JunkMask); + XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, &x, &y, &JunkX, + &JunkY, &JunkMask); - x = x + val1 * val1_unit / 100; - y = y + val2 * val2_unit / 100; + x = x + val1 * val1_unit / 100; + y = y + val2 * val2_unit / 100; #ifndef NON_VIRTUAL - virtual_x = Scr.Vx; - virtual_y = Scr.Vy; - if (x >= 0) - x_pages = x / Scr.MyDisplayWidth; - else - x_pages = ((x + 1) / Scr.MyDisplayWidth) - 1; - virtual_x += x_pages * Scr.MyDisplayWidth; - x -= x_pages * Scr.MyDisplayWidth; - if (virtual_x < 0) - { - x += virtual_x; - virtual_x = 0; - } - else if (virtual_x > Scr.VxMax) - { - x += virtual_x - Scr.VxMax; - virtual_x = Scr.VxMax; - } - - if (y >= 0) - y_pages = y / Scr.MyDisplayHeight; - else - y_pages = ((y + 1) / Scr.MyDisplayHeight) - 1; - virtual_y += y_pages * Scr.MyDisplayHeight; - y -= y_pages * Scr.MyDisplayHeight; - if (virtual_y < 0) - { - y += virtual_y; - virtual_y = 0; - } - else if (virtual_y > Scr.VyMax) - { - y += virtual_y - Scr.VyMax; - virtual_y = Scr.VyMax; - } - if (virtual_x != Scr.Vx || virtual_y != Scr.Vy) - MoveViewport(virtual_x, virtual_y, True); - pan_x = (Scr.EdgeScrollX != 0) ? 2 : 0; - pan_y = (Scr.EdgeScrollY != 0) ? 2 : 0; - /* prevent paging if EdgeScroll is active */ - if (x >= Scr.MyDisplayWidth - pan_x) - x = Scr.MyDisplayWidth - pan_x -1; - else if (x < pan_x) - x = pan_x; - if (y >= Scr.MyDisplayHeight - pan_y) - y = Scr.MyDisplayHeight - pan_y - 1; - else if (y < pan_y) - y = pan_y; + virtual_x = Scr.Vx; + virtual_y = Scr.Vy; + if (x >= 0) + x_pages = x / Scr.MyDisplayWidth; + else + x_pages = ((x + 1) / Scr.MyDisplayWidth) - 1; + virtual_x += x_pages * Scr.MyDisplayWidth; + x -= x_pages * Scr.MyDisplayWidth; + if (virtual_x < 0) { + x += virtual_x; + virtual_x = 0; + } else if (virtual_x > Scr.VxMax) { + x += virtual_x - Scr.VxMax; + virtual_x = Scr.VxMax; + } + + if (y >= 0) + y_pages = y / Scr.MyDisplayHeight; + else + y_pages = ((y + 1) / Scr.MyDisplayHeight) - 1; + virtual_y += y_pages * Scr.MyDisplayHeight; + y -= y_pages * Scr.MyDisplayHeight; + if (virtual_y < 0) { + y += virtual_y; + virtual_y = 0; + } else if (virtual_y > Scr.VyMax) { + y += virtual_y - Scr.VyMax; + virtual_y = Scr.VyMax; + } + if (virtual_x != Scr.Vx || virtual_y != Scr.Vy) + MoveViewport(virtual_x, virtual_y, True); + pan_x = (Scr.EdgeScrollX != 0) ? 2 : 0; + pan_y = (Scr.EdgeScrollY != 0) ? 2 : 0; + /* prevent paging if EdgeScroll is active */ + if (x >= Scr.MyDisplayWidth - pan_x) + x = Scr.MyDisplayWidth - pan_x - 1; + else if (x < pan_x) + x = pan_x; + if (y >= Scr.MyDisplayHeight - pan_y) + y = Scr.MyDisplayHeight - pan_y - 1; + else if (y < pan_y) + y = pan_y; #endif - XWarpPointer(dpy, Scr.Root, Scr.Root, 0, 0, Scr.MyDisplayWidth, - Scr.MyDisplayHeight, x, y); - return; + XWarpPointer(dpy, Scr.Root, Scr.Root, 0, 0, Scr.MyDisplayWidth, + Scr.MyDisplayHeight, x, y); + return; } +void +iconify_function(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) +{ + int val = 0; + + if (DeferExecution( + eventp, &w, &tmp_win, &context, SELECT, ButtonRelease)) + return; -void iconify_function(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context,char *action, int *Module) + GetIntegerArguments(action, NULL, &val, 1); -{ - int val = 0; - - if (DeferExecution(eventp,&w,&tmp_win,&context, SELECT, ButtonRelease)) - return; - - GetIntegerArguments(action, NULL, &val, 1); - - if (tmp_win->flags & ICONIFIED) - { - if(val <=0) - DeIconify(tmp_win); - } - else - { - if(check_allowed_function2(F_ICONIFY,tmp_win) == 0) - { - XBell(dpy, 0); - return; - } - if(val >=0) - Iconify(tmp_win,eventp->xbutton.x_root-5,eventp->xbutton.y_root-5); - } + if (tmp_win->flags & ICONIFIED) { + if (val <= 0) + DeIconify(tmp_win); + } else { + if (check_allowed_function2(F_ICONIFY, tmp_win) == 0) { + XBell(dpy, 0); + return; + } + if (val >= 0) + Iconify(tmp_win, eventp->xbutton.x_root - 5, + eventp->xbutton.y_root - 5); + } } -void raise_function(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action, int *Module) +void +raise_function(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - name_list styles; /* place for merged styles */ + name_list styles; /* place for merged styles */ - if (DeferExecution(eventp,&w,&tmp_win,&context, SELECT,ButtonRelease)) - return; + if (DeferExecution( + eventp, &w, &tmp_win, &context, SELECT, ButtonRelease)) + return; - if(tmp_win) - RaiseWindow(tmp_win); + if (tmp_win) + RaiseWindow(tmp_win); - LookInList(tmp_win, &styles); /* get merged styles */ - if (styles.on_flags & STAYSONTOP_FLAG) { - tmp_win->flags |= ONTOP; - } - KeepOnTop(); + LookInList(tmp_win, &styles); /* get merged styles */ + if (styles.on_flags & STAYSONTOP_FLAG) { + tmp_win->flags |= ONTOP; + } + KeepOnTop(); } -void lower_function(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context,char *action, int *Module) +void +lower_function(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - if (DeferExecution(eventp,&w,&tmp_win,&context, SELECT, ButtonRelease)) - return; + if (DeferExecution( + eventp, &w, &tmp_win, &context, SELECT, ButtonRelease)) + return; - LowerWindow(tmp_win); + LowerWindow(tmp_win); - tmp_win->flags &= ~ONTOP; + tmp_win->flags &= ~ONTOP; } -void destroy_function(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action, int *Module) +void +destroy_function(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - if (DeferExecution(eventp,&w,&tmp_win,&context, DESTROY, ButtonRelease)) - return; - - if(check_allowed_function2(F_DESTROY,tmp_win) == 0) - { - XBell(dpy, 0); - return; - } - - if (XGetGeometry(dpy, tmp_win->w, &JunkRoot, &JunkX, &JunkY, - &JunkWidth, &JunkHeight, &JunkBW, &JunkDepth) == 0) - Destroy(tmp_win); - else - XKillClient(dpy, tmp_win->w); - XSync(dpy,0); + if (DeferExecution( + eventp, &w, &tmp_win, &context, DESTROY, ButtonRelease)) + return; + + if (check_allowed_function2(F_DESTROY, tmp_win) == 0) { + XBell(dpy, 0); + return; + } + + if (XGetGeometry(dpy, tmp_win->w, &JunkRoot, &JunkX, &JunkY, &JunkWidth, + &JunkHeight, &JunkBW, &JunkDepth) == 0) + Destroy(tmp_win); + else + XKillClient(dpy, tmp_win->w); + XSync(dpy, 0); } -void delete_function(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context,char *action, int *Module) +void +delete_function(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - if (DeferExecution(eventp,&w,&tmp_win,&context, DESTROY,ButtonRelease)) - return; - - if(check_allowed_function2(F_DELETE,tmp_win) == 0) - { - XBell(dpy, 0); - return; - } - - if (tmp_win->flags & DoesWmDeleteWindow) - { - send_clientmessage (dpy, tmp_win->w, _XA_WM_DELETE_WINDOW, CurrentTime); - return; - } - else - XBell (dpy, 0); - XSync(dpy,0); + if (DeferExecution( + eventp, &w, &tmp_win, &context, DESTROY, ButtonRelease)) + return; + + if (check_allowed_function2(F_DELETE, tmp_win) == 0) { + XBell(dpy, 0); + return; + } + + if (tmp_win->flags & DoesWmDeleteWindow) { + send_clientmessage( + dpy, tmp_win->w, _XA_WM_DELETE_WINDOW, CurrentTime); + return; + } else + XBell(dpy, 0); + XSync(dpy, 0); } -void close_function(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context,char *action, int *Module) +void +close_function(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - if (DeferExecution(eventp,&w,&tmp_win,&context, DESTROY,ButtonRelease)) - return; - - if(check_allowed_function2(F_CLOSE,tmp_win) == 0) - { - XBell(dpy, 0); - return; - } - - if (tmp_win->flags & DoesWmDeleteWindow) - { - send_clientmessage (dpy, tmp_win->w, _XA_WM_DELETE_WINDOW, CurrentTime); - return; - } - else if (XGetGeometry(dpy, tmp_win->w, &JunkRoot, &JunkX, &JunkY, - &JunkWidth, &JunkHeight, &JunkBW, &JunkDepth) == 0) - Destroy(tmp_win); - else - XKillClient(dpy, tmp_win->w); - XSync(dpy,0); + if (DeferExecution( + eventp, &w, &tmp_win, &context, DESTROY, ButtonRelease)) + return; + + if (check_allowed_function2(F_CLOSE, tmp_win) == 0) { + XBell(dpy, 0); + return; + } + + if (tmp_win->flags & DoesWmDeleteWindow) { + send_clientmessage( + dpy, tmp_win->w, _XA_WM_DELETE_WINDOW, CurrentTime); + return; + } else if (XGetGeometry(dpy, tmp_win->w, &JunkRoot, &JunkX, &JunkY, + &JunkWidth, &JunkHeight, &JunkBW, &JunkDepth) == 0) + Destroy(tmp_win); + else + XKillClient(dpy, tmp_win->w); + XSync(dpy, 0); } -void restart_function(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action, int *Module) +void +restart_function(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - Done(1, action); + Done(1, action); } -void exec_setup(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context,char *action, int *Module) +void +exec_setup(XEvent *eventp, Window w, FvwmWindow *tmp_win, unsigned long context, + char *action, int *Module) { - char *arg=NULL; - static char shell_set = 0; - - if (shell_set) - free(exec_shell_name); - shell_set = 1; - action = GetNextToken(action,&arg); - if (arg) /* specific shell was specified */ - { - exec_shell_name = arg; - } - else /* no arg, so use $SHELL -- not working??? */ - { - if (getenv("SHELL")) - exec_shell_name = strdup(getenv("SHELL")); - else - /* if $SHELL not set, use default */ - exec_shell_name = strdup("/bin/sh"); - } + char *arg = NULL; + static char shell_set = 0; + + if (shell_set) + free(exec_shell_name); + shell_set = 1; + action = GetNextToken(action, &arg); + if (arg) { + exec_shell_name = xstrdup(arg); + } else { + if (getenv("SHELL")) + exec_shell_name = xstrdup(getenv("SHELL")); + else + exec_shell_name = xstrdup("/bin/sh"); + } } -void exec_function(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context,char *action, int *Module) +void +exec_function(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - char *cmd=NULL; - - /* if it doesn't already have an 'exec' as the first word, add that - * to keep down number of procs started */ - /* need to parse string better to do this right though, so not doing this - for now... */ -#if 0 - if (strncasecmp(action,"exec",4)!=0) - { - cmd = (char *)safemalloc(strlen(action)+6); - strcpy(cmd,"exec "); - strcat(cmd,action); - } - else -#endif - { - cmd = strdup(action); - } - if (!cmd) - return; - /* Use to grab the pointer here, but the fork guarantees that - * we wont be held up waiting for the function to finish, - * so the pointer-gram just caused needless delay and flashing - * on the screen */ - /* Thought I'd try vfork and _exit() instead of regular fork(). - * The man page says that its better. */ - /* Not everyone has vfork! */ - if (!(fork())) /* child process */ - { - if (execl(exec_shell_name, exec_shell_name, "-c", cmd, (char *)NULL)==-1) - { - fvwm_msg(ERR,"exec_function","execl failed (%s)",strerror(errno)); - exit(100); - } - } - free(cmd); - return; + char *cmd = NULL; + + { + cmd = strdup(action); + } + if (!cmd) + return; + /* Use to grab the pointer here, but the fork guarantees that + * we wont be held up waiting for the function to finish, + * so the pointer-gram just caused needless delay and flashing + * on the screen */ + /* Thought I'd try vfork and _exit() instead of regular fork(). + * The man page says that its better. */ + /* Not everyone has vfork! */ + if (!(fork())) { /* child process */ + if (execl(exec_shell_name, exec_shell_name, "-c", cmd, + (char *)NULL) == -1) { + fvwm_msg(ERR, "exec_function", "execl failed (%s)", + strerror(errno)); + _exit(100); + } + } + free(cmd); + return; } -void refresh_function(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action, int *Module) +void +refresh_function(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - XSetWindowAttributes attributes; - unsigned long valuemask; - -#if 0 - valuemask = (CWBackPixel); - attributes.background_pixel = 0; -#else /* CKH - i'd like to try this a little differently (clear window)*/ - valuemask = CWOverrideRedirect | CWBackingStore | CWSaveUnder | CWBackPixmap; - attributes.override_redirect = True; - attributes.save_under = False; - attributes.background_pixmap = None; -#endif - attributes.backing_store = NotUseful; - w = XCreateWindow (dpy, Scr.Root, 0, 0, - (unsigned int) Scr.MyDisplayWidth, - (unsigned int) Scr.MyDisplayHeight, - (unsigned int) 0, - CopyFromParent, (unsigned int) CopyFromParent, - (Visual *) CopyFromParent, valuemask, - &attributes); - XMapWindow (dpy, w); - XDestroyWindow (dpy, w); - XFlush (dpy); + XSetWindowAttributes attributes; + unsigned long valuemask; + + valuemask = + CWOverrideRedirect | CWBackingStore | CWSaveUnder | CWBackPixmap; + attributes.override_redirect = True; + attributes.save_under = False; + attributes.background_pixmap = None; + attributes.backing_store = NotUseful; + w = XCreateWindow(dpy, Scr.Root, 0, 0, (unsigned int)Scr.MyDisplayWidth, + (unsigned int)Scr.MyDisplayHeight, (unsigned int)0, CopyFromParent, + (unsigned int)CopyFromParent, (Visual *)CopyFromParent, valuemask, + &attributes); + XMapWindow(dpy, w); + XDestroyWindow(dpy, w); + XFlush(dpy); } - -void refresh_win_function(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action, int *Module) +void +refresh_win_function(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - XSetWindowAttributes attributes; - unsigned long valuemask; - - if (DeferExecution(eventp,&w,&tmp_win,&context,SELECT,ButtonRelease)) - return; - - valuemask = CWOverrideRedirect | CWBackingStore | CWSaveUnder | CWBackPixmap; - attributes.override_redirect = True; - attributes.save_under = False; - attributes.background_pixmap = None; - attributes.backing_store = NotUseful; - w = XCreateWindow (dpy, - (context == C_ICON)?(tmp_win->icon_w):(tmp_win->frame), - 0, 0, - (unsigned int) Scr.MyDisplayWidth, - (unsigned int) Scr.MyDisplayHeight, - (unsigned int) 0, - CopyFromParent, (unsigned int) CopyFromParent, - (Visual *) CopyFromParent, valuemask, - &attributes); - XMapWindow (dpy, w); - XDestroyWindow (dpy, w); - XFlush (dpy); -} + XSetWindowAttributes attributes; + unsigned long valuemask; + if (DeferExecution( + eventp, &w, &tmp_win, &context, SELECT, ButtonRelease)) + return; -void stick_function(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action, int *Module) -{ - if (DeferExecution(eventp,&w,&tmp_win,&context,SELECT,ButtonRelease)) - return; - - if(tmp_win->flags & STICKY) - { - tmp_win->flags &= ~STICKY; - } - else - { - tmp_win->flags |=STICKY; - move_window_doit(eventp, w, tmp_win, context, "", Module, FALSE, TRUE); - } - BroadcastConfig(M_CONFIGURE_WINDOW,tmp_win); - SetTitleBar(tmp_win,(Scr.Hilite==tmp_win),True); + valuemask = + CWOverrideRedirect | CWBackingStore | CWSaveUnder | CWBackPixmap; + attributes.override_redirect = True; + attributes.save_under = False; + attributes.background_pixmap = None; + attributes.backing_store = NotUseful; + w = XCreateWindow(dpy, + (context == C_ICON) ? (tmp_win->icon_w) : (tmp_win->frame), 0, 0, + (unsigned int)Scr.MyDisplayWidth, (unsigned int)Scr.MyDisplayHeight, + (unsigned int)0, CopyFromParent, (unsigned int)CopyFromParent, + (Visual *)CopyFromParent, valuemask, &attributes); + XMapWindow(dpy, w); + XDestroyWindow(dpy, w); + XFlush(dpy); } -void wait_func(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context,char *action, int *Module) +void +stick_function(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - Bool done = False; - extern FvwmWindow *Tmp_win; + if (DeferExecution( + eventp, &w, &tmp_win, &context, SELECT, ButtonRelease)) + return; - while(!done) - { -#if 0 - GrabEm(WAIT); -#endif - if(My_XNextEvent(dpy, &Event)) - { - DispatchEvent (); - if(Event.type == MapNotify) - { - if((Tmp_win)&&(matchWildcards(action,Tmp_win->name)==True)) - done = True; - if((Tmp_win)&&(Tmp_win->class.res_class)&& - (matchWildcards(action,Tmp_win->class.res_class)==True)) - done = True; - if((Tmp_win)&&(Tmp_win->class.res_name)&& - (matchWildcards(action,Tmp_win->class.res_name)==True)) - done = True; - } - else if (Event.type == KeyPress && - XLookupKeysym(&(Event.xkey),0) == XK_Escape && - Event.xbutton.state & ControlMask) - { - done = 1; - } - } - } -#if 0 - UngrabEm(); -#endif + if (tmp_win->flags & STICKY) { + tmp_win->flags &= ~STICKY; + } else { + tmp_win->flags |= STICKY; + move_window_doit( + eventp, w, tmp_win, context, "", Module, FALSE, TRUE); + } + BroadcastConfig(M_CONFIGURE_WINDOW, tmp_win); + SetTitleBar(tmp_win, (Scr.Hilite == tmp_win), True); } -void flip_focus_func(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action, int *Module) +void +wait_func(XEvent *eventp, Window w, FvwmWindow *tmp_win, unsigned long context, + char *action, int *Module) { - if (DeferExecution(eventp,&w,&tmp_win,&context,SELECT,ButtonRelease)) - return; - - /* Reorder the window list */ - FocusOn(tmp_win,TRUE); + Bool done = False; + extern FvwmWindow *Tmp_win; + + while (!done) { + if (My_XNextEvent(dpy, &Event)) { + DispatchEvent(); + if (Event.type == MapNotify) { + if ((Tmp_win) && (matchWildcards(action, + Tmp_win->name) == True)) + done = True; + if ((Tmp_win) && (Tmp_win->class.res_class) && + (matchWildcards(action, + Tmp_win->class.res_class) == True)) + done = True; + if ((Tmp_win) && (Tmp_win->class.res_name) && + (matchWildcards(action, + Tmp_win->class.res_name) == True)) + done = True; + } else if (Event.type == KeyPress && + XLookupKeysym(&(Event.xkey), 0) == + XK_Escape && + Event.xbutton.state & ControlMask) { + done = 1; + } + } + } } - -void focus_func(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action, int *Module) +void +flip_focus_func(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - if (DeferExecution(eventp,&w,&tmp_win,&context,SELECT,ButtonRelease)) - return; + if (DeferExecution( + eventp, &w, &tmp_win, &context, SELECT, ButtonRelease)) + return; - FocusOn(tmp_win,FALSE); + /* Reorder the window list */ + FocusOn(tmp_win, TRUE); } +void +focus_func(XEvent *eventp, Window w, FvwmWindow *tmp_win, unsigned long context, + char *action, int *Module) +{ + if (DeferExecution( + eventp, &w, &tmp_win, &context, SELECT, ButtonRelease)) + return; + + FocusOn(tmp_win, FALSE); +} -void warp_func(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action, int *Module) +void +warp_func(XEvent *eventp, Window w, FvwmWindow *tmp_win, unsigned long context, + char *action, int *Module) { - int val1_unit, val2_unit, n; - int val1, val2; + int val1_unit, val2_unit, n; + int val1, val2; - if (DeferExecution(eventp,&w,&tmp_win,&context,SELECT,ButtonRelease)) - return; + if (DeferExecution( + eventp, &w, &tmp_win, &context, SELECT, ButtonRelease)) + return; - n = GetTwoArguments (action, &val1, &val2, &val1_unit, &val2_unit); + n = GetTwoArguments(action, &val1, &val2, &val1_unit, &val2_unit); - if (n == 2) - WarpOn (tmp_win, val1, val1_unit, val2, val2_unit); - else - WarpOn (tmp_win, 0, 0, 0, 0); + if (n == 2) + WarpOn(tmp_win, val1, val1_unit, val2, val2_unit); + else + WarpOn(tmp_win, 0, 0, 0, 0); } - -static void menu_func(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int *Module, - Bool fStaysUp) +static void +menu_func(XEvent *eventp, Window w, FvwmWindow *tmp_win, unsigned long context, + char *action, int *Module, Bool fStaysUp) { - extern int menuFromFrameOrWindowOrTitlebar; - MenuRoot *menu; - MenuItem *miExecuteAction = NULL; - MenuOptions mops; - char *menu_name = NULL; - XEvent *teventp; - - mops.flags.allflags = 0; - action = GetNextToken(action,&menu_name); - action = GetMenuOptions(action,w,tmp_win,NULL,&mops); - while (action && *action && isspace(*action)) - action++; - if (action && *action == 0) - action = NULL; - menu = FindPopup(menu_name); - if(menu == NULL) - { - if(menu_name != NULL) - { - fvwm_msg(ERR,"menu_func","No such menu %s",menu_name); - free(menu_name); - } - return; - } - if(menu_name != NULL) - free(menu_name); - menuFromFrameOrWindowOrTitlebar = FALSE; - - if (!action && eventp && eventp->type == KeyPress) - teventp = (XEvent *)1; - else - teventp = eventp; - if ((do_menu(menu, NULL, &miExecuteAction, 0, fStaysUp, teventp, &mops) == - MENU_DOUBLE_CLICKED) && action) - { - ExecuteFunction(action,tmp_win,eventp,context,*Module); - } + extern int menuFromFrameOrWindowOrTitlebar; + MenuRoot *menu; + MenuItem *miExecuteAction = NULL; + MenuOptions mops; + char *menu_name = NULL; + XEvent *teventp; + + mops.flags.allflags = 0; + action = GetNextToken(action, &menu_name); + action = GetMenuOptions(action, w, tmp_win, NULL, &mops); + while (action && *action && isspace(*action)) + action++; + if (action && *action == 0) + action = NULL; + menu = FindPopup(menu_name); + if (menu == NULL) { + if (menu_name != NULL) { + fvwm_msg( + ERR, "menu_func", "No such menu %s", menu_name); + free(menu_name); + } + return; + } + if (menu_name != NULL) + free(menu_name); + menuFromFrameOrWindowOrTitlebar = FALSE; + + if (!action && eventp && eventp->type == KeyPress) + teventp = (XEvent *)1; + else + teventp = eventp; + if ((do_menu(menu, NULL, &miExecuteAction, 0, fStaysUp, teventp, + &mops) == MENU_DOUBLE_CLICKED) && + action) { + ExecuteFunction(action, tmp_win, eventp, context, *Module); + } } /* the function for the "Popup" command */ -void popup_func(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int *Module) +void +popup_func(XEvent *eventp, Window w, FvwmWindow *tmp_win, unsigned long context, + char *action, int *Module) { - menu_func(eventp, w, tmp_win, context, action, Module, False); + menu_func(eventp, w, tmp_win, context, action, Module, False); } /* the function for the "Menu" command */ -void staysup_func(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int *Module) +void +staysup_func(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - menu_func(eventp, w, tmp_win, context, action, Module, True); + menu_func(eventp, w, tmp_win, context, action, Module, True); } - -void quit_func(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int *Module) +void +quit_func(XEvent *eventp, Window w, FvwmWindow *tmp_win, unsigned long context, + char *action, int *Module) { - if (master_pid != getpid()) - kill(master_pid, SIGTERM); - Done(0,NULL); + if (master_pid != getpid()) + kill(master_pid, SIGTERM); + Done(0, NULL); } -void quit_screen_func(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int *Module) +void +quit_screen_func(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - Done(0,NULL); + Done(0, NULL); } -void echo_func(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int *Module) +void +echo_func(XEvent *eventp, Window w, FvwmWindow *tmp_win, unsigned long context, + char *action, int *Module) { - unsigned int len; - - if (!action) - action = ""; - len = strlen(action); - if (len != 0) - { - if (action[len-1]=='\n') - action[len-1]='\0'; - } - fvwm_msg(INFO,"Echo",action); + unsigned int len; + + if (!action) + action = ""; + len = strlen(action); + if (len != 0) { + if (action[len - 1] == '\n') + action[len - 1] = '\0'; + } + fvwm_msg(INFO, "Echo", action); } -void raiselower_func(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int *Module) +void +raiselower_func(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - name_list styles; - - if (DeferExecution(eventp,&w,&tmp_win,&context, SELECT,ButtonRelease)) - return; - if(tmp_win == NULL) - return; - - if((tmp_win == Scr.LastWindowRaised)|| - (tmp_win->flags & VISIBLE)) - { - LowerWindow(tmp_win); - tmp_win->flags &= ~ONTOP; - } - else - { - RaiseWindow(tmp_win); - LookInList(tmp_win, &styles); /* get merged styles */ - if (styles.on_flags & STAYSONTOP_FLAG) { - tmp_win->flags |= ONTOP; - } - KeepOnTop(); - } + name_list styles; + + if (DeferExecution( + eventp, &w, &tmp_win, &context, SELECT, ButtonRelease)) + return; + if (tmp_win == NULL) + return; + + if ((tmp_win == Scr.LastWindowRaised) || (tmp_win->flags & VISIBLE)) { + LowerWindow(tmp_win); + tmp_win->flags &= ~ONTOP; + } else { + RaiseWindow(tmp_win); + LookInList(tmp_win, &styles); /* get merged styles */ + if (styles.on_flags & STAYSONTOP_FLAG) { + tmp_win->flags |= ONTOP; + } + KeepOnTop(); + } } -void SetEdgeScroll(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +SetEdgeScroll(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - int val1, val2, val1_unit,val2_unit,n; - - n = GetTwoArguments(action, &val1, &val2, &val1_unit, &val2_unit); - if(n != 2) - { - fvwm_msg(ERR,"SetEdgeScroll","EdgeScroll requires two arguments"); - return; - } - - /* - * if edgescroll >1000 and < 100000m - * wrap at edges of desktop (a "spherical" desktop) - */ - if (val1 >= 1000) - { - val1 /= 1000; - Scr.flags |= EdgeWrapX; - } - else - { - Scr.flags &= ~EdgeWrapX; - } - if (val2 >= 1000) - { - val2 /= 1000; - Scr.flags |= EdgeWrapY; - } - else - { - Scr.flags &= ~EdgeWrapY; - } - - Scr.EdgeScrollX = val1*val1_unit/100; - Scr.EdgeScrollY = val2*val2_unit/100; - - checkPanFrames(); + int val1, val2, val1_unit, val2_unit, n; + + n = GetTwoArguments(action, &val1, &val2, &val1_unit, &val2_unit); + if (n != 2) { + fvwm_msg( + ERR, "SetEdgeScroll", "EdgeScroll requires two arguments"); + return; + } + + /* + * if edgescroll >1000 and < 100000m + * wrap at edges of desktop (a "spherical" desktop) + */ + if (val1 >= 1000) { + val1 /= 1000; + Scr.flags |= EdgeWrapX; + } else { + Scr.flags &= ~EdgeWrapX; + } + if (val2 >= 1000) { + val2 /= 1000; + Scr.flags |= EdgeWrapY; + } else { + Scr.flags &= ~EdgeWrapY; + } + + Scr.EdgeScrollX = val1 * val1_unit / 100; + Scr.EdgeScrollY = val2 * val2_unit / 100; + + checkPanFrames(); } -void SetEdgeResistance(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +SetEdgeResistance(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - int val[2]; + int val[2]; - if (GetIntegerArguments(action, NULL, val, 2) != 2) - { - fvwm_msg(ERR,"SetEdgeResistance","EdgeResistance requires two arguments"); - return; - } + if (GetIntegerArguments(action, NULL, val, 2) != 2) { + fvwm_msg(ERR, "SetEdgeResistance", + "EdgeResistance requires two arguments"); + return; + } - Scr.ScrollResistance = val[0]; - Scr.MoveResistance = val[1]; + Scr.ScrollResistance = val[0]; + Scr.MoveResistance = val[1]; } -void SetColormapFocus(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +SetColormapFocus(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - if (MatchToken(action,"FollowsFocus")) - { - Scr.ColormapFocus = COLORMAP_FOLLOWS_FOCUS; - } - else if (MatchToken(action,"FollowsMouse")) - { - Scr.ColormapFocus = COLORMAP_FOLLOWS_MOUSE; - } - else - { - fvwm_msg(ERR,"SetColormapFocus", - "ColormapFocus requires 1 arg: FollowsFocus or FollowsMouse"); - return; - } + if (MatchToken(action, "FollowsFocus")) { + Scr.ColormapFocus = COLORMAP_FOLLOWS_FOCUS; + } else if (MatchToken(action, "FollowsMouse")) { + Scr.ColormapFocus = COLORMAP_FOLLOWS_MOUSE; + } else { + fvwm_msg(ERR, "SetColormapFocus", + "ColormapFocus requires 1 arg: FollowsFocus or " + "FollowsMouse"); + return; + } } -void SetClick(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +SetClick(XEvent *eventp, Window w, FvwmWindow *tmp_win, unsigned long context, + char *action, int *Module) { - int val; - - if(GetIntegerArguments(action, NULL, &val, 1) != 1) - { - Scr.ClickTime = DEFAULT_CLICKTIME; - } - else - { - Scr.ClickTime = (val < 0)? 0 : val; - } - - /* Use a negative value during startup and change sign afterwards. This - * speeds things up quite a bit. */ - if (fFvwmInStartup) - Scr.ClickTime = -Scr.ClickTime; -} + int val; + if (GetIntegerArguments(action, NULL, &val, 1) != 1) { + Scr.ClickTime = DEFAULT_CLICKTIME; + } else { + Scr.ClickTime = (val < 0) ? 0 : val; + } -void SetSnapAttraction(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) -{ - int val; - char *token; - - if(GetIntegerArguments(action, &action, &val, 1) != 1) - { - fvwm_msg(ERR,"SetSnapAttraction", - "SnapAttraction requires at least 1 argument"); - return; - } - Scr.SnapAttraction = val; - - action = GetNextToken(action, &token); - if(token == NULL) - { - return; - } - - if(StrEquals(token,"All")) - { Scr.SnapMode = 0; } - if(StrEquals(token,"SameType")) - { Scr.SnapMode = 1; } - if(StrEquals(token,"Icons")) - { Scr.SnapMode = 2; } - if(StrEquals(token,"Windows")) - { Scr.SnapMode = 3; } - - free(token); + /* Use a negative value during startup and change sign afterwards. This + * speeds things up quite a bit. */ + if (fFvwmInStartup) + Scr.ClickTime = -Scr.ClickTime; } -void SetSnapGrid(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +SetSnapAttraction(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - int val[2]; - - if(GetIntegerArguments(action, NULL, &val[0], 2) != 2) - { - fvwm_msg(ERR,"SetSnapGrid","SetSnapGrid requires 2 arguments"); - return; - } - - Scr.SnapGridX = val[0]; - if(Scr.SnapGridX < 1) - { Scr.SnapGridX = 1;} - Scr.SnapGridY = val[1]; - if(Scr.SnapGridY < 1) - { Scr.SnapGridY = 1;} -} + int val; + char *token; + + if (GetIntegerArguments(action, &action, &val, 1) != 1) { + fvwm_msg(ERR, "SetSnapAttraction", + "SnapAttraction requires at least 1 argument"); + return; + } + Scr.SnapAttraction = val; + + action = GetNextToken(action, &token); + if (token == NULL) { + return; + } + + if (StrEquals(token, "All")) { + Scr.SnapMode = 0; + } + if (StrEquals(token, "SameType")) { + Scr.SnapMode = 1; + } + if (StrEquals(token, "Icons")) { + Scr.SnapMode = 2; + } + if (StrEquals(token, "Windows")) { + Scr.SnapMode = 3; + } + free(token); +} -void SetXOR(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +SetSnapGrid(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - int val; - XGCValues gcv; - unsigned long gcm; - - if(GetIntegerArguments(action, NULL, &val, 1) != 1) - { - fvwm_msg(ERR,"SetXOR","XORValue requires 1 argument"); - return; - } - - gcm = GCFunction|GCLineWidth|GCForeground|GCSubwindowMode; - gcv.function = GXxor; - gcv.line_width = 0; - /* use passed in value, or try to calculate appropriate value if 0 */ - /* ctwm method: */ - /* - gcv.foreground = (val1)?(val1):((((unsigned long) 1) << Scr.d_depth) - 1); - */ - /* Xlib programming manual suggestion: */ - gcv.foreground = (val)? - (val):(BlackPixel(dpy,Scr.screen) ^ WhitePixel(dpy,Scr.screen)); - gcv.subwindow_mode = IncludeInferiors; - if (Scr.DrawGC) - XFreeGC(dpy, Scr.DrawGC); - Scr.DrawGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); + int val[2]; + + if (GetIntegerArguments(action, NULL, &val[0], 2) != 2) { + fvwm_msg( + ERR, "SetSnapGrid", "SetSnapGrid requires 2 arguments"); + return; + } + + Scr.SnapGridX = val[0]; + if (Scr.SnapGridX < 1) { + Scr.SnapGridX = 1; + } + Scr.SnapGridY = val[1]; + if (Scr.SnapGridY < 1) { + Scr.SnapGridY = 1; + } } -void SetOpaque(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +SetXOR(XEvent *eventp, Window w, FvwmWindow *tmp_win, unsigned long context, + char *action, int *Module) { - int val; + int val; + XGCValues gcv; + unsigned long gcm; - if(GetIntegerArguments(action, NULL, &val, 1) != 1) - { - fvwm_msg(ERR,"SetOpaque","OpaqueMoveSize requires 1 argument"); - return; - } + if (GetIntegerArguments(action, NULL, &val, 1) != 1) { + fvwm_msg(ERR, "SetXOR", "XORValue requires 1 argument"); + return; + } - Scr.OpaqueSize = val; + gcm = GCFunction | GCLineWidth | GCForeground | GCSubwindowMode; + gcv.function = GXxor; + gcv.line_width = 0; + /* use passed in value, or try to calculate appropriate value if 0 */ + /* ctwm method: */ + /* + gcv.foreground = (val1)?(val1):((((unsigned long) 1) << Scr.d_depth) - + 1); + */ + /* Xlib programming manual suggestion: */ + gcv.foreground = + (val) ? (val) : + (BlackPixel(dpy, Scr.screen) ^ WhitePixel(dpy, Scr.screen)); + gcv.subwindow_mode = IncludeInferiors; + if (Scr.DrawGC) + XFreeGC(dpy, Scr.DrawGC); + Scr.DrawGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); } +void +SetOpaque(XEvent *eventp, Window w, FvwmWindow *tmp_win, unsigned long context, + char *action, int *Module) +{ + int val; + + if (GetIntegerArguments(action, NULL, &val, 1) != 1) { + fvwm_msg( + ERR, "SetOpaque", "OpaqueMoveSize requires 1 argument"); + return; + } + + Scr.OpaqueSize = val; +} -void SetDeskSize(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +SetDeskSize(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - int val[2]; + int val[2]; - if (GetIntegerArguments(action, NULL, val, 2) != 2 && - GetRectangleArguments(action, &val[0], &val[1]) != 2) - { - fvwm_msg(ERR,"SetDeskSize","DesktopSize requires two arguments"); - return; - } + if (GetIntegerArguments(action, NULL, val, 2) != 2 && + GetRectangleArguments(action, &val[0], &val[1]) != 2) { + fvwm_msg( + ERR, "SetDeskSize", "DesktopSize requires two arguments"); + return; + } - Scr.VxMax = (val[0] <= 0)? 0: val[0]*Scr.MyDisplayWidth-Scr.MyDisplayWidth; - Scr.VyMax = (val[1] <= 0)? 0: val[1]*Scr.MyDisplayHeight-Scr.MyDisplayHeight; - BroadcastPacket(M_NEW_PAGE, 5, - Scr.Vx, Scr.Vy, Scr.CurrentDesk, Scr.VxMax, Scr.VyMax); + Scr.VxMax = (val[0] <= 0) ? + 0 : + val[0] * Scr.MyDisplayWidth - Scr.MyDisplayWidth; + Scr.VyMax = (val[1] <= 0) ? + 0 : + val[1] * Scr.MyDisplayHeight - Scr.MyDisplayHeight; + BroadcastPacket(M_NEW_PAGE, 5, Scr.Vx, Scr.Vy, Scr.CurrentDesk, + Scr.VxMax, Scr.VyMax); - checkPanFrames(); + checkPanFrames(); } #ifdef XPM @@ -1363,975 +1325,946 @@ char *PixmapPath = FVWM_ICONDIR; #else char *PixmapPath = ""; #endif -void setPixmapPath(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +setPixmapPath(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { #ifdef XPM - static char *ptemp = NULL; - char *tmp; + static char *ptemp = NULL; + char *tmp; - if(ptemp == NULL) - ptemp = PixmapPath; + if (ptemp == NULL) + ptemp = PixmapPath; - if((PixmapPath != ptemp)&&(PixmapPath != NULL)) - free(PixmapPath); - tmp = stripcpy(action); - PixmapPath = envDupExpand(tmp, 0); - free(tmp); + if ((PixmapPath != ptemp) && (PixmapPath != NULL)) + free(PixmapPath); + tmp = stripcpy(action); + PixmapPath = envDupExpand(tmp, 0); + free(tmp); #else - fvwm_msg(ERR, "setPixmapPath", - "XPM support has not been included in this version of Fvwm2."); + fvwm_msg(ERR, "setPixmapPath", + "XPM support has not been included in this version of Fvwm2."); #endif } char *IconPath = FVWM_ICONDIR; -void setIconPath(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +setIconPath(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - static char *ptemp = NULL; - char *tmp; + static char *ptemp = NULL; + char *tmp; - if(ptemp == NULL) - ptemp = IconPath; + if (ptemp == NULL) + ptemp = IconPath; - if((IconPath != ptemp)&&(IconPath != NULL)) - free(IconPath); - tmp = stripcpy(action); - IconPath = envDupExpand(tmp, 0); - free(tmp); + if ((IconPath != ptemp) && (IconPath != NULL)) + free(IconPath); + tmp = stripcpy(action); + IconPath = envDupExpand(tmp, 0); + free(tmp); } char *ModulePath = FVWM_MODULEDIR; -void setModulePath(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +setModulePath(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - static int need_to_free = 0; - char *tmp; + static int need_to_free = 0; + char *tmp; - if ( need_to_free && ModulePath != NULL ) - free(ModulePath); + if (need_to_free && ModulePath != NULL) + free(ModulePath); - tmp = stripcpy(action); - ModulePath = envDupExpand(tmp, 0); - need_to_free = 1; - free(tmp); + tmp = stripcpy(action); + ModulePath = envDupExpand(tmp, 0); + need_to_free = 1; + free(tmp); } - -void SetHiColor(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +SetHiColor(XEvent *eventp, Window w, FvwmWindow *tmp_win, unsigned long context, + char *action, int *Module) { - XGCValues gcv; - unsigned long gcm; - char *hifore=NULL, *hiback=NULL; - FvwmWindow *hilight; + XGCValues gcv; + unsigned long gcm; + char *hifore = NULL, *hiback = NULL; + FvwmWindow *hilight; #ifdef USEDECOR - FvwmDecor *fl = cur_decor ? cur_decor : &Scr.DefaultDecor; + FvwmDecor *fl = cur_decor ? cur_decor : &Scr.DefaultDecor; #else - FvwmDecor *fl = &Scr.DefaultDecor; + FvwmDecor *fl = &Scr.DefaultDecor; #endif - action = GetNextToken(action,&hifore); - GetNextToken(action,&hiback); - if(Scr.d_depth > 2) - { - if(hifore != NULL) - { - fl->HiColors.fore = GetColor(hifore); - } - if(hiback != NULL) - { - fl->HiColors.back = GetColor(hiback); - } - fl->HiRelief.back = GetShadow(fl->HiColors.back); - fl->HiRelief.fore = GetHilite(fl->HiColors.back); - } - else - { - fl->HiColors.back = GetColor("white"); - fl->HiColors.fore = GetColor("black"); - fl->HiRelief.back = GetColor("black"); - fl->HiRelief.fore = GetColor("white"); - } - if (hifore) free(hifore); - if (hiback) free(hiback); - gcm = GCFunction|GCPlaneMask|GCGraphicsExposures|GCLineWidth|GCForeground| - GCBackground; - gcv.foreground = fl->HiRelief.fore; - gcv.background = fl->HiRelief.back; - gcv.fill_style = FillSolid; - gcv.plane_mask = AllPlanes; - gcv.function = GXcopy; - gcv.graphics_exposures = False; - gcv.line_width = 0; - if(fl->HiReliefGC != NULL) - { - XFreeGC(dpy,fl->HiReliefGC); - } - fl->HiReliefGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); - - gcv.foreground = fl->HiRelief.back; - gcv.background = fl->HiRelief.fore; - if(fl->HiShadowGC != NULL) - { - XFreeGC(dpy,fl->HiShadowGC); - } - fl->HiShadowGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); - - if((Scr.flags & WindowsCaptured)&&(Scr.Hilite != NULL)) - { - hilight = Scr.Hilite; - SetBorder(Scr.Hilite,False,True,True,None); - SetBorder(hilight,True,True,True,None); - } -} + action = GetNextToken(action, &hifore); + GetNextToken(action, &hiback); + if (Scr.d_depth > 2) { + if (hifore != NULL) { + fl->HiColors.fore = GetColor(hifore); + } + if (hiback != NULL) { + fl->HiColors.back = GetColor(hiback); + } + fl->HiRelief.back = GetShadow(fl->HiColors.back); + fl->HiRelief.fore = GetHilite(fl->HiColors.back); + } else { + fl->HiColors.back = GetColor("white"); + fl->HiColors.fore = GetColor("black"); + fl->HiRelief.back = GetColor("black"); + fl->HiRelief.fore = GetColor("white"); + } + if (hifore) + free(hifore); + if (hiback) + free(hiback); + gcm = GCFunction | GCPlaneMask | GCGraphicsExposures | GCLineWidth | + GCForeground | GCBackground; + gcv.foreground = fl->HiRelief.fore; + gcv.background = fl->HiRelief.back; + gcv.fill_style = FillSolid; + gcv.plane_mask = AllPlanes; + gcv.function = GXcopy; + gcv.graphics_exposures = False; + gcv.line_width = 0; + if (fl->HiReliefGC != NULL) { + XFreeGC(dpy, fl->HiReliefGC); + } + fl->HiReliefGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); + gcv.foreground = fl->HiRelief.back; + gcv.background = fl->HiRelief.fore; + if (fl->HiShadowGC != NULL) { + XFreeGC(dpy, fl->HiShadowGC); + } + fl->HiShadowGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); -void SafeDefineCursor(Window w, Cursor cursor) -{ - if (w) XDefineCursor(dpy,w,cursor); + if ((Scr.flags & WindowsCaptured) && (Scr.Hilite != NULL)) { + hilight = Scr.Hilite; + SetBorder(Scr.Hilite, False, True, True, None); + SetBorder(hilight, True, True, True, None); + } } -void CursorStyle(XEvent *eventp,Window junk,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +SafeDefineCursor(Window w, Cursor cursor) { - char *cname=NULL, *newcursor=NULL; - int index,nc,i; - FvwmWindow *fw; - MenuRoot *mr; - - action = GetNextToken(action,&cname); - action = GetNextToken(action,&newcursor); - if (!cname || !newcursor) - { - fvwm_msg(ERR,"CursorStyle","Bad cursor style"); - if (cname) - free(cname); - if (newcursor) - free(newcursor); - return; - } - if (StrEquals("POSITION",cname)) index = POSITION; - else if (StrEquals("DEFAULT",cname)) index = DEFAULT; - else if (StrEquals("SYS",cname)) index = SYS; - else if (StrEquals("TITLE",cname)) index = TITLE_CURSOR; - else if (StrEquals("MOVE",cname)) index = MOVE; - else if (StrEquals("MENU",cname)) index = MENU; - else if (StrEquals("WAIT",cname)) index = WAIT; - else if (StrEquals("SELECT",cname)) index = SELECT; - else if (StrEquals("DESTROY",cname)) index = DESTROY; - else if (StrEquals("LEFT",cname)) index = LEFT; - else if (StrEquals("RIGHT",cname)) index = RIGHT; - else if (StrEquals("TOP",cname)) index = TOP; - else if (StrEquals("BOTTOM",cname)) index = BOTTOM; - else if (StrEquals("TOP_LEFT",cname)) index = TOP_LEFT; - else if (StrEquals("TOP_RIGHT",cname)) index = TOP_RIGHT; - else if (StrEquals("BOTTOM_LEFT",cname)) index = BOTTOM_LEFT; - else if (StrEquals("BOTTOM_RIGHT",cname)) index = BOTTOM_RIGHT; - else - { - fvwm_msg(ERR,"CursorStyle","Unknown cursor name %s",cname); - free(cname); - free(newcursor); - return; - } - nc = atoi(newcursor); - free(cname); - if ((nc < 0) || (nc >= XC_num_glyphs) || ((nc % 2) != 0)) - { - fvwm_msg(ERR, "CursorStyle", "Bad cursor number %s", newcursor); - free(newcursor); - return; - } - free(newcursor); - - /* replace the cursor defn */ - if (Scr.FvwmCursors[index]) XFreeCursor(dpy,Scr.FvwmCursors[index]); - Scr.FvwmCursors[index] = XCreateFontCursor(dpy,nc); - - /* redefine all the windows using cursors */ - fw = Scr.FvwmRoot.next; - while(fw != NULL) - { - for (i=0;i<4;i++) - { - SafeDefineCursor(fw->corners[i],Scr.FvwmCursors[TOP_LEFT+i]); - SafeDefineCursor(fw->sides[i],Scr.FvwmCursors[TOP+i]); - } - for (i=0;ileft_w[i],Scr.FvwmCursors[SYS]); - } - for (i=0;iright_w[i],Scr.FvwmCursors[SYS]); - } - SafeDefineCursor(fw->title_w, Scr.FvwmCursors[TITLE_CURSOR]); - fw = fw->next; - } - - /* Do the menus for good measure */ - mr = Scr.menus.all; - while(mr != NULL) - { - SafeDefineCursor(mr->w,Scr.FvwmCursors[MENU]); - mr = mr->next; - } + if (w) + XDefineCursor(dpy, w, cursor); } -MenuStyle *FindMenuStyle(char *name) +void +CursorStyle(XEvent *eventp, Window junk, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - MenuStyle *ms = Scr.menus.DefaultStyle; - - while(ms != NULL ) - { - if(strcasecmp(ms->name,name)==0) - return ms; - ms = ms->next; - } - return NULL; -} + char *cname = NULL, *newcursor = NULL; + int index, nc, i; + FvwmWindow *fw; + MenuRoot *mr; + + action = GetNextToken(action, &cname); + action = GetNextToken(action, &newcursor); + if (!cname || !newcursor) { + fvwm_msg(ERR, "CursorStyle", "Bad cursor style"); + if (cname) + free(cname); + if (newcursor) + free(newcursor); + return; + } + if (StrEquals("POSITION", cname)) + index = POSITION; + else if (StrEquals("DEFAULT", cname)) + index = DEFAULT; + else if (StrEquals("SYS", cname)) + index = SYS; + else if (StrEquals("TITLE", cname)) + index = TITLE_CURSOR; + else if (StrEquals("MOVE", cname)) + index = MOVE; + else if (StrEquals("MENU", cname)) + index = MENU; + else if (StrEquals("WAIT", cname)) + index = WAIT; + else if (StrEquals("SELECT", cname)) + index = SELECT; + else if (StrEquals("DESTROY", cname)) + index = DESTROY; + else if (StrEquals("LEFT", cname)) + index = LEFT; + else if (StrEquals("RIGHT", cname)) + index = RIGHT; + else if (StrEquals("TOP", cname)) + index = TOP; + else if (StrEquals("BOTTOM", cname)) + index = BOTTOM; + else if (StrEquals("TOP_LEFT", cname)) + index = TOP_LEFT; + else if (StrEquals("TOP_RIGHT", cname)) + index = TOP_RIGHT; + else if (StrEquals("BOTTOM_LEFT", cname)) + index = BOTTOM_LEFT; + else if (StrEquals("BOTTOM_RIGHT", cname)) + index = BOTTOM_RIGHT; + else { + fvwm_msg(ERR, "CursorStyle", "Unknown cursor name %s", cname); + free(cname); + free(newcursor); + return; + } + nc = atoi(newcursor); + free(cname); + if ((nc < 0) || (nc >= XC_num_glyphs) || ((nc % 2) != 0)) { + fvwm_msg(ERR, "CursorStyle", "Bad cursor number %s", newcursor); + free(newcursor); + return; + } + free(newcursor); + + /* replace the cursor defn */ + if (Scr.FvwmCursors[index]) + XFreeCursor(dpy, Scr.FvwmCursors[index]); + Scr.FvwmCursors[index] = XCreateFontCursor(dpy, nc); + + /* redefine all the windows using cursors */ + fw = Scr.FvwmRoot.next; + while (fw != NULL) { + for (i = 0; i < 4; i++) { + SafeDefineCursor( + fw->corners[i], Scr.FvwmCursors[TOP_LEFT + i]); + SafeDefineCursor( + fw->sides[i], Scr.FvwmCursors[TOP + i]); + } + for (i = 0; i < Scr.nr_left_buttons; i++) { + SafeDefineCursor(fw->left_w[i], Scr.FvwmCursors[SYS]); + } + for (i = 0; i < Scr.nr_right_buttons; i++) { + SafeDefineCursor(fw->right_w[i], Scr.FvwmCursors[SYS]); + } + SafeDefineCursor(fw->title_w, Scr.FvwmCursors[TITLE_CURSOR]); + fw = fw->next; + } -static void FreeMenuStyle(MenuStyle *ms) -{ - MenuRoot *mr; - MenuStyle *before = Scr.menus.DefaultStyle; - - if (!ms) - return; - mr = Scr.menus.all; - while(mr != NULL) - { - if(mr->ms == ms) - mr->ms = Scr.menus.DefaultStyle; - mr = mr->next; - } - if(ms->look.MenuGC) - XFreeGC(dpy, ms->look.MenuGC); - if(ms->look.MenuActiveGC) - XFreeGC(dpy, ms->look.MenuActiveGC); - if(ms->look.MenuActiveBackGC) - XFreeGC(dpy, ms->look.MenuActiveBackGC); - if(ms->look.MenuReliefGC) - XFreeGC(dpy, ms->look.MenuReliefGC); - if(ms->look.MenuStippleGC) - XFreeGC(dpy, ms->look.MenuStippleGC); - if(ms->look.MenuShadowGC) - XFreeGC(dpy, ms->look.MenuShadowGC); - if (ms->look.sidePic) - DestroyPicture(dpy, ms->look.sidePic); - if (ms->look.f.hasSideColor == 1) - FreeColors(&ms->look.sideColor, 1); - - while(before->next != ms) - /* Not too many checks, may segfaults in race conditions */ - before = before->next; - - before->next = ms->next; - free(ms->name); - free(ms); + /* Do the menus for good measure */ + mr = Scr.menus.all; + while (mr != NULL) { + SafeDefineCursor(mr->w, Scr.FvwmCursors[MENU]); + mr = mr->next; + } } -void DestroyMenuStyle(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +MenuStyle * +FindMenuStyle(char *name) { - MenuStyle *ms = NULL; - char *name = NULL; - MenuRoot *mr; - - action = GetNextToken(action,&name); - if (name == NULL) - { - fvwm_msg(ERR,"DestroyMenuStyle", "needs one parameter"); - return; - } - - ms = FindMenuStyle(name); - if(ms == NULL) - fvwm_msg(ERR,"DestroyMenuStyle", "cannot find style %s", name); - else if (ms == Scr.menus.DefaultStyle) - fvwm_msg(ERR,"DestroyMenuStyle", "cannot destroy Default Menu Face"); - else - { - FreeMenuFace(dpy, &ms->look.face); - FreeMenuStyle(ms); - MakeMenus(); - } - free(name); - for (mr = Scr.menus.all; mr != NULL; mr = mr->next) - { - if (mr->ms == ms) - mr->ms = Scr.menus.DefaultStyle; - } - MakeMenus(); -} + MenuStyle *ms = Scr.menus.DefaultStyle; -static void UpdateMenuStyle(MenuStyle *ms) -{ - XGCValues gcv; - unsigned long gcm; - - if (ms->look.pStdFont != NULL && ms->look.pStdFont != &Scr.StdFont) - { - ms->look.pStdFont->y = ms->look.pStdFont->font->ascent; - ms->look.pStdFont->height = - ms->look.pStdFont->font->ascent + - ms->look.pStdFont->font->descent; - } - ms->look.EntryHeight = - ms->look.pStdFont->height + HEIGHT_EXTRA; - - /* calculate colors based on foreground */ - if (!ms->look.f.hasActiveFore) - ms->look.MenuActiveColors.fore=ms->look.MenuColors.fore; - - /* calculate colors based on background */ - if (!ms->look.f.hasActiveBack) - ms->look.MenuActiveColors.back = ms->look.MenuColors.back; - if (!ms->look.f.hasStippleFore) - ms->look.MenuStippleColors.fore = ms->look.MenuColors.back; - if(Scr.d_depth > 2) { /* if not black and white */ - ms->look.MenuRelief.back = GetShadow(ms->look.MenuColors.back); - ms->look.MenuRelief.fore = GetHilite(ms->look.MenuColors.back); - } else { /* black and white */ - ms->look.MenuRelief.back = GetColor("black"); - ms->look.MenuRelief.fore = GetColor("white"); - } - ms->look.MenuStippleColors.back = ms->look.MenuColors.back; - - /* make GC's */ - gcm = GCFunction|GCPlaneMask|GCFont|GCGraphicsExposures| - GCLineWidth|GCForeground|GCBackground; - gcv.fill_style = FillSolid; - gcv.font = ms->look.pStdFont->font->fid; - gcv.plane_mask = AllPlanes; - gcv.function = GXcopy; - gcv.graphics_exposures = False; - gcv.line_width = 0; - - gcv.foreground = ms->look.MenuRelief.fore; - gcv.background = ms->look.MenuRelief.back; - if(ms->look.MenuReliefGC != NULL) - XFreeGC(dpy,ms->look.MenuReliefGC); - ms->look.MenuReliefGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); - - gcv.foreground = ms->look.MenuRelief.back; - gcv.background = ms->look.MenuRelief.fore; - if(ms->look.MenuShadowGC != NULL) - XFreeGC(dpy,ms->look.MenuShadowGC); - ms->look.MenuShadowGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); - - gcv.foreground = (ms->look.f.hasActiveBack) ? - ms->look.MenuActiveColors.back : ms->look.MenuRelief.back; - gcv.background = (ms->look.f.hasActiveFore) ? - ms->look.MenuActiveColors.fore : ms->look.MenuRelief.fore; - if(ms->look.MenuActiveBackGC != NULL) - XFreeGC(dpy,ms->look.MenuActiveBackGC); - ms->look.MenuActiveBackGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); - - gcv.foreground = ms->look.MenuColors.fore; - gcv.background = ms->look.MenuColors.back; - if(ms->look.MenuGC != NULL) - XFreeGC(dpy,ms->look.MenuGC); - ms->look.MenuGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); - - gcv.foreground = ms->look.MenuActiveColors.fore; - gcv.background = ms->look.MenuActiveColors.back; - if(ms->look.MenuActiveGC != NULL) - XFreeGC(dpy,ms->look.MenuActiveGC); - ms->look.MenuActiveGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); - - if(ms->look.MenuStippleGC != NULL) - XFreeGC(dpy,ms->look.MenuStippleGC); - if(Scr.d_depth < 2) - { - gcv.fill_style = FillStippled; - gcv.stipple = Scr.gray_bitmap; - gcm=GCFunction|GCPlaneMask|GCGraphicsExposures|GCLineWidth| - GCForeground|GCBackground|GCFont|GCStipple|GCFillStyle; - ms->look.MenuStippleGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); - - gcm=GCFunction|GCPlaneMask|GCGraphicsExposures|GCLineWidth| - GCForeground|GCBackground|GCFont; - gcv.fill_style = FillSolid; - } - else - { - gcv.foreground = ms->look.MenuStippleColors.fore; - gcv.background = ms->look.MenuStippleColors.back; - ms->look.MenuStippleGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); - } + while (ms != NULL) { + if (strcasecmp(ms->name, name) == 0) + return ms; + ms = ms->next; + } + return NULL; } - -static int GetMenuStyleIndex(char *option) +static void +FreeMenuStyle(MenuStyle *ms) { - char *optlist[] = { - "fvwm", "mwm", "win", - "Foreground", "Background", "Greyed", - "HilightBack", "HilightBackOff", - "ActiveFore", "ActiveForeOff", - "Hilight3DThick", "Hilight3DThin", "Hilight3DOff", - "Animation", "AnimationOff", - "Font", - "MenuFace", - "PopupDelay", "PopupOffset", - "TitleWarp", "TitleWarpOff", - "TitleUnderlines0", "TitleUnderlines1", "TitleUnderlines2", - "SeparatorsLong", "SeparatorsShort", - "TrianglesSolid", "TrianglesRelief", - "PopupImmediately", "PopupDelayed", - "DoubleClickTime", - "SidePic", "SideColor", - NULL - }; - return GetTokenIndex(option, optlist, 0, NULL); + MenuRoot *mr; + MenuStyle *before = Scr.menus.DefaultStyle; + + if (!ms) + return; + mr = Scr.menus.all; + while (mr != NULL) { + if (mr->ms == ms) + mr->ms = Scr.menus.DefaultStyle; + mr = mr->next; + } + if (ms->look.MenuGC) + XFreeGC(dpy, ms->look.MenuGC); + if (ms->look.MenuActiveGC) + XFreeGC(dpy, ms->look.MenuActiveGC); + if (ms->look.MenuActiveBackGC) + XFreeGC(dpy, ms->look.MenuActiveBackGC); + if (ms->look.MenuReliefGC) + XFreeGC(dpy, ms->look.MenuReliefGC); + if (ms->look.MenuStippleGC) + XFreeGC(dpy, ms->look.MenuStippleGC); + if (ms->look.MenuShadowGC) + XFreeGC(dpy, ms->look.MenuShadowGC); + if (ms->look.sidePic) + DestroyPicture(dpy, ms->look.sidePic); + if (ms->look.f.hasSideColor == 1) + FreeColors(&ms->look.sideColor, 1); + + while (before != NULL && before->next != ms) + before = before->next; + + before->next = ms->next; + free(ms->name); + free(ms); } -static void NewMenuStyle(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +DestroyMenuStyle(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - char *name; - char *option = NULL; - char *optstring = NULL; - char *nextarg; - char *args; - char *arg1; - MenuStyle *ms; - MenuStyle *tmpms; - Bool is_initialised = True; - Bool gc_changed = False; - Bool is_default_style = False; - int val[2]; - int n; - XFontStruct *xfs = NULL; - int i; - - action = GetNextToken(action, &name); - if (!name) - { - fvwm_msg(ERR,"NewMenuStyle", "error in %s style specification",action); - return; - } - - tmpms = (MenuStyle *)safemalloc(sizeof(MenuStyle)); - memset(tmpms, 0, sizeof(MenuStyle)); - ms = FindMenuStyle(name); - if (ms != NULL) - { - /* copy the structure over our temporary menu face. */ - memcpy(tmpms, ms, sizeof(MenuStyle)); - if (ms == Scr.menus.DefaultStyle) - is_default_style = True; - free(name); - } - else - { - tmpms->name = name; - is_initialised = False; - } - - /* Parse the options. */ - while (action && *action) - { - if (is_initialised == False) - { - /* some default configuration goes here for the new menu style */ - tmpms->look.MenuColors.back = GetColor("white"); - tmpms->look.MenuColors.fore = GetColor("black"); - tmpms->look.pStdFont = &Scr.StdFont; - tmpms->look.face.type = SimpleMenu; - tmpms->look.f.hasActiveFore = 0; - tmpms->look.f.hasActiveBack = 0; - gc_changed = True; - option = "fvwm"; - } - else - { - /* Read next option specification (delimited by a comma or \0). */ - args = action; - action = GetQuotedString(action, &optstring, ",", NULL, NULL, NULL); - if (!optstring) - break; - - args = GetNextToken(optstring, &option); - if (!option) - { - free(optstring); - break; - } - nextarg = GetNextToken(args, &arg1); - } - - switch((i = GetMenuStyleIndex(option))) - { - case 0: /* fvwm */ - case 1: /* mwm */ - case 2: /* win */ - if (i == 0) { - tmpms->feel.PopupOffsetPercent = 67; - tmpms->feel.PopupOffsetAdd = 0; - tmpms->feel.f.PopupImmediately = 0; - tmpms->feel.f.TitleWarp = 1; - tmpms->look.ReliefThickness = 1; - tmpms->look.TitleUnderlines = 1; - tmpms->look.f.LongSeparators = 0; - tmpms->look.f.TriangleRelief = 1; - tmpms->look.f.Hilight = 0; - } else if (i == 1) { - tmpms->feel.PopupOffsetPercent = 100; - tmpms->feel.PopupOffsetAdd = -3; - tmpms->feel.f.PopupImmediately = 1; - tmpms->feel.f.TitleWarp = 0; - tmpms->look.ReliefThickness = 2; - tmpms->look.TitleUnderlines = 2; - tmpms->look.f.LongSeparators = 1; - tmpms->look.f.TriangleRelief = 1; - tmpms->look.f.Hilight = 0; - } else /* i == 2 */ { - tmpms->feel.PopupOffsetPercent = 100; - tmpms->feel.PopupOffsetAdd = -5; - tmpms->feel.f.PopupImmediately = 1; - tmpms->feel.f.TitleWarp = 0; - tmpms->look.ReliefThickness = 0; - tmpms->look.TitleUnderlines = 1; - tmpms->look.f.LongSeparators = 0; - tmpms->look.f.TriangleRelief = 0; - tmpms->look.f.Hilight = 1; - } - - /* common settings */ - tmpms->feel.f.Animated = 0; - FreeMenuFace(dpy, &tmpms->look.face); - tmpms->look.face.type = SimpleMenu; - if (tmpms->look.pStdFont && tmpms->look.pStdFont != &Scr.StdFont) - { - XFreeFont(dpy, tmpms->look.pStdFont->font); - free(tmpms->look.pStdFont); - } - tmpms->look.pStdFont = &Scr.StdFont; - gc_changed = True; - if (tmpms->look.f.hasSideColor == 1) - { - FreeColors(&tmpms->look.sideColor, 1); - tmpms->look.f.hasSideColor = 0; - } - tmpms->look.f.hasSideColor = 0; - if (tmpms->look.sidePic) - { - DestroyPicture(dpy, tmpms->look.sidePic); - tmpms->look.sidePic = NULL; - } + MenuStyle *ms = NULL; + char *name = NULL; + MenuRoot *mr; - if (is_initialised == False) - { - /* now begin the real work */ - is_initialised = True; - continue; + action = GetNextToken(action, &name); + if (name == NULL) { + fvwm_msg(ERR, "DestroyMenuStyle", "needs one parameter"); + return; } - break; - case 3: /* Foreground */ - FreeColors(&tmpms->look.MenuColors.fore, 1); - if (arg1) - tmpms->look.MenuColors.fore = GetColor(arg1); - else - tmpms->look.MenuColors.fore = GetColor("black"); - gc_changed = True; - break; - - case 4: /* Background */ - FreeColors(&tmpms->look.MenuColors.back, 1); - if (arg1) - tmpms->look.MenuColors.back = GetColor(arg1); - else - tmpms->look.MenuColors.back = GetColor("grey"); - gc_changed = True; - break; - - case 5: /* Greyed */ - if (tmpms->look.f.hasStippleFore) - FreeColors(&tmpms->look.MenuStippleColors.fore, 1); - if (arg1 == NULL) - { - tmpms->look.f.hasStippleFore = 0; + ms = FindMenuStyle(name); + if (ms == NULL) + fvwm_msg(ERR, "DestroyMenuStyle", "cannot find style %s", name); + else if (ms == Scr.menus.DefaultStyle) + fvwm_msg(ERR, "DestroyMenuStyle", + "cannot destroy Default Menu Face"); + else { + FreeMenuFace(dpy, &ms->look.face); + FreeMenuStyle(ms); + MakeMenus(); } - else - { - tmpms->look.MenuStippleColors.fore = GetColor(arg1); - tmpms->look.f.hasStippleFore = 1; + free(name); + for (mr = Scr.menus.all; mr != NULL; mr = mr->next) { + if (mr->ms == ms) + mr->ms = Scr.menus.DefaultStyle; } - gc_changed = True; - break; + MakeMenus(); +} - case 6: /* HilightBack */ - if (tmpms->look.f.hasActiveBack) - FreeColors(&tmpms->look.MenuActiveColors.back, 1); - if (arg1 == NULL) - { - tmpms->look.f.hasActiveBack = 0; +static void +UpdateMenuStyle(MenuStyle *ms) +{ + XGCValues gcv; + unsigned long gcm; + + if (ms->look.pStdFont != NULL && ms->look.pStdFont != &Scr.StdFont) { + ms->look.pStdFont->y = ms->look.pStdFont->font->ascent; + ms->look.pStdFont->height = ms->look.pStdFont->font->ascent + + ms->look.pStdFont->font->descent; } - else - { - tmpms->look.MenuActiveColors.back = GetColor(arg1); - tmpms->look.f.hasActiveBack = 1; - } - tmpms->look.f.Hilight = 1; - gc_changed = True; - break; - - case 7: /* HilightBackOff */ - tmpms->look.f.Hilight = 0; - gc_changed = True; - break; - - case 8: /* ActiveFore */ - if (tmpms->look.f.hasActiveFore) - FreeColors(&tmpms->look.MenuActiveColors.fore, 1); - if (arg1 == NULL) - { - tmpms->look.f.hasActiveFore = 0; + ms->look.EntryHeight = ms->look.pStdFont->height + HEIGHT_EXTRA; + + /* calculate colors based on foreground */ + if (!ms->look.f.hasActiveFore) + ms->look.MenuActiveColors.fore = ms->look.MenuColors.fore; + + /* calculate colors based on background */ + if (!ms->look.f.hasActiveBack) + ms->look.MenuActiveColors.back = ms->look.MenuColors.back; + if (!ms->look.f.hasStippleFore) + ms->look.MenuStippleColors.fore = ms->look.MenuColors.back; + if (Scr.d_depth > 2) { /* if not black and white */ + ms->look.MenuRelief.back = GetShadow(ms->look.MenuColors.back); + ms->look.MenuRelief.fore = GetHilite(ms->look.MenuColors.back); + } else { /* black and white */ + ms->look.MenuRelief.back = GetColor("black"); + ms->look.MenuRelief.fore = GetColor("white"); } - else - { - tmpms->look.MenuActiveColors.fore = GetColor(arg1); - tmpms->look.f.hasActiveFore = 1; + ms->look.MenuStippleColors.back = ms->look.MenuColors.back; + + /* make GC's */ + gcm = GCFunction | GCPlaneMask | GCFont | GCGraphicsExposures | + GCLineWidth | GCForeground | GCBackground; + gcv.fill_style = FillSolid; + gcv.font = ms->look.pStdFont->font->fid; + gcv.plane_mask = AllPlanes; + gcv.function = GXcopy; + gcv.graphics_exposures = False; + gcv.line_width = 0; + + gcv.foreground = ms->look.MenuRelief.fore; + gcv.background = ms->look.MenuRelief.back; + if (ms->look.MenuReliefGC != NULL) + XFreeGC(dpy, ms->look.MenuReliefGC); + ms->look.MenuReliefGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); + + gcv.foreground = ms->look.MenuRelief.back; + gcv.background = ms->look.MenuRelief.fore; + if (ms->look.MenuShadowGC != NULL) + XFreeGC(dpy, ms->look.MenuShadowGC); + ms->look.MenuShadowGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); + + gcv.foreground = (ms->look.f.hasActiveBack) ? + ms->look.MenuActiveColors.back : + ms->look.MenuRelief.back; + gcv.background = (ms->look.f.hasActiveFore) ? + ms->look.MenuActiveColors.fore : + ms->look.MenuRelief.fore; + if (ms->look.MenuActiveBackGC != NULL) + XFreeGC(dpy, ms->look.MenuActiveBackGC); + ms->look.MenuActiveBackGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); + + gcv.foreground = ms->look.MenuColors.fore; + gcv.background = ms->look.MenuColors.back; + if (ms->look.MenuGC != NULL) + XFreeGC(dpy, ms->look.MenuGC); + ms->look.MenuGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); + + gcv.foreground = ms->look.MenuActiveColors.fore; + gcv.background = ms->look.MenuActiveColors.back; + if (ms->look.MenuActiveGC != NULL) + XFreeGC(dpy, ms->look.MenuActiveGC); + ms->look.MenuActiveGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); + + if (ms->look.MenuStippleGC != NULL) + XFreeGC(dpy, ms->look.MenuStippleGC); + if (Scr.d_depth < 2) { + gcv.fill_style = FillStippled; + gcv.stipple = Scr.gray_bitmap; + gcm = GCFunction | GCPlaneMask | GCGraphicsExposures | + GCLineWidth | GCForeground | GCBackground | GCFont | + GCStipple | GCFillStyle; + ms->look.MenuStippleGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); + + gcm = GCFunction | GCPlaneMask | GCGraphicsExposures | + GCLineWidth | GCForeground | GCBackground | GCFont; + gcv.fill_style = FillSolid; + } else { + gcv.foreground = ms->look.MenuStippleColors.fore; + gcv.background = ms->look.MenuStippleColors.back; + ms->look.MenuStippleGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); } - gc_changed = True; - break; +} - case 9: /* ActiveForeOff */ - tmpms->look.f.hasActiveFore = 0; - gc_changed = True; - break; +static int +GetMenuStyleIndex(char *option) +{ + char *optlist[] = {"fvwm", "mwm", "win", "Foreground", "Background", + "Greyed", "HilightBack", "HilightBackOff", "ActiveFore", + "ActiveForeOff", "Hilight3DThick", "Hilight3DThin", "Hilight3DOff", + "Animation", "AnimationOff", "Font", "MenuFace", "PopupDelay", + "PopupOffset", "TitleWarp", "TitleWarpOff", "TitleUnderlines0", + "TitleUnderlines1", "TitleUnderlines2", "SeparatorsLong", + "SeparatorsShort", "TrianglesSolid", "TrianglesRelief", + "PopupImmediately", "PopupDelayed", "DoubleClickTime", "SidePic", + "SideColor", NULL}; + return GetTokenIndex(option, optlist, 0, NULL); +} - case 10: /* Hilight3DThick */ - tmpms->look.ReliefThickness = 2; - break; +static void +NewMenuStyle(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) +{ + char *name; + char *option = NULL; + char *optstring = NULL; + char *nextarg; + char *args; + char *arg1; + MenuStyle *ms; + MenuStyle *tmpms; + Bool is_initialised = True; + Bool gc_changed = False; + Bool is_default_style = False; + int val[2]; + int n; + XFontStruct *xfs = NULL; + int i; + + action = GetNextToken(action, &name); + if (!name) { + fvwm_msg(ERR, "NewMenuStyle", "error in %s style specification", + action); + return; + } - case 11: /* Hilight3DThin */ - tmpms->look.ReliefThickness = 1; - break; + tmpms = (MenuStyle *)xmalloc(sizeof(MenuStyle)); + memset(tmpms, 0, sizeof(MenuStyle)); + ms = FindMenuStyle(name); + if (ms != NULL) { + /* copy the structure over our temporary menu face. */ + memcpy(tmpms, ms, sizeof(MenuStyle)); + if (ms == Scr.menus.DefaultStyle) + is_default_style = True; + free(name); + } else { + tmpms->name = name; + is_initialised = False; + } - case 12: /* Hilight3DOff */ - tmpms->look.ReliefThickness = 0; - break; + /* Parse the options. */ + while (action && *action) { + if (is_initialised == False) { + /* some default configuration goes here for the new menu + * style */ + tmpms->look.MenuColors.back = GetColor("white"); + tmpms->look.MenuColors.fore = GetColor("black"); + tmpms->look.pStdFont = &Scr.StdFont; + tmpms->look.face.type = SimpleMenu; + tmpms->look.f.hasActiveFore = 0; + tmpms->look.f.hasActiveBack = 0; + gc_changed = True; + option = "fvwm"; + } else { + /* Read next option specification (delimited by a comma + * or \0). */ + args = action; + action = GetQuotedString( + action, &optstring, ",", NULL, NULL, NULL); + if (!optstring) + break; + + args = GetNextToken(optstring, &option); + if (!option) { + free(optstring); + break; + } + nextarg = GetNextToken(args, &arg1); + } - case 13: /* Animation */ - tmpms->feel.f.Animated = 1; - break; + switch ((i = GetMenuStyleIndex(option))) { + case 0: /* fvwm */ + case 1: /* mwm */ + case 2: /* win */ + if (i == 0) { + tmpms->feel.PopupOffsetPercent = 67; + tmpms->feel.PopupOffsetAdd = 0; + tmpms->feel.f.PopupImmediately = 0; + tmpms->feel.f.TitleWarp = 1; + tmpms->look.ReliefThickness = 1; + tmpms->look.TitleUnderlines = 1; + tmpms->look.f.LongSeparators = 0; + tmpms->look.f.TriangleRelief = 1; + tmpms->look.f.Hilight = 0; + } else if (i == 1) { + tmpms->feel.PopupOffsetPercent = 100; + tmpms->feel.PopupOffsetAdd = -3; + tmpms->feel.f.PopupImmediately = 1; + tmpms->feel.f.TitleWarp = 0; + tmpms->look.ReliefThickness = 2; + tmpms->look.TitleUnderlines = 2; + tmpms->look.f.LongSeparators = 1; + tmpms->look.f.TriangleRelief = 1; + tmpms->look.f.Hilight = 0; + } else /* i == 2 */ { + tmpms->feel.PopupOffsetPercent = 100; + tmpms->feel.PopupOffsetAdd = -5; + tmpms->feel.f.PopupImmediately = 1; + tmpms->feel.f.TitleWarp = 0; + tmpms->look.ReliefThickness = 0; + tmpms->look.TitleUnderlines = 1; + tmpms->look.f.LongSeparators = 0; + tmpms->look.f.TriangleRelief = 0; + tmpms->look.f.Hilight = 1; + } - case 14: /* AnimationOff */ - tmpms->feel.f.Animated = 0; - break; + /* common settings */ + tmpms->feel.f.Animated = 0; + FreeMenuFace(dpy, &tmpms->look.face); + tmpms->look.face.type = SimpleMenu; + if (tmpms->look.pStdFont && + tmpms->look.pStdFont != &Scr.StdFont) { + XFreeFont(dpy, tmpms->look.pStdFont->font); + free(tmpms->look.pStdFont); + } + tmpms->look.pStdFont = &Scr.StdFont; + gc_changed = True; + if (tmpms->look.f.hasSideColor == 1) { + FreeColors(&tmpms->look.sideColor, 1); + tmpms->look.f.hasSideColor = 0; + } + tmpms->look.f.hasSideColor = 0; + if (tmpms->look.sidePic) { + DestroyPicture(dpy, tmpms->look.sidePic); + tmpms->look.sidePic = NULL; + } - case 15: /* Font */ - if (arg1 != NULL && (xfs = GetFontOrFixed(dpy, arg1)) == NULL) - { - fvwm_msg(ERR,"NewMenuStyle", - "Couldn't load font '%s' or 'fixed'\n", arg1); - break; - } - if (tmpms->look.pStdFont && tmpms->look.pStdFont != &Scr.StdFont) - { - if (tmpms->look.pStdFont->font != NULL) - XFreeFont(dpy, tmpms->look.pStdFont->font); - free(tmpms->look.pStdFont); - } - if (arg1 == NULL) - { - /* reset to screen font */ - tmpms->look.pStdFont = &Scr.StdFont; - } - else - { - tmpms->look.pStdFont = (MyFont *)safemalloc(sizeof(MyFont)); - tmpms->look.pStdFont->font = xfs; - } - gc_changed = True; - break; + if (is_initialised == False) { + /* now begin the real work */ + is_initialised = True; + continue; + } + break; - case 16: /* MenuFace */ - while (args && *args != '\0' && isspace(*args)) - args++; - ReadMenuFace(args, &tmpms->look.face, True); - break; + case 3: /* Foreground */ + FreeColors(&tmpms->look.MenuColors.fore, 1); + if (arg1) + tmpms->look.MenuColors.fore = GetColor(arg1); + else + tmpms->look.MenuColors.fore = GetColor("black"); + gc_changed = True; + break; + + case 4: /* Background */ + FreeColors(&tmpms->look.MenuColors.back, 1); + if (arg1) + tmpms->look.MenuColors.back = GetColor(arg1); + else + tmpms->look.MenuColors.back = GetColor("grey"); + gc_changed = True; + break; + + case 5: /* Greyed */ + if (tmpms->look.f.hasStippleFore) + FreeColors( + &tmpms->look.MenuStippleColors.fore, 1); + if (arg1 == NULL) { + tmpms->look.f.hasStippleFore = 0; + } else { + tmpms->look.MenuStippleColors.fore = + GetColor(arg1); + tmpms->look.f.hasStippleFore = 1; + } + gc_changed = True; + break; + + case 6: /* HilightBack */ + if (tmpms->look.f.hasActiveBack) + FreeColors( + &tmpms->look.MenuActiveColors.back, 1); + if (arg1 == NULL) { + tmpms->look.f.hasActiveBack = 0; + } else { + tmpms->look.MenuActiveColors.back = + GetColor(arg1); + tmpms->look.f.hasActiveBack = 1; + } + tmpms->look.f.Hilight = 1; + gc_changed = True; + break; + + case 7: /* HilightBackOff */ + tmpms->look.f.Hilight = 0; + gc_changed = True; + break; + + case 8: /* ActiveFore */ + if (tmpms->look.f.hasActiveFore) + FreeColors( + &tmpms->look.MenuActiveColors.fore, 1); + if (arg1 == NULL) { + tmpms->look.f.hasActiveFore = 0; + } else { + tmpms->look.MenuActiveColors.fore = + GetColor(arg1); + tmpms->look.f.hasActiveFore = 1; + } + gc_changed = True; + break; + + case 9: /* ActiveForeOff */ + tmpms->look.f.hasActiveFore = 0; + gc_changed = True; + break; + + case 10: /* Hilight3DThick */ + tmpms->look.ReliefThickness = 2; + break; + + case 11: /* Hilight3DThin */ + tmpms->look.ReliefThickness = 1; + break; + + case 12: /* Hilight3DOff */ + tmpms->look.ReliefThickness = 0; + break; + + case 13: /* Animation */ + tmpms->feel.f.Animated = 1; + break; + + case 14: /* AnimationOff */ + tmpms->feel.f.Animated = 0; + break; + + case 15: /* Font */ + if (arg1 != NULL && + (xfs = GetFontOrFixed(dpy, arg1)) == NULL) { + fvwm_msg(ERR, "NewMenuStyle", + "Couldn't load font '%s' or 'fixed'\n", + arg1); + break; + } + if (tmpms->look.pStdFont && + tmpms->look.pStdFont != &Scr.StdFont) { + if (tmpms->look.pStdFont->font != NULL) + XFreeFont( + dpy, tmpms->look.pStdFont->font); + free(tmpms->look.pStdFont); + } + if (arg1 == NULL) { + /* reset to screen font */ + tmpms->look.pStdFont = &Scr.StdFont; + } else { + tmpms->look.pStdFont = + (MyFont *)xmalloc(sizeof(MyFont)); + tmpms->look.pStdFont->font = xfs; + } + gc_changed = True; + break; + + case 16: /* MenuFace */ + while (args && *args != '\0' && isspace(*args)) + args++; + ReadMenuFace(args, &tmpms->look.face, True); + break; + + case 17: /* PopupDelay */ + if (GetIntegerArguments(args, NULL, val, 1) == 0 || + *val < 0) + Scr.menus.PopupDelay10ms = DEFAULT_POPUP_DELAY; + else + Scr.menus.PopupDelay10ms = (*val + 9) / 10; + if (!is_default_style) { + fvwm_msg(WARN, "NewMenuStyle", + "PopupDelay applied to style '%s' will " + "affect all menus", + tmpms->name); + } + break; + + case 18: /* PopupOffset */ + if ((n = GetIntegerArguments(args, NULL, val, 2)) == + 0) { + fvwm_msg(ERR, "NewMenuStyle", + "PopupOffset requires one or two " + "arguments"); + } else { + tmpms->feel.PopupOffsetAdd = val[0]; + if (n == 2 && val[1] <= 100 && val[1] >= 0) + tmpms->feel.PopupOffsetPercent = val[1]; + else + tmpms->feel.PopupOffsetPercent = 100; + } + break; - case 17: /* PopupDelay */ - if (GetIntegerArguments(args, NULL, val, 1) == 0 || *val < 0) - Scr.menus.PopupDelay10ms = DEFAULT_POPUP_DELAY; - else - Scr.menus.PopupDelay10ms = (*val+9)/10; - if (!is_default_style) - { - fvwm_msg(WARN, "NewMenuStyle", - "PopupDelay applied to style '%s' will affect all menus", - tmpms->name); - } - break; + case 19: /* TitleWarp */ + tmpms->feel.f.TitleWarp = 1; + break; - case 18: /* PopupOffset */ - if ((n = GetIntegerArguments(args, NULL, val, 2)) == 0) - { - fvwm_msg(ERR,"NewMenuStyle", - "PopupOffset requires one or two arguments"); - } - else - { - tmpms->feel.PopupOffsetAdd = val[0]; - if (n == 2 && val[1] <= 100 && val[1] >= 0) - tmpms->feel.PopupOffsetPercent = val[1]; - else - tmpms->feel.PopupOffsetPercent = 100; - } - break; + case 20: /* TitleWarpOff */ + tmpms->feel.f.TitleWarp = 0; + break; - case 19: /* TitleWarp */ - tmpms->feel.f.TitleWarp = 1; - break; + case 21: /* TitleUnderlines0 */ + tmpms->look.TitleUnderlines = 0; + break; - case 20: /* TitleWarpOff */ - tmpms->feel.f.TitleWarp = 0; - break; + case 22: /* TitleUnderlines1 */ + tmpms->look.TitleUnderlines = 1; + break; - case 21: /* TitleUnderlines0 */ - tmpms->look.TitleUnderlines = 0; - break; + case 23: /* TitleUnderlines2 */ + tmpms->look.TitleUnderlines = 2; + break; - case 22: /* TitleUnderlines1 */ - tmpms->look.TitleUnderlines = 1; - break; + case 24: /* SeparatorsLong */ + tmpms->look.f.LongSeparators = 1; + break; - case 23: /* TitleUnderlines2 */ - tmpms->look.TitleUnderlines = 2; - break; + case 25: /* SeparatorsShort */ + tmpms->look.f.LongSeparators = 0; + break; - case 24: /* SeparatorsLong */ - tmpms->look.f.LongSeparators = 1; - break; + case 26: /* TrianglesSolid */ + tmpms->look.f.TriangleRelief = 0; + break; - case 25: /* SeparatorsShort */ - tmpms->look.f.LongSeparators = 0; - break; + case 27: /* TrianglesRelief */ + tmpms->look.f.TriangleRelief = 1; + break; - case 26: /* TrianglesSolid */ - tmpms->look.f.TriangleRelief = 0; - break; + case 28: /* PopupImmediately */ + tmpms->feel.f.PopupImmediately = 1; + break; - case 27: /* TrianglesRelief */ - tmpms->look.f.TriangleRelief = 1; - break; + case 29: /* PopupDelayed */ + tmpms->feel.f.PopupImmediately = 0; + break; - case 28: /* PopupImmediately */ - tmpms->feel.f.PopupImmediately = 1; - break; + case 30: /* DoubleClickTime */ + if (GetIntegerArguments(args, NULL, val, 1) == 0 || + *val < 0) + Scr.menus.DoubleClickTime = + DEFAULT_MENU_CLICKTIME; + else + Scr.menus.DoubleClickTime = *val; + if (!is_default_style) { + fvwm_msg(WARN, "NewMenuStyle", + "DoubleClickTime for style '%s' will " + "affect all menus", + tmpms->name); + } + break; - case 29: /* PopupDelayed */ - tmpms->feel.f.PopupImmediately = 0; - break; + case 31: /* SidePic */ + if (tmpms->look.sidePic) { + DestroyPicture(dpy, tmpms->look.sidePic); + tmpms->look.sidePic = NULL; + } + if (arg1 != NULL) { + tmpms->look.sidePic = + CachePicture(dpy, Scr.Root, IconPath, + PixmapPath, arg1, Scr.ColorLimit); + if (!tmpms->look.sidePic) + fvwm_msg(WARN, "NewMenuStyle", + "Couldn't find pixmap %s", arg1); + } + break; - case 30: /* DoubleClickTime */ - if (GetIntegerArguments(args, NULL, val, 1) == 0 || *val < 0) - Scr.menus.DoubleClickTime = DEFAULT_MENU_CLICKTIME; - else - Scr.menus.DoubleClickTime = *val; - if (!is_default_style) - { - fvwm_msg(WARN, "NewMenuStyle", - "DoubleClickTime for style '%s' will affect all menus", - tmpms->name); - } - break; + case 32: /* SideColor */ + if (tmpms->look.f.hasSideColor == 1) { + FreeColors(&tmpms->look.sideColor, 1); + tmpms->look.f.hasSideColor = 0; + } + if (arg1 != NULL) { + tmpms->look.sideColor = GetColor(arg1); + tmpms->look.f.hasSideColor = 1; + } + break; - case 31: /* SidePic */ - if (tmpms->look.sidePic) - { - DestroyPicture(dpy, tmpms->look.sidePic); - tmpms->look.sidePic = NULL; - } - if (arg1 != NULL) - { - tmpms->look.sidePic = CachePicture(dpy, Scr.Root, IconPath, - PixmapPath, arg1, Scr.ColorLimit); - if (!tmpms->look.sidePic) - fvwm_msg(WARN, "NewMenuStyle", "Couldn't find pixmap %s", arg1); - } - break; + default: + fvwm_msg( + ERR, "NewMenuStyle", "unknown option '%s'", option); + break; + } /* switch */ - case 32: /* SideColor */ - if (tmpms->look.f.hasSideColor == 1) - { - FreeColors(&tmpms->look.sideColor, 1); - tmpms->look.f.hasSideColor = 0; - } - if (arg1 != NULL) - { - tmpms->look.sideColor = GetColor(arg1); - tmpms->look.f.hasSideColor = 1; - } - break; + if (option) { + free(option); + option = NULL; + } + free(optstring); + optstring = NULL; + if (arg1) { + free(arg1); + arg1 = NULL; + } + } /* while */ + + if (gc_changed) { + UpdateMenuStyle(tmpms); + } /* if (gc_changed) */ + + if (Scr.menus.DefaultStyle == NULL) { + /* First MenuStyle MUST be the default style */ + Scr.menus.DefaultStyle = tmpms; + tmpms->next = NULL; + } else if (ms != NULL) { + /* copy our new menu face over the old one */ + memcpy(ms, tmpms, sizeof(MenuStyle)); + free(tmpms); + } else { + MenuStyle *before = Scr.menus.DefaultStyle; -#if 0 - case 33: /* PositionHints */ - break; -#endif + /* add a new menu face to list */ + tmpms->next = NULL; + while (before->next != NULL) + before = before->next; + before->next = tmpms; + } - default: - fvwm_msg(ERR,"NewMenuStyle", "unknown option '%s'", option); - break; - } /* switch */ + MakeMenus(); - if (option) - { - free(option); - option = NULL; - } - free(optstring); - optstring = NULL; - if (arg1) - { - free(arg1); - arg1 = NULL; - } - } /* while */ - - if (gc_changed) - { - UpdateMenuStyle(tmpms); - } /* if (gc_changed) */ - - if(Scr.menus.DefaultStyle == NULL) - { - /* First MenuStyle MUST be the default style */ - Scr.menus.DefaultStyle = tmpms; - tmpms->next = NULL; - } - else if (ms != NULL) - { - /* copy our new menu face over the old one */ - memcpy(ms, tmpms, sizeof(MenuStyle)); - free(tmpms); - } - else - { - MenuStyle *before = Scr.menus.DefaultStyle; - - /* add a new menu face to list */ - tmpms->next = NULL; - while(before->next != NULL) - before = before->next; - before->next = tmpms; - } - - MakeMenus(); - - return; + return; } -static void OldMenuStyle(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +static void +OldMenuStyle(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - char *buffer, *rest; - char *fore, *back, *stipple, *font, *style, *animated; - size_t len; - - rest = GetNextToken(action,&fore); - rest = GetNextToken(rest,&back); - rest = GetNextToken(rest,&stipple); - rest = GetNextToken(rest,&font); - rest = GetNextToken(rest,&style); - rest = GetNextToken(rest,&animated); - - if(!fore || !back || !stipple || !font || !style) - { - fvwm_msg(ERR,"OldMenuStyle", "error in %s style specification", action); - } - else - { - len = strlen(action) + 100; - buffer = (char *)safemalloc(len); - snprintf(buffer, len, - "* %s, Foreground %s, Background %s, Greyed %s, Font %s, %s", - style, fore, back, stipple, font, - (animated != NULL && StrEquals(animated, "anim")) ? - "Animation" : "AnimationOff"); - NewMenuStyle(eventp, w, tmp_win, context, buffer, Module); - free(buffer); - } - - if(fore != NULL) - free(fore); - if(back != NULL) - free(back); - if(stipple != NULL) - free(stipple); - if(font != NULL) - free(font); - if(style != NULL) - free(style); - if(animated != NULL) - free(animated); -} + char *buffer, *rest; + char *fore, *back, *stipple, *font, *style, *animated; + size_t len; + + rest = GetNextToken(action, &fore); + rest = GetNextToken(rest, &back); + rest = GetNextToken(rest, &stipple); + rest = GetNextToken(rest, &font); + rest = GetNextToken(rest, &style); + rest = GetNextToken(rest, &animated); + + if (!fore || !back || !stipple || !font || !style) { + fvwm_msg(ERR, "OldMenuStyle", "error in %s style specification", + action); + } else { + len = strlen(action) + 100; + buffer = (char *)xmalloc(len); + snprintf(buffer, len, + "* %s, Foreground %s, Background %s, Greyed %s, Font %s, " + "%s", + style, fore, back, stipple, font, + (animated != NULL && StrEquals(animated, "anim")) ? + "Animation" : + "AnimationOff"); + NewMenuStyle(eventp, w, tmp_win, context, buffer, Module); + free(buffer); + } + if (fore != NULL) + free(fore); + if (back != NULL) + free(back); + if (stipple != NULL) + free(stipple); + if (font != NULL) + free(font); + if (style != NULL) + free(style); + if (animated != NULL) + free(animated); +} -void SetMenuStyle(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +SetMenuStyle(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - char *option; - - GetNextOption(SkipNTokens(action, 1), &option); - if (option == NULL || GetMenuStyleIndex(option) != -1) - NewMenuStyle(eventp, w, tmp_win, context, action, Module); - else - OldMenuStyle(eventp, w, tmp_win, context, action, Module); - if (option) - free(option); - return; -} + char *option; + GetNextOption(SkipNTokens(action, 1), &option); + if (option == NULL || GetMenuStyleIndex(option) != -1) + NewMenuStyle(eventp, w, tmp_win, context, action, Module); + else + OldMenuStyle(eventp, w, tmp_win, context, action, Module); + if (option) + free(option); + return; +} -void ChangeMenuStyle(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +ChangeMenuStyle(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - char *name = NULL, *menuname = NULL; - MenuStyle *ms = NULL; - MenuRoot *mr = NULL; - - - action = GetNextToken(action,&name); - if (name == NULL) - { - fvwm_msg(ERR,"ChangeMenuStyle", "needs at least two parameters"); - return; - } - - ms = FindMenuStyle(name); - if(ms == NULL) - { - fvwm_msg(ERR,"ChangeMenuStyle", "cannot find style %s", name); - free(name); - return; - } - free(name); - - action = GetNextToken(action,&menuname); - while(menuname != NULL && *menuname) - { - mr = FindPopup(menuname); - if(mr == NULL) - { - fvwm_msg(ERR,"ChangeMenuStyle", "cannot find menu %s", menuname); - free(menuname); - break; - } - mr->ms = ms; - MakeMenu(mr); - free(menuname); - action = GetNextToken(action,&menuname); - } -} + char *name = NULL, *menuname = NULL; + MenuStyle *ms = NULL; + MenuRoot *mr = NULL; + + action = GetNextToken(action, &name); + if (name == NULL) { + fvwm_msg( + ERR, "ChangeMenuStyle", "needs at least two parameters"); + return; + } + ms = FindMenuStyle(name); + if (ms == NULL) { + fvwm_msg(ERR, "ChangeMenuStyle", "cannot find style %s", name); + free(name); + return; + } + free(name); + + action = GetNextToken(action, &menuname); + while (menuname != NULL && *menuname) { + mr = FindPopup(menuname); + if (mr == NULL) { + fvwm_msg(ERR, "ChangeMenuStyle", "cannot find menu %s", + menuname); + free(menuname); + break; + } + mr->ms = ms; + MakeMenu(mr); + free(menuname); + action = GetNextToken(action, &menuname); + } +} Boolean ReadButtonFace(char *s, ButtonFace *bf, int button, int verbose); void FreeButtonFace(Display *dpy, ButtonFace *bf); @@ -2342,91 +2275,94 @@ void FreeButtonFace(Display *dpy, ButtonFace *bf); * Sets the border style (veliaa@rpi.edu) * ****************************************************************************/ -void SetBorderStyle(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +SetBorderStyle(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - char *parm = NULL, *prev = action; + char *parm = NULL, *prev = action; #ifdef USEDECOR - FvwmDecor *fl = cur_decor ? cur_decor : &Scr.DefaultDecor; + FvwmDecor *fl = cur_decor ? cur_decor : &Scr.DefaultDecor; #else - FvwmDecor *fl = &Scr.DefaultDecor; + FvwmDecor *fl = &Scr.DefaultDecor; #endif - action = GetNextToken(action, &parm); - while (parm) - { - if (StrEquals(parm,"active") || StrEquals(parm,"inactive")) - { - int len; - char *end, *tmp; - ButtonFace tmpbf, *bf; - tmpbf.style = SimpleButton; + action = GetNextToken(action, &parm); + while (parm) { + if (StrEquals(parm, "active") || StrEquals(parm, "inactive")) { + int len; + char *end, *tmp; + ButtonFace tmpbf, *bf; + tmpbf.style = SimpleButton; #ifdef MULTISTYLE - tmpbf.next = NULL; + tmpbf.next = NULL; #endif #ifdef MINI_ICONS - tmpbf.u.p = NULL; + tmpbf.u.p = NULL; #endif - if (StrEquals(parm,"active")) - bf = &fl->BorderStyle.active; - else - bf = &fl->BorderStyle.inactive; - while (isspace(*action)) ++action; - if ('(' != *action) { - if (!*action) { - fvwm_msg(ERR,"SetBorderStyle", - "error in %s border specification", parm); - free(parm); - return; - } - free(parm); - if (ReadButtonFace(action, &tmpbf,-1,True)) { - FreeButtonFace(dpy, bf); - *bf = tmpbf; - } - break; - } - end = strchr(++action, ')'); - if (!end) { - fvwm_msg(ERR,"SetBorderStyle", - "error in %s border specification", parm); - free(parm); - return; - } - len = end - action + 1; - tmp = safemalloc(len); - strncpy(tmp, action, len - 1); - tmp[len - 1] = 0; - ReadButtonFace(tmp, bf,-1,True); - free(tmp); - action = end + 1; - } - else if (strcmp(parm,"--")==0) { - if (ReadButtonFace(prev, &fl->BorderStyle.active,-1,True)) - ReadButtonFace(prev, &fl->BorderStyle.inactive,-1,False); - free(parm); - break; - } else { - ButtonFace tmpbf; - tmpbf.style = SimpleButton; + if (StrEquals(parm, "active")) + bf = &fl->BorderStyle.active; + else + bf = &fl->BorderStyle.inactive; + while (isspace(*action)) + ++action; + if ('(' != *action) { + if (!*action) { + fvwm_msg(ERR, "SetBorderStyle", + "error in %s border specification", + parm); + free(parm); + return; + } + free(parm); + if (ReadButtonFace(action, &tmpbf, -1, True)) { + FreeButtonFace(dpy, bf); + *bf = tmpbf; + } + break; + } + end = strchr(++action, ')'); + if (!end) { + fvwm_msg(ERR, "SetBorderStyle", + "error in %s border specification", parm); + free(parm); + return; + } + len = end - action + 1; + tmp = xmalloc(len); + strncpy(tmp, action, len - 1); + tmp[len - 1] = 0; + ReadButtonFace(tmp, bf, -1, True); + free(tmp); + action = end + 1; + } else if (strcmp(parm, "--") == 0) { + if (ReadButtonFace( + prev, &fl->BorderStyle.active, -1, True)) + ReadButtonFace( + prev, &fl->BorderStyle.inactive, -1, False); + free(parm); + break; + } else { + ButtonFace tmpbf; + tmpbf.style = SimpleButton; #ifdef MULTISTYLE - tmpbf.next = NULL; + tmpbf.next = NULL; #endif #ifdef MINI_ICONS - tmpbf.u.p = NULL; + tmpbf.u.p = NULL; #endif - if (ReadButtonFace(prev, &tmpbf,-1,True)) { - FreeButtonFace(dpy,&fl->BorderStyle.active); - fl->BorderStyle.active = tmpbf; - ReadButtonFace(prev, &fl->BorderStyle.inactive,-1,False); - } - free(parm); - break; + if (ReadButtonFace(prev, &tmpbf, -1, True)) { + FreeButtonFace(dpy, &fl->BorderStyle.active); + fl->BorderStyle.active = tmpbf; + ReadButtonFace( + prev, &fl->BorderStyle.inactive, -1, False); + } + free(parm); + break; + } + free(parm); + prev = action; + action = GetNextToken(action, &parm); } - free(parm); - prev = action; - action = GetNextToken(action,&parm); - } } #endif @@ -2438,449 +2374,436 @@ char *ReadTitleButton(char *s, TitleButton *tb, Boolean append, int button); * Appends a titlestyle (veliaa@rpi.edu) * ****************************************************************************/ -void AddTitleStyle(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int *Module) +void +AddTitleStyle(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { #ifdef USEDECOR - FvwmDecor *fl = cur_decor ? cur_decor : &Scr.DefaultDecor; + FvwmDecor *fl = cur_decor ? cur_decor : &Scr.DefaultDecor; #else - FvwmDecor *fl = &Scr.DefaultDecor; + FvwmDecor *fl = &Scr.DefaultDecor; #endif - char *parm=NULL; - - /* See if there's a next token. We actually don't care what it is, so - GetNextToken allocating memory is overkill, but... */ - GetNextToken(action,&parm); - while (parm) - { - free(parm); - if ((action = ReadTitleButton(action, &fl->titlebar, True, -1)) == NULL) - break; - GetNextToken(action, &parm); - } + char *parm = NULL; + + /* See if there's a next token. We actually don't care what it is, so + GetNextToken allocating memory is overkill, but... */ + GetNextToken(action, &parm); + while (parm) { + free(parm); + if ((action = ReadTitleButton( + action, &fl->titlebar, True, -1)) == NULL) + break; + GetNextToken(action, &parm); + } } #endif /* MULTISTYLE && EXTENDED_TITLESTYLE */ -void SetTitleStyle(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +SetTitleStyle(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - char *parm=NULL, *prev = action; + char *parm = NULL, *prev = action; #ifdef USEDECOR - FvwmDecor *fl = cur_decor ? cur_decor : &Scr.DefaultDecor; + FvwmDecor *fl = cur_decor ? cur_decor : &Scr.DefaultDecor; #else - FvwmDecor *fl = &Scr.DefaultDecor; + FvwmDecor *fl = &Scr.DefaultDecor; #endif - action = GetNextToken(action,&parm); - while(parm) - { - if (StrEquals(parm,"centered")) - { - fl->titlebar.flags &= ~HOffCenter; - } - else if (StrEquals(parm,"leftjustified")) - { - fl->titlebar.flags |= HOffCenter; - fl->titlebar.flags &= ~HRight; - } - else if (StrEquals(parm,"rightjustified")) - { - fl->titlebar.flags |= HOffCenter | HRight; - } + action = GetNextToken(action, &parm); + while (parm) { + if (StrEquals(parm, "centered")) { + fl->titlebar.flags &= ~HOffCenter; + } else if (StrEquals(parm, "leftjustified")) { + fl->titlebar.flags |= HOffCenter; + fl->titlebar.flags &= ~HRight; + } else if (StrEquals(parm, "rightjustified")) { + fl->titlebar.flags |= HOffCenter | HRight; + } #ifdef EXTENDED_TITLESTYLE - else if (StrEquals(parm,"height")) - { - int height, next; - if ( sscanf(action, "%d%n", &height, &next) > 0 - && height > 4 - && height <= 256) - { - int x,y,w,h,extra_height; - FvwmWindow *tmp = Scr.FvwmRoot.next, *hi = Scr.Hilite; - - extra_height = fl->TitleHeight; - fl->TitleHeight = height; - extra_height -= fl->TitleHeight; - - fl->WindowFont.y = fl->WindowFont.font->ascent - + (height - (fl->WindowFont.font->ascent - + fl->WindowFont.font->descent + 3)) / 2; - if (fl->WindowFont.y < fl->WindowFont.font->ascent) - fl->WindowFont.y = fl->WindowFont.font->ascent; - - tmp = Scr.FvwmRoot.next; - hi = Scr.Hilite; - while(tmp != NULL) - { - if (!(tmp->flags & TITLE) + else if (StrEquals(parm, "height")) { + int height, next; + if (sscanf(action, "%d%n", &height, &next) > 0 && + height > 4 && height <= 256) { + int x, y, w, h, extra_height; + FvwmWindow *tmp = Scr.FvwmRoot.next, + *hi = Scr.Hilite; + + extra_height = fl->TitleHeight; + fl->TitleHeight = height; + extra_height -= fl->TitleHeight; + + fl->WindowFont.y = + fl->WindowFont.font->ascent + + (height - + (fl->WindowFont.font->ascent + + fl->WindowFont.font->descent + 3)) / + 2; + if (fl->WindowFont.y < + fl->WindowFont.font->ascent) + fl->WindowFont.y = + fl->WindowFont.font->ascent; + + tmp = Scr.FvwmRoot.next; + hi = Scr.Hilite; + while (tmp != NULL) { + if (!(tmp->flags & TITLE) #ifdef USEDECOR - || (tmp->fl != fl) + || (tmp->fl != fl) #endif - ) { - tmp = tmp->next; - continue; + ) { + tmp = tmp->next; + continue; + } + x = tmp->frame_x; + y = tmp->frame_y; + w = tmp->frame_width; + h = tmp->frame_height - extra_height; + tmp->frame_x = 0; + tmp->frame_y = 0; + tmp->frame_height = 0; + tmp->frame_width = 0; + SetupFrame(tmp, x, y, w, h, True); + SetTitleBar(tmp, True, True); + SetTitleBar(tmp, False, True); + tmp = tmp->next; + } + SetTitleBar(hi, True, True); + } else + fvwm_msg(ERR, "SetTitleStyle", + "bad height argument (height must be from " + "5 to 256)"); + action += next; + } else { + if (!(action = ReadTitleButton( + prev, &fl->titlebar, False, -1))) { + free(parm); + break; + } + } +#else /* ! EXTENDED_TITLESTYLE */ + else if (strcmp(parm, "--") == 0) { + if (!(action = ReadTitleButton( + prev, &fl->titlebar, False, -1))) { + free(parm); + break; + } } - x = tmp->frame_x; - y = tmp->frame_y; - w = tmp->frame_width; - h = tmp->frame_height-extra_height; - tmp->frame_x = 0; - tmp->frame_y = 0; - tmp->frame_height = 0; - tmp->frame_width = 0; - SetupFrame(tmp,x,y,w,h,True); - SetTitleBar(tmp,True,True); - SetTitleBar(tmp,False,True); - tmp = tmp->next; - } - SetTitleBar(hi,True,True); - } - else - fvwm_msg(ERR,"SetTitleStyle", - "bad height argument (height must be from 5 to 256)"); - action += next; - } - else - { - if (!(action = ReadTitleButton(prev, &fl->titlebar, False, -1))) { - free(parm); - break; - } - } -#else /* ! EXTENDED_TITLESTYLE */ - else if (strcmp(parm,"--")==0) { - if (!(action = ReadTitleButton(prev, &fl->titlebar, False, -1))) { - free(parm); - break; - } - } #endif /* EXTENDED_TITLESTYLE */ - free(parm); - prev = action; - action = GetNextToken(action,&parm); - } + free(parm); + prev = action; + action = GetNextToken(action, &parm); + } } /* SetTitleStyle */ -static void ApplyDefaultFontAndColors(void) +static void +ApplyDefaultFontAndColors(void) { - XGCValues gcv; - unsigned long gcm; - MenuStyle *ms; - int wid; - int hei; - - Scr.StdFont.y = Scr.StdFont.font->ascent; - Scr.StdFont.height = Scr.StdFont.font->ascent + Scr.StdFont.font->descent; - - /* make GC's */ - gcm = GCFunction|GCPlaneMask|GCFont|GCGraphicsExposures| - GCLineWidth|GCForeground|GCBackground; - gcv.fill_style = FillSolid; - gcv.font = Scr.StdFont.font->fid; - gcv.plane_mask = AllPlanes; - gcv.function = GXcopy; - gcv.graphics_exposures = False; - gcv.line_width = 0; - - gcv.foreground = Scr.StdColors.fore; - gcv.background = Scr.StdColors.back; - if(Scr.StdGC != NULL) - XFreeGC(dpy, Scr.StdGC); - Scr.StdGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); - - gcv.foreground = Scr.StdRelief.fore; - gcv.background = Scr.StdRelief.back; - if(Scr.StdReliefGC != NULL) - XFreeGC(dpy, Scr.StdReliefGC); - Scr.StdReliefGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); - - gcv.foreground = Scr.StdRelief.back; - gcv.background = Scr.StdRelief.fore; - if(Scr.StdShadowGC != NULL) - XFreeGC(dpy, Scr.StdShadowGC); - Scr.StdShadowGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); - - /* update the geometry window for move/resize */ - if(Scr.SizeWindow != None) - { - XSetWindowBackground(dpy, Scr.SizeWindow, Scr.StdColors.back); - Scr.SizeStringWidth = XTextWidth(Scr.StdFont.font, " +8888 x +8888 ", 15); - wid = Scr.SizeStringWidth + 2 * SIZE_HINDENT; - hei = Scr.StdFont.height + 2 * SIZE_VINDENT; - if(Scr.gs.EmulateMWM) - { - XMoveResizeWindow(dpy,Scr.SizeWindow, - (Scr.MyDisplayWidth - wid)/2, - (Scr.MyDisplayHeight - hei)/2, wid, hei); - } - else - { - XMoveResizeWindow(dpy,Scr.SizeWindow,0, 0, wid,hei); - } - } - - if (Scr.hasIconFont == False) - { - Scr.IconFont.font = Scr.StdFont.font; - ApplyIconFont(); - } - - if (Scr.hasWindowFont == False) - { - Scr.DefaultDecor.WindowFont.font = Scr.StdFont.font; - ApplyWindowFont(&Scr.DefaultDecor); - } - - for (ms = Scr.menus.DefaultStyle; ms != NULL; ms = ms->next) - { - if (ms->look.pStdFont == &Scr.StdFont) - ms->look.EntryHeight = Scr.StdFont.height + HEIGHT_EXTRA; - UpdateMenuStyle(ms); - } - MakeMenus(); + XGCValues gcv; + unsigned long gcm; + MenuStyle *ms; + int wid; + int hei; + + Scr.StdFont.y = Scr.StdFont.font->ascent; + Scr.StdFont.height = + Scr.StdFont.font->ascent + Scr.StdFont.font->descent; + + /* make GC's */ + gcm = GCFunction | GCPlaneMask | GCFont | GCGraphicsExposures | + GCLineWidth | GCForeground | GCBackground; + gcv.fill_style = FillSolid; + gcv.font = Scr.StdFont.font->fid; + gcv.plane_mask = AllPlanes; + gcv.function = GXcopy; + gcv.graphics_exposures = False; + gcv.line_width = 0; + + gcv.foreground = Scr.StdColors.fore; + gcv.background = Scr.StdColors.back; + if (Scr.StdGC != NULL) + XFreeGC(dpy, Scr.StdGC); + Scr.StdGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); + + gcv.foreground = Scr.StdRelief.fore; + gcv.background = Scr.StdRelief.back; + if (Scr.StdReliefGC != NULL) + XFreeGC(dpy, Scr.StdReliefGC); + Scr.StdReliefGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); + + gcv.foreground = Scr.StdRelief.back; + gcv.background = Scr.StdRelief.fore; + if (Scr.StdShadowGC != NULL) + XFreeGC(dpy, Scr.StdShadowGC); + Scr.StdShadowGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); + + /* update the geometry window for move/resize */ + if (Scr.SizeWindow != None) { + XSetWindowBackground(dpy, Scr.SizeWindow, Scr.StdColors.back); + Scr.SizeStringWidth = + XTextWidth(Scr.StdFont.font, " +8888 x +8888 ", 15); + wid = Scr.SizeStringWidth + 2 * SIZE_HINDENT; + hei = Scr.StdFont.height + 2 * SIZE_VINDENT; + if (Scr.gs.EmulateMWM) { + XMoveResizeWindow(dpy, Scr.SizeWindow, + (Scr.MyDisplayWidth - wid) / 2, + (Scr.MyDisplayHeight - hei) / 2, wid, hei); + } else { + XMoveResizeWindow(dpy, Scr.SizeWindow, 0, 0, wid, hei); + } + } + + if (Scr.hasIconFont == False) { + Scr.IconFont.font = Scr.StdFont.font; + ApplyIconFont(); + } + + if (Scr.hasWindowFont == False) { + Scr.DefaultDecor.WindowFont.font = Scr.StdFont.font; + ApplyWindowFont(&Scr.DefaultDecor); + } + + for (ms = Scr.menus.DefaultStyle; ms != NULL; ms = ms->next) { + if (ms->look.pStdFont == &Scr.StdFont) + ms->look.EntryHeight = + Scr.StdFont.height + HEIGHT_EXTRA; + UpdateMenuStyle(ms); + } + MakeMenus(); } -void SetDefaultColors(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +SetDefaultColors(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - char *fore = NULL; - char *back = NULL; - - action = GetNextToken(action, &fore); - action = GetNextToken(action, &back); - - if (!back) - back = strdup("grey"); - if (!fore) - back = strdup("black"); - - if (!StrEquals(fore, "-")) - { - FreeColors(&Scr.StdColors.fore, 1); - Scr.StdColors.fore = GetColor(fore); - } - if (!StrEquals(back, "-")) - { - FreeColors(&Scr.StdColors.back, 1); - FreeColors(&Scr.StdRelief.back, 1); - FreeColors(&Scr.StdRelief.fore, 1); - Scr.StdColors.back = GetColor(back); - Scr.StdRelief.fore = GetHilite(Scr.StdColors.back); - Scr.StdRelief.back = GetShadow(Scr.StdColors.back); - } - free(fore); - free(back); - - ApplyDefaultFontAndColors(); + char *fore = NULL; + char *back = NULL; + + action = GetNextToken(action, &fore); + action = GetNextToken(action, &back); + + if (!back) + back = strdup("grey"); + if (!fore) + back = strdup("black"); + + if (!StrEquals(fore, "-")) { + FreeColors(&Scr.StdColors.fore, 1); + Scr.StdColors.fore = GetColor(fore); + } + if (!StrEquals(back, "-")) { + FreeColors(&Scr.StdColors.back, 1); + FreeColors(&Scr.StdRelief.back, 1); + FreeColors(&Scr.StdRelief.fore, 1); + Scr.StdColors.back = GetColor(back); + Scr.StdRelief.fore = GetHilite(Scr.StdColors.back); + Scr.StdRelief.back = GetShadow(Scr.StdColors.back); + } + free(fore); + free(back); + + ApplyDefaultFontAndColors(); } -void LoadDefaultFont(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +LoadDefaultFont(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - char *font; - XFontStruct *xfs = NULL; - - action = GetNextToken(action,&font); - if (!font) - { - /* Try 'fixed' */ - font = strdup(""); - } - - if ((xfs = GetFontOrFixed(dpy, font)) == NULL) - { - fvwm_msg(ERR,"SetDefaultFont","Couldn't load font '%s' or 'fixed'\n", - font); - free(font); - if (Scr.StdFont.font == NULL) - exit(1); - else - return; - } - free(font); - if (Scr.StdFont.font != NULL) - XFreeFont(dpy, Scr.StdFont.font); - Scr.StdFont.font = xfs; - - ApplyDefaultFontAndColors(); + char *font; + XFontStruct *xfs = NULL; + + action = GetNextToken(action, &font); + if (!font) { + /* Try 'fixed' */ + font = strdup(""); + } + + if ((xfs = GetFontOrFixed(dpy, font)) == NULL) { + fvwm_msg(ERR, "SetDefaultFont", + "Couldn't load font '%s' or 'fixed'\n", font); + free(font); + if (Scr.StdFont.font == NULL) + exit(1); + else + return; + } + free(font); + if (Scr.StdFont.font != NULL) + XFreeFont(dpy, Scr.StdFont.font); + Scr.StdFont.font = xfs; + + ApplyDefaultFontAndColors(); } -void ApplyIconFont(void) +void +ApplyIconFont(void) { - FvwmWindow *tmp; - - Scr.IconFont.height = Scr.IconFont.font->ascent+Scr.IconFont.font->descent; - Scr.IconFont.y = Scr.IconFont.font->ascent; - - tmp = Scr.FvwmRoot.next; - while(tmp != NULL) - { - RedoIconName(tmp); - - if(tmp->flags& ICONIFIED) - { - DrawIconWindow(tmp); - } - tmp = tmp->next; - } + FvwmWindow *tmp; + + Scr.IconFont.height = + Scr.IconFont.font->ascent + Scr.IconFont.font->descent; + Scr.IconFont.y = Scr.IconFont.font->ascent; + + tmp = Scr.FvwmRoot.next; + while (tmp != NULL) { + RedoIconName(tmp); + + if (tmp->flags & ICONIFIED) { + DrawIconWindow(tmp); + } + tmp = tmp->next; + } } -void LoadIconFont(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +LoadIconFont(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - char *font; - XFontStruct *newfont; - - action = GetNextToken(action,&font); - if (!font) - { - if (Scr.hasIconFont == True) - { - /* reset to default font */ - XFreeFont(dpy, Scr.IconFont.font); - Scr.hasIconFont = False; - } - Scr.IconFont.font = Scr.StdFont.font; - ApplyIconFont(); - return; - } - - if ((newfont = GetFontOrFixed(dpy, font))!=NULL) - { - if (Scr.IconFont.font != NULL && Scr.hasIconFont == True) - XFreeFont(dpy, Scr.IconFont.font); - Scr.hasIconFont = True; - Scr.IconFont.font = newfont; - ApplyIconFont(); - } - else - { - fvwm_msg(ERR,"LoadIconFont","Couldn't load font '%s' or 'fixed'\n", font); - } - free(font); + char *font; + XFontStruct *newfont; + + action = GetNextToken(action, &font); + if (!font) { + if (Scr.hasIconFont == True) { + /* reset to default font */ + XFreeFont(dpy, Scr.IconFont.font); + Scr.hasIconFont = False; + } + Scr.IconFont.font = Scr.StdFont.font; + ApplyIconFont(); + return; + } + + if ((newfont = GetFontOrFixed(dpy, font)) != NULL) { + if (Scr.IconFont.font != NULL && Scr.hasIconFont == True) + XFreeFont(dpy, Scr.IconFont.font); + Scr.hasIconFont = True; + Scr.IconFont.font = newfont; + ApplyIconFont(); + } else { + fvwm_msg(ERR, "LoadIconFont", + "Couldn't load font '%s' or 'fixed'\n", font); + } + free(font); } -void ApplyWindowFont(FvwmDecor *fl) +void +ApplyWindowFont(FvwmDecor *fl) { - FvwmWindow *tmp,*hi; - int x,y,w,h,extra_height; - - fl->WindowFont.height = - fl->WindowFont.font->ascent+fl->WindowFont.font->descent; - fl->WindowFont.y = fl->WindowFont.font->ascent; - extra_height = fl->TitleHeight; - fl->TitleHeight=fl->WindowFont.font->ascent+fl->WindowFont.font->descent+3; - extra_height -= fl->TitleHeight; - - tmp = Scr.FvwmRoot.next; - hi = Scr.Hilite; - while(tmp != NULL) - { - if (!(tmp->flags & TITLE) + FvwmWindow *tmp, *hi; + int x, y, w, h, extra_height; + + fl->WindowFont.height = + fl->WindowFont.font->ascent + fl->WindowFont.font->descent; + fl->WindowFont.y = fl->WindowFont.font->ascent; + extra_height = fl->TitleHeight; + fl->TitleHeight = + fl->WindowFont.font->ascent + fl->WindowFont.font->descent + 3; + extra_height -= fl->TitleHeight; + + tmp = Scr.FvwmRoot.next; + hi = Scr.Hilite; + while (tmp != NULL) { + if (!(tmp->flags & TITLE) #ifdef USEDECOR - || (tmp->fl != fl) + || (tmp->fl != fl) #endif - ) - { - tmp = tmp->next; - continue; - } - x = tmp->frame_x; - y = tmp->frame_y; - w = tmp->frame_width; - h = tmp->frame_height-extra_height; - tmp->frame_x = 0; - tmp->frame_y = 0; - tmp->frame_height = 0; - tmp->frame_width = 0; - SetupFrame(tmp,x,y,w,h,True); - SetTitleBar(tmp,True,True); - SetTitleBar(tmp,False,True); - tmp = tmp->next; - } - SetTitleBar(hi,True,True); + ) { + tmp = tmp->next; + continue; + } + x = tmp->frame_x; + y = tmp->frame_y; + w = tmp->frame_width; + h = tmp->frame_height - extra_height; + tmp->frame_x = 0; + tmp->frame_y = 0; + tmp->frame_height = 0; + tmp->frame_width = 0; + SetupFrame(tmp, x, y, w, h, True); + SetTitleBar(tmp, True, True); + SetTitleBar(tmp, False, True); + tmp = tmp->next; + } + SetTitleBar(hi, True, True); } -void LoadWindowFont(XEvent *eventp,Window win,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +LoadWindowFont(XEvent *eventp, Window win, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - char *font; - XFontStruct *newfont; + char *font; + XFontStruct *newfont; #ifdef USEDECOR - FvwmDecor *fl = cur_decor ? cur_decor : &Scr.DefaultDecor; + FvwmDecor *fl = cur_decor ? cur_decor : &Scr.DefaultDecor; #else - FvwmDecor *fl = &Scr.DefaultDecor; + FvwmDecor *fl = &Scr.DefaultDecor; #endif - action = GetNextToken(action,&font); - if (!font) - { - /* reset to default font */ - if (Scr.hasWindowFont) - { - XFreeFont(dpy, Scr.DefaultDecor.WindowFont.font); - Scr.hasWindowFont = False; - fl->WindowFont.font = Scr.StdFont.font; - ApplyWindowFont(&Scr.DefaultDecor); - } - return; - } - - if ((newfont = GetFontOrFixed(dpy, font))!=NULL) - { - if (fl->WindowFont.font != NULL && - (fl != &Scr.DefaultDecor || Scr.hasWindowFont == True)) - XFreeFont(dpy, fl->WindowFont.font); - if (fl == &Scr.DefaultDecor) - Scr.hasWindowFont = True; - fl->WindowFont.font = newfont; - ApplyWindowFont(fl); - } - else - { - fvwm_msg(ERR,"LoadWindowFont","Couldn't load font '%s' or 'fixed'\n",font); - } - - free(font); + action = GetNextToken(action, &font); + if (!font) { + /* reset to default font */ + if (Scr.hasWindowFont) { + XFreeFont(dpy, Scr.DefaultDecor.WindowFont.font); + Scr.hasWindowFont = False; + fl->WindowFont.font = Scr.StdFont.font; + ApplyWindowFont(&Scr.DefaultDecor); + } + return; + } + + if ((newfont = GetFontOrFixed(dpy, font)) != NULL) { + if (fl->WindowFont.font != NULL && + (fl != &Scr.DefaultDecor || Scr.hasWindowFont == True)) + XFreeFont(dpy, fl->WindowFont.font); + if (fl == &Scr.DefaultDecor) + Scr.hasWindowFont = True; + fl->WindowFont.font = newfont; + ApplyWindowFont(fl); + } else { + fvwm_msg(ERR, "LoadWindowFont", + "Couldn't load font '%s' or 'fixed'\n", font); + } + + free(font); } -void FreeButtonFace(Display *dpy, ButtonFace *bf) +void +FreeButtonFace(Display *dpy, ButtonFace *bf) { - switch (bf->style) - { + switch (bf->style) { #ifdef GRADIENT_BUTTONS - case HGradButton: - case VGradButton: - /* - should we check visual is not TrueColor before doing this? - - XFreeColors(dpy, Scr.FvwmRoot.attr.colormap, - bf->u.grad.pixels, bf->u.grad.npixels, - AllPlanes); */ - free(bf->u.grad.pixels); - bf->u.grad.pixels = NULL; - break; + case HGradButton: + case VGradButton: + /* - should we check visual is not TrueColor before doing this? + + XFreeColors(dpy, Scr.FvwmRoot.attr.colormap, + bf->u.grad.pixels, bf->u.grad.npixels, + AllPlanes); */ + free(bf->u.grad.pixels); + bf->u.grad.pixels = NULL; + break; #endif #ifdef PIXMAP_BUTTONS - case PixmapButton: - case TiledPixmapButton: - if (bf->u.p) - DestroyPicture(dpy, bf->u.p); - bf->u.p = NULL; - break; + case PixmapButton: + case TiledPixmapButton: + if (bf->u.p) + DestroyPicture(dpy, bf->u.p); + bf->u.p = NULL; + break; #endif - default: - break; - } + default: + break; + } #ifdef MULTISTYLE - /* delete any compound styles */ - if (bf->next) { - FreeButtonFace(dpy, bf->next); - free(bf->next); - } - bf->next = NULL; + /* delete any compound styles */ + if (bf->next) { + FreeButtonFace(dpy, bf->next); + free(bf->next); + } + bf->next = NULL; #endif - bf->style = SimpleButton; + bf->style = SimpleButton; } /***************************************************************************** @@ -2888,517 +2811,509 @@ void FreeButtonFace(Display *dpy, ButtonFace *bf) * Reads a button face line into a structure (veliaa@rpi.edu) * ****************************************************************************/ -Boolean ReadButtonFace(char *s, ButtonFace *bf, int button, int verbose) +Boolean +ReadButtonFace(char *s, ButtonFace *bf, int button, int verbose) { - int offset; - char style[256], *file; - char *action = s; - - if (sscanf(s, "%s%n", style, &offset) < 1) { - if (verbose) - fvwm_msg(ERR, "ReadButtonFace", "error in face `%s'", s); - return False; - } - - if (strncasecmp(style, "--", 2) != 0) { - s += offset; - - FreeButtonFace(dpy, bf); - - /* determine button style */ - if (strncasecmp(style,"Simple",6)==0) - { - bf->style = SimpleButton; - } - else if (strncasecmp(style,"Default",7)==0) { - int b = -1, n = sscanf(s, "%d%n", &b, &offset); - - if (n < 1) { - if (button == -1) { - if(verbose)fvwm_msg(ERR,"ReadButtonFace", - "need default button number to load"); - return False; - } - b = button; - } - s += offset; - if ((b > 0) && (b <= 10)) - LoadDefaultButton(bf, b); - else { - if(verbose)fvwm_msg(ERR,"ReadButtonFace", - "button number out of range: %d", b); + int offset; + char style[256], *file; + char *action = s; + + if (sscanf(s, "%s%n", style, &offset) < 1) { + if (verbose) + fvwm_msg( + ERR, "ReadButtonFace", "error in face `%s'", s); return False; - } } -#ifdef VECTOR_BUTTONS - else if (strncasecmp(style,"Vector",6)==0 || - (strlen(style)<=2 && isdigit(*style))) - { - /* normal coordinate list button style */ - int i, num_coords, num; - struct vector_coords *vc = &bf->vector; - /* get number of points */ - if (strncasecmp(style,"Vector",6)==0) { - num = sscanf(s,"%d%n",&num_coords,&offset); + if (strncasecmp(style, "--", 2) != 0) { s += offset; - } else - num = sscanf(style,"%d",&num_coords); - if((num != 1)||(num_coords>20)||(num_coords<2)) - { - if(verbose)fvwm_msg(ERR,"ReadButtonFace", - "Bad button style (2) in line: %s",action); - return False; - } - - vc->num = num_coords; + FreeButtonFace(dpy, bf); + + /* determine button style */ + if (strncasecmp(style, "Simple", 6) == 0) { + bf->style = SimpleButton; + } else if (strncasecmp(style, "Default", 7) == 0) { + int b = -1, n = sscanf(s, "%d%n", &b, &offset); + + if (n < 1) { + if (button == -1) { + if (verbose) + fvwm_msg(ERR, "ReadButtonFace", + "need default button " + "number to load"); + return False; + } + b = button; + } + s += offset; + if ((b > 0) && (b <= 10)) + LoadDefaultButton(bf, b); + else { + if (verbose) + fvwm_msg(ERR, "ReadButtonFace", + "button number out of range: %d", + b); + return False; + } + } +#ifdef VECTOR_BUTTONS + else if (strncasecmp(style, "Vector", 6) == 0 || + (strlen(style) <= 2 && isdigit(*style))) { + /* normal coordinate list button style */ + int i, num_coords, num; + struct vector_coords *vc = &bf->vector; + + /* get number of points */ + if (strncasecmp(style, "Vector", 6) == 0) { + num = sscanf(s, "%d%n", &num_coords, &offset); + s += offset; + } else + num = sscanf(style, "%d", &num_coords); + + if ((num != 1) || (num_coords > 20) || + (num_coords < 2)) { + if (verbose) + fvwm_msg(ERR, "ReadButtonFace", + "Bad button style (2) in line: %s", + action); + return False; + } - /* get the points */ - for(i = 0; i < vc->num; ++i) - { - /* X x Y @ line_style */ - num = sscanf(s,"%dx%d@%d%n",&vc->x[i],&vc->y[i], - &vc->line_style[i], &offset); - if(num != 3) - { - if(verbose)fvwm_msg(ERR,"ReadButtonFace", - "Bad button style (3) in line %s", - action); - return False; + vc->num = num_coords; + + /* get the points */ + for (i = 0; i < vc->num; ++i) { + /* X x Y @ line_style */ + num = sscanf(s, "%dx%d@%d%n", &vc->x[i], + &vc->y[i], &vc->line_style[i], &offset); + if (num != 3) { + if (verbose) + fvwm_msg(ERR, "ReadButtonFace", + "Bad button style (3) in " + "line %s", + action); + return False; + } + s += offset; + } + bf->style = VectorButton; } - s += offset; - } - bf->style = VectorButton; - } #endif - else if (strncasecmp(style,"Solid",5)==0) - { - s = GetNextToken(s, &file); - if (file) { - bf->style = SolidButton; - bf->u.back = GetColor(file); - free(file); - } else { - if(verbose) - fvwm_msg(ERR,"ReadButtonFace", - "no color given for Solid face type: %s", action); - return False; - } - } -#ifdef GRADIENT_BUTTONS - else if (strncasecmp(style,"HGradient",9)==0 - || strncasecmp(style,"VGradient",9)==0) - { - char *item, **s_colors; - int npixels, nsegs, i, sum, *perc; - Pixel *pixels; - - if (!(s = GetNextToken(s, &item)) || (item == NULL)) { - if(verbose) - fvwm_msg(ERR,"ReadButtonFace", - "expected number of colors to allocate in gradient"); - if (item) - free(item); - return False; - } - npixels = atoi(item); - free(item); - - if (!(s = GetNextToken(s, &item)) || (item == NULL)) { - if(verbose) - fvwm_msg(ERR,"ReadButtonFace", "incomplete gradient style"); - if (item) - free(item); - return False; - } - - if (!(isdigit(*item))) { - s_colors = (char **)safemalloc(sizeof(char *) * 2); - perc = (int *)safemalloc(sizeof(int)); - nsegs = 1; - s_colors[0] = item; - s = GetNextToken(s, &s_colors[1]); - perc[0] = 100; - } else { - nsegs = atoi(item); - free(item); - if (nsegs < 1) nsegs = 1; - if (nsegs > 128) nsegs = 128; - s_colors = (char **)safemalloc(sizeof(char *) * (nsegs + 1)); - perc = (int *)safemalloc(sizeof(int) * nsegs); - for (i = 0; i <= nsegs; ++i) { - s =GetNextToken(s, &s_colors[i]); - if (i < nsegs) { - s = GetNextToken(s, &item); - if (item) - { - perc[i] = atoi(item); - free(item); - } - else - perc[i] = 0; - } + else if (strncasecmp(style, "Solid", 5) == 0) { + s = GetNextToken(s, &file); + if (file) { + bf->style = SolidButton; + bf->u.back = GetColor(file); + free(file); + } else { + if (verbose) + fvwm_msg(ERR, "ReadButtonFace", + "no color given for Solid face " + "type: %s", + action); + return False; + } } - } - - for (i = 0, sum = 0; i < nsegs; ++i) - sum += perc[i]; - - if (sum != 100) { - if(verbose)fvwm_msg(ERR,"ReadButtonFace", - "multi gradient lengths must sum to 100"); - for (i = 0; i <= nsegs; ++i) - if (s_colors[i]) - free(s_colors[i]); - free(s_colors); - free(perc); - return False; - } +#ifdef GRADIENT_BUTTONS + else if (strncasecmp(style, "HGradient", 9) == 0 || + strncasecmp(style, "VGradient", 9) == 0) { + char *item, **s_colors; + int npixels, nsegs, i, sum, *perc; + Pixel *pixels; + + if (!(s = GetNextToken(s, &item)) || (item == NULL)) { + if (verbose) + fvwm_msg(ERR, "ReadButtonFace", + "expected number of colors to " + "allocate in gradient"); + if (item) + free(item); + return False; + } + npixels = atoi(item); + free(item); + + if (!(s = GetNextToken(s, &item)) || (item == NULL)) { + if (verbose) + fvwm_msg(ERR, "ReadButtonFace", + "incomplete gradient style"); + if (item) + free(item); + return False; + } - if (npixels < 2) npixels = 2; - if (npixels > 128) npixels = 128; + if (!(isdigit(*item))) { + s_colors = + (char **)xmalloc(sizeof(char *) * 2); + perc = (int *)xmalloc(sizeof(int)); + nsegs = 1; + s_colors[0] = item; + s = GetNextToken(s, &s_colors[1]); + perc[0] = 100; + } else { + nsegs = atoi(item); + free(item); + if (nsegs < 1) + nsegs = 1; + if (nsegs > 128) + nsegs = 128; + s_colors = (char **)xmalloc( + sizeof(char *) * (nsegs + 1)); + perc = (int *)xmalloc(sizeof(int) * nsegs); + for (i = 0; i <= nsegs; ++i) { + s = GetNextToken(s, &s_colors[i]); + if (i < nsegs) { + s = GetNextToken(s, &item); + if (item) { + perc[i] = atoi(item); + free(item); + } else + perc[i] = 0; + } + } + } - pixels = AllocNonlinearGradient(s_colors, perc, nsegs, npixels); - for (i = 0; i <= nsegs; ++i) - if (s_colors[i]) - free(s_colors[i]); - free(s_colors); - free(perc); + for (i = 0, sum = 0; i < nsegs; ++i) + sum += perc[i]; + + if (sum != 100) { + if (verbose) + fvwm_msg(ERR, "ReadButtonFace", + "multi gradient lengths must sum " + "to 100"); + for (i = 0; i <= nsegs; ++i) + if (s_colors[i]) + free(s_colors[i]); + free(s_colors); + free(perc); + return False; + } - if (!pixels) { - if(verbose)fvwm_msg(ERR,"ReadButtonFace", - "couldn't create gradient"); - return False; - } + if (npixels < 2) + npixels = 2; + if (npixels > 128) + npixels = 128; + + pixels = AllocNonlinearGradient( + s_colors, perc, nsegs, npixels); + for (i = 0; i <= nsegs; ++i) + if (s_colors[i]) + free(s_colors[i]); + free(s_colors); + free(perc); + + if (!pixels) { + if (verbose) + fvwm_msg(ERR, "ReadButtonFace", + "couldn't create gradient"); + return False; + } - bf->u.grad.pixels = pixels; - bf->u.grad.npixels = npixels; + bf->u.grad.pixels = pixels; + bf->u.grad.npixels = npixels; - if (strncasecmp(style,"H",1)==0) - bf->style = HGradButton; - else - bf->style = VGradButton; - } + if (strncasecmp(style, "H", 1) == 0) + bf->style = HGradButton; + else + bf->style = VGradButton; + } #endif /* GRADIENT_BUTTONS */ #ifdef PIXMAP_BUTTONS - else if (strncasecmp(style,"Pixmap",6)==0 - || strncasecmp(style,"TiledPixmap",11)==0) - { - s = GetNextToken(s, &file); - bf->u.p = CachePicture(dpy, Scr.Root, - IconPath, - PixmapPath, - file,Scr.ColorLimit); - if (bf->u.p == NULL) - { - if (file) - { - if(verbose)fvwm_msg(ERR,"ReadButtonFace", - "couldn't load pixmap %s", file); - free(file); - } - return False; - } - if (file) - { - free(file); - file = NULL; - } + else if (strncasecmp(style, "Pixmap", 6) == 0 || + strncasecmp(style, "TiledPixmap", 11) == 0) { + s = GetNextToken(s, &file); + bf->u.p = CachePicture(dpy, Scr.Root, IconPath, + PixmapPath, file, Scr.ColorLimit); + if (bf->u.p == NULL) { + if (file) { + if (verbose) + fvwm_msg(ERR, "ReadButtonFace", + "couldn't load pixmap %s", + file); + free(file); + } + return False; + } + if (file) { + free(file); + file = NULL; + } - if (strncasecmp(style,"Tiled",5)==0) - bf->style = TiledPixmapButton; - else - bf->style = PixmapButton; - } + if (strncasecmp(style, "Tiled", 5) == 0) + bf->style = TiledPixmapButton; + else + bf->style = PixmapButton; + } #ifdef MINI_ICONS - else if (strncasecmp (style, "MiniIcon", 8) == 0) { - bf->style = MiniIconButton; -#if 0 -/* Have to remove this again. This is all so badly written there is no chance - * to prevent a coredump and a memory leak the same time without a rewrite of - * large parts of the code. */ - if (bf->u.p) - DestroyPicture(dpy, bf->u.p); -#endif - bf->u.p = NULL; /* pixmap read in when the window is created */ - } + else if (strncasecmp(style, "MiniIcon", 8) == 0) { + bf->style = MiniIconButton; + bf->u.p = NULL; /* pixmap read in when the window is + created */ + } #endif #endif /* PIXMAP_BUTTONS */ - else { - if(verbose)fvwm_msg(ERR,"ReadButtonFace", - "unknown style %s: %s", style, action); - return False; - } - } - - /* Process button flags ("--" signals start of flags, - it is also checked for above) */ - s = GetNextToken(s, &file); - if (file && (strcmp(file,"--")==0)) { - char *tok; - s = GetNextToken(s, &tok); - while (tok&&*tok) - { - int set = 1; - - if (*tok == '!') { /* flag negate */ - set = 0; - ++tok; - } - if (StrEquals(tok,"Clear")) { - if (set) - bf->style &= ButtonFaceTypeMask; - else - bf->style |= ~ButtonFaceTypeMask; /* ? */ - } - else if (StrEquals(tok,"Left")) - { - if (set) { - bf->style |= HOffCenter; - bf->style &= ~HRight; - } else - bf->style |= HOffCenter | HRight; - } - else if (StrEquals(tok,"Right")) - { - if (set) - bf->style |= HOffCenter | HRight; else { - bf->style |= HOffCenter; - bf->style &= ~HRight; + if (verbose) + fvwm_msg(ERR, "ReadButtonFace", + "unknown style %s: %s", style, action); + return False; } - } - else if (StrEquals(tok,"Centered")) { - bf->style &= ~HOffCenter; - bf->style &= ~VOffCenter; - } - else if (StrEquals(tok,"Top")) - { - if (set) { - bf->style |= VOffCenter; - bf->style &= ~VBottom; - } else - bf->style |= VOffCenter | VBottom; + } - } - else if (StrEquals(tok,"Bottom")) - { - if (set) - bf->style |= VOffCenter | VBottom; - else { - bf->style |= VOffCenter; - bf->style &= ~VBottom; - } - } - else if (StrEquals(tok,"Flat")) - { - if (set) { - bf->style &= ~SunkButton; - bf->style |= FlatButton; - } else - bf->style &= ~FlatButton; - } - else if (StrEquals(tok,"Sunk")) - { - if (set) { - bf->style &= ~FlatButton; - bf->style |= SunkButton; - } else - bf->style &= ~SunkButton; - } - else if (StrEquals(tok,"Raised")) - { - if (set) { - bf->style &= ~FlatButton; - bf->style &= ~SunkButton; - } else { - bf->style |= SunkButton; - bf->style &= ~FlatButton; - } - } + /* Process button flags ("--" signals start of flags, + it is also checked for above) */ + s = GetNextToken(s, &file); + if (file && (strcmp(file, "--") == 0)) { + char *tok; + s = GetNextToken(s, &tok); + while (tok && *tok) { + int set = 1; + + if (*tok == '!') { /* flag negate */ + set = 0; + ++tok; + } + if (StrEquals(tok, "Clear")) { + if (set) + bf->style &= ButtonFaceTypeMask; + else + bf->style |= + ~ButtonFaceTypeMask; /* ? */ + } else if (StrEquals(tok, "Left")) { + if (set) { + bf->style |= HOffCenter; + bf->style &= ~HRight; + } else + bf->style |= HOffCenter | HRight; + } else if (StrEquals(tok, "Right")) { + if (set) + bf->style |= HOffCenter | HRight; + else { + bf->style |= HOffCenter; + bf->style &= ~HRight; + } + } else if (StrEquals(tok, "Centered")) { + bf->style &= ~HOffCenter; + bf->style &= ~VOffCenter; + } else if (StrEquals(tok, "Top")) { + if (set) { + bf->style |= VOffCenter; + bf->style &= ~VBottom; + } else + bf->style |= VOffCenter | VBottom; + } else if (StrEquals(tok, "Bottom")) { + if (set) + bf->style |= VOffCenter | VBottom; + else { + bf->style |= VOffCenter; + bf->style &= ~VBottom; + } + } else if (StrEquals(tok, "Flat")) { + if (set) { + bf->style &= ~SunkButton; + bf->style |= FlatButton; + } else + bf->style &= ~FlatButton; + } else if (StrEquals(tok, "Sunk")) { + if (set) { + bf->style &= ~FlatButton; + bf->style |= SunkButton; + } else + bf->style &= ~SunkButton; + } else if (StrEquals(tok, "Raised")) { + if (set) { + bf->style &= ~FlatButton; + bf->style &= ~SunkButton; + } else { + bf->style |= SunkButton; + bf->style &= ~FlatButton; + } + } #ifdef EXTENDED_TITLESTYLE - else if (StrEquals(tok,"UseTitleStyle")) - { - if (set) { - bf->style |= UseTitleStyle; + else if (StrEquals(tok, "UseTitleStyle")) { + if (set) { + bf->style |= UseTitleStyle; #ifdef BORDERSTYLE - bf->style &= ~UseBorderStyle; + bf->style &= ~UseBorderStyle; #endif - } else - bf->style &= ~UseTitleStyle; - } + } else + bf->style &= ~UseTitleStyle; + } #endif #ifdef BORDERSTYLE - else if (StrEquals(tok,"HiddenHandles")) - { - if (set) - bf->style |= HiddenHandles; - else - bf->style &= ~HiddenHandles; - } - else if (StrEquals(tok,"NoInset")) - { - if (set) - bf->style |= NoInset; - else - bf->style &= ~NoInset; - } - else if (StrEquals(tok,"UseBorderStyle")) - { - if (set) { - bf->style |= UseBorderStyle; + else if (StrEquals(tok, "HiddenHandles")) { + if (set) + bf->style |= HiddenHandles; + else + bf->style &= ~HiddenHandles; + } else if (StrEquals(tok, "NoInset")) { + if (set) + bf->style |= NoInset; + else + bf->style &= ~NoInset; + } else if (StrEquals(tok, "UseBorderStyle")) { + if (set) { + bf->style |= UseBorderStyle; #ifdef EXTENDED_TITLESTYLE - bf->style &= ~UseTitleStyle; + bf->style &= ~UseTitleStyle; #endif - } else - bf->style &= ~UseBorderStyle; - } + } else + bf->style &= ~UseBorderStyle; + } #endif - else - if(verbose) - fvwm_msg(ERR,"ReadButtonFace", - "unknown button face flag %s -- line: %s", - tok, action); - if (set) - free(tok); - else - free(tok - 1); - s = GetNextToken(s, &tok); - } - } - if (file) - free(file); - return True; + else if (verbose) + fvwm_msg(ERR, "ReadButtonFace", + "unknown button face flag %s -- line: %s", + tok, action); + if (set) + free(tok); + else + free(tok - 1); + s = GetNextToken(s, &tok); + } + } + if (file) + free(file); + return True; } - /***************************************************************************** * * Reads a title button description (veliaa@rpi.edu) * ****************************************************************************/ -char *ReadTitleButton(char *s, TitleButton *tb, Boolean append, int button) +char * +ReadTitleButton(char *s, TitleButton *tb, Boolean append, int button) { - char *end = NULL, *spec; - ButtonFace tmpbf; - enum ButtonState bs = MaxButtonState; - int i = 0, all = 0, pstyle = 0; - - while(isspace(*s))++s; - for (; i < MaxButtonState; ++i) - if (strncasecmp(button_states[i],s, - strlen(button_states[i]))==0) { - bs = i; - break; - } - if (bs != MaxButtonState) - s += strlen(button_states[bs]); - else - all = 1; - while(isspace(*s))++s; - if ('(' == *s) { - int len; - pstyle = 1; - if (!(end = strchr(++s, ')'))) { - fvwm_msg(ERR,"ReadTitleButton", - "missing parenthesis: %s", s); - return NULL; - } - len = end - s + 1; - spec = safemalloc(len); - strncpy(spec, s, len - 1); - spec[len - 1] = 0; - } else - spec = s; - - while(isspace(*spec))++spec; - /* setup temporary in case button read fails */ - tmpbf.style = SimpleButton; + char *end = NULL, *spec; + ButtonFace tmpbf; + enum ButtonState bs = MaxButtonState; + int i = 0, all = 0, pstyle = 0; + + while (isspace(*s)) + ++s; + for (; i < MaxButtonState; ++i) + if (strncasecmp( + button_states[i], s, strlen(button_states[i])) == 0) { + bs = i; + break; + } + if (bs != MaxButtonState) + s += strlen(button_states[bs]); + else + all = 1; + while (isspace(*s)) + ++s; + if ('(' == *s) { + int len; + pstyle = 1; + if (!(end = strchr(++s, ')'))) { + fvwm_msg(ERR, "ReadTitleButton", + "missing parenthesis: %s", s); + return NULL; + } + len = end - s + 1; + spec = xmalloc(len); + strncpy(spec, s, len - 1); + spec[len - 1] = 0; + } else + spec = s; + + while (isspace(*spec)) + ++spec; + /* setup temporary in case button read fails */ + tmpbf.style = SimpleButton; #ifdef MULTISTYLE - tmpbf.next = NULL; + tmpbf.next = NULL; #endif #ifdef MINI_ICONS - tmpbf.u.p = NULL; + tmpbf.u.p = NULL; #endif - if (strncmp(spec, "--",2)==0) { - /* only change flags */ - if (ReadButtonFace(spec, &tb->state[all ? 0 : bs],button,True) && all) { - for (i = 0; i < MaxButtonState; ++i) - ReadButtonFace(spec, &tb->state[i],-1,False); - } - } - else if (ReadButtonFace(spec, &tmpbf,button,True)) { - int b = all ? 0 : bs; -#ifdef MULTISTYLE - if (append) { - ButtonFace *tail = &tb->state[b]; - while (tail->next) tail = tail->next; - tail->next = (ButtonFace *)safemalloc(sizeof(ButtonFace)); - *tail->next = tmpbf; - if (all) - for (i = 1; i < MaxButtonState; ++i) { - tail = &tb->state[i]; - while (tail->next) tail = tail->next; - tail->next = (ButtonFace *)safemalloc(sizeof(ButtonFace)); - tail->next->style = SimpleButton; - tail->next->next = NULL; - ReadButtonFace(spec, tail->next, button, False); + if (strncmp(spec, "--", 2) == 0) { + /* only change flags */ + if (ReadButtonFace( + spec, &tb->state[all ? 0 : bs], button, True) && + all) { + for (i = 0; i < MaxButtonState; ++i) + ReadButtonFace(spec, &tb->state[i], -1, False); } - } - else { + } else if (ReadButtonFace(spec, &tmpbf, button, True)) { + int b = all ? 0 : bs; +#ifdef MULTISTYLE + if (append) { + ButtonFace *tail = &tb->state[b]; + while (tail->next) + tail = tail->next; + tail->next = + (ButtonFace *)xmalloc(sizeof(ButtonFace)); + *tail->next = tmpbf; + if (all) + for (i = 1; i < MaxButtonState; ++i) { + tail = &tb->state[i]; + while (tail->next) + tail = tail->next; + tail->next = (ButtonFace *)xmalloc( + sizeof(ButtonFace)); + tail->next->style = SimpleButton; + tail->next->next = NULL; + ReadButtonFace( + spec, tail->next, button, False); + } + } else { #endif - FreeButtonFace(dpy, &tb->state[b]); - tb->state[b] = tmpbf; - if (all) - for (i = 1; i < MaxButtonState; ++i) - ReadButtonFace(spec, &tb->state[i],button,False); + FreeButtonFace(dpy, &tb->state[b]); + tb->state[b] = tmpbf; + if (all) + for (i = 1; i < MaxButtonState; ++i) + ReadButtonFace( + spec, &tb->state[i], button, False); #ifdef MULTISTYLE - } + } #endif - - } - if (pstyle) { - free(spec); - ++end; - while(isspace(*end))++end; - } - return end; + } + if (pstyle) { + free(spec); + ++end; + while (isspace(*end)) + ++end; + } + return end; } -static void FreeMenuFace(Display *dpy, MenuFace *mf) +static void +FreeMenuFace(Display *dpy, MenuFace *mf) { - switch (mf->type) - { + switch (mf->type) { #ifdef GRADIENT_BUTTONS - case HGradMenu: - case VGradMenu: - case DGradMenu: - /* - should we check visual is not TrueColor before doing this? - * - * XFreeColors(dpy, Scr.FvwmRoot.attr.colormap, - * ms->u.grad.pixels, ms->u.grad.npixels, - * AllPlanes); */ - free(mf->u.grad.pixels); - mf->u.grad.pixels = NULL; - break; + case HGradMenu: + case VGradMenu: + case DGradMenu: + /* - should we check visual is not TrueColor before doing this? + * + * XFreeColors(dpy, Scr.FvwmRoot.attr.colormap, + * ms->u.grad.pixels, ms->u.grad.npixels, + * AllPlanes); */ + free(mf->u.grad.pixels); + mf->u.grad.pixels = NULL; + break; #endif #ifdef PIXMAP_BUTTONS - case PixmapMenu: - case TiledPixmapMenu: - if (mf->u.p) - DestroyPicture(dpy, mf->u.p); - mf->u.p = NULL; - break; + case PixmapMenu: + case TiledPixmapMenu: + if (mf->u.p) + DestroyPicture(dpy, mf->u.p); + mf->u.p = NULL; + break; #endif - case SolidMenu: - FreeColors(&mf->u.back, 1); - default: - break; - } - mf->type = SimpleMenu; + case SolidMenu: + FreeColors(&mf->u.back, 1); + default: + break; + } + mf->type = SimpleMenu; } /***************************************************************************** @@ -3406,213 +3321,202 @@ static void FreeMenuFace(Display *dpy, MenuFace *mf) * Reads a menu face line into a structure (veliaa@rpi.edu) * ****************************************************************************/ -static Boolean ReadMenuFace(char *s, MenuFace *mf, int verbose) +static Boolean +ReadMenuFace(char *s, MenuFace *mf, int verbose) { - char *style; - char *token; - char *action = s; - - s = GetNextToken(s, &style); - if (style && strncasecmp(style, "--", 2) == 0) - { - free(style); - return True; - } - - FreeMenuFace(dpy, mf); - mf->type = SimpleMenu; - - /* determine menu style */ - if (!style) - return True; - else if (StrEquals(style,"Solid")) - { - s = GetNextToken(s, &token); - if (token) - { - mf->type = SolidMenu; - mf->u.back = GetColor(token); - free(token); - } - else - { - if(verbose) - fvwm_msg(ERR, "ReadMenuFace", "no color given for Solid face type: %s", - action); - free(style); - return False; - } - } + char *style; + char *token; + char *action = s; + + s = GetNextToken(s, &style); + if (style && strncasecmp(style, "--", 2) == 0) { + free(style); + return True; + } + FreeMenuFace(dpy, mf); + mf->type = SimpleMenu; + + /* determine menu style */ + if (!style) + return True; + else if (StrEquals(style, "Solid")) { + s = GetNextToken(s, &token); + if (token) { + mf->type = SolidMenu; + mf->u.back = GetColor(token); + free(token); + } else { + if (verbose) + fvwm_msg(ERR, "ReadMenuFace", + "no color given for Solid face type: %s", + action); + free(style); + return False; + } + } #ifdef GRADIENT_BUTTONS - else if (StrEquals(style,"HGradient") || StrEquals(style, "VGradient") || - StrEquals(style,"DGradient") || StrEquals(style, "BGradient")) - { - char *item, **s_colors; - int npixels, nsegs, i, sum, perc[128]; - Pixel *pixels; - char gtype = style[0]; - - s = GetNextToken(s, &item); - if (!item) - { - if(verbose) - fvwm_msg(ERR, "ReadMenuFace", - "expected number of colors to allocate in gradient"); - free(style); - return False; - } - npixels = atoi(item); - free(item); - - s = GetNextToken(s, &item); - if (!item) - { - if(verbose) - fvwm_msg(ERR, "ReadMenuFace", "incomplete gradient style"); - free(style); - return False; - } - - if (!(isdigit(*item))) - { - s_colors = (char **)safemalloc(sizeof(char *) * 2); - nsegs = 1; - s_colors[0] = item; - s = GetNextToken(s, &s_colors[1]); - if (!s_colors[1]) - { - if(verbose) - fvwm_msg(ERR, "ReadMenuFace", "incomplete gradient style"); - free(s_colors); - free(item); - free(style); - return False; - } - perc[0] = 100; - } - else - { - nsegs = atoi(item); - free(item); - if (nsegs < 1) - nsegs = 1; - if (nsegs > 128) - nsegs = 128; - s_colors = (char **)safemalloc(sizeof(char *) * (nsegs + 1)); - for (i = 0; i <= nsegs; ++i) - { - s = GetNextToken(s, &s_colors[i]); - if (i < nsegs) - { - s = GetNextToken(s, &item); - perc[i] = (item) ? atoi(item) : 0; - if (item) - free(item); - } - } - } - - for (i = 0, sum = 0; i < nsegs; ++i) - sum += perc[i]; - - if (sum != 100) - { - if(verbose) - fvwm_msg(ERR,"ReadMenuFace", "multi gradient lenghts must sum to 100"); - for (i = 0; i <= nsegs; ++i) - if (s_colors[i]) - free(s_colors[i]); - free(style); - free(s_colors); - return False; - } - - if (npixels < 2) - npixels = 2; - if (npixels > 128) - npixels = 128; - - pixels = AllocNonlinearGradient(s_colors, perc, nsegs, npixels); - for (i = 0; i <= nsegs; ++i) - if (s_colors[i]) - free(s_colors[i]); - free(s_colors); - - if (!pixels) - { - if(verbose) - fvwm_msg(ERR, "ReadMenuFace", "couldn't create gradient"); - free(style); - return False; - } - - mf->u.grad.pixels = pixels; - mf->u.grad.npixels = npixels; - - switch (gtype) - { - case 'h': - case 'H': - mf->type = HGradMenu; - break; - case 'v': - case 'V': - mf->type = VGradMenu; - break; - case 'd': - case 'D': - mf->type = DGradMenu; - break; - default: - mf->type = BGradMenu; - break; - } - } + else if (StrEquals(style, "HGradient") || + StrEquals(style, "VGradient") || + StrEquals(style, "DGradient") || + StrEquals(style, "BGradient")) { + char *item, **s_colors; + int npixels, nsegs, i, sum, perc[128]; + Pixel *pixels; + char gtype = style[0]; + + s = GetNextToken(s, &item); + if (!item) { + if (verbose) + fvwm_msg(ERR, "ReadMenuFace", + "expected number of colors to allocate in " + "gradient"); + free(style); + return False; + } + npixels = atoi(item); + free(item); + + s = GetNextToken(s, &item); + if (!item) { + if (verbose) + fvwm_msg(ERR, "ReadMenuFace", + "incomplete gradient style"); + free(style); + return False; + } + + if (!(isdigit(*item))) { + s_colors = (char **)xmalloc(sizeof(char *) * 2); + nsegs = 1; + s_colors[0] = item; + s = GetNextToken(s, &s_colors[1]); + if (!s_colors[1]) { + if (verbose) + fvwm_msg(ERR, "ReadMenuFace", + "incomplete gradient style"); + free(item); + free(s_colors); + free(style); + return False; + } + perc[0] = 100; + } else { + nsegs = atoi(item); + free(item); + if (nsegs < 1) + nsegs = 1; + if (nsegs > 128) + nsegs = 128; + s_colors = + (char **)xmalloc(sizeof(char *) * (nsegs + 1)); + for (i = 0; i <= nsegs; ++i) { + s = GetNextToken(s, &s_colors[i]); + if (i < nsegs) { + s = GetNextToken(s, &item); + perc[i] = (item) ? atoi(item) : 0; + if (item) + free(item); + } + } + } + + for (i = 0, sum = 0; i < nsegs; ++i) + sum += perc[i]; + + if (sum != 100) { + if (verbose) + fvwm_msg(ERR, "ReadMenuFace", + "multi gradient lengths must sum to 100"); + for (i = 0; i <= nsegs; ++i) + if (s_colors[i]) + free(s_colors[i]); + free(style); + free(s_colors); + return False; + } + + if (npixels < 2) + npixels = 2; + if (npixels > 128) + npixels = 128; + + pixels = AllocNonlinearGradient(s_colors, perc, nsegs, npixels); + for (i = 0; i <= nsegs; ++i) + if (s_colors[i]) + free(s_colors[i]); + free(s_colors); + + if (!pixels) { + if (verbose) + fvwm_msg(ERR, "ReadMenuFace", + "couldn't create gradient"); + free(style); + return False; + } + + mf->u.grad.pixels = pixels; + mf->u.grad.npixels = npixels; + + switch (gtype) { + case 'h': + case 'H': + mf->type = HGradMenu; + break; + case 'v': + case 'V': + mf->type = VGradMenu; + break; + case 'd': + case 'D': + mf->type = DGradMenu; + break; + default: + mf->type = BGradMenu; + break; + } + } #endif /* GRADIENT_BUTTONS */ #ifdef PIXMAP_BUTTONS - else if (StrEquals(style,"Pixmap") || StrEquals(style,"TiledPixmap")) - { - s = GetNextToken(s, &token); - if (token) - { - mf->u.p = CachePicture(dpy, Scr.Root, IconPath, - PixmapPath, - token, Scr.ColorLimit); - if (mf->u.p == NULL) - { - if(verbose) - fvwm_msg(ERR, "ReadMenuFace", "couldn't load pixmap %s", token); - free(token); - free(style); - return False; - } - free(token); - mf->type = (StrEquals(style,"TiledPixmap")) ? - TiledPixmapMenu : PixmapMenu; - } - else - { - if(verbose) - fvwm_msg(ERR, "ReadMenuFace", "missing pixmap name for style %s", - style); - free(style); - return False; - } - } + else if (StrEquals(style, "Pixmap") || + StrEquals(style, "TiledPixmap")) { + s = GetNextToken(s, &token); + if (token) { + mf->u.p = CachePicture(dpy, Scr.Root, IconPath, + PixmapPath, token, Scr.ColorLimit); + if (mf->u.p == NULL) { + if (verbose) + fvwm_msg(ERR, "ReadMenuFace", + "couldn't load pixmap %s", token); + free(token); + free(style); + return False; + } + free(token); + mf->type = (StrEquals(style, "TiledPixmap")) ? + TiledPixmapMenu : + PixmapMenu; + } else { + if (verbose) + fvwm_msg(ERR, "ReadMenuFace", + "missing pixmap name for style %s", style); + free(style); + return False; + } + } #endif /* PIXMAP_BUTTONS */ - else - { - if(verbose) - fvwm_msg(ERR, "ReadMenuFace", "unknown style %s: %s", style, action); - free(style); - return False; - } + else { + if (verbose) + fvwm_msg(ERR, "ReadMenuFace", "unknown style %s: %s", + style, action); + free(style); + return False; + } - free(style); - return True; + free(style); + return True; } #ifdef USEDECOR @@ -3621,14 +3525,18 @@ static Boolean ReadMenuFace(char *s, MenuFace *mf, int verbose) * Diverts a style definition to an FvwmDecor structure (veliaa@rpi.edu) * ****************************************************************************/ -void AddToDecor(FvwmDecor *fl, char *s) +void +AddToDecor(FvwmDecor *fl, char *s) { - if (!s) return; - while (*s&&isspace(*s))++s; - if (!*s) return; - cur_decor = fl; - ExecuteFunction(s,NULL,&Event,C_ROOT,-1); - cur_decor = NULL; + if (!s) + return; + while (*s && isspace(*s)) + ++s; + if (!*s) + return; + cur_decor = fl; + ExecuteFunction(s, NULL, &Event, C_ROOT, -1); + cur_decor = NULL; } /***************************************************************************** @@ -3636,47 +3544,49 @@ void AddToDecor(FvwmDecor *fl, char *s) * Changes the window's FvwmDecor pointer (veliaa@rpi.edu) * ****************************************************************************/ -void ChangeDecor(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int *Module) +void +ChangeDecor(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - char *item; - int x,y,width,height,old_height,extra_height; - FvwmDecor *fl = &Scr.DefaultDecor, *found = NULL; - if (DeferExecution(eventp,&w,&tmp_win,&context, SELECT,ButtonRelease)) - return; - action = GetNextToken(action, &item); - if (!action || !item) - { - if (item) - free(item); - return; - } - /* search for tag */ - for (; fl; fl = fl->next) - if (fl->tag) - if (StrEquals(item, fl->tag)) { - found = fl; - break; - } - free(item); - if (!found) { - XBell(dpy, 0); - return; - } - old_height = tmp_win->fl->TitleHeight; - tmp_win->fl = found; - extra_height = (tmp_win->flags & TITLE) ? - (old_height - tmp_win->fl->TitleHeight) : 0; - x = tmp_win->frame_x; - y = tmp_win->frame_y; - width = tmp_win->frame_width; - height = tmp_win->frame_height - extra_height; - tmp_win->frame_x = 0; - tmp_win->frame_y = 0; - tmp_win->frame_height = 0; - tmp_win->frame_width = 0; - SetupFrame(tmp_win,x,y,width,height,True); - SetBorder(tmp_win,Scr.Hilite == tmp_win,True,True,None); + char *item; + int x, y, width, height, old_height, extra_height; + FvwmDecor *fl = &Scr.DefaultDecor, *found = NULL; + if (DeferExecution( + eventp, &w, &tmp_win, &context, SELECT, ButtonRelease)) + return; + action = GetNextToken(action, &item); + if (!action || !item) { + if (item) + free(item); + return; + } + /* search for tag */ + for (; fl; fl = fl->next) + if (fl->tag) + if (StrEquals(item, fl->tag)) { + found = fl; + break; + } + free(item); + if (!found) { + XBell(dpy, 0); + return; + } + old_height = tmp_win->fl->TitleHeight; + tmp_win->fl = found; + extra_height = (tmp_win->flags & TITLE) ? + (old_height - tmp_win->fl->TitleHeight) : + 0; + x = tmp_win->frame_x; + y = tmp_win->frame_y; + width = tmp_win->frame_width; + height = tmp_win->frame_height - extra_height; + tmp_win->frame_x = 0; + tmp_win->frame_y = 0; + tmp_win->frame_height = 0; + tmp_win->frame_width = 0; + SetupFrame(tmp_win, x, y, width, height, True); + SetBorder(tmp_win, Scr.Hilite == tmp_win, True, True, None); } /***************************************************************************** @@ -3684,45 +3594,44 @@ void ChangeDecor(XEvent *eventp,Window w,FvwmWindow *tmp_win, * Destroys an FvwmDecor (veliaa@rpi.edu) * ****************************************************************************/ -void DestroyDecor(XEvent *eventp,Window junk,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +DestroyDecor(XEvent *eventp, Window junk, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - char *item; - FvwmDecor *fl = Scr.DefaultDecor.next; - FvwmDecor *prev = &Scr.DefaultDecor, *found = NULL; + char *item; + FvwmDecor *fl = Scr.DefaultDecor.next; + FvwmDecor *prev = &Scr.DefaultDecor, *found = NULL; - action = GetNextToken(action, &item); - if (!action || !item) - { - if (item) - free(item); - return; - } + action = GetNextToken(action, &item); + if (!action || !item) { + if (item) + free(item); + return; + } - /* search for tag */ - for (; fl; fl = fl->next) { - if (fl->tag) - if (StrEquals(item, fl->tag)) { - found = fl; - break; - } - prev = fl; - } - free(item); + /* search for tag */ + for (; fl; fl = fl->next) { + if (fl->tag) + if (StrEquals(item, fl->tag)) { + found = fl; + break; + } + prev = fl; + } + free(item); - if (found && (found != &Scr.DefaultDecor)) { - FvwmWindow *fw = Scr.FvwmRoot.next; - while(fw != NULL) - { - if (fw->fl == found) - ExecuteFunction("ChangeDecor Default",fw,eventp, - C_WINDOW,*Module); - fw = fw->next; - } - prev->next = found->next; - DestroyFvwmDecor(found); - free(found); - } + if (found && (found != &Scr.DefaultDecor)) { + FvwmWindow *fw = Scr.FvwmRoot.next; + while (fw != NULL) { + if (fw->fl == found) + ExecuteFunction("ChangeDecor Default", fw, + eventp, C_WINDOW, *Module); + fw = fw->next; + } + prev->next = found->next; + DestroyFvwmDecor(found); + free(found); + } } /***************************************************************************** @@ -3730,265 +3639,289 @@ void DestroyDecor(XEvent *eventp,Window junk,FvwmWindow *tmp_win, * Initiates an AddToDecor (veliaa@rpi.edu) * ****************************************************************************/ -void add_item_to_decor(XEvent *eventp,Window junk,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +add_item_to_decor(XEvent *eventp, Window junk, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - FvwmDecor *fl, *found = NULL; - char *item = NULL, *s = action; + FvwmDecor *fl, *found = NULL; + char *item = NULL, *s = action; - last_menu = NULL; + last_menu = NULL; - s = GetNextToken(s, &item); + s = GetNextToken(s, &item); - if (!item) - return; - if (!s) - { - free(item); - return; - } - /* search for tag */ - for (fl = &Scr.DefaultDecor; fl; fl = fl->next) - if (fl->tag) - if (StrEquals(item, fl->tag)) { - found = fl; - break; - } - if (!found) { /* then make a new one */ - found = (FvwmDecor *)safemalloc(sizeof( FvwmDecor )); - InitFvwmDecor(found); - found->tag = item; /* tag it */ - /* add it to list */ - for (fl = &Scr.DefaultDecor; fl->next; fl = fl->next); - fl->next = found; - } else - free(item); - if (found) { - AddToDecor(found, s); - last_decor = found; - } + if (!item) + return; + if (!s) { + free(item); + return; + } + /* search for tag */ + for (fl = &Scr.DefaultDecor; fl; fl = fl->next) + if (fl->tag) + if (StrEquals(item, fl->tag)) { + found = fl; + break; + } + if (!found) { /* then make a new one */ + found = (FvwmDecor *)xmalloc(sizeof(FvwmDecor)); + InitFvwmDecor(found); + found->tag = item; /* tag it */ + /* add it to list */ + for (fl = &Scr.DefaultDecor; fl->next; fl = fl->next) + ; + fl->next = found; + } else + free(item); + if (found) { + AddToDecor(found, s); + last_decor = found; + } } #endif /* USEDECOR */ - /***************************************************************************** * * Updates window decoration styles (veliaa@rpi.edu) * ****************************************************************************/ -void UpdateDecor(XEvent *eventp,Window junk,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +UpdateDecor(XEvent *eventp, Window junk, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - FvwmWindow *fw = Scr.FvwmRoot.next; + FvwmWindow *fw = Scr.FvwmRoot.next; #ifdef USEDECOR - FvwmDecor *fl = &Scr.DefaultDecor, *found = NULL; - char *item = NULL; - action = GetNextToken(action, &item); - if (item) { - /* search for tag */ - for (; fl; fl = fl->next) - if (fl->tag) - if (strcasecmp(item, fl->tag)==0) { - found = fl; - break; - } - free(item); - } + FvwmDecor *fl = &Scr.DefaultDecor, *found = NULL; + char *item = NULL; + action = GetNextToken(action, &item); + if (item) { + /* search for tag */ + for (; fl; fl = fl->next) + if (fl->tag) + if (strcasecmp(item, fl->tag) == 0) { + found = fl; + break; + } + free(item); + } #endif - for (; fw != NULL; fw = fw->next) - { + for (; fw != NULL; fw = fw->next) { #ifdef USEDECOR - /* update specific decor, or all */ - if (found) { - if (fw->fl == found) { - SetBorder(fw,True,True,True,None); - SetBorder(fw,False,True,True,None); - } - } - else + /* update specific decor, or all */ + if (found) { + if (fw->fl == found) { + SetBorder(fw, True, True, True, None); + SetBorder(fw, False, True, True, None); + } + } else #endif - { - SetBorder(fw,True,True,True,None); - SetBorder(fw,False,True,True,None); + { + SetBorder(fw, True, True, True, None); + SetBorder(fw, False, True, True, None); + } } - } - SetBorder(Scr.Hilite,True,True,True,None); + SetBorder(Scr.Hilite, True, True, True, None); } - /***************************************************************************** * * Changes a button decoration style (changes by veliaa@rpi.edu) * ****************************************************************************/ -#define SetButtonFlag(a) \ - do { \ - int i; \ - if (multi) { \ - if (multi&1) \ - for (i=0;i<5;++i) { \ - if (set) \ - fl->left_buttons[i].flags |= (a); \ - else \ - fl->left_buttons[i].flags &= ~(a); \ - } \ - if (multi&2) \ - for (i=0;i<5;++i) { \ - if (set) \ - fl->right_buttons[i].flags |= (a); \ - else \ - fl->right_buttons[i].flags &= ~(a); \ - } \ - } else \ - if (set) \ - tb->flags |= (a); \ - else \ - tb->flags &= ~(a); } while (0) - -void ButtonStyle(XEvent *eventp,Window junk,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +#define SetButtonFlag(a) \ + do { \ + int i; \ + if (multi) { \ + if (multi & 1) \ + for (i = 0; i < 5; ++i) { \ + if (set) \ + fl->left_buttons[i].flags |=\ + (a); \ + else \ + fl->left_buttons[i].flags &=\ + ~(a); \ + } \ + if (multi & 2) \ + for (i = 0; i < 5; ++i) { \ + if (set) \ + fl->right_buttons[i].flags |=\ + (a); \ + else \ + fl->right_buttons[i].flags &=\ + ~(a); \ + } \ + } else if (set) \ + tb->flags |= (a); \ + else \ + tb->flags &= ~(a); \ + } while (0) + +void +ButtonStyle(XEvent *eventp, Window junk, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - int button = 0,n; - int multi = 0; - char *text = action, *prev; - char *parm = NULL; - TitleButton *tb = NULL; + int button = 0, n; + int multi = 0; + char *text = action, *prev; + char *parm = NULL; + TitleButton *tb = NULL; #ifdef USEDECOR - FvwmDecor *fl = cur_decor ? cur_decor : &Scr.DefaultDecor; + FvwmDecor *fl = cur_decor ? cur_decor : &Scr.DefaultDecor; #else - FvwmDecor *fl = &Scr.DefaultDecor; + FvwmDecor *fl = &Scr.DefaultDecor; #endif - text = GetNextToken(text, &parm); - if (parm && isdigit(*parm)) - button = atoi(parm); + text = GetNextToken(text, &parm); + if (parm && isdigit(*parm)) + button = atoi(parm); - if ((parm == NULL) || (button > 10) || (button < 0)) { - fvwm_msg(ERR,"ButtonStyle","Bad button style (1) in line %s",action); - if (parm) - free(parm); - return; - } - - if (!isdigit(*parm)) { - if (StrEquals(parm,"left")) - multi = 1; /* affect all left buttons */ - else if (StrEquals(parm,"right")) - multi = 2; /* affect all right buttons */ - else if (StrEquals(parm,"all")) - multi = 3; /* affect all buttons */ - else { - /* we're either resetting buttons or - an invalid button set was specified */ - if (StrEquals(parm,"reset")) - ResetAllButtons(fl); - else - fvwm_msg(ERR,"ButtonStyle","Bad button style (2) in line %s", - action); - free(parm); - return; - } - } - free(parm); - if (multi == 0) { - /* a single button was specified */ - if (button==10) button=0; - /* which arrays to use? */ - n=button/2; - if((n*2) == button) - { - /* right */ - n = n - 1; - if(n<0)n=4; - tb = &fl->right_buttons[n]; + if ((parm == NULL) || (button > 10) || (button < 0)) { + fvwm_msg(ERR, "ButtonStyle", "Bad button style (1) in line %s", + action); + if (parm) + free(parm); + return; } - else { - /* left */ - tb = &fl->left_buttons[n]; - } - } - - prev = text; - text = GetNextToken(text,&parm); - while(parm) - { - if (strcmp(parm,"-")==0) { - char *tok; - text = GetNextToken(text, &tok); - while (tok) - { - int set = 1; - - if (*tok == '!') { /* flag negate */ - set = 0; - ++tok; + + if (!isdigit(*parm)) { + if (StrEquals(parm, "left")) + multi = 1; /* affect all left buttons */ + else if (StrEquals(parm, "right")) + multi = 2; /* affect all right buttons */ + else if (StrEquals(parm, "all")) + multi = 3; /* affect all buttons */ + else { + /* we're either resetting buttons or + an invalid button set was specified */ + if (StrEquals(parm, "reset")) + ResetAllButtons(fl); + else + fvwm_msg(ERR, "ButtonStyle", + "Bad button style (2) in line %s", action); + free(parm); + return; } - if (StrEquals(tok,"Clear")) { - int i; - if (multi) { - if (multi&1) { - for (i=0;i<5;++i) - if (set) - fl->left_buttons[i].flags = 0; - else - fl->left_buttons[i].flags = ~0; - } - if (multi&2) { - for (i=0;i<5;++i) { + } + free(parm); + if (multi == 0) { + /* a single button was specified */ + if (button == 10) + button = 0; + /* which arrays to use? */ + n = button / 2; + if ((n * 2) == button) { + /* right */ + n = n - 1; + if (n < 0) + n = 4; + tb = &fl->right_buttons[n]; + } else { + /* left */ + tb = &fl->left_buttons[n]; + } + } + + prev = text; + text = GetNextToken(text, &parm); + while (parm) { + if (strcmp(parm, "-") == 0) { + char *tok; + text = GetNextToken(text, &tok); + while (tok) { + int set = 1; + + if (*tok == '!') { /* flag negate */ + set = 0; + ++tok; + } + if (StrEquals(tok, "Clear")) { + int i; + if (multi) { + if (multi & 1) { + for (i = 0; i < 5; ++i) + if (set) + fl + ->left_buttons + [i] + .flags = + 0; + else + fl + ->left_buttons + [i] + .flags = + ~0; + } + if (multi & 2) { + for (i = 0; i < 5; + ++i) { + if (set) + fl + ->right_buttons + [i] + .flags = + 0; + else + fl + ->right_buttons + [i] + .flags = + ~0; + } + } + } else { + if (set) + tb->flags = 0; + else + tb->flags = ~0; + } + } else if (strncasecmp( + tok, "MWMDecorMenu", 12) == 0) { + SetButtonFlag(MWMDecorMenu); + } else if (strncasecmp( + tok, "MWMDecorMin", 11) == 0) { + SetButtonFlag(MWMDecorMinimize); + } else if (strncasecmp( + tok, "MWMDecorMax", 11) == 0) { + SetButtonFlag(MWMDecorMaximize); + } else { + fvwm_msg(ERR, "ButtonStyle", + "unknown title button flag %s -- " + "line: %s", + tok, text); + } if (set) - fl->right_buttons[i].flags = 0; + free(tok); else - fl->right_buttons[i].flags = ~0; - } + free(tok - 1); + text = GetNextToken(text, &tok); } - } else { - if (set) - tb->flags = 0; - else - tb->flags = ~0; - } - } - else if (strncasecmp(tok,"MWMDecorMenu",12)==0) { - SetButtonFlag(MWMDecorMenu); - } else if (strncasecmp(tok,"MWMDecorMin",11)==0) { - SetButtonFlag(MWMDecorMinimize); - } else if (strncasecmp(tok,"MWMDecorMax",11)==0) { - SetButtonFlag(MWMDecorMaximize); + free(parm); + break; } else { - fvwm_msg(ERR, "ButtonStyle", - "unknown title button flag %s -- line: %s", - tok, text); + if (multi) { + int i; + if (multi & 1) + for (i = 0; i < 5; ++i) + text = ReadTitleButton(prev, + &fl->left_buttons[i], False, + i * 2 + 1); + if (multi & 2) + for (i = 0; i < 5; ++i) + text = ReadTitleButton(prev, + &fl->right_buttons[i], + False, i * 2); + } else if (!(text = ReadTitleButton( + prev, tb, False, button))) { + free(parm); + break; + } } - if (set) - free(tok); - else - free(tok - 1); - text = GetNextToken(text, &tok); - } - free(parm); - break; - } else { - if (multi) { - int i; - if (multi&1) - for (i=0;i<5;++i) - text = ReadTitleButton(prev, &fl->left_buttons[i], - False, i*2+1); - if (multi&2) - for (i=0;i<5;++i) - text = ReadTitleButton(prev, &fl->right_buttons[i], - False, i*2); - } - else if (!(text = ReadTitleButton(prev, tb, False, button))) { free(parm); - break; - } + prev = text; + text = GetNextToken(text, &parm); } - free(parm); - prev = text; - text = GetNextToken(text,&parm); - } } #ifdef MULTISTYLE @@ -3997,118 +3930,122 @@ void ButtonStyle(XEvent *eventp,Window junk,FvwmWindow *tmp_win, * Appends a button decoration style (veliaa@rpi.edu) * ****************************************************************************/ -void AddButtonStyle(XEvent *eventp,Window junk,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +AddButtonStyle(XEvent *eventp, Window junk, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - int button = 0,n; - int multi = 0; - char *text = action, *prev; - char *parm = NULL; - TitleButton *tb = NULL; + int button = 0, n; + int multi = 0; + char *text = action, *prev; + char *parm = NULL; + TitleButton *tb = NULL; #ifdef USEDECOR - FvwmDecor *fl = cur_decor ? cur_decor : &Scr.DefaultDecor; + FvwmDecor *fl = cur_decor ? cur_decor : &Scr.DefaultDecor; #else - FvwmDecor *fl = &Scr.DefaultDecor; + FvwmDecor *fl = &Scr.DefaultDecor; #endif - text = GetNextToken(text, &parm); - if (parm && isdigit(*parm)) - button = atoi(parm); + text = GetNextToken(text, &parm); + if (parm && isdigit(*parm)) + button = atoi(parm); - if ((parm == NULL) || (button > 10) || (button < 0)) { - fvwm_msg(ERR,"ButtonStyle","Bad button style (1) in line %s",action); - if (parm) - free(parm); - return; - } - - if (!isdigit(*parm)) { - if (StrEquals(parm,"left")) - multi = 1; /* affect all left buttons */ - else if (StrEquals(parm,"right")) - multi = 2; /* affect all right buttons */ - else if (StrEquals(parm,"all")) - multi = 3; /* affect all buttons */ - else { - /* we're either resetting buttons or - an invalid button set was specified */ - if (StrEquals(parm,"reset")) - ResetAllButtons(fl); - else - fvwm_msg(ERR,"ButtonStyle","Bad button style (2) in line %s", - action); - free(parm); - return; - } - } - free(parm); - if (multi == 0) { - /* a single button was specified */ - if (button==10) button=0; - /* which arrays to use? */ - n=button/2; - if((n*2) == button) - { - /* right */ - n = n - 1; - if(n<0)n=4; - tb = &fl->right_buttons[n]; + if ((parm == NULL) || (button > 10) || (button < 0)) { + fvwm_msg(ERR, "ButtonStyle", "Bad button style (1) in line %s", + action); + if (parm) + free(parm); + return; } - else { - /* left */ - tb = &fl->left_buttons[n]; - } - } - - prev = text; - text = GetNextToken(text,&parm); - while(parm) - { - if (multi) { - int i; - if (multi&1) - for (i=0;i<5;++i) - text = ReadTitleButton(prev, &fl->left_buttons[i], True, i*2+1); - if (multi&2) - for (i=0;i<5;++i) - text = ReadTitleButton(prev, &fl->right_buttons[i], True, i*2); - } - else if (!(text = ReadTitleButton(prev, tb, True, button))) { - free(parm); - break; + + if (!isdigit(*parm)) { + if (StrEquals(parm, "left")) + multi = 1; /* affect all left buttons */ + else if (StrEquals(parm, "right")) + multi = 2; /* affect all right buttons */ + else if (StrEquals(parm, "all")) + multi = 3; /* affect all buttons */ + else { + /* we're either resetting buttons or + an invalid button set was specified */ + if (StrEquals(parm, "reset")) + ResetAllButtons(fl); + else + fvwm_msg(ERR, "ButtonStyle", + "Bad button style (2) in line %s", action); + free(parm); + return; + } } free(parm); + if (multi == 0) { + /* a single button was specified */ + if (button == 10) + button = 0; + /* which arrays to use? */ + n = button / 2; + if ((n * 2) == button) { + /* right */ + n = n - 1; + if (n < 0) + n = 4; + tb = &fl->right_buttons[n]; + } else { + /* left */ + tb = &fl->left_buttons[n]; + } + } + prev = text; - text = GetNextToken(text,&parm); - } + text = GetNextToken(text, &parm); + while (parm) { + if (multi) { + int i; + if (multi & 1) + for (i = 0; i < 5; ++i) + text = ReadTitleButton(prev, + &fl->left_buttons[i], True, + i * 2 + 1); + if (multi & 2) + for (i = 0; i < 5; ++i) + text = ReadTitleButton(prev, + &fl->right_buttons[i], True, i * 2); + } else if (!(text = ReadTitleButton(prev, tb, True, button))) { + free(parm); + break; + } + free(parm); + prev = text; + text = GetNextToken(text, &parm); + } } #endif /* MULTISTYLE */ - -void SetEnv(XEvent *eventp,Window junk,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +SetEnv(XEvent *eventp, Window junk, FvwmWindow *tmp_win, unsigned long context, + char *action, int *Module) { - char *szVar = NULL; - char *szValue = NULL; - char *szPutenv = NULL; - size_t len; - - action = GetNextToken(action,&szVar); - if (!szVar) - return; - action = GetNextToken(action,&szValue); - if (!szValue) - { + char *szVar = NULL; + char *szValue = NULL; + char *szPutenv = NULL; + size_t len; + + action = GetNextToken(action, &szVar); + if (!szVar) + return; + action = GetNextToken(action, &szValue); + if (!szValue) { + free(szVar); + return; + } + + len = strlen(szVar) + strlen(szValue) + 2; + szPutenv = xmalloc(len); + snprintf(szPutenv, len, "%s=%s", szVar, szValue); + if (setenv(szVar, szValue, 1) == -1) + fvwm_msg(WARN, "PutEnvironment", "setenv failed"); + free(szPutenv); free(szVar); - return; - } - - len = strlen(szVar)+strlen(szValue)+2; - szPutenv = safemalloc(len); - snprintf(szPutenv,len,"%s=%s",szVar,szValue); - putenv(szPutenv); - free(szVar); - free(szValue); + free(szValue); } /********************************************************************** @@ -4117,221 +4054,219 @@ void SetEnv(XEvent *eventp,Window junk,FvwmWindow *tmp_win, * Note that the returned string is allocated here and it must be * freed when it is not needed anymore. **********************************************************************/ -char *CreateFlagString(char *string, char **restptr) +char * +CreateFlagString(char *string, char **restptr) { - char *retval; - char *c; - char *start; - char closeopt; - int length; - - c = string; - while (isspace(*c) && (*c != 0)) - c++; - - if (*c == '[' || *c == '(') - { - /* Get the text between [ ] or ( ) */ - if (*c == '[') - closeopt = ']'; - else - closeopt = ')'; - c++; - start = c; - length = 0; - while (*c != closeopt) { - if (*c == 0) { - fvwm_msg(ERR, "CreateConditionMask", - "Conditionals require closing parenthesis"); - *restptr = NULL; - return NULL; - } - c++; - length++; - } - - /* We must allocate a new string because we null terminate the string - * between the [ ] or ( ) characters. - */ - retval = safemalloc(length + 1); - strncpy(retval, start, length); - retval[length] = 0; - - *restptr = c + 1; - } - else { - retval = NULL; - *restptr = c; - } - - return retval; + char *retval; + char *c; + char *start; + char closeopt; + int length; + + c = string; + while (isspace(*c) && (*c != 0)) + c++; + + if (*c == '[' || *c == '(') { + /* Get the text between [ ] or ( ) */ + if (*c == '[') + closeopt = ']'; + else + closeopt = ')'; + c++; + start = c; + length = 0; + while (*c != closeopt) { + if (*c == 0) { + fvwm_msg(ERR, "CreateConditionMask", + "Conditionals require closing parenthesis"); + *restptr = NULL; + return NULL; + } + c++; + length++; + } + + /* We must allocate a new string because we null terminate the + * string between the [ ] or ( ) characters. + */ + retval = xmalloc(length + 1); + strncpy(retval, start, length); + retval[length] = 0; + + *restptr = c + 1; + } else { + retval = NULL; + *restptr = c; + } + + return retval; } /********************************************************************** * The name field of the mask is allocated in CreateConditionMask. * It must be freed. **********************************************************************/ -void FreeConditionMask(WindowConditionMask *mask) +void +FreeConditionMask(WindowConditionMask *mask) { - if (mask->needsName) - free(mask->name); - else if (mask->needsNotName) - free(mask->name - 1); + if (mask->needsName) + free(mask->name); + else if (mask->needsNotName) + free(mask->name - 1); } /* Assign the default values for the window mask */ -void DefaultConditionMask(WindowConditionMask *mask) +void +DefaultConditionMask(WindowConditionMask *mask) { - mask->name = NULL; - mask->needsCurrentDesk = 0; - mask->needsCurrentPage = 0; - mask->needsName = 0; - mask->needsNotName = 0; - mask->useCirculateHit = 0; - mask->useCirculateHitIcon = 0; - mask->onFlags = 0; - mask->offFlags = 0; + mask->name = NULL; + mask->needsCurrentDesk = 0; + mask->needsCurrentPage = 0; + mask->needsName = 0; + mask->needsNotName = 0; + mask->useCirculateHit = 0; + mask->useCirculateHitIcon = 0; + mask->onFlags = 0; + mask->offFlags = 0; } /********************************************************************** * Note that this function allocates the name field of the mask struct. * FreeConditionMask must be called for the mask when the mask is discarded. **********************************************************************/ -void CreateConditionMask(char *flags, WindowConditionMask *mask) +void +CreateConditionMask(char *flags, WindowConditionMask *mask) { - char *condition; - char *prev_condition = NULL; - char *tmp; - - if (flags == NULL) - return; - - /* Next parse the flags in the string. */ - tmp = flags; - tmp = GetNextToken(tmp, &condition); - - while (condition) - { - if (StrEquals(condition,"Iconic")) - mask->onFlags |= ICONIFIED; - else if(StrEquals(condition,"!Iconic")) - mask->offFlags |= ICONIFIED; - else if(StrEquals(condition,"Visible")) - mask->onFlags |= VISIBLE; - else if(StrEquals(condition,"!Visible")) - mask->offFlags |= VISIBLE; - else if(StrEquals(condition,"Sticky")) - mask->onFlags |= STICKY; - else if(StrEquals(condition,"!Sticky")) - mask->offFlags |= STICKY; - else if(StrEquals(condition,"Maximized")) - mask->onFlags |= MAXIMIZED; - else if(StrEquals(condition,"!Maximized")) - mask->offFlags |= MAXIMIZED; - else if(StrEquals(condition,"Transient")) - mask->onFlags |= TRANSIENT; - else if(StrEquals(condition,"!Transient")) - mask->offFlags |= TRANSIENT; - else if(StrEquals(condition,"Raised")) - mask->onFlags |= RAISED; - else if(StrEquals(condition,"!Raised")) - mask->offFlags |= RAISED; - else if(StrEquals(condition,"CurrentDesk")) - mask->needsCurrentDesk = 1; - else if(StrEquals(condition,"CurrentPage")) - { - mask->needsCurrentDesk = 1; - mask->needsCurrentPage = 1; - } - else if(StrEquals(condition,"CurrentPageAnyDesk") || - StrEquals(condition,"CurrentScreen")) - mask->needsCurrentPage = 1; - else if(StrEquals(condition,"CirculateHit")) - mask->useCirculateHit = 1; - else if(StrEquals(condition,"CirculateHitIcon")) - mask->useCirculateHitIcon = 1; - else if(!mask->needsName && !mask->needsNotName) - { - /* only 1st name to avoid mem leak */ - mask->name = condition; - condition = NULL; - if (mask->name[0] == '!') - { - mask->needsNotName = 1; - mask->name++; - } - else - mask->needsName = 1; - } - - if (prev_condition) - free(prev_condition); - - prev_condition = condition; - tmp = GetNextToken(tmp, &condition); - } - - if(prev_condition != NULL) - free(prev_condition); + char *condition; + char *prev_condition = NULL; + char *tmp; + + if (flags == NULL) + return; + + /* Next parse the flags in the string. */ + tmp = flags; + tmp = GetNextToken(tmp, &condition); + + while (condition) { + if (StrEquals(condition, "Iconic")) + mask->onFlags |= ICONIFIED; + else if (StrEquals(condition, "!Iconic")) + mask->offFlags |= ICONIFIED; + else if (StrEquals(condition, "Visible")) + mask->onFlags |= VISIBLE; + else if (StrEquals(condition, "!Visible")) + mask->offFlags |= VISIBLE; + else if (StrEquals(condition, "Sticky")) + mask->onFlags |= STICKY; + else if (StrEquals(condition, "!Sticky")) + mask->offFlags |= STICKY; + else if (StrEquals(condition, "Maximized")) + mask->onFlags |= MAXIMIZED; + else if (StrEquals(condition, "!Maximized")) + mask->offFlags |= MAXIMIZED; + else if (StrEquals(condition, "Transient")) + mask->onFlags |= TRANSIENT; + else if (StrEquals(condition, "!Transient")) + mask->offFlags |= TRANSIENT; + else if (StrEquals(condition, "Raised")) + mask->onFlags |= RAISED; + else if (StrEquals(condition, "!Raised")) + mask->offFlags |= RAISED; + else if (StrEquals(condition, "CurrentDesk")) + mask->needsCurrentDesk = 1; + else if (StrEquals(condition, "CurrentPage")) { + mask->needsCurrentDesk = 1; + mask->needsCurrentPage = 1; + } else if (StrEquals(condition, "CurrentPageAnyDesk") || + StrEquals(condition, "CurrentScreen")) + mask->needsCurrentPage = 1; + else if (StrEquals(condition, "CirculateHit")) + mask->useCirculateHit = 1; + else if (StrEquals(condition, "CirculateHitIcon")) + mask->useCirculateHitIcon = 1; + else if (!mask->needsName && !mask->needsNotName) { + /* only 1st name to avoid mem leak */ + mask->name = condition; + condition = NULL; + if (mask->name[0] == '!') { + mask->needsNotName = 1; + mask->name++; + } else + mask->needsName = 1; + } + + if (prev_condition) + free(prev_condition); + + prev_condition = condition; + tmp = GetNextToken(tmp, &condition); + } + + if (prev_condition != NULL) + free(prev_condition); } /********************************************************************** * Checks whether the given window matches the mask created with * CreateConditionMask. **********************************************************************/ -Bool MatchesConditionMask(FvwmWindow *fw, WindowConditionMask *mask) +Bool +MatchesConditionMask(FvwmWindow *fw, WindowConditionMask *mask) { - Bool fMatchesName; - Bool fMatchesIconName; - Bool fMatchesClass; - Bool fMatchesResource; - Bool fMatches; - - if ((mask->onFlags & fw->flags) != mask->onFlags) - return 0; - - if ((mask->offFlags & fw->flags) != 0) - return 0; - - if (!mask->useCirculateHit && (fw->flags & CirculateSkip)) - return 0; - - /* This logic looks terribly wrong to me, but it was this way before so I - * did not change it (domivogt (24-Dec-1998)) */ - if (!mask->useCirculateHitIcon && fw->flags & ICONIFIED && - fw->flags & CirculateSkipIcon) - return 0; - - if (fw->flags & ICONIFIED && fw->flags & TRANSIENT && - fw->tmpflags.IconifiedByParent) - return 0; - - if (mask->needsCurrentDesk && fw->Desk != Scr.CurrentDesk) - return 0; - - if (mask->needsCurrentPage && !(fw->frame_x < Scr.MyDisplayWidth && - fw->frame_y < Scr.MyDisplayHeight && - fw->frame_x + fw->frame_width > 0 && - fw->frame_y + fw->frame_height > 0)) - return 0; - - /* Yes, I know this could be shorter, but it's hard to understand then */ - fMatchesName = matchWildcards(mask->name, fw->name); - fMatchesIconName = matchWildcards(mask->name, fw->icon_name); - fMatchesClass = (fw->class.res_class && - matchWildcards(mask->name,fw->class.res_class)); - fMatchesResource = (fw->class.res_name && - matchWildcards(mask->name, fw->class.res_name)); - fMatches = (fMatchesName || fMatchesIconName || fMatchesClass || - fMatchesResource); - - if (mask->needsName && !fMatches) - return 0; - - if (mask->needsNotName && fMatches) - return 0; - - return 1; + Bool fMatchesName; + Bool fMatchesIconName; + Bool fMatchesClass; + Bool fMatchesResource; + Bool fMatches; + + if ((mask->onFlags & fw->flags) != mask->onFlags) + return 0; + + if ((mask->offFlags & fw->flags) != 0) + return 0; + + if (!mask->useCirculateHit && (fw->flags & CirculateSkip)) + return 0; + + /* This logic looks terribly wrong to me, but it was this way before so + * I did not change it (domivogt (24-Dec-1998)) */ + if (!mask->useCirculateHitIcon && fw->flags & ICONIFIED && + fw->flags & CirculateSkipIcon) + return 0; + + if (fw->flags & ICONIFIED && fw->flags & TRANSIENT && + fw->tmpflags.IconifiedByParent) + return 0; + + if (mask->needsCurrentDesk && fw->Desk != Scr.CurrentDesk) + return 0; + + if (mask->needsCurrentPage && !(fw->frame_x < Scr.MyDisplayWidth && + fw->frame_y < Scr.MyDisplayHeight && + fw->frame_x + fw->frame_width > 0 && + fw->frame_y + fw->frame_height > 0)) + return 0; + + /* Yes, I know this could be shorter, but it's hard to understand then + */ + fMatchesName = matchWildcards(mask->name, fw->name); + fMatchesIconName = matchWildcards(mask->name, fw->icon_name); + fMatchesClass = (fw->class.res_class && + matchWildcards(mask->name, fw->class.res_class)); + fMatchesResource = (fw->class.res_name && + matchWildcards(mask->name, fw->class.res_name)); + fMatches = (fMatchesName || fMatchesIconName || fMatchesClass || + fMatchesResource); + + if (mask->needsName && !fMatches) + return 0; + + if (mask->needsNotName && fMatches) + return 0; + + return 1; } /************************************************************************** @@ -4341,318 +4276,305 @@ Bool MatchesConditionMask(FvwmWindow *fw, WindowConditionMask *mask) * Direction = 0 ==> operation on current window (returns pass or fail) * **************************************************************************/ -FvwmWindow *Circulate(char *action, int Direction, char **restofline) +FvwmWindow * +Circulate(char *action, int Direction, char **restofline) { - int pass = 0; - FvwmWindow *fw, *found = NULL; - WindowConditionMask mask; - char *flags; - - /* Create window mask */ - flags = CreateFlagString(action, restofline); - DefaultConditionMask(&mask); - if (Direction == 0) { /* override for Current [] */ - mask.useCirculateHit = 1; - mask.useCirculateHitIcon = 1; - } - CreateConditionMask(flags, &mask); - if (flags) - free(flags); - - if(Scr.Focus != NULL) - { - if(Direction == 1) - fw = Scr.Focus->prev; - else if(Direction == -1) - fw = Scr.Focus->next; - else - fw = Scr.Focus; - } - else - fw = NULL; - - while((pass < 3)&&(found == NULL)) - { - while((fw != NULL)&&(found==NULL)&&(fw != &Scr.FvwmRoot)) - { + int pass = 0; + FvwmWindow *fw, *found = NULL; + WindowConditionMask mask; + char *flags; + + /* Create window mask */ + flags = CreateFlagString(action, restofline); + DefaultConditionMask(&mask); + if (Direction == 0) { /* override for Current [] */ + mask.useCirculateHit = 1; + mask.useCirculateHitIcon = 1; + } + CreateConditionMask(flags, &mask); + if (flags) + free(flags); + + if (Scr.Focus != NULL) { + if (Direction == 1) + fw = Scr.Focus->prev; + else if (Direction == -1) + fw = Scr.Focus->next; + else + fw = Scr.Focus; + } else + fw = NULL; + + while ((pass < 3) && (found == NULL)) { + while ((fw != NULL) && (found == NULL) && + (fw != &Scr.FvwmRoot)) { #ifdef FVWM_DEBUG_MSGS - fvwm_msg(DBG,"Circulate","Trying %s",fw->name); + fvwm_msg(DBG, "Circulate", "Trying %s", fw->name); #endif /* FVWM_DEBUG_MSGS */ - /* Make CirculateUp and CirculateDown take args. by Y.NOMURA */ - if (MatchesConditionMask(fw, &mask)) - found = fw; - else - { - if(Direction == 1) - fw = fw->prev; - else - fw = fw->next; - } - if (Direction == 0) - { + /* Make CirculateUp and CirculateDown take args. by + * Y.NOMURA */ + if (MatchesConditionMask(fw, &mask)) + found = fw; + else { + if (Direction == 1) + fw = fw->prev; + else + fw = fw->next; + } + if (Direction == 0) { + FreeConditionMask(&mask); + return found; + } + } + if ((fw == NULL) || (fw == &Scr.FvwmRoot)) { + if (Direction == 1) { + /* Go to end of list */ + fw = &Scr.FvwmRoot; + while ((fw) && (fw->next != NULL)) { + fw = fw->next; + } + } else { + /* GO to top of list */ + fw = Scr.FvwmRoot.next; + } + } + pass++; + } FreeConditionMask(&mask); - return found; - } - } - if((fw == NULL)||(fw == &Scr.FvwmRoot)) - { - if(Direction == 1) - { - /* Go to end of list */ - fw = &Scr.FvwmRoot; - while((fw) && (fw->next != NULL)) - { - fw = fw->next; - } - } - else - { - /* GO to top of list */ - fw = Scr.FvwmRoot.next; - } - } - pass++; - } - FreeConditionMask(&mask); - return found; + return found; } -void PrevFunc(XEvent *eventp,Window junk,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +PrevFunc(XEvent *eventp, Window junk, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - FvwmWindow *found; - char *restofline; - - found = Circulate(action, -1, &restofline); - if(found != NULL && restofline != NULL) - { - ExecuteFunction(restofline,found,eventp,C_WINDOW,*Module); - } + FvwmWindow *found; + char *restofline; + found = Circulate(action, -1, &restofline); + if (found != NULL && restofline != NULL) { + ExecuteFunction(restofline, found, eventp, C_WINDOW, *Module); + } } -void NextFunc(XEvent *eventp,Window junk,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +NextFunc(XEvent *eventp, Window junk, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - FvwmWindow *found; - char *restofline; - - found = Circulate(action, 1, &restofline); - if(found != NULL && restofline != NULL) - { - ExecuteFunction(restofline,found,eventp,C_WINDOW,*Module); - } + FvwmWindow *found; + char *restofline; + found = Circulate(action, 1, &restofline); + if (found != NULL && restofline != NULL) { + ExecuteFunction(restofline, found, eventp, C_WINDOW, *Module); + } } -void NoneFunc(XEvent *eventp,Window junk,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +NoneFunc(XEvent *eventp, Window junk, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - FvwmWindow *found; - char *restofline; - - found = Circulate(action, 1, &restofline); - if(found == NULL && restofline != NULL) - { - ExecuteFunction(restofline,NULL,eventp,C_ROOT,*Module); - } + FvwmWindow *found; + char *restofline; + + found = Circulate(action, 1, &restofline); + if (found == NULL && restofline != NULL) { + ExecuteFunction(restofline, NULL, eventp, C_ROOT, *Module); + } } -void CurrentFunc(XEvent *eventp,Window junk,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +CurrentFunc(XEvent *eventp, Window junk, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - FvwmWindow *found; - char *restofline; - - found = Circulate(action, 0, &restofline); - if(found != NULL && restofline != NULL) - { - ExecuteFunction(restofline,found,eventp,C_WINDOW,*Module); - } + FvwmWindow *found; + char *restofline; + + found = Circulate(action, 0, &restofline); + if (found != NULL && restofline != NULL) { + ExecuteFunction(restofline, found, eventp, C_WINDOW, *Module); + } } -static void GetDirectionReference(FvwmWindow *w, int *x, int *y) +static void +GetDirectionReference(FvwmWindow *w, int *x, int *y) { - if ((w->flags & ICONIFIED) != 0) - { - *x = w->icon_x_loc + w->icon_w_width / 2; - *y = w->icon_y_loc + w->icon_w_height / 2; - } - else - { - *x = w->frame_x + w->frame_width / 2; - *y = w->frame_y + w->frame_height / 2; - } + if ((w->flags & ICONIFIED) != 0) { + *x = w->icon_x_loc + w->icon_w_width / 2; + *y = w->icon_y_loc + w->icon_w_height / 2; + } else { + *x = w->frame_x + w->frame_width / 2; + *y = w->frame_y + w->frame_height / 2; + } } /********************************************************************** * Execute a function to the closest window in the given * direction. **********************************************************************/ -void DirectionFunc(XEvent *eventp,Window junk,FvwmWindow *tmp_win, - unsigned long context, char *action, int *Module) +void +DirectionFunc(XEvent *eventp, Window junk, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - char *directions[] = { "North", "East", "South", "West", "NorthEast", - "SouthEast", "SouthWest", "NorthWest", NULL }; - int my_x; - int my_y; - int his_x; - int his_y; - int score; - int offset; - int distance; - int best_score; - FvwmWindow *window; - FvwmWindow *best_window; - int dir; - char *flags; - char *restofline; - char *tmp; - WindowConditionMask mask; - - /* Parse the direction. */ - action = GetNextToken(action, &tmp); - dir = GetTokenIndex(tmp, directions, 0, NULL); - if (dir == -1) - { - fvwm_msg(ERR, "Direction","Invalid direction %s", (tmp)? tmp : ""); - if (tmp) - free(tmp); - return; - } - if (tmp) - free(tmp); - - /* Create the mask for flags */ - flags = CreateFlagString(action, &restofline); - if (!restofline) - { - if (flags) - free(flags); - return; - } - DefaultConditionMask(&mask); - CreateConditionMask(flags, &mask); - if (flags) - free(flags); - - /* If there is a focused window, use that as a starting point. - * Otherwise we use the pointer as a starting point. */ - if (tmp_win != NULL) - { - GetDirectionReference(tmp_win, &my_x, &my_y); - } - else - XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, - &my_x, &my_y, &JunkX, &JunkY, &JunkMask); - - /* Next we iterate through all windows and choose the closest one in - * the wanted direction. - */ - best_window = NULL; - best_score = -1; - for (window = Scr.FvwmRoot.next; window != NULL; window = window->next) { - /* Skip every window that does not match conditionals. - * Skip also currently focused window. That would be too close. :) - */ - if (window == tmp_win || !MatchesConditionMask(window, &mask)) - continue; - - /* Calculate relative location of the window. */ - GetDirectionReference(window, &his_x, &his_y); - his_x -= my_x; - his_y -= my_y; - - if (dir > 3) - { - int tx; - /* Rotate the diagonals 45 degrees counterclockwise. To do this, - * multiply the matrix /+h +h\ with the vector (x y). - * \-h +h/ - * h = sqrt(0.5). We can set h := 1 since absolute distance doesn't - * matter here. */ - tx = his_x + his_y; - his_y = -his_x + his_y; - his_x = tx; - } - /* Arrange so that distance and offset are positive in desired direction. - */ - switch (dir) - { - case 0: /* N */ - case 2: /* S */ - case 4: /* NE */ - case 6: /* SW */ - offset = (his_x < 0) ? -his_x : his_x; - distance = (dir == 0 || dir == 4) ? -his_y : his_y; - break; - case 1: /* E */ - case 3: /* W */ - case 5: /* SE */ - case 7: /* NW */ - offset = (his_y < 0) ? -his_y : his_y; - distance = (dir == 3 || dir == 7) ? -his_x : his_x; - break; - } - - /* Target must be in given direction. */ - if (distance <= 0) continue; - - /* Calculate score for this window. The smaller the better. */ - score = 1024 * offset / distance + 2 * distance + 2 * offset; - if (best_score == -1 || score < best_score) { - best_window = window; - best_score = score; - } - } /* for */ - - if (best_window != NULL) - ExecuteFunction(restofline, best_window, eventp, C_WINDOW, *Module); - - FreeConditionMask(&mask); + char *directions[] = {"North", "East", "South", "West", "NorthEast", + "SouthEast", "SouthWest", "NorthWest", NULL}; + int my_x; + int my_y; + int his_x; + int his_y; + int score; + int offset; + int distance; + int best_score; + FvwmWindow *window; + FvwmWindow *best_window; + int dir; + char *flags; + char *restofline; + char *tmp; + WindowConditionMask mask; + + /* Parse the direction. */ + action = GetNextToken(action, &tmp); + dir = GetTokenIndex(tmp, directions, 0, NULL); + if (dir == -1) { + fvwm_msg( + ERR, "Direction", "Invalid direction %s", (tmp) ? tmp : ""); + if (tmp) + free(tmp); + return; + } + if (tmp) + free(tmp); + + /* Create the mask for flags */ + flags = CreateFlagString(action, &restofline); + if (!restofline) { + if (flags) + free(flags); + return; + } + DefaultConditionMask(&mask); + CreateConditionMask(flags, &mask); + if (flags) + free(flags); + + /* If there is a focused window, use that as a starting point. + * Otherwise we use the pointer as a starting point. */ + if (tmp_win != NULL) { + GetDirectionReference(tmp_win, &my_x, &my_y); + } else + XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, &my_x, + &my_y, &JunkX, &JunkY, &JunkMask); + + /* Next we iterate through all windows and choose the closest one in + * the wanted direction. + */ + best_window = NULL; + best_score = -1; + for (window = Scr.FvwmRoot.next; window != NULL; + window = window->next) { + /* Skip every window that does not match conditionals. + * Skip also currently focused window. That would be too close. + * :) + */ + if (window == tmp_win || !MatchesConditionMask(window, &mask)) + continue; + + /* Calculate relative location of the window. */ + GetDirectionReference(window, &his_x, &his_y); + his_x -= my_x; + his_y -= my_y; + + if (dir > 3) { + int tx; + /* Rotate the diagonals 45 degrees counterclockwise. To + * do this, multiply the matrix /+h +h\ with the vector + * (x y). + * \-h +h/ + * h = sqrt(0.5). We can set h := 1 since absolute + * distance doesn't matter here. */ + tx = his_x + his_y; + his_y = -his_x + his_y; + his_x = tx; + } + /* Arrange so that distance and offset are positive in desired + * direction. + */ + switch (dir) { + case 0: /* N */ + case 2: /* S */ + case 4: /* NE */ + case 6: /* SW */ + offset = (his_x < 0) ? -his_x : his_x; + distance = (dir == 0 || dir == 4) ? -his_y : his_y; + break; + case 1: /* E */ + case 3: /* W */ + case 5: /* SE */ + case 7: /* NW */ + offset = (his_y < 0) ? -his_y : his_y; + distance = (dir == 3 || dir == 7) ? -his_x : his_x; + break; + } + + /* Target must be in given direction. */ + if (distance <= 0) + continue; + + /* Calculate score for this window. The smaller the better. */ + score = 1024 * offset / distance + 2 * distance + 2 * offset; + if (best_score == -1 || score < best_score) { + best_window = window; + best_score = score; + } + } /* for */ + + if (best_window != NULL) + ExecuteFunction( + restofline, best_window, eventp, C_WINDOW, *Module); + + FreeConditionMask(&mask); } -void WindowIdFunc(XEvent *eventp,Window junk,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +WindowIdFunc(XEvent *eventp, Window junk, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - FvwmWindow *found=NULL,*t; - char *num; - unsigned long win; - - action = GetNextToken(action, &num); - - if (num) - { - win = (unsigned long)strtol(num,NULL,0); /* SunOS doesn't have strtoul */ - free(num); - } - else - win = 0; - for (t = Scr.FvwmRoot.next; t != NULL; t = t->next) - { - if (t->w == win) - { - found = t; - break; - } - } - if(found) - { - ExecuteFunction(action,found,eventp,C_WINDOW,*Module); - } + FvwmWindow *found = NULL, *t; + char *num; + unsigned long win; + + action = GetNextToken(action, &num); + + if (num) { + win = (unsigned long)strtol( + num, NULL, 0); /* SunOS doesn't have strtoul */ + free(num); + } else + win = 0; + for (t = Scr.FvwmRoot.next; t != NULL; t = t->next) { + if (t->w == win) { + found = t; + break; + } + } + if (found) { + ExecuteFunction(action, found, eventp, C_WINDOW, *Module); + } } - -void module_zapper(XEvent *eventp,Window junk,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +module_zapper(XEvent *eventp, Window junk, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - char *condition; + char *condition; - GetNextToken(action,&condition); - if (!condition) - return; - KillModuleByName(condition); - free(condition); + GetNextToken(action, &condition); + if (!condition) + return; + KillModuleByName(condition); + free(condition); } /*********************************************************************** @@ -4661,213 +4583,172 @@ void module_zapper(XEvent *eventp,Window junk,FvwmWindow *tmp_win, * Reborder - Removes fvwm border windows * ************************************************************************/ -void Recapture(XEvent *eventp,Window junk,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +Recapture(XEvent *eventp, Window junk, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - XEvent event; - - /* Wow, this grabbing speeds up recapture tremendously! I think that is the - * solution for this weird -blackout option. */ - MyXGrabServer(dpy); - GrabEm(WAIT); - BlackoutScreen(); /* if they want to hide the recapture */ - CaptureAllWindows(); - UnBlackoutScreen(); - /* Throw away queued up events. We don't want user input during a - * recapture. The window the user clicks in might disapper at the very same - * moment and the click goes through to the root window. Not goot */ - while (XCheckMaskEvent(dpy, ButtonPressMask|ButtonReleaseMask| - ButtonMotionMask|PointerMotionMask|EnterWindowMask| - LeaveWindowMask, &event) != False) - ; - UngrabEm(); - MyXUngrabServer(dpy); - XSync(dpy, 0); + XEvent event; + + /* Wow, this grabbing speeds up recapture tremendously! I think that is + * the solution for this weird -blackout option. */ + MyXGrabServer(dpy); + GrabEm(WAIT); + BlackoutScreen(); /* if they want to hide the recapture */ + CaptureAllWindows(); + UnBlackoutScreen(); + /* Throw away queued up events. We don't want user input during a + * recapture. The window the user clicks in might disapper at the very + * same moment and the click goes through to the root window. Not goot + */ + while (XCheckMaskEvent(dpy, + ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | + PointerMotionMask | EnterWindowMask | LeaveWindowMask, + &event) != False) + ; + UngrabEm(); + MyXUngrabServer(dpy); + XSync(dpy, 0); } -void SetGlobalOptions(XEvent *eventp,Window junk,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +SetGlobalOptions(XEvent *eventp, Window junk, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - char *opt; - - /* fvwm_msg(DBG,"SetGlobalOptions","init action == '%s'\n",action); */ - for (action = GetNextOption(action, &opt); opt; - action = GetNextOption(action, &opt)) - { - /* fvwm_msg(DBG,"SetGlobalOptions"," opt == '%s'\n",opt); */ - /* fvwm_msg(DBG,"SetGlobalOptions"," remaining == '%s'\n", - action?action:"(NULL)"); */ - if (StrEquals(opt,"SMARTPLACEMENTISREALLYSMART")) - { - Scr.SmartPlacementIsClever = True; - } - else if (StrEquals(opt,"SMARTPLACEMENTISNORMAL")) - { - Scr.SmartPlacementIsClever = False; - } - else if (StrEquals(opt,"CLICKTOFOCUSDOESNTPASSCLICK")) - { - Scr.ClickToFocusPassesClick = False; - } - else if (StrEquals(opt,"CLICKTOFOCUSPASSESCLICK")) - { - Scr.ClickToFocusPassesClick = True; - } - else if (StrEquals(opt,"CLICKTOFOCUSDOESNTRAISE")) - { - Scr.ClickToFocusRaises = False; - } - else if (StrEquals(opt,"CLICKTOFOCUSRAISES")) - { - Scr.ClickToFocusRaises = True; - } - else if (StrEquals(opt,"MOUSEFOCUSCLICKDOESNTRAISE")) - { - Scr.MouseFocusClickRaises = False; - } - else if (StrEquals(opt,"MOUSEFOCUSCLICKRAISES")) - { - Scr.MouseFocusClickRaises = True; - } - else if (StrEquals(opt,"NOSTIPLEDTITLES")) - { - Scr.StipledTitles = False; - } - else if (StrEquals(opt,"STIPLEDTITLES")) - { - Scr.StipledTitles = True; - } - /* RBW - 11/14/1998 - I'll eventually remove these. */ -/* - else if (StrEquals(opt,"STARTSONPAGEMODIFIESUSPOSITION")) - { - Scr.go.ModifyUSP = True; - } - else if (StrEquals(opt,"STARTSONPAGEHONORSUSPOSITION")) - { - Scr.go.ModifyUSP = False; - } -*/ - else if (StrEquals(opt,"CAPTUREHONORSSTARTSONPAGE")) - { - Scr.go.CaptureHonorsStartsOnPage = True; - } - else if (StrEquals(opt,"CAPTUREIGNORESSTARTSONPAGE")) - { - Scr.go.CaptureHonorsStartsOnPage = False; - } - else if (StrEquals(opt,"RECAPTUREHONORSSTARTSONPAGE")) - { - Scr.go.RecaptureHonorsStartsOnPage = True; - } - else if (StrEquals(opt,"RECAPTUREIGNORESSTARTSONPAGE")) - { - Scr.go.RecaptureHonorsStartsOnPage = False; - } - else if (StrEquals(opt,"ACTIVEPLACEMENTHONORSSTARTSONPAGE")) - { - Scr.go.ActivePlacementHonorsStartsOnPage = True; - } - else if (StrEquals(opt,"ACTIVEPLACEMENTIGNORESSTARTSONPAGE")) - { - Scr.go.ActivePlacementHonorsStartsOnPage = False; - } - else - fvwm_msg(ERR,"SetGlobalOptions","Unknown Global Option '%s'",opt); - if (opt) /* should never be null, but checking anyways... */ - free(opt); - } - if (opt) - free(opt); + char *opt; + + /* fvwm_msg(DBG,"SetGlobalOptions","init action == '%s'\n",action); */ + for (action = GetNextOption(action, &opt); opt; + action = GetNextOption(action, &opt)) { + /* fvwm_msg(DBG,"SetGlobalOptions"," opt == '%s'\n",opt); */ + /* fvwm_msg(DBG,"SetGlobalOptions"," remaining == '%s'\n", + action?action:"(NULL)"); */ + if (StrEquals(opt, "SMARTPLACEMENTISREALLYSMART")) { + Scr.SmartPlacementIsClever = True; + } else if (StrEquals(opt, "SMARTPLACEMENTISNORMAL")) { + Scr.SmartPlacementIsClever = False; + } else if (StrEquals(opt, "CLICKTOFOCUSDOESNTPASSCLICK")) { + Scr.ClickToFocusPassesClick = False; + } else if (StrEquals(opt, "CLICKTOFOCUSPASSESCLICK")) { + Scr.ClickToFocusPassesClick = True; + } else if (StrEquals(opt, "CLICKTOFOCUSDOESNTRAISE")) { + Scr.ClickToFocusRaises = False; + } else if (StrEquals(opt, "CLICKTOFOCUSRAISES")) { + Scr.ClickToFocusRaises = True; + } else if (StrEquals(opt, "MOUSEFOCUSCLICKDOESNTRAISE")) { + Scr.MouseFocusClickRaises = False; + } else if (StrEquals(opt, "MOUSEFOCUSCLICKRAISES")) { + Scr.MouseFocusClickRaises = True; + } else if (StrEquals(opt, "NOSTIPLEDTITLES")) { + Scr.StipledTitles = False; + } else if (StrEquals(opt, "STIPLEDTITLES")) { + Scr.StipledTitles = True; + } else if (StrEquals(opt, "CAPTUREHONORSSTARTSONPAGE")) { + Scr.go.CaptureHonorsStartsOnPage = True; + } else if (StrEquals(opt, "CAPTUREIGNORESSTARTSONPAGE")) { + Scr.go.CaptureHonorsStartsOnPage = False; + } else if (StrEquals(opt, "RECAPTUREHONORSSTARTSONPAGE")) { + Scr.go.RecaptureHonorsStartsOnPage = True; + } else if (StrEquals(opt, "RECAPTUREIGNORESSTARTSONPAGE")) { + Scr.go.RecaptureHonorsStartsOnPage = False; + } else if (StrEquals( + opt, "ACTIVEPLACEMENTHONORSSTARTSONPAGE")) { + Scr.go.ActivePlacementHonorsStartsOnPage = True; + } else if (StrEquals( + opt, "ACTIVEPLACEMENTIGNORESSTARTSONPAGE")) { + Scr.go.ActivePlacementHonorsStartsOnPage = False; + } else + fvwm_msg(ERR, "SetGlobalOptions", + "Unknown Global Option '%s'", opt); + if (opt) /* should never be null, but checking anyways... */ + free(opt); + } + if (opt) + free(opt); } -void Emulate(XEvent *eventp, Window junk, FvwmWindow *tmp_win, - unsigned long context, char *action, int* Module) +void +Emulate(XEvent *eventp, Window junk, FvwmWindow *tmp_win, unsigned long context, + char *action, int *Module) { - char *style; - - GetNextToken(action, &style); - if (!style || StrEquals(style, "fvwm")) - { - Scr.gs.EmulateMWM = False; - Scr.gs.EmulateWIN = False; - } - else if (StrEquals(style, "mwm")) - { - Scr.gs.EmulateMWM = True; - Scr.gs.EmulateWIN = False; - } - else if (StrEquals(style, "win")) - { - Scr.gs.EmulateMWM = False; - Scr.gs.EmulateWIN = True; - } - else - { - fvwm_msg(ERR, "Emulate", "Unknown style '%s'", style); - } - free(style); - ApplyDefaultFontAndColors(); - return; + char *style; + + GetNextToken(action, &style); + if (!style || StrEquals(style, "fvwm")) { + Scr.gs.EmulateMWM = False; + Scr.gs.EmulateWIN = False; + } else if (StrEquals(style, "mwm")) { + Scr.gs.EmulateMWM = True; + Scr.gs.EmulateWIN = False; + } else if (StrEquals(style, "win")) { + Scr.gs.EmulateMWM = False; + Scr.gs.EmulateWIN = True; + } else { + fvwm_msg(ERR, "Emulate", "Unknown style '%s'", style); + } + free(style); + ApplyDefaultFontAndColors(); + return; } -void SetColorLimit(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +SetColorLimit(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - int val; + int val; - if (GetIntegerArguments(action, NULL, &val, 1) != 1) - { - fvwm_msg(ERR,"SetColorLimit","ColorLimit requires one argument"); - return; - } + if (GetIntegerArguments(action, NULL, &val, 1) != 1) { + fvwm_msg( + ERR, "SetColorLimit", "ColorLimit requires one argument"); + return; + } - Scr.ColorLimit = (long)val; + Scr.ColorLimit = (long)val; } - extern float rgpctMovementDefault[32]; extern int cpctMovementDefault; extern int cmsDelayDefault; - /* set animation parameters */ -void set_animation(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +set_animation(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - char *opt; - int delay; - float pct; - int i = 0; - - action = GetNextToken(action, &opt); - if (!opt || sscanf(opt,"%d",&delay) != 1) { - fvwm_msg(ERR,"SetAnimation", - "Improper milli-second delay as first argument"); - if (opt) - free(opt); - return; - } - free(opt); - if (delay > 500) { - fvwm_msg(WARN,"SetAnimation", - "Using longer than .5 seconds as between frame animation delay"); - } - cmsDelayDefault = delay; - action = GetNextToken(action, &opt); - while (opt) { - if (sscanf(opt,"%f",&pct) != 1) { - fvwm_msg(ERR,"SetAnimation", - "Use fractional values ending in 1.0 as args 2 and on"); - free(opt); - return; - } - rgpctMovementDefault[i++] = pct; - free(opt); - action = GetNextToken(action, &opt); - } - /* No pct entries means don't change them at all */ - if (i>0 && rgpctMovementDefault[i-1] != 1.0) { - rgpctMovementDefault[i++] = 1.0; - } + char *opt; + int delay; + float pct; + int i = 0; + + action = GetNextToken(action, &opt); + if (!opt || sscanf(opt, "%d", &delay) != 1) { + fvwm_msg(ERR, "SetAnimation", + "Improper milli-second delay as first argument"); + if (opt) + free(opt); + return; + } + free(opt); + if (delay > 500) { + fvwm_msg(WARN, "SetAnimation", + "Using longer than .5 seconds as between frame animation " + "delay"); + } + cmsDelayDefault = delay; + action = GetNextToken(action, &opt); + while (opt) { + if (sscanf(opt, "%f", &pct) != 1) { + fvwm_msg(ERR, "SetAnimation", + "Use fractional values ending in 1.0 as args 2 and " + "on"); + free(opt); + return; + } + rgpctMovementDefault[i++] = pct; + free(opt); + action = GetNextToken(action, &opt); + } + /* No pct entries means don't change them at all */ + if (i > 0 && rgpctMovementDefault[i - 1] != 1.0) { + rgpctMovementDefault[i++] = 1.0; + } } Index: fvwm/fvwm/colormaps.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/colormaps.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/colormaps.c --- fvwm/fvwm/colormaps.c +++ fvwm/fvwm/colormaps.c @@ -9,16 +9,16 @@ * warrantees of any sort whatsoever are given or implied or anything. ****************************************************************************/ -#include "config.h" - +#include #include #include + +#include "config.h" #include "fvwm.h" -#include #include "misc.h" +#include "module.h" #include "parse.h" #include "screen.h" -#include "module.h" FvwmWindow *colormap_win; Colormap last_cmap = None; @@ -34,66 +34,56 @@ extern FvwmWindow *Tmp_win; * manager should do that, so we must set it correctly). * ***********************************************************************/ -void HandleColormapNotify(void) +void +HandleColormapNotify(void) { - XColormapEvent *cevent = (XColormapEvent *)&Event; - Bool ReInstall = False; - - - if(!Tmp_win) - { - return; - } - if(cevent->new) - { - XGetWindowAttributes(dpy,Tmp_win->w,&(Tmp_win->attr)); - if((Tmp_win == colormap_win)&&(Tmp_win->number_cmap_windows == 0)) - last_cmap = Tmp_win->attr.colormap; - ReInstall = True; - } - else if((cevent->state == ColormapUninstalled)&& - (last_cmap == cevent->colormap)) - { - /* Some window installed its colormap, change it back */ - ReInstall = True; - } + XColormapEvent *cevent = (XColormapEvent *)&Event; + Bool ReInstall = False; - while(XCheckTypedEvent(dpy,ColormapNotify,&Event)) - { - if (XFindContext (dpy, cevent->window, - FvwmContext, (caddr_t *) &Tmp_win) == XCNOENT) - Tmp_win = NULL; - if((Tmp_win)&&(cevent->new)) - { - XGetWindowAttributes(dpy,Tmp_win->w,&(Tmp_win->attr)); - if((Tmp_win == colormap_win)&&(Tmp_win->number_cmap_windows == 0)) - last_cmap = Tmp_win->attr.colormap; - ReInstall = True; + if (!Tmp_win) { + return; } - else if((Tmp_win)&& - (cevent->state == ColormapUninstalled)&& - (last_cmap == cevent->colormap)) - { - /* Some window installed its colormap, change it back */ - ReInstall = True; + if (cevent->new) { + XGetWindowAttributes(dpy, Tmp_win->w, &(Tmp_win->attr)); + if ((Tmp_win == colormap_win) && + (Tmp_win->number_cmap_windows == 0)) + last_cmap = Tmp_win->attr.colormap; + ReInstall = True; + } else if ((cevent->state == ColormapUninstalled) && + (last_cmap == cevent->colormap)) { + /* Some window installed its colormap, change it back */ + ReInstall = True; } - else if((Tmp_win)&& - (cevent->state == ColormapInstalled)&& - (last_cmap == cevent->colormap)) - { - /* The last color map installed was the correct one. Don't - * change anything */ - ReInstall = False; + + while (XCheckTypedEvent(dpy, ColormapNotify, &Event)) { + if (XFindContext(dpy, cevent->window, FvwmContext, + (caddr_t *)&Tmp_win) == XCNOENT) + Tmp_win = NULL; + if ((Tmp_win) && (cevent->new)) { + XGetWindowAttributes(dpy, Tmp_win->w, &(Tmp_win->attr)); + if ((Tmp_win == colormap_win) && + (Tmp_win->number_cmap_windows == 0)) + last_cmap = Tmp_win->attr.colormap; + ReInstall = True; + } else if ((Tmp_win) && + (cevent->state == ColormapUninstalled) && + (last_cmap == cevent->colormap)) { + /* Some window installed its colormap, change it back */ + ReInstall = True; + } else if ((Tmp_win) && (cevent->state == ColormapInstalled) && + (last_cmap == cevent->colormap)) { + /* The last color map installed was the correct one. + * Don't change anything */ + ReInstall = False; + } } - } - /* Reinstall the colormap that we think should be installed, - * UNLESS and unrecognized window has the focus - it might be - * an override-redirect window that has its own colormap. */ - if((ReInstall)&&(Scr.UnknownWinFocused == None)) - { - XInstallColormap(dpy,last_cmap); - } + /* Reinstall the colormap that we think should be installed, + * UNLESS and unrecognized window has the focus - it might be + * an override-redirect window that has its own colormap. */ + if ((ReInstall) && (Scr.UnknownWinFocused == None)) { + XInstallColormap(dpy, last_cmap); + } } /************************************************************************ @@ -101,9 +91,10 @@ void HandleColormapNotify(void) * Re-Install the active colormap * *************************************************************************/ -void ReInstallActiveColormap(void) +void +ReInstallActiveColormap(void) { - InstallWindowColormaps(colormap_win); + InstallWindowColormaps(colormap_win); } /*********************************************************************** @@ -118,72 +109,57 @@ void ReInstallActiveColormap(void) * ************************************************************************/ -void InstallWindowColormaps (FvwmWindow *tmp) +void +InstallWindowColormaps(FvwmWindow *tmp) { - int i; - XWindowAttributes attributes; - Window w; - Bool ThisWinInstalled = False; - - - /* If no window, then install root colormap */ - if(!tmp) - tmp = &Scr.FvwmRoot; - - colormap_win = tmp; - /* Save the colormap to be loaded for when force loading of - * root colormap(s) ends. - */ - Scr.pushed_window = tmp; - /* Don't load any new colormap if root colormap(s) has been - * force loaded. - */ - if (Scr.root_pushes) - { - return; - } - - if(tmp->number_cmap_windows > 0) - { - for(i=tmp->number_cmap_windows -1; i>=0;i--) - { - w = tmp->cmap_windows[i]; - if(w == tmp->w) - ThisWinInstalled = True; - XGetWindowAttributes(dpy,w,&attributes); + int i; + XWindowAttributes attributes; + Window w; + Bool ThisWinInstalled = False; + + /* If no window, then install root colormap */ + if (!tmp) + tmp = &Scr.FvwmRoot; + + colormap_win = tmp; + /* Save the colormap to be loaded for when force loading of + * root colormap(s) ends. + */ + Scr.pushed_window = tmp; + /* Don't load any new colormap if root colormap(s) has been + * force loaded. + */ + if (Scr.root_pushes) { + return; + } - /* - * On Sun X servers, don't install 24 bit TrueColor colourmaps. - * Despite what the server says, these colourmaps are always - * installed. - */ - if(last_cmap != attributes.colormap -#if defined(sun) && defined(TRUECOLOR_ALWAYS_INSTALLED) - && !(attributes.depth == 24 && attributes.visual->class == TrueColor) -#endif - ) - { - last_cmap = attributes.colormap; - XInstallColormap(dpy,attributes.colormap); - } + if (tmp->number_cmap_windows > 0) { + for (i = tmp->number_cmap_windows - 1; i >= 0; i--) { + w = tmp->cmap_windows[i]; + if (w == tmp->w) + ThisWinInstalled = True; + XGetWindowAttributes(dpy, w, &attributes); + + /* + * On Sun X servers, don't install 24 bit TrueColor + * colourmaps. Despite what the server says, these + * colourmaps are always installed. + */ + if (last_cmap != attributes.colormap) { + last_cmap = attributes.colormap; + XInstallColormap(dpy, attributes.colormap); + } + } } - } - if(!ThisWinInstalled) - { - if(last_cmap != tmp->attr.colormap -#if defined(sun) && defined(TRUECOLOR_ALWAYS_INSTALLED) - && !(tmp->attr.depth == 24 && tmp->attr.visual->class == TrueColor) -#endif - ) - { - last_cmap = tmp->attr.colormap; - XInstallColormap(dpy,tmp->attr.colormap); + if (!ThisWinInstalled) { + if (last_cmap != tmp->attr.colormap) { + last_cmap = tmp->attr.colormap; + XInstallColormap(dpy, tmp->attr.colormap); + } } - } } - /*********************************************************************** * * Procedures: @@ -201,17 +177,17 @@ void InstallWindowColormaps (FvwmWindow *tmp) * Enter or Leave Notify events are queued, indicating some * other colormap list would potentially be loaded anyway. ***********************************************************************/ -void InstallRootColormap() +void +InstallRootColormap() { - FvwmWindow *tmp; - if (Scr.root_pushes == 0) - { - tmp = Scr.pushed_window; - InstallWindowColormaps(&Scr.FvwmRoot); - Scr.pushed_window = tmp; - } - Scr.root_pushes++; - return; + FvwmWindow *tmp; + if (Scr.root_pushes == 0) { + tmp = Scr.pushed_window; + InstallWindowColormaps(&Scr.FvwmRoot); + Scr.pushed_window = tmp; + } + Scr.root_pushes++; + return; } /*************************************************************************** @@ -220,21 +196,19 @@ void InstallRootColormap() * If we peel off the last layer, re-install th e application colormap * ***************************************************************************/ -void UninstallRootColormap() +void +UninstallRootColormap() { - if (Scr.root_pushes) - Scr.root_pushes--; + if (Scr.root_pushes) + Scr.root_pushes--; - if (!Scr.root_pushes) - { - InstallWindowColormaps(Scr.pushed_window); - } + if (!Scr.root_pushes) { + InstallWindowColormaps(Scr.pushed_window); + } - return; + return; } - - /***************************************************************************** * * Gets the WM_COLORMAP_WINDOWS property from the window @@ -242,17 +216,15 @@ void UninstallRootColormap() * use it. These seem to occur mostly on SGI machines. * ****************************************************************************/ -void FetchWmColormapWindows (FvwmWindow *tmp) +void +FetchWmColormapWindows(FvwmWindow *tmp) { - if(tmp->cmap_windows != (Window *)NULL) - XFree((void *)tmp->cmap_windows); + if (tmp->cmap_windows != (Window *)NULL) + XFree((void *)tmp->cmap_windows); - if(!XGetWMColormapWindows (dpy, tmp->w, &(tmp->cmap_windows), - &(tmp->number_cmap_windows))) - { - tmp->number_cmap_windows = 0; - tmp->cmap_windows = NULL; - } + if (!XGetWMColormapWindows(dpy, tmp->w, &(tmp->cmap_windows), + &(tmp->number_cmap_windows))) { + tmp->number_cmap_windows = 0; + tmp->cmap_windows = NULL; + } } - - Index: fvwm/fvwm/colors.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/colors.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/colors.c --- fvwm/fvwm/colors.c +++ fvwm/fvwm/colors.c @@ -10,22 +10,18 @@ * ************************************************************************* */ - -#include "config.h" - -#include -#include -#include +#include +#include #include -#include #include -#include #include +#include +#include +#include +#include +#include -#include -#include - - +#include "config.h" #include "fvwm.h" #include "menus.h" #include "misc.h" @@ -39,47 +35,45 @@ * want to do this once, hence the first_time flag. * ***********************************************************************/ -void CreateGCs(void) +void +CreateGCs(void) { - XGCValues gcv; - unsigned long gcm; + XGCValues gcv; + unsigned long gcm; - /* create scratch GC's */ - gcm = GCFunction|GCPlaneMask|GCGraphicsExposures|GCLineWidth; - gcv.line_width = 0; - gcv.function = GXcopy; - gcv.plane_mask = AllPlanes; - gcv.graphics_exposures = False; + /* create scratch GC's */ + gcm = GCFunction | GCPlaneMask | GCGraphicsExposures | GCLineWidth; + gcv.line_width = 0; + gcv.function = GXcopy; + gcv.plane_mask = AllPlanes; + gcv.graphics_exposures = False; - Scr.ScratchGC1 = XCreateGC(dpy, Scr.Root, gcm, &gcv); - Scr.ScratchGC2 = XCreateGC(dpy, Scr.Root, gcm, &gcv); - Scr.ScratchGC3 = XCreateGC(dpy, Scr.Root, gcm, &gcv); + Scr.ScratchGC1 = XCreateGC(dpy, Scr.Root, gcm, &gcv); + Scr.ScratchGC2 = XCreateGC(dpy, Scr.Root, gcm, &gcv); + Scr.ScratchGC3 = XCreateGC(dpy, Scr.Root, gcm, &gcv); #if defined(PIXMAP_BUTTONS) || defined(GRADIENT_BUTTONS) - Scr.TransMaskGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); + Scr.TransMaskGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); #endif } - /**************************************************************************** * * Loads a single color * ****************************************************************************/ -Pixel GetColor(char *name) +Pixel +GetColor(char *name) { - XColor color; + XColor color; - color.pixel = 0; - if (!XParseColor (dpy, Scr.FvwmRoot.attr.colormap, name, &color)) - { - nocolor("parse",name); - } - else if(!XAllocColor (dpy, Scr.FvwmRoot.attr.colormap, &color)) - { - nocolor("alloc",name); - } - return color.pixel; + color.pixel = 0; + if (!XParseColor(dpy, Scr.FvwmRoot.attr.colormap, name, &color)) { + nocolor("parse", name); + } else if (!XAllocColor(dpy, Scr.FvwmRoot.attr.colormap, &color)) { + nocolor("alloc", name); + } + return color.pixel; } /**************************************************************************** @@ -87,16 +81,18 @@ Pixel GetColor(char *name) * Free an array of colours (n colours), never free black * ****************************************************************************/ -void FreeColors(Pixel *pixels, int n) +void +FreeColors(Pixel *pixels, int n) { - int i; - - /* We don't ever free "black" - dirty hack to allow freeing colours at all */ - for (i = 0; i < n; i++) - { - if (pixels[i] != 0) - XFreeColors(dpy, Scr.FvwmRoot.attr.colormap, pixels + i, 1, 0); - } + int i; + + /* We don't ever free "black" - dirty hack to allow freeing colours at + * all */ + for (i = 0; i < n; i++) { + if (pixels[i] != 0) + XFreeColors( + dpy, Scr.FvwmRoot.attr.colormap, pixels + i, 1, 0); + } } #ifdef GRADIENT_BUTTONS @@ -105,39 +101,39 @@ void FreeColors(Pixel *pixels, int n) * Allocates a nonlinear color gradient (veliaa@rpi.edu) * ****************************************************************************/ -Pixel *AllocNonlinearGradient(char *s_colors[], int clen[], - int nsegs, int npixels) +Pixel * +AllocNonlinearGradient(char *s_colors[], int clen[], int nsegs, int npixels) { - Pixel *pixels = (Pixel *)safemalloc(sizeof(Pixel) * npixels); - int i = 0, curpixel = 0, perc = 0; - if (nsegs < 1) { - fvwm_msg(ERR,"AllocNonlinearGradient", - "must specify at least one segment"); - free(pixels); - return NULL; - } - for (; i < npixels; i++) - pixels[i] = 0; - - for (i = 0; (i < nsegs) && (curpixel < npixels) && (perc <= 100); ++i) { - Pixel *p; - int j = 0, n = clen[i] * npixels / 100; - p = AllocLinearGradient(s_colors[i], s_colors[i + 1], n); - if (!p) { - fvwm_msg(ERR, "AllocNonlinearGradient", - "couldn't allocate gradient"); - free(pixels); - return NULL; + Pixel *pixels = (Pixel *)xmalloc(sizeof(Pixel) * npixels); + int i = 0, curpixel = 0, perc = 0; + if (nsegs < 1) { + fvwm_msg(ERR, "AllocNonlinearGradient", + "must specify at least one segment"); + free(pixels); + return NULL; + } + for (; i < npixels; i++) + pixels[i] = 0; + + for (i = 0; (i < nsegs) && (curpixel < npixels) && (perc <= 100); ++i) { + Pixel *p; + int j = 0, n = clen[i] * npixels / 100; + p = AllocLinearGradient(s_colors[i], s_colors[i + 1], n); + if (!p) { + fvwm_msg(ERR, "AllocNonlinearGradient", + "couldn't allocate gradient"); + free(pixels); + return NULL; + } + for (; j < n; ++j) + pixels[curpixel + j] = p[j]; + perc += clen[i]; + curpixel += n; + free(p); } - for (; j < n; ++j) - pixels[curpixel + j] = p[j]; - perc += clen[i]; - curpixel += n; - free(p); - } - for (i = curpixel; i < npixels; ++i) - pixels[i] = pixels[i - 1]; - return pixels; + for (i = curpixel; i < npixels; ++i) + pixels[i] = pixels[i - 1]; + return pixels; } /**************************************************************************** @@ -145,52 +141,57 @@ Pixel *AllocNonlinearGradient(char *s_colors[], int clen[], * Allocates a linear color gradient (veliaa@rpi.edu) * ****************************************************************************/ -Pixel *AllocLinearGradient(char *s_from, char *s_to, int npixels) +Pixel * +AllocLinearGradient(char *s_from, char *s_to, int npixels) { - Pixel *pixels; - XColor from, to, c; - int r, dr, g, dg, b, db; - int i = 0, got_all = 1; - - if (npixels < 1) { - fvwm_msg(ERR, "AllocLinearGradient", "Invalid number of pixels: %d", - npixels); - return NULL; - } - if (!s_from || !XParseColor(dpy, Scr.FvwmRoot.attr.colormap, s_from, - &from)) { - nocolor("parse", s_from); - return NULL; - } - if (!s_to || !XParseColor(dpy, Scr.FvwmRoot.attr.colormap, s_to, &to)) { - nocolor("parse", s_to); - return NULL; - } - c = from; - r = from.red; dr = (to.red - from.red) / npixels; - g = from.green; dg = (to.green - from.green) / npixels; - b = from.blue; db = (to.blue - from.blue) / npixels; - pixels = (Pixel *)safemalloc(sizeof(Pixel) * npixels); - c.flags = DoRed | DoGreen | DoBlue; - for (; i < npixels; ++i) - { - if (!XAllocColor(dpy, Scr.FvwmRoot.attr.colormap, &c)) - got_all = 0; - pixels[ i ] = c.pixel; - c.red = (unsigned short) (r += dr); - c.green = (unsigned short) (g += dg); - c.blue = (unsigned short) (b += db); - } - if (!got_all) { - char s[256]; - snprintf(s, 256, "color gradient %s to %s", s_from, s_to); - nocolor("alloc", s); - } - return pixels; + Pixel *pixels; + XColor from, to, c; + int r, dr, g, dg, b, db; + int i = 0, got_all = 1; + + if (npixels < 1) { + fvwm_msg(ERR, "AllocLinearGradient", + "Invalid number of pixels: %d", npixels); + return NULL; + } + if (!s_from || + !XParseColor(dpy, Scr.FvwmRoot.attr.colormap, s_from, &from)) { + nocolor("parse", s_from); + return NULL; + } + if (!s_to || !XParseColor(dpy, Scr.FvwmRoot.attr.colormap, s_to, &to)) { + nocolor("parse", s_to); + return NULL; + } + c = from; + r = from.red; + dr = (to.red - from.red) / npixels; + g = from.green; + dg = (to.green - from.green) / npixels; + b = from.blue; + db = (to.blue - from.blue) / npixels; + pixels = (Pixel *)xmalloc(sizeof(Pixel) * npixels); + c.flags = DoRed | DoGreen | DoBlue; + for (; i < npixels; ++i) { + if (!XAllocColor(dpy, Scr.FvwmRoot.attr.colormap, &c)) + got_all = 0; + pixels[i] = c.pixel; + c.red = (unsigned short)(r += dr); + c.green = (unsigned short)(g += dg); + c.blue = (unsigned short)(b += db); + } + if (!got_all) { + char s[256]; + snprintf(s, 256, "color gradient %s to %s", s_from, s_to); + nocolor("alloc", s); + } + return pixels; } #endif /* GRADIENT_BUTTONS */ -void nocolor(char *note, char *name) +void +nocolor(char *note, char *name) { - fvwm_msg(ERR,"nocolor","can't %s color %s", note, name ? name : ""); + fvwm_msg( + ERR, "nocolor", "can't %s color %s", note, name ? name : ""); } Index: fvwm/fvwm/complex.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/complex.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/complex.c --- fvwm/fvwm/complex.c +++ fvwm/fvwm/complex.c @@ -5,20 +5,19 @@ * as long as the copyright notice is preserved ****************************************************************************/ -#include "config.h" - -#include +#include #include +#include #include -#include #include +#include "config.h" #include "fvwm.h" #include "menus.h" #include "misc.h" +#include "module.h" #include "parse.h" #include "screen.h" -#include "module.h" /***************************************************************************** * @@ -26,36 +25,34 @@ * clicking, but is moving the cursor * ****************************************************************************/ -static Bool IsClick(int x,int y,long EndMask, XEvent *d) +static Bool +IsClick(int x, int y, long EndMask, XEvent *d) { - int xcurrent,ycurrent,total = 0; - Time t0; - extern Time lastTimestamp; + int xcurrent, ycurrent, total = 0; + Time t0; + extern Time lastTimestamp; - xcurrent = x; - ycurrent = y; - t0 = lastTimestamp; + xcurrent = x; + ycurrent = y; + t0 = lastTimestamp; - while((total < Scr.ClickTime)&& - (x - xcurrent < 3)&&(x - xcurrent > -3)&& - (y - ycurrent < 3)&&(y - ycurrent > -3)&& - ((lastTimestamp - t0) < Scr.ClickTime)) - { - usleep(20000); - total+=20; - if(XCheckMaskEvent (dpy,EndMask, d)) - { - StashEventTime(d); - return True; + while ((total < Scr.ClickTime) && (x - xcurrent < 3) && + (x - xcurrent > -3) && (y - ycurrent < 3) && + (y - ycurrent > -3) && ((lastTimestamp - t0) < Scr.ClickTime)) { + usleep(20000); + total += 20; + if (XCheckMaskEvent(dpy, EndMask, d)) { + StashEventTime(d); + return True; + } + if (XCheckMaskEvent( + dpy, ButtonMotionMask | PointerMotionMask, d)) { + xcurrent = d->xmotion.x_root; + ycurrent = d->xmotion.y_root; + StashEventTime(d); + } } - if(XCheckMaskEvent (dpy,ButtonMotionMask|PointerMotionMask, d)) - { - xcurrent = d->xmotion.x_root; - ycurrent = d->xmotion.y_root; - StashEventTime(d); - } - } - return False; + return False; } /***************************************************************************** @@ -63,240 +60,216 @@ static Bool IsClick(int x,int y,long EndMask, XEvent *d) * 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) +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; + 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]); - /* see functions.c to find out which functions need a window to operate on */ - 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); - NeedsTarget = mi->func_needs_window; - if(isupper(c)) - c=tolower(c); - if(c==DOUBLE_CLICK) - { - HaveDoubleClick = True; - Persist = True; + mr = FindPopup(action); + if (mr == NULL) { + if (!desperate) + fvwm_msg(ERR, "ComplexFunction", "No such function %s", + action); + return; } - 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); + 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]); + /* see functions.c to find out which functions need a window to operate + * on */ + 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); + NeedsTarget = mi->func_needs_window; + 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; } - 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 (!Persist) { + for (i = 0; i < 10; i++) + if (arguments[i] != NULL) + free(arguments[i]); + return; } - } - if(!GrabEm(SELECT)) - { - XBell(dpy, 0); - 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); + /* 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, 0); + 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; - } + /* 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; + /* 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 = 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; } - mi = mi->next; - } - WaitForButtonsUp(); - UngrabEm(); - for(i=0;i<10;i++) - if(arguments[i] != NULL)free(arguments[i]); + WaitForButtonsUp(); + UngrabEm(); + for (i = 0; i < 10; i++) + if (arguments[i] != NULL) + free(arguments[i]); } - -char *expand(char *input, char *arguments[],FvwmWindow *tmp_win) +char * +expand(char *input, char *arguments[], FvwmWindow *tmp_win) { - int l,i,l2,n,k,j; - char *out; - int addto = 0; /*special cas if doing addtofunc */ - size_t outlen; + int l, i, l2, n, k, j; + char *out; + int addto = 0; /*special cas if doing addtofunc */ + size_t outlen; - l = strlen(input); - l2 = l; + l = strlen(input); + l2 = l; - if(strncasecmp(input, "AddToFunc", 9) == 0 || input[0] == '+') - { - addto = 1; - } - i=0; - while(i= 0)&&(n <= 9)&&(arguments[n] != NULL)) - { - l2 += strlen(arguments[n])-2; - i++; - } - else if(input[i+1]=='w' || input[i+1] == 'd') - { - l2 += 16; - i++; - } + if (strncasecmp(input, "AddToFunc", 9) == 0 || input[0] == '+') { + addto = 1; + } + i = 0; + while (i < l) { + if (input[i] == '$') { + n = input[i + 1] - '0'; + if ((n >= 0) && (n <= 9) && (arguments[n] != NULL)) { + l2 += strlen(arguments[n]) - 2; + i++; + } else if (input[i + 1] == 'w' || input[i + 1] == 'd') { + l2 += 16; + i++; + } + } + i++; } - i++; - } - outlen = l2 + 1; - out = safemalloc(outlen); - i=0; - j=0; - while(i= 0)&&(n <= 9)) - { - if (arguments[n] != NULL) - { - for(k=0;kw); - else - snprintf(&out[j],outlen -j,"$w"); - j += strlen(&out[j]); - i++; - } - else if(input[i+1] == 'd') - { - snprintf(&out[j], outlen - j,"%d", Scr.CurrentDesk); - j += strlen(&out[j]); - i++; - } - else if(input[i+1] == '$') - { - out[j++] = '$'; - i++; - } - else - out[j++] = input[i]; + outlen = l2 + 1; + out = xmalloc(outlen); + i = 0; + j = 0; + while (i < l) { + if (input[i] == '$') { + n = input[i + 1] - '0'; + if ((n >= 0) && (n <= 9)) { + if (arguments[n] != NULL) { + for (k = 0; k < strlen(arguments[n]); + k++) + out[j++] = arguments[n][k]; + i++; + } else if (addto == 1) { + out[j++] = '$'; + } else { + i++; + if (isspace(input[i + 1])) + i++; /*eliminates extra white + space*/ + } + } else if (input[i + 1] == 'w') { + if (tmp_win) + snprintf(&out[j], outlen - j, "0x%x", + (unsigned int)tmp_win->w); + else + snprintf(&out[j], outlen - j, "$w"); + j += strlen(&out[j]); + i++; + } else if (input[i + 1] == 'd') { + snprintf( + &out[j], outlen - j, "%d", Scr.CurrentDesk); + j += strlen(&out[j]); + i++; + } else if (input[i + 1] == '$') { + out[j++] = '$'; + i++; + } else + out[j++] = input[i]; + } else + out[j++] = input[i]; + i++; } - else - out[j++] = input[i]; - i++; - } - out[j] = 0; - return out; + out[j] = 0; + return out; } Index: fvwm/fvwm/decorations.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/decorations.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/decorations.c --- fvwm/fvwm/decorations.c +++ fvwm/fvwm/decorations.c @@ -33,65 +33,65 @@ * ****************************************************************************/ -#include "config.h" - +#include +#include #include -#include #include +#include + +#include "config.h" #include "fvwm.h" -#include -#include +#include "lang-strings.h" +#include "menus.h" #include "misc.h" -#include "screen.h" #include "parse.h" -#include "menus.h" -#include "lang-strings.h" - +#include "screen.h" extern Atom _XA_MwmAtom; /* Motif window hints */ -typedef struct -{ - unsigned long flags; - unsigned long functions; - unsigned long decorations; - long inputMode; +typedef struct { + unsigned long flags; + unsigned long functions; + unsigned long decorations; + long inputMode; } PropMotifWmHints; -typedef PropMotifWmHints PropMwmHints; +typedef PropMotifWmHints PropMwmHints; /* Motif window hints */ -#define MWM_HINTS_FUNCTIONS (1L << 0) -#define MWM_HINTS_DECORATIONS (1L << 1) +#define MWM_HINTS_FUNCTIONS (1L << 0) +#define MWM_HINTS_DECORATIONS (1L << 1) /* bit definitions for MwmHints.functions */ -#define MWM_FUNC_ALL (1L << 0) -#define MWM_FUNC_RESIZE (1L << 1) -#define MWM_FUNC_MOVE (1L << 2) -#define MWM_FUNC_MINIMIZE (1L << 3) -#define MWM_FUNC_MAXIMIZE (1L << 4) -#define MWM_FUNC_CLOSE (1L << 5) +#define MWM_FUNC_ALL (1L << 0) +#define MWM_FUNC_RESIZE (1L << 1) +#define MWM_FUNC_MOVE (1L << 2) +#define MWM_FUNC_MINIMIZE (1L << 3) +#define MWM_FUNC_MAXIMIZE (1L << 4) +#define MWM_FUNC_CLOSE (1L << 5) /* bit definitions for MwmHints.decorations */ -#define MWM_DECOR_ALL (1L << 0) -#define MWM_DECOR_BORDER (1L << 1) -#define MWM_DECOR_RESIZEH (1L << 2) -#define MWM_DECOR_TITLE (1L << 3) -#define MWM_DECOR_MENU (1L << 4) -#define MWM_DECOR_MINIMIZE (1L << 5) -#define MWM_DECOR_MAXIMIZE (1L << 6) +#define MWM_DECOR_ALL (1L << 0) +#define MWM_DECOR_BORDER (1L << 1) +#define MWM_DECOR_RESIZEH (1L << 2) +#define MWM_DECOR_TITLE (1L << 3) +#define MWM_DECOR_MENU (1L << 4) +#define MWM_DECOR_MINIMIZE (1L << 5) +#define MWM_DECOR_MAXIMIZE (1L << 6) -#define PROP_MOTIF_WM_HINTS_ELEMENTS 4 -#define PROP_MWM_HINTS_ELEMENTS PROP_MOTIF_WM_HINTS_ELEMENTS +#define PROP_MOTIF_WM_HINTS_ELEMENTS 4 +#define PROP_MWM_HINTS_ELEMENTS PROP_MOTIF_WM_HINTS_ELEMENTS /* bit definitions for OL hints; I just * made these up, OL stores hints as atoms */ -#define OL_DECOR_CLOSE (1L << 0) -#define OL_DECOR_RESIZEH (1L << 1) -#define OL_DECOR_HEADER (1L << 2) -#define OL_DECOR_ICON_NAME (1L << 3) -#define OL_DECOR_ALL (OL_DECOR_CLOSE | OL_DECOR_RESIZEH | OL_DECOR_HEADER | OL_DECOR_ICON_NAME) +#define OL_DECOR_CLOSE (1L << 0) +#define OL_DECOR_RESIZEH (1L << 1) +#define OL_DECOR_HEADER (1L << 2) +#define OL_DECOR_ICON_NAME (1L << 3) +#define OL_DECOR_ALL \ + (OL_DECOR_CLOSE | OL_DECOR_RESIZEH | OL_DECOR_HEADER | \ + OL_DECOR_ICON_NAME) extern FvwmWindow *Tmp_win; @@ -100,23 +100,22 @@ extern FvwmWindow *Tmp_win; * Reads the property MOTIF_WM_HINTS * *****************************************************************************/ -void GetMwmHints(FvwmWindow *t) +void +GetMwmHints(FvwmWindow *t) { - int actual_format; - Atom actual_type; - unsigned long nitems, bytesafter; - - if(XGetWindowProperty (dpy, t->w, _XA_MwmAtom, 0L, 20L, False, - _XA_MwmAtom, &actual_type, &actual_format, &nitems, - &bytesafter,(unsigned char **)&t->mwm_hints)==Success) - { - if(nitems >= PROP_MOTIF_WM_HINTS_ELEMENTS) - { - return; + int actual_format; + Atom actual_type; + unsigned long nitems, bytesafter; + + if (XGetWindowProperty(dpy, t->w, _XA_MwmAtom, 0L, 20L, False, + _XA_MwmAtom, &actual_type, &actual_format, &nitems, &bytesafter, + (unsigned char **)&t->mwm_hints) == Success) { + if (nitems >= PROP_MOTIF_WM_HINTS_ELEMENTS) { + return; + } } - } - t->mwm_hints = NULL; + t->mwm_hints = NULL; } /**************************************************************************** @@ -146,318 +145,318 @@ void GetMwmHints(FvwmWindow *t) * (M&T Books), and the olvwm source code (available at ftp.x.org in * /R5contrib). *****************************************************************************/ -void GetOlHints(FvwmWindow *t) +void +GetOlHints(FvwmWindow *t) { - int actual_format; - Atom actual_type; - unsigned long nitems, bytesafter; - Atom *hints; - int i; - Atom win_type; - - t->ol_hints = OL_DECOR_ALL; - - if (XGetWindowProperty (dpy, t->w, _XA_OL_WIN_ATTR, 0L, 20L, False, - _XA_OL_WIN_ATTR, &actual_type, &actual_format, &nitems, - &bytesafter,(unsigned char **)&hints)==Success) - { - if (nitems > 0) - { - if (nitems == 3) - win_type = hints[0]; - else - win_type = hints[1]; - - /* got this from olvwm and sort of mapped it to - * FVWM/MWM hints */ - if (win_type == _XA_OL_WT_BASE) - t->ol_hints = OL_DECOR_ALL; - else if (win_type == _XA_OL_WT_CMD) - t->ol_hints = OL_DECOR_ALL & ~OL_DECOR_CLOSE; - else if (win_type == _XA_OL_WT_HELP) - t->ol_hints = OL_DECOR_ALL & ~(OL_DECOR_CLOSE | OL_DECOR_RESIZEH); - else if (win_type == _XA_OL_WT_NOTICE) - t->ol_hints = OL_DECOR_ALL & ~(OL_DECOR_CLOSE | OL_DECOR_RESIZEH | - OL_DECOR_HEADER | OL_DECOR_ICON_NAME); - else if (win_type == _XA_OL_WT_OTHER) - t->ol_hints = 0; - else - t->ol_hints = OL_DECOR_ALL; - - if (nitems == 3) - t->ol_hints &= ~OL_DECOR_ICON_NAME; + int actual_format; + Atom actual_type; + unsigned long nitems, bytesafter; + Atom *hints; + int i; + Atom win_type; + + t->ol_hints = OL_DECOR_ALL; + + if (XGetWindowProperty(dpy, t->w, _XA_OL_WIN_ATTR, 0L, 20L, False, + _XA_OL_WIN_ATTR, &actual_type, &actual_format, &nitems, + &bytesafter, (unsigned char **)&hints) == Success) { + if (nitems > 0) { + if (nitems == 3) + win_type = hints[0]; + else + win_type = hints[1]; + + /* got this from olvwm and sort of mapped it to + * FVWM/MWM hints */ + if (win_type == _XA_OL_WT_BASE) + t->ol_hints = OL_DECOR_ALL; + else if (win_type == _XA_OL_WT_CMD) + t->ol_hints = OL_DECOR_ALL & ~OL_DECOR_CLOSE; + else if (win_type == _XA_OL_WT_HELP) + t->ol_hints = + OL_DECOR_ALL & + ~(OL_DECOR_CLOSE | OL_DECOR_RESIZEH); + else if (win_type == _XA_OL_WT_NOTICE) + t->ol_hints = + OL_DECOR_ALL & + ~(OL_DECOR_CLOSE | OL_DECOR_RESIZEH | + OL_DECOR_HEADER | OL_DECOR_ICON_NAME); + else if (win_type == _XA_OL_WT_OTHER) + t->ol_hints = 0; + else + t->ol_hints = OL_DECOR_ALL; + + if (nitems == 3) + t->ol_hints &= ~OL_DECOR_ICON_NAME; + } + + if (hints) + XFree(hints); } - if (hints) - XFree (hints); - } - - if(XGetWindowProperty (dpy, t->w, _XA_OL_DECOR_ADD, 0L, 20L, False, - XA_ATOM, &actual_type, &actual_format, &nitems, - &bytesafter,(unsigned char **)&hints)==Success) - { - for (i = 0; i < nitems; i++) { - if (hints[i] == _XA_OL_DECOR_CLOSE) - t->ol_hints |= OL_DECOR_CLOSE; - else if (hints[i] == _XA_OL_DECOR_RESIZE) - t->ol_hints |= OL_DECOR_RESIZEH; - else if (hints[i] == _XA_OL_DECOR_HEADER) - t->ol_hints |= OL_DECOR_HEADER; - else if (hints[i] == _XA_OL_DECOR_ICON_NAME) - t->ol_hints |= OL_DECOR_ICON_NAME; - } - if (hints) - XFree (hints); - } - - if(XGetWindowProperty (dpy, t->w, _XA_OL_DECOR_DEL, 0L, 20L, False, - XA_ATOM, &actual_type, &actual_format, &nitems, - &bytesafter,(unsigned char **)&hints)==Success) - { - for (i = 0; i < nitems; i++) { - if (hints[i] == _XA_OL_DECOR_CLOSE) - t->ol_hints &= ~OL_DECOR_CLOSE; - else if (hints[i] == _XA_OL_DECOR_RESIZE) - t->ol_hints &= ~OL_DECOR_RESIZEH; - else if (hints[i] == _XA_OL_DECOR_HEADER) - t->ol_hints &= ~OL_DECOR_HEADER; - else if (hints[i] == _XA_OL_DECOR_ICON_NAME) - t->ol_hints &= ~OL_DECOR_ICON_NAME; - } - if (hints) - XFree (hints); - } + if (XGetWindowProperty(dpy, t->w, _XA_OL_DECOR_ADD, 0L, 20L, False, + XA_ATOM, &actual_type, &actual_format, &nitems, &bytesafter, + (unsigned char **)&hints) == Success) { + for (i = 0; i < nitems; i++) { + if (hints[i] == _XA_OL_DECOR_CLOSE) + t->ol_hints |= OL_DECOR_CLOSE; + else if (hints[i] == _XA_OL_DECOR_RESIZE) + t->ol_hints |= OL_DECOR_RESIZEH; + else if (hints[i] == _XA_OL_DECOR_HEADER) + t->ol_hints |= OL_DECOR_HEADER; + else if (hints[i] == _XA_OL_DECOR_ICON_NAME) + t->ol_hints |= OL_DECOR_ICON_NAME; + } + if (hints) + XFree(hints); + } + if (XGetWindowProperty(dpy, t->w, _XA_OL_DECOR_DEL, 0L, 20L, False, + XA_ATOM, &actual_type, &actual_format, &nitems, &bytesafter, + (unsigned char **)&hints) == Success) { + for (i = 0; i < nitems; i++) { + if (hints[i] == _XA_OL_DECOR_CLOSE) + t->ol_hints &= ~OL_DECOR_CLOSE; + else if (hints[i] == _XA_OL_DECOR_RESIZE) + t->ol_hints &= ~OL_DECOR_RESIZEH; + else if (hints[i] == _XA_OL_DECOR_HEADER) + t->ol_hints &= ~OL_DECOR_HEADER; + else if (hints[i] == _XA_OL_DECOR_ICON_NAME) + t->ol_hints &= ~OL_DECOR_ICON_NAME; + } + if (hints) + XFree(hints); + } } - /**************************************************************************** * * Interprets the property MOTIF_WM_HINTS, sets decoration and functions * accordingly * *****************************************************************************/ -void SelectDecor(FvwmWindow *t, unsigned long tflags, int border_width, - int resize_width) +void +SelectDecor( + FvwmWindow *t, unsigned long tflags, int border_width, int resize_width) { - int decor,i; - PropMwmHints *prop; - - if(!(tflags & BW_FLAG)) - border_width = Scr.NoBoundaryWidth; - - if(!(tflags & NOBW_FLAG)) - resize_width = Scr.BoundaryWidth; - - for(i=0;i<5;i++) - { - t->left_w[i] = 1; - t->right_w[i] = 1; - } - - decor = MWM_DECOR_ALL; - t->functions = MWM_FUNC_ALL; - if(t->mwm_hints) - { - prop = (PropMwmHints *)t->mwm_hints; - if(tflags & MWM_DECOR_FLAG) - if(prop->flags & MWM_HINTS_DECORATIONS) - decor = prop->decorations; - if(tflags & MWM_FUNCTIONS_FLAG) - if(prop->flags & MWM_HINTS_FUNCTIONS) - t->functions = prop->functions; - } - - /* functions affect the decorations! if the user says - * no iconify function, then the iconify button doesn't show - * up. */ - if(t->functions & MWM_FUNC_ALL) - { - /* If we get ALL + some other things, that means to use - * ALL except the other things... */ - t->functions &= ~MWM_FUNC_ALL; - t->functions = (MWM_FUNC_RESIZE | MWM_FUNC_MOVE | MWM_FUNC_MINIMIZE | - MWM_FUNC_MAXIMIZE | MWM_FUNC_CLOSE) & (~(t->functions)); - } - if((tflags & MWM_FUNCTIONS_FLAG) && (t->flags & TRANSIENT)) - { - t->functions &= ~(MWM_FUNC_MAXIMIZE|MWM_FUNC_MINIMIZE); - } - - if(decor & MWM_DECOR_ALL) - { - /* If we get ALL + some other things, that means to use - * ALL except the other things... */ - decor &= ~MWM_DECOR_ALL; - decor = (MWM_DECOR_BORDER | MWM_DECOR_RESIZEH | MWM_DECOR_TITLE | - MWM_DECOR_MENU | MWM_DECOR_MINIMIZE | MWM_DECOR_MAXIMIZE) - & (~decor); - } - - /* now remove any functions specified in the OL hints */ - if (tflags & OL_DECOR_FLAG) - { - if (!(t->ol_hints & OL_DECOR_CLOSE)) - t->functions &= ~MWM_FUNC_MINIMIZE; - if (!(t->ol_hints & OL_DECOR_RESIZEH)) - t->functions &= ~(MWM_FUNC_RESIZE | MWM_FUNC_MAXIMIZE); - if (!(t->ol_hints & OL_DECOR_HEADER)) - t->functions &= ~(MWM_DECOR_MENU | MWM_FUNC_MINIMIZE | - MWM_FUNC_MAXIMIZE | MWM_DECOR_TITLE); - if (!(t->ol_hints & OL_DECOR_ICON_NAME)) - t->flags |= NOICON_TITLE; - } - - /* Now I have the un-altered decor and functions, but with the - * ALL attribute cleared and interpreted. I need to modify the - * decorations that are affected by the functions */ - if(!(t->functions & MWM_FUNC_RESIZE)) - decor &= ~MWM_DECOR_RESIZEH; - /* MWM_FUNC_MOVE has no impact on decorations. */ - if(!(t->functions & MWM_FUNC_MINIMIZE)) - decor &= ~MWM_DECOR_MINIMIZE; - if(!(t->functions & MWM_FUNC_MAXIMIZE)) - decor &= ~MWM_DECOR_MAXIMIZE; - /* MWM_FUNC_CLOSE has no impact on decorations. */ - - /* This rule is implicit, but its easier to deal with if - * I take care of it now */ - if(decor & (MWM_DECOR_MENU| MWM_DECOR_MINIMIZE | MWM_DECOR_MAXIMIZE)) - decor |= MWM_DECOR_TITLE; - - /* Selected the mwm-decor field, now trim down, based on - * .fvwmrc entries */ - if ((tflags & NOTITLE_FLAG)|| - ((!(tflags & DECORATE_TRANSIENT_FLAG)) && (t->flags & TRANSIENT))) - decor &= ~MWM_DECOR_TITLE; - - if ((tflags & NOBORDER_FLAG)|| - ((!(tflags&DECORATE_TRANSIENT_FLAG)) && (t->flags & TRANSIENT))) - decor &= ~MWM_DECOR_RESIZEH; - - if((tflags & MWM_DECOR_FLAG) && (t->flags & TRANSIENT)) - { - decor &= ~(MWM_DECOR_MAXIMIZE|MWM_DECOR_MINIMIZE); - } + int decor, i; + PropMwmHints *prop; + + if (!(tflags & BW_FLAG)) + border_width = Scr.NoBoundaryWidth; + + if (!(tflags & NOBW_FLAG)) + resize_width = Scr.BoundaryWidth; + + for (i = 0; i < 5; i++) { + t->left_w[i] = 1; + t->right_w[i] = 1; + } + + decor = MWM_DECOR_ALL; + t->functions = MWM_FUNC_ALL; + if (t->mwm_hints) { + prop = (PropMwmHints *)t->mwm_hints; + if (tflags & MWM_DECOR_FLAG) + if (prop->flags & MWM_HINTS_DECORATIONS) + decor = prop->decorations; + if (tflags & MWM_FUNCTIONS_FLAG) + if (prop->flags & MWM_HINTS_FUNCTIONS) + t->functions = prop->functions; + } + + /* functions affect the decorations! if the user says + * no iconify function, then the iconify button doesn't show + * up. */ + if (t->functions & MWM_FUNC_ALL) { + /* If we get ALL + some other things, that means to use + * ALL except the other things... */ + t->functions &= ~MWM_FUNC_ALL; + t->functions = + (MWM_FUNC_RESIZE | MWM_FUNC_MOVE | MWM_FUNC_MINIMIZE | + MWM_FUNC_MAXIMIZE | MWM_FUNC_CLOSE) & + (~(t->functions)); + } + if ((tflags & MWM_FUNCTIONS_FLAG) && (t->flags & TRANSIENT)) { + t->functions &= ~(MWM_FUNC_MAXIMIZE | MWM_FUNC_MINIMIZE); + } + + if (decor & MWM_DECOR_ALL) { + /* If we get ALL + some other things, that means to use + * ALL except the other things... */ + decor &= ~MWM_DECOR_ALL; + decor = (MWM_DECOR_BORDER | MWM_DECOR_RESIZEH | + MWM_DECOR_TITLE | MWM_DECOR_MENU | + MWM_DECOR_MINIMIZE | MWM_DECOR_MAXIMIZE) & + (~decor); + } + + /* now remove any functions specified in the OL hints */ + if (tflags & OL_DECOR_FLAG) { + if (!(t->ol_hints & OL_DECOR_CLOSE)) + t->functions &= ~MWM_FUNC_MINIMIZE; + if (!(t->ol_hints & OL_DECOR_RESIZEH)) + t->functions &= ~(MWM_FUNC_RESIZE | MWM_FUNC_MAXIMIZE); + if (!(t->ol_hints & OL_DECOR_HEADER)) + t->functions &= ~(MWM_DECOR_MENU | MWM_FUNC_MINIMIZE | + MWM_FUNC_MAXIMIZE | MWM_DECOR_TITLE); + if (!(t->ol_hints & OL_DECOR_ICON_NAME)) + t->flags |= NOICON_TITLE; + } + + /* Now I have the un-altered decor and functions, but with the + * ALL attribute cleared and interpreted. I need to modify the + * decorations that are affected by the functions */ + if (!(t->functions & MWM_FUNC_RESIZE)) + decor &= ~MWM_DECOR_RESIZEH; + /* MWM_FUNC_MOVE has no impact on decorations. */ + if (!(t->functions & MWM_FUNC_MINIMIZE)) + decor &= ~MWM_DECOR_MINIMIZE; + if (!(t->functions & MWM_FUNC_MAXIMIZE)) + decor &= ~MWM_DECOR_MAXIMIZE; + /* MWM_FUNC_CLOSE has no impact on decorations. */ + + /* This rule is implicit, but its easier to deal with if + * I take care of it now */ + if (decor & (MWM_DECOR_MENU | MWM_DECOR_MINIMIZE | MWM_DECOR_MAXIMIZE)) + decor |= MWM_DECOR_TITLE; + + /* Selected the mwm-decor field, now trim down, based on + * .fvwmrc entries */ + if ((tflags & NOTITLE_FLAG) || + ((!(tflags & DECORATE_TRANSIENT_FLAG)) && (t->flags & TRANSIENT))) + decor &= ~MWM_DECOR_TITLE; + + if ((tflags & NOBORDER_FLAG) || + ((!(tflags & DECORATE_TRANSIENT_FLAG)) && (t->flags & TRANSIENT))) + decor &= ~MWM_DECOR_RESIZEH; + + if ((tflags & MWM_DECOR_FLAG) && (t->flags & TRANSIENT)) { + decor &= ~(MWM_DECOR_MAXIMIZE | MWM_DECOR_MINIMIZE); + } #ifdef SHAPE - if (ShapesSupported) - { - if(t->wShaped) - decor &= ~(BORDER|MWM_DECOR_RESIZEH); - } + if (ShapesSupported) { + if (t->wShaped) + decor &= ~(BORDER | MWM_DECOR_RESIZEH); + } #endif - /* Assume no decorations, and build up */ - t->flags &= ~(BORDER|TITLE); - if(tflags & MWM_BORDER_FLAG) - t->flags |= MWMBorders; - if(tflags & MWM_BUTTON_FLAG) - t->flags |= MWMButtons; - if(tflags & MWM_OVERRIDE_FLAG) - t->flags |= HintOverride; - t->boundary_width = 0; - t->corner_width = 0; - t->title_height = 0; - - if(decor & MWM_DECOR_BORDER) - { - /* A narrow border is displayed (5 pixels - 2 relief, 1 top, - * (2 shadow) */ - t->boundary_width = border_width; - } - if(decor & MWM_DECOR_TITLE) - { - /* A title barm with no buttons in it - * window gets a 1 pixel wide black border. */ - t->flags |= TITLE; - t->title_height = GetDecor(t,TitleHeight); - } - if(decor & MWM_DECOR_RESIZEH) - { - /* A wide border, with corner tiles is desplayed - * (10 pixels - 2 relief, 2 shadow) */ - t->flags |= BORDER; - t->boundary_width = resize_width; - t->corner_width = GetDecor(t,TitleHeight) + t->boundary_width; - } - if(!(decor & MWM_DECOR_MENU)) - { - /* title-bar menu button omitted - * window gets 1 pixel wide black border */ - /* disable any buttons with the MWMDecorMenu flag */ - int i; - for (i = 0; i < 5; ++i) { - if (GetDecor(t,left_buttons[i].flags)&MWMDecorMenu) - t->left_w[i] = None; - if (GetDecor(t,right_buttons[i].flags)&MWMDecorMenu) - t->right_w[i] = None; - } - } - if(!(decor & MWM_DECOR_MINIMIZE)) - { - /* title-bar + iconify button, no menu button. - * window gets 1 pixel wide black border */ - /* disable any buttons with the MWMDecorMinimize flag */ - int i; - for (i = 0; i < 5; ++i) { - if (GetDecor(t,left_buttons[i].flags)&MWMDecorMinimize) - t->left_w[i] = None; - if (GetDecor(t,right_buttons[i].flags)&MWMDecorMinimize) - t->right_w[i] = None; - } - } - if(!(decor & MWM_DECOR_MAXIMIZE)) - { - /* title-bar + maximize button, no menu button, no iconify. - * window has 1 pixel wide black border */ - /* disable any buttons with the MWMDecorMaximize flag */ - int i; - for (i = 0; i < 5; ++i) { - if (GetDecor(t,left_buttons[i].flags)&MWMDecorMaximize) - t->left_w[i] = None; - if (GetDecor(t,right_buttons[i].flags)&MWMDecorMaximize) - t->right_w[i] = None; - } - } - if (t->buttons & BUTTON1) t->left_w[0]=None; - if (t->buttons & BUTTON3) t->left_w[1]=None; - if (t->buttons & BUTTON5) t->left_w[2]=None; - if (t->buttons & BUTTON7) t->left_w[3]=None; - if (t->buttons & BUTTON9) t->left_w[4]=None; - - if (t->buttons & BUTTON2) t->right_w[0]=None; - if (t->buttons & BUTTON4) t->right_w[1]=None; - if (t->buttons & BUTTON6) t->right_w[2]=None; - if (t->buttons & BUTTON8) t->right_w[3]=None; - if (t->buttons & BUTTON10)t->right_w[4]=None; - - t->nr_left_buttons = Scr.nr_left_buttons; - t->nr_right_buttons = Scr.nr_right_buttons; - - for(i=0;ileft_w[i] == None) - t->nr_left_buttons--; - - for(i=0;iright_w[i] == None) - t->nr_right_buttons--; - - if(tflags & MWM_BORDER_FLAG) - t->bw = 0; - else if(t->boundary_width <= 0) - { - t->boundary_width = 0; - t->bw = 0; - } - else - { - t->bw = BW; - t->boundary_width = t->boundary_width - 1; - } - if(t->title_height > 0) - t->title_height += t->bw; - if(t->boundary_width == 0) - t->flags &= ~BORDER; + /* Assume no decorations, and build up */ + t->flags &= ~(BORDER | TITLE); + if (tflags & MWM_BORDER_FLAG) + t->flags |= MWMBorders; + if (tflags & MWM_BUTTON_FLAG) + t->flags |= MWMButtons; + if (tflags & MWM_OVERRIDE_FLAG) + t->flags |= HintOverride; + t->boundary_width = 0; + t->corner_width = 0; + t->title_height = 0; + + if (decor & MWM_DECOR_BORDER) { + /* A narrow border is displayed (5 pixels - 2 relief, 1 top, + * (2 shadow) */ + t->boundary_width = border_width; + } + if (decor & MWM_DECOR_TITLE) { + /* A title barm with no buttons in it + * window gets a 1 pixel wide black border. */ + t->flags |= TITLE; + t->title_height = GetDecor(t, TitleHeight); + } + if (decor & MWM_DECOR_RESIZEH) { + /* A wide border, with corner tiles is desplayed + * (10 pixels - 2 relief, 2 shadow) */ + t->flags |= BORDER; + t->boundary_width = resize_width; + t->corner_width = GetDecor(t, TitleHeight) + t->boundary_width; + } + if (!(decor & MWM_DECOR_MENU)) { + /* title-bar menu button omitted + * window gets 1 pixel wide black border */ + /* disable any buttons with the MWMDecorMenu flag */ + int i; + for (i = 0; i < 5; ++i) { + if (GetDecor(t, left_buttons[i].flags) & MWMDecorMenu) + t->left_w[i] = None; + if (GetDecor(t, right_buttons[i].flags) & MWMDecorMenu) + t->right_w[i] = None; + } + } + if (!(decor & MWM_DECOR_MINIMIZE)) { + /* title-bar + iconify button, no menu button. + * window gets 1 pixel wide black border */ + /* disable any buttons with the MWMDecorMinimize flag */ + int i; + for (i = 0; i < 5; ++i) { + if (GetDecor(t, left_buttons[i].flags) & + MWMDecorMinimize) + t->left_w[i] = None; + if (GetDecor(t, right_buttons[i].flags) & + MWMDecorMinimize) + t->right_w[i] = None; + } + } + if (!(decor & MWM_DECOR_MAXIMIZE)) { + /* title-bar + maximize button, no menu button, no iconify. + * window has 1 pixel wide black border */ + /* disable any buttons with the MWMDecorMaximize flag */ + int i; + for (i = 0; i < 5; ++i) { + if (GetDecor(t, left_buttons[i].flags) & + MWMDecorMaximize) + t->left_w[i] = None; + if (GetDecor(t, right_buttons[i].flags) & + MWMDecorMaximize) + t->right_w[i] = None; + } + } + if (t->buttons & BUTTON1) + t->left_w[0] = None; + if (t->buttons & BUTTON3) + t->left_w[1] = None; + if (t->buttons & BUTTON5) + t->left_w[2] = None; + if (t->buttons & BUTTON7) + t->left_w[3] = None; + if (t->buttons & BUTTON9) + t->left_w[4] = None; + + if (t->buttons & BUTTON2) + t->right_w[0] = None; + if (t->buttons & BUTTON4) + t->right_w[1] = None; + if (t->buttons & BUTTON6) + t->right_w[2] = None; + if (t->buttons & BUTTON8) + t->right_w[3] = None; + if (t->buttons & BUTTON10) + t->right_w[4] = None; + + t->nr_left_buttons = Scr.nr_left_buttons; + t->nr_right_buttons = Scr.nr_right_buttons; + + for (i = 0; i < Scr.nr_left_buttons; i++) + if (t->left_w[i] == None) + t->nr_left_buttons--; + + for (i = 0; i < Scr.nr_right_buttons; i++) + if (t->right_w[i] == None) + t->nr_right_buttons--; + + if (tflags & MWM_BORDER_FLAG) + t->bw = 0; + else if (t->boundary_width <= 0) { + t->boundary_width = 0; + t->bw = 0; + } else { + t->bw = BW; + t->boundary_width = t->boundary_width - 1; + } + if (t->title_height > 0) + t->title_height += t->bw; + if (t->boundary_width == 0) + t->flags &= ~BORDER; } /* @@ -465,98 +464,95 @@ void SelectDecor(FvwmWindow *t, unsigned long tflags, int border_width, ** check_allowed_function2 partially overlapping in their checks, so I ** combined them here and made them wrapper functions instead. */ -static int check_if_function_allowed(int function, - FvwmWindow *t, - MenuItem *mi) +static int +check_if_function_allowed(int function, FvwmWindow *t, MenuItem *mi) { - if (t) /* should always be ok */ - { - if (!mi) /* no menu item, must be exec check, so allow overrides */ - { - if(t->flags & HintOverride) - return 1; - } - - switch(function) - { - case F_DELETE: - if (!(t->flags & DoesWmDeleteWindow)) - return 0; - /* fall through to close clause */ - case F_CLOSE: - if (!(t->functions & MWM_FUNC_CLOSE)) - return 0; - break; - case F_DESTROY: /* shouldn't destroy always be allowed??? */ - if (!(t->functions & MWM_FUNC_CLOSE)) - return 0; - break; - case F_RESIZE: - if (!(t->functions & MWM_FUNC_RESIZE)) - return 0; - break; - case F_ICONIFY: - if ((!(t->flags & ICONIFIED))&& - (!(t->functions & MWM_FUNC_MINIMIZE))) - return 0; - break; - case F_MAXIMIZE: - if (!(t->functions & MWM_FUNC_MAXIMIZE)) - return 0; - break; - case F_MOVE: - /* Move is a funny hint. Keeps it out of the menu, but you're - * still allowed to move. */ - if((!(t->functions & MWM_FUNC_MOVE))&&mi) - return 0; - break; - case F_FUNCTION: - /* Hard part! What to do now? */ - /* Hate to do it, but for lack of a better idea, - * check based on the menu entry name */ - /* Complex functions are a little tricky, ignore them if no menu item*/ - if (mi && mi->item) - { - if((!(t->functions & MWM_FUNC_MOVE))&& - (StrEquals(mi->item,MOVE_STRING))) - return 0; - if((!(t->functions & MWM_FUNC_RESIZE))&& - (StrEquals(mi->item,RESIZE_STRING1))) - return 0; - if((!(t->functions & MWM_FUNC_RESIZE))&& - (StrEquals(mi->item,RESIZE_STRING2))) - return 0; - if((!(t->functions & MWM_FUNC_MINIMIZE))&& - (!(t->flags & ICONIFIED))&& - (StrEquals(mi->item,MINIMIZE_STRING))) - return 0; - if((!(t->functions & MWM_FUNC_MINIMIZE))&& - (StrEquals(mi->item,MINIMIZE_STRING2))) - return 0; - if((!(t->functions & MWM_FUNC_MAXIMIZE))&& - (StrEquals(mi->item,MAXIMIZE_STRING))) - return 0; - if((!(t->functions & MWM_FUNC_CLOSE))&& - (StrEquals(mi->item,CLOSE_STRING1))) - return 0; - if((!(t->functions & MWM_FUNC_CLOSE))&& - (StrEquals(mi->item,CLOSE_STRING2))) - return 0; - if((!(t->functions & MWM_FUNC_CLOSE))&& - (StrEquals(mi->item,CLOSE_STRING3))) - return 0; - if((!(t->functions & MWM_FUNC_CLOSE))&& - (StrEquals(mi->item,CLOSE_STRING4))) - return 0; - } - break; - default: - break; - } /* end of switch */ - } /* end of if */ - - /* if we fell through, just return a 1 */ - return 1; + if (t) { /* should always be ok */ + if (!mi) { /* no menu item, must be exec check, so allow overrides + */ + if (t->flags & HintOverride) + return 1; + } + + switch (function) { + case F_DELETE: + if (!(t->flags & DoesWmDeleteWindow)) + return 0; + /* fall through to close clause */ + case F_CLOSE: + if (!(t->functions & MWM_FUNC_CLOSE)) + return 0; + break; + case F_DESTROY: /* shouldn't destroy always be allowed??? */ + if (!(t->functions & MWM_FUNC_CLOSE)) + return 0; + break; + case F_RESIZE: + if (!(t->functions & MWM_FUNC_RESIZE)) + return 0; + break; + case F_ICONIFY: + if ((!(t->flags & ICONIFIED)) && + (!(t->functions & MWM_FUNC_MINIMIZE))) + return 0; + break; + case F_MAXIMIZE: + if (!(t->functions & MWM_FUNC_MAXIMIZE)) + return 0; + break; + case F_MOVE: + /* Move is a funny hint. Keeps it out of the menu, but + * you're still allowed to move. */ + if ((!(t->functions & MWM_FUNC_MOVE)) && mi) + return 0; + break; + case F_FUNCTION: + /* Hard part! What to do now? */ + /* Hate to do it, but for lack of a better idea, + * check based on the menu entry name */ + /* Complex functions are a little tricky, ignore them if + * no menu item*/ + if (mi && mi->item) { + if ((!(t->functions & MWM_FUNC_MOVE)) && + (StrEquals(mi->item, MOVE_STRING))) + return 0; + if ((!(t->functions & MWM_FUNC_RESIZE)) && + (StrEquals(mi->item, RESIZE_STRING1))) + return 0; + if ((!(t->functions & MWM_FUNC_RESIZE)) && + (StrEquals(mi->item, RESIZE_STRING2))) + return 0; + if ((!(t->functions & MWM_FUNC_MINIMIZE)) && + (!(t->flags & ICONIFIED)) && + (StrEquals(mi->item, MINIMIZE_STRING))) + return 0; + if ((!(t->functions & MWM_FUNC_MINIMIZE)) && + (StrEquals(mi->item, MINIMIZE_STRING2))) + return 0; + if ((!(t->functions & MWM_FUNC_MAXIMIZE)) && + (StrEquals(mi->item, MAXIMIZE_STRING))) + return 0; + if ((!(t->functions & MWM_FUNC_CLOSE)) && + (StrEquals(mi->item, CLOSE_STRING1))) + return 0; + if ((!(t->functions & MWM_FUNC_CLOSE)) && + (StrEquals(mi->item, CLOSE_STRING2))) + return 0; + if ((!(t->functions & MWM_FUNC_CLOSE)) && + (StrEquals(mi->item, CLOSE_STRING3))) + return 0; + if ((!(t->functions & MWM_FUNC_CLOSE)) && + (StrEquals(mi->item, CLOSE_STRING4))) + return 0; + } + break; + default: + break; + } /* end of switch */ + } /* end of if */ + + /* if we fell through, just return a 1 */ + return 1; } /**************************************************************************** @@ -568,9 +564,10 @@ static int check_if_function_allowed(int function, * This routine is used to determine whether or not to grey out menu items. * ****************************************************************************/ -int check_allowed_function(MenuItem *mi) +int +check_allowed_function(MenuItem *mi) { - return check_if_function_allowed(mi->func_type,Tmp_win,mi); + return check_if_function_allowed(mi->func_type, Tmp_win, mi); } /**************************************************************************** @@ -580,10 +577,8 @@ int check_allowed_function(MenuItem *mi) * This routine is used to decide if we should refuse to perform a function. * ****************************************************************************/ -int check_allowed_function2(int function, FvwmWindow *t) +int +check_allowed_function2(int function, FvwmWindow *t) { - return check_if_function_allowed(function,t,NULL); + return check_if_function_allowed(function, t, NULL); } - - - Index: fvwm/fvwm/defaults.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/defaults.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/defaults.h --- fvwm/fvwm/defaults.h +++ fvwm/fvwm/defaults.h @@ -7,6 +7,6 @@ * 23 Dec 1998 - Dominik Vogt */ -#define DEFAULT_CLICKTIME 150 /* ms */ -#define DEFAULT_POPUP_DELAY 15 /* ms*10 */ -#define DEFAULT_MENU_CLICKTIME (3*DEFAULT_CLICKTIME) +#define DEFAULT_CLICKTIME 150 /* ms */ +#define DEFAULT_POPUP_DELAY 15 /* ms*10 */ +#define DEFAULT_MENU_CLICKTIME (3 * DEFAULT_CLICKTIME) Index: fvwm/fvwm/events.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/events.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/events.c --- fvwm/fvwm/events.c +++ fvwm/fvwm/events.c @@ -29,7 +29,6 @@ /** OR PERFORMANCE OF THIS SOFTWARE. **/ /*****************************************************************************/ - /*********************************************************************** * * fvwm event handling @@ -38,23 +37,23 @@ #include "config.h" -#if HAVE_SYS_BSDTYPES_H -#include #endif +#include +#include + +#include #include #include -#include -#include #include -#include #if HAVE_SYS_SELECT_H #include #endif -#include "fvwm.h" #include + +#include "fvwm.h" #include "menus.h" #include "misc.h" #include "parse.h" @@ -64,20 +63,20 @@ #endif /* SHAPE */ #include "module.h" -unsigned int mods_used = (ShiftMask | ControlMask | Mod1Mask | - Mod2Mask| Mod3Mask| Mod4Mask| Mod5Mask); +unsigned int mods_used = (ShiftMask | ControlMask | Mod1Mask | Mod2Mask | + Mod3Mask | Mod4Mask | Mod5Mask); extern int menuFromFrameOrWindowOrTitlebar; extern Boolean debugging; -int Context = C_NO_CONTEXT; /* current button press context */ +int Context = C_NO_CONTEXT; /* current button press context */ int Button = 0; -FvwmWindow *ButtonWindow; /* button press window structure */ -XEvent Event; /* the current event */ -FvwmWindow *Tmp_win; /* the current fvwm window */ +FvwmWindow *ButtonWindow; /* button press window structure */ +XEvent Event; /* the current event */ +FvwmWindow *Tmp_win; /* the current fvwm window */ -int last_event_type=0; -Window last_event_window=0; +int last_event_type = 0; +Window last_event_window = 0; #ifdef SHAPE extern int ShapeEventBase; @@ -98,38 +97,39 @@ Window PressedW; #endif /* !LASTEvent */ typedef void (*PFEH)(void); PFEH EventHandlerJumpTable[LASTEvent]; -void ResyncFvwmStackRing(void); +void ResyncFvwmStackRing(void); /* ** Procedure: ** InitEventHandlerJumpTable */ -void InitEventHandlerJumpTable(void) +void +InitEventHandlerJumpTable(void) { - int i; - - for (i=0; ixany.window; - - if(*w == Scr.NoFocusWin) - return C_ROOT; - - /* Since key presses and button presses are grabbed in the frame - * when we have re-parented windows, we need to find out the real - * window where the event occured */ -#if 0 - /* domivogt (2-Jan-1999): Causes a bug with ClickToFocus. - * keys and buttons are treated differently here because keys are bound to - * the frame window and buttons are bound to the client window (with - * XGrabKey/XGrabButton). */ - if((e->type == KeyPress)&&(e->xkey.subwindow != None)) - *w = e->xkey.subwindow; - - if((e->type == ButtonPress)&&(e->xbutton.subwindow != None)&& - ((e->xbutton.subwindow == t->w)||(e->xbutton.subwindow == t->Parent))) - *w = e->xbutton.subwindow; -#else - if(e->xkey.subwindow != None) - { - if (e->type == KeyPress) - *w = e->xkey.subwindow; - else if ((*w != t->w && *w != t->Parent) || - e->xbutton.subwindow == t->w || - e->xbutton.subwindow == t->Parent) - /* domivogt (6-Jan-198): I don't understand what's happening here. If - * the mouse is over the client window. The subwindow has an unique id - * that no visible part of the FvwmWindow has. */ - *w = e->xbutton.subwindow; - } -#endif + int Context, i; + + if (!t) + return C_ROOT; + + Context = C_NO_CONTEXT; + *w = e->xany.window; + + if (*w == Scr.NoFocusWin) + return C_ROOT; + + /* Since key presses and button presses are grabbed in the frame + * when we have re-parented windows, we need to find out the real + * window where the event occured */ + if (e->xkey.subwindow != None) { + if (e->type == KeyPress) + *w = e->xkey.subwindow; + else if ((*w != t->w && *w != t->Parent) || + e->xbutton.subwindow == t->w || + e->xbutton.subwindow == t->Parent) + /* domivogt (6-Jan-198): I don't understand what's + * happening here. If the mouse is over the client + * window. The subwindow has an unique id that no + * visible part of the FvwmWindow has. */ + *w = e->xbutton.subwindow; + } - if (*w == Scr.Root) - Context = C_ROOT; - if (t) - { - if (*w == t->title_w) - Context = C_TITLE; - else if ((*w == t->w)||(*w == t->Parent)) - Context = C_WINDOW; - else if (*w == t->icon_w || *w == t->icon_pixmap_w) - Context = C_ICON; - else if (*w == t->frame) - Context = C_SIDEBAR; - else - { - for(i=0;i<4;i++) - { - if(*w == t->corners[i]) - { - Context = C_FRAME; - break; - } - if(*w == t->sides[i]) - { - Context = C_SIDEBAR; - break; - } - } - if (i < 4) - Button = i; - else - { - for(i=0;ileft_w[i]) - { - Context = (1<right_w[i]) - { - Context = (1<title_w) + Context = C_TITLE; + else if ((*w == t->w) || (*w == t->Parent)) + Context = C_WINDOW; + else if (*w == t->icon_w || *w == t->icon_pixmap_w) + Context = C_ICON; + else if (*w == t->frame) + Context = C_SIDEBAR; + else { + for (i = 0; i < 4; i++) { + if (*w == t->corners[i]) { + Context = C_FRAME; + break; + } + if (*w == t->sides[i]) { + Context = C_SIDEBAR; + break; + } + } + if (i < 4) + Button = i; + else { + for (i = 0; i < Scr.nr_left_buttons; i++) { + if (*w == t->left_w[i]) { + Context = (1 << i) * C_L1; + break; + } + } + if (i < Scr.nr_left_buttons) + Button = i; + else { + for (i = 0; i < Scr.nr_right_buttons; + i++) { + if (*w == t->right_w[i]) { + Context = + (1 << i) * C_R1; + Button = i; + break; + } + } + } + } /* if (i < 4) */ + } /* else */ + } /* if (t) */ + return Context; } /*********************************************************************** @@ -299,69 +277,53 @@ int GetContext(FvwmWindow *t, XEvent *e, Window *w) * HandleFocusIn - handles focus in events * ************************************************************************/ -void HandleFocusIn() +void +HandleFocusIn() { - XEvent d; - Window w; - - DBUG("HandleFocusIn","Routine Entered"); - - w= Event.xany.window; - while(XCheckTypedEvent(dpy,FocusIn,&d)) - { - w = d.xany.window; - } - if (XFindContext (dpy, w, FvwmContext, (caddr_t *) &Tmp_win) == XCNOENT) - { - Tmp_win = NULL; - } - - if(!Tmp_win) - { - if(w != Scr.NoFocusWin) - { - Scr.UnknownWinFocused = w; + XEvent d; + Window w; + + DBUG("HandleFocusIn", "Routine Entered"); + + w = Event.xany.window; + while (XCheckTypedEvent(dpy, FocusIn, &d)) { + w = d.xany.window; } - else - { - SetBorder(Scr.Hilite,False,True,True,None); - BroadcastPacket(M_FOCUS_CHANGE, 5, - 0, 0, 0, - Scr.DefaultDecor.HiColors.fore, - Scr.DefaultDecor.HiColors.back); - if (Scr.ColormapFocus == COLORMAP_FOLLOWS_FOCUS) - { - if((Scr.Hilite)&&(!(Scr.Hilite->flags & ICONIFIED))) - { - InstallWindowColormaps(Scr.Hilite); + if (XFindContext(dpy, w, FvwmContext, (caddr_t *)&Tmp_win) == XCNOENT) { + Tmp_win = NULL; + } + + if (!Tmp_win) { + if (w != Scr.NoFocusWin) { + Scr.UnknownWinFocused = w; + } else { + SetBorder(Scr.Hilite, False, True, True, None); + BroadcastPacket(M_FOCUS_CHANGE, 5, 0, 0, 0, + Scr.DefaultDecor.HiColors.fore, + Scr.DefaultDecor.HiColors.back); + if (Scr.ColormapFocus == COLORMAP_FOLLOWS_FOCUS) { + if ((Scr.Hilite) && + (!(Scr.Hilite->flags & ICONIFIED))) { + InstallWindowColormaps(Scr.Hilite); + } else { + InstallWindowColormaps(NULL); + } + } } - else - { - InstallWindowColormaps(NULL); + } else if (Tmp_win != Scr.Hilite) { + SetBorder(Tmp_win, True, True, True, None); + BroadcastPacket(M_FOCUS_CHANGE, 5, Tmp_win->w, Tmp_win->frame, + (unsigned long)Tmp_win, GetDecor(Tmp_win, HiColors.fore), + GetDecor(Tmp_win, HiColors.back)); + if (Scr.ColormapFocus == COLORMAP_FOLLOWS_FOCUS) { + if ((Scr.Hilite) && + (!(Scr.Hilite->flags & ICONIFIED))) { + InstallWindowColormaps(Scr.Hilite); + } else { + InstallWindowColormaps(NULL); + } } - } - } - } - else if(Tmp_win != Scr.Hilite) - { - SetBorder(Tmp_win,True,True,True,None); - BroadcastPacket(M_FOCUS_CHANGE, 5, - Tmp_win->w, Tmp_win->frame, (unsigned long)Tmp_win, - GetDecor(Tmp_win,HiColors.fore), - GetDecor(Tmp_win,HiColors.back)); - if (Scr.ColormapFocus == COLORMAP_FOLLOWS_FOCUS) - { - if((Scr.Hilite)&&(!(Scr.Hilite->flags & ICONIFIED))) - { - InstallWindowColormaps(Scr.Hilite); - } - else - { - InstallWindowColormaps(NULL); - } - } - } } /*********************************************************************** @@ -370,52 +332,61 @@ void HandleFocusIn() * HandleKeyPress - key press event handler * ************************************************************************/ -void HandleKeyPress() +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)) + 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; + + /* Normalize keycodes that map to the same keysym. */ { - ExecuteFunction(key->Action,Tmp_win, &Event,Context,-1); - return; + KeySym *mapping; + int width; + + mapping = + XGetKeyboardMapping(dpy, Event.xkey.keycode, 1, &width); + if (mapping != NULL && width > 0) { + KeySym primary = mapping[0]; + KeyCode canonical = XKeysymToKeycode(dpy, primary); + + if (canonical != 0) + Event.xkey.keycode = canonical; + } + if (mapping != NULL) + XFree(mapping); } - } - - /* 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); + + 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; + } } - } - ButtonWindow = NULL; -} + /* 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; +} /*********************************************************************** * @@ -423,253 +394,222 @@ void HandleKeyPress() * HandlePropertyNotify - property notify event handler * ***********************************************************************/ -#define MAX_NAME_LEN 200L /* truncate to this many */ -#define MAX_ICON_NAME_LEN 200L /* ditto */ +#define MAX_NAME_LEN 200L /* truncate to this many */ +#define MAX_ICON_NAME_LEN 200L /* ditto */ -void HandlePropertyNotify() +void +HandlePropertyNotify() { - XTextProperty text_prop; - Boolean OnThisPage = False; - - DBUG("HandlePropertyNotify","Routine Entered"); - - if ((!Tmp_win)|| - (XGetGeometry(dpy, Tmp_win->w, &JunkRoot, &JunkX, &JunkY, - &JunkWidth, &JunkHeight, &JunkBW, &JunkDepth) == 0)) - return; - - /* - Make sure at least part of window is on this page - before giving it focus... - */ - if ( (Tmp_win->Desk == Scr.CurrentDesk) && - ( ((Tmp_win->frame_x + Tmp_win->frame_width) >= 0 && - Tmp_win->frame_x < Scr.MyDisplayWidth) && - ((Tmp_win->frame_y + Tmp_win->frame_height) >= 0 && - Tmp_win->frame_y < Scr.MyDisplayHeight) - ) - ) - { - OnThisPage = True; - } - - switch (Event.xproperty.atom) - { - case XA_WM_TRANSIENT_FOR: - { - if(XGetTransientForHint(dpy, Tmp_win->w, &Tmp_win->transientfor)) - { - Tmp_win->flags |= TRANSIENT; - RaiseWindow(Tmp_win); - } - else - { - Tmp_win->flags &= ~TRANSIENT; - } - } - break; - - case XA_WM_NAME: - if (!XGetWMName(dpy, Tmp_win->w, &text_prop)) - return; - - free_window_names (Tmp_win, True, False); - - Tmp_win->name = (char *)text_prop.value; - if (Tmp_win->name && strlen(Tmp_win->name) > 200) - /* limit to prevent hanging X server */ - Tmp_win->name[200] = 0; - - if (Tmp_win->name == NULL) - Tmp_win->name = NoName; - BroadcastName(M_WINDOW_NAME,Tmp_win->w,Tmp_win->frame, - (unsigned long)Tmp_win,Tmp_win->name); - - /* fix the name in the title bar */ - if(!(Tmp_win->flags & ICONIFIED)) - SetTitleBar(Tmp_win,(Scr.Hilite==Tmp_win),True); + XTextProperty text_prop; + Boolean OnThisPage = False; + + DBUG("HandlePropertyNotify", "Routine Entered"); + + if ((!Tmp_win) || + (XGetGeometry(dpy, Tmp_win->w, &JunkRoot, &JunkX, &JunkY, + &JunkWidth, &JunkHeight, &JunkBW, &JunkDepth) == 0)) + return; + + /* + Make sure at least part of window is on this page + before giving it focus... + */ + if ((Tmp_win->Desk == Scr.CurrentDesk) && + (((Tmp_win->frame_x + Tmp_win->frame_width) >= 0 && + Tmp_win->frame_x < Scr.MyDisplayWidth) && + ((Tmp_win->frame_y + Tmp_win->frame_height) >= 0 && + Tmp_win->frame_y < Scr.MyDisplayHeight))) { + OnThisPage = True; + } - /* - * if the icon name is NoName, set the name of the icon to be - * the same as the window - */ - if (Tmp_win->icon_name == NoName) - { - Tmp_win->icon_name = Tmp_win->name; - BroadcastName(M_ICON_NAME,Tmp_win->w,Tmp_win->frame, - (unsigned long)Tmp_win,Tmp_win->icon_name); - RedoIconName(Tmp_win); + switch (Event.xproperty.atom) { + case XA_WM_TRANSIENT_FOR: { + if (XGetTransientForHint( + dpy, Tmp_win->w, &Tmp_win->transientfor)) { + Tmp_win->flags |= TRANSIENT; + RaiseWindow(Tmp_win); + } else { + Tmp_win->flags &= ~TRANSIENT; + } } - break; + break; - case XA_WM_ICON_NAME: - if (!XGetWMIconName (dpy, Tmp_win->w, &text_prop)) - return; - free_window_names (Tmp_win, False, True); - Tmp_win->icon_name = (char *) text_prop.value; - if (Tmp_win->icon_name && strlen(Tmp_win->icon_name) > 200) - /* limit to prevent hanging X server */ - Tmp_win->icon_name[200] = 0; - if (Tmp_win->icon_name == NULL) - Tmp_win->icon_name = NoName; - BroadcastName(M_ICON_NAME,Tmp_win->w,Tmp_win->frame, - (unsigned long)Tmp_win,Tmp_win->icon_name); - RedoIconName(Tmp_win); - break; - - case XA_WM_HINTS: - if (Tmp_win->wmhints) - XFree ((char *) Tmp_win->wmhints); - Tmp_win->wmhints = XGetWMHints(dpy, Event.xany.window); - - if(Tmp_win->wmhints == NULL) - return; + case XA_WM_NAME: + if (!XGetWMName(dpy, Tmp_win->w, &text_prop)) + return; + + free_window_names(Tmp_win, True, False); + + Tmp_win->name = (char *)text_prop.value; + if (Tmp_win->name && strlen(Tmp_win->name) > 200) + /* limit to prevent hanging X server */ + Tmp_win->name[200] = 0; + + if (Tmp_win->name == NULL) + Tmp_win->name = NoName; + BroadcastName(M_WINDOW_NAME, Tmp_win->w, Tmp_win->frame, + (unsigned long)Tmp_win, Tmp_win->name); + + /* fix the name in the title bar */ + if (!(Tmp_win->flags & ICONIFIED)) + SetTitleBar(Tmp_win, (Scr.Hilite == Tmp_win), True); + + /* + * if the icon name is NoName, set the name of the icon to be + * the same as the window + */ + if (Tmp_win->icon_name == NoName) { + Tmp_win->icon_name = Tmp_win->name; + BroadcastName(M_ICON_NAME, Tmp_win->w, Tmp_win->frame, + (unsigned long)Tmp_win, Tmp_win->icon_name); + RedoIconName(Tmp_win); + } + break; - if((Tmp_win->wmhints->flags & IconPixmapHint)|| - (Tmp_win->wmhints->flags & IconWindowHint)) - if(Tmp_win->icon_bitmap_file == Scr.DefaultIcon) - Tmp_win->icon_bitmap_file = (char *)0; + case XA_WM_ICON_NAME: + if (!XGetWMIconName(dpy, Tmp_win->w, &text_prop)) + return; + free_window_names(Tmp_win, False, True); + Tmp_win->icon_name = (char *)text_prop.value; + if (Tmp_win->icon_name && strlen(Tmp_win->icon_name) > 200) + /* limit to prevent hanging X server */ + Tmp_win->icon_name[200] = 0; + if (Tmp_win->icon_name == NULL) + Tmp_win->icon_name = NoName; + BroadcastName(M_ICON_NAME, Tmp_win->w, Tmp_win->frame, + (unsigned long)Tmp_win, Tmp_win->icon_name); + RedoIconName(Tmp_win); + break; - if((Tmp_win->wmhints->flags & IconPixmapHint)|| - (Tmp_win->wmhints->flags & IconWindowHint)) - { - if (!(Tmp_win->flags & SUPPRESSICON)) - { - if (Tmp_win->icon_w) - XDestroyWindow(dpy,Tmp_win->icon_w); - XDeleteContext(dpy, Tmp_win->icon_w, FvwmContext); - if(Tmp_win->flags & ICON_OURS) - { - if(Tmp_win->icon_pixmap_w != None) - { - XDestroyWindow(dpy,Tmp_win->icon_pixmap_w); - XDeleteContext(dpy, Tmp_win->icon_pixmap_w, FvwmContext); - } + case XA_WM_HINTS: + if (Tmp_win->wmhints) + XFree((char *)Tmp_win->wmhints); + Tmp_win->wmhints = XGetWMHints(dpy, Event.xany.window); + + if (Tmp_win->wmhints == NULL) + return; + + if ((Tmp_win->wmhints->flags & IconPixmapHint) || + (Tmp_win->wmhints->flags & IconWindowHint)) + if (Tmp_win->icon_bitmap_file == Scr.DefaultIcon) + Tmp_win->icon_bitmap_file = (char *)0; + + if ((Tmp_win->wmhints->flags & IconPixmapHint) || + (Tmp_win->wmhints->flags & IconWindowHint)) { + if (!(Tmp_win->flags & SUPPRESSICON)) { + if (Tmp_win->icon_w) + XDestroyWindow(dpy, Tmp_win->icon_w); + XDeleteContext( + dpy, Tmp_win->icon_w, FvwmContext); + if (Tmp_win->flags & ICON_OURS) { + if (Tmp_win->icon_pixmap_w != None) { + XDestroyWindow(dpy, + Tmp_win->icon_pixmap_w); + XDeleteContext(dpy, + Tmp_win->icon_pixmap_w, + FvwmContext); + } + } else + XUnmapWindow( + dpy, Tmp_win->icon_pixmap_w); + } + Tmp_win->icon_w = None; + Tmp_win->icon_pixmap_w = None; + Tmp_win->iconPixmap = (Window)NULL; + if (Tmp_win->flags & ICONIFIED) { + Tmp_win->flags &= ~ICONIFIED; + Tmp_win->flags &= ~ICON_UNMAPPED; + CreateIconWindow(Tmp_win, Tmp_win->icon_x_loc, + Tmp_win->icon_y_loc); + BroadcastPacket(M_ICONIFY, 7, Tmp_win->w, + Tmp_win->frame, (unsigned long)Tmp_win, + Tmp_win->icon_x_loc, Tmp_win->icon_y_loc, + Tmp_win->icon_w_width, + Tmp_win->icon_w_height); + BroadcastConfig(M_CONFIGURE_WINDOW, Tmp_win); + + if (!(Tmp_win->flags & SUPPRESSICON)) { + LowerWindow(Tmp_win); + AutoPlace(Tmp_win); + if (Tmp_win->Desk == Scr.CurrentDesk) { + if (Tmp_win->icon_w) + XMapWindow(dpy, + Tmp_win->icon_w); + if (Tmp_win->icon_pixmap_w != + None) + XMapWindow(dpy, + Tmp_win + ->icon_pixmap_w); + } + } + Tmp_win->flags |= ICONIFIED; + DrawIconWindow(Tmp_win); + } } - else - XUnmapWindow(dpy,Tmp_win->icon_pixmap_w); - } - Tmp_win->icon_w = None; - Tmp_win->icon_pixmap_w = None; - Tmp_win->iconPixmap = (Window)NULL; - if(Tmp_win->flags & ICONIFIED) - { - Tmp_win->flags &= ~ICONIFIED; - Tmp_win->flags &= ~ICON_UNMAPPED; - CreateIconWindow(Tmp_win, - Tmp_win->icon_x_loc,Tmp_win->icon_y_loc); - BroadcastPacket(M_ICONIFY, 7, - Tmp_win->w, Tmp_win->frame, - (unsigned long)Tmp_win, - Tmp_win->icon_x_loc, Tmp_win->icon_y_loc, - Tmp_win->icon_w_width, Tmp_win->icon_w_height); - BroadcastConfig(M_CONFIGURE_WINDOW, Tmp_win); - - if (!(Tmp_win->flags & SUPPRESSICON)) - { - LowerWindow(Tmp_win); - AutoPlace(Tmp_win); - if(Tmp_win->Desk == Scr.CurrentDesk) - { - if(Tmp_win->icon_w) - XMapWindow(dpy, Tmp_win->icon_w); - if(Tmp_win->icon_pixmap_w != None) - XMapWindow(dpy, Tmp_win->icon_pixmap_w); - } + break; + + case XA_WM_NORMAL_HINTS: + GetWindowSizeHints(Tmp_win); + BroadcastConfig(M_CONFIGURE_WINDOW, Tmp_win); + break; + + default: + if (Event.xproperty.atom == _XA_WM_PROTOCOLS) + FetchWmProtocols(Tmp_win); + else if (Event.xproperty.atom == _XA_WM_COLORMAP_WINDOWS) { + FetchWmColormapWindows(Tmp_win); /* frees old data */ + ReInstallActiveColormap(); + } else if (Event.xproperty.atom == _XA_WM_STATE) { + if ((Tmp_win != NULL) && + (Tmp_win->flags & ClickToFocus) && + (Tmp_win == Scr.Focus)) { + if (OnThisPage) { + Scr.Focus = NULL; + SetFocus(Tmp_win->w, Tmp_win, 0); + } + } } - Tmp_win->flags |= ICONIFIED; - DrawIconWindow(Tmp_win); - } - } - break; - - case XA_WM_NORMAL_HINTS: - GetWindowSizeHints (Tmp_win); -#if 0 - /* - ** ckh - not sure why this next stuff was here, but fvwm 1.xx - ** didn't do this, and it seems to cause a bug when changing - ** fonts in XTerm - */ - { - int new_width, new_height; - new_width = Tmp_win->frame_width; - new_height = Tmp_win->frame_height; - ConstrainSize(Tmp_win, &new_width, &new_height, False, 0, 0); - if((new_width != Tmp_win->frame_width)|| - (new_height != Tmp_win->frame_height)) - SetupFrame(Tmp_win,Tmp_win->frame_x, Tmp_win->frame_y, - new_width,new_height,False); - } -#endif /* 0 */ - BroadcastConfig(M_CONFIGURE_WINDOW,Tmp_win); - break; - - default: - if(Event.xproperty.atom == _XA_WM_PROTOCOLS) - FetchWmProtocols (Tmp_win); - else if (Event.xproperty.atom == _XA_WM_COLORMAP_WINDOWS) - { - FetchWmColormapWindows (Tmp_win); /* frees old data */ - ReInstallActiveColormap(); - } - else if(Event.xproperty.atom == _XA_WM_STATE) - { - if((Tmp_win != NULL)&&(Tmp_win->flags & ClickToFocus) - &&(Tmp_win == Scr.Focus)) - { - if (OnThisPage) - { - Scr.Focus = NULL; - SetFocus(Tmp_win->w,Tmp_win,0); - } - } + break; } - break; - } } - /*********************************************************************** * * Procedure: * HandleClientMessage - client message event handler * ************************************************************************/ -void HandleClientMessage() +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); - } - } + 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); + } + } } /*********************************************************************** @@ -678,259 +618,234 @@ void HandleClientMessage() * HandleExpose - expose event handler * ***********************************************************************/ -void HandleExpose() +void +HandleExpose() { - if (Event.xexpose.count != 0) - return; + if (Event.xexpose.count != 0) + return; - DBUG("HandleExpose","Routine Entered"); + DBUG("HandleExpose", "Routine Entered"); - if (Tmp_win) - { - if (Event.xany.window == Tmp_win->title_w) - { - SetTitleBar(Tmp_win,(Scr.Hilite == Tmp_win),False); - } - else - { - SetBorder(Tmp_win,(Scr.Hilite == Tmp_win),True,True, - Event.xany.window); + if (Tmp_win) { + if (Event.xany.window == Tmp_win->title_w) { + SetTitleBar(Tmp_win, (Scr.Hilite == Tmp_win), False); + } else { + SetBorder(Tmp_win, (Scr.Hilite == Tmp_win), True, True, + Event.xany.window); + } } - } - return; + return; } - - /*********************************************************************** * * Procedure: * HandleDestroyNotify - DestroyNotify event handler * ***********************************************************************/ -void HandleDestroyNotify() +void +HandleDestroyNotify() { - DBUG("HandleDestroyNotify","Routine Entered"); + DBUG("HandleDestroyNotify", "Routine Entered"); - Destroy(Tmp_win); + Destroy(Tmp_win); } - - - /*********************************************************************** * * Procedure: * HandleMapRequest - MapRequest event handler * ************************************************************************/ -void HandleMapRequest() +void +HandleMapRequest() { - DBUG("HandleMapRequest","Routine Entered"); + DBUG("HandleMapRequest", "Routine Entered"); - HandleMapRequestKeepRaised(None); + HandleMapRequestKeepRaised(None); } -void HandleMapRequestKeepRaised(Window KeepRaised) + +void +HandleMapRequestKeepRaised(Window KeepRaised) { - extern long isIconicState; - extern Boolean PPosOverride; - Boolean OnThisPage = False; + extern long isIconicState; + extern Boolean PPosOverride; + Boolean OnThisPage = False; - Event.xany.window = Event.xmaprequest.window; + Event.xany.window = Event.xmaprequest.window; - if(XFindContext(dpy, Event.xany.window, FvwmContext, - (caddr_t *)&Tmp_win)==XCNOENT) - Tmp_win = NULL; + if (XFindContext(dpy, Event.xany.window, FvwmContext, + (caddr_t *)&Tmp_win) == XCNOENT) + Tmp_win = NULL; - if(!PPosOverride) - XFlush(dpy); + if (!PPosOverride) + XFlush(dpy); - /* If the window has never been mapped before ... */ - if(!Tmp_win) - { - /* Add decorations. */ - Tmp_win = AddWindow(Event.xany.window); - if (Tmp_win == NULL) - return; - } - /* - Make sure at least part of window is on this page - before giving it focus... - */ - if ( (Tmp_win->Desk == Scr.CurrentDesk) && - ( ((Tmp_win->frame_x + Tmp_win->frame_width) >= 0 && - Tmp_win->frame_x < Scr.MyDisplayWidth) && - ((Tmp_win->frame_y + Tmp_win->frame_height) >= 0 && - Tmp_win->frame_y < Scr.MyDisplayHeight) - ) - ) - { - OnThisPage = True; - } - - if(KeepRaised != None) - XRaiseWindow(dpy,KeepRaised); - /* If it's not merely iconified, and we have hints, use them. */ - if (!(Tmp_win->flags & ICONIFIED)) - { - int state; - - if(Tmp_win->wmhints && (Tmp_win->wmhints->flags & StateHint)) - state = Tmp_win->wmhints->initial_state; - else - state = NormalState; - - if(Tmp_win->flags & STARTICONIC) - state = IconicState; - - if(isIconicState != DontCareState) - state = isIconicState; - - MyXGrabServer(dpy); - switch (state) - { - case DontCareState: - case NormalState: - case InactiveState: - default: - if (Tmp_win->Desk == Scr.CurrentDesk) - { - XMapWindow(dpy, Tmp_win->w); - XMapWindow(dpy, Tmp_win->frame); - Tmp_win->flags |= MAP_PENDING; - SetMapStateProp(Tmp_win, NormalState); - if((Tmp_win->flags & ClickToFocus)&& - ((!Scr.Focus)||(Scr.Focus->flags & ClickToFocus))) - { - if (OnThisPage) - { - SetFocus(Tmp_win->w,Tmp_win,1); - } + /* If the window has never been mapped before ... */ + if (!Tmp_win) { + /* Add decorations. */ + Tmp_win = AddWindow(Event.xany.window); + if (Tmp_win == NULL) + return; + } + /* + Make sure at least part of window is on this page + before giving it focus... + */ + if ((Tmp_win->Desk == Scr.CurrentDesk) && + (((Tmp_win->frame_x + Tmp_win->frame_width) >= 0 && + Tmp_win->frame_x < Scr.MyDisplayWidth) && + ((Tmp_win->frame_y + Tmp_win->frame_height) >= 0 && + Tmp_win->frame_y < Scr.MyDisplayHeight))) { + OnThisPage = True; + } + + if (KeepRaised != None) + XRaiseWindow(dpy, KeepRaised); + /* If it's not merely iconified, and we have hints, use them. */ + if (!(Tmp_win->flags & ICONIFIED)) { + int state; + + if (Tmp_win->wmhints && (Tmp_win->wmhints->flags & StateHint)) + state = Tmp_win->wmhints->initial_state; + else + state = NormalState; + + if (Tmp_win->flags & STARTICONIC) + state = IconicState; + + if (isIconicState != DontCareState) + state = isIconicState; + + MyXGrabServer(dpy); + switch (state) { + case DontCareState: + case NormalState: + case InactiveState: + default: + if (Tmp_win->Desk == Scr.CurrentDesk) { + XMapWindow(dpy, Tmp_win->w); + XMapWindow(dpy, Tmp_win->frame); + Tmp_win->flags |= MAP_PENDING; + SetMapStateProp(Tmp_win, NormalState); + if ((Tmp_win->flags & ClickToFocus) && + ((!Scr.Focus) || + (Scr.Focus->flags & ClickToFocus))) { + if (OnThisPage) { + SetFocus( + Tmp_win->w, Tmp_win, 1); + } + } + } else { + XMapWindow(dpy, Tmp_win->w); + SetMapStateProp(Tmp_win, NormalState); + } + break; + + case IconicState: + if (Tmp_win->wmhints) { + Iconify(Tmp_win, Tmp_win->wmhints->icon_x, + Tmp_win->wmhints->icon_y); + } else { + Iconify(Tmp_win, 0, 0); + } + break; } - } - else - { - XMapWindow(dpy, Tmp_win->w); - SetMapStateProp(Tmp_win, NormalState); - } - break; - - case IconicState: - if (Tmp_win->wmhints) - { - Iconify(Tmp_win, - Tmp_win->wmhints->icon_x, Tmp_win->wmhints->icon_y); - } - else - { - Iconify(Tmp_win, 0, 0); - } - break; + if (!PPosOverride) + XSync(dpy, 0); + MyXUngrabServer(dpy); } - if(!PPosOverride) - XSync(dpy,0); - MyXUngrabServer(dpy); - } - /* If no hints, or currently an icon, just "deiconify" */ - else - { - DeIconify(Tmp_win); - } - if(!PPosOverride) - KeepOnTop(); + /* If no hints, or currently an icon, just "deiconify" */ + else { + DeIconify(Tmp_win); + } + if (!PPosOverride) + KeepOnTop(); } - /*********************************************************************** * * Procedure: * HandleMapNotify - MapNotify event handler * ***********************************************************************/ -void HandleMapNotify() +void +HandleMapNotify() { - Boolean OnThisPage = False; + Boolean OnThisPage = False; - DBUG("HandleMapNotify","Routine Entered"); + DBUG("HandleMapNotify", "Routine Entered"); - if (!Tmp_win) - { - if((Event.xmap.override_redirect == True)&& - (Event.xmap.window != Scr.NoFocusWin)) - { - XSelectInput(dpy,Event.xmap.window,FocusChangeMask); - Scr.UnknownWinFocused = Event.xmap.window; + if (!Tmp_win) { + if ((Event.xmap.override_redirect == True) && + (Event.xmap.window != Scr.NoFocusWin)) { + XSelectInput(dpy, Event.xmap.window, FocusChangeMask); + Scr.UnknownWinFocused = Event.xmap.window; + } + return; + } + + /* Except for identifying over-ride redirect window mappings, we + * don't need or want windows associated with the sunstructurenotifymask + */ + if (Event.xmap.event != Event.xmap.window) + return; + + /* + Make sure at least part of window is on this page + before giving it focus... + */ + if ((Tmp_win->Desk == Scr.CurrentDesk) && + (((Tmp_win->frame_x + Tmp_win->frame_width) >= 0 && + Tmp_win->frame_x < Scr.MyDisplayWidth) && + ((Tmp_win->frame_y + Tmp_win->frame_height) >= 0 && + Tmp_win->frame_y < Scr.MyDisplayHeight))) { + OnThisPage = True; + } + + /* + * Need to do the grab to avoid race condition of having server send + * MapNotify to client before the frame gets mapped; this is bad because + * the client would think that the window has a chance of being viewable + * when it really isn't. + */ + MyXGrabServer(dpy); + if (Tmp_win->icon_w) + XUnmapWindow(dpy, Tmp_win->icon_w); + if (Tmp_win->icon_pixmap_w != None) + XUnmapWindow(dpy, Tmp_win->icon_pixmap_w); + XMapSubwindows(dpy, Tmp_win->frame); + + if (Tmp_win->Desk == Scr.CurrentDesk) { + XMapWindow(dpy, Tmp_win->frame); } - return; - } - - /* Except for identifying over-ride redirect window mappings, we - * don't need or want windows associated with the sunstructurenotifymask */ - if(Event.xmap.event != Event.xmap.window) - return; - - /* - Make sure at least part of window is on this page - before giving it focus... - */ - if ( (Tmp_win->Desk == Scr.CurrentDesk) && - ( ((Tmp_win->frame_x + Tmp_win->frame_width) >= 0 && - Tmp_win->frame_x < Scr.MyDisplayWidth) && - ((Tmp_win->frame_y + Tmp_win->frame_height) >= 0 && - Tmp_win->frame_y < Scr.MyDisplayHeight) - ) - ) - { - OnThisPage = True; - } - - /* - * Need to do the grab to avoid race condition of having server send - * MapNotify to client before the frame gets mapped; this is bad because - * the client would think that the window has a chance of being viewable - * when it really isn't. - */ - MyXGrabServer (dpy); - if (Tmp_win->icon_w) - XUnmapWindow(dpy, Tmp_win->icon_w); - if(Tmp_win->icon_pixmap_w != None) - XUnmapWindow(dpy, Tmp_win->icon_pixmap_w); - XMapSubwindows(dpy, Tmp_win->frame); - - if(Tmp_win->Desk == Scr.CurrentDesk) - { - XMapWindow(dpy, Tmp_win->frame); - } - - if(Tmp_win->flags & ICONIFIED) - BroadcastPacket(M_DEICONIFY, 3, - Tmp_win->w, Tmp_win->frame, (unsigned long)Tmp_win); - else - BroadcastPacket(M_MAP, 3, - Tmp_win->w,Tmp_win->frame, (unsigned long)Tmp_win); - - if((Tmp_win->flags & ClickToFocus)&& - ((!Scr.Focus)||(Scr.Focus->flags & ClickToFocus))) - { - if (OnThisPage) - { - SetFocus(Tmp_win->w,Tmp_win,1); - } - } - if((!(Tmp_win->flags &(BORDER|TITLE)))&&(Tmp_win->boundary_width <2)) - { - SetBorder(Tmp_win,False,True,True,Tmp_win->frame); - } - XSync(dpy,0); - MyXUngrabServer (dpy); - XFlush (dpy); - Tmp_win->flags |= MAPPED; - Tmp_win->flags &= ~MAP_PENDING; - Tmp_win->flags &= ~ICONIFIED; - Tmp_win->flags &= ~ICON_UNMAPPED; - KeepOnTop(); -} + if (Tmp_win->flags & ICONIFIED) + BroadcastPacket(M_DEICONIFY, 3, Tmp_win->w, Tmp_win->frame, + (unsigned long)Tmp_win); + else + BroadcastPacket(M_MAP, 3, Tmp_win->w, Tmp_win->frame, + (unsigned long)Tmp_win); + + if ((Tmp_win->flags & ClickToFocus) && + ((!Scr.Focus) || (Scr.Focus->flags & ClickToFocus))) { + if (OnThisPage) { + SetFocus(Tmp_win->w, Tmp_win, 1); + } + } + if ((!(Tmp_win->flags & (BORDER | TITLE))) && + (Tmp_win->boundary_width < 2)) { + SetBorder(Tmp_win, False, True, True, Tmp_win->frame); + } + XSync(dpy, 0); + MyXUngrabServer(dpy); + XFlush(dpy); + Tmp_win->flags |= MAPPED; + Tmp_win->flags &= ~MAP_PENDING; + Tmp_win->flags &= ~ICONIFIED; + Tmp_win->flags &= ~ICON_UNMAPPED; + KeepOnTop(); +} /*********************************************************************** * @@ -938,135 +853,129 @@ void HandleMapNotify() * HandleUnmapNotify - UnmapNotify event handler * ************************************************************************/ -void HandleUnmapNotify() +void +HandleUnmapNotify() { - int dstx, dsty; - Window dumwin; - XEvent dummy; - extern FvwmWindow *colormap_win; - int weMustUnmap; - - DBUG("HandleUnmapNotify","Routine Entered"); - - /* - * Don't ignore events as described below. - */ - if((Event.xunmap.event != Event.xunmap.window) && - (Event.xunmap.event != Scr.Root || !Event.xunmap.send_event)) - { - return; - } - - /* - * The July 27, 1988 ICCCM spec states that a client wishing to switch - * to WithdrawnState should send a synthetic UnmapNotify with the - * event field set to (pseudo-)root, in case the window is already - * unmapped (which is the case for fvwm for IconicState). Unfortunately, - * we looked for the FvwmContext using that field, so try the window - * field also. - */ - weMustUnmap = 0; - if (!Tmp_win) - { - Event.xany.window = Event.xunmap.window; - weMustUnmap = 1; - if (XFindContext(dpy, Event.xany.window, - FvwmContext, (caddr_t *)&Tmp_win) == XCNOENT) - Tmp_win = NULL; - } - - if(!Tmp_win) - return; - - if(weMustUnmap) - XUnmapWindow(dpy, Event.xunmap.window); - - if(Tmp_win == Scr.Hilite) - Scr.Hilite = NULL; - - if(Scr.PreviousFocus == Tmp_win) - Scr.PreviousFocus = NULL; - - if((Tmp_win == Scr.Focus)&&(Tmp_win->flags & ClickToFocus)) - { - if(Tmp_win->next) - { - HandleHardFocus(Tmp_win->next); + int dstx, dsty; + Window dumwin; + XEvent dummy; + extern FvwmWindow *colormap_win; + int weMustUnmap; + + DBUG("HandleUnmapNotify", "Routine Entered"); + + /* + * Don't ignore events as described below. + */ + if ((Event.xunmap.event != Event.xunmap.window) && + (Event.xunmap.event != Scr.Root || !Event.xunmap.send_event)) { + return; } - else - SetFocus(Scr.NoFocusWin,NULL,1); - } - - if(Scr.Focus == Tmp_win) - SetFocus(Scr.NoFocusWin,NULL,1); - - if(Tmp_win == Scr.pushed_window) - Scr.pushed_window = NULL; - - if(Tmp_win == colormap_win) - colormap_win = NULL; - - if ((!(Tmp_win->flags & MAPPED)&&!(Tmp_win->flags&ICONIFIED))) - { - return; - } - - MyXGrabServer(dpy); - - if(XCheckTypedWindowEvent (dpy, Event.xunmap.window, DestroyNotify,&dummy)) - { - Destroy(Tmp_win); - MyXUngrabServer (dpy); - return; - } - - /* - * The program may have unmapped the client window, from either - * NormalState or IconicState. Handle the transition to WithdrawnState. - * - * We need to reparent the window back to the root (so that fvwm exiting - * won't cause it to get mapped) and then throw away all state (pretend - * that we've received a DestroyNotify). - */ - if (XTranslateCoordinates (dpy, Event.xunmap.window, Scr.Root, - 0, 0, &dstx, &dsty, &dumwin)) - { - XEvent ev; - Bool reparented; - - reparented = XCheckTypedWindowEvent (dpy, Event.xunmap.window, - ReparentNotify, &ev); - SetMapStateProp (Tmp_win, WithdrawnState); - if (reparented) - { - if (Tmp_win->old_bw) - XSetWindowBorderWidth (dpy, Event.xunmap.window, Tmp_win->old_bw); - if((!(Tmp_win->flags & SUPPRESSICON))&& - (Tmp_win->wmhints && (Tmp_win->wmhints->flags & IconWindowHint))) - XUnmapWindow (dpy, Tmp_win->wmhints->icon_window); + + /* + * The July 27, 1988 ICCCM spec states that a client wishing to switch + * to WithdrawnState should send a synthetic UnmapNotify with the + * event field set to (pseudo-)root, in case the window is already + * unmapped (which is the case for fvwm for IconicState). Unfortunately, + * we looked for the FvwmContext using that field, so try the window + * field also. + */ + weMustUnmap = 0; + if (!Tmp_win) { + Event.xany.window = Event.xunmap.window; + weMustUnmap = 1; + if (XFindContext(dpy, Event.xany.window, FvwmContext, + (caddr_t *)&Tmp_win) == XCNOENT) + Tmp_win = NULL; } - else - { - RestoreWithdrawnLocation (Tmp_win,False); + + if (!Tmp_win) + return; + + if (weMustUnmap) + XUnmapWindow(dpy, Event.xunmap.window); + + if (Tmp_win == Scr.Hilite) + Scr.Hilite = NULL; + + if (Scr.PreviousFocus == Tmp_win) + Scr.PreviousFocus = NULL; + + if ((Tmp_win == Scr.Focus) && (Tmp_win->flags & ClickToFocus)) { + if (Tmp_win->next) { + HandleHardFocus(Tmp_win->next); + } else + SetFocus(Scr.NoFocusWin, NULL, 1); + } + + if (Scr.Focus == Tmp_win) + SetFocus(Scr.NoFocusWin, NULL, 1); + + if (Tmp_win == Scr.pushed_window) + Scr.pushed_window = NULL; + + if (Tmp_win == colormap_win) + colormap_win = NULL; + + if ((!(Tmp_win->flags & MAPPED) && !(Tmp_win->flags & ICONIFIED))) { + return; } - XRemoveFromSaveSet (dpy, Event.xunmap.window); - XSelectInput (dpy, Event.xunmap.window, NoEventMask); - Destroy(Tmp_win); /* do not need to mash event before */ - /* - * Flush any pending events for the window. - */ - /* Bzzt! it could be about to re-map */ -/* while(XCheckWindowEvent(dpy, Event.xunmap.window, - StructureNotifyMask | PropertyChangeMask | - ColormapChangeMask | VisibilityChangeMask | - EnterWindowMask | LeaveWindowMask, &dummy)); - */ - } /* else window no longer exists and we'll get a destroy notify */ - MyXUngrabServer(dpy); - - XFlush (dpy); -} + MyXGrabServer(dpy); + + if (XCheckTypedWindowEvent( + dpy, Event.xunmap.window, DestroyNotify, &dummy)) { + Destroy(Tmp_win); + MyXUngrabServer(dpy); + return; + } + + /* + * The program may have unmapped the client window, from either + * NormalState or IconicState. Handle the transition to WithdrawnState. + * + * We need to reparent the window back to the root (so that fvwm exiting + * won't cause it to get mapped) and then throw away all state (pretend + * that we've received a DestroyNotify). + */ + if (XTranslateCoordinates(dpy, Event.xunmap.window, Scr.Root, 0, 0, + &dstx, &dsty, &dumwin)) { + XEvent ev; + Bool reparented; + + reparented = XCheckTypedWindowEvent( + dpy, Event.xunmap.window, ReparentNotify, &ev); + SetMapStateProp(Tmp_win, WithdrawnState); + if (reparented) { + if (Tmp_win->old_bw) + XSetWindowBorderWidth( + dpy, Event.xunmap.window, Tmp_win->old_bw); + if ((!(Tmp_win->flags & SUPPRESSICON)) && + (Tmp_win->wmhints && + (Tmp_win->wmhints->flags & IconWindowHint))) + XUnmapWindow( + dpy, Tmp_win->wmhints->icon_window); + } else { + RestoreWithdrawnLocation(Tmp_win, False); + } + XRemoveFromSaveSet(dpy, Event.xunmap.window); + XSelectInput(dpy, Event.xunmap.window, NoEventMask); + Destroy(Tmp_win); /* do not need to mash event before */ + /* + * Flush any pending events for the window. + */ + /* Bzzt! it could be about to re-map */ + /* while(XCheckWindowEvent(dpy, Event.xunmap.window, + StructureNotifyMask | + PropertyChangeMask | ColormapChangeMask | + VisibilityChangeMask | EnterWindowMask | LeaveWindowMask, + &dummy)); + */ + } /* else window no longer exists and we'll get a destroy notify */ + MyXUngrabServer(dpy); + + XFlush(dpy); +} /*********************************************************************** * @@ -1074,105 +983,103 @@ void HandleUnmapNotify() * HandleButtonPress - ButtonPress event handler * ***********************************************************************/ -void HandleButtonPress() +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; + 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); + /* CLICKY_MODE_1: raise window on click */ + 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))) { + 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; } /*********************************************************************** @@ -1181,78 +1088,72 @@ void HandleButtonPress() * HandleEnterNotify - EnterNotify event handler * ************************************************************************/ -void HandleEnterNotify() +void +HandleEnterNotify() { - XEnterWindowEvent *ewp = &Event.xcrossing; - XEvent d; - - DBUG("HandleEnterNotify","Routine Entered"); - - /* look for a matching leaveNotify which would nullify this enterNotify */ - if(XCheckTypedWindowEvent (dpy, ewp->window, LeaveNotify, &d)) - { - /* - RBW - if we're in startup, this is a coerced focus, so we don't - want to save the event time, or exit prematurely. - */ - if (! fFvwmInStartup) - { - StashEventTime(&d); - if((d.xcrossing.mode==NotifyNormal)&& - (d.xcrossing.detail!=NotifyInferior)) - return; - } - } + XEnterWindowEvent *ewp = &Event.xcrossing; + XEvent d; + + DBUG("HandleEnterNotify", "Routine Entered"); + + /* look for a matching leaveNotify which would nullify this enterNotify + */ + if (XCheckTypedWindowEvent(dpy, ewp->window, LeaveNotify, &d)) { + /* + RBW - if we're in startup, this is a coerced focus, so we + don't want to save the event time, or exit prematurely. + */ + if (!fFvwmInStartup) { + StashEventTime(&d); + if ((d.xcrossing.mode == NotifyNormal) && + (d.xcrossing.detail != NotifyInferior)) + return; + } + } /* an EnterEvent in one of the PanFrameWindows activates the Paging */ #ifndef NON_VIRTUAL - if (ewp->window==Scr.PanFrameTop.win - || ewp->window==Scr.PanFrameLeft.win - || ewp->window==Scr.PanFrameRight.win - || ewp->window==Scr.PanFrameBottom.win ) - { - int delta_x=0, delta_y=0; - /* this was in the HandleMotionNotify before, HEDU */ - HandlePaging(Scr.EdgeScrollX,Scr.EdgeScrollY, - &Event.xcrossing.x_root,&Event.xcrossing.y_root, - &delta_x,&delta_y,True); - return; - } + if (ewp->window == Scr.PanFrameTop.win || + ewp->window == Scr.PanFrameLeft.win || + ewp->window == Scr.PanFrameRight.win || + ewp->window == Scr.PanFrameBottom.win) { + int delta_x = 0, delta_y = 0; + /* this was in the HandleMotionNotify before, HEDU */ + HandlePaging(Scr.EdgeScrollX, Scr.EdgeScrollY, + &Event.xcrossing.x_root, &Event.xcrossing.y_root, &delta_x, + &delta_y, True); + return; + } #endif /* NON_VIRTUAL */ - /* multi screen? */ - if (Event.xany.window == Scr.Root) - { - if (!Scr.Focus || (!(Scr.Focus->flags&ClickToFocus)&& - !(Scr.Focus->flags&SloppyFocus))) - { - SetFocus(Scr.NoFocusWin,NULL,1); - } - if (Scr.ColormapFocus == COLORMAP_FOLLOWS_MOUSE) - { - InstallWindowColormaps(NULL); - } - return; - } - - /* make sure its for one of our windows */ - if (!Tmp_win) - return; - - if(!(Tmp_win->flags & ClickToFocus)) - { - SetFocus(Tmp_win->w,Tmp_win,1); - } - if (Scr.ColormapFocus == COLORMAP_FOLLOWS_MOUSE) - { - if((!(Tmp_win->flags & ICONIFIED))&&(Event.xany.window == Tmp_win->w)) - InstallWindowColormaps(Tmp_win); - else - InstallWindowColormaps(NULL); - } - return; -} + /* multi screen? */ + if (Event.xany.window == Scr.Root) { + if (!Scr.Focus || (!(Scr.Focus->flags & ClickToFocus) && + !(Scr.Focus->flags & SloppyFocus))) { + SetFocus(Scr.NoFocusWin, NULL, 1); + } + if (Scr.ColormapFocus == COLORMAP_FOLLOWS_MOUSE) { + InstallWindowColormaps(NULL); + } + return; + } + + /* make sure its for one of our windows */ + if (!Tmp_win) + return; + if (!(Tmp_win->flags & ClickToFocus)) { + SetFocus(Tmp_win->w, Tmp_win, 1); + } + if (Scr.ColormapFocus == COLORMAP_FOLLOWS_MOUSE) { + if ((!(Tmp_win->flags & ICONIFIED)) && + (Event.xany.window == Tmp_win->w)) + InstallWindowColormaps(Tmp_win); + else + InstallWindowColormaps(NULL); + } + return; +} /*********************************************************************** * @@ -1260,212 +1161,215 @@ void HandleEnterNotify() * HandleLeaveNotify - LeaveNotify event handler * ************************************************************************/ -void HandleLeaveNotify() +void +HandleLeaveNotify() { - DBUG("HandleLeaveNotify","Routine Entered"); - - /* If we leave the root window, then we're really moving - * another screen on a multiple screen display, and we - * need to de-focus and unhighlight to make sure that we - * don't end up with more than one highlighted window at a time */ - if(Event.xcrossing.window == Scr.Root) - { - if(Event.xcrossing.mode == NotifyNormal) - { - if (Event.xcrossing.detail != NotifyInferior) - { - if(Scr.Focus != NULL) - { - SetFocus(Scr.NoFocusWin,NULL,1); + DBUG("HandleLeaveNotify", "Routine Entered"); + + /* If we leave the root window, then we're really moving + * another screen on a multiple screen display, and we + * need to de-focus and unhighlight to make sure that we + * don't end up with more than one highlighted window at a time */ + if (Event.xcrossing.window == Scr.Root) { + if (Event.xcrossing.mode == NotifyNormal) { + if (Event.xcrossing.detail != NotifyInferior) { + if (Scr.Focus != NULL) { + SetFocus(Scr.NoFocusWin, NULL, 1); + } + if (Scr.Hilite != NULL) + SetBorder(Scr.Hilite, False, True, True, + None); + } } - if(Scr.Hilite != NULL) - SetBorder(Scr.Hilite,False,True,True,None); - } } - } } - /*********************************************************************** * * Procedure: * HandleConfigureRequest - ConfigureRequest event handler * ************************************************************************/ -void HandleConfigureRequest() +void +HandleConfigureRequest() { - XWindowChanges xwc; - unsigned long xwcm; - int x, y, width, height; - XConfigureRequestEvent *cre = &Event.xconfigurerequest; - Bool sendEvent=False; - FvwmWindow *FvwmSib; - - DBUG("HandleConfigureRequest","Routine Entered"); - - /* - * Event.xany.window is Event.xconfigurerequest.parent, so Tmp_win will - * be wrong - */ - Event.xany.window = cre->window; /* mash parent field */ - if (XFindContext (dpy, cre->window, FvwmContext, (caddr_t *) &Tmp_win) == - XCNOENT) - Tmp_win = NULL; - - /* - * According to the July 27, 1988 ICCCM draft, we should ignore size and - * position fields in the WM_NORMAL_HINTS property when we map a window. - * Instead, we'll read the current geometry. Therefore, we should respond - * to configuration requests for windows which have never been mapped. - */ - if (!Tmp_win || cre->window == Tmp_win->icon_w || - cre->window == Tmp_win->icon_pixmap_w) - { - - xwcm = cre->value_mask & - (CWX | CWY | CWWidth | CWHeight | CWBorderWidth); - xwc.x = cre->x; - xwc.y = cre->y; - if((Tmp_win)&&((Tmp_win->icon_pixmap_w == cre->window))) - { - Tmp_win->icon_p_height = cre->height+ cre->border_width + - cre->border_width; - } - else if((Tmp_win)&&((Tmp_win->icon_w == cre->window))) - { - Tmp_win->icon_xl_loc = cre->x; - Tmp_win->icon_x_loc = cre->x + - (Tmp_win->icon_w_width - Tmp_win->icon_p_width)/2; - Tmp_win->icon_y_loc = cre->y - Tmp_win->icon_p_height; - if(!(Tmp_win->flags & ICON_UNMAPPED)) - BroadcastPacket(M_ICON_LOCATION, 7, - Tmp_win->w, Tmp_win->frame, - (unsigned long)Tmp_win, - Tmp_win->icon_x_loc, Tmp_win->icon_y_loc, - Tmp_win->icon_w_width, - Tmp_win->icon_w_height + Tmp_win->icon_p_height); - } - xwc.width = cre->width; - xwc.height = cre->height; - xwc.border_width = cre->border_width; - - XConfigureWindow(dpy, Event.xany.window, xwcm, &xwc); - - if(Tmp_win) - { - if (cre->window != Tmp_win->icon_pixmap_w && - Tmp_win->icon_pixmap_w != None) - { - xwc.x = Tmp_win->icon_x_loc; - xwc.y = Tmp_win->icon_y_loc - Tmp_win->icon_p_height; - xwcm = cre->value_mask & (CWX | CWY); - XConfigureWindow(dpy, Tmp_win->icon_pixmap_w, xwcm, &xwc); - } - if(Tmp_win->icon_w != None) - { - xwc.x = Tmp_win->icon_x_loc; - xwc.y = Tmp_win->icon_y_loc; - xwcm = cre->value_mask & (CWX | CWY); - XConfigureWindow(dpy, Tmp_win->icon_w, xwcm, &xwc); - } - } - return; - } - - /* Stacking order change requested... */ - if (cre->value_mask & CWStackMode) - { - FvwmWindow *otherwin; - - otherwin = NULL; - xwc.sibling = (((cre->value_mask & CWSibling) && - (XFindContext (dpy, cre->above, FvwmContext, - (caddr_t *) &otherwin) == XCSUCCESS)) - ? otherwin->frame : cre->above); - xwc.stack_mode = cre->detail; - XConfigureWindow (dpy, Tmp_win->frame, - cre->value_mask & (CWSibling | CWStackMode), &xwc); - sendEvent = True; - - /* - RBW - Update the stacking order ring. - */ - if (xwc.stack_mode == Above || xwc.stack_mode == Below) - { - FvwmSib = (otherwin != NULL ) ? otherwin: Scr.FvwmRoot.stack_next; /* Set up for Above. */ - if (xwc.stack_mode == Below) - { - /* - If Below-sibling, raise above next lower window. If no sibling, - bottom of stack is "above" Scr.FvwmRoot in the ring. - */ - FvwmSib = (FvwmSib == otherwin) ? FvwmSib->stack_next: FvwmSib->stack_prev; - } - if (Tmp_win != FvwmSib) /* Don't chain it to itself! */ - { - Tmp_win->stack_prev->stack_next = Tmp_win->stack_next; /* Pluck from chain. */ - Tmp_win->stack_next->stack_prev = Tmp_win->stack_prev; - Tmp_win->stack_next = FvwmSib; /* Set new pointers. */ - Tmp_win->stack_prev = FvwmSib->stack_prev; - FvwmSib->stack_prev->stack_next = Tmp_win; /* Re-insert above sibling. */ - FvwmSib->stack_prev = Tmp_win; - } - } - else - { - /* - Oh, bother! We have to rebuild the stacking order ring to figure - out where this one went (TopIf, BottomIf, or Opposite). - */ - ResyncFvwmStackRing(); - } - } + XWindowChanges xwc; + unsigned long xwcm; + int x, y, width, height; + XConfigureRequestEvent *cre = &Event.xconfigurerequest; + Bool sendEvent = False; + FvwmWindow *FvwmSib; + + DBUG("HandleConfigureRequest", "Routine Entered"); + + /* + * Event.xany.window is Event.xconfigurerequest.parent, so Tmp_win will + * be wrong + */ + Event.xany.window = cre->window; /* mash parent field */ + if (XFindContext(dpy, cre->window, FvwmContext, (caddr_t *)&Tmp_win) == + XCNOENT) + Tmp_win = NULL; + + /* + * According to the July 27, 1988 ICCCM draft, we should ignore size and + * position fields in the WM_NORMAL_HINTS property when we map a window. + * Instead, we'll read the current geometry. Therefore, we should + * respond to configuration requests for windows which have never been + * mapped. + */ + if (!Tmp_win || cre->window == Tmp_win->icon_w || + cre->window == Tmp_win->icon_pixmap_w) { + xwcm = cre->value_mask & + (CWX | CWY | CWWidth | CWHeight | CWBorderWidth); + xwc.x = cre->x; + xwc.y = cre->y; + if ((Tmp_win) && ((Tmp_win->icon_pixmap_w == cre->window))) { + Tmp_win->icon_p_height = + cre->height + cre->border_width + cre->border_width; + } else if ((Tmp_win) && ((Tmp_win->icon_w == cre->window))) { + Tmp_win->icon_xl_loc = cre->x; + Tmp_win->icon_x_loc = + cre->x + + (Tmp_win->icon_w_width - Tmp_win->icon_p_width) / 2; + Tmp_win->icon_y_loc = cre->y - Tmp_win->icon_p_height; + if (!(Tmp_win->flags & ICON_UNMAPPED)) + BroadcastPacket(M_ICON_LOCATION, 7, Tmp_win->w, + Tmp_win->frame, (unsigned long)Tmp_win, + Tmp_win->icon_x_loc, Tmp_win->icon_y_loc, + Tmp_win->icon_w_width, + Tmp_win->icon_w_height + + Tmp_win->icon_p_height); + } + xwc.width = cre->width; + xwc.height = cre->height; + xwc.border_width = cre->border_width; + + XConfigureWindow(dpy, Event.xany.window, xwcm, &xwc); + + if (Tmp_win) { + if (cre->window != Tmp_win->icon_pixmap_w && + Tmp_win->icon_pixmap_w != None) { + xwc.x = Tmp_win->icon_x_loc; + xwc.y = Tmp_win->icon_y_loc - + Tmp_win->icon_p_height; + xwcm = cre->value_mask & (CWX | CWY); + XConfigureWindow( + dpy, Tmp_win->icon_pixmap_w, xwcm, &xwc); + } + if (Tmp_win->icon_w != None) { + xwc.x = Tmp_win->icon_x_loc; + xwc.y = Tmp_win->icon_y_loc; + xwcm = cre->value_mask & (CWX | CWY); + XConfigureWindow( + dpy, Tmp_win->icon_w, xwcm, &xwc); + } + } + return; + } + + /* Stacking order change requested... */ + if (cre->value_mask & CWStackMode) { + FvwmWindow *otherwin; + + otherwin = NULL; + xwc.sibling = (((cre->value_mask & CWSibling) && + (XFindContext(dpy, cre->above, FvwmContext, + (caddr_t *)&otherwin) == XCSUCCESS)) ? + otherwin->frame : + cre->above); + xwc.stack_mode = cre->detail; + XConfigureWindow(dpy, Tmp_win->frame, + cre->value_mask & (CWSibling | CWStackMode), &xwc); + sendEvent = True; + + /* + RBW - Update the stacking order ring. + */ + if (xwc.stack_mode == Above || xwc.stack_mode == Below) { + FvwmSib = + (otherwin != NULL) ? + otherwin : + Scr.FvwmRoot + .stack_next; /* Set up for Above. */ + if (xwc.stack_mode == Below) { + /* + If Below-sibling, raise above next lower + window. If no sibling, bottom of stack is + "above" Scr.FvwmRoot in the ring. + */ + FvwmSib = (FvwmSib == otherwin) ? + FvwmSib->stack_next : + FvwmSib->stack_prev; + } + if (Tmp_win != + FvwmSib) { /* Don't chain it to itself! */ + Tmp_win->stack_prev->stack_next = + Tmp_win->stack_next; /* Pluck from chain. */ + Tmp_win->stack_next->stack_prev = + Tmp_win->stack_prev; + Tmp_win->stack_next = + FvwmSib; /* Set new pointers. */ + Tmp_win->stack_prev = FvwmSib->stack_prev; + FvwmSib->stack_prev->stack_next = + Tmp_win; /* Re-insert above sibling. */ + FvwmSib->stack_prev = Tmp_win; + } + } else { + /* + Oh, bother! We have to rebuild the stacking order + ring to figure out where this one went (TopIf, + BottomIf, or Opposite). + */ + ResyncFvwmStackRing(); + } + } #ifdef SHAPE - if (ShapesSupported) - { - int xws, yws, xbs, ybs; - unsigned wws, hws, wbs, hbs; - int boundingShaped, clipShaped; - - XShapeQueryExtents (dpy, Tmp_win->w,&boundingShaped, &xws, &yws, &wws, - &hws,&clipShaped, &xbs, &ybs, &wbs, &hbs); - Tmp_win->wShaped = boundingShaped; - } + if (ShapesSupported) { + int xws, yws, xbs, ybs; + unsigned wws, hws, wbs, hbs; + int boundingShaped, clipShaped; + + XShapeQueryExtents(dpy, Tmp_win->w, &boundingShaped, &xws, &yws, + &wws, &hws, &clipShaped, &xbs, &ybs, &wbs, &hbs); + Tmp_win->wShaped = boundingShaped; + } #endif /* SHAPE */ - /* Don't modify frame_XXX fields before calling SetupWindow! */ - x = Tmp_win->frame_x; - y = Tmp_win->frame_y; - width = Tmp_win->frame_width; - height = Tmp_win->frame_height; - - /* for restoring */ - if (cre->value_mask & CWBorderWidth) - { - Tmp_win->old_bw = cre->border_width; - } - /* override even if border change */ - - if (cre->value_mask & CWX) - x = cre->x - Tmp_win->boundary_width - Tmp_win->bw; - if (cre->value_mask & CWY) - y = cre->y - Tmp_win->boundary_width - Tmp_win->title_height - Tmp_win->bw; - if (cre->value_mask & CWWidth) - width = cre->width + 2*Tmp_win->boundary_width; - if (cre->value_mask & CWHeight) - height = cre->height+Tmp_win->title_height+2*Tmp_win->boundary_width; - - /* - * SetupWindow (x,y) are the location of the upper-left outer corner and - * are passed directly to XMoveResizeWindow (frame). The (width,height) - * are the inner size of the frame. The inner width is the same as the - * requested client window width; the inner height is the same as the - * requested client window height plus any title bar slop. - */ - ConstrainSize(Tmp_win, &width, &height, False, 0, 0); - SetupFrame (Tmp_win, x, y, width, height,sendEvent); - KeepOnTop(); + /* Don't modify frame_XXX fields before calling SetupWindow! */ + x = Tmp_win->frame_x; + y = Tmp_win->frame_y; + width = Tmp_win->frame_width; + height = Tmp_win->frame_height; + + /* for restoring */ + if (cre->value_mask & CWBorderWidth) { + Tmp_win->old_bw = cre->border_width; + } + /* override even if border change */ + + if (cre->value_mask & CWX) + x = cre->x - Tmp_win->boundary_width - Tmp_win->bw; + if (cre->value_mask & CWY) + y = cre->y - Tmp_win->boundary_width - Tmp_win->title_height - + Tmp_win->bw; + if (cre->value_mask & CWWidth) + width = cre->width + 2 * Tmp_win->boundary_width; + if (cre->value_mask & CWHeight) + height = cre->height + Tmp_win->title_height + + 2 * Tmp_win->boundary_width; + + /* + * SetupWindow (x,y) are the location of the upper-left outer corner and + * are passed directly to XMoveResizeWindow (frame). The (width,height) + * are the inner size of the frame. The inner width is the same as the + * requested client window width; the inner height is the same as the + * requested client window height plus any title bar slop. + */ + ConstrainSize(Tmp_win, &width, &height, False, 0, 0); + SetupFrame(Tmp_win, x, y, width, height, sendEvent); + KeepOnTop(); } /*********************************************************************** @@ -1475,23 +1379,23 @@ void HandleConfigureRequest() * ***********************************************************************/ #ifdef SHAPE -void HandleShapeNotify (void) +void +HandleShapeNotify(void) { - DBUG("HandleShapeNotify","Routine Entered"); - - if (ShapesSupported) - { - XShapeEvent *sev = (XShapeEvent *) &Event; - - if (!Tmp_win) - return; - if (sev->kind != ShapeBounding) - return; - Tmp_win->wShaped = sev->shaped; - SetShape(Tmp_win,Tmp_win->frame_width); - } + DBUG("HandleShapeNotify", "Routine Entered"); + + if (ShapesSupported) { + XShapeEvent *sev = (XShapeEvent *)&Event; + + if (!Tmp_win) + return; + if (sev->kind != ShapeBounding) + return; + Tmp_win->wShaped = sev->shaped; + SetShape(Tmp_win, Tmp_win->frame_width); + } } -#endif /* SHAPE*/ +#endif /* SHAPE*/ /*********************************************************************** * @@ -1500,127 +1404,114 @@ void HandleShapeNotify (void) * use in the RaiseLower function and the OnTop type windows. * ************************************************************************/ -void HandleVisibilityNotify() +void +HandleVisibilityNotify() { - XVisibilityEvent *vevent = (XVisibilityEvent *) &Event; - - DBUG("HandleVisibilityNotify","Routine Entered"); - - if(Tmp_win && Tmp_win->frame == last_event_window) - { - if(vevent->state == VisibilityUnobscured) - Tmp_win->flags |= VISIBLE; - else - Tmp_win->flags &= ~VISIBLE; - - /* For the most part, we'll raised partially obscured ONTOP windows - * here. The exception is ONTOP windows that are obscured by - * other ONTOP windows, which are raised in KeepOnTop(). This - * complicated set-up saves us from continually re-raising - * every on top window */ - if(((vevent->state == VisibilityPartiallyObscured)|| - (vevent->state == VisibilityFullyObscured))&& - (Tmp_win->flags&ONTOP)&&(Tmp_win->flags & RAISED)) - { - RaiseWindow(Tmp_win); - Tmp_win->flags &= ~RAISED; + XVisibilityEvent *vevent = (XVisibilityEvent *)&Event; + + DBUG("HandleVisibilityNotify", "Routine Entered"); + + if (Tmp_win && Tmp_win->frame == last_event_window) { + if (vevent->state == VisibilityUnobscured) + Tmp_win->flags |= VISIBLE; + else + Tmp_win->flags &= ~VISIBLE; + + /* For the most part, we'll raised partially obscured ONTOP + * windows here. The exception is ONTOP windows that are + * obscured by other ONTOP windows, which are raised in + * KeepOnTop(). This complicated set-up saves us from + * continually re-raising every on top window */ + if (((vevent->state == VisibilityPartiallyObscured) || + (vevent->state == VisibilityFullyObscured)) && + (Tmp_win->flags & ONTOP) && (Tmp_win->flags & RAISED)) { + RaiseWindow(Tmp_win); + Tmp_win->flags &= ~RAISED; + } } - } } - /*************************************************************************** * * Waits for next X event, or for an auto-raise timeout. * ****************************************************************************/ -int My_XNextEvent(Display *dpy, XEvent *event) +int +My_XNextEvent(Display *dpy, XEvent *event) { - extern int fd_width, x_fd; - fd_set in_fdset, out_fdset; - Window targetWindow; - int i; - - DBUG("My_XNextEvent","Routine Entered"); - - /* Do this IMMEDIATELY prior to select, to prevent any nasty - * queued up X events from just hanging around waiting to be - * flushed */ - XFlush(dpy); - if(XPending(dpy)) - { - DBUG("My_XNextEvent","taking care of queued up events & returning"); - XNextEvent(dpy,event); - StashEventTime(event); - return 1; - } - - DBUG("My_XNextEvent","no X events waiting - about to reap children"); - /* Zap all those zombies! */ - /* If we get to here, then there are no X events waiting to be processed. - * Just take a moment to check for dead children. */ - ReapChildren(); - - FD_ZERO(&in_fdset); - FD_SET(x_fd,&in_fdset); - FD_ZERO(&out_fdset); - for(i=0; i=0) - { - FD_SET(readPipes[i], &in_fdset); + extern int fd_width, x_fd; + fd_set in_fdset, out_fdset; + Window targetWindow; + int i; + + DBUG("My_XNextEvent", "Routine Entered"); + + /* Do this IMMEDIATELY prior to select, to prevent any nasty + * queued up X events from just hanging around waiting to be + * flushed */ + XFlush(dpy); + if (XPending(dpy)) { + DBUG("My_XNextEvent", + "taking care of queued up events & returning"); + XNextEvent(dpy, event); + StashEventTime(event); + return 1; } - if(pipeQueue[i]!= NULL) - { - FD_SET(writePipes[i], &out_fdset); - } - } - - DBUG("My_XNextEvent","waiting for module input/output"); - XFlush(dpy); - if (select((SELECT_TYPE_ARG1)fd_width, - SELECT_TYPE_ARG234 &in_fdset, - SELECT_TYPE_ARG234 &out_fdset, - SELECT_TYPE_ARG234 0, - SELECT_TYPE_ARG5 NULL) > 0) - { - - /* Check for module input. */ - for(i=0;i= 0) - { - if(FD_ISSET(readPipes[i], &in_fdset)) - { - if( read(readPipes[i],&targetWindow, sizeof(Window)) >0 ) - { - DBUG("My_XNextEvent","calling HandleModuleInput"); - HandleModuleInput(targetWindow,i); + + DBUG("My_XNextEvent", "no X events waiting - about to reap children"); + /* Zap all those zombies! */ + /* If we get to here, then there are no X events waiting to be + * processed. Just take a moment to check for dead children. */ + ReapChildren(); + + FD_ZERO(&in_fdset); + FD_SET(x_fd, &in_fdset); + FD_ZERO(&out_fdset); + for (i = 0; i < npipes; i++) { + if (readPipes[i] >= 0) { + FD_SET(readPipes[i], &in_fdset); } - else - { - DBUG("My_XNextEvent","calling KillModule"); - KillModule(i,10); + if (pipeQueue[i] != NULL) { + FD_SET(writePipes[i], &out_fdset); } - } } - if(writePipes[i] >= 0) - { - if(FD_ISSET(writePipes[i], &out_fdset)) - { - DBUG("My_XNextEvent","calling FlushQueue"); - FlushQueue(i); - } + + DBUG("My_XNextEvent", "waiting for module input/output"); + XFlush(dpy); + if (select((SELECT_TYPE_ARG1)fd_width, SELECT_TYPE_ARG234 & in_fdset, + SELECT_TYPE_ARG234 & out_fdset, SELECT_TYPE_ARG234 0, + SELECT_TYPE_ARG5 NULL) > 0) { + /* Check for module input. */ + for (i = 0; i < npipes; i++) { + if (readPipes[i] >= 0) { + if (FD_ISSET(readPipes[i], &in_fdset)) { + if (read(readPipes[i], &targetWindow, + sizeof(Window)) > 0) { + DBUG("My_XNextEvent", + "calling " + "HandleModuleInput"); + HandleModuleInput( + targetWindow, i); + } else { + DBUG("My_XNextEvent", + "calling KillModule"); + KillModule(i, 10); + } + } + } + if (writePipes[i] >= 0) { + if (FD_ISSET(writePipes[i], &out_fdset)) { + DBUG("My_XNextEvent", + "calling FlushQueue"); + FlushQueue(i); + } + } + } /* for */ } - } /* for */ - } - DBUG("My_XNextEvent","leaving My_XNextEvent"); - return 0; + DBUG("My_XNextEvent", "leaving My_XNextEvent"); + return 0; } - - - /* RBW - 01/07/1998 - this is here temporarily - I mean to move it to libfvwm eventually, along with some other chain manipulation functions. @@ -1633,65 +1524,56 @@ int My_XNextEvent(Display *dpy, XEvent *event) determine exactly where they ended up in the stacking order. - Based on code from Matthias Clasen. */ -void ResyncFvwmStackRing (void) +void +ResyncFvwmStackRing(void) { - Window root, parent, *children; - unsigned int nchildren, i; - FvwmWindow *t1, *t2; - - MyXGrabServer (dpy); - - if (!XQueryTree (dpy, Scr.Root, &root, &parent, &children, &nchildren)) - { - MyXUngrabServer (dpy); - return; - } - - t2 = &Scr.FvwmRoot; - for (i = 0; i < nchildren; i++) - { - for (t1 = Scr.FvwmRoot.next; t1 != NULL; t1 = t1->next) - { - if (t1->flags & ICONIFIED && (!(t1->flags & SUPPRESSICON))) - { - if (t1->icon_w == children[i]) - { - break; - } - else if (t1->icon_pixmap_w == children[i]) - { - break; - } - } - else - { - if (t1->frame == children[i]) - { - break; - } - } - } + Window root, parent, *children; + unsigned int nchildren, i; + FvwmWindow *t1, *t2; - if (t1 != NULL && t1 != t2) - { - /* - Move the window to its new position, working from the bottom up - (that's the way XQueryTree presents the list). - */ - t1->stack_prev->stack_next = t1->stack_next; /* Pluck from chain. */ - t1->stack_next->stack_prev = t1->stack_prev; - t1->stack_next = t2; /* Set new pointers. */ - t1->stack_prev = t2->stack_prev; - t2->stack_prev->stack_next = t1; /* Insert in new position. */ - t2->stack_prev = t1; - t2 = t1; + MyXGrabServer(dpy); + if (!XQueryTree(dpy, Scr.Root, &root, &parent, &children, &nchildren)) { + MyXUngrabServer(dpy); + return; } - } - MyXUngrabServer (dpy); + t2 = &Scr.FvwmRoot; + for (i = 0; i < nchildren; i++) { + for (t1 = Scr.FvwmRoot.next; t1 != NULL; t1 = t1->next) { + if (t1->flags & ICONIFIED && + (!(t1->flags & SUPPRESSICON))) { + if (t1->icon_w == children[i]) { + break; + } else if (t1->icon_pixmap_w == children[i]) { + break; + } + } else { + if (t1->frame == children[i]) { + break; + } + } + } - XFree (children); -} + if (t1 != NULL && t1 != t2) { + /* + Move the window to its new position, working + from the bottom up (that's the way XQueryTree + presents the list). + */ + t1->stack_prev->stack_next = + t1->stack_next; /* Pluck from chain. */ + t1->stack_next->stack_prev = t1->stack_prev; + t1->stack_next = t2; /* Set new pointers. */ + t1->stack_prev = t2->stack_prev; + t2->stack_prev->stack_next = + t1; /* Insert in new position. */ + t2->stack_prev = t1; + t2 = t1; + } + } + MyXUngrabServer(dpy); + XFree(children); +} Index: fvwm/fvwm/exec.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/exec.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/exec.c --- /dev/null +++ fvwm/fvwm/exec.c @@ -0,0 +1,208 @@ +/* + * exec.c -- interface to the privilege-separated execution helper. + * + * The main fvwm process communicates with fvwm_exec via imsg(3) + * over a socketpair(2). The helper executes external commands + * without inheriting the X11 connection. + */ + +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "config.h" +#include "fvwm.h" +#include "misc.h" + +enum imsg_exec_type { + IMSG_EXEC_RUN = 0, + IMSG_EXEC_OK, + IMSG_EXEC_ERROR, + IMSG_EXEC_EXIT, +}; + +static struct imsgbuf *exec_ibuf; +static int exec_fd = -1; +static pid_t exec_pid = -1; + +/* + * exec_helper_start -- fork and exec the execution helper. + * The helper receives one end of a socketpair for imsg communication. + */ +void +exec_helper_start(void) +{ + int sv[2]; + + if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, sv) == -1) + err(1, "socketpair"); + + exec_pid = fork(); + if (exec_pid == -1) + err(1, "fork"); + + if (exec_pid == 0) { + char fdstr[32]; + + close(sv[0]); + snprintf(fdstr, sizeof(fdstr), "%d", sv[1]); + setenv("FVWM_EXEC_FD", fdstr, 1); + + if (pledge("stdio proc exec", NULL) == -1) + err(1, "pledge"); + + execl(FVWMLIBDIR "/fvwm_exec", "fvwm_exec", NULL); + err(1, "execl %s/fvwm_exec", FVWMLIBDIR); + } + + close(sv[1]); + exec_fd = sv[0]; + + exec_ibuf = malloc(sizeof(struct imsgbuf)); + if (exec_ibuf == NULL) + err(1, "malloc"); + imsg_init(exec_ibuf, exec_fd); +} + +/* + * exec_helper_stop -- request helper shutdown and reap. + */ +void +exec_helper_stop(void) +{ + if (exec_ibuf == NULL) + return; + + imsg_clear(exec_ibuf); + close(exec_fd); + free(exec_ibuf); + exec_ibuf = NULL; + exec_fd = -1; + + if (exec_pid > 0) { + kill(exec_pid, SIGTERM); + waitpid(exec_pid, NULL, 0); + exec_pid = -1; + } +} + +/* + * exec_helper_handle -- process imsg responses from the helper. + * Called from the event loop when exec_fd is readable. + */ +void +exec_helper_handle(void) +{ + struct imsg imsg; + ssize_t n; + + if (exec_ibuf == NULL) + return; + + if ((n = imsg_read(exec_ibuf)) == -1 && errno != EAGAIN) + warn("imsg_read"); + if (n == 0) { + warnx("exec helper disconnected"); + exec_helper_stop(); + return; + } + + while ((n = imsg_get(exec_ibuf, &imsg)) != -1) { + if (n == 0) + break; + + switch (imsg.hdr.type) { + case IMSG_EXEC_OK: { + pid_t pid; + + if (imsg.hdr.len < (IMSG_HEADER_SIZE + sizeof(pid_t))) + break; + memcpy(&pid, imsg.data, sizeof(pid_t)); + break; + } + case IMSG_EXEC_ERROR: { + int errnum; + + if (imsg.hdr.len < (IMSG_HEADER_SIZE + sizeof(int))) + break; + memcpy(&errnum, imsg.data, sizeof(int)); + warnc(errnum, "exec helper reported error"); + break; + } + case IMSG_EXEC_EXIT: { + /* Module/command exit; handled by signal watching */ + break; + } + default: + break; + } + imsg_free(&imsg); + } +} + +/* + * exec_helper_launch -- request the helper to execute a command. + * On success, returns 0. On failure (fork error in helper), returns -1. + */ +int +exec_helper_launch(int argc, char **argv, char **envp) +{ + struct ibuf *buf; + size_t datalen, total; + int cargc = argc - 1; /* skip argv[0] which is the path */ + int envc = 0; + int i, ret = -1; + int fd; + + if (exec_ibuf == NULL) + return -1; + + /* Calculate total payload size: sizeof(int)*2 + all strings */ + datalen = sizeof(int) * 2; + for (i = 1; i < argc; i++) + datalen += strlen(argv[i]) + 1; + if (envp) { + for (i = 0; envp[i] != NULL; i++) { + datalen += strlen(envp[i]) + 1; + envc++; + } + } + + if (datalen > MAX_BODY_SIZE * sizeof(unsigned long)) { + warnx("exec argument too large"); + return -1; + } + + /* Compose and send the request */ + buf = imsg_create(exec_ibuf, IMSG_EXEC_RUN, 0, 0, datalen); + if (buf == NULL) + return -1; + + /* argc */ + buf->wpos += imsg_add(buf, &cargc, sizeof(int)); + /* envc */ + buf->wpos += imsg_add(buf, &envc, sizeof(int)); + /* strings */ + for (i = 1; i < argc; i++) { + buf->wpos += imsg_add(buf, argv[i], strlen(argv[i]) + 1); + } + if (envp) { + for (i = 0; envp[i] != NULL; i++) { + buf->wpos += imsg_add(buf, envp[i], + strlen(envp[i]) + 1); + } + } + imsg_close(exec_ibuf, buf); + imsg_flush(exec_ibuf); + + return 0; +} Index: fvwm/fvwm/focus.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/focus.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/focus.c --- fvwm/fvwm/focus.c +++ fvwm/fvwm/focus.c @@ -1,6 +1,6 @@ /**************************************************************************** - * This module is all original code - * by Rob Nation + * This module is all original code + * by Rob Nation * Copyright 1993, Robert Nation * You may use this code for any purpose, as long as the original * copyright remains in the source code and all documentation @@ -12,19 +12,17 @@ * ***********************************************************************/ -#include "config.h" - -#include #include +#include #include +#include "config.h" #include "fvwm.h" #include "menus.h" #include "misc.h" +#include "module.h" #include "parse.h" #include "screen.h" -#include "module.h" - /******************************************************************** * @@ -32,183 +30,173 @@ * **********************************************************************/ -void SetFocus(Window w, FvwmWindow *Fw, Bool FocusByMouse) +void +SetFocus(Window w, FvwmWindow *Fw, Bool FocusByMouse) { - int i; - Boolean OnThisPage = False; - extern Time lastTimestamp; - - /* ClickToFocus focus queue manipulation - only performed for - * Focus-by-mouse type focus events */ - /* Watch out: Fw may not be on the windowlist and the windowlist may be empty */ - if (Fw && Fw != Scr.Focus && Fw != &Scr.FvwmRoot) { - if (FocusByMouse) /* pluck window from list and deposit at top */ - { - /* remove Fw from list */ - if (Fw->prev) Fw->prev->next = Fw->next; - if (Fw->next) Fw->next->prev = Fw->prev; - - /* insert Fw at start */ - Fw->next = Scr.FvwmRoot.next; - if (Scr.FvwmRoot.next) Scr.FvwmRoot.next->prev = Fw; - Scr.FvwmRoot.next = Fw; - Fw->prev = &Scr.FvwmRoot; - } - else - { - /* move the windowlist around so that Fw is at the top */ - - FvwmWindow *tmp_win; - - /* find the window on the windowlist */ - tmp_win = &Scr.FvwmRoot; - while (tmp_win && tmp_win != Fw) - tmp_win = tmp_win->next; - - if (tmp_win) /* the window is on the (non-zero length) windowlist */ - { - /* make tmp_win point to the last window on the list */ - while (tmp_win->next) - tmp_win = tmp_win->next; - - /* close the ends of the windowlist */ - tmp_win->next = Scr.FvwmRoot.next; - Scr.FvwmRoot.next->prev = tmp_win; - - /* make Fw the new start of the list */ - Scr.FvwmRoot.next = Fw; - /* open the closed loop windowlist */ - Fw->prev->next = NULL; - Fw->prev = &Scr.FvwmRoot; - } - } - } - - if(Scr.NumberOfScreens > 1) - { - XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, - &JunkX, &JunkY, &JunkX, &JunkY, &JunkMask); - if(JunkRoot != Scr.Root) - { - if((Scr.Ungrabbed != NULL)&&(Scr.Ungrabbed->flags & ClickToFocus)) - { - /* Need to grab buttons for focus window */ - XSync(dpy,0); - for(i=0;i<3;i++) - if(Scr.buttons2grab & (1<frame,True, - ButtonPressMask, GrabModeSync,GrabModeAsync, - None,Scr.FvwmCursors[SYS]); - XGrabButton(dpy,(i+1),LockMask,Scr.Ungrabbed->frame,True, - ButtonPressMask, GrabModeSync,GrabModeAsync, - None,Scr.FvwmCursors[SYS]); - } - Scr.Focus = NULL; - Scr.Ungrabbed = NULL; - XSetInputFocus(dpy, Scr.NoFocusWin,RevertToParent,lastTimestamp); - } - return; + int i; + Boolean OnThisPage = False; + extern Time lastTimestamp; + + /* ClickToFocus focus queue manipulation - only performed for + * Focus-by-mouse type focus events */ + /* Watch out: Fw may not be on the windowlist and the windowlist may be + * empty */ + if (Fw && Fw != Scr.Focus && Fw != &Scr.FvwmRoot) { + if (FocusByMouse) { /* pluck window from list and deposit at top + */ + /* remove Fw from list */ + if (Fw->prev) + Fw->prev->next = Fw->next; + if (Fw->next) + Fw->next->prev = Fw->prev; + + /* insert Fw at start */ + Fw->next = Scr.FvwmRoot.next; + if (Scr.FvwmRoot.next) + Scr.FvwmRoot.next->prev = Fw; + Scr.FvwmRoot.next = Fw; + Fw->prev = &Scr.FvwmRoot; + } else { + /* move the windowlist around so that Fw is at the top + */ + + FvwmWindow *tmp_win; + + /* find the window on the windowlist */ + tmp_win = &Scr.FvwmRoot; + while (tmp_win && tmp_win != Fw) + tmp_win = tmp_win->next; + + if (tmp_win) { /* the window is on the (non-zero length) + windowlist */ + /* make tmp_win point to the last window on the + * list */ + while (tmp_win->next) + tmp_win = tmp_win->next; + + /* close the ends of the windowlist */ + tmp_win->next = Scr.FvwmRoot.next; + Scr.FvwmRoot.next->prev = tmp_win; + + /* make Fw the new start of the list */ + Scr.FvwmRoot.next = Fw; + /* open the closed loop windowlist */ + Fw->prev->next = NULL; + Fw->prev = &Scr.FvwmRoot; + } + } } - } - if (Fw != NULL) - { - /* - Make sure at least part of window is on this page - before giving it focus... + if (Scr.NumberOfScreens > 1) { + XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, &JunkX, + &JunkY, &JunkX, &JunkY, &JunkMask); + if (JunkRoot != Scr.Root) { + if ((Scr.Ungrabbed != NULL) && + (Scr.Ungrabbed->flags & ClickToFocus)) { + /* Need to grab buttons for focus window */ + XSync(dpy, 0); + for (i = 0; i < 3; i++) + if (Scr.buttons2grab & (1 << i)) { + XGrabButton(dpy, (i + 1), 0, + Scr.Ungrabbed->frame, True, + ButtonPressMask, + GrabModeSync, GrabModeAsync, + None, Scr.FvwmCursors[SYS]); + XGrabButton(dpy, (i + 1), + LockMask, + Scr.Ungrabbed->frame, True, + ButtonPressMask, + GrabModeSync, GrabModeAsync, + None, Scr.FvwmCursors[SYS]); + } + Scr.Focus = NULL; + Scr.Ungrabbed = NULL; + XSetInputFocus(dpy, Scr.NoFocusWin, + RevertToParent, lastTimestamp); + } + return; + } + } + + if (Fw != NULL) { + /* + Make sure at least part of window is on this page + before giving it focus... + */ + if ((Fw->Desk == Scr.CurrentDesk) && + (((Fw->frame_x + Fw->frame_width) >= 0 && + Fw->frame_x < Scr.MyDisplayWidth) && + ((Fw->frame_y + Fw->frame_height) >= 0 && + Fw->frame_y < Scr.MyDisplayHeight))) { + OnThisPage = True; + } + } + + if ((Fw != NULL) && (!OnThisPage)) { + Fw = NULL; + w = Scr.NoFocusWin; + } + + if ((Scr.Ungrabbed != NULL) && (Scr.Ungrabbed->flags & ClickToFocus) && + (Scr.Ungrabbed != Fw)) { + /* need to grab all buttons for window that we are about to + * unfocus */ + XSync(dpy, 0); + for (i = 0; i < 3; i++) + if (Scr.buttons2grab & (1 << i)) + XGrabButton(dpy, (i + 1), 0, + Scr.Ungrabbed->frame, True, ButtonPressMask, + GrabModeSync, GrabModeAsync, None, + Scr.FvwmCursors[SYS]); + Scr.Ungrabbed = NULL; + } + /* if we do click to focus, remove the grab on mouse events that + * was made to detect the focus change */ + if ((Fw != NULL) && (Fw->flags & ClickToFocus)) { + for (i = 0; i < 3; i++) + if (Scr.buttons2grab & (1 << i)) { + XUngrabButton(dpy, (i + 1), 0, Fw->frame); + XUngrabButton( + dpy, (i + 1), LockMask, Fw->frame); + } + Scr.Ungrabbed = Fw; + } + /* RBW - allow focus to go to a NoIconTitle icon window so + auto-raise will work on it... + if((Fw)&&(Fw->flags & ICONIFIED)&&(Fw->icon_w)) + w= Fw->icon_w; */ - if ( (Fw->Desk == Scr.CurrentDesk) && - ( ((Fw->frame_x + Fw->frame_width) >= 0 && - Fw->frame_x < Scr.MyDisplayWidth) && - ((Fw->frame_y + Fw->frame_height) >= 0 && - Fw->frame_y < Scr.MyDisplayHeight) - ) - ) - { - OnThisPage = True; - } - } - - if((Fw != NULL)&&(! OnThisPage)) - { - Fw = NULL; - w = Scr.NoFocusWin; - } - - if((Scr.Ungrabbed != NULL)&& - (Scr.Ungrabbed->flags & ClickToFocus) - && (Scr.Ungrabbed != Fw)) - { - /* need to grab all buttons for window that we are about to - * unfocus */ - XSync(dpy,0); - for(i=0;i<3;i++) - if(Scr.buttons2grab & (1<frame,True, - ButtonPressMask, GrabModeSync,GrabModeAsync,None, - Scr.FvwmCursors[SYS]); - Scr.Ungrabbed = NULL; - } - /* if we do click to focus, remove the grab on mouse events that - * was made to detect the focus change */ - if((Fw != NULL)&&(Fw->flags&ClickToFocus)) - { - for(i=0;i<3;i++) - if(Scr.buttons2grab & (1<frame); - XUngrabButton(dpy,(i+1),LockMask,Fw->frame); - } - Scr.Ungrabbed = Fw; - } -/* RBW - allow focus to go to a NoIconTitle icon window so - auto-raise will work on it... - if((Fw)&&(Fw->flags & ICONIFIED)&&(Fw->icon_w)) - w= Fw->icon_w; -*/ - if((Fw)&&(Fw->flags & ICONIFIED)) - { - if (Fw->icon_w) - { - w = Fw->icon_w; - } - else if (Fw->icon_pixmap_w) - { - w = Fw->icon_pixmap_w; - } - } - - if((Fw)&&(Fw->flags & Lenience)) - { - XSetInputFocus (dpy, w, RevertToParent, lastTimestamp); - Scr.Focus = Fw; - Scr.UnknownWinFocused = None; - } - else if(!((Fw)&&(Fw->wmhints)&&(Fw->wmhints->flags & InputHint)&& - (Fw->wmhints->input == False))) - { - /* Window will accept input focus */ - XSetInputFocus (dpy, w, RevertToParent, lastTimestamp); - Scr.Focus = Fw; - Scr.UnknownWinFocused = None; - } - else if ((Scr.Focus)&&(Scr.Focus->Desk == Scr.CurrentDesk)) - { - /* Window doesn't want focus. Leave focus alone */ - /* XSetInputFocus (dpy,Scr.Hilite->w , RevertToParent, lastTimestamp);*/ - } - else - { - XSetInputFocus (dpy, Scr.NoFocusWin, RevertToParent, lastTimestamp); - Scr.Focus = NULL; - } - - - if ((Fw)&&(Fw->flags & DoesWmTakeFocus)) - send_clientmessage (dpy, w, _XA_WM_TAKE_FOCUS, lastTimestamp); - - XSync(dpy,0); + if ((Fw) && (Fw->flags & ICONIFIED)) { + if (Fw->icon_w) { + w = Fw->icon_w; + } else if (Fw->icon_pixmap_w) { + w = Fw->icon_pixmap_w; + } + } -} + if ((Fw) && (Fw->flags & Lenience)) { + XSetInputFocus(dpy, w, RevertToParent, lastTimestamp); + Scr.Focus = Fw; + Scr.UnknownWinFocused = None; + } else if (!((Fw) && (Fw->wmhints) && + (Fw->wmhints->flags & InputHint) && + (Fw->wmhints->input == False))) { + /* Window will accept input focus */ + XSetInputFocus(dpy, w, RevertToParent, lastTimestamp); + Scr.Focus = Fw; + Scr.UnknownWinFocused = None; + } else if ((Scr.Focus) && (Scr.Focus->Desk == Scr.CurrentDesk)) { + /* Window doesn't want focus. Leave focus alone */ + /* XSetInputFocus (dpy,Scr.Hilite->w , RevertToParent, + * lastTimestamp);*/ + } else { + XSetInputFocus( + dpy, Scr.NoFocusWin, RevertToParent, lastTimestamp); + Scr.Focus = NULL; + } + if ((Fw) && (Fw->flags & DoesWmTakeFocus)) + send_clientmessage(dpy, w, _XA_WM_TAKE_FOCUS, lastTimestamp); + + XSync(dpy, 0); +} Index: fvwm/fvwm/functions.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/functions.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/functions.c --- fvwm/fvwm/functions.c +++ fvwm/fvwm/functions.c @@ -12,20 +12,19 @@ * ***********************************************************************/ -#include "config.h" - -#include +#include #include +#include #include -#include #include +#include "config.h" #include "fvwm.h" #include "menus.h" #include "misc.h" +#include "module.h" #include "parse.h" #include "screen.h" -#include "module.h" extern XEvent Event; extern FvwmWindow *Tmp_win; @@ -53,130 +52,126 @@ void setImagePath(F_CMD_ARGS); * how that goes. * dje 12/19/98. */ -static struct functions func_config[] = -{ - {"+", add_another_item, F_ADDMENU2, FUNC_NO_WINDOW}, +static struct functions func_config[] = { + {"+", add_another_item, F_ADDMENU2, FUNC_NO_WINDOW}, #ifdef MULTISTYLE - {"AddButtonStyle",AddButtonStyle, F_ADD_BUTTON_STYLE, FUNC_NO_WINDOW}, + {"AddButtonStyle", AddButtonStyle, F_ADD_BUTTON_STYLE, FUNC_NO_WINDOW}, #endif /* MULTISTYLE */ - {"AddModuleConfig", AddModConfig, F_ADD_MOD, FUNC_NO_WINDOW}, + {"AddModuleConfig", AddModConfig, F_ADD_MOD, FUNC_NO_WINDOW}, #ifdef MULTISTYLE #ifdef EXTENDED_TITLESTYLE - {"AddTitleStyle",AddTitleStyle, F_ADD_TITLE_STYLE, FUNC_NO_WINDOW}, + {"AddTitleStyle", AddTitleStyle, F_ADD_TITLE_STYLE, FUNC_NO_WINDOW}, #endif /* EXTENDED_TITLESTYLE */ #endif /* MULTISTYLE */ #ifdef USEDECOR - {"AddToDecor", add_item_to_decor,F_ADD_DECOR, FUNC_NO_WINDOW}, + {"AddToDecor", add_item_to_decor, F_ADD_DECOR, FUNC_NO_WINDOW}, #endif /* USEDECOR */ - {"AddToFunc", add_item_to_func, F_ADDFUNC, FUNC_NO_WINDOW}, - {"AddToMenu", add_item_to_menu, F_ADDMENU, FUNC_NO_WINDOW}, - {"AnimatedMove", animated_move_window,F_ANIMATED_MOVE, FUNC_NEEDS_WINDOW}, - {"Beep", Bell, F_BEEP, FUNC_NO_WINDOW}, + {"AddToFunc", add_item_to_func, F_ADDFUNC, FUNC_NO_WINDOW}, + {"AddToMenu", add_item_to_menu, F_ADDMENU, FUNC_NO_WINDOW}, + {"AnimatedMove", animated_move_window, F_ANIMATED_MOVE, FUNC_NEEDS_WINDOW}, + {"Beep", Bell, F_BEEP, FUNC_NO_WINDOW}, #ifdef BORDERSTYLE - {"BorderStyle", SetBorderStyle, F_BORDERSTYLE, FUNC_NO_WINDOW}, + {"BorderStyle", SetBorderStyle, F_BORDERSTYLE, FUNC_NO_WINDOW}, #endif /* BORDERSTYLE */ - {"ButtonStyle", ButtonStyle, F_BUTTON_STYLE, FUNC_NO_WINDOW}, + {"ButtonStyle", ButtonStyle, F_BUTTON_STYLE, FUNC_NO_WINDOW}, #ifdef USEDECOR - {"ChangeDecor", ChangeDecor, F_CHANGE_DECOR, FUNC_NEEDS_WINDOW}, + {"ChangeDecor", ChangeDecor, F_CHANGE_DECOR, FUNC_NEEDS_WINDOW}, #endif /* USEDECOR */ - {"ChangeMenuStyle", ChangeMenuStyle, F_CHANGE_MENUSTYLE, FUNC_NO_WINDOW}, - {"ClickTime", SetClick, F_CLICK, FUNC_NO_WINDOW}, - {"Close", close_function, F_CLOSE, FUNC_NEEDS_WINDOW}, - {"ColorLimit", SetColorLimit, F_COLOR_LIMIT, FUNC_NO_WINDOW}, - {"ColormapFocus",SetColormapFocus, F_COLORMAP_FOCUS, FUNC_NO_WINDOW}, - {"Current", CurrentFunc, F_CURRENT, FUNC_NO_WINDOW}, - {"CursorMove", movecursor, F_MOVECURSOR, FUNC_NO_WINDOW}, - {"CursorStyle", CursorStyle, F_CURSOR_STYLE, FUNC_NO_WINDOW}, - {"DefaultColors",SetDefaultColors, F_DFLT_COLORS, FUNC_NO_WINDOW}, - {"DefaultFont", LoadDefaultFont, F_DFLT_FONT, FUNC_NO_WINDOW}, - {"Delete", delete_function, F_DELETE, FUNC_NEEDS_WINDOW}, - {"Desk", changeDesks_func, F_DESK, FUNC_NO_WINDOW}, - {"DesktopSize", SetDeskSize, F_SETDESK, FUNC_NO_WINDOW}, - {"Destroy", destroy_function, F_DESTROY, FUNC_NEEDS_WINDOW}, + {"ChangeMenuStyle", ChangeMenuStyle, F_CHANGE_MENUSTYLE, FUNC_NO_WINDOW}, + {"ClickTime", SetClick, F_CLICK, FUNC_NO_WINDOW}, + {"Close", close_function, F_CLOSE, FUNC_NEEDS_WINDOW}, + {"ColorLimit", SetColorLimit, F_COLOR_LIMIT, FUNC_NO_WINDOW}, + {"ColormapFocus", SetColormapFocus, F_COLORMAP_FOCUS, FUNC_NO_WINDOW}, + {"Current", CurrentFunc, F_CURRENT, FUNC_NO_WINDOW}, + {"CursorMove", movecursor, F_MOVECURSOR, FUNC_NO_WINDOW}, + {"CursorStyle", CursorStyle, F_CURSOR_STYLE, FUNC_NO_WINDOW}, + {"DefaultColors", SetDefaultColors, F_DFLT_COLORS, FUNC_NO_WINDOW}, + {"DefaultFont", LoadDefaultFont, F_DFLT_FONT, FUNC_NO_WINDOW}, + {"Delete", delete_function, F_DELETE, FUNC_NEEDS_WINDOW}, + {"Desk", changeDesks_func, F_DESK, FUNC_NO_WINDOW}, + {"DesktopSize", SetDeskSize, F_SETDESK, FUNC_NO_WINDOW}, + {"Destroy", destroy_function, F_DESTROY, FUNC_NEEDS_WINDOW}, #ifdef USEDECOR - {"DestroyDecor", DestroyDecor, F_DESTROY_DECOR, FUNC_NO_WINDOW}, + {"DestroyDecor", DestroyDecor, F_DESTROY_DECOR, FUNC_NO_WINDOW}, #endif /* USEDECOR */ - {"DestroyFunc", destroy_menu, F_DESTROY_MENU, FUNC_NO_WINDOW}, - {"DestroyMenu", destroy_menu, F_DESTROY_MENU, FUNC_NO_WINDOW}, - {"DestroyMenuStyle", DestroyMenuStyle, F_DESTROY_MENUSTYLE,FUNC_NO_WINDOW}, - {"DestroyModuleConfig", DestroyModConfig, F_DESTROY_MOD, FUNC_NO_WINDOW}, - {"Direction", DirectionFunc, F_DIRECTION, FUNC_NO_WINDOW}, - {"Echo", echo_func, F_ECHO, FUNC_NO_WINDOW}, - {"EdgeResistance",SetEdgeResistance,F_EDGE_RES, FUNC_NO_WINDOW}, - {"EdgeScroll", SetEdgeScroll, F_EDGE_SCROLL, FUNC_NO_WINDOW}, - {"EdgeThickness",setEdgeThickness, F_NOP, FUNC_NO_WINDOW}, - {"Emulate", Emulate, F_EMULATE, FUNC_NO_WINDOW}, - {"Exec", exec_function, F_EXEC, FUNC_NO_WINDOW}, - {"ExecUseSHELL", exec_setup, F_EXEC_SETUP, FUNC_NO_WINDOW}, - {"FlipFocus", flip_focus_func, F_FLIP_FOCUS, FUNC_NEEDS_WINDOW}, - {"Focus", focus_func, F_FOCUS, FUNC_NEEDS_WINDOW}, - {"Function", ComplexFunction, F_FUNCTION, FUNC_NO_WINDOW}, - {"GlobalOpts", SetGlobalOptions, F_GLOBAL_OPTS, FUNC_NO_WINDOW}, - {"GotoPage", goto_page_func, F_GOTO_PAGE, FUNC_NO_WINDOW}, - {"HilightColor", SetHiColor, F_HICOLOR, FUNC_NO_WINDOW}, - {"IconFont", LoadIconFont, F_ICONFONT, FUNC_NO_WINDOW}, - {"Iconify", iconify_function, F_ICONIFY, FUNC_NEEDS_WINDOW}, - {"IconPath", setIconPath, F_ICON_PATH, FUNC_NO_WINDOW}, - {"ImagePath", setImagePath, F_ICON_PATH, FUNC_NO_WINDOW}, - {"Key", ParseKeyEntry, F_KEY, FUNC_NO_WINDOW}, - {"KillModule", module_zapper, F_ZAP, FUNC_NO_WINDOW}, - {"Lower", lower_function, F_LOWER, FUNC_NEEDS_WINDOW}, - {"Maximize", Maximize, F_MAXIMIZE, FUNC_NEEDS_WINDOW}, - {"Menu", staysup_func, F_STAYSUP, FUNC_NO_WINDOW}, - {"MenuStyle", SetMenuStyle, F_MENUSTYLE, FUNC_NO_WINDOW}, - {"Module", executeModule, F_MODULE, FUNC_NO_WINDOW}, - {"ModulePath", setModulePath, F_MODULE_PATH, FUNC_NO_WINDOW}, - {"Mouse", ParseMouseEntry, F_MOUSE, FUNC_NO_WINDOW}, - {"Move", move_window, F_MOVE, FUNC_NEEDS_WINDOW}, - {"MoveToDesk", changeWindowsDesk,F_CHANGE_WINDOWS_DESK, FUNC_NEEDS_WINDOW}, - {"MoveToPage", move_window_to_page,F_MOVE_TO_PAGE, FUNC_NEEDS_WINDOW}, - {"Next", NextFunc, F_NEXT, FUNC_NO_WINDOW}, - {"None", NoneFunc, F_NONE, FUNC_NO_WINDOW}, - {"Nop", Nop_func, F_NOP, FUNC_NO_WINDOW}, - {"OpaqueMoveSize", SetOpaque, F_OPAQUE, FUNC_NO_WINDOW}, - {"PipeRead", PipeRead, F_READ, FUNC_NO_WINDOW}, - {"PixmapPath", setPixmapPath, F_PIXMAP_PATH, FUNC_NO_WINDOW}, - {"PopUp", popup_func, F_POPUP, FUNC_NO_WINDOW}, - {"Prev", PrevFunc, F_PREV, FUNC_NO_WINDOW}, - {"Quit", quit_func, F_QUIT, FUNC_NO_WINDOW}, - {"QuitScreen", quit_screen_func, F_QUIT_SCREEN, FUNC_NO_WINDOW}, - {"Raise", raise_function, F_RAISE, FUNC_NEEDS_WINDOW}, - {"RaiseLower", raiselower_func, F_RAISELOWER, FUNC_NEEDS_WINDOW}, - {"Read", ReadFile, F_READ, FUNC_NO_WINDOW}, - {"Recapture", Recapture, F_RECAPTURE, FUNC_NO_WINDOW}, - {"Refresh", refresh_function, F_REFRESH, FUNC_NO_WINDOW}, - {"RefreshWindow",refresh_win_function, F_REFRESH, FUNC_NEEDS_WINDOW}, - {"Resize", resize_window, F_RESIZE, FUNC_NEEDS_WINDOW}, - {"Restart", restart_function, F_RESTART, FUNC_NO_WINDOW}, - {"Scroll", scroll, F_SCROLL, FUNC_NO_WINDOW}, - {"Send_ConfigInfo",SendDataToModule, F_CONFIG_LIST, FUNC_NO_WINDOW}, - {"Send_WindowList",send_list_func, F_SEND_WINDOW_LIST, FUNC_NO_WINDOW}, - {"SendToModule", SendStrToModule, F_SEND_STRING, FUNC_NO_WINDOW}, - {"set_mask", set_mask_function,F_SET_MASK, FUNC_NO_WINDOW}, - {"SetAnimation", set_animation, F_SET_ANIMATION, FUNC_NO_WINDOW}, - {"SetEnv", SetEnv, F_SETENV, FUNC_NO_WINDOW}, - {"SnapAttraction",SetSnapAttraction,F_SNAP_ATT, FUNC_NO_WINDOW}, - {"SnapGrid", SetSnapGrid, F_SNAP_GRID, FUNC_NO_WINDOW}, - {"Stick", stick_function, F_STICK, FUNC_NEEDS_WINDOW}, - {"Style", ProcessNewStyle, F_STYLE, FUNC_NO_WINDOW}, - {"Title", Nop_func, F_TITLE, FUNC_NO_WINDOW}, - {"TitleStyle", SetTitleStyle, F_TITLESTYLE, FUNC_NO_WINDOW}, - {"UpdateDecor", UpdateDecor, F_UPDATE_DECOR, FUNC_NO_WINDOW}, - {"Wait", wait_func, F_WAIT, FUNC_NO_WINDOW}, - {"WarpToWindow", warp_func, F_WARP, FUNC_NEEDS_WINDOW}, - {"WindowFont", LoadWindowFont, F_WINDOWFONT, FUNC_NO_WINDOW}, - {"WindowId", WindowIdFunc, F_WINDOWID, FUNC_NO_WINDOW}, - {"WindowList", do_windowList, F_WINDOWLIST, FUNC_NO_WINDOW}, + {"DestroyFunc", destroy_menu, F_DESTROY_MENU, FUNC_NO_WINDOW}, + {"DestroyMenu", destroy_menu, F_DESTROY_MENU, FUNC_NO_WINDOW}, + {"DestroyMenuStyle", DestroyMenuStyle, F_DESTROY_MENUSTYLE, FUNC_NO_WINDOW}, + {"DestroyModuleConfig", DestroyModConfig, F_DESTROY_MOD, FUNC_NO_WINDOW}, + {"Direction", DirectionFunc, F_DIRECTION, FUNC_NO_WINDOW}, + {"Echo", echo_func, F_ECHO, FUNC_NO_WINDOW}, + {"EdgeResistance", SetEdgeResistance, F_EDGE_RES, FUNC_NO_WINDOW}, + {"EdgeScroll", SetEdgeScroll, F_EDGE_SCROLL, FUNC_NO_WINDOW}, + {"EdgeThickness", setEdgeThickness, F_NOP, FUNC_NO_WINDOW}, + {"Emulate", Emulate, F_EMULATE, FUNC_NO_WINDOW}, + {"Exec", exec_function, F_EXEC, FUNC_NO_WINDOW}, + {"ExecUseSHELL", exec_setup, F_EXEC_SETUP, FUNC_NO_WINDOW}, + {"FlipFocus", flip_focus_func, F_FLIP_FOCUS, FUNC_NEEDS_WINDOW}, + {"Focus", focus_func, F_FOCUS, FUNC_NEEDS_WINDOW}, + {"Function", ComplexFunction, F_FUNCTION, FUNC_NO_WINDOW}, + {"GlobalOpts", SetGlobalOptions, F_GLOBAL_OPTS, FUNC_NO_WINDOW}, + {"GotoPage", goto_page_func, F_GOTO_PAGE, FUNC_NO_WINDOW}, + {"HilightColor", SetHiColor, F_HICOLOR, FUNC_NO_WINDOW}, + {"IconFont", LoadIconFont, F_ICONFONT, FUNC_NO_WINDOW}, + {"Iconify", iconify_function, F_ICONIFY, FUNC_NEEDS_WINDOW}, + {"IconPath", setIconPath, F_ICON_PATH, FUNC_NO_WINDOW}, + {"ImagePath", setImagePath, F_ICON_PATH, FUNC_NO_WINDOW}, + {"Key", ParseKeyEntry, F_KEY, FUNC_NO_WINDOW}, + {"KillModule", module_zapper, F_ZAP, FUNC_NO_WINDOW}, + {"Lower", lower_function, F_LOWER, FUNC_NEEDS_WINDOW}, + {"Maximize", Maximize, F_MAXIMIZE, FUNC_NEEDS_WINDOW}, + {"Menu", staysup_func, F_STAYSUP, FUNC_NO_WINDOW}, + {"MenuStyle", SetMenuStyle, F_MENUSTYLE, FUNC_NO_WINDOW}, + {"Module", executeModule, F_MODULE, FUNC_NO_WINDOW}, + {"ModulePath", setModulePath, F_MODULE_PATH, FUNC_NO_WINDOW}, + {"Mouse", ParseMouseEntry, F_MOUSE, FUNC_NO_WINDOW}, + {"Move", move_window, F_MOVE, FUNC_NEEDS_WINDOW}, + {"MoveToDesk", changeWindowsDesk, F_CHANGE_WINDOWS_DESK, FUNC_NEEDS_WINDOW}, + {"MoveToPage", move_window_to_page, F_MOVE_TO_PAGE, FUNC_NEEDS_WINDOW}, + {"Next", NextFunc, F_NEXT, FUNC_NO_WINDOW}, + {"None", NoneFunc, F_NONE, FUNC_NO_WINDOW}, + {"Nop", Nop_func, F_NOP, FUNC_NO_WINDOW}, + {"OpaqueMoveSize", SetOpaque, F_OPAQUE, FUNC_NO_WINDOW}, + {"PipeRead", PipeRead, F_READ, FUNC_NO_WINDOW}, + {"PixmapPath", setPixmapPath, F_PIXMAP_PATH, FUNC_NO_WINDOW}, + {"PopUp", popup_func, F_POPUP, FUNC_NO_WINDOW}, + {"Prev", PrevFunc, F_PREV, FUNC_NO_WINDOW}, + {"Quit", quit_func, F_QUIT, FUNC_NO_WINDOW}, + {"QuitScreen", quit_screen_func, F_QUIT_SCREEN, FUNC_NO_WINDOW}, + {"Raise", raise_function, F_RAISE, FUNC_NEEDS_WINDOW}, + {"RaiseLower", raiselower_func, F_RAISELOWER, FUNC_NEEDS_WINDOW}, + {"Read", ReadFile, F_READ, FUNC_NO_WINDOW}, + {"Recapture", Recapture, F_RECAPTURE, FUNC_NO_WINDOW}, + {"Refresh", refresh_function, F_REFRESH, FUNC_NO_WINDOW}, + {"RefreshWindow", refresh_win_function, F_REFRESH, FUNC_NEEDS_WINDOW}, + {"Resize", resize_window, F_RESIZE, FUNC_NEEDS_WINDOW}, + {"Restart", restart_function, F_RESTART, FUNC_NO_WINDOW}, + {"Scroll", scroll, F_SCROLL, FUNC_NO_WINDOW}, + {"Send_ConfigInfo", SendDataToModule, F_CONFIG_LIST, FUNC_NO_WINDOW}, + {"Send_WindowList", send_list_func, F_SEND_WINDOW_LIST, FUNC_NO_WINDOW}, + {"SendToModule", SendStrToModule, F_SEND_STRING, FUNC_NO_WINDOW}, + {"set_mask", set_mask_function, F_SET_MASK, FUNC_NO_WINDOW}, + {"SetAnimation", set_animation, F_SET_ANIMATION, FUNC_NO_WINDOW}, + {"SetEnv", SetEnv, F_SETENV, FUNC_NO_WINDOW}, + {"SnapAttraction", SetSnapAttraction, F_SNAP_ATT, FUNC_NO_WINDOW}, + {"SnapGrid", SetSnapGrid, F_SNAP_GRID, FUNC_NO_WINDOW}, + {"Stick", stick_function, F_STICK, FUNC_NEEDS_WINDOW}, + {"Style", ProcessNewStyle, F_STYLE, FUNC_NO_WINDOW}, + {"Title", Nop_func, F_TITLE, FUNC_NO_WINDOW}, + {"TitleStyle", SetTitleStyle, F_TITLESTYLE, FUNC_NO_WINDOW}, + {"UpdateDecor", UpdateDecor, F_UPDATE_DECOR, FUNC_NO_WINDOW}, + {"Wait", wait_func, F_WAIT, FUNC_NO_WINDOW}, + {"WarpToWindow", warp_func, F_WARP, FUNC_NEEDS_WINDOW}, + {"WindowFont", LoadWindowFont, F_WINDOWFONT, FUNC_NO_WINDOW}, + {"WindowId", WindowIdFunc, F_WINDOWID, FUNC_NO_WINDOW}, + {"WindowList", do_windowList, F_WINDOWLIST, FUNC_NO_WINDOW}, /* {"WindowsDesk", changeWindowsDesk,F_CHANGE_WINDOWS_DESK, FUNC_NEEDS_WINDOW}, */ #ifdef WINDOWSHADE - {"WindowShade", WindowShade, F_WINDOW_SHADE, FUNC_NEEDS_WINDOW}, + {"WindowShade", WindowShade, F_WINDOW_SHADE, FUNC_NEEDS_WINDOW}, #endif /* WINDOWSHADE */ - {"XORValue", SetXOR, F_XOR, FUNC_NO_WINDOW}, - {"",0,0,0} -}; - + {"XORValue", SetXOR, F_XOR, FUNC_NO_WINDOW}, {"", 0, 0, 0}}; /* migo (02-Oct-1999): add ImagePath not to break 2.3.x configurations */ /* setPath() is from fvwm-2.3.x/libs/System.c */ @@ -185,72 +180,76 @@ static struct functions func_config[] = * Set a colon-separated path, with environment variable expansions, * and expand '+' to be the value of the previous path. **/ -void setPath( char** p_path, char* newpath, int free_old_path ) +void +setPath(char **p_path, char *newpath, int free_old_path) { - char* oldpath = *p_path; - int oldlen = strlen( oldpath ); - char* stripped_path = stripcpy( newpath ); - int found_plus = strchr( newpath, '+' ) != NULL; + char *oldpath = *p_path; + int oldlen = strlen(oldpath); + char *stripped_path = stripcpy(newpath); + int found_plus = strchr(newpath, '+') != NULL; - /** Leave room for the old path, if we find a '+' in newpath **/ - *p_path = envDupExpand( stripped_path, found_plus ? oldlen : 0 ); - free( stripped_path ); + /** Leave room for the old path, if we find a '+' in newpath **/ + *p_path = envDupExpand(stripped_path, found_plus ? oldlen : 0); + free(stripped_path); - if ( found_plus ) { - char* p = strchr( *p_path, '+' ); - memmove( p+oldlen, p+1, strlen(p+1) ); + if (found_plus) { + char *p = strchr(*p_path, '+'); + memmove(p + oldlen, p + 1, strlen(p + 1)); - /* copy oldlen+1 bytes to include the trailing NUL */ - strncpy( p, oldpath, oldlen+1 ); - } + /* copy oldlen+1 bytes to include the trailing NUL */ + strncpy(p, oldpath, oldlen + 1); + } - if ( free_old_path ) - free( oldpath ); + if (free_old_path) + free(oldpath); } -void setImagePath(F_CMD_ARGS) + +void +setImagePath(F_CMD_ARGS) { - extern char *PixmapPath, *IconPath; - char *newPixmapPath = strdup(PixmapPath); - char *newIconPath = strdup(IconPath ); - setPath( &newPixmapPath, action, 1 ); - setPath( &newIconPath, action, 1 ); - setPixmapPath(eventp, w, tmp_win, context, newPixmapPath, Module); - setIconPath (eventp, w, tmp_win, context, newIconPath, Module); + extern char *PixmapPath, *IconPath; + char *newPixmapPath = strdup(PixmapPath); + char *newIconPath = strdup(IconPath); + setPath(&newPixmapPath, action, 1); + setPath(&newIconPath, action, 1); + setPixmapPath(eventp, w, tmp_win, context, newPixmapPath, Module); + setIconPath(eventp, w, tmp_win, context, newIconPath, Module); } - /* ** do binary search on func list */ -static int func_comp(const void *a, const void *b) +static int +func_comp(const void *a, const void *b) { - char *key=(char *)a; - char *f=((struct functions *)b)->keyword; - return (strcasecmp(key,f)); + char *key = (char *)a; + char *f = ((struct functions *)b)->keyword; + return (strcasecmp(key, f)); } -static struct functions *FindBuiltinFunction(char *func) +static struct functions * +FindBuiltinFunction(char *func) { - static int func_config_size=0; + static int func_config_size = 0; - if (!func) - return NULL; + if (!func) + return NULL; - if (!func_config_size) - { - /* remove finial NULL entry from size */ - func_config_size=((sizeof(func_config))/(sizeof(struct functions)))-1; - } + if (!func_config_size) { + /* remove finial NULL entry from size */ + func_config_size = + ((sizeof(func_config)) / (sizeof(struct functions))) - 1; + } - /* since a lot of lines in a typical rc are probably menu/func continues: */ - if (func[0]=='+') - return &(func_config[0]); + /* since a lot of lines in a typical rc are probably menu/func + * continues: */ + if (func[0] == '+') + return &(func_config[0]); - return (struct functions *)bsearch(func, func_config, func_config_size, - sizeof(struct functions), func_comp); + return (struct functions *)bsearch(func, func_config, func_config_size, + sizeof(struct functions), func_comp); } - /*********************************************************************** * * Procedure: @@ -263,112 +262,112 @@ static struct functions *FindBuiltinFunction(char *func) * context - the context in which the button was pressed * ***********************************************************************/ -void ExecuteFunction(char *Action, FvwmWindow *tmp_win, XEvent *eventp, - unsigned long context, int Module) +void +ExecuteFunction(char *Action, FvwmWindow *tmp_win, XEvent *eventp, + unsigned long context, int Module) { - Window w; - int matched,j; - char *function; - char *action, *taction; - char *arguments[10]; - struct functions *bif; - - if (!Action || Action[0] == 0 || Action[1] == 0) - { - /* impossibly short command */ - return; /* done */ - } - if (Action[0] == '#') { /* a comment */ - return; /* done */ - } - /* Note: the module config command, "*" can not be handled by the - regular command table because there is no required white space after - the asterisk. */ - if (Action[0] == '*') { /* a module config command */ - ModuleConfig(NULL,0,0,0,Action,0); /* process the command */ - return; /* done */ - } - - for(j=0;j<10;j++) - arguments[j] = NULL; - - if(tmp_win == NULL) - w = Scr.Root; - else - w = tmp_win->w; - - if((tmp_win) &&(eventp)) - w = eventp->xany.window; - if((tmp_win)&&(eventp->xbutton.subwindow != None)&& - (eventp->xany.window != tmp_win->w)) - w = eventp->xbutton.subwindow; - - taction = expand(Action,arguments,tmp_win); - action = GetNextToken(taction,&function); - if (!function) - return; - j=0; - matched = FALSE; - - bif = FindBuiltinFunction(function); - if (bif) - { - matched = TRUE; - bif->action(eventp,w,tmp_win,context,action,&Module); - } - - if(!matched) - { - desperate = 1; - ComplexFunction(eventp,w,tmp_win,context,taction, &Module); - if(desperate) - executeModule(eventp,w,tmp_win,context,taction, &Module); - desperate = 0; - } - - /* Only wait for an all-buttons-up condition after calls from - * regular built-ins, not from complex-functions or modules. */ - if(Module == -1) - WaitForButtonsUp(); - - if (function) - free(function); - if(taction != NULL) - free(taction); - return; + Window w; + int matched, j; + char *function; + char *action, *taction; + char *arguments[10]; + struct functions *bif; + + if (!Action || Action[0] == 0 || Action[1] == 0) { + /* impossibly short command */ + return; /* done */ + } + if (Action[0] == '#') { /* a comment */ + return; /* done */ + } + /* Note: the module config command, "*" can not be handled by the + regular command table because there is no required white space after + the asterisk. */ + if (Action[0] == '*') { /* a module config command */ + ModuleConfig( + NULL, 0, 0, 0, Action, 0); /* process the command */ + return; /* done */ + } + + for (j = 0; j < 10; j++) + arguments[j] = NULL; + + if (tmp_win == NULL) + w = Scr.Root; + else + w = tmp_win->w; + + if ((tmp_win) && (eventp)) + w = eventp->xany.window; + if ((tmp_win) && (eventp->xbutton.subwindow != None) && + (eventp->xany.window != tmp_win->w)) + w = eventp->xbutton.subwindow; + + taction = expand(Action, arguments, tmp_win); + action = GetNextToken(taction, &function); + if (!function) + return; + j = 0; + matched = FALSE; + + bif = FindBuiltinFunction(function); + if (bif) { + matched = TRUE; + bif->action(eventp, w, tmp_win, context, action, &Module); + } + + if (!matched) { + desperate = 1; + ComplexFunction(eventp, w, tmp_win, context, taction, &Module); + if (desperate) + executeModule( + eventp, w, tmp_win, context, taction, &Module); + desperate = 0; + } + + /* Only wait for an all-buttons-up condition after calls from + * regular built-ins, not from complex-functions or modules. */ + if (Module == -1) + WaitForButtonsUp(); + + if (function) + free(function); + if (taction != NULL) + free(taction); + return; } - -void find_func_type(char *action, short *func_type, Bool *func_needs_window) +void +find_func_type(char *action, short *func_type, Bool *func_needs_window) { - int j, len = 0; - char *endtok = action; - Bool matched; - int mlen; - - if (action) - { - while (*endtok&&!isspace(*endtok))++endtok; - len = endtok - action; - j=0; - matched = FALSE; - while((!matched)&&((mlen = strlen(func_config[j].keyword))>0)) - { - if((mlen == len) && - (strncasecmp(action,func_config[j].keyword,mlen)==0)) - { - matched=TRUE; - /* found key word */ - *func_type = func_config[j].func_type; - *func_needs_window = func_config[j].func_needs_window; - return; - } - else - j++; - } - /* No clue what the function is. Just return "BEEP" */ - } - *func_type = F_BEEP; - *func_needs_window = False; - return; + int j, len = 0; + char *endtok = action; + Bool matched; + int mlen; + + if (action) { + while (*endtok && !isspace(*endtok)) + ++endtok; + len = endtok - action; + j = 0; + matched = FALSE; + while ((!matched) && + ((mlen = strlen(func_config[j].keyword)) > 0)) { + if ((mlen == len) && + (strncasecmp( + action, func_config[j].keyword, mlen) == 0)) { + matched = TRUE; + /* found key word */ + *func_type = func_config[j].func_type; + *func_needs_window = + func_config[j].func_needs_window; + return; + } else + j++; + } + /* No clue what the function is. Just return "BEEP" */ + } + *func_type = F_BEEP; + *func_needs_window = False; + return; } Index: fvwm/fvwm/fvwm.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/fvwm.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/fvwm.c --- fvwm/fvwm/fvwm.c +++ fvwm/fvwm/fvwm.c @@ -1,4 +1,3 @@ - /**************************************************************************** * This module is all original code * by Rob Nation @@ -11,61 +10,50 @@ * fvwm - "F? Virtual Window Manager" ***********************************************************************/ -#include "config.h" +#include "fvwm.h" +#include +#include +#include +#include +#include +#include #include #include -#include -#include #include #include -#include -#include "fvwm.h" + +#include "config.h" +#include "fvwm_sandbox.h" #include "menus.h" #include "misc.h" -#include "screen.h" -#include "parse.h" #include "module.h" - -#include -#include -/* need to get prototype for XrmUniqueQuark for XUniqueContext call */ -#include +#include "parse.h" +#include "screen.h" #ifdef SHAPE #include #endif /* SHAPE */ -#if defined(HAVE_SYS_SYSTEMINFO_H) -/* Solaris has sysinfo instead of gethostname. */ -#include -#endif - #define MAXHOSTNAME 255 - #ifndef lint static char sccsid[] = "@(#)fvwm.c " VERSION " fvwm"; #endif -int master_pid; /* process number of 1st fvwm process */ +int master_pid; /* process number of 1st fvwm process */ -ScreenInfo Scr; /* structures for the screen */ -Display *dpy; /* which display are we talking to */ +ScreenInfo Scr; /* structures for the screen */ +Display *dpy; /* which display are we talking to */ -Window BlackoutWin=None; /* window to hide window captures */ -Bool fFvwmInStartup = True; /* Set to False when startup has finished */ +Window BlackoutWin = None; /* window to hide window captures */ +Bool fFvwmInStartup = True; /* Set to False when startup has finished */ -char *default_config_command = "Read "FVWMRC; +char *default_config_command = "Read " FVWMRC; #define MAX_CFG_CMDS 10 static char *config_commands[MAX_CFG_CMDS]; -static int num_config_commands=0; - -#if 0 -/* unsused */ -char *output_file = NULL; -#endif +static int num_config_commands = 0; int FvwmErrorHandler(Display *, XErrorEvent *); int CatchFatal(Display *); @@ -78,14 +66,14 @@ void SetMWM_INFO(Window window); void SetRCDefaults(void); void StartupStuff(void); -XContext FvwmContext; /* context for fvwm windows */ -XContext MenuContext; /* context for fvwm menus */ +XContext FvwmContext; /* context for fvwm windows */ +XContext MenuContext; /* context for fvwm menus */ int JunkX = 0, JunkY = 0; -Window JunkRoot, JunkChild; /* junk window */ +Window JunkRoot, JunkChild; /* junk window */ unsigned int JunkWidth, JunkHeight, JunkBW, JunkDepth, JunkMask; -Boolean debugging = False,PPosOverride,Blackout = False; +Boolean debugging = False, PPosOverride, Blackout = False; char **g_argv; int g_argc; @@ -99,16 +87,9 @@ static char g_bits[] = {0x02, 0x01}; #define l_g_height 2 static char l_g_bits[] = {0x08, 0x02}; -#if 0 -/* code unused */ -#define s_g_width 4 -#define s_g_height 4 -static char s_g_bits[] = {0x01, 0x02, 0x04, 0x08}; -#endif - #ifdef SHAPE int ShapeEventBase, ShapeErrorBase; -Boolean ShapesSupported=False; +Boolean ShapesSupported = False; #endif long isIconicState = 0; @@ -117,7 +98,7 @@ Bool Restarting = False; int fd_width, x_fd; char *display_name = NULL; -typedef enum { FVWM_RUNNING=0, FVWM_DONE, FVWM_RESTART } FVWM_STATE; +typedef enum { FVWM_RUNNING = 0, FVWM_DONE, FVWM_RESTART } FVWM_STATE; /* * Currently, the "isTerminated" variable is superfluous. However, @@ -136,451 +117,414 @@ volatile sig_atomic_t isTerminated = False; * *********************************************************************** */ -int main(int argc, char **argv) +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; - extern int x_fd; - int len; - char *display_string; - char message[255]; - Bool single = False; - Bool option_error = FALSE; - int x, y; - size_t buflen; - - g_argv = argv; - g_argc = argc; - - DBUG("main","Entered, about to parse args"); - - /* Put the default module directory into the environment so it can be used - later by the config file, etc. */ - putenv("FVWM_MODULEDIR=" FVWM_MODULEDIR); - - 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(); - if (num_config_commands < MAX_CFG_CMDS) - { - buflen = 6+strlen(argv[i]); - config_commands[num_config_commands] = (char *)malloc(buflen); - strlcpy(config_commands[num_config_commands],"Read ", buflen); - strlcat(config_commands[num_config_commands],argv[i], buflen); - num_config_commands++; - } - else - { - fvwm_msg(ERR,"main","only %d -f and -cmd parms allowed!",MAX_CFG_CMDS); - } - } - else if (strncasecmp(argv[i],"-cmd",4)==0) - { - if (++i >= argc) - usage(); - if (num_config_commands < MAX_CFG_CMDS) - { - config_commands[num_config_commands] = strdup(argv[i]); - num_config_commands++; - } - else - { - fvwm_msg(ERR,"main","only %d -f and -cmd parms allowed!",MAX_CFG_CMDS); - } - } -#if 0 -/* unused */ - else if (strncasecmp(argv[i],"-outfile",8)==0) - { - if (++i >= argc) - usage(); - output_file = argv[i]; - } -#endif - 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", "Fvwm Version %s\n", VERSION); - } - 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"); + unsigned long valuemask; /* mask for create windows */ + XSetWindowAttributes attributes; /* attributes for create windows */ + void InternUsefulAtoms(void); + void InitVariables(void); + int i; + extern int x_fd; + int len; + char *display_string; + char message[255]; + Bool single = False; + Bool option_error = FALSE; + int x, y; + size_t buflen; + + g_argv = argv; + g_argc = argc; + + DBUG("main", "Entered, about to parse args"); + + /* Put the default module directory into the environment so it can be + used later by the config file, etc. */ + putenv("FVWM_MODULEDIR=" FVWM_MODULEDIR); + + 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(); + if (num_config_commands < MAX_CFG_CMDS) { + buflen = 6 + strlen(argv[i]); + config_commands[num_config_commands] = + (char *)malloc(buflen); + strlcpy(config_commands[num_config_commands], + "Read ", buflen); + strlcat(config_commands[num_config_commands], + argv[i], buflen); + num_config_commands++; + } else { + fvwm_msg(ERR, "main", + "only %d -f and -cmd parms allowed!", + MAX_CFG_CMDS); + } + } else if (strncasecmp(argv[i], "-cmd", 4) == 0) { + if (++i >= argc) + usage(); + if (num_config_commands < MAX_CFG_CMDS) { + config_commands[num_config_commands] = + strdup(argv[i]); + num_config_commands++; + } else { + fvwm_msg(ERR, "main", + "only %d -f and -cmd parms allowed!", + MAX_CFG_CMDS); + } + } 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", "Fvwm Version %s\n", VERSION); + } 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"); #ifdef HAVE_SIGACTION - { - struct sigaction sigact; - - /* - * Use reliable signal semantics since they are predictable and portable. - * DeadPipe() looks like a no-op, so don't stop processing system calls - * to handle a SIGPIPE (Why don't we just -ignore- SIGPIPE?) - */ + { + struct sigaction sigact; + + /* + * Use reliable signal semantics since they are predictable and + * portable. DeadPipe() looks like a no-op, so don't stop + * processing system calls to handle a SIGPIPE (Why don't we + * just -ignore- SIGPIPE?) + */ #ifdef SA_RESTART - sigact.sa_flags = SA_RESTART; + sigact.sa_flags = SA_RESTART; #else - sigact.sa_flags = 0; + sigact.sa_flags = 0; #endif - sigemptyset(&sigact.sa_mask); + sigemptyset(&sigact.sa_mask); - sigact.sa_handler = DeadPipe; /* This handler does nothing ??? */ - sigaction(SIGPIPE, &sigact, NULL); + sigact.sa_handler = + DeadPipe; /* This handler does nothing ??? */ + sigaction(SIGPIPE, &sigact, NULL); - /* - * If we need to restart then we need to stop what we're doing as - * quickly as possible - hence interrupt any system call we're - * blocked in ... - */ + /* + * If we need to restart then we need to stop what we're doing + * as quickly as possible - hence interrupt any system call + * we're blocked in ... + */ #ifdef SA_INTERRUPT - sigact.sa_flags = SA_INTERRUPT; + sigact.sa_flags = SA_INTERRUPT; #else - sigact.sa_flags = 0; + sigact.sa_flags = 0; #endif - sigact.sa_handler = Restart; - sigaction(SIGUSR1, &sigact, NULL); - } + sigact.sa_handler = Restart; + sigaction(SIGUSR1, &sigact, NULL); + } #else - /* We don't have sigaction(), so fall back to less robust methods. */ - signal(SIGPIPE, DeadPipe); - signal(SIGUSR1, Restart); + /* We don't have sigaction(), so fall back to less robust methods. */ + signal(SIGPIPE, DeadPipe); + signal(SIGUSR1, Restart); #endif - newhandler(SIGINT); - newhandler(SIGHUP); - newhandler(SIGQUIT); - newhandler(SIGTERM); - - 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; - - strlcpy(message, XDisplayString(dpy), sizeof(message)); - - for(i=0;i 0) - { - int i; - for(i=0;i 0) { + int i; + for (i = 0; i < num_config_commands; i++) { + ExecuteFunction( + config_commands[i], NULL, &Event, C_ROOT, 1); + free(config_commands[i]); + } + } else { + ExecuteFunction( + default_config_command, NULL, &Event, C_ROOT, 1); + } + DBUG("main", "Done running config_commands"); + + if (Scr.d_depth < 2) { + Scr.gray_pixmap = XCreatePixmapFromBitmapData(dpy, Scr.Root, + g_bits, g_width, g_height, Scr.StdColors.fore, + Scr.StdColors.back, Scr.d_depth); + Scr.light_gray_pixmap = XCreatePixmapFromBitmapData(dpy, + Scr.Root, l_g_bits, l_g_width, l_g_height, + Scr.StdColors.fore, Scr.StdColors.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.StdColors.fore; + attributes.background_pixel = Scr.StdColors.back; + attributes.bit_gravity = NorthWestGravity; + valuemask = (CWBorderPixel | CWBackPixel | CWBitGravity); + if (!Scr.gs.EmulateMWM) { + x = 0; + y = 0; + } else { + x = Scr.MyDisplayWidth / 2 - + (Scr.SizeStringWidth + SIZE_HINDENT * 2) / 2; + y = Scr.MyDisplayHeight / 2 - + (Scr.StdFont.height + SIZE_VINDENT * 2) / 2; + } + Scr.SizeWindow = XCreateWindow(dpy, Scr.Root, x, y, + (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); + if (Scr.SizeWindow != None) + XSetWindowBackground(dpy, Scr.SizeWindow, Scr.StdColors.back); #ifndef NON_VIRTUAL - initPanFrames(); + initPanFrames(); #endif - MyXGrabServer(dpy); + MyXGrabServer(dpy); #ifndef NON_VIRTUAL - checkPanFrames(); + checkPanFrames(); #endif - MyXUngrabServer(dpy); - UnBlackoutScreen(); /* if we need to remove blackout window */ - CoerceEnterNotifyOnCurrentWindow(); - /* Make sure we have the correct click time now. */ - if (Scr.ClickTime < 0) - Scr.ClickTime = -Scr.ClickTime; - fFvwmInStartup = False; - DBUG("main","Entering HandleEvents loop..."); - - if (pledge("stdio rpath proc exec", NULL) == -1) - err(1, "pledge"); - - HandleEvents(); - switch( fvwmRunState ) - { - case FVWM_DONE: - Done(0, NULL); /* does not return */ - - case FVWM_RESTART: - Done(1, *g_argv); /* does not return */ - - default: - DBUG("main","Unknown FVWM run-state"); - } - - return 0; -} + MyXUngrabServer(dpy); + UnBlackoutScreen(); /* if we need to remove blackout window */ + CoerceEnterNotifyOnCurrentWindow(); + /* Make sure we have the correct click time now. */ + if (Scr.ClickTime < 0) + Scr.ClickTime = -Scr.ClickTime; + fFvwmInStartup = False; + DBUG("main", "Entering HandleEvents loop..."); + + if (unveil(FVWMLIBDIR, "rx") == -1) + err(1, "unveil %s", FVWMLIBDIR); + if (unveil("/etc/X11/fvwm", "r") == -1) + err(1, "unveil /etc/X11/fvwm"); + if (unveil("/tmp", "rwc") == -1) + err(1, "unveil /tmp"); + if (unveil(NULL, NULL) == -1) + err(1, "unveil"); + + if (pledge("stdio rpath proc exec", NULL) == -1) + err(1, "pledge"); + + HandleEvents(); + switch (fvwmRunState) { + case FVWM_DONE: + Done(0, NULL); /* does not return */ + + case FVWM_RESTART: + Done(1, *g_argv); /* does not return */ + + default: + DBUG("main", "Unknown FVWM run-state"); + } + return 0; +} /* ** StartupStuff ** ** Does initial window captures and runs init/restart function */ -void StartupStuff(void) +void +StartupStuff(void) { - MenuRoot *mr; + MenuRoot *mr; - CaptureAllWindows(); - MakeMenus(); + CaptureAllWindows(); + MakeMenus(); #ifndef NON_VIRTUAL - /* Have to do this here too because preprocessor modules have not run to the - * end when HandleEvents is entered from the main loop. */ - checkPanFrames(); + /* Have to do this here too because preprocessor modules have not run to + * the end when HandleEvents is entered from the main loop. */ + checkPanFrames(); #endif - /* migo (02-Oct-1999): execute StartFunction */ - if (FindPopup("StartFunction")) { - ExecuteFunction("Function StartFunction", NULL, &Event, C_ROOT, 1); - } - - 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); - } -} /* StartupStuff */ + /* migo (02-Oct-1999): execute StartFunction */ + if (FindPopup("StartFunction")) { + ExecuteFunction( + "Function StartFunction", NULL, &Event, C_ROOT, 1); + } + 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); + } +} /* StartupStuff */ /*********************************************************************** * @@ -591,120 +535,111 @@ void StartupStuff(void) * ***********************************************************************/ -void CaptureAllWindows(void) +void +CaptureAllWindows(void) { - int i,j; - unsigned int nchildren; - Window root, parent, *children; - FvwmWindow *tmp,*next; /* temp fvwm window structure */ - Window w; - unsigned long data[1]; - unsigned char *prop; - Atom atype; - int aformat; - unsigned long nitems, bytes_remain; - - MyXGrabServer(dpy); - - if(!XQueryTree(dpy, Scr.Root, &root, &parent, &children, &nchildren)) - { - MyXUngrabServer(dpy); - return; - } - - PPosOverride = True; - - if (!(Scr.flags & WindowsCaptured)) /* initial capture? */ - { - /* - ** weed out icon windows - */ - for (i=0;iflags & IconWindowHint) - { - for (j = 0; j < nchildren; j++) - { - if (children[j] == wmhintsp->icon_window) - { - children[j] = None; - break; - } - } - } - XFree ((char *) wmhintsp); - } - } - } - /* - ** map all of the non-override, non-icon windows - */ - for (i = 0; i < nchildren; i++) - { - if (children[i] && MappedNotOverride(children[i])) - { - XUnmapWindow(dpy, children[i]); - Event.xmaprequest.window = children[i]; - HandleMapRequestKeepRaised (BlackoutWin); - } - } - Scr.flags |= WindowsCaptured; - } - else /* must be recapture */ - { - /* reborder all windows */ - tmp = Scr.FvwmRoot.next; - for(i=0;iw,_XA_WM_STATE,0L,3L,False, - _XA_WM_STATE, - &atype,&aformat,&nitems,&bytes_remain,&prop)== - Success) - { - if(prop != NULL) - { - isIconicState = *(long *)prop; - XFree(prop); - } - } - next = tmp->next; - data[0] = (unsigned long) tmp->Desk; - XChangeProperty (dpy, tmp->w, _XA_WM_DESKTOP, _XA_WM_DESKTOP, 32, - PropModeReplace, (unsigned char *) data, 1); - - XSelectInput(dpy, tmp->w, 0); - w = tmp->w; - XUnmapWindow(dpy,tmp->frame); - XUnmapWindow(dpy,w); - RestoreWithdrawnLocation (tmp,True); - Destroy(tmp); - Event.xmaprequest.window = w; - HandleMapRequestKeepRaised(BlackoutWin); - tmp = next; - } - } - } - - isIconicState = DontCareState; - - if(nchildren > 0) - XFree((char *)children); - - /* after the windows already on the screen are in place, - * don't use PPosition */ - PPosOverride = False; - KeepOnTop(); - MyXUngrabServer(dpy); - XSync(dpy,0); /* should we do this on initial capture? */ + int i, j; + unsigned int nchildren; + Window root, parent, *children; + FvwmWindow *tmp, *next; /* temp fvwm window structure */ + Window w; + unsigned long data[1]; + unsigned char *prop; + Atom atype; + int aformat; + unsigned long nitems, bytes_remain; + + MyXGrabServer(dpy); + + if (!XQueryTree(dpy, Scr.Root, &root, &parent, &children, &nchildren)) { + MyXUngrabServer(dpy); + return; + } + + PPosOverride = True; + + if (!(Scr.flags & WindowsCaptured)) { /* initial capture? */ + /* + ** weed out icon windows + */ + for (i = 0; i < nchildren; i++) { + if (children[i]) { + XWMHints *wmhintsp = + XGetWMHints(dpy, children[i]); + if (wmhintsp) { + if (wmhintsp->flags & IconWindowHint) { + for (j = 0; j < nchildren; + j++) { + if (children[j] == + wmhintsp + ->icon_window) { + children[j] = + None; + break; + } + } + } + XFree((char *)wmhintsp); + } + } + } + /* + ** map all of the non-override, non-icon windows + */ + for (i = 0; i < nchildren; i++) { + if (children[i] && MappedNotOverride(children[i])) { + XUnmapWindow(dpy, children[i]); + Event.xmaprequest.window = children[i]; + HandleMapRequestKeepRaised(BlackoutWin); + } + } + Scr.flags |= WindowsCaptured; + } else /* must be recapture */ { + /* reborder all windows */ + tmp = Scr.FvwmRoot.next; + for (i = 0; i < nchildren; i++) { + if (XFindContext(dpy, children[i], FvwmContext, + (caddr_t *)&tmp) != XCNOENT) { + isIconicState = DontCareState; + if (XGetWindowProperty(dpy, tmp->w, + _XA_WM_STATE, 0L, 3L, False, + _XA_WM_STATE, &atype, &aformat, &nitems, + &bytes_remain, &prop) == Success) { + if (prop != NULL) { + isIconicState = *(long *)prop; + XFree(prop); + } + } + next = tmp->next; + data[0] = (unsigned long)tmp->Desk; + XChangeProperty(dpy, tmp->w, _XA_WM_DESKTOP, + _XA_WM_DESKTOP, 32, PropModeReplace, + (unsigned char *)data, 1); + + XSelectInput(dpy, tmp->w, 0); + w = tmp->w; + XUnmapWindow(dpy, tmp->frame); + XUnmapWindow(dpy, w); + RestoreWithdrawnLocation(tmp, True); + Destroy(tmp); + Event.xmaprequest.window = w; + HandleMapRequestKeepRaised(BlackoutWin); + tmp = next; + } + } + } + + isIconicState = DontCareState; + + if (nchildren > 0) + XFree((char *)children); + + /* after the windows already on the screen are in place, + * don't use PPosition */ + PPosOverride = False; + KeepOnTop(); + MyXUngrabServer(dpy); + XSync(dpy, 0); /* should we do this on initial capture? */ } /* @@ -712,34 +647,28 @@ void CaptureAllWindows(void) ** ** Sets some initial style values & such */ -void SetRCDefaults() +void +SetRCDefaults() { - /* set up default colors, fonts, etc */ - char *defaults[] = { - "HilightColor black grey", - "XORValue 0", - "DefaultFont fixed", - "DefaultColors black grey", - "MenuStyle * fvwm, Foreground black, Background grey, Greyed slategrey", - "TitleStyle Centered -- Raised", - "Style \"*\" Color lightgrey/dimgrey, Title", - "Style \"*\" RandomPlacement, SmartPlacement", - "AddToMenu builtin_menu \"Builtin Menu\" Title", - "+ \"Exit FVWM\" Quit", - "Mouse 1 R N Popup builtin_menu", - "AddToFunc WindowListFunc \"I\" WindowId $0 Iconify -1", - "+ \"I\" WindowId $0 FlipFocus", - "+ \"I\" WindowId $0 Raise", - "+ \"I\" WindowId $0 WarpToWindow 5p 5p", - NULL - }; - int i=0; - - while (defaults[i]) - { - ExecuteFunction(defaults[i],NULL,&Event,C_ROOT,1); - i++; - } + /* set up default colors, fonts, etc */ + char *defaults[] = {"HilightColor black grey", "XORValue 0", + "DefaultFont fixed", "DefaultColors black grey", + "MenuStyle * fvwm, Foreground black, Background grey, Greyed " + "slategrey", + "TitleStyle Centered -- Raised", + "Style \"*\" Color lightgrey/dimgrey, Title", + "Style \"*\" RandomPlacement, SmartPlacement", + "AddToMenu builtin_menu \"Builtin Menu\" Title", + "+ \"Exit FVWM\" Quit", "Mouse 1 R N Popup builtin_menu", + "AddToFunc WindowListFunc \"I\" WindowId $0 Iconify -1", + "+ \"I\" WindowId $0 FlipFocus", "+ \"I\" WindowId $0 Raise", + "+ \"I\" WindowId $0 WarpToWindow 5p 5p", NULL}; + int i = 0; + + while (defaults[i]) { + ExecuteFunction(defaults[i], NULL, &Event, C_ROOT, 1); + i++; + } } /* SetRCDefaults */ /*********************************************************************** @@ -757,37 +686,36 @@ void SetRCDefaults() * ***********************************************************************/ -int MappedNotOverride(Window w) +int +MappedNotOverride(Window w) { - XWindowAttributes wa; - Atom atype; - int aformat; - unsigned long nitems, bytes_remain; - unsigned char *prop; - - isIconicState = DontCareState; - - if((w==Scr.NoFocusWin)||(!XGetWindowAttributes(dpy, w, &wa))) - return False; - - if(XGetWindowProperty(dpy,w,_XA_WM_STATE,0L,3L,False,_XA_WM_STATE, - &atype,&aformat,&nitems,&bytes_remain,&prop)==Success) - { - if(prop != NULL) - { - isIconicState = *(long *)prop; - XFree(prop); - } - } - if(wa.override_redirect == True) - { - XSelectInput(dpy,w,FocusChangeMask); - } - return (((isIconicState == IconicState)||(wa.map_state != IsUnmapped)) && - (wa.override_redirect != True)); + XWindowAttributes wa; + Atom atype; + int aformat; + unsigned long nitems, bytes_remain; + unsigned char *prop; + + isIconicState = DontCareState; + + if ((w == Scr.NoFocusWin) || (!XGetWindowAttributes(dpy, w, &wa))) + return False; + + if (XGetWindowProperty(dpy, w, _XA_WM_STATE, 0L, 3L, False, + _XA_WM_STATE, &atype, &aformat, &nitems, &bytes_remain, + &prop) == Success) { + if (prop != NULL) { + isIconicState = *(long *)prop; + XFree(prop); + } + } + if (wa.override_redirect == True) { + XSelectInput(dpy, w, FocusChangeMask); + } + return ( + ((isIconicState == IconicState) || (wa.map_state != IsUnmapped)) && + (wa.override_redirect != True)); } - /*********************************************************************** * * Procedure: @@ -820,35 +748,38 @@ Atom _XA_OL_DECOR_RESIZE; Atom _XA_OL_DECOR_HEADER; Atom _XA_OL_DECOR_ICON_NAME; -void InternUsefulAtoms (void) +void +InternUsefulAtoms(void) { - /* - * Create priority colors if necessary. - */ - _XA_MIT_PRIORITY_COLORS = XInternAtom(dpy, "_MIT_PRIORITY_COLORS", False); - _XA_WM_CHANGE_STATE = XInternAtom (dpy, "WM_CHANGE_STATE", False); - _XA_WM_STATE = XInternAtom (dpy, "WM_STATE", False); - _XA_WM_COLORMAP_WINDOWS = XInternAtom (dpy, "WM_COLORMAP_WINDOWS", False); - _XA_WM_PROTOCOLS = XInternAtom (dpy, "WM_PROTOCOLS", False); - _XA_WM_TAKE_FOCUS = XInternAtom (dpy, "WM_TAKE_FOCUS", False); - _XA_WM_DELETE_WINDOW = XInternAtom (dpy, "WM_DELETE_WINDOW", False); - _XA_WM_DESKTOP = XInternAtom (dpy, "WM_DESKTOP", False); - _XA_MwmAtom=XInternAtom(dpy,"_MOTIF_WM_HINTS",False); - _XA_MOTIF_WM=XInternAtom(dpy,"_MOTIF_WM_INFO",False); - - _XA_OL_WIN_ATTR=XInternAtom(dpy,"_OL_WIN_ATTR",False); - _XA_OL_WT_BASE=XInternAtom(dpy,"_OL_WT_BASE",False); - _XA_OL_WT_CMD=XInternAtom(dpy,"_OL_WT_CMD",False); - _XA_OL_WT_HELP=XInternAtom(dpy,"_OL_WT_HELP",False); - _XA_OL_WT_NOTICE=XInternAtom(dpy,"_OL_WT_NOTICE",False); - _XA_OL_WT_OTHER=XInternAtom(dpy,"_OL_WT_OTHER",False); - _XA_OL_DECOR_ADD=XInternAtom(dpy,"_OL_DECOR_ADD",False); - _XA_OL_DECOR_DEL=XInternAtom(dpy,"_OL_DECOR_DEL",False); - _XA_OL_DECOR_CLOSE=XInternAtom(dpy,"_OL_DECOR_CLOSE",False); - _XA_OL_DECOR_RESIZE=XInternAtom(dpy,"_OL_DECOR_RESIZE",False); - _XA_OL_DECOR_HEADER=XInternAtom(dpy,"_OL_DECOR_HEADER",False); - _XA_OL_DECOR_ICON_NAME=XInternAtom(dpy,"_OL_DECOR_ICON_NAME",False); - return; + /* + * Create priority colors if necessary. + */ + _XA_MIT_PRIORITY_COLORS = + XInternAtom(dpy, "_MIT_PRIORITY_COLORS", False); + _XA_WM_CHANGE_STATE = XInternAtom(dpy, "WM_CHANGE_STATE", False); + _XA_WM_STATE = XInternAtom(dpy, "WM_STATE", False); + _XA_WM_COLORMAP_WINDOWS = + XInternAtom(dpy, "WM_COLORMAP_WINDOWS", False); + _XA_WM_PROTOCOLS = XInternAtom(dpy, "WM_PROTOCOLS", False); + _XA_WM_TAKE_FOCUS = XInternAtom(dpy, "WM_TAKE_FOCUS", False); + _XA_WM_DELETE_WINDOW = XInternAtom(dpy, "WM_DELETE_WINDOW", False); + _XA_WM_DESKTOP = XInternAtom(dpy, "WM_DESKTOP", False); + _XA_MwmAtom = XInternAtom(dpy, "_MOTIF_WM_HINTS", False); + _XA_MOTIF_WM = XInternAtom(dpy, "_MOTIF_WM_INFO", False); + + _XA_OL_WIN_ATTR = XInternAtom(dpy, "_OL_WIN_ATTR", False); + _XA_OL_WT_BASE = XInternAtom(dpy, "_OL_WT_BASE", False); + _XA_OL_WT_CMD = XInternAtom(dpy, "_OL_WT_CMD", False); + _XA_OL_WT_HELP = XInternAtom(dpy, "_OL_WT_HELP", False); + _XA_OL_WT_NOTICE = XInternAtom(dpy, "_OL_WT_NOTICE", False); + _XA_OL_WT_OTHER = XInternAtom(dpy, "_OL_WT_OTHER", False); + _XA_OL_DECOR_ADD = XInternAtom(dpy, "_OL_DECOR_ADD", False); + _XA_OL_DECOR_DEL = XInternAtom(dpy, "_OL_DECOR_DEL", False); + _XA_OL_DECOR_CLOSE = XInternAtom(dpy, "_OL_DECOR_CLOSE", False); + _XA_OL_DECOR_RESIZE = XInternAtom(dpy, "_OL_DECOR_RESIZE", False); + _XA_OL_DECOR_HEADER = XInternAtom(dpy, "_OL_DECOR_HEADER", False); + _XA_OL_DECOR_ICON_NAME = XInternAtom(dpy, "_OL_DECOR_ICON_NAME", False); + return; } /*********************************************************************** @@ -861,39 +792,38 @@ void newhandler(int sig) { #ifdef HAVE_SIGACTION - struct sigaction sigact; - - sigaction(sig,NULL,&sigact); - if (sigact.sa_handler != SIG_IGN) - { - /* - * SigDone requires that we QUIT as soon as possible afterwards, - * so we need to interrupt any system calls we are blocked in - */ - sigemptyset(&sigact.sa_mask); + struct sigaction sigact; + + sigaction(sig, NULL, &sigact); + if (sigact.sa_handler != SIG_IGN) { + /* + * SigDone requires that we QUIT as soon as possible afterwards, + * so we need to interrupt any system calls we are blocked in + */ + sigemptyset(&sigact.sa_mask); #ifdef SA_INTERRUPT - sigact.sa_flags = SA_INTERRUPT; + sigact.sa_flags = SA_INTERRUPT; #else - sigact.sa_flags = 0; + sigact.sa_flags = 0; #endif - sigact.sa_handler = SigDone; - sigaction(sig, &sigact, NULL); - } + sigact.sa_handler = SigDone; + sigaction(sig, &sigact, NULL); + } #else - /* We don't have sigaction(), so use less robust methods. */ - if (signal(sig,SIG_IGN) == SIG_IGN) - signal(sig,SigDone); + /* We don't have sigaction(), so use less robust methods. */ + if (signal(sig, SIG_IGN) == SIG_IGN) + signal(sig, SigDone); #endif } - /************************************************************************* * Restart on a signal ************************************************************************/ -RETSIGTYPE Restart(int nonsense) +void +Restart(int nonsense) { - isTerminated = True; - fvwmRunState = FVWM_RESTART; + isTerminated = True; + fvwmRunState = FVWM_RESTART; } /*********************************************************************** @@ -903,26 +833,31 @@ RETSIGTYPE Restart(int nonsense) * *********************************************************************** */ -void CreateCursors(void) +void +CreateCursors(void) { - /* define cursors */ - Scr.FvwmCursors[POSITION] = XCreateFontCursor(dpy,XC_top_left_corner); - Scr.FvwmCursors[DEFAULT] = XCreateFontCursor(dpy, XC_top_left_arrow); - Scr.FvwmCursors[SYS] = XCreateFontCursor(dpy, XC_hand2); - Scr.FvwmCursors[TITLE_CURSOR] = XCreateFontCursor(dpy, XC_top_left_arrow); - Scr.FvwmCursors[MOVE] = XCreateFontCursor(dpy, XC_fleur); - Scr.FvwmCursors[MENU] = XCreateFontCursor(dpy, XC_sb_left_arrow); - Scr.FvwmCursors[WAIT] = XCreateFontCursor(dpy, XC_watch); - Scr.FvwmCursors[SELECT] = XCreateFontCursor(dpy, XC_dot); - Scr.FvwmCursors[DESTROY] = XCreateFontCursor(dpy, XC_pirate); - Scr.FvwmCursors[LEFT] = XCreateFontCursor(dpy, XC_left_side); - Scr.FvwmCursors[RIGHT] = XCreateFontCursor(dpy, XC_right_side); - Scr.FvwmCursors[TOP] = XCreateFontCursor(dpy, XC_top_side); - Scr.FvwmCursors[BOTTOM] = XCreateFontCursor(dpy, XC_bottom_side); - Scr.FvwmCursors[TOP_LEFT] = XCreateFontCursor(dpy,XC_top_left_corner); - Scr.FvwmCursors[TOP_RIGHT] = XCreateFontCursor(dpy,XC_top_right_corner); - Scr.FvwmCursors[BOTTOM_LEFT] = XCreateFontCursor(dpy,XC_bottom_left_corner); - Scr.FvwmCursors[BOTTOM_RIGHT] =XCreateFontCursor(dpy,XC_bottom_right_corner); + /* define cursors */ + Scr.FvwmCursors[POSITION] = XCreateFontCursor(dpy, XC_top_left_corner); + Scr.FvwmCursors[DEFAULT] = XCreateFontCursor(dpy, XC_top_left_arrow); + Scr.FvwmCursors[SYS] = XCreateFontCursor(dpy, XC_hand2); + Scr.FvwmCursors[TITLE_CURSOR] = + XCreateFontCursor(dpy, XC_top_left_arrow); + Scr.FvwmCursors[MOVE] = XCreateFontCursor(dpy, XC_fleur); + Scr.FvwmCursors[MENU] = XCreateFontCursor(dpy, XC_sb_left_arrow); + Scr.FvwmCursors[WAIT] = XCreateFontCursor(dpy, XC_watch); + Scr.FvwmCursors[SELECT] = XCreateFontCursor(dpy, XC_dot); + Scr.FvwmCursors[DESTROY] = XCreateFontCursor(dpy, XC_pirate); + Scr.FvwmCursors[LEFT] = XCreateFontCursor(dpy, XC_left_side); + Scr.FvwmCursors[RIGHT] = XCreateFontCursor(dpy, XC_right_side); + Scr.FvwmCursors[TOP] = XCreateFontCursor(dpy, XC_top_side); + Scr.FvwmCursors[BOTTOM] = XCreateFontCursor(dpy, XC_bottom_side); + Scr.FvwmCursors[TOP_LEFT] = XCreateFontCursor(dpy, XC_top_left_corner); + Scr.FvwmCursors[TOP_RIGHT] = + XCreateFontCursor(dpy, XC_top_right_corner); + Scr.FvwmCursors[BOTTOM_LEFT] = + XCreateFontCursor(dpy, XC_bottom_left_corner); + Scr.FvwmCursors[BOTTOM_RIGHT] = + XCreateFontCursor(dpy, XC_bottom_right_corner); } /*********************************************************************** @@ -931,88 +866,88 @@ void CreateCursors(void) * assumes associated button memory is already free * ************************************************************************/ -void LoadDefaultLeftButton(ButtonFace *bf, int i) +void +LoadDefaultLeftButton(ButtonFace *bf, int i) { #ifndef VECTOR_BUTTONS - bf->style = SimpleButton; + bf->style = SimpleButton; #else - bf->style = VectorButton; - switch (i % 5) - { - case 0: - case 4: - bf->vector.x[0] = 22; - bf->vector.y[0] = 39; - bf->vector.line_style[0] = 1; - bf->vector.x[1] = 78; - bf->vector.y[1] = 39; - bf->vector.line_style[1] = 1; - bf->vector.x[2] = 78; - bf->vector.y[2] = 61; - bf->vector.line_style[2] = 0; - bf->vector.x[3] = 22; - bf->vector.y[3] = 61; - bf->vector.line_style[3] = 0; - bf->vector.x[4] = 22; - bf->vector.y[4] = 39; - bf->vector.line_style[4] = 1; - bf->vector.num = 5; - break; - case 1: - bf->vector.x[0] = 32; - bf->vector.y[0] = 45; - bf->vector.line_style[0] = 0; - bf->vector.x[1] = 68; - bf->vector.y[1] = 45; - bf->vector.line_style[1] = 0; - bf->vector.x[2] = 68; - bf->vector.y[2] = 55; - bf->vector.line_style[2] = 1; - bf->vector.x[3] = 32; - bf->vector.y[3] = 55; - bf->vector.line_style[3] = 1; - bf->vector.x[4] = 32; - bf->vector.y[4] = 45; - bf->vector.line_style[4] = 0; - bf->vector.num = 5; - break; - case 2: - bf->vector.x[0] = 49; - bf->vector.y[0] = 49; - bf->vector.line_style[0] = 1; - bf->vector.x[1] = 51; - bf->vector.y[1] = 49; - bf->vector.line_style[1] = 1; - bf->vector.x[2] = 51; - bf->vector.y[2] = 51; - bf->vector.line_style[2] = 0; - bf->vector.x[3] = 49; - bf->vector.y[3] = 51; - bf->vector.line_style[3] = 0; - bf->vector.x[4] = 49; - bf->vector.y[4] = 49; - bf->vector.line_style[4] = 1; - bf->vector.num = 5; - break; - case 3: - bf->vector.x[0] = 32; - bf->vector.y[0] = 45; - bf->vector.line_style[0] = 1; - bf->vector.x[1] = 68; - bf->vector.y[1] = 45; - bf->vector.line_style[1] = 1; - bf->vector.x[2] = 68; - bf->vector.y[2] = 55; - bf->vector.line_style[2] = 0; - bf->vector.x[3] = 32; - bf->vector.y[3] = 55; - bf->vector.line_style[3] = 0; - bf->vector.x[4] = 32; - bf->vector.y[4] = 45; - bf->vector.line_style[4] = 1; - bf->vector.num = 5; - break; - } + bf->style = VectorButton; + switch (i % 5) { + case 0: + case 4: + bf->vector.x[0] = 22; + bf->vector.y[0] = 39; + bf->vector.line_style[0] = 1; + bf->vector.x[1] = 78; + bf->vector.y[1] = 39; + bf->vector.line_style[1] = 1; + bf->vector.x[2] = 78; + bf->vector.y[2] = 61; + bf->vector.line_style[2] = 0; + bf->vector.x[3] = 22; + bf->vector.y[3] = 61; + bf->vector.line_style[3] = 0; + bf->vector.x[4] = 22; + bf->vector.y[4] = 39; + bf->vector.line_style[4] = 1; + bf->vector.num = 5; + break; + case 1: + bf->vector.x[0] = 32; + bf->vector.y[0] = 45; + bf->vector.line_style[0] = 0; + bf->vector.x[1] = 68; + bf->vector.y[1] = 45; + bf->vector.line_style[1] = 0; + bf->vector.x[2] = 68; + bf->vector.y[2] = 55; + bf->vector.line_style[2] = 1; + bf->vector.x[3] = 32; + bf->vector.y[3] = 55; + bf->vector.line_style[3] = 1; + bf->vector.x[4] = 32; + bf->vector.y[4] = 45; + bf->vector.line_style[4] = 0; + bf->vector.num = 5; + break; + case 2: + bf->vector.x[0] = 49; + bf->vector.y[0] = 49; + bf->vector.line_style[0] = 1; + bf->vector.x[1] = 51; + bf->vector.y[1] = 49; + bf->vector.line_style[1] = 1; + bf->vector.x[2] = 51; + bf->vector.y[2] = 51; + bf->vector.line_style[2] = 0; + bf->vector.x[3] = 49; + bf->vector.y[3] = 51; + bf->vector.line_style[3] = 0; + bf->vector.x[4] = 49; + bf->vector.y[4] = 49; + bf->vector.line_style[4] = 1; + bf->vector.num = 5; + break; + case 3: + bf->vector.x[0] = 32; + bf->vector.y[0] = 45; + bf->vector.line_style[0] = 1; + bf->vector.x[1] = 68; + bf->vector.y[1] = 45; + bf->vector.line_style[1] = 1; + bf->vector.x[2] = 68; + bf->vector.y[2] = 55; + bf->vector.line_style[2] = 0; + bf->vector.x[3] = 32; + bf->vector.y[3] = 55; + bf->vector.line_style[3] = 0; + bf->vector.x[4] = 32; + bf->vector.y[4] = 45; + bf->vector.line_style[4] = 1; + bf->vector.num = 5; + break; + } #endif /* VECTOR_BUTTONS */ } @@ -1022,88 +957,88 @@ void LoadDefaultLeftButton(ButtonFace *bf, int i) * assumes associated button memory is already free * ************************************************************************/ -void LoadDefaultRightButton(ButtonFace *bf, int i) +void +LoadDefaultRightButton(ButtonFace *bf, int i) { #ifndef VECTOR_BUTTONS - bf->style = SimpleButton; + bf->style = SimpleButton; #else - bf->style = VectorButton; - switch (i % 5) - { - case 0: - case 3: - bf->vector.x[0] = 25; - bf->vector.y[0] = 25; - bf->vector.line_style[0] = 1; - bf->vector.x[1] = 75; - bf->vector.y[1] = 25; - bf->vector.line_style[1] = 1; - bf->vector.x[2] = 75; - bf->vector.y[2] = 75; - bf->vector.line_style[2] = 0; - bf->vector.x[3] = 25; - bf->vector.y[3] = 75; - bf->vector.line_style[3] = 0; - bf->vector.x[4] = 25; - bf->vector.y[4] = 25; - bf->vector.line_style[4] = 1; - bf->vector.num = 5; - break; - case 1: - bf->vector.x[0] = 39; - bf->vector.y[0] = 39; - bf->vector.line_style[0] = 1; - bf->vector.x[1] = 61; - bf->vector.y[1] = 39; - bf->vector.line_style[1] = 1; - bf->vector.x[2] = 61; - bf->vector.y[2] = 61; - bf->vector.line_style[2] = 0; - bf->vector.x[3] = 39; - bf->vector.y[3] = 61; - bf->vector.line_style[3] = 0; - bf->vector.x[4] = 39; - bf->vector.y[4] = 39; - bf->vector.line_style[4] = 1; - bf->vector.num = 5; - break; - case 2: - bf->vector.x[0] = 49; - bf->vector.y[0] = 49; - bf->vector.line_style[0] = 1; - bf->vector.x[1] = 51; - bf->vector.y[1] = 49; - bf->vector.line_style[1] = 1; - bf->vector.x[2] = 51; - bf->vector.y[2] = 51; - bf->vector.line_style[2] = 0; - bf->vector.x[3] = 49; - bf->vector.y[3] = 51; - bf->vector.line_style[3] = 0; - bf->vector.x[4] = 49; - bf->vector.y[4] = 49; - bf->vector.line_style[4] = 1; - bf->vector.num = 5; - break; - case 4: - bf->vector.x[0] = 36; - bf->vector.y[0] = 36; - bf->vector.line_style[0] = 1; - bf->vector.x[1] = 64; - bf->vector.y[1] = 36; - bf->vector.line_style[1] = 1; - bf->vector.x[2] = 64; - bf->vector.y[2] = 64; - bf->vector.line_style[2] = 0; - bf->vector.x[3] = 36; - bf->vector.y[3] = 64; - bf->vector.line_style[3] = 0; - bf->vector.x[4] = 36; - bf->vector.y[4] = 36; - bf->vector.line_style[4] = 1; - bf->vector.num = 5; - break; - } + bf->style = VectorButton; + switch (i % 5) { + case 0: + case 3: + bf->vector.x[0] = 25; + bf->vector.y[0] = 25; + bf->vector.line_style[0] = 1; + bf->vector.x[1] = 75; + bf->vector.y[1] = 25; + bf->vector.line_style[1] = 1; + bf->vector.x[2] = 75; + bf->vector.y[2] = 75; + bf->vector.line_style[2] = 0; + bf->vector.x[3] = 25; + bf->vector.y[3] = 75; + bf->vector.line_style[3] = 0; + bf->vector.x[4] = 25; + bf->vector.y[4] = 25; + bf->vector.line_style[4] = 1; + bf->vector.num = 5; + break; + case 1: + bf->vector.x[0] = 39; + bf->vector.y[0] = 39; + bf->vector.line_style[0] = 1; + bf->vector.x[1] = 61; + bf->vector.y[1] = 39; + bf->vector.line_style[1] = 1; + bf->vector.x[2] = 61; + bf->vector.y[2] = 61; + bf->vector.line_style[2] = 0; + bf->vector.x[3] = 39; + bf->vector.y[3] = 61; + bf->vector.line_style[3] = 0; + bf->vector.x[4] = 39; + bf->vector.y[4] = 39; + bf->vector.line_style[4] = 1; + bf->vector.num = 5; + break; + case 2: + bf->vector.x[0] = 49; + bf->vector.y[0] = 49; + bf->vector.line_style[0] = 1; + bf->vector.x[1] = 51; + bf->vector.y[1] = 49; + bf->vector.line_style[1] = 1; + bf->vector.x[2] = 51; + bf->vector.y[2] = 51; + bf->vector.line_style[2] = 0; + bf->vector.x[3] = 49; + bf->vector.y[3] = 51; + bf->vector.line_style[3] = 0; + bf->vector.x[4] = 49; + bf->vector.y[4] = 49; + bf->vector.line_style[4] = 1; + bf->vector.num = 5; + break; + case 4: + bf->vector.x[0] = 36; + bf->vector.y[0] = 36; + bf->vector.line_style[0] = 1; + bf->vector.x[1] = 64; + bf->vector.y[1] = 36; + bf->vector.line_style[1] = 1; + bf->vector.x[2] = 64; + bf->vector.y[2] = 64; + bf->vector.line_style[2] = 0; + bf->vector.x[3] = 36; + bf->vector.y[3] = 64; + bf->vector.line_style[3] = 0; + bf->vector.x[4] = 36; + bf->vector.y[4] = 36; + bf->vector.line_style[4] = 1; + bf->vector.num = 5; + break; + } #endif /* VECTOR_BUTTONS */ } @@ -1113,14 +1048,16 @@ void LoadDefaultRightButton(ButtonFace *bf, int i) * assumes associated button memory is already free * ************************************************************************/ -void LoadDefaultButton(ButtonFace *bf, int i) +void +LoadDefaultButton(ButtonFace *bf, int i) { - int n = i / 2; - if ((n * 2) == i) { - if (--n < 0) n = 4; - LoadDefaultRightButton(bf, n); - } else - LoadDefaultLeftButton(bf, n); + int n = i / 2; + if ((n * 2) == i) { + if (--n < 0) + n = 4; + LoadDefaultRightButton(bf, n); + } else + LoadDefaultLeftButton(bf, n); } extern void FreeButtonFace(Display *dpy, ButtonFace *bf); @@ -1131,43 +1068,43 @@ extern void FreeButtonFace(Display *dpy, ButtonFace *bf); * destroys existing buttons * ************************************************************************/ -void ResetAllButtons(FvwmDecor *fl) +void +ResetAllButtons(FvwmDecor *fl) { - TitleButton *leftp, *rightp; - int i=0; + TitleButton *leftp, *rightp; + int i = 0; - for (leftp=fl->left_buttons, rightp=fl->right_buttons; - i < 5; - ++i, ++leftp, ++rightp) { - ButtonFace *lface, *rface; - int j; + for (leftp = fl->left_buttons, rightp = fl->right_buttons; i < 5; + ++i, ++leftp, ++rightp) { + ButtonFace *lface, *rface; + int j; - leftp->flags = 0; - rightp->flags = 0; + leftp->flags = 0; + rightp->flags = 0; - lface = leftp->state; - rface = rightp->state; + lface = leftp->state; + rface = rightp->state; - FreeButtonFace(dpy, lface); - FreeButtonFace(dpy, rface); + FreeButtonFace(dpy, lface); + FreeButtonFace(dpy, rface); - LoadDefaultLeftButton(lface++, i); - LoadDefaultRightButton(rface++, i); + LoadDefaultLeftButton(lface++, i); + LoadDefaultRightButton(rface++, i); - for (j = 1; j < MaxButtonState; ++j, ++lface, ++rface) { - FreeButtonFace(dpy, lface); - FreeButtonFace(dpy, rface); + for (j = 1; j < MaxButtonState; ++j, ++lface, ++rface) { + FreeButtonFace(dpy, lface); + FreeButtonFace(dpy, rface); - *lface = leftp->state[0]; - *rface = rightp->state[0]; - } - } + *lface = leftp->state[0]; + *rface = rightp->state[0]; + } + } - /* standard MWM decoration hint assignments (veliaa@rpi.edu) - [Menu] - Title Bar - [Minimize] [Maximize] */ - fl->left_buttons[0].flags |= MWMDecorMenu; - fl->right_buttons[1].flags |= MWMDecorMinimize; - fl->right_buttons[0].flags |= MWMDecorMaximize; + /* standard MWM decoration hint assignments (veliaa@rpi.edu) + [Menu] - Title Bar - [Minimize] [Maximize] */ + fl->left_buttons[0].flags |= MWMDecorMenu; + fl->right_buttons[1].flags |= MWMDecorMinimize; + fl->right_buttons[0].flags |= MWMDecorMaximize; } /*********************************************************************** @@ -1176,37 +1113,37 @@ void ResetAllButtons(FvwmDecor *fl) * structure, but does not free the FvwmDecor itself * ************************************************************************/ -void DestroyFvwmDecor(FvwmDecor *fl) +void +DestroyFvwmDecor(FvwmDecor *fl) { - int i; - /* reset to default button set (frees allocated mem) */ - ResetAllButtons(fl); - for (i = 0; i < 3; ++i) - { - int j = 0; - for (; j < MaxButtonState; ++j) - FreeButtonFace(dpy, &fl->titlebar.state[i]); - } + int i; + /* reset to default button set (frees allocated mem) */ + ResetAllButtons(fl); + for (i = 0; i < 3; ++i) { + int j = 0; + for (; j < MaxButtonState; ++j) + FreeButtonFace(dpy, &fl->titlebar.state[i]); + } #ifdef BORDERSTYLE - FreeButtonFace(dpy, &fl->BorderStyle.active); - FreeButtonFace(dpy, &fl->BorderStyle.inactive); + FreeButtonFace(dpy, &fl->BorderStyle.active); + FreeButtonFace(dpy, &fl->BorderStyle.inactive); #endif #ifdef USEDECOR - if (fl->tag) { - free(fl->tag); - fl->tag = NULL; - } + if (fl->tag) { + free(fl->tag); + fl->tag = NULL; + } #endif - if (fl->HiReliefGC != NULL) { - XFreeGC(dpy, fl->HiReliefGC); - fl->HiReliefGC = NULL; - } - if (fl->HiShadowGC != NULL) { - XFreeGC(dpy, fl->HiShadowGC); - fl->HiShadowGC = NULL; - } - if (fl->WindowFont.font != NULL) - XFreeFont(dpy, fl->WindowFont.font); + if (fl->HiReliefGC != NULL) { + XFreeGC(dpy, fl->HiReliefGC); + fl->HiReliefGC = NULL; + } + if (fl->HiShadowGC != NULL) { + XFreeGC(dpy, fl->HiShadowGC); + fl->HiShadowGC = NULL; + } + if (fl->WindowFont.font != NULL) + XFreeFont(dpy, fl->WindowFont.font); } /*********************************************************************** @@ -1214,60 +1151,61 @@ void DestroyFvwmDecor(FvwmDecor *fl) * InitFvwmDecor -- initializes an FvwmDecor structure to defaults * ************************************************************************/ -void InitFvwmDecor(FvwmDecor *fl) +void +InitFvwmDecor(FvwmDecor *fl) { - int i; - ButtonFace tmpbf; + int i; + ButtonFace tmpbf; - fl->HiReliefGC = NULL; - fl->HiShadowGC = NULL; - fl->TitleHeight = 0; - fl->WindowFont.font = NULL; + fl->HiReliefGC = NULL; + fl->HiShadowGC = NULL; + fl->TitleHeight = 0; + fl->WindowFont.font = NULL; #ifdef USEDECOR - fl->tag = NULL; - fl->next = NULL; - - if (fl != &Scr.DefaultDecor) { - extern void AddToDecor(FvwmDecor *, char *); - AddToDecor(fl, "HilightColor black grey"); - AddToDecor(fl, "WindowFont fixed"); - } + fl->tag = NULL; + fl->next = NULL; + + if (fl != &Scr.DefaultDecor) { + extern void AddToDecor(FvwmDecor *, char *); + AddToDecor(fl, "HilightColor black grey"); + AddToDecor(fl, "WindowFont fixed"); + } #endif - /* initialize title-bar button styles */ - tmpbf.style = SimpleButton; + /* initialize title-bar button styles */ + tmpbf.style = SimpleButton; #ifdef MULTISTYLE - tmpbf.next = NULL; + tmpbf.next = NULL; #endif - for (i = 0; i < 5; ++i) { - int j = 0; - for (; j < MaxButtonState; ++j) { - fl->left_buttons[i].state[j] = - fl->right_buttons[i].state[j] = tmpbf; + for (i = 0; i < 5; ++i) { + int j = 0; + for (; j < MaxButtonState; ++j) { + fl->left_buttons[i].state[j] = + fl->right_buttons[i].state[j] = tmpbf; + } } - } - /* reset to default button set */ - ResetAllButtons(fl); + /* reset to default button set */ + ResetAllButtons(fl); - /* initialize title-bar styles */ - fl->titlebar.flags = 0; + /* initialize title-bar styles */ + fl->titlebar.flags = 0; - for (i = 0; i < MaxButtonState; ++i) { - fl->titlebar.state[i].style = SimpleButton; + for (i = 0; i < MaxButtonState; ++i) { + fl->titlebar.state[i].style = SimpleButton; #ifdef MULTISTYLE - fl->titlebar.state[i].next = NULL; + fl->titlebar.state[i].next = NULL; #endif - } + } #ifdef BORDERSTYLE - /* initialize border texture styles */ - fl->BorderStyle.active.style = SimpleButton; - fl->BorderStyle.inactive.style = SimpleButton; + /* initialize border texture styles */ + fl->BorderStyle.active.style = SimpleButton; + fl->BorderStyle.inactive.style = SimpleButton; #ifdef MULTISTYLE - fl->BorderStyle.active.next = NULL; - fl->BorderStyle.inactive.next = NULL; + fl->BorderStyle.active.next = NULL; + fl->BorderStyle.inactive.next = NULL; #endif #endif } @@ -1278,138 +1216,138 @@ void InitFvwmDecor(FvwmDecor *fl) * InitVariables - initialize fvwm variables * ************************************************************************/ -void InitVariables(void) +void +InitVariables(void) { - FvwmContext = XUniqueContext(); - MenuContext = XUniqueContext(); - - /* initialize some lists */ - Scr.AllBindings = NULL; - Scr.TheList = NULL; - - Scr.menus.all = NULL; - Scr.menus.DefaultStyle = NULL; - Scr.menus.LastStyle = NULL; - Scr.menus.PopupDelay10ms = DEFAULT_POPUP_DELAY; - Scr.menus.DoubleClickTime = DEFAULT_MENU_CLICKTIME; - - Scr.DefaultIcon = NULL; - - Scr.StdColors.fore = 0; - Scr.StdColors.back = 0; - Scr.StdRelief.fore = 0; - Scr.StdRelief.back = 0; - Scr.StdGC = 0; - Scr.StdReliefGC = 0; - Scr.StdShadowGC = 0; - Scr.DrawGC = 0; - Scr.hasIconFont = False; - Scr.hasWindowFont = False; - - /* create graphics contexts */ - CreateGCs(); - - Scr.d_depth = DefaultDepth(dpy, Scr.screen); - Scr.FvwmRoot.w = Scr.Root; - Scr.FvwmRoot.next = 0; - - /* RBW - 11/13/1998 - 2 new fields to init - stacking order chain. */ - Scr.FvwmRoot.stack_next = &Scr.FvwmRoot; - Scr.FvwmRoot.stack_prev = &Scr.FvwmRoot; - - XGetWindowAttributes(dpy,Scr.Root,&(Scr.FvwmRoot.attr)); - Scr.root_pushes = 0; - Scr.pushed_window = &Scr.FvwmRoot; - Scr.FvwmRoot.number_cmap_windows = 0; - - - Scr.MyDisplayWidth = DisplayWidth(dpy, Scr.screen); - Scr.MyDisplayHeight = DisplayHeight(dpy, Scr.screen); - - Scr.NoBoundaryWidth = 1; - Scr.BoundaryWidth = BOUNDARY_WIDTH; - Scr.CornerWidth = CORNER_WIDTH; - Scr.Hilite = NULL; - Scr.Focus = NULL; - Scr.PreviousFocus = NULL; - Scr.Ungrabbed = NULL; - - Scr.StdFont.font = NULL; - Scr.IconFont.font = NULL; + FvwmContext = XUniqueContext(); + MenuContext = XUniqueContext(); + + /* initialize some lists */ + Scr.AllBindings = NULL; + Scr.TheList = NULL; + + Scr.menus.all = NULL; + Scr.menus.DefaultStyle = NULL; + Scr.menus.LastStyle = NULL; + Scr.menus.PopupDelay10ms = DEFAULT_POPUP_DELAY; + Scr.menus.DoubleClickTime = DEFAULT_MENU_CLICKTIME; + + Scr.DefaultIcon = NULL; + + Scr.StdColors.fore = 0; + Scr.StdColors.back = 0; + Scr.StdRelief.fore = 0; + Scr.StdRelief.back = 0; + Scr.StdGC = 0; + Scr.StdReliefGC = 0; + Scr.StdShadowGC = 0; + Scr.DrawGC = 0; + Scr.hasIconFont = False; + Scr.hasWindowFont = False; + + /* create graphics contexts */ + CreateGCs(); + + Scr.d_depth = DefaultDepth(dpy, Scr.screen); + Scr.FvwmRoot.w = Scr.Root; + Scr.FvwmRoot.next = 0; + + /* RBW - 11/13/1998 - 2 new fields to init - stacking order chain. */ + Scr.FvwmRoot.stack_next = &Scr.FvwmRoot; + Scr.FvwmRoot.stack_prev = &Scr.FvwmRoot; + + XGetWindowAttributes(dpy, Scr.Root, &(Scr.FvwmRoot.attr)); + Scr.root_pushes = 0; + Scr.pushed_window = &Scr.FvwmRoot; + Scr.FvwmRoot.number_cmap_windows = 0; + + Scr.MyDisplayWidth = DisplayWidth(dpy, Scr.screen); + Scr.MyDisplayHeight = DisplayHeight(dpy, Scr.screen); + + Scr.NoBoundaryWidth = 1; + Scr.BoundaryWidth = BOUNDARY_WIDTH; + Scr.CornerWidth = CORNER_WIDTH; + Scr.Hilite = NULL; + Scr.Focus = NULL; + Scr.PreviousFocus = NULL; + Scr.Ungrabbed = NULL; + + Scr.StdFont.font = NULL; + Scr.IconFont.font = NULL; #ifndef NON_VIRTUAL - Scr.VxMax = 2*Scr.MyDisplayWidth; - Scr.VyMax = 2*Scr.MyDisplayHeight; + Scr.VxMax = 2 * Scr.MyDisplayWidth; + Scr.VyMax = 2 * Scr.MyDisplayHeight; #else - Scr.VxMax = 0; - Scr.VyMax = 0; + Scr.VxMax = 0; + Scr.VyMax = 0; #endif - Scr.Vx = Scr.Vy = 0; - - Scr.SizeWindow = None; - - /* Sets the current desktop number to zero */ - /* Multiple desks are available even in non-virtual - * compilations */ - { - Atom atype; - int aformat; - unsigned long nitems, bytes_remain; - unsigned char *prop; - - Scr.CurrentDesk = 0; - if ((XGetWindowProperty(dpy, Scr.Root, _XA_WM_DESKTOP, 0L, 1L, True, - _XA_WM_DESKTOP, &atype, &aformat, &nitems, - &bytes_remain, &prop))==Success) - { - if(prop != NULL) - { - Restarting = True; - Scr.CurrentDesk = *(unsigned long *)prop; - } - } - } - - Scr.EdgeScrollX = Scr.EdgeScrollY = 100; - Scr.ScrollResistance = Scr.MoveResistance = 0; - Scr.SnapAttraction = -1; - Scr.SnapMode = 0; - Scr.SnapGridX = 1; - Scr.SnapGridY = 1; - Scr.OpaqueSize = 5; - /* ClickTime is set to the positive value upon entering the event loop. */ - Scr.ClickTime = -DEFAULT_CLICKTIME; - Scr.ColormapFocus = COLORMAP_FOLLOWS_MOUSE; - - /* set major operating modes */ - Scr.NumBoxes = 0; - - Scr.randomx = Scr.randomy = 0; - Scr.buttons2grab = 7; - - InitFvwmDecor(&Scr.DefaultDecor); + Scr.Vx = Scr.Vy = 0; + + Scr.SizeWindow = None; + + /* Sets the current desktop number to zero */ + /* Multiple desks are available even in non-virtual + * compilations */ + { + Atom atype; + int aformat; + unsigned long nitems, bytes_remain; + unsigned char *prop; + + Scr.CurrentDesk = 0; + if ((XGetWindowProperty(dpy, Scr.Root, _XA_WM_DESKTOP, 0L, 1L, + True, _XA_WM_DESKTOP, &atype, &aformat, &nitems, + &bytes_remain, &prop)) == Success) { + if (prop != NULL) { + Restarting = True; + Scr.CurrentDesk = *(unsigned long *)prop; + } + } + } + + Scr.EdgeScrollX = Scr.EdgeScrollY = 100; + Scr.ScrollResistance = Scr.MoveResistance = 0; + Scr.SnapAttraction = -1; + Scr.SnapMode = 0; + Scr.SnapGridX = 1; + Scr.SnapGridY = 1; + Scr.OpaqueSize = 5; + /* ClickTime is set to the positive value upon entering the event loop. + */ + Scr.ClickTime = -DEFAULT_CLICKTIME; + Scr.ColormapFocus = COLORMAP_FOLLOWS_MOUSE; + + /* set major operating modes */ + Scr.NumBoxes = 0; + + Scr.randomx = Scr.randomy = 0; + Scr.buttons2grab = 7; + + InitFvwmDecor(&Scr.DefaultDecor); #ifdef USEDECOR - Scr.DefaultDecor.tag = "Default"; + Scr.DefaultDecor.tag = "Default"; #endif - Scr.SmartPlacementIsClever = False; - Scr.ClickToFocusPassesClick = True; - Scr.ClickToFocusRaises = True; - Scr.MouseFocusClickRaises = False; - Scr.StipledTitles = False; - - /* RBW - 11/02/1998 */ - Scr.go.ModifyUSP = True; - Scr.go.CaptureHonorsStartsOnPage = True; - Scr.go.RecaptureHonorsStartsOnPage = False; - Scr.go.ActivePlacementHonorsStartsOnPage = False; - - Scr.gs.EmulateMWM = False; - Scr.gs.EmulateWIN = False; - /* Not the right place for this, should only be called once somewhere .. */ - InitPictureCMap(dpy,Scr.Root); - - return; + Scr.SmartPlacementIsClever = False; + Scr.ClickToFocusPassesClick = True; + Scr.ClickToFocusRaises = True; + Scr.MouseFocusClickRaises = False; + Scr.StipledTitles = False; + + /* RBW - 11/02/1998 */ + Scr.go.ModifyUSP = 1U; + Scr.go.CaptureHonorsStartsOnPage = 1U; + Scr.go.RecaptureHonorsStartsOnPage = 0U; + Scr.go.ActivePlacementHonorsStartsOnPage = 0U; + + Scr.gs.EmulateMWM = False; + Scr.gs.EmulateWIN = False; + /* Not the right place for this, should only be called once somewhere .. + */ + InitPictureCMap(dpy, Scr.Root); + + return; } /*********************************************************************** @@ -1418,29 +1356,30 @@ void InitVariables(void) * Reborder - Removes fvwm border windows * ************************************************************************/ -void Reborder(void) +void +Reborder(void) { - FvwmWindow *tmp; /* temp fvwm window structure */ - - /* put a border back around all windows */ - MyXGrabServer (dpy); - - InstallWindowColormaps (&Scr.FvwmRoot); /* force reinstall */ -/* - RBW - 05/15/1998 - Grab the last window and work backwards: preserve stacking order on restart. -*/ - for (tmp = Scr.FvwmRoot.stack_prev; tmp != &Scr.FvwmRoot; tmp = tmp->stack_prev) - { - RestoreWithdrawnLocation (tmp,True); - XUnmapWindow(dpy,tmp->frame); - XDestroyWindow(dpy,tmp->frame); - } - - MyXUngrabServer (dpy); - XSetInputFocus (dpy, PointerRoot, RevertToPointerRoot,CurrentTime); - XSync(dpy,0); + FvwmWindow *tmp; /* temp fvwm window structure */ + + /* put a border back around all windows */ + MyXGrabServer(dpy); + + InstallWindowColormaps(&Scr.FvwmRoot); /* force reinstall */ + /* + RBW - 05/15/1998 + Grab the last window and work backwards: preserve stacking order on + restart. + */ + for (tmp = Scr.FvwmRoot.stack_prev; tmp != &Scr.FvwmRoot; + tmp = tmp->stack_prev) { + RestoreWithdrawnLocation(tmp, True); + XUnmapWindow(dpy, tmp->frame); + XDestroyWindow(dpy, tmp->frame); + } + MyXUngrabServer(dpy); + XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); + XSync(dpy, 0); } /*********************************************************************** @@ -1450,84 +1389,84 @@ void Reborder(void) * *********************************************************************** */ -RETSIGTYPE SigDone(int nonsense) +void +SigDone(int nonsense) { - isTerminated = True; - fvwmRunState = FVWM_DONE; + isTerminated = True; + fvwmRunState = FVWM_DONE; } -void Done(int restart, char *command) +void +Done(int restart, char *command) { - MenuRoot *mr; + MenuRoot *mr; #ifndef NON_VIRTUAL - MoveViewport(0,0,False); + 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!!!! (restarting '%s' instead)", - command, - g_argv[0]); - 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); + 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, j; + + if (strstr(command, "fvwm") != NULL) { + i = 0; + j = 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++; + } + my_argv[i++] = "-s"; + while (i < 10) + my_argv[i++] = NULL; + } else { + my_argv[0] = command; + my_argv[1] = NULL; + } + + sleep(1); + ReapChildren(); + execvp(command, my_argv); + } + fvwm_msg(ERR, "Done", + "Call of '%s' failed!!!! (restarting '%s' instead)", + command, g_argv[0]); + 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); } -int CatchRedirectError(Display *dpy, XErrorEvent *event) +int +CatchRedirectError(Display *dpy, XErrorEvent *event) { - fvwm_msg(ERR,"CatchRedirectError","another WM is running"); - exit(1); + fvwm_msg(ERR, "CatchRedirectError", "another WM is running"); + exit(1); } /*********************************************************************** @@ -1536,13 +1475,14 @@ int CatchRedirectError(Display *dpy, XErrorEvent *event) * CatchFatal - Shuts down if the server connection is lost * ************************************************************************/ -int CatchFatal(Display *dpy) +int +CatchFatal(Display *dpy) { - /* No action is taken because usually this action is caused by someone - using "xlogout" to be able to switch between multiple window managers - */ - ClosePipes(); - exit(1); + /* No action is taken because usually this action is caused by someone + using "xlogout" to be able to switch between multiple window managers + */ + ClosePipes(); + exit(1); } /*********************************************************************** @@ -1551,37 +1491,36 @@ int CatchFatal(Display *dpy) * FvwmErrorHandler - displays info on internal errors * ************************************************************************/ -int FvwmErrorHandler(Display *dpy, XErrorEvent *event) +int +FvwmErrorHandler(Display *dpy, XErrorEvent *event) { - extern int last_event_type; - - /* some errors are acceptable, mostly they're caused by - * trying to update a lost window */ - if((event->error_code == BadWindow)||(event->request_code == X_GetGeometry)|| - (event->error_code==BadDrawable)||(event->request_code==X_SetInputFocus)|| - (event->request_code==X_GrabButton)|| - (event->request_code==X_ChangeWindowAttributes)|| - (event->request_code == X_InstallColormap)) - return 0 ; - - - fvwm_msg(ERR,"FvwmErrorHandler","*** internal error ***"); - fvwm_msg(ERR,"FvwmErrorHandler","Request %d, Error %d, EventType: %d", - event->request_code, - event->error_code, - last_event_type); - return 0; + extern int last_event_type; + + /* some errors are acceptable, mostly they're caused by + * trying to update a lost window */ + if ((event->error_code == BadWindow) || + (event->request_code == X_GetGeometry) || + (event->error_code == BadDrawable) || + (event->request_code == X_SetInputFocus) || + (event->request_code == X_GrabButton) || + (event->request_code == X_ChangeWindowAttributes) || + (event->request_code == X_InstallColormap)) + return 0; + + fvwm_msg(ERR, "FvwmErrorHandler", "*** internal error ***"); + fvwm_msg(ERR, "FvwmErrorHandler", "Request %d, Error %d, EventType: %d", + event->request_code, event->error_code, last_event_type); + return 0; } -void usage(void) +void +usage(void) { -#if 0 - fvwm_msg(INFO,"usage","\nFvwm Version %s Usage:\n\n",VERSION); - fvwm_msg(INFO,"usage"," %s [-d dpy] [-debug] [-f config_cmd] [-s] [-blackout] [-version] [-h]\n",g_argv[0]); -#else - fprintf(stderr,"\nFvwm Version %s Usage:\n\n",VERSION); - fprintf(stderr," %s [-d dpy] [-debug] [-f config_cmd] [-s] [-blackout] [-version] [-h]\n\n",g_argv[0]); -#endif + fprintf(stderr, "\nFvwm Version %s Usage:\n\n", VERSION); + fprintf(stderr, + " %s [-d dpy] [-debug] [-f config_cmd] [-s] [-blackout] " + "[-version] [-h]\n\n", + g_argv[0]); } /**************************************************************************** @@ -1589,80 +1528,76 @@ void usage(void) * Save Desktop State * ****************************************************************************/ -void SaveDesktopState() +void +SaveDesktopState() { - FvwmWindow *t; - unsigned long data[1]; + FvwmWindow *t; + unsigned long data[1]; - for (t = Scr.FvwmRoot.next; t != NULL; t = t->next) - { - data[0] = (unsigned long) t->Desk; - XChangeProperty (dpy, t->w, _XA_WM_DESKTOP, _XA_WM_DESKTOP, 32, - PropModeReplace, (unsigned char *) data, 1); - } + for (t = Scr.FvwmRoot.next; t != NULL; t = t->next) { + data[0] = (unsigned long)t->Desk; + XChangeProperty(dpy, t->w, _XA_WM_DESKTOP, _XA_WM_DESKTOP, 32, + PropModeReplace, (unsigned char *)data, 1); + } - data[0] = (unsigned long) Scr.CurrentDesk; - XChangeProperty (dpy, Scr.Root, _XA_WM_DESKTOP, _XA_WM_DESKTOP, 32, - PropModeReplace, (unsigned char *) data, 1); + data[0] = (unsigned long)Scr.CurrentDesk; + XChangeProperty(dpy, Scr.Root, _XA_WM_DESKTOP, _XA_WM_DESKTOP, 32, + PropModeReplace, (unsigned char *)data, 1); - XSync(dpy, 0); + XSync(dpy, 0); } - -void SetMWM_INFO(Window window) +void +SetMWM_INFO(Window window) { #ifdef MODALITY_IS_EVIL - struct mwminfo - { - long flags; - Window win; - } motif_wm_info; - - /* Set Motif WM_INFO atom to make motif relinquish - * broken handling of modal dialogs */ - motif_wm_info.flags = 2; - motif_wm_info.win = window; - - XChangeProperty(dpy,Scr.Root,_XA_MOTIF_WM,_XA_MOTIF_WM,32, - PropModeReplace,(char *)&motif_wm_info,2); + struct mwminfo { + long flags; + Window win; + } motif_wm_info; + + /* Set Motif WM_INFO atom to make motif relinquish + * broken handling of modal dialogs */ + motif_wm_info.flags = 2; + motif_wm_info.win = window; + + XChangeProperty(dpy, Scr.Root, _XA_MOTIF_WM, _XA_MOTIF_WM, 32, + PropModeReplace, (char *)&motif_wm_info, 2); #endif } -void BlackoutScreen() +void +BlackoutScreen() { - XSetWindowAttributes attributes; - unsigned long valuemask; - - if (Blackout && (BlackoutWin == None) && !debugging) - { - DBUG("BlackoutScreen","Blacking out screen during init..."); - /* blackout screen */ - attributes.border_pixel = BlackPixel(dpy,Scr.screen); - attributes.background_pixel = BlackPixel(dpy,Scr.screen); - attributes.bit_gravity = NorthWestGravity; - attributes.override_redirect = True; /* is override redirect needed? */ - valuemask = CWBorderPixel | - CWBackPixel | - CWBitGravity | - CWOverrideRedirect; - BlackoutWin = XCreateWindow(dpy,Scr.Root,0,0, - DisplayWidth(dpy, Scr.screen), - DisplayHeight(dpy, Scr.screen),0, - CopyFromParent, - CopyFromParent, CopyFromParent, - valuemask,&attributes); - XMapWindow(dpy,BlackoutWin); - XSync(dpy,0); - } + XSetWindowAttributes attributes; + unsigned long valuemask; + + if (Blackout && (BlackoutWin == None) && !debugging) { + DBUG("BlackoutScreen", "Blacking out screen during init..."); + /* blackout screen */ + attributes.border_pixel = BlackPixel(dpy, Scr.screen); + attributes.background_pixel = BlackPixel(dpy, Scr.screen); + attributes.bit_gravity = NorthWestGravity; + attributes.override_redirect = + True; /* is override redirect needed? */ + valuemask = CWBorderPixel | CWBackPixel | CWBitGravity | + CWOverrideRedirect; + BlackoutWin = XCreateWindow(dpy, Scr.Root, 0, 0, + DisplayWidth(dpy, Scr.screen), + DisplayHeight(dpy, Scr.screen), 0, CopyFromParent, + CopyFromParent, CopyFromParent, valuemask, &attributes); + XMapWindow(dpy, BlackoutWin); + XSync(dpy, 0); + } } /* BlackoutScreen */ -void UnBlackoutScreen() +void +UnBlackoutScreen() { - if (Blackout && (BlackoutWin != None) && !debugging) - { - DBUG("UnBlackoutScreen","UnBlacking out screen"); - XDestroyWindow(dpy,BlackoutWin); /* unblacken the screen */ - XSync(dpy,0); - BlackoutWin = None; - } + if (Blackout && (BlackoutWin != None) && !debugging) { + DBUG("UnBlackoutScreen", "UnBlacking out screen"); + XDestroyWindow(dpy, BlackoutWin); /* unblacken the screen */ + XSync(dpy, 0); + BlackoutWin = None; + } } /* UnBlackoutScreen */ Index: fvwm/fvwm/fvwm.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/fvwm.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/fvwm.h --- fvwm/fvwm/fvwm.h +++ fvwm/fvwm/fvwm.h @@ -29,7 +29,6 @@ /** OR PERFORMANCE OF THIS SOFTWARE. **/ /*****************************************************************************/ - /*********************************************************************** * fvwm include file ***********************************************************************/ @@ -52,55 +51,54 @@ #include -#define BW 1 /* border width */ -#define BOUNDARY_WIDTH 7 /* border width */ -#define CORNER_WIDTH 16 /* border width */ +#define BW 1 /* border width */ +#define BOUNDARY_WIDTH 7 /* border width */ +#define CORNER_WIDTH 16 /* border width */ -# define HEIGHT_EXTRA 4 /* Extra height for texts in popus */ -# define HEIGHT_EXTRA_TITLE 4 /* Extra height for underlining title */ -# define HEIGHT_SEPARATOR 4 /* Height of separator lines */ +#define HEIGHT_EXTRA 4 /* Extra height for texts in popus */ +#define HEIGHT_EXTRA_TITLE 4 /* Extra height for underlining title */ +#define HEIGHT_SEPARATOR 4 /* Height of separator lines */ #ifndef TRUE -#define TRUE 1 -#define FALSE 0 +#define TRUE 1 +#define FALSE 0 #endif -#define NULLSTR ((char *) NULL) +#define NULLSTR ((char *)NULL) /* contexts for button presses */ -#define C_NO_CONTEXT 0x00 -#define C_WINDOW 0x01 -#define C_TITLE 0x02 -#define C_ICON 0x04 -#define C_ROOT 0x08 -#define C_FRAME 0x10 -#define C_SIDEBAR 0x20 -#define C_L1 0x40 -#define C_L2 0x80 -#define C_L3 0x100 -#define C_L4 0x200 -#define C_L5 0x400 -#define C_R1 0x800 -#define C_R2 0x1000 -#define C_R3 0x2000 -#define C_R4 0x4000 -#define C_R5 0x8000 -#define C_RALL (C_R1|C_R2|C_R3|C_R4|C_R5) -#define C_LALL (C_L1|C_L2|C_L3|C_L4|C_L5) -#define C_ALL (C_WINDOW|C_TITLE|C_ICON|C_ROOT|C_FRAME|C_SIDEBAR|\ - C_L1|C_L2|C_L3|C_L4|C_L5|C_R1|C_R2|C_R3|C_R4|C_R5) - -typedef struct MyFont -{ - XFontStruct *font; /* font structure */ - int height; /* height of the font */ - int y; /* Y coordinate to draw characters */ +#define C_NO_CONTEXT 0x00 +#define C_WINDOW 0x01 +#define C_TITLE 0x02 +#define C_ICON 0x04 +#define C_ROOT 0x08 +#define C_FRAME 0x10 +#define C_SIDEBAR 0x20 +#define C_L1 0x40 +#define C_L2 0x80 +#define C_L3 0x100 +#define C_L4 0x200 +#define C_L5 0x400 +#define C_R1 0x800 +#define C_R2 0x1000 +#define C_R3 0x2000 +#define C_R4 0x4000 +#define C_R5 0x8000 +#define C_RALL (C_R1 | C_R2 | C_R3 | C_R4 | C_R5) +#define C_LALL (C_L1 | C_L2 | C_L3 | C_L4 | C_L5) +#define C_ALL \ + (C_WINDOW | C_TITLE | C_ICON | C_ROOT | C_FRAME | C_SIDEBAR | C_L1 |\ + C_L2 | C_L3 | C_L4 | C_L5 | C_R1 | C_R2 | C_R3 | C_R4 | C_R5) + +typedef struct MyFont { + XFontStruct *font; /* font structure */ + int height; /* height of the font */ + int y; /* Y coordinate to draw characters */ } MyFont; -typedef struct ColorPair -{ - Pixel fore; - Pixel back; +typedef struct ColorPair { + Pixel fore; + Pixel back; } ColorPair; #ifdef MINI_ICONS @@ -108,7 +106,7 @@ typedef struct ColorPair #endif #ifdef USEDECOR -struct FvwmDecor; /* definition in screen.h */ +struct FvwmDecor; /* definition in screen.h */ #endif /* @@ -116,174 +114,174 @@ struct FvwmDecor; /* definition in screen.h */ The name list points at the first one in the chain. */ typedef struct icon_boxes_struct { - struct icon_boxes_struct *next; /* next icon_boxes or zero */ - int IconBox[4]; /* x/y x/y for iconbox */ - short IconGrid[2]; /* x incr, y incr */ - unsigned char IconFlags; /* some bits */ - /* IconFill only takes 3 bits. Defaults are top, left, vert co-ord first */ - /* eg: t l = 0,0,0; l t = 0,0,1; b r = 1,1,0 */ -#define ICONFILLBOT (1<<0) -#define ICONFILLRGT (1<<1) -#define ICONFILLHRZ (1<<2) + struct icon_boxes_struct *next; /* next icon_boxes or zero */ + int IconBox[4]; /* x/y x/y for iconbox */ + short IconGrid[2]; /* x incr, y incr */ + unsigned char IconFlags; /* some bits */ + /* IconFill only takes 3 bits. Defaults are top, left, vert co-ord + * first */ + /* eg: t l = 0,0,0; l t = 0,0,1; b r = 1,1,0 */ +#define ICONFILLBOT (1 << 0) +#define ICONFILLRGT (1 << 1) +#define ICONFILLHRZ (1 << 2) } icon_boxes; /* for each window that is on the display, one of these structures * is allocated and linked into a list */ -typedef struct FvwmWindow -{ - struct FvwmWindow *next; /* next fvwm window */ - struct FvwmWindow *prev; /* prev fvwm window */ - struct FvwmWindow *stack_next; /* next (lower) fvwm window in stacking - * order*/ - struct FvwmWindow *stack_prev; /* prev (higher) fvwm window in stacking - * order */ - Window w; /* the child window */ - int old_bw; /* border width before reparenting */ - Window frame; /* the frame window */ - Window Parent; /* Ugly Ugly Ugly - it looks like you - * HAVE to reparent the app window into - * a window whose size = app window, - * or else you can't keep xv and matlab - * happy at the same time! */ - Window title_w; /* the title bar window */ - Window sides[4]; - Window corners[4]; /* Corner pieces */ - int nr_left_buttons; - int nr_right_buttons; - Window left_w[5]; - Window right_w[5]; +typedef struct FvwmWindow { + struct FvwmWindow *next; /* next fvwm window */ + struct FvwmWindow *prev; /* prev fvwm window */ + struct FvwmWindow *stack_next; /* next (lower) fvwm window in stacking + * order*/ + struct FvwmWindow *stack_prev; /* prev (higher) fvwm window in stacking + * order */ + Window w; /* the child window */ + int old_bw; /* border width before reparenting */ + Window frame; /* the frame window */ + Window Parent; /* Ugly Ugly Ugly - it looks like you + * HAVE to reparent the app window into + * a window whose size = app window, + * or else you can't keep xv and matlab + * happy at the same time! */ + Window title_w; /* the title bar window */ + Window sides[4]; + Window corners[4]; /* Corner pieces */ + int nr_left_buttons; + int nr_right_buttons; + Window left_w[5]; + Window right_w[5]; #ifdef USEDECOR - struct FvwmDecor *fl; + struct FvwmDecor *fl; #endif - Window icon_w; /* the icon window */ - Window icon_pixmap_w; /* the icon window */ + Window icon_w; /* the icon window */ + Window icon_pixmap_w; /* the icon window */ #ifdef SHAPE - int wShaped; /* is this a shaped window */ + int wShaped; /* is this a shaped window */ #endif - int frame_x; /* x position of frame */ - int frame_y; /* y position of frame */ - int frame_width; /* width of frame */ - int frame_height; /* height of frame */ - int boundary_width; - int corner_width; - int bw; - int title_x; - int title_y; - int title_height; /* height of the title bar */ - int title_width; /* width of the title bar */ - int icon_x_loc; /* icon window x coordinate */ - int icon_xl_loc; /* icon label window x coordinate */ - int icon_y_loc; /* icon window y coordiante */ - int icon_w_width; /* width of the icon window */ - int icon_w_height; /* height of the icon window */ - int icon_t_width; /* width of the icon title window */ - int icon_p_width; /* width of the icon pixmap window */ - int icon_p_height; /* height of the icon pixmap window */ - Pixmap iconPixmap; /* pixmap for the icon */ - int iconDepth; /* Drawable depth for the icon */ - Pixmap icon_maskPixmap; /* pixmap for the icon mask */ - char *name; /* name of the window */ - char *icon_name; /* name of the icon */ - XWindowAttributes attr; /* the child window attributes */ - XSizeHints hints; /* normal hints */ - XWMHints *wmhints; /* WM hints */ - XClassHint class; - int Desk; /* Tells which desktop this window is on */ - int FocusDesk; /* Where (if at all) was it focussed */ - int DeIconifyDesk; /* Desk to deiconify to, for StubbornIcons */ - Window transientfor; + int frame_x; /* x position of frame */ + int frame_y; /* y position of frame */ + int frame_width; /* width of frame */ + int frame_height; /* height of frame */ + int boundary_width; + int corner_width; + int bw; + int title_x; + int title_y; + int title_height; /* height of the title bar */ + int title_width; /* width of the title bar */ + int icon_x_loc; /* icon window x coordinate */ + int icon_xl_loc; /* icon label window x coordinate */ + int icon_y_loc; /* icon window y coordiante */ + int icon_w_width; /* width of the icon window */ + int icon_w_height; /* height of the icon window */ + int icon_t_width; /* width of the icon title window */ + int icon_p_width; /* width of the icon pixmap window */ + int icon_p_height; /* height of the icon pixmap window */ + Pixmap iconPixmap; /* pixmap for the icon */ + int iconDepth; /* Drawable depth for the icon */ + Pixmap icon_maskPixmap; /* pixmap for the icon mask */ + char *name; /* name of the window */ + char *icon_name; /* name of the icon */ + XWindowAttributes attr; /* the child window attributes */ + XSizeHints hints; /* normal hints */ + XWMHints *wmhints; /* WM hints */ + XClassHint class; + int Desk; /* Tells which desktop this window is on */ + int FocusDesk; /* Where (if at all) was it focussed */ + int DeIconifyDesk; /* Desk to deiconify to, for StubbornIcons */ + Window transientfor; #ifdef GSFR - struct { - start_iconic : 1; - staysontop : 1; - sticky : 1; - listskip : 1; - suppressicon : 1; - noicon_title : 1; - lenience : 1; - sticky_icon : 1; - circulate_skip_icon : 1; - circulateskip : 1; - click_focus : 1; - sloppy_focus : 1; - show_mapping : 1; - - notitle : 1; - noborder : 1; - icon : 1; - startsondesk : 1; - bw : 1; - nobw : 1; - fore_color : 1; - back_color : 1; - random_place : 1; - smart_place : 1; - mwm_button : 1; - mwm_decor : 1; - mwm_functions : 1; - mwm_override : 1; - mwm_border : 1; - decorate_transient : 1; - no_pposition : 1; - ol_decor : 1; + struct { + start_iconic :1; + staysontop :1; + sticky :1; + listskip :1; + suppressicon :1; + noicon_title :1; + lenience :1; + sticky_icon :1; + circulate_skip_icon :1; + circulateskip :1; + click_focus :1; + sloppy_focus :1; + show_mapping :1; + + notitle :1; + noborder :1; + icon :1; + startsondesk :1; + bw :1; + nobw :1; + fore_color :1; + back_color :1; + random_place :1; + smart_place :1; + mwm_button :1; + mwm_decor :1; + mwm_functions :1; + mwm_override :1; + mwm_border :1; + decorate_transient :1; + no_pposition :1; + ol_decor :1; #ifdef MINI_ICONS - miniicon : 1; + miniicon :1; #endif - } new_flags; + } new_flags; #else - unsigned long flags; -/* - RBW - 11/13/1998 - new flags to supplement the flags word, implemented - as named bit fields. -*/ - struct { - unsigned ViewportMoved : 1; /* To prevent double move in MoveViewport. */ - unsigned IconifiedByParent : 1; /* To prevent iconified transients in a - * parent icon from counting for Next */ - } tmpflags; + unsigned long flags; + /* + RBW - 11/13/1998 - new flags to supplement the flags word, implemented + as named bit fields. + */ + struct { + unsigned ViewportMoved:1; /* To prevent double move in MoveViewport. */ + unsigned IconifiedByParent:1; /* To prevent iconified transients in a + * parent icon from counting for Next */ + } tmpflags; #endif /* GSFR */ #ifdef MINI_ICONS - char *mini_pixmap_file; - FvwmPicture *mini_icon; + char *mini_pixmap_file; + FvwmPicture *mini_icon; #endif - char *icon_bitmap_file; - - int orig_x; /* unmaximized x coordinate */ - int orig_y; /* unmaximized y coordinate */ - int orig_wd; /* unmaximized window width */ - int orig_ht; /* unmaximized window height */ - - int xdiff,ydiff; /* used to restore window position on exit*/ - int *mwm_hints; - int ol_hints; - int functions; - Window *cmap_windows; /* Colormap windows property */ - int number_cmap_windows; /* Should generally be 0 */ - Pixel ReliefPixel; - Pixel ShadowPixel; - Pixel TextPixel; - Pixel BackPixel; - unsigned long buttons; - icon_boxes *IconBoxes; /* zero or more iconboxes */ + char *icon_bitmap_file; + + int orig_x; /* unmaximized x coordinate */ + int orig_y; /* unmaximized y coordinate */ + int orig_wd; /* unmaximized window width */ + int orig_ht; /* unmaximized window height */ + + int xdiff, ydiff; /* used to restore window position on exit*/ + int *mwm_hints; + int ol_hints; + int functions; + Window *cmap_windows; /* Colormap windows property */ + int number_cmap_windows; /* Should generally be 0 */ + Pixel ReliefPixel; + Pixel ShadowPixel; + Pixel TextPixel; + Pixel BackPixel; + unsigned long buttons; + icon_boxes *IconBoxes; /* zero or more iconboxes */ } FvwmWindow; /* Window mask for Circulate and Direction functions */ typedef struct WindowConditionMask { - Bool needsCurrentDesk; - Bool needsCurrentPage; - Bool needsName; - Bool needsNotName; - Bool useCirculateHit; - Bool useCirculateHitIcon; - Bool useCirculateSkip; - Bool useCirculateSkipIcon; - unsigned long onFlags; - unsigned long offFlags; - char *name; + Bool needsCurrentDesk; + Bool needsCurrentPage; + Bool needsName; + Bool needsNotName; + Bool useCirculateHit; + Bool useCirculateHitIcon; + Bool useCirculateSkip; + Bool useCirculateSkipIcon; + unsigned long onFlags; + unsigned long offFlags; + char *name; } WindowConditionMask; /*************************************************************************** @@ -291,71 +289,70 @@ typedef struct WindowConditionMask { ***************************************************************************/ /* The first 13 items are mapped directly from the style structure's * flag value, so they MUST correspond to the first 13 entries in misc.h */ -#define STARTICONIC (1<<0) -#define ONTOP (1<<1) /* does window stay on top */ -#define STICKY (1<<2) /* Does window stick to glass? */ -#define WINDOWLISTSKIP (1<<3) -#define SUPPRESSICON (1<<4) -#define NOICON_TITLE (1<<5) -#define Lenience (1<<6) -#define StickyIcon (1<<7) -#define CirculateSkipIcon (1<<8) -#define CirculateSkip (1<<9) -#define ClickToFocus (1<<10) -#define SloppyFocus (1<<11) -#define SHOW_ON_MAP (1<<12) /* switch to desk when it gets mapped? */ -#define ALL_COMMON_FLAGS (STARTICONIC|ONTOP|STICKY|WINDOWLISTSKIP| \ - SUPPRESSICON|NOICON_TITLE|Lenience|StickyIcon| \ - CirculateSkipIcon|CirculateSkip|ClickToFocus| \ - SloppyFocus|SHOW_ON_MAP) - -#define BORDER (1<<13) /* Is this decorated with border*/ -#define TITLE (1<<14) /* Is this decorated with title */ -#define MAPPED (1<<15) /* is it mapped? */ -#define ICONIFIED (1<<16) /* is it an icon now? */ -#define TRANSIENT (1<<17) /* is it a transient window? */ -#define RAISED (1<<18) /* if its a sticky window, needs raising? */ -#define VISIBLE (1<<19) /* is the window fully visible */ -#define ICON_OURS (1<<20) /* is the icon window supplied by the app? */ -#define PIXMAP_OURS (1<<21)/* is the icon pixmap ours to free? */ -#define SHAPED_ICON (1<<22)/* is the icon shaped? */ -#define MAXIMIZED (1<<23)/* is the window maximized? */ -#define DoesWmTakeFocus (1<<24) -#define DoesWmDeleteWindow (1<<25) +#define STARTICONIC (1 << 0) +#define ONTOP (1 << 1) /* does window stay on top */ +#define STICKY (1 << 2) /* Does window stick to glass? */ +#define WINDOWLISTSKIP (1 << 3) +#define SUPPRESSICON (1 << 4) +#define NOICON_TITLE (1 << 5) +#define Lenience (1 << 6) +#define StickyIcon (1 << 7) +#define CirculateSkipIcon (1 << 8) +#define CirculateSkip (1 << 9) +#define ClickToFocus (1 << 10) +#define SloppyFocus (1 << 11) +#define SHOW_ON_MAP (1 << 12) /* switch to desk when it gets mapped? */ +#define ALL_COMMON_FLAGS \ + (STARTICONIC | ONTOP | STICKY | WINDOWLISTSKIP | SUPPRESSICON | \ + NOICON_TITLE | Lenience | StickyIcon | CirculateSkipIcon | \ + CirculateSkip | ClickToFocus | SloppyFocus | SHOW_ON_MAP) + +#define BORDER (1 << 13) /* Is this decorated with border*/ +#define TITLE (1 << 14) /* Is this decorated with title */ +#define MAPPED (1 << 15) /* is it mapped? */ +#define ICONIFIED (1 << 16) /* is it an icon now? */ +#define TRANSIENT (1 << 17) /* is it a transient window? */ +#define RAISED (1 << 18) /* if its a sticky window, needs raising? */ +#define VISIBLE (1 << 19) /* is the window fully visible */ +#define ICON_OURS (1 << 20) /* is the icon window supplied by the app? */ +#define PIXMAP_OURS (1 << 21) /* is the icon pixmap ours to free? */ +#define SHAPED_ICON (1 << 22) /* is the icon shaped? */ +#define MAXIMIZED (1 << 23) /* is the window maximized? */ +#define DoesWmTakeFocus (1 << 24) +#define DoesWmDeleteWindow (1 << 25) /* has the icon been moved by the user? */ -#define ICON_MOVED (1<<26) +#define ICON_MOVED (1 << 26) /* was the icon unmapped, even though the window is still iconified * (Transients) */ -#define ICON_UNMAPPED (1<<27) +#define ICON_UNMAPPED (1 << 27) /* Sent an XMapWindow, but didn't receive a MapNotify yet.*/ -#define MAP_PENDING (1<<28) -#define HintOverride (1<<29) -#define MWMButtons (1<<30) -#define MWMBorders (1<<31) - +#define MAP_PENDING (1 << 28) +#define HintOverride (1 << 29) +#define MWMButtons (1 << 30) +#define MWMBorders (1 << 31) /* flags to suppress/enable title bar buttons */ -#define BUTTON1 1 -#define BUTTON2 2 -#define BUTTON3 4 -#define BUTTON4 8 -#define BUTTON5 16 -#define BUTTON6 32 -#define BUTTON7 64 -#define BUTTON8 128 -#define BUTTON9 256 -#define BUTTON10 512 +#define BUTTON1 1 +#define BUTTON2 2 +#define BUTTON3 4 +#define BUTTON4 8 +#define BUTTON5 16 +#define BUTTON6 32 +#define BUTTON7 64 +#define BUTTON8 128 +#define BUTTON9 256 +#define BUTTON10 512 #ifdef WINDOWSHADE /* we're sticking this at the end of the buttons window member since we don't want to use up any more flag bits */ -#define WSHADE (1<<31) +#define WSHADE (1 << 31) #endif #include extern void Reborder(void); -extern RETSIGTYPE SigDone(int nonsense); -extern RETSIGTYPE Restart(int nonsense); +extern void SigDone(int nonsense); +extern void Restart(int nonsense); extern void Done(int, char *) __attribute__((__noreturn__)); extern void BlackoutScreen(void); extern void UnBlackoutScreen(void); Index: fvwm/fvwm/fvwm_exec.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/fvwm_exec.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/fvwm_exec.c --- /dev/null +++ fvwm/fvwm/fvwm_exec.c @@ -0,0 +1,169 @@ +/* + * fvwm_exec.c -- privilege-separated execution helper for fvwm(1) + * + * Runs as a separate process that receives exec requests via imsg(3) + * from the main fvwm process, executes them, and reports results. + */ + +#include + +#include + +#include +#include +#include +#include +#include +#include + +#include "config.h" + +/* + * imsg_exec -- structured IPC message types for execution requests. + * + * Message flow: + * fvwm -> helper: IMSG_EXEC_RUN (path + argv + envp) + * helper -> fvwm: IMSG_EXEC_OK (pid of launched child) + * IMSG_EXEC_ERROR (errno + message) + * IMSG_EXEC_EXIT (pid + status, sent on child exit) + */ + +enum imsg_exec_type { + IMSG_EXEC_RUN = 0, + IMSG_EXEC_OK, + IMSG_EXEC_ERROR, + IMSG_EXEC_EXIT, +}; + +__dead static void +usage(void) +{ + extern char *__progname; + + fprintf(stderr, "usage: %s\n", __progname); + exit(1); +} + +static void +exec_child(int argc, char **argv, char **envp) +{ + if (pledge("stdio exec", NULL) == -1) + err(1, "pledge"); + + closefrom(3); + + if (envp) + execve(argv[0], argv, envp); + else + execv(argv[0], argv); + + err(1, "execv: %s", argv[0]); +} + +int +main(int argc, char **argv) +{ + struct imsgbuf ibuf; + struct imsg imsg; + ssize_t n; + int s; + + if (argc != 1) + usage(); + + if (getenv("FVWM_EXEC_FD") == NULL) + errx(1, "FVWM_EXEC_FD not set"); + + s = (int)strtonum(getenv("FVWM_EXEC_FD"), 0, INT_MAX, NULL); + + signal(SIGPIPE, SIG_IGN); + + imsg_init(&ibuf, s); + + if (pledge("stdio proc exec", NULL) == -1) + err(1, "pledge"); + + for (;;) { + if ((n = imsg_read(&ibuf)) == -1 && errno != EAGAIN) + err(1, "imsg_read"); + if (n == 0) + break; + + while ((n = imsg_get(&ibuf, &imsg)) != -1) { + if (n == 0) + break; + + switch (imsg.hdr.type) { + case IMSG_EXEC_RUN: { + pid_t pid; + char **child_argv; + char **child_envp; + int cargc, envc; + char *data = imsg.data; + + if (imsg.hdr.len < sizeof(int) * 2) { + warnx("short IMSG_EXEC_RUN"); + break; + } + memcpy(&cargc, data, sizeof(int)); + memcpy(&envc, data + sizeof(int), sizeof(int)); + data += sizeof(int) * 2; + + /* Reconstruct argv */ + child_argv = malloc( + (cargc + 1) * sizeof(char *)); + if (child_argv == NULL) + err(1, "malloc"); + for (int i = 0; i < cargc; i++) { + size_t len = strlen(data); + child_argv[i] = data; + data += len + 1; + } + child_argv[cargc] = NULL; + + /* Reconstruct envp */ + child_envp = malloc( + (envc + 1) * sizeof(char *)); + if (child_envp == NULL) + err(1, "malloc"); + for (int i = 0; i < envc; i++) { + size_t len = strlen(data); + child_envp[i] = data; + data += len + 1; + } + child_envp[envc] = NULL; + + pid = fork(); + if (pid == -1) { + warn("fork"); + imsg_compose(&ibuf, IMSG_EXEC_ERROR, + 0, 0, -1, &errno, sizeof(int)); + free(child_argv); + free(child_envp); + break; + } + if (pid == 0) + exec_child(cargc, child_argv, + child_envp); + + free(child_argv); + free(child_envp); + + imsg_compose(&ibuf, IMSG_EXEC_OK, + 0, 0, -1, &pid, sizeof(pid_t)); + imsg_flush(&ibuf); + break; + } + default: + warnx("unknown imsg type %d", + imsg.hdr.type); + break; + } + imsg_free(&imsg); + } + } + + imsg_clear(&ibuf); + close(s); + return 0; +} Index: fvwm/fvwm/fvwm_sandbox.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/fvwm_sandbox.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/fvwm_sandbox.h --- /dev/null +++ fvwm/fvwm/fvwm_sandbox.h @@ -0,0 +1,187 @@ +/* + * fvwm_sandbox.h -- common sandbox helper for fvwm processes. + * + * Provides pledge/unveil setup patterns used across the fvwm module set. + * Each module calls only the helpers it needs; there is no "one size fits + * all" policy. + * + * All pledge/unveil calls check return values and fail with diagnostics. + * + * IMPORTANT: Every policy declared here requires verification on a real + * OpenBSD system with ktrace(1) and a full X11 session. + */ + +#ifndef FVWM_SANDBOX_H +#define FVWM_SANDBOX_H + +#ifndef FVWMLIBDIR +#define FVWMLIBDIR "/usr/X11R6/lib/X11/fvwm" +#endif + +/* + * sandbox_x11_only -- process that only needs X11 + stdio + fvwm pipes. + * No filesystem access, no network, no process creation. + * Used by: FvwmAuto, FvwmBanner, FvwmBacker, FvwmIdent, FvwmIconBox, + * FvwmPager, FvwmScroll, FvwmTalk, FvwmWinList + */ +static inline void +sandbox_x11_only(const char *progname) +{ + if (pledge("stdio", NULL) == -1) + err(1, "%s: pledge stdio", progname); +} + +/* + * sandbox_x11_config -- X11 + read-only config file access. + * No write, no network, no process creation. + * Used by: FvwmButtons, FvwmIconMan (after config read), + * FvwmForm (after /dev/null open) + */ +static inline void +sandbox_x11_config(const char *progname) +{ + if (pledge("stdio rpath", NULL) == -1) + err(1, "%s: pledge stdio rpath", progname); +} + +/* + * sandbox_save_state -- X11 + write to home directory. + * No network, no process creation. + * Used by: FvwmSave, FvwmSaveDesk + * + * Unveil is set up BEFORE calling this to restrict to the exact file. + */ +static inline void +sandbox_save_state(const char *progname) +{ + if (pledge("stdio rpath wpath cpath", NULL) == -1) + err(1, "%s: pledge stdio rpath wpath cpath", progname); +} + +/* + * sandbox_cpp_preproc -- X11 + fork/exec cpp + tmp + dns. + * Used by: FvwmCpp + * + * Unveil is set up BEFORE calling this. + */ +static inline void +sandbox_cpp_preproc(const char *progname) +{ + if (pledge("stdio rpath wpath cpath proc exec dns getpw", + NULL) == -1) + err(1, "%s: pledge", progname); +} + +/* + * sandbox_m4_preproc -- X11 + popen m4 + tmp + dns. + * Used by: FvwmM4 + * + * Unveil is set up BEFORE calling this. + */ +static inline void +sandbox_m4_preproc(const char *progname) +{ + if (pledge("stdio rpath wpath cpath proc exec dns getpw", + NULL) == -1) + err(1, "%s: pledge", progname); +} + +/* + * sandbox_xpmroot -- X11-only utility, no filesystem writes. + */ +static inline void +sandbox_xpmroot(const char *progname) +{ + if (pledge("stdio", NULL) == -1) + err(1, "%s: pledge stdio", progname); +} + +/* + * sandbox_main_fvwm -- main window manager process. + * After startup: retains proc for module fork, exec for helper launch, + * rpath for config reads. + */ +static inline void +sandbox_main_fvwm(const char *progname) +{ + if (unveil(FVWMLIBDIR, "rx") == -1) + err(1, "%s: unveil %s", progname, FVWMLIBDIR); + if (unveil("/etc/X11/fvwm", "r") == -1) + err(1, "%s: unveil /etc/X11/fvwm", progname); + if (unveil("/tmp", "rwc") == -1) + err(1, "%s: unveil /tmp", progname); + if (unveil(NULL, NULL) == -1) + err(1, "%s: unveil lock", progname); + + if (pledge("stdio rpath proc exec", NULL) == -1) + err(1, "%s: pledge", progname); +} + +/* + * sandbox_exec_helper -- fvwm_exec helper process. + * Receives imsg requests, forks children, and execs them. + */ +static inline void +sandbox_exec_helper(const char *progname) +{ + if (pledge("stdio proc exec", NULL) == -1) + err(1, "%s: pledge", progname); +} + +/* + * sandbox_exec_child -- child of the execution helper, about to exec. + */ +static inline void +sandbox_exec_child(const char *progname) +{ + if (pledge("stdio exec", NULL) == -1) + err(1, "%s: pledge", progname); +} + +/* + * unveil_tempdir -- unveil the temporary directory (from $TMPDIR or /tmp). + * For modules that create temp files (FvwmCpp, FvwmM4). + */ +static inline void +unveil_tempdir(const char *progname) +{ + const char *tmp; + + tmp = getenv("TMPDIR"); + if (tmp == NULL) + tmp = "/tmp"; + if (unveil(tmp, "rwc") == -1) + err(1, "%s: unveil %s", progname, tmp); +} + +/* + * unveil_home_read -- unveil $HOME for reading only. + */ +static inline void +unveil_home_read(const char *progname) +{ + const char *home; + + home = getenv("HOME"); + if (home == NULL) + home = "."; + if (unveil(home, "r") == -1) + err(1, "%s: unveil %s", progname, home); +} + +/* + * unveil_home_write -- unveil $HOME for read/write/create. + */ +static inline void +unveil_home_write(const char *progname) +{ + const char *home; + + home = getenv("HOME"); + if (home == NULL) + home = "."; + if (unveil(home, "rwc") == -1) + err(1, "%s: unveil %s", progname, home); +} + +#endif /* FVWM_SANDBOX_H */ Index: fvwm/fvwm/fvwmdebug.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/fvwmdebug.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/fvwmdebug.c --- fvwm/fvwm/fvwmdebug.c +++ fvwm/fvwm/fvwmdebug.c @@ -10,9 +10,10 @@ #ifndef _DEBUG_ #define _DEBUG_ +#include + #include "config.h" #include "fvwm.h" -#include /* Don't put this into the #ifdef, since some compilers don't like completely * empty source files. @@ -21,83 +22,148 @@ int DB_DUMMY_EXPORTED_SYMBOL; #ifdef DEBUG /* WI stands for 'window info' */ -void DB_WI_WINDOWS(char *label, FvwmWindow *fw) +void +DB_WI_WINDOWS(char *label, FvwmWindow *fw) { - fprintf(stderr, "%s: FvwmWindow=0x%x, next=0x%x, prev=0x%x, stack_next=0x%x, stack_prev=0x%x\n", label?label:"", fw, fw->next, fw->prev, fw->stack_next, fw->stack_prev); - return; + fprintf(stderr, + "%s: FvwmWindow=0x%x, next=0x%x, prev=0x%x, stack_next=0x%x, " + "stack_prev=0x%x\n", + label ? label : "", fw, fw->next, fw->prev, fw->stack_next, + fw->stack_prev); + return; } -void DB_WI_SUBWINS(char *label, FvwmWindow *fw) +void +DB_WI_SUBWINS(char *label, FvwmWindow *fw) { - fprintf(stderr, "%s: FvwmWindow=0x%x, frame=0x%x, w=0x%x, parent=0x%x, title_w=0x%x, icon_w=0x%x, icon_pixmap_w=0x%x\n", label?label:"", fw, fw->frame, fw->w, fw->Parent, fw->title_w, fw->icon_w, fw->icon_pixmap_w); - return; + fprintf(stderr, + "%s: FvwmWindow=0x%x, frame=0x%x, w=0x%x, parent=0x%x, " + "title_w=0x%x, icon_w=0x%x, icon_pixmap_w=0x%x\n", + label ? label : "", fw, fw->frame, fw->w, fw->Parent, fw->title_w, + fw->icon_w, fw->icon_pixmap_w); + return; } -void DB_WI_FRAMEWINS(char *label, FvwmWindow *fw) +void +DB_WI_FRAMEWINS(char *label, FvwmWindow *fw) { - fprintf(stderr, "%s: FvwmWindow=0x%x, side windows: 0x%x 0x%x 0x%x 0x%x, corner windows: 0x%x 0x%x 0x%x 0x%x\n", label?label:"", fw, fw->frame, fw->sides[0], fw->sides[1], fw->sides[2], fw->sides[3], fw->corners[0], fw->corners[1], fw->corners[2], fw->corners[3]); - return; + fprintf(stderr, + "%s: FvwmWindow=0x%x, side windows: 0x%x 0x%x 0x%x 0x%x, " + "corner windows: 0x%x 0x%x 0x%x 0x%x\n", + label ? label : "", fw, fw->frame, fw->sides[0], fw->sides[1], + fw->sides[2], fw->sides[3], fw->corners[0], fw->corners[1], + fw->corners[2], fw->corners[3]); + return; } -void DB_WI_BUTTONWINS(char *label, FvwmWindow *fw) +void +DB_WI_BUTTONWINS(char *label, FvwmWindow *fw) { - fprintf(stderr, "%s: FvwmWindow=0x%x, left button windows: 0x%x 0x%x 0x%x 0x%x 0x%x, right button windows: 0x%x 0x%x 0x%x 0x%x 0x%x\n", label?label:"", fw, fw->frame, fw->left_w[0], fw->left_w[1], fw->left_w[2], fw->left_w[3], fw->left_w[4], fw->right_w[0], fw->right_w[1], fw->right_w[2], fw->right_w[3], fw->right_w[4]); - return; + fprintf(stderr, + "%s: FvwmWindow=0x%x, left button windows: 0x%x 0x%x 0x%x " + "0x%x 0x%x, right button windows: 0x%x 0x%x 0x%x 0x%x 0x%x\n", + label ? label : "", fw, fw->frame, fw->left_w[0], fw->left_w[1], + fw->left_w[2], fw->left_w[3], fw->left_w[4], fw->right_w[0], + fw->right_w[1], fw->right_w[2], fw->right_w[3], fw->right_w[4]); + return; } -void DB_WI_FRAME(char *label, FvwmWindow *fw) +void +DB_WI_FRAME(char *label, FvwmWindow *fw) { - fprintf(stderr, "%s: FvwmWindow=0x%x, frame=0x%x, name=%s, flags=0x%08x, frame_x=%d, frame_y=%d, frame_width=%d, frame_height=%d, orig_x=%d, orig_y=%d, orig_wd=%d, orig_ht=%d\n", label?label:"", fw, fw->frame, fw->name?fw->name:"(NULL)",fw->flags,fw->frame_x, fw->frame_y, fw->frame_width, fw->frame_height, fw->orig_x, fw->orig_y, fw->orig_wd, fw->orig_ht); - return; + fprintf(stderr, + "%s: FvwmWindow=0x%x, frame=0x%x, name=%s, flags=0x%08x, " + "frame_x=%d, frame_y=%d, frame_width=%d, frame_height=%d, " + "orig_x=%d, orig_y=%d, orig_wd=%d, orig_ht=%d\n", + label ? label : "", fw, fw->frame, fw->name ? fw->name : "(NULL)", + fw->flags, fw->frame_x, fw->frame_y, fw->frame_width, + fw->frame_height, fw->orig_x, fw->orig_y, fw->orig_wd, fw->orig_ht); + return; } -void DB_WI_ICON(char *label, FvwmWindow *fw) +void +DB_WI_ICON(char *label, FvwmWindow *fw) { - fprintf(stderr, "%s: FvwmWindow=0x%x, icon_w=0x%x, icon_pixmap_w=0x%x, icon_x_loc=%d, icon_xl_loc=%d, icon_y_loc=%d, icon_w_width=%d, icon_w_height=%d, icon_t_width=%d, icon_p_width=%d, icon_p_height=%d, icon_name=%d\n", label?label:"", fw, fw->icon_w, fw->icon_pixmap_w,fw->icon_x_loc,fw->icon_xl_loc,fw->icon_y_loc,fw->icon_w_width,fw->icon_w_height,fw->icon_t_width,fw->icon_p_width,fw->icon_p_height,fw->icon_name); - return; + fprintf(stderr, + "%s: FvwmWindow=0x%x, icon_w=0x%x, icon_pixmap_w=0x%x, " + "icon_x_loc=%d, icon_xl_loc=%d, icon_y_loc=%d, " + "icon_w_width=%d, icon_w_height=%d, icon_t_width=%d, " + "icon_p_width=%d, icon_p_height=%d, icon_name=%d\n", + label ? label : "", fw, fw->icon_w, fw->icon_pixmap_w, + fw->icon_x_loc, fw->icon_xl_loc, fw->icon_y_loc, fw->icon_w_width, + fw->icon_w_height, fw->icon_t_width, fw->icon_p_width, + fw->icon_p_height, fw->icon_name); + return; } -void DB_WI_SIZEHINTS(char *label, FvwmWindow *fw) +void +DB_WI_SIZEHINTS(char *label, FvwmWindow *fw) { - fprintf(stderr, "%s: FvwmWindow=0x%x, base_width=%d, base_height=%d, width_inc=%d, height_inc=%d, min_width=%d, max_width=%d, min_height=%d, max_height=%d, win_gravity=0x%x", label?label:"", fw, fw->hints.flags, fw->hints.base_width, fw->hints.base_height, fw->hints.width_inc, fw->hints.height_inc, fw->hints.min_width, fw->hints.max_width, fw->hints.min_height, fw->hints.max_height, fw->hints.win_gravity); - if (fw->hints.flags & PAspect) fprintf(stderr,"max_aspect.x=%d, max_aspect.y=%d, min_aspect.x=%d, min_aspect.y=%d", fw->hints.max_aspect.x, fw->hints.max_aspect.y, fw->hints.min_aspect.x, fw->hints.min_aspect.y); - fprintf(stderr,"\n"); - return; + fprintf(stderr, + "%s: FvwmWindow=0x%x, base_width=%d, base_height=%d, " + "width_inc=%d, height_inc=%d, min_width=%d, max_width=%d, " + "min_height=%d, max_height=%d, win_gravity=0x%x", + label ? label : "", fw, fw->hints.flags, fw->hints.base_width, + fw->hints.base_height, fw->hints.width_inc, fw->hints.height_inc, + fw->hints.min_width, fw->hints.max_width, fw->hints.min_height, + fw->hints.max_height, fw->hints.win_gravity); + if (fw->hints.flags & PAspect) + fprintf(stderr, + "max_aspect.x=%d, max_aspect.y=%d, min_aspect.x=%d, " + "min_aspect.y=%d", + fw->hints.max_aspect.x, fw->hints.max_aspect.y, + fw->hints.min_aspect.x, fw->hints.min_aspect.y); + fprintf(stderr, "\n"); + return; } -void DB_WI_TITLE(char *label, FvwmWindow *fw) +void +DB_WI_TITLE(char *label, FvwmWindow *fw) { - fprintf(stderr, "%s: FvwmWindow=0x%x, name=%s, icon_name=%s, title_x=%d, title_y=%d, title_width=%d, title_height=%d\n", label?label:"", fw, fw->name?fw->name:"(NULL)", fw->icon_name?fw->icon_name:"(NULL)", fw->title_x, fw->title_y, fw->title_width, fw->title_height); - return; + fprintf(stderr, + "%s: FvwmWindow=0x%x, name=%s, icon_name=%s, title_x=%d, " + "title_y=%d, title_width=%d, title_height=%d\n", + label ? label : "", fw, fw->name ? fw->name : "(NULL)", + fw->icon_name ? fw->icon_name : "(NULL)", fw->title_x, fw->title_y, + fw->title_width, fw->title_height); + return; } -void DB_WI_BORDER(char *label, FvwmWindow *fw) +void +DB_WI_BORDER(char *label, FvwmWindow *fw) { - fprintf(stderr, "%s: FvwmWindow=0x%x, bw=%d, old_bw=%d, boundary_width=%d, corner_width=%d\n", label?label:"", fw, fw->bw, fw->old_bw, fw->boundary_width, fw->corner_width); - return; + fprintf(stderr, + "%s: FvwmWindow=0x%x, bw=%d, old_bw=%d, boundary_width=%d, " + "corner_width=%d\n", + label ? label : "", fw, fw->bw, fw->old_bw, fw->boundary_width, + fw->corner_width); + return; } -void DB_WI_XWINATTR(char *label, FvwmWindow *fw) +void +DB_WI_XWINATTR(char *label, FvwmWindow *fw) { - /* too much work for now */ - return; + /* too much work for now */ + return; } -void DB_WI_ALL(char *label, FvwmWindow *fw) +void +DB_WI_ALL(char *label, FvwmWindow *fw) { - fprintf(stderr,"%s: --- all fvwm window values for fw=0x%x ---\n", label,fw); - DB_WI_WINDOWS("",fw); - DB_WI_SUBWINS("",fw); - DB_WI_BUTTONWINS("",fw); - DB_WI_FRAMEWINS("",fw); - DB_WI_FRAME("",fw); - DB_WI_ICON("",fw); - DB_WI_SIZEHINTS("",fw); - DB_WI_TITLE("",fw); - DB_WI_BORDER("",fw); - DB_WI_XWINATTR("",fw); - fprintf(stderr,"%s: ---------- end ----------\n",label); - return; + fprintf(stderr, "%s: --- all fvwm window values for fw=0x%x ---\n", + label, fw); + DB_WI_WINDOWS("", fw); + DB_WI_SUBWINS("", fw); + DB_WI_BUTTONWINS("", fw); + DB_WI_FRAMEWINS("", fw); + DB_WI_FRAME("", fw); + DB_WI_ICON("", fw); + DB_WI_SIZEHINTS("", fw); + DB_WI_TITLE("", fw); + DB_WI_BORDER("", fw); + DB_WI_XWINATTR("", fw); + fprintf(stderr, "%s: ---------- end ----------\n", label); + return; } #endif Index: fvwm/fvwm/fvwmdebug.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/fvwmdebug.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/fvwmdebug.h --- fvwm/fvwm/fvwmdebug.h +++ fvwm/fvwm/fvwmdebug.h @@ -14,17 +14,17 @@ void DB_WI_BORDER(char *label, FvwmWindow *fw); void DB_WI_XWINATTR(char *label, FvwmWindow *fw); void DB_WI_ALL(char *label, FvwmWindow *fw); #else -#define DB_WI_WINDOWS(x,y) -#define DB_WI_SUBWINS(x,y) -#define DB_WI_FRAMEWINS(x,y) -#define DB_WI_BUTTONWINS(x,y) -#define DB_WI_FRAME(x,y) -#define DB_WI_ICON(x,y) -#define DB_WI_SIZEHINTS(x,y) -#define DB_WI_TITLE(x,y) -#define DB_WI_BORDER(x,y) -#define DB_WI_XWINATTR(x,y) -#define DB_WI_ALL(x,y) +#define DB_WI_WINDOWS(x, y) +#define DB_WI_SUBWINS(x, y) +#define DB_WI_FRAMEWINS(x, y) +#define DB_WI_BUTTONWINS(x, y) +#define DB_WI_FRAME(x, y) +#define DB_WI_ICON(x, y) +#define DB_WI_SIZEHINTS(x, y) +#define DB_WI_TITLE(x, y) +#define DB_WI_BORDER(x, y) +#define DB_WI_XWINATTR(x, y) +#define DB_WI_ALL(x, y) #endif #endif /* _DEBUG_ */ Index: fvwm/fvwm/icons.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/icons.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/icons.c --- fvwm/fvwm/icons.c +++ fvwm/fvwm/icons.c @@ -11,12 +11,12 @@ * ***********************************************************************/ -#include "config.h" - -#include -#include #include +#include #include +#include + +#include "config.h" #ifdef NeXT #include @@ -28,15 +28,14 @@ #endif /* XPM */ #include "fvwm.h" #include "misc.h" +#include "module.h" #include "parse.h" #include "screen.h" -#include "module.h" #ifdef SHAPE #include #endif /* SHAPE */ - void GrabIconButtons(FvwmWindow *, Window); void GrabIconKeys(FvwmWindow *, Window); @@ -45,148 +44,139 @@ void GrabIconKeys(FvwmWindow *, Window); * Creates an icon window as needed * ****************************************************************************/ -void CreateIconWindow(FvwmWindow *tmp_win, int def_x, int def_y) +void +CreateIconWindow(FvwmWindow *tmp_win, int def_x, int def_y) { - int final_x, final_y; - unsigned long valuemask; /* mask for create windows */ - XSetWindowAttributes attributes; /* attributes for create windows */ + int final_x, final_y; + unsigned long valuemask; /* mask for create windows */ + XSetWindowAttributes attributes; /* attributes for create windows */ - tmp_win->flags |= ICON_OURS; - tmp_win->flags &= ~PIXMAP_OURS; - tmp_win->flags &= ~SHAPED_ICON; - tmp_win->icon_pixmap_w = None; - tmp_win->iconPixmap = None; - tmp_win->iconDepth = 0; + tmp_win->flags |= ICON_OURS; + tmp_win->flags &= ~PIXMAP_OURS; + tmp_win->flags &= ~SHAPED_ICON; + tmp_win->icon_pixmap_w = None; + tmp_win->iconPixmap = None; + tmp_win->iconDepth = 0; - if(tmp_win->flags & SUPPRESSICON) - return; + if (tmp_win->flags & SUPPRESSICON) + return; - /* First, see if it was specified in the .fvwmrc */ - tmp_win->icon_p_height = 0; - tmp_win->icon_p_width = 0; + /* First, see if it was specified in the .fvwmrc */ + tmp_win->icon_p_height = 0; + tmp_win->icon_p_width = 0; - /* First, check for a monochrome bitmap */ - if(tmp_win->icon_bitmap_file != NULL) - GetBitmapFile(tmp_win); + /* First, check for a monochrome bitmap */ + if (tmp_win->icon_bitmap_file != NULL) + GetBitmapFile(tmp_win); #ifdef XPM - /* Next, check for a color pixmap */ - if((tmp_win->icon_bitmap_file != NULL)&& - (tmp_win->icon_p_height == 0)&&(tmp_win->icon_p_width == 0)) - GetXPMFile(tmp_win); + /* Next, check for a color pixmap */ + if ((tmp_win->icon_bitmap_file != NULL) && + (tmp_win->icon_p_height == 0) && (tmp_win->icon_p_width == 0)) + GetXPMFile(tmp_win); #endif /* XPM */ - /* Next, See if the app supplies its own icon window */ - if((tmp_win->icon_p_height == 0)&&(tmp_win->icon_p_width == 0)&& - (tmp_win->wmhints) && (tmp_win->wmhints->flags & IconWindowHint)) - GetIconWindow(tmp_win); - - /* Finally, try to get icon bitmap from the application */ - if((tmp_win->icon_p_height == 0)&&(tmp_win->icon_p_width == 0)&& - (tmp_win->wmhints)&&(tmp_win->wmhints->flags & IconPixmapHint)) - GetIconBitmap(tmp_win); - - /* figure out the icon window size */ - if (!(tmp_win->flags & NOICON_TITLE)||(tmp_win->icon_p_height == 0)) - { - tmp_win->icon_t_width = XTextWidth(Scr.IconFont.font, - tmp_win->icon_name, - strlen(tmp_win->icon_name)); - tmp_win->icon_w_height = ICON_HEIGHT; - } - else - { - tmp_win->icon_t_width = 0; - tmp_win->icon_w_height = 0; - } - if((tmp_win->flags & ICON_OURS)&&(tmp_win->icon_p_height >0)) - { - tmp_win->icon_p_width += 4; - tmp_win->icon_p_height +=4; - } - - if(tmp_win->icon_p_width == 0) - tmp_win->icon_p_width = tmp_win->icon_t_width+6; - tmp_win->icon_w_width = tmp_win->icon_p_width; - - final_x = def_x; - final_y = def_y; - if(final_x <0) - final_x = 0; - if(final_y <0) - final_y = 0; - - if(final_x + tmp_win->icon_w_width >=Scr.MyDisplayWidth) - final_x = Scr.MyDisplayWidth - tmp_win->icon_w_width-1; - if(final_y + tmp_win->icon_w_height >=Scr.MyDisplayHeight) - final_y = Scr.MyDisplayHeight - tmp_win->icon_w_height-1; - - tmp_win->icon_x_loc = final_x; - tmp_win->icon_xl_loc = final_x; - tmp_win->icon_y_loc = final_y; - - /* clip to fit on screen */ - attributes.background_pixel = Scr.StdColors.back; - valuemask = CWBorderPixel | CWCursor | CWEventMask | CWBackPixel; - attributes.border_pixel = Scr.StdColors.fore; - attributes.cursor = Scr.FvwmCursors[DEFAULT]; - attributes.event_mask = (ButtonPressMask | ButtonReleaseMask | - VisibilityChangeMask | - ExposureMask | KeyPressMask|EnterWindowMask | - FocusChangeMask ); - if (!(tmp_win->flags & NOICON_TITLE)||(tmp_win->icon_p_height == 0)) - tmp_win->icon_w = - XCreateWindow(dpy, Scr.Root, final_x, final_y+tmp_win->icon_p_height, - tmp_win->icon_w_width, tmp_win->icon_w_height,0, - CopyFromParent, - CopyFromParent,CopyFromParent,valuemask,&attributes); - - if((tmp_win->flags & ICON_OURS)&&(tmp_win->icon_p_width>0)&& - (tmp_win->icon_p_height>0)) - { - tmp_win->icon_pixmap_w = - XCreateWindow(dpy, Scr.Root, final_x, final_y, tmp_win->icon_p_width, - tmp_win->icon_p_height, 0, CopyFromParent, - CopyFromParent,CopyFromParent,valuemask,&attributes); - } - else - { - attributes.event_mask = (ButtonPressMask | ButtonReleaseMask | - VisibilityChangeMask | - KeyPressMask|EnterWindowMask | - FocusChangeMask | LeaveWindowMask ); - - valuemask = CWEventMask; - XChangeWindowAttributes(dpy,tmp_win->icon_pixmap_w, - valuemask,&attributes); - } + /* Next, See if the app supplies its own icon window */ + if ((tmp_win->icon_p_height == 0) && (tmp_win->icon_p_width == 0) && + (tmp_win->wmhints) && (tmp_win->wmhints->flags & IconWindowHint)) + GetIconWindow(tmp_win); + + /* Finally, try to get icon bitmap from the application */ + if ((tmp_win->icon_p_height == 0) && (tmp_win->icon_p_width == 0) && + (tmp_win->wmhints) && (tmp_win->wmhints->flags & IconPixmapHint)) + GetIconBitmap(tmp_win); + + /* figure out the icon window size */ + if (!(tmp_win->flags & NOICON_TITLE) || (tmp_win->icon_p_height == 0)) { + tmp_win->icon_t_width = XTextWidth(Scr.IconFont.font, + tmp_win->icon_name, strlen(tmp_win->icon_name)); + tmp_win->icon_w_height = ICON_HEIGHT; + } else { + tmp_win->icon_t_width = 0; + tmp_win->icon_w_height = 0; + } + if ((tmp_win->flags & ICON_OURS) && (tmp_win->icon_p_height > 0)) { + tmp_win->icon_p_width += 4; + tmp_win->icon_p_height += 4; + } + if (tmp_win->icon_p_width == 0) + tmp_win->icon_p_width = tmp_win->icon_t_width + 6; + tmp_win->icon_w_width = tmp_win->icon_p_width; + + final_x = def_x; + final_y = def_y; + if (final_x < 0) + final_x = 0; + if (final_y < 0) + final_y = 0; + + if (final_x + tmp_win->icon_w_width >= Scr.MyDisplayWidth) + final_x = Scr.MyDisplayWidth - tmp_win->icon_w_width - 1; + if (final_y + tmp_win->icon_w_height >= Scr.MyDisplayHeight) + final_y = Scr.MyDisplayHeight - tmp_win->icon_w_height - 1; + + tmp_win->icon_x_loc = final_x; + tmp_win->icon_xl_loc = final_x; + tmp_win->icon_y_loc = final_y; + + /* clip to fit on screen */ + attributes.background_pixel = Scr.StdColors.back; + valuemask = CWBorderPixel | CWCursor | CWEventMask | CWBackPixel; + attributes.border_pixel = Scr.StdColors.fore; + attributes.cursor = Scr.FvwmCursors[DEFAULT]; + attributes.event_mask = + (ButtonPressMask | ButtonReleaseMask | VisibilityChangeMask | + ExposureMask | KeyPressMask | EnterWindowMask | + FocusChangeMask); + if (!(tmp_win->flags & NOICON_TITLE) || (tmp_win->icon_p_height == 0)) + tmp_win->icon_w = XCreateWindow(dpy, Scr.Root, final_x, + final_y + tmp_win->icon_p_height, tmp_win->icon_w_width, + tmp_win->icon_w_height, 0, CopyFromParent, CopyFromParent, + CopyFromParent, valuemask, &attributes); + + if ((tmp_win->flags & ICON_OURS) && (tmp_win->icon_p_width > 0) && + (tmp_win->icon_p_height > 0)) { + tmp_win->icon_pixmap_w = XCreateWindow(dpy, Scr.Root, final_x, + final_y, tmp_win->icon_p_width, tmp_win->icon_p_height, 0, + CopyFromParent, CopyFromParent, CopyFromParent, valuemask, + &attributes); + } else { + attributes.event_mask = + (ButtonPressMask | ButtonReleaseMask | + VisibilityChangeMask | KeyPressMask | EnterWindowMask | + FocusChangeMask | LeaveWindowMask); + + valuemask = CWEventMask; + XChangeWindowAttributes( + dpy, tmp_win->icon_pixmap_w, valuemask, &attributes); + } #ifdef XPM #ifdef SHAPE - if (ShapesSupported && (tmp_win->flags & SHAPED_ICON)) - { - XShapeCombineMask(dpy, tmp_win->icon_pixmap_w, ShapeBounding,2, 2, - tmp_win->icon_maskPixmap, ShapeSet); - } + if (ShapesSupported && (tmp_win->flags & SHAPED_ICON)) { + XShapeCombineMask(dpy, tmp_win->icon_pixmap_w, ShapeBounding, 2, + 2, tmp_win->icon_maskPixmap, ShapeSet); + } #endif #endif - if(tmp_win->icon_w != None) - { - XSaveContext(dpy, tmp_win->icon_w, FvwmContext, (caddr_t)tmp_win); - XDefineCursor(dpy, tmp_win->icon_w, Scr.FvwmCursors[DEFAULT]); - GrabIconButtons(tmp_win,tmp_win->icon_w); - GrabIconKeys(tmp_win,tmp_win->icon_w); - } - if(tmp_win->icon_pixmap_w != None) - { - XSaveContext(dpy, tmp_win->icon_pixmap_w, FvwmContext, (caddr_t)tmp_win); - XDefineCursor(dpy, tmp_win->icon_pixmap_w, Scr.FvwmCursors[DEFAULT]); - GrabIconButtons(tmp_win,tmp_win->icon_pixmap_w); - GrabIconKeys(tmp_win,tmp_win->icon_pixmap_w); - } - return; + if (tmp_win->icon_w != None) { + XSaveContext( + dpy, tmp_win->icon_w, FvwmContext, (caddr_t)tmp_win); + XDefineCursor(dpy, tmp_win->icon_w, Scr.FvwmCursors[DEFAULT]); + GrabIconButtons(tmp_win, tmp_win->icon_w); + GrabIconKeys(tmp_win, tmp_win->icon_w); + } + if (tmp_win->icon_pixmap_w != None) { + XSaveContext( + dpy, tmp_win->icon_pixmap_w, FvwmContext, (caddr_t)tmp_win); + XDefineCursor( + dpy, tmp_win->icon_pixmap_w, Scr.FvwmCursors[DEFAULT]); + GrabIconButtons(tmp_win, tmp_win->icon_pixmap_w); + GrabIconKeys(tmp_win, tmp_win->icon_pixmap_w); + } + return; } /**************************************************************************** @@ -194,136 +184,133 @@ void CreateIconWindow(FvwmWindow *tmp_win, int def_x, int def_y) * Draws the icon window * ****************************************************************************/ -void DrawIconWindow(FvwmWindow *Tmp_win) +void +DrawIconWindow(FvwmWindow *Tmp_win) { - GC Shadow, Relief; - Pixel TextColor,BackColor; - int x ; - - if(Tmp_win->flags & SUPPRESSICON) - return; - - if(Tmp_win->icon_w != None) - flush_expose (Tmp_win->icon_w); - if(Tmp_win->icon_pixmap_w != None) - flush_expose (Tmp_win->icon_pixmap_w); - - if(Scr.Hilite == Tmp_win) - { - if(Scr.d_depth < 2) { - Relief = - Shadow = Scr.DefaultDecor.HiShadowGC; - TextColor = Scr.DefaultDecor.HiColors.fore; - BackColor = Scr.DefaultDecor.HiColors.back; - } else { - Relief = GetDecor(Tmp_win,HiReliefGC); - Shadow = GetDecor(Tmp_win,HiShadowGC); - TextColor = GetDecor(Tmp_win,HiColors.fore); - BackColor = GetDecor(Tmp_win,HiColors.back); - } - /* resize the icon name window */ - if(Tmp_win->icon_w != None) - { - Tmp_win->icon_w_width = Tmp_win->icon_t_width+6; - if(Tmp_win->icon_w_width < Tmp_win->icon_p_width) - Tmp_win->icon_w_width = Tmp_win->icon_p_width; - Tmp_win->icon_xl_loc = Tmp_win->icon_x_loc - - (Tmp_win->icon_w_width - Tmp_win->icon_p_width)/2; - /* start keep label on screen. dje 8/7/97 */ - if (Tmp_win->icon_xl_loc < 0) { /* if new loc neg (off left edge) */ - Tmp_win->icon_xl_loc = 0; /* move to edge */ - } else { /* if not on left edge */ - /* if (new loc + width) > screen width (off edge on right) */ - if ((Tmp_win->icon_xl_loc + Tmp_win->icon_w_width) > - Scr.MyDisplayWidth) { /* off right */ - /* position up against right edge */ - Tmp_win->icon_xl_loc = Scr.MyDisplayWidth - Tmp_win->icon_w_width; - } - /* end keep label on screen. dje 8/7/97 */ - } - } - } - else - { - if(Scr.d_depth < 2) - { - Relief = Scr.StdReliefGC; - Shadow = Scr.StdShadowGC; + GC Shadow, Relief; + Pixel TextColor, BackColor; + int x; + + if (Tmp_win->flags & SUPPRESSICON) + return; + + if (Tmp_win->icon_w != None) + flush_expose(Tmp_win->icon_w); + if (Tmp_win->icon_pixmap_w != None) + flush_expose(Tmp_win->icon_pixmap_w); + + if (Scr.Hilite == Tmp_win) { + if (Scr.d_depth < 2) { + Relief = Shadow = Scr.DefaultDecor.HiShadowGC; + TextColor = Scr.DefaultDecor.HiColors.fore; + BackColor = Scr.DefaultDecor.HiColors.back; + } else { + Relief = GetDecor(Tmp_win, HiReliefGC); + Shadow = GetDecor(Tmp_win, HiShadowGC); + TextColor = GetDecor(Tmp_win, HiColors.fore); + BackColor = GetDecor(Tmp_win, HiColors.back); + } + /* resize the icon name window */ + if (Tmp_win->icon_w != None) { + Tmp_win->icon_w_width = Tmp_win->icon_t_width + 6; + if (Tmp_win->icon_w_width < Tmp_win->icon_p_width) + Tmp_win->icon_w_width = Tmp_win->icon_p_width; + Tmp_win->icon_xl_loc = + Tmp_win->icon_x_loc - + (Tmp_win->icon_w_width - Tmp_win->icon_p_width) / 2; + /* start keep label on screen. dje 8/7/97 */ + if (Tmp_win->icon_xl_loc < + 0) { /* if new loc neg (off left edge) */ + Tmp_win->icon_xl_loc = 0; /* move to edge */ + } else { /* if not on left edge */ + /* if (new loc + width) > screen width (off edge + * on right) */ + if ((Tmp_win->icon_xl_loc + + Tmp_win->icon_w_width) > + Scr.MyDisplayWidth) { /* off right */ + /* position up against right edge */ + Tmp_win->icon_xl_loc = + Scr.MyDisplayWidth - + Tmp_win->icon_w_width; + } + /* end keep label on screen. dje 8/7/97 */ + } + } + } else { + if (Scr.d_depth < 2) { + Relief = Scr.StdReliefGC; + Shadow = Scr.StdShadowGC; + } else { + Globalgcv.foreground = Tmp_win->ReliefPixel; + Globalgcm = GCForeground; + XChangeGC(dpy, Scr.ScratchGC1, Globalgcm, &Globalgcv); + Relief = Scr.ScratchGC1; + + Globalgcv.foreground = Tmp_win->ShadowPixel; + XChangeGC(dpy, Scr.ScratchGC2, Globalgcm, &Globalgcv); + Shadow = Scr.ScratchGC2; + } + /* resize the icon name window */ + if (Tmp_win->icon_w != None) { + Tmp_win->icon_w_width = Tmp_win->icon_p_width; + Tmp_win->icon_xl_loc = Tmp_win->icon_x_loc; + } + TextColor = Tmp_win->TextPixel; + BackColor = Tmp_win->BackPixel; } - else - { - Globalgcv.foreground = Tmp_win->ReliefPixel; - Globalgcm = GCForeground; - XChangeGC(dpy,Scr.ScratchGC1,Globalgcm,&Globalgcv); - Relief = Scr.ScratchGC1; - - Globalgcv.foreground = Tmp_win->ShadowPixel; - XChangeGC(dpy,Scr.ScratchGC2,Globalgcm,&Globalgcv); - Shadow = Scr.ScratchGC2; + if ((Tmp_win->flags & ICON_OURS) && (Tmp_win->icon_pixmap_w != None)) + XSetWindowBackground(dpy, Tmp_win->icon_pixmap_w, BackColor); + if (Tmp_win->icon_w != None) + XSetWindowBackground(dpy, Tmp_win->icon_w, BackColor); + + /* write the icon label */ + NewFontAndColor(Scr.IconFont.font->fid, TextColor, BackColor); + + if (Tmp_win->icon_pixmap_w != None) + XMoveWindow(dpy, Tmp_win->icon_pixmap_w, Tmp_win->icon_x_loc, + Tmp_win->icon_y_loc); + if (Tmp_win->icon_w != None) { + Tmp_win->icon_w_height = ICON_HEIGHT; + XMoveResizeWindow(dpy, Tmp_win->icon_w, Tmp_win->icon_xl_loc, + Tmp_win->icon_y_loc + Tmp_win->icon_p_height, + Tmp_win->icon_w_width, ICON_HEIGHT); + + XClearWindow(dpy, Tmp_win->icon_w); } - /* resize the icon name window */ - if(Tmp_win->icon_w != None) - { - Tmp_win->icon_w_width = Tmp_win->icon_p_width; - Tmp_win->icon_xl_loc = Tmp_win->icon_x_loc; - } - TextColor = Tmp_win->TextPixel; - BackColor = Tmp_win->BackPixel; - - } - if((Tmp_win->flags & ICON_OURS)&&(Tmp_win->icon_pixmap_w != None)) - XSetWindowBackground(dpy,Tmp_win->icon_pixmap_w, - BackColor); - if(Tmp_win->icon_w != None) - XSetWindowBackground(dpy,Tmp_win->icon_w,BackColor); - - /* write the icon label */ - NewFontAndColor(Scr.IconFont.font->fid,TextColor,BackColor); - - if(Tmp_win->icon_pixmap_w != None) - XMoveWindow(dpy,Tmp_win->icon_pixmap_w,Tmp_win->icon_x_loc, - Tmp_win->icon_y_loc); - if(Tmp_win->icon_w != None) - { - Tmp_win->icon_w_height = ICON_HEIGHT; - XMoveResizeWindow(dpy, Tmp_win->icon_w, Tmp_win->icon_xl_loc, - Tmp_win->icon_y_loc+Tmp_win->icon_p_height, - Tmp_win->icon_w_width,ICON_HEIGHT); - - XClearWindow(dpy,Tmp_win->icon_w); - } - - if((Tmp_win->iconPixmap != None)&&(!(Tmp_win->flags & SHAPED_ICON))) - RelieveWindow(Tmp_win,Tmp_win->icon_pixmap_w,0,0, - Tmp_win->icon_p_width, Tmp_win->icon_p_height, - Relief,Shadow, FULL_HILITE); - - /* need to locate the icon pixmap */ - if(Tmp_win->iconPixmap != None) - { - if(Tmp_win->iconDepth == Scr.d_depth) - { - XCopyArea(dpy,Tmp_win->iconPixmap,Tmp_win->icon_pixmap_w,Scr.ScratchGC3, - 0,0,Tmp_win->icon_p_width-4, Tmp_win->icon_p_height-4,2,2); + + if ((Tmp_win->iconPixmap != None) && (!(Tmp_win->flags & SHAPED_ICON))) + RelieveWindow(Tmp_win, Tmp_win->icon_pixmap_w, 0, 0, + Tmp_win->icon_p_width, Tmp_win->icon_p_height, Relief, + Shadow, FULL_HILITE); + + /* need to locate the icon pixmap */ + if (Tmp_win->iconPixmap != None) { + if (Tmp_win->iconDepth == Scr.d_depth) { + XCopyArea(dpy, Tmp_win->iconPixmap, + Tmp_win->icon_pixmap_w, Scr.ScratchGC3, 0, 0, + Tmp_win->icon_p_width - 4, + Tmp_win->icon_p_height - 4, 2, 2); + } else + XCopyPlane(dpy, Tmp_win->iconPixmap, + Tmp_win->icon_pixmap_w, Scr.ScratchGC3, 0, 0, + Tmp_win->icon_p_width - 4, + Tmp_win->icon_p_height - 4, 2, 2, 1); + } + + if (Tmp_win->icon_w != None) { + /* text position */ + x = (Tmp_win->icon_w_width - Tmp_win->icon_t_width) / 2; + if (x < 3) + x = 3; + + XDrawString(dpy, Tmp_win->icon_w, Scr.ScratchGC3, x, + Tmp_win->icon_w_height - Scr.IconFont.height + + Scr.IconFont.y - 3, + Tmp_win->icon_name, strlen(Tmp_win->icon_name)); + RelieveWindow(Tmp_win, Tmp_win->icon_w, 0, 0, + Tmp_win->icon_w_width, ICON_HEIGHT, Relief, Shadow, + FULL_HILITE); } - else - XCopyPlane(dpy,Tmp_win->iconPixmap,Tmp_win->icon_pixmap_w,Scr.ScratchGC3,0, - 0,Tmp_win->icon_p_width-4, Tmp_win->icon_p_height-4,2,2,1); - } - - if(Tmp_win->icon_w != None) - { - /* text position */ - x = (Tmp_win->icon_w_width - Tmp_win->icon_t_width)/2; - if(x<3)x=3; - - XDrawString (dpy, Tmp_win->icon_w, Scr.ScratchGC3, x, - Tmp_win->icon_w_height-Scr.IconFont.height+ - Scr.IconFont.y-3, - Tmp_win->icon_name, strlen(Tmp_win->icon_name)); - RelieveWindow(Tmp_win,Tmp_win->icon_w,0,0,Tmp_win->icon_w_width, - ICON_HEIGHT,Relief,Shadow, FULL_HILITE); - } } /*********************************************************************** @@ -332,252 +319,339 @@ void DrawIconWindow(FvwmWindow *Tmp_win) * RedoIconName - procedure to re-position the icon window and name * ************************************************************************/ -void RedoIconName(FvwmWindow *Tmp_win) +void +RedoIconName(FvwmWindow *Tmp_win) { - if(Tmp_win->flags & SUPPRESSICON) - return; + if (Tmp_win->flags & SUPPRESSICON) + return; - if (Tmp_win->icon_w == (int)NULL) - return; + if (Tmp_win->icon_w == None) + return; - Tmp_win->icon_t_width = XTextWidth(Scr.IconFont.font,Tmp_win->icon_name, - strlen(Tmp_win->icon_name)); - /* clear the icon window, and trigger a re-draw via an expose event */ - if (Tmp_win->flags & ICONIFIED) - XClearArea(dpy, Tmp_win->icon_w, 0, 0, 0, 0, True); - return; + Tmp_win->icon_t_width = XTextWidth( + Scr.IconFont.font, Tmp_win->icon_name, strlen(Tmp_win->icon_name)); + /* clear the icon window, and trigger a re-draw via an expose event */ + if (Tmp_win->flags & ICONIFIED) + XClearArea(dpy, Tmp_win->icon_w, 0, 0, 0, 0, True); + return; } - - - - /*********************************************************************** +/*********************************************************************** * * Procedure: * AutoPlace - Find a home for an icon * ************************************************************************/ -void AutoPlace(FvwmWindow *t) +void +AutoPlace(FvwmWindow *t) { - int tw,th,tx,ty; - int base_x, base_y; - int width,height; - FvwmWindow *test_window; - Bool loc_ok; - int real_x=10, real_y=10; - int new_x, new_y; - - /* New! Put icon in same page as the center of the window */ - /* Not a good idea for StickyIcons */ - if((t->flags & StickyIcon)||(t->flags & STICKY)) - { - base_x = 0; - base_y = 0; - /*Also, if its a stickyWindow, put it on the current page! */ - new_x = t->frame_x % Scr.MyDisplayWidth; - new_y = t->frame_y % Scr.MyDisplayHeight; - if(new_x < 0)new_x += Scr.MyDisplayWidth; - if(new_y < 0)new_y += Scr.MyDisplayHeight; - SetupFrame(t,new_x,new_y, - t->frame_width,t->frame_height,False); - t->Desk = Scr.CurrentDesk; - } - else - { - base_x=((t->frame_x+Scr.Vx+(t->frame_width>>1))/Scr.MyDisplayWidth)* - Scr.MyDisplayWidth - Scr.Vx; - base_y=((t->frame_y+Scr.Vy+(t->frame_height>>1))/Scr.MyDisplayHeight)* - Scr.MyDisplayHeight - Scr.Vy; - } - if(t->flags & ICON_MOVED) - { - /* just make sure the icon is on this screen */ - t->icon_x_loc = t->icon_x_loc % Scr.MyDisplayWidth + base_x; - t->icon_y_loc = t->icon_y_loc % Scr.MyDisplayHeight + base_y; - if(t->icon_x_loc < 0) - t->icon_x_loc += Scr.MyDisplayWidth; - if(t->icon_y_loc < 0) - t->icon_y_loc += Scr.MyDisplayHeight; - } - else if (t->wmhints && t->wmhints->flags & IconPositionHint) - { - t->icon_x_loc = t->wmhints->icon_x; - t->icon_y_loc = t->wmhints->icon_y; - } - /* dje 10/12/97: - Look thru chain of icon boxes assigned to window. - Add logic for grids and fill direction. - */ - else { - /* A place to hold inner and outer loop variables. */ - typedef struct dimension_struct { - int step; /* grid size (may be negative) */ - int start_at; /* starting edge */ - int real_start; /* on screen starting edge */ - int end_at; /* ending edge */ - int base; /* base for screen */ - int icon_dimension; /* height or width */ - int nom_dimension; /* nonminal height or width */ - int screen_dimension; /* screen height or width */ - } dimension; - dimension dim[3]; /* space for work, 1st, 2nd dimen */ - icon_boxes *icon_boxes_ptr; /* current icon box */ - int i; /* index for inner/outer loop data */ - - /* Hopefully this makes the following more readable. */ + int tw, th, tx, ty; + int base_x, base_y; + int width, height; + FvwmWindow *test_window; + Bool loc_ok; + int real_x = 10, real_y = 10; + int new_x, new_y; + + /* New! Put icon in same page as the center of the window */ + /* Not a good idea for StickyIcons */ + if ((t->flags & StickyIcon) || (t->flags & STICKY)) { + base_x = 0; + base_y = 0; + /*Also, if its a stickyWindow, put it on the current page! */ + new_x = t->frame_x % Scr.MyDisplayWidth; + new_y = t->frame_y % Scr.MyDisplayHeight; + if (new_x < 0) + new_x += Scr.MyDisplayWidth; + if (new_y < 0) + new_y += Scr.MyDisplayHeight; + SetupFrame( + t, new_x, new_y, t->frame_width, t->frame_height, False); + t->Desk = Scr.CurrentDesk; + } else { + base_x = ((t->frame_x + Scr.Vx + (t->frame_width >> 1)) / + Scr.MyDisplayWidth) * + Scr.MyDisplayWidth - + Scr.Vx; + base_y = ((t->frame_y + Scr.Vy + (t->frame_height >> 1)) / + Scr.MyDisplayHeight) * + Scr.MyDisplayHeight - + Scr.Vy; + } + if (t->flags & ICON_MOVED) { + /* just make sure the icon is on this screen */ + t->icon_x_loc = t->icon_x_loc % Scr.MyDisplayWidth + base_x; + t->icon_y_loc = t->icon_y_loc % Scr.MyDisplayHeight + base_y; + if (t->icon_x_loc < 0) + t->icon_x_loc += Scr.MyDisplayWidth; + if (t->icon_y_loc < 0) + t->icon_y_loc += Scr.MyDisplayHeight; + } else if (t->wmhints && t->wmhints->flags & IconPositionHint) { + t->icon_x_loc = t->wmhints->icon_x; + t->icon_y_loc = t->wmhints->icon_y; + } + /* dje 10/12/97: + Look thru chain of icon boxes assigned to window. + Add logic for grids and fill direction. + */ + else { + /* A place to hold inner and outer loop variables. */ + typedef struct dimension_struct { + int step; /* grid size (may be negative) */ + int start_at; /* starting edge */ + int real_start; /* on screen starting edge */ + int end_at; /* ending edge */ + int base; /* base for screen */ + int icon_dimension; /* height or width */ + int nom_dimension; /* nonminal height or width */ + int screen_dimension; /* screen height or width */ + } dimension; + dimension dim[3]; /* space for work, 1st, 2nd dimen */ + icon_boxes *icon_boxes_ptr; /* current icon box */ + int i; /* index for inner/outer loop data */ + + /* Hopefully this makes the following more readable. */ #define ICONBOX_LFT icon_boxes_ptr->IconBox[0] #define ICONBOX_TOP icon_boxes_ptr->IconBox[1] #define ICONBOX_RGT icon_boxes_ptr->IconBox[2] #define ICONBOX_BOT icon_boxes_ptr->IconBox[3] -#define BOT_FILL icon_boxes_ptr->IconFlags & ICONFILLBOT -#define RGT_FILL icon_boxes_ptr->IconFlags & ICONFILLRGT -#define HRZ_FILL icon_boxes_ptr->IconFlags & ICONFILLHRZ - - width = t->icon_p_width; /* unnecessary copy of width */ - height = t->icon_w_height + t->icon_p_height; /* total height */ - loc_ok = False; /* no slot found yet */ - - /* check all boxes in order */ - for(icon_boxes_ptr= t->IconBoxes; /* init */ - icon_boxes_ptr != NULL; /* until no more boxes */ - icon_boxes_ptr = icon_boxes_ptr->next) { /* all boxes */ - if (loc_ok == True) { - break; /* leave for loop */ - } - dim[1].step = icon_boxes_ptr->IconGrid[1]; /* y amount */ - dim[1].start_at = ICONBOX_TOP; /* init start from */ - dim[1].end_at = ICONBOX_BOT; /* init end at */ - dim[1].base = base_y; /* save base */ - dim[1].icon_dimension = height; /* save dimension */ - dim[1].screen_dimension = Scr.MyDisplayHeight; - if (BOT_FILL) { /* fill from bottom */ - dim[1].step = 0 - dim[1].step; /* reverse step */ - } /* end fill from bottom */ - - dim[2].step = icon_boxes_ptr->IconGrid[0]; /* x amount */ - dim[2].start_at = ICONBOX_LFT; /* init start from */ - dim[2].end_at = ICONBOX_RGT; /* init end at */ - dim[2].base = base_x; /* save base */ - dim[2].icon_dimension = width; /* save dimension */ - dim[2].screen_dimension = Scr.MyDisplayWidth; - if (RGT_FILL) { /* fill from right */ - dim[2].step = 0 - dim[2].step; /* reverse step */ - } /* end fill from right */ - for (i=1;i<=2;i++) { /* for dimensions 1 and 2 */ - /* If the window is taller than the icon box, ignore the icon height - * when figuring where to put it. Same goes for the width - * This should permit reasonably graceful handling of big icons. */ - dim[i].nom_dimension = dim[i].icon_dimension; - if (dim[i].icon_dimension >= dim[i].end_at - dim[i].start_at) { - dim[i].nom_dimension = dim[i].end_at - dim[i].start_at - 1; - } - if (dim[i].step < 0) { /* if moving backwards */ - dim[0].start_at = dim[i].start_at; /* save */ - dim[i].start_at = dim[i].end_at; /* swap one */ - dim[i].end_at = dim[0].start_at; /* swap the other */ - dim[i].start_at -= dim[i].icon_dimension; - } /* end moving backwards */ - dim[i].start_at += dim[i].base; /* adjust both to base */ - dim[i].end_at += dim[i].base; - } /* end 2 dimensions */ - if (HRZ_FILL) { /* if hrz first */ - memcpy(&dim[0],&dim[1],sizeof(dimension)); /* save */ - memcpy(&dim[1],&dim[2],sizeof(dimension)); /* switch one */ - memcpy(&dim[2],&dim[0],sizeof(dimension)); /* switch the other */ - } /* end horizontal dimension first */ - dim[0].start_at = dim[2].start_at; /* save for reseting inner loop */ - while((dim[1].step < 0 /* filling reversed */ - ? (dim[1].start_at + dim[1].icon_dimension - dim[1].nom_dimension - > dim[1].end_at) /* check back edge */ - : (dim[1].start_at + dim[1].nom_dimension - < dim[1].end_at)) /* check front edge */ - && (!loc_ok)) { /* nothing found yet */ - dim[1].real_start = dim[1].start_at; /* init */ - if (dim[1].start_at + dim[1].icon_dimension > - dim[1].screen_dimension - 2 + dim[1].base) { /* if off screen */ - dim[1].real_start = dim[1].screen_dimension - - dim[1].icon_dimension + dim[1].base; /* move on screen */ - } /* end off screen */ - if (dim[1].start_at < dim[1].base) { /* if off other edge */ - dim[1].real_start = dim[1].base; /* move on screen */ - } /* end off other edge */ - dim[2].start_at = dim[0].start_at; /* reset inner loop */ - while((dim[2].step < 0 /* filling reversed */ - ? (dim[2].start_at + dim[2].icon_dimension - dim[2].nom_dimension - > dim[2].end_at) /* check back edge */ - : (dim[2].start_at + dim[2].nom_dimension - < dim[2].end_at)) /* check front edge */ - && (!loc_ok)) { /* nothing found yet */ - dim[2].real_start = dim[2].start_at; /* init */ - if (dim[2].start_at + dim[2].icon_dimension > - dim[2].screen_dimension - 2 + dim[2].base) { /* if off screen */ - dim[2].real_start = dim[2].screen_dimension - - dim[2].icon_dimension + dim[2].base; /* move on screen */ - } /* end off screen */ - if (dim[2].start_at < dim[2].base) { /* if off other edge */ - dim[2].real_start = dim[2].base; /* move on screen */ - } /* end off other edge */ - - if (HRZ_FILL) { /* if hrz first */ - real_x = dim[1].real_start; /* unreverse them */ - real_y = dim[2].real_start; - } else { - real_x = dim[2].real_start; /* reverse them */ - real_y = dim[1].real_start; - } - - loc_ok = True; /* this may be a good location */ - test_window = Scr.FvwmRoot.next; - while((test_window != (FvwmWindow *)0) - &&(loc_ok == True)) { /* test overlap */ - if(test_window->Desk == t->Desk) { - if((test_window->flags&ICONIFIED) && - (!(test_window->flags&TRANSIENT) || - !test_window->tmpflags.IconifiedByParent) && - (test_window->icon_w||test_window->icon_pixmap_w) && - (test_window != t)) { - tw=test_window->icon_p_width; - th=test_window->icon_p_height+ - test_window->icon_w_height; - tx = test_window->icon_x_loc; - ty = test_window->icon_y_loc; - - if((tx<(real_x+width+3))&&((tx+tw+3) > real_x)&& - (ty<(real_y+height+3))&&((ty+th + 3)>real_y)) { - loc_ok = False; /* don't accept this location */ - } /* end if icons overlap */ - } /* end if its an icon */ - } /* end if same desk */ - test_window = test_window->next; - } /* end while icons that may overlap */ - dim[2].start_at += dim[2].step; /* Grid inner value & direction */ - } /* end while room inner dimension */ - dim[1].start_at += dim[1].step; /* Grid outer value & direction */ - } /* end while room outer dimension */ - } /* end for all icon boxes, or found space */ - if(loc_ok == False) /* If icon never found a home */ - return; /* just leave it */ - t->icon_x_loc = real_x; - t->icon_y_loc = real_y; - - if(t->icon_pixmap_w) - XMoveWindow(dpy,t->icon_pixmap_w,t->icon_x_loc, t->icon_y_loc); - - t->icon_w_width = t->icon_p_width; - t->icon_xl_loc = t->icon_x_loc; - - if (t->icon_w != None) - XMoveResizeWindow(dpy, t->icon_w, t->icon_xl_loc, - t->icon_y_loc+t->icon_p_height, - t->icon_w_width,ICON_HEIGHT); - BroadcastPacket(M_ICON_LOCATION, 7, - t->w, t->frame, - (unsigned long)t, - t->icon_x_loc, t->icon_y_loc, - t->icon_w_width, t->icon_w_height+t->icon_p_height); - } - +#define BOT_FILL icon_boxes_ptr->IconFlags &ICONFILLBOT +#define RGT_FILL icon_boxes_ptr->IconFlags &ICONFILLRGT +#define HRZ_FILL icon_boxes_ptr->IconFlags &ICONFILLHRZ + + width = t->icon_p_width; /* unnecessary copy of width */ + height = t->icon_w_height + t->icon_p_height; /* total height */ + loc_ok = False; /* no slot found yet */ + + /* check all boxes in order */ + for (icon_boxes_ptr = t->IconBoxes; /* init */ + icon_boxes_ptr != NULL; /* until no more boxes */ + icon_boxes_ptr = icon_boxes_ptr->next) { /* all boxes */ + if (loc_ok == True) { + break; /* leave for loop */ + } + dim[1].step = + icon_boxes_ptr->IconGrid[1]; /* y amount */ + dim[1].start_at = ICONBOX_TOP; /* init start from */ + dim[1].end_at = ICONBOX_BOT; /* init end at */ + dim[1].base = base_y; /* save base */ + dim[1].icon_dimension = height; /* save dimension */ + dim[1].screen_dimension = Scr.MyDisplayHeight; + if (BOT_FILL) { /* fill from bottom */ + dim[1].step = + 0 - dim[1].step; /* reverse step */ + } /* end fill from bottom */ + + dim[2].step = + icon_boxes_ptr->IconGrid[0]; /* x amount */ + dim[2].start_at = ICONBOX_LFT; /* init start from */ + dim[2].end_at = ICONBOX_RGT; /* init end at */ + dim[2].base = base_x; /* save base */ + dim[2].icon_dimension = width; /* save dimension */ + dim[2].screen_dimension = Scr.MyDisplayWidth; + if (RGT_FILL) { /* fill from right */ + dim[2].step = + 0 - dim[2].step; /* reverse step */ + } /* end fill from right */ + for (i = 1; i <= 2; i++) { /* for dimensions 1 and 2 */ + /* If the window is taller than the icon box, + * ignore the icon height when figuring where to + * put it. Same goes for the width This should + * permit reasonably graceful handling of big + * icons. */ + dim[i].nom_dimension = dim[i].icon_dimension; + if (dim[i].icon_dimension >= + dim[i].end_at - dim[i].start_at) { + dim[i].nom_dimension = + dim[i].end_at - dim[i].start_at - 1; + } + if (dim[i].step < 0) { /* if moving backwards */ + dim[0].start_at = + dim[i].start_at; /* save */ + dim[i].start_at = + dim[i].end_at; /* swap one */ + dim[i].end_at = + dim[0] + .start_at; /* swap the other */ + dim[i].start_at -= + dim[i].icon_dimension; + } /* end moving backwards */ + dim[i].start_at += + dim[i].base; /* adjust both to base */ + dim[i].end_at += dim[i].base; + } /* end 2 dimensions */ + if (HRZ_FILL) { /* if hrz first */ + memcpy(&dim[0], &dim[1], + sizeof(dimension)); /* save */ + memcpy(&dim[1], &dim[2], + sizeof(dimension)); /* switch one */ + memcpy(&dim[2], &dim[0], + sizeof(dimension)); /* switch the other */ + } /* end horizontal dimension first */ + dim[0].start_at = + dim[2].start_at; /* save for reseting inner loop */ + while ((dim[1].step < 0 ? /* filling reversed */ + (dim[1].start_at + dim[1].icon_dimension - + dim[1].nom_dimension > + dim[1].end_at) : /* check back edge */ + (dim[1].start_at + dim[1].nom_dimension < + dim[1].end_at)) && /* check front edge */ + (!loc_ok)) { /* nothing found yet */ + dim[1].real_start = dim[1].start_at; /* init */ + if (dim[1].start_at + dim[1].icon_dimension > + dim[1].screen_dimension - 2 + + dim[1].base) { /* if off screen */ + dim[1].real_start = + dim[1].screen_dimension - + dim[1].icon_dimension + + dim[1].base; /* move on screen */ + } /* end off screen */ + if (dim[1].start_at < + dim[1].base) { /* if off other edge */ + dim[1].real_start = + dim[1].base; /* move on screen */ + } /* end off other edge */ + dim[2].start_at = + dim[0].start_at; /* reset inner loop */ + while ((dim[2].step < 0 ? /* filling reversed */ + (dim[2].start_at + + dim[2].icon_dimension - + dim[2].nom_dimension > + dim[2].end_at) /* check back + edge */ + : (dim[2].start_at + + dim[2].nom_dimension < + dim[2].end_at)) /* check front + edge */ + && (!loc_ok)) { /* nothing found yet */ + dim[2].real_start = + dim[2].start_at; /* init */ + if (dim[2].start_at + + dim[2].icon_dimension > + dim[2].screen_dimension - 2 + + dim[2] + .base) { /* if off screen */ + dim[2].real_start = + dim[2].screen_dimension - + dim[2].icon_dimension + + dim[2].base; /* move on + screen */ + } /* end off screen */ + if (dim[2].start_at < + dim[2] + .base) { /* if off other edge */ + dim[2].real_start = + dim[2].base; /* move on + screen */ + } /* end off other edge */ + + if (HRZ_FILL) { /* if hrz first */ + real_x = + dim[1] + .real_start; /* unreverse + them */ + real_y = dim[2].real_start; + } else { + real_x = + dim[2] + .real_start; /* reverse + them */ + real_y = dim[1].real_start; + } + + loc_ok = True; /* this may be a good + location */ + test_window = Scr.FvwmRoot.next; + while ((test_window != + (FvwmWindow *)0) && + (loc_ok == + True)) { /* test overlap */ + if (test_window->Desk == + t->Desk) { + if ((test_window + ->flags & + ICONIFIED) && + (!(test_window + ->flags & + TRANSIENT) || + !test_window + ->tmpflags + .IconifiedByParent) && + (test_window + ->icon_w || + test_window + ->icon_pixmap_w) && + (test_window != + t)) { + tw = + test_window + ->icon_p_width; + th = + test_window + ->icon_p_height + + test_window + ->icon_w_height; + tx = + test_window + ->icon_x_loc; + ty = + test_window + ->icon_y_loc; + + if ((tx < + (real_x + + width + + 3)) && + ((tx + tw + + 3) > + real_x) && + (ty < + (real_y + + height + + 3)) && + ((ty + th + + 3) > + real_y)) { + loc_ok = + False; /* don't accept this location */ + } /* end if + icons + overlap */ + } /* end if its an icon + */ + } /* end if same desk */ + test_window = test_window->next; + } /* end while icons that may overlap */ + dim[2].start_at += + dim[2].step; /* Grid inner value & + direction */ + } /* end while room inner dimension */ + dim[1].start_at += + dim[1].step; /* Grid outer value & direction + */ + } /* end while room outer dimension */ + } /* end for all icon boxes, or found space */ + if (loc_ok == False) /* If icon never found a home */ + return; /* just leave it */ + t->icon_x_loc = real_x; + t->icon_y_loc = real_y; + + if (t->icon_pixmap_w) + XMoveWindow(dpy, t->icon_pixmap_w, t->icon_x_loc, + t->icon_y_loc); + + t->icon_w_width = t->icon_p_width; + t->icon_xl_loc = t->icon_x_loc; + + if (t->icon_w != None) + XMoveResizeWindow(dpy, t->icon_w, t->icon_xl_loc, + t->icon_y_loc + t->icon_p_height, t->icon_w_width, + ICON_HEIGHT); + BroadcastPacket(M_ICON_LOCATION, 7, t->w, t->frame, + (unsigned long)t, t->icon_x_loc, t->icon_y_loc, + t->icon_w_width, t->icon_w_height + t->icon_p_height); + } } /*********************************************************************** @@ -589,45 +663,43 @@ void AutoPlace(FvwmWindow *t) * tmp_win - the fvwm window structure to use * ***********************************************************************/ -void GrabIconButtons(FvwmWindow *tmp_win, Window w) +void +GrabIconButtons(FvwmWindow *tmp_win, Window w) { - Binding *MouseEntry; - - MouseEntry = Scr.AllBindings; - while(MouseEntry != (Binding *)0) - { - if((MouseEntry->Action != NULL)&&(MouseEntry->Context & C_ICON)&& - (MouseEntry->IsMouse == 1)) - { - if(MouseEntry->Button_Key >0) - XGrabButton(dpy, MouseEntry->Button_Key, MouseEntry->Modifier, w, - True, ButtonPressMask | ButtonReleaseMask, - GrabModeAsync, GrabModeAsync, None, - Scr.FvwmCursors[DEFAULT]); - else - { - XGrabButton(dpy, 1, MouseEntry->Modifier, w, - True, ButtonPressMask | ButtonReleaseMask, - GrabModeAsync, GrabModeAsync, None, - Scr.FvwmCursors[DEFAULT]); - XGrabButton(dpy, 2, MouseEntry->Modifier, w, - True, ButtonPressMask | ButtonReleaseMask, - GrabModeAsync, GrabModeAsync, None, - Scr.FvwmCursors[DEFAULT]); - XGrabButton(dpy, 3, MouseEntry->Modifier, w, - True, ButtonPressMask | ButtonReleaseMask, - GrabModeAsync, GrabModeAsync, None, - Scr.FvwmCursors[DEFAULT]); - } + Binding *MouseEntry; + + MouseEntry = Scr.AllBindings; + while (MouseEntry != (Binding *)0) { + if ((MouseEntry->Action != NULL) && + (MouseEntry->Context & C_ICON) && + (MouseEntry->IsMouse == 1)) { + if (MouseEntry->Button_Key > 0) + XGrabButton(dpy, MouseEntry->Button_Key, + MouseEntry->Modifier, w, True, + ButtonPressMask | ButtonReleaseMask, + GrabModeAsync, GrabModeAsync, None, + Scr.FvwmCursors[DEFAULT]); + else { + XGrabButton(dpy, 1, MouseEntry->Modifier, w, + True, ButtonPressMask | ButtonReleaseMask, + GrabModeAsync, GrabModeAsync, None, + Scr.FvwmCursors[DEFAULT]); + XGrabButton(dpy, 2, MouseEntry->Modifier, w, + True, ButtonPressMask | ButtonReleaseMask, + GrabModeAsync, GrabModeAsync, None, + Scr.FvwmCursors[DEFAULT]); + XGrabButton(dpy, 3, MouseEntry->Modifier, w, + True, ButtonPressMask | ButtonReleaseMask, + GrabModeAsync, GrabModeAsync, None, + Scr.FvwmCursors[DEFAULT]); + } + } + + MouseEntry = MouseEntry->NextBinding; } - - MouseEntry = MouseEntry->NextBinding; - } - return; + return; } - - /*********************************************************************** * * Procedure: @@ -637,44 +709,43 @@ void GrabIconButtons(FvwmWindow *tmp_win, Window w) * tmp_win - the fvwm window structure to use * ***********************************************************************/ -void GrabIconKeys(FvwmWindow *tmp_win,Window w) +void +GrabIconKeys(FvwmWindow *tmp_win, Window w) { - Binding *tmp; - for (tmp = Scr.AllBindings; tmp != NULL; tmp = tmp->NextBinding) - { - if ((tmp->Context & C_ICON)&&(tmp->IsMouse == 0)) - XGrabKey(dpy, tmp->Button_Key, tmp->Modifier, w, True, - GrabModeAsync, GrabModeAsync); - } - return; + Binding *tmp; + for (tmp = Scr.AllBindings; tmp != NULL; tmp = tmp->NextBinding) { + if ((tmp->Context & C_ICON) && (tmp->IsMouse == 0)) + XGrabKey(dpy, tmp->Button_Key, tmp->Modifier, w, True, + GrabModeAsync, GrabModeAsync); + } + return; } - /**************************************************************************** * * Looks for a monochrome icon bitmap file * ****************************************************************************/ -void GetBitmapFile(FvwmWindow *tmp_win) +void +GetBitmapFile(FvwmWindow *tmp_win) { - char *path = NULL; - int HotX,HotY; - extern char *IconPath; - - path = findIconFile(tmp_win->icon_bitmap_file, IconPath,R_OK); - - if(path == NULL)return; - if(XReadBitmapFile (dpy, Scr.Root,path, - (unsigned int *)&tmp_win->icon_p_width, - (unsigned int *)&tmp_win->icon_p_height, - &tmp_win->iconPixmap, - &HotX, &HotY) != BitmapSuccess) - { - tmp_win->icon_p_width = 0; - tmp_win->icon_p_height = 0; - } - - free(path); + char *path = NULL; + int HotX, HotY; + extern char *IconPath; + + path = findIconFile(tmp_win->icon_bitmap_file, IconPath, R_OK); + + if (path == NULL) + return; + if (XReadBitmapFile(dpy, Scr.Root, path, + (unsigned int *)&tmp_win->icon_p_width, + (unsigned int *)&tmp_win->icon_p_height, &tmp_win->iconPixmap, + &HotX, &HotY) != BitmapSuccess) { + tmp_win->icon_p_width = 0; + tmp_win->icon_p_height = 0; + } + + free(path); } /**************************************************************************** @@ -682,54 +753,55 @@ void GetBitmapFile(FvwmWindow *tmp_win) * Looks for a color XPM icon file * ****************************************************************************/ -void GetXPMFile(FvwmWindow *tmp_win) +void +GetXPMFile(FvwmWindow *tmp_win) { #ifdef XPM - XWindowAttributes root_attr; - XpmAttributes xpm_attributes; - extern char *PixmapPath; - char *path = NULL; - XpmImage my_image; - int rc; - - path = findIconFile(tmp_win->icon_bitmap_file, PixmapPath,R_OK); - if(path == NULL)return; - - XGetWindowAttributes(dpy,Scr.Root,&root_attr); - xpm_attributes.colormap = root_attr.colormap; - xpm_attributes.closeness = 40000; /* Allow for "similar" colors */ - xpm_attributes.valuemask = XpmSize|XpmReturnPixels|XpmColormap|XpmCloseness; - - rc =XpmReadFileToXpmImage(path, &my_image, NULL); - if (rc != XpmSuccess) { - fvwm_msg(ERR,"GetXPMFile","XpmReadFileToXpmImage failed, pixmap %s, rc %d", - path, rc); - free(path); - return; - } - free(path); - color_reduce_pixmap(&my_image,Scr.ColorLimit); - rc = XpmCreatePixmapFromXpmImage(dpy,Scr.Root, &my_image, - &tmp_win->iconPixmap, - &tmp_win->icon_maskPixmap, - &xpm_attributes); - if (rc != XpmSuccess) { - fvwm_msg(ERR,"GetXPMFile", - "XpmCreatePixmapFromXpmImage failed, rc %d\n", rc); - XpmFreeXpmImage(&my_image); - return; - } - tmp_win->icon_p_width = my_image.width; - tmp_win->icon_p_height = my_image.height; - tmp_win->flags |= PIXMAP_OURS; - tmp_win->iconDepth = Scr.d_depth; + XWindowAttributes root_attr; + XpmAttributes xpm_attributes; + extern char *PixmapPath; + char *path = NULL; + XpmImage my_image; + int rc; + + path = findIconFile(tmp_win->icon_bitmap_file, PixmapPath, R_OK); + if (path == NULL) + return; + + XGetWindowAttributes(dpy, Scr.Root, &root_attr); + xpm_attributes.colormap = root_attr.colormap; + xpm_attributes.closeness = 40000; /* Allow for "similar" colors */ + xpm_attributes.valuemask = + XpmSize | XpmReturnPixels | XpmColormap | XpmCloseness; + + rc = XpmReadFileToXpmImage(path, &my_image, NULL); + if (rc != XpmSuccess) { + fvwm_msg(ERR, "GetXPMFile", + "XpmReadFileToXpmImage failed, pixmap %s, rc %d", path, rc); + free(path); + return; + } + free(path); + color_reduce_pixmap(&my_image, Scr.ColorLimit); + rc = XpmCreatePixmapFromXpmImage(dpy, Scr.Root, &my_image, + &tmp_win->iconPixmap, &tmp_win->icon_maskPixmap, &xpm_attributes); + if (rc != XpmSuccess) { + fvwm_msg(ERR, "GetXPMFile", + "XpmCreatePixmapFromXpmImage failed, rc %d\n", rc); + XpmFreeXpmImage(&my_image); + return; + } + tmp_win->icon_p_width = my_image.width; + tmp_win->icon_p_height = my_image.height; + tmp_win->flags |= PIXMAP_OURS; + tmp_win->iconDepth = Scr.d_depth; #ifdef SHAPE - if (ShapesSupported && tmp_win->icon_maskPixmap) - tmp_win->flags |= SHAPED_ICON; + if (ShapesSupported && tmp_win->icon_maskPixmap) + tmp_win->flags |= SHAPED_ICON; #endif - XpmFreeXpmImage(&my_image); + XpmFreeXpmImage(&my_image); #endif /* XPM */ } @@ -739,269 +811,243 @@ void GetXPMFile(FvwmWindow *tmp_win) * Looks for an application supplied icon window * ****************************************************************************/ -void GetIconWindow(FvwmWindow *tmp_win) +void +GetIconWindow(FvwmWindow *tmp_win) { - /* We are guaranteed that wmhints is non-null when calling this - * routine */ - if(XGetGeometry(dpy, tmp_win->wmhints->icon_window, &JunkRoot, - &JunkX, &JunkY,(unsigned int *)&tmp_win->icon_p_width, - (unsigned int *)&tmp_win->icon_p_height, - &JunkBW, &JunkDepth)==0) - { - fvwm_msg(ERR,"GetIconWindow","Help! Bad Icon Window!"); - } - tmp_win->icon_p_width += JunkBW<<1; - tmp_win->icon_p_height += JunkBW<<1; - /* - * Now make the new window the icon window for this window, - * and set it up to work as such (select for key presses - * and button presses/releases, set up the contexts for it, - * and define the cursor for it). - */ - tmp_win->icon_pixmap_w = tmp_win->wmhints->icon_window; + /* We are guaranteed that wmhints is non-null when calling this + * routine */ + if (XGetGeometry(dpy, tmp_win->wmhints->icon_window, &JunkRoot, &JunkX, + &JunkY, (unsigned int *)&tmp_win->icon_p_width, + (unsigned int *)&tmp_win->icon_p_height, &JunkBW, + &JunkDepth) == 0) { + fvwm_msg(ERR, "GetIconWindow", "Help! Bad Icon Window!"); + } + tmp_win->icon_p_width += JunkBW << 1; + tmp_win->icon_p_height += JunkBW << 1; + /* + * Now make the new window the icon window for this window, + * and set it up to work as such (select for key presses + * and button presses/releases, set up the contexts for it, + * and define the cursor for it). + */ + tmp_win->icon_pixmap_w = tmp_win->wmhints->icon_window; #ifdef SHAPE - if (ShapesSupported) - { - if (tmp_win->wmhints->flags & IconMaskHint) - { - tmp_win->flags |= SHAPED_ICON; - tmp_win->icon_maskPixmap = tmp_win->wmhints->icon_mask; - } - } + if (ShapesSupported) { + if (tmp_win->wmhints->flags & IconMaskHint) { + tmp_win->flags |= SHAPED_ICON; + tmp_win->icon_maskPixmap = tmp_win->wmhints->icon_mask; + } + } #endif - /* Make sure that the window is a child of the root window ! */ - /* Olwais screws this up, maybe others do too! */ - XReparentWindow(dpy, tmp_win->icon_pixmap_w, Scr.Root, 0,0); - tmp_win->flags &= ~ICON_OURS; + /* Make sure that the window is a child of the root window ! */ + /* Olwais screws this up, maybe others do too! */ + XReparentWindow(dpy, tmp_win->icon_pixmap_w, Scr.Root, 0, 0); + tmp_win->flags &= ~ICON_OURS; } - /**************************************************************************** * * Looks for an application supplied bitmap or pixmap * ****************************************************************************/ -void GetIconBitmap(FvwmWindow *tmp_win) +void +GetIconBitmap(FvwmWindow *tmp_win) { - /* We are guaranteed that wmhints is non-null when calling this - * routine */ - XGetGeometry(dpy, tmp_win->wmhints->icon_pixmap, &JunkRoot, &JunkX, &JunkY, - (unsigned int *)&tmp_win->icon_p_width, - (unsigned int *)&tmp_win->icon_p_height, &JunkBW, &JunkDepth); - tmp_win->iconPixmap = tmp_win->wmhints->icon_pixmap; - tmp_win->iconDepth = JunkDepth; + /* We are guaranteed that wmhints is non-null when calling this + * routine */ + XGetGeometry(dpy, tmp_win->wmhints->icon_pixmap, &JunkRoot, &JunkX, + &JunkY, (unsigned int *)&tmp_win->icon_p_width, + (unsigned int *)&tmp_win->icon_p_height, &JunkBW, &JunkDepth); + tmp_win->iconPixmap = tmp_win->wmhints->icon_pixmap; + tmp_win->iconDepth = JunkDepth; #ifdef SHAPE - if (ShapesSupported) - { - if (tmp_win->wmhints->flags & IconMaskHint) - { - tmp_win->flags |= SHAPED_ICON; - tmp_win->icon_maskPixmap = tmp_win->wmhints->icon_mask; - } - } + if (ShapesSupported) { + if (tmp_win->wmhints->flags & IconMaskHint) { + tmp_win->flags |= SHAPED_ICON; + tmp_win->icon_maskPixmap = tmp_win->wmhints->icon_mask; + } + } #endif } - - /*********************************************************************** * * Procedure: * DeIconify a window * ***********************************************************************/ -void DeIconify(FvwmWindow *tmp_win) +void +DeIconify(FvwmWindow *tmp_win) { - FvwmWindow *t,*tmp; - - if(!tmp_win) - return; - - /* AS dje RaiseWindow(tmp_win); */ - /* now de-iconify transients */ - for (t = Scr.FvwmRoot.next; t != NULL; t = t->next) - { - if ((t == tmp_win)|| - ((t->flags & TRANSIENT) &&(t->transientfor == tmp_win->w))) - { - t->flags |= MAPPED; - t->tmpflags.IconifiedByParent = 0; - if(Scr.Hilite == t) - SetBorder (t, False,True,True,None); - - /* AS stuff starts here dje */ - if (t->icon_pixmap_w) - XUnmapWindow(dpy, t->icon_pixmap_w); - if (t->icon_w) - XUnmapWindow(dpy, t->icon_w); - XFlush(dpy); - if (t == tmp_win) - BroadcastPacket(M_DEICONIFY, 11, - t->w, t->frame, - (unsigned long)t, - t->icon_x_loc, t->icon_y_loc, - t->icon_p_width, t->icon_p_height+t->icon_w_height, - t->frame_x, t->frame_y, - t->frame_width, t->frame_height); - else - BroadcastPacket(M_DEICONIFY, 7, - t->w, t->frame, - (unsigned long)t, - t->icon_x_loc, t->icon_y_loc, - t->icon_p_width, t->icon_p_height+t->icon_w_height); - /* End AS */ - XMapWindow(dpy, t->w); - if(t->Desk == Scr.CurrentDesk) - { - XMapWindow(dpy, t->frame); - t->flags |= MAP_PENDING; - } - XMapWindow(dpy, t->Parent); - SetMapStateProp(t, NormalState); - t->flags &= ~ICONIFIED; - t->flags &= ~ICON_UNMAPPED; - /* Need to make sure the border is colored correctly, - * in case it was stuck or unstuck while iconified. */ - tmp = Scr.Hilite; - Scr.Hilite = t; - SetBorder(t,False,True,True,None); - Scr.Hilite = tmp; - XRaiseWindow(dpy,t->w); + FvwmWindow *t, *tmp; + + if (!tmp_win) + return; + + /* AS dje RaiseWindow(tmp_win); */ + /* now de-iconify transients */ + for (t = Scr.FvwmRoot.next; t != NULL; t = t->next) { + if ((t == tmp_win) || + IsTransientDescendantOf(t, tmp_win)) { + t->flags |= MAPPED; + t->tmpflags.IconifiedByParent = 0; + if (Scr.Hilite == t) + SetBorder(t, False, True, True, None); + + /* AS stuff starts here dje */ + if (t->icon_pixmap_w) + XUnmapWindow(dpy, t->icon_pixmap_w); + if (t->icon_w) + XUnmapWindow(dpy, t->icon_w); + XFlush(dpy); + if (t == tmp_win) + BroadcastPacket(M_DEICONIFY, 11, t->w, t->frame, + (unsigned long)t, t->icon_x_loc, + t->icon_y_loc, t->icon_p_width, + t->icon_p_height + t->icon_w_height, + t->frame_x, t->frame_y, t->frame_width, + t->frame_height); + else + BroadcastPacket(M_DEICONIFY, 7, t->w, t->frame, + (unsigned long)t, t->icon_x_loc, + t->icon_y_loc, t->icon_p_width, + t->icon_p_height + t->icon_w_height); + /* End AS */ + XMapWindow(dpy, t->w); + if (t->Desk == Scr.CurrentDesk) { + XMapWindow(dpy, t->frame); + t->flags |= MAP_PENDING; + } + XMapWindow(dpy, t->Parent); + SetMapStateProp(t, NormalState); + t->flags &= ~ICONIFIED; + t->flags &= ~ICON_UNMAPPED; + /* Need to make sure the border is colored correctly, + * in case it was stuck or unstuck while iconified. */ + tmp = Scr.Hilite; + Scr.Hilite = t; + SetBorder(t, False, True, True, None); + Scr.Hilite = tmp; + XRaiseWindow(dpy, t->w); + } } - } - RaiseWindow(tmp_win); /* moved dje */ + RaiseWindow(tmp_win); /* moved dje */ - if(tmp_win->flags & ClickToFocus) - FocusOn(tmp_win,TRUE); + if (tmp_win->flags & ClickToFocus) + FocusOn(tmp_win, TRUE); - KeepOnTop(); + KeepOnTop(); - return; + return; } - /**************************************************************************** * * Iconifies the selected window * ****************************************************************************/ -void Iconify(FvwmWindow *tmp_win, int def_x, int def_y) +void +Iconify(FvwmWindow *tmp_win, int def_x, int def_y) { - FvwmWindow *t; - XWindowAttributes winattrs = {0}; - unsigned long eventMask; - - if(!tmp_win) - return; - XGetWindowAttributes(dpy, tmp_win->w, &winattrs); - eventMask = winattrs.your_event_mask; - - if((tmp_win == Scr.Hilite)&& - (tmp_win->flags & ClickToFocus)&&(tmp_win->next)) - { - SetFocus(tmp_win->next->w,tmp_win->next,1); - } - - - /* iconify transients first */ - for (t = Scr.FvwmRoot.next; t != NULL; t = t->next) - { - if ((t==tmp_win)|| - ((t->flags & TRANSIENT) && (t->transientfor == tmp_win->w))) - { - /* - * Prevent the receipt of an UnmapNotify, since that would - * cause a transition to the Withdrawn state. - */ - t->flags &= ~MAPPED; - XSelectInput(dpy, t->w, eventMask & ~StructureNotifyMask); - XUnmapWindow(dpy, t->w); - XSelectInput(dpy, t->w, eventMask); - XUnmapWindow(dpy, t->frame); - t->DeIconifyDesk = t->Desk; - if (t->icon_w) - XUnmapWindow(dpy, t->icon_w); - if (t->icon_pixmap_w) - XUnmapWindow(dpy, t->icon_pixmap_w); - - SetMapStateProp(t, IconicState); - SetBorder (t, False,False,False,None); - if(t != tmp_win) - { - t->flags |= ICONIFIED|ICON_UNMAPPED; - t->tmpflags.IconifiedByParent = 1; - - BroadcastPacket(M_ICONIFY, 7, - t->w, t->frame, - (unsigned long)t, - -10000, -10000, - t->icon_w_width, - t->icon_w_height+t->icon_p_height); - BroadcastConfig(M_CONFIGURE_WINDOW,t); - } - } /* if */ - } /* for */ - if (tmp_win->icon_w == None) { - if(tmp_win->flags & ICON_MOVED) - CreateIconWindow(tmp_win,tmp_win->icon_x_loc,tmp_win->icon_y_loc); - else - CreateIconWindow(tmp_win, def_x, def_y); - } - - /* if no pixmap we want icon width to change to text width every iconify */ - if( (tmp_win->icon_w != None) && (tmp_win->icon_pixmap_w == None) ) { - tmp_win->icon_t_width = - XTextWidth(Scr.IconFont.font,tmp_win->icon_name, - strlen(tmp_win->icon_name)); - tmp_win->icon_p_width = tmp_win->icon_t_width+6; - tmp_win->icon_w_width = tmp_win->icon_p_width; - } - - AutoPlace(tmp_win); - tmp_win->flags |= ICONIFIED; - tmp_win->flags &= ~ICON_UNMAPPED; - BroadcastPacket(M_ICONIFY, 11, - tmp_win->w, tmp_win->frame, - (unsigned long)tmp_win, - tmp_win->icon_x_loc, - tmp_win->icon_y_loc, - tmp_win->icon_w_width, - tmp_win->icon_w_height+tmp_win->icon_p_height, - tmp_win->frame_x, /* next 4 added for Animate module */ - tmp_win->frame_y, - tmp_win->frame_width, - tmp_win->frame_height); - BroadcastConfig(M_CONFIGURE_WINDOW,tmp_win); - - LowerWindow(tmp_win); - if(tmp_win->Desk == Scr.CurrentDesk) - { - if (tmp_win->icon_w != None) - XMapWindow(dpy, tmp_win->icon_w); - - if(tmp_win->icon_pixmap_w != None) - XMapWindow(dpy, tmp_win->icon_pixmap_w); - KeepOnTop(); - } - if((tmp_win->flags & ClickToFocus)||(tmp_win->flags & SloppyFocus)) - { - if (tmp_win == Scr.Focus) - { - if(Scr.PreviousFocus == Scr.Focus) - Scr.PreviousFocus = NULL; - if((tmp_win->flags & ClickToFocus)&&(tmp_win->next)) - SetFocus(tmp_win->next->w, tmp_win->next,1); - else - { - SetFocus(Scr.NoFocusWin, NULL,1); - } + FvwmWindow *t; + XWindowAttributes winattrs = {0}; + unsigned long eventMask; + + if (!tmp_win) + return; + XGetWindowAttributes(dpy, tmp_win->w, &winattrs); + eventMask = winattrs.your_event_mask; + + if ((tmp_win == Scr.Hilite) && (tmp_win->flags & ClickToFocus) && + (tmp_win->next)) { + SetFocus(tmp_win->next->w, tmp_win->next, 1); } - } - return; -} + /* iconify transients first */ + for (t = Scr.FvwmRoot.next; t != NULL; t = t->next) { + if ((t == tmp_win) || + IsTransientDescendantOf(t, tmp_win)) { + /* + * Prevent the receipt of an UnmapNotify, since that + * would cause a transition to the Withdrawn state. + */ + t->flags &= ~MAPPED; + XSelectInput( + dpy, t->w, eventMask & ~StructureNotifyMask); + XUnmapWindow(dpy, t->w); + XSelectInput(dpy, t->w, eventMask); + XUnmapWindow(dpy, t->frame); + t->DeIconifyDesk = t->Desk; + if (t->icon_w) + XUnmapWindow(dpy, t->icon_w); + if (t->icon_pixmap_w) + XUnmapWindow(dpy, t->icon_pixmap_w); + + SetMapStateProp(t, IconicState); + SetBorder(t, False, False, False, None); + if (t != tmp_win) { + t->flags |= ICONIFIED | ICON_UNMAPPED; + t->tmpflags.IconifiedByParent = 1; + + BroadcastPacket(M_ICONIFY, 7, t->w, t->frame, + (unsigned long)t, -10000, -10000, + t->icon_w_width, + t->icon_w_height + t->icon_p_height); + BroadcastConfig(M_CONFIGURE_WINDOW, t); + } + } /* if */ + } /* for */ + if (tmp_win->icon_w == None) { + if (tmp_win->flags & ICON_MOVED) + CreateIconWindow( + tmp_win, tmp_win->icon_x_loc, tmp_win->icon_y_loc); + else + CreateIconWindow(tmp_win, def_x, def_y); + } + + /* if no pixmap we want icon width to change to text width every iconify + */ + if ((tmp_win->icon_w != None) && (tmp_win->icon_pixmap_w == None)) { + tmp_win->icon_t_width = XTextWidth(Scr.IconFont.font, + tmp_win->icon_name, strlen(tmp_win->icon_name)); + tmp_win->icon_p_width = tmp_win->icon_t_width + 6; + tmp_win->icon_w_width = tmp_win->icon_p_width; + } + AutoPlace(tmp_win); + tmp_win->flags |= ICONIFIED; + tmp_win->flags &= ~ICON_UNMAPPED; + BroadcastPacket(M_ICONIFY, 11, tmp_win->w, tmp_win->frame, + (unsigned long)tmp_win, tmp_win->icon_x_loc, tmp_win->icon_y_loc, + tmp_win->icon_w_width, + tmp_win->icon_w_height + tmp_win->icon_p_height, + tmp_win->frame_x, /* next 4 added for Animate module */ + tmp_win->frame_y, tmp_win->frame_width, tmp_win->frame_height); + BroadcastConfig(M_CONFIGURE_WINDOW, tmp_win); + + LowerWindow(tmp_win); + if (tmp_win->Desk == Scr.CurrentDesk) { + if (tmp_win->icon_w != None) + XMapWindow(dpy, tmp_win->icon_w); + + if (tmp_win->icon_pixmap_w != None) + XMapWindow(dpy, tmp_win->icon_pixmap_w); + KeepOnTop(); + } + if ((tmp_win->flags & ClickToFocus) || (tmp_win->flags & SloppyFocus)) { + if (tmp_win == Scr.Focus) { + if (Scr.PreviousFocus == Scr.Focus) + Scr.PreviousFocus = NULL; + if ((tmp_win->flags & ClickToFocus) && (tmp_win->next)) + SetFocus(tmp_win->next->w, tmp_win->next, 1); + else { + SetFocus(Scr.NoFocusWin, NULL, 1); + } + } + } + return; +} /**************************************************************************** * @@ -1010,15 +1056,16 @@ void Iconify(FvwmWindow *tmp_win, int def_x, int def_y) * that go with them. * ****************************************************************************/ -void SetMapStateProp(FvwmWindow *tmp_win, int state) +void +SetMapStateProp(FvwmWindow *tmp_win, int state) { - unsigned long data[2]; /* "suggested" by ICCCM version 1 */ + unsigned long data[2]; /* "suggested" by ICCCM version 1 */ - data[0] = (unsigned long) state; - data[1] = (unsigned long) tmp_win->icon_w; -/* data[2] = (unsigned long) tmp_win->icon_pixmap_w;*/ + data[0] = (unsigned long)state; + data[1] = (unsigned long)tmp_win->icon_w; + /* data[2] = (unsigned long) tmp_win->icon_pixmap_w;*/ - XChangeProperty (dpy, tmp_win->w, _XA_WM_STATE, _XA_WM_STATE, 32, - PropModeReplace, (unsigned char *) data, 2); - return; + XChangeProperty(dpy, tmp_win->w, _XA_WM_STATE, _XA_WM_STATE, 32, + PropModeReplace, (unsigned char *)data, 2); + return; } Index: fvwm/fvwm/menus.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/menus.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/menus.c --- fvwm/fvwm/menus.c +++ fvwm/fvwm/menus.c @@ -43,47 +43,47 @@ Rewrite of the MenuStyle code for cleaner parsing and better configurability. */ - /*********************************************************************** * * fvwm menu code * ***********************************************************************/ /* #define FVWM_DEBUG_MSGS */ -#include "config.h" +#include "menus.h" -#include +#include +#include + +#include #include -#include +#include #include -#include +#include #include -#include -#include -#include -#include +#include +#include +#include "config.h" #include "fvwm.h" -#include "menus.h" #include "misc.h" #include "parse.h" #include "screen.h" -static void DrawTrianglePattern(Window,GC,GC,GC,GC,int,int,int,int,char); -static void DrawSeparator(Window, GC,GC,int, int,int,int,int); -static void DrawUnderline(MenuRoot *mr, GC gc, int x, int y, - char *txt, int off); -static MenuStatus MenuInteraction(MenuRoot *menu,MenuRoot *menuPrior, - MenuItem **pmiExecuteAction,int cmenuDeep, - Bool fSticks); +static void DrawTrianglePattern( + Window, GC, GC, GC, GC, int, int, int, int, char); +static void DrawSeparator(Window, GC, GC, int, int, int, int, int); +static void DrawUnderline( + MenuRoot *mr, GC gc, int x, int y, char *txt, int off); +static MenuStatus MenuInteraction(MenuRoot *menu, MenuRoot *menuPrior, + MenuItem **pmiExecuteAction, int cmenuDeep, Bool fSticks); static void WarpPointerToTitle(MenuRoot *menu); static MenuItem *MiWarpPointerToItem(MenuItem *mi, Bool fSkipTitle); static void PopDownMenu(MenuRoot *mr); static void PopDownAndRepaintParent(MenuRoot *mr, Bool *fSubmenuOverlaps); -static int DoMenusOverlap(MenuRoot *mr, int x, int y, int width, int height, - Bool fTolerant); +static int DoMenusOverlap( + MenuRoot *mr, int x, int y, int width, int height, Bool fTolerant); static Bool FPopupMenu(MenuRoot *menu, MenuRoot *menuPrior, int x, int y, - Bool fWarpItem, MenuOptions *pops, Bool *ret_overlap); + Bool fWarpItem, MenuOptions *pops, Bool *ret_overlap); static void GetPreferredPopupPosition(MenuRoot *mr, int *x, int *y); static int PopupPositionOffset(MenuRoot *mr); static void GetPopupOptions(MenuItem *mi, MenuOptions *pops); @@ -91,19 +91,19 @@ static void PaintEntry(MenuItem *mi); static void PaintMenu(MenuRoot *, XEvent *); static void SetMenuItemSelected(MenuItem *mi, Bool f); static MenuRoot *MrPopupForMi(MenuItem *mi); -static int ButtonPosition(int context, FvwmWindow * t); +static int ButtonPosition(int context, FvwmWindow *t); static Bool FMenuMapped(MenuRoot *menu); Bool menuFromFrameOrWindowOrTitlebar = FALSE; Bool fShowPopupTimedout = FALSE; Bool mouse_moved = FALSE; -extern int Context,Button; +extern int Context, Button; extern FvwmWindow *ButtonWindow, *Tmp_win; extern XEvent Event; extern XContext MenuContext; -static FvwmWindow *s_Tmp_win=NULL; +static FvwmWindow *s_Tmp_win = NULL; /* dirty patch to pass the last popups position hints to popup_func */ MenuPosHints lastMenuPosHints; @@ -116,12 +116,19 @@ unsigned int dkp_keystate; unsigned int dkp_keycode; Time dkp_timestamp; -#define IS_TITLE_MENU_ITEM(mi) (((mi)?((mi)->func_type==F_TITLE):FALSE)) -#define IS_POPUP_MENU_ITEM(mi) (((mi)?((mi)->func_type==F_POPUP):FALSE)) -#define IS_SEPARATOR_MENU_ITEM(mi) ((mi)?(mi)->fIsSeparator:FALSE) -#define IS_REAL_SEPARATOR_MENU_ITEM(mi) ((mi)?((mi)->fIsSeparator && StrEquals((mi)->action,"nop") && !((mi)->strlen) && !((mi)->strlen2)):FALSE) -#define IS_LABEL_MENU_ITEM(mi) ((mi)?((mi)->fIsSeparator && StrEquals((mi)->action,"nop") && ((mi)->strlen || ((mi)->strlen2))):FALSE) -#define MENU_MIDDLE_OFFSET(menu) ((menu)->xoffset + ((menu)->width - (menu)->xoffset)/2) +#define IS_TITLE_MENU_ITEM(mi) (((mi) ? ((mi)->func_type == F_TITLE) : FALSE)) +#define IS_POPUP_MENU_ITEM(mi) (((mi) ? ((mi)->func_type == F_POPUP) : FALSE)) +#define IS_SEPARATOR_MENU_ITEM(mi) ((mi) ? (mi)->fIsSeparator : FALSE) +#define IS_REAL_SEPARATOR_MENU_ITEM(mi) \ + ((mi) ? ((mi)->fIsSeparator && StrEquals((mi)->action, "nop") &&\ + !((mi)->strlen) && !((mi)->strlen2)) \ + : FALSE) +#define IS_LABEL_MENU_ITEM(mi) \ + ((mi) ? ((mi)->fIsSeparator && StrEquals((mi)->action, "nop") &&\ + ((mi)->strlen || ((mi)->strlen2))) \ + : FALSE) +#define MENU_MIDDLE_OFFSET(menu) \ + ((menu)->xoffset + ((menu)->width - (menu)->xoffset) / 2) #define IS_LEFT_MENU(menu) ((menu)->flags.f.is_left) #define IS_RIGHT_MENU(menu) ((menu)->flags.f.is_right) #define IS_UP_MENU(menu) ((menu)->flags.f.is_up) @@ -143,149 +150,156 @@ Time dkp_timestamp; * * Returns one of MENU_NOP, MENU_ERROR, MENU_ABORTED, MENU_DONE ***************************************************************************/ -MenuStatus do_menu(MenuRoot *menu, MenuRoot *menuPrior, - MenuItem **pmiExecuteAction,int cmenuDeep,Bool fStick, - XEvent *eventp, MenuOptions *pops) +MenuStatus +do_menu(MenuRoot *menu, MenuRoot *menuPrior, MenuItem **pmiExecuteAction, + int cmenuDeep, Bool fStick, XEvent *eventp, MenuOptions *pops) { - MenuStatus retval=MENU_NOP; - int x,y; - static int x_start, y_start; - Bool fFailedPopup = FALSE; - Bool fWasAlreadyPopped = FALSE; - Bool key_press; - Bool fDoubleClick = FALSE; - Time t0 = lastTimestamp; - extern Time lastTimestamp; - static int cindirectDeep = 0; - - DBUG("do_menu","called"); - - key_press = (eventp && (eventp == (XEvent *)1 || eventp->type == KeyPress)); - /* this condition could get ugly */ - if(menu == NULL || menu->in_use) { - /* DBUG("do_menu","menu->in_use for %s -- returning",menu->name); */ - return MENU_ERROR; - } - - /* Try to pick a root-relative optimal x,y to - put the mouse right on the title w/o warping */ - XQueryPointer( dpy, Scr.Root, &JunkRoot, &JunkChild, - &x, &y, &JunkX, &JunkY, &JunkMask); - /* Save these-- we want to warp back here if this is a top level - menu brought up by a keystroke */ - if (cmenuDeep == 0 && cindirectDeep == 0) { - if (key_press) { - x_start = x; - y_start = y; - } else { - x_start = -1; - y_start = -1; - } - } - /* calculate position from positioning hints */ - if ((pops->flags.f.has_poshints) && !fIgnorePosHints) { - pops->pos_hints.x += pops->pos_hints.x_factor * menu->width; - pops->pos_hints.y += pops->pos_hints.y_factor * menu->height; - } - /* Figure out where we should popup, if possible */ - if (!FMenuMapped(menu)) { - if(cmenuDeep > 0) { - /* this is a submenu popup */ - assert(menuPrior); - if ((pops->flags.f.has_poshints) && !fIgnorePosHints) { - x = pops->pos_hints.x; - y = pops->pos_hints.y; - } else { - GetPreferredPopupPosition(menuPrior, &x, &y); - } - } else { - /* we're a top level menu */ - mouse_moved = FALSE; - if(!GrabEm(MENU)) { /* GrabEm specifies the cursor to use */ - XBell(dpy, 0); - return MENU_ABORTED; - } - if ((pops->flags.f.has_poshints) && !fIgnorePosHints) { - x = pops->pos_hints.x; - y = pops->pos_hints.y; - } else { - /* Make the menu appear under the pointer rather than warping */ - x -= MENU_MIDDLE_OFFSET(menu); - y -= menu->ms->look.EntryHeight/2 + 2; - } - } - - /* FPopupMenu may move the x,y to make it fit on screen more nicely */ - /* it might also move menuPrior out of the way */ - if (!FPopupMenu (menu, menuPrior, x, y, key_press /*warp*/, pops, NULL)) { - fFailedPopup = TRUE; - XBell (dpy, 0); - } - } - else { - fWasAlreadyPopped = TRUE; - if (key_press) MiWarpPointerToItem(menu->first, TRUE /* skip Title */); - } - fWarpPointerToTitle = FALSE; - - menu->in_use = TRUE; - /* Remember the key that popped up the root menu. */ - if (!(cmenuDeep++)) { - if (eventp && eventp != (XEvent *)1) { - /* we have a real key event */ - dkp_keystate = eventp->xkey.state; - dkp_keycode = eventp->xkey.keycode; - } - dkp_timestamp = (key_press) ? t0 : 0; - } - if (!fFailedPopup) - retval = MenuInteraction(menu,menuPrior,pmiExecuteAction,cmenuDeep,fStick); - else - retval = MENU_ABORTED; - cmenuDeep--; - menu->in_use = FALSE; - - if (!fWasAlreadyPopped) - PopDownMenu(menu); - /* FIX: this global is bad */ - menuFromFrameOrWindowOrTitlebar = FALSE; - XFlush(dpy); - - if (cmenuDeep == 0 && x_start >= 0 && y_start >= 0 && - IS_MENU_BUTTON(retval)) { - /* warp pointer back to where invoked if this was brought up - with a keypress and we're returning from a top level menu, - and a button release event didn't end it */ - XWarpPointer(dpy, 0, Scr.Root, 0, 0, - Scr.MyDisplayWidth, Scr.MyDisplayHeight,x_start, y_start); - } - - if (lastTimestamp-t0 < Scr.menus.DoubleClickTime && !mouse_moved && - (!key_press || dkp_timestamp != 0)) { - /* dkp_timestamp is non-zero if a double-keypress occured! */ - fDoubleClick = TRUE; - } - dkp_timestamp = 0; - if(cmenuDeep == 0) { - UngrabEm(); - WaitForButtonsUp(); - if (retval == MENU_DONE || retval == MENU_DONE_BUTTON) { - if (pmiExecuteAction && *pmiExecuteAction && !fDoubleClick) { - cindirectDeep++; - ExecuteFunction( - (*pmiExecuteAction)->action,ButtonWindow, &Event,Context, -1); - cindirectDeep--; - } - fIgnorePosHints = FALSE; - fLastMenuPosHintsValid = FALSE; - } - } - - if (fDoubleClick) - retval = MENU_DOUBLE_CLICKED; - return retval; -} + MenuStatus retval = MENU_NOP; + int x, y; + static int x_start, y_start; + Bool fFailedPopup = FALSE; + Bool fWasAlreadyPopped = FALSE; + Bool key_press; + Bool fDoubleClick = FALSE; + Time t0 = lastTimestamp; + extern Time lastTimestamp; + static int cindirectDeep = 0; + + DBUG("do_menu", "called"); + + key_press = + (eventp && (eventp == (XEvent *)1 || eventp->type == KeyPress)); + /* this condition could get ugly */ + if (menu == NULL || menu->in_use) { + /* DBUG("do_menu","menu->in_use for %s -- + * returning",menu->name); */ + return MENU_ERROR; + } + + /* Try to pick a root-relative optimal x,y to + put the mouse right on the title w/o warping */ + XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, &x, &y, &JunkX, + &JunkY, &JunkMask); + /* Save these-- we want to warp back here if this is a top level + menu brought up by a keystroke */ + if (cmenuDeep == 0 && cindirectDeep == 0) { + if (key_press) { + x_start = x; + y_start = y; + } else { + x_start = -1; + y_start = -1; + } + } + /* calculate position from positioning hints */ + if ((pops->flags.f.has_poshints) && !fIgnorePosHints) { + pops->pos_hints.x += pops->pos_hints.x_factor * menu->width; + pops->pos_hints.y += pops->pos_hints.y_factor * menu->height; + } + /* Figure out where we should popup, if possible */ + if (!FMenuMapped(menu)) { + if (cmenuDeep > 0) { + /* this is a submenu popup */ + assert(menuPrior); + if ((pops->flags.f.has_poshints) && !fIgnorePosHints) { + x = pops->pos_hints.x; + y = pops->pos_hints.y; + } else { + GetPreferredPopupPosition(menuPrior, &x, &y); + } + } else { + /* we're a top level menu */ + mouse_moved = FALSE; + if (!GrabEm(MENU)) { /* GrabEm specifies the cursor to + use */ + XBell(dpy, 0); + return MENU_ABORTED; + } + if ((pops->flags.f.has_poshints) && !fIgnorePosHints) { + x = pops->pos_hints.x; + y = pops->pos_hints.y; + } else { + /* Make the menu appear under the pointer rather + * than warping */ + x -= MENU_MIDDLE_OFFSET(menu); + y -= menu->ms->look.EntryHeight / 2 + 2; + } + } + /* FPopupMenu may move the x,y to make it fit on screen more + * nicely */ + /* it might also move menuPrior out of the way */ + if (!FPopupMenu(menu, menuPrior, x, y, key_press /*warp*/, pops, + NULL)) { + fFailedPopup = TRUE; + XBell(dpy, 0); + } + } else { + fWasAlreadyPopped = TRUE; + if (key_press) + MiWarpPointerToItem(menu->first, TRUE /* skip Title */); + } + fWarpPointerToTitle = FALSE; + + menu->in_use = TRUE; + /* Remember the key that popped up the root menu. */ + if (!(cmenuDeep++)) { + if (eventp && eventp != (XEvent *)1) { + /* we have a real key event */ + dkp_keystate = eventp->xkey.state; + dkp_keycode = eventp->xkey.keycode; + } + dkp_timestamp = (key_press) ? t0 : 0; + } + if (!fFailedPopup) + retval = MenuInteraction( + menu, menuPrior, pmiExecuteAction, cmenuDeep, fStick); + else + retval = MENU_ABORTED; + cmenuDeep--; + menu->in_use = FALSE; + + if (!fWasAlreadyPopped) + PopDownMenu(menu); + /* FIX: this global is bad */ + menuFromFrameOrWindowOrTitlebar = FALSE; + XFlush(dpy); + + if (cmenuDeep == 0 && x_start >= 0 && y_start >= 0 && + IS_MENU_BUTTON(retval)) { + /* warp pointer back to where invoked if this was brought up + with a keypress and we're returning from a top level menu, + and a button release event didn't end it */ + XWarpPointer(dpy, 0, Scr.Root, 0, 0, Scr.MyDisplayWidth, + Scr.MyDisplayHeight, x_start, y_start); + } + + if (lastTimestamp - t0 < Scr.menus.DoubleClickTime && !mouse_moved && + (!key_press || dkp_timestamp != 0)) { + /* dkp_timestamp is non-zero if a double-keypress occured! */ + fDoubleClick = TRUE; + } + dkp_timestamp = 0; + if (cmenuDeep == 0) { + UngrabEm(); + WaitForButtonsUp(); + if (retval == MENU_DONE || retval == MENU_DONE_BUTTON) { + if (pmiExecuteAction && *pmiExecuteAction && + !fDoubleClick) { + cindirectDeep++; + ExecuteFunction((*pmiExecuteAction)->action, + ButtonWindow, &Event, Context, -1); + cindirectDeep--; + } + fIgnorePosHints = FALSE; + fLastMenuPosHintsValid = FALSE; + } + } + + if (fDoubleClick) + retval = MENU_DOUBLE_CLICKED; + return retval; +} /*********************************************************************** * @@ -294,114 +308,115 @@ MenuStatus do_menu(MenuRoot *menu, MenuRoot *menuPrior, * * Return value is a menu item ***********************************************************************/ -static -MenuItem *FindEntry(int *px_offset /*NULL means don't return this value */) +static MenuItem * +FindEntry(int *px_offset /*NULL means don't return this value */) { - MenuItem *mi; - MenuRoot *mr; - int root_x, root_y; - int x,y; - Window Child; - - /* x_offset returns the x offset of the pointer in the found menu item */ - if (px_offset) - *px_offset = 0; - - XQueryPointer( dpy, Scr.Root, &JunkRoot, &Child, - &root_x,&root_y, &JunkX, &JunkY, &JunkMask); - if (XFindContext (dpy, Child,MenuContext,(caddr_t *)&mr)==XCNOENT) { - return NULL; - } - - /* now get position in that child window */ - XQueryPointer( dpy, Child, &JunkRoot, &JunkChild, - &root_x,&root_y, &x, &y, &JunkMask); - - /* look for the entry that the mouse is in */ - for(mi=mr->first; mi; mi=mi->next) - if(y>=mi->y_offset && y<=mi->y_offset+mi->y_height) - break; - if(xxoffset || x>mr->width+2) - mi = NULL; - - if (mi && px_offset) - *px_offset = x; - - return mi; + MenuItem *mi; + MenuRoot *mr; + int root_x, root_y; + int x, y; + Window Child; + + /* x_offset returns the x offset of the pointer in the found menu item + */ + if (px_offset) + *px_offset = 0; + + XQueryPointer(dpy, Scr.Root, &JunkRoot, &Child, &root_x, &root_y, + &JunkX, &JunkY, &JunkMask); + if (XFindContext(dpy, Child, MenuContext, (caddr_t *)&mr) == XCNOENT) { + return NULL; + } + + /* now get position in that child window */ + XQueryPointer(dpy, Child, &JunkRoot, &JunkChild, &root_x, &root_y, &x, + &y, &JunkMask); + + /* look for the entry that the mouse is in */ + for (mi = mr->first; mi; mi = mi->next) + if (y >= mi->y_offset && y <= mi->y_offset + mi->y_height) + break; + if (x < mr->xoffset || x > mr->width + 2) + mi = NULL; + + if (mi && px_offset) + *px_offset = x; + + return mi; } /* return the appropriate x offset from the prior menu to use as the location of a popup menu */ -static -int PopupPositionOffset(MenuRoot *mr) +static int +PopupPositionOffset(MenuRoot *mr) { - return (mr->width * mr->ms->feel.PopupOffsetPercent / 100 + - mr->ms->feel.PopupOffsetAdd); + return (mr->width * mr->ms->feel.PopupOffsetPercent / 100 + + mr->ms->feel.PopupOffsetAdd); } -static -void GetPreferredPopupPosition(MenuRoot *mr, int *px, int *py) +static void +GetPreferredPopupPosition(MenuRoot *mr, int *px, int *py) { - int menu_x, menu_y; - XGetGeometry(dpy,mr->w,&JunkRoot,&menu_x,&menu_y, - &JunkWidth,&JunkHeight,&JunkBW,&JunkDepth); - *px = menu_x + PopupPositionOffset(mr); - *py = menu_y; - if(mr->selected) { - /* *py = mr->selected->y_offset + menu_y - (mr->ms->look.EntryHeight/2); */ - *py = mr->selected->y_offset + menu_y; - } + int menu_x, menu_y; + XGetGeometry(dpy, mr->w, &JunkRoot, &menu_x, &menu_y, &JunkWidth, + &JunkHeight, &JunkBW, &JunkDepth); + *px = menu_x + PopupPositionOffset(mr); + *py = menu_y; + if (mr->selected) { + /* *py = mr->selected->y_offset + menu_y - + * (mr->ms->look.EntryHeight/2); */ + *py = mr->selected->y_offset + menu_y; + } } - -static -int IndexFromMi(MenuItem *miTarget) +static int +IndexFromMi(MenuItem *miTarget) { - int i = 0; - MenuRoot *mr = miTarget->mr; - MenuItem *mi = mr->first; - for (; mi && mi != miTarget; mi = mi->next) { - if (!IS_TITLE_MENU_ITEM(mi) && !IS_SEPARATOR_MENU_ITEM(mi)) - i++; - } - if (mi == miTarget) { - /* DBUG("IndexFromMi","%s = %d",miTarget->item,i); */ - return i; - } - return -1; + int i = 0; + MenuRoot *mr = miTarget->mr; + MenuItem *mi = mr->first; + for (; mi && mi != miTarget; mi = mi->next) { + if (!IS_TITLE_MENU_ITEM(mi) && !IS_SEPARATOR_MENU_ITEM(mi)) + i++; + } + if (mi == miTarget) { + /* DBUG("IndexFromMi","%s = %d",miTarget->item,i); */ + return i; + } + return -1; } -static -Bool FMenuMapped(MenuRoot *menu) +static Bool +FMenuMapped(MenuRoot *menu) { - XWindowAttributes win_attribs; - XGetWindowAttributes(dpy,menu->w,&win_attribs); - return (menu->w == None) ? False : (win_attribs.map_state == IsViewable); + XWindowAttributes win_attribs; + XGetWindowAttributes(dpy, menu->w, &win_attribs); + return (menu->w == None) ? False : + (win_attribs.map_state == IsViewable); } -static -MenuItem *MiFromMenuIndex(MenuRoot *mr, int index) +static MenuItem * +MiFromMenuIndex(MenuRoot *mr, int index) { - int i = -1; - MenuItem *mi = mr->first; - MenuItem *miLastOk = NULL; - for (; mi && (i < index || miLastOk == NULL); mi=mi->next) { - if (!IS_TITLE_MENU_ITEM(mi) && !IS_SEPARATOR_MENU_ITEM(mi)) { - miLastOk = mi; - i++; - } - } - /* DBUG("MiFromMenuIndex","%d = %s",index,miLastOk->item); */ - return miLastOk; + int i = -1; + MenuItem *mi = mr->first; + MenuItem *miLastOk = NULL; + for (; mi && (i < index || miLastOk == NULL); mi = mi->next) { + if (!IS_TITLE_MENU_ITEM(mi) && !IS_SEPARATOR_MENU_ITEM(mi)) { + miLastOk = mi; + i++; + } + } + /* DBUG("MiFromMenuIndex","%d = %s",index,miLastOk->item); */ + return miLastOk; } -static -int CmiFromMenu(MenuRoot *mr) +static int +CmiFromMenu(MenuRoot *mr) { - return IndexFromMi(mr->last); + return IndexFromMi(mr->last); } - /*********************************************************************** * Procedure * menuShortcuts() - Menu keyboard processing @@ -414,152 +429,154 @@ int CmiFromMenu(MenuRoot *mr) * routine is called. * TKP - uses XLookupString so that keypad numbers work with windowlist ***********************************************************************/ -static -MenuStatus menuShortcuts(MenuRoot *menu,XEvent *Event,MenuItem **pmiCurrent) +static MenuStatus +menuShortcuts(MenuRoot *menu, XEvent *Event, MenuItem **pmiCurrent) { - int fControlKey = Event->xkey.state & ControlMask? TRUE : FALSE; - int fShiftedKey = Event->xkey.state & ShiftMask? TRUE: FALSE; - KeySym keysym; - char keychar; - MenuItem *newItem; - MenuItem *miCurrent = pmiCurrent?*pmiCurrent:NULL; - int index; - - /* handle double-keypress */ - if (dkp_timestamp && - lastTimestamp-dkp_timestamp < Scr.menus.DoubleClickTime && - Event->xkey.state == dkp_keystate && Event->xkey.keycode == dkp_keycode){ - *pmiCurrent = NULL; - return MENU_SELECTED; - } - dkp_timestamp = 0; - /* Is it okay to treat keysym-s as Ascii? */ - /* No, because the keypad numbers don't work. Use XlookupString */ - index = XLookupString(&(Event->xkey), &keychar, 1, &keysym, NULL); - /* Try to match hot keys */ - /* Need isascii here - isgraph might coredump! */ - if (index == 1 && isascii((int)keychar) && isgraph((int)keychar) && - fControlKey == FALSE) { - /* allow any printable character to be a keysym, but be sure control - isn't pressed */ - MenuItem *mi; - char key; - /* Search menu for matching hotkey */ - for (mi = menu->first; mi; mi = mi->next) { - key = tolower(mi->chHotkey); - if (keychar == key) { - *pmiCurrent = mi; - if (IS_POPUP_MENU_ITEM(mi)) - return MENU_POPUP; - else - return MENU_SELECTED; - } - } - } - - switch(keysym) /* Other special keyboard handling */ - { - case XK_Escape: /* Escape key pressed. Abort */ - return MENU_ABORTED; - break; - - case XK_Return: - case XK_KP_Enter: - return MENU_SELECTED; - break; - - case XK_Left: - case XK_KP_4: - case XK_b: /* back */ - case XK_h: /* vi left */ - return MENU_POPDOWN; - break; - - case XK_Right: - case XK_KP_6: - case XK_f: /* forward */ - case XK_l: /* vi right */ - if (IS_POPUP_MENU_ITEM(miCurrent)) - return MENU_POPUP; - break; - - case XK_Up: - case XK_KP_8: - case XK_k: /* vi up */ - case XK_p: /* prior */ - if (!miCurrent) { - if ((*pmiCurrent = menu->last) != NULL) - return MENU_NEWITEM; - else - return MENU_NOP; - } - /* Need isascii here - isgraph might coredump! */ - if (isascii(keysym) && isgraph(keysym)) - fControlKey = FALSE; /* don't use control modifier - for k or p, since those might - be shortcuts too-- C-k, C-p will - always work to do a single up */ - index = IndexFromMi(miCurrent); - if (index == 0) - /* wraparound */ - index = CmiFromMenu(miCurrent->mr); - else if (fShiftedKey) - index = 0; - else { - index -= (fControlKey?5:1); - } - newItem = MiFromMenuIndex(miCurrent->mr,index); - if (newItem) { - *pmiCurrent = newItem; - return MENU_NEWITEM; - } else - return MENU_NOP; - break; - - case XK_Down: - case XK_KP_2: - case XK_j: /* vi down */ - case XK_n: /* next */ - if (!miCurrent) { - if ((*pmiCurrent = MiFromMenuIndex(menu,0)) != NULL) - return MENU_NEWITEM; - else - return MENU_NOP; - } - /* Need isascii here - isgraph might coredump! */ - if (isascii(keysym) && isgraph(keysym)) - fControlKey = FALSE; /* don't use control modifier - for j or n, since those might - be shortcuts too-- C-j, C-n will - always work to do a single down */ - if (fShiftedKey) - index = CmiFromMenu(miCurrent->mr); - else { - index = IndexFromMi(miCurrent) + (fControlKey?5:1); - /* correct for the case that we're between items */ - if (IS_SEPARATOR_MENU_ITEM(miCurrent) || - IS_TITLE_MENU_ITEM(miCurrent)) - index--; - } - newItem = MiFromMenuIndex(miCurrent->mr,index); - if (newItem == miCurrent) - newItem = MiFromMenuIndex(miCurrent->mr,0); - if (newItem) { - *pmiCurrent = newItem; - return MENU_NEWITEM; - } else - return MENU_NOP; - break; + int fControlKey = Event->xkey.state & ControlMask ? TRUE : FALSE; + int fShiftedKey = Event->xkey.state & ShiftMask ? TRUE : FALSE; + KeySym keysym; + char keychar; + MenuItem *newItem; + MenuItem *miCurrent = pmiCurrent ? *pmiCurrent : NULL; + int index; + + /* handle double-keypress */ + if (dkp_timestamp && + lastTimestamp - dkp_timestamp < Scr.menus.DoubleClickTime && + Event->xkey.state == dkp_keystate && + Event->xkey.keycode == dkp_keycode) { + *pmiCurrent = NULL; + return MENU_SELECTED; + } + dkp_timestamp = 0; + /* Is it okay to treat keysym-s as Ascii? */ + /* No, because the keypad numbers don't work. Use XlookupString */ + index = XLookupString(&(Event->xkey), &keychar, 1, &keysym, NULL); + /* Try to match hot keys */ + /* Need isascii here - isgraph might coredump! */ + if (index == 1 && isascii((int)keychar) && isgraph((int)keychar) && + fControlKey == FALSE) { + /* allow any printable character to be a keysym, but be sure + control isn't pressed */ + MenuItem *mi; + char key; + /* Search menu for matching hotkey */ + for (mi = menu->first; mi; mi = mi->next) { + key = tolower(mi->chHotkey); + if (keychar == key) { + *pmiCurrent = mi; + if (IS_POPUP_MENU_ITEM(mi)) + return MENU_POPUP; + else + return MENU_SELECTED; + } + } + } - /* Nothing special --- Allow other shortcuts */ - default: - /* There are no useful shortcuts, so don't do that. - * (Dominik Vogt, 11-Nov-1998) - * Keyboard_shortcuts(Event, NULL, ButtonRelease); */ - break; - } + switch (keysym) { /* Other special keyboard handling */ + case XK_Escape: /* Escape key pressed. Abort */ + return MENU_ABORTED; + break; + + case XK_Return: + case XK_KP_Enter: + return MENU_SELECTED; + break; + + case XK_Left: + case XK_KP_4: + case XK_b: /* back */ + case XK_h: /* vi left */ + return MENU_POPDOWN; + break; + + case XK_Right: + case XK_KP_6: + case XK_f: /* forward */ + case XK_l: /* vi right */ + if (IS_POPUP_MENU_ITEM(miCurrent)) + return MENU_POPUP; + break; + + case XK_Up: + case XK_KP_8: + case XK_k: /* vi up */ + case XK_p: /* prior */ + if (!miCurrent) { + if ((*pmiCurrent = menu->last) != NULL) + return MENU_NEWITEM; + else + return MENU_NOP; + } + /* Need isascii here - isgraph might coredump! */ + if (isascii(keysym) && isgraph(keysym)) + fControlKey = + FALSE; /* don't use control modifier + for k or p, since those might + be shortcuts too-- C-k, C-p will + always work to do a single up */ + index = IndexFromMi(miCurrent); + if (index == 0) + /* wraparound */ + index = CmiFromMenu(miCurrent->mr); + else if (fShiftedKey) + index = 0; + else { + index -= (fControlKey ? 5 : 1); + } + newItem = MiFromMenuIndex(miCurrent->mr, index); + if (newItem) { + *pmiCurrent = newItem; + return MENU_NEWITEM; + } else + return MENU_NOP; + break; + + case XK_Down: + case XK_KP_2: + case XK_j: /* vi down */ + case XK_n: /* next */ + if (!miCurrent) { + if ((*pmiCurrent = MiFromMenuIndex(menu, 0)) != NULL) + return MENU_NEWITEM; + else + return MENU_NOP; + } + /* Need isascii here - isgraph might coredump! */ + if (isascii(keysym) && isgraph(keysym)) + fControlKey = + FALSE; /* don't use control modifier + for j or n, since those might + be shortcuts too-- C-j, C-n will + always work to do a single down */ + if (fShiftedKey) + index = CmiFromMenu(miCurrent->mr); + else { + index = IndexFromMi(miCurrent) + (fControlKey ? 5 : 1); + /* correct for the case that we're between items */ + if (IS_SEPARATOR_MENU_ITEM(miCurrent) || + IS_TITLE_MENU_ITEM(miCurrent)) + index--; + } + newItem = MiFromMenuIndex(miCurrent->mr, index); + if (newItem == miCurrent) + newItem = MiFromMenuIndex(miCurrent->mr, 0); + if (newItem) { + *pmiCurrent = newItem; + return MENU_NEWITEM; + } else + return MENU_NOP; + break; + + /* Nothing special --- Allow other shortcuts */ + default: + /* There are no useful shortcuts, so don't do that. + * (Dominik Vogt, 11-Nov-1998) + * Keyboard_shortcuts(Event, NULL, ButtonRelease); */ + break; + } - return MENU_NOP; + return MENU_NOP; } #define MICRO_S_FOR_10MS 10000 @@ -584,510 +601,564 @@ MenuStatus menuShortcuts(MenuRoot *menu,XEvent *Event,MenuItem **pmiCurrent) * *pmiExecuteAction * ***********************************************************************/ -static -MenuStatus MenuInteraction(MenuRoot *menu,MenuRoot *menuPrior, - MenuItem **pmiExecuteAction,int cmenuDeep, - Bool fSticks) +static MenuStatus +MenuInteraction(MenuRoot *menu, MenuRoot *menuPrior, + MenuItem **pmiExecuteAction, int cmenuDeep, Bool fSticks) { - Bool fPopupImmediately; - MenuItem *mi = NULL, *tmi; - MenuRoot *mrPopup = NULL; - MenuRoot *mrMiPopup = NULL; - MenuRoot *mrNeedsPainting = NULL; - Bool fDoPopupNow = FALSE; /* used for delay popups, to just popup the menu */ - Bool fPopupAndWarp = FALSE; /* used for keystrokes, to popup and move to - * that menu */ - Bool fKeyPress = FALSE; - Bool fForceReposition = TRUE; - int x_init = 0, y_init = 0; - int x_offset = 0; - MenuStatus retval = MENU_NOP; - int c10msDelays = 0; - MenuOptions mops; - Bool fOffMenuAllowed = FALSE; - Bool fPopdown = FALSE; - Bool fPopup = FALSE; - Bool fDoMenu = FALSE; - Bool fMotionFirst = FALSE; - Bool fReleaseFirst = FALSE; - Bool fFakedMotion = FALSE; - Bool fSubmenuOverlaps = False; - - mops.flags.allflags = 0; - fPopupImmediately = (menu->ms->feel.f.PopupImmediately && - (Scr.menus.PopupDelay10ms > 0)); - - /* remember where the pointer was so we can tell if it has moved */ - XQueryPointer( dpy, Scr.Root, &JunkRoot, &JunkChild, - &x_init, &y_init, &JunkX, &JunkY, &JunkMask); - - while (TRUE) { - fPopupAndWarp = FALSE; - fDoPopupNow = FALSE; - fKeyPress = FALSE; - if (fForceReposition) { - Event.type = MotionNotify; - Event.xmotion.time = lastTimestamp; - fFakedMotion = TRUE; - fForceReposition = FALSE; - } else if (!XCheckMaskEvent(dpy,ExposureMask,&Event)) { - /* handle exposure events first */ - if (Scr.menus.PopupDelay10ms > 0) { - while (XCheckMaskEvent(dpy, - ButtonPressMask|ButtonReleaseMask| - ExposureMask|KeyPressMask| - VisibilityChangeMask|ButtonMotionMask, - &Event) == FALSE) { - usleep(MICRO_S_FOR_10MS); - if (c10msDelays++ == Scr.menus.PopupDelay10ms) { - DBUG("MenuInteraction","Faking motion"); - /* fake a motion event, and set fDoPopupNow */ - Event.type = MotionNotify; - Event.xmotion.time = lastTimestamp; - fFakedMotion = TRUE; - fDoPopupNow = TRUE; - break; - } - } - } else { /* block until there is an event */ - XMaskEvent(dpy, - ButtonPressMask|ButtonReleaseMask|ExposureMask | - KeyPressMask|VisibilityChangeMask|ButtonMotionMask, - &Event); - } - } - /*DBUG("MenuInteraction","mrPopup=%s",mrPopup?mrPopup->name:"(none)");*/ - - StashEventTime(&Event); - if (Event.type == MotionNotify) { - /* discard any extra motion events before a release */ - while((XCheckMaskEvent(dpy,ButtonMotionMask|ButtonReleaseMask, - &Event))&&(Event.type != ButtonRelease)); - } - - switch(Event.type) - { - case ButtonRelease: - mi = FindEntry(&x_offset); - /* hold the menu up when the button is released - for the first time if released OFF of the menu */ - if(fSticks && !fMotionFirst) { - fReleaseFirst = TRUE; - fSticks = FALSE; - continue; - /* break; */ - } - retval = mi?MENU_SELECTED:MENU_ABORTED; - dkp_timestamp = 0; - goto DO_RETURN; - - case ButtonPress: - /* if the first event is a button press allow the release to - select something */ - fSticks = FALSE; - continue; - - case VisibilityNotify: - continue; - - case KeyPress: - /* Handle a key press events to allow mouseless operation */ - fKeyPress = TRUE; - x_offset = 0; - retval = menuShortcuts(menu,&Event,&mi); - if (retval == MENU_POPDOWN || - retval == MENU_ABORTED || - retval == MENU_SELECTED) - goto DO_RETURN; - /* now warp to the new menu-item, if any */ - if (mi && mi != FindEntry(NULL)) { - MiWarpPointerToItem(mi,FALSE); - /* DBUG("MenuInteraction","Warping on keystroke to %s",mi->item);*/ - } - if (retval == MENU_POPUP && IS_POPUP_MENU_ITEM(mi)) { - fPopupAndWarp = TRUE; - DBUG("MenuInteraction","fPopupAndWarp = TRUE"); - break; - } - break; - - case MotionNotify: - if (mouse_moved == FALSE) { - int x_root, y_root; - XQueryPointer( dpy, Scr.Root, &JunkRoot, &JunkChild, - &x_root,&y_root, &JunkX, &JunkY, &JunkMask); - if(x_root-x_init > 3 || x_init-x_root > 3 || - y_root-y_init > 3 || y_init-y_root > 3) { - /* global variable remember that this isn't just - a click any more since the pointer moved */ - mouse_moved = TRUE; - } - } - mi = FindEntry(&x_offset); - if (!fReleaseFirst && !fFakedMotion && mouse_moved) - fMotionFirst = TRUE; - fFakedMotion = FALSE; - break; - - case Expose: - /* grab our expose events, let the rest go through */ - if((XFindContext(dpy, Event.xany.window,MenuContext, - (caddr_t *)&mrNeedsPainting)!=XCNOENT)) { - flush_expose(Event.xany.window); - PaintMenu(mrNeedsPainting,&Event); - } - /* continue; */ /* instead of continuing, we want to - dispatch this too by letting it fall - through so window decorations get redrawn - after being obscured by menus */ - s_Tmp_win = Tmp_win; /* BUT we need to save Tmp_win first - because DispatchEvent changes - Tmp_win and messes up our calls to - check_allowed_function for stippling - disallowed menu items */ - - default: - DispatchEvent(); - if (s_Tmp_win) - { - Tmp_win = s_Tmp_win; /* restore Tmp_win */ - s_Tmp_win = NULL; - continue; /* now 'continue' if event was an expose */ - } - break; - } /* switch (Event.type) */ - - /* Now handle new menu items, whether it is from a keypress or - a pointer motion event */ - if (mi) { - /* we're on a menu item */ - fOffMenuAllowed = FALSE; - mrMiPopup = MrPopupForMi(mi); - if (mi->mr != menu && mi->mr != mrPopup && mi->mr != mrMiPopup) { - /* we're on an item from a prior menu */ - /* DBUG("MenuInteraction","menu %s: returning popdown",menu->name);*/ - retval = MENU_POPDOWN; - dkp_timestamp = 0; - goto DO_RETURN; - } - - /* see if we're on a new item of this menu */ - if (mi != menu->selected && mi->mr == menu) { - c10msDelays = 0; - /* we're on the same menu, but a different item, - so we need to unselect the old item */ - if (menu->selected) { - /* something else was already selected on this menu */ - if (mrPopup) { - PopDownAndRepaintParent(mrPopup, &fSubmenuOverlaps); - mrPopup = NULL; - } - /* We have to pop down the menu before unselecting the item in case - * we are using gradient menus. The recalled image would paint over - * the submenu. */ - SetMenuItemSelected(menu->selected,FALSE); - } else { - /* DBUG("MenuInteraction","Menu %s had nothing else selected", - menu->name); */ - } - /* do stuff to highlight the new item; this - sets menu->selected, too */ - SetMenuItemSelected(mi,TRUE); - } /* new item of the same menu */ - - /* check what has to be done with the item */ - fPopdown = FALSE; - fPopup = FALSE; - fDoMenu = FALSE; - - if (mi->mr == mrPopup) { - /* must make current popup menu a real menu */ - fDoMenu = TRUE; - } - else if (fPopupAndWarp) { - /* must create a real menu and warp into it */ - if (mrPopup == NULL || mrPopup != mrMiPopup) { - fPopup = TRUE; - } else { - XRaiseWindow(dpy, mrPopup->w); - MiWarpPointerToItem(mrPopup->first,TRUE); - fDoMenu = TRUE; - } - } - else if (IS_POPUP_MENU_ITEM(mi)) { - if (x_offset >= mi->mr->width*3/4 || fDoPopupNow || - fPopupImmediately) { - /* must create a new menu or popup */ - if (mrPopup == NULL || mrPopup != mrMiPopup) - fPopup = TRUE; - else if (fPopupAndWarp) - MiWarpPointerToItem(mrPopup->first,TRUE); - } - } /* else if (IS_POPUP_MENU_ITEM(mi)) */ - if (fPopup && mrPopup && mrPopup != mrMiPopup) { - /* must remove previous popup first */ - fPopdown = TRUE; - } - - if (fPopdown) { - DBUG("MenuInteraction","Popping down"); - /* popdown previous popup */ - if (mrPopup) { - PopDownAndRepaintParent(mrPopup, &fSubmenuOverlaps); - } - mrPopup = NULL; - fPopdown = FALSE; - } - if (fPopup) { - DBUG("MenuInteraction","Popping up"); - /* get pos hints for item's action */ - GetPopupOptions(mi,&mops); - mrPopup = mrMiPopup; - if (!mrPopup) { - fDoMenu = FALSE; - fPopdown = FALSE; - } else { - /* create a popup menu */ - if (!FMenuMapped(mrPopup)) { - /* We want to pop prepop menus so it doesn't *have* to be - unpopped; do_menu pops down any menus it pops up, but we - want to be able to popdown w/o actually removing the menu */ - int x, y; - if (mops.flags.f.has_poshints) { - x = mops.pos_hints.x + mops.pos_hints.x_factor*mrPopup->width; - y = mops.pos_hints.y + mops.pos_hints.y_factor*mrPopup->height; - } else { - GetPreferredPopupPosition(menu,&x,&y); - } - FPopupMenu(mrPopup, menu, x, y, fPopupAndWarp, &mops, - &fSubmenuOverlaps); - } - if (mrPopup->mrDynamicPrev == menu) { - mi = FindEntry(NULL); - if (mi && mi->mr == mrPopup) { - fDoMenu = TRUE; - fPopdown = !menu->ms->feel.f.PopupImmediately; - } - } - else { - /* This menu must be already mapped somewhere else, so ignore - * it completely. */ - fDoMenu = FALSE; - fPopdown = FALSE; - mrPopup = NULL; - } - } /* if (!mrPopup) */ - } /* if (fPopup) */ - if (fDoMenu) { - /* recursively do the new menu we've moved into */ - retval = do_menu(mrPopup,menu,pmiExecuteAction,cmenuDeep,FALSE, - (fPopupAndWarp) ? (XEvent *)1 : NULL, &mops); - if (IS_MENU_RETURN(retval)) { - dkp_timestamp = 0; - goto DO_RETURN; - } - if (fPopdown || !menu->ms->feel.f.PopupImmediately) { - PopDownAndRepaintParent(mrPopup, &fSubmenuOverlaps); - mrPopup = NULL; - } - if (retval == MENU_POPDOWN) { - c10msDelays = 0; - fForceReposition = TRUE; - } - } /* if (fDoMenu) */ - - /* Now check whether we can animate the current popup menu - over to the right to unobscure the current menu; this - happens only when using animation */ - tmi = FindEntry(NULL); - if (mrPopup && mrPopup->xanimation && tmi && - (tmi == menu->selected || tmi->mr != menu)) { - int x_popup, y_popup; - DBUG("MenuInteraction","Moving the popup menu back over"); - XGetGeometry(dpy, mrPopup->w, &JunkRoot, &x_popup, &y_popup, - &JunkWidth, &JunkHeight, &JunkBW, &JunkDepth); - /* move it back */ - AnimatedMoveOfWindow(mrPopup->w,x_popup,y_popup, - x_popup-mrPopup->xanimation, y_popup, - FALSE /* no warp ptr */,-1,NULL); - mrPopup->xanimation = 0; - } - /* now check whether we should animate the current real menu - over to the right to unobscure the prior menu; only a very - limited case where this might be helpful and not too disruptive */ - if (mrPopup == NULL && menuPrior != NULL && menu->xanimation != 0 && - x_offset < menu->width/4) { - int x_menu, y_menu; - DBUG("MenuInteraction","Moving the menu back over"); - /* we have to see if we need menu to be moved */ - XGetGeometry( dpy, menu->w, &JunkRoot, &x_menu, &y_menu, - &JunkWidth, &JunkHeight, &JunkBW, &JunkDepth); - /* move it back */ - AnimatedMoveOfWindow(menu->w,x_menu,y_menu, - x_menu - menu->xanimation,y_menu, - TRUE /* warp ptr */,-1,NULL); - menu->xanimation = 0; - } + Bool fPopupImmediately; + MenuItem *mi = NULL, *tmi; + MenuRoot *mrPopup = NULL; + MenuRoot *mrMiPopup = NULL; + MenuRoot *mrNeedsPainting = NULL; + Bool fDoPopupNow = + FALSE; /* used for delay popups, to just popup the menu */ + Bool fPopupAndWarp = FALSE; /* used for keystrokes, to popup and move to + * that menu */ + Bool fKeyPress = FALSE; + Bool fForceReposition = TRUE; + int x_init = 0, y_init = 0; + int x_offset = 0; + MenuStatus retval = MENU_NOP; + int c10msDelays = 0; + MenuOptions mops; + Bool fOffMenuAllowed = FALSE; + Bool fPopdown = FALSE; + Bool fPopup = FALSE; + Bool fDoMenu = FALSE; + Bool fMotionFirst = FALSE; + Bool fReleaseFirst = FALSE; + Bool fFakedMotion = FALSE; + Bool fSubmenuOverlaps = False; + + mops.flags.allflags = 0; + fPopupImmediately = (menu->ms->feel.f.PopupImmediately && + (Scr.menus.PopupDelay10ms > 0)); + + /* remember where the pointer was so we can tell if it has moved */ + XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, &x_init, &y_init, + &JunkX, &JunkY, &JunkMask); + + while (TRUE) { + fPopupAndWarp = FALSE; + fDoPopupNow = FALSE; + fKeyPress = FALSE; + if (fForceReposition) { + Event.type = MotionNotify; + Event.xmotion.time = lastTimestamp; + fFakedMotion = TRUE; + fForceReposition = FALSE; + } else if (!XCheckMaskEvent(dpy, ExposureMask, &Event)) { + /* handle exposure events first */ + if (Scr.menus.PopupDelay10ms > 0) { + while (XCheckMaskEvent(dpy, + ButtonPressMask | ButtonReleaseMask | + ExposureMask | KeyPressMask | + VisibilityChangeMask | + ButtonMotionMask, + &Event) == FALSE) { + usleep(MICRO_S_FOR_10MS); + if (c10msDelays++ == + Scr.menus.PopupDelay10ms) { + DBUG("MenuInteraction", + "Faking motion"); + /* fake a motion event, and set + * fDoPopupNow */ + Event.type = MotionNotify; + Event.xmotion.time = + lastTimestamp; + fFakedMotion = TRUE; + fDoPopupNow = TRUE; + break; + } + } + } else { /* block until there is an event */ + XMaskEvent(dpy, + ButtonPressMask | ButtonReleaseMask | + ExposureMask | KeyPressMask | + VisibilityChangeMask | ButtonMotionMask, + &Event); + } + } + /*DBUG("MenuInteraction","mrPopup=%s",mrPopup?mrPopup->name:"(none)");*/ + + StashEventTime(&Event); + if (Event.type == MotionNotify) { + /* discard any extra motion events before a release */ + while ((XCheckMaskEvent(dpy, + ButtonMotionMask | ButtonReleaseMask, + &Event)) && + (Event.type != ButtonRelease)) + ; + } - } /* if (mi) */ - else { - /* moved off menu, deselect selected item... */ - if (menu->selected) { - SetMenuItemSelected(menu->selected,FALSE); - if (mrPopup && fOffMenuAllowed == FALSE) { - int x, y, mx, my; - unsigned int mw, mh; - XQueryPointer( dpy, Scr.Root, &JunkRoot, &JunkChild, - &x, &y, &JunkX, &JunkY, &JunkMask); - XGetGeometry( dpy, menu->w, &JunkRoot, &mx, &my, - &mw, &mh, &JunkBW, &JunkDepth); - if ((!IS_LEFT_MENU(mrPopup) && x < mx) || - (!IS_RIGHT_MENU(mrPopup) && x > mx+mw) || - (!IS_UP_MENU(mrPopup) && y < my) || - (!IS_DOWN_MENU(mrPopup) && y > my+mh)) { - PopDownAndRepaintParent(mrPopup, &fSubmenuOverlaps); - mrPopup = NULL; - } else { - fOffMenuAllowed = TRUE; - } - } /* if (mrPopup && fOffMenuAllowed == FALSE) */ - } /* if (menu->selected) */ - } /* else (!mi) */ - XFlush(dpy); - } /* while (TRUE) */ - - DO_RETURN: - if (mrPopup) { - PopDownAndRepaintParent(mrPopup, &fSubmenuOverlaps); - } - if (retval == MENU_POPDOWN) { - if (menu->selected) - SetMenuItemSelected(menu->selected,FALSE); - if (fKeyPress) { - if (cmenuDeep == 1) - /* abort a root menu rather than pop it down */ - retval = MENU_ABORTED; - if (menuPrior && menuPrior->selected) { - MiWarpPointerToItem(menuPrior->selected, FALSE); - if (menuPrior->selected != FindEntry(NULL) && - menu->xanimation == 0) { - XRaiseWindow(dpy, menuPrior->w); + switch (Event.type) { + case ButtonRelease: + mi = FindEntry(&x_offset); + /* hold the menu up when the button is released + for the first time if released OFF of the menu */ + if (fSticks && !fMotionFirst) { + fReleaseFirst = TRUE; + fSticks = FALSE; + continue; + /* break; */ + } + retval = mi ? MENU_SELECTED : MENU_ABORTED; + dkp_timestamp = 0; + goto DO_RETURN; + + case ButtonPress: + /* if the first event is a button press allow the + release to select something */ + fSticks = FALSE; + continue; + + case VisibilityNotify: + continue; + + case KeyPress: + /* Handle a key press events to allow mouseless + * operation */ + fKeyPress = TRUE; + x_offset = 0; + retval = menuShortcuts(menu, &Event, &mi); + if (retval == MENU_POPDOWN || retval == MENU_ABORTED || + retval == MENU_SELECTED) + goto DO_RETURN; + /* now warp to the new menu-item, if any */ + if (mi && mi != FindEntry(NULL)) { + MiWarpPointerToItem(mi, FALSE); + /* DBUG("MenuInteraction","Warping on keystroke + * to %s",mi->item);*/ + } + if (retval == MENU_POPUP && IS_POPUP_MENU_ITEM(mi)) { + fPopupAndWarp = TRUE; + DBUG("MenuInteraction", "fPopupAndWarp = TRUE"); + break; + } + break; + + case MotionNotify: + if (mouse_moved == FALSE) { + int x_root, y_root; + XQueryPointer(dpy, Scr.Root, &JunkRoot, + &JunkChild, &x_root, &y_root, &JunkX, + &JunkY, &JunkMask); + if (x_root - x_init > 3 || + x_init - x_root > 3 || + y_root - y_init > 3 || + y_init - y_root > 3) { + /* global variable remember that this + isn't just a click any more since the + pointer moved */ + mouse_moved = TRUE; + } + } + mi = FindEntry(&x_offset); + if (!fReleaseFirst && !fFakedMotion && mouse_moved) + fMotionFirst = TRUE; + fFakedMotion = FALSE; + break; + + case Expose: + /* grab our expose events, let the rest go through */ + if ((XFindContext(dpy, Event.xany.window, MenuContext, + (caddr_t *)&mrNeedsPainting) != XCNOENT)) { + flush_expose(Event.xany.window); + PaintMenu(mrNeedsPainting, &Event); + } + /* continue; */ /* instead of continuing, we want to + dispatch this too by letting it fall + through so window decorations get redrawn + after being obscured by menus */ + s_Tmp_win = + Tmp_win; /* BUT we need to save Tmp_win first + because DispatchEvent changes + Tmp_win and messes up our calls to + check_allowed_function for stippling + disallowed menu items */ + + default: + DispatchEvent(); + if (s_Tmp_win) { + Tmp_win = s_Tmp_win; /* restore Tmp_win */ + s_Tmp_win = NULL; + continue; /* now 'continue' if event was an + expose */ + } + break; + } /* switch (Event.type) */ + + /* Now handle new menu items, whether it is from a keypress or + a pointer motion event */ + if (mi) { + /* we're on a menu item */ + fOffMenuAllowed = FALSE; + mrMiPopup = MrPopupForMi(mi); + if (mi->mr != menu && mi->mr != mrPopup && + mi->mr != mrMiPopup) { + /* we're on an item from a prior menu */ + /* DBUG("MenuInteraction","menu %s: returning + * popdown",menu->name);*/ + retval = MENU_POPDOWN; + dkp_timestamp = 0; + goto DO_RETURN; + } + + /* see if we're on a new item of this menu */ + if (mi != menu->selected && mi->mr == menu) { + c10msDelays = 0; + /* we're on the same menu, but a different item, + so we need to unselect the old item */ + if (menu->selected) { + /* something else was already selected + * on this menu */ + if (mrPopup) { + PopDownAndRepaintParent( + mrPopup, &fSubmenuOverlaps); + mrPopup = NULL; + } + /* We have to pop down the menu before + * unselecting the item in case we are + * using gradient menus. The recalled + * image would paint over the submenu. + */ + SetMenuItemSelected( + menu->selected, FALSE); + } else { + /* DBUG("MenuInteraction","Menu %s had + nothing else selected", menu->name); + */ + } + /* do stuff to highlight the new item; this + sets menu->selected, too */ + SetMenuItemSelected(mi, TRUE); + } /* new item of the same menu */ + + /* check what has to be done with the item */ + fPopdown = FALSE; + fPopup = FALSE; + fDoMenu = FALSE; + + if (mi->mr == mrPopup) { + /* must make current popup menu a real menu */ + fDoMenu = TRUE; + } else if (fPopupAndWarp) { + /* must create a real menu and warp into it */ + if (mrPopup == NULL || mrPopup != mrMiPopup) { + fPopup = TRUE; + } else { + XRaiseWindow(dpy, mrPopup->w); + MiWarpPointerToItem( + mrPopup->first, TRUE); + fDoMenu = TRUE; + } + } else if (IS_POPUP_MENU_ITEM(mi)) { + if (x_offset >= mi->mr->width * 3 / 4 || + fDoPopupNow || fPopupImmediately) { + /* must create a new menu or popup */ + if (mrPopup == NULL || + mrPopup != mrMiPopup) + fPopup = TRUE; + else if (fPopupAndWarp) + MiWarpPointerToItem( + mrPopup->first, TRUE); + } + } /* else if (IS_POPUP_MENU_ITEM(mi)) */ + if (fPopup && mrPopup && mrPopup != mrMiPopup) { + /* must remove previous popup first */ + fPopdown = TRUE; + } + + if (fPopdown) { + DBUG("MenuInteraction", "Popping down"); + /* popdown previous popup */ + if (mrPopup) { + PopDownAndRepaintParent( + mrPopup, &fSubmenuOverlaps); + } + mrPopup = NULL; + fPopdown = FALSE; + } + if (fPopup) { + DBUG("MenuInteraction", "Popping up"); + /* get pos hints for item's action */ + GetPopupOptions(mi, &mops); + mrPopup = mrMiPopup; + if (!mrPopup) { + fDoMenu = FALSE; + fPopdown = FALSE; + } else { + /* create a popup menu */ + if (!FMenuMapped(mrPopup)) { + /* We want to pop prepop menus + so it doesn't *have* to be + unpopped; do_menu pops down + any menus it pops up, but we + want to be able to popdown + w/o actually removing the + menu */ + int x, y; + if (mops.flags.f.has_poshints) { + x = mops.pos_hints.x + + mops.pos_hints + .x_factor * + mrPopup->width; + y = mops.pos_hints.y + + mops.pos_hints + .y_factor * + mrPopup->height; + } else { + GetPreferredPopupPosition( + menu, + &x, &y); + } + FPopupMenu(mrPopup, menu, x, y, + fPopupAndWarp, &mops, + &fSubmenuOverlaps); + } + if (mrPopup->mrDynamicPrev == menu) { + mi = FindEntry(NULL); + if (mi && mi->mr == mrPopup) { + fDoMenu = TRUE; + fPopdown = + !menu->ms->feel.f + .PopupImmediately; + } + } else { + /* This menu must be already + * mapped somewhere else, so + * ignore it completely. */ + fDoMenu = FALSE; + fPopdown = FALSE; + mrPopup = NULL; + } + } /* if (!mrPopup) */ + } /* if (fPopup) */ + if (fDoMenu) { + /* recursively do the new menu we've moved into + */ + retval = do_menu(mrPopup, menu, + pmiExecuteAction, cmenuDeep, FALSE, + (fPopupAndWarp) ? (XEvent *)1 : NULL, + &mops); + if (IS_MENU_RETURN(retval)) { + dkp_timestamp = 0; + goto DO_RETURN; + } + if (fPopdown || + !menu->ms->feel.f.PopupImmediately) { + PopDownAndRepaintParent( + mrPopup, &fSubmenuOverlaps); + mrPopup = NULL; + } + if (retval == MENU_POPDOWN) { + c10msDelays = 0; + fForceReposition = TRUE; + } + } /* if (fDoMenu) */ + + /* Now check whether we can animate the current popup + menu over to the right to unobscure the current menu; + this happens only when using animation */ + tmi = FindEntry(NULL); + if (mrPopup && mrPopup->xanimation && tmi && + (tmi == menu->selected || tmi->mr != menu)) { + int x_popup, y_popup; + DBUG("MenuInteraction", + "Moving the popup menu back over"); + XGetGeometry(dpy, mrPopup->w, &JunkRoot, + &x_popup, &y_popup, &JunkWidth, &JunkHeight, + &JunkBW, &JunkDepth); + /* move it back */ + AnimatedMoveOfWindow(mrPopup->w, x_popup, + y_popup, x_popup - mrPopup->xanimation, + y_popup, FALSE /* no warp ptr */, -1, NULL); + mrPopup->xanimation = 0; + } + /* now check whether we should animate the current real + menu over to the right to unobscure the prior menu; + only a very limited case where this might be helpful + and not too disruptive */ + if (mrPopup == NULL && menuPrior != NULL && + menu->xanimation != 0 && + x_offset < menu->width / 4) { + int x_menu, y_menu; + DBUG("MenuInteraction", + "Moving the menu back over"); + /* we have to see if we need menu to be moved */ + XGetGeometry(dpy, menu->w, &JunkRoot, &x_menu, + &y_menu, &JunkWidth, &JunkHeight, &JunkBW, + &JunkDepth); + /* move it back */ + AnimatedMoveOfWindow(menu->w, x_menu, y_menu, + x_menu - menu->xanimation, y_menu, + TRUE /* warp ptr */, -1, NULL); + menu->xanimation = 0; + } + + } /* if (mi) */ else { + /* moved off menu, deselect selected item... */ + if (menu->selected) { + SetMenuItemSelected(menu->selected, FALSE); + if (mrPopup && fOffMenuAllowed == FALSE) { + int x, y, mx, my; + unsigned int mw, mh; + XQueryPointer(dpy, Scr.Root, &JunkRoot, + &JunkChild, &x, &y, &JunkX, &JunkY, + &JunkMask); + XGetGeometry(dpy, menu->w, &JunkRoot, + &mx, &my, &mw, &mh, &JunkBW, + &JunkDepth); + if ((!IS_LEFT_MENU(mrPopup) && + x < mx) || + (!IS_RIGHT_MENU(mrPopup) && + x > mx + mw) || + (!IS_UP_MENU(mrPopup) && y < my) || + (!IS_DOWN_MENU(mrPopup) && + y > my + mh)) { + PopDownAndRepaintParent( + mrPopup, &fSubmenuOverlaps); + mrPopup = NULL; + } else { + fOffMenuAllowed = TRUE; + } + } /* if (mrPopup && fOffMenuAllowed == FALSE) */ + } /* if (menu->selected) */ + } /* else (!mi) */ + XFlush(dpy); + } /* while (TRUE) */ + +DO_RETURN: + if (mrPopup) { + PopDownAndRepaintParent(mrPopup, &fSubmenuOverlaps); } - } - } - /* DBUG("MenuInteraction","Prior menu has %s selected", - menuPrior?(menuPrior->selected? - menuPrior->selected->item:"(no selected item)"):"(no prior menu)"); */ - } else if (retval == MENU_SELECTED) { - /* DBUG("MenuInteraction","Got MENU_SELECTED for menu %s, on item %s", - menu->name,mi->item); */ - *pmiExecuteAction = mi; - retval = MENU_ADD_BUTTON_IF(fKeyPress,MENU_DONE); - } - if ((retval == MENU_DONE || retval == MENU_DONE_BUTTON) && - pmiExecuteAction && *pmiExecuteAction && (*pmiExecuteAction)->action) { - switch ((*pmiExecuteAction)->func_type) - { - case F_POPUP: - case F_STAYSUP: - case F_WINDOWLIST: - GetPopupOptions(mi, &mops); - if (!(mops.flags.f.select_in_place)) { - fIgnorePosHints = TRUE; - } else { - if (mops.flags.f.has_poshints) { - lastMenuPosHints = mops.pos_hints; - } else { - GetPreferredPopupPosition( - menu, &lastMenuPosHints.x, &lastMenuPosHints.y); - lastMenuPosHints.x_factor = 0; - lastMenuPosHints.y_factor = 0; - lastMenuPosHints.fRelative = FALSE; - } - fLastMenuPosHintsValid = TRUE; - if (mops.flags.f.select_warp) { - fWarpPointerToTitle = TRUE; + if (retval == MENU_POPDOWN) { + if (menu->selected) + SetMenuItemSelected(menu->selected, FALSE); + if (fKeyPress) { + if (cmenuDeep == 1) + /* abort a root menu rather than pop it down */ + retval = MENU_ABORTED; + if (menuPrior && menuPrior->selected) { + MiWarpPointerToItem(menuPrior->selected, FALSE); + if (menuPrior->selected != FindEntry(NULL) && + menu->xanimation == 0) { + XRaiseWindow(dpy, menuPrior->w); + } + } + } + /* DBUG("MenuInteraction","Prior menu has %s selected", + menuPrior?(menuPrior->selected? + menuPrior->selected->item:"(no selected item)"):"(no prior + menu)"); */ + } else if (retval == MENU_SELECTED) { + /* DBUG("MenuInteraction","Got MENU_SELECTED for menu %s, on + item %s", menu->name,mi->item); */ + *pmiExecuteAction = mi; + retval = MENU_ADD_BUTTON_IF(fKeyPress, MENU_DONE); } - } /* else (mops.flags.f.select_in_place) */ - break; - default: - break; - } - } /* ((retval == MENU_DONE ||... */ - return MENU_ADD_BUTTON_IF(fKeyPress,retval); + if ((retval == MENU_DONE || retval == MENU_DONE_BUTTON) && + pmiExecuteAction && *pmiExecuteAction && + (*pmiExecuteAction)->action) { + switch ((*pmiExecuteAction)->func_type) { + case F_POPUP: + case F_STAYSUP: + case F_WINDOWLIST: + GetPopupOptions(mi, &mops); + if (!(mops.flags.f.select_in_place)) { + fIgnorePosHints = TRUE; + } else { + if (mops.flags.f.has_poshints) { + lastMenuPosHints = mops.pos_hints; + } else { + GetPreferredPopupPosition(menu, + &lastMenuPosHints.x, + &lastMenuPosHints.y); + lastMenuPosHints.x_factor = 0; + lastMenuPosHints.y_factor = 0; + lastMenuPosHints.fRelative = FALSE; + } + fLastMenuPosHintsValid = TRUE; + if (mops.flags.f.select_warp) { + fWarpPointerToTitle = TRUE; + } + } /* else (mops.flags.f.select_in_place) */ + break; + default: + break; + } + } /* ((retval == MENU_DONE ||... */ + return MENU_ADD_BUTTON_IF(fKeyPress, retval); } -static -void WarpPointerToTitle(MenuRoot *menu) +static void +WarpPointerToTitle(MenuRoot *menu) { - int y = menu->ms->look.EntryHeight/2 + 2; - int x = MENU_MIDDLE_OFFSET(menu); - XWarpPointer(dpy, 0, menu->w, 0, 0, 0, 0, x, y); + int y = menu->ms->look.EntryHeight / 2 + 2; + int x = MENU_MIDDLE_OFFSET(menu); + XWarpPointer(dpy, 0, menu->w, 0, 0, 0, 0, x, y); } -static -MenuItem *MiWarpPointerToItem(MenuItem *mi, Bool fSkipTitle) +static MenuItem * +MiWarpPointerToItem(MenuItem *mi, Bool fSkipTitle) { - MenuRoot *menu = mi->mr; - int y; - int x = MENU_MIDDLE_OFFSET(menu); - - if (fSkipTitle && IS_TITLE_MENU_ITEM(mi) && - /* also don't skip if there is no next item */ - mi->next != NULL) { - mi = mi->next; - /* Shouldn't ever have a separator right after a title, but - lets skip one if we do, anyway */ - if (IS_SEPARATOR_MENU_ITEM(mi) && mi->next != NULL) - mi = mi->next; - } - - y = mi->y_offset + menu->ms->look.EntryHeight/2; - XWarpPointer(dpy, 0, menu->w, 0, 0, 0, 0, x, y); - return mi; + MenuRoot *menu = mi->mr; + int y; + int x = MENU_MIDDLE_OFFSET(menu); + + if (fSkipTitle && IS_TITLE_MENU_ITEM(mi) && + /* also don't skip if there is no next item */ + mi->next != NULL) { + mi = mi->next; + /* Shouldn't ever have a separator right after a title, but + lets skip one if we do, anyway */ + if (IS_SEPARATOR_MENU_ITEM(mi) && mi->next != NULL) + mi = mi->next; + } + + y = mi->y_offset + menu->ms->look.EntryHeight / 2; + XWarpPointer(dpy, 0, menu->w, 0, 0, 0, 0, x, y); + return mi; } -static -int DoMenusOverlap(MenuRoot *mr, int x, int y, int width, int height, - Bool fTolerant) +static int +DoMenusOverlap( + MenuRoot *mr, int x, int y, int width, int height, Bool fTolerant) { - int prior_x, prior_y, x_overlap; - unsigned int prior_width, prior_height; - int tolerance1; - int tolerance2; - - if (mr == NULL) - return 0; - - if (fTolerant) - { - tolerance1 = 3; - if (mr->ms->feel.PopupOffsetAdd < 0) - tolerance1 -= mr->ms->feel.PopupOffsetAdd; - tolerance2 = 4; - } - else - { - tolerance1 = 1; - tolerance2 = 1; - } - XGetGeometry(dpy,mr->w,&JunkRoot,&prior_x,&prior_y, - &prior_width,&prior_height,&JunkBW,&JunkDepth); - x_overlap = 0; - if (fTolerant) { - /* Don't use multiplier if doing an intolerant check */ - prior_width *= (float)(mr->ms->feel.PopupOffsetPercent) / 100.0; - } - if (y <= prior_y + prior_height - tolerance2 && - prior_y <= y + height - tolerance2 && - x <= prior_x + prior_width - tolerance1 && - prior_x <= x + width - tolerance2) { - x_overlap = x - prior_x; - if (x <= prior_x) { - x_overlap--; - } - } - return x_overlap; + int prior_x, prior_y, x_overlap; + unsigned int prior_width, prior_height; + int tolerance1; + int tolerance2; + + if (mr == NULL) + return 0; + + if (fTolerant) { + tolerance1 = 3; + if (mr->ms->feel.PopupOffsetAdd < 0) + tolerance1 -= mr->ms->feel.PopupOffsetAdd; + tolerance2 = 4; + } else { + tolerance1 = 1; + tolerance2 = 1; + } + XGetGeometry(dpy, mr->w, &JunkRoot, &prior_x, &prior_y, &prior_width, + &prior_height, &JunkBW, &JunkDepth); + x_overlap = 0; + if (fTolerant) { + /* Don't use multiplier if doing an intolerant check */ + prior_width *= (float)(mr->ms->feel.PopupOffsetPercent) / 100.0; + } + if (y <= prior_y + prior_height - tolerance2 && + prior_y <= y + height - tolerance2 && + x <= prior_x + prior_width - tolerance1 && + prior_x <= x + width - tolerance2) { + x_overlap = x - prior_x; + if (x <= prior_x) { + x_overlap--; + } + } + return x_overlap; } /*********************************************************************** @@ -1102,349 +1173,363 @@ int DoMenusOverlap(MenuRoot *mr, int x, int y, int width, int height, * pops - pointer to the menu options for new menu * ***********************************************************************/ -static -Bool FPopupMenu (MenuRoot *menu, MenuRoot *menuPrior, int x, int y, - Bool fWarpItem, MenuOptions *pops, Bool *ret_overlap) +static Bool +FPopupMenu(MenuRoot *menu, MenuRoot *menuPrior, int x, int y, Bool fWarpItem, + MenuOptions *pops, Bool *ret_overlap) { - Bool fWarpTitle = FALSE; - int x_overlap, x_clipped_overlap; - MenuItem *mi = NULL; - - DBUG("FPopupMenu","called"); - if ((!menu)||(menu->w == None)||(menu->items == 0)||(menu->in_use)) { - fWarpPointerToTitle = FALSE; - return False; - } - menu->mrDynamicPrev = menuPrior; - menu->flags.f.painted = 0; - menu->flags.f.is_left = 0; - menu->flags.f.is_right = 0; - menu->flags.f.is_up = 0; - menu->flags.f.is_down = 0; - menu->xanimation = 0; - - /* RepaintAlreadyReversedMenuItems(menu); */ - - InstallRootColormap(); - - /* First handle popups from button clicks on buttons in the title bar, - or the title bar itself. Position hints override this. */ - if (!(pops->flags.f.has_poshints)) { - if((Tmp_win)&&(menuPrior == NULL)&&(Context&C_LALL)) - { - y = Tmp_win->frame_y+Tmp_win->boundary_width+Tmp_win->title_height+1; - x = Tmp_win->frame_x + Tmp_win->boundary_width + - ButtonPosition(Context,Tmp_win)*Tmp_win->title_height+1; - } - if((Tmp_win)&&(menuPrior == NULL)&&(Context&C_RALL)) - { - y = Tmp_win->frame_y+Tmp_win->boundary_width+Tmp_win->title_height+1; - x = Tmp_win->frame_x +Tmp_win->frame_width - Tmp_win->boundary_width- - ButtonPosition(Context,Tmp_win)*Tmp_win->title_height-menu->width+1; - } - if((Tmp_win)&&(menuPrior == NULL)&&(Context&C_TITLE)) - { - y = Tmp_win->frame_y+Tmp_win->boundary_width+Tmp_win->title_height+1; - if(x < Tmp_win->frame_x + Tmp_win->title_x) - x = Tmp_win->frame_x + Tmp_win->title_x; - if((x + menu->width) > - (Tmp_win->frame_x + Tmp_win->title_x +Tmp_win->title_width)) - x = Tmp_win->frame_x + Tmp_win->title_x +Tmp_win->title_width- - menu->width +1; - } - } /* if (pops->flags.f.has_poshints) */ - x_overlap = DoMenusOverlap(menuPrior, x, y, menu->width, menu->height, True); - /* clip to screen */ - if (x + menu->width > Scr.MyDisplayWidth - 2) - x = Scr.MyDisplayWidth - 2 - menu->width; - if (y + menu->height > Scr.MyDisplayHeight) - y = Scr.MyDisplayHeight - menu->height; - if (x < 0) - x = 0; - if (y < 0) - y = 0; - - if (menuPrior != NULL) { - int prev_x, prev_y, left_x, right_x; - unsigned int prev_width, prev_height; - int x_offset; - - /* try to find a better place */ - XGetGeometry(dpy,menuPrior->w,&JunkRoot,&prev_x,&prev_y, - &prev_width,&prev_height,&JunkBW,&JunkDepth); - - /* check if menus overlap */ - x_clipped_overlap = DoMenusOverlap(menuPrior, x, y, menu->width, - menu->height, True); - if (x_clipped_overlap && - (!(pops->flags.f.has_poshints) || - pops->pos_hints.fRelative == FALSE || x_overlap == 0)) { - /* menus do overlap, but do not reposition if overlap was caused by - relative positioning hints */ - Bool fDefaultLeft; - Bool fEmergencyLeft; - - x_offset = prev_width * menuPrior->ms->feel.PopupOffsetPercent / 100 + - menuPrior->ms->feel.PopupOffsetAdd; - left_x = prev_x - menu->width + 2; - right_x = prev_x + x_offset; - if (x_offset > prev_width - 2) - right_x = prev_x + prev_width - 2; - if (x + menu->width < prev_x + right_x) - fDefaultLeft = TRUE; - else - fDefaultLeft = FALSE; - fEmergencyLeft = (prev_x > Scr.MyDisplayWidth - right_x) ? TRUE : FALSE; - - if (menu->ms->feel.f.Animated) { - /* animate previous out of the way */ - int left_x, right_x, end_x; - - left_x = x - x_offset; - if (x_offset >= prev_width) - left_x = x - x_offset + 3; - right_x = x + menu->width; - if (fDefaultLeft) { - /* popup menu is left of old menu, try to move prior menu right */ - if (right_x + prev_width <= Scr.MyDisplayWidth - 2) - end_x = right_x; - else if (left_x >= 0) - end_x = left_x; - else - end_x = Scr.MyDisplayWidth - 2 - prev_width; - } else { - /* popup menu is right of old menu, try to move prior menu left */ - if (left_x >= 0) - end_x = left_x; - else if (right_x + prev_width <= Scr.MyDisplayWidth - 2) - end_x = right_x; - else - end_x = 0; - } - menuPrior->xanimation += end_x - prev_x; - AnimatedMoveOfWindow(menuPrior->w,prev_x,prev_y,end_x,prev_y, - TRUE, -1, NULL); - } /* if (menu->ms->feel.f.Animated) */ - else if (prev_x + x_offset > x + 3 && x_offset + 3 > -menu->width && - !(pops->flags.f.fixed)) { - Bool fLeftIsOK = FALSE; - Bool fRightIsOK = FALSE; - Bool fUseLeft = FALSE; - - if (left_x >= 0) - fLeftIsOK = TRUE; - if (right_x + menu->width < Scr.MyDisplayWidth - 2) - fRightIsOK = TRUE; - if (!fLeftIsOK && !fRightIsOK) - fUseLeft = fEmergencyLeft; - else if (fLeftIsOK && (fDefaultLeft || !fRightIsOK)) - fUseLeft = TRUE; - else - fUseLeft = FALSE; - x = (fUseLeft) ? left_x : right_x; - /* force the menu onto the screen; prefer to have the left border - * visible if the menu is wider than the screen. But leave at least - * 20 pixels of the parent menu visible */ - - if (x + menu->width >= Scr.MyDisplayWidth - 2) - { - int d = x + menu->width - Scr.MyDisplayWidth + 3; - int c; - - if (prev_width >= 20) - c = prev_x + 20; - else - c = prev_x + prev_width; - - if (x - c >= d || x <= prev_x) - x -= d; - else if (x > c) - x = c; + Bool fWarpTitle = FALSE; + int x_overlap, x_clipped_overlap; + MenuItem *mi = NULL; + + DBUG("FPopupMenu", "called"); + if ((!menu) || (menu->w == None) || (menu->items == 0) || + (menu->in_use)) { + fWarpPointerToTitle = FALSE; + return False; } + menu->mrDynamicPrev = menuPrior; + menu->flags.f.painted = 0; + menu->flags.f.is_left = 0; + menu->flags.f.is_right = 0; + menu->flags.f.is_up = 0; + menu->flags.f.is_down = 0; + menu->xanimation = 0; + + /* RepaintAlreadyReversedMenuItems(menu); */ + + InstallRootColormap(); + + /* First handle popups from button clicks on buttons in the title bar, + or the title bar itself. Position hints override this. */ + if (!(pops->flags.f.has_poshints)) { + if ((Tmp_win) && (menuPrior == NULL) && (Context & C_LALL)) { + y = Tmp_win->frame_y + Tmp_win->boundary_width + + Tmp_win->title_height + 1; + x = Tmp_win->frame_x + Tmp_win->boundary_width + + ButtonPosition(Context, Tmp_win) * + Tmp_win->title_height + + 1; + } + if ((Tmp_win) && (menuPrior == NULL) && (Context & C_RALL)) { + y = Tmp_win->frame_y + Tmp_win->boundary_width + + Tmp_win->title_height + 1; + x = Tmp_win->frame_x + Tmp_win->frame_width - + Tmp_win->boundary_width - + ButtonPosition(Context, Tmp_win) * + Tmp_win->title_height - + menu->width + 1; + } + if ((Tmp_win) && (menuPrior == NULL) && (Context & C_TITLE)) { + y = Tmp_win->frame_y + Tmp_win->boundary_width + + Tmp_win->title_height + 1; + if (x < Tmp_win->frame_x + Tmp_win->title_x) + x = Tmp_win->frame_x + Tmp_win->title_x; + if ((x + menu->width) > + (Tmp_win->frame_x + Tmp_win->title_x + + Tmp_win->title_width)) + x = Tmp_win->frame_x + Tmp_win->title_x + + Tmp_win->title_width - menu->width + 1; + } + } /* if (pops->flags.f.has_poshints) */ + x_overlap = + DoMenusOverlap(menuPrior, x, y, menu->width, menu->height, True); + /* clip to screen */ + if (x + menu->width > Scr.MyDisplayWidth - 2) + x = Scr.MyDisplayWidth - 2 - menu->width; + if (y + menu->height > Scr.MyDisplayHeight) + y = Scr.MyDisplayHeight - menu->height; if (x < 0) - { - int c = prev_width - 20; - - if (c < 0) - c = 0; - if (-x > c) - x += c; - else - x = 0; + x = 0; + if (y < 0) + y = 0; + + if (menuPrior != NULL) { + int prev_x, prev_y, left_x, right_x; + unsigned int prev_width, prev_height; + int x_offset; + + /* try to find a better place */ + XGetGeometry(dpy, menuPrior->w, &JunkRoot, &prev_x, &prev_y, + &prev_width, &prev_height, &JunkBW, &JunkDepth); + + /* check if menus overlap */ + x_clipped_overlap = DoMenusOverlap( + menuPrior, x, y, menu->width, menu->height, True); + if (x_clipped_overlap && + (!(pops->flags.f.has_poshints) || + pops->pos_hints.fRelative == FALSE || x_overlap == 0)) { + /* menus do overlap, but do not reposition if overlap + was caused by relative positioning hints */ + Bool fDefaultLeft; + Bool fEmergencyLeft; + + x_offset = prev_width * + menuPrior->ms->feel.PopupOffsetPercent / + 100 + + menuPrior->ms->feel.PopupOffsetAdd; + left_x = prev_x - menu->width + 2; + right_x = prev_x + x_offset; + if (x_offset > prev_width - 2) + right_x = prev_x + prev_width - 2; + if (x + menu->width < prev_x + right_x) + fDefaultLeft = TRUE; + else + fDefaultLeft = FALSE; + fEmergencyLeft = (prev_x > + Scr.MyDisplayWidth - right_x) ? TRUE : FALSE; + + if (menu->ms->feel.f.Animated) { + /* animate previous out of the way */ + int left_x, right_x, end_x; + + left_x = x - x_offset; + if (x_offset >= prev_width) + left_x = x - x_offset + 3; + right_x = x + menu->width; + if (fDefaultLeft) { + /* popup menu is left of old menu, try + * to move prior menu right */ + if (right_x + prev_width <= + Scr.MyDisplayWidth - 2) + end_x = right_x; + else if (left_x >= 0) + end_x = left_x; + else + end_x = Scr.MyDisplayWidth - 2 - + prev_width; + } else { + /* popup menu is right of old menu, try + * to move prior menu left */ + if (left_x >= 0) + end_x = left_x; + else if (right_x + prev_width <= + Scr.MyDisplayWidth - 2) + end_x = right_x; + else + end_x = 0; + } + menuPrior->xanimation += end_x - prev_x; + AnimatedMoveOfWindow(menuPrior->w, prev_x, + prev_y, end_x, prev_y, TRUE, -1, NULL); + } /* if (menu->ms->feel.f.Animated) */ else if (prev_x + + x_offset > x + 3 && x_offset + 3 > -menu->width && + !(pops->flags.f.fixed)) { + Bool fLeftIsOK = FALSE; + Bool fRightIsOK = FALSE; + Bool fUseLeft = FALSE; + + if (left_x >= 0) + fLeftIsOK = TRUE; + if (right_x + menu->width < + Scr.MyDisplayWidth - 2) + fRightIsOK = TRUE; + if (!fLeftIsOK && !fRightIsOK) + fUseLeft = fEmergencyLeft; + else if (fLeftIsOK && + (fDefaultLeft || !fRightIsOK)) + fUseLeft = TRUE; + else + fUseLeft = FALSE; + x = (fUseLeft) ? left_x : right_x; + /* force the menu onto the screen; prefer to + * have the left border visible if the menu is + * wider than the screen. But leave at least 20 + * pixels of the parent menu visible */ + + if (x + menu->width >= Scr.MyDisplayWidth - 2) { + int d = x + menu->width - + Scr.MyDisplayWidth + 3; + int c; + + if (prev_width >= 20) + c = prev_x + 20; + else + c = prev_x + prev_width; + + if (x - c >= d || x <= prev_x) + x -= d; + else if (x > c) + x = c; + } + if (x < 0) { + int c = prev_width - 20; + + if (c < 0) + c = 0; + if (-x > c) + x += c; + else + x = 0; + } + } /* else if (non-overlapping menu style) */ + } /* if (x_clipped_overlap && ...) */ + + if (x < prev_x) + menu->flags.f.is_left = 1; + if (x + menu->width > prev_x + prev_width) + menu->flags.f.is_right = 1; + if (y < prev_y) + menu->flags.f.is_up = 1; + if (y + menu->height > prev_y + prev_height) + menu->flags.f.is_down = 1; + if (!menu->flags.f.is_left && !menu->flags.f.is_right) { + menu->flags.f.is_left = 1; + menu->flags.f.is_right = 1; + } + } /* if (menuPrior) */ + + /* popup the menu */ + XMoveWindow(dpy, menu->w, x, y); + XMapRaised(dpy, menu->w); + if (ret_overlap) { + *ret_overlap = DoMenusOverlap(menuPrior, x, y, menu->width, + menu->height, False) ? + True : + False; } - } /* else if (non-overlapping menu style) */ - } /* if (x_clipped_overlap && ...) */ - - if (x < prev_x) - menu->flags.f.is_left = 1; - if (x + menu->width > prev_x + prev_width) - menu->flags.f.is_right = 1; - if (y < prev_y) - menu->flags.f.is_up = 1; - if (y + menu->height > prev_y + prev_height) - menu->flags.f.is_down = 1; - if (!menu->flags.f.is_left && !menu->flags.f.is_right) - { - menu->flags.f.is_left = 1; - menu->flags.f.is_right = 1; - } - } /* if (menuPrior) */ - - /* popup the menu */ - XMoveWindow(dpy, menu->w, x, y); - XMapRaised(dpy, menu->w); - if (ret_overlap) { - *ret_overlap = - DoMenusOverlap(menuPrior, x, y, menu->width, menu->height, False) ? - True : False; - } - - if (!fWarpItem) { - mi = FindEntry(NULL); - if (mi && mi->mr == menu && mi != mi->mr->first) { - /* pointer is on an item of the popup */ - if (menu->ms->feel.f.TitleWarp) { - /* warp pointer if not on a root menu and MWM/WIN menu style */ - fWarpTitle = TRUE; - } - } - } /* if (!fWarpItem) */ - - if (pops->flags.f.no_warp) { - fWarpTitle = FALSE; - } else if (pops->flags.f.warp_title) { - fWarpTitle = TRUE; - } - if (fWarpPointerToTitle) { - fWarpTitle = TRUE; - fWarpPointerToTitle = FALSE; - } - if (fWarpItem) { - /* also warp */ - DBUG("FPopupMenu","Warping to item"); - menu->selected = MiWarpPointerToItem(menu->first, TRUE /* skip Title */); - SetMenuItemSelected( - MiWarpPointerToItem(menu->first, TRUE /* skip Title */),TRUE); - } else if(fWarpTitle) { - /* Warp pointer to middle of top line, since we don't - * want the user to come up directly on an option */ - DBUG("FPopupMenu","Warping to title"); - WarpPointerToTitle(menu); - } - return True; + + if (!fWarpItem) { + mi = FindEntry(NULL); + if (mi && mi->mr == menu && mi != mi->mr->first) { + /* pointer is on an item of the popup */ + if (menu->ms->feel.f.TitleWarp) { + /* warp pointer if not on a root menu and + * MWM/WIN menu style */ + fWarpTitle = TRUE; + } + } + } /* if (!fWarpItem) */ + + if (pops->flags.f.no_warp) { + fWarpTitle = FALSE; + } else if (pops->flags.f.warp_title) { + fWarpTitle = TRUE; + } + if (fWarpPointerToTitle) { + fWarpTitle = TRUE; + fWarpPointerToTitle = FALSE; + } + if (fWarpItem) { + /* also warp */ + DBUG("FPopupMenu", "Warping to item"); + menu->selected = + MiWarpPointerToItem(menu->first, TRUE /* skip Title */); + SetMenuItemSelected( + MiWarpPointerToItem(menu->first, TRUE /* skip Title */), + TRUE); + } else if (fWarpTitle) { + /* Warp pointer to middle of top line, since we don't + * want the user to come up directly on an option */ + DBUG("FPopupMenu", "Warping to title"); + WarpPointerToTitle(menu); + } + return True; } /* Set the selected-ness state of the menuitem passed in */ -static -void SetMenuItemSelected(MenuItem *mi, Bool f) +static void +SetMenuItemSelected(MenuItem *mi, Bool f) { - if (f == True && mi->mr->selected != NULL && mi->mr->selected != mi) - SetMenuItemSelected(mi->mr->selected, False); - if (f == False && mi->mr->selected == NULL) - return; + if (f == True && mi->mr->selected != NULL && mi->mr->selected != mi) + SetMenuItemSelected(mi->mr->selected, False); + if (f == False && mi->mr->selected == NULL) + return; - if (mi->state == f) - return; + if (mi->state == f) + return; #ifdef GRADIENT_BUTTONS - switch (mi->mr->ms->look.face.type) - { - case HGradMenu: - case VGradMenu: - case DGradMenu: - case BGradMenu: - if (f == True) - { - int iy, ih; - int mw, mh; - - if (!mi->mr->flags.f.painted) - { - PaintMenu(mi->mr, NULL); - flush_expose(mi->mr->w); - } - iy = mi->y_offset - 2; - ih = mi->y_height + 4; - if (iy < 0) - { - ih += iy; - iy = 0; - } - XGetGeometry(dpy, mi->mr->w, &JunkRoot, &JunkX, &JunkY, - &mw, &mh, &JunkBW, &JunkDepth); - if (iy + ih > mh) - ih = mh - iy; - /* grab image */ - mi->mr->stored_item.stored = XCreatePixmap(dpy, Scr.Root, mw, ih, - Scr.d_depth); - XCopyArea(dpy, mi->mr->w, mi->mr->stored_item.stored, - mi->mr->ms->look.MenuGC, 0, iy, mw, ih, 0, 0); - mi->mr->stored_item.y = iy; - mi->mr->stored_item.width = mw; - mi->mr->stored_item.height = ih; - } - else if (f == False && mi->mr->stored_item.width != 0) - { - /* ungrab image */ - - XCopyArea(dpy, mi->mr->stored_item.stored, mi->mr->w, - mi->mr->ms->look.MenuGC, 0,0, mi->mr->stored_item.width, - mi->mr->stored_item.height, 0, mi->mr->stored_item.y); - - XFreePixmap(dpy, mi->mr->stored_item.stored); - mi->mr->stored_item.width = 0; - mi->mr->stored_item.height = 0; - mi->mr->stored_item.y = 0; - - } - break; - default: - if (mi->mr->stored_item.width != 0) - { - XFreePixmap(dpy, mi->mr->stored_item.stored); - mi->mr->stored_item.width = 0; - mi->mr->stored_item.height = 0; - mi->mr->stored_item.y = 0; - } - break; - } + switch (mi->mr->ms->look.face.type) { + case HGradMenu: + case VGradMenu: + case DGradMenu: + case BGradMenu: + if (f == True) { + int iy, ih; + int mw, mh; + + if (!mi->mr->flags.f.painted) { + PaintMenu(mi->mr, NULL); + flush_expose(mi->mr->w); + } + iy = mi->y_offset - 2; + ih = mi->y_height + 4; + if (iy < 0) { + ih += iy; + iy = 0; + } + XGetGeometry(dpy, mi->mr->w, &JunkRoot, &JunkX, &JunkY, + &mw, &mh, &JunkBW, &JunkDepth); + if (iy + ih > mh) + ih = mh - iy; + /* grab image */ + mi->mr->stored_item.stored = + XCreatePixmap(dpy, Scr.Root, mw, ih, Scr.d_depth); + XCopyArea(dpy, mi->mr->w, mi->mr->stored_item.stored, + mi->mr->ms->look.MenuGC, 0, iy, mw, ih, 0, 0); + mi->mr->stored_item.y = iy; + mi->mr->stored_item.width = mw; + mi->mr->stored_item.height = ih; + } else if (f == False && mi->mr->stored_item.width != 0) { + /* ungrab image */ + + XCopyArea(dpy, mi->mr->stored_item.stored, mi->mr->w, + mi->mr->ms->look.MenuGC, 0, 0, + mi->mr->stored_item.width, + mi->mr->stored_item.height, 0, + mi->mr->stored_item.y); + + XFreePixmap(dpy, mi->mr->stored_item.stored); + mi->mr->stored_item.width = 0; + mi->mr->stored_item.height = 0; + mi->mr->stored_item.y = 0; + } + break; + default: + if (mi->mr->stored_item.width != 0) { + XFreePixmap(dpy, mi->mr->stored_item.stored); + mi->mr->stored_item.width = 0; + mi->mr->stored_item.height = 0; + mi->mr->stored_item.y = 0; + } + break; + } #endif - mi->state = f; - mi->mr->selected = (f) ? mi : NULL; - PaintEntry(mi); + mi->state = f; + mi->mr->selected = (f) ? mi : NULL; + PaintEntry(mi); } /* Returns a menu root that a given menu item pops up */ -static -MenuRoot *MrPopupForMi(MenuItem *mi) +static MenuRoot * +MrPopupForMi(MenuItem *mi) { - char *menu_name = NULL; - MenuRoot *tmp = NULL; - - /* This checks if mi is != NULL too */ - if (!IS_POPUP_MENU_ITEM(mi)) - return NULL; - /* just look past "Popup " in the action, and find that menu root */ - GetNextToken(SkipNTokens(mi->action, 1), &menu_name); - tmp = FindPopup(menu_name); - if (menu_name != NULL) - free(menu_name); - return tmp; + char *menu_name = NULL; + MenuRoot *tmp = NULL; + + /* This checks if mi is != NULL too */ + if (!IS_POPUP_MENU_ITEM(mi)) + return NULL; + /* just look past "Popup " in the action, and find that menu root */ + GetNextToken(SkipNTokens(mi->action, 1), &menu_name); + tmp = FindPopup(menu_name); + if (menu_name != NULL) + free(menu_name); + return tmp; } /* Returns the menu options for the menu that a given menu item pops up */ -static -void GetPopupOptions(MenuItem *mi, MenuOptions *pops) +static void +GetPopupOptions(MenuItem *mi, MenuOptions *pops) { - if (!mi) - return; - pops->flags.f.has_poshints = 0; - /* just look past "Popup " in the action */ - GetMenuOptions(SkipNTokens(mi->action, 2), mi->mr->w, NULL, mi, pops); + if (!mi) + return; + pops->flags.f.has_poshints = 0; + /* just look past "Popup " in the action */ + GetMenuOptions(SkipNTokens(mi->action, 2), mi->mr->w, NULL, mi, pops); } - /*********************************************************************** * * Procedure: @@ -1459,29 +1544,29 @@ void GetPopupOptions(MenuItem *mi, MenuOptions *pops) * being processed here. DO NOT USE mr->mrDynamicPrev here! * ***********************************************************************/ -static -void PopDownMenu(MenuRoot *mr) +static void +PopDownMenu(MenuRoot *mr) { - MenuItem *mi; - assert(mr); - - mr->flags.allflags = 0; - XUnmapWindow(dpy, mr->w); - - UninstallRootColormap(); - XFlush(dpy); - /* FIX: Context and menuFromFrameOrWindowOrTitlebar should really - be passed around, and not global */ - if (Context & (C_WINDOW | C_FRAME | C_TITLE | C_SIDEBAR)) - menuFromFrameOrWindowOrTitlebar = TRUE; - else - menuFromFrameOrWindowOrTitlebar = FALSE; - if ((mi = mr->selected) != NULL) { - SetMenuItemSelected(mi,FALSE); - } - - /* DBUG("PopDownMenu","popped down %s",mr->name); */ - return; + MenuItem *mi; + assert(mr); + + mr->flags.allflags = 0; + XUnmapWindow(dpy, mr->w); + + UninstallRootColormap(); + XFlush(dpy); + /* FIX: Context and menuFromFrameOrWindowOrTitlebar should really + be passed around, and not global */ + if (Context & (C_WINDOW | C_FRAME | C_TITLE | C_SIDEBAR)) + menuFromFrameOrWindowOrTitlebar = TRUE; + else + menuFromFrameOrWindowOrTitlebar = FALSE; + if ((mi = mr->selected) != NULL) { + SetMenuItemSelected(mi, FALSE); + } + + /* DBUG("PopDownMenu","popped down %s",mr->name); */ + return; } /*********************************************************************** @@ -1493,34 +1578,32 @@ void PopDownMenu(MenuRoot *mr) * afterwards. * ***********************************************************************/ -static void PopDownAndRepaintParent(MenuRoot *mr, Bool *fSubmenuOverlaps) +static void +PopDownAndRepaintParent(MenuRoot *mr, Bool *fSubmenuOverlaps) { - MenuRoot *parent = mr->mrDynamicPrev; - XEvent event; - int mr_y; - int mr_height; - int parent_y; - - if (*fSubmenuOverlaps && parent) - { - XGetGeometry(dpy, mr->w, &JunkRoot, &JunkX, &mr_y, - &JunkWidth, &mr_height, &JunkBW, &JunkDepth); - XGetGeometry(dpy, parent->w, &JunkRoot, &JunkX, &parent_y, - &JunkWidth, &JunkWidth, &JunkBW, &JunkDepth); - PopDownMenu(mr); - /* Create a fake event to pass into PaintMenu */ - event.type = Expose; - event.xexpose.y = mr_y - parent_y; - event.xexpose.height = mr_height; - PaintMenu(parent, &event); - flush_expose(parent->w); - } - else - { - PopDownMenu(mr); - } - *fSubmenuOverlaps = False; - return; + MenuRoot *parent = mr->mrDynamicPrev; + XEvent event; + int mr_y; + int mr_height; + int parent_y; + + if (*fSubmenuOverlaps && parent) { + XGetGeometry(dpy, mr->w, &JunkRoot, &JunkX, &mr_y, &JunkWidth, + &mr_height, &JunkBW, &JunkDepth); + XGetGeometry(dpy, parent->w, &JunkRoot, &JunkX, &parent_y, + &JunkWidth, &JunkWidth, &JunkBW, &JunkDepth); + PopDownMenu(mr); + /* Create a fake event to pass into PaintMenu */ + event.type = Expose; + event.xexpose.y = mr_y - parent_y; + event.xexpose.height = mr_height; + PaintMenu(parent, &event); + flush_expose(parent->w); + } else { + PopDownMenu(mr); + } + *fSubmenuOverlaps = False; + return; } /*********************************************************************** @@ -1529,14 +1612,14 @@ static void PopDownAndRepaintParent(MenuRoot *mr, Bool *fSubmenuOverlaps) * RelieveRectangle - add relief lines to a rectangular window * ***********************************************************************/ -static -void RelieveRectangle(Window win,int x,int y,int w, int h,GC Hilite,GC Shadow) +static void +RelieveRectangle(Window win, int x, int y, int w, int h, GC Hilite, GC Shadow) { - XDrawLine(dpy, win, Hilite, x, y, w+x-1, y); - XDrawLine(dpy, win, Hilite, x, y, x, h+y-1); + XDrawLine(dpy, win, Hilite, x, y, w + x - 1, y); + XDrawLine(dpy, win, Hilite, x, y, x, h + y - 1); - XDrawLine(dpy, win, Shadow, x, h+y-1, w+x-1, h+y-1); - XDrawLine(dpy, win, Shadow, w+x-1, y, w+x-1, h+y-1); + XDrawLine(dpy, win, Shadow, x, h + y - 1, w + x - 1, h + y - 1); + XDrawLine(dpy, win, Shadow, w + x - 1, y, w + x - 1, h + y - 1); } /*********************************************************************** @@ -1546,294 +1629,285 @@ void RelieveRectangle(Window win,int x,int y,int w, int h,GC Hilite,GC Shadow) * rectangular window * ***********************************************************************/ -static -void RelieveHalfRectangle(Window win,int x,int y,int w,int h, - GC Hilite,GC Shadow) +static void +RelieveHalfRectangle( + Window win, int x, int y, int w, int h, GC Hilite, GC Shadow) { - XDrawLine(dpy, win, Hilite, x, y-1, x, h+y); - XDrawLine(dpy, win, Hilite, x+1, y, x+1, h+y-1); + XDrawLine(dpy, win, Hilite, x, y - 1, x, h + y); + XDrawLine(dpy, win, Hilite, x + 1, y, x + 1, h + y - 1); - XDrawLine(dpy, win, Shadow, w+x-1, y-1, w+x-1, h+y); - XDrawLine(dpy, win, Shadow, w+x-2, y, w+x-2, h+y-1); + XDrawLine(dpy, win, Shadow, w + x - 1, y - 1, w + x - 1, h + y); + XDrawLine(dpy, win, Shadow, w + x - 2, y, w + x - 2, h + y - 1); } - /*********************************************************************** * * Procedure: * PaintEntry - draws a single entry in a popped up menu * ***********************************************************************/ -static -void PaintEntry(MenuItem *mi) +static void +PaintEntry(MenuItem *mi) { - int y_offset,text_y,d, y_height,y,x; - GC ShadowGC, ReliefGC, currentGC; - MenuRoot *mr = mi->mr; - char th = mr->ms->look.ReliefThickness; - Bool fClear = False; + int y_offset, text_y, d, y_height, y, x; + GC ShadowGC, ReliefGC, currentGC; + MenuRoot *mr = mi->mr; + char th = mr->ms->look.ReliefThickness; + Bool fClear = False; #ifdef GRADIENT_BUTTONS - Bool fGradient; - - switch (mi->mr->ms->look.face.type) - { - case HGradMenu: - case VGradMenu: - case DGradMenu: - case BGradMenu: - fGradient = True; - break; - default: - fGradient = False; - break; - } + Bool fGradient; + + switch (mi->mr->ms->look.face.type) { + case HGradMenu: + case VGradMenu: + case DGradMenu: + case BGradMenu: + fGradient = True; + break; + default: + fGradient = False; + break; + } #endif - y_offset = mi->y_offset; - y_height = mi->y_height; - text_y = y_offset + mi->mr->ms->look.pStdFont->y; - /* center text vertically if the pixmap is taller */ - if(mi->picture) - text_y+=mi->picture->height; - if (mi->lpicture) - { - y = mi->lpicture->height - mi->mr->ms->look.pStdFont->height; - if (y>1) - text_y += y/2; - } - - ShadowGC = mr->ms->look.MenuShadowGC; - if(Scr.d_depth<2) - ReliefGC = mr->ms->look.MenuShadowGC; - else - ReliefGC = mr->ms->look.MenuReliefGC; - - /* Hilight background */ - if (mr->ms->look.f.Hilight) { - if (mi->state && (!mi->fIsSeparator) && - (((*mi->item)!=0) || mi->picture || mi->lpicture)) { - int d = (th == 2 && mi->prev && mi->prev->state) ? 1 : 0; - - XChangeGC(dpy, Scr.ScratchGC1, Globalgcm, &Globalgcv); - XFillRectangle(dpy, mr->w, mr->ms->look.MenuActiveBackGC, mr->xoffset+3, - y_offset + d, mr->width - mr->xoffset-6, y_height - d); - } else if (th == 0) { + y_offset = mi->y_offset; + y_height = mi->y_height; + text_y = y_offset + mi->mr->ms->look.pStdFont->y; + /* center text vertically if the pixmap is taller */ + if (mi->picture) + text_y += mi->picture->height; + if (mi->lpicture) { + y = mi->lpicture->height - mi->mr->ms->look.pStdFont->height; + if (y > 1) + text_y += y / 2; + } + + ShadowGC = mr->ms->look.MenuShadowGC; + if (Scr.d_depth < 2) + ReliefGC = mr->ms->look.MenuShadowGC; + else + ReliefGC = mr->ms->look.MenuReliefGC; + + /* Hilight background */ + if (mr->ms->look.f.Hilight) { + if (mi->state && (!mi->fIsSeparator) && + (((*mi->item) != 0) || mi->picture || mi->lpicture)) { + int d = + (th == 2 && mi->prev && mi->prev->state) ? 1 : 0; + + XChangeGC(dpy, Scr.ScratchGC1, Globalgcm, &Globalgcv); + XFillRectangle(dpy, mr->w, + mr->ms->look.MenuActiveBackGC, mr->xoffset + 3, + y_offset + d, mr->width - mr->xoffset - 6, + y_height - d); + } else if (th == 0) { #ifdef GRADIENT_BUTTONS - if (!fGradient) + if (!fGradient) #endif - XClearArea(dpy,mr->w,mr->xoffset+3,y_offset,mr->width -mr->xoffset-6, - y_height,0); - } else { - fClear = True; - } - if (th == 0) { - RelieveHalfRectangle(mr->w, 0, y_offset-1, mr->width, y_height+3, - ReliefGC, ShadowGC); - } - } - - if (mr->ms->look.ReliefThickness > 0 && (fClear || !mr->ms->look.f.Hilight)){ - /* background was already painted above? */ + XClearArea(dpy, mr->w, mr->xoffset + 3, + y_offset, mr->width - mr->xoffset - 6, + y_height, 0); + } else { + fClear = True; + } + if (th == 0) { + RelieveHalfRectangle(mr->w, 0, y_offset - 1, mr->width, + y_height + 3, ReliefGC, ShadowGC); + } + } + + if (mr->ms->look.ReliefThickness > 0 && + (fClear || !mr->ms->look.f.Hilight)) { + /* background was already painted above? */ #ifdef GRADIENT_BUTTONS - if (!fGradient) + if (!fGradient) #endif - { - - if (th == 2 && mi->prev && mi->prev->state) - XClearArea(dpy, mr->w,mr->xoffset,y_offset+1,mr->width,y_height-1,0); - else - XClearArea(dpy, mr->w, mr->xoffset, y_offset - th + 1, mr->width, - y_height + 2*(th - 1), 0); - } - } - - - - /* Hilight 3D */ - if (mr->ms->look.ReliefThickness > 0) { - int sw = 0; - - if (mr->sidePic != NULL) - sw = mr->sidePic->width + 5; - else if (mr->ms->look.sidePic != NULL) - sw = mr->ms->look.sidePic->width + 5; - - if ((mi->state)&&(!mi->fIsSeparator)&& - (((*mi->item)!=0) || mi->picture || mi->lpicture)) { - RelieveRectangle(mr->w, mr->xoffset + th + 1, y_offset, - mr->width - 2*(th + 1) - sw, mi->y_height, - ReliefGC,ShadowGC); - if (th == 2) { - RelieveRectangle(mr->w, mr->xoffset + 2, y_offset - 1, - mr->width - 4 - sw, mi->y_height + 2, - ReliefGC,ShadowGC); - } - } - - RelieveHalfRectangle(mr->w, 0, y_offset - th + 1, mr->width, - y_height + 2*(th - 1), ReliefGC, ShadowGC); - } - - - /* Draw the shadows for the absolute outside of the menus - This stuff belongs in here, not in PaintMenu, since we only - want to redraw it when we have too (i.e. on expose event) */ - - /* Top of the menu */ - if(mi == mr->first) - DrawSeparator(mr->w,ReliefGC,ReliefGC,0,0, mr->width-1,0,-1); - - /* Botton of the menu */ - if(mi->next == NULL) - DrawSeparator(mr->w,ShadowGC,ShadowGC,1,mr->height-2, - mr->width-2, mr->height-2,1); - - if(IS_TITLE_MENU_ITEM(mi)) - { - if(mr->ms->look.TitleUnderlines == 2) - { - text_y += HEIGHT_EXTRA/2; - XDrawLine(dpy, mr->w, ShadowGC, mr->xoffset+2, y_offset+y_height-2, - mr->width-3, y_offset+y_height-2); - XDrawLine(dpy, mr->w, ShadowGC, mr->xoffset+2, y_offset+y_height-4, - mr->width-3, y_offset+y_height-4); + { + if (th == 2 && mi->prev && mi->prev->state) + XClearArea(dpy, mr->w, mr->xoffset, + y_offset + 1, mr->width, y_height - 1, 0); + else + XClearArea(dpy, mr->w, mr->xoffset, + y_offset - th + 1, mr->width, + y_height + 2 * (th - 1), 0); + } } - else if(mr->ms->look.TitleUnderlines == 1) - { - if(mi->next != NULL) - { - DrawSeparator(mr->w,ShadowGC,ReliefGC,mr->xoffset+5, - y_offset+y_height-3, - mr->width-6, y_offset+y_height-3,1); - } - if(mi != mr->first) - { - text_y += HEIGHT_EXTRA_TITLE/2; - DrawSeparator(mr->w,ShadowGC,ReliefGC,mr->xoffset+5, y_offset+1, - mr->width-6, y_offset+1,1); - } + + /* Hilight 3D */ + if (mr->ms->look.ReliefThickness > 0) { + int sw = 0; + + if (mr->sidePic != NULL) + sw = mr->sidePic->width + 5; + else if (mr->ms->look.sidePic != NULL) + sw = mr->ms->look.sidePic->width + 5; + + if ((mi->state) && (!mi->fIsSeparator) && + (((*mi->item) != 0) || mi->picture || mi->lpicture)) { + RelieveRectangle(mr->w, mr->xoffset + th + 1, y_offset, + mr->width - 2 * (th + 1) - sw, mi->y_height, + ReliefGC, ShadowGC); + if (th == 2) { + RelieveRectangle(mr->w, mr->xoffset + 2, + y_offset - 1, mr->width - 4 - sw, + mi->y_height + 2, ReliefGC, ShadowGC); + } + } + + RelieveHalfRectangle(mr->w, 0, y_offset - th + 1, mr->width, + y_height + 2 * (th - 1), ReliefGC, ShadowGC); } - } - else - text_y += HEIGHT_EXTRA/2; - - /* see if it's an actual separator (titles are also separators) */ - if(mi->fIsSeparator && !IS_TITLE_MENU_ITEM(mi) && !IS_LABEL_MENU_ITEM(mi)) - { - int d = (mr->ms->look.f.LongSeparators) ? 3 : 0; - - DrawSeparator(mr->w,ShadowGC,ReliefGC,mr->xoffset+5-d, - y_offset-1+HEIGHT_SEPARATOR/2, - mr->width-6+d,y_offset-1+HEIGHT_SEPARATOR/2,1); - } - if(mi->next == NULL) - DrawSeparator(mr->w,ShadowGC,ShadowGC,mr->xoffset+1,mr->height-2, - mr->width-2, mr->height-2,1); - if(mi == mr->first) - DrawSeparator(mr->w,ReliefGC,ReliefGC,mr->xoffset,0, mr->width-1,0,-1); - - if(check_allowed_function(mi)) - { - if(mi->state && !IS_TITLE_MENU_ITEM(mi)) - currentGC = mr->ms->look.MenuActiveGC; - else - currentGC = mr->ms->look.MenuGC; - } - else - /* should be a shaded out word, not just re-colored. */ - currentGC = mr->ms->look.MenuStippleGC; - - if (mr->ms->look.f.Hilight && !mr->ms->look.f.hasActiveFore && - mi->state && mi->fIsSeparator == FALSE) - /* Use a lighter color for highlighted windows menu items for win mode */ - currentGC = mr->ms->look.MenuReliefGC; - - if(*mi->item) - XDrawString(dpy, mr->w,currentGC,mi->x+mr->xoffset,text_y, mi->item, - mi->strlen); - if(mi->strlen2>0) - XDrawString(dpy, mr->w,currentGC,mi->x2+mr->xoffset,text_y, mi->item2, - mi->strlen2); - - /* pete@tecc.co.uk: If the item has a hot key, underline it */ - if (mi->hotkey > 0) - DrawUnderline(mr, currentGC,mr->xoffset+mi->x,text_y,mi->item, - mi->hotkey - 1); - if (mi->hotkey < 0) - DrawUnderline(mr, currentGC,mr->xoffset+mi->x2,text_y,mi->item2, - -1 - mi->hotkey); - - d=(mr->ms->look.EntryHeight-7)/2; - if(mi->func_type == F_POPUP) { - if(mi->state) - DrawTrianglePattern(mr->w, ShadowGC, ReliefGC, ShadowGC, ReliefGC, - mr->width-13, y_offset+d-1, mr->width-7, - y_offset+d+7, mr->ms->look.f.TriangleRelief); - else - DrawTrianglePattern(mr->w, ReliefGC, ShadowGC, ReliefGC, - mr->ms->look.MenuGC, - mr->width-13, y_offset+d-1, mr->width-7, - y_offset+d+7, mr->ms->look.f.TriangleRelief); - } - - if(mi->picture) - { - x = (mr->width - mi->picture->width)/2; - if(mi->lpicture && x < mr->width0 + 5) - x = mr->width0+5; - - if(mi->picture->depth > 0) /* pixmap? */ - { - Globalgcm = GCClipMask | GCClipXOrigin | GCClipYOrigin; - Globalgcv.clip_mask = mi->picture->mask; - Globalgcv.clip_x_origin= x; - Globalgcv.clip_y_origin = y_offset+1; - XChangeGC(dpy,ReliefGC,Globalgcm,&Globalgcv); - XCopyArea(dpy,mi->picture->picture,mr->w,ReliefGC, 0, 0, - mi->picture->width, mi->picture->height, - x,y_offset+1); - Globalgcm = GCClipMask; - Globalgcv.clip_mask = None; - XChangeGC(dpy,ReliefGC,Globalgcm,&Globalgcv); + + /* Draw the shadows for the absolute outside of the menus + This stuff belongs in here, not in PaintMenu, since we only + want to redraw it when we have too (i.e. on expose event) */ + + /* Top of the menu */ + if (mi == mr->first) + DrawSeparator( + mr->w, ReliefGC, ReliefGC, 0, 0, mr->width - 1, 0, -1); + + /* Botton of the menu */ + if (mi->next == NULL) + DrawSeparator(mr->w, ShadowGC, ShadowGC, 1, mr->height - 2, + mr->width - 2, mr->height - 2, 1); + + if (IS_TITLE_MENU_ITEM(mi)) { + if (mr->ms->look.TitleUnderlines == 2) { + text_y += HEIGHT_EXTRA / 2; + XDrawLine(dpy, mr->w, ShadowGC, mr->xoffset + 2, + y_offset + y_height - 2, mr->width - 3, + y_offset + y_height - 2); + XDrawLine(dpy, mr->w, ShadowGC, mr->xoffset + 2, + y_offset + y_height - 4, mr->width - 3, + y_offset + y_height - 4); + } else if (mr->ms->look.TitleUnderlines == 1) { + if (mi->next != NULL) { + DrawSeparator(mr->w, ShadowGC, ReliefGC, + mr->xoffset + 5, y_offset + y_height - 3, + mr->width - 6, y_offset + y_height - 3, 1); + } + if (mi != mr->first) { + text_y += HEIGHT_EXTRA_TITLE / 2; + DrawSeparator(mr->w, ShadowGC, ReliefGC, + mr->xoffset + 5, y_offset + 1, + mr->width - 6, y_offset + 1, 1); + } + } + } else + text_y += HEIGHT_EXTRA / 2; + + /* see if it's an actual separator (titles are also separators) */ + if (mi->fIsSeparator && !IS_TITLE_MENU_ITEM(mi) && + !IS_LABEL_MENU_ITEM(mi)) { + int d = (mr->ms->look.f.LongSeparators) ? 3 : 0; + + DrawSeparator(mr->w, ShadowGC, ReliefGC, mr->xoffset + 5 - d, + y_offset - 1 + HEIGHT_SEPARATOR / 2, mr->width - 6 + d, + y_offset - 1 + HEIGHT_SEPARATOR / 2, 1); } - else - { - XCopyPlane(dpy,mi->picture->picture,mr->w, - currentGC,0,0,mi->picture->width,mi->picture->height, - x,y_offset+1,1); + if (mi->next == NULL) + DrawSeparator(mr->w, ShadowGC, ShadowGC, mr->xoffset + 1, + mr->height - 2, mr->width - 2, mr->height - 2, 1); + if (mi == mr->first) + DrawSeparator(mr->w, ReliefGC, ReliefGC, mr->xoffset, 0, + mr->width - 1, 0, -1); + + if (check_allowed_function(mi)) { + if (mi->state && !IS_TITLE_MENU_ITEM(mi)) + currentGC = mr->ms->look.MenuActiveGC; + else + currentGC = mr->ms->look.MenuGC; + } else + /* should be a shaded out word, not just re-colored. */ + currentGC = mr->ms->look.MenuStippleGC; + + if (mr->ms->look.f.Hilight && !mr->ms->look.f.hasActiveFore && + mi->state && mi->fIsSeparator == FALSE) + /* Use a lighter color for highlighted windows menu items for + * win mode */ + currentGC = mr->ms->look.MenuReliefGC; + + if (*mi->item) + XDrawString(dpy, mr->w, currentGC, mi->x + mr->xoffset, text_y, + mi->item, mi->strlen); + if (mi->strlen2 > 0) + XDrawString(dpy, mr->w, currentGC, mi->x2 + mr->xoffset, text_y, + mi->item2, mi->strlen2); + + /* pete@tecc.co.uk: If the item has a hot key, underline it */ + if (mi->hotkey > 0) + DrawUnderline(mr, currentGC, mr->xoffset + mi->x, text_y, + mi->item, mi->hotkey - 1); + if (mi->hotkey < 0) + DrawUnderline(mr, currentGC, mr->xoffset + mi->x2, text_y, + mi->item2, -1 - mi->hotkey); + + d = (mr->ms->look.EntryHeight - 7) / 2; + if (mi->func_type == F_POPUP) { + if (mi->state) + DrawTrianglePattern(mr->w, ShadowGC, ReliefGC, ShadowGC, + ReliefGC, mr->width - 13, y_offset + d - 1, + mr->width - 7, y_offset + d + 7, + mr->ms->look.f.TriangleRelief); + else + DrawTrianglePattern(mr->w, ReliefGC, ShadowGC, ReliefGC, + mr->ms->look.MenuGC, mr->width - 13, + y_offset + d - 1, mr->width - 7, y_offset + d + 7, + mr->ms->look.f.TriangleRelief); } - } - - if(mi->lpicture) - { - int lp_offset = 6; - if(mi->picture && *mi->item != 0) - y = y_offset + mi->y_height - mi->lpicture->height-1; - else - y = y_offset + mi->y_height/2 - mi->lpicture->height/2; - if(mi->lpicture->depth > 0) /* pixmap? */ - { - Globalgcm = GCClipMask | GCClipXOrigin | GCClipYOrigin; - Globalgcv.clip_mask = mi->lpicture->mask; - Globalgcv.clip_x_origin= lp_offset + mr->xoffset; - Globalgcv.clip_y_origin = y; - - XChangeGC(dpy,ReliefGC,Globalgcm,&Globalgcv); - XCopyArea(dpy,mi->lpicture->picture,mr->w,ReliefGC,0,0, - mi->lpicture->width, mi->lpicture->height, - lp_offset + mr->xoffset,y); - Globalgcm = GCClipMask; - Globalgcv.clip_mask = None; - XChangeGC(dpy,ReliefGC,Globalgcm,&Globalgcv); + + if (mi->picture) { + x = (mr->width - mi->picture->width) / 2; + if (mi->lpicture && x < mr->width0 + 5) + x = mr->width0 + 5; + + if (mi->picture->depth > 0) { /* pixmap? */ + Globalgcm = GCClipMask | GCClipXOrigin | GCClipYOrigin; + Globalgcv.clip_mask = mi->picture->mask; + Globalgcv.clip_x_origin = x; + Globalgcv.clip_y_origin = y_offset + 1; + XChangeGC(dpy, ReliefGC, Globalgcm, &Globalgcv); + XCopyArea(dpy, mi->picture->picture, mr->w, ReliefGC, 0, + 0, mi->picture->width, mi->picture->height, x, + y_offset + 1); + Globalgcm = GCClipMask; + Globalgcv.clip_mask = None; + XChangeGC(dpy, ReliefGC, Globalgcm, &Globalgcv); + } else { + XCopyPlane(dpy, mi->picture->picture, mr->w, currentGC, + 0, 0, mi->picture->width, mi->picture->height, x, + y_offset + 1, 1); + } } - else - { - XCopyPlane(dpy,mi->lpicture->picture,mr->w, - currentGC,0,0,mi->lpicture->width,mi->lpicture->height, - lp_offset + mr->xoffset,y,1); + + if (mi->lpicture) { + int lp_offset = 6; + if (mi->picture && *mi->item != 0) + y = y_offset + mi->y_height - mi->lpicture->height - 1; + else + y = y_offset + mi->y_height / 2 - + mi->lpicture->height / 2; + if (mi->lpicture->depth > 0) { /* pixmap? */ + Globalgcm = GCClipMask | GCClipXOrigin | GCClipYOrigin; + Globalgcv.clip_mask = mi->lpicture->mask; + Globalgcv.clip_x_origin = lp_offset + mr->xoffset; + Globalgcv.clip_y_origin = y; + + XChangeGC(dpy, ReliefGC, Globalgcm, &Globalgcv); + XCopyArea(dpy, mi->lpicture->picture, mr->w, ReliefGC, + 0, 0, mi->lpicture->width, mi->lpicture->height, + lp_offset + mr->xoffset, y); + Globalgcm = GCClipMask; + Globalgcv.clip_mask = None; + XChangeGC(dpy, ReliefGC, Globalgcm, &Globalgcv); + } else { + XCopyPlane(dpy, mi->lpicture->picture, mr->w, currentGC, + 0, 0, mi->lpicture->width, mi->lpicture->height, + lp_offset + mr->xoffset, y, 1); + } } - } - return; + return; } /************************************************************ @@ -1842,59 +1916,55 @@ void PaintEntry(MenuItem *mi) * ************************************************************/ -void PaintSidePic(MenuRoot *mr) +void +PaintSidePic(MenuRoot *mr) { - GC ReliefGC, TextGC; - FvwmPicture *sidePic; - - if (mr->sidePic) - sidePic = mr->sidePic; - else if (mr->ms->look.sidePic) - sidePic = mr->ms->look.sidePic; - else - return; - - if(Scr.d_depth<2) - ReliefGC = mr->ms->look.MenuShadowGC; - else - ReliefGC = mr->ms->look.MenuReliefGC; - TextGC = mr->ms->look.MenuGC; - - if(mr->colorize) - Globalgcv.foreground = mr->sideColor; - else if (mr->ms->look.f.hasSideColor) - Globalgcv.foreground = mr->ms->look.sideColor; - if (mr->colorize || mr->ms->look.f.hasSideColor) { - Globalgcm = GCForeground; - XChangeGC(dpy, Scr.ScratchGC1, Globalgcm, &Globalgcv); - XFillRectangle(dpy, mr->w, Scr.ScratchGC1, 3, 3, - sidePic->width, mr->height - 6); - } - - if(sidePic->depth > 0) /* pixmap? */ - { - Globalgcm = GCClipMask | GCClipXOrigin | GCClipYOrigin; - Globalgcv.clip_mask = sidePic->mask; - Globalgcv.clip_x_origin = 3; - Globalgcv.clip_y_origin = mr->height - sidePic->height -3; - - XChangeGC(dpy,ReliefGC,Globalgcm,&Globalgcv); - XCopyArea(dpy, sidePic->picture, mr->w, - ReliefGC, 0, 0, - sidePic->width, sidePic->height, - Globalgcv.clip_x_origin, Globalgcv.clip_y_origin); - Globalgcm = GCClipMask; - Globalgcv.clip_mask = None; - XChangeGC(dpy,ReliefGC,Globalgcm,&Globalgcv); - } else { - XCopyPlane(dpy, sidePic->picture, mr->w, - TextGC, 0, 0, - sidePic->width, sidePic->height, - 1, mr->height - sidePic->height, 1); - } -} + GC ReliefGC, TextGC; + FvwmPicture *sidePic; + if (mr->sidePic) + sidePic = mr->sidePic; + else if (mr->ms->look.sidePic) + sidePic = mr->ms->look.sidePic; + else + return; + + if (Scr.d_depth < 2) + ReliefGC = mr->ms->look.MenuShadowGC; + else + ReliefGC = mr->ms->look.MenuReliefGC; + TextGC = mr->ms->look.MenuGC; + + if (mr->colorize) + Globalgcv.foreground = mr->sideColor; + else if (mr->ms->look.f.hasSideColor) + Globalgcv.foreground = mr->ms->look.sideColor; + if (mr->colorize || mr->ms->look.f.hasSideColor) { + Globalgcm = GCForeground; + XChangeGC(dpy, Scr.ScratchGC1, Globalgcm, &Globalgcv); + XFillRectangle(dpy, mr->w, Scr.ScratchGC1, 3, 3, sidePic->width, + mr->height - 6); + } + if (sidePic->depth > 0) { /* pixmap? */ + Globalgcm = GCClipMask | GCClipXOrigin | GCClipYOrigin; + Globalgcv.clip_mask = sidePic->mask; + Globalgcv.clip_x_origin = 3; + Globalgcv.clip_y_origin = mr->height - sidePic->height - 3; + + XChangeGC(dpy, ReliefGC, Globalgcm, &Globalgcv); + XCopyArea(dpy, sidePic->picture, mr->w, ReliefGC, 0, 0, + sidePic->width, sidePic->height, Globalgcv.clip_x_origin, + Globalgcv.clip_y_origin); + Globalgcm = GCClipMask; + Globalgcv.clip_mask = None; + XChangeGC(dpy, ReliefGC, Globalgcm, &Globalgcv); + } else { + XCopyPlane(dpy, sidePic->picture, mr->w, TextGC, 0, 0, + sidePic->width, sidePic->height, 1, + mr->height - sidePic->height, 1); + } +} /**************************************************************************** * Procedure: @@ -1906,24 +1976,26 @@ void PaintSidePic(MenuRoot *mr) * the character... * ****************************************************************************/ -static -void DrawUnderline(MenuRoot *mr, GC gc, int x, int y, char *txt, int posn) +static void +DrawUnderline(MenuRoot *mr, GC gc, int x, int y, char *txt, int posn) { - int off1 = XTextWidth(mr->ms->look.pStdFont->font, txt, posn); - int off2 = XTextWidth(mr->ms->look.pStdFont->font, txt, posn + 1) - 1; - XDrawLine(dpy, mr->w, gc, x + off1, y + 2, x + off2, y + 2); + int off1 = XTextWidth(mr->ms->look.pStdFont->font, txt, posn); + int off2 = XTextWidth(mr->ms->look.pStdFont->font, txt, posn + 1) - 1; + XDrawLine(dpy, mr->w, gc, x + off1, y + 2, x + off2, y + 2); } + /**************************************************************************** * * Draws two horizontal lines to form a separator * ****************************************************************************/ -static -void DrawSeparator(Window w, GC TopGC, GC BottomGC,int x1,int y1,int x2,int y2, - int extra_off) +static void +DrawSeparator(Window w, GC TopGC, GC BottomGC, int x1, int y1, int x2, int y2, + int extra_off) { - XDrawLine(dpy, w, TopGC , x1, y1, x2, y2); - XDrawLine(dpy, w, BottomGC, x1-extra_off, y1+1,x2+extra_off,y2+1); + XDrawLine(dpy, w, TopGC, x1, y1, x2, y2); + XDrawLine( + dpy, w, BottomGC, x1 - extra_off, y1 + 1, x2 + extra_off, y2 + 1); } /**************************************************************************** @@ -1931,27 +2003,30 @@ void DrawSeparator(Window w, GC TopGC, GC BottomGC,int x1,int y1,int x2,int y2, * Draws a little Triangle pattern within a window * ****************************************************************************/ -static -void DrawTrianglePattern(Window w,GC GC1,GC GC2,GC GC3,GC gc,int l,int u, - int r,int b, char relief) +static void +DrawTrianglePattern(Window w, GC GC1, GC GC2, GC GC3, GC gc, int l, int u, + int r, int b, char relief) { - int m; - - m = (u + b)/2; - - if (!relief) { - /* solid triangle */ - XPoint points[3]; - points[0].x = l; points[0].y = u; - points[1].x = l; points[1].y = b; - points[2].x = r; points[2].y = m; - XFillPolygon(dpy, w, gc, points, 3, Convex, CoordModeOrigin); - } else { - /* relief triangle */ - XDrawLine(dpy,w,GC1,l,u,l,b); - XDrawLine(dpy,w,GC2,l,b,r,m); - XDrawLine(dpy,w,GC3,r,m,l,u); - } + int m; + + m = (u + b) / 2; + + if (!relief) { + /* solid triangle */ + XPoint points[3]; + points[0].x = l; + points[0].y = u; + points[1].x = l; + points[1].y = b; + points[2].x = r; + points[2].y = m; + XFillPolygon(dpy, w, gc, points, 3, Convex, CoordModeOrigin); + } else { + /* relief triangle */ + XDrawLine(dpy, w, GC1, l, u, l, b); + XDrawLine(dpy, w, GC2, l, b, r, m); + XDrawLine(dpy, w, GC3, r, m, l, u); + } } /*********************************************************************** @@ -1960,269 +2035,271 @@ void DrawTrianglePattern(Window w,GC GC1,GC GC2,GC GC3,GC gc,int l,int u, * PaintMenu - draws the entire menu * ***********************************************************************/ -void PaintMenu(MenuRoot *mr, XEvent *pevent) +void +PaintMenu(MenuRoot *mr, XEvent *pevent) { - MenuItem *mi; - MenuStyle *ms = mr->ms; - register int type; - XRectangle bounds; + MenuItem *mi; + MenuStyle *ms = mr->ms; + register int type; + XRectangle bounds; #ifdef PIXMAP_BUTTONS - FvwmPicture *p; - int border = 0; - int width, height, x, y; + FvwmPicture *p; + int border = 0; + int width, height, x, y; #endif #ifdef GRADIENT_BUTTONS - Pixmap pmap; - GC pmapgc; - XGCValues gcv; - unsigned long gcm = 0; - gcv.line_width=3; - gcm = GCLineWidth; + Pixmap pmap; + GC pmapgc; + XGCValues gcv; + unsigned long gcm = 0; + gcv.line_width = 3; + gcm = GCLineWidth; #endif - mr->flags.f.painted = 1; - if( ms ) - { - type = ms->look.face.type; - switch(type) - { - case SolidMenu: - XSetWindowBackground(dpy, mr->w, mr->ms->look.face.u.back); - flush_expose(mr->w); - XClearWindow(dpy,mr->w); - break; + mr->flags.f.painted = 1; + if (ms) { + type = ms->look.face.type; + switch (type) { + case SolidMenu: + XSetWindowBackground( + dpy, mr->w, mr->ms->look.face.u.back); + flush_expose(mr->w); + XClearWindow(dpy, mr->w); + break; #ifdef GRADIENT_BUTTONS - case HGradMenu: - case VGradMenu: - case DGradMenu: - case BGradMenu: - bounds.x = 2; bounds.y = 2; - bounds.width = mr->width - 5; - bounds.height = mr->height; - - if (type == HGradMenu) { - if (mr->backgroundset == False) - { - register int i = 0; - register int dw; - - pmap = XCreatePixmap(dpy, Scr.Root, mr->width, 5, Scr.d_depth); - pmapgc = XCreateGC(dpy, pmap, gcm, &gcv); - - bounds.width = mr->width; - dw= (float) bounds.width / ms->look.face.u.grad.npixels + 1; - while (i < ms->look.face.u.grad.npixels) - { - unsigned short x = i * bounds.width / ms->look.face.u.grad.npixels; - XSetForeground(dpy, pmapgc, - ms->look.face.u.grad.pixels[i++ ]); - XFillRectangle(dpy, pmap, pmapgc, - x, 0, - dw, 5); - } - XSetWindowBackgroundPixmap(dpy, mr->w, pmap); - XFreeGC(dpy,pmapgc); - XFreePixmap(dpy,pmap); - mr->backgroundset = True; - } - XClearWindow(dpy, mr->w); - } - else if (type == VGradMenu) - { - if (mr->backgroundset == False) - { - register int i = 0; - register int dh = bounds.height / ms->look.face.u.grad.npixels + 1; - - pmap = XCreatePixmap(dpy, Scr.Root, 5, mr->height, Scr.d_depth); - pmapgc = XCreateGC(dpy, pmap, gcm, &gcv); - - while (i < ms->look.face.u.grad.npixels) - { - unsigned short y = i*bounds.height / ms->look.face.u.grad.npixels; - XSetForeground(dpy, pmapgc, - ms->look.face.u.grad.pixels[i++]); - XFillRectangle(dpy, pmap, pmapgc, - 0, y, - 5, dh); - } - XSetWindowBackgroundPixmap(dpy, mr->w, pmap); - XFreeGC(dpy,pmapgc); - XFreePixmap(dpy,pmap); - mr->backgroundset = True; - } - XClearWindow(dpy, mr->w); - } - else /* D or BGradient */ - { - register int i = 0, numLines; - int cindex = -1; - - XSetClipMask(dpy, Scr.TransMaskGC, None); - numLines = mr->width + mr->height - 1; - for(i = 0; i < numLines; i++) - { - if((int)(i * ms->look.face.u.grad.npixels / numLines) > cindex) - { - /* pick the next colour (skip if necc.) */ - cindex = i * ms->look.face.u.grad.npixels / numLines; - XSetForeground(dpy, Scr.TransMaskGC, ms->look.face.u.grad.pixels[cindex]); - } - if (type == DGradMenu) - XDrawLine(dpy, mr->w, Scr.TransMaskGC, - 0, i, i, 0); - else /* BGradient */ - XDrawLine(dpy, mr->w, Scr.TransMaskGC, - 0, mr->height - 1 - i, i, mr->height - 1); - } - } - break; -#endif /* GRADIENT_BUTTONS */ + case HGradMenu: + case VGradMenu: + case DGradMenu: + case BGradMenu: + bounds.x = 2; + bounds.y = 2; + bounds.width = mr->width - 5; + bounds.height = mr->height; + + if (type == HGradMenu) { + if (mr->backgroundset == False) { + register int i = 0; + register int dw; + + pmap = XCreatePixmap(dpy, Scr.Root, + mr->width, 5, Scr.d_depth); + pmapgc = + XCreateGC(dpy, pmap, gcm, &gcv); + + bounds.width = mr->width; + dw = (float)bounds.width / + ms->look.face.u.grad.npixels + + 1; + while (i < + ms->look.face.u.grad.npixels) { + unsigned short x = + i * bounds.width / + ms->look.face.u.grad + .npixels; + XSetForeground(dpy, pmapgc, + ms->look.face.u.grad + .pixels[i++]); + XFillRectangle(dpy, pmap, + pmapgc, x, 0, dw, 5); + } + XSetWindowBackgroundPixmap( + dpy, mr->w, pmap); + XFreeGC(dpy, pmapgc); + XFreePixmap(dpy, pmap); + mr->backgroundset = True; + } + XClearWindow(dpy, mr->w); + } else if (type == VGradMenu) { + if (mr->backgroundset == False) { + register int i = 0; + register int dh = + bounds.height / + ms->look.face.u.grad.npixels + + 1; + + pmap = XCreatePixmap(dpy, Scr.Root, 5, + mr->height, Scr.d_depth); + pmapgc = + XCreateGC(dpy, pmap, gcm, &gcv); + + while (i < + ms->look.face.u.grad.npixels) { + unsigned short y = + i * bounds.height / + ms->look.face.u.grad + .npixels; + XSetForeground(dpy, pmapgc, + ms->look.face.u.grad + .pixels[i++]); + XFillRectangle(dpy, pmap, + pmapgc, 0, y, 5, dh); + } + XSetWindowBackgroundPixmap( + dpy, mr->w, pmap); + XFreeGC(dpy, pmapgc); + XFreePixmap(dpy, pmap); + mr->backgroundset = True; + } + XClearWindow(dpy, mr->w); + } else /* D or BGradient */ { + register int i = 0, numLines; + int cindex = -1; + + XSetClipMask(dpy, Scr.TransMaskGC, None); + numLines = mr->width + mr->height - 1; + for (i = 0; i < numLines; i++) { + if ((int)(i * + ms->look.face.u.grad.npixels / + numLines) > cindex) { + /* pick the next colour (skip if + * necc.) */ + cindex = i * + ms->look.face.u.grad + .npixels / + numLines; + XSetForeground(dpy, + Scr.TransMaskGC, + ms->look.face.u.grad + .pixels[cindex]); + } + if (type == DGradMenu) + XDrawLine(dpy, mr->w, + Scr.TransMaskGC, 0, i, i, + 0); + else /* BGradient */ + XDrawLine(dpy, mr->w, + Scr.TransMaskGC, 0, + mr->height - 1 - i, i, + mr->height - 1); + } + } + break; +#endif /* GRADIENT_BUTTONS */ #ifdef PIXMAP_BUTTONS - case PixmapMenu: - p = ms->look.face.u.p; - - border = 0; - width = mr->width - border * 2; height = mr->height - border * 2; - -#if 0 - /* these flags are never set at the moment */ - x = border; - if (ms->look.FaceStyle & HOffCenter) { - if (ms->look.FaceStyle & HRight) - x += (int)(width - p->width); - } else - x += (int)(width - p->width) / 2; - - y = border; - if (ms->look.FaceStyle & VOffCenter) { - if (ms->look.FaceStyle & VBottom) - y += (int)(height - p->height); - } else -#else - y = border + (int)(height - p->height) / 2; - x = border + (int)(width - p->width) / 2; -#endif - - if (x < border) - x = border; - if (y < border) - y = border; - if (width > p->width) - width = p->width; - if (height > p->height) - height = p->height; - if (width > mr->width - x - border) - width = mr->width - x - border; - if (height > mr->height - y - border) - height = mr->height - y - border; - - XSetClipMask(dpy, Scr.TransMaskGC, p->mask); - XSetClipOrigin(dpy, Scr.TransMaskGC, x, y); - XCopyArea(dpy, p->picture, mr->w, Scr.TransMaskGC, - 0, 0, width, height, x, y); - break; - - case TiledPixmapMenu: - XSetWindowBackgroundPixmap(dpy, mr->w, ms->look.face.u.p->picture); - flush_expose(mr->w); - XClearWindow(dpy,mr->w); - break; + case PixmapMenu: + p = ms->look.face.u.p; + + border = 0; + width = mr->width - border * 2; + height = mr->height - border * 2; + + y = border + (int)(height - p->height) / 2; + x = border + (int)(width - p->width) / 2; + + if (x < border) + x = border; + if (y < border) + y = border; + if (width > p->width) + width = p->width; + if (height > p->height) + height = p->height; + if (width > mr->width - x - border) + width = mr->width - x - border; + if (height > mr->height - y - border) + height = mr->height - y - border; + + XSetClipMask(dpy, Scr.TransMaskGC, p->mask); + XSetClipOrigin(dpy, Scr.TransMaskGC, x, y); + XCopyArea(dpy, p->picture, mr->w, Scr.TransMaskGC, 0, 0, + width, height, x, y); + break; + + case TiledPixmapMenu: + XSetWindowBackgroundPixmap( + dpy, mr->w, ms->look.face.u.p->picture); + flush_expose(mr->w); + XClearWindow(dpy, mr->w); + break; #endif /* PIXMAP_BUTTONS */ - } - } - - for (mi = mr->first; mi != NULL; mi = mi->next) - { - /* be smart about handling the expose, redraw only the entries - * that we need to */ - if( (mr->ms->look.face.type != SolidMenu && - mr->ms->look.face.type != SimpleMenu) || pevent == NULL || - (pevent->xexpose.y < (mi->y_offset + mi->y_height) && - (pevent->xexpose.y + pevent->xexpose.height) > mi->y_offset)) - { - PaintEntry(mi); - } - } - - PaintSidePic(mr); - XSync(dpy, 0); - return; -} + } + } + for (mi = mr->first; mi != NULL; mi = mi->next) { + /* be smart about handling the expose, redraw only the entries + * that we need to */ + if ((mr->ms->look.face.type != SolidMenu && + mr->ms->look.face.type != SimpleMenu) || + pevent == NULL || + (pevent->xexpose.y < (mi->y_offset + mi->y_height) && + (pevent->xexpose.y + pevent->xexpose.height) > + mi->y_offset)) { + PaintEntry(mi); + } + } -void FreeMenuItem(MenuItem *mi) -{ - if (!mi) - return; - if (mi->item != NULL) - free(mi->item); - if (mi->item2 != NULL) - free(mi->item2); - if (mi->action != NULL) - free(mi->action); - if(mi->picture) - DestroyPicture(dpy,mi->picture); - if(mi->lpicture) - DestroyPicture(dpy,mi->lpicture); - free(mi); + PaintSidePic(mr); + XSync(dpy, 0); + return; } +void +FreeMenuItem(MenuItem *mi) +{ + if (!mi) + return; + if (mi->item != NULL) + free(mi->item); + if (mi->item2 != NULL) + free(mi->item2); + if (mi->action != NULL) + free(mi->action); + if (mi->picture) + DestroyPicture(dpy, mi->picture); + if (mi->lpicture) + DestroyPicture(dpy, mi->lpicture); + free(mi); +} -void DestroyMenu(MenuRoot *mr) +void +DestroyMenu(MenuRoot *mr) { - MenuItem *mi,*tmp2; - MenuRoot *tmp, *prev; - - if(mr == NULL) - return; - - tmp = Scr.menus.all; - prev = NULL; - while((tmp != NULL)&&(tmp != mr)) - { - prev = tmp; - tmp = tmp->next; - } - if(tmp != mr) - return; - - if(prev == NULL) - Scr.menus.all = mr->next; - else - prev->next = mr->next; - - free(mr->name); - XDestroyWindow(dpy,mr->w); - XDeleteContext(dpy, mr->w, MenuContext); - - if (mr->sidePic) - DestroyPicture(dpy, mr->sidePic); - -#if 0 - /* Hey, we can't just destroy the menu face here. Another menu may need it */ - if (mr->ms != Scr.DefaultMenuStyle && mr->ms) /* I'm a bit paranoid about - segfaults :) */ - { - XFreeGC(dpy,mr->ms->look.MenuReliefGC); - XFreeGC(dpy,mr->ms->look.MenuShadowGC); - XFreeGC(dpy,mr->ms->look.MenuActiveGC); - XFreeGC(dpy,mr->ms->look.MenuGC); - free( mr->ms ); - } -#endif + MenuItem *mi, *tmp2; + MenuRoot *tmp, *prev; + + if (mr == NULL) + return; + + if (mr->in_use) { + PopDownMenu(mr); + mr->in_use = 0; + if (mr->mrDynamicPrev && mr->mrDynamicPrev->selected && + MrPopupForMi(mr->mrDynamicPrev->selected) == mr) { + mr->mrDynamicPrev->selected = NULL; + } + } - /* need to free the window list ? */ - mi = mr->first; - while(mi != NULL) - { - tmp2 = mi->next; - FreeMenuItem(mi); - mi = tmp2; - } - free(mr); + tmp = Scr.menus.all; + prev = NULL; + while ((tmp != NULL) && (tmp != mr)) { + prev = tmp; + tmp = tmp->next; + } + if (tmp != mr) + return; + + if (prev == NULL) + Scr.menus.all = mr->next; + else + prev->next = mr->next; + + free(mr->name); + XDestroyWindow(dpy, mr->w); + XDeleteContext(dpy, mr->w, MenuContext); + + if (mr->sidePic) + DestroyPicture(dpy, mr->sidePic); + + /* need to free the window list ? */ + mi = mr->first; + while (mi != NULL) { + tmp2 = mi->next; + FreeMenuItem(mi); + mi = tmp2; + } + free(mr); } /**************************************************************************** @@ -2230,16 +2307,16 @@ void DestroyMenu(MenuRoot *mr) * Generates the windows for all menus * ****************************************************************************/ -void MakeMenus(void) +void +MakeMenus(void) { - MenuRoot *mr; - - mr = Scr.menus.all; - while(mr != NULL) - { - MakeMenu(mr); - mr = mr->next; - } + MenuRoot *mr; + + mr = Scr.menus.all; + while (mr != NULL) { + MakeMenu(mr); + mr = mr->next; + } } /**************************************************************************** @@ -2247,228 +2324,231 @@ void MakeMenus(void) * Generates the window for a menu * ****************************************************************************/ -void MakeMenu(MenuRoot *mr) +void +MakeMenu(MenuRoot *mr) { - MenuItem *cur; - MenuItem *cur_prev; - unsigned long valuemask; - XSetWindowAttributes attributes; - int y,width; - int cItems; - size_t len; - - if((mr->func != F_POPUP)||(!(Scr.flags & WindowsCaptured))) - return; - - /* merge menu continuations into one menu again - needed when changing the - * font size of a long menu. */ - while (mr->continuation != NULL) - { - MenuRoot *cont = mr->continuation; - - if (mr->first == mr->last) - { - fvwm_msg(ERR, "MakeMenu", "BUG: Menu contains only contionuation"); - break; - } - /* link first item of continuation to item before 'more...' */ - mr->last->prev->next = cont->first; - cont->first->prev = mr->last->prev; - FreeMenuItem(mr->last); - mr ->last = cont->last; - mr->continuation = cont->continuation; - /* fake an empty menu so that DestroyMenu does not destroy the items. */ - cont->first = NULL; - DestroyMenu(cont); - } - - mr->width = 0; - mr->width2 = 0; - mr->width0 = 0; - for (cur = mr->first; cur != NULL; cur = cur->next) - { - width = XTextWidth(mr->ms->look.pStdFont->font, cur->item, cur->strlen); - if(cur->picture && width < cur->picture->width) - width = cur->picture->width; - if(cur->func_type == F_POPUP) - width += 15; - if (width <= 0) - width = 1; - if (width > mr->width) - mr->width = width; - - width = XTextWidth(mr->ms->look.pStdFont->font, cur->item2,cur->strlen2); - if (width < 0) - width = 0; - if (width > mr->width2) - mr->width2 = width; - if((width==0)&&(cur->strlen2>0)) - mr->width2 = 1; - - if(cur->lpicture) - if(mr->width0 < (cur->lpicture->width+3)) - mr->width0 = cur->lpicture->width+3; - } - - /* lets first size the window accordingly */ - mr->width += 10; - if(mr->width2 > 0) - mr->width += 5; - - /* cur_prev trails one behind cur, since we need to move that - into a newly-made menu if we run out of space */ - for (y=2, cItems = 0, cur = mr->first, cur_prev = NULL; - cur != NULL; - cur_prev = cur, cur = cur->next, cItems++) - { - cur->mr = mr; - cur->y_offset = y; - cur->x = 5+mr->width0; - if(IS_TITLE_MENU_ITEM(cur)) - { - width = XTextWidth(mr->ms->look.pStdFont->font, cur->item, - cur->strlen); - /* Title */ - if(cur->strlen2 == 0) - cur->x = (mr->width+mr->width2+mr->width0 - width) / 2; - - if((cur->strlen > 0)||(cur->strlen2>0)) - { - if(mr->ms->look.TitleUnderlines == 2) - cur->y_height = mr->ms->look.EntryHeight + HEIGHT_EXTRA_TITLE; - else - { - if((cur == mr->first)||(cur->next == NULL)) - cur->y_height=mr->ms->look.EntryHeight-HEIGHT_EXTRA+1+ - (HEIGHT_EXTRA_TITLE/2); - else - cur->y_height = mr->ms->look.EntryHeight-HEIGHT_EXTRA +1+ - HEIGHT_EXTRA_TITLE; + MenuItem *cur; + MenuItem *cur_prev; + unsigned long valuemask; + XSetWindowAttributes attributes; + int y, width; + int cItems; + size_t len; + + if ((mr->func != F_POPUP) || (!(Scr.flags & WindowsCaptured))) + return; + + /* merge menu continuations into one menu again - needed when changing + * the font size of a long menu. */ + while (mr->continuation != NULL) { + MenuRoot *cont = mr->continuation; + + if (mr->first == mr->last) { + fvwm_msg(ERR, "MakeMenu", + "BUG: Menu contains only continuation"); + mr->continuation = cont->continuation; + continue; } - } - else { - cur->y_height = HEIGHT_SEPARATOR; - } - /* Titles are separators, too */ - cur->fIsSeparator = TRUE; - } - else if((cur->strlen==0)&&(cur->strlen2 == 0)&& - /* added check for NOP to distinguish from items with no text, - * only pixmap */ - StrEquals(cur->action,"nop")) { - /* Separator */ - cur->y_height = HEIGHT_SEPARATOR; - cur->fIsSeparator = TRUE; - } - else { - /* Normal text entry */ - cur->fIsSeparator = FALSE; - if ((cur->strlen==0)&&(cur->strlen2 == 0)) - cur->y_height = HEIGHT_EXTRA; - else - cur->y_height = mr->ms->look.EntryHeight; - } - if(cur->picture) - cur->y_height += cur->picture->height; - if(cur->lpicture && cur->y_height < cur->lpicture->height+4) - cur->y_height = cur->lpicture->height+4; - y += cur->y_height; - if(mr->width2 == 0) - { - cur->x2 = cur->x; - } - else - { - cur->x2 = mr->width -5 + mr->width0; + /* link first item of continuation to item before 'more...' */ + mr->last->prev->next = cont->first; + cont->first->prev = mr->last->prev; + FreeMenuItem(mr->last); + mr->last = cont->last; + mr->continuation = cont->continuation; + /* fake an empty menu so that DestroyMenu does not destroy the + * items. */ + cont->first = NULL; + DestroyMenu(cont); } - /* this item would have to be the last item, or else - we need to add a "More..." entry pointing to a new menu */ - if (y+mr->ms->look.EntryHeight > Scr.MyDisplayHeight && - cur->next != NULL) - { - char *szMenuContinuationActionAndName; - MenuRoot *menuContinuation; - - if (mr->continuation != NULL) { - fvwm_msg(ERR, "MakeMenu", - "Confused-- expected continuation to be null"); - break; - } - len = 8 + strlen(mr->name); - szMenuContinuationActionAndName = (char *) safemalloc(len); - strlcpy(szMenuContinuationActionAndName,"Popup ", len); - strlcat(szMenuContinuationActionAndName, mr->name, len); - strlcat(szMenuContinuationActionAndName,"$", len); - /* NewMenuRoot inserts at the head of the list of menus - but, we need it at the end */ - /* (Give it just the name, which is 6 chars past the action - since strlen("Popup ")==6 ) */ - menuContinuation = NewMenuRoot(szMenuContinuationActionAndName+6, - False); - mr->continuation = menuContinuation; - - /* Now move this item and the remaining items into the new menu */ - cItems--; - menuContinuation->first = cur; - menuContinuation->last = mr->last; - menuContinuation->items = mr->items - cItems; - cur->prev = NULL; - - /* cur_prev is now the last item in the current menu */ - mr->last = cur_prev; - mr->items = cItems; - cur_prev->next = NULL; - - /* Go back one, so that this loop will process the new item */ - y -= cur->y_height; - cur = cur_prev; - - /* And add the entry pointing to the new menu */ - AddToMenu(mr,"More&...",szMenuContinuationActionAndName, - FALSE /* no pixmap scan */, FALSE); - MakeMenu(menuContinuation); - free(szMenuContinuationActionAndName); + + mr->width = 0; + mr->width2 = 0; + mr->width0 = 0; + for (cur = mr->first; cur != NULL; cur = cur->next) { + width = XTextWidth( + mr->ms->look.pStdFont->font, cur->item, cur->strlen); + if (cur->picture && width < cur->picture->width) + width = cur->picture->width; + if (cur->func_type == F_POPUP) + width += 15; + if (width <= 0) + width = 1; + if (width > mr->width) + mr->width = width; + + width = XTextWidth( + mr->ms->look.pStdFont->font, cur->item2, cur->strlen2); + if (width < 0) + width = 0; + if (width > mr->width2) + mr->width2 = width; + if ((width == 0) && (cur->strlen2 > 0)) + mr->width2 = 1; + + if (cur->lpicture) + if (mr->width0 < (cur->lpicture->width + 3)) + mr->width0 = cur->lpicture->width + 3; } - } /* for */ - mr->in_use = 0; - /* allow two pixels for top border */ - mr->height = y + ((mr->ms->look.ReliefThickness == 1) ? 2 : 3); - mr->flags.allflags = 0; - mr->xanimation = 0; + + /* lets first size the window accordingly */ + mr->width += 10; + if (mr->width2 > 0) + mr->width += 5; + + /* cur_prev trails one behind cur, since we need to move that + into a newly-made menu if we run out of space */ + for (y = 2, cItems = 0, cur = mr->first, cur_prev = NULL; cur != NULL; + cur_prev = cur, cur = cur->next, cItems++) { + cur->mr = mr; + cur->y_offset = y; + cur->x = 5 + mr->width0; + if (IS_TITLE_MENU_ITEM(cur)) { + width = XTextWidth(mr->ms->look.pStdFont->font, + cur->item, cur->strlen); + /* Title */ + if (cur->strlen2 == 0) + cur->x = (mr->width + mr->width2 + mr->width0 - + width) / + 2; + + if ((cur->strlen > 0) || (cur->strlen2 > 0)) { + if (mr->ms->look.TitleUnderlines == 2) + cur->y_height = + mr->ms->look.EntryHeight + + HEIGHT_EXTRA_TITLE; + else { + if ((cur == mr->first) || + (cur->next == NULL)) + cur->y_height = + mr->ms->look.EntryHeight - + HEIGHT_EXTRA + 1 + + (HEIGHT_EXTRA_TITLE / 2); + else + cur->y_height = + mr->ms->look.EntryHeight - + HEIGHT_EXTRA + 1 + + HEIGHT_EXTRA_TITLE; + } + } else { + cur->y_height = HEIGHT_SEPARATOR; + } + /* Titles are separators, too */ + cur->fIsSeparator = TRUE; + } else if ((cur->strlen == 0) && (cur->strlen2 == 0) && + /* added check for NOP to distinguish from items with + * no text, only pixmap */ + StrEquals(cur->action, "nop")) { + /* Separator */ + cur->y_height = HEIGHT_SEPARATOR; + cur->fIsSeparator = TRUE; + } else { + /* Normal text entry */ + cur->fIsSeparator = FALSE; + if ((cur->strlen == 0) && (cur->strlen2 == 0)) + cur->y_height = HEIGHT_EXTRA; + else + cur->y_height = mr->ms->look.EntryHeight; + } + if (cur->picture) + cur->y_height += cur->picture->height; + if (cur->lpicture && cur->y_height < cur->lpicture->height + 4) + cur->y_height = cur->lpicture->height + 4; + y += cur->y_height; + if (mr->width2 == 0) { + cur->x2 = cur->x; + } else { + cur->x2 = mr->width - 5 + mr->width0; + } + /* this item would have to be the last item, or else + we need to add a "More..." entry pointing to a new menu */ + if (y + mr->ms->look.EntryHeight > Scr.MyDisplayHeight && + cur->next != NULL) { + char *szMenuContinuationActionAndName; + MenuRoot *menuContinuation; + + if (mr->continuation != NULL) { + fvwm_msg(ERR, "MakeMenu", + "Confused-- expected continuation to be " + "null"); + break; + } + len = 8 + strlen(mr->name); + szMenuContinuationActionAndName = + (char *)xmalloc(len); + strlcpy(szMenuContinuationActionAndName, "Popup ", len); + strlcat(szMenuContinuationActionAndName, mr->name, len); + strlcat(szMenuContinuationActionAndName, "$", len); + /* NewMenuRoot inserts at the head of the list of menus + but, we need it at the end */ + /* (Give it just the name, which is 6 chars past the + action since strlen("Popup ")==6 ) */ + menuContinuation = NewMenuRoot( + szMenuContinuationActionAndName + 6, False); + mr->continuation = menuContinuation; + + /* Now move this item and the remaining items into the + * new menu */ + cItems--; + menuContinuation->first = cur; + menuContinuation->last = mr->last; + menuContinuation->items = mr->items - cItems; + cur->prev = NULL; + + /* cur_prev is now the last item in the current menu */ + mr->last = cur_prev; + mr->items = cItems; + cur_prev->next = NULL; + + /* Go back one, so that this loop will process the new + * item */ + y -= cur->y_height; + cur = cur_prev; + + /* And add the entry pointing to the new menu */ + AddToMenu(mr, "More&...", + szMenuContinuationActionAndName, + FALSE /* no pixmap scan */, FALSE); + MakeMenu(menuContinuation); + free(szMenuContinuationActionAndName); + } + } /* for */ + mr->in_use = 0; + /* allow two pixels for top border */ + mr->height = y + ((mr->ms->look.ReliefThickness == 1) ? 2 : 3); + mr->flags.allflags = 0; + mr->xanimation = 0; #ifndef NO_SAVEUNDERS - valuemask = (CWBackPixel | CWEventMask | CWCursor | CWSaveUnder); + valuemask = (CWBackPixel | CWEventMask | CWCursor | CWSaveUnder); #else - valuemask = (CWBackPixel | CWEventMask | CWCursor); + valuemask = (CWBackPixel | CWEventMask | CWCursor); #endif - attributes.background_pixel = mr->ms->look.MenuColors.back; - attributes.event_mask = (ExposureMask | EnterWindowMask); - attributes.cursor = Scr.FvwmCursors[MENU]; + attributes.background_pixel = mr->ms->look.MenuColors.back; + attributes.event_mask = (ExposureMask | EnterWindowMask); + attributes.cursor = Scr.FvwmCursors[MENU]; #ifndef NO_SAVEUNDERS - attributes.save_under = TRUE; + attributes.save_under = TRUE; #endif - if(mr->w != None) - XDestroyWindow(dpy,mr->w); - - mr->xoffset = 0; - if(mr->sidePic) { - mr->xoffset = mr->sidePic->width + 5; - } - else if (mr->ms->look.sidePic) { - mr->xoffset = mr->ms->look.sidePic->width + 5; - } - - mr->width = mr->width0 + mr->width + mr->width2 + mr->xoffset; - mr->backgroundset = False; - - mr->w = XCreateWindow (dpy, Scr.Root, 0, 0, (unsigned int) (mr->width), - (unsigned int) mr->height, (unsigned int) 0, - CopyFromParent, (unsigned int) InputOutput, - (Visual *) CopyFromParent, - valuemask, &attributes); - XSaveContext(dpy,mr->w,MenuContext,(caddr_t)mr); - - return; + if (mr->w != None) + XDestroyWindow(dpy, mr->w); + + mr->xoffset = 0; + if (mr->sidePic) { + mr->xoffset = mr->sidePic->width + 5; + } else if (mr->ms->look.sidePic) { + mr->xoffset = mr->ms->look.sidePic->width + 5; + } + + mr->width = mr->width0 + mr->width + mr->width2 + mr->xoffset; + mr->backgroundset = False; + + mr->w = XCreateWindow(dpy, Scr.Root, 0, 0, (unsigned int)(mr->width), + (unsigned int)mr->height, (unsigned int)0, CopyFromParent, + (unsigned int)InputOutput, (Visual *)CopyFromParent, valuemask, + &attributes); + XSaveContext(dpy, mr->w, MenuContext, (caddr_t)mr); + + return; } /* FHotKeyUsedBefore @@ -2476,23 +2556,22 @@ void MakeMenu(MenuRoot *mr) * used the given hotkey already * This means that it doesn't check the last element of the menu */ -int FHotKeyUsedBefore(MenuRoot *menu, char ch) { - int f = FALSE; - MenuItem *currentMenuItem = menu->first; - /* we want to stop just before the last item in the menu */ - while (currentMenuItem != 0 && currentMenuItem->next != 0) - { - if (currentMenuItem->chHotkey == ch) - { - f = TRUE; - break; - } - currentMenuItem = currentMenuItem->next; - } - return f; +int +FHotKeyUsedBefore(MenuRoot *menu, char ch) +{ + int f = FALSE; + MenuItem *currentMenuItem = menu->first; + /* we want to stop just before the last item in the menu */ + while (currentMenuItem != 0 && currentMenuItem->next != 0) { + if (currentMenuItem->chHotkey == ch) { + f = TRUE; + break; + } + currentMenuItem = currentMenuItem->next; + } + return f; } - /*********************************************************************** * Procedure: * scanForHotkeys - Look for hotkey markers in a MenuItem @@ -2503,171 +2582,172 @@ int FHotKeyUsedBefore(MenuRoot *menu, char ch) { * which - +1 to look in it->item1 and -1 to look in it->item2. * ***********************************************************************/ -char scanForHotkeys(MenuItem *it, int which) +char +scanForHotkeys(MenuItem *it, int which) { - char *start, *txt; - - start = (which > 0) ? it->item : it->item2; /* Get start of string */ - for (txt = start; *txt != '\0'; txt++) - { - /* Scan whole string */ - if (*txt == '&') - { /* A hotkey marker? */ - if (txt[1] == '&') - { /* Just an escaped & */ - char *tmp; /* Copy the string down over it */ - for (tmp = txt; *tmp != '\0'; tmp++) tmp[0] = tmp[1]; - continue; /* ...And skip to the key char */ - } - else { - char ch = txt[1]; - /* It's a hot key marker - work out the offset value */ - it->hotkey = (1 + (txt - start)) * which; - for (; *txt != '\0'; txt++) txt[0] = txt[1];/* Copy down.. */ - return ch; /* Only one hotkey per item... */ - } + char *start, *txt; + + start = (which > 0) ? it->item : it->item2; /* Get start of string + */ + for (txt = start; *txt != '\0'; txt++) { + /* Scan whole string */ + if (*txt == '&') { /* A hotkey marker? */ + if (txt[1] == + '&') { /* Just an escaped & */ + char *tmp; /* Copy the string down over it + */ + for (tmp = txt; *tmp != '\0'; tmp++) + tmp[0] = tmp[1]; + continue; /* ...And skip to the key char + */ + } else { + char ch = txt[1]; + /* It's a hot key marker - work out the offset + * value */ + it->hotkey = (1 + (txt - start)) * which; + for (; *txt != '\0'; txt++) + txt[0] = txt[1]; /* Copy down.. */ + return ch; /* Only one hotkey per item... + */ + } + } } - } - it->hotkey = 0; /* No hotkey found. Set offset to zero */ - return '\0'; + it->hotkey = 0; /* No hotkey found. Set offset to zero */ + return '\0'; } - /* Side picture support: this scans for a color int the menu name for colorization */ -void scanForColor(char *instring, Pixel *p, Bool *c, char identifier) +void +scanForColor(char *instring, Pixel *p, Bool *c, char identifier) { - char *tstart, *txt, *save_instring, *name; - int i; - size_t len; - - *c = False; - - /* save instring in case can't find pixmap */ - save_instring = (char *)safemalloc(strlen(instring)+1); - len = strlen(instring)+1; - name = (char *)safemalloc(len); - strlcpy(save_instring,instring, len); - - /* Scan whole string */ - for (txt = instring; *txt != '\0'; txt++) - { - /* A hotkey marker? */ - if (*txt == identifier) - { - /* Just an escaped '^' */ - if (txt[1] == identifier) - { - char *tmp; /* Copy the string down over it */ - for (tmp = txt; *tmp != '\0'; tmp++) tmp[0] = tmp[1]; - continue; /* ...And skip to the key char */ - } - /* It's a hot key marker - work out the offset value */ - tstart = txt; - txt++; - i=0; - while((*txt != identifier)&&(*txt != '\0')) - { - name[i] = *txt; - txt++; - i++; - } - name[i] = 0; - - *p = GetColor(name); - *c = True; - - if(*txt != '\0')txt++; - while(*txt != '\0') - { - *tstart++ = *txt++; - } - *tstart = 0; - break; - } - } - free(name); - free(save_instring); - return; + char *tstart, *txt, *save_instring, *name; + int i; + size_t len; + + *c = False; + + /* save instring in case can't find pixmap */ + save_instring = (char *)xmalloc(strlen(instring) + 1); + len = strlen(instring) + 1; + name = (char *)xmalloc(len); + strlcpy(save_instring, instring, len); + + /* Scan whole string */ + for (txt = instring; *txt != '\0'; txt++) { + /* A hotkey marker? */ + if (*txt == identifier) { + /* Just an escaped '^' */ + if (txt[1] == identifier) { + char *tmp; /* Copy the string down over it */ + for (tmp = txt; *tmp != '\0'; tmp++) + tmp[0] = tmp[1]; + continue; /* ...And skip to the key char */ + } + /* It's a hot key marker - work out the offset value */ + tstart = txt; + txt++; + i = 0; + while ((*txt != identifier) && (*txt != '\0')) { + name[i] = *txt; + txt++; + i++; + } + name[i] = 0; + + *p = GetColor(name); + *c = True; + + if (*txt != '\0') + txt++; + while (*txt != '\0') { + *tstart++ = *txt++; + } + *tstart = 0; + break; + } + } + free(name); + free(save_instring); + return; } -void scanForPixmap(char *instring, FvwmPicture **p, char identifier) +void +scanForPixmap(char *instring, FvwmPicture **p, char identifier) { - char *tstart, *txt, *name; - int i; - FvwmPicture *pp; - extern char *IconPath; - extern char *PixmapPath; + char *tstart, *txt, *name; + int i; + FvwmPicture *pp; + extern char *IconPath; + extern char *PixmapPath; #ifdef UGLY_WHEN_PIXMAPS_MISSING - char *save_instring; - size_t len; + char *save_instring; + size_t len; #endif - if (!instring) - { - *p = NULL; - return; - } + if (!instring) { + *p = NULL; + return; + } #ifdef UGLY_WHEN_PIXMAPS_MISSING - /* save instring in case can't find pixmap */ - len = strlen(instring)+1; - save_instring = (char *)safemalloc(len); - strlcpy(save_instring,instring,len); + /* save instring in case can't find pixmap */ + len = strlen(instring) + 1; + save_instring = (char *)xmalloc(len); + strlcpy(save_instring, instring, len); #endif - name = (char *)safemalloc(strlen(instring)+1); - - /* Scan whole string */ - for (txt = instring; *txt != '\0'; txt++) - { - /* A hotkey marker? */ - if (*txt == identifier) - { - /* Just an escaped & */ - if (txt[1] == identifier) - { - char *tmp; /* Copy the string down over it */ - for (tmp = txt; *tmp != '\0'; tmp++) - tmp[0] = tmp[1]; - continue; /* ...And skip to the key char */ - } - /* It's a hot key marker - work out the offset value */ - tstart = txt; - txt++; - i=0; - while((*txt != identifier)&&(*txt != '\0')) - { - name[i] = *txt; - txt++; - i++; - } - name[i] = 0; - - /* Next, check for a color pixmap */ - pp=CachePicture(dpy,Scr.Root,IconPath,PixmapPath,name, - Scr.ColorLimit); - if(*txt != '\0') - txt++; - while(*txt != '\0') - { - *tstart++ = *txt++; - } - *tstart = 0; - if (pp) - *p = pp; - else + name = (char *)xmalloc(strlen(instring) + 1); + + /* Scan whole string */ + for (txt = instring; *txt != '\0'; txt++) { + /* A hotkey marker? */ + if (*txt == identifier) { + /* Just an escaped & */ + if (txt[1] == identifier) { + char *tmp; /* Copy the string down over it + */ + for (tmp = txt; *tmp != '\0'; tmp++) + tmp[0] = tmp[1]; + continue; /* ...And skip to the key char + */ + } + /* It's a hot key marker - work out the offset value + */ + tstart = txt; + txt++; + i = 0; + while ((*txt != identifier) && (*txt != '\0')) { + name[i] = *txt; + txt++; + i++; + } + name[i] = 0; + + /* Next, check for a color pixmap */ + pp = CachePicture(dpy, Scr.Root, IconPath, PixmapPath, + name, Scr.ColorLimit); + if (*txt != '\0') + txt++; + while (*txt != '\0') { + *tstart++ = *txt++; + } + *tstart = 0; + if (pp) + *p = pp; + else #ifdef UGLY_WHEN_PIXMAPS_MISSING - strlcpy(instring,save_instring,len); + strlcpy(instring, save_instring, len); #else - fvwm_msg(WARN,"scanForPixmap","Couldn't find pixmap %s",name); + fvwm_msg(WARN, "scanForPixmap", + "Couldn't find pixmap %s", name); #endif - break; + break; + } } - } - free(name); + free(name); #ifdef UGLY_WHEN_PIXMAPS_MISSING - free(save_instring); + free(save_instring); #endif } @@ -2675,16 +2755,15 @@ void scanForPixmap(char *instring, FvwmPicture **p, char identifier) * Given an menu root, return the menu root to add to by * following continuation links until there are no more */ -MenuRoot *FollowMenuContinuations(MenuRoot *mr, MenuRoot **pmrPrior ) +MenuRoot * +FollowMenuContinuations(MenuRoot *mr, MenuRoot **pmrPrior) { - *pmrPrior = NULL; - while ((mr != NULL) && - (mr->continuation != NULL)) - { - *pmrPrior = mr; - mr = mr->continuation; - } - return mr; + *pmrPrior = NULL; + while ((mr != NULL) && (mr->continuation != NULL)) { + *pmrPrior = mr; + mr = mr->continuation; + } + return mr; } /*********************************************************************** @@ -2705,171 +2784,150 @@ MenuRoot *FollowMenuContinuations(MenuRoot *mr, MenuRoot **pmrPrior ) * so built in window list can handle windows w/ * and % in title. * ***********************************************************************/ -void AddToMenu(MenuRoot *menu, char *item, char *action, Bool fPixmapsOk, - Bool fNoPlus) +void +AddToMenu( + MenuRoot *menu, char *item, char *action, Bool fPixmapsOk, Bool fNoPlus) { - MenuItem *tmp; - char *start,*end; - char *token = NULL; - char *token2 = NULL; - char *option = NULL; - - if ((item == NULL || *item == 0) && fNoPlus) - return; - /* empty items screw up our menu when painted, so we replace them with a - * separator */ - if (item == NULL) - item = ""; - if (action == NULL || *action == 0) - action = "Nop"; - GetNextToken(GetNextToken(action, &token), &option); - - tmp = (MenuItem *)safemalloc(sizeof(MenuItem)); - tmp->chHotkey = '\0'; - tmp->next = NULL; - tmp->mr = menu; /* this gets updated in MakeMenu if we split the menu - because it's too large vertically */ - if (menu->first == NULL) - { - menu->first = tmp; - menu->last = tmp; - tmp->prev = NULL; - } - else if (StrEquals(token, "title") && option && StrEquals(option, "top")) - { - if (menu->first->action) - { - GetNextToken(menu->first->action, &token2); - } - if (StrEquals(token2, "title")) - { - tmp->next = menu->first->next; - FreeMenuItem(menu->first); - } - else - { - tmp->next = menu->first; - } - if (token2) - free(token2); - tmp->prev = NULL; - if (menu->first == NULL) - menu->last = tmp; - menu->first = tmp; - } - else - { - menu->last->next = tmp; - tmp->prev = menu->last; - menu->last = tmp; - } - if (token) - free(token); - if (option) - free(option); - tmp->picture=NULL; - tmp->lpicture=NULL; - - /* skip leading spaces */ - /*while(isspace(*item)&&(item != NULL)) - item++;*/ - /* up to first tab goes in "item" field */ - start = item; - end=item; - while((*end != '\t')&&(*end != 0)) - end++; - tmp->item = safemalloc(end-start+1); - strncpy(tmp->item,start,end-start); - tmp->item[end-start] = 0; - tmp->item2 = NULL; - if(*end=='\t') - { - start = end+1; - while(*start == '\t') - start++; - end = start; - while(*end != 0) - end++; - if(end > start) - { - char *s; - - tmp->item2 = safemalloc(end-start+1); - strncpy(tmp->item2,start,end-start); - tmp->item2[end-start] = 0; - s = tmp->item2; - while (*s) - { - if (*s == '\t') - *s = ' '; - s++; - } - } - } - - if (item != (char *)0) - { - char ch; - if (fPixmapsOk) - { - scanForPixmap(tmp->item,&tmp->picture,'*'); - scanForPixmap(tmp->item,&tmp->lpicture,'%'); - } - ch = scanForHotkeys(tmp, 1); /* pete@tecc.co.uk */ - if (ch != '\0') - { - if (FHotKeyUsedBefore(menu,ch)) - { - fvwm_msg(WARN, "AddToMenu", - "Hotkey %c is reused in menu %s; second binding ignored.", - ch, menu->name); - tmp->hotkey = 0; - } - else - { - tmp->chHotkey = ch; - } + MenuItem *tmp; + char *start, *end; + char *token = NULL; + char *token2 = NULL; + char *option = NULL; + + if ((item == NULL || *item == 0) && fNoPlus) + return; + /* empty items screw up our menu when painted, so we replace them with a + * separator */ + if (item == NULL) + item = ""; + if (action == NULL || *action == 0) + action = "Nop"; + GetNextToken(GetNextToken(action, &token), &option); + + tmp = (MenuItem *)xmalloc(sizeof(MenuItem)); + tmp->chHotkey = '\0'; + tmp->next = NULL; + tmp->mr = menu; /* this gets updated in MakeMenu if we split the menu + because it's too large vertically */ + if (menu->first == NULL) { + menu->first = tmp; + menu->last = tmp; + tmp->prev = NULL; + } else if (StrEquals(token, "title") && option && + StrEquals(option, "top")) { + if (menu->first->action) { + GetNextToken(menu->first->action, &token2); + } + if (StrEquals(token2, "title")) { + tmp->next = menu->first->next; + FreeMenuItem(menu->first); + } else { + tmp->next = menu->first; + } + if (token2) + free(token2); + tmp->prev = NULL; + if (menu->first == NULL) + menu->last = tmp; + menu->first = tmp; + } else { + menu->last->next = tmp; + tmp->prev = menu->last; + menu->last = tmp; } - tmp->strlen = strlen(tmp->item); - } - else - tmp->strlen = 0; - - if (tmp->item2 != (char *)0) - { - if (fPixmapsOk) - { - if(!tmp->picture) - scanForPixmap(tmp->item2,&tmp->picture,'*'); - if(!tmp->lpicture) - scanForPixmap(tmp->item2,&tmp->lpicture,'%'); - } - if (tmp->hotkey == 0) { - char ch = scanForHotkeys(tmp, -1); /* pete@tecc.co.uk */ - if (ch != '\0') - { - if (FHotKeyUsedBefore(menu,ch)) - { - fvwm_msg(WARN, "AddToMenu", - "Hotkey %c is reused in menu %s; second binding ignored.", - ch, menu->name); - tmp->hotkey = 0; - } - else - { - tmp->chHotkey = ch; - } + if (token) + free(token); + if (option) + free(option); + tmp->picture = NULL; + tmp->lpicture = NULL; + + /* skip leading spaces */ + /*while(isspace(*item)&&(item != NULL)) + item++;*/ + /* up to first tab goes in "item" field */ + start = item; + end = item; + while ((*end != '\t') && (*end != 0)) + end++; + tmp->item = xmalloc(end - start + 1); + strncpy(tmp->item, start, end - start); + tmp->item[end - start] = 0; + tmp->item2 = NULL; + if (*end == '\t') { + start = end + 1; + while (*start == '\t') + start++; + end = start; + while (*end != 0) + end++; + if (end > start) { + char *s; + + tmp->item2 = xmalloc(end - start + 1); + strncpy(tmp->item2, start, end - start); + tmp->item2[end - start] = 0; + s = tmp->item2; + while (*s) { + if (*s == '\t') + *s = ' '; + s++; + } + } } - } - tmp->strlen2 = strlen(tmp->item2); - } - else - tmp->strlen2 = 0; - - tmp->action = stripcpy(action); - tmp->state = 0; - find_func_type(tmp->action, &(tmp->func_type), &(tmp->func_needs_window)); - tmp->item_num = menu->items++; + + if (item != (char *)0) { + char ch; + if (fPixmapsOk) { + scanForPixmap(tmp->item, &tmp->picture, '*'); + scanForPixmap(tmp->item, &tmp->lpicture, '%'); + } + ch = scanForHotkeys(tmp, 1); /* pete@tecc.co.uk */ + if (ch != '\0') { + if (FHotKeyUsedBefore(menu, ch)) { + fvwm_msg(WARN, "AddToMenu", + "Hotkey %c is reused in menu %s; second " + "binding ignored.", + ch, menu->name); + tmp->hotkey = 0; + } else { + tmp->chHotkey = ch; + } + } + tmp->strlen = strlen(tmp->item); + } else + tmp->strlen = 0; + + if (tmp->item2 != (char *)0) { + if (fPixmapsOk) { + if (!tmp->picture) + scanForPixmap(tmp->item2, &tmp->picture, '*'); + if (!tmp->lpicture) + scanForPixmap(tmp->item2, &tmp->lpicture, '%'); + } + if (tmp->hotkey == 0) { + char ch = scanForHotkeys(tmp, -1); /* pete@tecc.co.uk */ + if (ch != '\0') { + if (FHotKeyUsedBefore(menu, ch)) { + fvwm_msg(WARN, "AddToMenu", + "Hotkey %c is reused in menu %s; " + "second binding ignored.", + ch, menu->name); + tmp->hotkey = 0; + } else { + tmp->chHotkey = ch; + } + } + } + tmp->strlen2 = strlen(tmp->item2); + } else + tmp->strlen2 = 0; + + tmp->action = stripcpy(action); + tmp->state = 0; + find_func_type( + tmp->action, &(tmp->func_type), &(tmp->func_needs_window)); + tmp->item_num = menu->items++; } /*********************************************************************** @@ -2886,46 +2944,45 @@ void AddToMenu(MenuRoot *menu, char *item, char *action, Bool fPixmapsOk, * F_POPUP otherwise * ***********************************************************************/ -MenuRoot *NewMenuRoot(char *name, Bool fFunction) +MenuRoot * +NewMenuRoot(char *name, Bool fFunction) { - MenuRoot *tmp; + MenuRoot *tmp; - tmp = (MenuRoot *) safemalloc(sizeof(MenuRoot)); + tmp = (MenuRoot *)xmalloc(sizeof(MenuRoot)); - tmp->first = NULL; - tmp->last = NULL; - tmp->selected = NULL; + tmp->first = NULL; + tmp->last = NULL; + tmp->selected = NULL; #ifdef GRADIENT_BUTTONS - tmp->stored_item.width = 0; - tmp->stored_item.height = 0; - tmp->stored_item.y = 0; + tmp->stored_item.width = 0; + tmp->stored_item.height = 0; + tmp->stored_item.y = 0; #endif - tmp->next = Scr.menus.all; - tmp->continuation = NULL; - tmp->mrDynamicPrev = NULL; - tmp->name = stripcpy(name); - tmp->w = None; - tmp->height = 0; - tmp->width = 0; - tmp->width2 = 0; - tmp->width0 = 0; - tmp->items = 0; - tmp->in_use = 0; - tmp->func = (fFunction) ? F_FUNCTION : F_POPUP; - tmp->sidePic = NULL; - scanForPixmap(tmp->name, &tmp->sidePic, '@'); - scanForColor(tmp->name, &tmp->sideColor, &tmp->colorize,'^'); - tmp->xoffset = 0; - tmp->ms = Scr.menus.DefaultStyle; - tmp->flags.allflags = 0; - tmp->xanimation = 0; - - Scr.menus.all = tmp; - return (tmp); + tmp->next = Scr.menus.all; + tmp->continuation = NULL; + tmp->mrDynamicPrev = NULL; + tmp->name = stripcpy(name); + tmp->w = None; + tmp->height = 0; + tmp->width = 0; + tmp->width2 = 0; + tmp->width0 = 0; + tmp->items = 0; + tmp->in_use = 0; + tmp->func = (fFunction) ? F_FUNCTION : F_POPUP; + tmp->sidePic = NULL; + scanForPixmap(tmp->name, &tmp->sidePic, '@'); + scanForColor(tmp->name, &tmp->sideColor, &tmp->colorize, '^'); + tmp->xoffset = 0; + tmp->ms = Scr.menus.DefaultStyle; + tmp->flags.allflags = 0; + tmp->xanimation = 0; + + Scr.menus.all = tmp; + return (tmp); } - - /*********************************************************************** * change by KitS@bartley.demon.co.uk to correct popups off title buttons * @@ -2942,33 +2999,31 @@ MenuRoot *NewMenuRoot(char *name, Bool fFunction) * t - the window (FvwmWindow) to test against * ***********************************************************************/ -int ButtonPosition(int context, FvwmWindow * t) +int +ButtonPosition(int context, FvwmWindow *t) { - int i; - int buttons = -1; - - if (context&C_RALL) { - for(i=0;iright_w[i]) { - buttons++; + int i; + int buttons = -1; + + if (context & C_RALL) { + for (i = 0; i < Scr.nr_right_buttons; i++) { + if (t->right_w[i]) { + buttons++; + } + /* is this the button ? */ + if (((1 << i) * C_R1) & context) + return (buttons); + } + } else { + for (i = 0; i < Scr.nr_left_buttons; i++) { + if (t->left_w[i]) { + buttons++; + } + /* is this the button ? */ + if (((1 << i) * C_L1) & context) + return (buttons); + } } - /* is this the button ? */ - if (((1<left_w[i]) - { - buttons++; - } - /* is this the button ? */ - if (((1<mr when - selected IS_POPUP_MENU_ITEM(selected) */ - struct MenuRoot *mrDynamicPrev; /* the menu that popped this up, if any */ + struct MenuRoot *next; /* next in list of root menus */ + struct MenuRoot *continuation; /* continuation of this menu + * (too tall for screen */ + /* can get the menu that this popped up through selected->mr when + selected IS_POPUP_MENU_ITEM(selected) */ + struct MenuRoot *mrDynamicPrev; /* the menu that popped this up, if any */ - char *name; /* name of root */ - Window w; /* the window of the menu */ - short height; /* height of the menu */ - short width; /* width of the menu for 1st col */ - short width2; /* width of the menu for 2nd col */ - short width0; /* width of the menu-left-picture col */ - short items; /* number of items in the menu */ - Bool backgroundset; /* is win background set for this menu ?? */ - Bool in_use; - int func; - FvwmPicture *sidePic; - Pixel sideColor; - Bool colorize; - short xoffset; - MenuStyle *ms; /* Menu Face */ - union /* internal flags, deleted when menu pops down! */ - { - /* need to change that type if we have more than 8 flags. - * more that a word will entail some changes in the code! */ - unsigned char allflags; - struct - { - unsigned painted : 1; - unsigned is_left : 1; /* menu direction relative to parent menu */ - unsigned is_right : 1; - unsigned is_up : 1; - unsigned is_down : 1; - } f; - } flags; - int xanimation; /* x distance window was moved by animation */ + char *name; /* name of root */ + Window w; /* the window of the menu */ + short height; /* height of the menu */ + short width; /* width of the menu for 1st col */ + short width2; /* width of the menu for 2nd col */ + short width0; /* width of the menu-left-picture col */ + short items; /* number of items in the menu */ + Bool backgroundset; /* is win background set for this menu ?? */ + Bool in_use; + int func; + FvwmPicture *sidePic; + Pixel sideColor; + Bool colorize; + short xoffset; + MenuStyle *ms; /* Menu Face */ + union /* internal flags, deleted when menu pops down! */ { + /* need to change that type if we have more than 8 flags. + * more that a word will entail some changes in the code! */ + unsigned char allflags; + struct { + unsigned painted:1; + unsigned is_left:1; /* menu direction relative to parent menu */ + unsigned is_right:1; + unsigned is_up:1; + unsigned is_down:1; + } f; + } flags; + int xanimation; /* x distance window was moved by animation */ } MenuRoot; /* don't forget to initialise new members in NewMenuRoot()! */ typedef struct MenuGlobals { - MenuRoot *all; - struct MenuStyle *DefaultStyle; - struct MenuStyle *LastStyle; - int PopupDelay10ms; - int DoubleClickTime; + MenuRoot *all; + struct MenuStyle *DefaultStyle; + struct MenuStyle *LastStyle; + int PopupDelay10ms; + int DoubleClickTime; } MenuGlobals; -typedef struct Binding -{ - char IsMouse; /* Is it a mouse or key binding 1= mouse; */ - int Button_Key; /* Mouse Button number of Keycode */ - char *key_name; /* In case of keycode, give the key_name too */ - int Context; /* Contex is Fvwm context, ie titlebar, frame, etc */ - int Modifier; /* Modifiers for keyboard state */ - char *Action; /* What to do? */ - struct Binding *NextBinding; +typedef struct Binding { + char IsMouse; /* Is it a mouse or key binding 1= mouse; */ + int Button_Key; /* Mouse Button number of Keycode */ + char *key_name; /* In case of keycode, give the key_name too */ + int Context; /* Contex is Fvwm context, ie titlebar, frame, etc */ + int Modifier; /* Modifiers for keyboard state */ + char *Action; /* What to do? */ + struct Binding *NextBinding; } Binding; -typedef struct -{ - int x; /* suggested x position */ - int y; /* suggested y position */ - float x_factor; /* to take menu width into account (0, -1 or -0.5) */ - float y_factor; /* same with height */ - Bool fRelative; /* FALSE if referring to absolute screen position */ +typedef struct { + int x; /* suggested x position */ + int y; /* suggested y position */ + float x_factor; /* to take menu width into account (0, -1 or -0.5) */ + float y_factor; /* same with height */ + Bool fRelative; /* FALSE if referring to absolute screen position */ } MenuPosHints; -typedef struct -{ - MenuPosHints pos_hints; - union - { - /* need to change that type if we have more than 8 flags. - * more that a word will entail some changes in the code! */ - unsigned char allflags; - struct - { - unsigned no_warp : 1; - unsigned warp_title : 1; - unsigned fixed : 1; - unsigned select_in_place : 1; - unsigned select_warp : 1; - unsigned has_poshints : 1; - } f; - } flags; +typedef struct { + MenuPosHints pos_hints; + union { + /* need to change that type if we have more than 8 flags. + * more that a word will entail some changes in the code! */ + unsigned char allflags; + struct { + unsigned no_warp:1; + unsigned warp_title:1; + unsigned fixed:1; + unsigned select_in_place:1; + unsigned select_warp:1; + unsigned has_poshints:1; + } f; + } flags; } MenuOptions; extern MenuPosHints lastMenuPosHints; extern Bool fLastMenuPosHintsValid; - /* Return values for UpdateMenu, do_menu, menuShortcuts */ /* Just uses enum-s for their constant value, replaced a bunch of #define-s * before */ /* This is a lame hack, in that "_BUTTON" is added to mean a button-release caused the return-- the macros below help deal with the ugliness */ typedef enum { - MENU_ERROR = -1, - MENU_NOP = 0, - MENU_DONE = 1, - MENU_DONE_BUTTON = 2, /* must be MENU_DONE + 1 */ - MENU_ABORTED = 3, - MENU_ABORTED_BUTTON = 4, /* must be MENU_ABORTED + 1 */ - MENU_SUBMENU_DONE, - MENU_DOUBLE_CLICKED, - MENU_POPUP, - MENU_POPDOWN, - MENU_SELECTED, - MENU_NEWITEM + MENU_ERROR = -1, + MENU_NOP = 0, + MENU_DONE = 1, + MENU_DONE_BUTTON = 2, /* must be MENU_DONE + 1 */ + MENU_ABORTED = 3, + MENU_ABORTED_BUTTON = 4, /* must be MENU_ABORTED + 1 */ + MENU_SUBMENU_DONE, + MENU_DOUBLE_CLICKED, + MENU_POPUP, + MENU_POPDOWN, + MENU_SELECTED, + MENU_NEWITEM } MenuStatus; -#define IS_MENU_RETURN(x) ((x)>=MENU_DONE && (x)<=MENU_ABORTED_BUTTON) -#define IS_MENU_BUTTON(x) ((x)==MENU_DONE_BUTTON || (x)==MENU_ABORTED_BUTTON) -#define MENU_ADD_BUTTON(x) ((x)==MENU_DONE || (x)==MENU_ABORTED?(x)+1:(x)) -#define MENU_ADD_BUTTON_IF(y,x) (y?MENU_ADD_BUTTON((x)):(x)) +#define IS_MENU_RETURN(x) ((x) >= MENU_DONE && (x) <= MENU_ABORTED_BUTTON) +#define IS_MENU_BUTTON(x) \ + ((x) == MENU_DONE_BUTTON || (x) == MENU_ABORTED_BUTTON) +#define MENU_ADD_BUTTON(x) \ + ((x) == MENU_DONE || (x) == MENU_ABORTED ? (x) + 1 : (x)) +#define MENU_ADD_BUTTON_IF(y, x) (y ? MENU_ADD_BUTTON((x)) : (x)) /* Types of events for the FUNCTION builtin */ #define MOTION 'm' @@ -310,10 +299,8 @@ typedef enum { #define DOUBLE_CLICK 'd' #define ONE_AND_A_HALF_CLICKS 'o' -MenuRoot *FollowMenuContinuations(MenuRoot *mr,MenuRoot **pmrPrior); -void AnimatedMoveOfWindow(Window w,int startX,int startY,int endX, int endY, - Bool fWarpPointerToo, int cusDelay, - float *ppctMovement ); +MenuRoot *FollowMenuContinuations(MenuRoot *mr, MenuRoot **pmrPrior); +void AnimatedMoveOfWindow(Window w, int startX, int startY, int endX, int endY, + Bool fWarpPointerToo, int cusDelay, float *ppctMovement); #endif /* _MENUS_ */ - Index: fvwm/fvwm/misc.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/misc.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/misc.c --- fvwm/fvwm/misc.c +++ fvwm/fvwm/misc.c @@ -12,30 +12,30 @@ * **************************************************************************/ +#include "misc.h" -#include "config.h" +#include +#include +#include +#include +#include +#include #include #include -#include -#include #include -#include -#include +#include "config.h" #include "fvwm.h" -#include -#include #include "menus.h" -#include "misc.h" +#include "module.h" #include "parse.h" #include "screen.h" -#include "module.h" FvwmWindow *FocusOnNextTimeStamp = NULL; -char NoName[] = "Untitled"; /* name if no name in XA_WM_NAME */ -char NoClass[] = "NoClass"; /* Class if no res_class in class hints */ +char NoName[] = "Untitled"; /* name if no name in XA_WM_NAME */ +char NoClass[] = "NoClass"; /* Class if no res_class in class hints */ char NoResource[] = "NoResource"; /* Class if no res_name in class hints */ /************************************************************************** @@ -43,25 +43,24 @@ char NoResource[] = "NoResource"; /* Class if no res_name in class hints */ * Releases dynamically allocated space used to store window/icon names * **************************************************************************/ -void free_window_names (FvwmWindow *tmp, Bool nukename, Bool nukeicon) +void +free_window_names(FvwmWindow *tmp, Bool nukename, Bool nukeicon) { - if (!tmp) - return; - - if (nukename && tmp->name) - { - if (tmp->name != tmp->icon_name && tmp->name != NoName) - XFree(tmp->name); - tmp->name = NULL; - } - if (nukeicon && tmp->icon_name) - { - if (tmp->name != tmp->icon_name && tmp->icon_name != NoName) - XFree(tmp->icon_name); - tmp->icon_name = NULL; - } - - return; + if (!tmp) + return; + + if (nukename && tmp->name) { + if (tmp->name != tmp->icon_name && tmp->name != NoName) + XFree(tmp->name); + tmp->name = NULL; + } + if (nukeicon && tmp->icon_name) { + if (tmp->name != tmp->icon_name && tmp->icon_name != NoName) + XFree(tmp->icon_name); + tmp->icon_name = NULL; + } + + return; } /*************************************************************************** @@ -69,170 +68,153 @@ void free_window_names (FvwmWindow *tmp, Bool nukename, Bool nukeicon) * Handles destruction of a window * ****************************************************************************/ -void Destroy(FvwmWindow *Tmp_win) +void +Destroy(FvwmWindow *Tmp_win) { - int i; - extern FvwmWindow *ButtonWindow; - extern FvwmWindow *colormap_win; - extern Boolean PPosOverride; - - /* - * Warning, this is also called by HandleUnmapNotify; if it ever needs to - * look at the event, HandleUnmapNotify will have to mash the UnmapNotify - * into a DestroyNotify. - */ - if(!Tmp_win) - return; - - /* first of all, remove the window from the list of all windows! */ - /* - RBW - 11/13/1998 - new: have to unhook the stacking order chain also. - There's always a prev and next, since this is a ring anchored on - Scr.FvwmRoot - */ - Tmp_win->stack_prev->stack_next = Tmp_win->stack_next; - Tmp_win->stack_next->stack_prev = Tmp_win->stack_prev; - - Tmp_win->prev->next = Tmp_win->next; - if (Tmp_win->next != NULL) - Tmp_win->next->prev = Tmp_win->prev; - - XUnmapWindow(dpy, Tmp_win->frame); - - if(!PPosOverride) - XSync(dpy,0); - - if(Tmp_win == Scr.Hilite) - Scr.Hilite = NULL; - - BroadcastPacket(M_DESTROY_WINDOW, 3, - Tmp_win->w, Tmp_win->frame, (unsigned long)Tmp_win); - - if(Scr.PreviousFocus == Tmp_win) - Scr.PreviousFocus = NULL; - - if(ButtonWindow == Tmp_win) - ButtonWindow = NULL; - - if((Tmp_win == Scr.Focus)&&(Tmp_win->flags & ClickToFocus)) - { - if(Tmp_win->next) - { - HandleHardFocus(Tmp_win->next); - } - else - SetFocus(Scr.NoFocusWin, NULL,1); - } - else if(Scr.Focus == Tmp_win) - SetFocus(Scr.NoFocusWin, NULL,1); + int i; + extern FvwmWindow *ButtonWindow; + extern FvwmWindow *colormap_win; + extern Boolean PPosOverride; + + /* + * Warning, this is also called by HandleUnmapNotify; if it ever needs + * to look at the event, HandleUnmapNotify will have to mash the + * UnmapNotify into a DestroyNotify. + */ + if (!Tmp_win) + return; + + /* first of all, remove the window from the list of all windows! */ + /* + RBW - 11/13/1998 - new: have to unhook the stacking order chain + also. There's always a prev and next, since this is a ring anchored + on Scr.FvwmRoot + */ + Tmp_win->stack_prev->stack_next = Tmp_win->stack_next; + Tmp_win->stack_next->stack_prev = Tmp_win->stack_prev; + + Tmp_win->prev->next = Tmp_win->next; + if (Tmp_win->next != NULL) + Tmp_win->next->prev = Tmp_win->prev; + + XUnmapWindow(dpy, Tmp_win->frame); + + if (!PPosOverride) + XSync(dpy, 0); + + if (Tmp_win == Scr.Hilite) + Scr.Hilite = NULL; + + BroadcastPacket(M_DESTROY_WINDOW, 3, Tmp_win->w, Tmp_win->frame, + (unsigned long)Tmp_win); + + if (Scr.PreviousFocus == Tmp_win) + Scr.PreviousFocus = NULL; + + if (ButtonWindow == Tmp_win) + ButtonWindow = NULL; - if(Tmp_win == FocusOnNextTimeStamp) - FocusOnNextTimeStamp = NULL; + if ((Tmp_win == Scr.Focus) && (Tmp_win->flags & ClickToFocus)) { + if (Tmp_win->next) { + HandleHardFocus(Tmp_win->next); + } else + SetFocus(Scr.NoFocusWin, NULL, 1); + } else if (Scr.Focus == Tmp_win) + SetFocus(Scr.NoFocusWin, NULL, 1); - if(Tmp_win == Scr.Ungrabbed) - Scr.Ungrabbed = NULL; + if (Tmp_win == FocusOnNextTimeStamp) + FocusOnNextTimeStamp = NULL; - if(Tmp_win == Scr.pushed_window) - Scr.pushed_window = NULL; + if (Tmp_win == Scr.Ungrabbed) + Scr.Ungrabbed = NULL; - if(Tmp_win == colormap_win) - colormap_win = NULL; + if (Tmp_win == Scr.pushed_window) + Scr.pushed_window = NULL; - XDestroyWindow(dpy, Tmp_win->frame); - XDeleteContext(dpy, Tmp_win->frame, FvwmContext); + if (Tmp_win == colormap_win) + colormap_win = NULL; - XDestroyWindow(dpy, Tmp_win->Parent); + XDestroyWindow(dpy, Tmp_win->frame); + XDeleteContext(dpy, Tmp_win->frame, FvwmContext); - XDeleteContext(dpy, Tmp_win->Parent, FvwmContext); + XDestroyWindow(dpy, Tmp_win->Parent); - XDeleteContext(dpy, Tmp_win->w, FvwmContext); + XDeleteContext(dpy, Tmp_win->Parent, FvwmContext); - if ((Tmp_win->icon_w)&&(Tmp_win->flags & PIXMAP_OURS)) - { - XFreePixmap(dpy, Tmp_win->iconPixmap); - XFreePixmap(dpy, Tmp_win->icon_maskPixmap); - } + XDeleteContext(dpy, Tmp_win->w, FvwmContext); + + if ((Tmp_win->icon_w) && (Tmp_win->flags & PIXMAP_OURS)) { + XFreePixmap(dpy, Tmp_win->iconPixmap); + XFreePixmap(dpy, Tmp_win->icon_maskPixmap); + } #ifdef MINI_ICON - if (Tmp_win->mini_icon) - { - DestroyPicture(dpy, Tmp_win->mini_icon); - } + if (Tmp_win->mini_icon) { + DestroyPicture(dpy, Tmp_win->mini_icon); + } #endif - if (Tmp_win->icon_w) - { - XDestroyWindow(dpy, Tmp_win->icon_w); - XDeleteContext(dpy, Tmp_win->icon_w, FvwmContext); - } - if((Tmp_win->flags &ICON_OURS)&&(Tmp_win->icon_pixmap_w != None)) - XDestroyWindow(dpy, Tmp_win->icon_pixmap_w); - if(Tmp_win->icon_pixmap_w != None) - XDeleteContext(dpy, Tmp_win->icon_pixmap_w, FvwmContext); - - if (Tmp_win->flags & TITLE) - { - XDeleteContext(dpy, Tmp_win->title_w, FvwmContext); - for(i=0;ileft_w[i], FvwmContext); - for(i=0;iright_w[i] != None) - XDeleteContext(dpy, Tmp_win->right_w[i], FvwmContext); - } - if (Tmp_win->flags & BORDER) - { - for(i=0;i<4;i++) - XDeleteContext(dpy, Tmp_win->sides[i], FvwmContext); - for(i=0;i<4;i++) - XDeleteContext(dpy, Tmp_win->corners[i], FvwmContext); - } - - free_window_names (Tmp_win, True, True); - if (Tmp_win->wmhints) - XFree ((char *)Tmp_win->wmhints); - /* removing NoClass change for now... */ -#if 0 - if (Tmp_win->class.res_name) - XFree ((char *)Tmp_win->class.res_name); - if (Tmp_win->class.res_class) - XFree ((char *)Tmp_win->class.res_class); -#else - if (Tmp_win->class.res_name && Tmp_win->class.res_name != NoResource) - XFree ((char *)Tmp_win->class.res_name); - if (Tmp_win->class.res_class && Tmp_win->class.res_class != NoClass) - XFree ((char *)Tmp_win->class.res_class); -#endif /* 0 */ - if(Tmp_win->mwm_hints) - XFree((char *)Tmp_win->mwm_hints); - - if(Tmp_win->cmap_windows != (Window *)NULL) - XFree((void *)Tmp_win->cmap_windows); - - free((char *)Tmp_win); - - if(!PPosOverride) - XSync(dpy,0); - return; -} + if (Tmp_win->icon_w) { + XDestroyWindow(dpy, Tmp_win->icon_w); + XDeleteContext(dpy, Tmp_win->icon_w, FvwmContext); + } + if ((Tmp_win->flags & ICON_OURS) && (Tmp_win->icon_pixmap_w != None)) + XDestroyWindow(dpy, Tmp_win->icon_pixmap_w); + if (Tmp_win->icon_pixmap_w != None) + XDeleteContext(dpy, Tmp_win->icon_pixmap_w, FvwmContext); + + if (Tmp_win->flags & TITLE) { + XDeleteContext(dpy, Tmp_win->title_w, FvwmContext); + for (i = 0; i < Scr.nr_left_buttons; i++) + XDeleteContext(dpy, Tmp_win->left_w[i], FvwmContext); + for (i = 0; i < Scr.nr_right_buttons; i++) + if (Tmp_win->right_w[i] != None) + XDeleteContext( + dpy, Tmp_win->right_w[i], FvwmContext); + } + if (Tmp_win->flags & BORDER) { + for (i = 0; i < 4; i++) + XDeleteContext(dpy, Tmp_win->sides[i], FvwmContext); + for (i = 0; i < 4; i++) + XDeleteContext(dpy, Tmp_win->corners[i], FvwmContext); + } + free_window_names(Tmp_win, True, True); + if (Tmp_win->wmhints) + XFree((char *)Tmp_win->wmhints); + if (Tmp_win->class.res_name && Tmp_win->class.res_name != NoResource) + XFree((char *)Tmp_win->class.res_name); + if (Tmp_win->class.res_class && Tmp_win->class.res_class != NoClass) + XFree((char *)Tmp_win->class.res_class); + if (Tmp_win->mwm_hints) + XFree((char *)Tmp_win->mwm_hints); + if (Tmp_win->cmap_windows != (Window *)NULL) + XFree((void *)Tmp_win->cmap_windows); + + free((char *)Tmp_win); + + if (!PPosOverride) + XSync(dpy, 0); + return; +} /************************************************************************** * * Removes expose events for a specific window from the queue * *************************************************************************/ -int flush_expose (Window w) +int +flush_expose(Window w) { - XEvent dummy; - int i=0; + XEvent dummy; + int i = 0; - while (XCheckTypedWindowEvent (dpy, w, Expose, &dummy))i++; - return i; + while (XCheckTypedWindowEvent(dpy, w, Expose, &dummy)) + i++; + return i; } - - /*********************************************************************** * * Procedure: @@ -241,190 +223,190 @@ int flush_expose (Window w) * Puts windows back where they were before fvwm took over * ************************************************************************/ -void RestoreWithdrawnLocation (FvwmWindow *tmp,Bool restart) +void +RestoreWithdrawnLocation(FvwmWindow *tmp, Bool restart) { - int a,b,w2,h2; - unsigned int mask; - XWindowChanges xwc; - - if(!tmp) - return; - - if (XGetGeometry (dpy, tmp->w, &JunkRoot, &xwc.x, &xwc.y, - &JunkWidth, &JunkHeight, &JunkBW, &JunkDepth)) - { - XTranslateCoordinates(dpy,tmp->frame,Scr.Root,xwc.x,xwc.y, - &a,&b,&JunkChild); - xwc.x = a + tmp->xdiff; - xwc.y = b + tmp->ydiff; - xwc.border_width = tmp->old_bw; - mask = (CWX | CWY| CWBorderWidth); - - /* We can not assume that the window is currently on the screen. - * Although this is normally the case, it is not always true. The - * most common example is when the user does something in an - * application which will, after some amount of computational delay, - * cause the window to be unmapped, but then switches screens before - * this happens. The XTranslateCoordinates call above will set the - * window coordinates to either be larger than the screen, or negative. - * This will result in the window being placed in odd, or even - * unviewable locations when the window is remapped. The followin code - * forces the "relative" location to be within the bounds of the display. - * - * gpw -- 11/11/93 - * - * Unfortunately, this does horrendous things during re-starts, - * hence the "if(restart)" clause (RN) - * - * Also, fixed so that it only does this stuff if a window is more than - * half off the screen. (RN) - */ - - if(!restart) - { - /* Don't mess with it if its partially on the screen now */ - if((tmp->frame_x < 0)||(tmp->frame_y<0)|| - (tmp->frame_x >= Scr.MyDisplayWidth)|| - (tmp->frame_y >= Scr.MyDisplayHeight)) - { - w2 = (tmp->frame_width>>1); - h2 = (tmp->frame_height>>1); - if (( xwc.x < -w2) || (xwc.x > (Scr.MyDisplayWidth-w2 ))) - { - xwc.x = xwc.x % Scr.MyDisplayWidth; - if ( xwc.x < -w2 ) - xwc.x += Scr.MyDisplayWidth; + int a, b, w2, h2; + unsigned int mask; + XWindowChanges xwc; + + if (!tmp) + return; + + if (XGetGeometry(dpy, tmp->w, &JunkRoot, &xwc.x, &xwc.y, &JunkWidth, + &JunkHeight, &JunkBW, &JunkDepth)) { + XTranslateCoordinates(dpy, tmp->frame, Scr.Root, xwc.x, xwc.y, + &a, &b, &JunkChild); + xwc.x = a + tmp->xdiff; + xwc.y = b + tmp->ydiff; + xwc.border_width = tmp->old_bw; + mask = (CWX | CWY | CWBorderWidth); + + /* We can not assume that the window is currently on the screen. + * Although this is normally the case, it is not always true. + * The most common example is when the user does something in an + * application which will, after some amount of computational + * delay, cause the window to be unmapped, but then switches + * screens before this happens. The XTranslateCoordinates call + * above will set the window coordinates to either be larger + * than the screen, or negative. This will result in the window + * being placed in odd, or even unviewable locations when the + * window is remapped. The followin code forces the "relative" + * location to be within the bounds of the display. + * + * gpw -- 11/11/93 + * + * Unfortunately, this does horrendous things during re-starts, + * hence the "if(restart)" clause (RN) + * + * Also, fixed so that it only does this stuff if a window is + * more than half off the screen. (RN) + */ + + if (!restart) { + /* Don't mess with it if its partially on the screen now + */ + if ((tmp->frame_x < 0) || (tmp->frame_y < 0) || + (tmp->frame_x >= Scr.MyDisplayWidth) || + (tmp->frame_y >= Scr.MyDisplayHeight)) { + w2 = (tmp->frame_width >> 1); + h2 = (tmp->frame_height >> 1); + if ((xwc.x < -w2) || + (xwc.x > (Scr.MyDisplayWidth - w2))) { + xwc.x = xwc.x % Scr.MyDisplayWidth; + if (xwc.x < -w2) + xwc.x += Scr.MyDisplayWidth; + } + if ((xwc.y < -h2) || + (xwc.y > (Scr.MyDisplayHeight - h2))) { + xwc.y = xwc.y % Scr.MyDisplayHeight; + if (xwc.y < -h2) + xwc.y += Scr.MyDisplayHeight; + } + } } - if ((xwc.y < -h2) || (xwc.y > (Scr.MyDisplayHeight-h2 ))) - { - xwc.y = xwc.y % Scr.MyDisplayHeight; - if ( xwc.y < -h2 ) - xwc.y += Scr.MyDisplayHeight; + XReparentWindow(dpy, tmp->w, Scr.Root, xwc.x, xwc.y); + + if ((tmp->flags & ICONIFIED) && + (!(tmp->flags & SUPPRESSICON))) { + if (tmp->icon_w) + XUnmapWindow(dpy, tmp->icon_w); + if (tmp->icon_pixmap_w) + XUnmapWindow(dpy, tmp->icon_pixmap_w); } - } - } - XReparentWindow (dpy, tmp->w,Scr.Root,xwc.x,xwc.y); - - if((tmp->flags & ICONIFIED)&&(!(tmp->flags & SUPPRESSICON))) - { - if (tmp->icon_w) - XUnmapWindow(dpy, tmp->icon_w); - if (tmp->icon_pixmap_w) - XUnmapWindow(dpy, tmp->icon_pixmap_w); - } - XConfigureWindow (dpy, tmp->w, mask, &xwc); - if(!restart) - XSync(dpy,0); - } + XConfigureWindow(dpy, tmp->w, mask, &xwc); + if (!restart) + XSync(dpy, 0); + } } - /**************************************************************************** * * Records the time of the last processed event. Used in XSetInputFocus * ****************************************************************************/ -Time lastTimestamp = CurrentTime; /* until Xlib does this for us */ +Time lastTimestamp = CurrentTime; /* until Xlib does this for us */ -Bool StashEventTime (XEvent *ev) +Bool +StashEventTime(XEvent *ev) { - Time NewTimestamp = CurrentTime; - - switch (ev->type) - { - case KeyPress: - case KeyRelease: - NewTimestamp = ev->xkey.time; - break; - case ButtonPress: - case ButtonRelease: - NewTimestamp = ev->xbutton.time; - break; - case MotionNotify: - NewTimestamp = ev->xmotion.time; - break; - case EnterNotify: - case LeaveNotify: - NewTimestamp = ev->xcrossing.time; - break; - case PropertyNotify: - NewTimestamp = ev->xproperty.time; - break; - case SelectionClear: - NewTimestamp = ev->xselectionclear.time; - break; - case SelectionRequest: - NewTimestamp = ev->xselectionrequest.time; - break; - case SelectionNotify: - NewTimestamp = ev->xselection.time; - break; - default: - return False; - } - /* Only update is the new timestamp is later than the old one, or - * if the new one is from a time at least 30 seconds earlier than the - * old one (in which case the system clock may have changed) */ - if((NewTimestamp > lastTimestamp)||((lastTimestamp - NewTimestamp) > 30000)) - lastTimestamp = NewTimestamp; - if(FocusOnNextTimeStamp) - { - SetFocus(FocusOnNextTimeStamp->w,FocusOnNextTimeStamp,1); - FocusOnNextTimeStamp = NULL; - } - return True; + Time NewTimestamp = CurrentTime; + + switch (ev->type) { + case KeyPress: + case KeyRelease: + NewTimestamp = ev->xkey.time; + break; + case ButtonPress: + case ButtonRelease: + NewTimestamp = ev->xbutton.time; + break; + case MotionNotify: + NewTimestamp = ev->xmotion.time; + break; + case EnterNotify: + case LeaveNotify: + NewTimestamp = ev->xcrossing.time; + break; + case PropertyNotify: + NewTimestamp = ev->xproperty.time; + break; + case SelectionClear: + NewTimestamp = ev->xselectionclear.time; + break; + case SelectionRequest: + NewTimestamp = ev->xselectionrequest.time; + break; + case SelectionNotify: + NewTimestamp = ev->xselection.time; + break; + default: + return False; + } + /* Only update is the new timestamp is later than the old one, or + * if the new one is from a time at least 30 seconds earlier than the + * old one (in which case the system clock may have changed) */ + if ((NewTimestamp > lastTimestamp) || + ((lastTimestamp - NewTimestamp) > 30000)) + lastTimestamp = NewTimestamp; + if (FocusOnNextTimeStamp) { + SetFocus(FocusOnNextTimeStamp->w, FocusOnNextTimeStamp, 1); + FocusOnNextTimeStamp = NULL; + } + return True; } - -void ComputeActualPosition(int x,int y,int x_unit,int y_unit, - int width,int height,int *pfinalX, int *pfinalY) +void +ComputeActualPosition(int x, int y, int x_unit, int y_unit, int width, + int height, int *pfinalX, int *pfinalY) { - *pfinalX = x*x_unit/100; - *pfinalY = y*y_unit/100; - if (*pfinalX < 0) - *pfinalX += Scr.MyDisplayWidth - width; - if (*pfinalY < 0) - *pfinalY += Scr.MyDisplayHeight - height; + *pfinalX = x * x_unit / 100; + *pfinalY = y * y_unit / 100; + if (*pfinalX < 0) + *pfinalX += Scr.MyDisplayWidth - width; + if (*pfinalY < 0) + *pfinalY += Scr.MyDisplayHeight - height; } -int GetTwoArguments(char *action, int *val1, int *val2, int *val1_unit, - int *val2_unit) +int +GetTwoArguments( + char *action, int *val1, int *val2, int *val1_unit, int *val2_unit) { - *val1_unit = Scr.MyDisplayWidth; - *val2_unit = Scr.MyDisplayHeight; - return GetTwoPercentArguments(action, val1, val2, val1_unit, val2_unit); + *val1_unit = Scr.MyDisplayWidth; + *val2_unit = Scr.MyDisplayHeight; + return GetTwoPercentArguments(action, val1, val2, val1_unit, val2_unit); } /* The vars are named for the x-direction, but this is used for both x and y */ -static -int GetOnePositionArgument(char *s1,int x,int w,int *pFinalX,float factor, - int max) +static int +GetOnePositionArgument( + char *s1, int x, int w, int *pFinalX, float factor, int max) { - int val; - int cch = strlen(s1); - - if (cch == 0) - return 0; - if (s1[cch-1] == 'p') { - factor = 1; /* Use pixels, so don't multiply by factor */ - s1[cch-1] = '\0'; - } - if (strcmp(s1,"w") == 0) { - *pFinalX = x; - } else if (sscanf(s1,"w-%d",&val) == 1) { - *pFinalX = x-(val*factor); - } else if (sscanf(s1,"w+%d",&val) == 1) { - *pFinalX = x+(val*factor); - } else if (sscanf(s1,"-%d",&val) == 1) { - *pFinalX = max-w - val*factor; - } else if (sscanf(s1,"%d",&val) == 1) { - *pFinalX = val*factor; - } else { - return 0; - } - /* DEBUG_FPRINTF((stderr,"Got %d\n",*pFinalX)); */ - return 1; + int val; + int cch = strlen(s1); + + if (cch == 0) + return 0; + if (s1[cch - 1] == 'p') { + factor = 1; /* Use pixels, so don't multiply by factor */ + s1[cch - 1] = '\0'; + } + if (strcmp(s1, "w") == 0) { + *pFinalX = x; + } else if (sscanf(s1, "w-%d", &val) == 1) { + *pFinalX = x - (val * factor); + } else if (sscanf(s1, "w+%d", &val) == 1) { + *pFinalX = x + (val * factor); + } else if (sscanf(s1, "-%d", &val) == 1) { + *pFinalX = max - w - val * factor; + } else if (sscanf(s1, "%d", &val) == 1) { + *pFinalX = val * factor; + } else { + return 0; + } + /* DEBUG_FPRINTF((stderr,"Got %d\n",*pFinalX)); */ + return 1; } /* GetMoveArguments is used for Move & AnimatedMove @@ -436,32 +418,39 @@ int GetOnePositionArgument(char *s1,int x,int w,int *pFinalX,float factor, * w+5 w-10p Relative position, right 5%, up ten pixels * Returns 2 when x & y have parsed without error, 0 otherwise */ -int GetMoveArguments(char *action, int x, int y, int w, int h, - int *pFinalX, int *pFinalY, Bool *fWarp) +int +GetMoveArguments(char *action, int x, int y, int w, int h, int *pFinalX, + int *pFinalY, Bool *fWarp) { - char *s1, *s2, *warp; - int scrWidth = Scr.MyDisplayWidth; - int scrHeight = Scr.MyDisplayHeight; - int retval = 0; - - action = GetNextToken(action, &s1); - action = GetNextToken(action, &s2); - GetNextToken(action, &warp); - *fWarp = StrEquals(warp, "Warp"); - - if (s1 != NULL && s2 != NULL) { - if (GetOnePositionArgument(s1,x,w,pFinalX,(float)scrWidth/100,scrWidth) && - GetOnePositionArgument(s2,y,h,pFinalY,(float)scrHeight/100,scrHeight)) - retval = 2; - else - *fWarp = FALSE; /* make sure warping is off for interactive moves */ - } - - if (s1) free(s1); - if (s2) free(s2); - if (warp) free(warp); - - return retval; + char *s1, *s2, *warp; + int scrWidth = Scr.MyDisplayWidth; + int scrHeight = Scr.MyDisplayHeight; + int retval = 0; + + action = GetNextToken(action, &s1); + action = GetNextToken(action, &s2); + GetNextToken(action, &warp); + *fWarp = StrEquals(warp, "Warp"); + + if (s1 != NULL && s2 != NULL) { + if (GetOnePositionArgument( + s1, x, w, pFinalX, (float)scrWidth / 100, scrWidth) && + GetOnePositionArgument( + s2, y, h, pFinalY, (float)scrHeight / 100, scrHeight)) + retval = 2; + else + *fWarp = FALSE; /* make sure warping is off for + interactive moves */ + } + + if (s1) + free(s1); + if (s2) + free(s2); + if (warp) + free(warp); + + return retval; } /***************************************************************************** @@ -469,54 +458,54 @@ int GetMoveArguments(char *action, int x, int y, int w, int h, * * The vars are named for the x-direction, but this is used for both x and y *****************************************************************************/ -static -char *GetOneMenuPositionArgument(char *action,int x,int w,int *pFinalX, - float *width_factor) +static char * +GetOneMenuPositionArgument( + char *action, int x, int w, int *pFinalX, float *width_factor) { - char *token, *orgtoken, *naction; - char c; - int val; - int chars; - float factor = (float)w/100; - - naction = GetNextToken(action, &token); - if (token == NULL) - return action; - orgtoken = token; - *pFinalX = x; - *width_factor = 0; - if (sscanf(token,"o%d%n", &val, &chars) >= 1) { - token += chars; - *pFinalX += val*factor; - *width_factor -= val/100; - } else if (token[0] == 'c') { - token++; - *pFinalX += w/2; - *width_factor -= 0.5; - } - while (*token != 0) { - if (sscanf(token,"%d%n", &val, &chars) >= 1) { - token += chars; - if (sscanf(token,"%c", &c) == 1) { - if (c == 'm') { - token++; - *width_factor += val/100; - } else if (c == 'p') { - token++; - *pFinalX += val; - } else { - *pFinalX += val*factor; + char *token, *orgtoken, *naction; + char c; + int val; + int chars; + float factor = (float)w / 100; + + naction = GetNextToken(action, &token); + if (token == NULL) + return action; + orgtoken = token; + *pFinalX = x; + *width_factor = 0; + if (sscanf(token, "o%d%n", &val, &chars) >= 1) { + token += chars; + *pFinalX += val * factor; + *width_factor -= val / 100; + } else if (token[0] == 'c') { + token++; + *pFinalX += w / 2; + *width_factor -= 0.5; + } + while (*token != 0) { + if (sscanf(token, "%d%n", &val, &chars) >= 1) { + token += chars; + if (sscanf(token, "%c", &c) == 1) { + if (c == 'm') { + token++; + *width_factor += val / 100; + } else if (c == 'p') { + token++; + *pFinalX += val; + } else { + *pFinalX += val * factor; + } + } else { + *pFinalX += val * factor; + } + } else { + naction = action; + break; + } } - } else { - *pFinalX += val*factor; - } - } else { - naction = action; - break; - } - } - free(orgtoken); - return naction; + free(orgtoken); + return naction; } /***************************************************************************** @@ -530,182 +519,208 @@ char *GetOneMenuPositionArgument(char *action,int x,int w,int *pFinalX, * * See documentation for a detailed description. ****************************************************************************/ -char *GetMenuOptions(char *action, Window w, FvwmWindow *tmp_win, - MenuItem *mi, MenuOptions *pops) +char * +GetMenuOptions(char *action, Window w, FvwmWindow *tmp_win, MenuItem *mi, + MenuOptions *pops) { - char *tok = NULL, *naction = action, *taction; - int x, y, button, gflags; - unsigned int width, height; - Window context_window = 0; - Bool fHasContext, fUseItemOffset; - Bool fValidPosHints = fLastMenuPosHintsValid; - - fLastMenuPosHintsValid = FALSE; - if (pops == NULL) { - fvwm_msg(ERR,"GetMenuOptions","no MenuOptions pointer passed"); - return action; - } - - taction = action; - while (action != NULL) { - /* ^ just to be able to jump to end of loop without 'goto' */ - gflags = NoValue; - pops->flags.allflags = 0; - pops->pos_hints.fRelative = FALSE; - /* parse context argument (if present) */ - naction = GetNextToken(taction, &tok); - if (!tok) { - /* no context string */ - fHasContext = FALSE; - break; - } - - pops->pos_hints.fRelative = TRUE; /* set to FALSE for absolute hints! */ - fUseItemOffset = FALSE; - fHasContext = TRUE; - if (StrEquals(tok, "context")) { - if (mi && mi->mr) context_window = mi->mr->w; - else if (tmp_win) { - if (tmp_win->flags & ICONIFIED) context_window=tmp_win->icon_pixmap_w; - else context_window = tmp_win->frame; - } else context_window = w; - pops->pos_hints.fRelative = TRUE; - } else if (StrEquals(tok,"menu")) { - if (mi && mi->mr) context_window = mi->mr->w; - } else if (StrEquals(tok,"item")) { - if (mi && mi->mr) { - context_window = mi->mr->w; - fUseItemOffset = TRUE; - } - } else if (StrEquals(tok,"icon")) { - if (tmp_win) context_window = tmp_win->icon_pixmap_w; - } else if (StrEquals(tok,"window")) { - if (tmp_win) context_window = tmp_win->frame; - } else if (StrEquals(tok,"interior")) { - if (tmp_win) context_window = tmp_win->w; - } else if (StrEquals(tok,"title")) { - if (tmp_win) { - if (tmp_win->flags & ICONIFIED) context_window = tmp_win->icon_w; - else context_window = tmp_win->title_w; - } - } else if (strncasecmp(tok,"button",6) == 0) { - if (sscanf(&(tok[6]),"%d",&button) != 1 || - tok[6] == '+' || tok[6] == '-' || button < 0 || button > 9) { - fHasContext = FALSE; - } else if (tmp_win) { - if (button == 0) button = 10; - if (button & 0x01) context_window = tmp_win->left_w[button/2]; - else context_window = tmp_win->right_w[button/2-1]; - } - } else if (StrEquals(tok,"root")) { - context_window = Scr.Root; - pops->pos_hints.fRelative = FALSE; - } else if (StrEquals(tok,"mouse")) { - context_window = 0; - } else if (StrEquals(tok,"rectangle")) { - int flags; - /* parse the rectangle */ - free(tok); - naction = GetNextToken(taction, &tok); - if (tok == NULL) { - fvwm_msg(ERR,"GetMenuOptions","missing rectangle geometry"); - return action; - } - flags = XParseGeometry(tok, &x, &y, &width, &height); - if ((flags & AllValues) != AllValues) { - free(tok); - fvwm_msg(ERR,"GetMenuOptions","invalid rectangle geometry"); + char *tok = NULL, *naction = action, *taction; + int x, y, button, gflags; + unsigned int width, height; + Window context_window = 0; + Bool fHasContext, fUseItemOffset; + Bool fValidPosHints = fLastMenuPosHintsValid; + + fLastMenuPosHintsValid = FALSE; + if (pops == NULL) { + fvwm_msg( + ERR, "GetMenuOptions", "no MenuOptions pointer passed"); + return action; + } + + taction = action; + while (action != NULL) { + /* ^ just to be able to jump to end of loop without 'goto' */ + gflags = NoValue; + pops->flags.allflags = 0; + pops->pos_hints.fRelative = FALSE; + /* parse context argument (if present) */ + naction = GetNextToken(taction, &tok); + if (!tok) { + /* no context string */ + fHasContext = FALSE; + break; + } + + pops->pos_hints.fRelative = + TRUE; /* set to FALSE for absolute hints! */ + fUseItemOffset = FALSE; + fHasContext = TRUE; + if (StrEquals(tok, "context")) { + if (mi && mi->mr) + context_window = mi->mr->w; + else if (tmp_win) { + if (tmp_win->flags & ICONIFIED) + context_window = tmp_win->icon_pixmap_w; + else + context_window = tmp_win->frame; + } else + context_window = w; + pops->pos_hints.fRelative = TRUE; + } else if (StrEquals(tok, "menu")) { + if (mi && mi->mr) + context_window = mi->mr->w; + } else if (StrEquals(tok, "item")) { + if (mi && mi->mr) { + context_window = mi->mr->w; + fUseItemOffset = TRUE; + } + } else if (StrEquals(tok, "icon")) { + if (tmp_win) + context_window = tmp_win->icon_pixmap_w; + } else if (StrEquals(tok, "window")) { + if (tmp_win) + context_window = tmp_win->frame; + } else if (StrEquals(tok, "interior")) { + if (tmp_win) + context_window = tmp_win->w; + } else if (StrEquals(tok, "title")) { + if (tmp_win) { + if (tmp_win->flags & ICONIFIED) + context_window = tmp_win->icon_w; + else + context_window = tmp_win->title_w; + } + } else if (strncasecmp(tok, "button", 6) == 0) { + if (sscanf(&(tok[6]), "%d", &button) != 1 || + tok[6] == '+' || tok[6] == '-' || button < 0 || + button > 9) { + fHasContext = FALSE; + } else if (tmp_win) { + if (button == 0) + button = 10; + if (button & 0x01) + context_window = + tmp_win->left_w[button / 2]; + else + context_window = + tmp_win->right_w[button / 2 - 1]; + } + } else if (StrEquals(tok, "root")) { + context_window = Scr.Root; + pops->pos_hints.fRelative = FALSE; + } else if (StrEquals(tok, "mouse")) { + context_window = 0; + } else if (StrEquals(tok, "rectangle")) { + int flags; + /* parse the rectangle */ + free(tok); + naction = GetNextToken(taction, &tok); + if (tok == NULL) { + fvwm_msg(ERR, "GetMenuOptions", + "missing rectangle geometry"); + return action; + } + flags = XParseGeometry(tok, &x, &y, &width, &height); + if ((flags & AllValues) != AllValues) { + free(tok); + fvwm_msg(ERR, "GetMenuOptions", + "invalid rectangle geometry"); + return action; + } + if (flags & XNegative) + x = Scr.MyDisplayWidth - x - width; + if (flags & YNegative) + y = Scr.MyDisplayHeight - y - height; + pops->pos_hints.fRelative = FALSE; + } else if (StrEquals(tok, "this")) { + context_window = w; + } else { + /* no context string */ + fHasContext = FALSE; + } + + if (tok) + free(tok); + if (fHasContext) + taction = naction; + else + naction = action; + + if (!context_window || !fHasContext || + !XGetGeometry(dpy, context_window, &JunkRoot, &JunkX, + &JunkY, &width, &height, &JunkBW, &JunkDepth) || + !XTranslateCoordinates(dpy, context_window, Scr.Root, 0, 0, + &x, &y, &JunkChild)) { + /* now window or could not get geometry */ + XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, &x, + &y, &JunkX, &JunkY, &JunkMask); + width = height = 1; + } else if (fUseItemOffset) { + y += mi->y_offset; + height = mi->y_height; + } + + /* parse position arguments */ + taction = GetOneMenuPositionArgument(naction, x, width, + &(pops->pos_hints.x), &(pops->pos_hints.x_factor)); + naction = GetOneMenuPositionArgument(taction, y, height, + &(pops->pos_hints.y), &(pops->pos_hints.y_factor)); + if (naction == taction) { + /* argument is missing or invalid */ + if (fHasContext) + fvwm_msg(ERR, "GetMenuOptions", + "invalid position arguments"); + naction = action; + taction = action; + break; + } + taction = naction; + pops->flags.f.has_poshints = 1; + if (fValidPosHints == TRUE && + pops->pos_hints.fRelative == TRUE) { + pops->pos_hints = lastMenuPosHints; + } + /* we want to do this only once */ + break; + } /* while (1) */ + + if (!pops->flags.f.has_poshints && fValidPosHints) { + DBUG("GetMenuOptions", "recycling position hints"); + pops->flags.f.has_poshints = 1; + pops->pos_hints = lastMenuPosHints; + pops->pos_hints.fRelative = FALSE; + } + + action = naction; + /* parse additional options */ + while (naction && *naction) { + naction = GetNextToken(action, &tok); + if (!tok) + break; + if (StrEquals(tok, "WarpTitle")) { + pops->flags.f.warp_title = 1; + pops->flags.f.no_warp = 0; + } else if (StrEquals(tok, "NoWarp")) { + pops->flags.f.warp_title = 0; + pops->flags.f.no_warp = 1; + } else if (StrEquals(tok, "Fixed")) { + pops->flags.f.fixed = 1; + } else if (StrEquals(tok, "SelectInPlace")) { + pops->flags.f.select_in_place = 1; + } else if (StrEquals(tok, "SelectWarp")) { + pops->flags.f.select_warp = 1; + } else { + free(tok); + break; + } + action = naction; + free(tok); + } + if (!pops->flags.f.select_in_place) { + pops->flags.f.select_warp = 0; + } + return action; - } - if (flags & XNegative) x = Scr.MyDisplayWidth - x - width; - if (flags & YNegative) y = Scr.MyDisplayHeight - y - height; - pops->pos_hints.fRelative = FALSE; - } else if (StrEquals(tok,"this")) { - context_window = w; - } else { - /* no context string */ - fHasContext = FALSE; - } - - if (tok) - free(tok); - if (fHasContext) - taction = naction; - else naction = action; - - if (!context_window || !fHasContext - || !XGetGeometry(dpy, context_window, &JunkRoot, &JunkX, &JunkY, - &width, &height, &JunkBW, &JunkDepth) - || !XTranslateCoordinates( - dpy, context_window, Scr.Root, 0, 0, &x, &y, &JunkChild)) { - /* now window or could not get geometry */ - XQueryPointer(dpy,Scr.Root,&JunkRoot,&JunkChild,&x,&y,&JunkX,&JunkY, - &JunkMask); - width = height = 1; - } else if (fUseItemOffset) { - y += mi->y_offset; - height = mi->y_height; - } - - /* parse position arguments */ - taction = GetOneMenuPositionArgument( - naction, x, width, &(pops->pos_hints.x), &(pops->pos_hints.x_factor)); - naction = GetOneMenuPositionArgument( - taction, y, height, &(pops->pos_hints.y), &(pops->pos_hints.y_factor)); - if (naction == taction) { - /* argument is missing or invalid */ - if (fHasContext) - fvwm_msg(ERR,"GetMenuOptions","invalid position arguments"); - naction = action; - taction = action; - break; - } - taction = naction; - pops->flags.f.has_poshints = 1; - if (fValidPosHints == TRUE && pops->pos_hints.fRelative == TRUE) { - pops->pos_hints = lastMenuPosHints; - } - /* we want to do this only once */ - break; - } /* while (1) */ - - if (!pops->flags.f.has_poshints && fValidPosHints) { - DBUG("GetMenuOptions","recycling position hints"); - pops->flags.f.has_poshints = 1; - pops->pos_hints = lastMenuPosHints; - pops->pos_hints.fRelative = FALSE; - } - - action = naction; - /* parse additional options */ - while (naction && *naction) { - naction = GetNextToken(action, &tok); - if (!tok) - break; - if (StrEquals(tok, "WarpTitle")) { - pops->flags.f.warp_title = 1; - pops->flags.f.no_warp = 0; - } else if (StrEquals(tok, "NoWarp")) { - pops->flags.f.warp_title = 0; - pops->flags.f.no_warp = 1; - } else if (StrEquals(tok, "Fixed")) { - pops->flags.f.fixed = 1; - } else if (StrEquals(tok, "SelectInPlace")) { - pops->flags.f.select_in_place = 1; - } else if (StrEquals(tok, "SelectWarp")) { - pops->flags.f.select_warp = 1; - } else { - free (tok); - break; - } - action = naction; - free (tok); - } - if (!pops->flags.f.select_in_place) { - pops->flags.f.select_warp = 0; - } - - return action; } /*************************************************************************** @@ -716,31 +731,29 @@ char *GetMenuOptions(char *action, Window w, FvwmWindow *tmp_win, * Discard superflous button events during this wait period. * ***************************************************************************/ -void WaitForButtonsUp() +void +WaitForButtonsUp() { - Bool AllUp = False; - XEvent JunkEvent; - unsigned int mask; - - while(!AllUp) - { - XAllowEvents(dpy,ReplayPointer,CurrentTime); - XQueryPointer( dpy, Scr.Root, &JunkRoot, &JunkChild, - &JunkX, &JunkY, &JunkX, &JunkY, &mask); - - if((mask& - (Button1Mask|Button2Mask|Button3Mask|Button4Mask|Button5Mask))==0) - AllUp = True; - } - XSync(dpy,0); - while(XCheckMaskEvent(dpy, - ButtonPressMask|ButtonReleaseMask|ButtonMotionMask, - &JunkEvent)) - { - StashEventTime (&JunkEvent); - XAllowEvents(dpy,ReplayPointer,CurrentTime); - } - + Bool AllUp = False; + XEvent JunkEvent; + unsigned int mask; + + while (!AllUp) { + XAllowEvents(dpy, ReplayPointer, CurrentTime); + XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, &JunkX, + &JunkY, &JunkX, &JunkY, &mask); + + if ((mask & (Button1Mask | Button2Mask | Button3Mask | + Button4Mask | Button5Mask)) == 0) + AllUp = True; + } + XSync(dpy, 0); + while (XCheckMaskEvent(dpy, + ButtonPressMask | ButtonReleaseMask | ButtonMotionMask, + &JunkEvent)) { + StashEventTime(&JunkEvent); + XAllowEvents(dpy, ReplayPointer, CurrentTime); + } } /***************************************************************************** @@ -748,70 +761,65 @@ void WaitForButtonsUp() * Grab the pointer and keyboard * ****************************************************************************/ -Bool GrabEm(int cursor) +Bool +GrabEm(int cursor) { - int i=0,val=0; - unsigned int mask; - - XSync(dpy,0); - /* move the keyboard focus prior to grabbing the pointer to - * eliminate the enterNotify and exitNotify events that go - * to the windows */ - if(Scr.PreviousFocus == NULL) - Scr.PreviousFocus = Scr.Focus; - SetFocus(Scr.NoFocusWin,NULL,0); - mask = ButtonPressMask|ButtonReleaseMask|ButtonMotionMask|PointerMotionMask - | EnterWindowMask | LeaveWindowMask; - while((i<1000)&&(val=XGrabPointer(dpy, Scr.Root, True, mask, - GrabModeAsync, GrabModeAsync, Scr.Root, - Scr.FvwmCursors[cursor], CurrentTime)!= - GrabSuccess)) - { - i++; - /* If you go too fast, other windows may not get a change to release - * any grab that they have. */ - usleep(1000); - } - - /* If we fall out of the loop without grabbing the pointer, its - time to give up */ - XSync(dpy,0); - if(val!=GrabSuccess) - { - return False; - } - return True; -} + int i = 0, val = 0; + unsigned int mask; + + XSync(dpy, 0); + /* move the keyboard focus prior to grabbing the pointer to + * eliminate the enterNotify and exitNotify events that go + * to the windows */ + if (Scr.PreviousFocus == NULL) + Scr.PreviousFocus = Scr.Focus; + SetFocus(Scr.NoFocusWin, NULL, 0); + mask = ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | + PointerMotionMask | EnterWindowMask | LeaveWindowMask; + while ((i < 1000) && + (val = XGrabPointer(dpy, Scr.Root, True, mask, GrabModeAsync, + GrabModeAsync, Scr.Root, Scr.FvwmCursors[cursor], + CurrentTime) != GrabSuccess)) { + i++; + /* If you go too fast, other windows may not get a change to + * release any grab that they have. */ + usleep(1000); + } + /* If we fall out of the loop without grabbing the pointer, its + time to give up */ + XSync(dpy, 0); + if (val != GrabSuccess) { + return False; + } + return True; +} /***************************************************************************** * * UnGrab the pointer and keyboard * ****************************************************************************/ -void UngrabEm() +void +UngrabEm() { - Window w; + Window w; - XSync(dpy,0); - XUngrabPointer(dpy,CurrentTime); + XSync(dpy, 0); + XUngrabPointer(dpy, CurrentTime); - if(Scr.PreviousFocus != NULL) - { - w = Scr.PreviousFocus->w; + if (Scr.PreviousFocus != NULL) { + w = Scr.PreviousFocus->w; - /* if the window still exists, focus on it */ - if (w) - { - SetFocus(w,Scr.PreviousFocus,0); + /* if the window still exists, focus on it */ + if (w) { + SetFocus(w, Scr.PreviousFocus, 0); + } + Scr.PreviousFocus = NULL; } - Scr.PreviousFocus = NULL; - } - XSync(dpy,0); + XSync(dpy, 0); } - - /**************************************************************************** * * Keeps the "StaysOnTop" windows on the top of the pile. @@ -820,52 +828,47 @@ void UngrabEm() * obscured by other OnTop windows, which need to be raised here. * ****************************************************************************/ -void KeepOnTop() +void +KeepOnTop() { - FvwmWindow *t; - - /* flag that on-top windows should be re-raised */ - for (t = Scr.FvwmRoot.next; t != NULL; t = t->next) - { - if((t->flags & ONTOP)&&!(t->flags & VISIBLE)) - { - RaiseWindow(t); - t->flags &= ~RAISED; + FvwmWindow *t; + + /* flag that on-top windows should be re-raised */ + for (t = Scr.FvwmRoot.next; t != NULL; t = t->next) { + if ((t->flags & ONTOP) && !(t->flags & VISIBLE)) { + RaiseWindow(t); + t->flags &= ~RAISED; + } else + t->flags |= RAISED; } - else - t->flags |= RAISED; - } } - /************************************************************************** * * Unmaps a window on transition to a new desktop * *************************************************************************/ -void UnmapIt(FvwmWindow *t) +void +UnmapIt(FvwmWindow *t) { - XWindowAttributes winattrs; - unsigned long eventMask; - /* - * Prevent the receipt of an UnmapNotify, since that would - * cause a transition to the Withdrawn state. - */ - XGetWindowAttributes(dpy, t->w, &winattrs); - eventMask = winattrs.your_event_mask; - XSelectInput(dpy, t->w, eventMask & ~StructureNotifyMask); - if(t->flags & ICONIFIED) - { - if(t->icon_pixmap_w != None) - XUnmapWindow(dpy,t->icon_pixmap_w); - if(t->icon_w != None) - XUnmapWindow(dpy,t->icon_w); - } - else if(t->flags & (MAPPED|MAP_PENDING)) - { - XUnmapWindow(dpy,t->frame); - } - XSelectInput(dpy, t->w, eventMask); + XWindowAttributes winattrs; + unsigned long eventMask; + /* + * Prevent the receipt of an UnmapNotify, since that would + * cause a transition to the Withdrawn state. + */ + XGetWindowAttributes(dpy, t->w, &winattrs); + eventMask = winattrs.your_event_mask; + XSelectInput(dpy, t->w, eventMask & ~StructureNotifyMask); + if (t->flags & ICONIFIED) { + if (t->icon_pixmap_w != None) + XUnmapWindow(dpy, t->icon_pixmap_w); + if (t->icon_w != None) + XUnmapWindow(dpy, t->icon_w); + } else if (t->flags & (MAPPED | MAP_PENDING)) { + XUnmapWindow(dpy, t->frame); + } + XSelectInput(dpy, t->w, eventMask); } /************************************************************************** @@ -873,236 +876,246 @@ void UnmapIt(FvwmWindow *t) * Maps a window on transition to a new desktop * *************************************************************************/ -void MapIt(FvwmWindow *t) +void +MapIt(FvwmWindow *t) { - if(t->flags & ICONIFIED) - { - if(t->icon_pixmap_w != None) - XMapWindow(dpy,t->icon_pixmap_w); - if(t->icon_w != None) - XMapWindow(dpy,t->icon_w); - } - else if(t->flags & MAPPED) - { - XMapWindow(dpy,t->frame); - t->flags |= MAP_PENDING; - XMapWindow(dpy, t->Parent); - } + if (t->flags & ICONIFIED) { + if (t->icon_pixmap_w != None) + XMapWindow(dpy, t->icon_pixmap_w); + if (t->icon_w != None) + XMapWindow(dpy, t->icon_w); + } else if (t->flags & MAPPED) { + XMapWindow(dpy, t->frame); + t->flags |= MAP_PENDING; + XMapWindow(dpy, t->Parent); + } } +Bool +IsTransientDescendantOf(FvwmWindow *t, FvwmWindow *ancestor) +{ + FvwmWindow *p; + Window tw; + + if (t == ancestor) + return False; + if ((t->flags & TRANSIENT) == 0) + return False; + tw = t->transientfor; + while (tw != None && tw != Scr.Root) { + if (tw == ancestor->w) + return True; + for (p = Scr.FvwmRoot.next; p != NULL; p = p->next) { + if (p->w == tw) { + if ((p->flags & TRANSIENT) == 0) + return False; + tw = p->transientfor; + break; + } + } + if (p == NULL) + return False; + } + return False; +} - - -void RaiseWindow(FvwmWindow *t) +void +RaiseWindow(FvwmWindow *t) { - FvwmWindow *t2; - int count, i; - Window *wins; - XWindowChanges changes; - FvwmWindow *t1; - FvwmWindow **FvwmTopwins = NULL; - int j, count2; - - - memset((void *) &changes, '\0', sizeof(changes)); - /* raise the target, at least */ - count = 1; - BroadcastPacket(M_RAISE_WINDOW, 3, t->w, t->frame, (unsigned long)t); - - for (t2 = Scr.FvwmRoot.stack_next; t2 != &Scr.FvwmRoot; t2 = t2->stack_next) - { - if(t2->flags & ONTOP) - count++; - if((t2->flags & TRANSIENT) &&(t2->transientfor == t->w)&& - (t2 != t)) - { - count++; - BroadcastPacket(M_RAISE_WINDOW, 3, - t2->w, t2->frame,(unsigned long) t2); - if ((t2->flags & ICONIFIED)&&(!(t2->flags & SUPPRESSICON))) - { - count += 2; - } + FvwmWindow *t2; + int count, i; + Window *wins; + XWindowChanges changes; + FvwmWindow *t1; + FvwmWindow **FvwmTopwins = NULL; + int j, count2; + + memset((void *)&changes, '\0', sizeof(changes)); + /* raise the target, at least */ + count = 1; + BroadcastPacket(M_RAISE_WINDOW, 3, t->w, t->frame, (unsigned long)t); + + for (t2 = Scr.FvwmRoot.stack_next; t2 != &Scr.FvwmRoot; + t2 = t2->stack_next) { + if (t2->flags & ONTOP) + count++; + if (IsTransientDescendantOf(t2, t)) { + count++; + BroadcastPacket(M_RAISE_WINDOW, 3, t2->w, t2->frame, + (unsigned long)t2); + if ((t2->flags & ICONIFIED) && + (!(t2->flags & SUPPRESSICON))) { + count += 2; + } + } } - } - if ((t->flags & ICONIFIED)&&(!(t->flags & SUPPRESSICON))) - { - count += 2; - } - - wins = (Window *)safemalloc(count*sizeof(Window)); - FvwmTopwins = (FvwmWindow **)safemalloc(count*sizeof(FvwmWindow)); - - i=0; - j = 0; - count2 = 0; - - /* ONTOP windows on top */ - for (t2 = Scr.FvwmRoot.stack_next; t2 != &Scr.FvwmRoot; t2 = t2->stack_next) - { - if(t2->flags & ONTOP) - { - BroadcastPacket(M_RAISE_WINDOW, 3, - t2->w, t2->frame, (unsigned long) t2); - wins[i++] = t2->frame; - FvwmTopwins[j++] = t2; + if ((t->flags & ICONIFIED) && (!(t->flags & SUPPRESSICON))) { + count += 2; } - } - /* now raise transients */ + wins = (Window *)xmalloc(count * sizeof(Window)); + FvwmTopwins = (FvwmWindow **)xmalloc(count * sizeof(FvwmWindow)); + + i = 0; + j = 0; + count2 = 0; + + /* ONTOP windows on top */ + for (t2 = Scr.FvwmRoot.stack_next; t2 != &Scr.FvwmRoot; + t2 = t2->stack_next) { + if (t2->flags & ONTOP) { + BroadcastPacket(M_RAISE_WINDOW, 3, t2->w, t2->frame, + (unsigned long)t2); + wins[i++] = t2->frame; + FvwmTopwins[j++] = t2; + } + } + + /* now raise transients */ #ifndef DONT_RAISE_TRANSIENTS - for (t2 = Scr.FvwmRoot.stack_next; t2 != &Scr.FvwmRoot; t2 = t2->stack_next) - { - if((t2->flags & TRANSIENT) && - (t2->transientfor == t->w) && - (t2 != t) && - (!(t2->flags & ONTOP))) - { - wins[i++] = t2->frame; - FvwmTopwins[j++] = t2; - if ((t2->flags & ICONIFIED)&&(!(t2->flags & SUPPRESSICON))) - { - if(!(t2->flags & NOICON_TITLE)) - wins[i++] = t2->icon_w; - if(!(t2->icon_pixmap_w)) - wins[i++] = t2->icon_pixmap_w; - } - } - } + for (t2 = Scr.FvwmRoot.stack_next; t2 != &Scr.FvwmRoot; + t2 = t2->stack_next) { + if (IsTransientDescendantOf(t2, t) && + (!(t2->flags & ONTOP))) { + wins[i++] = t2->frame; + FvwmTopwins[j++] = t2; + if ((t2->flags & ICONIFIED) && + (!(t2->flags & SUPPRESSICON))) { + if (!(t2->flags & NOICON_TITLE)) + wins[i++] = t2->icon_w; + if (!(t2->icon_pixmap_w)) + wins[i++] = t2->icon_pixmap_w; + } + } + } #endif - if ((t->flags & ICONIFIED)&&(!(t->flags & SUPPRESSICON))) - { - if(!(t->flags & NOICON_TITLE)) - wins[i++] = t->icon_w; - if (t->icon_pixmap_w) - wins[i++] = t->icon_pixmap_w; - } - if(!(t->flags & ONTOP)) - { - wins[i++] = t->frame; - FvwmTopwins[j++] = t; - Scr.LastWindowRaised = t; - } - count2 = j; - - if(i > 0) - { -/* XRaiseWindow(dpy,wins[0]); */ - /* - clasen@mathematik.uni-freiburg.de - 01/01/1999 - - simply calling XRaiseWindow(dpy,wins[0]); here will put StaysOnTop - windows over override_redirect windows like FvwmPager ballon_win or - Motif menus. Instead raise wins[0] only above the topmost window - which is managed by us. - */ - if (wins[0] != Scr.FvwmRoot.stack_next->frame && wins[0] != Scr.FvwmRoot.stack_next->icon_w && wins[0] != Scr.FvwmRoot.stack_next->icon_pixmap_w) - { - if (Scr.FvwmRoot.stack_next->flags & ICONIFIED) - { - /* - RBW - use the icon window or pixmap if there is one; but - there may not be (NoIconTitle or NoIcon) -- - */ - if (Scr.FvwmRoot.stack_next->icon_w) - { - changes.sibling = Scr.FvwmRoot.stack_next->icon_w; - } - else if (Scr.FvwmRoot.stack_next->icon_pixmap_w) - { - changes.sibling = Scr.FvwmRoot.stack_next->icon_pixmap_w; - } - else - { - changes.sibling = Scr.FvwmRoot.stack_next->frame; - } - } - else - { - changes.sibling = Scr.FvwmRoot.stack_next->frame; - } - changes.stack_mode = Above; - XConfigureWindow(dpy, wins[0], (CWSibling|CWStackMode), &changes); - } - - - /* - RBW - 01/05/1998 - move all raised windows to front of stacking - order chain. - */ - j = 0; - t2 = &Scr.FvwmRoot; - while (j < count2) - { - t1 = FvwmTopwins[j]; - if (t1 != t2->stack_next) - { - t1->stack_prev->stack_next = t1->stack_next; /* Pluck from chain. */ - t1->stack_next->stack_prev = t1->stack_prev; - t1->stack_next = t2->stack_next; /* Set new pointers. */ - t1->stack_prev = t2->stack_next->stack_prev; - t2->stack_next->stack_prev = t1; /* Insert in new position in chain. */ - t2->stack_next = t1; - } - j++; - if (t2->stack_next != &Scr.FvwmRoot) - { - t2 = t2->stack_next; - } - } - - } - - XRestackWindows(dpy,wins,i); - free(wins); - if (FvwmTopwins) free(FvwmTopwins); - raisePanFrames(); -} + if ((t->flags & ICONIFIED) && (!(t->flags & SUPPRESSICON))) { + if (!(t->flags & NOICON_TITLE)) + wins[i++] = t->icon_w; + if (t->icon_pixmap_w) + wins[i++] = t->icon_pixmap_w; + } + if (!(t->flags & ONTOP)) { + wins[i++] = t->frame; + FvwmTopwins[j++] = t; + Scr.LastWindowRaised = t; + } + count2 = j; + + if (i > 0) { + /* XRaiseWindow(dpy,wins[0]); */ + /* + clasen@mathematik.uni-freiburg.de - 01/01/1999 - + Simply calling XRaiseWindow(dpy,wins[0]); here will put + StaysOnTop windows over override_redirect windows like + FvwmPager ballon_win or Motif menus. Instead raise wins[0] + only above the topmost window which is managed by us. + */ + if (wins[0] != Scr.FvwmRoot.stack_next->frame && + wins[0] != Scr.FvwmRoot.stack_next->icon_w && + wins[0] != Scr.FvwmRoot.stack_next->icon_pixmap_w) { + if (Scr.FvwmRoot.stack_next->flags & ICONIFIED) { + /* + RBW - use the icon window or pixmap if + there is one; but there may not be + (NoIconTitle or NoIcon) -- + */ + if (Scr.FvwmRoot.stack_next->icon_w) { + changes.sibling = + Scr.FvwmRoot.stack_next->icon_w; + } else if (Scr.FvwmRoot.stack_next + ->icon_pixmap_w) { + changes.sibling = + Scr.FvwmRoot.stack_next + ->icon_pixmap_w; + } else { + changes.sibling = + Scr.FvwmRoot.stack_next->frame; + } + } else { + changes.sibling = + Scr.FvwmRoot.stack_next->frame; + } + changes.stack_mode = Above; + XConfigureWindow( + dpy, wins[0], (CWSibling | CWStackMode), &changes); + } + /* + RBW - 01/05/1998 - move all raised windows to front of + stacking order chain. + */ + j = 0; + t2 = &Scr.FvwmRoot; + while (j < count2) { + t1 = FvwmTopwins[j]; + if (t1 != t2->stack_next) { + t1->stack_prev->stack_next = + t1->stack_next; /* Pluck from chain. */ + t1->stack_next->stack_prev = t1->stack_prev; + t1->stack_next = + t2->stack_next; /* Set new pointers. */ + t1->stack_prev = t2->stack_next->stack_prev; + t2->stack_next->stack_prev = + t1; /* Insert in new position in chain. */ + t2->stack_next = t1; + } + j++; + if (t2->stack_next != &Scr.FvwmRoot) { + t2 = t2->stack_next; + } + } + } -void LowerWindow(FvwmWindow *t) -{ - XLowerWindow(dpy,t->frame); - - BroadcastPacket(M_LOWER_WINDOW, 3, t->w, t->frame, (unsigned long)t); - - if((t->flags & ICONIFIED)&&(!(t->flags & SUPPRESSICON))) - { - XLowerWindow(dpy, t->icon_w); - XLowerWindow(dpy, t->icon_pixmap_w); - } - Scr.LastWindowRaised = (FvwmWindow *)0; - /* - RBW - 11/13/1998 - new: maintain the stacking order chain. - */ - t->stack_prev->stack_next = t->stack_next; /* Pluck from chain. */ - t->stack_next->stack_prev = t->stack_prev; - t->stack_next = Scr.FvwmRoot.stack_prev->stack_next; /* Set new pointers. */ - t->stack_prev = Scr.FvwmRoot.stack_prev; - Scr.FvwmRoot.stack_prev->stack_next = t; /* Insert at end of chain. */ - Scr.FvwmRoot.stack_prev = t; + XRestackWindows(dpy, wins, i); + free(wins); + if (FvwmTopwins) + free(FvwmTopwins); + raisePanFrames(); } - -void HandleHardFocus(FvwmWindow *t) +void +LowerWindow(FvwmWindow *t) { - int x,y; - - FocusOnNextTimeStamp = t; - Scr.Focus = NULL; - /* Do something to guarantee a new time stamp! */ - XQueryPointer( dpy, Scr.Root, &JunkRoot, &JunkChild, - &JunkX, &JunkY, &x, &y, &JunkMask); - GrabEm(WAIT); - XWarpPointer(dpy, Scr.Root, Scr.Root, 0, 0, Scr.MyDisplayWidth, - Scr.MyDisplayHeight, - x + 2,y+2); - XSync(dpy,0); - XWarpPointer(dpy, Scr.Root, Scr.Root, 0, 0, Scr.MyDisplayWidth, - Scr.MyDisplayHeight, - x ,y); - UngrabEm(); + XLowerWindow(dpy, t->frame); + + BroadcastPacket(M_LOWER_WINDOW, 3, t->w, t->frame, (unsigned long)t); + + if ((t->flags & ICONIFIED) && (!(t->flags & SUPPRESSICON))) { + XLowerWindow(dpy, t->icon_w); + XLowerWindow(dpy, t->icon_pixmap_w); + } + Scr.LastWindowRaised = (FvwmWindow *)0; + /* + RBW - 11/13/1998 - new: maintain the stacking order chain. + */ + t->stack_prev->stack_next = t->stack_next; /* Pluck from chain. */ + t->stack_next->stack_prev = t->stack_prev; + t->stack_next = + Scr.FvwmRoot.stack_prev->stack_next; /* Set new pointers. */ + t->stack_prev = Scr.FvwmRoot.stack_prev; + Scr.FvwmRoot.stack_prev->stack_next = t; /* Insert at end of chain. */ + Scr.FvwmRoot.stack_prev = t; } +void +HandleHardFocus(FvwmWindow *t) +{ + int x, y; + + FocusOnNextTimeStamp = t; + Scr.Focus = NULL; + /* Do something to guarantee a new time stamp! */ + XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, &JunkX, &JunkY, &x, + &y, &JunkMask); + GrabEm(WAIT); + XWarpPointer(dpy, Scr.Root, Scr.Root, 0, 0, Scr.MyDisplayWidth, + Scr.MyDisplayHeight, x + 2, y + 2); + XSync(dpy, 0); + XWarpPointer(dpy, Scr.Root, Scr.Root, 0, 0, Scr.MyDisplayWidth, + Scr.MyDisplayHeight, x, y); + UngrabEm(); +} /* ** fvwm_msg: used to send output from fvwm to files and or stderr/stdout @@ -1110,51 +1123,48 @@ void HandleHardFocus(FvwmWindow *t) ** type -> DBG == Debug, ERR == Error, INFO == Information, WARN == Warning ** id -> name of function, or other identifier */ -void fvwm_msg(int type,char *id,char *msg,...) +void +fvwm_msg(int type, const char *id, const char *msg, ...) { - char *typestr; - va_list args1, args2; - - switch(type) - { - case DBG: -#if 0 - if (!debugging) - return; -#endif /* 0 */ - typestr="<>"; - break; - case ERR: - typestr="<>"; - break; - case WARN: - typestr="<>"; - break; - case INFO: - default: - typestr=""; - break; - } - - va_start(args1,msg); - va_copy(args2,args1); - - fprintf(stderr,"[FVWM][%s]: %s ",id,typestr); - vfprintf(stderr, msg, args1); - fprintf(stderr,"\n"); - - if (type == ERR) - { - char tmp[1024]; /* I hate to use a fixed length but this will do for now */ - snprintf(tmp, sizeof(tmp), "[FVWM][%s]: %s ",id,typestr); - vsnprintf(tmp+strlen(tmp), sizeof(tmp)-strlen(tmp), msg, args2); - tmp[strlen(tmp)+1]='\0'; - tmp[strlen(tmp)]='\n'; - BroadcastName(M_ERROR,0,0,0,tmp); - } - - va_end(args1); - va_end(args2); + char *typestr; + va_list args1, args2; + + switch (type) { + case DBG: + typestr = "<>"; + break; + case ERR: + typestr = "<>"; + break; + case WARN: + typestr = "<>"; + break; + case INFO: + default: + typestr = ""; + break; + } + + va_start(args1, msg); + va_copy(args2, args1); + + fprintf(stderr, "[FVWM][%s]: %s ", id, typestr); + vfprintf(stderr, msg, args1); + fprintf(stderr, "\n"); + + if (type == ERR) { + char tmp[1024]; /* I hate to use a fixed length but this will do + for now */ + snprintf(tmp, sizeof(tmp), "[FVWM][%s]: %s ", id, typestr); + vsnprintf( + tmp + strlen(tmp), sizeof(tmp) - strlen(tmp), msg, args2); + tmp[strlen(tmp) + 1] = '\0'; + tmp[strlen(tmp)] = '\n'; + BroadcastName(M_ERROR, 0, 0, 0, tmp); + } + + va_end(args1); + va_end(args2); } /* fvwm_msg */ /* CoerceEnterNotifyOnCurrentWindow() @@ -1167,18 +1177,18 @@ void fvwm_msg(int type,char *id,char *msg,...) void CoerceEnterNotifyOnCurrentWindow() { - extern FvwmWindow *Tmp_win; /* from events.c */ - Window child, root; - int root_x, root_y; - int win_x, win_y; - Bool f = XQueryPointer(dpy, Scr.Root, &root, - &child, &root_x, &root_y, &win_x, &win_y, &JunkMask); - if (f && child != None) { - Event.xany.window = child; - if (XFindContext(dpy, child, FvwmContext, (caddr_t *) &Tmp_win) == -XCNOENT) - Tmp_win = NULL; - HandleEnterNotify(); - Tmp_win = None; - } + extern FvwmWindow *Tmp_win; /* from events.c */ + Window child, root; + int root_x, root_y; + int win_x, win_y; + Bool f = XQueryPointer(dpy, Scr.Root, &root, &child, &root_x, &root_y, + &win_x, &win_y, &JunkMask); + if (f && child != None) { + Event.xany.window = child; + if (XFindContext(dpy, child, FvwmContext, + (caddr_t *)&Tmp_win) == XCNOENT) + Tmp_win = NULL; + HandleEnterNotify(); + Tmp_win = None; + } } Index: fvwm/fvwm/misc.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/misc.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/misc.h --- fvwm/fvwm/misc.h +++ fvwm/fvwm/misc.h @@ -2,9 +2,11 @@ #define MISC_H #include +#include + +#include "../libs/fvwmlib.h" #include "defaults.h" #include "menus.h" -#include "../libs/fvwmlib.h" /************************************************************************ * ReapChildren - wait() for all dead child processes @@ -12,121 +14,107 @@ #include #include -#if HAVE_WAITPID -# define ReapChildren() while ((waitpid(-1, NULL, WNOHANG)) > 0); -#elif HAVE_WAIT3 -# define ReapChildren() while ((wait3(NULL, WNOHANG, NULL)) > 0); -#else -# error One of waitpid or wait3 is needed. -#endif +#define ReapChildren() \ + while ((waitpid(-1, NULL, WNOHANG)) > 0) \ + ; -typedef struct name_list_struct -{ - struct name_list_struct *next; /* pointer to the next name */ - char *name; /* the name of the window */ - char *value; /* icon name */ +typedef struct name_list_struct { + struct name_list_struct *next; /* pointer to the next name */ + char *name; /* the name of the window */ + char *value; /* icon name */ #ifdef MINI_ICONS - char *mini_value; /* mini icon name */ + char *mini_value; /* mini icon name */ #endif #ifdef USEDECOR - char *Decor; + char *Decor; #endif - int Desk; /* Desktop number */ -/* RBW - 11/02/1998 - page x,y numbers */ - int PageX; - int PageY; -/**/ - unsigned long on_flags; - unsigned long off_flags; - int border_width; - int resize_width; - char *ForeColor; - char *BackColor; - icon_boxes *IconBoxes; /* pointer to iconbox(s) */ - unsigned long on_buttons; - unsigned long off_buttons; - + int Desk; /* Desktop number */ + /* RBW - 11/02/1998 - page x,y numbers */ + int PageX; + int PageY; + /**/ + unsigned long on_flags; + unsigned long off_flags; + int border_width; + int resize_width; + char *ForeColor; + char *BackColor; + icon_boxes *IconBoxes; /* pointer to iconbox(s) */ + unsigned long on_buttons; + unsigned long off_buttons; } name_list; /* used for parsing configuration */ -struct config -{ - char *keyword; -#ifdef __STDC__ - void (*action)(char *, FILE *, char **, int *); -#else - void (*action)(); -#endif - char **arg; - int *arg2; +struct config { + char *keyword; + void (*action)(char *, FILE *, char **, int *); + char **arg; + int *arg2; }; /* used for parsing commands*/ -struct functions -{ - char *keyword; -#ifdef __STDC__ - void (*action)(XEvent *,Window,FvwmWindow *, unsigned long,char *, int *); -#else - void (*action)(); -#endif - short func_type; - Bool func_needs_window; +struct functions { + char *keyword; + void (*action)(XEvent *, Window, FvwmWindow *, unsigned long, char *, + int *); + short func_type; + Bool func_needs_window; }; /* values for name_list flags */ /* The first 13 items are mapped directly into the FvwmWindow structures * flag value, so they MUST correspond to the first 13 entries in fvwm.h */ -#define START_ICONIC_FLAG (1<<0) -#define STAYSONTOP_FLAG (1<<1) -#define STICKY_FLAG (1<<2) -#define LISTSKIP_FLAG (1<<3) -#define SUPPRESSICON_FLAG (1<<4) -#define NOICON_TITLE_FLAG (1<<5) -#define LENIENCE_FLAG (1<<6) -#define STICKY_ICON_FLAG (1<<7) -#define CIRCULATE_SKIP_ICON_FLAG (1<<8) -#define CIRCULATESKIP_FLAG (1<<9) -#define CLICK_FOCUS_FLAG (1<<10) -#define SLOPPY_FOCUS_FLAG (1<<11) -#define SHOW_MAPPING (1<<12) - -#define NOTITLE_FLAG (1<<13) -#define NOBORDER_FLAG (1<<14) -#define ICON_FLAG (1<<15) -#define STARTSONDESK_FLAG (1<<16) -#define BW_FLAG (1<<17) -#define NOBW_FLAG (1<<18) -#define FORE_COLOR_FLAG (1<<19) -#define BACK_COLOR_FLAG (1<<20) -#define RANDOM_PLACE_FLAG (1<<21) -#define SMART_PLACE_FLAG (1<<22) -#define MWM_BUTTON_FLAG (1<<23) -#define MWM_DECOR_FLAG (1<<24) -#define MWM_FUNCTIONS_FLAG (1<<25) -#define MWM_OVERRIDE_FLAG (1<<26) -#define MWM_BORDER_FLAG (1<<27) -#define DECORATE_TRANSIENT_FLAG (1<<28) -#define NO_PPOSITION_FLAG (1<<29) -#define OL_DECOR_FLAG (1<<30) +#define START_ICONIC_FLAG (1 << 0) +#define STAYSONTOP_FLAG (1 << 1) +#define STICKY_FLAG (1 << 2) +#define LISTSKIP_FLAG (1 << 3) +#define SUPPRESSICON_FLAG (1 << 4) +#define NOICON_TITLE_FLAG (1 << 5) +#define LENIENCE_FLAG (1 << 6) +#define STICKY_ICON_FLAG (1 << 7) +#define CIRCULATE_SKIP_ICON_FLAG (1 << 8) +#define CIRCULATESKIP_FLAG (1 << 9) +#define CLICK_FOCUS_FLAG (1 << 10) +#define SLOPPY_FOCUS_FLAG (1 << 11) +#define SHOW_MAPPING (1 << 12) + +#define NOTITLE_FLAG (1 << 13) +#define NOBORDER_FLAG (1 << 14) +#define ICON_FLAG (1 << 15) +#define STARTSONDESK_FLAG (1 << 16) +#define BW_FLAG (1 << 17) +#define NOBW_FLAG (1 << 18) +#define FORE_COLOR_FLAG (1 << 19) +#define BACK_COLOR_FLAG (1 << 20) +#define RANDOM_PLACE_FLAG (1 << 21) +#define SMART_PLACE_FLAG (1 << 22) +#define MWM_BUTTON_FLAG (1 << 23) +#define MWM_DECOR_FLAG (1 << 24) +#define MWM_FUNCTIONS_FLAG (1 << 25) +#define MWM_OVERRIDE_FLAG (1 << 26) +#define MWM_BORDER_FLAG (1 << 27) +#define DECORATE_TRANSIENT_FLAG (1 << 28) +#define NO_PPOSITION_FLAG (1 << 29) +#define OL_DECOR_FLAG (1 << 30) #ifdef MINI_ICONS -#define MINIICON_FLAG (1<<31) +#define MINIICON_FLAG (1 << 31) #endif /* some fancy font handling stuff */ -#define NewFontAndColor(newfont,color,backcolor) {\ - Globalgcv.font = newfont;\ - Globalgcv.foreground = color;\ - Globalgcv.background = backcolor;\ - Globalgcm = GCFont | GCForeground | GCBackground; \ - XChangeGC(dpy,Scr.ScratchGC3,Globalgcm,&Globalgcv); \ -} +#define NewFontAndColor(newfont, color, backcolor) \ + { \ + Globalgcv.font = newfont; \ + Globalgcv.foreground = color; \ + Globalgcv.background = backcolor; \ + Globalgcm = GCFont | GCForeground | GCBackground; \ + XChangeGC(dpy, Scr.ScratchGC3, Globalgcm, &Globalgcv); \ + } #ifdef NO_ICONS #define ICON_HEIGHT 1 #else -#define ICON_HEIGHT (Scr.IconFont.height+6) +#define ICON_HEIGHT (Scr.IconFont.height + 6) #endif extern XGCValues Globalgcv; @@ -149,145 +137,147 @@ extern char NoResource[]; /* Macro for args passed to fvwm commands... For now, this macro is only used within this file. dje 12/19/98 */ -#define F_CMD_ARGS XEvent *eventp,Window w,FvwmWindow *tmp_win,\ -unsigned long context,char *action, int *Module - -extern void LookInList(FvwmWindow *, name_list *); -extern void MoveOutline(Window, int,int,int,int); -extern void AnimatedMoveOfWindow(Window w,int startX,int startY,int endX, - int endY,Bool fWarpPointerToo, - int cusDelay, float *ppctMovement); -extern void DisplaySize(FvwmWindow *, int, int, Bool, Bool); -extern void DisplayPosition(FvwmWindow *, int, int,Bool); -extern void SetupFrame(FvwmWindow *,int,int,int,int,Bool); -extern void CreateGCs(void); -extern void InstallWindowColormaps(FvwmWindow *); -extern void InstallRootColormap(void); -extern void UninstallRootColormap(void); -extern void FetchWmProtocols(FvwmWindow *); -extern void FetchWmColormapWindows (FvwmWindow *tmp); -extern void InitEventHandlerJumpTable(void); -extern void DispatchEvent(void); -extern void HandleEvents(void); -extern void HandleExpose(void); -extern void HandleFocusIn(void); -extern void HandleFocusOut(void); -extern void HandleDestroyNotify(void); -extern void HandleMapRequest(void); -extern void HandleMapRequestKeepRaised(Window keepraised); -extern void HandleMapNotify(void); -extern void HandleUnmapNotify(void); -extern void HandleMotionNotify(void); -extern void HandleButtonRelease(void); -extern void HandleButtonPress(void); -extern void HandleEnterNotify(void); -extern void HandleLeaveNotify(void); -extern void HandleConfigureRequest(void); -extern void HandleClientMessage(void); -extern void HandlePropertyNotify(void); -extern void HandleKeyPress(void); -extern void HandleVisibilityNotify(void); -extern void HandleColormapNotify(void); -extern void SetTitleBar(FvwmWindow *, Bool,Bool); -extern void RestoreWithdrawnLocation(FvwmWindow *, Bool); -extern void Destroy(FvwmWindow *); -extern void GetGravityOffsets (FvwmWindow *, int *, int *); -extern void MoveViewport(int newx, int newy,Bool); +#define F_CMD_ARGS \ + XEvent *eventp, Window w, FvwmWindow *tmp_win, unsigned long context,\ + char *action, int *Module + +extern void LookInList(FvwmWindow *, name_list *); +extern void MoveOutline(Window, int, int, int, int); +extern void AnimatedMoveOfWindow(Window w, int startX, int startY, int endX, + int endY, Bool fWarpPointerToo, int cusDelay, float *ppctMovement); +extern void DisplaySize(FvwmWindow *, int, int, Bool, Bool); +extern void DisplayPosition(FvwmWindow *, int, int, Bool); +extern void SetupFrame(FvwmWindow *, int, int, int, int, Bool); +extern void CreateGCs(void); +extern void InstallWindowColormaps(FvwmWindow *); +extern void InstallRootColormap(void); +extern void UninstallRootColormap(void); +extern void FetchWmProtocols(FvwmWindow *); +extern void FetchWmColormapWindows(FvwmWindow *tmp); +extern void InitEventHandlerJumpTable(void); +extern void DispatchEvent(void); +extern void HandleEvents(void); +extern void HandleExpose(void); +extern void HandleFocusIn(void); +extern void HandleFocusOut(void); +extern void HandleDestroyNotify(void); +extern void HandleMapRequest(void); +extern void HandleMapRequestKeepRaised(Window keepraised); +extern void HandleMapNotify(void); +extern void HandleUnmapNotify(void); +extern void HandleMotionNotify(void); +extern void HandleButtonRelease(void); +extern void HandleButtonPress(void); +extern void HandleEnterNotify(void); +extern void HandleLeaveNotify(void); +extern void HandleConfigureRequest(void); +extern void HandleClientMessage(void); +extern void HandlePropertyNotify(void); +extern void HandleKeyPress(void); +extern void HandleVisibilityNotify(void); +extern void HandleColormapNotify(void); +extern void SetTitleBar(FvwmWindow *, Bool, Bool); +extern void RestoreWithdrawnLocation(FvwmWindow *, Bool); +extern void Destroy(FvwmWindow *); +extern void GetGravityOffsets(FvwmWindow *, int *, int *); +extern void MoveViewport(int newx, int newy, Bool); extern FvwmWindow *AddWindow(Window w); -extern int MappedNotOverride(Window w); -extern void GrabButtons(FvwmWindow *); -extern void GrabKeys(FvwmWindow *); -extern void GetWindowSizeHints(FvwmWindow *); -extern void SwitchPages(Bool,Bool); -extern void NextPage(void); -extern void PrevPage(void); -extern void moveLoop(FvwmWindow *,int,int,int,int,int *,int *,Bool,Bool); - -extern void Keyboard_shortcuts(XEvent *, FvwmWindow*, int); -extern void RedoIconName(FvwmWindow *); -extern void DrawIconWindow(FvwmWindow *); -extern void CreateIconWindow(FvwmWindow *tmp_win, int def_x, int def_y); - - -extern void RelieveWindow(FvwmWindow *, Window, int, int, int, int, GC, GC, - int); -extern void RelieveWindowHH(FvwmWindow *,Window, int,int,int,int, GC, GC, int, - int); -void RelieveParts(FvwmWindow *t,int i,GC hor, GC vert); -#define NO_HILITE 0x0000 -#define TOP_HILITE 0x0001 -#define RIGHT_HILITE 0x0002 +extern int MappedNotOverride(Window w); +extern void GrabButtons(FvwmWindow *); +extern void GrabKeys(FvwmWindow *); +extern void GetWindowSizeHints(FvwmWindow *); +extern void SwitchPages(Bool, Bool); +extern void NextPage(void); +extern void PrevPage(void); +extern void moveLoop( + FvwmWindow *, int, int, int, int, int *, int *, Bool, Bool); + +extern void Keyboard_shortcuts(XEvent *, FvwmWindow *, int); +extern void RedoIconName(FvwmWindow *); +extern void DrawIconWindow(FvwmWindow *); +extern void CreateIconWindow(FvwmWindow *tmp_win, int def_x, int def_y); + +extern void RelieveWindow( + FvwmWindow *, Window, int, int, int, int, GC, GC, int); +extern void RelieveWindowHH( + FvwmWindow *, Window, int, int, int, int, GC, GC, int, int); +void RelieveParts(FvwmWindow *t, int i, GC hor, GC vert); +#define NO_HILITE 0x0000 +#define TOP_HILITE 0x0001 +#define RIGHT_HILITE 0x0002 #define BOTTOM_HILITE 0x0004 -#define LEFT_HILITE 0x0008 -#define FULL_HILITE 0x000F -#define HH_HILITE 0x0010 +#define LEFT_HILITE 0x0008 +#define FULL_HILITE 0x000F +#define HH_HILITE 0x0010 void Maximize(F_CMD_ARGS); -#ifdef WINDOWSHADE +#ifdef WINDOWSHADE void WindowShade(F_CMD_ARGS); #endif -extern void RaiseWindow(FvwmWindow *t); -extern void LowerWindow(FvwmWindow *t); -extern Bool GrabEm(int); -extern void UngrabEm(void); -extern MenuRoot *NewMenuRoot(char *name, Bool function_or_popup); -extern void AddToMenu(MenuRoot *, char *, char *, Bool, Bool); -extern void MakeMenu(MenuRoot *); -extern void CaptureAllWindows(void); -extern void SetTimer(int); -extern int flush_expose(Window w); +extern void RaiseWindow(FvwmWindow *t); +extern void LowerWindow(FvwmWindow *t); +extern Bool IsTransientDescendantOf(FvwmWindow *t, FvwmWindow *ancestor); +extern Bool GrabEm(int); +extern void UngrabEm(void); +extern MenuRoot *NewMenuRoot(char *name, Bool function_or_popup); +extern void AddToMenu(MenuRoot *, char *, char *, Bool, Bool); +extern void MakeMenu(MenuRoot *); +extern void CaptureAllWindows(void); +extern void SetTimer(int); +extern int flush_expose(Window w); void ExecuteFunction(char *Action, FvwmWindow *tmp_win, XEvent *eventp, - unsigned long context, int Module); + unsigned long context, int Module); void do_windowList(F_CMD_ARGS); -extern void RaiseThisWindow(int); -extern int GetContext(FvwmWindow *, XEvent *, Window *dummy); -extern void ConstrainSize (FvwmWindow *, int *, int *, Bool roundUp, - int xmotion, int ymotion); -extern void HandlePaging(int, int, int *, int *, int *, int *,Bool); -extern void SetShape(FvwmWindow *, int); -extern void AutoPlace(FvwmWindow *); +extern void RaiseThisWindow(int); +extern int GetContext(FvwmWindow *, XEvent *, Window *dummy); +extern void ConstrainSize( + FvwmWindow *, int *, int *, Bool roundUp, int xmotion, int ymotion); +extern void HandlePaging(int, int, int *, int *, int *, int *, Bool); +extern void SetShape(FvwmWindow *, int); +extern void AutoPlace(FvwmWindow *); void executeModule(F_CMD_ARGS); -extern void SetFocus(Window,FvwmWindow *, Bool FocusByMouse); -extern void CheckAndSetFocus(void); -extern void initModules(void); -extern int HandleModuleInput(Window w, int channel); -extern void match_string(struct config *, char *, char *, FILE *); -extern void no_popup(char *ptr); -extern void KillModule(int channel, int place); -extern void ClosePipes(void); -extern char *findIconFile(char *icon, char *pathlist, int mode); +extern void SetFocus(Window, FvwmWindow *, Bool FocusByMouse); +extern void CheckAndSetFocus(void); +extern void initModules(void); +extern int HandleModuleInput(Window w, int channel); +extern void match_string(struct config *, char *, char *, FILE *); +extern void no_popup(char *ptr); +extern void KillModule(int channel, int place); +extern void ClosePipes(void); +extern char *findIconFile(char *icon, char *pathlist, int mode); void find_func_type(char *action, short *func_type, Bool *func_needs_window); -extern void GetBitmapFile(FvwmWindow *tmp_win); -extern void GetXPMFile(FvwmWindow *tmp_win); -extern void GetIconWindow(FvwmWindow *tmp_win); -extern void GetIconBitmap(FvwmWindow *tmp_win); +extern void GetBitmapFile(FvwmWindow *tmp_win); +extern void GetXPMFile(FvwmWindow *tmp_win); +extern void GetIconWindow(FvwmWindow *tmp_win); +extern void GetIconBitmap(FvwmWindow *tmp_win); /* RBW - 11/02/1998 */ -extern int SmartPlacement(FvwmWindow *t, int width, int height,int *x,int *y, - int pdeltax, int pdeltay); +extern int SmartPlacement(FvwmWindow *t, int width, int height, int *x, int *y, + int pdeltax, int pdeltay); /**/ extern void usage(void); void BroadcastPacket(unsigned long event_type, unsigned long num_datum, ...); -void SendPacket(int channel, unsigned long event_type, - unsigned long num_datum, ...); +void SendPacket( + int channel, unsigned long event_type, unsigned long num_datum, ...); void BroadcastConfig(unsigned long event_type, const FvwmWindow *t); void SendConfig(int Module, unsigned long event_type, const FvwmWindow *t); void BroadcastName(unsigned long event_type, unsigned long data1, - unsigned long data2, unsigned long data3, const char *name); + unsigned long data2, unsigned long data3, const char *name); void SendName(int channel, unsigned long event_type, unsigned long data1, - unsigned long data2, unsigned long data3, const char *name); + unsigned long data2, unsigned long data3, const char *name); void SendStrToModule(F_CMD_ARGS); -RETSIGTYPE DeadPipe(int nonsense); +void DeadPipe(int nonsense); void GetMwmHints(FvwmWindow *t); void GetOlHints(FvwmWindow *t); -void SelectDecor(FvwmWindow *, unsigned long, int,int); +void SelectDecor(FvwmWindow *, unsigned long, int, int); extern Bool PopUpMenu(MenuRoot *, int, int); void ComplexFunction(F_CMD_ARGS); -extern int DeferExecution(XEvent *, Window *,FvwmWindow **, unsigned long *, int, int); -void SetBorder (FvwmWindow *, Bool,Bool,Bool, Window); +extern int DeferExecution( + XEvent *, Window *, FvwmWindow **, unsigned long *, int, int); +void SetBorder(FvwmWindow *, Bool, Bool, Bool, Window); void move_window(F_CMD_ARGS); -void move_window_doit(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module, - Bool fAnimated, Bool fMoveToPage); +void move_window_doit(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module, Bool fAnimated, + Bool fMoveToPage); void animated_move_window(F_CMD_ARGS); void move_window_to_page(F_CMD_ARGS); void set_animation(F_CMD_ARGS); @@ -301,30 +291,30 @@ void DeIconify(FvwmWindow *); void KeepOnTop(void); void show_panner(void); void WaitForButtonsUp(void); -void FocusOn(FvwmWindow *t,Bool FocusByMouse); -void WarpOn(FvwmWindow *t,int warp_x, int x_unit, int warp_y, int y_unit); +void FocusOn(FvwmWindow *t, Bool FocusByMouse); +void WarpOn(FvwmWindow *t, int warp_x, int x_unit, int warp_y, int y_unit); /* RBW - 11/02/1998 */ -Bool PlaceWindow(FvwmWindow *tmp_win, unsigned long flags, - int Desk, int PageX, int PageY); -void free_window_names (FvwmWindow *tmp, Bool nukename, Bool nukeicon); +Bool PlaceWindow( + FvwmWindow *tmp_win, unsigned long flags, int Desk, int PageX, int PageY); +void free_window_names(FvwmWindow *tmp, Bool nukename, Bool nukeicon); -MenuStatus do_menu (MenuRoot *menu,MenuRoot *menuPrior, - MenuItem **pmiExecuteAction, int cmenuDeep, Bool fSticks, - XEvent *eventp, MenuOptions *pops); +MenuStatus do_menu(MenuRoot *menu, MenuRoot *menuPrior, + MenuItem **pmiExecuteAction, int cmenuDeep, Bool fSticks, XEvent *eventp, + MenuOptions *pops); int check_allowed_function(MenuItem *mi); int check_allowed_function2(int function, FvwmWindow *t); void ReInstallActiveColormap(void); -void ParsePopupEntry(char *,FILE *, char **, int *); +void ParsePopupEntry(char *, FILE *, char **, int *); void ParseMouseEntry(F_CMD_ARGS); void ParseKeyEntry(F_CMD_ARGS); -void SetOneStyle(char *text,FILE *,char **,int *); -void ParseStyle(char *text,FILE *,char **,int *); -void assign_string(char *text, FILE *fd, char **arg,int *); -void SetFlag(char *text, FILE *fd, char **arg,int *); -void SetCursor(char *text, FILE *fd, char **arg,int *); -void SetInts(char *text, FILE *fd, char **arg,int *); -void SetBox(char *text, FILE *fd, char **arg,int *); -void set_func(char *, FILE *, char **,int *); +void SetOneStyle(char *text, FILE *, char **, int *); +void ParseStyle(char *text, FILE *, char **, int *); +void assign_string(char *text, FILE *fd, char **arg, int *); +void SetFlag(char *text, FILE *fd, char **arg, int *); +void SetCursor(char *text, FILE *fd, char **arg, int *); +void SetInts(char *text, FILE *fd, char **arg, int *); +void SetBox(char *text, FILE *fd, char **arg, int *); +void set_func(char *, FILE *, char **, int *); void copy_config(FILE **config_fd); void SetEdgeScroll(F_CMD_ARGS); void SetEdgeResistance(F_CMD_ARGS); @@ -350,16 +340,16 @@ void do_save(void); void checkPanFrames(void); void raisePanFrames(void); void initPanFrames(void); -Bool StashEventTime (XEvent *ev); +Bool StashEventTime(XEvent *ev); int My_XNextEvent(Display *dpy, XEvent *event); void FlushQueue(int Module); void QuickRestart(void); -void AddFuncKey (char *, int, int, int, char *, int, int, MenuRoot *, - char , char); +void AddFuncKey( + char *, int, int, int, char *, int, int, MenuRoot *, char, char); char *GetNextPtr(char *ptr); -void InteractiveMove(Window *w, FvwmWindow *tmp_win, int *FinalX, int *FinalY, - XEvent *eventp); +void InteractiveMove( + Window *w, FvwmWindow *tmp_win, int *FinalX, int *FinalY, XEvent *eventp); MenuRoot *FindPopup(char *action); @@ -384,14 +374,14 @@ void changeDesks_func(F_CMD_ARGS); void changeDesks(int desk); void changeWindowsDesk(F_CMD_ARGS); -int GetMoveArguments(char *action, int x, int y, int w, int h, - int *pfinalX, int *pfinalY, Bool *fWarp); -char *GetMenuOptions(char *action, Window w, FvwmWindow *tmp_win, - MenuItem *mi, MenuOptions *pops); -int GetTwoArguments(char *action, int *val1, int *val2, int *val1_unit, - int *val2_unit); -int GetTwoPercentArguments(char *action, int *val1, int *val2, int *val1_unit, - int *val2_unit); +int GetMoveArguments(char *action, int x, int y, int w, int h, int *pfinalX, + int *pfinalY, Bool *fWarp); +char *GetMenuOptions(char *action, Window w, FvwmWindow *tmp_win, MenuItem *mi, + MenuOptions *pops); +int GetTwoArguments( + char *action, int *val1, int *val2, int *val1_unit, int *val2_unit); +int GetTwoPercentArguments( + char *action, int *val1, int *val2, int *val1_unit, int *val2_unit); void goto_page_func(F_CMD_ARGS); @@ -416,8 +406,8 @@ Pixel GetColor(char *); void FreeColors(Pixel *pixels, int n); #ifdef GRADIENT_BUTTONS Pixel *AllocLinearGradient(char *s_from, char *s_to, int npixels); -Pixel *AllocNonlinearGradient(char *s_colors[], int clen[], - int nsegs, int npixels); +Pixel *AllocNonlinearGradient( + char *s_colors[], int clen[], int nsegs, int npixels); #endif void bad_binding(int num); void nocolor(char *note, char *name); @@ -478,11 +468,10 @@ void CoerceEnterNotifyOnCurrentWindow(); /* ** message levels for fvwm_msg: */ -#define DBG -1 +#define DBG -1 #define INFO 0 #define WARN 1 -#define ERR 2 -void fvwm_msg(int type,char *id,char *msg,...); +#define ERR 2 +void fvwm_msg(int type, const char *id, const char *msg, ...); #endif /* MISC_H */ - Index: fvwm/fvwm/modconf.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/modconf.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/modconf.c --- fvwm/fvwm/modconf.c +++ fvwm/fvwm/modconf.c @@ -24,40 +24,38 @@ * ******************************************************************** */ -#include "config.h" +#include +#include -#include -#include +#include +#include #include +#include #include -#include -#include -#include -#include +#include +#include "config.h" #include "fvwm.h" #include "menus.h" #include "misc.h" +#include "module.h" #include "parse.h" #include "screen.h" -#include "module.h" -extern unsigned long *PipeMask; /* in module.c */ +extern unsigned long *PipeMask; /* in module.c */ extern Boolean debugging; -struct moduleInfoList -{ - char *data; - struct moduleInfoList *next; +struct moduleInfoList { + char *data; + struct moduleInfoList *next; }; struct moduleInfoList *modlistroot = NULL; -void AddToModList(char *tline); /* prototypes */ +void AddToModList(char *tline); /* prototypes */ extern void StartupStuff(void); - /* * ModuleConfig handles commands starting with "*". * @@ -67,141 +65,136 @@ extern void StartupStuff(void); * Some modules request that module config commands be sent to them * as the commands are entered. Send to modules that want it. */ -void ModuleConfig(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, - char *action, int *Module) { - int module; - AddToModList(action); /* save for config request */ - for (module=0;modulenext; - } - - this = (struct moduleInfoList *)safemalloc(sizeof(struct moduleInfoList)); - len = strlen(tline)+1; - this->data = (char *)safemalloc(len); - this->next = NULL; - strlcpy(this->data, tline, len); - if(prev == NULL) - { - modlistroot = this; - } - else - prev->next = this; + struct moduleInfoList *t, *prev, *this; + size_t len; + + /* Find end of list */ + t = modlistroot; + prev = NULL; + + while (t != NULL) { + prev = t; + t = t->next; + } + + this = + (struct moduleInfoList *)xmalloc(sizeof(struct moduleInfoList)); + len = strlen(tline) + 1; + this->data = (char *)xmalloc(len); + this->next = NULL; + strlcpy(this->data, tline, len); + if (prev == NULL) { + modlistroot = this; + } else + prev->next = this; } /* interface function for AddToModList */ /* dje, this doesn't seem to be used? */ -void AddModConfig(XEvent *eventp,Window junk,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +AddModConfig(XEvent *eventp, Window junk, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - AddToModList( action ); + AddToModList(action); } /**************************************************************/ /* delete from module configuration */ /**************************************************************/ -void DestroyModConfig(XEvent *eventp,Window junk,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +DestroyModConfig(XEvent *eventp, Window junk, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - struct moduleInfoList *current, *next, *prev; - char *info; /* info to be deleted - may contain wildcards */ - char *mi; - - GetNextToken(action, &info); - if( info == NULL ) - { - return; - } - - current = modlistroot; - prev = NULL; - - while(current != NULL) - { - GetNextToken( current->data, &mi); - next = current->next; - if( matchWildcards(info, mi+1) ) - { - free(current->data); - free(current); - if( prev ) - { - prev->next = next; - } - else - { - modlistroot = next; - } - } - else - { - prev = current; - } - current = next; - if (mi) - free(mi); - } - free(info); + struct moduleInfoList *current, *next, *prev; + char *info; /* info to be deleted - may contain wildcards */ + char *mi; + + GetNextToken(action, &info); + if (info == NULL) { + return; + } + + current = modlistroot; + prev = NULL; + + while (current != NULL) { + GetNextToken(current->data, &mi); + next = current->next; + if (mi != NULL && matchWildcards(info, mi + 1)) { + free(current->data); + free(current); + if (prev) { + prev->next = next; + } else { + modlistroot = next; + } + } else { + prev = current; + } + current = next; + if (mi) + free(mi); + } + free(info); } -void SendDataToModule(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action, int *Module) +void +SendDataToModule(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - struct moduleInfoList *t; - char *message,msg2[32]; - extern char *IconPath; - extern char *PixmapPath; - size_t len; - - if (IconPath && strlen(IconPath)) - { - len=strlen(IconPath)+11; - message=safemalloc(len); - snprintf(message,len,"IconPath %s\n",IconPath); - SendName(*Module,M_CONFIG_INFO,0,0,0,message); - free(message); - } + struct moduleInfoList *t; + char *message, msg2[32]; + extern char *IconPath; + extern char *PixmapPath; + size_t len; + + if (IconPath && strlen(IconPath)) { + len = strlen(IconPath) + 11; + message = xmalloc(len); + snprintf(message, len, "IconPath %s\n", IconPath); + SendName(*Module, M_CONFIG_INFO, 0, 0, 0, message); + free(message); + } #ifdef XPM - if (PixmapPath && strlen(PixmapPath)) - { - len=strlen(PixmapPath)+13; - message=safemalloc(len); - snprintf(message,len,"PixmapPath %s\n",PixmapPath); - SendName(*Module,M_CONFIG_INFO,0,0,0,message); - snprintf(message,len,"ColorLimit %d\n",Scr.ColorLimit); - SendName(*Module,M_CONFIG_INFO,0,0,0,message); - free(message); - } + if (PixmapPath && strlen(PixmapPath)) { + len = strlen(PixmapPath) + 13; + message = xmalloc(len); + snprintf(message, len, "PixmapPath %s\n", PixmapPath); + SendName(*Module, M_CONFIG_INFO, 0, 0, 0, message); + snprintf(message, len, "ColorLimit %d\n", Scr.ColorLimit); + SendName(*Module, M_CONFIG_INFO, 0, 0, 0, message); + free(message); + } #endif - /* Dominik Vogt (8-Nov-1998): Scr.ClickTime patch to set ClickTime to - * 'not at all' during InitFunction and RestartFunction. */ - snprintf(msg2,sizeof(msg2),"ClickTime %d\n", (Scr.ClickTime < 0) ? - -Scr.ClickTime : Scr.ClickTime); - SendName(*Module,M_CONFIG_INFO,0,0,0,msg2); - - t = modlistroot; - while(t != NULL) - { - SendName(*Module,M_CONFIG_INFO,0,0,0,t->data); - t = t->next; - } - SendPacket(*Module,M_END_CONFIG_INFO,0,0,0,0,0,0,0,0); + /* Dominik Vogt (8-Nov-1998): Scr.ClickTime patch to set ClickTime to + * 'not at all' during InitFunction and RestartFunction. */ + snprintf(msg2, sizeof(msg2), "ClickTime %d\n", + (Scr.ClickTime < 0) ? -Scr.ClickTime : Scr.ClickTime); + SendName(*Module, M_CONFIG_INFO, 0, 0, 0, msg2); + + t = modlistroot; + while (t != NULL) { + SendName(*Module, M_CONFIG_INFO, 0, 0, 0, t->data); + t = t->next; + } + SendPacket(*Module, M_END_CONFIG_INFO, 0, 0, 0, 0, 0, 0, 0, 0); } Index: fvwm/fvwm/module.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/module.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/module.c --- fvwm/fvwm/module.c +++ fvwm/fvwm/module.c @@ -12,27 +12,26 @@ * ***********************************************************************/ -#include "config.h" +#include "module.h" + +#include +#include -#include -#include -#include #include -#include #include - -#include #include -#include -#include +#include +#include +#include +#include +#include +#include "config.h" #include "fvwm.h" #include "menus.h" #include "misc.h" #include "parse.h" #include "screen.h" -#include "module.h" - int npipes; int *readPipes; @@ -47,792 +46,750 @@ inline int PositiveWrite(int module, unsigned long *ptr, int size); void DeleteQueueBuff(int module); void AddToQueue(int module, unsigned long *ptr, int size, int done); -void initModules(void) +void +initModules(void) { - int i; - - npipes = GetFdWidth(); - - writePipes = (int *)safemalloc(sizeof(int)*npipes); - readPipes = (int *)safemalloc(sizeof(int)*npipes); - pipeOn = (int *)safemalloc(sizeof(int)*npipes); - PipeMask = (unsigned long *)safemalloc(sizeof(unsigned long)*npipes); - pipeName = (char **)safemalloc(sizeof(char *)*npipes); - pipeQueue=(struct queue_buff_struct **) - safemalloc(sizeof(struct queue_buff_struct *)*npipes); - - for(i=0;i0) - { - close(writePipes[i]); - close(readPipes[i]); + int i; + for (i = 0; i < npipes; i++) { + if (writePipes[i] > 0) { + close(writePipes[i]); + close(readPipes[i]); + } + if (pipeName[i] != NULL) { + free(pipeName[i]); + pipeName[i] = 0; + } + while (pipeQueue[i] != NULL) { + DeleteQueueBuff(i); + } } - if(pipeName[i] != NULL) - { - free(pipeName[i]); - pipeName[i] = 0; +} + +void +executeModule(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) +{ + int fvwm_to_app[2], app_to_fvwm[2]; + int i, val, nargs = 0; + char *cptr; + char *args[20]; + char *arg1 = NULL; + char arg2[20]; + char arg3[20]; + char arg5[20]; + char arg6[20]; + extern char *ModulePath; + extern char *fvwm_file; + Window win; + + if (eventp->type != KeyPress) + UngrabEm(); + + if (action == NULL) + return; + + if (tmp_win) + win = tmp_win->w; + else + win = None; + + /* If we execute a module, don't wait for buttons to come up, + * that way, a pop-up menu could be implemented */ + *Module = 0; + + action = GetNextToken(action, &cptr); + if (!cptr) + return; + + arg1 = findIconFile(cptr, ModulePath, X_OK); + if (arg1 == NULL) { + fvwm_msg(ERR, "executeModule", + "No such module '%s' in ModulePath '%s'", cptr, ModulePath); + free(cptr); + return; } - while(pipeQueue[i] != NULL) - { - DeleteQueueBuff(i); + + /* Look for an available pipe slot */ + i = 0; + while ((i < npipes) && (writePipes[i] >= 0)) + i++; + if (i >= npipes) { + fvwm_msg(ERR, "executeModule", "Too many Accessories!"); + free(arg1); + free(cptr); + return; } - } -} + /* I want one-ended pipes, so I open two two-ended pipes, + * and close one end of each. I need one ended pipes so that + * I can detect when the module crashes/malfunctions */ + if (pipe(fvwm_to_app) != 0) { + fvwm_msg(ERR, "executeModule", "Failed to open pipe"); + free(arg1); + free(cptr); + return; + } + if (pipe(app_to_fvwm) != 0) { + fvwm_msg(ERR, "executeModule", "Failed to open pipe2"); + free(arg1); + free(cptr); + close(fvwm_to_app[0]); + close(fvwm_to_app[1]); + return; + } -void executeModule(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) -{ - int fvwm_to_app[2],app_to_fvwm[2]; - int i,val,nargs = 0; - char *cptr; - char *args[20]; - char *arg1 = NULL; - char arg2[20]; - char arg3[20]; - char arg5[20]; - char arg6[20]; - extern char *ModulePath; - extern char *fvwm_file; - Window win; - - if(eventp->type != KeyPress) - UngrabEm(); - - if(action == NULL) - return; - - if(tmp_win) - win = tmp_win->w; - else - win = None; - - /* If we execute a module, don't wait for buttons to come up, - * that way, a pop-up menu could be implemented */ - *Module = 0; - - action = GetNextToken(action, &cptr); - if (!cptr) - return; - - arg1 = findIconFile(cptr,ModulePath,X_OK); - if(arg1 == NULL) - { - fvwm_msg(ERR,"executeModule", - "No such module '%s' in ModulePath '%s'",cptr,ModulePath); - free(cptr); - return; - } - - /* Look for an available pipe slot */ - i=0; - while((i=0)) - i++; - if(i>=npipes) - { - fvwm_msg(ERR,"executeModule","Too many Accessories!"); - free(arg1); - free(cptr); - return; - } - - /* I want one-ended pipes, so I open two two-ended pipes, - * and close one end of each. I need one ended pipes so that - * I can detect when the module crashes/malfunctions */ - if(pipe(fvwm_to_app)!=0) - { - fvwm_msg(ERR,"executeModule","Failed to open pipe"); - free(arg1); - free(cptr); - return; - } - if(pipe(app_to_fvwm)!=0) - { - fvwm_msg(ERR,"executeModule","Failed to open pipe2"); - free(arg1); - free(cptr); - close(fvwm_to_app[0]); - close(fvwm_to_app[1]); - return; - } - - pipeName[i] = stripcpy(cptr); - free(cptr); - snprintf(arg2,sizeof(arg2),"%d",app_to_fvwm[1]); - snprintf(arg3,sizeof(arg3),"%d",fvwm_to_app[0]); - snprintf(arg5,sizeof(arg5),"%lx",(unsigned long)win); - snprintf(arg6,sizeof(arg6),"%lx",(unsigned long)context); - args[0]=arg1; - args[1]=arg2; - args[2]=arg3; - if(fvwm_file != NULL) - args[3]=fvwm_file; - else - args[3]="none"; - args[4]=arg5; - args[5]=arg6; - nargs = 6; - while((action != NULL)&&(nargs < 20)&&(args[nargs-1] != NULL)) - { - args[nargs] = 0; - action = GetNextToken(action,&args[nargs]); - nargs++; - } - if(args[nargs-1] == NULL) - nargs--; - args[nargs] = 0; - - /* Try vfork instead of fork. The man page says that vfork is better! */ - /* Also, had to change exit to _exit() */ - /* Not everyone has vfork! */ - val = fork(); - if(val > 0) - { - /* This fork remains running fvwm */ - /* close appropriate descriptors from each pipe so - * that fvwm will be able to tell when the app dies */ - close(app_to_fvwm[1]); - close(fvwm_to_app[0]); - - /* add these pipes to fvwm's active pipe list */ - writePipes[i] = fvwm_to_app[1]; - readPipes[i] = app_to_fvwm[0]; - pipeOn[i] = -1; - PipeMask[i] = MAX_MASK; - free(arg1); - pipeQueue[i] = NULL; - - /* make the PositiveWrite pipe non-blocking. Don't want to jam up - fvwm because of an uncooperative module */ -#ifdef O_NONBLOCK - fcntl(writePipes[i],F_SETFL,O_NONBLOCK); /* POSIX, better behavior */ -#else - fcntl(writePipes[i],F_SETFL,O_NDELAY); /* early SYSV, bad behavior */ -#endif - /* Mark the pipes close-on exec so other programs - * won`t inherit them */ - if (fcntl(readPipes[i], F_SETFD, 1) == -1) - fvwm_msg(ERR,"executeModule","module close-on-exec failed"); - if (fcntl(writePipes[i], F_SETFD, 1) == -1) - fvwm_msg(ERR,"executeModule","module close-on-exec failed"); - for(i=6;i 0) { + /* This fork remains running fvwm */ + /* close appropriate descriptors from each pipe so + * that fvwm will be able to tell when the app dies */ + close(app_to_fvwm[1]); + close(fvwm_to_app[0]); + + /* add these pipes to fvwm's active pipe list */ + writePipes[i] = fvwm_to_app[1]; + readPipes[i] = app_to_fvwm[0]; + pipeOn[i] = -1; + PipeMask[i] = MAX_MASK; + free(arg1); + pipeQueue[i] = NULL; + + /* make the PositiveWrite pipe non-blocking. Don't want to jam + up fvwm because of an uncooperative module */ + fcntl(writePipes[i], F_SETFL, O_NONBLOCK); + /* Mark the pipes close-on exec so other programs + * won`t inherit them */ + if (fcntl(readPipes[i], F_SETFD, 1) == -1) + fvwm_msg(ERR, "executeModule", + "module close-on-exec failed"); + if (fcntl(writePipes[i], F_SETFD, 1) == -1) + fvwm_msg(ERR, "executeModule", + "module close-on-exec failed"); + for (i = 6; i < nargs; i++) { + if (args[i] != 0) + free(args[i]); + } + } else if (val == 0) { + /* this is the child */ + /* this fork execs the module */ + close(fvwm_to_app[1]); + close(app_to_fvwm[0]); + + execvp(arg1, args); + fvwm_msg(ERR, "executeModule", "Execution of module failed: %s", + arg1); + perror(""); + _exit(1); + } else { + fvwm_msg(ERR, "executeModule", "Fork failed"); + free(arg1); + for (i = 6; i < nargs; i++) { + if (args[i] != 0) + free(args[i]); + } } - } - return; + return; } /* Changed to return 66, Locking code AS dje */ -int HandleModuleInput(Window w, int channel) +int +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 0; - } - - if(size >255) - { - fvwm_msg(ERR, "HandleModuleInput", - "Module command is too big (%d)", size); - size=255; - } - - pipeOn[channel] = 1; - - n = read(readPipes[channel],text, size); - if(n < size) - { - KillModule(channel,2); - return 0; - } - text[n] = '\0'; - /* DB(("Module read[%d] (%d): `%s'", n, size, text)); */ - - n = read(readPipes[channel],&cont, sizeof(cont)); - /* DB(("Module read[%d] cont = %d", n, cont)); */ - if(n < sizeof(cont)) - { - KillModule(channel,3); - return 0; - } - if(cont == 0) - { - KillModule(channel,4); - } - if(strlen(text)>0) - { - extern int Context; - FvwmWindow *tmp_win; - - if(strncasecmp(text,"UNLOCK",6)==0) { /* synchronous response */ - return 66; - } - - /* perhaps the module would like us to kill it? */ - if(strncasecmp(text,"KillMe",6)==0) - { - KillModule(channel,12); - return 0; - } - - /* If a module does XUngrabPointer(), it can now get proper Popups */ - if(StrEquals(text, "popup")) - Event.xany.type = ButtonPress; - else - Event.xany.type = ButtonRelease; - Event.xany.window = w; - - if (XFindContext (dpy, w, FvwmContext, (caddr_t *) &tmp_win) == XCNOENT) - { - tmp_win = NULL; - w = None; + 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 0; + } + + if (size < 0) { + fvwm_msg(ERR, "HandleModuleInput", + "Module sent negative command size (%d)", size); + KillModule(channel, 5); + return 0; + } + if (size > (int)(sizeof(text) - 1)) { + fvwm_msg(ERR, "HandleModuleInput", + "Module command is too big (%d)", size); + size = (int)(sizeof(text) - 1); + } + + pipeOn[channel] = 1; + + n = read(readPipes[channel], text, size); + if (n < size) { + KillModule(channel, 2); + return 0; } - 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; + text[n] = '\0'; + /* DB(("Module read[%d] (%d): `%s'", n, size, text)); */ + + n = read(readPipes[channel], &cont, sizeof(cont)); + /* DB(("Module read[%d] cont = %d", n, cont)); */ + if (n < sizeof(cont)) { + KillModule(channel, 3); + return 0; } - 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; + if (cont == 0) { + KillModule(channel, 4); } - Context = GetContext(tmp_win,&Event,&w); - ExecuteFunction(text,tmp_win,&Event,Context ,channel); - } - return 0; + if (strlen(text) > 0) { + extern int Context; + FvwmWindow *tmp_win; + + if (strncasecmp(text, "UNLOCK", 6) == + 0) { /* synchronous response */ + return 66; + } + + /* perhaps the module would like us to kill it? */ + if (strncasecmp(text, "KillMe", 6) == 0) { + KillModule(channel, 12); + return 0; + } + + /* If a module does XUngrabPointer(), it can now get proper + * Popups */ + if (StrEquals(text, "popup")) + Event.xany.type = ButtonPress; + else + Event.xany.type = ButtonRelease; + Event.xany.window = w; + + if (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); + } + return 0; } - -RETSIGTYPE DeadPipe(int nonsense) +void +DeadPipe(int nonsense) { } - -void KillModule(int channel, int place) +void +KillModule(int channel, int place) { - close(readPipes[channel]); - close(writePipes[channel]); - - readPipes[channel] = -1; - writePipes[channel] = -1; - pipeOn[channel] = -1; - while(pipeQueue[channel] != NULL) - { - DeleteQueueBuff(channel); - } - if(pipeName[channel] != NULL) - { - free(pipeName[channel]); - pipeName[channel] = NULL; - } - - return; + close(readPipes[channel]); + close(writePipes[channel]); + + readPipes[channel] = -1; + writePipes[channel] = -1; + pipeOn[channel] = -1; + while (pipeQueue[channel] != NULL) { + DeleteQueueBuff(channel); + } + if (pipeName[channel] != NULL) { + free(pipeName[channel]); + pipeName[channel] = NULL; + } + + return; } -void KillModuleByName(char *name) +void +KillModuleByName(char *name) { - int i = 0; + int i = 0; - if(name == NULL) - return; + if (name == NULL) + return; - while(i 0; --num) - *(bp++) = va_arg(ap, unsigned long); + for (; num > 0; --num) + *(bp++) = va_arg(ap, unsigned long); - return body; + return body; } void SendPacket(int module, unsigned long event_type, unsigned long num_datum, ...) { - unsigned long body[MAX_BODY_SIZE+HEADER_SIZE]; - va_list ap; + unsigned long body[MAX_BODY_SIZE + HEADER_SIZE]; + va_list ap; - va_start(ap, num_datum); - make_vpacket(body, event_type, num_datum, ap); - va_end(ap); + va_start(ap, num_datum); + make_vpacket(body, event_type, num_datum, ap); + va_end(ap); - PositiveWrite(module, body, (num_datum+HEADER_SIZE)*sizeof(body[0])); + PositiveWrite( + module, body, (num_datum + HEADER_SIZE) * sizeof(body[0])); } void BroadcastPacket(unsigned long event_type, unsigned long num_datum, ...) { - unsigned long body[MAX_BODY_SIZE+HEADER_SIZE]; - va_list ap; - int i; + unsigned long body[MAX_BODY_SIZE + HEADER_SIZE]; + va_list ap; + int i; - va_start(ap,num_datum); - make_vpacket(body, event_type, num_datum, ap); - va_end(ap); + va_start(ap, num_datum); + make_vpacket(body, event_type, num_datum, ap); + va_end(ap); - for (i=0; iw,\ - (_t)->frame,\ - (unsigned long)(_t),\ - (_t)->frame_x,\ - (_t)->frame_y,\ - (_t)->frame_width,\ - (_t)->frame_height,\ - (_t)->Desk,\ - (_t)->flags,\ - (_t)->title_height,\ - (_t)->boundary_width,\ - ((_t)->hints.flags & PBaseSize) ? (_t)->hints.base_width : 0,\ - ((_t)->hints.flags & PBaseSize) ? (_t)->hints.base_height: 0,\ - ((_t)->hints.flags & PResizeInc)? (_t)->hints.width_inc : 1,\ - ((_t)->hints.flags & PResizeInc)? (_t)->hints.height_inc : 1,\ - (_t)->hints.min_width,\ - (_t)->hints.min_height,\ - (_t)->hints.max_width,\ - (_t)->hints.max_height,\ - (_t)->icon_w,\ - (_t)->icon_pixmap_w,\ - (_t)->hints.win_gravity,\ - (_t)->TextPixel,\ - (_t)->BackPixel - -void SendConfig(int module, unsigned long event_type, const FvwmWindow *t) +#define CONFIGARGS(_t) \ + 24, (_t)->w, (_t)->frame, (unsigned long)(_t), (_t)->frame_x, \ + (_t)->frame_y, (_t)->frame_width, (_t)->frame_height, (_t)->Desk,\ + (_t)->flags, (_t)->title_height, (_t)->boundary_width, \ + ((_t)->hints.flags & PBaseSize) ? (_t)->hints.base_width : 0,\ + ((_t)->hints.flags & PBaseSize) ? (_t)->hints.base_height : 0,\ + ((_t)->hints.flags & PResizeInc) ? (_t)->hints.width_inc : 1,\ + ((_t)->hints.flags & PResizeInc) ? (_t)->hints.height_inc : 1,\ + (_t)->hints.min_width, (_t)->hints.min_height, \ + (_t)->hints.max_width, (_t)->hints.max_height, (_t)->icon_w,\ + (_t)->icon_pixmap_w, (_t)->hints.win_gravity, (_t)->TextPixel,\ + (_t)->BackPixel + +void +SendConfig(int module, unsigned long event_type, const FvwmWindow *t) { - SendPacket(module, event_type, CONFIGARGS(t)); + SendPacket(module, event_type, CONFIGARGS(t)); } - -void BroadcastConfig(unsigned long event_type, const FvwmWindow *t) +void +BroadcastConfig(unsigned long event_type, const FvwmWindow *t) { - BroadcastPacket(event_type, CONFIGARGS(t)); + BroadcastPacket(event_type, CONFIGARGS(t)); } static unsigned long * -make_named_packet(int *len, unsigned long event_type, const char *name, - int num, ...) +make_named_packet( + int *len, unsigned long event_type, const char *name, int num, ...) { - unsigned long *body; - va_list ap; + unsigned long *body; + va_list ap; - /* Packet is the header plus the items plus enough items to hold the name - string. */ - *len = HEADER_SIZE + num + (strlen(name) / sizeof(unsigned long)) + 1; + /* Packet is the header plus the items plus enough items to hold the + name string. */ + *len = HEADER_SIZE + num + (strlen(name) / sizeof(unsigned long)) + 1; - body = (unsigned long *)safemalloc(*len * sizeof(unsigned long)); - body[*len-1] = 0; /* Zero out end of memory to avoid uninit memory access. */ + body = (unsigned long *)xmalloc(*len * sizeof(unsigned long)); + body[*len - 1] = + 0; /* Zero out end of memory to avoid uninit memory access. */ - va_start(ap, num); - make_vpacket(body, event_type, num, ap); - va_end(ap); + va_start(ap, num); + make_vpacket(body, event_type, num, ap); + va_end(ap); - strlcpy((char *)&body[HEADER_SIZE+num], name, - *len * sizeof(unsigned long) - HEADER_SIZE - num); - body[2] = *len; + strlcpy((char *)&body[HEADER_SIZE + num], name, + (*len - HEADER_SIZE - num) * sizeof(unsigned long)); + body[2] = *len; - /* DB(("Packet (%lu): %lu %lu %lu `%s'", *len, - body[HEADER_SIZE], body[HEADER_SIZE+1], body[HEADER_SIZE+2], name)); */ + /* DB(("Packet (%lu): %lu %lu %lu `%s'", *len, + body[HEADER_SIZE], body[HEADER_SIZE+1], body[HEADER_SIZE+2], + name)); */ - return (body); + return (body); } void -SendName(int module, unsigned long event_type, - unsigned long data1,unsigned long data2, unsigned long data3, - const char *name) +SendName(int module, unsigned long event_type, unsigned long data1, + unsigned long data2, unsigned long data3, const char *name) { - unsigned long *body; - int l; + unsigned long *body; + int l; - if (name == NULL) - return; + if (name == NULL) + return; - body = make_named_packet(&l, event_type, name, 3, data1, data2, data3); - PositiveWrite(module, body, l*sizeof(unsigned long)); - free(body); + body = make_named_packet(&l, event_type, name, 3, data1, data2, data3); + PositiveWrite(module, body, l * sizeof(unsigned long)); + free(body); } void -BroadcastName(unsigned long event_type, - unsigned long data1, unsigned long data2, unsigned long data3, - const char *name) +BroadcastName(unsigned long event_type, unsigned long data1, + unsigned long data2, unsigned long data3, const char *name) { - unsigned long *body; - int i, l; + unsigned long *body; + int i, l; - if (name == NULL) - return; + if (name == NULL) + return; - body = make_named_packet(&l, event_type, name, 3, data1, data2, data3); + body = make_named_packet(&l, event_type, name, 3, data1, data2, data3); - for (i=0; i < npipes; i++) - PositiveWrite(i, body, l*sizeof(unsigned long)); + for (i = 0; i < npipes; i++) + PositiveWrite(i, body, l * sizeof(unsigned long)); - free(body); + free(body); } #ifdef MINI_ICONS void -SendMiniIcon(int module, unsigned long event_type, - unsigned long data1, unsigned long data2, - unsigned long data3, unsigned long data4, - unsigned long data5, unsigned long data6, - unsigned long data7, unsigned long data8, - const char *name) +SendMiniIcon(int module, unsigned long event_type, unsigned long data1, + unsigned long data2, unsigned long data3, unsigned long data4, + unsigned long data5, unsigned long data6, unsigned long data7, + unsigned long data8, const char *name) { - unsigned long *body; - int l; + unsigned long *body; + int l; - if ((name == NULL) || (event_type != M_MINI_ICON)) - return; + if ((name == NULL) || (event_type != M_MINI_ICON)) + return; - body = make_named_packet(&l, event_type, name, 8, data1, data2, data3, - data4, data5, data6, data7, data8); - PositiveWrite(module, body, l*sizeof(unsigned long)); - free(body); + body = make_named_packet(&l, event_type, name, 8, data1, data2, data3, + data4, data5, data6, data7, data8); + PositiveWrite(module, body, l * sizeof(unsigned long)); + free(body); } void -BroadcastMiniIcon(unsigned long event_type, - unsigned long data1, unsigned long data2, - unsigned long data3, unsigned long data4, - unsigned long data5, unsigned long data6, - unsigned long data7, unsigned long data8, - const char *name) +BroadcastMiniIcon(unsigned long event_type, unsigned long data1, + unsigned long data2, unsigned long data3, unsigned long data4, + unsigned long data5, unsigned long data6, unsigned long data7, + unsigned long data8, const char *name) { - unsigned long *body; - int i, l; + unsigned long *body; + int i, l; - body = make_named_packet(&l, event_type, name, 8, data1, data2, data3, - data4, data5, data6, data7, data8); + body = make_named_packet(&l, event_type, name, 8, data1, data2, data3, + data4, data5, data6, data7, data8); - for (i=0; i < npipes; i++) - PositiveWrite(i, body, l*sizeof(unsigned long)); + for (i = 0; i < npipes; i++) + PositiveWrite(i, body, l * sizeof(unsigned long)); - free(body); + free(body); } #endif /* MINI_ICONS */ /* ** send an arbitrary string to all instances of a module */ -void SendStrToModule(XEvent *eventp,Window junk,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +SendStrToModule(XEvent *eventp, Window junk, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - char *module,*str; - int i; - - if (!action) - return; - GetNextToken(action,&module); - if (!module) - return; - str = strdup(action + strlen(module) + 1); - - for (i=0;i 0) { - if (HandleModuleInput(targetWindow,module) == 66) { - break; - } - } - if (e <= 0) { - KillModule(module,10); - } - fcntl(readPipes[module],F_SETFL,O_NDELAY); - } - return size; + if ((pipeOn[module] < 0) || (!((PipeMask[module]) & ptr[1]))) + return -1; + + /* + * fvwm2 recapture has the x server grabbed while iconify events are + * simulated. Right now (01/24/99), the only module using lock on send + * is FvwmAnimate which always does a grab of its own. To avoid a + * deadlock, iconify events are not sent to a lock on send module while + * the server is grabbed. In the future, it might make sense to send + * the fact that the server is grabbed to the lock on send module, or + * in some other way get finer control. + */ + if ((PipeMask[module] & M_LOCKONSEND) && /* module uses lock on send */ + (myxgrabcount != 0) && /* and server grabbed */ + (ptr[1] & M_ICONIFY)) { /* and its an iconify event */ + return -1; /* don't send it */ + } + AddToQueue(module, ptr, size, 0); + /* dje, from afterstep, for FvwmAnimate, + allows the module to synchronize with fvwm. + */ + if (PipeMask[module] & M_LOCKONSEND) { + Window targetWindow; + int e; + + FlushQueue(module); + fcntl(readPipes[module], F_SETFL, 0); + while ((e = read(readPipes[module], &targetWindow, + sizeof(Window))) > 0) { + if (HandleModuleInput(targetWindow, module) == 66) { + break; + } + } + if (e <= 0) { + KillModule(module, 10); + } + fcntl(readPipes[module], F_SETFL, O_NDELAY); + } + return size; } - -void AddToQueue(int module, unsigned long *ptr, int size, int done) +void +AddToQueue(int module, unsigned long *ptr, int size, int done) { - struct queue_buff_struct *c,*e; - unsigned long *d; - - c = (struct queue_buff_struct *)safemalloc(sizeof(struct queue_buff_struct)); - c->next = NULL; - c->size = size; - c->done = done; - d = (unsigned long *)safemalloc(size); - c->data = d; - memcpy((void*)d,(const void*)ptr,size); - - e = pipeQueue[module]; - if(e == NULL) - { - pipeQueue[module] = c; - return; - } - while(e->next != NULL) - e = e->next; - e->next = c; + struct queue_buff_struct *c, *e; + unsigned long *d; + + c = (struct queue_buff_struct *)xmalloc( + sizeof(struct queue_buff_struct)); + c->next = NULL; + c->size = size; + c->done = done; + d = (unsigned long *)xmalloc(size); + c->data = d; + memcpy((void *)d, (const void *)ptr, size); + + e = pipeQueue[module]; + if (e == NULL) { + pipeQueue[module] = c; + return; + } + while (e->next != NULL) + e = e->next; + e->next = c; } -void DeleteQueueBuff(int module) +void +DeleteQueueBuff(int module) { - struct queue_buff_struct *a; - - if(pipeQueue[module] == NULL) - return; - a = pipeQueue[module]; - pipeQueue[module] = a->next; - free(a->data); - free(a); - return; + struct queue_buff_struct *a; + + if (pipeQueue[module] == NULL) + return; + a = pipeQueue[module]; + pipeQueue[module] = a->next; + free(a->data); + free(a); + return; } -void FlushQueue(int module) +void +FlushQueue(int module) { - char *dptr; - struct queue_buff_struct *d; - int a; - - if((pipeOn[module] <= 0)||(pipeQueue[module] == NULL)) - return; - - while(pipeQueue[module] != NULL) - { - d = pipeQueue[module]; - dptr = (char *)d->data; - while(d->done < d->size) - { - a = write(writePipes[module],&dptr[d->done], d->size - d->done); - if(a >=0) - d->done += a; - /* the write returns EWOULDBLOCK or EAGAIN if the pipe is full. - * (This is non-blocking I/O). SunOS returns EWOULDBLOCK, OSF/1 - * returns EAGAIN under these conditions. Hopefully other OSes - * return one of these values too. Solaris 2 doesn't seem to have - * a man page for write(2) (!) */ - else if ((errno == EWOULDBLOCK)||(errno == EAGAIN)||(errno==EINTR)) - { - return; - } - else - { - KillModule(module,123); - return; - } + char *dptr; + struct queue_buff_struct *d; + int a; + + if ((pipeOn[module] <= 0) || (pipeQueue[module] == NULL)) + return; + + while (pipeQueue[module] != NULL) { + d = pipeQueue[module]; + dptr = (char *)d->data; + while (d->done < d->size) { + a = write(writePipes[module], &dptr[d->done], + d->size - d->done); + if (a >= 0) + d->done += a; + /* the write returns EWOULDBLOCK or EAGAIN if the pipe + * is full. (This is non-blocking I/O). SunOS returns + * EWOULDBLOCK, OSF/1 returns EAGAIN under these + * conditions. Hopefully other OSes return one of these + * values too. Solaris 2 doesn't seem to have a man page + * for write(2) (!) */ + else if ((errno == EWOULDBLOCK) || (errno == EAGAIN) || + (errno == EINTR)) { + return; + } else { + KillModule(module, 123); + return; + } + } + DeleteQueueBuff(module); } - DeleteQueueBuff(module); - } } - -void send_list_func(XEvent *eventp, Window w, FvwmWindow *tmp_win, - unsigned long context, char *action, int *Module) +void +send_list_func(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - FvwmWindow *t; - - if(*Module >= 0) - { - SendPacket(*Module, M_NEW_DESK, 1, Scr.CurrentDesk); - SendPacket(*Module, M_NEW_PAGE, 5, - Scr.Vx, Scr.Vy, Scr.CurrentDesk, Scr.VxMax, Scr.VyMax); - - if(Scr.Hilite != NULL) - SendPacket(*Module, M_FOCUS_CHANGE, 5, - Scr.Hilite->w, - Scr.Hilite->frame, - (unsigned long)Scr.Hilite, - Scr.DefaultDecor.HiColors.fore, - Scr.DefaultDecor.HiColors.back); - else - SendPacket(*Module, M_FOCUS_CHANGE, 5, - 0, 0, 0, - Scr.DefaultDecor.HiColors.fore, - Scr.DefaultDecor.HiColors.back); - if (Scr.DefaultIcon != NULL) - SendName(*Module, M_DEFAULTICON, 0, 0, 0, Scr.DefaultIcon); - - for (t = Scr.FvwmRoot.next; t != NULL; t = t->next) - { - SendConfig(*Module,M_CONFIGURE_WINDOW,t); - SendName(*Module,M_WINDOW_NAME,t->w,t->frame, - (unsigned long)t,t->name); - SendName(*Module,M_ICON_NAME,t->w,t->frame, - (unsigned long)t,t->icon_name); - - if (t->icon_bitmap_file != NULL - && t->icon_bitmap_file != Scr.DefaultIcon) - SendName(*Module,M_ICON_FILE,t->w,t->frame, - (unsigned long)t,t->icon_bitmap_file); - - SendName(*Module,M_RES_CLASS,t->w,t->frame, - (unsigned long)t,t->class.res_class); - SendName(*Module,M_RES_NAME,t->w,t->frame, - (unsigned long)t,t->class.res_name); - - if((t->flags & ICONIFIED)&&(!(t->flags & ICON_UNMAPPED))) - SendPacket(*Module, M_ICONIFY, 7, t->w, t->frame, - (unsigned long)t, - t->icon_x_loc, t->icon_y_loc, - t->icon_w_width, t->icon_w_height+t->icon_p_height); - - if((t->flags & ICONIFIED) && (t->flags & ICON_UNMAPPED)) - SendPacket(*Module, M_ICONIFY, 7, t->w, t->frame, - (unsigned long)t, - 0, 0, 0, 0); + FvwmWindow *t; + + if (*Module >= 0) { + SendPacket(*Module, M_NEW_DESK, 1, Scr.CurrentDesk); + SendPacket(*Module, M_NEW_PAGE, 5, Scr.Vx, Scr.Vy, + Scr.CurrentDesk, Scr.VxMax, Scr.VyMax); + + if (Scr.Hilite != NULL) + SendPacket(*Module, M_FOCUS_CHANGE, 5, Scr.Hilite->w, + Scr.Hilite->frame, (unsigned long)Scr.Hilite, + Scr.DefaultDecor.HiColors.fore, + Scr.DefaultDecor.HiColors.back); + else + SendPacket(*Module, M_FOCUS_CHANGE, 5, 0, 0, 0, + Scr.DefaultDecor.HiColors.fore, + Scr.DefaultDecor.HiColors.back); + if (Scr.DefaultIcon != NULL) + SendName( + *Module, M_DEFAULTICON, 0, 0, 0, Scr.DefaultIcon); + + for (t = Scr.FvwmRoot.next; t != NULL; t = t->next) { + SendConfig(*Module, M_CONFIGURE_WINDOW, t); + SendName(*Module, M_WINDOW_NAME, t->w, t->frame, + (unsigned long)t, t->name); + SendName(*Module, M_ICON_NAME, t->w, t->frame, + (unsigned long)t, t->icon_name); + + if (t->icon_bitmap_file != NULL && + t->icon_bitmap_file != Scr.DefaultIcon) + SendName(*Module, M_ICON_FILE, t->w, t->frame, + (unsigned long)t, t->icon_bitmap_file); + + SendName(*Module, M_RES_CLASS, t->w, t->frame, + (unsigned long)t, t->class.res_class); + SendName(*Module, M_RES_NAME, t->w, t->frame, + (unsigned long)t, t->class.res_name); + + if ((t->flags & ICONIFIED) && + (!(t->flags & ICON_UNMAPPED))) + SendPacket(*Module, M_ICONIFY, 7, t->w, + t->frame, (unsigned long)t, t->icon_x_loc, + t->icon_y_loc, t->icon_w_width, + t->icon_w_height + t->icon_p_height); + + if ((t->flags & ICONIFIED) && + (t->flags & ICON_UNMAPPED)) + SendPacket(*Module, M_ICONIFY, 7, t->w, + t->frame, (unsigned long)t, 0, 0, 0, 0); #ifdef MINI_ICONS - if (t->mini_icon != NULL) - SendMiniIcon(*Module, M_MINI_ICON, - t->w, t->frame, (unsigned long)t, - t->mini_icon->width, - t->mini_icon->height, - t->mini_icon->depth, - t->mini_icon->picture, - t->mini_icon->mask, - t->mini_pixmap_file); + if (t->mini_icon != NULL) + SendMiniIcon(*Module, M_MINI_ICON, t->w, + t->frame, (unsigned long)t, + t->mini_icon->width, t->mini_icon->height, + t->mini_icon->depth, t->mini_icon->picture, + t->mini_icon->mask, t->mini_pixmap_file); #endif + } + + if (Scr.Hilite == NULL) + BroadcastPacket(M_FOCUS_CHANGE, 5, 0, 0, 0, + Scr.DefaultDecor.HiColors.fore, + Scr.DefaultDecor.HiColors.back); + else + BroadcastPacket(M_FOCUS_CHANGE, 5, Scr.Hilite->w, + Scr.Hilite->frame, (unsigned long)Scr.Hilite, + Scr.DefaultDecor.HiColors.fore, + Scr.DefaultDecor.HiColors.back); + + SendPacket(*Module, M_END_WINDOWLIST, 0); } - - if(Scr.Hilite == NULL) - BroadcastPacket(M_FOCUS_CHANGE, 5, - 0, 0, 0, - Scr.DefaultDecor.HiColors.fore, - Scr.DefaultDecor.HiColors.back); - else - BroadcastPacket(M_FOCUS_CHANGE, 5, - Scr.Hilite->w, - Scr.Hilite->frame, - (unsigned long)Scr.Hilite, - Scr.DefaultDecor.HiColors.fore, - Scr.DefaultDecor.HiColors.back); - - SendPacket(*Module, M_END_WINDOWLIST, 0); - } } -void set_mask_function(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) + +void +set_mask_function(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - int val = 0; + int val = 0; - GetIntegerArguments(action, NULL, &val, 1); - PipeMask[*Module] = (unsigned long)val; + GetIntegerArguments(action, NULL, &val, 1); + PipeMask[*Module] = (unsigned long)val; } Index: fvwm/fvwm/module.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/module.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/module.h --- fvwm/fvwm/module.h +++ fvwm/fvwm/module.h @@ -1,12 +1,11 @@ #ifndef MODULE_H #define MODULE_H -struct queue_buff_struct -{ - struct queue_buff_struct *next; - unsigned long *data; - int size; - int done; +struct queue_buff_struct { + struct queue_buff_struct *next; + unsigned long *data; + int size; + int done; }; extern int npipes; @@ -16,43 +15,43 @@ extern struct queue_buff_struct **pipeQueue; #define START_FLAG 0xffffffff -#define M_NEW_PAGE (1) -#define M_NEW_DESK (1<<1) -#define M_ADD_WINDOW (1<<2) -#define M_RAISE_WINDOW (1<<3) -#define M_LOWER_WINDOW (1<<4) -#define M_CONFIGURE_WINDOW (1<<5) -#define M_FOCUS_CHANGE (1<<6) -#define M_DESTROY_WINDOW (1<<7) -#define M_ICONIFY (1<<8) -#define M_DEICONIFY (1<<9) -#define M_WINDOW_NAME (1<<10) -#define M_ICON_NAME (1<<11) -#define M_RES_CLASS (1<<12) -#define M_RES_NAME (1<<13) -#define M_END_WINDOWLIST (1<<14) -#define M_ICON_LOCATION (1<<15) -#define M_MAP (1<<16) +#define M_NEW_PAGE (1) +#define M_NEW_DESK (1 << 1) +#define M_ADD_WINDOW (1 << 2) +#define M_RAISE_WINDOW (1 << 3) +#define M_LOWER_WINDOW (1 << 4) +#define M_CONFIGURE_WINDOW (1 << 5) +#define M_FOCUS_CHANGE (1 << 6) +#define M_DESTROY_WINDOW (1 << 7) +#define M_ICONIFY (1 << 8) +#define M_DEICONIFY (1 << 9) +#define M_WINDOW_NAME (1 << 10) +#define M_ICON_NAME (1 << 11) +#define M_RES_CLASS (1 << 12) +#define M_RES_NAME (1 << 13) +#define M_END_WINDOWLIST (1 << 14) +#define M_ICON_LOCATION (1 << 15) +#define M_MAP (1 << 16) /* It turns out this is defined by on Solaris 2.6. - I suspect that simply redefining this will lead to trouble; + I suspect that simply redefining this will lead to trouble; at some point, these should probably be renamed (FVWM_MSG_ERROR?). */ #ifdef M_ERROR -# undef M_ERROR +#undef M_ERROR #endif -#define M_ERROR (1<<17) +#define M_ERROR (1 << 17) -#define M_CONFIG_INFO (1<<18) -#define M_END_CONFIG_INFO (1<<19) -#define M_ICON_FILE (1<<20) -#define M_DEFAULTICON (1<<21) -#define M_STRING (1<<22) -#define M_MINI_ICON (1<<23) -#define M_WINDOWSHADE (1<<24) -#define M_DEWINDOWSHADE (1<<25) -#define M_LOCKONSEND (1<<26) -#define M_SENDCONFIG (1<<27) -#define MAX_MESSAGES 28 +#define M_CONFIG_INFO (1 << 18) +#define M_END_CONFIG_INFO (1 << 19) +#define M_ICON_FILE (1 << 20) +#define M_DEFAULTICON (1 << 21) +#define M_STRING (1 << 22) +#define M_MINI_ICON (1 << 23) +#define M_WINDOWSHADE (1 << 24) +#define M_DEWINDOWSHADE (1 << 25) +#define M_LOCKONSEND (1 << 26) +#define M_SENDCONFIG (1 << 27) +#define MAX_MESSAGES 28 /* * MAX_MASK is used to initialize the pipeMask array. In a few places @@ -71,8 +70,7 @@ extern struct queue_buff_struct **pipeQueue; * creating and looping over large arrays. The impact seems to be in * module.c, modconf.c and event.c. dje 10/2/98 */ -#define MAX_MASK (((1< +#include #include +#include #include #include -#include + +#include "config.h" #include "fvwm.h" #include "menus.h" #include "misc.h" +#include "module.h" #include "parse.h" #include "screen.h" -#include "module.h" extern XEvent Event; extern int menuFromFrameOrWindowOrTitlebar; @@ -33,374 +33,379 @@ Bool NeedToResizeToo; /* Animated move stuff added by Greg J. Badros, gjb@cs.washington.edu */ float rgpctMovementDefault[32] = { - -.01, 0, .01, .03,.08,.18,.3,.45,.60,.75,.85,.90,.94,.97,.99,1.0 + -.01, 0, .01, .03, .08, .18, .3, .45, .60, .75, .85, .90, .94, .97, .99, 1.0 /* must end in 1.0 */ - }; +}; int cmsDelayDefault = 10; /* milliseconds */ /* Perform the movement of the window. ppctMovement *must* have a 1.0 entry * somewhere in ins list of floats, and movement will stop when it hits a 1.0 * entry */ -void AnimatedMoveOfWindow(Window w,int startX,int startY,int endX, int endY, - Bool fWarpPointerToo, int cmsDelay, - float *ppctMovement ) +void +AnimatedMoveOfWindow(Window w, int startX, int startY, int endX, int endY, + Bool fWarpPointerToo, int cmsDelay, float *ppctMovement) { - int pointerX, pointerY; - int currentX, currentY; - int lastX, lastY; - int deltaX, deltaY; - - /* set our defaults */ - if (ppctMovement == NULL) ppctMovement = rgpctMovementDefault; - if (cmsDelay < 0) cmsDelay = cmsDelayDefault; - - if (startX < 0 || startY < 0) - { - XGetGeometry(dpy, w, &JunkRoot, ¤tX, ¤tY, - &JunkWidth, &JunkHeight, &JunkBW, &JunkDepth); - if (startX < 0) startX = currentX; - if (startY < 0) startY = currentY; - } - - deltaX = endX - startX; - deltaY = endY - startY; - lastX = startX; - lastY = startY; - - if (deltaX == 0 && deltaY == 0) return; /* go nowhere fast */ - do { - currentX = startX + deltaX * (*ppctMovement); - currentY = startY + deltaY * (*ppctMovement); - XMoveWindow(dpy,w,currentX,currentY); - if (fWarpPointerToo == TRUE) { - XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, - &JunkX,&JunkY,&pointerX,&pointerY,&JunkMask); - pointerX += currentX - lastX; - pointerY += currentY - lastY; - XWarpPointer(dpy,None,Scr.Root,0,0,0,0, - pointerX,pointerY); - } - XFlush(dpy); - usleep(cmsDelay*1000); /* usleep takes microseconds */ + int pointerX, pointerY; + int currentX, currentY; + int lastX, lastY; + int deltaX, deltaY; + + /* set our defaults */ + if (ppctMovement == NULL) + ppctMovement = rgpctMovementDefault; + if (cmsDelay < 0) + cmsDelay = cmsDelayDefault; + + if (startX < 0 || startY < 0) { + XGetGeometry(dpy, w, &JunkRoot, ¤tX, ¤tY, + &JunkWidth, &JunkHeight, &JunkBW, &JunkDepth); + if (startX < 0) + startX = currentX; + if (startY < 0) + startY = currentY; + } + + deltaX = endX - startX; + deltaY = endY - startY; + lastX = startX; + lastY = startY; + + if (deltaX == 0 && deltaY == 0) + return; /* go nowhere fast */ + do { + currentX = startX + deltaX * (*ppctMovement); + currentY = startY + deltaY * (*ppctMovement); + XMoveWindow(dpy, w, currentX, currentY); + if (fWarpPointerToo == TRUE) { + XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, + &JunkX, &JunkY, &pointerX, &pointerY, &JunkMask); + pointerX += currentX - lastX; + pointerY += currentY - lastY; + XWarpPointer(dpy, None, Scr.Root, 0, 0, 0, 0, pointerX, + pointerY); + } + XFlush(dpy); + usleep(cmsDelay * 1000); /* usleep takes microseconds */ #ifdef GJB_ALLOW_ABORTING_ANIMATED_MOVES - /* this didn't work for me -- maybe no longer necessary since - we warn the user when they use > .5 seconds as a between-frame delay - time */ - if (XCheckMaskEvent(dpy, - ButtonPressMask|ButtonReleaseMask|KeyPressMask, - &Event)) { - /* finish the move immediately */ - XMoveWindow(dpy,w,endX,endY); - XFlush(dpy); - return; - } + /* this didn't work for me -- maybe no longer necessary since + we warn the user when they use > .5 seconds as a + between-frame delay time */ + if (XCheckMaskEvent(dpy, + ButtonPressMask | ButtonReleaseMask | KeyPressMask, + &Event)) { + /* finish the move immediately */ + XMoveWindow(dpy, w, endX, endY); + XFlush(dpy); + return; + } #endif - lastX = currentX; - lastY = currentY; - } - while (*ppctMovement != 1.0 && ppctMovement++); - + lastX = currentX; + lastY = currentY; + } while (*ppctMovement != 1.0 && ppctMovement++); } - /**************************************************************************** * * Start a window move operation * ****************************************************************************/ -void move_window_doit(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module, - Bool fAnimated, Bool fMoveToPage) +void +move_window_doit(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module, Bool fAnimated, + Bool fMoveToPage) { - int FinalX, FinalY; - int n; - int x,y; - int width, height; - int page[2]; - Bool fWarp = FALSE; - - if (DeferExecution(eventp,&w,&tmp_win,&context, MOVE,ButtonPress)) - return; - - if (tmp_win == NULL) - return; - - /* gotta have a window */ - w = tmp_win->frame; - if(tmp_win->flags & ICONIFIED) - { - if(tmp_win->icon_pixmap_w != None) - { - XUnmapWindow(dpy,tmp_win->icon_w); - w = tmp_win->icon_pixmap_w; + int FinalX, FinalY; + int n; + int x, y; + int width, height; + int page[2]; + Bool fWarp = FALSE; + + if (DeferExecution(eventp, &w, &tmp_win, &context, MOVE, ButtonPress)) + return; + + if (tmp_win == NULL) + return; + + /* gotta have a window */ + w = tmp_win->frame; + if (tmp_win->flags & ICONIFIED) { + if (tmp_win->icon_pixmap_w != None) { + XUnmapWindow(dpy, tmp_win->icon_w); + w = tmp_win->icon_pixmap_w; + } else + w = tmp_win->icon_w; } - else - w = tmp_win->icon_w; - } - - XGetGeometry(dpy, w, &JunkRoot, &x, &y, - &width, &height, &JunkBW, &JunkDepth); - if (fMoveToPage) - { - fAnimated = FALSE; - FinalX = x % Scr.MyDisplayWidth; - FinalY = y % Scr.MyDisplayHeight; - if (GetIntegerArguments(action, NULL, page, 2) == 2) - { - if (page[0] < 0 || page[1] < 0 || - page[0]*Scr.MyDisplayWidth > Scr.VxMax || - page[1]*Scr.MyDisplayHeight > Scr.VyMax) - { - fvwm_msg(ERR, "move_window_doit", - "MoveToPage: invalid page number"); - return; - } - tmp_win->flags &= ~STICKY; - FinalX += page[0]*Scr.MyDisplayWidth - Scr.Vx; - FinalY += page[1]*Scr.MyDisplayHeight - Scr.Vy; - } - } - else - { - n = GetMoveArguments(action,x,y,width+tmp_win->bw,height+tmp_win->bw, - &FinalX,&FinalY,&fWarp); - if (n != 2) - InteractiveMove(&w,tmp_win,&FinalX,&FinalY,eventp); - } - - if (w == tmp_win->frame) - { - if (fAnimated) { - AnimatedMoveOfWindow(w,-1,-1,FinalX,FinalY,fWarp,-1,NULL); - } - SetupFrame (tmp_win, FinalX, FinalY, - tmp_win->frame_width, tmp_win->frame_height,FALSE); - if (fWarp & !fAnimated) - XWarpPointer(dpy, None, None, 0, 0, 0, 0, FinalX - x, FinalY - y); - } - else /* icon window */ - { - tmp_win->flags |= ICON_MOVED; - tmp_win->icon_x_loc = FinalX ; - tmp_win->icon_xl_loc = FinalX - - (tmp_win->icon_w_width - tmp_win->icon_p_width)/2; - tmp_win->icon_y_loc = FinalY; - BroadcastPacket(M_ICON_LOCATION, 7, - tmp_win->w, tmp_win->frame, - (unsigned long)tmp_win, - tmp_win->icon_x_loc, tmp_win->icon_y_loc, - tmp_win->icon_w_width, - tmp_win->icon_w_height + tmp_win->icon_p_height); - if (fAnimated) { - AnimatedMoveOfWindow(tmp_win->icon_w,-1,-1,tmp_win->icon_xl_loc, - FinalY+tmp_win->icon_p_height, fWarp,-1,NULL); - } else { - XMoveWindow(dpy,tmp_win->icon_w, tmp_win->icon_xl_loc, - FinalY+tmp_win->icon_p_height); - if (fWarp) - XWarpPointer(dpy, None, None, 0, 0, 0, 0, FinalX - x, FinalY - y); - } - if(tmp_win->icon_pixmap_w != None) - { - XMapWindow(dpy,tmp_win->icon_w); - if (fAnimated) { - AnimatedMoveOfWindow(tmp_win->icon_pixmap_w, -1,-1, - tmp_win->icon_x_loc,FinalY,fWarp,-1,NULL); - } else { - XMoveWindow(dpy, tmp_win->icon_pixmap_w, tmp_win->icon_x_loc, - FinalY); - if (fWarp) - XWarpPointer(dpy, None, None, 0, 0, 0, 0, FinalX - x, - FinalY - y); - } - XMapWindow(dpy,w); + + XGetGeometry( + dpy, w, &JunkRoot, &x, &y, &width, &height, &JunkBW, &JunkDepth); + if (fMoveToPage) { + fAnimated = FALSE; + FinalX = x % Scr.MyDisplayWidth; + FinalY = y % Scr.MyDisplayHeight; + if (GetIntegerArguments(action, NULL, page, 2) == 2) { + if (page[0] < 0 || page[1] < 0 || + page[0] * Scr.MyDisplayWidth > Scr.VxMax || + page[1] * Scr.MyDisplayHeight > Scr.VyMax) { + fvwm_msg(ERR, "move_window_doit", + "MoveToPage: invalid page number"); + return; + } + tmp_win->flags &= ~STICKY; + FinalX += page[0] * Scr.MyDisplayWidth - Scr.Vx; + FinalY += page[1] * Scr.MyDisplayHeight - Scr.Vy; + } + } else { + n = GetMoveArguments(action, x, y, width + tmp_win->bw, + height + tmp_win->bw, &FinalX, &FinalY, &fWarp); + if (n != 2) + InteractiveMove(&w, tmp_win, &FinalX, &FinalY, eventp); } - } + if (w == tmp_win->frame) { + if (fAnimated) { + AnimatedMoveOfWindow( + w, -1, -1, FinalX, FinalY, fWarp, -1, NULL); + } + SetupFrame(tmp_win, FinalX, FinalY, tmp_win->frame_width, + tmp_win->frame_height, FALSE); + if (fWarp & !fAnimated) + XWarpPointer(dpy, None, None, 0, 0, 0, 0, FinalX - x, + FinalY - y); + } else /* icon window */ { + tmp_win->flags |= ICON_MOVED; + tmp_win->icon_x_loc = FinalX; + tmp_win->icon_xl_loc = + FinalX - + (tmp_win->icon_w_width - tmp_win->icon_p_width) / 2; + tmp_win->icon_y_loc = FinalY; + BroadcastPacket(M_ICON_LOCATION, 7, tmp_win->w, tmp_win->frame, + (unsigned long)tmp_win, tmp_win->icon_x_loc, + tmp_win->icon_y_loc, tmp_win->icon_w_width, + tmp_win->icon_w_height + tmp_win->icon_p_height); + if (fAnimated) { + AnimatedMoveOfWindow(tmp_win->icon_w, -1, -1, + tmp_win->icon_xl_loc, + FinalY + tmp_win->icon_p_height, fWarp, -1, NULL); + } else { + XMoveWindow(dpy, tmp_win->icon_w, tmp_win->icon_xl_loc, + FinalY + tmp_win->icon_p_height); + if (fWarp) + XWarpPointer(dpy, None, None, 0, 0, 0, 0, + FinalX - x, FinalY - y); + } + if (tmp_win->icon_pixmap_w != None) { + XMapWindow(dpy, tmp_win->icon_w); + if (fAnimated) { + AnimatedMoveOfWindow(tmp_win->icon_pixmap_w, -1, + -1, tmp_win->icon_x_loc, FinalY, fWarp, -1, + NULL); + } else { + XMoveWindow(dpy, tmp_win->icon_pixmap_w, + tmp_win->icon_x_loc, FinalY); + if (fWarp) + XWarpPointer(dpy, None, None, 0, 0, 0, + 0, FinalX - x, FinalY - y); + } + XMapWindow(dpy, w); + } + } - return; + return; } -void move_window(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +move_window(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - move_window_doit(eventp,w,tmp_win,context,action,Module,FALSE,FALSE); + move_window_doit( + eventp, w, tmp_win, context, action, Module, FALSE, FALSE); } -void animated_move_window(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +animated_move_window(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - move_window_doit(eventp,w,tmp_win,context,action,Module,TRUE,FALSE); + move_window_doit( + eventp, w, tmp_win, context, action, Module, TRUE, FALSE); } -void move_window_to_page(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +move_window_to_page(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - move_window_doit(eventp,w,tmp_win,context,action,Module,FALSE,TRUE); + move_window_doit( + eventp, w, tmp_win, context, action, Module, FALSE, TRUE); } -typedef struct _FvwmMoveable -{ - int w; - int h; - int x; - int y; +typedef struct _FvwmMoveable { + int w; + int h; + int x; + int y; } FvwmMoveable; /* This function does the SnapAttraction stuff. If takes x and y coordinates * (*px and *py) and returns the snapped values. */ -static void DoSnapAttract(FvwmWindow *tmp_win, int Width, int Height, - int *px, int *py) +static void +DoSnapAttract(FvwmWindow *tmp_win, int Width, int Height, int *px, int *py) { - int nyt,nxl,dist,closestLeft,closestRight,closestBottom,closestTop; - FvwmMoveable self, other; - FvwmWindow *tmp; - - /* START OF SNAPATTRACTION BLOCK, mirrored in ButtonRelease */ - /* resist based on window edges */ - tmp = Scr.FvwmRoot.next; - closestTop = Scr.SnapAttraction; - closestBottom = Scr.SnapAttraction; - closestRight = Scr.SnapAttraction; - closestLeft = Scr.SnapAttraction; - nxl = -1; - nyt = -1; - self.x = *px; - self.y = *py; - if(tmp_win->flags&ICONIFIED) - { - self.w = Width; - self.h = Height; - } - else - { - self.w = Width + 2 * tmp_win->bw; - self.h = Height + 2 * tmp_win->bw; - } - while(Scr.SnapAttraction >= 0 && tmp) - { - if(Scr.SnapMode == 0) /* All */ - { - /* NOOP */ + int nyt, nxl, dist, closestLeft, closestRight, closestBottom, + closestTop; + FvwmMoveable self, other; + FvwmWindow *tmp; + + /* START OF SNAPATTRACTION BLOCK, mirrored in ButtonRelease */ + /* resist based on window edges */ + tmp = Scr.FvwmRoot.next; + closestTop = Scr.SnapAttraction; + closestBottom = Scr.SnapAttraction; + closestRight = Scr.SnapAttraction; + closestLeft = Scr.SnapAttraction; + nxl = -1; + nyt = -1; + self.x = *px; + self.y = *py; + if (tmp_win->flags & ICONIFIED) { + self.w = Width; + self.h = Height; + } else { + self.w = Width + 2 * tmp_win->bw; + self.h = Height + 2 * tmp_win->bw; } - if(Scr.SnapMode == 1) /* SameType */ - { - if( (tmp->flags&ICONIFIED) != (tmp_win->flags&ICONIFIED) ) - { tmp = tmp->next; continue; } - } - if(Scr.SnapMode == 2) /* Icons */ - { - if( !(tmp->flags&ICONIFIED) || !(tmp_win->flags&ICONIFIED) ) - { tmp = tmp->next; continue; } - } - if(Scr.SnapMode == 3) /* Windows */ - { - if( (tmp->flags&ICONIFIED) || (tmp_win->flags&ICONIFIED) ) - { tmp = tmp->next; continue; } - } - if (tmp_win != tmp && (tmp_win->Desk == tmp->Desk)) - { - if(tmp->flags&ICONIFIED) - { - if(tmp->icon_p_height > 0) - { - other.w = tmp->icon_p_width; - other.h = tmp->icon_p_height; - } - else - { - other.w = tmp->icon_w_width; - other.h = tmp->icon_w_height; + while (Scr.SnapAttraction >= 0 && tmp) { + if (Scr.SnapMode == 0) { /* All */ + /* NOOP */ } - other.x = tmp->icon_x_loc; - other.y = tmp->icon_y_loc; - } - else - { - other.w = tmp->frame_width + 2 * tmp->bw; - other.h = tmp->frame_height + 2 * tmp->bw; - other.x = tmp->frame_x; - other.y = tmp->frame_y; - } - if(!((other.y + other.h) < (*py) || - (other.y) > (*py + self.h) )) - { - dist = abs(other.x - (*px + self.w)); - if(dist < closestRight) - { - closestRight = dist; - if(((*px + self.w) >= other.x)&& - ((*px + self.w) < other.x+Scr.SnapAttraction)) - nxl = other.x - self.w; - - if(((*px + self.w) >= other.x - Scr.SnapAttraction)&& - ((*px + self.w) < other.x)) - nxl = other.x - self.w; + if (Scr.SnapMode == 1) { /* SameType */ + if ((tmp->flags & ICONIFIED) != + (tmp_win->flags & ICONIFIED)) { + tmp = tmp->next; + continue; + } } - dist = abs(other.x + other.w - *px); - if(dist < closestLeft) - { - closestLeft = dist; - if((*px <= other.x + other.w)&& - (*px > other.x + other.w - Scr.SnapAttraction)) - nxl = other.x + other.w; - if((*px <= other.x + other.w + Scr.SnapAttraction)&& - (*px > other.x + other.w)) - nxl = other.x + other.w; + if (Scr.SnapMode == 2) { /* Icons */ + if (!(tmp->flags & ICONIFIED) || + !(tmp_win->flags & ICONIFIED)) { + tmp = tmp->next; + continue; + } } - } - if(!((other.x + other.w) < (*px) || (other.x) > (*px + self.w) )) - { - dist = abs(other.y - (*py + self.h)); - if(dist < closestBottom) - { - closestBottom = dist; - if(((*py + self.h) >= other.y)&& - ((*py + self.h) < other.y+Scr.SnapAttraction)) - nyt = other.y - self.h; - if(((*py + self.h) >= other.y - Scr.SnapAttraction)&& - ((*py + self.h) < other.y)) - nyt = other.y - self.h; + if (Scr.SnapMode == 3) { /* Windows */ + if ((tmp->flags & ICONIFIED) || + (tmp_win->flags & ICONIFIED)) { + tmp = tmp->next; + continue; + } } - dist = abs(other.y + other.h - *py); - if(dist < closestTop) - { - closestTop = dist; - if((*py <= other.y + other.h)&& - (*py > other.y + other.h - Scr.SnapAttraction)) - nyt = other.y + other.h; - if((*py <= other.y + other.h + Scr.SnapAttraction)&& - (*py > other.y + other.h)) - nyt = other.y + other.h; + if (tmp_win != tmp && (tmp_win->Desk == tmp->Desk)) { + if (tmp->flags & ICONIFIED) { + if (tmp->icon_p_height > 0) { + other.w = tmp->icon_p_width; + other.h = tmp->icon_p_height; + } else { + other.w = tmp->icon_w_width; + other.h = tmp->icon_w_height; + } + other.x = tmp->icon_x_loc; + other.y = tmp->icon_y_loc; + } else { + other.w = tmp->frame_width + 2 * tmp->bw; + other.h = tmp->frame_height + 2 * tmp->bw; + other.x = tmp->frame_x; + other.y = tmp->frame_y; + } + if (!((other.y + other.h) < (*py) || + (other.y) > (*py + self.h))) { + dist = abs(other.x - (*px + self.w)); + if (dist < closestRight) { + closestRight = dist; + if (((*px + self.w) >= other.x) && + ((*px + self.w) < + other.x + Scr.SnapAttraction)) + nxl = other.x - self.w; + + if (((*px + self.w) >= + other.x - Scr.SnapAttraction) && + ((*px + self.w) < other.x)) + nxl = other.x - self.w; + } + dist = abs(other.x + other.w - *px); + if (dist < closestLeft) { + closestLeft = dist; + if ((*px <= other.x + other.w) && + (*px > other.x + other.w - + Scr.SnapAttraction)) + nxl = other.x + other.w; + if ((*px <= other.x + other.w + + Scr.SnapAttraction) && + (*px > other.x + other.w)) + nxl = other.x + other.w; + } + } + if (!((other.x + other.w) < (*px) || + (other.x) > (*px + self.w))) { + dist = abs(other.y - (*py + self.h)); + if (dist < closestBottom) { + closestBottom = dist; + if (((*py + self.h) >= other.y) && + ((*py + self.h) < + other.y + Scr.SnapAttraction)) + nyt = other.y - self.h; + if (((*py + self.h) >= + other.y - Scr.SnapAttraction) && + ((*py + self.h) < other.y)) + nyt = other.y - self.h; + } + dist = abs(other.y + other.h - *py); + if (dist < closestTop) { + closestTop = dist; + if ((*py <= other.y + other.h) && + (*py > other.y + other.h - + Scr.SnapAttraction)) + nyt = other.y + other.h; + if ((*py <= other.y + other.h + + Scr.SnapAttraction) && + (*py > other.y + other.h)) + nyt = other.y + other.h; + } + } } - } + tmp = tmp->next; } - tmp = tmp->next; - } - if(nxl == -1) - { - if(*px != *px / Scr.SnapGridX * Scr.SnapGridX) - { - *px = (*px+Scr.SnapGridX/2) / Scr.SnapGridX * Scr.SnapGridX; + if (nxl == -1) { + if (*px != *px / Scr.SnapGridX * Scr.SnapGridX) { + *px = (*px + Scr.SnapGridX / 2) / Scr.SnapGridX * + Scr.SnapGridX; + } + } else { + *px = nxl; } - } - else - { - *px = nxl; - } - if(nyt == -1) - { - if(*py != *py / Scr.SnapGridY * Scr.SnapGridY) - { - *py = (*py+Scr.SnapGridY/2) / Scr.SnapGridY * Scr.SnapGridY; + if (nyt == -1) { + if (*py != *py / Scr.SnapGridY * Scr.SnapGridY) { + *py = (*py + Scr.SnapGridY / 2) / Scr.SnapGridY * + Scr.SnapGridY; + } + } else { + *py = nyt; } - } - else - { - *py = nyt; - } - /* END OF SNAPATTRACTION BLOCK, mirrored in ButtonRelease */ + /* END OF SNAPATTRACTION BLOCK, mirrored in ButtonRelease */ +} + +static void +ClampToScreen(int *x, int *y, int width, int height, int bw) +{ + int margin = 32; + + if (*x + width < margin) + *x = margin - width + 1; + if (*x > Scr.MyDisplayWidth - margin) + *x = Scr.MyDisplayWidth - margin; + if (*y + height < margin) + *y = margin - height + 1; + if (*y > Scr.MyDisplayHeight - margin) + *y = Scr.MyDisplayHeight - margin; } /**************************************************************************** @@ -408,218 +413,251 @@ static void DoSnapAttract(FvwmWindow *tmp_win, int Width, int Height, * Move the rubberband around, return with the new window location * ****************************************************************************/ -void moveLoop(FvwmWindow *tmp_win, int XOffset, int YOffset, int Width, - int Height, int *FinalX, int *FinalY,Bool opaque_move, - Bool AddWindow) +void +moveLoop(FvwmWindow *tmp_win, int XOffset, int YOffset, int Width, int Height, + int *FinalX, int *FinalY, Bool opaque_move, Bool AddWindow) { - Bool finished = False; - Bool done; - int xl,yt,delta_x,delta_y,paged; - unsigned int button_mask = 0; - unsigned int bw = tmp_win->bw; - - XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild,&xl, &yt, - &JunkX, &JunkY, &button_mask); - button_mask &= Button1Mask|Button2Mask|Button3Mask|Button4Mask|Button5Mask; - xl += XOffset; - yt += YOffset; - - if(((!opaque_move)&&(!Scr.gs.EmulateMWM))||(AddWindow)) - MoveOutline(Scr.Root, xl, yt, Width - 1 + 2 * bw, Height - 1 + 2 * bw); - - DisplayPosition(tmp_win,xl,yt,True); - - while (!finished) - { - /* block until there is an interesting event */ - XMaskEvent(dpy, ButtonPressMask | ButtonReleaseMask | KeyPressMask | - PointerMotionMask | ButtonMotionMask | ExposureMask, &Event); - StashEventTime(&Event); - - /* discard any extra motion events before a logical release */ - if (Event.type == MotionNotify) - { - while(XCheckMaskEvent(dpy, PointerMotionMask | ButtonMotionMask | - ButtonPressMask |ButtonRelease, &Event)) - { - StashEventTime(&Event); - if(Event.type == ButtonRelease) break; - } - } - - done = FALSE; - /* Handle a limited number of key press events to allow mouseless - * operation */ - if (Event.type == KeyPress) - Keyboard_shortcuts(&Event, tmp_win, ButtonRelease); - switch(Event.type) - { - case KeyPress: - /* simple code to bag out of move - CKH */ - if (XLookupKeysym(&(Event.xkey),0) == XK_Escape) - { - if(!opaque_move) - MoveOutline(Scr.Root, 0, 0, 0, 0); - *FinalX = tmp_win->frame_x; - *FinalY = tmp_win->frame_y; - finished = TRUE; - } - done = TRUE; - break; - case ButtonPress: - XAllowEvents(dpy,ReplayPointer,CurrentTime); - if (((Event.xbutton.button == 1) && (button_mask & Button1Mask)) || - ((Event.xbutton.button == 2) && (button_mask & Button2Mask)) || - ((Event.xbutton.button == 3) && (button_mask & Button3Mask)) || - ((Event.xbutton.button == 4) && (button_mask & Button4Mask)) || - ((Event.xbutton.button == 5) && (button_mask & Button5Mask))) - { - /* No new button was pressed, just a delayed event */ - done = 1; - break; - } - if(((Event.xbutton.button == 2)&&(!Scr.gs.EmulateMWM))|| - ((Event.xbutton.button == 1)&&(Scr.gs.EmulateMWM)&& - (Event.xbutton.state & ShiftMask))) - { - NeedToResizeToo = True; - /* Fallthrough to button-release */ - } - else - { - /* Abort the move if - * - the move started with a pressed button and another button - * was pressed during the operation - * - no button was started at the beginning and any button - * except button 1 was pressed. */ - if (button_mask || (Event.xbutton.button != 1)) - { - if(!opaque_move) - MoveOutline(Scr.Root, 0, 0, 0, 0); - *FinalX = tmp_win->frame_x; - *FinalY = tmp_win->frame_y; - finished = TRUE; + Bool finished = False; + Bool done; + int xl, yt, delta_x, delta_y, paged; + unsigned int button_mask = 0; + unsigned int bw = tmp_win->bw; + + XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, &xl, &yt, &JunkX, + &JunkY, &button_mask); + button_mask &= + Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask; + xl += XOffset; + yt += YOffset; + + if (((!opaque_move) && (!Scr.gs.EmulateMWM)) || (AddWindow)) + MoveOutline( + Scr.Root, xl, yt, Width - 1 + 2 * bw, Height - 1 + 2 * bw); + + DisplayPosition(tmp_win, xl, yt, True); + + while (!finished) { + /* block until there is an interesting event */ + XMaskEvent(dpy, + ButtonPressMask | ButtonReleaseMask | KeyPressMask | + PointerMotionMask | ButtonMotionMask | ExposureMask, + &Event); + StashEventTime(&Event); + + /* discard any extra motion events before a logical release */ + if (Event.type == MotionNotify) { + while (XCheckMaskEvent(dpy, + PointerMotionMask | ButtonMotionMask | + ButtonPressMask | ButtonRelease, + &Event)) { + StashEventTime(&Event); + if (Event.type == ButtonRelease) + break; + } } - done = 1; - break; - } - case ButtonRelease: - if(!opaque_move) - MoveOutline(Scr.Root, 0, 0, 0, 0); - xl = Event.xmotion.x_root + XOffset; - yt = Event.xmotion.y_root + YOffset; - - DoSnapAttract(tmp_win, Width, Height, &xl, &yt); - - /* Resist moving windows over the edge of the screen! */ - if(((xl + Width) >= Scr.MyDisplayWidth)&& - ((xl + Width) < Scr.MyDisplayWidth+Scr.MoveResistance)) - xl = Scr.MyDisplayWidth - Width - 2 * bw; - if((xl <= 0)&&(xl > -Scr.MoveResistance)) - xl = 0; - if(((yt + Height) >= Scr.MyDisplayHeight)&& - ((yt + Height) < Scr.MyDisplayHeight+Scr.MoveResistance)) - yt = Scr.MyDisplayHeight - Height - 2 * bw; - if((yt <= 0)&&(yt > -Scr.MoveResistance)) - yt = 0; - - *FinalX = xl; - *FinalY = yt; - - done = TRUE; - finished = TRUE; - break; - - case MotionNotify: - xl = Event.xmotion.x_root; - yt = Event.xmotion.y_root; -/* HandlePaging(Scr.MyDisplayWidth,Scr.MyDisplayHeight,&xl,&yt, - &delta_x,&delta_y,False); mab */ - /* redraw the rubberband */ - xl += XOffset; - yt += YOffset; - - DoSnapAttract(tmp_win, Width, Height, &xl, &yt); - - /* Resist moving windows over the edge of the screen! */ - if(((xl + Width) >= Scr.MyDisplayWidth)&& - ((xl + Width) < Scr.MyDisplayWidth+Scr.MoveResistance)) - xl = Scr.MyDisplayWidth - Width - 2 * bw; - if((xl <= 0)&&(xl > -Scr.MoveResistance)) - xl = 0; - if(((yt + Height) >= Scr.MyDisplayHeight)&& - ((yt + Height) < Scr.MyDisplayHeight+Scr.MoveResistance)) - yt = Scr.MyDisplayHeight - Height - 2 * bw; - if((yt <= 0)&&(yt > -Scr.MoveResistance)) - yt = 0; - - /* check Paging request once and only once after outline redrawn */ - /* redraw after paging if needed - mab */ - paged=0; - while(paged<=1) - { - if(!opaque_move) - MoveOutline(Scr.Root, xl, yt, Width - 1 + 2 * bw, Height - 1 + 2 * bw); - else - { - if (tmp_win->flags & ICONIFIED) - { - tmp_win->icon_x_loc = xl ; - tmp_win->icon_xl_loc = xl - - (tmp_win->icon_w_width - tmp_win->icon_p_width)/2; - tmp_win->icon_y_loc = yt; - if(tmp_win->icon_pixmap_w != None) - XMoveWindow (dpy, tmp_win->icon_pixmap_w, - tmp_win->icon_x_loc,yt); - else if (tmp_win->icon_w != None) - XMoveWindow(dpy, tmp_win->icon_w,tmp_win->icon_xl_loc, - yt+tmp_win->icon_p_height); - - } - else - XMoveWindow(dpy,tmp_win->frame,xl,yt); - } - DisplayPosition(tmp_win,xl,yt,False); - - /* prevent window from lagging behind mouse when paging - mab */ - if(paged==0) - { - int dx; - int dy; - - xl = Event.xmotion.x_root; - yt = Event.xmotion.y_root; - dx = Scr.EdgeScrollX ? Scr.EdgeScrollX : Scr.MyDisplayWidth; - dy = Scr.EdgeScrollY ? Scr.EdgeScrollY : Scr.MyDisplayHeight; - HandlePaging(dx, dy, &xl,&yt, &delta_x,&delta_y,False); - xl += XOffset; - yt += YOffset; - if ( (delta_x==0) && (delta_y==0)) - /* break from while paged */ - break; - } - paged++; - } /* end while paged */ - done = TRUE; - break; - - default: - break; - } /* switch */ - if(!done) - { - if(!opaque_move) - MoveOutline(Scr.Root,0,0,0,0); - DispatchEvent(); - if(!opaque_move) - MoveOutline(Scr.Root, xl, yt, Width - 1 + 2 * bw, Height - 1 + 2 * bw); + done = FALSE; + /* Handle a limited number of key press events to allow + * mouseless operation */ + if (Event.type == KeyPress) + Keyboard_shortcuts(&Event, tmp_win, ButtonRelease); + switch (Event.type) { + case KeyPress: + /* simple code to bag out of move - CKH */ + if (XLookupKeysym(&(Event.xkey), 0) == XK_Escape) { + if (!opaque_move) + MoveOutline(Scr.Root, 0, 0, 0, 0); + *FinalX = tmp_win->frame_x; + *FinalY = tmp_win->frame_y; + ClampToScreen(FinalX, FinalY, + Width, Height, bw); + finished = TRUE; + } + done = TRUE; + break; + case ButtonPress: + XAllowEvents(dpy, ReplayPointer, CurrentTime); + if (((Event.xbutton.button == 1) && + (button_mask & Button1Mask)) || + ((Event.xbutton.button == 2) && + (button_mask & Button2Mask)) || + ((Event.xbutton.button == 3) && + (button_mask & Button3Mask)) || + ((Event.xbutton.button == 4) && + (button_mask & Button4Mask)) || + ((Event.xbutton.button == 5) && + (button_mask & Button5Mask))) { + /* No new button was pressed, just a delayed + * event */ + done = 1; + break; + } + if (((Event.xbutton.button == 2) && + (!Scr.gs.EmulateMWM)) || + ((Event.xbutton.button == 1) && + (Scr.gs.EmulateMWM) && + (Event.xbutton.state & ShiftMask))) { + NeedToResizeToo = True; + /* Fallthrough to button-release */ + } else { + /* Abort the move if + * - the move started with a pressed button and + * another button was pressed during the + * operation + * - no button was started at the beginning and + * any button except button 1 was pressed. */ + if (button_mask || + (Event.xbutton.button != 1)) { + if (!opaque_move) + MoveOutline( + Scr.Root, 0, 0, 0, 0); + *FinalX = tmp_win->frame_x; + *FinalY = tmp_win->frame_y; + ClampToScreen(FinalX, FinalY, + Width, Height, bw); + finished = TRUE; + } + done = 1; + break; + } + case ButtonRelease: + if (!opaque_move) + MoveOutline(Scr.Root, 0, 0, 0, 0); + xl = Event.xmotion.x_root + XOffset; + yt = Event.xmotion.y_root + YOffset; + + DoSnapAttract(tmp_win, Width, Height, &xl, &yt); + + /* Resist moving windows over the edge of the screen! */ + if (((xl + Width) >= Scr.MyDisplayWidth) && + ((xl + Width) < + Scr.MyDisplayWidth + Scr.MoveResistance)) + xl = Scr.MyDisplayWidth - Width - 2 * bw; + if ((xl <= 0) && (xl > -Scr.MoveResistance)) + xl = 0; + if (((yt + Height) >= Scr.MyDisplayHeight) && + ((yt + Height) < + Scr.MyDisplayHeight + Scr.MoveResistance)) + yt = Scr.MyDisplayHeight - Height - 2 * bw; + if ((yt <= 0) && (yt > -Scr.MoveResistance)) + yt = 0; + + *FinalX = xl; + *FinalY = yt; + + done = TRUE; + finished = TRUE; + break; + + case MotionNotify: + xl = Event.xmotion.x_root; + yt = Event.xmotion.y_root; + /* HandlePaging(Scr.MyDisplayWidth,Scr.MyDisplayHeight,&xl,&yt, + &delta_x,&delta_y,False); mab */ + /* redraw the rubberband */ + xl += XOffset; + yt += YOffset; + + DoSnapAttract(tmp_win, Width, Height, &xl, &yt); + + /* Resist moving windows over the edge of the screen! */ + if (((xl + Width) >= Scr.MyDisplayWidth) && + ((xl + Width) < + Scr.MyDisplayWidth + Scr.MoveResistance)) + xl = Scr.MyDisplayWidth - Width - 2 * bw; + if ((xl <= 0) && (xl > -Scr.MoveResistance)) + xl = 0; + if (((yt + Height) >= Scr.MyDisplayHeight) && + ((yt + Height) < + Scr.MyDisplayHeight + Scr.MoveResistance)) + yt = Scr.MyDisplayHeight - Height - 2 * bw; + if ((yt <= 0) && (yt > -Scr.MoveResistance)) + yt = 0; + + /* check Paging request once and only once after outline + * redrawn */ + /* redraw after paging if needed - mab */ + paged = 0; + while (paged <= 1) { + if (!opaque_move) + MoveOutline(Scr.Root, xl, yt, + Width - 1 + 2 * bw, + Height - 1 + 2 * bw); + else { + if (tmp_win->flags & ICONIFIED) { + tmp_win->icon_x_loc = xl; + tmp_win->icon_xl_loc = + xl - + (tmp_win->icon_w_width - + tmp_win->icon_p_width) / + 2; + tmp_win->icon_y_loc = yt; + if (tmp_win->icon_pixmap_w != + None) + XMoveWindow(dpy, + tmp_win + ->icon_pixmap_w, + tmp_win->icon_x_loc, + yt); + else if (tmp_win->icon_w != + None) + XMoveWindow(dpy, + tmp_win->icon_w, + tmp_win + ->icon_xl_loc, + yt + + tmp_win + ->icon_p_height); + } else + XMoveWindow(dpy, tmp_win->frame, + xl, yt); + } + DisplayPosition(tmp_win, xl, yt, False); + + /* prevent window from lagging behind mouse when + * paging - mab */ + if (paged == 0) { + int dx; + int dy; + + xl = Event.xmotion.x_root; + yt = Event.xmotion.y_root; + dx = Scr.EdgeScrollX ? + Scr.EdgeScrollX : + Scr.MyDisplayWidth; + dy = Scr.EdgeScrollY ? + Scr.EdgeScrollY : + Scr.MyDisplayHeight; + HandlePaging(dx, dy, &xl, &yt, &delta_x, + &delta_y, False); + xl += XOffset; + yt += YOffset; + if ((delta_x == 0) && (delta_y == 0)) + /* break from while paged */ + break; + } + paged++; + } /* end while paged */ + + done = TRUE; + break; + + default: + break; + } /* switch */ + if (!done) { + if (!opaque_move) + MoveOutline(Scr.Root, 0, 0, 0, 0); + DispatchEvent(); + if (!opaque_move) + MoveOutline(Scr.Root, xl, yt, + Width - 1 + 2 * bw, Height - 1 + 2 * bw); + } } - } - if (!NeedToResizeToo) - /* Don't wait for buttons to come up when user is placing a new window - * and wants to resize it. */ - WaitForButtonsUp(); + if (!NeedToResizeToo) + /* Don't wait for buttons to come up when user is placing a new + * window and wants to resize it. */ + WaitForButtonsUp(); } /*********************************************************************** @@ -633,37 +671,31 @@ void moveLoop(FvwmWindow *tmp_win, int XOffset, int YOffset, int Width, * ************************************************************************/ -void DisplayPosition (FvwmWindow *tmp_win, int x, int y,int Init) +void +DisplayPosition(FvwmWindow *tmp_win, int x, int y, int Init) { - char str [100]; - int offset; - - (void) snprintf (str, sizeof(str), " %+-4d %+-4d ", x, y); - if(Init) - { - XClearWindow(dpy,Scr.SizeWindow); - if(Scr.d_depth >= 2) - RelieveWindow(tmp_win,Scr.SizeWindow,0,0, - Scr.SizeStringWidth+ SIZE_HINDENT*2, - Scr.StdFont.height + SIZE_VINDENT*2, - Scr.StdReliefGC, - Scr.StdShadowGC, FULL_HILITE); - - } - else - { - XClearArea(dpy,Scr.SizeWindow,SIZE_HINDENT,SIZE_VINDENT, - Scr.SizeStringWidth, Scr.StdFont.height,False); - } - - offset = (Scr.SizeStringWidth + SIZE_HINDENT*2 - - XTextWidth(Scr.StdFont.font,str,strlen(str)))/2; - XDrawString (dpy, Scr.SizeWindow, Scr.StdGC, - offset, - Scr.StdFont.font->ascent + SIZE_VINDENT, - str, strlen(str)); -} + char str[100]; + int offset; + + (void)snprintf(str, sizeof(str), " %+-4d %+-4d ", x, y); + if (Init) { + XClearWindow(dpy, Scr.SizeWindow); + if (Scr.d_depth >= 2) + RelieveWindow(tmp_win, Scr.SizeWindow, 0, 0, + Scr.SizeStringWidth + SIZE_HINDENT * 2, + Scr.StdFont.height + SIZE_VINDENT * 2, + Scr.StdReliefGC, Scr.StdShadowGC, FULL_HILITE); + } else { + XClearArea(dpy, Scr.SizeWindow, SIZE_HINDENT, SIZE_VINDENT, + Scr.SizeStringWidth, Scr.StdFont.height, False); + } + offset = (Scr.SizeStringWidth + SIZE_HINDENT * 2 - + XTextWidth(Scr.StdFont.font, str, strlen(str))) / + 2; + XDrawString(dpy, Scr.SizeWindow, Scr.StdGC, offset, + Scr.StdFont.font->ascent + SIZE_VINDENT, str, strlen(str)); +} /**************************************************************************** * @@ -671,164 +703,162 @@ void DisplayPosition (FvwmWindow *tmp_win, int x, int y,int Init) * shortcuts by warping the pointer. * ****************************************************************************/ -void Keyboard_shortcuts(XEvent *Event, FvwmWindow *w, int ReturnEvent) +void +Keyboard_shortcuts(XEvent *Event, FvwmWindow *w, int ReturnEvent) { - int x,y,x_root,y_root; - int x_move_size = 0, y_move_size = 0; - int x_move,y_move; - - KeySym keysym; - - if (w) - { - x_move_size = w->hints.width_inc; - y_move_size = w->hints.height_inc; - } - if (y_move_size < 5) y_move_size = 5; - if (x_move_size < 5) x_move_size = 5; - if(Event->xkey.state & ControlMask) - x_move_size = y_move_size = 1; - if(Event->xkey.state & ShiftMask) - x_move_size = y_move_size = 100; - - keysym = XLookupKeysym(&Event->xkey,0); - - x_move = 0; - y_move = 0; - switch(keysym) - { - case XK_Up: - case XK_KP_8: - case XK_k: - case XK_p: - y_move = -y_move_size; - break; - case XK_Down: - case XK_KP_2: - case XK_n: - case XK_j: - y_move = y_move_size; - break; - case XK_Left: - case XK_KP_4: - case XK_b: - case XK_h: - x_move = -x_move_size; - break; - case XK_Right: - case XK_KP_6: - case XK_f: - case XK_l: - x_move = x_move_size; - break; - case XK_KP_1: - x_move = -x_move_size; - y_move = y_move_size; - break; - case XK_KP_3: - x_move = x_move_size; - y_move = y_move_size; - break; - case XK_KP_7: - x_move = -x_move_size; - y_move = -y_move_size; - break; - case XK_KP_9: - x_move = x_move_size; - y_move = -y_move_size; - break; - case XK_Return: - case XK_KP_Enter: - case XK_space: - /* beat up the event */ - Event->type = ReturnEvent; - break; - case XK_Escape: - /* simple code to bag out of move - CKH */ - /* return keypress event instead */ - Event->type = KeyPress; - Event->xkey.keycode = XKeysymToKeycode(Event->xkey.display,keysym); - break; - default: - break; - } - XQueryPointer( dpy, Scr.Root, &JunkRoot, &Event->xany.window, - &x_root, &y_root, &x, &y, &JunkMask); - - if((x_move != 0)||(y_move != 0)) - { - /* beat up the event */ - XWarpPointer(dpy, None, Scr.Root, 0, 0, 0, 0, x_root+x_move, - y_root+y_move); - - /* beat up the event */ - Event->type = MotionNotify; - Event->xkey.x += x_move; - Event->xkey.y += y_move; - Event->xkey.x_root += x_move; - Event->xkey.y_root += y_move; - } -} + int x, y, x_root, y_root; + int x_move_size = 0, y_move_size = 0; + int x_move, y_move; + + KeySym keysym; + if (w) { + x_move_size = w->hints.width_inc; + y_move_size = w->hints.height_inc; + } + if (y_move_size < 5) + y_move_size = 5; + if (x_move_size < 5) + x_move_size = 5; + if (Event->xkey.state & ControlMask) + x_move_size = y_move_size = 1; + if (Event->xkey.state & ShiftMask) + x_move_size = y_move_size = 100; + + keysym = XLookupKeysym(&Event->xkey, 0); + + x_move = 0; + y_move = 0; + switch (keysym) { + case XK_Up: + case XK_KP_8: + case XK_k: + case XK_p: + y_move = -y_move_size; + break; + case XK_Down: + case XK_KP_2: + case XK_n: + case XK_j: + y_move = y_move_size; + break; + case XK_Left: + case XK_KP_4: + case XK_b: + case XK_h: + x_move = -x_move_size; + break; + case XK_Right: + case XK_KP_6: + case XK_f: + case XK_l: + x_move = x_move_size; + break; + case XK_KP_1: + x_move = -x_move_size; + y_move = y_move_size; + break; + case XK_KP_3: + x_move = x_move_size; + y_move = y_move_size; + break; + case XK_KP_7: + x_move = -x_move_size; + y_move = -y_move_size; + break; + case XK_KP_9: + x_move = x_move_size; + y_move = -y_move_size; + break; + case XK_Return: + case XK_KP_Enter: + case XK_space: + /* beat up the event */ + Event->type = ReturnEvent; + break; + case XK_Escape: + /* simple code to bag out of move - CKH */ + /* return keypress event instead */ + Event->type = KeyPress; + Event->xkey.keycode = + XKeysymToKeycode(Event->xkey.display, keysym); + break; + default: + break; + } + XQueryPointer(dpy, Scr.Root, &JunkRoot, &Event->xany.window, &x_root, + &y_root, &x, &y, &JunkMask); + + if ((x_move != 0) || (y_move != 0)) { + /* beat up the event */ + XWarpPointer(dpy, None, Scr.Root, 0, 0, 0, 0, x_root + x_move, + y_root + y_move); + + /* beat up the event */ + Event->type = MotionNotify; + Event->xkey.x += x_move; + Event->xkey.y += y_move; + Event->xkey.x_root += x_move; + Event->xkey.y_root += y_move; + } +} -void InteractiveMove(Window *win, FvwmWindow *tmp_win, int *FinalX, int *FinalY, XEvent *eventp) +void +InteractiveMove( + Window *win, FvwmWindow *tmp_win, int *FinalX, int *FinalY, XEvent *eventp) { - int origDragX,origDragY,DragX, DragY, DragWidth, DragHeight; - int XOffset, YOffset; - Window w; - - Bool opaque_move = False; - - w = *win; - - InstallRootColormap(); - if (menuFromFrameOrWindowOrTitlebar) - { - /* warp the pointer to the cursor position from before menu appeared*/ - XFlush(dpy); - } - - /* Although a move is usually done with a button depressed we have to check - * for ButtonRelease too since the event may be faked. */ - if (eventp->type == ButtonPress || eventp->type == ButtonRelease) - { - DragX = eventp->xbutton.x_root; - DragY = eventp->xbutton.y_root; - } - else - XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, &DragX, &DragY, - &JunkX, &JunkY, &JunkMask); - - if(!GrabEm(MOVE)) - { - XBell(dpy, 0); - return; - } - - XGetGeometry(dpy, w, &JunkRoot, &origDragX, &origDragY, - (unsigned int *)&DragWidth, (unsigned int *)&DragHeight, - &JunkBW, &JunkDepth); - - if(DragWidth*DragHeight < - (Scr.OpaqueSize*Scr.MyDisplayWidth*Scr.MyDisplayHeight)/100) - opaque_move = True; - else - MyXGrabServer(dpy); - - if((!opaque_move)&&(tmp_win->flags & ICONIFIED)) - XUnmapWindow(dpy,w); - - XOffset = origDragX - DragX; - YOffset = origDragY - DragY; - XMapRaised(dpy,Scr.SizeWindow); - moveLoop(tmp_win, XOffset,YOffset,DragWidth,DragHeight, FinalX,FinalY, - opaque_move,False); - - XUnmapWindow(dpy,Scr.SizeWindow); - UninstallRootColormap(); - - if(!opaque_move) - MyXUngrabServer(dpy); - UngrabEm(); + int origDragX, origDragY, DragX, DragY, DragWidth, DragHeight; + int XOffset, YOffset; + Window w; + + Bool opaque_move = False; + + w = *win; + + InstallRootColormap(); + if (menuFromFrameOrWindowOrTitlebar) { + /* warp the pointer to the cursor position from before menu + * appeared*/ + XFlush(dpy); + } + + /* Although a move is usually done with a button depressed we have to + * check for ButtonRelease too since the event may be faked. */ + if (eventp->type == ButtonPress || eventp->type == ButtonRelease) { + DragX = eventp->xbutton.x_root; + DragY = eventp->xbutton.y_root; + } else + XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, &DragX, + &DragY, &JunkX, &JunkY, &JunkMask); + + if (!GrabEm(MOVE)) { + XBell(dpy, 0); + return; + } + + XGetGeometry(dpy, w, &JunkRoot, &origDragX, &origDragY, + (unsigned int *)&DragWidth, (unsigned int *)&DragHeight, &JunkBW, + &JunkDepth); + + if (DragWidth * DragHeight < + (Scr.OpaqueSize * Scr.MyDisplayWidth * Scr.MyDisplayHeight) / 100) + opaque_move = True; + else + MyXGrabServer(dpy); + + if ((!opaque_move) && (tmp_win->flags & ICONIFIED)) + XUnmapWindow(dpy, w); + + XOffset = origDragX - DragX; + YOffset = origDragY - DragY; + XMapRaised(dpy, Scr.SizeWindow); + moveLoop(tmp_win, XOffset, YOffset, DragWidth, DragHeight, FinalX, + FinalY, opaque_move, False); + + XUnmapWindow(dpy, Scr.SizeWindow); + UninstallRootColormap(); + if (!opaque_move) + MyXUngrabServer(dpy); + UngrabEm(); } Index: fvwm/fvwm/parse.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/parse.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/parse.h --- fvwm/fvwm/parse.h +++ fvwm/fvwm/parse.h @@ -18,113 +18,112 @@ #define _PARSE_ enum { - F_NOP = 0, - F_BEEP, - F_QUIT, - F_RESTART, - F_REFRESH, - F_TITLE, - F_SCROLL, - F_CIRCULATE_UP, - F_CIRCULATE_DOWN, - F_TOGGLE_PAGE, - F_GOTO_PAGE, - F_WINDOWLIST, - F_MOVECURSOR, - F_FUNCTION, - F_MODULE = 15, - F_DESK, - F_CHANGE_WINDOWS_DESK, - F_EXEC, - F_POPUP, - F_WAIT, - F_CLOSE, - F_SET_MASK, - F_ADDMENU, - F_ADDFUNC, - F_STYLE, - F_EDGE_SCROLL, - F_PIXMAP_PATH, - F_ICON_PATH, - F_MODULE_PATH, - F_HICOLOR, - F_SETDESK, - F_MOUSE, - F_KEY, - F_OPAQUE, - F_XOR, - F_CLICK, - F_MENUSTYLE, - F_ICONFONT, - F_WINDOWFONT, - F_EDGE_RES, - F_BUTTON_STYLE, - F_READ, - F_ADDMENU2, - F_DIRECTION, - F_NEXT, - F_PREV, - F_NONE, - F_STAYSUP, - F_RECAPTURE, - F_CONFIG_LIST, - F_DESTROY_MENU, - F_ZAP, - F_QUIT_SCREEN, - F_COLORMAP_FOCUS, - F_TITLESTYLE, - F_EXEC_SETUP, - F_CURSOR_STYLE, - F_CURRENT, - F_SETENV, - F_SET_ANIMATION, - F_CHANGE_MENUSTYLE, - F_DESTROY_MENUSTYLE, - F_SNAP_ATT, - F_SNAP_GRID, - F_DFLT_FONT, - F_DFLT_COLORS, - F_GLOBAL_OPTS, - F_EMULATE, + F_NOP = 0, + F_BEEP, + F_QUIT, + F_RESTART, + F_REFRESH, + F_TITLE, + F_SCROLL, + F_CIRCULATE_UP, + F_CIRCULATE_DOWN, + F_TOGGLE_PAGE, + F_GOTO_PAGE, + F_WINDOWLIST, + F_MOVECURSOR, + F_FUNCTION, + F_MODULE = 15, + F_DESK, + F_CHANGE_WINDOWS_DESK, + F_EXEC, + F_POPUP, + F_WAIT, + F_CLOSE, + F_SET_MASK, + F_ADDMENU, + F_ADDFUNC, + F_STYLE, + F_EDGE_SCROLL, + F_PIXMAP_PATH, + F_ICON_PATH, + F_MODULE_PATH, + F_HICOLOR, + F_SETDESK, + F_MOUSE, + F_KEY, + F_OPAQUE, + F_XOR, + F_CLICK, + F_MENUSTYLE, + F_ICONFONT, + F_WINDOWFONT, + F_EDGE_RES, + F_BUTTON_STYLE, + F_READ, + F_ADDMENU2, + F_DIRECTION, + F_NEXT, + F_PREV, + F_NONE, + F_STAYSUP, + F_RECAPTURE, + F_CONFIG_LIST, + F_DESTROY_MENU, + F_ZAP, + F_QUIT_SCREEN, + F_COLORMAP_FOCUS, + F_TITLESTYLE, + F_EXEC_SETUP, + F_CURSOR_STYLE, + F_CURRENT, + F_SETENV, + F_SET_ANIMATION, + F_CHANGE_MENUSTYLE, + F_DESTROY_MENUSTYLE, + F_SNAP_ATT, + F_SNAP_GRID, + F_DFLT_FONT, + F_DFLT_COLORS, + F_GLOBAL_OPTS, + F_EMULATE, - F_RESIZE = 100, - F_RAISE, - F_LOWER, - F_DESTROY, - F_DELETE, - F_MOVE, - F_MOVE_TO_PAGE, - F_ICONIFY, - F_STICK, - F_RAISELOWER, - F_MAXIMIZE, - F_FOCUS, - F_WARP, - F_SEND_STRING, - F_ADD_MOD, - F_DESTROY_MOD, - F_FLIP_FOCUS, - F_ECHO, - F_BORDERSTYLE, - F_WINDOWID, - F_ADD_BUTTON_STYLE, - F_ADD_TITLE_STYLE, - F_ADD_DECOR, - F_CHANGE_DECOR, - F_DESTROY_DECOR, - F_UPDATE_DECOR, - F_WINDOW_SHADE, - F_COLOR_LIMIT, - F_ANIMATED_MOVE, + F_RESIZE = 100, + F_RAISE, + F_LOWER, + F_DESTROY, + F_DELETE, + F_MOVE, + F_MOVE_TO_PAGE, + F_ICONIFY, + F_STICK, + F_RAISELOWER, + F_MAXIMIZE, + F_FOCUS, + F_WARP, + F_SEND_STRING, + F_ADD_MOD, + F_DESTROY_MOD, + F_FLIP_FOCUS, + F_ECHO, + F_BORDERSTYLE, + F_WINDOWID, + F_ADD_BUTTON_STYLE, + F_ADD_TITLE_STYLE, + F_ADD_DECOR, + F_CHANGE_DECOR, + F_DESTROY_DECOR, + F_UPDATE_DECOR, + F_WINDOW_SHADE, + F_COLOR_LIMIT, + F_ANIMATED_MOVE, - F_END_OF_LIST = 999, + F_END_OF_LIST = 999, -/* Functions for use by modules only! */ - F_SEND_WINDOW_LIST = 1000 + /* Functions for use by modules only! */ + F_SEND_WINDOW_LIST = 1000 -/* Functions for internal only! */ - /* F_RAISE_IT = 2000 */ + /* Functions for internal only! */ + /* F_RAISE_IT = 2000 */ }; #endif /* _PARSE_ */ - Index: fvwm/fvwm/placement.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/placement.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/placement.c --- fvwm/fvwm/placement.c +++ fvwm/fvwm/placement.c @@ -9,12 +9,11 @@ * warrantees of any sort whatsoever are given or implied or anything. ****************************************************************************/ -#include "config.h" - #include -#include #include +#include +#include "config.h" #include "fvwm.h" #include "menus.h" #include "misc.h" @@ -22,16 +21,17 @@ #include "screen.h" #ifndef MIN -#define MIN(A,B) ((A)<(B)? (A):(B)) +#define MIN(A, B) ((A) < (B) ? (A) : (B)) #endif #ifndef MAX -#define MAX(A,B) ((A)>(B)? (A):(B)) +#define MAX(A, B) ((A) > (B) ? (A) : (B)) #endif /* RBW - 11/02/1998 */ int get_next_x(FvwmWindow *t, int x, int y, int pdeltax, int pdeltay); int get_next_y(FvwmWindow *t, int y, int pdeltay); -int test_fit(FvwmWindow *t, int test_x, int test_y, int aoimin, int pdeltax, int pdeltay); +int test_fit(FvwmWindow *t, int test_x, int test_y, int aoimin, int pdeltax, + int pdeltay); void CleverPlacement(FvwmWindow *t, int *x, int *y, int pdeltax, int pdeltay); /**/ @@ -49,366 +49,354 @@ void CleverPlacement(FvwmWindow *t, int *x, int *y, int pdeltax, int pdeltay); #define AVOIDONTOP 5 #define AVOIDSTICKY 1 #ifdef NO_STUBBORN_PLACEMENT -#define AVOIDICON 0 /* Ignore Icons. Place windows over them */ +#define AVOIDICON 0 /* Ignore Icons. Place windows over them */ #else -#define AVOIDICON 10 /* Try hard no to place windows over icons */ +#define AVOIDICON 10 /* Try hard no to place windows over icons */ #endif /* RBW - 11/02/1998 */ -int SmartPlacement(FvwmWindow *t, - int width, - int height, - int *x, - int *y, - int pdeltax, - int pdeltay) +int +SmartPlacement(FvwmWindow *t, int width, int height, int *x, int *y, + int pdeltax, int pdeltay) { - int PageBottom = Scr.MyDisplayHeight - pdeltay; - int PageRight = Scr.MyDisplayWidth - pdeltax; - int PageTop = 0 - pdeltay; - int PageLeft = 0 - pdeltax; - int rc = True; -/**/ - int temp_h,temp_w; - int test_x = 0,test_y = 0; - int loc_ok = False, tw,tx,ty,th; - FvwmWindow *test_window; - int stickyx, stickyy; - - if (Scr.SmartPlacementIsClever) /* call clever placement instead? */ - { -/* RBW - 11/02/1998 */ - CleverPlacement(t,x,y,pdeltax,pdeltay); -/**/ - return rc; - } -/* RBW - 11/02/1998 */ -test_x = PageLeft; -test_y = PageTop; -/**/ - - temp_h = height; - temp_w = width; - -/* RBW - 11/02/1998 */ - while(((test_y + temp_h) < (PageBottom))&&(!loc_ok)) - { - test_x = PageLeft; - while(((test_x + temp_w) < (PageRight))&&(!loc_ok)) - { - loc_ok = True; - test_window = Scr.FvwmRoot.next; - while((test_window != (FvwmWindow *)0)&&(loc_ok == True)) - { - /* RBW - account for sticky windows... */ - if(test_window->Desk == t->Desk || (test_window->flags & STICKY)) - { - if (test_window->flags & STICKY) - { - stickyx = pdeltax; - stickyy = pdeltay; - } - else - { - stickyx = 0; - stickyy = 0; - } + int PageBottom = Scr.MyDisplayHeight - pdeltay; + int PageRight = Scr.MyDisplayWidth - pdeltax; + int PageTop = 0 - pdeltay; + int PageLeft = 0 - pdeltax; + int rc = True; + /**/ + int temp_h, temp_w; + int test_x = 0, test_y = 0; + int loc_ok = False, tw, tx, ty, th; + FvwmWindow *test_window; + int stickyx, stickyy; + + if (Scr.SmartPlacementIsClever) { /* call clever placement instead? */ + /* RBW - 11/02/1998 */ + CleverPlacement(t, x, y, pdeltax, pdeltay); + /**/ + return rc; + } + /* RBW - 11/02/1998 */ + test_x = PageLeft; + test_y = PageTop; + /**/ + + temp_h = height; + temp_w = width; + + /* RBW - 11/02/1998 */ + while (((test_y + temp_h) < (PageBottom)) && (!loc_ok)) { + test_x = PageLeft; + while (((test_x + temp_w) < (PageRight)) && (!loc_ok)) { + loc_ok = True; + test_window = Scr.FvwmRoot.next; + while ((test_window != (FvwmWindow *)0) && + (loc_ok == True)) { + /* RBW - account for sticky windows... */ + if (test_window->Desk == t->Desk || + (test_window->flags & STICKY)) { + if (test_window->flags & STICKY) { + stickyx = pdeltax; + stickyy = pdeltay; + } else { + stickyx = 0; + stickyy = 0; + } #ifndef NO_STUBBORN_PLACEMENT - if((test_window->flags & ICONIFIED)&& - (!(test_window->flags & ICON_UNMAPPED))&& - (test_window->icon_w)&& - (test_window != t)) - { - tw=test_window->icon_p_width; - th=test_window->icon_p_height+ - test_window->icon_w_height; - tx = test_window->icon_x_loc - stickyx; - ty = test_window->icon_y_loc - stickyy; - - if((tx<(test_x+width))&&((tx + tw) > test_x)&& - (ty<(test_y+height))&&((ty + th)>test_y)) - { - loc_ok = False; - test_x = tx + tw; - } - } + if ((test_window->flags & ICONIFIED) && + (!(test_window->flags & + ICON_UNMAPPED)) && + (test_window->icon_w) && + (test_window != t)) { + tw = test_window->icon_p_width; + th = + test_window->icon_p_height + + test_window->icon_w_height; + tx = test_window->icon_x_loc - + stickyx; + ty = test_window->icon_y_loc - + stickyy; + + if ((tx < (test_x + width)) && + ((tx + tw) > test_x) && + (ty < (test_y + height)) && + ((ty + th) > test_y)) { + loc_ok = False; + test_x = tx + tw; + } + } #endif /* !NO_STUBBORN_PLACEMENT */ - if(!(test_window->flags & ICONIFIED)&&(test_window != t)) - { - tw=test_window->frame_width+2*test_window->bw; - th=test_window->frame_height+2*test_window->bw; - tx = test_window->frame_x - stickyx; - ty = test_window->frame_y - stickyy; - if((tx <= (test_x+width))&&((tx + tw) >= test_x)&& - (ty <= (test_y+height))&&((ty + th)>= test_y)) - { - loc_ok = False; - test_x = tx + tw; - } - } - } - test_window = test_window->next; - } - test_x +=1; - } - test_y +=1; - } - /* RBW - 11/02/1998 */ - if(loc_ok == False) - { - rc = False; - return rc; - } - *x = test_x; - *y = test_y; - return rc; - /**/ + if (!(test_window->flags & ICONIFIED) && + (test_window != t)) { + tw = test_window->frame_width + + 2 * test_window->bw; + th = test_window->frame_height + + 2 * test_window->bw; + tx = test_window->frame_x - + stickyx; + ty = test_window->frame_y - + stickyy; + if ((tx <= (test_x + width)) && + ((tx + tw) >= test_x) && + (ty <= (test_y + height)) && + ((ty + th) >= test_y)) { + loc_ok = False; + test_x = tx + tw; + } + } + } + test_window = test_window->next; + } + test_x += 1; + } + test_y += 1; + } + /* RBW - 11/02/1998 */ + if (loc_ok == False) { + rc = False; + return rc; + } + *x = test_x; + *y = test_y; + return rc; + /**/ } - /* CleverPlacement by Anthony Martin * This function will place a new window such that there is a minimum amount * of interference with other windows. If it can place a window without any * interference, fine. Otherwise, it places it so that the area of of * interference between the new window and the other windows is minimized */ /* RBW - 11/02/1998 */ -void CleverPlacement(FvwmWindow *t, int *x, int *y, int pdeltax, int pdeltay) +void +CleverPlacement(FvwmWindow *t, int *x, int *y, int pdeltax, int pdeltay) { -/**/ - int test_x = 0,test_y = 0; - int xbest, ybest; - int aoi, aoimin; /* area of interference */ - -/* RBW - 11/02/1998 */ - int PageTop = 0 - pdeltay; - int PageLeft = 0 - pdeltax; - - test_x = PageLeft; - test_y = PageTop; - aoi = aoimin = test_fit(t, test_x, test_y, -1, pdeltax, pdeltay); -/**/ - xbest = test_x; - ybest = test_y; - - while((aoi != 0) && (aoi != -1)) - { - if(aoi > 0) /* Windows interfere. Try next x. */ - { - test_x = get_next_x(t, test_x, test_y, pdeltax, pdeltay); - } - else /* Out of room in x direction. Try next y. Reset x.*/ - { - test_x = PageLeft; - test_y = get_next_y(t, test_y, pdeltay); - } - aoi = test_fit(t, test_x, test_y, aoimin, pdeltax, pdeltay); - if((aoi >= 0) && (aoi < aoimin)) - { - xbest = test_x; - ybest = test_y; - aoimin = aoi; - } - } - *x = xbest; - *y = ybest; + /**/ + int test_x = 0, test_y = 0; + int xbest, ybest; + int aoi, aoimin; /* area of interference */ + + /* RBW - 11/02/1998 */ + int PageTop = 0 - pdeltay; + int PageLeft = 0 - pdeltax; + + test_x = PageLeft; + test_y = PageTop; + aoi = aoimin = test_fit(t, test_x, test_y, -1, pdeltax, pdeltay); + /**/ + xbest = test_x; + ybest = test_y; + + while ((aoi != 0) && (aoi != -1)) { + if (aoi > 0) { /* Windows interfere. Try next x. */ + test_x = + get_next_x(t, test_x, test_y, pdeltax, pdeltay); + } else /* Out of room in x direction. Try next y. Reset x.*/ { + test_x = PageLeft; + test_y = get_next_y(t, test_y, pdeltay); + } + aoi = test_fit(t, test_x, test_y, aoimin, pdeltax, pdeltay); + if ((aoi >= 0) && (aoi < aoimin)) { + xbest = test_x; + ybest = test_y; + aoimin = aoi; + } + } + *x = xbest; + *y = ybest; } /* RBW - 11/02/1998 */ -int get_next_x(FvwmWindow *t, int x, int y, int pdeltax, int pdeltay) +int +get_next_x(FvwmWindow *t, int x, int y, int pdeltax, int pdeltay) { -/**/ - int xnew; - int xtest; - FvwmWindow *testw; - int PageRight = Scr.MyDisplayWidth - pdeltax; - int stickyx, stickyy; - - /* Test window at far right of screen */ -/* RBW - 11/02/1998 */ - xnew = PageRight; - xtest = PageRight - (t->frame_width + 2 * t->bw); -/**/ - if(xtest > x) - xnew = MIN(xnew, xtest); - /* Test the values of the right edges of every window */ - for(testw = Scr.FvwmRoot.next ; testw != NULL ; testw = testw->next) - { - if((testw == t) || ((testw->Desk != t->Desk) && (! (testw->flags & STICKY)))) - continue; - - if (testw->flags & STICKY) - { - stickyx = pdeltax; - stickyy = pdeltay; - } - else - { - stickyx = 0; - stickyy = 0; - } - - if(testw->flags & ICONIFIED) - { - if((y < (testw->icon_p_height+testw->icon_w_height+testw->icon_y_loc - stickyy))&& - (testw->icon_y_loc - stickyy < (t->frame_height+2*t->bw+y))) - { - xtest = testw->icon_p_width+testw->icon_x_loc - stickyx; - if(xtest > x) - xnew = MIN(xnew, xtest); - xtest = testw->icon_x_loc - stickyx - (t->frame_width + 2 * t->bw); - if(xtest > x) - xnew = MIN(xnew, xtest); - } - } - else if((y < (testw->frame_height+2*testw->bw+testw->frame_y - stickyy)) && - (testw->frame_y - stickyy < (t->frame_height+2*t->bw+y))) - { - xtest = testw->frame_width+2*testw->bw+testw->frame_x - stickyx; - if(xtest > x) - xnew = MIN(xnew, xtest); - xtest = testw->frame_x - stickyx - (t->frame_width + 2 * t->bw); - if(xtest > x) - xnew = MIN(xnew, xtest); - } - } - return xnew; + /**/ + int xnew; + int xtest; + FvwmWindow *testw; + int PageRight = Scr.MyDisplayWidth - pdeltax; + int stickyx, stickyy; + + /* Test window at far right of screen */ + /* RBW - 11/02/1998 */ + xnew = PageRight; + xtest = PageRight - (t->frame_width + 2 * t->bw); + /**/ + if (xtest > x) + xnew = MIN(xnew, xtest); + /* Test the values of the right edges of every window */ + for (testw = Scr.FvwmRoot.next; testw != NULL; testw = testw->next) { + if ((testw == t) || + ((testw->Desk != t->Desk) && (!(testw->flags & STICKY)))) + continue; + + if (testw->flags & STICKY) { + stickyx = pdeltax; + stickyy = pdeltay; + } else { + stickyx = 0; + stickyy = 0; + } + + if (testw->flags & ICONIFIED) { + if ((y < (testw->icon_p_height + testw->icon_w_height + + testw->icon_y_loc - stickyy)) && + (testw->icon_y_loc - stickyy < + (t->frame_height + 2 * t->bw + y))) { + xtest = testw->icon_p_width + + testw->icon_x_loc - stickyx; + if (xtest > x) + xnew = MIN(xnew, xtest); + xtest = testw->icon_x_loc - stickyx - + (t->frame_width + 2 * t->bw); + if (xtest > x) + xnew = MIN(xnew, xtest); + } + } else if ((y < (testw->frame_height + 2 * testw->bw + + testw->frame_y - stickyy)) && + (testw->frame_y - stickyy < + (t->frame_height + 2 * t->bw + y))) { + xtest = testw->frame_width + 2 * testw->bw + + testw->frame_x - stickyx; + if (xtest > x) + xnew = MIN(xnew, xtest); + xtest = testw->frame_x - stickyx - + (t->frame_width + 2 * t->bw); + if (xtest > x) + xnew = MIN(xnew, xtest); + } + } + return xnew; } -/* RBW - 11/02/1998 */ -int get_next_y(FvwmWindow *t, int y, int pdeltay) -{ -/**/ - int ynew; - int ytest; - FvwmWindow *testw; - int PageBottom = Scr.MyDisplayHeight - pdeltay; - int stickyy; - /* Test window at far bottom of screen */ /* RBW - 11/02/1998 */ - ynew = PageBottom; - ytest = PageBottom - (t->frame_height + 2 * t->bw); -/**/ - if(ytest > y) - ynew = MIN(ynew, ytest); - /* Test the values of the bottom edge of every window */ - for(testw = Scr.FvwmRoot.next ; testw != NULL ; testw = testw->next) - { - if((testw == t) || ((testw->Desk != t->Desk) && (! (testw->flags & STICKY)))) - continue; - - if (testw->flags & STICKY) - { - stickyy = pdeltay; - } - else - { - stickyy = 0; - } - - if(testw->flags & ICONIFIED) - { - ytest = testw->icon_p_height+testw->icon_w_height+testw->icon_y_loc - stickyy; - if(ytest > y) - ynew = MIN(ynew, ytest); - ytest = testw->icon_y_loc - stickyy - (t->frame_height + 2 * t->bw); - if(ytest > y) - ynew = MIN(ynew, ytest); - } - else - { - ytest = testw->frame_height+2*testw->bw+testw->frame_y - stickyy; - if(ytest > y) - ynew = MIN(ynew, ytest); - ytest = testw->frame_y - stickyy - (t->frame_height + 2 * t->bw); - if(ytest > y) - ynew = MIN(ynew, ytest); - } - } - return ynew; +int +get_next_y(FvwmWindow *t, int y, int pdeltay) +{ + /**/ + int ynew; + int ytest; + FvwmWindow *testw; + int PageBottom = Scr.MyDisplayHeight - pdeltay; + int stickyy; + + /* Test window at far bottom of screen */ + /* RBW - 11/02/1998 */ + ynew = PageBottom; + ytest = PageBottom - (t->frame_height + 2 * t->bw); + /**/ + if (ytest > y) + ynew = MIN(ynew, ytest); + /* Test the values of the bottom edge of every window */ + for (testw = Scr.FvwmRoot.next; testw != NULL; testw = testw->next) { + if ((testw == t) || + ((testw->Desk != t->Desk) && (!(testw->flags & STICKY)))) + continue; + + if (testw->flags & STICKY) { + stickyy = pdeltay; + } else { + stickyy = 0; + } + + if (testw->flags & ICONIFIED) { + ytest = testw->icon_p_height + testw->icon_w_height + + testw->icon_y_loc - stickyy; + if (ytest > y) + ynew = MIN(ynew, ytest); + ytest = testw->icon_y_loc - stickyy - + (t->frame_height + 2 * t->bw); + if (ytest > y) + ynew = MIN(ynew, ytest); + } else { + ytest = testw->frame_height + 2 * testw->bw + + testw->frame_y - stickyy; + if (ytest > y) + ynew = MIN(ynew, ytest); + ytest = testw->frame_y - stickyy - + (t->frame_height + 2 * t->bw); + if (ytest > y) + ynew = MIN(ynew, ytest); + } + } + return ynew; } /* RBW - 11/02/1998 */ -int test_fit(FvwmWindow *t, int x11, int y11, int aoimin, int pdeltax, - int pdeltay) +int +test_fit(FvwmWindow *t, int x11, int y11, int aoimin, int pdeltax, int pdeltay) { -/**/ - FvwmWindow *testw; - int x12, x21, x22; - int y12, y21, y22; - int xl, xr, yt, yb; /* xleft, xright, ytop, ybottom */ - int aoi = 0; /* area of interference */ - int anew; - int avoidance_factor; - int PageBottom = Scr.MyDisplayHeight - pdeltay; - int PageRight = Scr.MyDisplayWidth - pdeltax; - int stickyx, stickyy; - - x12 = x11 + t->frame_width + 2 * t->bw; - y12 = y11 + t->frame_height + 2 * t->bw; - - if (y12 > PageBottom) /* No room in y direction */ - return -1; - if (x12 > PageRight) /* No room in x direction */ - return -2; - for(testw = Scr.FvwmRoot.next ; testw != NULL ; testw = testw->next) - { - if ((testw == t) || ((testw->Desk != t->Desk) && (! (testw->flags & STICKY)))) - continue; - - if (testw->flags & STICKY) - { - stickyx = pdeltax; - stickyy = pdeltay; - } - else - { - stickyx = 0; - stickyy = 0; - } - - if(testw->flags & ICONIFIED) - { - if(testw->icon_w == None || testw->flags & ICON_UNMAPPED) - continue; - x21 = testw->icon_x_loc - stickyx; - y21 = testw->icon_y_loc - stickyy; - x22 = x21 + testw->icon_p_width; - y22 = y21 + testw->icon_p_height + testw->icon_w_height; - } - else - { - x21 = testw->frame_x - stickyx; - y21 = testw->frame_y - stickyy; - x22 = x21 + testw->frame_width + 2 * testw->bw; - y22 = y21 + testw->frame_height + 2 * testw->bw; - } - if((x11 < x22) && (x12 > x21) && - (y11 < y22) && (y12 > y21)) - { - /* Windows interfere */ - xl = MAX(x11, x21); - xr = MIN(x12, x22); - yt = MAX(y11, y21); - yb = MIN(y12, y22); - anew = (xr - xl) * (yb - yt); - if(testw->flags & ICONIFIED) - avoidance_factor = AVOIDICON; - else if(testw->flags & ONTOP) - avoidance_factor = AVOIDONTOP; - else if(testw->flags & STICKY) - avoidance_factor = AVOIDSTICKY; - else - avoidance_factor = 1; - anew *= avoidance_factor; - aoi += anew; - if((aoi > aoimin)&&(aoimin != -1)) - return aoi; - } - } - return aoi; + /**/ + FvwmWindow *testw; + int x12, x21, x22; + int y12, y21, y22; + int xl, xr, yt, yb; /* xleft, xright, ytop, ybottom */ + int aoi = 0; /* area of interference */ + int anew; + int avoidance_factor; + int PageBottom = Scr.MyDisplayHeight - pdeltay; + int PageRight = Scr.MyDisplayWidth - pdeltax; + int stickyx, stickyy; + + x12 = x11 + t->frame_width + 2 * t->bw; + y12 = y11 + t->frame_height + 2 * t->bw; + + if (y12 > PageBottom) /* No room in y direction */ + return -1; + if (x12 > PageRight) /* No room in x direction */ + return -2; + for (testw = Scr.FvwmRoot.next; testw != NULL; testw = testw->next) { + if ((testw == t) || + ((testw->Desk != t->Desk) && (!(testw->flags & STICKY)))) + continue; + + if (testw->flags & STICKY) { + stickyx = pdeltax; + stickyy = pdeltay; + } else { + stickyx = 0; + stickyy = 0; + } + + if (testw->flags & ICONIFIED) { + if (testw->icon_w == None || + testw->flags & ICON_UNMAPPED) + continue; + x21 = testw->icon_x_loc - stickyx; + y21 = testw->icon_y_loc - stickyy; + x22 = x21 + testw->icon_p_width; + y22 = y21 + testw->icon_p_height + testw->icon_w_height; + } else { + x21 = testw->frame_x - stickyx; + y21 = testw->frame_y - stickyy; + x22 = x21 + testw->frame_width + 2 * testw->bw; + y22 = y21 + testw->frame_height + 2 * testw->bw; + } + if ((x11 < x22) && (x12 > x21) && (y11 < y22) && (y12 > y21)) { + /* Windows interfere */ + xl = MAX(x11, x21); + xr = MIN(x12, x22); + yt = MAX(y11, y21); + yb = MIN(y12, y22); + anew = (xr - xl) * (yb - yt); + if (testw->flags & ICONIFIED) + avoidance_factor = AVOIDICON; + else if (testw->flags & ONTOP) + avoidance_factor = AVOIDONTOP; + else if (testw->flags & STICKY) + avoidance_factor = AVOIDSTICKY; + else + avoidance_factor = 1; + anew *= avoidance_factor; + aoi += anew; + if ((aoi > aoimin) && (aoimin != -1)) + return aoi; + } + } + return aoi; } - /************************************************************************** * * Handles initial placement and sizing of a new window @@ -416,377 +404,385 @@ int test_fit(FvwmWindow *t, int x11, int y11, int aoimin, int pdeltax, * **************************************************************************/ /* RBW - 11/02/1998 */ -Bool PlaceWindow(FvwmWindow *tmp_win, unsigned long tflag,int Desk, int PageX, int PageY) +Bool +PlaceWindow( + FvwmWindow *tmp_win, unsigned long tflag, int Desk, int PageX, int PageY) { -/**/ - FvwmWindow *t; - int xl = -1,yt,DragWidth,DragHeight; - int gravx, gravy; /* gravity signs for positioning */ -/* RBW - 11/02/1998 */ - int px = 0, py = 0, pdeltax = 0, pdeltay = 0; - int PageRight = Scr.MyDisplayWidth, PageBottom = Scr.MyDisplayHeight; - int smartlyplaced = False; - Bool HonorStartsOnPage = False; - extern Bool Restarting; -/**/ - extern Boolean PPosOverride; - - yt = 0; - - GetGravityOffsets (tmp_win, &gravx, &gravy); - - - /* Select a desk to put the window on (in list of priority): - * 1. Sticky Windows stay on the current desk. - * 2. Windows specified with StartsOnDesk go where specified - * 3. Put it on the desk it was on before the restart. - * 4. Transients go on the same desk as their parents. - * 5. Window groups stay together (completely untested) - */ - -/* RBW - 11/02/1998 */ -/* - Let's get the StartsOnDesk/Page tests out of the way first. -*/ - if (tflag & STARTSONDESK_FLAG) - { - HonorStartsOnPage = True; - /* - Honor the flag unless... - it's a restart or recapture, and that option's disallowed... - */ - if (PPosOverride && (Restarting || (Scr.flags & WindowsCaptured)) && - !Scr.go.RecaptureHonorsStartsOnPage) - { - HonorStartsOnPage = False; - } - /* - it's a cold start window capture, and that's disallowed... - */ - if (PPosOverride && (!Restarting && !(Scr.flags & WindowsCaptured)) && - !Scr.go.CaptureHonorsStartsOnPage) - { - HonorStartsOnPage = False; - } - /* - we have a USPosition, and overriding it is disallowed... + /**/ + FvwmWindow *t; + int xl = -1, yt, DragWidth, DragHeight; + int gravx, gravy; /* gravity signs for positioning */ + /* RBW - 11/02/1998 */ + int px = 0, py = 0, pdeltax = 0, pdeltay = 0; + int PageRight = Scr.MyDisplayWidth, PageBottom = Scr.MyDisplayHeight; + int smartlyplaced = False; + Bool HonorStartsOnPage = False; + extern Bool Restarting; + /**/ + extern Boolean PPosOverride; + + yt = 0; + + GetGravityOffsets(tmp_win, &gravx, &gravy); + + /* Select a desk to put the window on (in list of priority): + * 1. Sticky Windows stay on the current desk. + * 2. Windows specified with StartsOnDesk go where specified + * 3. Put it on the desk it was on before the restart. + * 4. Transients go on the same desk as their parents. + * 5. Window groups stay together (completely untested) + */ + + /* RBW - 11/02/1998 */ + /* + Let's get the StartsOnDesk/Page tests out of the way first. */ - if (!PPosOverride && (USPosition && !Scr.go.ModifyUSP)) - { - HonorStartsOnPage = False; - } - /* - it's ActivePlacement and SkipMapping, and that's disallowed. + if (tflag & STARTSONDESK_FLAG) { + HonorStartsOnPage = True; + /* + Honor the flag unless... + it's a restart or recapture, and that option's + disallowed... + */ + if (PPosOverride && + (Restarting || (Scr.flags & WindowsCaptured)) && + !Scr.go.RecaptureHonorsStartsOnPage) { + HonorStartsOnPage = False; + } + /* + it's a cold start window capture, and that's disallowed... + */ + if (PPosOverride && + (!Restarting && !(Scr.flags & WindowsCaptured)) && + !Scr.go.CaptureHonorsStartsOnPage) { + HonorStartsOnPage = False; + } + /* + we have a USPosition, and overriding it is disallowed... + */ + if (!PPosOverride && ((USPosition != 0) && !Scr.go.ModifyUSP)) { + HonorStartsOnPage = False; + } + /* + it's ActivePlacement and SkipMapping, and that's + disallowed. + */ + if (!PPosOverride && + ((tmp_win->flags & SHOW_ON_MAP) && + (!(tflag & RANDOM_PLACE_FLAG)) && + !Scr.go.ActivePlacementHonorsStartsOnPage)) { + HonorStartsOnPage = False; + } + } + /**/ + + tmp_win->Desk = Scr.CurrentDesk; + if (tflag & STICKY_FLAG) + tmp_win->Desk = Scr.CurrentDesk; + else if ((tflag & STARTSONDESK_FLAG) && Desk && HonorStartsOnPage) + tmp_win->Desk = + (Desk > -1) ? Desk - 1 : Desk; /* RBW - 11/20/1998 */ + else { + Atom atype; + int aformat; + unsigned long nitems, bytes_remain; + unsigned char *prop; + + if ((tmp_win->wmhints) && + (tmp_win->wmhints->flags & WindowGroupHint) && + (tmp_win->wmhints->window_group != None) && + (tmp_win->wmhints->window_group != Scr.Root)) { + /* Try to find the group leader or another window + * in the group */ + for (t = Scr.FvwmRoot.next; t != NULL; t = t->next) { + if ((t->w == tmp_win->wmhints->window_group) || + ((t->wmhints) && + (t->wmhints->flags & WindowGroupHint) && + (t->wmhints->window_group == + tmp_win->wmhints->window_group))) + tmp_win->Desk = t->Desk; + } + } + if ((tmp_win->flags & TRANSIENT) && + (tmp_win->transientfor != None) && + (tmp_win->transientfor != Scr.Root)) { + /* Try to find the parent's desktop */ + for (t = Scr.FvwmRoot.next; t != NULL; t = t->next) { + if (t->w == tmp_win->transientfor) + tmp_win->Desk = t->Desk; + } + } + + if ((XGetWindowProperty(dpy, tmp_win->w, _XA_WM_DESKTOP, 0L, 1L, + True, _XA_WM_DESKTOP, &atype, &aformat, &nitems, + &bytes_remain, &prop)) == Success) { + if (prop != NULL) { + tmp_win->Desk = *(unsigned long *)prop; + XFree(prop); + } + } + } + /* I think it would be good to switch to the selected desk + * whenever a new window pops up, except during initialization */ + if ((!PPosOverride) && (!(tmp_win->flags & SHOW_ON_MAP))) + /* RBW - 11/02/1998 -- I dont. */ + { + changeDesks(tmp_win->Desk); + } + + /* + Don't move viewport if SkipMapping, or if recapturing the window, + adjust the coordinates later. Otherwise, just switch to the target + page - it's ever so much simpler. */ - if (!PPosOverride && ((tmp_win->flags & SHOW_ON_MAP) && - (!(tflag & RANDOM_PLACE_FLAG)) && - !Scr.go.ActivePlacementHonorsStartsOnPage)) - { - HonorStartsOnPage = False; - } - } -/**/ - - tmp_win->Desk = Scr.CurrentDesk; - if (tflag & STICKY_FLAG) - tmp_win->Desk = Scr.CurrentDesk; - else if ((tflag & STARTSONDESK_FLAG) && Desk && HonorStartsOnPage) - tmp_win->Desk = (Desk > -1) ? Desk - 1 : Desk; /* RBW - 11/20/1998 */ - else - { - Atom atype; - int aformat; - unsigned long nitems, bytes_remain; - unsigned char *prop; - - if((tmp_win->wmhints)&&(tmp_win->wmhints->flags & WindowGroupHint)&& - (tmp_win->wmhints->window_group != None)&& - (tmp_win->wmhints->window_group != Scr.Root)) - { - /* Try to find the group leader or another window - * in the group */ - for (t = Scr.FvwmRoot.next; t != NULL; t = t->next) - { - if((t->w == tmp_win->wmhints->window_group)|| - ((t->wmhints)&&(t->wmhints->flags & WindowGroupHint)&& - (t->wmhints->window_group==tmp_win->wmhints->window_group))) - tmp_win->Desk = t->Desk; - } - } - if((tmp_win->flags & TRANSIENT)&&(tmp_win->transientfor!=None)&& - (tmp_win->transientfor != Scr.Root)) - { - /* Try to find the parent's desktop */ - for (t = Scr.FvwmRoot.next; t != NULL; t = t->next) - { - if(t->w == tmp_win->transientfor) - tmp_win->Desk = t->Desk; - } - } - - if ((XGetWindowProperty(dpy, tmp_win->w, _XA_WM_DESKTOP, 0L, 1L, True, - _XA_WM_DESKTOP, &atype, &aformat, &nitems, - &bytes_remain, &prop))==Success) - { - if(prop != NULL) - { - tmp_win->Desk = *(unsigned long *)prop; - XFree(prop); - } - } - } - /* I think it would be good to switch to the selected desk - * whenever a new window pops up, except during initialization */ - if((!PPosOverride)&&(!(tmp_win->flags & SHOW_ON_MAP))) -/* RBW - 11/02/1998 -- I dont. */ - { - changeDesks(tmp_win->Desk); - } - -/* - Don't move viewport if SkipMapping, or if recapturing the window, - adjust the coordinates later. Otherwise, just switch to the target - page - it's ever so much simpler. -*/ - if (!(tflag & STICKY_FLAG) && (tflag & STARTSONDESK_FLAG)) - { - if (PageX && PageY) - { - px = PageX - 1; - py = PageY -1 ; - px *= Scr.MyDisplayWidth; - py *= Scr.MyDisplayHeight; - if ( (!PPosOverride) && (!(tmp_win->flags & SHOW_ON_MAP)) ) - { - MoveViewport(px,py,True); - } - else - { - if (HonorStartsOnPage) - { - /* Save the delta from current page */ - pdeltax = Scr.Vx - px; - pdeltay = Scr.Vy - py; - PageRight -= pdeltax; - PageBottom -= pdeltay; - } - } - } - } - -/**/ - - - /* Desk has been selected, now pick a location for the window */ - /* - * If - * o the window is a transient, or - * - * o a USPosition was requested - * - * then put the window where requested. - * - * If RandomPlacement was specified, - * then place the window in a psuedo-random location - */ - if (!(tmp_win->flags & TRANSIENT) && - !(tmp_win->hints.flags & USPosition) && - ((tflag & NO_PPOSITION_FLAG)|| - !(tmp_win->hints.flags & PPosition)) && - !(PPosOverride) && - /* RBW - allow StartsOnPage to go through, even if iconic. */ - ( ((!((tmp_win->wmhints)&& - (tmp_win->wmhints->flags & StateHint)&& - (tmp_win->wmhints->initial_state == IconicState))) - || (HonorStartsOnPage)) ) ) - { - /* Get user's window placement, unless RandomPlacement is specified */ - if(tflag & RANDOM_PLACE_FLAG) - { - if(tflag & SMART_PLACE_FLAG) - smartlyplaced = SmartPlacement(tmp_win,tmp_win->frame_width+2*tmp_win->bw, - tmp_win->frame_height+2*tmp_win->bw, - &xl,&yt, pdeltax, pdeltay); - if(! smartlyplaced) - { - /* place window in a random location */ - if ((Scr.randomx += GetDecor(tmp_win,TitleHeight)) > Scr.MyDisplayWidth / 2) - Scr.randomx = GetDecor(tmp_win,TitleHeight); - if ((Scr.randomy += 2*GetDecor(tmp_win,TitleHeight)) > Scr.MyDisplayHeight / 2) - Scr.randomy = 2 * GetDecor(tmp_win,TitleHeight); - tmp_win->attr.x = (Scr.randomx - pdeltax) - tmp_win->old_bw; - tmp_win->attr.y = (Scr.randomy - pdeltay) - tmp_win->old_bw; - } - else - { - tmp_win->attr.x = xl - tmp_win->old_bw + tmp_win->bw; - tmp_win->attr.y = yt - tmp_win->old_bw + tmp_win->bw; - } - /* patches 11/93 to try to keep the window on the - * screen */ - tmp_win->frame_x = tmp_win->attr.x + tmp_win->old_bw - tmp_win->bw; - tmp_win->frame_y = tmp_win->attr.y + tmp_win->old_bw - tmp_win->bw; - - if(tmp_win->frame_x + tmp_win->frame_width + - 2*tmp_win->boundary_width> PageRight) - { - tmp_win->attr.x = PageRight -tmp_win->attr.width - - tmp_win->old_bw +tmp_win->bw - 2*tmp_win->boundary_width; - Scr.randomx = 0; - } - if(tmp_win->frame_y + 2*tmp_win->boundary_width+tmp_win->title_height - + tmp_win->frame_height > PageBottom) - { - tmp_win->attr.y = PageBottom -tmp_win->attr.height - - tmp_win->old_bw +tmp_win->bw - tmp_win->title_height - - 2*tmp_win->boundary_width;; - Scr.randomy = 0; - } - - tmp_win->xdiff = tmp_win->attr.x; - tmp_win->ydiff = tmp_win->attr.y; - /* put it where asked, mod title bar */ - /* if the gravity is towards the top, move it by the title height */ - tmp_win->ydiff += gravy*(tmp_win->bw-tmp_win->old_bw); - tmp_win->xdiff += gravx*(tmp_win->bw-tmp_win->old_bw); - if(gravy > 0) - tmp_win->ydiff += 2*tmp_win->boundary_width + tmp_win->title_height; - if(gravx > 0) - tmp_win->xdiff += 2*tmp_win->boundary_width; - } - else - { - /* Must be ActivePlacement */ - xl = -1; - yt = -1; - if(tflag & SMART_PLACE_FLAG) - smartlyplaced = SmartPlacement(tmp_win,tmp_win->frame_width+2*tmp_win->bw, - tmp_win->frame_height+2*tmp_win->bw, - &xl,&yt, pdeltax, pdeltay); - if(! smartlyplaced) - { - if(GrabEm(POSITION)) - { - /* Grabbed the pointer - continue */ - MyXGrabServer(dpy); - if(XGetGeometry(dpy, tmp_win->w, &JunkRoot, &JunkX, &JunkY, - (unsigned int *)&DragWidth, - (unsigned int *)&DragHeight, - &JunkBW, &JunkDepth) == 0) - { - free((char *)tmp_win); - MyXUngrabServer(dpy); - return False; - } - DragWidth = tmp_win->frame_width; - DragHeight = tmp_win->frame_height; - - XMapRaised(dpy,Scr.SizeWindow); - moveLoop(tmp_win,0,0,DragWidth,DragHeight,&xl,&yt,False,True); - XUnmapWindow(dpy,Scr.SizeWindow); - MyXUngrabServer(dpy); - UngrabEm(); - } - else - { - /* couldn't grab the pointer - better do something */ - XBell(dpy, 0); - xl = 0; - yt = 0; - } - } - /* RBW - 01/24/1999 */ - if (HonorStartsOnPage && ! smartlyplaced) - { - xl -= pdeltax; - yt -= pdeltay; - } - /**/ - tmp_win->attr.y = yt - tmp_win->old_bw + tmp_win->bw; - tmp_win->attr.x = xl - tmp_win->old_bw + tmp_win->bw; - tmp_win->xdiff = xl ; - tmp_win->ydiff = yt ; - } - } - else - { - /* the USPosition was specified, or the window is a transient, - * or it starts iconic so place it automatically */ - -/* RBW - 11/02/1998 */ -/* - If SkipMapping, and other legalities are observed, adjust for StartsOnPage. -*/ - - if ( ( (tmp_win->flags & SHOW_ON_MAP) && HonorStartsOnPage ) && - - ( !(tmp_win->flags & TRANSIENT) && - - ((tflag & NO_PPOSITION_FLAG) || - !(tmp_win->hints.flags & PPosition)) && - - /* RBW - allow StartsOnPage to go through, even if iconic. */ - ( ((!((tmp_win->wmhints)&& - (tmp_win->wmhints->flags & StateHint)&& - (tmp_win->wmhints->initial_state == IconicState))) - || (HonorStartsOnPage)) ) - - ) ) - { - /* - We're placing a SkipMapping window - either capturing one that's - previously been mapped, or overriding USPosition - so what we - have here is its actual untouched coordinates. In case it was - a StartsOnPage window, we have to 1) convert the existing x,y - offsets relative to the requested page (i.e., as though there - were only one page, no virtual desktop), then 2) readjust - relative to the current page. - */ - - - if (tmp_win->attr.x < 0) - { - tmp_win->attr.x = ((Scr.MyDisplayWidth + tmp_win->attr.x) % Scr.MyDisplayWidth); - } - else - { - tmp_win->attr.x = tmp_win->attr.x % Scr.MyDisplayWidth; - } -/* - Noticed a quirk here. With some apps (e.g., xman), we find the - placement has moved 1 pixel away from where we originally put it when we - come through here. Why is this happening? - Probably old_bw, try xclock -borderwidth 100 -*/ - if (tmp_win->attr.y < 0) - { - tmp_win->attr.y = ((Scr.MyDisplayHeight + tmp_win->attr.y) % Scr.MyDisplayHeight); - } - else - { - tmp_win->attr.y = tmp_win->attr.y % Scr.MyDisplayHeight; - } - tmp_win->attr.x -= pdeltax; - tmp_win->attr.y -= pdeltay; - } -/**/ - - tmp_win->xdiff = tmp_win->attr.x; - tmp_win->ydiff = tmp_win->attr.y; - /* put it where asked, mod title bar */ - /* if the gravity is towards the top, move it by the title height */ - tmp_win->attr.y -= gravy*(tmp_win->bw-tmp_win->old_bw); - tmp_win->attr.x -= gravx*(tmp_win->bw-tmp_win->old_bw); - if(gravy > 0) - tmp_win->attr.y -= 2*tmp_win->boundary_width + tmp_win->title_height; - if(gravx > 0) - tmp_win->attr.x -= 2*tmp_win->boundary_width; - } - return True; + if (!(tflag & STICKY_FLAG) && (tflag & STARTSONDESK_FLAG)) { + if (PageX || PageY) { + int current_px = (Scr.MyDisplayWidth != 0) ? + Scr.Vx / Scr.MyDisplayWidth : + 0; + int current_py = (Scr.MyDisplayHeight != 0) ? + Scr.Vy / Scr.MyDisplayHeight : + 0; + + px = (PageX != 0) ? ((PageX > 0) ? PageX - 1 : PageX) : + current_px; + py = (PageY != 0) ? ((PageY > 0) ? PageY - 1 : PageY) : + current_py; + + px *= Scr.MyDisplayWidth; + py *= Scr.MyDisplayHeight; + + if ((!PPosOverride) && + (!(tmp_win->flags & SHOW_ON_MAP))) { + MoveViewport(px, py, True); + } else if (HonorStartsOnPage) { + pdeltax = Scr.Vx - px; + pdeltay = Scr.Vy - py; + PageRight -= pdeltax; + PageBottom -= pdeltay; + } + } + } + + /**/ + + /* Desk has been selected, now pick a location for the window */ + /* + * If + * o the window is a transient, or + * + * o a USPosition was requested + * + * then put the window where requested. + * + * If RandomPlacement was specified, + * then place the window in a psuedo-random location + */ + if (!(tmp_win->flags & TRANSIENT) && + !(tmp_win->hints.flags & USPosition) && + ((tflag & NO_PPOSITION_FLAG) || + !(tmp_win->hints.flags & PPosition)) && + !(PPosOverride) && + /* RBW - allow StartsOnPage to go through, even if iconic. */ + (((!((tmp_win->wmhints) && (tmp_win->wmhints->flags & StateHint) && + (tmp_win->wmhints->initial_state == IconicState))) || + (HonorStartsOnPage)))) { + /* Get user's window placement, unless RandomPlacement is + * specified */ + if (tflag & RANDOM_PLACE_FLAG) { + if (tflag & SMART_PLACE_FLAG) + smartlyplaced = SmartPlacement(tmp_win, + tmp_win->frame_width + 2 * tmp_win->bw, + tmp_win->frame_height + 2 * tmp_win->bw, + &xl, &yt, pdeltax, pdeltay); + if (!smartlyplaced) { + /* place window in a random location */ + if ((Scr.randomx += GetDecor(tmp_win, + TitleHeight)) > Scr.MyDisplayWidth / 2) + Scr.randomx = + GetDecor(tmp_win, TitleHeight); + if ((Scr.randomy += + 2 * GetDecor(tmp_win, TitleHeight)) > + Scr.MyDisplayHeight / 2) + Scr.randomy = + 2 * GetDecor(tmp_win, TitleHeight); + tmp_win->attr.x = + (Scr.randomx - pdeltax) - tmp_win->old_bw; + tmp_win->attr.y = + (Scr.randomy - pdeltay) - tmp_win->old_bw; + } else { + tmp_win->attr.x = + xl - tmp_win->old_bw + tmp_win->bw; + tmp_win->attr.y = + yt - tmp_win->old_bw + tmp_win->bw; + } + /* patches 11/93 to try to keep the window on the + * screen */ + tmp_win->frame_x = + tmp_win->attr.x + tmp_win->old_bw - tmp_win->bw; + tmp_win->frame_y = + tmp_win->attr.y + tmp_win->old_bw - tmp_win->bw; + + if (tmp_win->frame_x + tmp_win->frame_width + + 2 * tmp_win->boundary_width > + PageRight) { + tmp_win->attr.x = + PageRight - tmp_win->attr.width - + tmp_win->old_bw + tmp_win->bw - + 2 * tmp_win->boundary_width; + Scr.randomx = 0; + } + if (tmp_win->frame_y + 2 * tmp_win->boundary_width + + tmp_win->title_height + tmp_win->frame_height > + PageBottom) { + tmp_win->attr.y = + PageBottom - tmp_win->attr.height - + tmp_win->old_bw + tmp_win->bw - + tmp_win->title_height - + 2 * tmp_win->boundary_width; + ; + Scr.randomy = 0; + } + + tmp_win->xdiff = tmp_win->attr.x; + tmp_win->ydiff = tmp_win->attr.y; + /* put it where asked, mod title bar */ + /* if the gravity is towards the top, move it by the + * title height */ + tmp_win->ydiff += + gravy * (tmp_win->bw - tmp_win->old_bw); + tmp_win->xdiff += + gravx * (tmp_win->bw - tmp_win->old_bw); + if (gravy > 0) + tmp_win->ydiff += 2 * tmp_win->boundary_width + + tmp_win->title_height; + if (gravx > 0) + tmp_win->xdiff += 2 * tmp_win->boundary_width; + } else { + /* Must be ActivePlacement */ + xl = -1; + yt = -1; + if (tflag & SMART_PLACE_FLAG) + smartlyplaced = SmartPlacement(tmp_win, + tmp_win->frame_width + 2 * tmp_win->bw, + tmp_win->frame_height + 2 * tmp_win->bw, + &xl, &yt, pdeltax, pdeltay); + if (!smartlyplaced) { + if (GrabEm(POSITION)) { + /* Grabbed the pointer - continue */ + MyXGrabServer(dpy); + if (XGetGeometry(dpy, tmp_win->w, + &JunkRoot, &JunkX, &JunkY, + (unsigned int *)&DragWidth, + (unsigned int *)&DragHeight, + &JunkBW, &JunkDepth) == 0) { + free((char *)tmp_win); + MyXUngrabServer(dpy); + return False; + } + DragWidth = tmp_win->frame_width; + DragHeight = tmp_win->frame_height; + + XMapRaised(dpy, Scr.SizeWindow); + moveLoop(tmp_win, 0, 0, DragWidth, + DragHeight, &xl, &yt, False, True); + XUnmapWindow(dpy, Scr.SizeWindow); + MyXUngrabServer(dpy); + UngrabEm(); + } else { + /* couldn't grab the pointer - better do + * something */ + XBell(dpy, 0); + xl = 0; + yt = 0; + } + } + /* RBW - 01/24/1999 */ + if (HonorStartsOnPage && !smartlyplaced) { + xl -= pdeltax; + yt -= pdeltay; + } + /**/ + tmp_win->attr.y = yt - tmp_win->old_bw + tmp_win->bw; + tmp_win->attr.x = xl - tmp_win->old_bw + tmp_win->bw; + tmp_win->xdiff = xl; + tmp_win->ydiff = yt; + } + } else { + /* the USPosition was specified, or the window is a transient, + * or it starts iconic so place it automatically */ + + /* RBW - 11/02/1998 */ + /* + If SkipMapping, and other legalities are observed, adjust for + StartsOnPage. + */ + + if (((tmp_win->flags & SHOW_ON_MAP) && HonorStartsOnPage) && + (!(tmp_win->flags & TRANSIENT) && + ((tflag & NO_PPOSITION_FLAG) || + !(tmp_win->hints.flags & PPosition)) && + /* RBW - allow StartsOnPage to go through, even if + iconic. */ + (((!((tmp_win->wmhints) && + (tmp_win->wmhints->flags & StateHint) && + (tmp_win->wmhints->initial_state == IconicState))) || + (HonorStartsOnPage))))) { + /* + We're placing a SkipMapping window - either + capturing one that's previously been mapped, or + overriding USPosition - so what we have here is its + actual untouched coordinates. In case it was a + StartsOnPage window, we have to 1) convert the + existing x,y offsets relative to the requested page + (i.e., as though there were only one page, no virtual + desktop), then 2) readjust relative to the current + page. + */ + + if (tmp_win->attr.x < 0) { + tmp_win->attr.x = + ((Scr.MyDisplayWidth + tmp_win->attr.x) % + Scr.MyDisplayWidth); + } else { + tmp_win->attr.x = + tmp_win->attr.x % Scr.MyDisplayWidth; + } + /* + Noticed a quirk here. With some apps (e.g., xman), we find + the placement has moved 1 pixel away from where we + originally put it when we come through here. Why is this + happening? Probably old_bw, try xclock -borderwidth 100 + */ + if (tmp_win->attr.y < 0) { + tmp_win->attr.y = + ((Scr.MyDisplayHeight + tmp_win->attr.y) % + Scr.MyDisplayHeight); + } else { + tmp_win->attr.y = + tmp_win->attr.y % Scr.MyDisplayHeight; + } + tmp_win->attr.x -= pdeltax; + tmp_win->attr.y -= pdeltay; + } + /**/ + + tmp_win->xdiff = tmp_win->attr.x; + tmp_win->ydiff = tmp_win->attr.y; + /* put it where asked, mod title bar */ + /* if the gravity is towards the top, move it by the title + * height */ + tmp_win->attr.y -= gravy * (tmp_win->bw - tmp_win->old_bw); + tmp_win->attr.x -= gravx * (tmp_win->bw - tmp_win->old_bw); + if (gravy > 0) + tmp_win->attr.y -= + 2 * tmp_win->boundary_width + tmp_win->title_height; + if (gravx > 0) + tmp_win->attr.x -= 2 * tmp_win->boundary_width; + } + return True; } - - /************************************************************************ * * Procedure: @@ -794,36 +790,35 @@ Bool PlaceWindow(FvwmWindow *tmp_win, unsigned long tflag,int Desk, int PageX, i * to x and y when window is mapped to get proper placement. * ************************************************************************/ -struct _gravity_offset -{ - int x, y; +struct _gravity_offset { + int x, y; }; -void GetGravityOffsets (FvwmWindow *tmp,int *xp,int *yp) +void +GetGravityOffsets(FvwmWindow *tmp, int *xp, int *yp) { - static struct _gravity_offset gravity_offsets[11] = - { - { 0, 0 }, /* ForgetGravity */ - { -1, -1 }, /* NorthWestGravity */ - { 0, -1 }, /* NorthGravity */ - { 1, -1 }, /* NorthEastGravity */ - { -1, 0 }, /* WestGravity */ - { 0, 0 }, /* CenterGravity */ - { 1, 0 }, /* EastGravity */ - { -1, 1 }, /* SouthWestGravity */ - { 0, 1 }, /* SouthGravity */ - { 1, 1 }, /* SouthEastGravity */ - { 0, 0 }, /* StaticGravity */ - }; - register int g = ((tmp->hints.flags & PWinGravity) - ? tmp->hints.win_gravity : NorthWestGravity); - - if (g < ForgetGravity || g > StaticGravity) - *xp = *yp = 0; - else - { - *xp = (int)gravity_offsets[g].x; - *yp = (int)gravity_offsets[g].y; - } - return; + static struct _gravity_offset gravity_offsets[11] = { + {0, 0}, /* ForgetGravity */ + {-1, -1}, /* NorthWestGravity */ + {0, -1}, /* NorthGravity */ + {1, -1}, /* NorthEastGravity */ + {-1, 0}, /* WestGravity */ + {0, 0}, /* CenterGravity */ + {1, 0}, /* EastGravity */ + {-1, 1}, /* SouthWestGravity */ + {0, 1}, /* SouthGravity */ + {1, 1}, /* SouthEastGravity */ + {0, 0}, /* StaticGravity */ + }; + register int g = + ((tmp->hints.flags & PWinGravity) ? tmp->hints.win_gravity : + NorthWestGravity); + + if (g < ForgetGravity || g > StaticGravity) + *xp = *yp = 0; + else { + *xp = (int)gravity_offsets[g].x; + *yp = (int)gravity_offsets[g].y; + } + return; } Index: fvwm/fvwm/read.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/read.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/read.c --- fvwm/fvwm/read.c +++ fvwm/fvwm/read.c @@ -11,21 +11,26 @@ * Its now in "modconf.c". * ************************************************************************* */ -#include "config.h" +#include +#include +#include +#include -#include +#include +#include +#include #include +#include #include -#include #include -#include +#include "config.h" #include "fvwm.h" #include "menus.h" #include "misc.h" +#include "module.h" #include "parse.h" #include "screen.h" -#include "module.h" extern Boolean debugging; @@ -33,10 +38,114 @@ char *fvwm_file = NULL; int numfilesread = 0; -static int last_read_failed=0; +#define MAX_NESTING_DEPTH 128 + +static int last_read_failed = 0; + +static const char *read_system_rc_cmd = "Read system" FVWMRC; + +typedef struct { + FILE *stream; + pid_t pid; + int fd; +} PipeChild; + +#define PIPE_READ_INTERVAL_SEC 1 +#define PIPE_READ_MAX_IDLE_LOOPS 10 +#define PIPE_REAP_WAIT_USEC 100000 +#define PIPE_REAP_ATTEMPTS 20 + +static int +start_pipe_process(const char *command, PipeChild *child) +{ + int pipe_fd[2]; + pid_t pid; + + if (pipe(pipe_fd) < 0) + return -1; + + pid = fork(); + if (pid < 0) { + close(pipe_fd[0]); + close(pipe_fd[1]); + return -1; + } + + if (pid == 0) { + close(pipe_fd[0]); + if (dup2(pipe_fd[1], STDOUT_FILENO) == -1) + _exit(127); + close(pipe_fd[1]); + execl("/bin/sh", "sh", "-c", command, (char *)NULL); + _exit(127); + } + + close(pipe_fd[1]); + child->fd = pipe_fd[0]; + child->stream = fdopen(child->fd, "r"); + if (child->stream == NULL) { + close(child->fd); + kill(pid, SIGTERM); + (void)waitpid(pid, NULL, 0); + child->fd = -1; + return -1; + } + fcntl(child->fd, F_SETFD, 1); + child->pid = pid; + return 0; +} + +static void +stop_pipe_process( + PipeChild *child, int timed_out, const char *cmdname, const char *command) +{ + int status; + int attempt; + pid_t waited = -1; + + if (child->stream) { + fclose(child->stream); + child->stream = NULL; + } + + if (child->fd >= 0) + child->fd = -1; + + if (child->pid <= 0) + return; -static const char *read_system_rc_cmd="Read system"FVWMRC; + if (timed_out) { + fvwm_msg(WARN, cmdname, + "command '%s' did not close pipe, terminating it", command); + kill(child->pid, SIGTERM); + } + for (attempt = 0; attempt < PIPE_REAP_ATTEMPTS; ++attempt) { + waited = waitpid(child->pid, &status, timed_out ? WNOHANG : 0); + if (waited == child->pid) + break; + if (waited == -1) { + if (errno == EINTR) + continue; + if (errno != ECHILD) + fvwm_msg(ERR, cmdname, + "waitpid failed for '%s': %s", command, + strerror(errno)); + break; + } + if (waited == 0) + usleep(PIPE_REAP_WAIT_USEC); + } + + if (timed_out && waited != child->pid) { + kill(child->pid, SIGKILL); + while ((waited = waitpid(child->pid, &status, 0)) == -1 && + errno == EINTR) + ; + } + + child->pid = -1; +} extern void StartupStuff(void); @@ -45,209 +154,248 @@ extern void StartupStuff(void); * Arg 1 is file name to read. * Arg 2 (optional) "Quiet" to suppress message on missing file. */ -static void ReadSubFunc(XEvent *eventp,Window junk,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module, - int piperead) +static void +ReadSubFunc(XEvent *eventp, Window junk, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module, int piperead) { - char *filename= NULL,*Home, *home_file, *ofilename = NULL; - char *option; /* optional arg to read */ - char *rest,*tline,line[1024]; - FILE *fd; - int thisfileno; - char missing_quiet; /* missing file msg control */ - char *cmdname; - size_t len; - - /* domivogt (30-Dec-1998: I tried using conditional evaluation instead - * of the cmdname variable ( piperead?"PipeRead":"Read" ), but gcc seems - * to treat this expression as a pointer to a character pointer, not just - * as a character pointer, but it doesn't complain either. Or perhaps - * insure++ gets this wrong? */ - if (piperead) - cmdname = "PipeRead"; - else - cmdname = "Read"; - - thisfileno = numfilesread; - numfilesread++; - -/* fvwm_msg(INFO,cmdname,"action == '%s'",action); */ - - rest = GetNextToken(action,&ofilename); /* read file name arg */ - if(ofilename == NULL) - { - fvwm_msg(ERR, cmdname,"missing parameter"); - last_read_failed = 1; - return; - } - missing_quiet='n'; /* init */ - rest = GetNextToken(rest,&option); /* read optional arg */ - if (option != NULL) { /* if there is a second arg */ - if (strncasecmp(option,"Quiet",5)==0) { /* is the arg "quiet"? */ - missing_quiet='y'; /* no missing file message wanted */ - } /* end quiet arg */ - free(option); /* arg not needed after this */ - } /* end there is a second arg */ - - filename = ofilename; -/* fvwm_msg(INFO, cmdname,"trying '%s'",filename); */ - - if (piperead) - fd = popen(filename,"r"); - else if (ofilename[0] != '/') - { - /* find the home directory to look in */ - Home = getenv("HOME"); - if (Home != NULL) - { - len = strlen(Home) + strlen(ofilename) + 3; - home_file = safemalloc(len); - strlcpy(home_file,Home,len); - strlcat(home_file,"/",len); - strlcat(home_file,ofilename,len); - filename = home_file; - fd = fopen(filename,"r"); - } - else - { - fd = 0; - } - if (fd == 0) - { - if((filename != NULL)&&(filename!= ofilename)) - free(filename); - /* find the home directory to look in */ - Home = FVWM_CONFIGDIR; - len = strlen(Home) + strlen(ofilename) + 3; - home_file = safemalloc(len); - strlcpy(home_file,Home,len); - strlcat(home_file,"/",len); - strlcat(home_file,ofilename,len); - filename = home_file; - fd = fopen(filename,"r"); - } - } - else - { - /* open file with absolute path */ - fd = fopen(filename,"r"); - } - - if(fd == NULL) - { - if (missing_quiet == 'n') { /* if quiet option not on */ - if (piperead) - fvwm_msg(ERR, cmdname, "command '%s' not run", ofilename); - else - fvwm_msg(ERR, cmdname, - "file '%s' not found in $HOME or "FVWM_CONFIGDIR, ofilename); - } /* end quiet option not on */ - if((ofilename != filename)&&(filename != NULL)) - { - free(filename); - } - if(ofilename != NULL) - { - free(ofilename); - } - last_read_failed = 1; - return; - } - if((ofilename != NULL)&&(filename!= ofilename)) - free(ofilename); - fcntl(fileno(fd), F_SETFD, 1); - if (!piperead) - { - if(fvwm_file != NULL) - free(fvwm_file); - fvwm_file = filename; - } - else - { - if (filename) - free(filename); - } - - tline = fgets(line,(sizeof line)-1,fd); - while(tline) - { - int l; - while(tline && (l = strlen(line)) < sizeof(line) && l >= 2 && - line[l-2]=='\\' && line[l-1]=='\n') - { - tline = fgets(line+l-2,sizeof(line)-l+1,fd); - } - tline=line; - while(isspace(*tline)) - tline++; - if (debugging) - { - fvwm_msg(DBG,"ReadSubFunc","about to exec: '%s'",tline); - } - ExecuteFunction(tline,tmp_win,eventp,context,*Module); - tline = fgets(line,(sizeof line)-1,fd); - } - - if (piperead) - pclose(fd); - else - fclose(fd); - last_read_failed = 0; + + if (numfilesread >= MAX_NESTING_DEPTH) { + fvwm_msg(ERR, piperead ? "PipeRead" : "Read", + "nesting depth exceeded (%d)", MAX_NESTING_DEPTH); + return; + } + char *filename = NULL, *Home, *home_file, *ofilename = NULL; + char *option; /* optional arg to read */ + char *rest, *tline, line[1024]; + FILE *stream = NULL; + PipeChild child = {NULL, -1, -1}; + int thisfileno; + char missing_quiet; /* missing file msg control */ + char *cmdname; + size_t len; + int timed_out = 0; + int idle_loops = 0; + + /* domivogt (30-Dec-1998: I tried using conditional evaluation instead + * of the cmdname variable ( piperead?"PipeRead":"Read" ), but gcc seems + * to treat this expression as a pointer to a character pointer, not + * just as a character pointer, but it doesn't complain either. Or + * perhaps insure++ gets this wrong? */ + if (piperead) + cmdname = "PipeRead"; + else + cmdname = "Read"; + + thisfileno = numfilesread; + numfilesread++; + + /* fvwm_msg(INFO,cmdname,"action == '%s'",action); */ + + rest = GetNextToken(action, &ofilename); /* read file name arg */ + if (ofilename == NULL) { + fvwm_msg(ERR, cmdname, "missing parameter"); + last_read_failed = 1; + return; + } + missing_quiet = 'n'; /* init */ + rest = GetNextToken(rest, &option); /* read optional arg */ + if (option != NULL) { /* if there is a second arg */ + if (strncasecmp(option, "Quiet", 5) == + 0) { /* is the arg "quiet"? */ + missing_quiet = + 'y'; /* no missing file message wanted */ + } /* end quiet arg */ + free(option); /* arg not needed after this */ + } /* end there is a second arg */ + + if (piperead) { + child.pid = -1; + child.fd = -1; + child.stream = NULL; + if (start_pipe_process(ofilename, &child) == 0) + stream = child.stream; + } else { + filename = ofilename; + if (ofilename[0] != '/') { + Home = getenv("HOME"); + if (Home != NULL) { + len = strlen(Home) + strlen(ofilename) + 3; + home_file = xmalloc(len); + strlcpy(home_file, Home, len); + strlcat(home_file, "/", len); + strlcat(home_file, ofilename, len); + filename = home_file; + stream = fopen(filename, "r"); + } else { + stream = NULL; + } + if (stream == NULL) { + if ((filename != NULL) && + (filename != ofilename)) + free(filename); + Home = FVWM_CONFIGDIR; + len = strlen(Home) + strlen(ofilename) + 3; + home_file = xmalloc(len); + strlcpy(home_file, Home, len); + strlcat(home_file, "/", len); + strlcat(home_file, ofilename, len); + filename = home_file; + stream = fopen(filename, "r"); + } + } else { + stream = fopen(filename, "r"); + } + } + + if (stream == NULL) { + if (missing_quiet == 'n') { + if (piperead) + fvwm_msg(ERR, cmdname, "command '%s' not run", + ofilename); + else + fvwm_msg(ERR, cmdname, + "file '%s' not found in $HOME " + "or " FVWM_CONFIGDIR, + ofilename); + } + if (!piperead && filename && filename != ofilename) + free(filename); + if (piperead && child.pid > 0) + stop_pipe_process(&child, 1, cmdname, ofilename); + if (piperead || (filename != ofilename)) + free(ofilename); + last_read_failed = 1; + return; + } + + if (!piperead) { + if (filename != ofilename && ofilename != NULL) { + free(ofilename); + ofilename = NULL; + } + fcntl(fileno(stream), F_SETFD, 1); + if (fvwm_file != NULL) + free(fvwm_file); + fvwm_file = filename; + } + + while (stream && !timed_out) { + if (piperead) { + fd_set readfds; + struct timeval tv; + int ready; + + FD_ZERO(&readfds); + FD_SET(child.fd, &readfds); + tv.tv_sec = PIPE_READ_INTERVAL_SEC; + tv.tv_usec = 0; + + ready = select(child.fd + 1, &readfds, NULL, NULL, &tv); + if (ready < 0) { + if (errno == EINTR) + continue; + timed_out = 1; + break; + } + if (ready == 0) { + if (++idle_loops >= PIPE_READ_MAX_IDLE_LOOPS) { + timed_out = 1; + break; + } + continue; + } + idle_loops = 0; + } + + tline = fgets(line, (sizeof line) - 1, stream); + if (tline == NULL) { + if (!piperead || feof(stream)) + break; + if (ferror(stream)) { + clearerr(stream); + continue; + } + break; + } + { + int l; + while ((l = strlen(line)) < sizeof(line) && l >= 2 && + line[l - 2] == '\\' && line[l - 1] == '\n') { + char *cont = fgets( + line + l - 2, sizeof(line) - l + 1, stream); + if (cont == NULL) + break; + } + } + tline = line; + while (isspace(*tline)) + tline++; + if (debugging) { + fvwm_msg( + DBG, "ReadSubFunc", "about to exec: '%s'", tline); + } + ExecuteFunction(tline, tmp_win, eventp, context, *Module); + } + + if (piperead) + stop_pipe_process(&child, timed_out, cmdname, ofilename); + else + fclose(stream); + if (piperead && ofilename) + free(ofilename); + last_read_failed = timed_out; } -void ReadFile(XEvent *eventp,Window junk,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +ReadFile(XEvent *eventp, Window junk, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - int this_read = numfilesread; - - if (debugging) - { - fvwm_msg(DBG,"ReadFile","about to attempt '%s'",action); - } - - ReadSubFunc(eventp,junk,tmp_win,context,action,Module,0); - - if (last_read_failed && this_read == 0) - { - fvwm_msg(INFO,"Read","trying to read system rc file"); - ExecuteFunction((char *)read_system_rc_cmd,NULL,&Event,C_ROOT,-1); - } - - if (this_read == 0) - { - if (debugging) - { - fvwm_msg(DBG,"ReadFile","about to call startup functions"); - } - StartupStuff(); - } + int this_read = numfilesread; + + if (debugging) { + fvwm_msg(DBG, "ReadFile", "about to attempt '%s'", action); + } + + ReadSubFunc(eventp, junk, tmp_win, context, action, Module, 0); + + if (last_read_failed && this_read == 0) { + fvwm_msg(INFO, "Read", "trying to read system rc file"); + ExecuteFunction( + (char *)read_system_rc_cmd, NULL, &Event, C_ROOT, -1); + } + + if (this_read == 0) { + if (debugging) { + fvwm_msg( + DBG, "ReadFile", "about to call startup functions"); + } + StartupStuff(); + } } -void PipeRead(XEvent *eventp,Window junk,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +PipeRead(XEvent *eventp, Window junk, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - int this_read = numfilesread; - - if (debugging) - { - fvwm_msg(DBG,"PipeRead","about to attempt '%s'",action); - } - - ReadSubFunc(eventp,junk,tmp_win,context,action,Module,1); - - if (last_read_failed && this_read == 0) - { - fvwm_msg(INFO,"PipeRead","trying to read system rc file"); - ExecuteFunction((char *)read_system_rc_cmd,NULL,&Event,C_ROOT,-1); - } - - if (this_read == 0) - { - if (debugging) - { - fvwm_msg(DBG,"PipeRead","about to call startup functions"); - } - StartupStuff(); - } -} + int this_read = numfilesread; + + if (debugging) { + fvwm_msg(DBG, "PipeRead", "about to attempt '%s'", action); + } + ReadSubFunc(eventp, junk, tmp_win, context, action, Module, 1); + + if (last_read_failed && this_read == 0) { + fvwm_msg(INFO, "PipeRead", "trying to read system rc file"); + ExecuteFunction( + (char *)read_system_rc_cmd, NULL, &Event, C_ROOT, -1); + } + + if (this_read == 0) { + if (debugging) { + fvwm_msg( + DBG, "PipeRead", "about to call startup functions"); + } + StartupStuff(); + } +} Index: fvwm/fvwm/resize.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/resize.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/resize.c --- fvwm/fvwm/resize.c +++ fvwm/fvwm/resize.c @@ -1,4 +1,3 @@ - /**************************************************************************** * This module is all original code * by Rob Nation @@ -7,27 +6,25 @@ * copyright remains in the source code and all documentation ****************************************************************************/ - /*********************************************************************** * * window resizing borrowed from the "wm" window manager * ***********************************************************************/ -#include "config.h" - -#include #include +#include + +#include "config.h" #include "fvwm.h" #include "misc.h" -#include "screen.h" #include "parse.h" +#include "screen.h" -typedef struct geom -{ - int x; - int y; - int width; - int height; +typedef struct geom { + int x; + int y; + int width; + int height; } geom; /* DO NOT USE (STATIC) GLOBALS IN THIS MODULE! @@ -37,282 +34,279 @@ typedef struct geom extern int menuFromFrameOrWindowOrTitlebar; extern Window PressedW; -static void DoResize(int x_root, int y_root, FvwmWindow *tmp_win, - geom *drag, geom *orig, int *xmotionp, int *ymotionp); +static void DoResize(int x_root, int y_root, FvwmWindow *tmp_win, geom *drag, + geom *orig, int *xmotionp, int *ymotionp); /**************************************************************************** * * Starts a window resize operation * ****************************************************************************/ -void resize_window(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int *Module) +void +resize_window(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - Bool finished = FALSE, done = FALSE, abort = FALSE; - int x,y,delta_x,delta_y,stashed_x,stashed_y; - Window ResizeWindow; - Bool flags; - Bool fButtonAbort = False; - int val1, val2, val1_unit,val2_unit,n; - unsigned int button_mask = 0; - geom sdrag; - geom sorig; - geom *drag = &sdrag; - geom *orig = &sorig; - int ymotion=0, xmotion = 0; - - if (DeferExecution(eventp,&w,&tmp_win,&context, MOVE, ButtonPress)) - return; - - if (tmp_win == NULL) - return; - - XQueryPointer( dpy, Scr.Root, &JunkRoot, &JunkChild, - &JunkX, &JunkY, &JunkX, &JunkY, &button_mask); - button_mask &= Button1Mask|Button2Mask|Button3Mask|Button4Mask|Button5Mask; - - if(check_allowed_function2(F_RESIZE,tmp_win) == 0 + Bool finished = FALSE, done = FALSE, abort = FALSE; + int x, y, delta_x, delta_y, stashed_x, stashed_y; + Window ResizeWindow; + Bool flags; + Bool fButtonAbort = False; + int val1, val2, val1_unit, val2_unit, n; + unsigned int button_mask = 0; + geom sdrag; + geom sorig; + geom *drag = &sdrag; + geom *orig = &sorig; + int ymotion = 0, xmotion = 0; + + if (DeferExecution(eventp, &w, &tmp_win, &context, MOVE, ButtonPress)) + return; + + if (tmp_win == NULL) + return; + + XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, &JunkX, &JunkY, + &JunkX, &JunkY, &button_mask); + button_mask &= + Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask; + + if (check_allowed_function2(F_RESIZE, tmp_win) == 0 #ifdef WINDOWSHADE - || (tmp_win->buttons & WSHADE) + || (tmp_win->buttons & WSHADE) #endif - ) - { - XBell(dpy, 0); - return; - } - n = GetTwoArguments(action, &val1, &val2, &val1_unit, &val2_unit); - - tmp_win->flags &= ~MAXIMIZED; - - /* Already checked this in functions.c, but its here too incase - * there's a resize on initial placement. */ - if(check_allowed_function2(F_RESIZE,tmp_win) == 0) - { - XBell(dpy, 0); - return; - } - /* can't resize icons */ - if(tmp_win->flags & ICONIFIED) - return; - - ResizeWindow = tmp_win->frame; - - if(n == 2) - { - drag->width = val1*val1_unit/100; - drag->height = val2*val2_unit/100; - drag->width += (2*tmp_win->boundary_width); - drag->height += (tmp_win->title_height + 2*tmp_win->boundary_width); - - /* size will be less or equal to requested */ - ConstrainSize (tmp_win, &drag->width, &drag->height, False, xmotion, - ymotion); - SetupFrame (tmp_win, tmp_win->frame_x, - tmp_win->frame_y ,drag->width, drag->height,FALSE); - - ResizeWindow = None; - return; - } - - InstallRootColormap(); - - if(!GrabEm(MOVE)) - { - XBell(dpy, 0); - return; - } - - MyXGrabServer(dpy); - - - /* handle problems with edge-wrapping while resizing */ - flags = Scr.flags; - Scr.flags &= ~(EdgeWrapX|EdgeWrapY); - - XGetGeometry(dpy, (Drawable) ResizeWindow, &JunkRoot, - &drag->x, &drag->y, (unsigned int *)&drag->width, - (unsigned int *)&drag->height, &JunkBW,&JunkDepth); - - drag->x += tmp_win->bw; - drag->y += tmp_win->bw; - orig->x = drag->x; - orig->y = drag->y; - orig->width = drag->width; - orig->height = drag->height; - ymotion=xmotion=0; - - /* pop up a resize dimensions window */ - XMapRaised(dpy, Scr.SizeWindow); - DisplaySize(tmp_win, orig->width, orig->height,True,True); - - /* Get the current position to determine which border to resize */ - if((PressedW != Scr.Root)&&(PressedW != None)) - { - if(PressedW == tmp_win->sides[0]) /* top */ - ymotion = 1; - if(PressedW == tmp_win->sides[1]) /* right */ - xmotion = -1; - if(PressedW == tmp_win->sides[2]) /* bottom */ - ymotion = -1; - if(PressedW == tmp_win->sides[3]) /* left */ - xmotion = 1; - if(PressedW == tmp_win->corners[0]) /* upper-left */ - { - ymotion = 1; - xmotion = 1; - } - if(PressedW == tmp_win->corners[1]) /* upper-right */ - { - xmotion = -1; - ymotion = 1; + ) { + XBell(dpy, 0); + return; } - if(PressedW == tmp_win->corners[2]) /* lower left */ - { - ymotion = -1; - xmotion = 1; + n = GetTwoArguments(action, &val1, &val2, &val1_unit, &val2_unit); + + tmp_win->flags &= ~MAXIMIZED; + + /* Already checked this in functions.c, but its here too incase + * there's a resize on initial placement. */ + if (check_allowed_function2(F_RESIZE, tmp_win) == 0) { + XBell(dpy, 0); + return; } - if(PressedW == tmp_win->corners[3]) /* lower right */ - { - ymotion = -1; - xmotion = -1; + /* can't resize icons */ + if (tmp_win->flags & ICONIFIED) + return; + + ResizeWindow = tmp_win->frame; + + if (n == 2) { + drag->width = val1 * val1_unit / 100; + drag->height = val2 * val2_unit / 100; + drag->width += (2 * tmp_win->boundary_width); + drag->height += + (tmp_win->title_height + 2 * tmp_win->boundary_width); + + /* size will be less or equal to requested */ + ConstrainSize(tmp_win, &drag->width, &drag->height, False, + xmotion, ymotion); + SetupFrame(tmp_win, tmp_win->frame_x, tmp_win->frame_y, + drag->width, drag->height, FALSE); + + ResizeWindow = None; + return; } - } - /* draw the rubber-band window */ - MoveOutline (Scr.Root, drag->x - tmp_win->bw, drag->y - tmp_win->bw, - drag->width - 1 + 2 * tmp_win->bw, - drag->height - 1 + 2 * tmp_win->bw); - /* kick off resizing without requiring any motion if invoked with a key press */ - if (eventp->type == KeyPress) - { - XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, - &stashed_x,&stashed_y,&JunkX, &JunkY, &JunkMask); - DoResize(stashed_x, stashed_y, tmp_win, drag, orig, &xmotion, &ymotion); - } - else - stashed_x = stashed_y = -1; - - /* loop to resize */ - while(!finished) - { - XMaskEvent(dpy, ButtonPressMask | ButtonReleaseMask | KeyPressMask | - ButtonMotionMask | PointerMotionMask | ExposureMask, &Event); - StashEventTime(&Event); - - if (Event.type == MotionNotify) - /* discard any extra motion events before a release */ - while(XCheckMaskEvent(dpy, ButtonMotionMask | ButtonReleaseMask | - PointerMotionMask,&Event)) - { - StashEventTime(&Event); - if (Event.type == ButtonRelease) break; - } - - done = FALSE; - /* Handle a limited number of key press events to allow mouseless - * operation */ - if(Event.type == KeyPress) - Keyboard_shortcuts(&Event, tmp_win, ButtonRelease); - switch(Event.type) - { - case ButtonPress: - XAllowEvents(dpy,ReplayPointer,CurrentTime); - done = TRUE; - if (((Event.xbutton.button == 1) && (button_mask & Button1Mask)) || - ((Event.xbutton.button == 2) && (button_mask & Button2Mask)) || - ((Event.xbutton.button == 3) && (button_mask & Button3Mask)) || - ((Event.xbutton.button == 4) && (button_mask & Button4Mask)) || - ((Event.xbutton.button == 5) && (button_mask & Button5Mask))) - { - /* No new button was pressed, just a delayed event */ - break; - } - /* Abort the resize if - * - the move started with a pressed button and another button - * was pressed during the operation - * - no button was started at the beginning and any button - * except button 1 was pressed. */ - if (button_mask || (Event.xbutton.button != 1)) - fButtonAbort = TRUE; - case KeyPress: - /* simple code to bag out of move - CKH */ - if (XLookupKeysym(&(Event.xkey),0) == XK_Escape || fButtonAbort) - { - abort = TRUE; - finished = TRUE; - /* return pointer if aborted resize was invoked with key */ - if (stashed_x >= 0) - XWarpPointer(dpy, None, Scr.Root, 0, 0, 0, 0, stashed_x, - stashed_y); - } - done = TRUE; - break; - - case ButtonRelease: - finished = TRUE; - done = TRUE; - break; - - case MotionNotify: - x = Event.xmotion.x_root; - y = Event.xmotion.y_root; - /* resize before paging request to prevent resize from lagging - * mouse - mab */ - DoResize(x, y, tmp_win, drag, orig, &xmotion, &ymotion); - /* need to move the viewport */ - HandlePaging(Scr.EdgeScrollX,Scr.EdgeScrollY,&x,&y, - &delta_x,&delta_y,False); - /* redraw outline if we paged - mab */ - if ( (delta_x != 0) || (delta_y != 0) ) - { - orig->x -= delta_x; - orig->y -= delta_y; - drag->x -= delta_x; - drag->y -= delta_y; - - DoResize(x, y, tmp_win, drag, orig, &xmotion, &ymotion); - } - done = TRUE; - default: - break; + + InstallRootColormap(); + + if (!GrabEm(MOVE)) { + XBell(dpy, 0); + return; } - if(!done) - { - MoveOutline(Scr.Root,0,0,0,0); - DispatchEvent(); - MoveOutline(Scr.Root, drag->x - tmp_win->bw, drag->y - tmp_win->bw, - drag->width - 1 + 2 * tmp_win->bw, - drag->height - 1 + 2 * tmp_win->bw); + MyXGrabServer(dpy); + + /* handle problems with edge-wrapping while resizing */ + flags = Scr.flags; + Scr.flags &= ~(EdgeWrapX | EdgeWrapY); + + XGetGeometry(dpy, (Drawable)ResizeWindow, &JunkRoot, &drag->x, &drag->y, + (unsigned int *)&drag->width, (unsigned int *)&drag->height, + &JunkBW, &JunkDepth); + + drag->x += tmp_win->bw; + drag->y += tmp_win->bw; + orig->x = drag->x; + orig->y = drag->y; + orig->width = drag->width; + orig->height = drag->height; + ymotion = xmotion = 0; + + /* pop up a resize dimensions window */ + XMapRaised(dpy, Scr.SizeWindow); + DisplaySize(tmp_win, orig->width, orig->height, True, True); + + /* Get the current position to determine which border to resize */ + if ((PressedW != Scr.Root) && (PressedW != None)) { + if (PressedW == tmp_win->sides[0]) /* top */ + ymotion = 1; + if (PressedW == tmp_win->sides[1]) /* right */ + xmotion = -1; + if (PressedW == tmp_win->sides[2]) /* bottom */ + ymotion = -1; + if (PressedW == tmp_win->sides[3]) /* left */ + xmotion = 1; + if (PressedW == tmp_win->corners[0]) { /* upper-left */ + ymotion = 1; + xmotion = 1; + } + if (PressedW == tmp_win->corners[1]) { /* upper-right */ + xmotion = -1; + ymotion = 1; + } + if (PressedW == tmp_win->corners[2]) { /* lower left */ + ymotion = -1; + xmotion = 1; + } + if (PressedW == tmp_win->corners[3]) { /* lower right */ + ymotion = -1; + xmotion = -1; + } + } + /* draw the rubber-band window */ + MoveOutline(Scr.Root, drag->x - tmp_win->bw, drag->y - tmp_win->bw, + drag->width - 1 + 2 * tmp_win->bw, + drag->height - 1 + 2 * tmp_win->bw); + /* kick off resizing without requiring any motion if invoked with a key + * press */ + if (eventp->type == KeyPress) { + XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, &stashed_x, + &stashed_y, &JunkX, &JunkY, &JunkMask); + DoResize(stashed_x, stashed_y, tmp_win, drag, orig, &xmotion, + &ymotion); + } else + stashed_x = stashed_y = -1; + + /* loop to resize */ + while (!finished) { + XMaskEvent(dpy, + ButtonPressMask | ButtonReleaseMask | KeyPressMask | + ButtonMotionMask | PointerMotionMask | ExposureMask, + &Event); + StashEventTime(&Event); + + if (Event.type == MotionNotify) + /* discard any extra motion events before a release */ + while (XCheckMaskEvent(dpy, + ButtonMotionMask | ButtonReleaseMask | + PointerMotionMask, + &Event)) { + StashEventTime(&Event); + if (Event.type == ButtonRelease) + break; + } + + done = FALSE; + /* Handle a limited number of key press events to allow + * mouseless operation */ + if (Event.type == KeyPress) + Keyboard_shortcuts(&Event, tmp_win, ButtonRelease); + switch (Event.type) { + case ButtonPress: + XAllowEvents(dpy, ReplayPointer, CurrentTime); + done = TRUE; + if (((Event.xbutton.button == 1) && + (button_mask & Button1Mask)) || + ((Event.xbutton.button == 2) && + (button_mask & Button2Mask)) || + ((Event.xbutton.button == 3) && + (button_mask & Button3Mask)) || + ((Event.xbutton.button == 4) && + (button_mask & Button4Mask)) || + ((Event.xbutton.button == 5) && + (button_mask & Button5Mask))) { + /* No new button was pressed, just a delayed + * event */ + break; + } + /* Abort the resize if + * - the move started with a pressed button and another + * button was pressed during the operation + * - no button was started at the beginning and any + * button except button 1 was pressed. */ + if (button_mask || (Event.xbutton.button != 1)) + fButtonAbort = TRUE; + case KeyPress: + /* simple code to bag out of move - CKH */ + if (XLookupKeysym(&(Event.xkey), 0) == XK_Escape || + fButtonAbort) { + abort = TRUE; + finished = TRUE; + /* return pointer if aborted resize was invoked + * with key */ + if (stashed_x >= 0) + XWarpPointer(dpy, None, Scr.Root, 0, 0, + 0, 0, stashed_x, stashed_y); + } + done = TRUE; + break; + + case ButtonRelease: + finished = TRUE; + done = TRUE; + break; + + case MotionNotify: + x = Event.xmotion.x_root; + y = Event.xmotion.y_root; + /* resize before paging request to prevent resize from + * lagging mouse - mab */ + DoResize(x, y, tmp_win, drag, orig, &xmotion, &ymotion); + /* need to move the viewport */ + HandlePaging(Scr.EdgeScrollX, Scr.EdgeScrollY, &x, &y, + &delta_x, &delta_y, False); + /* redraw outline if we paged - mab */ + if ((delta_x != 0) || (delta_y != 0)) { + orig->x -= delta_x; + orig->y -= delta_y; + drag->x -= delta_x; + drag->y -= delta_y; + + DoResize(x, y, tmp_win, drag, orig, &xmotion, + &ymotion); + } + done = TRUE; + default: + break; + } + if (!done) { + MoveOutline(Scr.Root, 0, 0, 0, 0); + DispatchEvent(); + MoveOutline(Scr.Root, drag->x - tmp_win->bw, + drag->y - tmp_win->bw, + drag->width - 1 + 2 * tmp_win->bw, + drag->height - 1 + 2 * tmp_win->bw); + } } - } - - /* erase the rubber-band */ - MoveOutline(Scr.Root, 0, 0, 0, 0); - - /* pop down the size window */ - XUnmapWindow(dpy, Scr.SizeWindow); - - if(!abort) - { - /* size will be >= to requested */ - ConstrainSize (tmp_win, &drag->width, &drag->height, True, xmotion, - ymotion); - SetupFrame (tmp_win, drag->x - tmp_win->bw, - drag->y - tmp_win->bw, drag->width, drag->height,FALSE); - } - UninstallRootColormap(); - ResizeWindow = None; - MyXUngrabServer(dpy); - UngrabEm(); - xmotion = 0; - ymotion = 0; - WaitForButtonsUp(); - - Scr.flags |= flags & (EdgeWrapX|EdgeWrapY); - return; -} + /* erase the rubber-band */ + MoveOutline(Scr.Root, 0, 0, 0, 0); + /* pop down the size window */ + XUnmapWindow(dpy, Scr.SizeWindow); + + if (!abort) { + /* size will be >= to requested */ + ConstrainSize(tmp_win, &drag->width, &drag->height, True, + xmotion, ymotion); + SetupFrame(tmp_win, drag->x - tmp_win->bw, + drag->y - tmp_win->bw, drag->width, drag->height, FALSE); + } + UninstallRootColormap(); + ResizeWindow = None; + MyXUngrabServer(dpy); + UngrabEm(); + xmotion = 0; + ymotion = 0; + WaitForButtonsUp(); + + Scr.flags |= flags & (EdgeWrapX | EdgeWrapY); + return; +} /*********************************************************************** * @@ -330,63 +324,57 @@ void resize_window(XEvent *eventp,Window w,FvwmWindow *tmp_win, * ymotionp - pointer to ymotion in resize_window * ************************************************************************/ -static void DoResize(int x_root, int y_root, FvwmWindow *tmp_win, - geom *drag, geom *orig, int *xmotionp, int *ymotionp) +static void +DoResize(int x_root, int y_root, FvwmWindow *tmp_win, geom *drag, geom *orig, + int *xmotionp, int *ymotionp) { - int action=0; - - if ((y_root <= orig->y) || - ((*ymotionp == 1)&&(y_root < orig->y+orig->height-1))) - { - drag->y = y_root; - drag->height = orig->y + orig->height - y_root; - action = 1; - *ymotionp = 1; - } - else if ((y_root >= orig->y + orig->height - 1)|| - ((*ymotionp == -1)&&(y_root > orig->y))) - { - drag->y = orig->y; - drag->height = 1 + y_root - drag->y; - action = 1; - *ymotionp = -1; - } - - if ((x_root <= orig->x)|| - ((*xmotionp == 1)&&(x_root < orig->x + orig->width - 1))) - { - drag->x = x_root; - drag->width = orig->x + orig->width - x_root; - action = 1; - *xmotionp = 1; - } - if ((x_root >= orig->x + orig->width - 1)|| - ((*xmotionp == -1)&&(x_root > orig->x))) - { - drag->x = orig->x; - drag->width = 1 + x_root - orig->x; - action = 1; - *xmotionp = -1; - } - - if (action) - { - /* round up to nearest OK size to keep pointer inside rubberband */ - ConstrainSize (tmp_win, &drag->width, &drag->height, True, *xmotionp, - *ymotionp); - if (*xmotionp == 1) - drag->x = orig->x + orig->width - drag->width; - if (*ymotionp == 1) - drag->y = orig->y + orig->height - drag->height; - - MoveOutline(Scr.Root, drag->x - tmp_win->bw,drag->y - tmp_win->bw, - drag->width - 1 + 2 * tmp_win->bw, - drag->height - 1 + 2 * tmp_win->bw); - } - DisplaySize(tmp_win, drag->width, drag->height,False,False); -} + int action = 0; + + if ((y_root <= orig->y) || + ((*ymotionp == 1) && (y_root < orig->y + orig->height - 1))) { + drag->y = y_root; + drag->height = orig->y + orig->height - y_root; + action = 1; + *ymotionp = 1; + } else if ((y_root >= orig->y + orig->height - 1) || + ((*ymotionp == -1) && (y_root > orig->y))) { + drag->y = orig->y; + drag->height = 1 + y_root - drag->y; + action = 1; + *ymotionp = -1; + } + if ((x_root <= orig->x) || + ((*xmotionp == 1) && (x_root < orig->x + orig->width - 1))) { + drag->x = x_root; + drag->width = orig->x + orig->width - x_root; + action = 1; + *xmotionp = 1; + } + if ((x_root >= orig->x + orig->width - 1) || + ((*xmotionp == -1) && (x_root > orig->x))) { + drag->x = orig->x; + drag->width = 1 + x_root - orig->x; + action = 1; + *xmotionp = -1; + } + if (action) { + /* round up to nearest OK size to keep pointer inside rubberband + */ + ConstrainSize(tmp_win, &drag->width, &drag->height, True, + *xmotionp, *ymotionp); + if (*xmotionp == 1) + drag->x = orig->x + orig->width - drag->width; + if (*ymotionp == 1) + drag->y = orig->y + orig->height - drag->height; + + MoveOutline(Scr.Root, drag->x - tmp_win->bw, + drag->y - tmp_win->bw, drag->width - 1 + 2 * tmp_win->bw, + drag->height - 1 + 2 * tmp_win->bw); + } + DisplaySize(tmp_win, drag->width, drag->height, False, False); +} /*********************************************************************** * @@ -399,54 +387,51 @@ static void DoResize(int x_root, int y_root, FvwmWindow *tmp_win, * height - the height of the rubber band * ***********************************************************************/ -void DisplaySize(FvwmWindow *tmp_win, int width, int height, Bool Init, - Bool resetLast) +void +DisplaySize( + FvwmWindow *tmp_win, int width, int height, Bool Init, Bool resetLast) { - char str[100]; - int dwidth,dheight,offset; - static int last_width = 0; - static int last_height = 0; - - if (resetLast) - { - last_width = 0; - last_height = 0; - } - if (last_width == width && last_height == height) - return; - - last_width = width; - last_height = height; - - dheight = height - tmp_win->title_height - 2*tmp_win->boundary_width; - dwidth = width - 2*tmp_win->boundary_width; - - dwidth -= tmp_win->hints.base_width; - dheight -= tmp_win->hints.base_height; - dwidth /= tmp_win->hints.width_inc; - dheight /= tmp_win->hints.height_inc; - - (void) snprintf (str, sizeof(str), " %4d x %-4d ", dwidth, dheight); - offset = (Scr.SizeStringWidth + SIZE_HINDENT*2 - - XTextWidth(Scr.StdFont.font,str,strlen(str)))/2; - if(Init) - { - XClearWindow(dpy,Scr.SizeWindow); - if(Scr.d_depth >= 2) - RelieveWindow(tmp_win, - Scr.SizeWindow,0,0,Scr.SizeStringWidth+ SIZE_HINDENT*2, - Scr.StdFont.height + SIZE_VINDENT*2, - Scr.StdReliefGC, - Scr.StdShadowGC,FULL_HILITE); - } - else - { - XClearArea(dpy, Scr.SizeWindow, SIZE_HINDENT, SIZE_VINDENT, - Scr.SizeStringWidth, Scr.StdFont.height,False); - } - - XDrawString (dpy, Scr.SizeWindow, Scr.StdGC, - offset, Scr.StdFont.font->ascent + SIZE_VINDENT, str, 13); + char str[100]; + int dwidth, dheight, offset; + static int last_width = 0; + static int last_height = 0; + + if (resetLast) { + last_width = 0; + last_height = 0; + } + if (last_width == width && last_height == height) + return; + + last_width = width; + last_height = height; + + dheight = height - tmp_win->title_height - 2 * tmp_win->boundary_width; + dwidth = width - 2 * tmp_win->boundary_width; + + dwidth -= tmp_win->hints.base_width; + dheight -= tmp_win->hints.base_height; + dwidth /= tmp_win->hints.width_inc; + dheight /= tmp_win->hints.height_inc; + + (void)snprintf(str, sizeof(str), " %4d x %-4d ", dwidth, dheight); + offset = (Scr.SizeStringWidth + SIZE_HINDENT * 2 - + XTextWidth(Scr.StdFont.font, str, strlen(str))) / + 2; + if (Init) { + XClearWindow(dpy, Scr.SizeWindow); + if (Scr.d_depth >= 2) + RelieveWindow(tmp_win, Scr.SizeWindow, 0, 0, + Scr.SizeStringWidth + SIZE_HINDENT * 2, + Scr.StdFont.height + SIZE_VINDENT * 2, + Scr.StdReliefGC, Scr.StdShadowGC, FULL_HILITE); + } else { + XClearArea(dpy, Scr.SizeWindow, SIZE_HINDENT, SIZE_VINDENT, + Scr.SizeStringWidth, Scr.StdFont.height, False); + } + + XDrawString(dpy, Scr.SizeWindow, Scr.StdGC, offset, + Scr.StdFont.font->ascent + SIZE_VINDENT, str, 13); } /*********************************************************************** @@ -460,146 +445,144 @@ void DisplaySize(FvwmWindow *tmp_win, int width, int height, Bool Init, * ***********************************************************************/ -void ConstrainSize (FvwmWindow *tmp_win, int *widthp, int *heightp, - Bool roundUp, int xmotion, int ymotion) +void +ConstrainSize(FvwmWindow *tmp_win, int *widthp, int *heightp, Bool roundUp, + int xmotion, int ymotion) { -#define makemult(a,b) ((b==1) ? (a) : (((int)((a)/(b))) * (b)) ) -#define _min(a,b) (((a) < (b)) ? (a) : (b)) - int minWidth, minHeight, maxWidth, maxHeight, xinc, yinc, delta; - int baseWidth, baseHeight; - int dwidth = *widthp, dheight = *heightp; - int constrainx, constrainy; - - /* roundUp is True if called from an interactive resize */ - if (roundUp) - { - constrainx = tmp_win->hints.width_inc - 1; - constrainy = tmp_win->hints.height_inc - 1; - } - else - { - constrainx = 0; - constrainy = 0; - } - dwidth -= 2 *tmp_win->boundary_width; - dheight -= (tmp_win->title_height + 2*tmp_win->boundary_width); - - minWidth = tmp_win->hints.min_width; - minHeight = tmp_win->hints.min_height; - - baseWidth = tmp_win->hints.base_width; - baseHeight = tmp_win->hints.base_height; - - maxWidth = tmp_win->hints.max_width; - maxHeight = tmp_win->hints.max_height; - -/* maxWidth = Scr.VxMax + Scr.MyDisplayWidth; - maxHeight = Scr.VyMax + Scr.MyDisplayHeight;*/ - - xinc = tmp_win->hints.width_inc; - yinc = tmp_win->hints.height_inc; - - /* - * First, clamp to min and max values - */ - if (dwidth < minWidth) dwidth = minWidth; - if (dheight < minHeight) dheight = minHeight; - - if (dwidth > maxWidth) dwidth = maxWidth; - if (dheight > maxHeight) dheight = maxHeight; - - - /* - * Second, round to base + N * inc (up or down depending on resize type) - */ - dwidth = ((dwidth - baseWidth + constrainx) / xinc * xinc) + baseWidth; - dheight = ((dheight - baseHeight + constrainy) / yinc * yinc) + baseHeight; - - - /* - * Third, adjust for aspect ratio - */ +#define makemult(a, b) ((b == 1) ? (a) : (((int)((a) / (b))) * (b))) +#define _min(a, b) (((a) < (b)) ? (a) : (b)) + int minWidth, minHeight, maxWidth, maxHeight, xinc, yinc, delta; + int baseWidth, baseHeight; + int dwidth = *widthp, dheight = *heightp; + int constrainx, constrainy; + + /* roundUp is True if called from an interactive resize */ + if (roundUp) { + constrainx = tmp_win->hints.width_inc - 1; + constrainy = tmp_win->hints.height_inc - 1; + } else { + constrainx = 0; + constrainy = 0; + } + dwidth -= 2 * tmp_win->boundary_width; + dheight -= (tmp_win->title_height + 2 * tmp_win->boundary_width); + + minWidth = tmp_win->hints.min_width; + minHeight = tmp_win->hints.min_height; + + baseWidth = tmp_win->hints.base_width; + baseHeight = tmp_win->hints.base_height; + + maxWidth = tmp_win->hints.max_width; + maxHeight = tmp_win->hints.max_height; + + /* maxWidth = Scr.VxMax + Scr.MyDisplayWidth; + maxHeight = Scr.VyMax + Scr.MyDisplayHeight;*/ + + xinc = tmp_win->hints.width_inc; + yinc = tmp_win->hints.height_inc; + + /* + * First, clamp to min and max values + */ + if (dwidth < minWidth) + dwidth = minWidth; + if (dheight < minHeight) + dheight = minHeight; + + if (dwidth > maxWidth) + dwidth = maxWidth; + if (dheight > maxHeight) + dheight = maxHeight; + + /* + * Second, round to base + N * inc (up or down depending on resize type) + */ + dwidth = ((dwidth - baseWidth + constrainx) / xinc * xinc) + baseWidth; + dheight = + ((dheight - baseHeight + constrainy) / yinc * yinc) + baseHeight; + + /* + * Third, adjust for aspect ratio + */ #define maxAspectX tmp_win->hints.max_aspect.x #define maxAspectY tmp_win->hints.max_aspect.y #define minAspectX tmp_win->hints.min_aspect.x #define minAspectY tmp_win->hints.min_aspect.y - /* - * The math looks like this: - * - * minAspectX dwidth maxAspectX - * ---------- <= ------- <= ---------- - * minAspectY dheight maxAspectY - * - * If that is multiplied out, then the width and height are - * invalid in the following situations: - * - * minAspectX * dheight > minAspectY * dwidth - * maxAspectX * dheight < maxAspectY * dwidth - * - */ - - if (tmp_win->hints.flags & PAspect) - { - if ((minAspectX * dheight > minAspectY * dwidth)&&(xmotion == 0)) - { - /* Change width to match */ - delta = makemult(minAspectX * dheight / minAspectY - dwidth, - xinc); - if (dwidth + delta <= maxWidth) - dwidth += delta; - } - if (minAspectX * dheight > minAspectY * dwidth) - { - delta = makemult(dheight - dwidth*minAspectY/minAspectX, - yinc); - if (dheight - delta >= minHeight) - dheight -= delta; - else - { - delta = makemult(minAspectX*dheight / minAspectY - dwidth, - xinc); - if (dwidth + delta <= maxWidth) - dwidth += delta; - } - } - - if ((maxAspectX * dheight < maxAspectY * dwidth)&&(ymotion == 0)) - { - delta = makemult(dwidth * maxAspectY / maxAspectX - dheight, - yinc); - if (dheight + delta <= maxHeight) - dheight += delta; - } - if ((maxAspectX * dheight < maxAspectY * dwidth)) - { - delta = makemult(dwidth - maxAspectX*dheight/maxAspectY, - xinc); - if (dwidth - delta >= minWidth) - dwidth -= delta; - else - { - delta = makemult(dwidth * maxAspectY / maxAspectX - dheight, - yinc); - if (dheight + delta <= maxHeight) - dheight += delta; - } - } - } - - /* - * Fourth, account for border width and title height - */ - *widthp = dwidth + 2*tmp_win->boundary_width; - *heightp = dheight + tmp_win->title_height + 2*tmp_win->boundary_width; + /* + * The math looks like this: + * + * minAspectX dwidth maxAspectX + * ---------- <= ------- <= ---------- + * minAspectY dheight maxAspectY + * + * If that is multiplied out, then the width and height are + * invalid in the following situations: + * + * minAspectX * dheight > minAspectY * dwidth + * maxAspectX * dheight < maxAspectY * dwidth + * + */ + + if (tmp_win->hints.flags & PAspect) { + if ((minAspectX * dheight > minAspectY * dwidth) && + (xmotion == 0)) { + /* Change width to match */ + delta = makemult( + minAspectX * dheight / minAspectY - dwidth, xinc); + if (dwidth + delta <= maxWidth) + dwidth += delta; + } + if (minAspectX * dheight > minAspectY * dwidth) { + delta = makemult( + dheight - dwidth * minAspectY / minAspectX, yinc); + if (dheight - delta >= minHeight) + dheight -= delta; + else { + delta = makemult( + minAspectX * dheight / minAspectY - dwidth, + xinc); + if (dwidth + delta <= maxWidth) + dwidth += delta; + } + } + + if ((maxAspectX * dheight < maxAspectY * dwidth) && + (ymotion == 0)) { + delta = makemult( + dwidth * maxAspectY / maxAspectX - dheight, yinc); + if (dheight + delta <= maxHeight) + dheight += delta; + } + if ((maxAspectX * dheight < maxAspectY * dwidth)) { + delta = makemult( + dwidth - maxAspectX * dheight / maxAspectY, xinc); + if (dwidth - delta >= minWidth) + dwidth -= delta; + else { + delta = makemult( + dwidth * maxAspectY / maxAspectX - dheight, + yinc); + if (dheight + delta <= maxHeight) + dheight += delta; + } + } + } + + /* + * Fourth, account for border width and title height + */ + *widthp = dwidth + 2 * tmp_win->boundary_width; + *heightp = + dheight + tmp_win->title_height + 2 * tmp_win->boundary_width; #ifdef WINDOWSHADE - if (tmp_win->buttons & WSHADE) - *heightp = tmp_win->title_height + tmp_win->boundary_width; + if (tmp_win->buttons & WSHADE) + *heightp = tmp_win->title_height + tmp_win->boundary_width; #endif - return; + return; } - /*********************************************************************** * * Procedure: @@ -613,52 +596,49 @@ void ConstrainSize (FvwmWindow *tmp_win, int *widthp, int *heightp, * height - the height of the rectangle * ***********************************************************************/ -void MoveOutline(Window root, int x, int y, int width, int height) +void +MoveOutline(Window root, int x, int y, int width, int height) { - static int lastx = 0; - static int lasty = 0; - static int lastWidth = 0; - static int lastHeight = 0; - char draw; - XRectangle rects[5]; - - if (x == lastx && y == lasty && width == lastWidth && height == lastHeight) - return; - - /* undraw the old one, if any */ - /* draw the new one, if any */ - draw = 0; - while (1) - { - if (lastWidth || lastHeight) - { - int i; - - for (i=0; i < 4; i++) - { - rects[i].x = lastx + i; - rects[i].y = lasty + i; - rects[i].width = lastWidth - (i << 1); - rects[i].height = lastHeight - (i << 1); - } - rects[3].y = lasty+3 + (lastHeight-6)/3; - rects[3].height = (lastHeight-6)/3; - rects[4].x = lastx+3 + (lastWidth-6)/3; - rects[4].y = lasty+3; - rects[4].width = (lastWidth-6)/3; - rects[4].height = (lastHeight-6); - XDrawRectangles(dpy,Scr.Root,Scr.DrawGC,rects,5); - } - draw++; - - if (draw < 2) - { - lastx = x; - lasty = y; - lastWidth = width; - lastHeight = height; - } - else - break; - } + static int lastx = 0; + static int lasty = 0; + static int lastWidth = 0; + static int lastHeight = 0; + char draw; + XRectangle rects[5]; + + if (x == lastx && y == lasty && width == lastWidth && + height == lastHeight) + return; + + /* undraw the old one, if any */ + /* draw the new one, if any */ + draw = 0; + while (1) { + if (lastWidth || lastHeight) { + int i; + + for (i = 0; i < 4; i++) { + rects[i].x = lastx + i; + rects[i].y = lasty + i; + rects[i].width = lastWidth - (i << 1); + rects[i].height = lastHeight - (i << 1); + } + rects[3].y = lasty + 3 + (lastHeight - 6) / 3; + rects[3].height = (lastHeight - 6) / 3; + rects[4].x = lastx + 3 + (lastWidth - 6) / 3; + rects[4].y = lasty + 3; + rects[4].width = (lastWidth - 6) / 3; + rects[4].height = (lastHeight - 6); + XDrawRectangles(dpy, Scr.Root, Scr.DrawGC, rects, 5); + } + draw++; + + if (draw < 2) { + lastx = x; + lasty = y; + lastWidth = width; + lastHeight = height; + } else + break; + } } Index: fvwm/fvwm/screen.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/screen.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/screen.h --- fvwm/fvwm/screen.h +++ fvwm/fvwm/screen.h @@ -35,28 +35,28 @@ #include #include #include -#include "misc.h" + #include "menus.h" +#include "misc.h" #define SIZE_HINDENT 5 #define SIZE_VINDENT 3 #define MAX_WINDOW_WIDTH 32767 #define MAX_WINDOW_HEIGHT 32767 - /* Cursor types */ -#define POSITION 0 /* upper Left corner cursor */ -#define TITLE_CURSOR 1 /* title-bar cursor */ -#define DEFAULT 2 /* cursor for apps to inherit */ -#define SYS 3 /* sys-menu and iconify boxes cursor */ -#define MOVE 4 /* resize cursor */ +#define POSITION 0 /* upper Left corner cursor */ +#define TITLE_CURSOR 1 /* title-bar cursor */ +#define DEFAULT 2 /* cursor for apps to inherit */ +#define SYS 3 /* sys-menu and iconify boxes cursor */ +#define MOVE 4 /* resize cursor */ #ifdef WAIT #undef WAIT -#endif /*WAIT */ -#define WAIT 5 /* wait a while cursor */ -#define MENU 6 /* menu cursor */ -#define SELECT 7 /* dot cursor for f.move, etc. from menus */ -#define DESTROY 8 /* skull and cross bones, f.destroy */ +#endif /*WAIT */ +#define WAIT 5 /* wait a while cursor */ +#define MENU 6 /* menu cursor */ +#define SELECT 7 /* dot cursor for f.move, etc. from menus */ +#define DESTROY 8 /* skull and cross bones, f.destroy */ #define TOP 9 #define RIGHT 10 #define BOTTOM 11 @@ -71,271 +71,258 @@ #define COLORMAP_FOLLOWS_MOUSE 1 /* default */ #define COLORMAP_FOLLOWS_FOCUS 2 - #ifndef NON_VIRTUAL -typedef struct -{ - Window win; - int isMapped; +typedef struct { + Window win; + int isMapped; } PanFrame; #endif - typedef enum { - /* button types */ +/* button types */ #ifdef VECTOR_BUTTONS - VectorButton , + VectorButton, #endif - SimpleButton , + SimpleButton, #ifdef GRADIENT_BUTTONS - HGradButton , - VGradButton , + HGradButton, + VGradButton, #endif #ifdef PIXMAP_BUTTONS - PixmapButton , - TiledPixmapButton , + PixmapButton, + TiledPixmapButton, #endif #ifdef MINI_ICONS - MiniIconButton , + MiniIconButton, #endif - SolidButton - /* max button is 15 (0xF) */ + SolidButton + /* max button is 15 (0xF) */ } ButtonFaceStyle; -#define ButtonFaceTypeMask 0x000F +#define ButtonFaceTypeMask 0x000F /* button style flags (per-state) */ enum { - - /* specific style flags */ - /* justification bits (3.17 -> 4 bits) */ - HOffCenter = (1<<4), - HRight = (1<<5), - VOffCenter = (1<<6), - VBottom = (1<<7), - - /* general style flags */ + /* specific style flags */ + /* justification bits (3.17 -> 4 bits) */ + HOffCenter = (1 << 4), + HRight = (1 << 5), + VOffCenter = (1 << 6), + VBottom = (1 << 7), + +/* general style flags */ #ifdef EXTENDED_TITLESTYLE - UseTitleStyle = (1<<8), + UseTitleStyle = (1 << 8), #endif #ifdef BORDERSTYLE - UseBorderStyle = (1<<9), + UseBorderStyle = (1 << 9), #endif - FlatButton = (1<<10), - SunkButton = (1<<11) + FlatButton = (1 << 10), + SunkButton = (1 << 11) }; #ifdef BORDERSTYLE /* border style flags (uses ButtonFace) */ -enum { - HiddenHandles = (1<<8), - NoInset = (1<<9) -}; +enum { HiddenHandles = (1 << 8), NoInset = (1 << 9) }; #endif typedef struct ButtonFace { - ButtonFaceStyle style; - union { + ButtonFaceStyle style; + union { #ifdef PIXMAP_BUTTONS - FvwmPicture *p; + FvwmPicture *p; #endif - Pixel back; + Pixel back; #ifdef GRADIENT_BUTTONS - struct { - int npixels; - Pixel *pixels; - } grad; + struct { + int npixels; + Pixel *pixels; + } grad; #endif - } u; + } u; #ifdef VECTOR_BUTTONS - struct vector_coords { - int num; - int x[20]; - int y[20]; - int line_style[20]; - } vector; + struct vector_coords { + int num; + int x[20]; + int y[20]; + int line_style[20]; + } vector; #endif #ifdef MULTISTYLE - struct ButtonFace *next; + struct ButtonFace *next; #endif } ButtonFace; /* button style flags (per title button) */ enum { - /* MWM function hint button assignments */ - MWMDecorMenu = (1<<0), - MWMDecorMinimize = (1<<1), - MWMDecorMaximize = (1<<2) + /* MWM function hint button assignments */ + MWMDecorMenu = (1 << 0), + MWMDecorMinimize = (1 << 1), + MWMDecorMaximize = (1 << 2) }; enum ButtonState { - ActiveUp, + ActiveUp, #ifdef ACTIVEDOWN_BTNS - ActiveDown, + ActiveDown, #endif #ifdef INACTIVE_BTNS - Inactive, + Inactive, #endif - MaxButtonState + MaxButtonState }; typedef struct { - int flags; - ButtonFace state[MaxButtonState]; + int flags; + ButtonFace state[MaxButtonState]; } TitleButton; typedef struct FvwmDecor { #ifdef USEDECOR - char *tag; /* general style tag */ + char *tag; /* general style tag */ #endif - ColorPair HiColors; /* standard fore/back colors */ - ColorPair HiRelief; - GC HiReliefGC; /* GC for highlighted window relief */ - GC HiShadowGC; /* GC for highlighted window shadow */ - - int TitleHeight; /* height of the title bar window */ - MyFont WindowFont; /* font structure for window titles */ - - /* titlebar buttons */ - TitleButton left_buttons[5]; - TitleButton right_buttons[5]; - TitleButton titlebar; + ColorPair HiColors; /* standard fore/back colors */ + ColorPair HiRelief; + GC HiReliefGC; /* GC for highlighted window relief */ + GC HiShadowGC; /* GC for highlighted window shadow */ + + int TitleHeight; /* height of the title bar window */ + MyFont WindowFont; /* font structure for window titles */ + + /* titlebar buttons */ + TitleButton left_buttons[5]; + TitleButton right_buttons[5]; + TitleButton titlebar; #ifdef BORDERSTYLE - struct BorderStyle - { - ButtonFace active, inactive; - } BorderStyle; + struct BorderStyle { + ButtonFace active, inactive; + } BorderStyle; #endif #ifdef USEDECOR - struct FvwmDecor *next; /* additional user-defined styles */ + struct FvwmDecor *next; /* additional user-defined styles */ #endif } FvwmDecor; - -typedef struct ScreenInfo -{ - - unsigned long screen; - int d_depth; /* copy of DefaultDepth(dpy, screen) */ - int NumberOfScreens; /* number of screens on display */ - int MyDisplayWidth; /* my copy of DisplayWidth(dpy, screen) */ - int MyDisplayHeight; /* my copy of DisplayHeight(dpy, screen) */ - - FvwmWindow FvwmRoot; /* the head of the fvwm window list */ - Window Root; /* the root window */ - Window SizeWindow; /* the resize dimensions window */ - Window NoFocusWin; /* Window which will own focus when no other - * windows have it */ +typedef struct ScreenInfo { + unsigned long screen; + int d_depth; /* copy of DefaultDepth(dpy, screen) */ + int NumberOfScreens; /* number of screens on display */ + int MyDisplayWidth; /* my copy of DisplayWidth(dpy, screen) */ + int MyDisplayHeight; /* my copy of DisplayHeight(dpy, screen) */ + + FvwmWindow FvwmRoot; /* the head of the fvwm window list */ + Window Root; /* the root window */ + Window SizeWindow; /* the resize dimensions window */ + Window NoFocusWin; /* Window which will own focus when no other + * windows have it */ #ifndef NON_VIRTUAL - PanFrame PanFrameTop,PanFrameLeft,PanFrameRight,PanFrameBottom; + PanFrame PanFrameTop, PanFrameLeft, PanFrameRight, PanFrameBottom; #endif - Pixmap gray_bitmap; /*dark gray pattern for shaded out menu items*/ - Pixmap gray_pixmap; /* dark gray pattern for inactive borders */ - Pixmap light_gray_pixmap; /* light gray pattern for inactive borders */ - Pixmap sticky_gray_pixmap; /* light gray pattern for sticky borders */ + Pixmap gray_bitmap; /*dark gray pattern for shaded out menu items*/ + Pixmap gray_pixmap; /* dark gray pattern for inactive borders */ + Pixmap light_gray_pixmap; /* light gray pattern for inactive borders */ + Pixmap sticky_gray_pixmap; /* light gray pattern for sticky borders */ - Binding *AllBindings; + Binding *AllBindings; - int root_pushes; /* current push level to install root - colormap windows */ - FvwmWindow *pushed_window; /* saved window to install when pushes drops - to zero */ - Cursor FvwmCursors[MAX_CURSORS]; + int root_pushes; /* current push level to install root + colormap windows */ + FvwmWindow *pushed_window; /* saved window to install when pushes drops + to zero */ + Cursor FvwmCursors[MAX_CURSORS]; - name_list *TheList; /* list of window names with attributes */ - char *DefaultIcon; /* Icon to use when no other icons are found */ + name_list *TheList; /* list of window names with attributes */ + char *DefaultIcon; /* Icon to use when no other icons are found */ - ColorPair StdColors; /* standard fore/back colors */ - ColorPair StdRelief; + ColorPair StdColors; /* standard fore/back colors */ + ColorPair StdRelief; - MenuGlobals menus; + MenuGlobals menus; - MyFont StdFont; /* font structure */ - MyFont IconFont; /* for icon labels */ + MyFont StdFont; /* font structure */ + MyFont IconFont; /* for icon labels */ #if defined(PIXMAP_BUTTONS) || defined(GRADIENT_BUTTONS) - GC TransMaskGC; /* GC for transparency masks */ + GC TransMaskGC; /* GC for transparency masks */ #endif - GC StdGC; - GC StdReliefGC; - GC StdShadowGC; - GC DrawGC; /* GC to draw lines for move and resize */ - GC ScratchGC1; - GC ScratchGC2; - GC ScratchGC3; - int SizeStringWidth; /* minimum width of size window */ - int CornerWidth; /* corner width for decoratedwindows */ - int BoundaryWidth; /* frame width for decorated windows */ - int NoBoundaryWidth; /* frame width for decorated windows */ - - FvwmDecor DefaultDecor; /* decoration style(s) */ - - int nr_left_buttons; /* number of left-side title-bar buttons */ - int nr_right_buttons; /* number of right-side title-bar buttons */ - - FvwmWindow *Hilite; /* the fvwm window that is highlighted - * except for networking delays, this is the - * window which REALLY has the focus */ - FvwmWindow *Focus; /* Last window which Fvwm gave the focus to - * NOT the window that really has the focus */ - Window UnknownWinFocused; /* None, if the focus is nowhere or on an fvwm - * managed window. Set to id of otherwindow - * with focus otherwise */ - FvwmWindow *Ungrabbed; - FvwmWindow *PreviousFocus; /* Window which had focus before fvwm stole it - * to do moves/menus/etc. */ - int EdgeScrollX; /* #pixels to scroll on screen edge */ - int EdgeScrollY; /* #pixels to scroll on screen edge */ - unsigned char buttons2grab; /* buttons to grab in click to focus mode */ - unsigned long flags; - int NumBoxes; - int randomx; /* values used for randomPlacement */ - int randomy; - FvwmWindow *LastWindowRaised; /* Last window which was raised. Used for raise - * lower func. */ - int VxMax; /* Max location for top left of virt desk*/ - int VyMax; - int Vx; /* Current loc for top left of virt desk */ - int Vy; - - int ClickTime; /*Max button-click delay for Function built-in*/ - int ScrollResistance; /* resistance to scrolling in desktop */ - int MoveResistance; /* res to moving windows over viewport edge */ - int SnapAttraction; /* attractiveness of window edges */ - int SnapMode; /* mode of snap attraction */ - int SnapGridX; /* snap grid X size */ - int SnapGridY; /* snap grid Y size */ - int OpaqueSize; - int CurrentDesk; /* The current desktop number */ - int ColormapFocus; /* colormap focus style */ - int ColorLimit; /* Limit on colors used in pixmaps */ - - /* - ** some additional global options which will probably become window - ** specific options later on: - */ - int SmartPlacementIsClever; - int ClickToFocusPassesClick; - int ClickToFocusRaises; - int MouseFocusClickRaises; - int StipledTitles; - struct - { - Bool ModifyUSP : 1; /* - RBW - 11/02/1998 */ - Bool CaptureHonorsStartsOnPage : 1; /* - RBW - 11/02/1998 */ - Bool RecaptureHonorsStartsOnPage : 1; /* - RBW - 11/02/1998 */ - Bool ActivePlacementHonorsStartsOnPage : 1; /* - RBW - 11/02/1998 */ - } go; /* global options */ - struct - { - Bool EmulateMWM : 1; - Bool EmulateWIN : 1; - } gs; /* global style structure */ - Bool hasIconFont; - Bool hasWindowFont; + GC StdGC; + GC StdReliefGC; + GC StdShadowGC; + GC DrawGC; /* GC to draw lines for move and resize */ + GC ScratchGC1; + GC ScratchGC2; + GC ScratchGC3; + int SizeStringWidth; /* minimum width of size window */ + int CornerWidth; /* corner width for decoratedwindows */ + int BoundaryWidth; /* frame width for decorated windows */ + int NoBoundaryWidth; /* frame width for decorated windows */ + + FvwmDecor DefaultDecor; /* decoration style(s) */ + + int nr_left_buttons; /* number of left-side title-bar buttons */ + int nr_right_buttons; /* number of right-side title-bar buttons */ + + FvwmWindow *Hilite; /* the fvwm window that is highlighted + * except for networking delays, this is the + * window which REALLY has the focus */ + FvwmWindow *Focus; /* Last window which Fvwm gave the focus to + * NOT the window that really has the focus */ + Window UnknownWinFocused; /* None, if the focus is nowhere or on an fvwm + * managed window. Set to id of otherwindow + * with focus otherwise */ + FvwmWindow *Ungrabbed; + FvwmWindow *PreviousFocus; /* Window which had focus before fvwm stole + * it to do moves/menus/etc. */ + int EdgeScrollX; /* #pixels to scroll on screen edge */ + int EdgeScrollY; /* #pixels to scroll on screen edge */ + unsigned char buttons2grab; /* buttons to grab in click to focus mode */ + unsigned long flags; + int NumBoxes; + int randomx; /* values used for randomPlacement */ + int randomy; + FvwmWindow *LastWindowRaised; /* Last window which was raised. Used for + * raise lower func. */ + int VxMax; /* Max location for top left of virt desk*/ + int VyMax; + int Vx; /* Current loc for top left of virt desk */ + int Vy; + + int ClickTime; /*Max button-click delay for Function built-in*/ + int ScrollResistance; /* resistance to scrolling in desktop */ + int MoveResistance; /* res to moving windows over viewport edge */ + int SnapAttraction; /* attractiveness of window edges */ + int SnapMode; /* mode of snap attraction */ + int SnapGridX; /* snap grid X size */ + int SnapGridY; /* snap grid Y size */ + int OpaqueSize; + int CurrentDesk; /* The current desktop number */ + int ColormapFocus; /* colormap focus style */ + int ColorLimit; /* Limit on colors used in pixmaps */ + + /* + ** some additional global options which will probably become window + ** specific options later on: + */ + int SmartPlacementIsClever; + int ClickToFocusPassesClick; + int ClickToFocusRaises; + int MouseFocusClickRaises; + int StipledTitles; + struct { + unsigned int ModifyUSP:1; /* - RBW - 11/02/1998 */ + unsigned int CaptureHonorsStartsOnPage:1; /* - RBW - 11/02/1998 */ + unsigned int RecaptureHonorsStartsOnPage:1; /* - RBW - 11/02/1998 */ + unsigned int ActivePlacementHonorsStartsOnPage:1; /* - RBW - 11/02/1998 */ + } go; /* global options */ + struct { + unsigned int EmulateMWM:1; + unsigned int EmulateWIN:1; + } gs; /* global style structure */ + Bool hasIconFont; + Bool hasWindowFont; } ScreenInfo; /* @@ -344,9 +331,9 @@ typedef struct ScreenInfo the UseDecor mechanism. */ #ifdef USEDECOR -#define GetDecor(window,part) ((window)->fl->part) +#define GetDecor(window, part) ((window)->fl->part) #else -#define GetDecor(window,part) (Scr.DefaultDecor.part) +#define GetDecor(window, part) (Scr.DefaultDecor.part) #endif /* some protos for the decoration structures */ @@ -360,10 +347,10 @@ void DestroyFvwmDecor(FvwmDecor *fl); extern ScreenInfo Scr; /* for the flags value - these used to be seperate Bool's */ -#define WindowsCaptured (1) -#define EdgeWrapX (64) /* Should EdgeScroll wrap around? */ -#define EdgeWrapY (128) -#define AnimatedMenus (1024) +#define WindowsCaptured (1) +#define EdgeWrapX (64) /* Should EdgeScroll wrap around? */ +#define EdgeWrapY (128) +#define AnimatedMenus (1024) /* Have to declare this here because FvwmDecor isn't declared in misc.h when * this gets parsed :( */ Index: fvwm/fvwm/style.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/style.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/style.c --- fvwm/fvwm/style.c +++ fvwm/fvwm/style.c @@ -21,14 +21,13 @@ * code for parsing the fvwm style command * ***********************************************************************/ -#include "config.h" - -#include -#include #include +#include #include +#include #include +#include "config.h" #include "fvwm.h" #include "menus.h" #include "misc.h" @@ -36,906 +35,1011 @@ #include "screen.h" static int Get_TBLR(char *, unsigned char *); /* prototype */ -static void AddToList(name_list *); /* prototype */ +static void AddToList(name_list *); /* prototype */ /* A macro for skipping over white space */ -#define SKIPSPACE \ - while(isspace(*restofline))restofline++; +#define SKIPSPACE \ + while (isspace(*restofline)) \ + restofline++; /* A macro for checking the command with a caseless compare */ -#define ITIS(THIS) \ - strncasecmp(restofline,THIS,sizeof(THIS)-1)==0 +#define ITIS(THIS) strncasecmp(restofline, THIS, sizeof(THIS) - 1) == 0 /* A macro for skipping over the command without counting it's size */ -#define SKIP(THIS) \ - restofline += sizeof(THIS)-1 +#define SKIP(THIS) restofline += sizeof(THIS) - 1 /* A macro for getting a non-quoted operand */ -#define GETWORD \ - SKIPSPACE; \ - tmp = restofline; \ - len = 0; \ - while((tmp != NULL)&&(*tmp != 0)&&(*tmp != ',')&& \ - (*tmp != '\n')&&(!isspace(*tmp))) { \ - tmp++; \ - len++; \ - } +#define GETWORD \ + SKIPSPACE; \ + tmp = restofline; \ + len = 0; \ + while ((tmp != NULL) && (*tmp != 0) && (*tmp != ',') && \ + (*tmp != '\n') && (!isspace(*tmp))) { \ + tmp++; \ + len++; \ + } /* A macro for getting a quoted operand */ -#define GETQUOTEDWORD \ - is_quoted = 0; \ - SKIPSPACE; \ - if (*restofline == '"') { \ - is_quoted = 1; \ - ++restofline; \ - } \ - tmp = restofline; \ - len = 0; \ - while (tmp && *tmp && \ - ((!is_quoted&&(*tmp != ',')&&(*tmp != '\n')&&(!isspace(*tmp))) \ - || (is_quoted&&(*tmp != '\n')&&(*tmp != '"')))) \ - { \ - tmp++; \ - len++; \ - } \ - if (tmp && (*tmp == '"')) ++tmp; +#define GETQUOTEDWORD \ + is_quoted = 0; \ + SKIPSPACE; \ + if (*restofline == '"') { \ + is_quoted = 1; \ + ++restofline; \ + } \ + tmp = restofline; \ + len = 0; \ + while (tmp && *tmp && \ + ((!is_quoted && (*tmp != ',') && (*tmp != '\n') && \ + (!isspace(*tmp))) || \ + (is_quoted && (*tmp != '\n') && (*tmp != '"')))) { \ + tmp++; \ + len++; \ + } \ + if (tmp && (*tmp == '"')) \ + ++tmp; /* Process a style command. First built up in a temp area. If valid, added to the list in a malloced area. */ -void ProcessNewStyle(XEvent *eventp, - Window w, - FvwmWindow *tmp_win, - unsigned long context, - char *text, - int *Module) +void +ProcessNewStyle(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *text, int *Module) { - char *line; - char *restofline,*tmp; - name_list *nptr; - int butt; /* work area for button number */ - int num,i; - /* RBW - 11/02/1998 */ - int tmpno1 = -1, tmpno2 = -1, tmpno3 = -1, spargs = 0; - /**/ + char *line; + char *restofline, *tmp; + name_list *nptr; + int butt; /* work area for button number */ + int num, i; + /* RBW - 11/02/1998 */ + int tmpno1 = -1, tmpno2 = -1, tmpno3 = -1, spargs = 0; + /**/ - name_list tname; /* temp area to build name list */ - int len = 0; - icon_boxes *which = 0; /* which current boxes to chain to */ - int is_quoted; /* for parsing args with quotes */ + name_list tname; /* temp area to build name list */ + int len = 0; + icon_boxes *which = 0; /* which current boxes to chain to */ + int is_quoted; /* for parsing args with quotes */ - memset(&tname, 0, sizeof(name_list)); /* init temp name_list area */ + memset(&tname, 0, sizeof(name_list)); /* init temp name_list area */ - restofline = GetNextToken(text,&tname.name); /* parse style name */ - /* in case there was no argument! */ - if((tname.name == NULL)||(restofline == NULL))/* If no name, or blank cmd */ - { - if (tname.name) - free(tname.name); - return; /* drop it. */ - } + restofline = GetNextToken(text, &tname.name); /* parse style name */ + /* in case there was no argument! */ + if ((tname.name == NULL) || + (restofline == NULL)) { /* If no name, or blank cmd */ + if (tname.name) + free(tname.name); + return; /* drop it. */ + } - SKIPSPACE; /* skip over white space */ - line = restofline; + SKIPSPACE; /* skip over white space */ + line = restofline; - if(restofline == NULL) - { - free(tname.name); - return; - } - while((*restofline != 0)&&(*restofline != '\n')) - { - SKIPSPACE; /* skip white space */ - /* It might make more sense to capture the whole word, fix its - case, and use strcmp, but there aren't many caseless compares - because of this "switch" on the first letter. */ - switch (tolower(restofline[0])) - { - case 'a': - if(ITIS("ACTIVEPLACEMENT")) - { - SKIP("ACTIVEPLACEMENT"); - tname.on_flags |= RANDOM_PLACE_FLAG; - } - break; - case 'b': - if(ITIS("BACKCOLOR")) - { - SKIP("BACKCOLOR"); - GETWORD; - if(len > 0) - { - tname.BackColor = safemalloc(len+1); - strncpy(tname.BackColor,restofline,len); - tname.BackColor[len] = 0; - tname.off_flags |= BACK_COLOR_FLAG; - } - restofline = tmp; - } - else if (ITIS("BUTTON")) - { - SKIP("BUTTON"); - butt = -1; /* just in case sscanf fails */ - sscanf(restofline,"%d",&butt); - GETWORD; - restofline = tmp; - SKIPSPACE; - if (butt == 0) butt = 10; - if (butt > 0 && butt <= 10) - tname.on_buttons |= (1<<(butt-1)); - } - else if(ITIS("BorderWidth")) - { - SKIP("BorderWidth"); - tname.off_flags |= BW_FLAG; - sscanf(restofline,"%d",&tname.border_width); - GETWORD; - restofline = tmp; - SKIPSPACE; - } - break; - case 'c': - if(ITIS("COLOR")) - { - SKIP("COLOR"); - SKIPSPACE; - tmp = restofline; - len = 0; - while((tmp != NULL)&&(*tmp != 0)&&(*tmp != ',')&& - (*tmp != '\n')&&(*tmp != '/')&&(!isspace(*tmp))) - { - tmp++; - len++; - } - if(len > 0) - { - tname.ForeColor = safemalloc(len+1); - strncpy(tname.ForeColor,restofline,len); - tname.ForeColor[len] = 0; - tname.off_flags |= FORE_COLOR_FLAG; - } + if (restofline == NULL) { + free(tname.name); + return; + } + while ((*restofline != 0) && (*restofline != '\n')) { + SKIPSPACE; /* skip white space */ + /* It might make more sense to capture the whole word, fix its + case, and use strcmp, but there aren't many caseless compares + because of this "switch" on the first letter. */ + switch (tolower(restofline[0])) { + case 'a': + if (ITIS("ACTIVEPLACEMENT")) { + SKIP("ACTIVEPLACEMENT"); + tname.on_flags |= RANDOM_PLACE_FLAG; + } + break; + case 'b': + if (ITIS("BACKCOLOR")) { + SKIP("BACKCOLOR"); + GETWORD; + if (len > 0) { + tname.BackColor = xmalloc(len + 1); + strncpy( + tname.BackColor, restofline, len); + tname.BackColor[len] = 0; + tname.off_flags |= BACK_COLOR_FLAG; + } + restofline = tmp; + } else if (ITIS("BUTTON")) { + SKIP("BUTTON"); + butt = -1; /* just in case sscanf fails */ + sscanf(restofline, "%d", &butt); + GETWORD; + restofline = tmp; + SKIPSPACE; + if (butt == 0) + butt = 10; + if (butt > 0 && butt <= 10) + tname.on_buttons |= (1 << (butt - 1)); + } else if (ITIS("BorderWidth")) { + SKIP("BorderWidth"); + tname.off_flags |= BW_FLAG; + sscanf(restofline, "%d", &tname.border_width); + GETWORD; + restofline = tmp; + SKIPSPACE; + } + break; + case 'c': + if (ITIS("COLOR")) { + SKIP("COLOR"); + SKIPSPACE; + tmp = restofline; + len = 0; + while ((tmp != NULL) && (*tmp != 0) && + (*tmp != ',') && (*tmp != '\n') && + (*tmp != '/') && (!isspace(*tmp))) { + tmp++; + len++; + } + if (len > 0) { + tname.ForeColor = xmalloc(len + 1); + strncpy( + tname.ForeColor, restofline, len); + tname.ForeColor[len] = 0; + tname.off_flags |= FORE_COLOR_FLAG; + } - while(isspace(*tmp))tmp++; - if(*tmp == '/') - { - tmp++; - while(isspace(*tmp))tmp++; - restofline = tmp; - len = 0; - while((tmp != NULL)&&(*tmp != 0)&&(*tmp != ',')&& - (*tmp != '\n')&&(*tmp != '/')&&(!isspace(*tmp))) - { - tmp++; - len++; - } - if(len > 0) - { - tname.BackColor = safemalloc(len+1); - strncpy(tname.BackColor,restofline,len); - tname.BackColor[len] = 0; - tname.off_flags |= BACK_COLOR_FLAG; - } - } - restofline = tmp; - } - else if(ITIS("CirculateSkipIcon")) - { - SKIP("CirculateSkipIcon"); - tname.off_flags |= CIRCULATE_SKIP_ICON_FLAG; - } - else if(ITIS("CirculateHitIcon")) - { - SKIP("CirculateHitIcon"); - tname.on_flags |= CIRCULATE_SKIP_ICON_FLAG; - } - else if(ITIS("CLICKTOFOCUS")) - { - SKIP("CLICKTOFOCUS"); - tname.off_flags |= CLICK_FOCUS_FLAG; - tname.on_flags |= SLOPPY_FOCUS_FLAG; - } - else if(ITIS("CirculateSkip")) - { - SKIP("CirculateSkip"); - tname.off_flags |= CIRCULATESKIP_FLAG; - } - else if(ITIS("CirculateHit")) - { - SKIP("CirculateHit"); - tname.on_flags |= CIRCULATESKIP_FLAG; - } - break; - case 'd': - if(ITIS("DecorateTransient")) - { - SKIP("DecorateTransient"); - tname.off_flags |= DECORATE_TRANSIENT_FLAG; - } - else if(ITIS("DUMBPLACEMENT")) - { - SKIP("DUMBPLACEMENT"); - tname.on_flags |= SMART_PLACE_FLAG; - } - break; - case 'e': - break; - case 'f': - if(ITIS("FORECOLOR")) - { - SKIP("FORECOLOR"); - GETWORD; - if(len > 0) - { - tname.ForeColor = safemalloc(len+1); - strncpy(tname.ForeColor,restofline,len); - tname.ForeColor[len] = 0; - tname.off_flags |= FORE_COLOR_FLAG; - } - restofline = tmp; - } - else if(ITIS("FVWMBUTTONS")) - { - SKIP("FVWMBUTTONS"); - tname.on_flags |= MWM_BUTTON_FLAG; - } - else if(ITIS("FVWMBORDER")) - { - SKIP("FVWMBORDER"); - tname.on_flags |= MWM_BORDER_FLAG; - } - else if(ITIS("FocusFollowsMouse")) - { - SKIP("FocusFollowsMouse"); - tname.on_flags |= CLICK_FOCUS_FLAG; - tname.on_flags |= SLOPPY_FOCUS_FLAG; - } - break; - case 'g': - break; - case 'h': - if(ITIS("HINTOVERRIDE")) - { - SKIP("HINTOVERRIDE"); - tname.off_flags |= MWM_OVERRIDE_FLAG; - } - else if(ITIS("HANDLES")) - { - SKIP("HANDLES"); - tname.on_flags |= NOBORDER_FLAG; - } - else if(ITIS("HandleWidth")) - { - SKIP("HandleWidth"); - tname.off_flags |= NOBW_FLAG; - sscanf(restofline,"%d",&tname.resize_width); - GETWORD; - restofline = tmp; - SKIPSPACE; - } - break; - case 'i': - if(ITIS("IconTitle")) - { - SKIP("IconTitle"); - tname.on_flags |= NOICON_TITLE_FLAG; - } - else if(ITIS("IconBox")) - { - icon_boxes *IconBoxes = 0; - SKIP("IconBox"); /* Skip over word "IconBox" */ - IconBoxes = (icon_boxes *)safemalloc(sizeof(icon_boxes)); - memset(IconBoxes, 0, sizeof(icon_boxes)); /* clear it */ - IconBoxes->IconGrid[0] = 3; /* init grid x */ - IconBoxes->IconGrid[1] = 3; /* init grid y */ - /* try for 4 numbers x y x y */ - num = sscanf(restofline,"%d%d%d%d", - &IconBoxes->IconBox[0], - &IconBoxes->IconBox[1], - &IconBoxes->IconBox[2], - &IconBoxes->IconBox[3]); - if (num == 4) { /* if 4 numbers */ - for(i=0;iIconBox[i] += Scr.MyDisplayWidth; - } else { /* it must be a height */ - IconBoxes->IconBox[i] += Scr.MyDisplayHeight; - } /* end width/height */ - } /* end leading minus sign */ - while((!isspace(*restofline))&&(*restofline!= 0)&& - (*restofline != ',')&&(*restofline != '\n')) - restofline++; - } - /* Note: here there is no test for valid co-ords, use geom */ - } else { /* Not 4 numeric args dje */ - char geom_string[25]; /* bigger than =32767x32767+32767+32767 */ - int geom_flags; - GETWORD; /* read in 1 word w/o advancing */ - if(len > 0 && len < 24) { /* if word found, not too long */ - strncpy(geom_string,restofline,len); /* copy and null term */ - geom_string[len] = 0; /* null terminate it */ - geom_flags=XParseGeometry(geom_string, - &IconBoxes->IconBox[0], - &IconBoxes->IconBox[1], /* x/y */ - &IconBoxes->IconBox[2], - &IconBoxes->IconBox[3]); /* width/ht */ - if (IconBoxes->IconBox[2] == 0) { /* zero width ind invalid */ - fvwm_msg(ERR,"ProcessNewStyle", - "IconBox requires 4 numbers or geometry! Invalid string <%s>.", - geom_string); - free(IconBoxes); /* Drop the box */ - IconBoxes = 0; /* forget about it */ - } else { /* got valid iconbox geom */ - if (geom_flags&XNegative) { - IconBoxes->IconBox[0] = Scr.MyDisplayWidth /* screen width */ - + IconBoxes->IconBox[0] /* neg x coord */ - - IconBoxes->IconBox[2] -2; /* width - 2 */ - } - if (geom_flags&YNegative) { - IconBoxes->IconBox[1] = Scr.MyDisplayHeight /* scr height */ - + IconBoxes->IconBox[1] /* neg y coord */ - - IconBoxes->IconBox[3] -2; /* height - 2 */ - } - IconBoxes->IconBox[2] += - IconBoxes->IconBox[0]; /* x + wid = right x */ - IconBoxes->IconBox[3] += - IconBoxes->IconBox[1]; /* y + height = bottom y */ - } /* end icon geom worked */ - } else { /* no word or too long */ - fvwm_msg(ERR,"ProcessNewStyle", - "IconBox requires 4 numbers or geometry! Too long (%d).", - len); - free(IconBoxes); /* Drop the box */ - IconBoxes = 0; /* forget about it */ - } /* end word found, not too long */ - restofline = tmp; /* got word, move past it */ - } /* end not 4 args */ - /* If we created an IconBox, put it in the chain. */ - if (IconBoxes != 0) { /* If no error */ - if (tname.IconBoxes == 0) { /* If first one */ - tname.IconBoxes = IconBoxes; /* chain to root */ - } else { /* else not first one */ - which->next = IconBoxes; /* add to end of chain */ - } /* end not first one */ - which = IconBoxes; /* new current box. save for grid */ - } /* end no error */ - } /* end iconbox parameter */ - else if(ITIS("ICONGRID")) { - SKIP("ICONGRID"); - SKIPSPACE; /* skip whitespace after keyword */ - /* The grid always affects the prior iconbox */ - if (which == 0) { /* If no current box */ - fvwm_msg(ERR,"ProcessNewStyle", - "IconGrid must follow an IconBox in same Style command"); - } else { /* have a place to grid */ - num = sscanf(restofline,"%hd%hd", /* 2 shorts */ - &which->IconGrid[0], - &which->IconGrid[1]); - if (num != 2 - || which->IconGrid[0] < 1 - || which->IconGrid[1] < 1) { - fvwm_msg(ERR,"ProcessNewStyle", - "IconGrid needs 2 numbers > 0. Got %d numbers. x=%d y=%d!", - num, (int)which->IconGrid[0], (int)which->IconGrid[1]); - which->IconGrid[0] = 3; /* reset grid x */ - which->IconGrid[1] = 3; /* reset grid y */ - } else { /* it worked */ - GETWORD; /* swallow word */ - restofline = tmp; - GETWORD; /* swallow word */ - restofline = tmp; - } /* end bad grid */ - } /* end place to grid */ - } else if(ITIS("ICONFILL")) { /* direction to fill iconbox */ - SKIP("ICONFILL"); - SKIPSPACE; /* skip whitespace after keyword */ - /* The fill always affects the prior iconbox */ - if (which == 0) { /* If no current box */ - fvwm_msg(ERR,"ProcessNewStyle", - "IconFill must follow an IconBox in same Style command"); - } else { /* have a place to fill */ - unsigned char IconFill_1; /* first type direction parsed */ - unsigned char IconFill_2; /* second type direction parsed */ - GETWORD; /* read in word for length */ - if (Get_TBLR(restofline,&IconFill_1) == 0) { /* top/bot/lft/rgt */ - fvwm_msg(ERR,"ProcessNewStyle", - "IconFill must be followed by T|B|R|L, found %.*s.", - len, restofline); /* its wrong */ - } else { /* first word valid */ - restofline = tmp; /* swallow it */ - SKIPSPACE; /* skip space between words */ - GETWORD; /* read in second word */ - if (Get_TBLR(restofline,&IconFill_2) == 0) {/* top/bot/lft/rgt */ - fvwm_msg(ERR,"ProcessNewStyle", - "IconFill must be followed by T|B|R|L, found %.*s.", - len, restofline); /* its wrong */ - } else if ((IconFill_1&ICONFILLHRZ)==(IconFill_2&ICONFILLHRZ)) { - fvwm_msg(ERR,"ProcessNewStyle", - "IconFill must specify a horizontal and vertical direction."); - } else { /* Its valid! */ - which->IconFlags |= IconFill_1; /* merge in flags */ - IconFill_2 &= ~ICONFILLHRZ; /* ignore horiz in 2nd arg */ - which->IconFlags |= IconFill_2; /* merge in flags */ - } /* end second word valid */ - } /* end first word valid */ - restofline = tmp; /* swallow first or second word */ - } /* end have a place to fill */ - } /* end iconfill */ - else if(ITIS("ICON")) - { - SKIP("ICON"); - GETWORD; - if(len > 0) - { - tname.value = safemalloc(len+1); - strncpy(tname.value,restofline,len); - tname.value[len] = 0; - tname.off_flags |= ICON_FLAG; - tname.on_flags |= SUPPRESSICON_FLAG; - } - else - tname.on_flags |= SUPPRESSICON_FLAG; - restofline = tmp; - } - break; - case 'j': - break; - case 'k': - break; - case 'l': - if(ITIS("LENIENCE")) - { - SKIP("LENIENCE"); - tname.off_flags |= LENIENCE_FLAG; - } - break; - case 'm': - if(ITIS("MWMBUTTONS")) - { - SKIP("MWMBUTTONS"); - tname.off_flags |= MWM_BUTTON_FLAG; - } + while (isspace(*tmp)) + tmp++; + if (*tmp == '/') { + tmp++; + while (isspace(*tmp)) + tmp++; + restofline = tmp; + len = 0; + while ((tmp != NULL) && (*tmp != 0) && + (*tmp != ',') && (*tmp != '\n') && + (*tmp != '/') && (!isspace(*tmp))) { + tmp++; + len++; + } + if (len > 0) { + tname.BackColor = + xmalloc(len + 1); + strncpy(tname.BackColor, + restofline, len); + tname.BackColor[len] = 0; + tname.off_flags |= + BACK_COLOR_FLAG; + } + } + restofline = tmp; + } else if (ITIS("CirculateSkipIcon")) { + SKIP("CirculateSkipIcon"); + tname.off_flags |= CIRCULATE_SKIP_ICON_FLAG; + } else if (ITIS("CirculateHitIcon")) { + SKIP("CirculateHitIcon"); + tname.on_flags |= CIRCULATE_SKIP_ICON_FLAG; + } else if (ITIS("CLICKTOFOCUS")) { + SKIP("CLICKTOFOCUS"); + tname.off_flags |= CLICK_FOCUS_FLAG; + tname.on_flags |= SLOPPY_FOCUS_FLAG; + } else if (ITIS("CirculateSkip")) { + SKIP("CirculateSkip"); + tname.off_flags |= CIRCULATESKIP_FLAG; + } else if (ITIS("CirculateHit")) { + SKIP("CirculateHit"); + tname.on_flags |= CIRCULATESKIP_FLAG; + } + break; + case 'd': + if (ITIS("DecorateTransient")) { + SKIP("DecorateTransient"); + tname.off_flags |= DECORATE_TRANSIENT_FLAG; + } else if (ITIS("DUMBPLACEMENT")) { + SKIP("DUMBPLACEMENT"); + tname.on_flags |= SMART_PLACE_FLAG; + } + break; + case 'e': + break; + case 'f': + if (ITIS("FORECOLOR")) { + SKIP("FORECOLOR"); + GETWORD; + if (len > 0) { + tname.ForeColor = xmalloc(len + 1); + strncpy( + tname.ForeColor, restofline, len); + tname.ForeColor[len] = 0; + tname.off_flags |= FORE_COLOR_FLAG; + } + restofline = tmp; + } else if (ITIS("FVWMBUTTONS")) { + SKIP("FVWMBUTTONS"); + tname.on_flags |= MWM_BUTTON_FLAG; + } else if (ITIS("FVWMBORDER")) { + SKIP("FVWMBORDER"); + tname.on_flags |= MWM_BORDER_FLAG; + } else if (ITIS("FocusFollowsMouse")) { + SKIP("FocusFollowsMouse"); + tname.on_flags |= CLICK_FOCUS_FLAG; + tname.on_flags |= SLOPPY_FOCUS_FLAG; + } + break; + case 'g': + break; + case 'h': + if (ITIS("HINTOVERRIDE")) { + SKIP("HINTOVERRIDE"); + tname.off_flags |= MWM_OVERRIDE_FLAG; + } else if (ITIS("HANDLES")) { + SKIP("HANDLES"); + tname.on_flags |= NOBORDER_FLAG; + } else if (ITIS("HandleWidth")) { + SKIP("HandleWidth"); + tname.off_flags |= NOBW_FLAG; + sscanf(restofline, "%d", &tname.resize_width); + GETWORD; + restofline = tmp; + SKIPSPACE; + } + break; + case 'i': + if (ITIS("IconTitle")) { + SKIP("IconTitle"); + tname.on_flags |= NOICON_TITLE_FLAG; + } else if (ITIS("IconBox")) { + icon_boxes *IconBoxes = 0; + SKIP("IconBox"); /* Skip over word "IconBox" */ + IconBoxes = (icon_boxes *)xmalloc( + sizeof(icon_boxes)); + memset(IconBoxes, 0, + sizeof(icon_boxes)); /* clear it */ + IconBoxes->IconGrid[0] = 3; /* init grid x */ + IconBoxes->IconGrid[1] = 3; /* init grid y */ + /* try for 4 numbers x y x y */ + num = sscanf(restofline, "%d%d%d%d", + &IconBoxes->IconBox[0], + &IconBoxes->IconBox[1], + &IconBoxes->IconBox[2], + &IconBoxes->IconBox[3]); + if (num == 4) { /* if 4 numbers */ + for (i = 0; i < num; i++) { + SKIPSPACE; + if (*restofline == + '-') { /* If leading minus + sign */ + if (i == 0 || + i == + 2) { /* if a + width */ + IconBoxes + ->IconBox + [i] += + Scr.MyDisplayWidth; + } else { /* it must be a + height */ + IconBoxes + ->IconBox + [i] += + Scr.MyDisplayHeight; + } /* end width/height */ + } /* end leading minus sign */ + while ((!isspace( + *restofline)) && + (*restofline != 0) && + (*restofline != ',') && + (*restofline != '\n')) + restofline++; + } + /* Note: here there is no test for valid + * co-ords, use geom */ + } else { /* Not 4 numeric args dje */ + char geom_string[25]; /* bigger than + =32767x32767+32767+32767 + */ + int geom_flags; + GETWORD; /* read in 1 word w/o advancing + */ + if (len > 0 && + len < 24) { /* if word found, not + too long */ + strncpy(geom_string, restofline, + len); /* copy and null term + */ + geom_string[len] = + 0; /* null terminate it */ + geom_flags = XParseGeometry( + geom_string, + &IconBoxes->IconBox[0], + &IconBoxes + ->IconBox[1], /* x/y */ + &IconBoxes->IconBox[2], + &IconBoxes->IconBox + [3]); /* width/ht + */ + if (IconBoxes->IconBox[2] == + 0) { /* zero width ind + invalid */ + fvwm_msg(ERR, + "ProcessNewStyle", + "IconBox requires " + "4 numbers or " + "geometry! " + "Invalid string " + "<%s>.", + geom_string); + free(IconBoxes); /* Drop + the + box + */ + IconBoxes = + 0; /* forget about + it */ + } else { /* got valid iconbox + geom */ + if (geom_flags & + XNegative) { + IconBoxes + ->IconBox + [0] = + Scr.MyDisplayWidth + + /* screen width */ + IconBoxes->IconBox + [0] /* neg + x coord */ + - + IconBoxes + ->IconBox + [2] - + 2; /* width + - 2 */ + } + if (geom_flags & + YNegative) { + IconBoxes + ->IconBox + [1] = + Scr.MyDisplayHeight + + /* scr height */ + IconBoxes->IconBox + [1] /* neg + y coord */ + - + IconBoxes + ->IconBox + [3] - + 2; /* height + - 2 */ + } + IconBoxes->IconBox[2] += + IconBoxes->IconBox + [0]; /* x + wid + = right + x */ + IconBoxes->IconBox[3] += + IconBoxes->IconBox + [1]; /* y + + height = + bottom y + */ + } /* end icon geom worked */ + } else { /* no word or too long */ + fvwm_msg(ERR, "ProcessNewStyle", + "IconBox requires 4 " + "numbers or geometry! Too " + "long (%d).", + len); + free(IconBoxes); /* Drop the box + */ + IconBoxes = + 0; /* forget about it */ + } /* end word found, not too long */ + restofline = + tmp; /* got word, move past it */ + } /* end not 4 args */ + /* If we created an IconBox, put it in the + * chain. */ + if (IconBoxes != 0) { /* If no error */ + if (tname.IconBoxes == + 0) { /* If first one */ + tname.IconBoxes = + IconBoxes; /* chain to root + */ + } else { /* else not first one */ + which->next = + IconBoxes; /* add to end of + chain */ + } /* end not first one */ + which = IconBoxes; /* new current box. + save for grid */ + } /* end no error */ + } /* end iconbox parameter */ else if (ITIS( + "ICONGRID")) { + SKIP("ICONGRID"); + SKIPSPACE; /* skip whitespace after keyword */ + /* The grid always affects the prior iconbox */ + if (which == 0) { /* If no current box */ + fvwm_msg(ERR, "ProcessNewStyle", + "IconGrid must follow an IconBox " + "in same Style command"); + } else { /* have a place to grid */ + num = sscanf(restofline, + "%hd%hd", /* 2 shorts */ + &which->IconGrid[0], + &which->IconGrid[1]); + if (num != 2 || + which->IconGrid[0] < 1 || + which->IconGrid[1] < 1) { + fvwm_msg(ERR, "ProcessNewStyle", + "IconGrid needs 2 numbers " + "> 0. Got %d numbers. " + "x=%d y=%d!", + num, + (int)which->IconGrid[0], + (int)which->IconGrid[1]); + which->IconGrid[0] = + 3; /* reset grid x */ + which->IconGrid[1] = + 3; /* reset grid y */ + } else { /* it worked */ + GETWORD; /* swallow word */ + restofline = tmp; + GETWORD; /* swallow word */ + restofline = tmp; + } /* end bad grid */ + } /* end place to grid */ + } else if (ITIS("ICONFILL")) { /* direction to fill + iconbox */ + SKIP("ICONFILL"); + SKIPSPACE; /* skip whitespace after keyword */ + /* The fill always affects the prior iconbox */ + if (which == 0) { /* If no current box */ + fvwm_msg(ERR, "ProcessNewStyle", + "IconFill must follow an IconBox " + "in same Style command"); + } else { /* have a place to fill */ + unsigned char IconFill_1; /* first type direction + parsed */ + unsigned char IconFill_2; /* second type direction + parsed */ + GETWORD; /* read in word for length */ + if (Get_TBLR(restofline, &IconFill_1) == + 0) { /* top/bot/lft/rgt */ + fvwm_msg(ERR, "ProcessNewStyle", + "IconFill must be followed " + "by T|B|R|L, found %.*s.", + len, + restofline); /* its wrong */ + } else { /* first word valid */ + restofline = + tmp; /* swallow it */ + SKIPSPACE; /* skip space between + words */ + GETWORD; /* read in second word + */ + if (Get_TBLR(restofline, + &IconFill_2) == + 0) { /* top/bot/lft/rgt */ + fvwm_msg(ERR, + "ProcessNewStyle", + "IconFill must be " + "followed by " + "T|B|R|L, found " + "%.*s.", + len, + restofline); /* its + wrong + */ + } else if ((IconFill_1 & + ICONFILLHRZ) == + (IconFill_2 & + ICONFILLHRZ)) { + fvwm_msg(ERR, + "ProcessNewStyle", + "IconFill must " + "specify a " + "horizontal and " + "vertical " + "direction."); + } else { /* Its valid! */ + which->IconFlags |= + IconFill_1; /* merge + in + flags + */ + IconFill_2 &= + ~ICONFILLHRZ; /* ignore + horiz + in + 2nd + arg + */ + which->IconFlags |= + IconFill_2; /* merge + in + flags + */ + } /* end second word valid */ + } /* end first word valid */ + restofline = tmp; /* swallow first or + second word */ + } /* end have a place to fill */ + } /* end iconfill */ else if (ITIS("ICON")) { + SKIP("ICON"); + GETWORD; + if (len > 0) { + tname.value = xmalloc(len + 1); + strncpy(tname.value, restofline, len); + tname.value[len] = 0; + tname.off_flags |= ICON_FLAG; + tname.on_flags |= SUPPRESSICON_FLAG; + } else + tname.on_flags |= SUPPRESSICON_FLAG; + restofline = tmp; + } + break; + case 'j': + break; + case 'k': + break; + case 'l': + if (ITIS("LENIENCE")) { + SKIP("LENIENCE"); + tname.off_flags |= LENIENCE_FLAG; + } + break; + case 'm': + if (ITIS("MWMBUTTONS")) { + SKIP("MWMBUTTONS"); + tname.off_flags |= MWM_BUTTON_FLAG; + } #ifdef MINI_ICONS - else if (ITIS("MINIICON")) - { - SKIP("MINIICON"); - GETWORD; - if(len > 0) - { - tname.mini_value = safemalloc(len+1); - strncpy(tname.mini_value,restofline,len); - tname.mini_value[len] = 0; - tname.off_flags |= MINIICON_FLAG; - } - restofline = tmp; - } + else if (ITIS("MINIICON")) { + SKIP("MINIICON"); + GETWORD; + if (len > 0) { + tname.mini_value = xmalloc(len + 1); + strncpy( + tname.mini_value, restofline, len); + tname.mini_value[len] = 0; + tname.off_flags |= MINIICON_FLAG; + } + restofline = tmp; + } #endif - else if(ITIS("MWMBORDER")) - { - SKIP("MWMBORDER"); - tname.off_flags |= MWM_BORDER_FLAG; - } - else if(ITIS("MWMDECOR")) - { - SKIP("MWMDECOR"); - tname.off_flags |= MWM_DECOR_FLAG; - } - else if(ITIS("MWMFUNCTIONS")) - { - SKIP("MWMFUNCTIONS"); - tname.off_flags |= MWM_FUNCTIONS_FLAG; - } - else if(ITIS("MOUSEFOCUS")) - { - SKIP("MOUSEFOCUS"); - tname.on_flags |= CLICK_FOCUS_FLAG; - tname.on_flags |= SLOPPY_FOCUS_FLAG; - } - break; - case 'n': - if(ITIS("NoIconTitle")) - { - SKIP("NoIconTitle"); - tname.off_flags |= NOICON_TITLE_FLAG; - } - else if(ITIS("NOICON")) - { - SKIP("NOICON"); - tname.off_flags |= SUPPRESSICON_FLAG; - } - else if(ITIS("NOTITLE")) - { - SKIP("NOTITLE"); - tname.off_flags |= NOTITLE_FLAG; - } - else if(ITIS("NoPPosition")) - { - SKIP("NoPPosition"); - tname.off_flags |= NO_PPOSITION_FLAG; - } - else if(ITIS("NakedTransient")) - { - SKIP("NakedTransient"); - tname.on_flags |= DECORATE_TRANSIENT_FLAG; - } - else if(ITIS("NODECORHINT")) - { - SKIP("NODECORHINT"); - tname.on_flags |= MWM_DECOR_FLAG; - } - else if(ITIS("NOFUNCHINT")) - { - SKIP("NOFUNCHINT"); - tname.on_flags |= MWM_FUNCTIONS_FLAG; - } - else if(ITIS("NOOVERRIDE")) - { - SKIP("NOOVERRIDE"); - tname.on_flags |= MWM_OVERRIDE_FLAG; - } - else if(ITIS("NOHANDLES")) - { - SKIP("NOHANDLES"); - tname.off_flags |= NOBORDER_FLAG; - } - else if(ITIS("NOLENIENCE")) - { - SKIP("NOLENIENCE"); - tname.on_flags |= LENIENCE_FLAG; - } - else if (ITIS("NOBUTTON")) - { - SKIP("NOBUTTON"); - - butt = -1; /* just in case sscanf fails */ - sscanf(restofline,"%d",&butt); - GETWORD; - SKIPSPACE; + else if (ITIS("MWMBORDER")) { + SKIP("MWMBORDER"); + tname.off_flags |= MWM_BORDER_FLAG; + } else if (ITIS("MWMDECOR")) { + SKIP("MWMDECOR"); + tname.off_flags |= MWM_DECOR_FLAG; + } else if (ITIS("MWMFUNCTIONS")) { + SKIP("MWMFUNCTIONS"); + tname.off_flags |= MWM_FUNCTIONS_FLAG; + } else if (ITIS("MOUSEFOCUS")) { + SKIP("MOUSEFOCUS"); + tname.on_flags |= CLICK_FOCUS_FLAG; + tname.on_flags |= SLOPPY_FOCUS_FLAG; + } + break; + case 'n': + if (ITIS("NoIconTitle")) { + SKIP("NoIconTitle"); + tname.off_flags |= NOICON_TITLE_FLAG; + } else if (ITIS("NOICON")) { + SKIP("NOICON"); + tname.off_flags |= SUPPRESSICON_FLAG; + } else if (ITIS("NOTITLE")) { + SKIP("NOTITLE"); + tname.off_flags |= NOTITLE_FLAG; + } else if (ITIS("NoPPosition")) { + SKIP("NoPPosition"); + tname.off_flags |= NO_PPOSITION_FLAG; + } else if (ITIS("NakedTransient")) { + SKIP("NakedTransient"); + tname.on_flags |= DECORATE_TRANSIENT_FLAG; + } else if (ITIS("NODECORHINT")) { + SKIP("NODECORHINT"); + tname.on_flags |= MWM_DECOR_FLAG; + } else if (ITIS("NOFUNCHINT")) { + SKIP("NOFUNCHINT"); + tname.on_flags |= MWM_FUNCTIONS_FLAG; + } else if (ITIS("NOOVERRIDE")) { + SKIP("NOOVERRIDE"); + tname.on_flags |= MWM_OVERRIDE_FLAG; + } else if (ITIS("NOHANDLES")) { + SKIP("NOHANDLES"); + tname.off_flags |= NOBORDER_FLAG; + } else if (ITIS("NOLENIENCE")) { + SKIP("NOLENIENCE"); + tname.on_flags |= LENIENCE_FLAG; + } else if (ITIS("NOBUTTON")) { + SKIP("NOBUTTON"); - if (butt == 0) butt = 10; - if (butt > 0 && butt <= 10) - tname.off_buttons |= (1<<(butt-1)); - restofline = tmp; - } - else if(ITIS("NOOLDECOR")) - { - SKIP("NOOLDECOR"); - tname.on_flags |= OL_DECOR_FLAG; - } - break; - case 'o': - if(ITIS("OLDECOR")) - { - SKIP("OLDECOR"); - tname.off_flags |= OL_DECOR_FLAG; - } - break; - case 'p': - break; - case 'q': - break; - case 'r': - if(ITIS("RANDOMPLACEMENT")) - { - SKIP("RANDOMPLACEMENT"); - tname.off_flags |= RANDOM_PLACE_FLAG; - } - break; - case 's': - if(ITIS("SMARTPLACEMENT")) - { - SKIP("SMARTPLACEMENT"); - tname.off_flags |= SMART_PLACE_FLAG; - } - else if(ITIS("SkipMapping")) - { - SKIP("SkipMapping"); - tname.off_flags |= SHOW_MAPPING; - } - else if(ITIS("ShowMapping")) - { - SKIP("ShowMapping"); - tname.on_flags |= SHOW_MAPPING; - } - else if(ITIS("StickyIcon")) - { - SKIP("StickyIcon"); - tname.off_flags |= STICKY_ICON_FLAG; - } - else if(ITIS("SlipperyIcon")) - { - SKIP("SlipperyIcon"); - tname.on_flags |= STICKY_ICON_FLAG; - } - else if(ITIS("SLOPPYFOCUS")) - { - SKIP("SLOPPYFOCUS"); - tname.on_flags |= CLICK_FOCUS_FLAG; - tname.off_flags |= SLOPPY_FOCUS_FLAG; - } - else if(ITIS("StartIconic")) - { - SKIP("StartIconic"); - tname.off_flags |= START_ICONIC_FLAG; - } - else if(ITIS("StartNormal")) - { - SKIP("StartNormal"); - tname.on_flags |= START_ICONIC_FLAG; - } - else if(ITIS("StaysOnTop")) - { - SKIP("StaysOnTop"); - tname.off_flags |= STAYSONTOP_FLAG; - } - else if(ITIS("StaysPut")) - { - SKIP("StaysPut"); - tname.on_flags |= STAYSONTOP_FLAG; - } - else if(ITIS("Sticky")) - { - tname.off_flags |= STICKY_FLAG; - SKIP("Sticky"); - } - else if(ITIS("Slippery")) - { - tname.on_flags |= STICKY_FLAG; - SKIP("Slippery"); - } - else if(ITIS("STARTSONDESK")) - { - SKIP("STARTSONDESK"); - tname.off_flags |= STARTSONDESK_FLAG; - /* RBW - 11/02/1998 */ - spargs = sscanf(restofline,"%d",&tmpno1); - if (spargs == 1) - { - /* RBW - 11/20/1998 - allow for the special case of -1 */ - tname.Desk = (tmpno1 > -1) ? tmpno1 + 1 : tmpno1; - } - else - { - tname.off_flags &= ~STARTSONDESK_FLAG; - fvwm_msg(ERR,"ProcessNewStyle", - "bad StartsOnDesk arg: %s", restofline); - } - /**/ - GETWORD; - restofline = tmp; - SKIPSPACE; - } - /* RBW - 11/02/1998 - StartsOnPage is like StartsOnDesk-Plus - */ - else if(ITIS("STARTSONPAGE")) - { - SKIP("STARTSONPAGE"); - tname.off_flags |= STARTSONDESK_FLAG; - spargs = sscanf(restofline,"%d %d %d", &tmpno1, &tmpno2, &tmpno3); + butt = -1; /* just in case sscanf fails */ + sscanf(restofline, "%d", &butt); + GETWORD; + SKIPSPACE; - if (spargs == 1 || spargs == 3) - { - /* We have a desk no., with or without page. */ - /* RBW - 11/20/1998 - allow for the special case of -1 */ - tname.Desk = (tmpno1 > -1) ? tmpno1 + 1 : tmpno1; /* Desk is now actual + 1 */ - /* Bump past desk no. */ - GETWORD; - restofline = tmp; - SKIPSPACE; - } + if (butt == 0) + butt = 10; + if (butt > 0 && butt <= 10) + tname.off_buttons |= (1 << (butt - 1)); + restofline = tmp; + } else if (ITIS("NOOLDECOR")) { + SKIP("NOOLDECOR"); + tname.on_flags |= OL_DECOR_FLAG; + } + break; + case 'o': + if (ITIS("OLDECOR")) { + SKIP("OLDECOR"); + tname.off_flags |= OL_DECOR_FLAG; + } + break; + case 'p': + break; + case 'q': + break; + case 'r': + if (ITIS("RANDOMPLACEMENT")) { + SKIP("RANDOMPLACEMENT"); + tname.off_flags |= RANDOM_PLACE_FLAG; + } + break; + case 's': + if (ITIS("SMARTPLACEMENT")) { + SKIP("SMARTPLACEMENT"); + tname.off_flags |= SMART_PLACE_FLAG; + } else if (ITIS("SkipMapping")) { + SKIP("SkipMapping"); + tname.off_flags |= SHOW_MAPPING; + } else if (ITIS("ShowMapping")) { + SKIP("ShowMapping"); + tname.on_flags |= SHOW_MAPPING; + } else if (ITIS("StickyIcon")) { + SKIP("StickyIcon"); + tname.off_flags |= STICKY_ICON_FLAG; + } else if (ITIS("SlipperyIcon")) { + SKIP("SlipperyIcon"); + tname.on_flags |= STICKY_ICON_FLAG; + } else if (ITIS("SLOPPYFOCUS")) { + SKIP("SLOPPYFOCUS"); + tname.on_flags |= CLICK_FOCUS_FLAG; + tname.off_flags |= SLOPPY_FOCUS_FLAG; + } else if (ITIS("StartIconic")) { + SKIP("StartIconic"); + tname.off_flags |= START_ICONIC_FLAG; + } else if (ITIS("StartNormal")) { + SKIP("StartNormal"); + tname.on_flags |= START_ICONIC_FLAG; + } else if (ITIS("StaysOnTop")) { + SKIP("StaysOnTop"); + tname.off_flags |= STAYSONTOP_FLAG; + } else if (ITIS("StaysPut")) { + SKIP("StaysPut"); + tname.on_flags |= STAYSONTOP_FLAG; + } else if (ITIS("Sticky")) { + tname.off_flags |= STICKY_FLAG; + SKIP("Sticky"); + } else if (ITIS("Slippery")) { + tname.on_flags |= STICKY_FLAG; + SKIP("Slippery"); + } else if (ITIS("STARTSONDESK")) { + SKIP("STARTSONDESK"); + tname.off_flags |= STARTSONDESK_FLAG; + /* RBW - 11/02/1998 */ + spargs = sscanf(restofline, "%d", &tmpno1); + if (spargs == 1) { + /* RBW - 11/20/1998 - allow for the + * special case of -1 */ + tname.Desk = + (tmpno1 > -1) ? tmpno1 + 1 : tmpno1; + } else { + tname.off_flags &= ~STARTSONDESK_FLAG; + fvwm_msg(ERR, "ProcessNewStyle", + "bad StartsOnDesk arg: %s", + restofline); + } + /**/ + GETWORD; + restofline = tmp; + SKIPSPACE; + } + /* RBW - 11/02/1998 + StartsOnPage is like StartsOnDesk-Plus + */ + else if (ITIS("STARTSONPAGE")) { + SKIP("STARTSONPAGE"); + tname.off_flags |= STARTSONDESK_FLAG; + spargs = sscanf(restofline, "%d %d %d", &tmpno1, + &tmpno2, &tmpno3); - if (spargs == 2 || spargs == 3) - { - if (spargs == 3) - { - /* RBW - 11/20/1998 - allow for the special case of -1 */ - tname.PageX = (tmpno2 > -1) ? tmpno2 + 1 : tmpno2; - tname.PageY = (tmpno3 > -1) ? tmpno3 + 1 : tmpno3; - } - else - { - tname.PageX = (tmpno1 > -1) ? tmpno1 + 1 : tmpno1; - tname.PageY = (tmpno2 > -1) ? tmpno2 + 1 : tmpno2; - } - /* Bump past next 2 args. */ - GETWORD; - restofline = tmp; - SKIPSPACE; - GETWORD; - restofline = tmp; - SKIPSPACE; + if (spargs == 1 || spargs == 3) { + /* We have a desk no., with or without + * page. */ + /* RBW - 11/20/1998 - allow for the + * special case of -1 */ + tname.Desk = + (tmpno1 > -1) ? + tmpno1 + 1 : + tmpno1; /* Desk is now actual + + 1 */ + /* Bump past desk no. */ + GETWORD; + restofline = tmp; + SKIPSPACE; + } - } - if (spargs < 1 || spargs > 3) - { - tname.off_flags &= ~STARTSONDESK_FLAG; - fvwm_msg(ERR,"ProcessNewStyle", - "bad StartsOnPage args: %s", restofline); - } - - } - /**/ - else if(ITIS("STARTSANYWHERE")) - { - SKIP("STARTSANYWHERE"); - tname.on_flags |= STARTSONDESK_FLAG; - } - break; - case 't': - if(ITIS("TITLE")) - { - SKIP("TITLE"); - tname.on_flags |= NOTITLE_FLAG; - } - break; - case 'u': - if(ITIS("UsePPosition")) - { - SKIP("UsePPosition"); - tname.on_flags |= NO_PPOSITION_FLAG; - } + if (spargs == 2 || spargs == 3) { + if (spargs == 3) { + /* RBW - 11/20/1998 - allow for + * the special case of -1 */ + tname.PageX = (tmpno2 > -1) ? + tmpno2 + 1 : + tmpno2; + tname.PageY = (tmpno3 > -1) ? + tmpno3 + 1 : + tmpno3; + } else { + tname.PageX = (tmpno1 > -1) ? + tmpno1 + 1 : + tmpno1; + tname.PageY = (tmpno2 > -1) ? + tmpno2 + 1 : + tmpno2; + } + /* Bump past next 2 args. */ + GETWORD; + restofline = tmp; + SKIPSPACE; + GETWORD; + restofline = tmp; + SKIPSPACE; + } + if (spargs < 1 || spargs > 3) { + tname.off_flags &= ~STARTSONDESK_FLAG; + fvwm_msg(ERR, "ProcessNewStyle", + "bad StartsOnPage args: %s", + restofline); + } + } + /**/ + else if (ITIS("STARTSANYWHERE")) { + SKIP("STARTSANYWHERE"); + tname.on_flags |= STARTSONDESK_FLAG; + } + break; + case 't': + if (ITIS("TITLE")) { + SKIP("TITLE"); + tname.on_flags |= NOTITLE_FLAG; + } + break; + case 'u': + if (ITIS("UsePPosition")) { + SKIP("UsePPosition"); + tname.on_flags |= NO_PPOSITION_FLAG; + } #ifdef USEDECOR - if(ITIS("UseDecor")) - { - SKIP("UseDecor"); - GETQUOTEDWORD; - if (len > 0) - { - tname.Decor = safemalloc(len+1); - strncpy(tname.Decor,restofline,len); - tname.Decor[len] = 0; - } - restofline = tmp; - } + if (ITIS("UseDecor")) { + SKIP("UseDecor"); + GETQUOTEDWORD; + if (len > 0) { + tname.Decor = xmalloc(len + 1); + strncpy(tname.Decor, restofline, len); + tname.Decor[len] = 0; + } + restofline = tmp; + } #endif - else if(ITIS("UseStyle")) - { - SKIP("UseStyle"); - GETQUOTEDWORD; - if (len > 0) { - int hit = 0; - /* changed to accum multiple Style definitions (veliaa@rpi.edu) */ - for ( nptr = Scr.TheList; nptr; nptr = nptr->next ) { - if (!strncasecmp(restofline,nptr->name,len)) { /* match style */ - if (!hit) { /* first match */ - char *save_name; - save_name = tname.name; - memcpy((void*)&tname, (const void*)nptr, sizeof(name_list)); /* copy everything */ - tname.next = 0; /* except the next pointer */ - tname.name = save_name; /* and the name */ - hit = 1; /* set not first match */ - } else { /* subsequent match */ - tname.off_flags |= nptr->off_flags; - tname.on_flags &= ~(nptr->on_flags); - tname.off_buttons |= nptr->off_buttons; - tname.on_buttons &= ~(nptr->on_buttons); - if(nptr->value) tname.value = nptr->value; + else if (ITIS("UseStyle")) { + SKIP("UseStyle"); + GETQUOTEDWORD; + if (len > 0) { + int hit = 0; + /* changed to accum multiple Style + * definitions (veliaa@rpi.edu) */ + for (nptr = Scr.TheList; nptr; + nptr = nptr->next) { + if (!strncasecmp(restofline, + nptr->name, + len)) { /* match style + */ + if (!hit) { /* first + match */ + char *save_name; + save_name = + tname.name; + memcpy( + (void *)&tname, + (const void *) + nptr, + sizeof( + name_list)); /* copy everything */ + tname.next = + 0; /* except + the + next + pointer + */ + tname.name = + save_name; /* and the name */ + hit = + 1; /* set + not + first + match + */ + } else { /* subsequent + match */ + tname + .off_flags |= + nptr->off_flags; + tname + .on_flags &= ~( + nptr->on_flags); + tname + .off_buttons |= + nptr->off_buttons; + tname + .on_buttons &= + ~(nptr->on_buttons); + if (nptr->value) + tname + .value = + nptr->value; #ifdef MINI_ICONS - if(nptr->mini_value) tname.mini_value = nptr->mini_value; + if (nptr->mini_value) + tname + .mini_value = + nptr->mini_value; #endif #ifdef USEDECOR - if(nptr->Decor) tname.Decor = nptr->Decor; + if (nptr->Decor) + tname + .Decor = + nptr->Decor; #endif - if(nptr->off_flags & STARTSONDESK_FLAG) - /* RBW - 11/02/1998 */ - { - tname.Desk = nptr->Desk; - tname.PageX = nptr->PageX; - tname.PageY = nptr->PageY; - } - /**/ - if(nptr->off_flags & BW_FLAG) - tname.border_width = nptr->border_width; - if(nptr->off_flags & NOBW_FLAG) - tname.resize_width = nptr->resize_width; - if(nptr->off_flags & FORE_COLOR_FLAG) - tname.ForeColor = nptr->ForeColor; - if(nptr->off_flags & BACK_COLOR_FLAG) - tname.BackColor = nptr->BackColor; - tname.IconBoxes = nptr->IconBoxes; /* use same chain */ - } /* end hit/not hit */ - } /* end found matching style */ - } /* end looking at all styles */ - restofline = tmp; /* move forward one word */ - if (!hit) { - tmp=safemalloc(500); - strlcat(tmp,"UseStyle: ", 500); - strlcat(tmp,restofline-len,500); - strlcat(tmp," style not found!",500); - fvwm_msg(ERR,"ProcessNewStyle",tmp); - free(tmp); - } - } - while(isspace(*restofline)) restofline++; - } - break; - case 'v': - break; - case 'w': - if(ITIS("WindowListSkip")) - { - SKIP("WindowListSkip"); - tname.off_flags |= LISTSKIP_FLAG; - } - else if(ITIS("WindowListHit")) - { - SKIP("WindowListHit"); - tname.on_flags |= LISTSKIP_FLAG; - } - break; - case 'x': - break; - case 'y': - break; - case 'z': - break; - default: - break; - } + if (nptr->off_flags & + STARTSONDESK_FLAG) + /* RBW - + 11/02/1998 */ + { + tname + .Desk = + nptr->Desk; + tname + .PageX = + nptr->PageX; + tname + .PageY = + nptr->PageY; + } + /**/ + if (nptr->off_flags & + BW_FLAG) + tname + .border_width = + nptr->border_width; + if (nptr->off_flags & + NOBW_FLAG) + tname + .resize_width = + nptr->resize_width; + if (nptr->off_flags & + FORE_COLOR_FLAG) + tname + .ForeColor = + nptr->ForeColor; + if (nptr->off_flags & + BACK_COLOR_FLAG) + tname + .BackColor = + nptr->BackColor; + tname + .IconBoxes = + nptr->IconBoxes; /* use same chain */ + } /* end hit/not hit */ + } /* end found matching style */ + } /* end looking at all styles */ + restofline = + tmp; /* move forward one word */ + if (!hit) { + tmp = xmalloc(500); + tmp[0] = '\0'; + strlcat(tmp, "UseStyle: ", 500); + strlcat( + tmp, restofline - len, 500); + strlcat(tmp, + " style not found!", 500); + fvwm_msg(ERR, "ProcessNewStyle", + tmp); + free(tmp); + } + } + while (isspace(*restofline)) + restofline++; + } + break; + case 'v': + break; + case 'w': + if (ITIS("WindowListSkip")) { + SKIP("WindowListSkip"); + tname.off_flags |= LISTSKIP_FLAG; + } else if (ITIS("WindowListHit")) { + SKIP("WindowListHit"); + tname.on_flags |= LISTSKIP_FLAG; + } + break; + case 'x': + break; + case 'y': + break; + case 'z': + break; + default: + break; + } - SKIPSPACE; - if(*restofline == ',') - restofline++; - else if((*restofline != 0)&&(*restofline != '\n')) - { - fvwm_msg(ERR,"ProcessNewStyle", - "bad style command: %s", restofline); - /* Can't return here since all malloced memory will be lost. Ignore rest - * of line instead. */ - break; - } - } /* end while still stuff on command */ + SKIPSPACE; + if (*restofline == ',') + restofline++; + else if ((*restofline != 0) && (*restofline != '\n')) { + fvwm_msg(ERR, "ProcessNewStyle", + "bad style command: %s", restofline); + /* Can't return here since all malloced memory will be + * lost. Ignore rest of line instead. */ + break; + } + } /* end while still stuff on command */ - /* capture default icons */ - if(strcmp(tname.name,"*") == 0) - { - if(tname.off_flags & ICON_FLAG) - Scr.DefaultIcon = tname.value; - tname.off_flags &= ~ICON_FLAG; - tname.value = NULL; - } - AddToList(&tname); /* add temp name list to list */ + /* capture default icons */ + if (strcmp(tname.name, "*") == 0) { + if (tname.off_flags & ICON_FLAG) + Scr.DefaultIcon = tname.value; + tname.off_flags &= ~ICON_FLAG; + tname.value = NULL; + } + AddToList(&tname); /* add temp name list to list */ } /* Check word after IconFill to see if its "Top,Bottom,Left,Right" */ -static int Get_TBLR(char *restofline,unsigned char *IconFill) { - *IconFill = 0; /* init */ - if (ITIS("B") || ITIS("BOT")|| ITIS("BOTTOM")) { - *IconFill |= ICONFILLBOT; /* turn on bottom bit */ - *IconFill |= ICONFILLHRZ; /* turn on vertical */ - } else if (ITIS("T") || ITIS("TOP")) { /* else if its "top" */ - *IconFill |= ICONFILLHRZ; /* turn on vertical */ - } else if (ITIS("R") || ITIS("RGT") || ITIS("RIGHT")) { - *IconFill |= ICONFILLRGT; /* turn on right bit */ - } else if (!(ITIS("L") || ITIS("LFT") || ITIS("LEFT"))) { /* "left" */ - return 0; /* anything else is bad */ - } - return 1; /* return OK */ +static int +Get_TBLR(char *restofline, unsigned char *IconFill) +{ + *IconFill = 0; /* init */ + if (ITIS("B") || ITIS("BOT") || ITIS("BOTTOM")) { + *IconFill |= ICONFILLBOT; /* turn on bottom bit */ + *IconFill |= ICONFILLHRZ; /* turn on vertical */ + } else if (ITIS("T") || ITIS("TOP")) { /* else if its "top" */ + *IconFill |= ICONFILLHRZ; /* turn on vertical */ + } else if (ITIS("R") || ITIS("RGT") || ITIS("RIGHT")) { + *IconFill |= ICONFILLRGT; /* turn on right bit */ + } else if (!(ITIS("L") || ITIS("LFT") || ITIS("LEFT"))) { /* "left" */ + return 0; /* anything else is bad */ + } + return 1; /* return OK */ } -static void AddToList(name_list *tname) +static void +AddToList(name_list *tname) { - name_list *nptr,*lastptr = NULL; + name_list *nptr, *lastptr = NULL; - /* This used to contain logic that returned if the style didn't contain - anything. I don't see why we should bother. dje. */ + /* This used to contain logic that returned if the style didn't contain + anything. I don't see why we should bother. dje. */ - /* used to merge duplicate entries, but that is no longer - * appropriate since conficting styles are possible, and the - * last match should win! */ + /* used to merge duplicate entries, but that is no longer + * appropriate since conficting styles are possible, and the + * last match should win! */ - /* seems like a pretty inefficient way to keep track of the end - of the list, but how long can the style list be? dje */ - for (nptr = Scr.TheList; nptr != NULL; nptr = nptr->next) { - lastptr=nptr; /* find end of style list */ - } + /* seems like a pretty inefficient way to keep track of the end + of the list, but how long can the style list be? dje */ + for (nptr = Scr.TheList; nptr != NULL; nptr = nptr->next) { + lastptr = nptr; /* find end of style list */ + } - nptr = (name_list *)safemalloc(sizeof(name_list)); /* malloc area */ - memcpy((void*)nptr, (const void*)tname, sizeof(name_list)); /* copy term area into list */ - if(lastptr != NULL) /* If not first entry in list */ - lastptr->next = nptr; /* chain this entry to the list */ - else /* else first entry in list */ - Scr.TheList = nptr; /* set the list root pointer. */ + nptr = (name_list *)xmalloc(sizeof(name_list)); /* malloc area */ + memcpy((void *)nptr, (const void *)tname, + sizeof(name_list)); /* copy term area into list */ + if (lastptr != NULL) /* If not first entry in list */ + lastptr->next = nptr; /* chain this entry to the list */ + else /* else first entry in list */ + Scr.TheList = nptr; /* set the list root pointer. */ } /* end function */ - Index: fvwm/fvwm/virtual.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/virtual.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/virtual.c --- fvwm/fvwm/virtual.c +++ fvwm/fvwm/virtual.c @@ -1,17 +1,16 @@ -#include "config.h" - -#include +#include #include +#include #include -#include #include +#include "config.h" #include "fvwm.h" #include "menus.h" #include "misc.h" +#include "module.h" #include "parse.h" #include "screen.h" -#include "module.h" /* * dje 12/19/98 @@ -35,24 +34,26 @@ int edge_thickness = 2; int last_edge_thickness = 2; -void setEdgeThickness(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context,char *action, int *Module) +void +setEdgeThickness(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - int val, n; - - n = GetIntegerArguments(action, NULL, &val, 1); - if(n != 1) { - fvwm_msg(ERR,"setEdgeThickness", - "EdgeThickness requires 1 numeric argument, found %d args",n); - return; - } - if (val < 0 || val > 2) { /* check range */ - fvwm_msg(ERR,"setEdgeThickness", - "EdgeThickness arg must be between 0 and 2, found %d",val); - return; - } - edge_thickness = val; - checkPanFrames(); + int val, n; + + n = GetIntegerArguments(action, NULL, &val, 1); + if (n != 1) { + fvwm_msg(ERR, "setEdgeThickness", + "EdgeThickness requires 1 numeric argument, found %d args", + n); + return; + } + if (val < 0 || val > 2) { /* check range */ + fvwm_msg(ERR, "setEdgeThickness", + "EdgeThickness arg must be between 0 and 2, found %d", val); + return; + } + edge_thickness = val; + checkPanFrames(); } /*************************************************************************** @@ -60,175 +61,151 @@ void setEdgeThickness(XEvent *eventp,Window w,FvwmWindow *tmp_win, * Check to see if the pointer is on the edge of the screen, and scroll/page * if needed ***************************************************************************/ -void HandlePaging(int HorWarpSize, int VertWarpSize, int *xl, int *yt, - int *delta_x, int *delta_y,Bool Grab) +void +HandlePaging(int HorWarpSize, int VertWarpSize, int *xl, int *yt, int *delta_x, + int *delta_y, Bool Grab) { - int x,y,total; - - *delta_x = 0; - *delta_y = 0; - - if((Scr.ScrollResistance >= 10000)|| - ((HorWarpSize ==0)&&(VertWarpSize==0))) - return; - - /* need to move the viewport */ - if(( Scr.VxMax == 0 || - (*xl >= edge_thickness && - *xl < Scr.MyDisplayWidth - edge_thickness)) && - ( Scr.VyMax == 0 || - (*yt >= edge_thickness && - *yt < Scr.MyDisplayHeight - edge_thickness))) - return; - - total = 0; - while(total < Scr.ScrollResistance) - { - usleep(10000); - total+=10; - - XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, - &x, &y, &JunkX, &JunkY, &JunkMask); - - if(XCheckWindowEvent(dpy,Scr.PanFrameTop.win, - LeaveWindowMask,&Event)) - { - StashEventTime(&Event); - return; - } - if(XCheckWindowEvent(dpy,Scr.PanFrameBottom.win, - LeaveWindowMask,&Event)) - { - StashEventTime(&Event); - return; - } - if(XCheckWindowEvent(dpy,Scr.PanFrameLeft.win, - LeaveWindowMask,&Event)) - { - StashEventTime(&Event); - return; - } - if(XCheckWindowEvent(dpy,Scr.PanFrameRight.win, - LeaveWindowMask,&Event)) - { - StashEventTime(&Event); - return; - } - /* check actual pointer location since PanFrames can get buried under - a window being moved or resized - mab */ - if(( x >= edge_thickness )&& - ( x < Scr.MyDisplayWidth-edge_thickness )&& - ( y >= edge_thickness )&& - ( y < Scr.MyDisplayHeight-edge_thickness )) - return ; - } - - XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, - &x, &y, &JunkX, &JunkY, &JunkMask); - - /* Move the viewport */ - /* and/or move the cursor back to the approximate correct location */ - /* that is, the same place on the virtual desktop that it */ - /* started at */ - if( x= Scr.MyDisplayWidth-edge_thickness) - *delta_x = HorWarpSize; - else - *delta_x = 0; - if (Scr.VxMax == 0) *delta_x = 0; - if( y= Scr.MyDisplayHeight-edge_thickness) - *delta_y = VertWarpSize; - else - *delta_y = 0; - if (Scr.VyMax == 0) *delta_y = 0; - - /* Ouch! lots of bounds checking */ - if(Scr.Vx + *delta_x < 0) - { - if (!(Scr.flags & EdgeWrapX )) - { - *delta_x = -Scr.Vx; - *xl = x - *delta_x; - } - else - { - *delta_x += Scr.VxMax + Scr.MyDisplayWidth; - *xl = x + *delta_x % Scr.MyDisplayWidth + HorWarpSize; - } - } - else if(Scr.Vx + *delta_x > Scr.VxMax) - { - if (!(Scr.flags & EdgeWrapX)) - { - *delta_x = Scr.VxMax - Scr.Vx; - *xl = x - *delta_x; + int x, y, total; + + *delta_x = 0; + *delta_y = 0; + + if ((Scr.ScrollResistance >= 10000) || + ((HorWarpSize == 0) && (VertWarpSize == 0))) + return; + + /* need to move the viewport */ + if ((Scr.VxMax == 0 || + (*xl >= edge_thickness && + *xl < Scr.MyDisplayWidth - edge_thickness)) && + (Scr.VyMax == 0 || (*yt >= edge_thickness && + *yt < Scr.MyDisplayHeight - edge_thickness))) + return; + + total = 0; + while (total < Scr.ScrollResistance) { + usleep(10000); + total += 10; + + XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, &x, &y, + &JunkX, &JunkY, &JunkMask); + + if (XCheckWindowEvent( + dpy, Scr.PanFrameTop.win, LeaveWindowMask, &Event)) { + StashEventTime(&Event); + return; + } + if (XCheckWindowEvent( + dpy, Scr.PanFrameBottom.win, LeaveWindowMask, &Event)) { + StashEventTime(&Event); + return; + } + if (XCheckWindowEvent( + dpy, Scr.PanFrameLeft.win, LeaveWindowMask, &Event)) { + StashEventTime(&Event); + return; + } + if (XCheckWindowEvent( + dpy, Scr.PanFrameRight.win, LeaveWindowMask, &Event)) { + StashEventTime(&Event); + return; + } + /* check actual pointer location since PanFrames can get buried + under a window being moved or resized - mab */ + if ((x >= edge_thickness) && + (x < Scr.MyDisplayWidth - edge_thickness) && + (y >= edge_thickness) && + (y < Scr.MyDisplayHeight - edge_thickness)) + return; } - else - { - *delta_x -= Scr.VxMax +Scr.MyDisplayWidth; - *xl = x + *delta_x % Scr.MyDisplayWidth - HorWarpSize; - } - } - else - *xl = x - *delta_x; - - if(Scr.Vy + *delta_y < 0) - { - if (!(Scr.flags & EdgeWrapY)) - { - *delta_y = -Scr.Vy; - *yt = y - *delta_y; - } - else - { - *delta_y += Scr.VyMax + Scr.MyDisplayHeight; - *yt = y + *delta_y % Scr.MyDisplayHeight + VertWarpSize; - } - } - else if(Scr.Vy + *delta_y > Scr.VyMax) - { - if (!(Scr.flags & EdgeWrapY)) - { - *delta_y = Scr.VyMax - Scr.Vy; - *yt = y - *delta_y; - } - else - { - *delta_y -= Scr.VyMax + Scr.MyDisplayHeight; - *yt = y + *delta_y % Scr.MyDisplayHeight - VertWarpSize; + + XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, &x, &y, &JunkX, + &JunkY, &JunkMask); + + /* Move the viewport */ + /* and/or move the cursor back to the approximate correct location */ + /* that is, the same place on the virtual desktop that it */ + /* started at */ + if (x < edge_thickness) + *delta_x = -HorWarpSize; + else if (x >= Scr.MyDisplayWidth - edge_thickness) + *delta_x = HorWarpSize; + else + *delta_x = 0; + if (Scr.VxMax == 0) + *delta_x = 0; + if (y < edge_thickness) + *delta_y = -VertWarpSize; + else if (y >= Scr.MyDisplayHeight - edge_thickness) + *delta_y = VertWarpSize; + else + *delta_y = 0; + if (Scr.VyMax == 0) + *delta_y = 0; + + /* Ouch! lots of bounds checking */ + if (Scr.Vx + *delta_x < 0) { + if (!(Scr.flags & EdgeWrapX)) { + *delta_x = -Scr.Vx; + *xl = x - *delta_x; + } else { + *delta_x += Scr.VxMax + Scr.MyDisplayWidth; + *xl = x + *delta_x % Scr.MyDisplayWidth + HorWarpSize; + } + } else if (Scr.Vx + *delta_x > Scr.VxMax) { + if (!(Scr.flags & EdgeWrapX)) { + *delta_x = Scr.VxMax - Scr.Vx; + *xl = x - *delta_x; + } else { + *delta_x -= Scr.VxMax + Scr.MyDisplayWidth; + *xl = x + *delta_x % Scr.MyDisplayWidth - HorWarpSize; + } + } else + *xl = x - *delta_x; + + if (Scr.Vy + *delta_y < 0) { + if (!(Scr.flags & EdgeWrapY)) { + *delta_y = -Scr.Vy; + *yt = y - *delta_y; + } else { + *delta_y += Scr.VyMax + Scr.MyDisplayHeight; + *yt = y + *delta_y % Scr.MyDisplayHeight + VertWarpSize; + } + } else if (Scr.Vy + *delta_y > Scr.VyMax) { + if (!(Scr.flags & EdgeWrapY)) { + *delta_y = Scr.VyMax - Scr.Vy; + *yt = y - *delta_y; + } else { + *delta_y -= Scr.VyMax + Scr.MyDisplayHeight; + *yt = y + *delta_y % Scr.MyDisplayHeight - VertWarpSize; + } + } else + *yt = y - *delta_y; + + /* make sure the pointer isn't warped into the panframes */ + if (*xl < edge_thickness) + *xl = edge_thickness; + if (*yt < edge_thickness) + *yt = edge_thickness; + if (*xl >= Scr.MyDisplayWidth - edge_thickness) + *xl = Scr.MyDisplayWidth - edge_thickness - 1; + if (*yt >= Scr.MyDisplayHeight - edge_thickness) + *yt = Scr.MyDisplayHeight - edge_thickness - 1; + + if ((*delta_x != 0) || (*delta_y != 0)) { + if (Grab) + MyXGrabServer(dpy); + /* Turn off the rubberband if its on */ + MoveOutline(Scr.Root, 0, 0, 0, 0); + XWarpPointer(dpy, None, Scr.Root, 0, 0, 0, 0, *xl, *yt); + MoveViewport(Scr.Vx + *delta_x, Scr.Vy + *delta_y, False); + XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, xl, yt, + &JunkX, &JunkY, &JunkMask); + if (Grab) + MyXUngrabServer(dpy); } - } - else - *yt = y - *delta_y; - - /* make sure the pointer isn't warped into the panframes */ - if(*xl < edge_thickness) *xl = edge_thickness; - if(*yt < edge_thickness) *yt = edge_thickness; - if(*xl >= Scr.MyDisplayWidth - edge_thickness) - *xl = Scr.MyDisplayWidth - edge_thickness -1; - if(*yt >= Scr.MyDisplayHeight - edge_thickness) - *yt = Scr.MyDisplayHeight - edge_thickness -1; - - if((*delta_x != 0)||(*delta_y!=0)) - { - if(Grab) - MyXGrabServer(dpy); - /* Turn off the rubberband if its on */ - MoveOutline(Scr.Root,0,0,0,0); - XWarpPointer(dpy,None,Scr.Root,0,0,0,0,*xl,*yt); - MoveViewport(Scr.Vx + *delta_x,Scr.Vy + *delta_y,False); - XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, - xl, yt, &JunkX, &JunkY, &JunkMask); - if(Grab) - MyXUngrabServer(dpy); - } } - - /* the root window is surrounded by four window slices, which are InputOnly. * So you can see 'through' them, but they eat the input. An EnterEvent in * one of these windows causes a Paging. The windows have the according cursor @@ -238,118 +215,110 @@ void HandlePaging(int HorWarpSize, int VertWarpSize, int *xl, int *yt, * eat all mouse events. * * Hermann Dunkel, HEDU, dunkel@cul-ipn.uni-kiel.de 1/94 -*/ + */ /*************************************************************************** * checkPanFrames hides PanFrames if they are on the very border of the * VIRTUAL screen and EdgeWrap for that direction is off. * (A special cursor for the EdgeWrap border could be nice) HEDU ****************************************************************************/ -void checkPanFrames(void) +void +checkPanFrames(void) { - Bool wrapX = (Scr.flags & EdgeWrapX) && Scr.VxMax; - Bool wrapY = (Scr.flags & EdgeWrapY) && Scr.VyMax; - - if(!(Scr.flags & WindowsCaptured)) - return; - - /* thickness of 0 means remove the pan frames */ - if (edge_thickness == 0) { - if (Scr.PanFrameTop.isMapped) { - XUnmapWindow(dpy,Scr.PanFrameTop.win); - Scr.PanFrameTop.isMapped=False; - } - if (Scr.PanFrameBottom.isMapped) { - XUnmapWindow (dpy,Scr.PanFrameBottom.win); - Scr.PanFrameBottom.isMapped=False; - } - if (Scr.PanFrameLeft.isMapped) { - XUnmapWindow(dpy,Scr.PanFrameLeft.win); - Scr.PanFrameLeft.isMapped=False; - } - if (Scr.PanFrameRight.isMapped) { - XUnmapWindow (dpy,Scr.PanFrameRight.win); - Scr.PanFrameRight.isMapped=False; - } - return; - } - - /* check they are the right size */ - if (edge_thickness != last_edge_thickness) { - XResizeWindow (dpy, Scr.PanFrameTop.win, Scr.MyDisplayWidth, edge_thickness); - XResizeWindow (dpy, Scr.PanFrameLeft.win, edge_thickness, Scr.MyDisplayHeight); - XMoveResizeWindow (dpy, Scr.PanFrameRight.win, - Scr.MyDisplayWidth - edge_thickness, 0, - edge_thickness, Scr.MyDisplayHeight); - XMoveResizeWindow (dpy, Scr.PanFrameBottom.win, - 0, Scr.MyDisplayHeight - edge_thickness, - Scr.MyDisplayWidth, edge_thickness); - last_edge_thickness = edge_thickness; - } - - /* Remove Pan frames if paging by edge-scroll is permanently or - * temporarily disabled */ - if(Scr.EdgeScrollY == 0) - { - XUnmapWindow(dpy,Scr.PanFrameTop.win); - Scr.PanFrameTop.isMapped=False; - XUnmapWindow (dpy,Scr.PanFrameBottom.win); - Scr.PanFrameBottom.isMapped=False; - } - if(Scr.EdgeScrollX == 0) - { - XUnmapWindow(dpy,Scr.PanFrameLeft.win); - Scr.PanFrameLeft.isMapped=False; - XUnmapWindow (dpy,Scr.PanFrameRight.win); - Scr.PanFrameRight.isMapped=False; - } - if((Scr.EdgeScrollX == 0)&&(Scr.EdgeScrollY == 0)) - return; - - /* LEFT, hide only if EdgeWrap is off */ - if (Scr.Vx==0 && Scr.PanFrameLeft.isMapped && (!wrapX)) - { - XUnmapWindow(dpy,Scr.PanFrameLeft.win); - Scr.PanFrameLeft.isMapped=False; - } - else if ((Scr.Vx > 0 || wrapX) && Scr.PanFrameLeft.isMapped==False) - { - XMapRaised(dpy,Scr.PanFrameLeft.win); - Scr.PanFrameLeft.isMapped=True; - } - /* RIGHT, hide only if EdgeWrap is off */ - if (Scr.Vx == Scr.VxMax && Scr.PanFrameRight.isMapped && (!wrapX)) - { - XUnmapWindow (dpy,Scr.PanFrameRight.win); - Scr.PanFrameRight.isMapped=False; - } - else if ((Scr.Vx < Scr.VxMax || wrapX) && Scr.PanFrameRight.isMapped==False) - { - XMapRaised(dpy,Scr.PanFrameRight.win); - Scr.PanFrameRight.isMapped=True; - } - /* TOP, hide only if EdgeWrap is off */ - if (Scr.Vy==0 && Scr.PanFrameTop.isMapped && (!wrapY)) - { - XUnmapWindow(dpy,Scr.PanFrameTop.win); - Scr.PanFrameTop.isMapped=False; - } - else if ((Scr.Vy > 0 || wrapY) && Scr.PanFrameTop.isMapped==False) - { - XMapRaised(dpy,Scr.PanFrameTop.win); - Scr.PanFrameTop.isMapped=True; - } - /* BOTTOM, hide only if EdgeWrap is off */ - if (Scr.Vy == Scr.VyMax && Scr.PanFrameBottom.isMapped && (!wrapY)) - { - XUnmapWindow (dpy,Scr.PanFrameBottom.win); - Scr.PanFrameBottom.isMapped=False; - } - else if ((Scr.Vy < Scr.VyMax || wrapY) && Scr.PanFrameBottom.isMapped==False) - { - XMapRaised(dpy,Scr.PanFrameBottom.win); - Scr.PanFrameBottom.isMapped=True; - } + Bool wrapX = (Scr.flags & EdgeWrapX) && Scr.VxMax; + Bool wrapY = (Scr.flags & EdgeWrapY) && Scr.VyMax; + + if (!(Scr.flags & WindowsCaptured)) + return; + + /* thickness of 0 means remove the pan frames */ + if (edge_thickness == 0) { + if (Scr.PanFrameTop.isMapped) { + XUnmapWindow(dpy, Scr.PanFrameTop.win); + Scr.PanFrameTop.isMapped = False; + } + if (Scr.PanFrameBottom.isMapped) { + XUnmapWindow(dpy, Scr.PanFrameBottom.win); + Scr.PanFrameBottom.isMapped = False; + } + if (Scr.PanFrameLeft.isMapped) { + XUnmapWindow(dpy, Scr.PanFrameLeft.win); + Scr.PanFrameLeft.isMapped = False; + } + if (Scr.PanFrameRight.isMapped) { + XUnmapWindow(dpy, Scr.PanFrameRight.win); + Scr.PanFrameRight.isMapped = False; + } + return; + } + + /* check they are the right size */ + if (edge_thickness != last_edge_thickness) { + XResizeWindow(dpy, Scr.PanFrameTop.win, Scr.MyDisplayWidth, + edge_thickness); + XResizeWindow(dpy, Scr.PanFrameLeft.win, edge_thickness, + Scr.MyDisplayHeight); + XMoveResizeWindow(dpy, Scr.PanFrameRight.win, + Scr.MyDisplayWidth - edge_thickness, 0, edge_thickness, + Scr.MyDisplayHeight); + XMoveResizeWindow(dpy, Scr.PanFrameBottom.win, 0, + Scr.MyDisplayHeight - edge_thickness, Scr.MyDisplayWidth, + edge_thickness); + last_edge_thickness = edge_thickness; + } + + /* Remove Pan frames if paging by edge-scroll is permanently or + * temporarily disabled */ + if (Scr.EdgeScrollY == 0) { + XUnmapWindow(dpy, Scr.PanFrameTop.win); + Scr.PanFrameTop.isMapped = False; + XUnmapWindow(dpy, Scr.PanFrameBottom.win); + Scr.PanFrameBottom.isMapped = False; + } + if (Scr.EdgeScrollX == 0) { + XUnmapWindow(dpy, Scr.PanFrameLeft.win); + Scr.PanFrameLeft.isMapped = False; + XUnmapWindow(dpy, Scr.PanFrameRight.win); + Scr.PanFrameRight.isMapped = False; + } + if ((Scr.EdgeScrollX == 0) && (Scr.EdgeScrollY == 0)) + return; + + /* LEFT, hide only if EdgeWrap is off */ + if (Scr.Vx == 0 && Scr.PanFrameLeft.isMapped && (!wrapX)) { + XUnmapWindow(dpy, Scr.PanFrameLeft.win); + Scr.PanFrameLeft.isMapped = False; + } else if ((Scr.Vx > 0 || wrapX) && + Scr.PanFrameLeft.isMapped == False) { + XMapRaised(dpy, Scr.PanFrameLeft.win); + Scr.PanFrameLeft.isMapped = True; + } + /* RIGHT, hide only if EdgeWrap is off */ + if (Scr.Vx == Scr.VxMax && Scr.PanFrameRight.isMapped && (!wrapX)) { + XUnmapWindow(dpy, Scr.PanFrameRight.win); + Scr.PanFrameRight.isMapped = False; + } else if ((Scr.Vx < Scr.VxMax || wrapX) && + Scr.PanFrameRight.isMapped == False) { + XMapRaised(dpy, Scr.PanFrameRight.win); + Scr.PanFrameRight.isMapped = True; + } + /* TOP, hide only if EdgeWrap is off */ + if (Scr.Vy == 0 && Scr.PanFrameTop.isMapped && (!wrapY)) { + XUnmapWindow(dpy, Scr.PanFrameTop.win); + Scr.PanFrameTop.isMapped = False; + } else if ((Scr.Vy > 0 || wrapY) && Scr.PanFrameTop.isMapped == False) { + XMapRaised(dpy, Scr.PanFrameTop.win); + Scr.PanFrameTop.isMapped = True; + } + /* BOTTOM, hide only if EdgeWrap is off */ + if (Scr.Vy == Scr.VyMax && Scr.PanFrameBottom.isMapped && (!wrapY)) { + XUnmapWindow(dpy, Scr.PanFrameBottom.win); + Scr.PanFrameBottom.isMapped = False; + } else if ((Scr.Vy < Scr.VyMax || wrapY) && + Scr.PanFrameBottom.isMapped == False) { + XMapRaised(dpy, Scr.PanFrameBottom.win); + Scr.PanFrameBottom.isMapped = True; + } } /**************************************************************************** @@ -360,12 +329,17 @@ void checkPanFrames(void) * For some reason, this seems to be unneeded. * ***************************************************************************/ -void raisePanFrames(void) +void +raisePanFrames(void) { - if (Scr.PanFrameTop.isMapped) XRaiseWindow(dpy,Scr.PanFrameTop.win); - if (Scr.PanFrameLeft.isMapped) XRaiseWindow(dpy,Scr.PanFrameLeft.win); - if (Scr.PanFrameRight.isMapped) XRaiseWindow(dpy,Scr.PanFrameRight.win); - if (Scr.PanFrameBottom.isMapped) XRaiseWindow(dpy,Scr.PanFrameBottom.win); + if (Scr.PanFrameTop.isMapped) + XRaiseWindow(dpy, Scr.PanFrameTop.win); + if (Scr.PanFrameLeft.isMapped) + XRaiseWindow(dpy, Scr.PanFrameLeft.win); + if (Scr.PanFrameRight.isMapped) + XRaiseWindow(dpy, Scr.PanFrameRight.win); + if (Scr.PanFrameBottom.isMapped) + XRaiseWindow(dpy, Scr.PanFrameBottom.win); } /**************************************************************************** @@ -373,239 +347,254 @@ void raisePanFrames(void) * Creates the windows for edge-scrolling * ****************************************************************************/ -void initPanFrames() +void +initPanFrames() { - XSetWindowAttributes attributes; /* attributes for create */ - unsigned long valuemask; - int saved_thickness; - - /* Not creating the frames disables all subsequent behavior */ - /* TKP. This is bad, it will cause an XMap request on a null window later*/ - /* if (edge_thickness == 0) return; */ - saved_thickness = edge_thickness; - if (edge_thickness == 0) edge_thickness = 2; - - attributes.event_mask = (EnterWindowMask | LeaveWindowMask | - VisibilityChangeMask); - valuemask= (CWEventMask | CWCursor ); - - attributes.cursor = Scr.FvwmCursors[TOP]; - /* I know these overlap, it's useful when at (0,0) and the top one is unmapped */ - Scr.PanFrameTop.win = - XCreateWindow (dpy, Scr.Root, - 0, 0, - Scr.MyDisplayWidth, edge_thickness, - 0, /* no border */ - CopyFromParent, InputOnly, - CopyFromParent, - valuemask, &attributes); - attributes.cursor = Scr.FvwmCursors[LEFT]; - Scr.PanFrameLeft.win = - XCreateWindow (dpy, Scr.Root, - 0, 0, - edge_thickness, Scr.MyDisplayHeight, - 0, /* no border */ - CopyFromParent, InputOnly, CopyFromParent, - valuemask, &attributes); - attributes.cursor = Scr.FvwmCursors[RIGHT]; - Scr.PanFrameRight.win = - XCreateWindow (dpy, Scr.Root, - Scr.MyDisplayWidth - edge_thickness, 0, - edge_thickness, Scr.MyDisplayHeight, - 0, /* no border */ - CopyFromParent, InputOnly, CopyFromParent, - valuemask, &attributes); - attributes.cursor = Scr.FvwmCursors[BOTTOM]; - Scr.PanFrameBottom.win = - XCreateWindow (dpy, Scr.Root, - 0, Scr.MyDisplayHeight - edge_thickness, - Scr.MyDisplayWidth, edge_thickness, - 0, /* no border */ - CopyFromParent, InputOnly, CopyFromParent, - valuemask, &attributes); - Scr.PanFrameTop.isMapped=Scr.PanFrameLeft.isMapped= - Scr.PanFrameRight.isMapped= Scr.PanFrameBottom.isMapped=False; - - edge_thickness = saved_thickness; + XSetWindowAttributes attributes; /* attributes for create */ + unsigned long valuemask; + int saved_thickness; + + /* Not creating the frames disables all subsequent behavior */ + /* TKP. This is bad, it will cause an XMap request on a null window + * later*/ + /* if (edge_thickness == 0) return; */ + saved_thickness = edge_thickness; + if (edge_thickness == 0) + edge_thickness = 2; + + attributes.event_mask = + (EnterWindowMask | LeaveWindowMask | VisibilityChangeMask); + valuemask = (CWEventMask | CWCursor); + + attributes.cursor = Scr.FvwmCursors[TOP]; + /* I know these overlap, it's useful when at (0,0) and the top one is + * unmapped */ + Scr.PanFrameTop.win = XCreateWindow(dpy, Scr.Root, 0, 0, + Scr.MyDisplayWidth, edge_thickness, 0, /* no border */ + CopyFromParent, InputOnly, CopyFromParent, valuemask, &attributes); + attributes.cursor = Scr.FvwmCursors[LEFT]; + Scr.PanFrameLeft.win = XCreateWindow(dpy, Scr.Root, 0, 0, + edge_thickness, Scr.MyDisplayHeight, 0, /* no border */ + CopyFromParent, InputOnly, CopyFromParent, valuemask, &attributes); + attributes.cursor = Scr.FvwmCursors[RIGHT]; + Scr.PanFrameRight.win = XCreateWindow(dpy, Scr.Root, + Scr.MyDisplayWidth - edge_thickness, 0, edge_thickness, + Scr.MyDisplayHeight, 0, /* no border */ + CopyFromParent, InputOnly, CopyFromParent, valuemask, &attributes); + attributes.cursor = Scr.FvwmCursors[BOTTOM]; + Scr.PanFrameBottom.win = XCreateWindow(dpy, Scr.Root, 0, + Scr.MyDisplayHeight - edge_thickness, Scr.MyDisplayWidth, + edge_thickness, 0, /* no border */ + CopyFromParent, InputOnly, CopyFromParent, valuemask, &attributes); + Scr.PanFrameTop.isMapped = Scr.PanFrameLeft.isMapped = + Scr.PanFrameRight.isMapped = Scr.PanFrameBottom.isMapped = False; + + edge_thickness = saved_thickness; } - /*************************************************************************** * * Moves the viewport within the virtual desktop * ***************************************************************************/ -void MoveViewport(int newx, int newy, Bool grab) +void +MoveViewport(int newx, int newy, Bool grab) { - FvwmWindow *t, *t1; - int deltax,deltay; - int PageTop, PageLeft; - int PageBottom, PageRight; - int txl, txr, tyt, tyb; - - if(grab) - MyXGrabServer(dpy); - - - if(newx > Scr.VxMax) - newx = Scr.VxMax; - if(newy > Scr.VyMax) - newy = Scr.VyMax; - if(newx <0) - newx = 0; - if(newy <0) - newy = 0; - - deltay = Scr.Vy - newy; - deltax = Scr.Vx - newx; - /* - Identify the bounding rectangle that will be moved into - the viewport. - */ - PageBottom = Scr.MyDisplayHeight - deltay; - PageRight = Scr.MyDisplayWidth - deltax; - PageTop = 0 - deltay; - PageLeft = 0 - deltax; - - Scr.Vx = newx; - Scr.Vy = newy; - BroadcastPacket(M_NEW_PAGE, 5, - Scr.Vx, Scr.Vy, Scr.CurrentDesk, Scr.VxMax, Scr.VyMax); - - if((deltax!=0)||(deltay!=0)) - { - -/* - RBW - 11/13/1998 - new: chase the chain bidirectionally, all at once! - The idea is to move the windows that are moving out of the viewport from - the bottom of the stacking order up, to minimize the expose-redraw overhead. - Windows that will be moving into view will be moved top down, for the same - reason. Use the new stacking-order chain, rather than the old - last-focussed chain. -*/ - - t = Scr.FvwmRoot.stack_next; - t1 = Scr.FvwmRoot.stack_prev; - while (t != &Scr.FvwmRoot || t1 != &Scr.FvwmRoot) - { - if (t != &Scr.FvwmRoot) - { - /* - If the window is moving into the viewport... + FvwmWindow *t, *t1; + int deltax, deltay; + int PageTop, PageLeft; + int PageBottom, PageRight; + int txl, txr, tyt, tyb; + + if (grab) + MyXGrabServer(dpy); + + if (newx > Scr.VxMax) + newx = Scr.VxMax; + if (newy > Scr.VyMax) + newy = Scr.VyMax; + if (newx < 0) + newx = 0; + if (newy < 0) + newy = 0; + + deltay = Scr.Vy - newy; + deltax = Scr.Vx - newx; + /* + Identify the bounding rectangle that will be moved into + the viewport. + */ + PageBottom = Scr.MyDisplayHeight - deltay; + PageRight = Scr.MyDisplayWidth - deltax; + PageTop = 0 - deltay; + PageLeft = 0 - deltax; + + Scr.Vx = newx; + Scr.Vy = newy; + BroadcastPacket(M_NEW_PAGE, 5, Scr.Vx, Scr.Vy, Scr.CurrentDesk, + Scr.VxMax, Scr.VyMax); + + if ((deltax != 0) || (deltay != 0)) { + /* + RBW - 11/13/1998 - new: chase the chain bidirectionally, all + at once! The idea is to move the windows that are moving out of + the viewport from the bottom of the stacking order up, to + minimize the expose-redraw overhead. Windows that will be moving + into view will be moved top down, for the same reason. Use the + new stacking-order chain, rather than the old last-focussed + chain. */ - txl = t->frame_x; - tyt = t->frame_y; - txr = t->frame_x + t->frame_width; - tyb = t->frame_y + t->frame_height; - if ((txr >= PageLeft && txl <= PageRight - && tyb >= PageTop && tyt <= PageBottom) - && ! t->tmpflags.ViewportMoved) - { - t->tmpflags.ViewportMoved = True; /* Block double move. */ - /* If the window is iconified, and sticky Icons is set, - * then the window should essentially be sticky */ - if(!((t->flags & ICONIFIED)&&(t->flags & StickyIcon)) && - (!(t->flags & STICKY))) - { - if(!(t->flags & StickyIcon)) - { - t->icon_x_loc += deltax; - t->icon_xl_loc += deltax; - t->icon_y_loc += deltay; - if(t->icon_pixmap_w != None) - XMoveWindow(dpy,t->icon_pixmap_w,t->icon_x_loc, - t->icon_y_loc); - if(t->icon_w != None) - XMoveWindow(dpy,t->icon_w,t->icon_x_loc, - t->icon_y_loc+t->icon_p_height); - if(!(t->flags &ICON_UNMAPPED)) - { - BroadcastPacket(M_ICON_LOCATION, 7, - t->w, t->frame, - (unsigned long)t, - t->icon_x_loc, t->icon_y_loc, - t->icon_w_width, - t->icon_w_height+t->icon_p_height); - } - } - SetupFrame (t, t->frame_x+ deltax, t->frame_y + deltay, - t->frame_width, t->frame_height,FALSE); - } - } - /* Bump to next win... */ - t = t->stack_next; - } - if (t1 != &Scr.FvwmRoot) - { - /* - If the window is not moving into the viewport... - */ - txl = t1->frame_x; - tyt = t1->frame_y; - txr = t1->frame_x + t1->frame_width; - tyb = t1->frame_y + t1->frame_height; - if (! (txr >= PageLeft && txl <= PageRight - && tyb >= PageTop && tyt <= PageBottom) - && ! t1->tmpflags.ViewportMoved) - { - t1->tmpflags.ViewportMoved = True; /* Block double move.*/ - /* If the window is iconified, and sticky Icons is set, - * then the window should essentially be sticky */ - if(!((t1->flags & ICONIFIED)&&(t1->flags & StickyIcon)) && - (!(t1->flags & STICKY))) - { - if(!(t1->flags & StickyIcon)) - { - t1->icon_x_loc += deltax; - t1->icon_xl_loc += deltax; - t1->icon_y_loc += deltay; - if(t1->icon_pixmap_w != None) - XMoveWindow(dpy,t1->icon_pixmap_w, - t1->icon_x_loc, - t1->icon_y_loc); - if(t1->icon_w != None) - XMoveWindow(dpy,t1->icon_w,t1->icon_x_loc, - t1->icon_y_loc+t1->icon_p_height); - if(!(t1->flags &ICON_UNMAPPED)) - { - BroadcastPacket(M_ICON_LOCATION, 7, - t1->w, t1->frame, - (unsigned long)t1, - t1->icon_x_loc, t1->icon_y_loc, - t1->icon_w_width, - t1->icon_w_height + - t1->icon_p_height); - } - } - SetupFrame (t1, t1->frame_x+ deltax, - t1->frame_y + deltay, - t1->frame_width, t1->frame_height,FALSE); - } - } - /* Bump to next win... */ - t1 = t1->stack_prev; - } - } - for (t = Scr.FvwmRoot.next; t != NULL; t = t->next) - { - t->tmpflags.ViewportMoved = False; /* Clear double move blocker. */ - /* If its an icon, and its sticking, autoplace it so - * that it doesn't wind up on top a a stationary - * icon */ - if(((t->flags & STICKY)||(t->flags & StickyIcon))&& - (t->flags & ICONIFIED)&&(!(t->flags & ICON_MOVED))&& - (!(t->flags & ICON_UNMAPPED))) - AutoPlace(t); - } - } - checkPanFrames(); + t = Scr.FvwmRoot.stack_next; + t1 = Scr.FvwmRoot.stack_prev; + while (t != &Scr.FvwmRoot || t1 != &Scr.FvwmRoot) { + if (t != &Scr.FvwmRoot) { + /* + If the window is moving into the + viewport... + */ + txl = t->frame_x; + tyt = t->frame_y; + txr = t->frame_x + t->frame_width; + tyb = t->frame_y + t->frame_height; + if ((txr >= PageLeft && txl <= PageRight && + tyb >= PageTop && tyt <= PageBottom) && + !t->tmpflags.ViewportMoved) { + t->tmpflags.ViewportMoved = + True; /* Block double move. */ + /* If the window is iconified, and + * sticky Icons is set, then the window + * should essentially be sticky */ + if (!((t->flags & ICONIFIED) && + (t->flags & StickyIcon)) && + (!(t->flags & STICKY))) { + if (!(t->flags & StickyIcon)) { + t->icon_x_loc += deltax; + t->icon_xl_loc += + deltax; + t->icon_y_loc += deltay; + if (t->icon_pixmap_w != + None) + XMoveWindow(dpy, + t->icon_pixmap_w, + t->icon_x_loc, + t->icon_y_loc); + if (t->icon_w != None) + XMoveWindow(dpy, + t->icon_w, + t->icon_x_loc, + t->icon_y_loc + + t->icon_p_height); + if (!(t->flags & + ICON_UNMAPPED)) { + BroadcastPacket( + M_ICON_LOCATION, + 7, t->w, + t->frame, + (unsigned long) + t, + t->icon_x_loc, + t->icon_y_loc, + t->icon_w_width, + t->icon_w_height + + t->icon_p_height); + } + } + SetupFrame(t, + t->frame_x + deltax, + t->frame_y + deltay, + t->frame_width, + t->frame_height, FALSE); + } + } + /* Bump to next win... */ + t = t->stack_next; + } + if (t1 != &Scr.FvwmRoot) { + /* + If the window is not moving into the + viewport... + */ + txl = t1->frame_x; + tyt = t1->frame_y; + txr = t1->frame_x + t1->frame_width; + tyb = t1->frame_y + t1->frame_height; + if (!(txr >= PageLeft && txl <= PageRight && + tyb >= PageTop && tyt <= PageBottom) && + !t1->tmpflags.ViewportMoved) { + t1->tmpflags.ViewportMoved = + True; /* Block double move.*/ + /* If the window is iconified, and + * sticky Icons is set, then the window + * should essentially be sticky */ + if (!((t1->flags & ICONIFIED) && + (t1->flags & StickyIcon)) && + (!(t1->flags & STICKY))) { + if (!(t1->flags & StickyIcon)) { + t1->icon_x_loc += + deltax; + t1->icon_xl_loc += + deltax; + t1->icon_y_loc += + deltay; + if (t1->icon_pixmap_w != + None) + XMoveWindow(dpy, + t1->icon_pixmap_w, + t1->icon_x_loc, + t1->icon_y_loc); + if (t1->icon_w != None) + XMoveWindow(dpy, + t1->icon_w, + t1->icon_x_loc, + t1->icon_y_loc + + t1->icon_p_height); + if (!(t1->flags & + ICON_UNMAPPED)) { + BroadcastPacket( + M_ICON_LOCATION, + 7, t1->w, + t1->frame, + (unsigned long) + t1, + t1->icon_x_loc, + t1->icon_y_loc, + t1->icon_w_width, + t1->icon_w_height + + t1->icon_p_height); + } + } + SetupFrame(t1, + t1->frame_x + deltax, + t1->frame_y + deltay, + t1->frame_width, + t1->frame_height, FALSE); + } + } + /* Bump to next win... */ + t1 = t1->stack_prev; + } + } + for (t = Scr.FvwmRoot.next; t != NULL; t = t->next) { + t->tmpflags.ViewportMoved = + False; /* Clear double move blocker. */ + /* If its an icon, and its sticking, autoplace it so + * that it doesn't wind up on top a a stationary + * icon */ + if (((t->flags & STICKY) || (t->flags & StickyIcon)) && + (t->flags & ICONIFIED) && + (!(t->flags & ICON_MOVED)) && + (!(t->flags & ICON_UNMAPPED))) + AutoPlace(t); + } + } + checkPanFrames(); - /* do this with PanFrames too ??? HEDU */ - while(XCheckTypedEvent(dpy,MotionNotify,&Event)) - StashEventTime(&Event); - if(grab) - MyXUngrabServer(dpy); + /* do this with PanFrames too ??? HEDU */ + while (XCheckTypedEvent(dpy, MotionNotify, &Event)) + StashEventTime(&Event); + if (grab) + MyXUngrabServer(dpy); } /************************************************************************** @@ -626,77 +615,65 @@ void MoveViewport(int newx, int newy, Bool grab) * read (or if action is empty). * **************************************************************************/ -int GetDeskNumber(char *action) +int +GetDeskNumber(char *action) { - int n; - int m; - int desk; - int val[4]; - int min, max; - - n = GetIntegerArguments(action, NULL, &(val[0]), 4); - if (n <= 0) - return Scr.CurrentDesk; - if (n == 1) - return Scr.CurrentDesk + val[0]; - - desk = Scr.CurrentDesk; - m = 0; - - if (val[0] == 0) - { - /* absolute desk number */ - desk = val[1]; - } - else - { - /* relative desk number */ - desk += val[0]; - } - - if (n == 3) - { - m = 1; - } - if (n == 4) - { - m = 2; - } - - - if (n > 2) - { - /* handle limits */ - if (val[m] <= val[m+1]) - { - min = val[m]; - max = val[m+1]; + int n; + int m; + int desk; + int val[4]; + int min, max; + + n = GetIntegerArguments(action, NULL, &(val[0]), 4); + if (n <= 0) + return Scr.CurrentDesk; + if (n == 1) + return Scr.CurrentDesk + val[0]; + + desk = Scr.CurrentDesk; + m = 0; + + if (val[0] == 0) { + /* absolute desk number */ + desk = val[1]; + } else { + /* relative desk number */ + desk += val[0]; } - else - { - /* min > max is nonsense, so swap 'em. */ - min = val[m+1]; - max = val[m]; + + if (n == 3) { + m = 1; } - if (desk < min) - { - /* Relative move outside of range, wrap around. */ - if (val[0] < 0) - desk = max; - else - desk = min; + if (n == 4) { + m = 2; } - else if (desk > max) - { - /* Relative move outside of range, wrap around. */ - if (val[0] > 0) - desk = min; - else - desk = max; + + if (n > 2) { + /* handle limits */ + if (val[m] <= val[m + 1]) { + min = val[m]; + max = val[m + 1]; + } else { + /* min > max is nonsense, so swap 'em. */ + min = val[m + 1]; + max = val[m]; + } + if (desk < min) { + /* Relative move outside of range, wrap around. */ + if (val[0] < 0) + desk = max; + else + desk = min; + } else if (desk > max) { + /* Relative move outside of range, wrap around. */ + if (val[0] > 0) + desk = min; + else + desk = max; + } } - } - return desk; + return desk; } /************************************************************************** @@ -704,228 +681,210 @@ int GetDeskNumber(char *action) * Move to a new desktop * *************************************************************************/ -void changeDesks_func(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context,char *action, int *Module) +void +changeDesks_func(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - changeDesks(GetDeskNumber(action)); + changeDesks(GetDeskNumber(action)); } -void changeDesks(int desk) +void +changeDesks(int desk) { - int oldDesk; - FvwmWindow *FocusWin = 0, *t, *t1; - static FvwmWindow *StickyWin = 0; - - oldDesk = Scr.CurrentDesk; - Scr.CurrentDesk = desk; - if(Scr.CurrentDesk == oldDesk) - return; - BroadcastPacket(M_NEW_DESK, 1, Scr.CurrentDesk); - /* Scan the window list, mapping windows on the new Desk, - * unmapping windows on the old Desk */ - MyXGrabServer(dpy); + int oldDesk; + FvwmWindow *FocusWin = 0, *t, *t1; + static FvwmWindow *StickyWin = 0; + + oldDesk = Scr.CurrentDesk; + Scr.CurrentDesk = desk; + if (Scr.CurrentDesk == oldDesk) + return; + BroadcastPacket(M_NEW_DESK, 1, Scr.CurrentDesk); + /* Scan the window list, mapping windows on the new Desk, + * unmapping windows on the old Desk */ + MyXGrabServer(dpy); -/* - RBW - 11/13/1998 - new: chase the chain bidirectionally, unmapping - windows bottom-up and mapping them top-down, to minimize expose-redraw - overhead. Use the new stacking-order chain, rather than the old - last-focussed chain. -*/ - t = Scr.FvwmRoot.stack_next; - t1 = Scr.FvwmRoot.stack_prev; - while (t != &Scr.FvwmRoot || t1 != &Scr.FvwmRoot) - { - if (t != &Scr.FvwmRoot) - { - if(!((t->flags & ICONIFIED)&&(t->flags & StickyIcon)) && - (!(t->flags & STICKY))&&(!(t->flags & ICON_UNMAPPED))) - { - if(t->Desk == Scr.CurrentDesk) - { - MapIt(t); - if (t->FocusDesk == Scr.CurrentDesk) - { - FocusWin = t; - } - } - } - else - /* - Only need to do these in one of the passes... - */ - { - /* Window is sticky */ - t->Desk = Scr.CurrentDesk; - if (Scr.Focus == t) - { - t->FocusDesk =oldDesk; - StickyWin = t; - } - } - t = t->stack_next; - } - if (t1 != &Scr.FvwmRoot) - { - /* Only change mapping for non-sticky windows */ - if(!((t1->flags & ICONIFIED)&&(t1->flags & StickyIcon)) && - (!(t1->flags & STICKY))&&(!(t1->flags & ICON_UNMAPPED))) - { - if(t1->Desk == oldDesk) - { - if (Scr.Focus == t1) - t1->FocusDesk = oldDesk; - else - t1->FocusDesk = -1; - UnmapIt(t1); - } - } - t1 = t1->stack_prev; - } - } - - - MyXUngrabServer(dpy); - for (t = Scr.FvwmRoot.next; t != NULL; t = t->next) - { - /* If its an icon, and its sticking, autoplace it so - * that it doesn't wind up on top a a stationary - * icon */ - if(((t->flags & STICKY)||(t->flags & StickyIcon))&& - (t->flags & ICONIFIED)&&(!(t->flags & ICON_MOVED))&& - (!(t->flags & ICON_UNMAPPED))) - AutoPlace(t); - } - - if((FocusWin)&&(FocusWin->flags & ClickToFocus)) + /* + RBW - 11/13/1998 - new: chase the chain bidirectionally, unmapping + windows bottom-up and mapping them top-down, to minimize expose-redraw + overhead. Use the new stacking-order chain, rather than the old + last-focussed chain. + */ + t = Scr.FvwmRoot.stack_next; + t1 = Scr.FvwmRoot.stack_prev; + while (t != &Scr.FvwmRoot || t1 != &Scr.FvwmRoot) { + if (t != &Scr.FvwmRoot) { + if (!((t->flags & ICONIFIED) && + (t->flags & StickyIcon)) && + (!(t->flags & STICKY)) && + (!(t->flags & ICON_UNMAPPED))) { + if (t->Desk == Scr.CurrentDesk) { + MapIt(t); + if (t->FocusDesk == Scr.CurrentDesk) { + FocusWin = t; + } + } + } else + /* + Only need to do these in one of the + passes... + */ + { + /* Window is sticky */ + t->Desk = Scr.CurrentDesk; + if (Scr.Focus == t) { + t->FocusDesk = oldDesk; + StickyWin = t; + } + } + t = t->stack_next; + } + if (t1 != &Scr.FvwmRoot) { + /* Only change mapping for non-sticky windows */ + if (!((t1->flags & ICONIFIED) && + (t1->flags & StickyIcon)) && + (!(t1->flags & STICKY)) && + (!(t1->flags & ICON_UNMAPPED))) { + if (t1->Desk == oldDesk) { + if (Scr.Focus == t1) + t1->FocusDesk = oldDesk; + else + t1->FocusDesk = -1; + UnmapIt(t1); + } + } + t1 = t1->stack_prev; + } + } + + MyXUngrabServer(dpy); + for (t = Scr.FvwmRoot.next; t != NULL; t = t->next) { + /* If its an icon, and its sticking, autoplace it so + * that it doesn't wind up on top a a stationary + * icon */ + if (((t->flags & STICKY) || (t->flags & StickyIcon)) && + (t->flags & ICONIFIED) && (!(t->flags & ICON_MOVED)) && + (!(t->flags & ICON_UNMAPPED))) + AutoPlace(t); + } + + if ((FocusWin) && (FocusWin->flags & ClickToFocus)) #ifndef NO_REMEMBER_FOCUS - SetFocus(FocusWin->w, FocusWin,0); - /* OK, someone beat me up, but I don't like this. If you are a predominantly - * focus-follows-mouse person, but put in one sticky click-to-focus window - * (typically because you don't really want to give focus to this window), - * then the following lines are screwed up. */ -/* else if (StickyWin && (StickyWin->flags & STICKY)) - SetFocus(StickyWin->w, StickyWin,1);*/ - else + SetFocus(FocusWin->w, FocusWin, 0); + /* OK, someone beat me up, but I don't like this. If you are a + * predominantly focus-follows-mouse person, but put in one sticky + * click-to-focus window (typically because you don't really want to + * give focus to this window), then the following lines are screwed up. + */ + /* else if (StickyWin && (StickyWin->flags & STICKY)) + SetFocus(StickyWin->w, StickyWin,1);*/ + else #endif - SetFocus(Scr.NoFocusWin,NULL,1); + SetFocus(Scr.NoFocusWin, NULL, 1); } - - /************************************************************************** * * Move a window to a new desktop * *************************************************************************/ -void changeWindowsDesk(XEvent *eventp,Window w,FvwmWindow *t, - unsigned long context,char *action, int *Module) +void +changeWindowsDesk(XEvent *eventp, Window w, FvwmWindow *t, + unsigned long context, char *action, int *Module) { - int desk; - - if (DeferExecution(eventp,&w,&t,&context,SELECT,ButtonRelease)) - return; - - if(t == NULL) - return; - - desk = GetDeskNumber(action); - if(desk == t->Desk) - return; - - /* - Set the window's desktop, and map or unmap it as needed. - */ - /* Only change mapping for non-sticky windows */ - if(!((t->flags & ICONIFIED)&&(t->flags & StickyIcon)) && - (!(t->flags & STICKY))&&(!(t->flags & ICON_UNMAPPED))) - { - if(t->Desk == Scr.CurrentDesk) - { - t->Desk = desk; - UnmapIt(t); + int desk; + + if (DeferExecution(eventp, &w, &t, &context, SELECT, ButtonRelease)) + return; + + if (t == NULL) + return; + + desk = GetDeskNumber(action); + if (desk == t->Desk) + return; + + /* + Set the window's desktop, and map or unmap it as needed. + */ + /* Only change mapping for non-sticky windows */ + if (!((t->flags & ICONIFIED) && (t->flags & StickyIcon)) && + (!(t->flags & STICKY)) && (!(t->flags & ICON_UNMAPPED))) { + if (t->Desk == Scr.CurrentDesk) { + t->Desk = desk; + UnmapIt(t); + } else if (desk == Scr.CurrentDesk) { + t->Desk = desk; + /* If its an icon, auto-place it */ + if (t->flags & ICONIFIED) + AutoPlace(t); + MapIt(t); + } else + t->Desk = desk; } - else if(desk == Scr.CurrentDesk) - { - t->Desk = desk; - /* If its an icon, auto-place it */ - if(t->flags & ICONIFIED) - AutoPlace(t); - MapIt(t); - } - else - t->Desk = desk; - - } - BroadcastConfig(M_CONFIGURE_WINDOW,t); + BroadcastConfig(M_CONFIGURE_WINDOW, t); } - -void scroll(XEvent *eventp,Window w,FvwmWindow *tmp_win,unsigned long context, - char *action, int *Module) +void +scroll(XEvent *eventp, Window w, FvwmWindow *tmp_win, unsigned long context, + char *action, int *Module) { - int x,y; - int val1, val2, val1_unit,val2_unit,n; - - n = GetTwoArguments(action, &val1, &val2, &val1_unit, &val2_unit); - - if((val1 > -100000)&&(val1 < 100000)) - x=Scr.Vx + val1*val1_unit/100; - else - x = Scr.Vx + (val1/1000)*val1_unit/100; - - if((val2 > -100000)&&(val2 < 100000)) - y=Scr.Vy + val2*val2_unit/100; - else - y = Scr.Vy + (val2/1000)*val2_unit/100; - - if(((val1 <= -100000)||(val1 >= 100000))&&(x>Scr.VxMax)) - { - x = 0; - y += Scr.MyDisplayHeight; - if(y > Scr.VyMax) - y=0; - } - if(((val1 <= -100000)||(val1 >= 100000))&&(x<0)) - { - x = Scr.VxMax; - y -= Scr.MyDisplayHeight; - if(y < 0) - y=Scr.VyMax; - } - if(((val2 <= -100000)||(val2>= 100000))&&(y>Scr.VyMax)) - { - y = 0; - x += Scr.MyDisplayWidth; - if(x > Scr.VxMax) - x=0; - } - if(((val2 <= -100000)||(val2>= 100000))&&(y<0)) - { - y = Scr.VyMax; - x -= Scr.MyDisplayWidth; - if(x < 0) - x=Scr.VxMax; - } - MoveViewport(x,y,True); + int x, y; + int val1, val2, val1_unit, val2_unit, n; + + n = GetTwoArguments(action, &val1, &val2, &val1_unit, &val2_unit); + + if ((val1 > -100000) && (val1 < 100000)) + x = Scr.Vx + val1 * val1_unit / 100; + else + x = Scr.Vx + (val1 / 1000) * val1_unit / 100; + + if ((val2 > -100000) && (val2 < 100000)) + y = Scr.Vy + val2 * val2_unit / 100; + else + y = Scr.Vy + (val2 / 1000) * val2_unit / 100; + + if (((val1 <= -100000) || (val1 >= 100000)) && (x > Scr.VxMax)) { + x = 0; + y += Scr.MyDisplayHeight; + if (y > Scr.VyMax) + y = 0; + } + if (((val1 <= -100000) || (val1 >= 100000)) && (x < 0)) { + x = Scr.VxMax; + y -= Scr.MyDisplayHeight; + if (y < 0) + y = Scr.VyMax; + } + if (((val2 <= -100000) || (val2 >= 100000)) && (y > Scr.VyMax)) { + y = 0; + x += Scr.MyDisplayWidth; + if (x > Scr.VxMax) + x = 0; + } + if (((val2 <= -100000) || (val2 >= 100000)) && (y < 0)) { + y = Scr.VyMax; + x -= Scr.MyDisplayWidth; + if (x < 0) + x = Scr.VxMax; + } + MoveViewport(x, y, True); } -void goto_page_func(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context,char *action, int *Module) +void +goto_page_func(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - int val[2], n, x, y; - - n = GetIntegerArguments(action, NULL, val, 2); - if(n != 2) - { - fvwm_msg(ERR,"goto_page_func","GotoPage requires two arguments"); - return; - } - - x = val[0] * Scr.MyDisplayWidth; - y = val[1] * Scr.MyDisplayHeight; - MoveViewport(x,y,True); -} - - + int val[2], n, x, y; + n = GetIntegerArguments(action, NULL, val, 2); + if (n != 2) { + fvwm_msg( + ERR, "goto_page_func", "GotoPage requires two arguments"); + return; + } + x = val[0] * Scr.MyDisplayWidth; + y = val[1] * Scr.MyDisplayHeight; + MoveViewport(x, y, True); +} Index: fvwm/fvwm/windows.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/windows.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/windows.c --- fvwm/fvwm/windows.c +++ fvwm/fvwm/windows.c @@ -11,341 +11,351 @@ * ***********************************************************************/ +#include +#include #include #include -#include #include -#include #include "config.h" -#include "fvwmlib.h" - #include "fvwm.h" +#include "fvwmlib.h" #include "menus.h" #include "misc.h" #include "parse.h" #include "screen.h" -#define SHOW_GEOMETRY (1<<0) -#define SHOW_ALLDESKS (1<<1) -#define SHOW_NORMAL (1<<2) -#define SHOW_ICONIC (1<<3) -#define SHOW_STICKY (1<<4) -#define SHOW_ONTOP (1<<5) -#define NO_DESK_SORT (1<<6) -#define SHOW_ICONNAME (1<<7) -#define SHOW_ALPHABETIC (1<<8) -#define SHOW_EVERYTHING (SHOW_GEOMETRY | SHOW_ALLDESKS | SHOW_NORMAL | SHOW_ICONIC | SHOW_STICKY | SHOW_ONTOP) +#define SHOW_GEOMETRY (1 << 0) +#define SHOW_ALLDESKS (1 << 1) +#define SHOW_NORMAL (1 << 2) +#define SHOW_ICONIC (1 << 3) +#define SHOW_STICKY (1 << 4) +#define SHOW_ONTOP (1 << 5) +#define NO_DESK_SORT (1 << 6) +#define SHOW_ICONNAME (1 << 7) +#define SHOW_ALPHABETIC (1 << 8) +#define SHOW_EVERYTHING \ + (SHOW_GEOMETRY | SHOW_ALLDESKS | SHOW_NORMAL | SHOW_ICONIC | \ + SHOW_STICKY | SHOW_ONTOP) /* Function to compare window title names */ static int globalFlags; -int winCompare(const FvwmWindow **a, const FvwmWindow **b) +int +winCompare(const FvwmWindow **a, const FvwmWindow **b) { - if(globalFlags & SHOW_ICONNAME) - return strcasecmp((*a)->icon_name,(*b)->icon_name); - else - return strcasecmp((*a)->name,(*b)->name); + if (globalFlags & SHOW_ICONNAME) + return strcasecmp((*a)->icon_name, (*b)->icon_name); + else + return strcasecmp((*a)->name, (*b)->name); } - /* * Change by PRB (pete@tecc.co.uk), 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) +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; + 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; + 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; + 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); + } } - } - 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); + 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; - } + 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); + /* 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 */ + 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 */ + 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; - } + /* 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_ICONNAME) + name = t->icon_name; + else + name = t->name; + hotlen = strlen(name) + strlen(tname) + 48; + t_hot = xmalloc(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)); + 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; + 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.base_width; + dheight -= t->hints.base_height; - dwidth /= t->hints.width_inc; - dheight /= t->hints.height_inc; + 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)); + 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); + 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 = xmalloc(40); + snprintf(tfunc, 40, + "WindowListFunc %ld", t->w); + } else { + size_t funclen = strlen(func) + 32; + tfunc = xmalloc(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 */ - } + /* 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 (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); + 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); } - Index: fvwm/fvwm/xalloc.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/xalloc.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/xalloc.h --- /dev/null +++ fvwm/fvwm/xalloc.h @@ -0,0 +1,77 @@ +#ifndef FVWM_XALLOC_H +#define FVWM_XALLOC_H + +#include +#include +#include + +static inline void * +xmalloc(size_t size) +{ + void *ptr; + + if (size == 0) + size = 1; + ptr = malloc(size); + if (ptr == NULL) + err(1, "malloc"); + return ptr; +} + +static inline void * +xcalloc(size_t nmemb, size_t size) +{ + void *ptr; + + if (nmemb == 0 || size == 0) { + nmemb = 1; + size = 1; + } + ptr = calloc(nmemb, size); + if (ptr == NULL) + err(1, "calloc"); + return ptr; +} + +static inline void * +xrealloc(void *ptr, size_t size) +{ + void *newptr; + + if (size == 0) + size = 1; + newptr = realloc(ptr, size); + if (newptr == NULL) + err(1, "realloc"); + return newptr; +} + +static inline void * +xreallocarray(void *ptr, size_t nmemb, size_t size) +{ + return xrealloc(ptr, nmemb * size); +} + +static inline char * +xstrdup(const char *s) +{ + char *copy; + + copy = strdup(s); + if (copy == NULL) + err(1, "strdup"); + return copy; +} + +static inline char * +xstrndup(const char *s, size_t n) +{ + char *copy; + + copy = strndup(s, n); + if (copy == NULL) + err(1, "strndup"); + return copy; +} + +#endif /* FVWM_XALLOC_H */ Index: fvwm/libs/ClientMsg.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/libs/ClientMsg.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/libs/ClientMsg.c --- fvwm/libs/ClientMsg.c +++ fvwm/libs/ClientMsg.c @@ -11,24 +11,25 @@ * data[1] time stamp * ****************************************************************************/ -#include #include +#include #include Atom _XA_WM_PROTOCOLS = None; -void send_clientmessage (Display *disp, Window w, Atom a, Time timestamp) +void +send_clientmessage(Display *disp, Window w, Atom a, Time timestamp) { - XClientMessageEvent ev; + XClientMessageEvent ev; - if (_XA_WM_PROTOCOLS == None) - _XA_WM_PROTOCOLS = XInternAtom(disp, "WM_PROTOCOLS", False); + if (_XA_WM_PROTOCOLS == None) + _XA_WM_PROTOCOLS = XInternAtom(disp, "WM_PROTOCOLS", False); - ev.type = ClientMessage; - ev.window = w; - ev.message_type = _XA_WM_PROTOCOLS; - ev.format = 32; - ev.data.l[0] = a; - ev.data.l[1] = timestamp; - XSendEvent (disp, w, False, 0L, (XEvent *) &ev); + ev.type = ClientMessage; + ev.window = w; + ev.message_type = _XA_WM_PROTOCOLS; + ev.format = 32; + ev.data.l[0] = a; + ev.data.l[1] = timestamp; + XSendEvent(disp, w, False, 0L, (XEvent *)&ev); } Index: fvwm/libs/GetFont.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/libs/GetFont.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/libs/GetFont.c --- fvwm/libs/GetFont.c +++ fvwm/libs/GetFont.c @@ -1,32 +1,30 @@ -#include "config.h" - -#include -#include -#include - #include #include +#include +#include +#include +#include "config.h" #include "fvwmlib.h" /* ** loads font or "fixed" on failure */ -XFontStruct *GetFontOrFixed(Display *disp, char *fontname) +XFontStruct * +GetFontOrFixed(Display *disp, char *fontname) { - XFontStruct *fnt; + XFontStruct *fnt; - if ((fnt = XLoadQueryFont(disp,fontname))==NULL) - { - fprintf(stderr, - "[GetFontOrFixed]: WARNING -- can't get font %s, trying 'fixed'", - fontname); - /* fixed should always be avail, so try that */ - if ((fnt = XLoadQueryFont(disp,"fixed"))==NULL) - { - fprintf(stderr,"[GetFontOrFixed]: ERROR -- can't get font 'fixed'"); - } - } - return fnt; + if ((fnt = XLoadQueryFont(disp, fontname)) == NULL) { + fprintf(stderr, + "[GetFontOrFixed]: WARNING -- can't get font %s, trying " + "'fixed'", + fontname); + /* fixed should always be avail, so try that */ + if ((fnt = XLoadQueryFont(disp, "fixed")) == NULL) { + fprintf(stderr, "[GetFontOrFixed]: ERROR -- can't get " + "font 'fixed'"); + } + } + return fnt; } - Index: fvwm/libs/GetFontSet.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/libs/GetFontSet.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/libs/GetFontSet.c --- fvwm/libs/GetFontSet.c +++ fvwm/libs/GetFontSet.c @@ -1,38 +1,38 @@ /* This file brings from GetFont.c */ -#include "../configure.h" - -#include -#include -#include - #include #include +#include +#include +#include +#include "../configure.h" #include "fvwmlib.h" /* ** loads fontset or "fixed" on failure */ -XFontSet GetFontSetOrFixed(Display *disp, char *fontname) +XFontSet +GetFontSetOrFixed(Display *disp, char *fontname) { - XFontSet fontset; - char **ml; - int mc; - char *ds; + XFontSet fontset; + char **ml; + int mc; + char *ds; - if ((fontset = XCreateFontSet(disp,fontname,&ml,&mc,&ds))==NULL) - { - fprintf(stderr, - "[FVWM][GetFontSetOrFixed]: WARNING -- can't get fontset %s, trying 'fixed'\n", - fontname); - /* fixed should always be avail, so try that */ - /* plain X11R6.3 hack */ - if ((fontset = XCreateFontSet(disp,"fixed,-*--14-*",&ml,&mc,&ds))==NULL) - { - fprintf(stderr,"[FVWM][GetFontSetOrFixed]: ERROR -- can't get fontset 'fixed'\n"); - } - } - return fontset; + if ((fontset = XCreateFontSet(disp, fontname, &ml, &mc, &ds)) == NULL) { + fprintf(stderr, + "[FVWM][GetFontSetOrFixed]: WARNING -- can't get fontset " + "%s, trying 'fixed'\n", + fontname); + /* fixed should always be avail, so try that */ + /* plain X11R6.3 hack */ + if ((fontset = XCreateFontSet( + disp, "fixed,-*--14-*", &ml, &mc, &ds)) == NULL) { + fprintf(stderr, + "[FVWM][GetFontSetOrFixed]: ERROR -- can't get " + "fontset 'fixed'\n"); + } + } + return fontset; } - Index: fvwm/libs/Grab.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/libs/Grab.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/libs/Grab.c --- fvwm/libs/Grab.c +++ fvwm/libs/Grab.c @@ -7,25 +7,23 @@ /* Made into global for module interface. See module.c. */ int myxgrabcount = 0; -void MyXGrabServer(Display *disp) +void +MyXGrabServer(Display *disp) { - if (myxgrabcount == 0) - { - XGrabServer(disp); - } - ++myxgrabcount; + if (myxgrabcount == 0) { + XGrabServer(disp); + } + ++myxgrabcount; } -void MyXUngrabServer(Display *disp) +void +MyXUngrabServer(Display *disp) { - if (--myxgrabcount < 0) /* should never happen */ - { - /* fvwm_msg(ERR,"MyXUngrabServer","too many ungrabs!\n"); */ - myxgrabcount = 0; - } - if (myxgrabcount == 0) - { - XUngrabServer(disp); - } + if (--myxgrabcount < 0) { /* should never happen */ + /* fvwm_msg(ERR,"MyXUngrabServer","too many ungrabs!\n"); */ + myxgrabcount = 0; + } + if (myxgrabcount == 0) { + XUngrabServer(disp); + } } - Index: fvwm/libs/ModParse.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/libs/ModParse.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/libs/ModParse.c --- fvwm/libs/ModParse.c +++ fvwm/libs/ModParse.c @@ -9,9 +9,9 @@ itself for parsing. */ +#include "ModParse.h" #include "fvwmlib.h" -#include "ModParse.h" /* ** PeekArgument: returns next token from string, leaving string intact @@ -24,146 +24,130 @@ ** to MAX_TOKEN_LENGTH in size. */ - -char *DoPeekArgument(const char *pstr, char **pret) +char * +DoPeekArgument(const char *pstr, const char **pret) { - char *tok=NULL; - const char *p; - char bc=0,be=0,tmptok[MAX_TOKEN_LENGTH]; - int len=0; - - if (!pstr) - return NULL; - - p=pstr; - EatWS(p); /* skip leading space */ - if (*p) - { - if (IsQuote(*p) || IsBlockStart(*p)) /* quoted string or block start? */ - { - bc = *p; /* save block start char */ - p++; - } - /* find end of token */ - while (*p && len < MAX_TOKEN_LENGTH) - { - /* first, check stop conditions based on block or normal token */ - if (bc) - { - if ((IsQuote(*p) && bc == *p) || IsBlockEnd(*p,bc)) - { - be = *p; - break; - } - } - else /* normal token */ - { - if (isspace(*p) || *p == ',') - break; - } - - if (*p == '\\' && *(p+1)) /* if \, copy next char verbatim */ - p++; - tmptok[len] = *p; - len++; - p++; - } - - /* sanity checks: */ - if (bc && !be) /* did we have block start, but not end? */ - { - /* should yell about this */ - return NULL; - } - - if (len) - { - tok = (char *)safemalloc(len+1); - strncpy(tok,tmptok,len); - tok[len]='\0'; - } - } - - if (!isspace(*p)) p++; - if (pret) *pret = p; - return tok; + char *tok = NULL; + const char *p; + char bc = 0, be = 0, tmptok[MAX_TOKEN_LENGTH]; + int len = 0; + + if (!pstr) + return NULL; + + p = pstr; + EatWS(p); /* skip leading space */ + if (*p) { + if (IsQuote(*p) || + IsBlockStart(*p)) { /* quoted string or block start? */ + bc = *p; /* save block start char */ + p++; + } + /* find end of token */ + while (*p && len < MAX_TOKEN_LENGTH) { + /* first, check stop conditions based on block or normal + * token */ + if (bc) { + if ((IsQuote(*p) && bc == *p) || + IsBlockEnd(*p, bc)) { + be = *p; + break; + } + } else /* normal token */ { + if (isspace(*p) || *p == ',') + break; + } + + if (*p == '\\' && + *(p + 1)) /* if \, copy next char verbatim */ + p++; + tmptok[len] = *p; + len++; + p++; + } + + /* sanity checks: */ + if (bc && !be) { /* did we have block start, but not end? */ + /* should yell about this */ + return NULL; + } + + if (len) { + tok = (char *)xmalloc(len + 1); + strncpy(tok, tmptok, len); + tok[len] = '\0'; + } + } + + if (*p && !isspace((unsigned char)*p)) + p++; + if (pret) + *pret = p; + return tok; } -char *PeekArgument(const char *pstr) +char * +PeekArgument(const char *pstr) { - return DoPeekArgument(pstr, NULL); + return DoPeekArgument(pstr, NULL); } /* ** GetArgument: destructively rips next token from string, returning it ** (you should free returned string later) */ -char *GetArgument(char **pstr) +char * +GetArgument(char **pstr) { - char *tok ; + char *tok; + const char *next = NULL; - if (!pstr || !*pstr || !(tok=DoPeekArgument(*pstr, pstr))) - return NULL; /* *pstr=NULL; ???? */ + if (!pstr || !*pstr || !(tok = DoPeekArgument(*pstr, &next))) + return NULL; - /* skip tok and following whitespace/separators in pstr & DON'T realloc */ - EatWS(*pstr); + *pstr = (char *)next; + /* skip tok and following whitespace/separators in pstr & DON'T realloc + */ + EatWS(*pstr); - if (!**pstr) - *pstr=NULL; /* change \0 to NULL */ + if (*pstr && !**pstr) + *pstr = NULL; /* change \0 to NULL */ - return tok; + return tok; } /* ** CmpArgument: does case-insensitive compare on next token in string, leaving ** string intact (return code like strcmp) */ -int CmpArgument(const char *pstr,char *tok) +int +CmpArgument(const char *pstr, char *tok) { - int rc=0; - char *ntok=PeekArgument(pstr); - if (ntok) - { - rc = strcasecmp(tok,ntok); - free(ntok); - } - return rc; + int rc = 0; + char *ntok = PeekArgument(pstr); + if (ntok) { + rc = strcasecmp(tok, ntok); + free(ntok); + } + return rc; } /* ** MatchArgument: does case-insensitive compare on next token in string, leaving ** string intact (returns true if matches, false otherwise) */ -int MatchArgument(const char *pstr,char *tok) +int +MatchArgument(const char *pstr, char *tok) { - int rc=0; - char *ntok=PeekArgument(pstr); - if (ntok) - { - rc = (strcasecmp(tok,ntok)==0); - free(ntok); - } - return rc; + int rc = 0; + char *ntok = PeekArgument(pstr); + if (ntok) { + rc = (strcasecmp(tok, ntok) == 0); + free(ntok); + } + return rc; } - -#if 0 -/* -** GetNextArgument: equiv interface of old parsing routine, for ease of transition -*/ -char *GetNextArgument(char *indata,char **token) -{ - char *nindata=indata; - - *token = PeekArgument(indata); - - if (*token) - nindata+=strlen(*token); - EatWS(nindata); - - return nindata; -} -#else /**************************************************************************** * * Gets the next "word" of input from char string indata. @@ -171,83 +155,71 @@ char *GetNextArgument(char *indata,char **token) * Return value is ptr to indata,updated to point to text after the word * which is extracted. * token is the extracted word, which is copied into a malloced - * space, and must be freed after use. + * space, and must be freed after use. * **************************************************************************/ -char *GetNextArgument(char *indata,char **token) -{ - char *t,*start, *end, *text; - - t = indata; - if(t == NULL) - { - *token = NULL; - return NULL; - } - while(isspace(*t)&&(*t != 0))t++; - start = t; - while(!isspace(*t)&&(*t != 0)) - { - /* Check for qouted text */ - if(*t == '"') - { - t++; - while((*t != '"')&&(*t != 0)) - { - /* Skip over escaped text, ie \" or \space " */ - if((*t == '\\')&&(*(t+1) != 0)) - t++; - t++; - } - if(*t == '"') - t++; - } - else - { - /* Skip over escaped text, ie \" or \space " */ - if((*t == '\\')&&(*(t+1) != 0)) - t++; - t++; +char * +GetNextArgument(char *indata, char **token) +{ + char *t, *start, *end, *text; + + t = indata; + if (t == NULL) { + *token = NULL; + return NULL; } - } - end = t; - - text = safemalloc(end-start+1); - *token = text; - - while(start < end) - { - /* Check for qouted text */ - if(*start == '"') - { - start++; - while((*start != '"')&&(*start != 0)) - { - /* Skip over escaped text, ie \" or \space " */ - if((*start == '\\')&&(*(start+1) != 0)) - start++; - *text++ = *start++; - } - if(*start == '"') - start++; + while (isspace(*t) && (*t != 0)) + t++; + start = t; + while (!isspace(*t) && (*t != 0)) { + /* Check for qouted text */ + if (*t == '"') { + t++; + while ((*t != '"') && (*t != 0)) { + /* Skip over escaped text, ie \" or \space " */ + if ((*t == '\\') && (*(t + 1) != 0)) + t++; + t++; + } + if (*t == '"') + t++; + } else { + /* Skip over escaped text, ie \" or \space " */ + if ((*t == '\\') && (*(t + 1) != 0)) + t++; + t++; + } } - else - { - /* Skip over escaped text, ie \" or \space " */ - if((*start == '\\')&&(*(start+1) != 0)) - start++; - *text++ = *start++; + end = t; + + text = xmalloc(end - start + 1); + *token = text; + + while (start < end) { + /* Check for qouted text */ + if (*start == '"') { + start++; + while ((*start != '"') && (*start != 0)) { + /* Skip over escaped text, ie \" or \space " */ + if ((*start == '\\') && (*(start + 1) != 0)) + start++; + *text++ = *start++; + } + if (*start == '"') + start++; + } else { + /* Skip over escaped text, ie \" or \space " */ + if ((*start == '\\') && (*(start + 1) != 0)) + start++; + *text++ = *start++; + } } - } - *text = 0; - if(*end != 0) - end++; + *text = 0; + if (*end != 0) + end++; - return end; + return end; } -#endif /* 0 */ - - /* function: MatchToken @@ -256,29 +228,6 @@ char *GetNextArgument(char *indata,char **token) NULL if no match */ -#if 0 /* supported in 2.0.47b */ -const char *MatchToken(register const char *s, register const char *w) -{ - if (s==NULL) return NULL; - assert(w!=NULL); /* the token may not be NULL -> design flaw */ - - while (*w && (*s==*w || -#ifdef WORD_IS_UPPERCASE - isupper(*s) && _toupper(*s)==*w -#else - toupper(*s)==toupper(*w) -#endif - )) - s++,w++; - - if (*w=='\0' && /* end of word and */ - (*s=='\0' || ispunct(*s) || isspace(*s))) /* same in string */ - return s; /* return endptr */ - else - return NULL; /* no match */ -} -#endif - /* function: CmpToken description: compare 1st word of s to 1st word of w @@ -286,31 +235,44 @@ const char *MatchToken(register const char *s, register const char *w) = 0 if s = t > 0 if s > t - Note arguments are not declares register, so the function can be + Note arguments are not declares register, so the function can be used with the bsearch() function of the c library. */ -int XCmpToken(char *s, char **t) +int +XCmpToken(const void *vs, const void *vt) { - register char *w=*t; + const char *s = (const char *)vs; + const char *w = *(const char *const *)vt; - if (w==NULL) return 1; /* non existant word */ - if (s==NULL) return -1; /* non existant string */ + if (w == NULL) + return 1; /* non existant word */ + if (s == NULL) + return -1; /* non existant string */ - while (*w && (*s==*w || #ifdef WORD_IS_UPPERCASE - isupper(*s) && _toupper(*s)==*w + while (*w && + (*s == *w || + (isupper((unsigned char)*s) && + _toupper((unsigned char)*s) == *w))) { + s++, w++; + } #else - toupper(*s)==toupper(*w) + while (*w && + (*s == *w || + toupper((unsigned char)*s) == + toupper((unsigned char)*w))) { + s++, w++; + } #endif - )) - s++,w++; - - if ((*s=='\0' && (ispunct(*w) || isspace(*w)))|| - (*w=='\0' && (ispunct(*s) || isspace(*s))) ) - return 0; /* 1st word equal */ - else - return toupper(*s)-toupper(*w); /* smaller/greater */ -} + if ((*s == '\0' && + (ispunct((unsigned char)*w) || isspace((unsigned char)*w))) || + (*w == '\0' && + (ispunct((unsigned char)*s) || isspace((unsigned char)*s)))) + return 0; /* 1st word equal */ + else + return toupper((unsigned char)*s) - + toupper((unsigned char)*w); /* smaller/greater */ +} Index: fvwm/libs/ModParse.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/libs/ModParse.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/libs/ModParse.h --- fvwm/libs/ModParse.h +++ fvwm/libs/ModParse.h @@ -13,16 +13,15 @@ #include #include +#include /* for free() */ #include -#include /* for free() */ char *PeekArgument(const char *pstr); char *GetArgument(char **pstr); -int CmpArgument(const char *pstr,char *tok); -int MatchArgument(const char *pstr,char *tok); +int CmpArgument(const char *pstr, char *tok); +int MatchArgument(const char *pstr, char *tok); #define NukeArgument(pstr) free(GetArgument(pstr)) - /* function: FindToken description: find the entry of type 'struct_entry' @@ -33,44 +32,12 @@ int MatchArgument(const char *pstr,char *tok); table must be sorted in ascending order for FindToken. */ -#define FindToken(key,table,struct_entry) \ - (struct_entry *) bsearch(key, \ - (char *)(table), \ - sizeof(table) / sizeof(struct_entry), \ - sizeof(struct_entry), \ - XCmpToken) - -int XCmpToken(); /* (char *s, char **t); but avoid compiler warning */ - /* needed by (L)FindToken */ - -#if 0 -/* e.g: */ - - struct entry /* these are stored in the table */ - { char *token; - /* ... */ /* any info */ - }; - - struct entry table[] = { /* ... */ }; /* define entries here */ - - char *word = GetArgument( /* ... */); - entry_ptr = FindToken(word,table,struct entry); - - (struct token *)bsearch("Style", - (char *)table, sizeof (table)/sizeof (struct entry), - sizeof(struct entry), CmpToken); -#endif /* 0 */ +#define FindToken(key, table, struct_entry) \ + (struct_entry *)bsearch(key, (char *)(table), \ + sizeof(table) / sizeof(struct_entry), sizeof(struct_entry), \ + XCmpToken) -#if 0 -/* Note that lfind() is not part of the ANSI standard. This is never used - * currently; I think we should just keep it that way... - */ -# define LFindToken(key,table,struct_entry) \ - (struct_entry *) lfind(key, \ - (char *)(table), \ - sizeof(table) / sizeof(struct_entry), \ - sizeof(struct_entry), \ - XCmpToken) -#endif /* 0 */ +int XCmpToken(const void *s, const void *t); +/* needed by (L)FindToken */ -#endif /* MODPARSE_H */ +#endif /* MODPARSE_H */ Index: fvwm/libs/Module.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/libs/Module.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/libs/Module.c --- fvwm/libs/Module.c +++ fvwm/libs/Module.c @@ -1,17 +1,15 @@ /* ** Module.c: code for modules to communicate with fvwm */ -#include "config.h" +#include "../fvwm/module.h" -#include -#include #include - #include +#include +#include +#include "config.h" #include "fvwmlib.h" -#include "../fvwm/module.h" - /************************************************************************ * @@ -30,43 +28,40 @@ * body is a malloc'ed space which needs to be freed * **************************************************************************/ -int ReadFvwmPacket(int fd, unsigned long *header, unsigned long **body) +int +ReadFvwmPacket(int fd, unsigned long *header, unsigned long **body) { - int count,total,count2,body_length; - char *cbody; - extern RETSIGTYPE DeadPipe(int); - - errno = 0; - if((count = read(fd,header,HEADER_SIZE*sizeof(unsigned long))) >0) - { - if(header[0] == START_FLAG) - { - body_length = header[2]-HEADER_SIZE; - *body = (unsigned long *) - safemalloc(body_length * sizeof(unsigned long)); - cbody = (char *)(*body); - total = 0; - while(total < body_length*sizeof(unsigned long)) - { - errno = 0; - if((count2= - read(fd,&cbody[total], - body_length*sizeof(unsigned long)-total)) >0) - { - total += count2; - } - else if(count2 < 0) - { - DeadPipe(errno); - } - } - } - else - count = 0; - } - if(count <= 0) - DeadPipe(errno); - return count; + int count, total, count2, body_length; + char *cbody; + extern void DeadPipe(int); + + errno = 0; + if ((count = read(fd, header, HEADER_SIZE * sizeof(unsigned long))) > + 0) { + if (header[0] == START_FLAG) { + if (header[2] < HEADER_SIZE) + return -1; + body_length = header[2] - HEADER_SIZE; + *body = (unsigned long *)xmalloc( + body_length * sizeof(unsigned long)); + cbody = (char *)(*body); + total = 0; + while (total < body_length * sizeof(unsigned long)) { + errno = 0; + if ((count2 = read(fd, &cbody[total], + body_length * sizeof(unsigned long) - + total)) > 0) { + total += count2; + } else if (count2 < 0) { + DeadPipe(errno); + } + } + } else + count = 0; + } + if (count <= 0) + DeadPipe(errno); + return count; } /************************************************************************ @@ -74,23 +69,23 @@ int ReadFvwmPacket(int fd, unsigned long *header, unsigned long **body) * SendText - Sends arbitrary text/command back to fvwm * ***********************************************************************/ -void SendText(int *fd,char *message,unsigned long window) +void +SendText(int *fd, char *message, unsigned long window) { - int w; + int w; - if(message != NULL) - { - write(fd[0],&window, sizeof(unsigned long)); + if (message != NULL) { + write(fd[0], &window, sizeof(unsigned long)); - w=strlen(message); - write(fd[0],&w,sizeof(int)); - if (w) - write(fd[0],message,w); + w = strlen(message); + write(fd[0], &w, sizeof(int)); + if (w) + write(fd[0], message, w); - /* keep going */ - w = 1; - write(fd[0],&w,sizeof(int)); - } + /* keep going */ + w = 1; + write(fd[0], &w, sizeof(int)); + } } /*************************************************************************** @@ -98,12 +93,13 @@ void SendText(int *fd,char *message,unsigned long window) * Sets the which-message-types-do-I-want mask for modules * **************************************************************************/ -void SetMessageMask(int *fd, unsigned long mask) +void +SetMessageMask(int *fd, unsigned long mask) { - char set_mask_mesg[50]; + char set_mask_mesg[50]; - snprintf(set_mask_mesg, sizeof(set_mask_mesg), "SET_MASK %lu\n",mask); - SendText(fd,set_mask_mesg,0); + snprintf(set_mask_mesg, sizeof(set_mask_mesg), "SET_MASK %lu\n", mask); + SendText(fd, set_mask_mesg, 0); } /*************************************************************************** @@ -116,50 +112,48 @@ void SetMessageMask(int *fd, unsigned long mask) * input area. This could have led to the creation of a core file. Added * "body_size" to keep it in bounds. **************************************************************************/ -void GetConfigLine(int *fd, char **tline) +void +GetConfigLine(int *fd, char **tline) { - static int first_pass = 1; - int count,done = 0; - int body_size; - static char *line = NULL; - unsigned long header[HEADER_SIZE]; - - if(line != NULL) - free(line); - - if(first_pass) - { - SendInfo(fd,"Send_ConfigInfo",0); - first_pass = 0; - } - - while(!done) - { - count = ReadFvwmPacket(fd[1],header,(unsigned long **)&line); - /* DB(("Packet count is %d", count)); */ - if (count <= 0) - *tline = NULL; - else { - *tline = &line[3*sizeof(long)]; - body_size = header[2]-HEADER_SIZE; - /* DB(("Config line (%d): `%s'", body_size, body_size ? *tline : "")); */ - while((body_size > 0) - && isspace(**tline)) { - (*tline)++; - --body_size; - } - } - -/* fprintf(stderr,"%x %x\n",header[1],M_END_CONFIG_INFO);*/ - if(header[1] == M_CONFIG_INFO) - done = 1; - else if(header[1] == M_END_CONFIG_INFO) - { - done = 1; - if(line != NULL) - free(line); - line = NULL; - *tline = NULL; - } - } + static int first_pass = 1; + int count, done = 0; + int body_size; + static char *line = NULL; + unsigned long header[HEADER_SIZE]; + + if (line != NULL) + free(line); + + if (first_pass) { + SendInfo(fd, "Send_ConfigInfo", 0); + first_pass = 0; + } + + while (!done) { + count = ReadFvwmPacket(fd[1], header, (unsigned long **)&line); + /* DB(("Packet count is %d", count)); */ + if (count <= 0) + *tline = NULL; + else { + *tline = &line[3 * sizeof(long)]; + body_size = header[2] - HEADER_SIZE; + /* DB(("Config line (%d): `%s'", body_size, body_size ? + * *tline : "")); */ + while ((body_size > 0) && isspace(**tline)) { + (*tline)++; + --body_size; + } + } + + /* fprintf(stderr,"%x %x\n",header[1],M_END_CONFIG_INFO);*/ + if (header[1] == M_CONFIG_INFO) + done = 1; + else if (header[1] == M_END_CONFIG_INFO) { + done = 1; + if (line != NULL) + free(line); + line = NULL; + *tline = NULL; + } + } } Index: fvwm/libs/Parse.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/libs/Parse.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/libs/Parse.c --- fvwm/libs/Parse.c +++ fvwm/libs/Parse.c @@ -2,11 +2,11 @@ ** Parse.c: routines for parsing in fvwm & modules */ -#include "config.h" - #include -#include #include +#include + +#include "config.h" #include "fvwmlib.h" /* If the string s begins with a quote chracter SkipQuote returns a pointer @@ -30,48 +30,43 @@ * * The defaults are used if NULL is passed for the corresponding string. */ -char *SkipQuote(char *s, const char *qlong, const char *qstart, - const char *qend) +char * +SkipQuote(char *s, const char *qlong, const char *qstart, const char *qend) { - char *t; - - if (s == NULL || *s == 0) - return s; - if (!qlong) - qlong = "\"'`"; - if (!qstart) - qstart = ""; - if (!qend) - qend = ""; - - if (*s == '\\' && s[1] != 0) - return s+2; - else if (*qlong && (t = strchr(qlong, *s))) - { - char c = *t; - - s++; - while(*s && *s != c) - { - /* Skip over escaped text, ie \quote */ - if(*s == '\\' && *(s+1) != 0) - s++; - s++; - } - if(*s == c) - s++; - return s; - } - else if (*qstart && (t = strchr(qstart, *s))) - { - char c = *((t - qstart) + qend); - - while (*s && *s != c) - s = SkipQuote(s, qlong, "", ""); - return (*s == *t) ? ++s : s; - } - else - return ++s; + char *t; + + if (s == NULL || *s == 0) + return s; + if (!qlong) + qlong = "\"'`"; + if (!qstart) + qstart = ""; + if (!qend) + qend = ""; + + if (*s == '\\' && s[1] != 0) + return s + 2; + else if (*qlong && (t = strchr(qlong, *s))) { + char c = *t; + + s++; + while (*s && *s != c) { + /* Skip over escaped text, ie \quote */ + if (*s == '\\' && *(s + 1) != 0) + s++; + s++; + } + if (*s == c) + s++; + return s; + } else if (*qstart && (t = strchr(qstart, *s))) { + char c = *((t - qstart) + qend); + + while (*s && *s != c) + s = SkipQuote(s, qlong, "", ""); + return (*s == *t) ? ++s : s; + } else + return ++s; } /* Returns a string up to the first character from the string delims in a @@ -79,27 +74,27 @@ char *SkipQuote(char *s, const char *qlong, const char *qstart, * returned string. The returned string is stored in *sout, the return value * of this call is a pointer to the first character after the delimiter or * to the terminating '\0'. Quoting is handled like in SkipQuote. */ -char *GetQuotedString(char *sin, char **sout, const char *delims, - const char *qlong, const char *qstart, const char *qend) +char * +GetQuotedString(char *sin, char **sout, const char *delims, const char *qlong, + const char *qstart, const char *qend) { - char *t = sin; - unsigned int len; - - if (!sout || !sin) - return NULL; - - while (*t && !strchr(delims, *t)) - t = SkipQuote(t, qlong, qstart, qend); - len = t - sin; - *sout = (char *)safemalloc(len + 1); - memcpy(*sout, sin, len); - (*sout)[len] = 0; - if (*t) - t++; - - return t; -} + char *t = sin; + unsigned int len; + + if (!sout || !sin) + return NULL; + + while (*t && !strchr(delims, *t)) + t = SkipQuote(t, qlong, qstart, qend); + len = t - sin; + *sout = (char *)xmalloc(len + 1); + memcpy(*sout, sin, len); + (*sout)[len] = 0; + if (*t) + t++; + return t; +} /* ** PeekToken: returns next token from string, leaving string intact @@ -111,117 +106,114 @@ char *GetQuotedString(char *sin, char **sout, const char *delims, ** must be escaped too, if you want one... (\\). Tokens may be up ** to MAX_TOKEN_LENGTH in size. */ -char *PeekToken(const char *pstr) +char * +PeekToken(const char *pstr) { - char *tok=NULL; - const char* p; - char bc=0,be=0,tmptok[MAX_TOKEN_LENGTH]; - int len=0; - - if (!pstr) - return NULL; - - p=pstr; - EatWS(p); /* skip leading space */ - if (*p) - { - if (IsQuote(*p) || IsBlockStart(*p)) /* quoted string or block start? */ - { - bc = *p; /* save block start char */ - p++; - } - /* find end of token */ - while (*p && len < MAX_TOKEN_LENGTH) - { - /* first, check stop conditions based on block or normal token */ - if (bc) - { - if ((IsQuote(*p) && bc == *p) || IsBlockEnd(*p,bc)) - { - be = *p; - break; - } - } - else /* normal token */ - { - if (isspace((unsigned char)*p) || *p == ',') - break; - } - - if (*p == '\\' && *(p+1)) /* if \, copy next char verbatim */ - p++; - tmptok[len] = *p; - len++; - p++; - } - - /* sanity checks: */ - if (bc && !be) /* did we have block start, but not end? */ - { - /* should yell about this */ - return NULL; - } - - if (len) - { - tok = (char *)malloc(len+1); - strncpy(tok,tmptok,len); - tok[len]='\0'; - } - } - - return tok; + char *tok = NULL; + const char *p; + char bc = 0, be = 0, tmptok[MAX_TOKEN_LENGTH]; + int len = 0; + + if (!pstr) + return NULL; + + p = pstr; + EatWS(p); /* skip leading space */ + if (*p) { + if (IsQuote(*p) || + IsBlockStart(*p)) { /* quoted string or block start? */ + bc = *p; /* save block start char */ + p++; + } + /* find end of token */ + while (*p && len < MAX_TOKEN_LENGTH) { + /* first, check stop conditions based on block or normal + * token */ + if (bc) { + if ((IsQuote(*p) && bc == *p) || + IsBlockEnd(*p, bc)) { + be = *p; + break; + } + } else /* normal token */ { + if (isspace((unsigned char)*p) || *p == ',') + break; + } + + if (*p == '\\' && + *(p + 1)) /* if \, copy next char verbatim */ + p++; + tmptok[len] = *p; + len++; + p++; + } + + /* sanity checks: */ + if (bc && !be) { /* did we have block start, but not end? */ + /* should yell about this */ + return NULL; + } + + if (len) { + tok = (char *)malloc(len + 1); + strncpy(tok, tmptok, len); + tok[len] = '\0'; + } + } + + return tok; } /* ** CmpToken: does case-insensitive compare on next token in string, leaving ** string intact (return code like strcmp) */ -int CmpToken(const char *pstr,char *tok) +int +CmpToken(const char *pstr, char *tok) { - int rc=0; - char *ntok=PeekToken(pstr); - if (ntok) - { - rc = strcasecmp(tok,ntok); - free(ntok); - } - return rc; + int rc = 0; + char *ntok = PeekToken(pstr); + if (ntok) { + rc = strcasecmp(tok, ntok); + free(ntok); + } + return rc; } /* ** MatchToken: does case-insensitive compare on next token in string, leaving ** string intact (returns true if matches, false otherwise) */ -int MatchToken(const char *pstr,char *tok) +int +MatchToken(const char *pstr, char *tok) { - int rc=0; - char *ntok=PeekToken(pstr); - if (ntok) - { - rc = (strcasecmp(tok,ntok)==0); - free(ntok); - } - return rc; + int rc = 0; + char *ntok = PeekToken(pstr); + if (ntok) { + rc = (strcasecmp(tok, ntok) == 0); + free(ntok); + } + return rc; } /* ** NukeToken: removes next token from string */ -void NukeToken(char **pstr) +void +NukeToken(char **pstr) { - char *tok; - char *next; - char *temp = NULL; - - next = GetNextToken(*pstr, &tok); - if (next != NULL) - temp = strdup(next); - if (pstr && *pstr) - free(*pstr); - *pstr = temp; - if (tok) - free(tok); + char *tok; + char *next; + char *temp = NULL; + + next = GetNextToken(*pstr, &tok); + if (next != NULL) + temp = strdup(next); + if (pstr && *pstr) + free(*pstr); + *pstr = temp; + if (tok) + free(tok); } /**************************************************************************** @@ -243,128 +235,114 @@ void NukeToken(char **pstr) * characters (spaces are skipped before a token, delimiters are not). * **************************************************************************/ -char *DoGetNextToken(char *indata, char **token, char *spaces, char *delims, - char *out_delim) +char * +DoGetNextToken( + char *indata, char **token, char *spaces, char *delims, char *out_delim) { - char *t, *start, *end, *text; - int snum; - int dnum; - - snum = (spaces) ? strlen(spaces) : 0; - dnum = (delims) ? strlen(delims) : 0; - if(indata == NULL) - { - if (out_delim) - *out_delim = '\0'; - *token = NULL; - return NULL; - } - t = indata; - while ( (*t != 0) && - ( isspace((unsigned char)*t) || - (snum && - strchr(spaces, *t)) ) ) - t++; - start = t; - while ( (*t != 0) && - !( isspace((unsigned char)*t) || - (snum && - strchr(spaces, *t)) || - (dnum && - strchr(delims, *t)) ) ) - { - /* Check for qouted text */ - if (IsQuote(*t)) - { - char c = *t; - - t++; - while((*t != c)&&(*t != 0)) - { - /* Skip over escaped text, ie \quote */ - if((*t == '\\')&&(*(t+1) != 0)) - t++; - t++; - } - if(*t == c) - t++; + char *t, *start, *end, *text; + int snum; + int dnum; + + snum = (spaces) ? strlen(spaces) : 0; + dnum = (delims) ? strlen(delims) : 0; + if (indata == NULL) { + if (out_delim) + *out_delim = '\0'; + *token = NULL; + return NULL; } - else - { - /* Skip over escaped text, ie \" or \space */ - if((*t == '\\')&&(*(t+1) != 0)) - t++; - t++; + t = indata; + while ((*t != 0) && + (isspace((unsigned char)*t) || (snum && strchr(spaces, *t)))) + t++; + start = t; + while ((*t != 0) && + !(isspace((unsigned char)*t) || (snum && strchr(spaces, *t)) || + (dnum && strchr(delims, *t)))) { + /* Check for qouted text */ + if (IsQuote(*t)) { + char c = *t; + + t++; + while ((*t != c) && (*t != 0)) { + /* Skip over escaped text, ie \quote */ + if ((*t == '\\') && (*(t + 1) != 0)) + t++; + t++; + } + if (*t == c) + t++; + } else { + /* Skip over escaped text, ie \" or \space */ + if ((*t == '\\') && (*(t + 1) != 0)) + t++; + t++; + } } - } - end = t; - if (out_delim) - *out_delim = *end; - - text = safemalloc(end-start+1); - *token = text; - - /* copy token */ - while(start < end) - { - /* Check for qouted text */ - if(IsQuote(*start)) - { - char c = *start; - start++; - while((*start != c)&&(*start != 0)) - { - /* Skip over escaped text, ie \" or \space */ - if((*start == '\\')&&(*(start+1) != 0)) - start++; - *text++ = *start++; - } - if(*start == c) - start++; + end = t; + if (out_delim) + *out_delim = *end; + + text = xmalloc(end - start + 1); + *token = text; + + /* copy token */ + while (start < end) { + /* Check for qouted text */ + if (IsQuote(*start)) { + char c = *start; + start++; + while ((*start != c) && (*start != 0)) { + /* Skip over escaped text, ie \" or \space */ + if ((*start == '\\') && (*(start + 1) != 0)) + start++; + *text++ = *start++; + } + if (*start == c) + start++; + } else { + /* Skip over escaped text, ie \" or \space */ + if ((*start == '\\') && (*(start + 1) != 0)) + start++; + *text++ = *start++; + } } - else - { - /* Skip over escaped text, ie \" or \space */ - if((*start == '\\')&&(*(start+1) != 0)) - start++; - *text++ = *start++; + *text = 0; + if (*end != 0) + end++; + + if (**token == 0) { + free(*token); + *token = NULL; } - } - *text = 0; - if(*end != 0) - end++; - - if (**token == 0) - { - free(*token); - *token = NULL; - } - return end; + return end; } -char *GetNextToken(char *indata, char **token) +char * +GetNextToken(char *indata, char **token) { - return DoGetNextToken(indata, token, NULL, NULL, NULL); + return DoGetNextToken(indata, token, NULL, NULL, NULL); } -char *GetNextOption(char *indata, char **token) +char * +GetNextOption(char *indata, char **token) { - return DoGetNextToken(indata, token, ",", NULL, NULL); + return DoGetNextToken(indata, token, ",", NULL, NULL); } -char *SkipNTokens(char *indata, unsigned int n) +char * +SkipNTokens(char *indata, unsigned int n) { - char *tmp; - char *junk; - - tmp = indata; - for ( ; n > 0 ; n--) - { - tmp = GetNextToken(tmp, &junk); - if (junk) - free(junk); - } - return tmp; + char *tmp; + char *junk; + + tmp = indata; + for (; n > 0; n--) { + tmp = GetNextToken(tmp, &junk); + if (junk) + free(junk); + } + return tmp; } /**************************************************************************** @@ -378,28 +356,28 @@ char *SkipNTokens(char *indata, unsigned int n) * returns "Geometry" in token. * **************************************************************************/ -char *GetModuleResource(char *indata, char **resource, char *module_name) +char * +GetModuleResource(char *indata, char **resource, char *module_name) { - char *tmp; - char *next; - - if (!module_name) - { - *resource = NULL; - return indata; - } - next = GetNextToken(indata, &tmp); - if (!tmp) - return next; - - if (tmp[0] != '*' || strncasecmp(tmp+1, module_name, strlen(module_name))) - { - *resource = NULL; - return indata; - } - CopyString(resource, tmp+1+strlen(module_name)); - free(tmp); - return next; + char *tmp; + char *next; + + if (!module_name) { + *resource = NULL; + return indata; + } + next = GetNextToken(indata, &tmp); + if (!tmp) + return next; + + if (tmp[0] != '*' || + strncasecmp(tmp + 1, module_name, strlen(module_name))) { + *resource = NULL; + return indata; + } + CopyString(resource, tmp + 1 + strlen(module_name)); + free(tmp); + return next; } /**************************************************************************** @@ -409,27 +387,27 @@ char *GetModuleResource(char *indata, char **resource, char *module_name) * If ret_action is non-NULL, a pointer to the next token is returned there. * **************************************************************************/ -int GetIntegerArguments(char *action, char **ret_action, int retvals[],int num) +int +GetIntegerArguments(char *action, char **ret_action, int retvals[], int num) { - int i; - char *token; - - for (i = 0; i < num && action; i++) - { - action = GetNextToken(action, &token); - if (token == NULL) - break; - if (sscanf(token, "%d", &(retvals[i])) != 1) - break; - free(token); - token = NULL; - } - if (token) - free(token); - if (ret_action != NULL) - *ret_action = action; - - return i; + int i; + char *token; + + for (i = 0; i < num && action; i++) { + action = GetNextToken(action, &token); + if (token == NULL) + break; + if (sscanf(token, "%d", &(retvals[i])) != 1) + break; + free(token); + token = NULL; + } + if (token) + free(token); + if (ret_action != NULL) + *ret_action = action; + + return i; } /*************************************************************************** @@ -446,35 +424,33 @@ int GetIntegerArguments(char *action, char **ret_action, int retvals[],int num) * in token after the match. * **************************************************************************/ -int GetTokenIndex(char *token, char *list[], int len, char **next) +int +GetTokenIndex(char *token, char *list[], int len, char **next) { - int i; - int l; - int k; - - if (!token || !list) - { - if (next) - *next = NULL; - return -1; - } - l = (len) ? len : strlen(token); - for (i = 0; list[i] != NULL; i++) - { - k = strlen(list[i]); - if (len < 0) - l = k; - if (len == 0 && k != l) - continue; - if (!strncasecmp(token, list[i], l)) - break; - } - if (next) - { - *next = (list[i]) ? token + l : token; - } - - return (list[i]) ? i : -1; + int i; + int l; + int k; + + if (!token || !list) { + if (next) + *next = NULL; + return -1; + } + l = (len) ? len : strlen(token); + for (i = 0; list[i] != NULL; i++) { + k = strlen(list[i]); + if (len < 0) + l = k; + if (len == 0 && k != l) + continue; + if (!strncasecmp(token, list[i], l)) + break; + } + if (next) { + *next = (list[i]) ? token + l : token; + } + + return (list[i]) ? i : -1; } /*************************************************************************** @@ -485,96 +461,95 @@ int GetTokenIndex(char *token, char *list[], int len, char **next) * token (just like the return value of GetNextToken). * **************************************************************************/ -char *GetNextTokenIndex(char *action, char *list[], int len, int *index) +char * +GetNextTokenIndex(char *action, char *list[], int len, int *index) { - char *token; - char *next; - - if (!index) - return action; - - next = GetNextToken(action, &token); - if (!token) - { - *index = -1; - return action; - } - *index = GetTokenIndex(token, list, len, NULL); - free(token); - - return (*index == -1) ? action : next; -} + char *token; + char *next; + if (!index) + return action; -int GetRectangleArguments(char *action, int *width, int *height) + next = GetNextToken(action, &token); + if (!token) { + *index = -1; + return action; + } + *index = GetTokenIndex(token, list, len, NULL); + free(token); + + return (*index == -1) ? action : next; +} + +int +GetRectangleArguments(char *action, int *width, int *height) { - char *token; - int n; + char *token; + int n; - GetNextToken(action, &token); - if (!token) - return 0; - /* now try MxN style number, specifically for DeskTopSize: */ - n = sscanf(token, "%d%*c%d", width, height); - free(token); + GetNextToken(action, &token); + if (!token) + return 0; + /* now try MxN style number, specifically for DeskTopSize: */ + n = sscanf(token, "%d%*c%d", width, height); + free(token); - return (n == 2) ? 2 : 0; + return (n == 2) ? 2 : 0; } /* unit_io is input as well as output. If action has a postfix 'p' or 'P', * *unit_io is set to 100, otherwise it is left untouched. */ -int GetOnePercentArgument(char *action, int *value, int *unit_io) +int +GetOnePercentArgument(char *action, int *value, int *unit_io) { - unsigned int len; - char *token; - int n; - - *value = 0; - if (!action) - return 0; - GetNextToken(action, &token); - if (!token) - return 0; - - len = strlen(token); - /* token never contains an empty string, so this is ok */ - if (token[len - 1] == 'p' || token[len - 1] == 'P') - { - *unit_io = 100; - token[len - 1] = '\0'; - } - n = sscanf(token, "%d", value); - - free(token); - return n; -} + unsigned int len; + char *token; + int n; + + *value = 0; + if (!action) + return 0; + GetNextToken(action, &token); + if (!token) + return 0; + + len = strlen(token); + /* token never contains an empty string, so this is ok */ + if (token[len - 1] == 'p' || token[len - 1] == 'P') { + *unit_io = 100; + token[len - 1] = '\0'; + } + n = sscanf(token, "%d", value); + free(token); + return n; +} -int GetTwoPercentArguments(char *action, int *val1, int *val2, int *val1_unit, - int *val2_unit) +int +GetTwoPercentArguments( + char *action, int *val1, int *val2, int *val1_unit, int *val2_unit) { - char *tok1, *tok2; - int n = 0; - - *val1 = 0; - *val2 = 0; - - action = GetNextToken(action, &tok1); - if (!tok1) - return 0; - GetNextToken(action, &tok2); - if (GetOnePercentArgument(tok2, val2, val2_unit) == 1 && - GetOnePercentArgument(tok1, val1, val1_unit) == 1) - { - free(tok1); - free(tok2); - return 2; - } - - /* now try MxN style number, specifically for DeskTopSize: */ - n = GetRectangleArguments(tok1, val1, val2); - free(tok1); - if (tok2) - free(tok2); - return n; + char *tok1, *tok2; + int n = 0; + + *val1 = 0; + *val2 = 0; + + action = GetNextToken(action, &tok1); + if (!tok1) + return 0; + GetNextToken(action, &tok2); + if (GetOnePercentArgument(tok2, val2, val2_unit) == 1 && + GetOnePercentArgument(tok1, val1, val1_unit) == 1) { + free(tok1); + free(tok2); + return 2; + } + + /* now try MxN style number, specifically for DeskTopSize: */ + n = GetRectangleArguments(tok1, val1, val2); + free(tok1); + if (tok2) + free(tok2); + return n; } Index: fvwm/libs/Picture.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/libs/Picture.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/libs/Picture.c --- fvwm/libs/Picture.c +++ fvwm/libs/Picture.c @@ -1,4 +1,4 @@ - /**************************************************************************** +/**************************************************************************** * This module is all original code * by Rob Nation * Copyright 1993, Robert Nation @@ -31,189 +31,188 @@ * ****************************************************************************/ -#include "config.h" - -#include -#include -#include -#include -#include -#include -#include -#include #include +#include #include #include +#include +#include +#include +#include +#include +#include +#include + +#include "config.h" #ifdef XPM /* static function prototypes */ -static void c100_init_base_table (); /* prototype */ -static void c200_substitute_color(char **,int); /* prototype */ +static void c100_init_base_table(); /* prototype */ +static void c200_substitute_color(char **, int); /* prototype */ static void c300_color_to_rgb(char *, XColor *); /* prototype */ static double c400_distance(XColor *, XColor *); /* prototype */ #endif #include "fvwmlib.h" - -static FvwmPicture *PictureList=NULL; +static FvwmPicture *PictureList = NULL; Colormap PictureCMap; -Display *PictureSaveDisplay; /* Save area for display pointer */ +Display *PictureSaveDisplay; /* Save area for display pointer */ /* This routine called during fvwm and some modules initialization */ -void InitPictureCMap(Display *dpy,Window Root) +void +InitPictureCMap(Display *dpy, Window Root) { - XWindowAttributes root_attr; - PictureSaveDisplay = dpy; /* save for latter */ - XGetWindowAttributes(dpy,Root,&root_attr); - PictureCMap=root_attr.colormap; + XWindowAttributes root_attr; + PictureSaveDisplay = dpy; /* save for latter */ + XGetWindowAttributes(dpy, Root, &root_attr); + PictureCMap = root_attr.colormap; } - -FvwmPicture *LoadPicture(Display *dpy,Window Root,char *path, int color_limit) +FvwmPicture * +LoadPicture(Display *dpy, Window Root, char *path, int color_limit) { - int l; - FvwmPicture *p; + int l; + FvwmPicture *p; #ifdef XPM - XpmAttributes xpm_attributes; - int rc; - XpmImage my_image = {0}; + XpmAttributes xpm_attributes; + int rc; + XpmImage my_image = {0}; #endif - p=(FvwmPicture*)safemalloc(sizeof(FvwmPicture)); - p->count=1; - p->name=path; - p->next=NULL; + p = (FvwmPicture *)xmalloc(sizeof(FvwmPicture)); + p->count = 1; + p->name = path; + p->next = NULL; #ifdef XPM - /* Try to load it as an X Pixmap first */ - xpm_attributes.colormap=PictureCMap; - xpm_attributes.closeness=40000; /* Allow for "similar" colors */ - xpm_attributes.valuemask= - XpmSize | XpmReturnPixels | XpmColormap | XpmCloseness; - - rc =XpmReadFileToXpmImage(path, &my_image, NULL); - if (rc == XpmSuccess) { - color_reduce_pixmap(&my_image, color_limit); - rc = XpmCreatePixmapFromXpmImage(dpy, Root, &my_image, - &p->picture,&p->mask, - &xpm_attributes); - if (rc == XpmSuccess) { - p->width = my_image.width; - p->height = my_image.height; - XpmFreeXpmImage(&my_image); - p->depth = DefaultDepthOfScreen(DefaultScreenOfDisplay(dpy)); - return p; - } - XpmFreeXpmImage(&my_image); - } + /* Try to load it as an X Pixmap first */ + xpm_attributes.colormap = PictureCMap; + xpm_attributes.closeness = 40000; /* Allow for "similar" colors */ + xpm_attributes.valuemask = + XpmSize | XpmReturnPixels | XpmColormap | XpmCloseness; + + rc = XpmReadFileToXpmImage(path, &my_image, NULL); + if (rc == XpmSuccess) { + color_reduce_pixmap(&my_image, color_limit); + rc = XpmCreatePixmapFromXpmImage(dpy, Root, &my_image, + &p->picture, &p->mask, &xpm_attributes); + if (rc == XpmSuccess) { + p->width = my_image.width; + p->height = my_image.height; + XpmFreeXpmImage(&my_image); + p->depth = + DefaultDepthOfScreen(DefaultScreenOfDisplay(dpy)); + return p; + } + XpmFreeXpmImage(&my_image); + } #endif - /* If no XPM support, or XPM loading failed, try bitmap */ - if(XReadBitmapFile(dpy,Root,path,&p->width,&p->height,&p->picture,&l,&l) - == BitmapSuccess) - { - p->depth = 0; - p->mask = None; - return p; - } - - free(p); - return NULL; + /* If no XPM support, or XPM loading failed, try bitmap */ + if (XReadBitmapFile(dpy, Root, path, &p->width, &p->height, &p->picture, + &l, &l) == BitmapSuccess) { + p->depth = 0; + p->mask = None; + return p; + } + + free(p); + return NULL; } -FvwmPicture *GetPicture(Display *dpy,Window Root,char *IconPath, - char *PixmapPath, char *name, int color_limit) +FvwmPicture * +GetPicture(Display *dpy, Window Root, char *IconPath, char *PixmapPath, + char *name, int color_limit) { - char *path; - FvwmPicture *p; - - if(!(path=findIconFile(name,PixmapPath,R_OK))) - if(!(path=findIconFile(name,IconPath,R_OK))) - return NULL; - p = LoadPicture(dpy,Root,path, color_limit); - if (!p) - free(path); - return p; + char *path; + FvwmPicture *p; + + if (!(path = findIconFile(name, PixmapPath, R_OK))) + if (!(path = findIconFile(name, IconPath, R_OK))) + return NULL; + p = LoadPicture(dpy, Root, path, color_limit); + if (!p) + free(path); + return p; } -FvwmPicture *CachePicture(Display *dpy,Window Root,char *IconPath,char *PixmapPath, - char *name, int color_limit) +FvwmPicture * +CachePicture(Display *dpy, Window Root, char *IconPath, char *PixmapPath, + char *name, int color_limit) { - char *path; - FvwmPicture *p=PictureList; + char *path; + FvwmPicture *p = PictureList; - /* First find the full pathname */ + /* First find the full pathname */ #ifdef XPM - if(!(path=findIconFile(name,PixmapPath,R_OK))) - if(!(path=findIconFile(name,IconPath,R_OK))) - return NULL; + if (!(path = findIconFile(name, PixmapPath, R_OK))) + if (!(path = findIconFile(name, IconPath, R_OK))) + return NULL; #else - /* Ignore the given pixmap path when compiled without XPM support */ - if(!(path=findIconFile(name,IconPath,R_OK))) - return NULL; + /* Ignore the given pixmap path when compiled without XPM support */ + if (!(path = findIconFile(name, IconPath, R_OK))) + return NULL; #endif - /* See if the picture is already cached */ - while(p) - { - register char *p1, *p2; - - for (p1=path, p2=p->name; *p1 && *p2; ++p1, ++p2) - if (*p1 != *p2) - break; - - if(!*p1 && !*p2) /* We have found a picture with the wanted name */ - { - p->count++; /* Put another weight on the picture */ - free(path); - return p; + /* See if the picture is already cached */ + while (p) { + register char *p1, *p2; + + for (p1 = path, p2 = p->name; *p1 && *p2; ++p1, ++p2) + if (*p1 != *p2) + break; + + if (!*p1 && + !*p2) { /* We have found a picture with the wanted name */ + p->count++; /* Put another weight on the picture */ + free(path); + return p; + } + p = p->next; } - p=p->next; - } - - /* Not previously cached, have to load it ourself. Put it first in list */ - p=LoadPicture(dpy,Root,path, color_limit); - if(p) - { - p->next=PictureList; - PictureList=p; - } - else - free(path); - return p; -} + /* Not previously cached, have to load it ourself. Put it first in list + */ + p = LoadPicture(dpy, Root, path, color_limit); + if (p) { + p->next = PictureList; + PictureList = p; + } else + free(path); + return p; +} -void DestroyPicture(Display *dpy,FvwmPicture *p) +void +DestroyPicture(Display *dpy, FvwmPicture *p) { - FvwmPicture *q=PictureList; - - if (!p) /* bag out if NULL */ - return; - if(--(p->count)>0) /* Remove a weight, still too heavy? */ - return; - - /* Let it fly */ - if(p->name!=NULL) - free(p->name); - if(p->picture!=None) - XFreePixmap(dpy,p->picture); - if(p->mask!=None) - XFreePixmap(dpy,p->mask); - - /* Link it out of the list (it might not be there) */ - if(p==q) /* in head? simple */ - PictureList=p->next; - else - { - while(q && q->next!=p) /* fast forward until end or found */ - q=q->next; - if(q) /* not end? means we found it in there, possibly at end */ - q->next=p->next; /* link around it */ - } - free(p); + FvwmPicture *q = PictureList; + + if (!p) /* bag out if NULL */ + return; + if (--(p->count) > 0) /* Remove a weight, still too heavy? */ + return; + + /* Let it fly */ + if (p->name != NULL) + free(p->name); + if (p->picture != None) + XFreePixmap(dpy, p->picture); + if (p->mask != None) + XFreePixmap(dpy, p->mask); + + /* Link it out of the list (it might not be there) */ + if (p == q) /* in head? simple */ + PictureList = p->next; + else { + while (q && q->next != p) /* fast forward until end or found */ + q = q->next; + if (q) /* not end? means we found it in there, possibly at end + */ + q->next = p->next; /* link around it */ + } + free(p); } /**************************************************************************** @@ -225,66 +224,62 @@ void DestroyPicture(Display *dpy,FvwmPicture *p) * Oh well. * ****************************************************************************/ -char *findIconFile(char *icon, char *pathlist, int type) +char * +findIconFile(char *icon, char *pathlist, int type) { - char *path; - char *dir_end; - int l; - size_t pathlen; - - if (!icon) - return NULL; - - l = (pathlist) ? strlen(pathlist) : 0; - pathlen = strlen(icon) + l + 10; - path = safemalloc(pathlen); - *path = '\0'; - if (*icon == '/' || pathlist == NULL || *pathlist == '\0') - { - /* No search if icon begins with a slash */ - /* No search if pathlist is empty */ - strlcpy(path, icon, pathlen); - return path; - } - - /* Search each element of the pathlist for the icon file */ - while ((pathlist)&&(*pathlist)) - { - dir_end = strchr(pathlist, ':'); - if (dir_end != NULL) - { - strncpy(path, pathlist, dir_end - pathlist); - path[dir_end - pathlist] = 0; + char *path; + char *dir_end; + int l; + size_t pathlen; + + if (!icon) + return NULL; + + l = (pathlist) ? strlen(pathlist) : 0; + pathlen = strlen(icon) + l + 10; + path = xmalloc(pathlen); + *path = '\0'; + if (*icon == '/' || pathlist == NULL || *pathlist == '\0') { + /* No search if icon begins with a slash */ + /* No search if pathlist is empty */ + strlcpy(path, icon, pathlen); + return path; } - else - strlcpy(path, pathlist, pathlen); - - strlcat(path, "/", pathlen); - strlcat(path, icon, pathlen); - if (access(path, type) == 0) - return path; - strlcat(path, ".gz", pathlen); - if (access(path, type) == 0) - return path; - - /* Point to next element of the path */ - if(dir_end == NULL) - pathlist = NULL; - else - pathlist = dir_end + 1; - } - /* Hmm, couldn't find the file. Return NULL */ - free(path); - return NULL; -} + /* Search each element of the pathlist for the icon file */ + while ((pathlist) && (*pathlist)) { + dir_end = strchr(pathlist, ':'); + if (dir_end != NULL) { + strncpy(path, pathlist, dir_end - pathlist); + path[dir_end - pathlist] = 0; + } else + strlcpy(path, pathlist, pathlen); + + strlcat(path, "/", pathlen); + strlcat(path, icon, pathlen); + if (access(path, type) == 0) + return path; + strlcat(path, ".gz", pathlen); + if (access(path, type) == 0) + return path; + + /* Point to next element of the path */ + if (dir_end == NULL) + pathlist = NULL; + else + pathlist = dir_end + 1; + } + /* Hmm, couldn't find the file. Return NULL */ + free(path); + return NULL; +} #ifdef XPM /* This structure is used to quickly access the RGB values of the colors */ /* without repeatedly having to transform them. */ typedef struct { - char * c_color; /* Pointer to the name of the color */ - XColor rgb_space; /* rgb color info */ + char *c_color; /* Pointer to the name of the color */ + XColor rgb_space; /* rgb color info */ } Color_Info; /* First thing in base array are colors probably already in the color map @@ -295,188 +290,169 @@ typedef struct { Currently 61 colors in this list. */ static Color_Info base_array[] = { - {"white"}, - {"black"}, - {"grey"}, - {"green"}, - {"blue"}, - {"red"}, - {"cyan"}, - {"yellow"}, - {"magenta"}, - {"DodgerBlue"}, - {"SteelBlue"}, - {"chartreuse"}, - {"wheat"}, - {"turquoise"}, - {"CadetBlue"}, - {"gray87"}, - {"CornflowerBlue"}, - {"YellowGreen"}, - {"NavyBlue"}, - {"MediumBlue"}, - {"plum"}, - {"aquamarine"}, - {"orchid"}, - {"ForestGreen"}, - {"lightyellow"}, - {"brown"}, - {"orange"}, - {"red3"}, - {"HotPink"}, - {"LightBlue"}, - {"gray47"}, - {"pink"}, - {"red4"}, - {"violet"}, - {"purple"}, - {"gray63"}, - {"gray94"}, - {"plum1"}, - {"PeachPuff"}, - {"maroon"}, - {"lavender"}, - {"salmon"}, /* for peachpuff, orange gap */ - {"blue4"}, /* for navyblue/mediumblue gap */ - {"PaleGreen4"}, /* for forestgreen, yellowgreen gap */ - {"#AA7700"}, /* brick, no close named color */ - {"#11EE88"}, /* light green, no close named color */ - {"#884466"}, /* dark brown, no close named color */ - {"#CC8888"}, /* light brick, no close named color */ - {"#EECC44"}, /* gold, no close named color */ - {"#AAAA44"}, /* dull green, no close named color */ - {"#FF1188"}, /* pinkish red */ - {"#992299"}, /* purple */ - {"#CCFFAA"}, /* light green */ - {"#664400"}, /* dark brown*/ - {"#AADD99"}, /* light green */ - {"#66CCFF"}, /* light blue */ - {"#CC2299"}, /* dark red */ - {"#FF11CC"}, /* bright pink */ - {"#11CC99"}, /* grey/green */ - {"#AA77AA"}, /* purple/red */ - {"#EEBB77"} /* orange/yellow */ + {"white"}, {"black"}, {"grey"}, {"green"}, {"blue"}, {"red"}, {"cyan"}, + {"yellow"}, {"magenta"}, {"DodgerBlue"}, {"SteelBlue"}, {"chartreuse"}, + {"wheat"}, {"turquoise"}, {"CadetBlue"}, {"gray87"}, {"CornflowerBlue"}, + {"YellowGreen"}, {"NavyBlue"}, {"MediumBlue"}, {"plum"}, {"aquamarine"}, + {"orchid"}, {"ForestGreen"}, {"lightyellow"}, {"brown"}, {"orange"}, + {"red3"}, {"HotPink"}, {"LightBlue"}, {"gray47"}, {"pink"}, {"red4"}, + {"violet"}, {"purple"}, {"gray63"}, {"gray94"}, {"plum1"}, {"PeachPuff"}, + {"maroon"}, {"lavender"}, {"salmon"}, /* for peachpuff, orange gap */ + {"blue4"}, /* for navyblue/mediumblue gap */ + {"PaleGreen4"}, /* for forestgreen, yellowgreen gap */ + {"#AA7700"}, /* brick, no close named color */ + {"#11EE88"}, /* light green, no close named color */ + {"#884466"}, /* dark brown, no close named color */ + {"#CC8888"}, /* light brick, no close named color */ + {"#EECC44"}, /* gold, no close named color */ + {"#AAAA44"}, /* dull green, no close named color */ + {"#FF1188"}, /* pinkish red */ + {"#992299"}, /* purple */ + {"#CCFFAA"}, /* light green */ + {"#664400"}, /* dark brown*/ + {"#AADD99"}, /* light green */ + {"#66CCFF"}, /* light blue */ + {"#CC2299"}, /* dark red */ + {"#FF11CC"}, /* bright pink */ + {"#11CC99"}, /* grey/green */ + {"#AA77AA"}, /* purple/red */ + {"#EEBB77"} /* orange/yellow */ }; #define NColors (sizeof(base_array) / sizeof(Color_Info)) /* if c_color isn't set, copy it from one of the other colours */ -Bool xpmcolor_require_c_color(XpmColor *p) +Bool +xpmcolor_require_c_color(XpmColor *p) { - if (p->c_color != NULL) - return False; - else if (p->g_color != NULL) - p->c_color = strdup(p->g_color); - else if (p->g4_color != NULL) - p->c_color = strdup(p->g4_color); - else if (p->m_color != NULL) - p->c_color = strdup(p->m_color); - else - p->c_color = strdup("none"); - - return True; + if (p->c_color != NULL) + return False; + else if (p->g_color != NULL) + p->c_color = strdup(p->g_color); + else if (p->g4_color != NULL) + p->c_color = strdup(p->g4_color); + else if (p->m_color != NULL) + p->c_color = strdup(p->m_color); + else + p->c_color = strdup("none"); + + return True; } /* given an xpm, change colors to colors close to the subset above. */ void -color_reduce_pixmap(XpmImage *image,int color_limit) { - int i; - XpmColor *color_table_ptr; - static char base_init = 'n'; - - if (color_limit > 0) { /* If colors to be limited */ - if (base_init == 'n') { /* if base table not created yet */ - c100_init_base_table(); /* init the base table */ - base_init = 'y'; /* remember that its set now. */ - } /* end base table init */ - color_table_ptr = image->colorTable; /* start of xpm color table */ - for(i=0; incolors; i++) { /* all colors in the xpm */ - /* Theres an array for this in the xpm library, but it doesn't - appear to be part of the API. Too bad. dje 01/09/00 */ - char **visual_color = 0; - if (color_table_ptr->c_color) { - visual_color = &color_table_ptr->c_color; - } else if (color_table_ptr->g_color) { - visual_color = &color_table_ptr->g_color; - } else if (color_table_ptr->g4_color) { - visual_color = &color_table_ptr->g4_color; - } else { /* its got to be one of these */ - visual_color = &color_table_ptr->m_color; - } - c200_substitute_color(visual_color,color_limit); - color_table_ptr +=1; /* counter for loop */ - } /* end all colors in xpm */ - } /* end colors limited */ - return; /* return, no rc! */ +color_reduce_pixmap(XpmImage *image, int color_limit) +{ + int i; + XpmColor *color_table_ptr; + static char base_init = 'n'; + + if (color_limit > 0) { /* If colors to be limited */ + if (base_init == 'n') { /* if base table not created yet */ + c100_init_base_table(); /* init the base table */ + base_init = 'y'; /* remember that its set now. */ + } /* end base table init */ + color_table_ptr = + image->colorTable; /* start of xpm color table */ + for (i = 0; i < image->ncolors; + i++) { /* all colors in the xpm */ + /* Theres an array for this in the xpm library, but it + doesn't appear to be part of the API. Too bad. dje + 01/09/00 */ + char **visual_color = 0; + if (color_table_ptr->c_color) { + visual_color = &color_table_ptr->c_color; + } else if (color_table_ptr->g_color) { + visual_color = &color_table_ptr->g_color; + } else if (color_table_ptr->g4_color) { + visual_color = &color_table_ptr->g4_color; + } else { /* its got to be one of these */ + visual_color = &color_table_ptr->m_color; + } + c200_substitute_color(visual_color, color_limit); + color_table_ptr += 1; /* counter for loop */ + } /* end all colors in xpm */ + } /* end colors limited */ + return; /* return, no rc! */ } /* from the color names in the base table, calc rgbs */ static void -c100_init_base_table () { - int i; - for (i=0; ired - target_ptr->red )/655.35) - + SQUARE((double)(base_ptr->green - target_ptr->green)/655.35) - + SQUARE((double)(base_ptr->blue - target_ptr->blue )/655.35); - return dst; +double +c400_distance(XColor *target_ptr, XColor *base_ptr) +{ + register double dst; + dst = SQUARE((double)(base_ptr->red - target_ptr->red) / 655.35) + + SQUARE((double)(base_ptr->green - target_ptr->green) / 655.35) + + SQUARE((double)(base_ptr->blue - target_ptr->blue) / 655.35); + return dst; } #endif /* XPM */ Index: fvwm/libs/Strings.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/libs/Strings.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/libs/Strings.c --- fvwm/libs/Strings.c +++ fvwm/libs/Strings.c @@ -2,10 +2,10 @@ ** Strings.c: various routines for dealing with strings */ +#include #include #include #include -#include #include "fvwmlib.h" @@ -16,102 +16,101 @@ *************************************************************************/ char CatS[256]; -char *CatString3(char *a, char *b, char *c) +char * +CatString3(char *a, char *b, char *c) { - int len = 0; + int len = 0; - if(a != NULL) - len += strlen(a); - if(b != NULL) - len += strlen(b); - if(c != NULL) - len += strlen(c); + if (a != NULL) + len += strlen(a); + if (b != NULL) + len += strlen(b); + if (c != NULL) + len += strlen(c); - if (len > 255) - return NULL; + if (len > 255) + return NULL; - if(a == NULL) - CatS[0] = 0; - else - strlcpy(CatS, a, sizeof(CatS)); - if(b != NULL) - strlcat(CatS, b, sizeof(CatS)); - if(c != NULL) - strlcat(CatS, c, sizeof(CatS)); - return CatS; + if (a == NULL) + CatS[0] = 0; + else + strlcpy(CatS, a, sizeof(CatS)); + if (b != NULL) + strlcat(CatS, b, sizeof(CatS)); + if (c != NULL) + strlcat(CatS, c, sizeof(CatS)); + return CatS; } /*************************************************************************** * A simple routine to copy a string, stripping spaces and mallocing - * space for the new string + * space for the new string ***************************************************************************/ -void CopyString(char **dest, char *source) +void +CopyString(char **dest, char *source) { - int len; - char *start; - - if (source == NULL) - { - *dest = NULL; - return; - } - while(((isspace(*source))&&(*source != '\n'))&&(*source != 0)) - { - source++; - } - len = 0; - start = source; - while((*source != '\n')&&(*source != 0)) - { - len++; - source++; - } - - source--; - while((isspace(*source))&&(*source != 0)&&(len >0)) - { - len--; - source--; - } - *dest = safemalloc(len+1); - strncpy(*dest,start,len); - (*dest)[len]=0; + int len; + char *start; + + if (source == NULL) { + *dest = NULL; + return; + } + while (((isspace(*source)) && (*source != '\n')) && (*source != 0)) { + source++; + } + len = 0; + start = source; + while ((*source != '\n') && (*source != 0)) { + len++; + source++; + } + + source--; + while ((isspace(*source)) && (*source != 0) && (len > 0)) { + len--; + source--; + } + *dest = xmalloc(len + 1); + strncpy(*dest, start, len); + (*dest)[len] = 0; } /**************************************************************************** - * + * * Copies a string into a new, malloc'ed string * Strips leading spaces and trailing spaces and new lines * - ****************************************************************************/ -char *stripcpy(char *source) + ****************************************************************************/ +char * +stripcpy(char *source) { - char *tmp,*ptr; - int len; + char *tmp, *ptr; + int len; - if(source == NULL) - return NULL; + if (source == NULL) + return NULL; - while(isspace(*source)) - source++; - len = strlen(source); - tmp = source + len -1; - while(((isspace(*tmp))||(*tmp == '\n'))&&(tmp >=source)) - { - tmp--; - len--; - } - ptr = safemalloc(len+1); - strncpy(ptr,source,len); - ptr[len]=0; - return ptr; + while (isspace(*source)) + source++; + len = strlen(source); + tmp = source + len - 1; + while (((isspace(*tmp)) || (*tmp == '\n')) && (tmp >= source)) { + tmp--; + len--; + } + ptr = xmalloc(len + 1); + strncpy(ptr, source, len); + ptr[len] = 0; + return ptr; } - -int StrEquals(char *s1,char *s2) + +int +StrEquals(char *s1, char *s2) { - if (!s1 && !s2) - return 1; - if (!s1 || !s2) - return 0; - return (strcasecmp(s1,s2)==0); + if (!s1 && !s2) + return 1; + if (!s1 || !s2) + return 0; + return (strcasecmp(s1, s2) == 0); } Index: fvwm/libs/System.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/libs/System.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/libs/System.c --- fvwm/libs/System.c +++ fvwm/libs/System.c @@ -1,44 +1,27 @@ -/* -** System.c: code for dealing with various OS system call variants -*/ - -#include "config.h" - -#include - -#if HAVE_UNAME #include -#endif +#include +#include "config.h" -/* -** just in case... -*/ #ifndef FD_SETSIZE #define FD_SETSIZE 2048 #endif - -int GetFdWidth(void) +int +GetFdWidth(void) { -#if HAVE_SYSCONF - return min(sysconf(_SC_OPEN_MAX),FD_SETSIZE); -#else - return min(getdtablesize(),FD_SETSIZE); -#endif + return min(sysconf(_SC_OPEN_MAX), FD_SETSIZE); } -/* return a string indicating the OS type (i.e. "Linux", "SINIX-D", ... ) */ -int getostype(char *buf, int max) +int +getostype(char *buf, int max) { -#if HAVE_UNAME - struct utsname sysname; - - if ( uname( &sysname ) >= 0 ) { - strlcpy( buf, sysname.sysname, max); - return 0; - } -#endif - strlcpy (buf,"",max); - return -1; + struct utsname sysname; + + if (uname(&sysname) >= 0) { + strlcpy(buf, sysname.sysname, max); + return 0; + } + strlcpy(buf, "", max); + return -1; } Index: fvwm/libs/XResource.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/libs/XResource.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/libs/XResource.c --- fvwm/libs/XResource.c +++ fvwm/libs/XResource.c @@ -5,107 +5,34 @@ ** file lines) in the same way (Xrm database). */ -#include "config.h" - #include #include #include +#include "config.h" #include "fvwmlib.h" - - -/*************************************************************************** - * If you have a module MyModule and want to parse X resources as well as - * command line options and a config file: - * - *** EXAMPLE ***************************************************************/ -#if 0 -#include - - void main(int argc, char **argv) - { - const char *MyName = "MyModule"; - XrmDatabase db = NULL; - char *value; - char *line; - - /* our private options */ - const XrmOptionDescRec my_opts[] = { - { "-iconic", ".Iconic", XrmoptionNoArg, "any_string" }, - { "-foo", "*bar", XrmoptionSepArg, NULL } - }; - int opt_argc = argc - 6; /* options start at 6th argument for modules */ - char **opt_argv = argv + 6; - - /* ... (open config file, etc.) */ - - /* Get global X resources */ - MergeXResources(NULL, &db, False); - - /* config file descriptor in fd; config file takes precedence over X - * resources (this may not be what you want). */ - for (GetConfigLine(fd, &line); line != NULL; GetConfigLine(fd, &line)) - { - if (!MergeConfigLineResource(&db, line, MyName, '*')) - { - /* Parse other lines here (e.g. "IconPath") */ - } - else - { - /* You may still have to parse the line here yourself (e.g. - * FvwmButtons may have multiple lines for the same resource). */ - } - } - - /* command line takes precedence over all */ - MergeCmdLineResources(&db, (XrmOptionDescList)my_opts, 2, MyName, - &opt_argc, opt_argv, True /*no default options*/); - - /* Now parse the database values: */ - if (GetResourceString(db, "iconic", MyName, &value)) - { - /* Just see if there is *any* string and don't mind it's value. */ - /* flags |= ICONIC */ - } - if (GetResourceString(db, "bar", MyName, &value)) - { - /* ... */ - } - - /* ... */ - XrmDestroyDatabase(db); - } -#endif - -/*** END OF EXAMPLE ********************************************************/ - - - - /* Default option table */ -static XrmOptionDescRec default_opts[] = -{ - { "-fg", "*Foreground", XrmoptionSepArg, NULL }, - { "-bg", "*Background", XrmoptionSepArg, NULL }, - { "-fn", "*Font", XrmoptionSepArg, NULL }, - { "-geometry", "*Geometry", XrmoptionSepArg, NULL }, - { "-title", "*Title", XrmoptionSepArg, NULL } - /* Remember to update NUM_DEFAULT_OPTIONS if you change this list! */ +static XrmOptionDescRec default_opts[] = { + {"-fg", "*Foreground", XrmoptionSepArg, NULL}, + {"-bg", "*Background", XrmoptionSepArg, NULL}, + {"-fn", "*Font", XrmoptionSepArg, NULL}, + {"-geometry", "*Geometry", XrmoptionSepArg, NULL}, + {"-title", "*Title", XrmoptionSepArg, NULL} + /* Remember to update NUM_DEFAULT_OPTIONS if you change this list! */ }; #define NUM_DEFAULT_OPTS 5 - - /* internal function */ -static void DoMergeString(char *resource, XrmDatabase *ptarget, Bool override) +static void +DoMergeString(char *resource, XrmDatabase *ptarget, Bool override) { - XrmDatabase db; + XrmDatabase db; - if (!resource) - return; - db = XrmGetStringDatabase(resource); - XrmCombineDatabase(db, ptarget, override); + if (!resource) + return; + db = XrmGetStringDatabase(resource); + XrmCombineDatabase(db, ptarget, override); } /*************************************************************************** @@ -118,14 +45,15 @@ static void DoMergeString(char *resource, XrmDatabase *ptarget, Bool override) * if you do not need it amymore. * ***************************************************************************/ -void MergeXResources(Display *dpy, XrmDatabase *pdb, Bool override) +void +MergeXResources(Display *dpy, XrmDatabase *pdb, Bool override) { - if (!*pdb) - /* create new database */ - XrmPutStringResource(pdb, "", ""); - DoMergeString(XResourceManagerString(dpy), pdb, override); - DoMergeString(XScreenResourceString(DefaultScreenOfDisplay(dpy)), pdb, - override); + if (!*pdb) + /* create new database */ + XrmPutStringResource(pdb, "", ""); + DoMergeString(XResourceManagerString(dpy), pdb, override); + DoMergeString( + XScreenResourceString(DefaultScreenOfDisplay(dpy)), pdb, override); } /*************************************************************************** @@ -145,15 +73,15 @@ void MergeXResources(Display *dpy, XrmDatabase *pdb, Bool override) * if you do not need it amymore. * ***************************************************************************/ -void MergeCmdLineResources(XrmDatabase *pdb, XrmOptionDescList opts, - int num_opts, char *name, int *pargc, char **argv, - Bool fNoDefaults) +void +MergeCmdLineResources(XrmDatabase *pdb, XrmOptionDescList opts, int num_opts, + char *name, int *pargc, char **argv, Bool fNoDefaults) { - if (opts && num_opts > 0) - XrmParseCommand(pdb, opts, num_opts, name, pargc, argv); - if (!fNoDefaults) - XrmParseCommand(pdb, default_opts, NUM_DEFAULT_OPTS, - name, pargc, argv); + if (opts && num_opts > 0) + XrmParseCommand(pdb, opts, num_opts, name, pargc, argv); + if (!fNoDefaults) + XrmParseCommand( + pdb, default_opts, NUM_DEFAULT_OPTS, name, pargc, argv); } /*************************************************************************** @@ -178,55 +106,56 @@ void MergeCmdLineResources(XrmDatabase *pdb, XrmOptionDescList opts, * if you do not need it amymore. * ***************************************************************************/ -Bool MergeConfigLineResource(XrmDatabase *pdb, char *line, char *prefix, - char *bindstr) +Bool +MergeConfigLineResource( + XrmDatabase *pdb, char *line, char *prefix, char *bindstr) { - int len; - char *end; - char *value; - char *myvalue; - char *resource; - size_t reslen; - - /* translate "*(prefix)(suffix)" to "(prefix)(binding)(suffix)", - * e.g. "*FvwmPagerGeometry" to "FvwmPager.Geometry" */ - if (!line || *line != '*') - return False; - - line++; - len = (prefix) ? strlen(prefix) : 0; - if (!prefix || strncasecmp(line, prefix, len)) - return False; - - line += len; - end = line; - while (*end && !isspace(*end)) - end++; - if (line == end) - return False; - value = end; - while (*value && isspace(*value)) - value++; - - /* prefix*suffix: value */ - reslen = len + (end - line) + 2; - resource = (char *)safemalloc(reslen); - strlcpy(resource, prefix,reslen); - strlcat(resource, bindstr,reslen); - strncat(resource, line, end - line); - - len = strlen(value); - myvalue = (char *)safemalloc(len + 1); - strlcpy(myvalue, value,len+1); - for (len--; len >= 0 && isspace(myvalue[len]); len--) - myvalue[len] = 0; - - /* merge string into database */ - XrmPutStringResource(pdb, resource, myvalue); - - free(resource); - free(myvalue); - return True; + int len; + char *end; + char *value; + char *myvalue; + char *resource; + size_t reslen; + + /* translate "*(prefix)(suffix)" to "(prefix)(binding)(suffix)", + * e.g. "*FvwmPagerGeometry" to "FvwmPager.Geometry" */ + if (!line || *line != '*') + return False; + + line++; + len = (prefix) ? strlen(prefix) : 0; + if (!prefix || strncasecmp(line, prefix, len)) + return False; + + line += len; + end = line; + while (*end && !isspace(*end)) + end++; + if (line == end) + return False; + value = end; + while (*value && isspace(*value)) + value++; + + /* prefix*suffix: value */ + reslen = len + (end - line) + 2; + resource = (char *)xmalloc(reslen); + strlcpy(resource, prefix, reslen); + strlcat(resource, bindstr, reslen); + strncat(resource, line, end - line); + + len = strlen(value); + myvalue = (char *)xmalloc(len + 1); + strlcpy(myvalue, value, len + 1); + for (len--; len >= 0 && isspace(myvalue[len]); len--) + myvalue[len] = 0; + + /* merge string into database */ + XrmPutStringResource(pdb, resource, myvalue); + + free(resource); + free(myvalue); + return True; } /*************************************************************************** @@ -246,30 +175,31 @@ Bool MergeConfigLineResource(XrmDatabase *pdb, char *line, char *prefix, * returns the string value of the "Geometry" resource for MyModule in s. * ***************************************************************************/ -Bool GetResourceString(XrmDatabase db, const char *resource, - const char *prefix, char **val) +Bool +GetResourceString( + XrmDatabase db, const char *resource, const char *prefix, char **val) { - XrmValue xval = { 0, NULL }; - char *str_type; - char *name; - size_t len; - - len = strlen(resource) + strlen(prefix) + 2; - name = (char *)safemalloc(len); - strlcpy(name, prefix,len); - strlcat(name, ".",len); - strlcat(name, resource,len); - - if (!XrmGetResource(db, name, name, &str_type, &xval) || xval.addr == NULL) - { - free(name); - if (val) - *val = NULL; - return False; - } - free(name); - if (val) - *val = xval.addr; - - return True; + XrmValue xval = {0, NULL}; + char *str_type; + char *name; + size_t len; + + len = strlen(resource) + strlen(prefix) + 2; + name = (char *)xmalloc(len); + strlcpy(name, prefix, len); + strlcat(name, ".", len); + strlcat(name, resource, len); + + if (!XrmGetResource(db, name, name, &str_type, &xval) || + xval.addr == NULL) { + free(name); + if (val) + *val = NULL; + return False; + } + free(name); + if (val) + *val = xval.addr; + + return True; } Index: fvwm/libs/debug.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/libs/debug.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/libs/debug.c --- fvwm/libs/debug.c +++ fvwm/libs/debug.c @@ -8,25 +8,14 @@ * 6 Nov 1998 - Paul D. Smith */ -#include "config.h" - -#include #include +#include +#include "config.h" #include "fvwmlib.h" -#ifndef HAVE_VFPRINTF -# define VA_PRINTF(fp, lastarg, args) _doprnt((lastarg), (args), (fp)) -#else -# define VA_PRINTF(fp, lastarg, args) vfprintf((fp), (lastarg), (args)) -#endif - -/* Don't put this into the #ifdef, since some compilers don't like completely - * empty source files. - */ int f_db_level = 0; - #ifdef DEBUG struct f_db_info f_db_info; @@ -34,15 +23,15 @@ struct f_db_info f_db_info; void f_db_print(const char *fmt, ...) { - va_list ap; + va_list ap; - fprintf(stderr, "%s:%ld: ", f_db_info.filenm, f_db_info.lineno); + fprintf(stderr, "%s:%ld: ", f_db_info.filenm, f_db_info.lineno); - va_start(ap, fmt); - VA_PRINTF(stderr, fmt, ap); - va_end(ap); + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); - fputc('\n', stderr); + fputc('\n', stderr); } #endif Index: fvwm/libs/envvar.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/libs/envvar.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/libs/envvar.c --- fvwm/libs/envvar.c +++ fvwm/libs/envvar.c @@ -13,9 +13,9 @@ * **************************************************************************/ +#include #include #include -#include #include "fvwmlib.h" @@ -51,24 +51,23 @@ * characters back. * */ -static void strDel(char *s, int idx, int n) +static void +strDel(char *s, int idx, int n) { - int l; - char *p; + int l; + char *p; - if (idx >= (l = strlen(s))) - return; - if (idx + n > l) - n = l - idx; - s += idx; - p = s + n; - do { - *s++ = *p; - } while (*p++); + if (idx >= (l = strlen(s))) + return; + if (idx + n > l) + n = l - idx; + s += idx; + p = s + n; + do { + *s++ = *p; + } while (*p++); } - - /*------------------------------------------------------------------------- * * NAME strIns @@ -87,34 +86,33 @@ static void strDel(char *s, int idx, int n) * The string is always '\0'-terminated. * */ -static void strIns(char *s, const char *ins, int idx, int maxstrlen) +static void +strIns(char *s, const char *ins, int idx, int maxstrlen) { - int l, li, move; - char *p1, *p2; + int l, li, move; + char *p1, *p2; - if (idx > (l = strlen(s))) - idx = l; - li = strlen(ins); - move = l - idx + 1; /* include '\0' in move */ - p1 = s + l; - p2 = p1 + li; - while (p2 >= s + maxstrlen) { - --p1; - --p2; - --move; - } - while (move-- > 0) - *p2-- = *p1--; - p1 = s + idx; - if (idx + li >= maxstrlen) - li = maxstrlen - idx - 1; - while (li--) - *p1++ = *ins++; - s[maxstrlen - 1] = '\0'; + if (idx > (l = strlen(s))) + idx = l; + li = strlen(ins); + move = l - idx + 1; /* include '\0' in move */ + p1 = s + l; + p2 = p1 + li; + while (p2 >= s + maxstrlen) { + --p1; + --p2; + --move; + } + while (move-- > 0) + *p2-- = *p1--; + p1 = s + idx; + if (idx + li >= maxstrlen) + li = maxstrlen - idx - 1; + while (li--) + *p1++ = *ins++; + s[maxstrlen - 1] = '\0'; } - - /*------------------------------------------------------------------------- * * NAME findEnvVar @@ -138,41 +136,41 @@ static void strIns(char *s, const char *ins, int idx, int maxstrlen) * occurrences are skipped. * */ -static char *findEnvVar(const char *s, int *len) +static char * +findEnvVar(const char *s, int *len) { - int brace = 0; - char *ret = NULL; - const char *next; + int brace = 0; + char *ret = NULL; + const char *next; - if (!s) - return NULL; - while (*s) { - next = s + 1; - if (*s == '$' && (isalpha(*next) || *next == '_' || *next == '{')) { - ret = (char *) s++; - if (*s == '{') { - brace = 1; - ++s; - } - while (*s && (isalnum(*s) || *s == '_')) - ++s; - *len = s - ret; - if (brace) { - if (*s == '}') { - ++*len; - break; + if (!s) + return NULL; + while (*s) { + next = s + 1; + if (*s == '$' && + (isalpha(*next) || *next == '_' || *next == '{')) { + ret = (char *)s++; + if (*s == '{') { + brace = 1; + ++s; + } + while (*s && (isalnum(*s) || *s == '_')) + ++s; + *len = s - ret; + if (brace) { + if (*s == '}') { + ++*len; + break; + } + ret = NULL; + } else + break; } - ret = NULL; - } else - break; + ++s; } - ++s; - } - return ret; + return ret; } - - /*------------------------------------------------------------------------- * * NAME getEnv @@ -185,29 +183,28 @@ static char *findEnvVar(const char *s, int *len) * RETURNS The variable contents, or "" if not found. * */ -static const char *getEnv(const char *name) +static const char * +getEnv(const char *name) { - static char *empty = ""; - char *ret, *tmp, *p, *p2; + static char *empty = ""; + char *ret, *tmp, *p, *p2; - if ((tmp = strdup(name)) == NULL) - return empty; /* better than no test at all. */ - p = tmp; - if (*p == '$') - ++p; - if (*p == '{') { - ++p; - if ((p2 = strchr(p, '}')) != NULL) - *p2 = '\0'; - } - if ((ret = getenv(p)) == NULL) - ret = empty; - free(tmp); - return ret; + if ((tmp = strdup(name)) == NULL) + return empty; /* better than no test at all. */ + p = tmp; + if (*p == '$') + ++p; + if (*p == '{') { + ++p; + if ((p2 = strchr(p, '}')) != NULL) + *p2 = '\0'; + } + if ((ret = getenv(p)) == NULL) + ret = empty; + free(tmp); + return ret; } - - /************************************************************************** * * * P U B L I C F U N C T I O N S * @@ -234,28 +231,27 @@ static const char *getEnv(const char *name) * string. * */ -int envExpand(char *s, int maxstrlen) +int +envExpand(char *s, int maxstrlen) { - char *var, *s2, save; - const char *env; - int len, ret = 0; + char *var, *s2, save; + const char *env; + int len, ret = 0; - s2 = s; - while ((var = findEnvVar(s2, &len)) != NULL) { - ++ret; - save = var[len]; - var[len] = '\0'; - env = getEnv(var); - var[len] = save; - strDel(s, var - s, len); - strIns(s, env, var - s, maxstrlen); - s2 = var + strlen(env); - } - return ret; + s2 = s; + while ((var = findEnvVar(s2, &len)) != NULL) { + ++ret; + save = var[len]; + var[len] = '\0'; + env = getEnv(var); + var[len] = save; + strDel(s, var - s, len); + strIns(s, env, var - s, maxstrlen); + s2 = var + strlen(env); + } + return ret; } - - /*------------------------------------------------------------------------- * * NAME envDupExpand @@ -280,39 +276,40 @@ int envExpand(char *s, int maxstrlen) * string. * */ -char *envDupExpand(const char *s, int extra) +char * +envDupExpand(const char *s, int extra) { - char *var, *ret, save; - const char *env, *s2; - int len, slen, elen, bufflen; + char *var, *ret, save; + const char *env, *s2; + int len, slen, elen, bufflen; - /* - * calculate length needed. - */ - s2 = s; - slen = strlen(s); - bufflen = slen + 1 + extra; - while ((var = findEnvVar(s2, &len)) != NULL) { - save = var[len]; - var[len] = '\0'; - env = getEnv(var); - var[len] = save; - elen = strlen(env); - /* need to make a buffer the maximum possible size, else we - * may get trouble while expanding. */ - bufflen += len > elen ? len : elen; - s2 = var + len; - } - if (bufflen < slen + 1) - bufflen = slen + 1; + /* + * calculate length needed. + */ + s2 = s; + slen = strlen(s); + bufflen = slen + 1 + extra; + while ((var = findEnvVar(s2, &len)) != NULL) { + save = var[len]; + var[len] = '\0'; + env = getEnv(var); + var[len] = save; + elen = strlen(env); + /* need to make a buffer the maximum possible size, else we + * may get trouble while expanding. */ + bufflen += len > elen ? len : elen; + s2 = var + len; + } + if (bufflen < slen + 1) + bufflen = slen + 1; - ret = safemalloc(bufflen); + ret = xmalloc(bufflen); - /* - * now do the real expansion. - */ - strlcpy(ret, s,bufflen); - envExpand(ret, bufflen - extra); + /* + * now do the real expansion. + */ + strlcpy(ret, s, bufflen); + envExpand(ret, bufflen - extra); - return ret; + return ret; } Index: fvwm/libs/fvwmlib.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/libs/fvwmlib.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/libs/fvwmlib.h --- fvwm/libs/fvwmlib.h +++ fvwm/libs/fvwmlib.h @@ -1,47 +1,38 @@ #ifndef FVWMLIB_H #define FVWMLIB_H +#include /* needed for xpm.h and Pixel defn */ #include -#include #include -#include /* needed for xpm.h and Pixel defn */ +#include #include -/* Allow GCC extensions to work, if you have GCC */ - -#ifndef __attribute__ -/* This feature is available in gcc versions 2.5 and later. */ -# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || defined(__STRICT_ANSI__) -# define __attribute__(x) -# endif -/* The __-protected variants of `format' and `printf' attributes - are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */ -# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) -# define __format__ format -# define __printf__ printf -# endif -#endif - /*********************************************************************** * Generic debugging ***********************************************************************/ #ifndef DEBUG -# define DB(_x) +#define DB(_x) #else -# ifndef __FILE__ -# define __FILE__ "?" -# define __LINE__ 0 -# endif -# define DB(_x) do{f_db_info.filenm=__FILE__;f_db_info.lineno=__LINE__;\ - f_db_print _x;}while(0) -struct f_db_info { const char *filenm; unsigned long lineno; }; +#ifndef __FILE__ +#define __FILE__ "?" +#define __LINE__ 0 +#endif +#define DB(_x) \ + do { \ + f_db_info.filenm = __FILE__; \ + f_db_info.lineno = __LINE__; \ + f_db_print _x; \ + } while (0) +struct f_db_info { + const char *filenm; + unsigned long lineno; +}; extern struct f_db_info f_db_info; extern void f_db_print(const char *fmt, ...) - __attribute__ ((__format__ (__printf__, 1, 2))); + __attribute__((__format__(__printf__, 1, 2))); #endif - /*********************************************************************** * Routines for dealing with strings ***********************************************************************/ @@ -49,9 +40,9 @@ extern void f_db_print(const char *fmt, ...) char *CatString3(char *a, char *b, char *c); void CopyString(char **dest, char *source); char *stripcpy(char *source); -int StrEquals(char *s1,char *s2); +int StrEquals(char *s1, char *s2); -int envExpand(char *s, int maxstrlen); +int envExpand(char *s, int maxstrlen); char *envDupExpand(const char *s, int extra); int matchWildcards(char *pattern, char *string); @@ -59,37 +50,43 @@ int matchWildcards(char *pattern, char *string); /*********************************************************************** * Stuff for consistent parsing ***********************************************************************/ -#define EatWS(s) do { while ((s) && (isspace(*(s)) || *(s) == ',')) (s)++; } while (0) -#define IsQuote(c) ((c) == '"' || (c) == '\'' || (c) =='`') +#define EatWS(s) \ + do { \ + while ((s) && (isspace(*(s)) || *(s) == ',')) \ + (s)++; \ + } while (0) +#define IsQuote(c) ((c) == '"' || (c) == '\'' || (c) == '`') #define IsBlockStart(c) ((c) == '[' || (c) == '{' || (c) == '(') -#define IsBlockEnd(c,cs) (((c) == ']' && (cs) == '[') || ((c) == '}' && (cs) == '{') || ((c) == ')' && (cs) == '(')) +#define IsBlockEnd(c, cs) \ + (((c) == ']' && (cs) == '[') || ((c) == '}' && (cs) == '{') || \ + ((c) == ')' && (cs) == '(')) #define MAX_TOKEN_LENGTH 255 -char *SkipQuote(char *s, const char *qlong, const char *qstart, - const char *qend); +char *SkipQuote( + char *s, const char *qlong, const char *qstart, const char *qend); char *GetQuotedString(char *sin, char **sout, const char *delims, - const char *qlong, const char *qstart, const char *qend); + const char *qlong, const char *qstart, const char *qend); char *PeekToken(const char *pstr); char *GetToken(char **pstr); -int CmpToken(const char *pstr,char *tok); -int MatchToken(const char *pstr,char *tok); +int CmpToken(const char *pstr, char *tok); +int MatchToken(const char *pstr, char *tok); void NukeToken(char **pstr); /* old style parse routine: */ -char *DoGetNextToken(char *indata,char **token, char *spaces, char *delims, - char *out_delim); -char *GetNextToken(char *indata,char **token); -char *GetNextOption(char *indata,char **token); +char *DoGetNextToken( + char *indata, char **token, char *spaces, char *delims, char *out_delim); +char *GetNextToken(char *indata, char **token); +char *GetNextOption(char *indata, char **token); char *SkipNTokens(char *indata, unsigned int n); char *GetModuleResource(char *indata, char **resource, char *module_name); -int GetIntegerArguments(char *action, char**ret_action, int retvals[],int num); +int GetIntegerArguments( + char *action, char **ret_action, int retvals[], int num); int GetTokenIndex(char *token, char *list[], int len, char **next); char *GetNextTokenIndex(char *action, char *list[], int len, int *index); int GetRectangleArguments(char *action, int *width, int *height); int GetOnePercentArgument(char *action, int *value, int *unit_io); -int GetTwoPercentArguments(char *action, int *val1, int *val2, int *val1_unit, - int *val2_unit); - +int GetTwoPercentArguments( + char *action, int *val1, int *val2, int *val1_unit, int *val2_unit); /*********************************************************************** * Various system related utils @@ -97,13 +94,12 @@ int GetTwoPercentArguments(char *action, int *val1, int *val2, int *val1_unit, int GetFdWidth(void); int getostype(char *buf, int max); -char *safemalloc(int); /*********************************************************************** * Stuff for modules to communicate with fvwm ***********************************************************************/ int ReadFvwmPacket(int fd, unsigned long *header, unsigned long **body); -void SendText(int *fd,char *message,unsigned long window); +void SendText(int *fd, char *message, unsigned long window); #define SendInfo SendText void GetConfigLine(int *fd, char **tline); void SetMessageMask(int *fd, unsigned long mask); @@ -111,34 +107,32 @@ void SetMessageMask(int *fd, unsigned long mask); /*********************************************************************** * Stuff for dealing w/ bitmaps & pixmaps: ***********************************************************************/ -typedef struct PictureThing -{ - struct PictureThing *next; - char *name; - Pixmap picture; - Pixmap mask; - unsigned int depth; - unsigned int width; - unsigned int height; - unsigned int count; +typedef struct PictureThing { + struct PictureThing *next; + char *name; + Pixmap picture; + Pixmap mask; + unsigned int depth; + unsigned int width; + unsigned int height; + unsigned int count; } FvwmPicture; -void InitPictureCMap(Display*,Window); -FvwmPicture *GetPicture(Display* dpy, Window Root, char* IconPath, - char* PixmapPath, char* name, int color_limit); -FvwmPicture *CachePicture(Display*,Window,char *iconpath, - char *pixmappath,char*,int); -void DestroyPicture(Display*,FvwmPicture*); +void InitPictureCMap(Display *, Window); +FvwmPicture *GetPicture(Display *dpy, Window Root, char *IconPath, + char *PixmapPath, char *name, int color_limit); +FvwmPicture *CachePicture( + Display *, Window, char *iconpath, char *pixmappath, char *, int); +void DestroyPicture(Display *, FvwmPicture *); char *findIconFile(char *icon, char *pathlist, int type); #ifdef XPM -#include /* needed for next prototype */ +#include /* needed for next prototype */ void color_reduce_pixmap(XpmImage *, int); #endif -Pixel GetShadow(Pixel); /* 3d.c */ -Pixel GetHilite(Pixel); /* 3d.c */ - +Pixel GetShadow(Pixel); /* 3d.c */ +Pixel GetHilite(Pixel); /* 3d.c */ /*********************************************************************** * Wrappers around various X11 routines @@ -149,19 +143,17 @@ XFontStruct *GetFontOrFixed(Display *disp, char *fontname); void MyXGrabServer(Display *disp); void MyXUngrabServer(Display *disp); -void send_clientmessage (Display *disp, Window w, Atom a, Time timestamp); +void send_clientmessage(Display *disp, Window w, Atom a, Time timestamp); /*********************************************************************** * Wrappers around Xrm routines (XResources.c) ***********************************************************************/ void MergeXResources(Display *dpy, XrmDatabase *pdb, Bool override); void MergeCmdLineResources(XrmDatabase *pdb, XrmOptionDescList opts, - int num_opts, char *name, int *pargc, char **argv, - Bool fNoDefaults); -Bool MergeConfigLineResource(XrmDatabase *pdb, char *line, char *prefix, - char *bindstr); -Bool GetResourceString(XrmDatabase db, const char *resource, - const char *prefix, char **val); - + int num_opts, char *name, int *pargc, char **argv, Bool fNoDefaults); +Bool MergeConfigLineResource( + XrmDatabase *pdb, char *line, char *prefix, char *bindstr); +Bool GetResourceString( + XrmDatabase db, const char *resource, const char *prefix, char **val); #endif Index: fvwm/libs/lang-strings.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/libs/lang-strings.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/libs/lang-strings.h --- fvwm/libs/lang-strings.h +++ fvwm/libs/lang-strings.h @@ -1,9 +1,9 @@ /*************************************************************************** - * Please translate the strings into the language which you use for + * Please translate the strings into the language which you use for * your pop-up menus. * - * Some decisions about where a function is prohibited (based on - * mwm-function-hints) is based on a string comparison between the + * Some decisions about where a function is prohibited (based on + * mwm-function-hints) is based on a string comparison between the * menu item and the strings below. ***************************************************************************/ #define MOVE_STRING "move" Index: fvwm/libs/safemalloc.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/libs/safemalloc.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/libs/safemalloc.c --- fvwm/libs/safemalloc.c +++ /dev/null @@ -1,27 +0,0 @@ -#include -#include - -/*********************************************************************** - * - * Procedure: - * safemalloc - mallocs specified space or exits if there's a - * problem - * - ***********************************************************************/ -char *safemalloc(int length) -{ - char *ptr; - - if(length <= 0) - length = 1; - - ptr = malloc(length); - if(ptr == (char *)0) - { - fprintf(stderr,"malloc of %d bytes failed. Exiting\n",length); - exit(1); - } - return ptr; -} - - Index: fvwm/libs/wild.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/libs/wild.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/libs/wild.c --- fvwm/libs/wild.c +++ fvwm/libs/wild.c @@ -1,9 +1,9 @@ #include #include -#ifndef TRUE -#define TRUE 1 -#define FALSE 0 +#ifndef TRUE +#define TRUE 1 +#define FALSE 0 #endif /***************************************************************************** @@ -11,66 +11,55 @@ * (including the null string) '?' matches any single char. For use * by filenameforall. Note that '*' matches across directory boundaries * - * This code donated by Paul Hudson + * This code donated by Paul Hudson * It is public domain, no strings attached. No guarantees either. * *****************************************************************************/ -int matchWildcards(char *pattern, char *string) +int +matchWildcards(char *pattern, char *string) { - if(string == NULL) - { - if(pattern == NULL) - return TRUE; - else if(strcmp(pattern,"*")==0) - return TRUE; - else - return FALSE; - } - if(pattern == NULL) - return TRUE; - - while (*string && *pattern) - { - if (*pattern == '?') - { - /* match any character */ - pattern += 1; - string += 1; + if (string == NULL) { + if (pattern == NULL) + return TRUE; + else if (strcmp(pattern, "*") == 0) + return TRUE; + else + return FALSE; } - else if (*pattern == '*') - { - /* see if the rest of the pattern matches any trailing substring - of the string. */ - pattern += 1; - if (*pattern == 0) - { - return TRUE; /* trailing * must match rest */ - } - while (*string) - { - if (matchWildcards(pattern,string)) - { - return TRUE; + if (pattern == NULL) + return TRUE; + + while (*string && *pattern) { + if (*pattern == '?') { + /* match any character */ + pattern += 1; + string += 1; + } else if (*pattern == '*') { + /* see if the rest of the pattern matches any trailing + substring of the string. */ + pattern += 1; + if (*pattern == 0) { + return TRUE; /* trailing * must match rest */ + } + while (*string) { + if (matchWildcards(pattern, string)) { + return TRUE; + } + string++; + } + return FALSE; + } else { + if (*pattern == '\\') + pattern++; /* has strange, but harmless effects + if the last character is a '\\' */ + if (*pattern++ != *string++) { + return FALSE; + } } - string++; - } - return FALSE; } - else - { - if (*pattern == '\\') - pattern ++; /* has strange, but harmless effects if the last - character is a '\\' */ - if (*pattern++ != *string++) - { - return FALSE; - } - } - } - if((*pattern == 0)&&(*string == 0)) - return TRUE; - if((*string == 0)&&(strcmp(pattern,"*")==0)) - return TRUE; - return FALSE; + if ((*pattern == 0) && (*string == 0)) + return TRUE; + if ((*string == 0) && (strcmp(pattern, "*") == 0)) + return TRUE; + return FALSE; } - --- /dev/null +++ fvwm/fvwm/exec.c @@ -0,0 +1,208 @@ +/* + * exec.c -- interface to the privilege-separated execution helper. + * + * The main fvwm process communicates with fvwm_exec via imsg(3) + * over a socketpair(2). The helper executes external commands + * without inheriting the X11 connection. + */ + +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "config.h" +#include "fvwm.h" +#include "misc.h" + +enum imsg_exec_type { + IMSG_EXEC_RUN = 0, + IMSG_EXEC_OK, + IMSG_EXEC_ERROR, + IMSG_EXEC_EXIT, +}; + +static struct imsgbuf *exec_ibuf; +static int exec_fd = -1; +static pid_t exec_pid = -1; + +/* + * exec_helper_start -- fork and exec the execution helper. + * The helper receives one end of a socketpair for imsg communication. + */ +void +exec_helper_start(void) +{ + int sv[2]; + + if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, sv) == -1) + err(1, "socketpair"); + + exec_pid = fork(); + if (exec_pid == -1) + err(1, "fork"); + + if (exec_pid == 0) { + char fdstr[32]; + + close(sv[0]); + snprintf(fdstr, sizeof(fdstr), "%d", sv[1]); + setenv("FVWM_EXEC_FD", fdstr, 1); + + if (pledge("stdio proc exec", NULL) == -1) + err(1, "pledge"); + + execl(FVWMLIBDIR "/fvwm_exec", "fvwm_exec", NULL); + err(1, "execl %s/fvwm_exec", FVWMLIBDIR); + } + + close(sv[1]); + exec_fd = sv[0]; + + exec_ibuf = malloc(sizeof(struct imsgbuf)); + if (exec_ibuf == NULL) + err(1, "malloc"); + imsg_init(exec_ibuf, exec_fd); +} + +/* + * exec_helper_stop -- request helper shutdown and reap. + */ +void +exec_helper_stop(void) +{ + if (exec_ibuf == NULL) + return; + + imsg_clear(exec_ibuf); + close(exec_fd); + free(exec_ibuf); + exec_ibuf = NULL; + exec_fd = -1; + + if (exec_pid > 0) { + kill(exec_pid, SIGTERM); + waitpid(exec_pid, NULL, 0); + exec_pid = -1; + } +} + +/* + * exec_helper_handle -- process imsg responses from the helper. + * Called from the event loop when exec_fd is readable. + */ +void +exec_helper_handle(void) +{ + struct imsg imsg; + ssize_t n; + + if (exec_ibuf == NULL) + return; + + if ((n = imsg_read(exec_ibuf)) == -1 && errno != EAGAIN) + warn("imsg_read"); + if (n == 0) { + warnx("exec helper disconnected"); + exec_helper_stop(); + return; + } + + while ((n = imsg_get(exec_ibuf, &imsg)) != -1) { + if (n == 0) + break; + + switch (imsg.hdr.type) { + case IMSG_EXEC_OK: { + pid_t pid; + + if (imsg.hdr.len < (IMSG_HEADER_SIZE + sizeof(pid_t))) + break; + memcpy(&pid, imsg.data, sizeof(pid_t)); + break; + } + case IMSG_EXEC_ERROR: { + int errnum; + + if (imsg.hdr.len < (IMSG_HEADER_SIZE + sizeof(int))) + break; + memcpy(&errnum, imsg.data, sizeof(int)); + warnc(errnum, "exec helper reported error"); + break; + } + case IMSG_EXEC_EXIT: { + /* Module/command exit; handled by signal watching */ + break; + } + default: + break; + } + imsg_free(&imsg); + } +} + +/* + * exec_helper_launch -- request the helper to execute a command. + * On success, returns 0. On failure (fork error in helper), returns -1. + */ +int +exec_helper_launch(int argc, char **argv, char **envp) +{ + struct ibuf *buf; + size_t datalen, total; + int cargc = argc - 1; /* skip argv[0] which is the path */ + int envc = 0; + int i, ret = -1; + int fd; + + if (exec_ibuf == NULL) + return -1; + + /* Calculate total payload size: sizeof(int)*2 + all strings */ + datalen = sizeof(int) * 2; + for (i = 1; i < argc; i++) + datalen += strlen(argv[i]) + 1; + if (envp) { + for (i = 0; envp[i] != NULL; i++) { + datalen += strlen(envp[i]) + 1; + envc++; + } + } + + if (datalen > MAX_BODY_SIZE * sizeof(unsigned long)) { + warnx("exec argument too large"); + return -1; + } + + /* Compose and send the request */ + buf = imsg_create(exec_ibuf, IMSG_EXEC_RUN, 0, 0, datalen); + if (buf == NULL) + return -1; + + /* argc */ + buf->wpos += imsg_add(buf, &cargc, sizeof(int)); + /* envc */ + buf->wpos += imsg_add(buf, &envc, sizeof(int)); + /* strings */ + for (i = 1; i < argc; i++) { + buf->wpos += imsg_add(buf, argv[i], strlen(argv[i]) + 1); + } + if (envp) { + for (i = 0; envp[i] != NULL; i++) { + buf->wpos += imsg_add(buf, envp[i], + strlen(envp[i]) + 1); + } + } + imsg_close(exec_ibuf, buf); + imsg_flush(exec_ibuf); + + return 0; +} --- /dev/null +++ fvwm/fvwm/fvwm_exec.c @@ -0,0 +1,169 @@ +/* + * fvwm_exec.c -- privilege-separated execution helper for fvwm(1) + * + * Runs as a separate process that receives exec requests via imsg(3) + * from the main fvwm process, executes them, and reports results. + */ + +#include + +#include + +#include +#include +#include +#include +#include +#include + +#include "config.h" + +/* + * imsg_exec -- structured IPC message types for execution requests. + * + * Message flow: + * fvwm -> helper: IMSG_EXEC_RUN (path + argv + envp) + * helper -> fvwm: IMSG_EXEC_OK (pid of launched child) + * IMSG_EXEC_ERROR (errno + message) + * IMSG_EXEC_EXIT (pid + status, sent on child exit) + */ + +enum imsg_exec_type { + IMSG_EXEC_RUN = 0, + IMSG_EXEC_OK, + IMSG_EXEC_ERROR, + IMSG_EXEC_EXIT, +}; + +__dead static void +usage(void) +{ + extern char *__progname; + + fprintf(stderr, "usage: %s\n", __progname); + exit(1); +} + +static void +exec_child(int argc, char **argv, char **envp) +{ + if (pledge("stdio exec", NULL) == -1) + err(1, "pledge"); + + closefrom(3); + + if (envp) + execve(argv[0], argv, envp); + else + execv(argv[0], argv); + + err(1, "execv: %s", argv[0]); +} + +int +main(int argc, char **argv) +{ + struct imsgbuf ibuf; + struct imsg imsg; + ssize_t n; + int s; + + if (argc != 1) + usage(); + + if (getenv("FVWM_EXEC_FD") == NULL) + errx(1, "FVWM_EXEC_FD not set"); + + s = (int)strtonum(getenv("FVWM_EXEC_FD"), 0, INT_MAX, NULL); + + signal(SIGPIPE, SIG_IGN); + + imsg_init(&ibuf, s); + + if (pledge("stdio proc exec", NULL) == -1) + err(1, "pledge"); + + for (;;) { + if ((n = imsg_read(&ibuf)) == -1 && errno != EAGAIN) + err(1, "imsg_read"); + if (n == 0) + break; + + while ((n = imsg_get(&ibuf, &imsg)) != -1) { + if (n == 0) + break; + + switch (imsg.hdr.type) { + case IMSG_EXEC_RUN: { + pid_t pid; + char **child_argv; + char **child_envp; + int cargc, envc; + char *data = imsg.data; + + if (imsg.hdr.len < sizeof(int) * 2) { + warnx("short IMSG_EXEC_RUN"); + break; + } + memcpy(&cargc, data, sizeof(int)); + memcpy(&envc, data + sizeof(int), sizeof(int)); + data += sizeof(int) * 2; + + /* Reconstruct argv */ + child_argv = malloc( + (cargc + 1) * sizeof(char *)); + if (child_argv == NULL) + err(1, "malloc"); + for (int i = 0; i < cargc; i++) { + size_t len = strlen(data); + child_argv[i] = data; + data += len + 1; + } + child_argv[cargc] = NULL; + + /* Reconstruct envp */ + child_envp = malloc( + (envc + 1) * sizeof(char *)); + if (child_envp == NULL) + err(1, "malloc"); + for (int i = 0; i < envc; i++) { + size_t len = strlen(data); + child_envp[i] = data; + data += len + 1; + } + child_envp[envc] = NULL; + + pid = fork(); + if (pid == -1) { + warn("fork"); + imsg_compose(&ibuf, IMSG_EXEC_ERROR, + 0, 0, -1, &errno, sizeof(int)); + free(child_argv); + free(child_envp); + break; + } + if (pid == 0) + exec_child(cargc, child_argv, + child_envp); + + free(child_argv); + free(child_envp); + + imsg_compose(&ibuf, IMSG_EXEC_OK, + 0, 0, -1, &pid, sizeof(pid_t)); + imsg_flush(&ibuf); + break; + } + default: + warnx("unknown imsg type %d", + imsg.hdr.type); + break; + } + imsg_free(&imsg); + } + } + + imsg_clear(&ibuf); + close(s); + return 0; +} --- /dev/null +++ fvwm/fvwm/fvwm_sandbox.h @@ -0,0 +1,187 @@ +/* + * fvwm_sandbox.h -- common sandbox helper for fvwm processes. + * + * Provides pledge/unveil setup patterns used across the fvwm module set. + * Each module calls only the helpers it needs; there is no "one size fits + * all" policy. + * + * All pledge/unveil calls check return values and fail with diagnostics. + * + * IMPORTANT: Every policy declared here requires verification on a real + * OpenBSD system with ktrace(1) and a full X11 session. + */ + +#ifndef FVWM_SANDBOX_H +#define FVWM_SANDBOX_H + +#ifndef FVWMLIBDIR +#define FVWMLIBDIR "/usr/X11R6/lib/X11/fvwm" +#endif + +/* + * sandbox_x11_only -- process that only needs X11 + stdio + fvwm pipes. + * No filesystem access, no network, no process creation. + * Used by: FvwmAuto, FvwmBanner, FvwmBacker, FvwmIdent, FvwmIconBox, + * FvwmPager, FvwmScroll, FvwmTalk, FvwmWinList + */ +static inline void +sandbox_x11_only(const char *progname) +{ + if (pledge("stdio", NULL) == -1) + err(1, "%s: pledge stdio", progname); +} + +/* + * sandbox_x11_config -- X11 + read-only config file access. + * No write, no network, no process creation. + * Used by: FvwmButtons, FvwmIconMan (after config read), + * FvwmForm (after /dev/null open) + */ +static inline void +sandbox_x11_config(const char *progname) +{ + if (pledge("stdio rpath", NULL) == -1) + err(1, "%s: pledge stdio rpath", progname); +} + +/* + * sandbox_save_state -- X11 + write to home directory. + * No network, no process creation. + * Used by: FvwmSave, FvwmSaveDesk + * + * Unveil is set up BEFORE calling this to restrict to the exact file. + */ +static inline void +sandbox_save_state(const char *progname) +{ + if (pledge("stdio rpath wpath cpath", NULL) == -1) + err(1, "%s: pledge stdio rpath wpath cpath", progname); +} + +/* + * sandbox_cpp_preproc -- X11 + fork/exec cpp + tmp + dns. + * Used by: FvwmCpp + * + * Unveil is set up BEFORE calling this. + */ +static inline void +sandbox_cpp_preproc(const char *progname) +{ + if (pledge("stdio rpath wpath cpath proc exec dns getpw", + NULL) == -1) + err(1, "%s: pledge", progname); +} + +/* + * sandbox_m4_preproc -- X11 + popen m4 + tmp + dns. + * Used by: FvwmM4 + * + * Unveil is set up BEFORE calling this. + */ +static inline void +sandbox_m4_preproc(const char *progname) +{ + if (pledge("stdio rpath wpath cpath proc exec dns getpw", + NULL) == -1) + err(1, "%s: pledge", progname); +} + +/* + * sandbox_xpmroot -- X11-only utility, no filesystem writes. + */ +static inline void +sandbox_xpmroot(const char *progname) +{ + if (pledge("stdio", NULL) == -1) + err(1, "%s: pledge stdio", progname); +} + +/* + * sandbox_main_fvwm -- main window manager process. + * After startup: retains proc for module fork, exec for helper launch, + * rpath for config reads. + */ +static inline void +sandbox_main_fvwm(const char *progname) +{ + if (unveil(FVWMLIBDIR, "rx") == -1) + err(1, "%s: unveil %s", progname, FVWMLIBDIR); + if (unveil("/etc/X11/fvwm", "r") == -1) + err(1, "%s: unveil /etc/X11/fvwm", progname); + if (unveil("/tmp", "rwc") == -1) + err(1, "%s: unveil /tmp", progname); + if (unveil(NULL, NULL) == -1) + err(1, "%s: unveil lock", progname); + + if (pledge("stdio rpath proc exec", NULL) == -1) + err(1, "%s: pledge", progname); +} + +/* + * sandbox_exec_helper -- fvwm_exec helper process. + * Receives imsg requests, forks children, and execs them. + */ +static inline void +sandbox_exec_helper(const char *progname) +{ + if (pledge("stdio proc exec", NULL) == -1) + err(1, "%s: pledge", progname); +} + +/* + * sandbox_exec_child -- child of the execution helper, about to exec. + */ +static inline void +sandbox_exec_child(const char *progname) +{ + if (pledge("stdio exec", NULL) == -1) + err(1, "%s: pledge", progname); +} + +/* + * unveil_tempdir -- unveil the temporary directory (from $TMPDIR or /tmp). + * For modules that create temp files (FvwmCpp, FvwmM4). + */ +static inline void +unveil_tempdir(const char *progname) +{ + const char *tmp; + + tmp = getenv("TMPDIR"); + if (tmp == NULL) + tmp = "/tmp"; + if (unveil(tmp, "rwc") == -1) + err(1, "%s: unveil %s", progname, tmp); +} + +/* + * unveil_home_read -- unveil $HOME for reading only. + */ +static inline void +unveil_home_read(const char *progname) +{ + const char *home; + + home = getenv("HOME"); + if (home == NULL) + home = "."; + if (unveil(home, "r") == -1) + err(1, "%s: unveil %s", progname, home); +} + +/* + * unveil_home_write -- unveil $HOME for read/write/create. + */ +static inline void +unveil_home_write(const char *progname) +{ + const char *home; + + home = getenv("HOME"); + if (home == NULL) + home = "."; + if (unveil(home, "rwc") == -1) + err(1, "%s: unveil %s", progname, home); +} + +#endif /* FVWM_SANDBOX_H */ --- /dev/null +++ fvwm/fvwm/xalloc.h @@ -0,0 +1,77 @@ +#ifndef FVWM_XALLOC_H +#define FVWM_XALLOC_H + +#include +#include +#include + +static inline void * +xmalloc(size_t size) +{ + void *ptr; + + if (size == 0) + size = 1; + ptr = malloc(size); + if (ptr == NULL) + err(1, "malloc"); + return ptr; +} + +static inline void * +xcalloc(size_t nmemb, size_t size) +{ + void *ptr; + + if (nmemb == 0 || size == 0) { + nmemb = 1; + size = 1; + } + ptr = calloc(nmemb, size); + if (ptr == NULL) + err(1, "calloc"); + return ptr; +} + +static inline void * +xrealloc(void *ptr, size_t size) +{ + void *newptr; + + if (size == 0) + size = 1; + newptr = realloc(ptr, size); + if (newptr == NULL) + err(1, "realloc"); + return newptr; +} + +static inline void * +xreallocarray(void *ptr, size_t nmemb, size_t size) +{ + return xrealloc(ptr, nmemb * size); +} + +static inline char * +xstrdup(const char *s) +{ + char *copy; + + copy = strdup(s); + if (copy == NULL) + err(1, "strdup"); + return copy; +} + +static inline char * +xstrndup(const char *s, size_t n) +{ + char *copy; + + copy = strndup(s, n); + if (copy == NULL) + err(1, "strndup"); + return copy; +} + +#endif /* FVWM_XALLOC_H */ Index: fvwm/fvwm/Makefile =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/Makefile,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/Makefile --- fvwm/fvwm/Makefile +++ fvwm/fvwm/Makefile @@ -11,6 +11,7 @@ SRCS= add_window.c bindings.c borders.c \ virtual.c windows.c CPPFLAGS+= -DFVWM_MODULEDIR=\"$(FVWMLIBDIR)\" \ + -DFVWMLIBDIR=\"$(FVWMLIBDIR)\" \ -DFVWMRC=\".fvwmrc\" \ -DFVWM_CONFIGDIR=\"$(FVWMLIBDIR)\" Index: fvwm/fvwm/events.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/events.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/events.c --- fvwm/fvwm/events.c +++ fvwm/fvwm/events.c @@ -37,8 +37,6 @@ #include "config.h" -#endif - #include #include @@ -1478,9 +1476,7 @@ My_XNextEvent(Display *dpy, XEvent *event) DBUG("My_XNextEvent", "waiting for module input/output"); XFlush(dpy); - if (select((SELECT_TYPE_ARG1)fd_width, SELECT_TYPE_ARG234 & in_fdset, - SELECT_TYPE_ARG234 & out_fdset, SELECT_TYPE_ARG234 0, - SELECT_TYPE_ARG5 NULL) > 0) { + if (select(fd_width, &in_fdset, &out_fdset, NULL, NULL) > 0) { /* Check for module input. */ for (i = 0; i < npipes; i++) { if (readPipes[i] >= 0) { Index: fvwm/fvwm/exec.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/exec.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/exec.c --- fvwm/fvwm/exec.c +++ fvwm/fvwm/exec.c @@ -21,6 +21,7 @@ #include "config.h" #include "fvwm.h" +#include "module.h" #include "misc.h" enum imsg_exec_type { @@ -70,7 +71,8 @@ exec_helper_start(void) exec_ibuf = malloc(sizeof(struct imsgbuf)); if (exec_ibuf == NULL) err(1, "malloc"); - imsg_init(exec_ibuf, exec_fd); + if (imsgbuf_init(exec_ibuf, exec_fd) == -1) + err(1, "imsgbuf_init"); } /* @@ -82,7 +84,7 @@ exec_helper_stop(void) if (exec_ibuf == NULL) return; - imsg_clear(exec_ibuf); + imsgbuf_clear(exec_ibuf); close(exec_fd); free(exec_ibuf); exec_ibuf = NULL; @@ -108,8 +110,8 @@ exec_helper_handle(void) if (exec_ibuf == NULL) return; - if ((n = imsg_read(exec_ibuf)) == -1 && errno != EAGAIN) - warn("imsg_read"); + if ((n = imsgbuf_read(exec_ibuf)) == -1 && errno != EAGAIN) + warn("imsgbuf_read"); if (n == 0) { warnx("exec helper disconnected"); exec_helper_stop(); @@ -202,7 +204,7 @@ exec_helper_launch(int argc, char **argv, char **envp) } } imsg_close(exec_ibuf, buf); - imsg_flush(exec_ibuf); + imsgbuf_flush(exec_ibuf); return 0; } Index: fvwm/fvwm/fvwm.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/fvwm.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/fvwm.h --- fvwm/fvwm/fvwm.h +++ fvwm/fvwm/fvwm.h @@ -40,6 +40,8 @@ #include #include +#include "xalloc.h" + #ifndef WithdrawnState #define WithdrawnState 0 #endif Index: fvwm/fvwm/fvwm_exec.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/fvwm_exec.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/fvwm_exec.c --- fvwm/fvwm/fvwm_exec.c +++ fvwm/fvwm/fvwm_exec.c @@ -10,7 +10,9 @@ #include #include +#include #include +#include #include #include #include @@ -78,14 +80,15 @@ main(int argc, char **argv) signal(SIGPIPE, SIG_IGN); - imsg_init(&ibuf, s); + if (imsgbuf_init(&ibuf, s) == -1) + err(1, "imsgbuf_init"); if (pledge("stdio proc exec", NULL) == -1) err(1, "pledge"); for (;;) { - if ((n = imsg_read(&ibuf)) == -1 && errno != EAGAIN) - err(1, "imsg_read"); + if ((n = imsgbuf_read(&ibuf)) == -1 && errno != EAGAIN) + err(1, "imsgbuf_read"); if (n == 0) break; @@ -151,7 +154,7 @@ main(int argc, char **argv) imsg_compose(&ibuf, IMSG_EXEC_OK, 0, 0, -1, &pid, sizeof(pid_t)); - imsg_flush(&ibuf); + imsgbuf_flush(&ibuf); break; } default: @@ -163,7 +166,7 @@ main(int argc, char **argv) } } - imsg_clear(&ibuf); + imsgbuf_clear(&ibuf); close(s); return 0; } Index: fvwm/fvwm/fvwm_sandbox.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/fvwm_sandbox.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/fvwm_sandbox.h --- fvwm/fvwm/fvwm_sandbox.h +++ fvwm/fvwm/fvwm_sandbox.h @@ -14,6 +14,8 @@ #ifndef FVWM_SANDBOX_H #define FVWM_SANDBOX_H +#include + #ifndef FVWMLIBDIR #define FVWMLIBDIR "/usr/X11R6/lib/X11/fvwm" #endif Index: fvwm/fvwm/fvwmdebug.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/fvwmdebug.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/fvwmdebug.h --- fvwm/fvwm/fvwmdebug.h +++ fvwm/fvwm/fvwmdebug.h @@ -27,4 +27,8 @@ void DB_WI_ALL(char *label, FvwmWindow *fw); #define DB_WI_ALL(x, y) #endif +#ifndef DBUG +#define DBUG(x, y) do { (void)(x); (void)(y); } while (0) +#endif + #endif /* _DEBUG_ */ Index: fvwm/fvwm/module.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/module.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/module.h --- fvwm/fvwm/module.h +++ fvwm/fvwm/module.h @@ -1,6 +1,8 @@ #ifndef MODULE_H #define MODULE_H +#include "xalloc.h" + struct queue_buff_struct { struct queue_buff_struct *next; unsigned long *data; Index: fvwm/libs/fvwmlib.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/libs/fvwmlib.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/libs/fvwmlib.h --- fvwm/libs/fvwmlib.h +++ fvwm/libs/fvwmlib.h @@ -7,6 +7,8 @@ #include #include +#include "../fvwm/xalloc.h" + /*********************************************************************** * Generic debugging ***********************************************************************/ OpenBSD FVWM 2.2.5: GPL Code Replacement ========================================= Replaces GPL-licensed code with permissive-licensed equivalents. Files rewritten to remove GPL dependencies: fvwm/COPYING License text replaced fvwm/fvwm/fvwm2.1 Man page (GPL references removed) fvwm/libs/ColorUtils.c Color utilities rewritten fvwm/modules/FvwmBacker/root_bits.c Root pixmap code rewritten fvwm/modules/FvwmRearrange/FvwmRearrange.1 Man page rewritten fvwm/modules/FvwmRearrange/FvwmRearrange.c Module rewritten These files contained code derived from GPL-licensed sources. They have been rewritten to use only permissive-licensed code compatible with the OpenBSD base system. To apply: cd && patch -p0 < this-file Index: fvwm/COPYING =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/COPYING,v retrieving revision 1.1 diff -u -r1.1 fvwm/COPYING --- fvwm/COPYING +++ fvwm/COPYING @@ -1,3 +1,8 @@ +FVWM Licensing Terms and Conditions +=================================== + +General Terms +------------- Permission is granted to distribute all software within this distribution freely as long as the individual copyrights, copyright notices and associated disclaimers remain intact @@ -11,29 +16,9 @@ THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. ----------------------------------------------------------------------- - -In addition - with the exception of the following directories -and all files within: - - modules/FvwmRearrange - extras/FvwmPipe - modules/FvwmAnimate - modules/FvwmAudio - modules/FvwmEvents - -- permission is granted to use this software for any purpose, as -long as the individual copyrights, copyright notices and -associated disclaimers remain intact in the sources and the -supporting documentation. The following pieces of software are -exempt from this statement. - -The modules modules/FvwmAnimate, modules/FvwmAudio and modules/FvwmEvents -are subject to the GNU public license (see below). - ----------------------------------------------------------------------- - -The copyrights of the fvwm main module are: +FVWM Main Module +---------------- +The FVWM main module is distributed under the following license: fvwm is copyright 1988 by Evans and Sutherland Computer Corporation, Salt Lake City, Utah, and 1989 by the Massachusetts @@ -58,314 +43,25 @@ USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -------------------------------------------------------------------------- - - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Library General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) 19yy - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +Additional Component Licenses +----------------------------- +The following pieces of software are distributed under the ISC License: + libs/ColorUtils.c + modules/FvwmRearrange + modules/FvwmBacker/root_bits.c + +ISC License +----------- + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. Index: fvwm/fvwm/fvwm2.1 =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/fvwm2.1,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/fvwm2.1 --- fvwm/fvwm/fvwm2.1 +++ fvwm/fvwm/fvwm2.1 @@ -1,2899 +1,369 @@ -.\" $OpenBSD: fvwm2.1,v 1.2 2019/10/19 16:39:49 matthieu Exp $ -.\" t -.\" @(#)fvwm2.1 8/11/1998 -.de EX \"Begin example -.ne 5 -.if n .sp 1 -.if t .sp .5 -.nf -.in +.5i -.. -.de EE -.fi -.in -.5i -.if n .sp 1 -.if t .sp .5 -.. -.ta .3i .6i .9i 1.2i 1.5i 1.8i -.TH FVWM 1 "late 20th century" "fvwm 2.xx" -.UC -.SH NAME -fvwm \- F(?) Virtual Window Manager (version 2.xx) for X11 -.SH SYNOPSIS -\fBfvwm\fP [ \fIoptions\fP ] -.SH DESCRIPTION -\fIFvwm\fP is a window manager for X11. It is a derivative of -\fItwm\fP, redesigned to minimize memory consumption, provide a 3-D -look to window frames, and provide a simple virtual desktop. Version -2.xx uses only slightly more memory than 1.xx, mostly due to some -global options being able to be window specific now. - -Fvwm provides both a large virtual desktop and multiple disjoint -desktops which can be used separately or together. The virtual desktop -allows you to pretend that your video screen is really quite large, -and you can scroll around within the desktop. The multiple disjoint -desktops allow you to pretend that you really have several screens to -work at, but each screen is completely unrelated to the others. - -Fvwm provides keyboard accelerators which allow you to perform most -window-manager functions, including moving and resizing windows, and -operating the window-manager's menus, using keyboard shortcuts. - -Fvwm has also blurred the distinction between configuration commands -and built-in commands that most window-managers make. Configuration -commands typically set fonts, colors, menu contents, key and mouse -function bindings, while built-in commands typically do things like -raise and lower windows. Fvwm makes no such distinction, and allows, -to the extent that is practical, anything to be changed at any time. - -Other noteworthy differences between Fvwm and other X11 window managers -are the introduction of the SloppyFocus and per-window focus methods. -SloppyFocus is focus-follows-mouse, but focus is not removed from -windows when the mouse leaves a window and enters the root window. -When sloppy focus is used as the default focus style, it is nice to -make windows in which you do not typically type into (xmag, -xload, xclock, xbiff, etc) click-to-focus, so that your terminal -window doesn't lose focus unnecessarily. - -.SH COPYRIGHTS -Since \fIfvwm\fP is derived from \fItwm\fP code it shares \fItwm\fP's -copyrights. Since nearly every line of twm code has been changed, the -twm copyright has been removed from most of the individual code files. -I do still recognize the influence of twm code in the overall package, -so fvwm's copyright is still considered to be the same as twm's. - -Please consult the COPYING file that has come with your distribution -for details. - -.SH ANATOMY OF A WINDOW -\fIFvwm\fP puts a decorative border around most windows. This border -consists of a bar on each side and a small "L" shaped section on each -corner. There is an additional top bar called the title bar which is -used to display the name of the window. In addition, there are up to -10 title-bar buttons. The top, side, and bottom bars are collectively -known as the side-bars. The corner pieces are called the frame. - -Unless the standard defaults files are modified, pressing mouse button -1 in the title or side-bars will begin a move operation on the -window. Pressing button 1 in the corner frame pieces will begin a -resize operation. Pressing button 2 anywhere in the border brings up -an extensive list of window operations. - -Up to ten title-bar buttons may exist. Their use is completely user -definable. The default configuration has a title-bar button on each -side of the title-bar. The one on the left is used to bring up a list -of window options, regardless of which mouse button is used. The one -on the right is used to iconify the window. The number of title-bar -buttons used depends on which ones have mouse actions bound to -them. See the section on the "Mouse" configuration parameter below. - - -.SH THE VIRTUAL DESKTOP -\fIFvwm\fP provides multiple virtual desktops for users who wish to -use them. The screen is a viewport onto a desktop which may be larger -than the screen. Several distinct desktops can be accessed (concept: -one desktop for each project, or one desktop for each application, -when view applications are distinct). Since each desktop can be -larger than the physical screen, divided into m by n pages which are -each the size of the physical screen, windows which are larger than -the screen or large groups of related windows can easily be viewed. - -The (m by n) size (i.e. number of pages) of the virtual desktops can be -changed any time, by using the DeskTopSize built-in command. All -virtual desktops must be (are) the same size. The total number of -distinct desktops need not be specified, but is limited to -approximately 4 billion total. All windows on a range of desktops can -be viewed in the Pager, a miniature view of the desktops. The pager -is an accessory program, called a module, which is not essential for -the window manager to operate. Windows may also be listed, along with -their geometries, in a window list, accessible as a pop-up menu, or as -a separate window, called the FvwmWinList (another module). - -"Sticky" windows are windows which transcend the virtual desktop by -"Sticking to the screen's glass." They always stay put on the screen. -This is convenient for things like clocks and xbiff's, so you only need -to run one such gadget and it always stays with you. Icons can also be -made to stick to the glass, if desired. - -Window geometries are specified relative to the current viewport. That -is: -.EX -xterm -geometry +0+0 -.EE -will always show up in the upper-left hand -corner of the visible portion of the screen. It is permissible to -specify geometries which place windows on the virtual desktop, but off -the screen. For example, if the visible screen is 1000 by 1000 pixels, -and the desktop size is 3x3, and the current viewport is at the upper -left hand corner of the desktop, then invoking: -.EX -xterm -geometry +1000+1000 -.EE -will place the window just off of the lower right hand corner of the -screen. It can be found by moving the mouse to the lower right hand -corner of the screen and waiting for it to scroll into view. - -A geometry specified as something like: -.EX -xterm -geometry -5-5 -.EE -will -generally place the window's lower right hand corner 5 pixels from the -lower right corner of the visible portion of the screen. Not all -applications support window geometries with negative offsets. Some will -place the window's upper right hand corner 5 pixels above and to the left -of the upper left hand corner of the screen; others may do just plain -bizarre things. - - -There are several ways to cause a window to map onto a desktop or page -other than the currently active one. The geometry technique mentioned above -(specifying x,y coordinates larger than the physical screen size), however, -suffers from the limitation of being interpreted relative to the current -viewport: the window will not consistently appear on a specific page, unless -you always invoke the application from the same page. - -A better way to place windows on a different page or desk from the -currently mapped viewport is to use the StartsOnPage style specification -(the successor to the older StartsOnDesk style) in the .fvwmrc configuration -file. The placement is consistent: it does not depend on your current location -on the virtual desktop. - -Some applications that understand standard Xt command line arguments -and X resources, like xterm and xfontsel, allow the user to specify -the start-up desk or page on the command line: -.EX -xterm -xrm "*Desk:1" -.EE -will start an xterm on desk number 1; -.EX -xterm -xrm "*Page:3 2 1" -.EE -will start an xterm two pages to the right and one down from the upper -left hand page of desk number 3. Not all applications understand the use -of these options, however. - -You could achieve the same results with the following lines in your -.Xdefaults file: -.EX -XTerm*Desk: 1 -.EE -or -.EX -XTerm*Page: 3 2 1 -.EE - -.SH INITIALIZATION -During initialization, \fIfvwm\fP will search for a configuration file -which describes key and button bindings, and a few other things. The -format of these files will be described later. First, \fIfvwm\fP will -search for a file named .fvwmrc in the user's home directory, then in -${sysconfdir} (typically __projectroot__/lib/X11/fvwm). -Failing that, it will look for system.fvwmrc in ${sysconfdir} for -system-wide defaults. If that file is not found, \fIfvwm\fP will be -basically useless. - -\fIFvwm\fP will set two environment variables which will be inherited -by its children. These are $DISPLAY which describes the display on -which \fIfvwm\fP is running. $DISPLAY may be unix:0.0 or :0.0, which -doesn't work too well when passed through rsh to another machine, so -$HOSTDISPLAY will also be set and will use a network-ready description -of the display. $HOSTDISPLAY will always use the TCP/IP transport -protocol (even for a local connection) so $DISPLAY should be used for -local connections, as it may use Unix-domain sockets, which are -faster. - -Fvwm has three special functions for initialization: -StartFunction, which is executed on startups and restarts; InitFunction -and RestartFunction, which are executed during Initialization and Restarts -(respectively) just after StartFunction. These may be customized -in a user's rc file via the AddToFunc facility (described later) to start up -modules, xterms, or whatever you'd like to have started by fvwm. - -\fIFvwm\fP also has a special exit function: ExitFunction, executed -when exiting or restarting before actually quitting or anything else. -It could be used to explicitly kill modules, etc. - -.SH COMPILATION OPTIONS -\fIFvwm\fP has a number of compile-time options to reduce memory usage -by limiting the use of certain features. If you -have trouble using a certain command or feature, check to see if -support for it was included at compile time. Optional features are -described in the config.h file. - -.SH ICONS -The basic \fIFvwm\fP configuration uses monochrome bitmap icons, -similar to \fItwm\fP. If XPM extensions are compiled in, then color -icons similar to ctwm, MS-Windows, or the Macintosh icons can be used. -In order to use these options you will need the XPM package, as -described in the INSTALL.fvwm file. - -If both the SHAPE and XPM options are compiled in you will get shaped -color icons, which are very spiffy. - -.SH MODULES -A module is a separate program which runs as a separate Unix process -but transmits commands to \fIfvwm\fP to execute. Users can write -their own modules to do any weird or bizarre manipulations without -bloating or affecting the integrity of \fIfvwm\fP itself. - -Modules MUST be spawned by \fIfvwm\fP so that it can set up two pipes for -\fIfvwm\fP and the module to communicate with. The pipes will already be -open for the module when it starts and the file descriptors for the -pipes are provided as command line arguments. - -Modules can be spawned during \fIfvwm\fP at any time during the X -session by use of the Module built-in command. Modules can exist for -the duration of the X session, or can perform a single task and exit. -If the module is still active when \fIfvwm\fP is told to quit, then -\fIfvwm\fP will close the communication pipes and wait to receive a -SIGCHLD from the module, indicating that it has detected the pipe -closure and has exited. If modules fail to detect the pipe closure -\fIfvwm\fP will exit after approximately 30 seconds anyway. The -number of simultaneously executing modules is limited by the operating -system's maximum number of simultaneously open files, usually between -60 and 256. - -Modules simply transmit text commands to the \fIfvwm\fP built-in -command engine. Text commands are formatted just as in the case of a -mouse binding in the .fvwmrc setup file. Certain auxiliary -information is also transmitted, as in the sample module FvwmButtons. -The FvwmButtons module is documented in its own man page. - -.SH ICCCM COMPLIANCE -\fIFvwm\fP attempts to be ICCCM 1.1 compliant. In addition, ICCCM -states that it should be possible for applications to receive ANY -keystroke, which is not consistent with the keyboard shortcut approach -used in \fIfvwm\fP and most other window managers. In particular you -cannot have the same keyboard shortcuts working with your fvwm2 and -another fvwm2 running within Xnest (a nested X server). The same problem -exists with mouse bindings. - -The ICCCM states that windows possessing the property -.EX -WM_HINTS(WM_HINTS): - Client accepts input or input focus: False -.EE -should not be given the keyboard input focus by the window manager. -These windows can take the input focus by themselves, however. A -number of applications set this property, and yet expect the -window-manager to give them the keyboard focus anyway, so fvwm -provides a window-style, "Lenience", which will allow fvwm to overlook -this ICCCM rule. - - -.SH M4 PREPROCESSING -.PP -M4 pre-processing is handled by a module in fvwm-2.0. To get more -details, try man FvwmM4. In short, if you want fvwm to parse your -files with m4, then replace the word "Read" with "FvwmM4" in -your .fvwmrc file (if it appears at all), and start fvwm with the -command -.EX -fvwm -cmd "FvwmM4 .fvwmrc" -.EE - -.SH CPP PREPROCESSING -.PP -Cpp is the C-language pre-processor. fvwm-2.0 offers cpp processing -which mirrors the m4 pre-processing. To find out about it, re-read -the M4 section above, but replace "m4" with "cpp". - -.SH AUTO-RAISE -.PP -Windows can be automatically raised when it receives focus, or some -number of milliseconds after it receives focus, by using the -auto-raise module, FvwmAuto. - -.SH OPTIONS -These are the command line options that are recognized by \fIfvwm\fP: -.IP "\fB-blackout\fP" -The screen is blacked out during window recaptures and startup. This option -is provided for backwards compatibility only. -.IP "\fB-cmd\fP \fIconfig_command\fP" -Causes \fIfvwm\fP to use \fIconfig_command\fP instead of "Read .fvwmrc" -as its initialization command. -(Note that up to 10 \fB-f\fP and \fB-cmd\fP parameters can be given, -and they are executed in the order specified.) -.IP "\fB-d\fP \fIdisplayname\fP" -Manage the display called "displayname" instead of the name obtained from -the environment variable $DISPLAY. -.IP "\fB-debug\fP" -Puts X transactions in synchronous mode, which dramatically slows things -down, but guarantees that \fIfvwm\fP's internal error messages are correct. -Also causes \fIfvwm\fP to output debug messages while running. -.IP "\fB-f\fP \fIconfig_file\fP" -Causes \fIfvwm\fP to Read \fIconfig_file\fP instead of ".fvwmrc" -as its initialization file. This is equivalent to -\fB-cmd\fP "Read \fIconfig_file\fP". -.IP "\fB-h\fP" -A short usage description is printed. -.IP "\fB-s\fP" -On a multi-screen display, run \fIfvwm\fP only on the screen named in -the $DISPLAY environment variable or provided through the -d -option. Normally, \fIfvwm\fP will attempt to start up on all screens -of a multi-screen display. -.IP "\fB-version\fP" -Print the version of \fIfvwm\fP to stderr. - -.SH CONFIGURATION FILES -The configuration file is used to describe mouse and button bindings, -colors, the virtual display size, and related items. The -initialization configuration file is typically called ".fvwmrc". By -using the "Read" built-in, it is easy to read in new configuration -files as you go. - -Lines beginning with '#' will be ignored by \fIfvwm\fP. Lines -starting with '*' are expected to contain module configuration -commands (rather than configuration commands for \fIfvwm\fP itself). - -Fvwm makes no distinction between configuration commands and built-in -commands, so anything mentioned in the built-in commands section can -be placed on a line by itself for fvwm to execute as it reads the -configuration file, or it can be placed as an executable command in a -menu or bound to a mouse button or a keyboard key. It is left as an -exercise for the user to decide which function make sense for -initialization and which ones make sense for run-time. - -.SH BUILT IN FUNCTIONS -\fIFvwm\fP supports a set of built-in functions which can be bound to -keyboard or mouse buttons. If fvwm expects to find a built-in function -in a command, but fails, it will check to see if the specified command -should have been "Function (rest of command)" or "Module (rest of -command)". This allows complex functions or modules to be invoked in a -manner which is fairly transparent to the configuration file. - -Example: the .fvwmrc file contains the line "HelpMe". Fvwm will look -for a built-in command called "HelpMe", and will fail. Next it will -look for a user-defined complex function called "HelpMe". If no such -user defined function exists, Fvwm will try to execute a module called -"HelpMe". - -In previous versions of fvwm, quoting was critical and irrational in -the .fvwmrc file. As of fvwm-2, most of this has been cleared up. -Quotes are required only when needed to make fvwm consider two or more -words to be a single argument. Unnecessary quoting is allowed. If you -want a quote character in your text, you must escape it by using the -backslash character. For example, if you have a pop-up menu called -Window-Ops, then you don't need quotes: Popup Window-Ops, but if you -replace the dash with a space, then you need quotes: Popup "Window -Ops". - - -.IP "AddButtonStyle \fIbutton\fP [ \fIstate\fP ] [ \fIstyle\fP ] [-- \fI[!]flag ...\fP]" -Adds a button style to \fIbutton\fP. \fIbutton\fP can be a button -number, or one of "All," "Left," or "Right." \fIstate\fP can be -"ActiveUp," "ActiveDown" or "Inactive." If \fIstate\fP is omitted, -then the style is added to every state. If the button style and flags -are enclosed in parentheses, then multiple state definitions can be -placed on a single line. Flags for additional button styles cannot be -changed after definition. - -Buttons are drawn in the order of definition, beginning with the most -recent ButtonStyle, followed by those added with AddButtonStyle. To -clear the button style stack, change style flags, or for descriptions -of available styles and flags, see the ButtonStyle command. Examples: -.EX -ButtonStyle 1 Pixmap led.xpm -- Top Left -ButtonStyle 1 ActiveDown HGradient 8 grey \\ - black -ButtonStyle All -- UseTitleStyle -AddButtonStyle 1 ActiveUp (Pixmap a.xpm) \\ - ActiveDown (Pixmap b.xpm -- Top) -AddButtonStyle 1 Vector 4 50x30@1 70x70@0 \\ - 30x70@0 50x30@1 -.EE -Initially for this example all button states are set to a pixmap. The -second line replaces the ActiveDown state with a gradient (it -overrides the pixmap assigned to it in the line before, which assigned -the same style to every state). Then, the UseTitleStyle flag is set -for all buttons, which causes \fIfvwm\fP to draw any styles set with -TitleStyle before drawing the buttons. Finally, AddButtonStyle is -used to place additional pixmaps for both ActiveUp and ActiveDown -states and a Vector button style is drawn on top of all state. - - -.IP "AddTitleStyle [ \fIstate\fP ] [ \fIstyle\fP ] [ -- \fI[!]flag ...\fP ]" -Adds a title style to the title bar. \fIstate\fP should be one of -"ActiveUp," "ActiveDown," or "Inactive." If \fIstate\fP is omitted, -then the style is added to every state. If the style and flags are -enclosed in parentheses, then multiple state definitions can be placed -on a single line. This command is quite similar to the AddButtonStyle -command (see above). - -Title bars are drawn in the order of definition, beginning with the -most recent TitleStyle, followed by those added with AddTitleStyle. -To clear the title style stack, change style flags, or for the -descriptions of available styles and flags, see the TitleStyle and -ButtonStyle commands. - - -.IP "AddToDecor \fIdecor\fP" -Add or divert commands to the decor named \fIdecor\fP. A decor is a -name given to the set of commands which affect button styles, -title-bar styles, border styles, hilight colors, and window fonts. If -\fIdecor\fP does not exist it is created; otherwise the existing -\fIdecor\fP is modified. - -Created decors start out exactly like the default fvwm decor without -any style definitions. A given decor may be applied to a set of -windows with the UseDecor option of the Style command. Modifying an -existing decor will affect windows which are currently assigned to it. - -AddToDecor is similar in usage to the AddToMenu and AddToFunc -commands, except that menus and functions are replaced by ButtonStyle, -AddButtonStyle, TitleStyle, AddTitleStyle, BorderStyle, HilightColor -and WindowFont commands. Decors created with AddToDecor can be -manipulated with ChangeDecor, DestroyDecor, UpdateDecor, and the -UseDecor Style option. - -The following example creates a decor and style, both named -"flatness." Despite having the same name, they are distinct entities: -.EX -AddToDecor flatness - + ButtonStyle All ActiveUp (-- flat) \\ - Inactive (-- flat) - + TitleStyle -- flat - + BorderStyle -- HiddenHandles NoInset - + HilightColor white navy -Style "flatness" UseDecor flatness, \\ - Color white/grey40,HandleWidth 4 - -Style "xterm" UseStyle flatness -.EE -An existing window's decor may be reassigned with ChangeDecor, or a -Style command followed by a Recapture. The decorations of all windows -or of a specific decor can be updated with UpdateDecor (useful after -decorations are modified; changing Style options requires a Recapture -instead). A decor can be destroyed with DestroyDecor. - - -.IP "AddToFunc [ \fIname\fP [ \fItrigger\fP \fIaction\fP] ]" -Begins or add to a function definition. Here's an example: -.EX -AddToFunc Move-or-Raise "I" Raise - + "M" Move - + "D" Lower -.EE -The function name is Move-or-Raise, and could be invoked from a menu -or a mouse binding or key binding: -.EX -Mouse 1 TS A Move-or-Raise -.EE -The quoted portion of the function tells what kind of action will -trigger the command which follows it. "I" stands for Immediate, and is -executed as soon as the function is invoked. "M" stands for Motion, i.e. -if the user starts moving the mouse. "C" stands for Click, i.e., if the -user presses and releases the mouse in a short period of time -(ClickTime milliseconds). "D" stands for double-click. The action "I" -will cause an action to be performed on the button-press, if the -function is invoked with prior knowledge of which window to act on. - -The special symbols $d, $w and $0 through $9 are available in the -ComplexFunctions or Macros, or whatever you want to call them. Within -a macro, $w is expanded to the window-id (expressed in -hex, i.e. 0x10023c) of the window for which the macro was called -and $d is expanded to the current desk number. $0 -through $9 are the arguments to the macro, so if you call -.EX -Key F10 R A Function MailFunction \\ - xmh "-font fixed" -.EE -and MailFunction is - -.EX -AddToFunc MailFunction - + "I" Next ($0) Iconify -1 - + "I" Next ($0) focus - + "I" None ($0) Exec exec $0 $1 -.EE -Then the last line of the function becomes -.EX - + "I" None (xmh) Exec exec xmh -font fixed -.EE -The expansion is performed as the function is executed, so you can use the -same function with all sorts of different arguments. I could use -.EX -Key F11 R A Function MailFunction \\ - zmail "-bg pink" -.EE -in the same .fvwmrc, if I wanted. An example of using $w is: -.EX -AddToFunc PrintFunction - + "I" Raise - + "I" Exec xdpr -id $w -.EE -Note that $$ is expanded to $. - - -.IP "AddToMenu \fImenu-name\fP [ \fImenu-label\fP \fIaction\fP ]" -Begins or adds to a menu definition. Typically a menu definition looks -like this: -.EX -AddToMenu Utilities "Utilities" Title - + "Xterm" Exec exec xterm -e tcsh - + "Rxvt" Exec exec rxvt - + "Remote Logins" Popup Remote-Logins - + "Top" Exec exec rxvt -T Top -n \\ - Top -e top - + "Calculator" Exec exec xcalc - + "Xmag" Exec exec xmag - + "emacs" Exec exec xemacs - + "Mail" MailFunction \\ - xmh "-font fixed" - + "" Nop - + "Modules" Popup Module-Popup - + "" Nop - + "Exit Fvwm" Popup Quit-Verify -.EE -The menu could be invoked via -.EX -Mouse 1 R A Menu Utilities Nop -.EE -or -.EX -Mouse 1 R A Popup Utilities -.EE -There is no end-of-menu symbol. Menus do not have to be defined in a -contiguous region of the .fvwmrc file. The quoted portion in the -above examples is the menu-label, which will appear in the menu when -the user pops it up. The remaining portion is a built-in command -which should be executed if the user selects that menu item. An empty -menu-label ("") and the Nop function can be used to insert a separator -into the menu. - -Titles can be used within the menu. If you add the option "top" behind -the keyword "Title", the title will be added to the top of the menu. -If there was a title already, it is overwritten. - -.EX -AddToMenu Utilities "Tools" Title top -.EE - -All text up to the first TAB in the menu label is aligned to the -left side of the menu, all text right of the first TAB is aligned -to the right side. All other TABs are replaced by spaces. - -If the menu-label contains an ampersand ('&'), the next character -is taken as a hotkey for the menu item. Hotkeys are underlined in -the label. To get a literal '&', insert '&&'. - -If the menu-label contains a sub-string which is set off by stars, -then the text between the stars is expected to be the name of an -xpm-icon or bitmap-file to insert in the menu. To get a literal '*', -insert '**'.For example -.EX - + "Calculator*xcalc.xpm*" Exec exec xcalc -.EE -inserts a menu item labeled "calculator" with a picture of a -calculator above it. The following: -.EX - + "*xcalc.xpm*" Exec exec xcalc -.EE -Omits the "Calculator" label, but leaves the picture. - -If the menu-label contains a sub-string which is set off by percent signs, -then the text between the percent signs is expected to be the name of an -xpm-icon or bitmap-file to insert to the left of the menu label. -To get a literal '%', insert '%%'. For example -.EX - + "Calculator%xcalc.xpm%" Exec exec xcalc -.EE -inserts a menu item labeled "calculator" with a picture of a -calculator to the left. The following: -.EX - + "%xcalc.xpm%" Exec exec xcalc -.EE -Omits the "Calculator" label, but leaves the picture. The pictures -used with this feature should be small (perhaps 16x16). - -If the menu-name (not the label) contains a sub-string which is set -off by at signs ("@"), then the text between them is expected to be -the name of an xpm or bitmap file to draw along the left side of the -menu (a "side pixmap"). You will probably want to use the SidePic -option of the \fIMenuStyle\fP command instead. To get a literal '@', -insert '@@'. For example -.EX -AddToMenu "StartMenu@linux-menu.xpm@" -.EE -creates a menu with a picture in its bottom left corner. - -If the menu-name contains also a sub-string set of by '^'s, then the -text between '^'s is expected to be the name a of X11 color and the -column containing the side picture will be colorized with that -color. You can set this color for a menu style using the SideColor -option of the \fIMenuStyle\fP command. To get a literal '^', insert -'^^'. Example: -.EX -AddToMenu "StartMenu@linux-menu.xpm@^blue^" -.EE -creates a menu with a picture in its bottom left corner and colorizes -with blue the region of the menu containing the picture. - -In all the above cases, the name of the resulting menu is name specified, -stripped of the substrings between the various delimiters. - - -.IP "AnimatedMove \fIx y\fP [ \fIWarp\fP ]" - -Move a window in an animated way. Similar to Move command, below. -Options are the same, except they are required, since it doesn't make -sense to have a user move the window interactively and animatedly. If -the optional argument \fIWarp\fP is specified the pointer is warped with -the window. - - -.IP "Beep" -As might be expected, this makes the terminal beep. - - -.IP "BorderStyle [ \fIstate\fP ] [ \fIstyle\fP ] [ -- \fI[!]flag ...\fP ]" -Defines a border style for windows. \fIstate\fP can be either -"Active" or "Inactive." If \fIstate\fP is omitted, then the style is -set for both states. If the style and flags are enclosed in -parentheses, then multiple state definitions can be specified per -line. - -\fIstyle\fP is a subset of the available ButtonStyles, and can only be -TiledPixmap (uniform pixmaps which match the bevel colors work best -this way). If an "!" is prefixed to any flag, flag behavior is -negated. If \fIstyle\fP is not specified, then one can change flags -without resetting the style. - -The "HiddenHandles" flag hides the corner handle dividing lines on -windows with handles (this option has no effect for NoHandle windows). -By default, HiddenHandles is disabled. - -The "NoInset" flag supplements HiddenHandles. If given, the inner -bevel around the window frame is not drawn. If HiddenHandles is not -specified, this flag has no effect. - -To decorate the active and inactive window borders with a textured -pixmap, one might specify: -.EX -BorderStyle Active TiledPixmap marble.xpm -BorderStyle Inactive TiledPixmap granite.xpm -BorderStyle Active -- HiddenHandles NoInset -.EE -To clear the style for both states: -.EX -BorderStyle Simple -.EE -To clear for a single state: -.EX -BorderStyle Active Simple -.EE -To unset a flag for a given state: -.EX -BorderStyle Inactive -- !NoInset -.EE -Title-bar buttons can inherit the border style with the UseBorderStyle -flag (see ButtonStyle). - - -.IP "ButtonStyle \fIbutton\fP [ \fIstate\fP ] [ \fIstyle\fP ] [ -- \fI[!]flag ...\fP ]" -Sets the button style for a title-bar button. \fIbutton\fP is the -title-bar button number between 0 and 9, or one of "All," "Left," -"Right," or "Reset." Button numbering is described in the Mouse -section (see below). If the style and flags are enclosed in -parentheses, then multiple state definitions can be specified per -line. - -\fIstate\fP refers to which button state should be set. Button states -are defined as follows: "ActiveUp" and "ActiveDown" refer to the -unpressed and pressed states for buttons on active windows; while the -"Inactive" state denotes buttons on inactive windows. - -If \fIstate\fP is ActiveUp, ActiveDown, or Inactive, that particular -button state is set. If \fIstate\fP is omitted, every state is set. -Specifying a style destroys the current style (use AddButtonStyle to -avoid this). - -If \fIstyle\fP is omitted, then state-dependent flags can be set for -the primary button style without destroying the current style. -Examples (each line should be considered independent): -.EX -ButtonStyle Left -- flat -ButtonStyle All ActiveUp (-- flat) \\ - Inactive (-- flat) -.EE -The first line sets every state of the left buttons to flat, while the -second sets only the ActiveUp and Inactive states of every button to -flat (only flags are changed; the buttons' individual styles are not -changed). - -If you want to reset all buttons to their defaults: -.EX -ButtonStyle Reset -.EE -To reset the ActiveUp button state of button 1 to the default: -.EX -ButtonStyle 1 ActiveUp Default -.EE -To reset all button states of button 1 to the default of -button number 2: -.EX -ButtonStyle 1 Default 2 -.EE - -For any given button, multiple state definitions can be given on one -line by enclosing the style and flags in parentheses. If only one -definition per line is given the parentheses can be omitted. - -\fIflags\fP affect the specified \fIstate\fP. If an "!" is prefixed -to any \fIflag\fP, its behavior is negated. The available -state-dependent flags for all styles are described here (the next -ButtonStyle entry deals with state-independent flags). - -"Raised" causes a raised relief pattern to be drawn. - -"Sunk" causes a sunken relief pattern to be drawn. - -"Flat" inhibits the relief pattern from being drawn. - -"UseTitleStyle" causes the given button state to render the current -title style before rendering the button's own styles. The Raised, -Flat, and Sunk TitleStyle flags are ignored since they are redundant -in this context. - -"UseBorderStyle" causes the button to inherit the decorated -BorderStyle options. - -Raised, Sunk, and Flat are mutually exclusive, and can be specified -for the initial ButtonStyle only. UseTitleStyle and UseBorderStyle -are also mutually exclusive (both can be off however). The default is -Raised with both UseBorderStyle and UseTitleStyle left unset. - -There is an \fBimportant note\fP for the ActiveDown state. When a -button is pressed, the relief is inverted. Because of this, to obtain -a sunken ActiveDown state you must specify the opposite of the desired -relief (i.e. to obtain a pressed-in look which is raised, specify Sunk -for ActiveDown). This behavior is consistent, but may seem confusing -at first. - -Button styles are classified as non-destructive, partially destructive, -or fully destructive. Non-destructive styles do not affect the image. -Partially destructive styles can obscure some or all parts of the -underlying image (i.e. Pixmap). Fully destructive styles obscure the -entire underlying image (i.e. Solid or one of the gradient styles). -Thus, if stacking styles with AddButtonStyle (or AddTitleStyle for -title bars), use care in sequencing styles to minimize redraw. - -The available styles and their arguments now follow (depending on -compilation options, some button styles may be unavailable). - -The "Simple" style does nothing. There are no arguments, and this -style is an example of a non-destructive button style. - -The "Default" style conditionally accepts one argument: a number which -specifies the default button number to load. If the style command -given is ButtonStyle or AddButtonStyle, the argument is optional (if -given, will override the current button). If a command other than -ButtonStyle or AddButtonStyle is used, the number must be specified. - -The "Solid" style fills the button with a solid color. The relief -border color is not affected. The color should be specified as a -single argument. This style is fully destructive. - -The "Vector" style draws a line pattern. Since this is a standard -button style, the keyword "Vector" is optional. The specification is -a little cumbersome: -.EX -ButtonStyle 2 Vector 4 50x30@1 70x70@0 \\ - 30x70@0 50x30@1 -.EE -then the button 2 decoration will use a 4-point pattern consisting of -a line from (x=50,y=30) to (70,70) in the shadow color (@0), and then -to (30,70) in the shadow color, and finally to (50,30) in the -highlight color (@1). Is that too confusing? See the sample .fvwmrc -for a few examples. This style is partially destructive. - -The "VGradient" and "HGradient" styles denote gradient styles. The H -and V prefixes denote both horizontal and vertical directions. - -This style has two forms: - -.in +2 -The first form specifies a linear gradient. Arguments: total number -of colors to allocate (between 2 and 128), the initial color, and the -final color. - -The second form specifies a nonlinear gradient. Arguments: total -number of colors to allocate (between 2 and 128), then the number of -segments. For each segment, specify the starting color, percentage to -increment, then ending color. Each subsequent segment begins with the -color of the last segment. All of the percentages must add up to 100. -.in -2 - -Example: -.EX -TitleStyle VGradient 16 3 Red 20 Blue 30 \\ - Black 50 Grey -.EE -The gradient styles are fully destructive. - -The "Pixmap" style displays a pixmap. A pixmap should be specified as -an argument. For example, the following would give button 2 the same -pixmap for both states, and button 4 different pixmaps for the up, -down and inactive states. -.EX -ButtonStyle 2 Pixmap my_pixmap.xpm -ButtonStyle 4 ActiveUp (Pixmap up.xpm) \\ - ActiveDown (Pixmap down.xpm) -ButtonStyle 4 Inactive Pixmap inactive.xpm -.EE -The pixmap specification can be given as an absolute or relative -pathname (see PixmapPath). If the pixmap cannot be found, the button -style reverts to Simple. Flags specific to the Pixmap style are -"Left," "Right," "Top," and "Bottom." These can be used to justify -the pixmap (default is centered for both directions). Pixmap -transparency is used for the color "None." This style is partially -destructive. - -The "MiniIcon" style draws the window's miniature icon in the button, -which is specified with the MiniIcon option of the Style command. This -button style accepts no arguments. Example: -.EX -Style "*" MiniIcon mini-bx2.xpm -Style "xterm" MiniIcon mini-term.xpm -Style "Emacs" MiniIcon mini-doc.xpm - -ButtonStyle 1 MiniIcon -.EE - -The "TiledPixmap" style accepts a pixmap to be tiled as the button -background. One pixmap is specified as an argument. Pixmap -transparency is not used. This style is fully destructive. - - -.IP "ButtonStyle \fIbutton\fP - \fI[!]flag ...\fP" -Sets state-independent flags for the specified \fIbutton\fP. -State-independent flags affect button behavior. Each flag is -separated by a space. If an "!" is prefixed to the flag then the flag -behavior is negated. The special flag "Clear" clears any existing -flags. - -The following flags are usually used to tell fvwm which buttons should -be affected by MWM function hints. This is not done automatically -since you might have buttons bound to complex functions, for instance. - -"MWMDecorMenu" should be assigned to title bar buttons which display a -menu. The default assignment is the leftmost button. When a window -with the MWMFunctions Style option requests not to show this button, -it will be hidden. - -"MWMDecorMin" should be assigned to title bar buttons which minimize -or iconify the window. The default assignment is the second button -over from the rightmost button. When a window with the MWMFunctions -Style option requests not to show this button, it will be hidden. - -"MWMDecorMax" should be assigned to title bar buttons which maximize -the window. The default assignment is the rightmost button. When a -window with the MWMFunctions Style option requests not to show this -button, it will be hidden. - - -.IP "ChangeDecor \fIdecor\fP" -Changes the decor of a window to \fIdecor\fP. \fIdecor\fP is -"Default," or the name of a decor defined with AddToDecor. If -\fIdecor\fP is invalid, nothing occurs. If called from somewhere in a -window or its border, then that window is affected. If called from -the root window the user will be allowed to select the target window. -ChangeDecor only affects attributes which can be set using the -AddToDecor command. -.EX -ChangeDecor "CustomDecor1" -.EE - -.IP "ChangeMenuStyle \fImenustyle menu ...\fP" -Changes the menu style of "menu" to "menustyle", you may specified more -than one menu in each \fIChangeMenuStyle\fP. -.EX -ChangeMenuStyle pixmap1 Screensavers ScreenLock -.EE - -.IP "ClickTime [ \fIdelay\fP ]" -Specifies the maximum delay (in milliseconds) between a button press -and a button release for the Function built-in to consider the action -a mouse click. The default delay is 150 milliseconds. Omitting the -delay value resets the ClickTime to the default. - - -.IP "Close" -If the window accepts the delete window protocol a message is sent to -the window asking it to gracefully remove itself. If the window does -not understand the delete window protocol then the window is -destroyed. - - -.IP "ColorLimit \fIlimit\fP" -Specifies a limit on the colors used in pixmaps used by fvwm. Zero -(the default) sets no limit. Fvwm uses pixmaps for icons, -mini-icons, and pixmap borders and titles. This command limits pixmap -colors to a set of colors that starts out with common colors. The -current list contains about 60 colors and starts with white, black, -grey, green, blue, red, cyan, yellow, and magenta. The command -"ColorLimit 9" would limit pixmaps to these 9 colors. - -It makes the most sense to put this command at the front of the -.fvwmrc file. This command should be before any menu -definitions that contain mini-icons. - -Solid frame and title colors (including shadows and gradients) are not -controlled by this command. - - -.IP "ColormapFocus \fIFollowsMouse\fP|\fIFollowsFocus\fP" -By default, fvwm installs the colormap of the window that the cursor -is in. If you use ColormapFocus FollowsFocus, then the installed -colormap will be the one for the window that currently has the -keyboard focus. - - -.IP "Current (\fIconditions\fP) \fIcommand\fP" -Performs \fIcommand\fP on the current window if it satisfies all -\fIconditions\fP. Conditions include "Iconic", "!Iconic", "Visible", -"!Visible", "Sticky", "!Sticky", "Maximized", "!Maximized", -"Transient", "!Transient", "Raised", "!Raised", "CurrentDesk", -"CurrentPage", and "CurrentPageAnyDesk". In addition, the condition -may include a window name to match to. The window name may include -the wildcards * and ?. The window name, icon name, class, and -resource will be considered when attempting to find a match. The -window name can begin with ! which will prevent \fIcommand\fP if any -of the window name, icon name, class or resource match. - -Note that earlier versions of fvwm2 required the conditions to be -enclosed in brackets instead of parentheses (this is still supported -for backwards compatibility). - - -.IP "CursorMove \fIhorizontal vertical\fP" -Moves the mouse pointer by \fIhorizontal\fP pages in the X direction -and \fIvertical\fP pages in the Y direction. Either or both entries -may be negative. Both horizontal and vertical values are expressed in -percent of pages, so "CursorMove 100 100" means to move down and right -by one full page. "CursorMove 50 25" means to move right half a page -and down a quarter of a page. Alternatively, the distance can be -specified in pixels by appending a 'p' to the horizontal and/or vertical -specification. For example "CursorMove -10p -10p" means move ten -pixels up and ten pixels left. The CursorMove function should not be -called from pop-up menus. - -.IP "CursorStyle \fIcontext cursornum\fP" -Defines a new cursor for the specified context. The various contexts -are: - -.in +.5i -POSITION (XC_top_left_corner) -.in +.3i -used when initially placing windows -.in -.3i - -TITLE (XC_top_left_arrow) -.in +.3i -used in a window title-bar -.in -.3i - -DEFAULT (XC_top_left_arrow) -.in +.3i -used in windows that don't set their cursor -.in -.3i - -SYS (XC_hand2) -.in +.3i -used in one of the title-bar buttons -.in -.3i - -MOVE (XC_fleur) -.in +.3i -used when moving or resizing windows -.in -.3i - -WAIT (XC_watch) -.in +.3i -used during an EXEC builtin command -.in -.3i - -MENU (XC_sb_left_arrow) -.in +.3i -used in menus -.in -.3i - -SELECT (XC_dot) -.in +.3i -used for various builtin commands such as iconify -.in -.3i - -DESTROY (XC_pirate) -.in +.3i -used for DESTROY, CLOSE, and DELETE built-ins -.in -.3i - -TOP (XC_top_side) -.in +.3i -used in the top side-bar of a window -.in -.3i - -RIGHT (XC_right_side) -.in +.3i -used in the right side-bar of a window -.in -.3i - -BOTTOM (XC_bottom_side) -.in +.3i -used in the bottom side-bar of a window -.in -.3i - -LEFT (XC_left_side) -.in +.3i -used in the left side-bar of a window -.in -.3i - -TOP_LEFT (XC_top_left_corner) -.in +.3i -used in the top left corner of a window -.in -.3i - -TOP_RIGHT (XC_top_right_corner) -.in +.3i -used in the top right corner of a window -.in -.3i - -BOTTOM_LEFT (XC_bottom_left_corner) -.in +.3i -used in the bottom left corner of a window -.in -.3i - -BOTTOM_RIGHT (XC_bottom_right_corner) -.in +.3i -used in the bottom right corner of a window -.in -.3i -.in -.5i - -And the cursornum is the numeric value of the cursor as defined in the -include file X11/cursorfont.h. An example: -.EX -\&# make the kill cursor be XC_gumby: -CursorStyle DESTROY 56 -.EE -The defaults are shown in parenthesis above. - - -.IP "DefaultColors [ \fI foreground background\fP ]" -\fIDefaultColors\fP sets the default forground and background -colors used in miscellaneous windows created by fvwm, for example -in the geometry feedback windows during a move or resize operation. -If you don't want to change one color or the other, use - as its -color name. To revert to the builtin default colors omit both -color names. Note that the default colors are not used in menus, -window titles or icon titles. - - -.IP "DefaultFont [ \fIfontname\fP ]" -\fIDefaultFont\fP sets the default font to font \fIfontname\fP. -The default font is used by fvwm2 whenever no other font has been -specified. To reset the default font to the built in default, omit -the argument. The default font is used for menus, window titles, -icon titles as well as the geometry feedback windows during a move -or resize operation. To override the default font in a specific -context, use the \fIWindowFont\fP, \fIIconFont\fP or \fIMenuStyle\fP -commands. - - -.IP "Delete" -Sends a message to a window asking that it remove itself, frequently -causing the application to exit. - - -.IP "Desk \fIarg1\fP [ \fIarg2\fP ] [ \fImin max\fP ]" -Switches the current viewport to another desktop (workspace, room). - -The command takes 1, 2, 3, or 4 arguments. A single argument is -interpreted as a relative desk number. Two arguments are understood -as a relative and an absolute desk number. Three arguments specify -a relative desk and the minimum and maximum of the allowable range. -Four arguments specify the relative, absolute, minimum and maximum -values. (Desktop numbers can be negative.) - -If \fIarg1\fP is non zero then the next desktop number will be the -current desktop number plus \fIarg1\fP. - -If \fIarg1\fP is zero then the new desktop number will be \fIarg2\fP. -(If \fIarg2\fP is not present, then the command has no effect.) - -If \fImin\fP and \fImax\fP are given, the new desktop number will -be no smaller than min and no bigger than max. Values out of this -range are truncated (if you gave an absolute desk number) or wrapped -around (if you gave a relative desk number). - -The syntax is the same as for \fIMoveToDesk\fP, which moves a window -to a different desktop. - -The number of active desktops is determined dynamically. Only -desktops which contain windows or are currently being displayed are -active. Desktop numbers must be between 2147483647 and -2147483648 -(is that enough?). - - -.IP "DeskTopSize \fIHorizontal\fPx\fIVertical\fP" -Defines the virtual desktop size in units of the physical screen size. - - -.IP "Destroy" -Destroys an application window, which usually causes the application -to crash and burn. - - -.IP "DestroyDecor \fIdecor\fP" -Deletes the \fIdecor\fP defined with AddToDecor, so that subsequent -references to it are no longer valid. Windows using this \fIdecor\fP -revert to the default fvwm decor. The decor named "Default" cannot be -destroyed. -.EX -DestroyDecor "CustomDecor1" -.EE - - -.IP "DestroyFunc" -Deletes a function, so that subsequent references to it are no longer -valid. You can use this to change the contents of a function during an -fvwm session. The function can be rebuilt using AddToFunc. -.EX -DestroyFunc "PrintFunction" -.EE - - -.IP "DestroyMenu" -Deletes a menu, so that subsequent references to it are no longer -valid. You can use this to change the contents of a menu during an -fvwm session. The menu can be rebuilt using AddToMenu. -.EX -DestroyMenu "Utilities" -.EE - -.IP "DestroyMenuStyle \fImenustyle\fP" -Deletes the menu style named "menustyle" and changes all menus using -this style to the default style, you cannot destroy the default menu. -.EX -DestroyMenuStyle pixamp1 -.EE - -.IP "DestroyModuleConfig" -Deletes module configuration entries, so that new configuration lines -may be entered instead. You can use this to change the the way a -module runs during an fvwm session without restarting. Wildcards can -be used for portions of the name as well. -.EX -DestroyModuleConfig FvwmFormFore -DestroyModuleConfig FvwmButtons* -.EE - - -.IP "Direction \fIdirection\fP (\fIconditions\fP) \fIcommand\fP" -Performs \fIcommand\fP (typically Focus) on a window in the given -direction which satisfies all \fIconditions\fP. Conditions are the same -as for \fICurrent\fP. The \fIdirection\fP may be one of North, Northeast, -East, Southeast, South, Southwest, West and Northwest. Which window -Direction selects depends on angle and distance between the centerpoints -of the windows. Closer windows are considered a better match than -those farther away. - - -.IP "Echo \fIstring\fP" -Prints a message to stderr. Potentially useful for debugging things -in your .fvwmrc. -.EX -Echo Beginning style defs... -.EE - - -.IP "EdgeResistance \fIscrolling moving\fP" -Tells how hard it should be to change the desktop viewport by moving -the mouse over the edge of the screen and how hard it should be to -move a window over the edge of the screen. - -The first parameter tells how milliseconds the pointer must spend on -the screen edge before \fIfvwm\fP will move the viewport. This is -intended for people who use "EdgeScroll 100 100" but find themselves -accidentally flipping pages when they don't want to. - -The second parameter tells how many pixels over the edge of the screen -a window's edge must move before it actually moves partially off the -screen. By default the viewport is moved a full page in the requested -direction, but if you used \fIEdgeScroll\fP and set any values other -than zero they will be used instead. - -Note that, with "EdgeScroll 0 0", it is still possible to move or -resize windows across the edge of the current screen. By making the -first parameter to EdgeResistance 10000 this type of motion is -impossible. With EdgeResistance less than 10000 but greater than 0 -moving over pages becomes difficult but not impossible. -See also, EdgeThickness. - -.IP "EdgeScroll \fIhorizontal vertical\fP" -Specifies the percentage of a page to scroll when the cursor hits the -edge of a page. A trailing "p" changes the interpretation to mean "pixels". -If you don't want any paging or scrolling when you hit the edge of a -page include "EdgeScroll 0 0" in your .fvwmrc file, -or possibly better, set the EdgeThickness to zero. -See the EdgeThickness command. If you want whole -pages, use "EdgeScroll 100 100". Both horizontal and vertical should -be positive numbers. - -If the horizontal and vertical percentages are multiplied by 1000 then -scrolling will wrap around at the edge of the desktop. If "EdgeScroll -100000 100000" is used \fIfvwm\fP will scroll by whole pages, wrapping -around at the edge of the desktop. - -.IP "EdgeThickness \fI0\fP|\fI1\fP|\fI2\fP" -This is the width or height of the invisible window that fvwm2 creates -on the edges of the screen that are used for the edgescrolling feature. - -A value of zero completely disables mouse edge scrolling, even while -dragging a window. - -1 gives the smallest pan frames, which seem to work best except on -some servers. - -2 is the default. - -Pan frames of 1 or 2 pixels can sometimes be confusing, for example, -if you drag a window over the edge of the screen, so that it stradles -aa pan frame, clicks on the window, near the edge of the screen are -treated as clicks on the root window. - - -.IP "Emulate \fIfvwm\fP|\fImwm\fP|\fIwin\fP" -This command affects how miscellaneous things are done by fvwm. -For example where the move/resize feedback window appears depends -on this command. To have more MWM- or WIN-like behavior you can call -Emulate with "MWM" or "WIN" as its argument. - - -.IP "Exec \fIcommand\fP" -Executes \fIcommand\fP. You should not use an ampersand ``&'' at the -end of the command. You probably want to use an additional ``exec'' at -the beginning of \fIcommand\fP. Without that, the shell that fvwm -invokes to run your command will stay until the command exits. In -effect, you'll have twice as many processes running as you need. -Note that some shells are smart enough to avoid this, but it never hurts -to include the ``exec'' anyway. - -The following example binds function key F1 in the root window, with -no modifiers, to the exec function. The program rxvt will be started -with an assortment of options. -.EX -Key F1 R N Exec exec rxvt -fg yellow -bg blue \\ - -e /bin/tcsh -.EE - -Note that this function doesn't wait for \fIcommand\fP to complete, so -things like: -.EX -Exec "echo AddToMenu ... > /tmp/file" -Read /tmp/file -.EE -won't work reliably. - -.IP "ExecUseShell [ \fIshell\fP ]" -Makes the Exec command use the specified shell, or the value of the -$SHELL environment variable if no shell is specified, instead of the -default Bourne shell (/bin/sh). -.EX -ExecUseShell -ExecUseShell /usr/local/bin/tcsh -.EE - - -.IP "FlipFocus" -Executes a \fIFocus\fP command as if the user had used the pointer to -select the window. This command alters the order of the windowlist in -the same way as clicking in a window to focus, i.e. the target window is -removed from the windowlist and placed at the start. This command is -recommended for use with the \fIDirection\fP command and in the function -invoked from \fIWindowList\fP. - - -.IP "Focus" -Moves the viewport or window as needed to make the selected window -visible. Sets the keyboard focus to the selected window. Does not -automatically raise the window. Does not warp the pointer into -the selected window (see WarpToWindow function). Does not de-iconify. -This command does not alter the order of the windowlist, it rotates the -windowlist around so that the target window is at the start. - -To raise and warp a pointer together with Focus or FlipFocus, use a function: -.EX -AddToFunc SelectWindow -+ I Focus -+ I Raise -+ I WarpToWindow 50 8p -.EE - - -.IP "Function \fI\FunctionName\\fP" -Used to bind a previously defined function to a key or mouse button. - -The following example binds mouse button 1 to a function called -"Move-or-Raise", whose definition was provided as an example earlier -in this man page. After performing this binding \fIfvwm\fP will -execute to move-or-raise function whenever button 1 is pressed in a -window title-bar. -.EX -Mouse 1 T A Function Move-or-Raise -.EE -The keyword "Function" may be omitted if "FunctionName" does not -coincide with an fvwm built-in function name - - -.IP "GlobalOpts [ \fIoptions\fP ]" -This is a TEMPORARY command used to set some global options which will -later be handled as Style parms (or options to Style parms). It -currently handles the following: -SmartPlacementIsReallySmart/SmartPlacementIsNormal, -ClickToFocusDoesntPassClick/ClickToFocusPassesClick, -ClickToFocusDoesntRaise/ClickToFocusRaises, -MouseFocusClickDoesntRaise/MouseFocusClickRaises, -CaptureHonorsStartsOnPage/CaptureIgnoresStartsOnPage, -RecaptureHonorsStartsOnPage/RecaptureIgnoresStartsOnPage, -ActivePlacementHonorsStartsOnPage/ActivePlacementIgnoresStartsOnPage, -NoStipledTitles/StipledTitles - -Example: -.EX -GlobalOpts ClickToFocusDoesntPassClick, \\ - ClickToFocusDoesntRaise -.EE - -RecaptureHonorsStartsOnPage causes a window to be placed according to, or -revert to, the StartsOnPage desk and page specification on Restart or -Recapture. RecaptureIgnoresStartsOnPage causes fvwm to respect the current -window position on Restart or Recapture. The default is -RecaptureIgnoresStartsOnPage. - -CaptureHonorsStartsOnPage causes the initial capture (of an already -existing window) at startup to place the window according to the -StartsOnPage desk and page specification. CaptureIgnoresStartsOnPage -causes fvwm to ignore these settings (including StartsOnDesk) on -initial capture. The default is CaptureHonorsStartsOnPage. - -ActivePlacementIgnoresStartsOnPage suppresses StartsOnPage or StartsOnDesk -placement in the event that both ActivePlacement and SkipMapping are in -effect when a window is created. This prevents you from interactively -placing a window and then wondering where it disappeared to, because it got -placed on a different desk or page. ActivePlacementHonorsStartsOnPage -allows this to happen anyway. The option has no effect if SkipMapping is -not in effect, because fvwm will switch to the proper desk/page to perform -interactive placement. The default is ActivePlacementHonorsStartsOnPage, -which matches the way StartsOnDesk handled the situation. - -.IP "GotoPage x y" -Moves the desktop viewport to page (x,y). The upper left page is -(0,0), the upper right is (M,0), where M is one less than the current -number of horizontal pages specified in the DeskTopSize command. The -lower left page is (0,N), and the lower right page is (M,N), where N -is the desktop's vertical size as specified in the DeskTopSize -command. The GotoPage function should not be used in a pop-up menu. - - -.IP "HilightColor \fItextcolor backgroundcolor\fP" -Specifies the text and background colors for the decorations on the -window which currently has the keyboard focus. - - -.IP "IconFont [ \fIfontname\fP ]" -Makes \fIfvwm\fP use font \fIfontname\fP for icon labels. To reset -this font to the default font (see \fIDefaultFont\fP) you may omit -\fIfontname\fP. - - -.IP "Iconify [ \fIvalue\fP ]" -Iconifies a window if it is not already iconified or de-iconifies it -if it is already iconified. If the optional argument \fIvalue\fP is -positive only iconification will be allowed. If the optional -argument is negative only de-iconification will be allowed. - - -.IP "IconPath \fIpath\fP" -Specifies a colon separated list of full path names of directories -where bitmap (monochrome) icons can be found. Each path should start -with a slash. Environment variables can be used here as well (i.e. -$HOME or ${HOME}). - -Note: if the FvwmM4 is used to parse your rc files, then \fIm4\fP may -want to mangle the word "include" which will frequently show up in the -IconPath or PixmapPath command. To fix this add undefine(`include') -prior to the IconPath command, or better use the '-m4-prefix' option -to force all m4 directives to have a prefix of "m4_" (see the -\fIFvwmM4\fP man page). - - -.IP "ImagePath \fIpath\fP" -Specifies a colon separated list of directories in which to search -for images (both monochrome and pixmap). - -\fINOTE\fP: ImagePath makes obsolete IconPath and PixmapPath commands in the -next fvwm versions. In this version all of the three commands are allowed. - -The ImagePath may contain environment variables such as $HOME (or -${HOME}). Further, a '+' in the path is expanded to the previous -value of the path, allowing easy appending or prepending to the path. - -For example: -.EX -ImagePath $HOME/icons:+:__projectroot__/include/bitmaps -.EE - - -.IP "Key \fIkeyname Context Modifiers Function\fP" -Binds a keyboard key to a specified \fIfvwm\fP built-in function, or -removes the binding if \fIFunction\fP is '-'. Definition is the same -as for a mouse binding except that the mouse button number is replaced -with a key name. The \fIkeyname\fP is one of the entries from -__projectroot__/include/X11/keysymdef.h, with the leading XK_ omitted. The -\fIContext\fP and \fIModifiers\fP fields are defined as in the Mouse -binding. However, when you press a key the context window is the -window that has the keyboard focus. That is not necessarily the -same as the window the pointer is over (with SloppyFocus or -ClickToFocus). - -The following example binds the built in window list to pop up when -Alt-Ctrl-Shift-F11 is hit, no matter where the mouse pointer is: -.EX -Key F11 A SCM WindowList -.EE - -Binding a key to a title-bar button will not cause that button to -appear unless a mouse binding also exists. - - -.IP "KillModule \fIname\fP" -Causes the module which was invoked with name \fIname\fP to be killed. -\fIname\fP may include wild-cards. - - -.IP "Lower" -Allows the user to lower a window. - - -.IP "Maximize [ \fI horizontal vertical\fP ]" -Without its optional arguments Maximize causes the window to -alternately switch from a full-screen size to its normal size. - -With the optional arguments horizontal and vertical, which are -expressed as percentage of a full screen, the user can control the new -size of the window. If horizontal is greater than 0 then the -horizontal dimension of the window will be set to -horizontal*screen_width/100. The vertical resizing is similar. For -example, the following will add a title-bar button to switch a window -to the full vertical size of the screen: -.EX -Mouse 0 4 A Maximize 0 100 -.EE -The following causes windows to be stretched to the full width: -.EX -Mouse 0 4 A Maximize 100 0 -.EE -This makes a window that is half the screen size in each direction: -.EX -Mouse 0 4 A Maximize 50 50 -.EE -Values larger than 100 can be used with caution. - -If the letter "p" is appended to each coordinate (horizontal and/or -vertical), then the scroll amount will be measured in pixels. - - -.IP "Menu \fImenu-name\fP [ \fIposition\fP ] [ \fIdouble-click-action\fP ]" -Causes a previously defined menu to be popped up in a "sticky" manner. -That is, if the user invokes the menu with a click action instead of a -drag action, the menu will stay up. The command -\fIdouble-click-action\fP will be invoked if the user double-clicks -(or hits the key rapidly twice if the menu is bound to a key) when -bringing the menu up. - -Several other commands affect menu operation. See \fIMenuStyle\fP -and \fISetAnimation\fP. When in a menu, keyboard -shortcuts work as expected. Cursor keystrokes are also allowed. -Specifically, Cursor-Down, Ctrl-N, and Ctrl-J all move to the next -item; Cursor-Up, Ctrl-P, and Ctrl-K all move to the prior item; -Cursor-Left and Ctrl-B return to the prior menu; Cursor-Right and -Ctrl-F popup the next menu; Ctrl-Cursor-Up and Ctrl-Cursor-Down move -up and down five items, respectively; Shift-Cursor-Up and -Shift-Cursor-Down move to the first and last items, respectively; Enter -executes the current item; Escape exits the current sequence of menus. - -The pointer will be warped to where it was when the menu was invoked if -it was both invoked and terminated with a keystroke. - -The \fIposition\fP arguments allow to place the menu somewhere on the -screen, for example centered on the visible screen or above a title -bar. Basically it works like this: you specify a \fIcontext-rectangle\fP -and an offset to this rectangle by which the upper left corner of the menu -is moved from the upper left corner of the rectangle. The \fIposition\fP -arguments consist of several parts: -.EX -[ [context-rectangle] x y ] [ special-options ] -.EE -The \fIcontext-rectangle\fP can be one of: - -.in +.5i -Root -.in +.3i -the root window. -.in -.3i -Mouse -.in +.3i -a 1x1 rectangle at the mouse position. -.in -.3i -Window -.in +.3i -the window with the focus. -.in -.3i -Interior -.in +.3i -the inside of the focused window. -.in -.3i -Title -.in +.3i -the title of the focused window or icon. -.in -.3i -Button -.in +.3i -button #n of the focused window. -.in -.3i -Icon -.in +.3i -the focused icon. -.in -.3i -Menu -.in +.3i -the current menu. -.in -.3i -Item -.in +.3i -the current menu item. -.in -.3i -Context -.in +.3i -the current window, menu or icon. -.in -.3i -This -.in +.3i -whatever widget the pointer is on (e.g. a corner of a window or the root window). -.in -.3i -Rectangle -.in +.3i -the rectangle defined by <\fIgeometry\fP> in X geometry format. Width and height default to 1 if omitted. -.in -.3i -.in -.5i - -If the context-rectangle is omitted "Mouse" is the default. -Note that not all of these make sense under all circumstances -(e.g. "Icon" if the pointer is on a menu). - -The offset values \fIx\fP and \fIy\fP specify how far the menu is -moved from it's default position. By default, the numeric value given -is interpreted as a percentage of the context rectangle's width (height), -but with a trailing "m" the menu's width (height) is used instead. -Furthermore a trailing "p" changes the interpretation to mean "pixels". - -Instead of a single value you can use a list of values. All additional -numbers after the first one are separated from threir predecessor but -their sign. Do not use any other separators. - -If x or y are prefixed with 'o' where is an integer, the -menu and the rectangle will be moved to overlap at the specified position -before any other offsets are applied. The menu and the rectangle will be -placed so that the pixel at percent of the rectangle's width/height -is right over the pixel at percent of the menu's width/height. -So 'o0' means that the top/left borders of the menu and the rectangle -overlap, with 'o100' it's the bottom/right borders and if you use 'o50' -they are centered upon each other (try it and you will see it is much -simpler than this description). The default is 'o0'. The prefix -'o' is an abbreviation for '+-m'. - -A prefix of 'c' is equivalent of 'o50'. Examples: - -.EX -\&# window list in the middle of the screen -WindowList Root c c - -\&# menu to the left of a window -Menu name window -100m c+0 - -\&# popup menu 8 pixels above the mouse pointer -Popup name mouse c -100m-8p - -\&# somewhere on the screen -Menu name rectangle 512x384+1+1 +0 +0 - -\&# centered vertially around a menu item -AddToMenu foobar-menu - + "first item" Nop - + "special item" Popup "another menu" item \\ - +100 c - + "last item" Nop - -\&# above the first menu item -AddToMenu foobar-menu - + "first item" Popup "another menu" item +0 -100m -.EE -Note that you can put a submenu far off the current menu so you could -not reach it with the mouse without leaving the menu. If the pointer -leaves the current menu in the general direction of the submenu the -menu will stay up. - -The \fIspecial-options\fP: - -.in +.5i -The "animated" and "mwm" or "win" meny styles may move a menu somewhere -else on the screen. If you do not want this you can add \fIFixed\fP -as an option. This might happen for example if you want the menu always -in the top right corner of the screen. - -Where do you want a submenu to appear when you click on it's menu item? -The default is to place the title under the cursor, but if you want it -where the position arguments say, use the \fISelectInPlace\fP option. -If you want the pointer on the title of the menu, use \fISelectWarp\fP -too. - -The pointer is warped to the title of a submenu whenever the pointer -would be on an item when the submenu is popped up ("fvwm" menu style) or -never warped to thetitle at all ("mwm" or "win" menu styles). You can -force (forbid) warping whenever the submenu is opened with the -\fIWarpTitle\fP (\fINoWarp\fP) option. - -Note that the \fIspecial-options\fP do work with a normal menu that has -no other position arguments. -.in -.5i - -.IP "MenuStyle \fIstylename options\fP" -Sets a new menu style or changes a previously defined style. -The \fIstylename\fP is the style name; if it contains spaces or tabs it -has to be quoted. The name "*" is reserved for the default menu style. -The default menu style is used for every menu-like object (e.g. the -window created by the \fIWindowList\fP command) that had not be assigned -a style using the \fIChangeMenuStyle\fP. See also \fIDestroyMenuStyle\fP. -When using monochrome color options are ignored. - -\fIoptions\fP is a comma separated list containing some of the -keywords FVWM/MWM/WIN, -Foreground, -Background, -Greyed, -HilightBack/HilightBackOff, -ActiveFore/ActiveForeOff, -Hilight3DThick/Hilight3DThin/Hilight3DOff, -Animation/AnimationOff, -Font, -MenuFace, -PopupDelay, -PopupOffset, -TitleWarp/TitleWarpOff, -TitleUnderlines0/TitleUnderlines1/TitleUnderlines2, -SeparatorsLong/SeparatorsShort, -TrianglesSolid/TrianglesRelief, -PopupImmediately/PopupDelayed, -DoubleClickTime, -SidePic, -SideColor. - -In the above list some options are listed as option pairs or triples -with a / in between. These options exclude each other. - -\fIFVWM\fP, \fIMWM\fP, \fIWIN\fP reset all options to the style with -the same name in former versions of fvwm2. The default for new menu -styles is FVWM style. These options override all others except -Foreground, Background, Greyed, HilightBack, HilightFore and -PopupDelay, so they should be used only as the first option -specified for a menu style or to reset the style to defined bahavior. -The same effect can be created by setting all the other options one -by one. - -\fIMWM\fP and \fIWIN\fP style menus popup sub-menus automatically. -WIN menus indicate the current menu item by changing the -background to dark. \fIFVWM\fP sub-menus overlap the parent menu, -MWM and WIN style menus never overlap the parent menu. - -\fIFVWM\fP style is equivalent to HilightBackOff, Hilight3DThin, -ActiveForeOff, AnimationOff, Font, MenuFace, PopupOffset 0 67, TitleWarp, -TitleUnderlines1, SeparatorsShort, TriangleRelief, PopupDelayed. - -\fIMWM\fP style is equivalent to HilightBackOff, Hilight3DThick, -ActiveForeOff, AnimationOff, Font, MenuFace, PopupOffset -3 100, -TitleWarpOff, TitleUnderlines2, SeparatorsLong, TriangleRelief, -PopupImmediately. - -\fIWIN\fP style is equivalent to HilightBack, Hilight3DOff, -ActiveForeOff, AnimationOff, Font, MenuFace, PopupOffset -5 100, -TitleWarpOff, TitleUnderlines1, SeparatorsShort, TriangleSolid, -PopupImmediately. - -\fIForeground\fP and \fIBackground\fP may have a color name as an -argument. This color is used for menu text or the menu's background. -You can omit the color name to reset these colors to the built in default. - -\fIGreyed\fP may have a color name as an argument. This color is the -one used to draw a menu-selection which is prohibited (or not -recommended) by the mwm-hints which an application has specified. -If the color is omitted the color of "greyed" menu entries is based -on the background color of the menu. - -\fIHilightBack\fP and \fIHilightBackOff\fP switch hilighting the background -of the selected menu item on and off. A specific background color -may be used by providing the color name as an argument to -\fIHilightBack\fP. If you use this option without an argument the -color is based on the menu's background color. - -\fIActiveFore\fP and \fIActiveForeOff\fP switch hilighting the foreground -of the selected menu item on and off. A specific foreground color -may be used by providing the color name as an argument to -ActiveFore. Omitting the color name has the same effet as -using ActiveForeOff. - -\fIHilight3DThick\fP, \fIHilight3DThin\fP and \fIHilight3DOff\fP -determine if the selected menu item is hilighted with a 3D relief. -Thick reliefs are two pixels wide, thin reliefs are one pixel wide. - -\fIAnimation\fP and \fIAnimationOff\fP turn menu animation on or off. -When animation is on, sub-menus that don't fit on the screen cause -the parent menu to be shifted to the left so the sub-menu can be seen. - -\fIFont\fP takes a font name as an argument. If a font by this name -exists it is used for the text of all menu items. If it does not -exist or if the name is left blank the built in default is used. - -\fIMenuFace\fP enforces a fancy background upon the menus. You can -use the same options for MenuFace as for ButtonStyle plus DGradient, -(top-left to down-right) and BGradient (down-left to top-right). See -\fIButtonStyle\fP for more info. If you use MenuFace without arguments -the style is reverted back to normal. - -Some examples of MenuFaces are: - -.EX -MenuFace DGradient 128 2 lightgrey 50 blue 50 white -MenuFace TiledPixmap texture10.xpm -MenuFace HGradient 128 2 Red 40 Maroon 60 White -MenuFace Solid Maroon -.EE - -If you encounter performance problems with gradient backgrounds -you can try one or all of the following: - -Turn Hilighting of the active menu item other than forground color -off: - -.EX -MenuStyle Hilight3DOff, HilightBackOff -MenuStyle ActiveFore -.EE - -Make sure submenus do not overlap the parent menu. This can prevent -menus being redrawn every time a submenu pops up or down. - -.EX -MenuStyle PopupOffset 1 100 -.EE - -Run you X server with backing storage. If your Xserver is started -with the -bs option, turn it off. If not try the -wm option. - -.EX -startx -- -wm -.EE - -You may have to adapt this example to your system (e.g. if you -use xinit to start X). - -\fIPopupDelay\fP requires one numeric argument. This value is the -delay in milliseconds before a sub-menu is popped up when the -pointer moves over a menu item that has a sub-menu. If the value -is zero no automatical pop up is done. If the argument is omitted -the built in default is used. Note that the popup delay has no -effect if the \fIPopupImmediately\fP option is used since sub-menus pop -up immediately then. The PopupDelay option should only be applied to the -default style ('*') since it is a global setting and affects all -menus. - -\fIPopupImmediately\fP makes menu items with sub menus pop up it up as -soon as the pointer enters the item. The PopupDelay is ignored then. -If \fIPopupDelayed\fP is used fvwm2 looks at the \fIPopupDelay\fP option -if or when this automatic popup happens. - -\fIPopupOffset\fP requires two integer arguments. Both values affect -where sub-menus are placed relative to the parent menu. If both -values are zero, the left edge of the sub-menu overlaps the left edge -of the parent menu. If the first value is non-zero the sub-menu is -shifted that many pixels to the right (or left if negative). If the -second value is non-zero the menu is moved by that many percent of -the parent menu's width to the right or left. - -\fITitleWarp\fP and \fITitleWarpOff\fP affect if the pointer warps to -the menu title when a sub-menu is opened or not. Not that regardless of -this setting the pointer will not be warped if the menu does not pop up -under the pointer. - -\fITitleUnderlines0\fP, \fITitleUnderlines1\fP and \fITitleUnderlines2\fP -specify how many lines are drawn below a menu title. - -\fISeparatorsLong\fP and \fISeparatorsShort\fP set the length of -menu separators. Long separators run from the left edge all the -way to the right edge. Short separators leave a few pixels to -the edges of the menu. - -\fITrianglesSolid\fP and \fITrianglesRelief\fP affect how the -small triangles for sub-menus is drawn. Solid triangles are -filled with a color while relief triangles are hollow. - -\fIDoubleClickTime\fP requires one numeric argument. This value is the -time in milliseconds between two mouse clicks in a menu to be -considered as a double click. The default is 450 milliseconds. -If the argument is omitted the doucle click time is reset to this -default. The DoubleClickTime option should only be applied to the -default style ('*') since it is a global setting and affects all -menus. - -\fISidePic\fP takes the name of an xpm or bitmap file as an argument. -The picture is drawn along the left side of the menu. The SidePic -option can be overridden by a menu specific side pixmap (see -\fIAddToMenu\fP). If the file name is omitted an existing side -pixmap is remove from the menu style. - -\fISideColor\fP takes the name of an X11 color as an argument. This -color is used to colorize the column containing the side picture -(see above). The SideColor option can be overridden by a menu -specific side color (see \fIAddToMenu\fP). If the color name is -omitted the side color option is switched off. - -Examples: - -.EX -MenuStyle * mwm -MenuStyle * Foreground Black, Background gray40 -MenuStyle * Greyed gray70, ActiveFore White -MenuStyle * HilightBackOff, Hilight3DOff -MenuStyle * Font lucidasanstypewriter-14 -MenuStyle * MenuFace DGradient 64 darkgray MidnightBlue - -MenuStyle gred mwm -MenuStyle gred Foreground Yellow, Background Maroon -MenuStyle gred Greyed Red, ActiveFore Red -MenuStyle gred HilightBackOff, Hilight3DOff -MenuStyle gred Font lucidasanstypewriter-12 -MenuStyle gred MenuFace DGradient 64 Red Black -.EE - -Note that all style options could be placed on a single line for each -style name. - - -.IP "MenuStyle \fIforecolor backcolor shadecolor font style\fP [ \fIanim\fP ]" -This is the old syntax of the MenuStyle command. It is obsolete and -may be removed in the future. Please use the new syntax as described -above. - -Sets the menu style. When using monochrome the colors are ignored. -The shade-color is the one used to draw a menu-selection which is -prohibited (or not recommended) by the mwm-hints which an application -has specified. The style option is either "fvwm" "mwm" or "win", -which changes the appearance and operation of the menus -and where the feedback window appears during resizes and moves. - -"mwm" and "win" style menus popup sub-menus automatically. -"win" menus indicate the current menu item by changing the -background to black. -"fvwm" sub-menus overlap the parent menu, "mwm" and "win" style menus -never overlap the parent menu. -"mwm" resize and move feedback windows are in the center of the -screen, instead of the upper left corner. - -The "anim" option is either "anim" or blank. When this option -is "anim", sub-menus that don't fit on the screen cause the parent menu -to be shifted to the left so the sub-menu can be seen. - -See also \fISetAnimation\fP command. - -.IP "Module \fIModuleName\fP" -Specifies a module which should be spawned during initialization. At -the current time the available modules (included with fvwm) are -FvwmAnimate (fancy animation of (de)iconification) FvwmAudio (makes -sounds to go with window manager actions), FvwmAuto -(an auto raise module), FvwmBacker (to change the background when you -change desktops), FvwmBanner (to display a spiffy XPM), FvwmButtons -(brings up a customizable tool bar), FvwmCpp (to preprocess your .fvwmrc -with cpp), FvwmEvent (trigger various actions by events), FvwmForm -(to bring up dialogs), FvwmIconBox (like the mwm IconBox), FvwmIconMan -(like the twm icon manager), FvwmIdent (to get window info), FvwmM4 -(to preprocess your .fvwmrc with m4), FvwmPager (a mini version of -the desktop), FvwmSave (saves the desktop state in .xinitrc style), -FvwmSaveDesk (saves the desktop state in fvwm commands), FvwmScroll -(puts scrollbars on any window), FvwmTalk (to interactively run fvwm -commands), and FvwmWinList (a window list), FvwmAnimate (produces -animation effects when a window is iconified or deiconifed). -.\" Note: The "Optional Module Name" description is missing. -These modules have their own man pages. There are other modules out -on there as well. - -Modules can be short lived transient programs or, like FvwmButtons, -can remain for the duration of the X session. Modules will be -terminated by the window manager prior to restarts and quits, if -possible. See the introductory section on modules. The keyword -"module" may be omitted if \fIModuleName\fP is distinct from all -built-in and function names. - - -.IP "ModulePath" -Specifies a colon separated list of paths for \fIfvwm\fP to search -when looking for a module to load. Individual directories do not need -trailing slashes. Environment variables can be used here as well (i.e. -$HOME or ${HOME}). The builtin module path is available via the -environment variable $FVWM_MODULEDIR. - - -.IP "Mouse \fIButton Context Modifiers Function\fP" -Defines a mouse binding, or removes the binding if \fIFunction\fP is -'-'. \fIButton\fP is the mouse button number. If \fIButton\fP is -zero then any button will perform the specified function. -\fIContext\fP describes where the binding applies. Valid contexts are -R for the root window, W for an application window, T for a window -title bar, S for a window side, top, or bottom bar, F for a window -frame (the corners), I for an Icon window, or 0 through 9 for -title-bar buttons, or any combination of these letters. A is for any -context except for title-bar buttons. For instance, a context of FST -will apply when the mouse is anywhere in a window's border except the -title-bar buttons. - -\fIModifiers\fP is any combination of N for no modifiers, C for -control, S for shift, M for Meta, or A for any modifier. For example, -a modifier of SM will apply when both the Meta and Shift keys are -down. X11 modifiers mod1 through mod5 are represented as the digits -1 through 5. - -\fIFunction\fP is one of \fIfvwm\fP's built-in functions. - -The title bar buttons are numbered with odd numbered buttons on the -left side of the title bar and even numbers on the right. -Smaller-numbered buttons are displayed toward the outside of the -window while larger-numbered buttons appear toward the middle of the -window (0 is short for 10). In summary, the buttons are numbered: -.EX -1 3 5 7 9 0 8 6 4 2 -.EE -The highest odd numbered button which has an action bound to it -determines the number of buttons drawn on the left side of the title -bar. The highest even number determines the number or right side -buttons which are drawn. Actions can be bound to either mouse buttons -or keyboard keys. - - -.IP "Move [ \fIx y\fP [ \fIWarp\fP ] ]" -Allows the user to move a window. If called from somewhere in a -window or its border, then that window will be moved. If called from -the root window then the user will be allowed to select the target -window. If the optional argument \fIWarp\fP is specified the pointer is warped -with the window. - -The operation can be aborted with Escape or by pressing any mouse button -(except button 1 which confirms the move). - -If the optional arguments x and y are provided, then the window will -be moved immediately without user interaction. Each argument can -specify an absolute or relative position from either the left (top) or -right (bottom) of the screen. By default, the numeric value given is -interpreted as a percentage of the screen width (height), but a trailing -"p" changes the interpretation to mean "pixels". - -Simple Examples: -.EX -\&# Interactive move -Mouse 1 T A Move -\&# Move window so top left is at (10%,10%) -Mouse 2 T A Move 10 10 -\&# Move top left to (10pixels,10pixels) -Mouse 3 T A Move 10p 10p -.EE - -More complex examples (these can be bound as actions to keystrokes, -etc.; only the command is shown, though): -.EX -\&# Move window so bottom right is at bottom -\&# right of screen -Move -0 -0 - -\&# Move window 5% to the right, and to the -\&# middle vertically -Move w+5 50 - -\&# Move window up 10 pixels, and so left edge -\&# is at x=40 pixels -Move 40p w-10p -.EE - -See also the "AnimatedMove" command, above. - - -.IP "MoveToDesk \fIarg1\fP [ \fIarg2\fP ] [ \fImin max\fP ]" -Moves the selected window to another desktop (workspace, room). - -The arguments are the same as for the \fIDesk\fP command. MoveToDesk -is a replacement for the old WindowsDesk command, which can no longer -be used. - - -.IP "MoveToPage [ \fIx y\fP ]" -Moves the selected window to another page (x,y). The upper left page is -(0,0), the upper right is (M,0), where M is one less than the current -number of horizontal pages specified in the DeskTopSize command. The -lower left page is (0,N), and the lower right page is (M,N), where N -is the desktop's vertical size as specified in the DeskTopSize -command. If \fIx\fP and \fIy\fP are not given, the window is moved to -the current page (a window that has the focus but is off-screen can -be retrieved with this). - - -.IP "Next (\fIconditions\fP) \fIcommand\fP" -Performs \fIcommand\fP (typically Focus) on the next window which -satisfies all \fIconditions\fP. Conditions are the same as for \fICurrent\fP -with the addition of CirculateHit which overrides the CirculateSkip style -attribute and CirculateHitIcon which overrides the CirculateSkipIcon style -attribute for iconified windows. - - -.IP "None (\fIconditions\fP) \fIcommand\fP" -Performs \fIcommand\fP if no window which satisfies all -\fIconditions\fP exists. Conditions are the same as for \fINext\fP. - - -.IP "Nop" -Does nothing. This is used to insert a blank line or separator in a -menu. If the menu item specification is Nop " ", then a blank line is -inserted. If it looks like Nop "", then a separator line is inserted. -Can also be used as the double-click action for Menu. - - -.IP "OpaqueMoveSize \fIpercentage\fP" -Tells \fIfvwm\fP the maximum size window with which opaque window -movement should be used. The percentage is percent of the total -screen area. With "OpaqueMoveSize 0" all windows will be moved using the -traditional rubber-band outline. With "OpaqueMoveSize 100" all windows -will be move as solid windows. The default is "OpaqueMoveSize 5", which -allows small windows to be moved in an opaque manner but large windows -are moved as rubber-bands. - - -.IP "PipeRead \fIcmd option\fP" -Causes fvwm to read commands output from the program named -\fIcmd\fP. Useful for building up dynamic menu entries based on a -directories contents, for example. - - -.IP "PixmapPath \fIpath\fP" -Specifies a colon separated list of full path names of directories -where pixmap (color) icons can be found. Each path should start with -a slash. Environment variables can be used here as well (i.e. $HOME -or ${HOME}). - - -.IP "Popup \fIPopupName\fP [ \fIposition\fP ] [ \fIdefault-action\fP ]" -This built-in has two purposes: to bind a menu to a key or mouse -button, and to bind a sub-menu into a menu. The formats for the two -purposes differ slightly. The \fIposition\fP arguments are the same -as for \fIMenu\fP. The command \fIdefault-action\fP will be invoked -if the user clicks a button to invoke the menu and releases it -immediately again (or hits the key rapidly twice if the menu is bound -to a key). - -To bind a previously defined pop-up menu to a key or mouse button: -.sp -.in +.25i -The following example binds mouse buttons 2 and 3 to a pop-up called -"Window Ops". The menu will pop up if the buttons 2 or 3 are pressed -in the window frame, side-bar, or title-bar, with no modifiers (none -of shift, control, or meta). -.EX -Mouse 2 FST N Popup "Window Ops" -Mouse 3 FST N Popup "Window Ops" -.EE -Pop-ups can be bound to keys through the use of the Key built in. -Pop-ups can be operated without using the mouse by binding to keys and -operating via the up arrow, down arrow, and enter keys. -.in -.25i -.sp -To bind a previously defined pop-up menu to another menu, for use as a -sub-menu: -.sp -.in +.25i -The following example defines a sub menu, "Quit-Verify" and binds it into a -main menu, called "RootMenu": -.EX -AddToMenu Quit-Verify - + "Really Quit Fvwm?" Title - + "Yes, Really Quit" Quit - + "Restart Fvwm2" Restart fvwm2 - + "Restart Fvwm 1.xx" Restart fvwm - + "" Nop - + "No, Don't Quit" Nop - -AddToMenu RootMenu "Root Menu" Title - + "Open XTerm Window" Popup NewWindowMenu - + "Login as Root" Exec exec xterm \\ - -fg green -T Root \\ - -n Root -e su - - + "Login as Anyone" Popup AnyoneMenu - + "Remote Hosts" Popup HostMenu - + "" Nop - + "X utilities" Popup Xutils - + "" Nop - + "Fvwm Modules" Popup Module-Popup - + "Fvwm Window Ops" Popup Window-Ops - + "" Nop - + "Previous Focus" Prev (*) Focus - + "Next Focus" Next (*) Focus - + "" Nop - + "Refresh screen" Refresh - + "Recapture screen" Recapture - + "" Nop - + "Reset X defaults" Exec xrdb -load \\ - $HOME/.Xdefaults - + "" Nop - + "" Nop - + "Quit" Popup Quit-Verify -.EE -.in -.25i -.sp -Popup differs from Menu in that pop-ups do not stay up if the user -simply clicks. These are Twm style popup-menus, which are a little -hard on the wrist. Menu provides Motif or Microsoft-Windows style -menus which will stay up on a click action. See menu for an explanation -of the interactive behaviour of menus. - - -.IP "Prev (\fIconditions\fP) \fIcommand\fP" -Performs \fIcommand\fP (typically Focus) on the previous window which -satisfies all \fIconditions\fP. Conditions are the same as for \fINext\fP. - - -.IP "Quit" -Exits fvwm, generally causing X to exit too. - - -.IP "QuitScreen" -Causes fvwm to stop managing the screen on which the command was issued. - - -.IP "Raise" -Allows the user to raise a window. - - -.IP "RaiseLower" -Alternately raises and lowers a window. - - -.IP "Read \fIfilename\fP [ \fIoption\fP ]" -Causes fvwm to read commands from the file named \fIfilename\fP. -If the option following the filename is "Quiet", no message is -produced if the file is not found. - - -.IP "Recapture" -Causes fvwm to recapture all of its windows. This ensures that the -latest style parameters will be used. The recapture operation is -visually disturbing. - - -.IP "Refresh" -Causes all windows on the screen to redraw themselves. - - -.IP "RefreshWindow" -Causes current (or chosen) window to redraw itself. - - -.IP "Resize [ \fIx y\fP ]" -Allows the user to resize a window. If called from somewhere in a -window or its border, then that window will be resized. If called from -the root window then the user will be allowed to select the target -window. - -The operation can be aborted with Escape or by pressing any mouse button -(except button 1 which confirms the resize). - -If the optional arguments x and y are provided, then the window will -be resized so that its dimensions are \fIx\fP by \fIy\fP). The units -of x and y are percent-of-screen, unless a letter "p" is appended to -each coordinate, in which case the location is specified in pixels. - - -.IP "Restart \fIWindowManagerName\fP " -Causes \fIfvwm\fP to restart itself if WindowManagerName is "fvwm2", -or to switch to an alternate window manager if WindowManagerName is -other than "fvwm2". If the window manager is not in your default -search path, then you should use the full path name for -\fIWindowManagerName\fP. - -This command should not have a trailing ampersand or any command line -arguments and should not make use of any environmental variables. Of -the following examples, the first two are sure losers, but the third -is OK: -.EX -Key F1 R N Restart fvwm & -Key F1 R N Restart $(HOME)/bin/fvwm -Key F1 R N Restart /home/nation/bin/fvwm -.EE - -.IP "Scroll \fIhorizonal vertical\fP" -Scrolls the virtual desktop's viewport by \fIhorizontal\fP pages in -the x-direction and \fIvertical\fP pages in the y-direction. Either -or both entries may be negative. Both horizontal and vertical values -are expressed in percent of pages, so "Scroll 100 100" means to scroll -down and left by one full page. "Scroll 50 25" means to scroll left -half a page and down a quarter of a page. The scroll function should -not be called from pop-up menus. Normally, scrolling stops at the edge -of the desktop. - -If the horizontal and vertical percentages are multiplied by 1000 then -scrolling will wrap around at the edge of the desktop. If "Scroll -100000 0" is executed over and over \fIfvwm\fP will move to the next -desktop page on each execution and will wrap around at the edge of the -desktop, so that every page is hit in turn. - -If the letter "p" is appended to each coordinate (horizontal and/or -vertical), then the scroll amount will be measured in pixels. - -.IP "SendToModule \fImodulename string\fP" -Sends an arbitrary string (no quotes required) to all modules matching -\fImodulename\fP, which may contain wildcards. This only makes sense -if the module is set up to understand and deal with these strings -though... Can be used for module to module communication, or -implementation of more complex commands in modules. - -.IP "SetAnimation \fImilliseconds-delay\fP [ \fifractions-to-move-list\fP ]" -Sets the time between frames and the list of fractional offsets to -customize the animated moves of the \fIAnimatedMove\fP command and -the animation of menus (if the menu style is set to animated). If -the \fIfractions-to-move-list\fP is omitted, only the time between frames -is altered. The fractions-to-move-list specifies how far the window -should be offset at each successive frame as a fraction of the difference -between the starting location and the ending location. e.g.: -.EX -SetAnimation 10 -.01 0 .01 .03 .08 .18 .3 \\ - .45 .6 .75 .85 .90 .94 .97 .99 1.0 -.EE - -Sets the delay between frames to 10ms, and sets the positions of the 16 -frames of the animation motion. Notice that negative values are allowed, -and in particular can be used to make the motion appear more cartoonish, by -briefly moving slightly in the opposite direction of the main motion. The -above settings are the default. - -.IP "SetEnv \fIvarname stringvalue\fP" -Set an environment variable to a new value, similar to shell's export -or setenv command. The variable and its value are inherited by processes -started directly by fvwm2. This can be especially useful in conjunction -with the FvwmM4 module; e.g. "SetEnv height HEIGHT" will make the FvwmM4-set -variable "HEIGHT" usable by processes started by fvwm2 as the environment -variable "$height". If \fIstringvalue\fP includes whitespace, you should -enclose it in quotes. - - -.IP "SnapAttraction \fIproximity\fP [ \fIbehavior\fP ]" -If during an interactive move the window (or icon) comes within \fIproximity\fP -pixels of another the window (or icon) will be moved to make the borders -adjoin. The default of -1 means that no snapping will happen. A setting of -0 does indeed snap when the distance is zero pixels. This is relevant when -the \fISnapGrid\fP command is used. - -The \fIbehavior\fP argument is optional and may be set to one of the four -following values: - -With \fIAll\fP both icons and windows snap to other windows and other -icons. - -\fISameType\fP lets snap windows only to other windows and icons -only to other icons. - -With \fIWindows\fP windows snap only to other windows. Icons do not -snap. - -Similarly with \fIIcons\fP icons snap to only other icons and -windows do not snap. - -The default SnapAttraction setting for behavior is "All". - -.IP "SnapGrid \fIx-grid-size y-grid-size\fP" -During an interactive move a window (or icon) will be positioned such that -its location (top left corner) will be coincindent with the nearest grid point. -The default \fIx-grid-size\fP and \fIy-grid-size\fP setting are both 1, which -is effectively no grid all. An interactive move with both \fISnapGrid\fP -and \fISnapAttraction\fP in effect will result in the window being moved to be -adjacent to the nearest window border (if within snap proximity) or grid -position. In other words, the window will move the shortest distance possible -to satisfy both \fISnapGrid\fP and \fISnapAttraction\fP. Note that the X and -Y coordinates are not coupled. For example, a window may snap to another window -on the X axis while snapping to a grid point on the Y axis. - -.IP "Stick" -Makes a window sticky if it is not already sticky, or non-sticky if it -is already sticky. - -.IP "Style \fIwindowname options\fP" -This command is intended to replace the old fvwm 1.xx global commands -NoBorder, NoTitle, StartsOnDesk, Sticky, StaysOnTop, Icon, -WindowListSkip, CirculateSkip, SuppressIcons, BoundaryWidth, -NoBoundaryWidth, StdForeColor, and StdBackColor with a single flexible -and comprehensive window(s) specific command. This command is used to -set attributes of a window to values other than the default or to set -the window manager default styles. - -\fIwindowname\fP can be a window's name, class, or resource string. -It can contain the wildcards * and/or ?, which are matched in the -usual Unix filename manner. They are searched in the reverse order -stated, so that Style commands based on the name override or augment -those based on the class, which override or augment those based on the -resource string. - -Note - windows that have no name (WM_NAME) are given a name of -"Untitled", and windows that don't have a class (WM_CLASS, res_class) -are given Class = "NoClass" and those that don't have a resource -(WM_CLASS, res_name) are given Resource = "NoResource". - -\fIoptions\fP is a comma separated list containing some or all of the -keywords BorderWidth, HandleWidth, NoIcon/Icon, MiniIcon, IconBox, -IconGrid, IconFill, -NoTitle/Title, NoHandles/Handles, WindowListSkip/WindowListHit, -CirculateSkip/CirculateHit, StaysOnTop/StaysPut, Sticky/Slippery, -StartIconic/StartNormal, Color, ForeColor, BackColor, -StartsOnDesk/StartsOnPage/StartsAnyWhere, IconTitle/NoIconTitle, -MWMButtons/FvwmButtons, MWMBorder/FvwmBorder, MWMDecor/NoDecorHint, -MWMFunctions/NoFuncHint, HintOverride/NoOverride, NoButton/Button, -OLDecor/NoOLDecor, StickyIcon/SlipperyIcon, -SmartPlacement/DumbPlacement, RandomPlacement/ActivePlacement, -DecorateTransient/NakedTransient, SkipMapping/ShowMapping, UseDecor, -UseStyle, NoPPosition/UsePPosition, Lenience/NoLenience, -ClickToFocus/SloppyFocus/MouseFocus|FocusFollowsMouse. - -In the above list some options are listed as -style-option/opposite-style-option. The opposite-style-option for -entries that have them describes the \fIfvwm\fP default behavior and -can be used if you want to change the \fIfvwm\fP default behavior. - -\fIDecorateTransient\fP causes transient windows, which are normally -left undecorated, to be given the usual \fIfvwm\fP decorations (title -bar, buttons, etc.). Note that some pop-up windows, such as the xterm -menus, are not managed by the window manager and still do not receive -decorations. \fINakedTransient\fP (the default) causes transient windows -not to be given the standard decorations. - -\fIIcon\fP takes an (optional) unquoted string argument which is the icon -bitmap or pixmap to use. - -\fIIconBox\fP takes four numeric arguments or an X11 geometry string: -.EX -IconBox l t r b -.EE -or -.EX -IconBox geometry -.EE - -Where l is the left coordinate, t is the top, r is right and b is -bottom. Negative coordinates indicate distance from the right or -bottom of the screen. -Perhaps easier to use is an X11 Geometry string: -.EX -IconBox -80x200-1-1 -.EE -Which would place an 80 by 240 pixel iconbox in the lower right hand -corner of the screen. -The iconbox is a region of the screen where fvwm -attempts to put icons for any matching window, as long as they do not -overlap other icons. -Multiple icon boxes can be defined as overflow areas. When the first -icon box is filled, the second one is filled. All the icon boxes for -one style must be defined in one command. For example: -.EX -Style "*" IconBox -80x200-1-1, \\ - IconBox 1000x70-1-1 -.EE - -\fIIconGrid\fP takes 2 numeric arguments greater than zero. -.EX -IconGrid x y -.EE -Icons are placed in an icon box by stepping thru the icon box using -the x and y values for the icon grid, looking for a free space. -The default grid is 3 by 3 pixels which gives a tightly packed appearance. -To get a more regular appearance use a grid larger than your largest icon. -Currently there is no way to clip an icon to a maximum size. -An IconGrid definition must follow the IconBox definition that it -applies to: -.EX -Style "*" IconBox -80x240-1-1, IconGrid 90 90 -.EE - -\fIIconFill\fP takes 2 arguments. -.EX -IconFill Bottom Right -.EE -Icons are placed in an icon box by stepping thru the icon box using -these arguments to control the direction the box is filled in. -By default the direction is left to right, then top to bottom. -This would be expressed as: -.EX -IconFill left bottom -.EE -To fill an icon box in columns instead of rows, specify the -vertical direction (top or bottom) first. -The directions can be abbreviated or spelled out as follows: "t", "top", -"b", "bot", "bottom", "l", "lft", "left", "r", "rgt", "right". -An IconFill definition must follow the IconBox definition that it -applies to: -.EX -Style "*" IconBox -80x240-1-1, IconFill b r -.EE - -\fIMiniIcon\fP specifies a pixmap to use as the miniature icon for the -window. This miniature icon can be drawn in a title-bar button (see -ButtonStyle), and can be used by various fvwm modules (FvwmWinList, -FvwmIconMan, and FvwmTaskBar). It takes the name of a pixmap as an -argument. - -\fIStartsOnDesk\fP takes a numeric argument which is the desktop number on -which the window should be initially placed. Note that standard Xt -programs can also specify this via a resource (e.g. "-xrm '*Desk: 1'"). - -\fIStartsOnPage\fP takes 1, 2, or 3 numeric arguments. If one or three -arguments are givem, the first (or only) argument is the desktop number. If -three arguments are given, the 2nd and 3rd arguments identify the x,y page -position on the virtual window. If two arguments are given, they specify the -page position, and indicate no desk preference. If only one argument is given, -StartsOnPage functions exactly like StartsOnDesk. For those standard Xt -programs which understand this usage, the starting desk/page can also be -specified via a resource (e.g., "-xrm 'Fvwm.Page: 1 0 2'"). - -StartsOnPage in conjunction with SkipMapping is a useful technique when you -want to start an app on some other page and continue with what you were -doing, rather than waiting for it to appear. - -\fIStaysOnTop\fP makes the window always try to stay on top of the other -windows. This might be handy for clocks or mailboxes that you would -always like to be visible. If the window is explicitly lowered it -will not try to force its way back to the top until it is explicitly -raised. StaysPut (the default) allows the window to be obscured and -stay that way. - -\fIBorderWidth\fP takes a numeric argument which is the width of the border -to place the window if it does not have resize-handles. - -\fIHandleWidth\fP takes a numeric argument which is the width of the border -to place the window if it does have resize-handles. - -\fIButton\fP and \fINoButton\fP take a numeric argument which is the -number of the title-bar button which is to be included/omitted. - -\fIStickyIcon\fP makes the window sticky when its iconified. It will -deiconify on top the active desktop. - -\fIMWMButtons\fP makes the Maximize button look pressed-in when the window -is maximized. See the MWMButton flag in ButtonStyle for more -information. - -\fIMWMBorder\fP makes the 3-D bevel more closely match mwm's. - -\fIMWMDecor\fP makes fvwm attempt to recognize and respect the mwm -decoration hints that applications occasionally use. - -\fIMWMFunctions\fP makes fvwm attempt to recognize and respect the mwm -prohibited operations hints that applications occasionally use. -HintOverride makes fvwm shade out operations that mwm would prohibit, -but it lets you perform the operation anyway. - -\fIOLDecor\fP makes fvwm attempt to recognize and respect the olwm and olvwm -hints that many older XView and OLIT applications use. - -\fIColor\fP takes two arguments. The first is the window-label text color -and the second is the window decoration's normal background color. -The two colors are separated with a slash. If the use of a slash -causes problems then the separate ForeColor and BackColor options can -be used. - -\fIUseDecor\fP accepts one argument: the name of a decor created with -AddToDecor. If UseDecor is not specified, the "Default" decor is -used. Windows do not actually contain decors, but are always assigned -to one. If the decor is later modified with AddToDecor, the changes -will be visible for all windows which are assigned to it. The decor -for a window can be reassigned with ChangeDecor. - -\fIUseStyle\fP takes one arg, which is the name of another style. That way -you can have unrelated window names easily inherit similar traits -without retyping. For example: 'Style "rxvt" UseStyle "XTerm"'. - -\fISkipMapping\fP tells fvwm not to switch to the desk the window is on when -it gets mapped initially (useful with StartsOnDesk or StartsOnPage). - -\fILenience\fP instructs fvwm to ignore the convention in the ICCCM which -states that if an application sets the input field of the wm_hints -structure to False, then it never wants the window manager to give it -the input focus. The only application that I know of which needs this -is sxpm, and that is a silly bug with a trivial fix and has no overall -effect on the program anyway. Rumor is that some older applications -have problems too. - -\fIClickToFocus\fP instructs fvwm to give the focus to the window when it is -clicked in. The default \fIMouseFocus\fP (or its alias -\fIFocusFollowsMouse\fP) tells fvwm to give the window the focus as soon as -the pointer enters the window, and take it away when the pointer leaves the -window. \fISloppyFocus\fP is similar, but doesn't give up the focus if the -pointer leaves the window to pass over the root window or a ClickToFocus -window (unless you click on it, that is), which makes it possible to -move the mouse out of the way without losing focus. - -\fINoPPosition\fP instructs fvwm to ignore the PPosition field when adding -new windows. Adherence to the PPosition field is required for some -applications, but if you don't have one of those its a real headache. - -\fIRandomPlacement\fP causes windows which would normally require user -placement to be automatically placed in ever-so-slightly random -locations. For the best of all possible worlds use both -RandomPlacement and SmartPlacement. - -\fISmartPlacement\fP causes windows which would normally require user -placement to be automatically placed in a smart location - a location -in which they do not overlap any other windows on the screen. If no -such position can be found user placement or random placement (if -specified) will be used as a fall-back method. For the best of all -possible worlds use both RandomPlacement and SmartPlacement. - -An example: -.EX -\&# Change default fvwm behavior to no title- -\&# bars on windows! Also define a default icon. -Style "*" NoTitle, \\ - Icon unknown1.xpm, \\ - BorderWidth 4, \\ - HandleWidth 5 - -\&# now, window specific changes: -Style "Fvwm*" NoHandles, Sticky, \\ - WindowListSkip, \\ - BorderWidth 0 -Style "Fvwm Pager" StaysOnTop, BorderWidth 0 -Style "*lock" NoHandles, Sticky, \\ - StaysOnTop, WindowListSkip -Style "xbiff" Sticky, WindowListSkip -Style "FvwmButtons" NoHandles, Sticky, \\ - WindowListSkip -Style "sxpm" NoHandles -Style "makerkit" - -\&# Put title-bars back on xterms only! -Style "xterm" Title, Color black/grey - -Style "rxvt" Icon term.xpm -Style "xterm" Icon rterm.xpm -Style "xcalc" Icon xcalc.xpm -Style "xbiff" Icon mail1.xpm -Style "xmh" Icon mail1.xpm, \\ - StartsOnDesk 2 -Style "matlab" Icon math4.xpm, \\ - StartsOnDesk 3 -Style "xmag" Icon magnifying_glass2.xpm -Style "xgraph" Icon graphs.xpm -Style "FvwmButtons" Icon toolbox.xpm -Style "Maker" StartsOnDesk 1 -Style "signal" StartsOnDesk 3 - -\&# Fire up Netscape on the second desk, in the -\&# middle of my 3x3 virtual desktop, and don't -\&# bother me with it... -Style "Netscape*" SkipMapping, \\ - StartsOnPage 1 1 1 -.EE -Note that all properties for a window will be OR'ed together. In the -above example "FvwmPager" gets the property StaysOnTop via an exact -window name match but also gets NoHandles, Sticky, and WindowListSkip -by a match to "Fvwm*". It will get NoTitle by virtue of a match to -"*". If conflicting styles are specified for a window, then the last -style specified will be used. - -If the NoIcon attribute is set then the specified window will simply -disappear when it is iconified. The window can be recovered through -the window-list. If Icon is set without an argument then the NoIcon -attribute is cleared but no icon is specified. An example which -allows only the FvwmPager module icon to exist: -.EX -Style "*" NoIcon -Style "Fvwm Pager" Icon -.EE - - -.IP "Title" -Does nothing. This is used to insert a title line in a popup or menu. - - -.IP "TitleStyle [ \fIjustification\fP ] [ \fIheight num\fP ]" -Sets attributes for the title bar. Justifications can be "Centered", -"RightJustified," or "LeftJustified." \fIheight\fP sets the title -bar's height to an amount in pixels. Defaults are Centered and -WindowFont height. The \fIheight\fP parameter must be set after a -WindowFont command since WindowFont resets the height to the default -for the specified font. Example: -.EX -TitleStyle LeftJustified Height 24 -.EE - - -.IP "TitleStyle [ \fIstate\fP ] [ \fIstyle\fP ] [ -- \fI[!]flag ...\fP ]" -Sets the style for the title bar. \fIstate\fP can be one of -"ActiveUp," "ActiveDown," or "Inactive." If \fIstate\fP is omitted, -then the style is added to every state. If parentheses are placed -around the style and flags, then multiple state definitions can be -given per line. \fIstyle\fP can be omitted so that flags can be set -while not destroying the current style. - -If an "!" is prefixed to any \fIflag\fP, its behavior is negated. -Valid flags for each state include "Raised," "Flat," and "Sunk" (these -are mutually exclusive). The default is Raised. See the note in -ButtonStyle regarding the ActiveDown state. Examples: -.EX -TitleStyle ActiveUp HGradient 16 navy black -TitleStyle ActiveDown (Solid red -- flat) \\ - Inactive (TiledPixmap wood.xpm) -TitleStyle ActiveUp (-- Flat) ActiveDown \\ - (-- Raised) Inactive (-- Flat) -.EE -This sets the ActiveUp state to a horizontal gradient, the ActiveDown -state to solid red, and the Inactive state to a tiled wood pixmap. -Finally, ActiveUp is set to look flat, while ActiveDown set to be sunk -(the Raised flag for the ActiveDown state causes it to appear Sunk due -to relief inversion), and Inactive is set to flat as well. An example -which sets flags for all states: -.EX -TitleStyle -- flat -.EE -For a flattened look: -.EX -TitleStyle -- flat -ButtonStyle All ActiveUp (-- flat) Inactive \\ - (-- flat) -.EE - - -.IP "UpdateDecor [ \fIdecor\fP ]" -Updates window decorations. \fIdecor\fP is an optional argument which -specifies the \fIdecor\fP to update. If given, only windows which are -assigned to that particular \fIdecor\fP will be updated. This command -is useful, for instance, after a ButtonStyle, TitleStyle or -BorderStyle (possibly used in conjunction with AddToDecor). -Specifying an invalid decor results in all windows being updated. -This command is less disturbing than Recapture, but does not affect -window style options as Recapture does. - - -.IP "Wait \fIname\fP" -This built-in is intended to be used in \fIfvwm\fP functions only. It -causes execution of a function to pause until a new window name -\fIname\fP appears. \fIFvwm\fP remains fully functional during a wait. -This is particularly useful in the InitFunction if you are trying to -start windows on specific desktops: -.EX -AddToFunc InitFunction - + "I" exec xterm -geometry 80x64+0+0 - + "I" Wait xterm - + "I" Desk 0 2 - + "I" Exec exec xmh -font fixed -geometry \\ - 507x750+0+0 - + "I" Wait xmh - + "I" Desk 0 0 -.EE -The above function starts an xterm on the current desk, waits for it -to map itself, then switches to desk 2 and starts an xmh. After the -xmh window appears control moves to desk 0. - - -.IP "WarpToWindow \fIx y\fP" -Warps the cursor to the associated window. The parameters x and y -default to percentage of window down and in from the upper left hand -corner (or number of pixels down and in if 'p' is appended to the -numbers). - - -.IP "WindowFont [ \fIfontname\fP ]" -Makes \fIfvwm\fP use font \fIfontname\fP instead of "fixed" for window -title-bars. To reset this font to the default font (see \fIDefaultFont\fP) -you may omit \fIfontname\fP. - - -.IP "WindowId \fIid func\fP" -The WindowId function is similar to the Next and Prev funcs, except -that it looks for a specific window \fIid\fP and runs the specified -\fIfunc\fP on it. -.EX -WindowId 0x34567890 Raise -WindowId 0x34567890 WarpToWindow 50 50 -.EE -Mostly this is useful for functions used with the WindowList builtin. - - -.IP "WindowList [ \fIposition\fP ] [ \fIoptions\fP ] [ \fIdouble-click-action\fP ]" -Generates a pop-up menu (and pops it up) in which the title and -geometry of each of the windows currently on the desk top are shown. -The geometry of iconified windows is shown in parenthesis. Selecting -an item from the window list pop-up menu will by default cause the -interpreted function WindowListFunc to be run with the window id of -that window passed in as $0. By default the WindowListFunc looks like -this: -.EX -AddToFunc WindowListFunc - + "I" WindowId $0 Iconify -1 - + "I" WindowId $0 FlipFocus - + "I" WindowId $0 Raise - + "I" WindowId $0 WarpToWindow 5p 5p -.EE -You can Destroy the builtin WindowListFunc and create your own if -these defaults do not suit you. - -The \fIposition\fP arguments are the same as for \fIMenu\fP. The -command \fIdouble-click-action\fP will be invoked if the user -double-clicks (or hits the key rapidly twice if the menu is bound -to a key) when bringing the window list. The double-click-action -must be quoted if it consists of more than one word. - -The double-click-action is useful to define a default window if you -have bound the window list to a key (or button) like this: -.EX -Key Tab A M WindowList "Prev FlipFocus" -.EE -Hitting Alt-Tab once it brings up the window list, if you hit it -twice the focus is flipped between the current and the last focused -window. - -The \fIoptions\fP passed to WindowList can be "NoGeometry", "Function -", "Desk ", "CurrentDesk", "NoIcons", "Icons", -"OnlyIcons", "NoNormal", "Normal", "OnlyNormal", "NoSticky", "Sticky", -"OnlySticky", "NoOnTop", "OnTop", "OnlyOnTop", "NoDeskSort", "UseIconName", -"Alphabetic", "NotAlphabetic". - -(Note - normal means not iconic, sticky, or ontop) - -If you pass in a function via "Function ", $0 is the window -id: -.EX -AddToFunc IFunc "I" WindowId $0 Iconify -WindowList Function IFunc, NoSticky, \\ - CurrentDesk, NoIcons -.EE - -If you wanted to use the WindowList as an icon manager, you could invoke -the following: -.EX -WindowList OnlyIcons, Sticky, OnTop, Geometry -.EE -(Note - the "Only" options essentially wipe out all other ones...) - - -.IP "WindowsDesk \fIarg1\fP [ \fIarg2\fP ]" -Moves the selected window to another desktop (workspace, room). - -This command has been removed and must be replaced by \fIMoveToDesk\fP, -the arguments for which are the same as for the \fIDesk\fP command. -\fINote:\fP You cannot simply change the name of the command: the -syntax has changed. If you used "WindowsDesk n" to move a window to -desk n, you will have to change it to "MoveToDesk 0 n". - - -.IP "WindowShade [ \fIopt\fP ]" -Toggles the window shade feature for titled windows. Windows in the -shaded state only display a title bar. If \fIopt\fP is not given, the -window shade state is toggled. If \fIopt\fP is 1, the window is -forced to the shaded state. If \fIopt\fP is 2, then the window is -forced to the non-shaded state. Maximized windows and windows without -titles cannot be shaded. - - -.IP "XORvalue \fInumber\fP" -Changes the value with which bits are XOR'ed when doing rubber-band -window moving or resizing. Setting this value is a trial-and-error +.Dd $Mdocdate$ +.Dt FVWM2 1 +.Os OpenBSD +.Sh NAME +.Nm fvwm2 +.Nd F Virtual Window Manager for X11 +.Sh SYNOPSIS +.Nm fvwm2 +.Op Fl s +.Op Fl f Ar config-file +.Op Fl cmd Ar config-command +.Op Fl display Ar display +.Op Fl debug +.Sh DESCRIPTION +.Nm +is the F Virtual Window Manager, a highly configurable ICCCM-compliant +window manager for the X Window System. +.Pp +.Nm +provides virtual desktops, complex function definitions, extensive +styling capabilities, and a modular architecture. +.Pp +The options are as follows: +.Bl -tag -width Ds +.It Fl s +Single-screen mode. +Do not manage multiple screens on a multi-headed display. +Each screen must then be managed by a separate +.Nm process. - - -.IP "+" -Used to continue adding to the last specified decor, function or menu. -See the discussion for AddToDecor, AddToFunc, and AddToMenu. - - - -.SH KEYBOARD SHORTCUTS -All (I think) window manager operations can be performed from the -keyboard so mouseless operation should be possible. In addition to -scrolling around the virtual desktop by binding the Scroll built-in to -appropriate keys, pop-ups, move, resize, and most other built-ins can -be bound to keys. Once a built-in function is started the pointer is -moved by using the up, down, left, and right arrows, and the action is -terminated by pressing return. Holding down the shift key will cause -the pointer movement to go in larger steps and holding down the -control key will cause the cursor movement to go in smaller steps. -Standard emacs and vi cursor movement controls (^n, ^p, ^f, ^b, and -^j, ^k, ^h, ^l) can be used instead of the arrow keys. - - -.SH SUPPLIED CONFIGURATION -A sample configuration file, .fvwmrc, is supplied with the \fIfvwm\fP -distribution. It is well commented and can be used as a source of -examples for \fIfvwm\fP configuration. - - -.SH USE ON MULTI-SCREEN DISPLAYS -If the -s command line argument is not given, \fIfvwm\fP will -automatically start up on every screen on the specified display. -After \fIfvwm\fP starts each screen is treated independently. -Restarts of \fIfvwm\fP need to be performed separately on each screen. -The use of EdgeScroll 0 0 is strongly recommended for multi-screen -displays. - -You may need to quit on each screen to quit from the X session -completely. - - -.SH ENVIRONMENT -.TP -DISPLAY -Fvwm starts on this display unless the -.I -display -option is given. -.TP -FVWM_MODULEDIR -Set by \fIfvwm\fP to the directory containing the standard \fIfvwm\fP -modules. - - -.SH BUGS -As of fvwm 2.2 there were exactly 46.144 unidentified bugs. -Identified bugs have mostly been fixed, though. Since then 12.25 bugs -have been fixed. Assuming that there are at least 10 unidentified -bugs for every identified one, that leaves us with 46.144 - 12.25 + 10 -* 12.25 = 156.395 unidentified bugs. If we follow this to its logical -conclusion we will have an infinite number of unidentified bugs before -the number of bugs can start to diminish, at which point the program -will be bug-free. Since this is a computer program infinity = -3.4028e+38 if you don't insist on double-precision. At the current -rate of bug discovery we should expect to achieve this point in -4.27e+27 years. I guess I better plan on passing this thing on to my -children.... - -Known bugs can be found in the BUGS file in the distribution, in -the fvwm bug tracking system (accessible from the fvwm home page) and -in the TO-DO list. - -Bug reports can be sent to the FVWM workers' mailing list (see the FAQ). - -.SH AUTHOR -Robert Nation with help from many people, based on \fItwm\fP code, -which was written by Tom LaStrange. After Robert Nation came Charles Hines, -followed by Brady Montz. Currently fvwm is maintained by a number of people -on the fvwm-workers mailing list (Dan Espen, Steve Robbins, Paul Smith, -Jason Tibbitts, Dominik Vogt, Bob Woodside and others). - -The official FVWM homepage is http://www.fvwm.org/. +.It Fl f Ar config-file +Read +.Ar config-file +instead of the default +.Pa ~/.fvwmrc +or the system-wide +.Pa /etc/X11/fvwm/system.fvwm2rc . +.It Fl cmd Ar config-command +Execute +.Ar config-command +after reading the configuration file. +.It Fl display Ar display +Connect to the X display +.Ar display . +.It Fl debug +Enable synchronous X11 protocol debugging. +.El +.Sh CONFIGURATION +.Nm +reads configuration from +.Pa ~/.fvwmrc +by default. +If that file does not exist, the system configuration at +.Pa /etc/X11/fvwm/system.fvwm2rc +is used. +.Pp +The configuration language supports: +.Bl -dash +.It +Style rules for window appearance and behavior. +.It +Key and mouse bindings for interactive control. +.It +Complex functions with conditional logic. +.It +Menu definitions. +.It +Module invocations. +.It +Environment variable expansion. +.It +File inclusion with +.Ic Read +and +.Ic PipeRead . +.El +.Sh COMMANDS +The following built-in commands are available in configuration +files and from modules: +.Pp +.Bl -tag -width "ButtonStyle" -compact +.It Ic AddToFunc +Define or extend a complex function. +.It Ic AddToMenu +Define or extend a menu. +.It Ic ButtonStyle +Set button decoration style. +.It Ic ChangeDecor +Change window decoration at runtime. +.It Ic ClickTime +Set double-click timeout. +.It Ic CursorMove +Move the cursor relative to its current position. +.It Ic Desk +Switch to a different desktop. +.It Ic DestroyDecor +Destroy a named decoration set. +.It Ic DestroyMenu +Destroy a menu definition. +.It Ic DestroyMenuStyle +Destroy a menu style. +.It Ic EdgeResistance +Set resistance to moving windows past screen edges. +.It Ic EdgeScroll +Set edge-triggered viewport scrolling. +.It Ic Exec +Execute an external command. +.It Ic Function +Execute a named complex function. +.It Ic GlobalOpts +Set global window manager options. +.It Ic GotoPage +Move the viewport to a specific page. +.It Ic HilightColor +Set the highlight color for the focus window. +.It Ic IconFont +Set the font for icon labels. +.It Ic IconPath +Set the icon search path. +.It Ic Key +Define a keyboard binding. +.It Ic Lower +Lower a window. +.It Ic Maximize +Maximize or restore a window. +.It Ic MenuStyle +Set menu appearance and behavior. +.It Ic Module +Launch a module. +.It Ic ModulePath +Set the module search path. +.It Ic Mouse +Define a mouse binding. +.It Ic Move +Move a window. +.It Ic Next +Focus the next window. +.It Ic NoBoundaryWidth +Remove window boundary width. +.It Ic OpaqueMove +Set opaque window moving. +.It Ic OpaqueResize +Set opaque window resizing. +.It Ic PipeRead +Read configuration from a pipe. +.It Ic PixmapPath +Set the pixmap search path. +.It Ic Popup +Display a popup menu. +.It Ic Prev +Focus the previous window. +.It Ic Quit +Exit +.Nm . +.It Ic Raise +Raise a window. +.It Ic RaiseLower +Toggle raise/lower state. +.It Ic Read +Read configuration from a file. +.It Ic Recapture +Re-capture all windows on the display. +.It Ic Refresh +Refresh all window decorations. +.It Ic Resize +Resize a window. +.It Ic Restart +Restart +.Nm . +.It Ic Scroll +Scroll the viewport. +.It Ic SetEnv +Set an environment variable. +.It Ic Style +Set window style options. +.It Ic TitleStyle +Set title bar decoration style. +.It Ic UseDecor +Apply a named decoration set to a window. +.It Ic Wait +Wait for a named window. +.It Ic WindowFont +Set the font for window titles. +.It Ic WindowList +Invoke the built-in window list. +.It Ic WindowShade +Shade or unshade a window. +.It Ic XORvalue +Set XOR drawing value. +.El +.Sh MODULES +.Nm +supports loadable modules that communicate with the window manager +via a binary packet protocol over Unix pipes. +Modules typically provide additional functionality such as: +.Bl -dash +.It +Desktop pagers +.Pq Xr FvwmPager 1 . +.It +Button bars and docks +.Pq Xr FvwmButtons 1 . +.It +Window lists +.Pq Xr FvwmWinList 1 . +.It +Icon management +.Pq Xr FvwmIconBox 1 , Xr FvwmIconMan 1 . +.It +Desktop background management +.Pq Xr FvwmBacker 1 . +.It +Session state saving +.Pq Xr FvwmSave 1 , Xr FvwmSaveDesk 1 . +.It +Configuration preprocessors +.Pq Xr FvwmCpp 1 , Xr FvwmM4 1 . +.El +.Sh ENVIRONMENT +.Bl -tag -width "FVWM_MODULEDIR" -compact +.It Ev DISPLAY +X11 display to connect to. +.It Ev HOME +User home directory, used for configuration file location. +.It Ev FVWM_MODULEDIR +Override the module installation directory. +.It Ev FVWM_EXEC_FD +Internal: file descriptor for the execution helper IPC (not user-settable). +.El +.Sh FILES +.Bl -tag -width "~/.fvwm2rc" -compact +.It Pa ~/.fvwmrc +Per-user configuration file. +.It Pa ~/.fvwm2rc +Alternative per-user configuration file. +.It Pa /etc/X11/fvwm/system.fvwm2rc +System-wide configuration file. +.It Pa /usr/X11R6/lib/X11/fvwm/ +System module and resource directory. +.El +.Sh SECURITY CONSIDERATIONS +.Nm +runs with privilege separation: +.Bl -dash +.It +The main window manager process owns the X11 connection and +manages windows. +.It +The +.Nm fvwm_exec +helper process executes external commands without access +to the X11 connection. +.It +After initialization, the main process drops privileges via +.Xr pledge 2 +and +.Xr unveil 2 . +.El +.Pp +The main +.Nm +process runs with the following +.Xr pledge 2 +promises after startup: +.Bl -dash -compact +.It +.Va stdio +(memory allocation, logging) +.It +.Va rpath +(read configuration and resources) +.It +.Va proc +(fork for module launching) +.It +.Va exec +(launch the execution helper) +.El +.Pp +The execution helper runs with the following +.Xr pledge 2 +promises: +.Bl -dash -compact +.It +.Va stdio +.It +.Va proc +.It +.Va exec +.El +.Pp +.Nm +uses +.Xr unveil 2 +to restrict filesystem access to: +.Bl -dash -compact +.It +.Pa /usr/X11R6/lib/X11/fvwm/ +(read + execute) +.It +.Pa /etc/X11/fvwm/ +(read) +.It +.Pa /tmp/ +(read, write, create) +.El +.Pp +.Nm +modules are separate processes. +Each module opens its own X11 connection and communicates +with the main +.Nm +process via Unix pipes. +Module binaries are executed by the helper process, preventing +the main window manager from directly executing user commands. +.Sh SEE ALSO +.Xr fvwm_exec 1 , +.Xr FvwmAuto 1 , +.Xr FvwmBacker 1 , +.Xr FvwmBanner 1 , +.Xr FvwmButtons 1 , +.Xr FvwmCpp 1 , +.Xr FvwmForm 1 , +.Xr FvwmIconBox 1 , +.Xr FvwmIconMan 1 , +.Xr FvwmIdent 1 , +.Xr FvwmM4 1 , +.Xr FvwmPager 1 , +.Xr FvwmRearrange 1 , +.Xr FvwmSave 1 , +.Xr FvwmSaveDesk 1 , +.Xr FvwmScroll 1 , +.Xr FvwmTalk 1 , +.Xr FvwmWinList 1 , +.Xr xpmroot 1 , +.Xr pledge 2 , +.Xr unveil 2 +.Sh COMPATIBILITY +.Nm +is compatible with FVWM 2.2.5 configuration syntax. +Existing +.Pa .fvwm2rc +files should work without modification. +.Pp +Module IPC protocol semantics are preserved from FVWM 2.2.5. +The binary packet format and message type numbering are unchanged. +Module descriptor conventions are unchanged. +.Sh HISTORY +.Nm +was originally written by Robert Nation in 1993. +This is the OpenBSD fork of FVWM 2.2.5. +.Sh AUTHORS +.An Robert Nation +and many contributors. +.Ox +fork maintained by the +.Ox +project. +.Sh CAVEATS +Privilege separation, +.Xr pledge 2 , +and +.Xr unveil 2 +policies in this version have not been verified through runtime testing. +.Pp +The execution helper and imsg IPC have not been tested against real +X11 workloads. +Module protocol compatibility has been preserved through static +inspection of message layouts but has not been empirically verified. Index: fvwm/libs/ColorUtils.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/libs/ColorUtils.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/libs/ColorUtils.c --- fvwm/libs/ColorUtils.c +++ fvwm/libs/ColorUtils.c @@ -1,261 +1,133 @@ /* - * The following GPL code from scwm implements a good, fast 3D-shadowing - * algorithm. It converts the color from RGB to HLS space, then - * multiplies both the luminosity and the saturation by a specified - * factor (clipping at the extremes). Then it converts back to RGB and - * creates a color. The guts of it, i.e. the `color_mult' routine, looks - * a bit longish, but this is only because there are 6-way conditionals - * at the begining and end; it actually runs quite fast. The algorithm is - * the same as Gtk's, but the implemenation is independent and more - * streamlined. + * Copyright (c) 2025-2026 David Uhden Collado * - * Calling `adjust_pixel_brightness' with a `factor' of 1.3 for hilights - * and 0.7 for shadows exactly emulates Gtk's shadowing, which is, IMO - * the most visually pleasing shadowing of any widget set; using 1.2 and - * 0.5 respectively gives something closer to the "classic" fvwm effect - * with deeper shadows and more subtle hilights, but still (IMO) smoother - * and more attractive than fvwm. - * - * The only color these routines do not usefully handle is black; black - * will be returned even for a factor greater than 1.0, when optimally - * one would like to see a very dark gray. This could possibly be - * addressed by adding a small additive factor when brightening - * colors. If anyone adds that feature, please feed it upstream to me. - * - * Feel free to use this code in fvwm2, of course. - * - * - Maciej Stachowiak - * - * And, of course, history shows, we took him up on the offer. - * Integrated into fvwm2 by Dan Espen, 11/13/98. - */ - - -/* - * Copyright (C) 1997, 1998, Maciej Stachowiak and Greg J. Badros - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this software; see the file COPYING.GPL. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307 USA + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include "config.h" /* must be first */ - +#include #include -#include /* for X functions in general */ -#include "fvwmlib.h" /* prototype GetShadow GetHilit */ - -#define SCALE 65535.0 -#define HALF_SCALE (SCALE / 2) -typedef enum { - R_MAX_G_MIN, R_MAX_B_MIN, - G_MAX_B_MIN, G_MAX_R_MIN, - B_MAX_R_MIN, B_MAX_G_MIN -} MinMaxState; +#include "config.h" +#include "fvwmlib.h" -/* Multiply the HLS-space lightness and saturation of the color by the - given multiple, k - based on the way gtk does shading, but independently - coded. Should give better relief colors for many cases than the old - fvwm algorithm. */ +#define SCALE 65535.0 +#define HALF_SCALE (SCALE * 0.5) -/* FIXMS: This can probably be optimized more, examine later. */ +enum ColorChannel { CHANNEL_RED = 0, CHANNEL_GREEN = 1, CHANNEL_BLUE = 2 }; -static void -color_mult (unsigned short *red, - unsigned short *green, - unsigned short *blue, double k) +static void +color_mult(unsigned short *red, unsigned short *green, unsigned short *blue, + double factor) { - if (*red == *green && *red == *blue) { - double temp; - /* A shade of gray */ - temp = k * (double) (*red); - if (temp > SCALE) { - temp = SCALE; - } - *red = (unsigned short)(temp); - *green = *red; - *blue = *red; - } else { - /* Non-zero saturation */ - double r, g, b; - double min, max; - double a, l, s; - double delta; - double middle; - MinMaxState min_max_state; + double components[3]; + components[CHANNEL_RED] = (double)*red; + components[CHANNEL_GREEN] = (double)*green; + components[CHANNEL_BLUE] = (double)*blue; + + if (components[CHANNEL_RED] == components[CHANNEL_GREEN] && + components[CHANNEL_RED] == components[CHANNEL_BLUE]) { + double level = components[CHANNEL_RED] * factor; + if (level > SCALE) { + level = SCALE; + } + *red = (unsigned short)level; + *green = *red; + *blue = *red; + return; + } - r = (double) *red; - g = (double) *green; - b = (double) *blue; + int max_index = CHANNEL_RED; + int min_index = CHANNEL_RED; + for (int idx = CHANNEL_GREEN; idx <= CHANNEL_BLUE; ++idx) { + if (components[idx] > components[max_index]) { + max_index = idx; + } + if (components[idx] < components[min_index]) { + min_index = idx; + } + } - if (r > g) { - if (r > b) { - max = r; - if (g < b) { - min = g; - min_max_state = R_MAX_G_MIN; - a = b - g; - } else { - min = b; - min_max_state = R_MAX_B_MIN; - a = g - b; + int mid_index = + CHANNEL_RED + CHANNEL_GREEN + CHANNEL_BLUE - max_index - min_index; + double max_value = components[max_index]; + double min_value = components[min_index]; + double span = max_value - min_value; + double ratio = (components[mid_index] - min_value) / span; + + double lightness = 0.5 * (max_value + min_value); + double extrema_sum = max_value + min_value; + double saturation_denominator = (lightness <= HALF_SCALE) ? + extrema_sum : + (2.0 * SCALE - extrema_sum); + double saturation = span / saturation_denominator; + + lightness *= factor; + if (lightness > SCALE) { + lightness = SCALE; } - } else { - max = b; - min = g; - min_max_state = B_MAX_G_MIN; - a = r - g; - } - } else { - if (g > b) { - max = g; - if (b < r) { - min = b; - min_max_state = G_MAX_B_MIN; - a = r - b; - } else { - min = r; - min_max_state = G_MAX_R_MIN; - a = b - r; + saturation *= factor; + if (saturation > 1.0) { + saturation = 1.0; } - } else { - max = b; - min = r; - min_max_state = B_MAX_R_MIN; - a = g - r; - } - } - - delta = max - min; - a = a / delta; - - l = (max + min) / 2; - if (l <= HALF_SCALE) { - s = max + min; - } else { - s = 2.0 * SCALE - (max + min); - } - s = delta/s; - - l *= k; - if (l > SCALE) { - l = SCALE; - } - s *= k; - if (s > 1.0) { - s = 1.0; - } - if (l <= HALF_SCALE) { - max = l * (1 + s); - } else { - max = s * SCALE + l - s * l; - } + double new_max; + if (lightness <= HALF_SCALE) { + new_max = lightness * (1.0 + saturation); + } else { + new_max = + saturation * SCALE + lightness - saturation * lightness; + } - min = 2 * l - max; - delta = max - min; - middle = min + delta * a; + double new_min = 2.0 * lightness - new_max; + double new_span = new_max - new_min; + double new_mid = new_min + new_span * ratio; - switch (min_max_state) { - case R_MAX_G_MIN: - r = max; - g = min; - b = middle; - break; - case R_MAX_B_MIN: - r = max; - g = middle; - b = min; - break; - case G_MAX_B_MIN: - r = middle; - g = max; - b = min; - break; - case G_MAX_R_MIN: - r = min; - g = max; - b = middle; - break; - case B_MAX_G_MIN: - r = middle; - g = min; - b = max; - break; - case B_MAX_R_MIN: - r = min; - g = middle; - b = max; - break; - } + double updated[3]; + updated[max_index] = new_max; + updated[min_index] = new_min; + updated[mid_index] = new_mid; - *red = (unsigned short) r; - *green = (unsigned short) g; - *blue = (unsigned short) b; - } + *red = (unsigned short)updated[CHANNEL_RED]; + *green = (unsigned short)updated[CHANNEL_GREEN]; + *blue = (unsigned short)updated[CHANNEL_BLUE]; } -/* - * This routine uses PictureSaveDisplay and PictureCMap which must be - * created by InitPictureCMAP in Picture.c. - * - * If you attempt to use GetShadow and GetHilit, make sure your module - * calls InitPictureCMAP first. - */ static Pixel adjust_pixel_brightness(Pixel pixel, double factor) { - extern Colormap PictureCMap; - extern Display *PictureSaveDisplay; - XColor c; - c.pixel = pixel; - XQueryColor (PictureSaveDisplay, PictureCMap, &c); - color_mult(&c.red, &c.green, &c.blue, factor); - XAllocColor (PictureSaveDisplay, PictureCMap, &c); + extern Colormap PictureCMap; + extern Display *PictureSaveDisplay; + XColor color_spec; + + color_spec.pixel = pixel; + XQueryColor(PictureSaveDisplay, PictureCMap, &color_spec); + color_mult( + &color_spec.red, &color_spec.green, &color_spec.blue, factor); + XAllocColor(PictureSaveDisplay, PictureCMap, &color_spec); - return c.pixel; + return color_spec.pixel; } -/* - * These are the original fvwm2 APIs, one for highlights and one for - * shadows. Together, if used in a frame around a rectangle, they - * produce a 3d appearance. - * - * The input pixel, is normally the background color used in the - * rectangle. One would hope, when the user selects to color something - * with a multi-color pixmap, they will have the insight to also assign a - * background color to the pixmaped area that approximates the average - * color of the pixmap. - * - * Currently callers handle monochrome before calling this routine. The - * next logical enhancement is for that logic to be moved here. Probably - * a new API that deals with foreground/background/hilite/shadow - * allocation all in 1 call is the next logical extenstion. - * - * Color allocation is also a good candidate for becoming a library - * routine. The color allocation logic in FvwmButtons using the XPM - * library closeness stuff may be the ideal model. - * (dje 11/15/98) - */ #define DARKNESS_FACTOR 0.5 -Pixel GetShadow(Pixel background) { - return adjust_pixel_brightness(background, DARKNESS_FACTOR); +Pixel +GetShadow(Pixel background) +{ + return adjust_pixel_brightness(background, DARKNESS_FACTOR); } #define BRIGHTNESS_FACTOR 1.4 -Pixel GetHilite(Pixel background) { - return adjust_pixel_brightness(background, BRIGHTNESS_FACTOR); +Pixel +GetHilite(Pixel background) +{ + return adjust_pixel_brightness(background, BRIGHTNESS_FACTOR); } Index: fvwm/modules/FvwmBacker/root_bits.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmBacker/root_bits.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmBacker/root_bits.c --- fvwm/modules/FvwmBacker/root_bits.c +++ fvwm/modules/FvwmBacker/root_bits.c @@ -1,19 +1,17 @@ -/* Rewrite of this file by Dominik Vogt on Nov-1-1998 to remove the - * Xconsortium copyright. +/* + * Copyright (c) 2025-2026 David Uhden Collado * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include @@ -24,22 +22,22 @@ extern Display *dpy; extern int screen; extern char *Module; -unsigned long GetColor(char *name) +unsigned long +GetColor(char *name) { - XColor color; + Colormap cmap = DefaultColormap(dpy, screen); + XColor spec = {0}; + + if (!XParseColor(dpy, cmap, name, &spec)) { + fprintf(stderr, "%s: unknown color \"%s\"\n", Module, name); + exit(1); + } - color.pixel = 0; - if (!XParseColor (dpy, DefaultColormap(dpy,screen), name, &color)) - { - fprintf(stderr,"%s: unknown color \"%s\"\n",Module,name); - exit(1); - } - else if(!XAllocColor (dpy, DefaultColormap(dpy,screen), &color)) - { - fprintf(stderr, "%s: unable to allocate color for \"%s\"\n", - Module, name); - exit(1); - } + if (!XAllocColor(dpy, cmap, &spec)) { + fprintf(stderr, "%s: unable to allocate color for \"%s\"\n", + Module, name); + exit(1); + } - return color.pixel; + return spec.pixel; } Index: fvwm/modules/FvwmRearrange/FvwmRearrange.1 =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmRearrange/FvwmRearrange.1,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmRearrange/FvwmRearrange.1 --- fvwm/modules/FvwmRearrange/FvwmRearrange.1 +++ fvwm/modules/FvwmRearrange/FvwmRearrange.1 @@ -1,7 +1,8 @@ -.\" $OpenBSD: FvwmRearrange.1,v 1.1.1.1 2006/11/26 10:53:53 matthieu Exp $ +.\" $OpenBSD: FvwmRearrange.1,v 2.0 2025/10/18 10:00:00 random Exp $ .\" t -.\" @(#)FvwmRearrange.1 11/9/98 -.de EX \"Begin example +.\" @(#)FvwmRearrange.1 18/10/25 +.de EX +.\" Begin example macro .ne 5 .if n .sp 1 .if t .sp .5 @@ -9,133 +10,123 @@ .in +.5i .. .de EE +.\" End example macro .fi .in -.5i .if n .sp 1 .if t .sp .5 .. -.TH FvwmRearrange 1 "November 9, 1998" "FvwmRearrange 1.0" "FvwmRearrange 1.0" +.TH FVWMREARRANGE 1 "October 18, 2025" "2.0" "FVWM Modules" .UC .SH NAME -FvwmRearrange \- rearrange FVWM windows +FvwmRearrange \- reorganise FVWM clients .SH SYNOPSIS -FvwmRearrange is spawned by fvwm, so no command line invocation will work. - +FvwmRearrange is launched internally by fvwm; invoking it directly from a shell +is not supported. .SH DESCRIPTION -This module can be called to tile or cascade windows. - -When tiling the module attempts to tile windows on the current screen -subject to certain constraints. Horizontal or vertical tiling is performed -so that each window does not overlap another, and by default each window -is resized to its nearest resize increment (note sometimes some space -might appear between tiled windows -- this is why). - -When cascading the module attempts to cascade windows on the current screen -subject to certain constraints. Layering is performed so consecutive -windows will have their window titles visible underneath the previous. - +FvwmRearrange arranges windows either in a tiled grid or in a cascading stack. +Tiling fills the current screen with non-overlapping frames. Rows or columns +may be generated automatically so every client finds a slot. When tiling is in +effect, windows are resized to match their assigned cell unless stretching has +been disabled, which can leave gaps between tiles. +.PP +In cascade mode the module positions successive windows so that the title of +each client remains visible beneath the one before it. Windows can optionally +be constrained to a maximum width and height while still honouring the resize +increment rules. .SH INVOCATION -FvwmRearrange is best invoked from a menu, popup or button. There are a -number of command line options which can be used to constrain the -layering, these are described below. As an example case, one could -call FvwmRearrange with the following arguments: +FvwmRearrange is normally bound to menus, buttons, or key bindings. The module +accepts a variety of switches that tailor how windows are selected and laid +out. The following samples show typical usage: .EX FvwmRearrange -tile -h 10 10 90 90 .EE -or .EX -FvwmRearrange -cascade \-resize 10 2 80 70 +FvwmRearrange -cascade -resize 10 2 80 70 .EE - -The first invocation will horizontally tile windows with a bounding box -which starts at 10 by 10 percent into and down the screen and ends at -90 by 90 percent into and down the screen. - -The second invocation will cascade windows starting 10 by 2 percent into and -down the screen. Windows will be constrained to 80 by 70 percent of -the screen dimensions. Since the \fIresize\fP is also specified, -windows will be resized to the given constrained width and height. - -FvwmRearrange can be called as FvwmTile or FvwmCascade. This is equivalent -to providing the -tile or -cascade option. This form is obsolete and -supplied for backwards compatibility only. - -Command-line arguments passed to FvwmRearrange are described here. +.PP +The first command tiles across the screen horizontally, beginning 10 percent +from the left and top edges and finishing at the point 90 percent across and +down. The second command cascades windows starting 10 percent across and +2 percent down, resizing each client to 80 by 70 percent of the screen when +possible. +.PP +For backward compatibility the module can also be invoked as FvwmTile or +FvwmCascade, which internally pass \-tile or \-cascade. +.SH OPTIONS +The options recognised by FvwmRearrange are described below. .IP \-a -Causes \fIall\fP window styles to be affected, even ones with the -WindowListSkip style. +Process every window, including those marked with the WindowListSkip style. As +part of this shortcut, untitled, transient, and maximised clients are also +selected. .IP \-cascade -Cascade windows. This argument must be the first on the command line. -This is the default. +Choose cascade mode. If neither \-cascade nor \-tile is supplied, cascade is +the default behaviour. .IP \-desk -Causes all windows on the desk to be cascaded/tiled instead of the -current screen only. +Operate on all windows on the current desk rather than limiting the action to +those that intersect the visible screen. .IP \-flatx -Inhibits border width increment. Only used when cascading. +When cascading, suppress the automatic horizontal offset that would normally be +added for each step. .IP \-flaty -Inhibits border height increment. Only used when cascading. +When cascading, suppress the automatic vertical offset that would normally be +added for each step. .IP \-h -Tiles horizontally (default is to tile vertically). Used for tiling only. -.IP "\-incx \fIarg\fP" -Specifies a horizontal increment which is successively added to -cascaded windows. \fIarg\fP is a percentage of screen width, or pixel -value if a \fIp\fP is suffixed. Default is zero. Used only for cascading. -.IP "\-incy \fIarg\fP" -Specifies a vertical increment which is successively added to cascaded -windows. \fIarg\fP is a percentage of screen height, or pixel value -if a \fIp\fP is suffixed. Default is zero. Used only for cascading. - +Tile across the screen first, and then downward. Without this option the module +tiles vertically. +.IP "\-incx \fIvalue\fP" +Add \fIvalue\fP to the horizontal offset between cascaded windows. The value +is taken as a percentage of the screen width unless suffixed with \fIp\fP, in +which case it is a pixel amount. +.IP "\-incy \fIvalue\fP" +Add \fIvalue\fP to the vertical offset between cascaded windows. Percentages +are relative to the screen height; appending \fIp\fP forces interpretation as +pixels. .IP \-m -Causes maximized windows to also be affected (implied by \-all). -.IP "\-mn \fIarg\fP" -Tiles up to \fIarg\fP windows in tile direction. If more windows -exist, a new direction row or column is created (in effect, a matrix -is created). Used only when tiling windows. +Include maximised windows in the operation (this is implied by \-a). +.IP "\-mn \fIcount\fP" +Limit each tile row or column to \fIcount\fP windows before starting another +row or column. Only meaningful when tiling. .IP \-noraise -Inhibits window raising, leaving the depth ordering intact. +Do not alter the stacking order of affected clients. .IP \-noresize -Inhibits window resizing, leaving window sizes intact. This is the default -when cascading windows. +Preserve existing window sizes. This is the implicit default when cascading. .IP \-nostretch -If tiling: inhibits window growth to fit tile. Windows are shrunk to fit the -tile but not expanded. - -If cascading: inhibits window expansion when using the \-resize option. Windows -will only shrink to fit the maximal width and height (if given). +While tiling, only shrink windows to fit their cells; never enlarge them. While +cascading, do not expand windows beyond the specified maximum size when +\-resize is active. .IP \-r -Reverses the window sequence. +Reverse the sequence in which windows are processed. .IP \-resize -Forces all windows to resize to the constrained width and height (if -given). This is the default when tiling windows. +Force clients to adopt the requested tiling or cascade dimensions. This is the +default when tiling. .IP \-s -Causes sticky windows to also be affected (implied by \-all). +Consider sticky windows along with normal clients (also implied by \-a). .IP \-t -Causes transient windows to also be affected (implied by \-all). +Include transient windows (implied by \-a). .IP \-tile -Tile windows. This argument must be the first on the command line. +Tile windows. If supplied it must appear before other options. .IP \-u -Causes untitled windows to also be affected (implied by \-all). - -Up to four numbers can be placed on the command line that are not -switches. The first pair specify an x and y offset to start the first -window (default is 0, 0). -The meaning of the second pair depends on operation mode: - -When tiling windows it specifies an absolute coordinate reference -denoting the lower right bounding box for tiling. - -When cascading it specifies a maximal width and height for the layered -windows. If an affected window exceeds either this width or height, it -is resized to the maximal width or height. - -If any number is suffixed with the letter p, then it is taken to be a -pixel value, otherwise it is interpreted as a screen percentage. -Specifying zero for any parameter is equivalent to not specifying it. - -.SH BUGS -It is probably not a good idea to delete windows while windows are -being rearranged. - +Include untitled windows (implied by \-a). +.PP +You may supply up to four additional numeric arguments. The first two numbers +specify the initial X and Y offsets, in percentages of the screen size unless +they end with \fIp\fP to denote pixels. The interpretation of the third and +fourth numbers varies with the chosen mode: +.RS +.TP +Tiling +The third and fourth parameters represent the lower-right corner of the tiling +bounding box. +.TP +Cascading +The third value caps the window width and the fourth value caps the height. A +window that exceeds either limit is resized down to the limit. +.RE +.PP +Supplying zero for any numeric parameter leaves the corresponding default in +place. .SH AUTHORS Andrew Veliath (original FvwmTile and FvwmCascade modules) -Dominik Vogt (merged FvwmTile and FvwmCascade to FvwmRearrange) +Dominik Vogt (merged FvwmTile and FvwmCascade into FvwmRearrange) +David Uhden Collado (Complete rewrite and modernization) Index: fvwm/modules/FvwmRearrange/FvwmRearrange.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/modules/FvwmRearrange/FvwmRearrange.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/modules/FvwmRearrange/FvwmRearrange.c --- fvwm/modules/FvwmRearrange/FvwmRearrange.c +++ fvwm/modules/FvwmRearrange/FvwmRearrange.c @@ -1,40 +1,34 @@ /* - * FvwmRearrange.c -- fvwm module to arrange windows + * FvwmRearrange: fvwm module to tile or cascade windows in a region. * - * Copyright (C) 1996, 1997, 1998, 1999 Andrew T. Veliath + * Copyright (c) 2025-2026 David Uhden Collado * - * Version 1.0 + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Combined FvwmTile and FvwmCascade to FvwmRearrange module. - * 9-Nov-1998 Dominik Vogt + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include "config.h" +#include +#include + +#include +#include #include #include -#include #include -#include -#include #include -#include -#ifdef HAVE_SYS_BSDTYPES_H -#include +#include "config.h" +#include "../../fvwm/fvwm_sandbox.h" + #endif #if HAVE_SYS_SELECT_H @@ -43,587 +37,832 @@ #include -#include "fvwmlib.h" -#include "../../fvwm/module.h" #include "../../fvwm/fvwm.h" +#include "../../fvwm/module.h" +#include "fvwmlib.h" -typedef struct window_item { - Window frame; - int th, bw; - unsigned long width, height; - struct window_item *prev, *next; -} window_item, *window_list; - -/* vars */ -Display *dpy; -int dwidth, dheight; -char *argv0; -int fd[2], fd_width; -window_list wins = NULL, wins_tail = NULL; -int wins_count = 0; -FILE *console; - -/* switches */ -int ofsx = 0, ofsy = 0; -int maxw = 0, maxh = 0; -int maxx, maxy; -int untitled = 0, transients = 0; -int maximized = 0; -int all = 0; -int desk = 0; -int reversed = 0, raise_window = 1; -int resize = 0; -int nostretch = 0; -int sticky = 0; -int flatx = 0, flaty = 0; -int incx = 0, incy = 0; -int horizontal = 0; -int maxnum = 0; - -char FvwmTile; -char FvwmCascade; - -void insert_window_list(window_list *wl, window_item *i) +void DeadPipe(int sig); + +typedef struct ClientNode { + Window frame; + int title_height; + int border_width; + unsigned long width; + unsigned long height; + struct ClientNode *prev; + struct ClientNode *next; +} ClientNode; + +typedef struct ModuleState { + Display *display; + int screen_width; + int screen_height; + char *program_name; + int pipe_fd[2]; + int fd_width; + ClientNode *head; + ClientNode *tail; + int client_count; + FILE *log; + int offset_x; + int offset_y; + int limit_width; + int limit_height; + int bound_x; + int bound_y; + int include_untitled; + int include_transients; + int include_maximized; + int include_sticky; + int include_all; + int entire_desk; + int reverse_order; + int raise_clients; + int resize_clients; + int avoid_stretch; + int flat_x; + int flat_y; + int step_x; + int step_y; + int tile_horizontal; + int tile_limit; + char run_tile; + char run_cascade; +} ModuleState; + +static ModuleState g_state = {.raise_clients = 1}; + +static void +prepend_client(ModuleState *state, ClientNode *node) { - if (*wl) { - if ((i->prev = (*wl)->prev)) - i->prev->next = i; - i->next = *wl; - (*wl)->prev = i; - } else - i->next = i->prev = NULL; - *wl = i; + node->prev = NULL; + node->next = state->head; + if (state->head) { + state->head->prev = node; + } else { + state->tail = node; + } + state->head = node; + ++state->client_count; } -void free_window_list(window_list *wl) +static void +release_clients(ModuleState *state) { - window_item *q; - while (*wl) { - q = *wl; - *wl = (*wl)->next; - free(q); - } + ClientNode *cursor = state->head; + while (cursor) { + ClientNode *next = cursor->next; + free(cursor); + cursor = next; + } + state->head = NULL; + state->tail = NULL; + state->client_count = 0; } -int is_suitable_window(unsigned long *body) +static ClientNode * +find_client(ModuleState *state, Window frame) { - XWindowAttributes xwa; - unsigned long flags = body[8]; - - if ((flags&WINDOWLISTSKIP) && !all) - return 0; - - if ((flags&MAXIMIZED) && !maximized) - return 0; - - if ((flags&STICKY) && !sticky) - return 0; - - if (!XGetWindowAttributes(dpy, (Window)body[1], &xwa)) - return 0; - - if (xwa.map_state != IsViewable) - return 0; + for (ClientNode *cursor = state->head; cursor; cursor = cursor->next) { + if (cursor->frame == frame) { + return cursor; + } + } + return NULL; +} - if (!(flags&MAPPED)) - return 0; +static void +detach_client(ModuleState *state, ClientNode *node) +{ + if (!node) { + return; + } + if (node->prev) { + node->prev->next = node->next; + } else { + state->head = node->next; + } + if (node->next) { + node->next->prev = node->prev; + } else { + state->tail = node->prev; + } + free(node); + --state->client_count; +} - if (flags&ICONIFIED) - return 0; +static int +window_matches(ModuleState *state, unsigned long *body) +{ + unsigned long flags = body[8]; + XWindowAttributes xwa; - if (!desk) { - int x = (int)body[3], y = (int)body[4]; - int w = (int)body[5], h = (int)body[6]; - if (!((x < dwidth) && (y < dheight) - && (x + w > 0) && (y + h > 0))) - return 0; - } - - if (!(flags&TITLE) && !untitled) - return 0; + if ((flags & WINDOWLISTSKIP) && !state->include_all) { + return 0; + } + if ((flags & MAXIMIZED) && !state->include_maximized) { + return 0; + } + if ((flags & STICKY) && !state->include_sticky) { + return 0; + } + if (!XGetWindowAttributes(state->display, (Window)body[1], &xwa)) { + return 0; + } + if (xwa.map_state != IsViewable) { + return 0; + } + if (!(flags & MAPPED)) { + return 0; + } + if (flags & ICONIFIED) { + return 0; + } + if (!state->entire_desk) { + int x = (int)body[3]; + int y = (int)body[4]; + int w = (int)body[5]; + int h = (int)body[6]; + if (!((x < state->screen_width) && (y < state->screen_height) && + (x + w > 0) && (y + h > 0))) { + return 0; + } + } + if (!(flags & TITLE) && !state->include_untitled) { + return 0; + } + if ((flags & TRANSIENT) && !state->include_transients) { + return 0; + } + return 1; +} - if ((flags&TRANSIENT) && !transients) - return 0; +static int +collect_client(ModuleState *state) +{ + unsigned long header[HEADER_SIZE]; + unsigned long *body; + fd_set infds; + int keep_running = 1; + + FD_ZERO(&infds); + FD_SET(state->pipe_fd[1], &infds); + select(state->fd_width, &infds, NULL, NULL, NULL); + + if (ReadFvwmPacket(state->pipe_fd[1], header, &body) > 0) { + switch (header[1]) { + case M_CONFIGURE_WINDOW: + if (window_matches(state, body)) { + ClientNode *node = (ClientNode *)xmalloc( + sizeof(ClientNode)); + node->frame = (Window)body[1]; + node->title_height = (int)body[9]; + node->border_width = (int)body[10]; + node->width = body[5]; + node->height = body[6]; + prepend_client(state, node); + } + break; + case M_DESTROY_WINDOW: + if (body) { + ClientNode *node = + find_client(state, (Window)body[1]); + if (node) { + detach_client(state, node); + } + } + break; + case M_END_WINDOWLIST: + keep_running = 0; + break; + default: + fprintf(state->log, + "%s: internal inconsistency: unknown message\n", + state->program_name); + break; + } + free(body); + } else { + keep_running = 0; + } - return 1; + return keep_running; } -int get_window(void) +static int +await_configure(ModuleState *state, ClientNode *node) { - unsigned long header[HEADER_SIZE], *body; - int count, last = 0; - fd_set infds; - FD_ZERO(&infds); - FD_SET(fd[1], &infds); - select(fd_width,&infds, 0, 0, NULL); - if ((count = ReadFvwmPacket(fd[1],header,&body)) > 0) { - switch (header[1]) - { - case M_CONFIGURE_WINDOW: - if (is_suitable_window(body)) { - window_item *wi = - (window_item*)safemalloc(sizeof( window_item )); - wi->frame = (Window)body[1]; - wi->th = (int)body[9]; - wi->bw = (int)body[10]; - wi->width = body[5]; - wi->height = body[6]; - if (!wins_tail) wins_tail = wi; - insert_window_list(&wins, wi); - ++wins_count; - } - last = 1; - break; - - case M_END_WINDOWLIST: - break; - - default: - fprintf(console, - "%s: internal inconsistency: unknown message\n", - argv0); - break; - } - free(body); - } - return last; + for (;;) { + unsigned long header[HEADER_SIZE]; + unsigned long *body; + fd_set infds; + + FD_ZERO(&infds); + FD_SET(state->pipe_fd[1], &infds); + select(state->fd_width, &infds, NULL, NULL, NULL); + + if (ReadFvwmPacket(state->pipe_fd[1], header, &body) > 0) { + switch (header[1]) { + case M_CONFIGURE_WINDOW: + if (body && (Window)body[1] == node->frame) { + free(body); + return 1; + } + break; + case M_DESTROY_WINDOW: + if (body) { + Window frame = (Window)body[1]; + if (frame == node->frame) { + free(body); + return 0; + } + ClientNode *other = + find_client(state, frame); + if (other) { + detach_client(state, other); + } + } + break; + case M_END_WINDOWLIST: + break; + default: + break; + } + free(body); + } else { + return 0; + } + } } -void wait_configure(window_item *wi) +static int +parse_metric(const char *token, unsigned long reference) { - int found = 0; - unsigned long header[HEADER_SIZE], *body; - int count; - fd_set infds; - FD_ZERO(&infds); - FD_SET(fd[1], &infds); - select(fd_width,&infds, 0, 0, NULL); - while (!found) - if ((count = ReadFvwmPacket(fd[1],header,&body)) > 0) { - if ((header[1] == M_CONFIGURE_WINDOW) - && (Window)body[1] == wi->frame) - found = 1; - free(body); + char *endptr; + long value; + + if (!token || !*token) { + return 0; + } + + value = strtol(token, &endptr, 10); + if (endptr && *endptr && isalpha((unsigned char)*endptr)) { + return (int)value; } + return (int)((value * (long)reference) / 100); } -int atopixel(char *s, unsigned long f) +static void +send_resize(ModuleState *state, const ClientNode *node, unsigned long width, + unsigned long height) { - int l = strlen(s); - if (l < 1) return 0; - if (isalpha(s[l - 1])) { - char s2[24]; - strcpy(s2,s); - s2[strlen(s2) - 1] = 0; - return atoi(s2); - } - return (atoi(s) * f) / 100; + char command[128]; + + snprintf(command, sizeof(command), "Resize %lup %lup", width, height); + SendInfo(state->pipe_fd, command, node->frame); } -void tile_windows(void) +static void +send_move(ModuleState *state, const ClientNode *node, int x, int y) { - char msg[128]; - int cur_x = ofsx, cur_y = ofsy; - int wdiv, hdiv, i, j, count = 1; - window_item *w = reversed ? wins_tail : wins; - - if (horizontal) { - if ((maxnum > 0) && (maxnum < wins_count)) { - count = wins_count / maxnum; - if (wins_count % maxnum) ++count; - hdiv = (maxy - ofsy + 1) / maxnum; - } else { - maxnum = wins_count; - hdiv = (maxy - ofsy + 1) / wins_count; - } - wdiv = (maxx - ofsx + 1) / count; - - for (i = 0; w && (i < count); ++i) { - for (j = 0; w && (j < maxnum); ++j) { - int nw = wdiv - w->bw * 2; - int nh = hdiv - w->bw * 2 - w->th; - - if (resize) { - if (nostretch) { - if (nw > w->width) - nw = w->width; - if (nh > w->height) - nh = w->height; - } - sprintf(msg, "Resize %lup %lup", - (nw > 0) ? nw : w->width, - (nh > 0) ? nh : w->height); - SendInfo(fd,msg,w->frame); + char command[128]; + + snprintf(command, sizeof(command), "Move %up %up", x, y); + SendInfo(state->pipe_fd, command, node->frame); +} + +static void +tile_clients(ModuleState *state) +{ + ClientNode *cursor = state->reverse_order ? state->tail : state->head; + int stripes = 1; + int slots_per_stripe; + int wdiv; + int hdiv; + int current_x = state->offset_x; + int current_y = state->offset_y; + int limit = state->tile_limit; + + if (state->tile_horizontal) { + if ((limit > 0) && (limit < state->client_count)) { + stripes = state->client_count / limit; + if (state->client_count % limit) { + ++stripes; + } + hdiv = (state->bound_y - state->offset_y + 1) / limit; + } else { + limit = state->client_count; + state->tile_limit = limit; + hdiv = (state->bound_y - state->offset_y + 1) / + state->client_count; + } + slots_per_stripe = limit; + wdiv = (state->bound_x - state->offset_x + 1) / stripes; + + for (int s = 0; cursor && (s < stripes); ++s) { + for (int slot = 0; cursor && (slot < slots_per_stripe); + ++slot) { + int new_width = wdiv - cursor->border_width * 2; + int new_height = hdiv - + cursor->border_width * 2 - + cursor->title_height; + + if (state->resize_clients) { + if (state->avoid_stretch) { + if (new_width > + (int)cursor->width) { + new_width = + (int)cursor->width; + } + if (new_height > + (int)cursor->height) { + new_height = + (int)cursor->height; + } + } + send_resize(state, cursor, + (new_width > 0) ? + (unsigned long)new_width : + cursor->width, + (new_height > 0) ? + (unsigned long)new_height : + cursor->height); + } + + send_move(state, cursor, current_x, current_y); + if (state->raise_clients) { + SendInfo(state->pipe_fd, "Raise", + cursor->frame); + } + + current_y += hdiv; + { + int alive = + await_configure(state, cursor); + ClientNode *next = state->reverse_order + ? + cursor->prev : cursor->next; + if (!alive) { + detach_client(state, cursor); + } + cursor = next; + } + } + current_x += wdiv; + current_y = state->offset_y; } - sprintf(msg, "Move %up %up", cur_x, cur_y); - SendInfo(fd,msg,w->frame); - if (raise_window) - SendInfo(fd,"Raise",w->frame); - cur_y += hdiv; - wait_configure(w); - w = reversed ? w->prev : w->next; - } - cur_x += wdiv; - cur_y = ofsy; - } - } else { - if ((maxnum > 0) && (maxnum < wins_count)) { - count = wins_count / maxnum; - if (wins_count % maxnum) ++count; - wdiv = (maxx - ofsx + 1) / maxnum; } else { - maxnum = wins_count; - wdiv = (maxx - ofsx + 1) / wins_count; - } - hdiv = (maxy - ofsy + 1) / count; - - for (i = 0; w && (i < count); ++i) { - for (j = 0; w && (j < maxnum); ++j) { - int nw = wdiv - w->bw * 2; - int nh = hdiv - w->bw * 2 - w->th; - - if (resize) { - if (nostretch) { - if (nw > w->width) - nw = w->width; - if (nh > w->height) - nh = w->height; - } - sprintf(msg, "Resize %lup %lup", - (nw > 0) ? nw : w->width, - (nh > 0) ? nh : w->height); - SendInfo(fd,msg,w->frame); + if ((limit > 0) && (limit < state->client_count)) { + stripes = state->client_count / limit; + if (state->client_count % limit) { + ++stripes; + } + wdiv = (state->bound_x - state->offset_x + 1) / limit; + } else { + limit = state->client_count; + state->tile_limit = limit; + wdiv = (state->bound_x - state->offset_x + 1) / + state->client_count; } - sprintf(msg, "Move %up %up", cur_x, cur_y); - SendInfo(fd,msg,w->frame); - if (raise_window) - SendInfo(fd,"Raise",w->frame); - cur_x += wdiv; - wait_configure(w); - w = reversed ? w->prev : w->next; - } - cur_x = ofsx; - cur_y += hdiv; - } - } + slots_per_stripe = limit; + hdiv = (state->bound_y - state->offset_y + 1) / stripes; + + for (int s = 0; cursor && (s < stripes); ++s) { + for (int slot = 0; cursor && (slot < slots_per_stripe); + ++slot) { + int new_width = wdiv - cursor->border_width * 2; + int new_height = hdiv - + cursor->border_width * 2 - + cursor->title_height; + + if (state->resize_clients) { + if (state->avoid_stretch) { + if (new_width > + (int)cursor->width) { + new_width = + (int)cursor->width; + } + if (new_height > + (int)cursor->height) { + new_height = + (int)cursor->height; + } + } + send_resize(state, cursor, + (new_width > 0) ? + (unsigned long)new_width : + cursor->width, + (new_height > 0) ? + (unsigned long)new_height : + cursor->height); + } + + send_move(state, cursor, current_x, current_y); + if (state->raise_clients) { + SendInfo(state->pipe_fd, "Raise", + cursor->frame); + } + + current_x += wdiv; + { + int alive = + await_configure(state, cursor); + ClientNode *next = state->reverse_order + ? + cursor->prev : cursor->next; + if (!alive) { + detach_client(state, cursor); + } + cursor = next; + } + } + current_x = state->offset_x; + current_y += hdiv; + } + } } -void cascade_windows(void) +static void +cascade_clients(ModuleState *state) { - char msg[128]; - int cur_x = ofsx, cur_y = ofsy; - window_item *w = reversed ? wins_tail : wins; - while (w) - { - unsigned long nw = 0, nh = 0; - if (raise_window) - SendInfo(fd,"Raise",w->frame); - sprintf(msg, "Move %up %up", cur_x, cur_y); - SendInfo(fd,msg,w->frame); - if (resize) { - if (nostretch) { - if (maxw - && (w->width > maxw)) - nw = maxw; - if (maxh - && (w->height > maxh)) - nh = maxh; - } else { - nw = maxw; - nh = maxh; - } - if (nw || nh) { - sprintf(msg, "Resize %lup %lup", - nw ? nw : w->width, - nh ? nh : w->height); - SendInfo(fd,msg,w->frame); - } - } - wait_configure(w); - if (!flatx) - cur_x += w->bw; - cur_x += incx; - if (!flaty) - cur_y += w->bw + w->th; - cur_y += incy; - w = reversed ? w->prev : w->next; - } + ClientNode *cursor = state->reverse_order ? state->tail : state->head; + int current_x = state->offset_x; + int current_y = state->offset_y; + + while (cursor) { + unsigned long target_width = 0; + unsigned long target_height = 0; + int advance_x = state->step_x; + int advance_y = state->step_y; + + if (state->raise_clients) { + SendInfo(state->pipe_fd, "Raise", cursor->frame); + } + + send_move(state, cursor, current_x, current_y); + + if (state->resize_clients) { + if (state->avoid_stretch) { + if (state->limit_width && + cursor->width > + (unsigned long)state->limit_width) { + target_width = + (unsigned long)state->limit_width; + } + if (state->limit_height && + cursor->height > + (unsigned long)state->limit_height) { + target_height = + (unsigned long)state->limit_height; + } + } else { + target_width = state->limit_width; + target_height = state->limit_height; + } + + if (target_width || target_height) { + send_resize(state, cursor, + target_width ? target_width : cursor->width, + target_height ? target_height : + cursor->height); + } + } + + if (!state->flat_x) { + advance_x += cursor->border_width; + } + if (!state->flat_y) { + advance_y += + cursor->border_width + cursor->title_height; + } + + { + int alive = await_configure(state, cursor); + ClientNode *next = + state->reverse_order ? cursor->prev : cursor->next; + if (!alive) { + detach_client(state, cursor); + } + cursor = next; + } + + current_x += advance_x; + current_y += advance_y; + } } -void parse_args(char *s, int argc, char *argv[], int argi) +static void +parse_arguments(ModuleState *state, const char *source, int argc, char *argv[], + int start_index) { - int nsargc = 0; - /* parse args */ - for (; argi < argc; ++argi) - { - if (!strcmp(argv[argi],"-tile") || !strcmp(argv[argi],"-cascade")) { - /* ignore */ - } - else if (!strcmp(argv[argi],"-u")) { - untitled = 1; - } - else if (!strcmp(argv[argi],"-t")) { - transients = 1; - } - else if (!strcmp(argv[argi], "-a")) { - all = untitled = transients = maximized = 1; - if (FvwmCascade) - sticky = 1; - } - else if (!strcmp(argv[argi], "-r")) { - reversed = 1; - } - else if (!strcmp(argv[argi], "-noraise")) { - raise_window = 0; - } - else if (!strcmp(argv[argi], "-noresize")) { - resize = 0; - } - else if (!strcmp(argv[argi], "-nostretch")) { - nostretch = 1; - } - else if (!strcmp(argv[argi], "-desk")) { - desk = 1; - } - else if (!strcmp(argv[argi], "-flatx")) { - flatx = 1; - } - else if (!strcmp(argv[argi], "-flaty")) { - flaty = 1; - } - else if (!strcmp(argv[argi], "-r")) { - reversed = 1; - } - else if (!strcmp(argv[argi], "-h")) { - horizontal = 1; - } - else if (!strcmp(argv[argi], "-m")) { - maximized = 1; - } - else if (!strcmp(argv[argi], "-s")) { - sticky = 1; - } - else if (!strcmp(argv[argi], "-mn") && ((argi + 1) < argc)) { - maxnum = atoi(argv[++argi]); - } - else if (!strcmp(argv[argi], "-resize")) { - resize = 1; - } - else if (!strcmp(argv[argi], "-nostretch")) { - nostretch = 1; - } - else if (!strcmp(argv[argi], "-incx") && ((argi + 1) < argc)) { - incx = atopixel(argv[++argi], dwidth); - } - else if (!strcmp(argv[argi], "-incy") && ((argi + 1) < argc)) { - incy = atopixel(argv[++argi], dheight); - } - else { - if (++nsargc > 4) { - fprintf(console, - "%s: %s: ignoring unknown arg %s\n", - argv0, s, argv[argi]); - continue; - } - if (nsargc == 1) { - ofsx = atopixel(argv[argi], dwidth); - } else if (nsargc == 2) { - ofsy = atopixel(argv[argi], dheight); - } else if (nsargc == 3) { - if (FvwmCascade) - maxw = atopixel(argv[argi], dwidth); - else /* FvwmTile */ - maxx = atopixel(argv[argi], dwidth); - } else if (nsargc == 4) { - if (FvwmCascade) - maxh = atopixel(argv[argi], dheight); - else /* FvwmTile */ - maxy = atopixel(argv[argi], dheight); - } - } - } + int positional = 0; + + for (int i = start_index; i < argc; ++i) { + const char *arg = argv[i]; + + if (!strcmp(arg, "-tile") || !strcmp(arg, "-cascade")) { + continue; + } else if (!strcmp(arg, "-u")) { + state->include_untitled = 1; + } else if (!strcmp(arg, "-t")) { + state->include_transients = 1; + } else if (!strcmp(arg, "-a")) { + state->include_all = 1; + state->include_untitled = 1; + state->include_transients = 1; + state->include_maximized = 1; + if (state->run_cascade) { + state->include_sticky = 1; + } + } else if (!strcmp(arg, "-r")) { + state->reverse_order = 1; + } else if (!strcmp(arg, "-noraise")) { + state->raise_clients = 0; + } else if (!strcmp(arg, "-noresize")) { + state->resize_clients = 0; + } else if (!strcmp(arg, "-nostretch")) { + state->avoid_stretch = 1; + } else if (!strcmp(arg, "-desk")) { + state->entire_desk = 1; + } else if (!strcmp(arg, "-flatx")) { + state->flat_x = 1; + } else if (!strcmp(arg, "-flaty")) { + state->flat_y = 1; + } else if (!strcmp(arg, "-h")) { + state->tile_horizontal = 1; + } else if (!strcmp(arg, "-m")) { + state->include_maximized = 1; + } else if (!strcmp(arg, "-s")) { + state->include_sticky = 1; + } else if (!strcmp(arg, "-mn") && ((i + 1) < argc)) { + state->tile_limit = atoi(argv[++i]); + } else if (!strcmp(arg, "-resize")) { + state->resize_clients = 1; + } else if (!strcmp(arg, "-incx") && ((i + 1) < argc)) { + state->step_x = + parse_metric(argv[++i], state->screen_width); + } else if (!strcmp(arg, "-incy") && ((i + 1) < argc)) { + state->step_y = + parse_metric(argv[++i], state->screen_height); + } else { + ++positional; + if (positional > 4) { + fprintf(state->log, + "%s: %s: ignoring unknown arg %s\n", + state->program_name, source, arg); + continue; + } + + if (positional == 1) { + state->offset_x = + parse_metric(arg, state->screen_width); + } else if (positional == 2) { + state->offset_y = + parse_metric(arg, state->screen_height); + } else if (positional == 3) { + if (state->run_cascade) { + state->limit_width = parse_metric( + arg, state->screen_width); + } else { + state->bound_x = parse_metric( + arg, state->screen_width); + } + } else if (positional == 4) { + if (state->run_cascade) { + state->limit_height = parse_metric( + arg, state->screen_height); + } else { + state->bound_y = parse_metric( + arg, state->screen_height); + } + } + } + } } #ifdef USERC -int parse_line(char *s, char ***args) +static int +tokenise_config(char *line, char ***argv_out) { - int count = 0, i = 0; - char *arg_save[48]; - strtok(s, " "); - while ((s = strtok(NULL, " "))) - arg_save[count++] = s; - *args = (char **)safemalloc(sizeof( char * ) * count); - for (; i < count; ++i) - (*args)[i] = arg_save[i]; - return count; + char *tokens[48]; + int count = 0; + char *cursor = strtok(line, " \t"); + + while (cursor && count < 48) { + cursor = strtok(NULL, " \t"); + if (!cursor) { + break; + } + tokens[count++] = cursor; + } + + if (count > 0) { + *argv_out = (char **)xmalloc(sizeof(char *) * count); + for (int i = 0; i < count; ++i) { + (*argv_out)[i] = tokens[i]; + } + } else { + *argv_out = NULL; + } + + return count; } #ifdef FVWM1 -char *GetConfigLine(char *filename, char *match) +static char * +LoadConfigLine(const char *filename, const char *match) { - FILE *f = fopen(filename, "r"); - if (f) { - int l = strlen(match), found = 0; - char line[256], *s = line; - line[0] = 0; - s = fgets(line, 256, f); - while (s && !found) { - if (strncmp(line, match, l) == 0) { - found = 1; - break; - } - s = fgets(line, 256, f); - } - fclose(f); - if (found) { - char *ret; - int l2 = strlen(line); - ret = (char *)safemalloc(sizeof(char) * l2); - strcpy(ret, line); - if (ret[l2 - 1] == '\n') - ret[l2 - 1] = 0; - return ret; - } else - return NULL; - } else + FILE *f = fopen(filename, "r"); + if (f) { + char line[256]; + size_t match_len = strlen(match); + + while (fgets(line, sizeof(line), f)) { + if (strncmp(line, match, match_len) == 0) { + size_t len = strlen(line); + char *copy = (char *)xmalloc(len + 1); + + strcpy(copy, line); + if (len && copy[len - 1] == '\n') { + copy[len - 1] = '\0'; + } + fclose(f); + return copy; + } + } + fclose(f); + } return NULL; } #endif /* FVWM1 */ #endif /* USERC */ -void DeadPipe(int sig) { exit(0); } +static void +handle_sigpipe(int sig) +{ + (void)sig; + exit(0); +} -int main(int argc, char *argv[]) +int +main(int argc, char *argv[]) { + ModuleState *state = &g_state; + #ifdef USERC - char match[128]; - int config_line_count, len; - char *config_line; + char match[128]; + char *config_line; #endif - console = fopen("/dev/console","w"); - if (!console) console = stderr; + state->log = fopen("/dev/console", "w"); + if (!state->log) { + state->log = stderr; + } - if (!(argv0 = strrchr(argv[0],'/'))) - argv0 = argv[0]; - else - ++argv0; + state->program_name = strrchr(argv[0], '/'); + state->program_name = + state->program_name ? state->program_name + 1 : argv[0]; - if (argc < 6) { - fprintf(stderr, + if (argc < 6) { #ifdef FVWM1 - "%s: module should be executed by fvwm only\n", + fprintf(stderr, "%s: module should be executed by fvwm only\n", + state->program_name); #else - "%s: module should be executed by fvwm2 only\n", + fprintf(stderr, "%s: module should be executed by fvwm2 only\n", + state->program_name); #endif - argv0); - exit(-1); - } - - fd[0] = atoi(argv[1]); - fd[1] = atoi(argv[2]); - - if (!(dpy = XOpenDisplay(NULL))) { - fprintf(console, "%s: couldn't open display %s\n", - argv0, - XDisplayName(NULL)); - exit(-1); - } - signal (SIGPIPE, DeadPipe); - - { - int s = DefaultScreen(dpy); - dwidth = DisplayWidth(dpy, s); - dheight = DisplayHeight(dpy, s); - } - - fd_width = GetFdWidth(); - + exit(1); + } + + state->pipe_fd[0] = atoi(argv[1]); + state->pipe_fd[1] = atoi(argv[2]); + + state->display = XOpenDisplay(NULL); + if (!state->display) { + fprintf(state->log, "%s: couldn't open display %s\n", + state->program_name, XDisplayName(NULL)); + exit(1); + } + + signal(SIGPIPE, handle_sigpipe); + + { + int screen = DefaultScreen(state->display); + state->screen_width = DisplayWidth(state->display, screen); + state->screen_height = DisplayHeight(state->display, screen); + } + + state->fd_width = GetFdWidth(); + #ifdef USERC - strcpy(match, "*"); - strcat(match, argv0); - len = strlen(match); + strlcpy(match, "*", sizeof(match)); + strlcat(match, state->program_name, sizeof(match)); + #ifdef FVWM1 - if ((config_line = GetConfigLine(argv[3], match))) { - char **args = NULL; - config_line_count = parse_line(config_line, &args); - parse_args("config args", - config_line_count, args, 0); - free(config_line); - free(args); - } + config_line = LoadConfigLine(argv[3], match); + if (config_line) { + char **args = NULL; + int arg_count = tokenise_config(config_line, &args); + + parse_arguments(state, "config args", arg_count, args, 0); + free(args); + free(config_line); + } #else - GetConfigLine(fd, &config_line); - while (config_line != NULL) { - if (strncmp(match,config_line,len)==0) { - char **args = NULL; - int cllen = strlen(config_line); - if (config_line[cllen - 1] == '\n') - config_line[cllen - 1] = 0; - config_line_count = parse_line(config_line, &args); - parse_args("config args", - config_line_count, args, 0); - free(args); - } - GetConfigLine(fd, &config_line); - } + GetConfigLine(state->pipe_fd, &config_line); + while (config_line) { + if (strncmp(match, config_line, strlen(match)) == 0) { + char **args = NULL; + int len = strlen(config_line); + if (len && config_line[len - 1] == '\n') { + config_line[len - 1] = '\0'; + } + { + int arg_count = + tokenise_config(config_line, &args); + parse_arguments( + state, "config args", arg_count, args, 0); + free(args); + } + } + GetConfigLine(state->pipe_fd, &config_line); + } #endif /* FVWM1 */ #endif /* USERC */ - if (strcmp(argv0, "FvwmCascade") && (!strcmp(argv0, "FvwmTile") || - (argc >= 7 && !strcmp(argv[6], "-tile")))) - { - FvwmTile = 1; - FvwmCascade = 0; - resize = 1; - } - else - { - FvwmCascade = 1; - FvwmTile = 0; - resize = 0; - } - parse_args("module args", argc, argv, 6); + if (strcmp(state->program_name, "FvwmCascade") && + (!strcmp(state->program_name, "FvwmTile") || + (argc >= 7 && !strcmp(argv[6], "-tile")))) { + state->run_tile = 1; + state->run_cascade = 0; + state->resize_clients = 1; + } else { + state->run_cascade = 1; + state->run_tile = 0; + state->resize_clients = 0; + } + + parse_arguments(state, "module args", argc, argv, 6); #ifdef FVWM1 - { - char msg[256]; - sprintf(msg, "SET_MASK %lu\n",(unsigned long)( - M_CONFIGURE_WINDOW| - M_END_WINDOWLIST - )); - SendInfo(fd,msg,0); - + { + char msg[256]; + snprintf(msg, sizeof(msg), "SET_MASK %lu\n", + (unsigned long)(M_CONFIGURE_WINDOW | M_DESTROY_WINDOW | + M_END_WINDOWLIST)); + SendInfo(state->pipe_fd, msg, 0); + #ifdef FVWM1_MOVENULL - /* avoid interactive placement in fvwm version 1 */ - if (!ofsx) ++ofsx; - if (!ofsy) ++ofsy; + if (!state->offset_x) { + ++state->offset_x; + } + if (!state->offset_y) { + ++state->offset_y; + } #endif - } + } #else - SetMessageMask(fd, - M_CONFIGURE_WINDOW - | M_END_WINDOWLIST - ); + SetMessageMask(state->pipe_fd, + M_CONFIGURE_WINDOW | M_DESTROY_WINDOW | M_END_WINDOWLIST); #endif - if (FvwmTile) - { - if (!maxx) maxx = dwidth; - if (!maxy) maxy = dheight; - } - - SendInfo(fd,"Send_WindowList",0); - while (get_window()); - if (wins_count) - { - if (FvwmCascade) - cascade_windows(); - else /* FvwmTile */ - tile_windows(); - } - free_window_list(&wins); - if (console != stderr) - fclose(console); - return 0; + if (state->run_tile) { + if (!state->bound_x) { + state->bound_x = state->screen_width; + } + if (!state->bound_y) { + state->bound_y = state->screen_height; + } + } + + SendInfo(state->pipe_fd, "Send_WindowList", 0); + + sandbox_x11_config("FvwmRearrange"); + + while (collect_client(state)) { + /* keep reading until the end marker arrives */ + } + + if (state->client_count) { + if (state->run_cascade) { + cascade_clients(state); + } else { + tile_clients(state); + } + } + + release_clients(state); + + if (state->log != stderr) { + fclose(state->log); + } + + return 0; +} + +void +DeadPipe(int sig) +{ + (void)sig; + exit(0); }