vexar
Search Log in
Back to the feed

VexOS Goes Graphical (Paint and Mouse Included)

Hey everyone,

When VexOS got its desktop (back when it was still called kernel-test), I described it as an 80×25 text screen with no graphics and no mouse, on purpose. Well... it turns out "on purpose" had an expiry date.

VexOS can now switch to real graphics modes, show pictures in true color and let you paint them with a mouse. Along the way it also picked up themes, much bigger limits, every key on your keyboard, a fix for a sneaky keyboard bug, and the first building block of something bigger.

Here's the tour.

Before vs. now

Until now, everything in VexOS happened on an 80×25 text screen: 16 colors, no pixels, keyboard only.

Now:

  • Any resolution. From 640×480 all the way up to 4K and ultrawide, with VexOS drawing the text itself at any size from 100% to 800%.
  • Themes. Every color of every part of the screen can be changed, and there are ready-made presets.
  • Pictures. .bmp files are a real file type now, with two viewers and a paint program.
  • A mouse. A PS/2 mouse works on the desktop and in paint.

Text mode isn't going anywhere: it's still how VexOS starts until you pick something else, and everything still works without a mouse.

A quick tour

  • Pick a resolution. display 1920x1080 switches to Full HD, and adding -s 200 makes the text twice as big. display -l lists common resolutions and whether your PC can show them, display native picks what your monitor likes best, and names like 1080p, 4k or uw1440 work too.
  • No black-screen panic. After switching, VexOS asks Keep this mode? (y/n). Press any other key, or just wait 15 seconds, and it goes back to the mode before. So a mode your monitor can't show undoes itself.
  • Make it yours. theme preset dark restyles everything at once: the shell, the editors, the desktop, the taskbar, even the Alt+Tab list. There's also light, amber and classic. Or change one thing at a time, like theme desktop white on blue or theme clock 12h. You can even change what a color is: theme palette.yellow #ffb000.
  • Look at pictures. Press Enter on a picture on the desktop, or use the commands: gview shows it in true color, pixel for pixel, and view draws it with colored characters, so it works even in text mode or over a serial terminal.
  • Draw something. paint opens a blank canvas (paint pic.bmp opens a picture). You get a pencil, line, rectangle, ellipse, fill, color picker and eraser, 16 steps of undo and redo (Ctrl-Z / Ctrl-Y), zoom from 1/64 all the way up to x16, and canvases up to 4096×4096. Ctrl-S saves a regular BMP that any PC can open. Paint works in text mode too, using half-characters as pixels.
  • Grab the mouse. On the desktop: click to choose an icon, double-click to open it, drag to move it. Click the taskbar to switch tasks from anywhere. In paint, the left button draws in the foreground color, the right one in the background color, the middle one drags the picture around and the wheel zooms. Type mouse to see what VexOS found, or mouse off if your PC doesn't get along with it.

Your display, theme and mouse settings are saved in /system, so they come back on every boot. And if a graphics mode ever gives you trouble, hold Shift while the computer starts to stay in text mode just that once.

The smaller (but important) stuff

Bigger limits and a snappier desktop

  • More tasks. Up to 62 open tasks instead of 14. The Alt+Tab list scrolls when it doesn't fit on the screen.
  • More memory. The kernel heap used to stop at 32 MiB. Now it takes all the RAM it can get below the program slots (about 60 MiB), plus a second region above them that's no longer capped at 1 GiB. That's where big pictures go: a 4096×4096 canvas alone is 64 MiB.
  • Running out is no longer a crash. When memory is full, a new task is refused with "not enough memory for a new task" instead of taking the kernel down with it.
  • The desktop goes first. Switching tasks, the taskbar and the home screen now get priority over everything else, and a key press or mouse click wakes them right away. So the desktop stays responsive even while programs keep the CPU busy. Regular tasks still take turns like before.
  • Tasks leave a note. VexOS now remembers how each task ended (its exit code, a crash, a stop or a kill) and keeps count of how much CPU time each one got.

Every key on your keyboard

Until now, VexOS simply didn't decode F-keys, the Win key or most key combinations. Now it knows F1 to F12, Win (alone or with another key), the Menu key, arrows, Home, End, Page Up/Down, Insert, Delete and Esc with Ctrl, Alt or Win held, and Tab with Shift, Ctrl or Win. Everything that worked before works exactly the same, Alt+Tab included.

Programs get these as a key code with the modifiers added as bits: Shift is 0x1000, Ctrl 0x2000, Alt 0x4000 and Win 0x8000. So Alt+F4 comes in as 0x4113, and Win+d as 0x8064. (These come from a PS/2 keyboard only, not from a serial terminal.)

