XenevaOS
Loading...
Searching...
No Matches
Classes | Macros | Typedefs | Functions
compose3d.cpp File Reference
#include "compose3d.h"
#include "compose.h"
#include "cursor.h"
#include "xr_present.h"
#include "nanojpg.h"
#include <keycode.h>
#include <color.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/_kefile.h>
#include <_xeneva.h>
Include dependency graph for compose3d.cpp:

Classes

struct  _vec3_
 
struct  _lin3_
 
struct  _win3d_
 

Macros

#define DEODHAI3D_PI   3.14159265f
 
#define DEODHAI3D_TWO_PI   6.28318531f
 
#define DEODHAI3D_FOV_X   1.57079633f /* 90 degrees horizontal */
 
#define DEODHAI3D_PITCH_LIMIT   0.52359878f /* 30 degrees */
 
#define DEODHAI3D_NEAR   0.05f /* near plane, fraction of focal */
 
#define DEODHAI3D_MIN_DIST   0.25f /* closest a window may come, x focal */
 
#define DEODHAI3D_MAX_DIST   8.0f /* farthest, x focal */
 
#define DEODHAI3D_DEPTH_SPEED   0.004f /* Ctrl+drag: distance change per pixel */
 
#define DEODHAI3D_DEPTH_STEP   1.25f /* Ctrl+'-' / Ctrl+'=' distance factor */
 
#define DEODHAI3D_DEPTH_GAP   1.12f /* send-to-back / bring-to-front spacing */
 
#define DEODHAI3D_DEPTH_EASE   0.25f /* fraction of the remaining depth per frame */
 
#define DEODHAI3D_DEN_EPS   1e-3f
 
#define DEODHAI3D_TITLEBAR   26 /* same hit zone as DeodhaiWindowCheckDraggable */
 
#define DEODHAI3D_CURSOR_SIZE   24
 
#define DEODHAI3D_SUBSPAN   16 /* perspective-correct samples every N pixels */
 
#define DEODHAI3D_DRAG_LOD   1 /* half-resolution panorama while turning */
 
#define DEODHAI3D_HASH_SIZE   256 /* power of two, > 2 x DEODHAI3D_MAX_WINDOWS */
 
#define DEODHAI3D_DRAG_NONE   0
 
#define DEODHAI3D_DRAG_CAMERA   1
 
#define DEODHAI3D_DRAG_WINDOW   2
 

Typedefs

typedef struct _vec3_ Vec3
 
typedef struct _lin3_ Lin3
 
typedef struct _win3d_ Win3D
 

Functions

Window * _get_root_window ()
 
Window * _get_always_on_top ()
 
Window * _get_focused_window ()
 
Cursor * _get_current_cursor ()
 
void _take_update_bits (bool *window_update_all, bool *always_on_top_update)
 
void _set_always_on_top_update (bool update)
 
void XRComposeFrame (ChCanvas *canvas)
 
void CursorStoreBack (ChCanvas *canv, Cursor *cur, unsigned x, unsigned y)
 
void CursorDrawBack (ChCanvas *canv, Cursor *cur, unsigned x, unsigned y)
 
void DeodhaiWindowSetFocused (Window *win, bool notify)
 DeodhaiWindowSetFocused – cast focus to a new window.
 
void DeodhaiSendMouseEvent (int handle, int ownerId, uint8_t handleType, uint8_t eventType, int x, int y, int button)
 DeodhaiSendMouseEvent – send mouse event to desired window.
 
bool Deodhai3DLoadPanorama (const char *path)
 Deodhai3DLoadPanorama – load a 360 degree cylindrical panorama.
 
void Deodhai3DSetCamera (float yaw, float pitch)
 Deodhai3DSetCamera – set camera orientation (radians)
 
void Deodhai3DGetCamera (float *yaw, float *pitch)
 Deodhai3DGetCamera – get camera orientation (radians)
 
void Deodhai3DInitialise (ChCanvas *canvas)
 Deodhai3DInitialise – set up the 3D compositor.
 
bool Deodhai3DEnabled ()
 Deodhai3DEnabled – returns true while 3D mode is active.
 
void Deodhai3DSetEnabled (bool enable)
 Deodhai3DSetEnabled – switch between 3D and 2D compositing.
 
