Home / Docs / Window Manager

Historical engineering note, architecture superseded, current facts inlined below. This is a point-in-time analysis snapshot written against kernel v1.8.2 (2026-02-07), and its central premise has since changed: kernel/gui/window.c's own compositing (wm_draw_all() / wm_draw_apps()) is now a fallback path only, used solely on the rare boot where the real desktop process is missing. The actual window manager MayteraOS runs today is a userland process, /APPS/COMPOSIT (built from userland/apps/compositor/, over 16,000 lines), spawned by kernel/gui/desktop.c's desktop_run(). The SYS_WIN_* syscall numbers below are still verified current (apps like Files, Calculator, and the browser all still create their windows through them), but the window-flags struct, the per-window settings menu, and the theme syscall numbers described further down are for the old kernel-side implementation and have since changed or moved into the userland compositor; corrections are inlined at each point below.

Window Manager Analysis - MayteraOS v1.8.2

Executive Summary

The MayteraOS window manager is a fully-featured system that provides:

  • Kernel-mode window management with user-mode application support
  • Full theme engine with multiple built-in themes and INI file loading
  • Per-window settings menu with opacity slider and locked checkbox
  • Complete syscall interface for userland applications

Architecture Overview

Kernel-Side Components

FilePurpose
kernel/gui/window.hWindow structures, flags, and API declarations
kernel/gui/window.cWindow manager implementation (1730 lines)
kernel/gui/theme.hEnhanced theme engine with 50+ color IDs
kernel/gui/theme.cTheme loading, switching, and drawing helpers
kernel/gui/widget.h/cWidget system (buttons, textboxes, etc.)
kernel/video/framebuffer.cGraphics primitives including alpha blending

Userland Components

FilePurpose
userland/libc/gui.cHigh-level GUI wrapper library
userland/libc/syscall.hWindow syscall definitions
userland/libc/compositor_client.cCompositor protocol client

Window Manager Features

1. Window Flags (window.h:20-32)

#define WINDOW_FLAG_VISIBLE     (1 << 0)   // Window is visible
#define WINDOW_FLAG_FOCUSED     (1 << 1)   // Window has focus
#define WINDOW_FLAG_DRAGGING    (1 << 2)   // Being dragged
#define WINDOW_FLAG_MOVABLE     (1 << 3)   // Can be moved
#define WINDOW_FLAG_CLOSABLE    (1 << 4)   // Has close button
#define WINDOW_FLAG_RESIZABLE   (1 << 5)   // Can be resized
#define WINDOW_FLAG_RESIZING    (1 << 6)   // Being resized
#define WINDOW_FLAG_MINIMIZED   (1 << 7)   // Minimized to taskbar
#define WINDOW_FLAG_MAXIMIZED   (1 << 8)   // Maximized
#define WINDOW_FLAG_LOCKED      (1 << 10)  // Locked (no move/resize)
#define WINDOW_FLAG_SETTINGS_OPEN (1 << 11) // Settings menu open

2. Window Structure (window.h:160-192)

typedef struct window {
    uint32_t id;
    char title[MAX_WINDOW_TITLE];
    rect_t bounds;
    uint32_t flags;
    uint32_t z_order;

    // Colors (customizable per window)
    uint32_t bg_color;
    uint32_t border_color;
    uint32_t titlebar_color;

    // Widgets
    struct widget *widgets;
    uint32_t widget_count;

    // Event handlers
    event_handler_t on_close;
    event_handler_t on_click;
    event_handler_t on_key;
    void *user_data;

    // State
    int32_t drag_offset_x, drag_offset_y;
    uint32_t resize_edge;
    uint8_t opacity;           // 0-255, default 255
    rect_t stored_bounds;      // For restore from maximize

    // Linked list
    struct window *next, *prev;
} window_t;

Correction: in the current kernel/gui/window.h, bits 10 (WINDOW_FLAG_LOCKED) and 11 (WINDOW_FLAG_SETTINGS_OPEN) described below no longer exist; the flag set stops at bit 9, which is now WINDOW_FLAG_NOCHROME (a borderless-panel flag, unrelated to this section). Locking and opacity are real, current features, but the "locked" and "settings open" state for them now lives in the userland compositor's own window bookkeeping (userland/apps/compositor/main.c, widgets.c, traymenu.c, profile.c), not in this kernel struct.

3. Per-Window Settings Menu

The settings menu appears when clicking the gear button (leftmost titlebar button):

+---------------------------+
| [Gear] [Min] [Max] [X]    |  <- Titlebar buttons
+---------------------------+
|                           |
|  Settings Menu drops down |
|  +---------------------+  |
|  | [] Locked           |  |
|  |---------------------|  |
|  | Opacity:            |  |
|  | [====o------]       |  |
|  |      75%            |  |
|  +---------------------+  |

Features:

  • Locked checkbox: Prevents window movement and resizing
  • Opacity slider: Adjusts window opacity from 25% to 100%
  • Z-index: Drawn AFTER all windows so it always appears on top

4. Theme Engine

The theme system provides:

FeatureStatus
Built-in themes2 (Default, Dark Mode)
Custom theme loadingVia INI files in /System/Themes/
Color IDs50+ named colors
Metrics11 configurable dimensions
Style types6 (Flat, Motif, Win95, Win11, Mac, GTK)
Theme callbacksSupports change notifications
PersistenceSaves to /CONFIG/THEME.CFG