The same commit also quietly changed how the editors, the viewers and paint figure out their size: instead of asking the screen directly, they now ask for the size of their own view. Today that's exactly the same thing. More on why below.

How it works, in three tricks

No need to read this part to enjoy the update, but if you're curious, here are three of my favorite bits.

1. Text, drawn by hand

In text mode, the graphics card draws the letters for you. In a graphics mode there are only pixels, so VexOS draws every character itself. It borrows the video BIOS's own 8×16 font and stretches it to any size: 200% gives 16×32 characters, and odd sizes like 150% work too (some pixel columns just come out a little wider than others).

The nice part: terminals, editors and programs don't have to care. When the mode changes, they simply get a new number of rows and columns and keep what they were showing. Full HD at 150% gives you 160×45 characters.

2. Sizes your graphics card doesn't have

Graphics modes come from the video card's BIOS (VESA BIOS Extensions, version 2.0 or newer). In QEMU, Bochs and VirtualBox, VexOS can set pretty much any size exactly. On other cards, if you ask for a size the card doesn't offer, VexOS shows it framed: in the middle of the next bigger mode, with a black border around it. Your text area is still exactly the size you asked for.

3. The case of the frozen keyboard

This one comes from the bug fix commit, and it's my favorite kind of bug.

Whenever VexOS asks the BIOS for something (reading the disk, switching display modes), it briefly hands the machine back to the BIOS and then sets the interrupt controller up again. Setting it up again also wipes any keyboard interrupt that was still waiting. If a key arrived at exactly the wrong moment, the keyboard controller kept holding it and kept its line raised, but the interrupt controller only reacts to a new signal, which never came. So that key, and every key after it, just sat there waiting, until something else (like a mouse movement) happened to read the controller.

The fix: right after every BIOS call, read whatever the controller is still holding.

pub fn poll_pending() {
    for _ in 0..32 {
        let status = unsafe { inb(STATUS) };
        if status == 0xFF || status & STATUS_OUTPUT_FULL == 0 {
            break; // no controller, or nothing waiting
        }
        handle_irq(); // handle it like a normal key press
    }
}

It reads at most 32 bytes, so a stuck controller can't hang it, and it stops at once on a PC with no keyboard controller at all. Mouse bytes still go to the mouse.

A sneak peek: a drawing library

The last commit adds gfx, a small 2D drawing library: rectangles, fills, see-through (alpha) blending, lines, outlines, rounded corners, fast copying and scaling of images, and text at any size. It also keeps a "damage list" of which parts of the screen changed, so only those need to be drawn again.

It follows a few strict rules: integer math only (no floating point), it never panics no matter what numbers you throw at it (negative, huge, way off screen, it all just gets clipped), and it never assumes memory is there. The kernel already builds with it, and the exact same code runs in the tests on my own PC, so both produce bit-identical pictures.

So what's it for? Rounded corners, title bars, shadows, a list of what changed on screen, plus editors and paint that now ask for the size of their own view... if that sounds like windows to you, you're not wrong. This is groundwork for a windowed desktop.

How it was tested

  • New self-tests run at every boot, including one for the screen's pixels and the mouse pointer, and one that fakes a key press right before a BIOS call and checks that it still arrives.
  • The drawing library has its own tests that check results pixel by pixel, plus a couple of "golden" scenes (one looks like a little window, with a title bar, buttons and a shadow). If a later change moves even one pixel, the tests notice. They run together with all the other tests.
  • The picture code was hardened for huge pictures: a fill on a 4096×4096 canvas that runs out of memory stops cleanly instead of crashing, and saving checks for free disk space first.

All in all, that's five commits and 15,663 added lines (12,384 of them in the graphics commit alone), along with a stack of new manual pages.

Good to know

To keep expectations honest:

  • PS/2 mice only. A USB mouse works only if your BIOS makes it look like a PS/2 one ("legacy USB support"). Many laptop touchpads are PS/2 and should be fine.
  • The mouse only works on the desktop and in paint. Terminals, editors and the viewers are still keyboard only.
  • BMP only. No PNG or JPEG yet, and no compressed BMPs.
  • Graphics need VBE 2.0 or newer. And big modes need video memory: 4K needs 32 MiB of it.
  • Still one task on screen at a time. No windows side by side (yet).
  • Still one core, still no protection between programs. Same as last time.

Still on the Alpha branch

Like the desktop update, all of this is on the Alpha branch on GitHub, not the main one, so I can do some bug fixing before it's considered done. If you want to try it early, that's where to look, just expect a few rough edges.

Your feedback is still welcome

As always, suggestions, comments and feedback are welcome, whether it's about VexOS or the site. Leave a comment below or send me a message through Contact.

Thanks for being here 💜

— Vex

Join the conversation
Log in or make an account to comment and vote.

0 comments

No comments yet. Start the conversation.