void Deodhai3DToggle ()
 Deodhai3DToggle – flips 3D mode.
 
bool Deodhai3DWindowSetPosition (Window *win, float x, float y, float z)
 Deodhai3DWindowSetPosition – translate a window in 3D space.
 
bool Deodhai3DWindowGetPosition (Window *win, float *x, float *y, float *z)
 Deodhai3DWindowGetPosition – get the world position of a window.
 
bool Deodhai3DWindowPushDepth (Window *win, float factor)
 Deodhai3DWindowPushDepth – move a window along its view ray.
 
bool Deodhai3DWindowSendToBack (Window *win)
 Deodhai3DWindowSendToBack – behind every other window.
 
bool Deodhai3DWindowBringToFront (Window *win)
 Deodhai3DWindowBringToFront – in front of every other window.
 
bool Deodhai3DHandleKey (int key, bool ctrl)
 Deodhai3DHandleKey – 3D shortcuts (with Ctrl held)
 
bool Deodhai3DScreenToWindow (Window *win, int sx, int sy, int *lx, int *ly)
 Deodhai3DScreenToWindow – maps a screen pixel onto a window.
 
void XRComposeFrame3D (ChCanvas *canvas)
 XRComposeFrame3D – the 3D compose pipeline.
 
bool Deodhai3DHandleMouse (ChCanvas *canvas, int x, int y, int button)
 Deodhai3DHandleMouse – 3D input routing.
 

Macro Definition Documentation

◆ DEODHAI3D_CURSOR_SIZE

#define DEODHAI3D_CURSOR_SIZE   24

◆ DEODHAI3D_DEN_EPS

#define DEODHAI3D_DEN_EPS   1e-3f

◆ DEODHAI3D_DEPTH_EASE

#define DEODHAI3D_DEPTH_EASE   0.25f /* fraction of the remaining depth per frame */

◆ DEODHAI3D_DEPTH_GAP

#define DEODHAI3D_DEPTH_GAP   1.12f /* send-to-back / bring-to-front spacing */

◆ DEODHAI3D_DEPTH_SPEED

#define DEODHAI3D_DEPTH_SPEED   0.004f /* Ctrl+drag: distance change per pixel */

◆ DEODHAI3D_DEPTH_STEP

#define DEODHAI3D_DEPTH_STEP   1.25f /* Ctrl+'-' / Ctrl+'=' distance factor */

◆ DEODHAI3D_DRAG_CAMERA

#define DEODHAI3D_DRAG_CAMERA   1

◆ DEODHAI3D_DRAG_LOD

#define DEODHAI3D_DRAG_LOD   1 /* half-resolution panorama while turning */

◆ DEODHAI3D_DRAG_NONE

#define DEODHAI3D_DRAG_NONE   0

◆ DEODHAI3D_DRAG_WINDOW

#define DEODHAI3D_DRAG_WINDOW   2

◆ DEODHAI3D_FOV_X

#define DEODHAI3D_FOV_X   1.57079633f /* 90 degrees horizontal */

◆ DEODHAI3D_HASH_SIZE

#define DEODHAI3D_HASH_SIZE   256 /* power of two, > 2 x DEODHAI3D_MAX_WINDOWS */

◆ DEODHAI3D_MAX_DIST

#define DEODHAI3D_MAX_DIST   8.0f /* farthest, x focal */

◆ DEODHAI3D_MIN_DIST

#define DEODHAI3D_MIN_DIST   0.25f /* closest a window may come, x focal */

◆ DEODHAI3D_NEAR

#define DEODHAI3D_NEAR   0.05f /* near plane, fraction of focal */

◆ DEODHAI3D_PI

#define DEODHAI3D_PI   3.14159265f

◆ DEODHAI3D_PITCH_LIMIT

#define DEODHAI3D_PITCH_LIMIT   0.52359878f /* 30 degrees */

◆ DEODHAI3D_SUBSPAN

#define DEODHAI3D_SUBSPAN   16 /* perspective-correct samples every N pixels */

◆ DEODHAI3D_TITLEBAR

#define DEODHAI3D_TITLEBAR   26 /* same hit zone as DeodhaiWindowCheckDraggable */

◆ DEODHAI3D_TWO_PI

#define DEODHAI3D_TWO_PI   6.28318531f

Typedef Documentation