Correction: these six names and numbers no longer exist. They were accurate for the build this analysis was written against, but the theme syscall interface has since been renumbered and renamed. The current theme syscalls, verified against kernel/proc/syscall.h, are:

SYS_SET_THEME           (133) // Set system-wide UI theme
SYS_GET_THEME           (134) // Get current system theme ID
SYS_SET_CURSOR_THEME    (148) // Set cursor theme: 0=Retro, 1=Light, 2=Dark
SYS_GET_CURSOR_THEME    (149) // Get current cursor theme
SYS_THEME_COLOR         (290) // Get active theme color by theme_color_id_t
SYS_THEME_LOAD_FILE     (335) // Load a theme from an INI file
SYS_THEME_METRIC        (357) // mtheme v2 integer metric: (theme_id, metric) -> int32

For the authoritative, always-current list (including whether a given number actually has a dispatcher case, not just a header declaration), see the generated Syscall Reference rather than any hand-maintained table, including this one.

5. Window Syscalls for Userland

SYS_WIN_CREATE      (30) // Create window
SYS_WIN_DESTROY     (31) // Destroy window
SYS_WIN_DRAW_RECT   (32) // Draw rectangle
SYS_WIN_DRAW_TEXT   (33) // Draw text
SYS_WIN_DRAW_PIXEL  (34) // Draw pixel
SYS_WIN_BLIT        (35) // Blit bitmap
SYS_WIN_GET_EVENT   (36) // Get window event
SYS_WIN_INVALIDATE  (37) // Invalidate window
SYS_WIN_GET_SIZE    (38) // Get window content dimensions (added since this analysis)

Verified current: numbers 30-38 above all still match kernel/proc/syscall.h exactly, with a real case arm in the dispatcher for each. SYS_WIN_SET_OPACITY (discussed as a future enhancement below) has still not been added; that specific limitation is still accurate today.

6. Alpha Blending Support

Framebuffer provides alpha blending functions:

void fb_blend_pixel(uint32_t x, uint32_t y, uint32_t color, uint8_t alpha);
void fb_fill_rect_alpha(uint32_t x, uint32_t y, uint32_t w, uint32_t h,
                        uint32_t color, uint8_t alpha);

Known Limitations

1. No Window Opacity Syscall (Minor)

Userland apps cannot programmatically set window opacity - there's no SYS_WIN_SET_OPACITY syscall. Users can still adjust opacity via the settings menu.

2. Always on Top - Removed

The "Always on Top" feature was removed (commented out) because it wasn't fully implemented. The z-order system exists but lacks the logic to keep specific windows above others persistently.

3. Titlebar Opacity

Currently only the window content area supports opacity. The titlebar remains fully opaque for better usability (buttons need to be visible).

Integration Status

User-Mode Applications Support: COMPLETE

FeatureStatusNotes
Window creationWORKINGVia SYS_WIN_CREATE syscall
Window destructionWORKINGVia SYS_WIN_DESTROY syscall
Drawing primitivesWORKINGRect, pixel, text
Event handlingWORKINGMouse and keyboard events
Widget supportWORKINGButtons, textboxes, etc.
Theme accessWORKINGFull syscall interface

Theming Support: COMPLETE

FeatureStatusNotes
Built-in themesWORKINGDefault + Dark Mode
Theme switchingWORKINGRuntime switching
Custom themesWORKINGINI file loading
Color queriesWORKING50+ color IDs
MetricsWORKINGConfigurable dimensions
PersistenceWORKINGSaves preference
Userland accessWORKINGVia syscalls

Opacity Support: COMPLETE (as of v1.8.2)

FeatureStatusNotes
Opacity storageWORKINGPer-window uint8_t
Slider UIWORKINGIn settings menu
Value calculationWORKING64-255 range (25%-100%)
Alpha blending functionsWORKINGIn framebuffer
Actual renderingWORKINGContent area uses fb_fill_rect_alpha()

Recommendations

1. Opacity Rendering - IMPLEMENTED

The window_draw() function now uses alpha blending for the content area:

// Draw window content area (with opacity support)
if (win->opacity < 255) {
    fb_fill_rect_alpha(content_x, content_y, content_w, content_h,
                      win->bg_color, win->opacity);
} else {
    fb_fill_rect(content_x, content_y, content_w, content_h, win->bg_color);
}

Location: kernel/gui/window.c:1123-1129

2. Add Window Opacity Syscall (Future Enhancement)

// In syscall.h:
#define SYS_WIN_SET_OPACITY  39

// In syscall.c:
case SYS_WIN_SET_OPACITY:
    result = sys_win_set_opacity((int)arg1, (uint8_t)arg2);
    break;

3. Consider Compositor-Based Opacity

For proper window transparency with overlapping content, a full compositor architecture would be needed where each window renders to an off-screen buffer that is then composited with alpha blending.

Conclusion

The MayteraOS window manager provides complete support for:

  • User-mode applications: Full syscall interface for GUI apps (8 window syscalls, 6 theme syscalls)
  • Theming: Complete theme engine with runtime switching, 50+ color IDs, custom INI themes
  • Opacity: Full implementation with slider UI, value storage, and alpha-blended rendering

The window manager is production-ready for:

  1. Kernel-mode desktop applications
  2. Userland applications via syscalls
  3. Custom theming via INI files
  4. Per-window transparency effects All major features are fully integrated and operational.

Analysis performed: 2026-02-07 Kernel version: v1.8.2