Commit Graph
11 Commits
Author SHA1 Message Date
Haroldo Santos 558e67f303 WINGs: do not call memcpy() for empty data in WMCreateDataWithBytes()
WMCreateDataWithBytes() always copies 'length' bytes from 'bytes', even
when the length is zero. A caller creating an empty WMData naturally
passes a NULL pointer in that case, but passing NULL to memcpy() is
undefined behavior in C, even with a zero size, and static analyzers
report it.

Only copy when there is something to copy. The result is unchanged: the
data is created with the requested capacity and a length of zero.

Signed-off-by: Haroldo Santos <haroldo.santos@gmail.com>
2026-10-21 12:20:34 +01:00
Haroldo Santos 9c2b6865be wrlib: release context resources on RCreateContext() failure
RCreateContext() duplicates the attributes and creates a GC before it
validates the visual and sets up the colormap. Its failure paths only
called free(context), which leaks the attributes structure and the GC
each time a context cannot be created (bad visual ID, colormap setup
failure, gray scale allocation failure).

Use RDestroyContext() on these paths so that everything allocated so far
is released. Since the visual-ID failure happens before any drawable
window is created, make RDestroyContext() destroy the drawable only when
one exists, instead of calling XDestroyWindow() on None.

Signed-off-by: Haroldo Santos <haroldo.santos@gmail.com>
2026-10-21 12:20:34 +01:00
Haroldo Santos 0dd8b6a099 wrlib: check RCreateImage() result in RMakeTiledImage()
When the requested size is larger than the tile, RMakeTiledImage()
creates a new image with RCreateImage() and immediately writes to
image->data. RCreateImage() returns NULL when the allocation fails or
when the dimensions exceed its limit (20000 pixels), so a very large
background texture, or memory pressure, makes the caller crash instead
of getting an error.

The other branches of this function already return NULL on failure
(RCloneImage() and RGetSubImage()), and the callers handle a NULL
result, so return NULL here as well.

Signed-off-by: Haroldo Santos <haroldo.santos@gmail.com>
2026-10-21 12:20:34 +01:00
Haroldo Santos c0104d56bf wrlib: do not use the image cache when its allocation fails
init_cache() allocates RImageCache with malloc() for RImageCacheSize
entries. When the allocation fails it prints a warning and returns, but
leaves RImageCacheSize at its positive value.

RLoadImage() decides whether to use the cache by testing
RImageCacheSize > 0, so after such a failure every image load walks
RImageCache[i] through a NULL pointer and crashes. RReleaseCache()
likewise loops over the missing entries.

Reset RImageCacheSize to 0 when the allocation fails, so images are
simply loaded without caching, as already happens when the cache is
disabled by configuration.

Signed-off-by: Haroldo Santos <haroldo.santos@gmail.com>
2026-10-21 12:20:34 +01:00
Haroldo Santos 56ec56136f wmaker: fix NULL dereference in window shortcut with no focused window
The WKBD_WINDOW1..10 handler in dispatchWKBDCommand() receives 'wwin'
from handleKeyPress(), which takes it from scr->focused_window. That is
NULL when no window is focused, for instance on an empty workspace or
right after the last window was closed.

If the shortcut slot is empty and some windows are currently selected,
the last branch of the handler reads wwin->flags.selected without
checking wwin, so pressing the shortcut crashes the window manager.

Check that 'wwin' is not NULL before using it, as the other cases of
this function already do. Found with the clang static analyzer.

Signed-off-by: Haroldo Santos <haroldo.santos@gmail.com>
2026-10-21 12:20:34 +01:00
Haroldo SantosandCopilot 6c107e0ce5 wmsetbg: fix "X connection broken" crash when setting background
setPixmapProperty() called XKillClient(dpy, old_pixmap) to free the
previous background pixmap stored in _XROOTPMAP_ID.  The pixmap was
created by duplicatePixmap() via a short-lived second X connection
that used XSetCloseDownMode(RetainPermanent).  After that connection
closed, the X server eventually recycled its client ID for a new
connection.  If wmsetbg's own 'dpy' connection received that recycled
ID, XKillClient() would kill wmsetbg itself, causing the fatal error:

  X connection to :0 broken (explicit kill or server shutdown).

Fix by switching from RetainPermanent to RetainTemporary in
duplicatePixmap().  With RetainTemporary, background pixmaps are kept
alive for the lifetime of the X session and freed automatically at
logout — no explicit XKillClient() is needed.

Remove the now-dead XKillClient() block from setPixmapProperty():
- dummyErrorHandler() was only used to suppress its X errors; remove.
- The mode variable toggled PropModeReplace/PropModeAppend based on
  whether an old pixmap was present; since we always want to replace,
  use PropModeReplace unconditionally.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-06-15 17:29:07 +01:00
Haroldo SantosandCopilot 7c80e917d7 wmsetbg: fix memory leak of XGetWindowProperty data in setPixmapProperty
XGetWindowProperty() allocates a buffer and returns it via the 'data'
pointer; the caller is responsible for freeing it with XFree() when
done.  setPixmapProperty() read the old _XROOTPMAP_ID value but never
freed the returned buffer, leaking memory on every background change.

Add the missing XFree(data) call.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-06-15 17:29:07 +01:00
Haroldo be922384ac slight increase in default switch panel icon size to improve border view 2019-07-28 23:05:28 +01:00
Haroldo 31f16b65a3 higher resolution images for switch panel 2019-07-28 20:21:14 +01:00
Haroldo 3665410377 make switchpanel configurable 2019-07-14 17:43:28 +01:00
Haroldo Santos c82138eab9 switchpanel: Add skip_switchpanel advanced option
Some applications running in my machine are only background
windows, e.g.: screenlets showing CPU usage.

In current wmaker version all these applications pollute my
switchpanel, so I wrote this patch (thanks Carlos for the helping me).

It includes an additional advanced option for windows "Do not
include in switchpanel" which, if set, allows applications to
not appear in the switchpanel.

Signed-off-by: Haroldo Santos <haroldo.santos@gmail.com>
2011-02-17 19:29:15 +01:00