◆ Lin3

typedef struct _lin3_ Lin3

◆ Vec3

typedef struct _vec3_ Vec3

◆ Win3D

typedef struct _win3d_ Win3D

Function Documentation

◆ _get_always_on_top()

Window * _get_always_on_top ( )
extern

◆ _get_current_cursor()

Cursor * _get_current_cursor ( )
extern

◆ _get_focused_window()

Window * _get_focused_window ( )
extern

◆ _get_root_window()

Window * _get_root_window ( )
extern

BSD 2-Clause License

Copyright (c) 2022-2026, Manas Kamal Choudhury All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

◆ _set_always_on_top_update()

void _set_always_on_top_update ( bool  update)
extern

◆ _take_update_bits()

void _take_update_bits ( bool *  window_update_all,
bool *  always_on_top_update 
)
extern

◆ CursorDrawBack()

void CursorDrawBack ( ChCanvas *  canv,
Cursor *  cur,
unsigned  x,
unsigned  y 
)
extern

◆ CursorStoreBack()

void CursorStoreBack ( ChCanvas *  canv,
Cursor *  cur,
unsigned  x,
unsigned  y 
)
extern

◆ Deodhai3DEnabled()

bool Deodhai3DEnabled ( )

Deodhai3DEnabled – returns true while 3D mode is active.

◆ Deodhai3DGetCamera()

void Deodhai3DGetCamera ( float *  yaw,
float *  pitch 
)

Deodhai3DGetCamera – get camera orientation (radians)

◆ Deodhai3DHandleKey()

bool Deodhai3DHandleKey ( int  key,
bool  ctrl 
)

Deodhai3DHandleKey – 3D shortcuts (with Ctrl held)

Deodhai3DHandleKey – 3D keyboard shortcuts, all with Ctrl held: Ctrl+3 toggle 3D compositing Ctrl+- push the focused window back Ctrl+= pull it closer Ctrl+[ send it behind every window Ctrl+] bring it to the front.

◆ Deodhai3DHandleMouse()

bool Deodhai3DHandleMouse ( ChCanvas *  canvas,
int  x,
int  y,
int  button 
)

Deodhai3DHandleMouse – 3D input routing.

Deodhai3DHandleMouse – 3D input: drag on empty space turns the camera, drag a titlebar to move a window around you, Ctrl + titlebar drag pushes it away / pulls it closer. Everything else is forwarded to the window under the cursor in the coordinates the client expects.

◆ Deodhai3DInitialise()

void Deodhai3DInitialise ( ChCanvas *  canvas)

Deodhai3DInitialise – set up the 3D compositor.

Deodhai3DInitialise – set up the 3D compositor. Call once after the wallpaper is in the back surface and the screen blur is baked. Snapshots the flat wallpaper (used as the fallback panorama and to restore 2D mode). 3D mode starts disabled.

◆ Deodhai3DLoadPanorama()

bool Deodhai3DLoadPanorama ( const char *  path)

Deodhai3DLoadPanorama – load a 360 degree cylindrical panorama.

Deodhai3DLoadPanorama – load a 360 degree cylindrical panorama (JPEG). Without one, the flat wallpaper is wrapped with mirror repeat.

◆ Deodhai3DScreenToWindow()

bool Deodhai3DScreenToWindow ( Window *  win,
int  sx,
int  sy,
int *  lx,
int *  ly 
)

Deodhai3DScreenToWindow – maps a screen pixel onto a window.

Deodhai3DScreenToWindow – maps a screen pixel onto a window's own pixel grid using the last composed frame.

◆ Deodhai3DSetCamera()

void Deodhai3DSetCamera ( float  yaw,
float  pitch 
)

Deodhai3DSetCamera – set camera orientation (radians)

Parameters
yaw– rotation about the vertical axis, + turns right
pitch– + looks up; clamped to +-DEODHAI3D_PITCH_LIMIT

◆ Deodhai3DSetEnabled()

void Deodhai3DSetEnabled ( bool  enable)

Deodhai3DSetEnabled – switch between 3D and 2D compositing.

Deodhai3DSetEnabled – switch between 3D and the classic 2D compositor. Enabling places every window where it is on screen now; disabling restores the flat wallpaper and the 2D layout.

◆ Deodhai3DToggle()

void Deodhai3DToggle ( )

Deodhai3DToggle – flips 3D mode.

◆ Deodhai3DWindowBringToFront()

bool Deodhai3DWindowBringToFront ( Window *  win)

Deodhai3DWindowBringToFront – in front of every other window.

Deodhai3DWindowBringToFront – eases a window in front of every other window.

◆ Deodhai3DWindowGetPosition()

bool Deodhai3DWindowGetPosition ( Window *  win,
float *  x,
float *  y,
float *  z 
)

Deodhai3DWindowGetPosition – get the world position of a window.

◆ Deodhai3DWindowPushDepth()

bool Deodhai3DWindowPushDepth ( Window *  win,
float  factor 
)

Deodhai3DWindowPushDepth – move a window along its view ray.

Deodhai3DWindowPushDepth – move a window along its view ray (it stays under the same screen spot, only grows / shrinks). Eased over a few frames.

◆ Deodhai3DWindowSendToBack()

bool Deodhai3DWindowSendToBack ( Window *  win)

Deodhai3DWindowSendToBack – behind every other window.

Deodhai3DWindowSendToBack – eases a window behind every other window (painter order is by distance, so it draws first)

◆ Deodhai3DWindowSetPosition()

bool Deodhai3DWindowSetPosition ( Window *  win,
float  x,
float  y,
float  z 
)

Deodhai3DWindowSetPosition – translate a window in 3D space.

Deodhai3DWindowSetPosition – translate a window in 3D space. The window turns to face the camera.

◆ DeodhaiSendMouseEvent()

void DeodhaiSendMouseEvent ( int  handle,
int  ownerId,
uint8_t  handleType,
uint8_t  eventType,
int  x,
int  y,
int  button 
)
extern

DeodhaiSendMouseEvent – send mouse event to desired window.

Parameters
win– Pointer to window
eventType– either MOUSE_EVENT or MOUSE_LEAVE
x– Mouse x location
y– Mouse y location
button– Mouse button state

◆ DeodhaiWindowSetFocused()

void DeodhaiWindowSetFocused ( Window *  win,
bool  notify 
)
extern

DeodhaiWindowSetFocused – cast focus to a new window.

◆ XRComposeFrame()

void XRComposeFrame ( ChCanvas *  canvas)
extern

Normal application windows

do either one – dirty area tracking or else update all

Zoomed (maximised) windows: stretched-fill upscale into the compose canvas (the back surface the GPU flush presents from), above normal windows; always-on-top and cursor still compose over them afterwards. Fullscreen dirty is published so transfer moves it.

Always on Top window , stacking order

◆ XRComposeFrame3D()

void XRComposeFrame3D ( ChCanvas *  canvas)

XRComposeFrame3D – the 3D compose pipeline.

XRComposeFrame3D – the 3D compose pipeline; drop-in for XRComposeFrame (falls back to it while 3D mode is off or a window is zoomed).

Variable Documentation

◆ blurStale

bool blurStale

◆ cameraDirty

bool cameraDirty

◆ canvas

ChCanvas* canvas

◆ colK

float* colK

◆ colTex

int32_t* colTex

◆ colU

int32_t* colU

◆ cosYaw

float cosYaw

◆ cx

float cx

◆ cy

float cy

◆ dragEntry

Win3D* dragEntry

◆ dragHandle

uint32_t dragHandle

◆ dragMode

int dragMode

◆ enabled

bool enabled

◆ f

float f

◆ flat

uint32_t* flat

◆ grabR

float grabR

◆ grabU

float grabU

◆ grabV

float grabV

◆ H

int H

◆ hovered

Window* hovered

◆ hoveredHandle

uint32_t hoveredHandle

◆ hudRefresh

bool hudRefresh

◆ lastButton

int lastButton

◆ lastX

int lastX

◆ lastY

int lastY

◆ needSync

bool needSync

◆ pano

uint32_t* pano

◆ panoH

int panoH

◆ panoMirror

bool panoMirror

◆ panoOwned

bool panoOwned

◆ panoSpan

float panoSpan

◆ panoW

int panoW

◆ pitch

float pitch

◆ ready

bool ready

◆ shear

float shear

◆ sinYaw

float sinYaw

◆ W

int W

◆ wasZoomed

bool wasZoomed

◆ yaw

float yaw