Making Tiling Window Manager in C on Windows
Вставка
- Опубліковано 21 січ 2024
- Making Minimalist Tiling Window Manager (like i3wm or Suckless dwm, but much more simple) for Windows using the C Programming Language and Windows API.
I am planning to build upon the code I wrote in the video and improve this, here is a link to the Github for this project: github.com/nir9/lightwm - Наука та технологія
You make shell programming look easy!
Incredibly useful video showing that some things on Windows are actually much simpler than you imagine.
And it is, most of the functions you use are already programmed. Don't expect it to be difficult
It always look simple when somebody who knows what he is doing, doing it. But it's an illusion, you need underlying knowledge to know where to look for or what to type, if you don't have that knowledge no amount of documentation will help you.
Omg Nir what an amazing timing I was literally thinking of writing a wm of my own!
Thanks bro, I honestly did not know that we can build this kind of app!
this rules. I have been looking for a wm in windows 10 that isn't awful, bloated or behind a paywall. please keep improving this!
Suckless DWM is pretty good and there are Windows builds
@@MaxmWotan-hm7zk there's also komorebi which is also quite configurable
@@xStormyyy have you tried glazewm? It's an even more enjoyable experience and has more customization
Your videos are awesome! I'm glad you decided to do this!
Great work! Plain and simple explanation. With great quality.
No words for this, you're on par bro 🙏🏻
wake up babe, new nir lichtman video dropped
your channel is a true blessing. i hope you make a linux Xorg version of this tutorial one day. thank you so much for your work
i3/sway like configurable wm would be great on windows. Thanks for your effort man.
Awesome! thanks for sharing. Following your project!
There are two bugs in your program, but they are subtle:
1. Setting signal handler after creating hook may result in race condition (user sends SIGINT after SetHook... but before signal)
2. Bare C spec about signal handlers is very restrict. It allows no functions from standard library and basically you can only assign to type `volatile sig_atomic_t`, everything else is undefined. I see two solutions:
a) maybe windows spec about signal handlers allows more functions, or
b) using POSIX signals you can block SIGINT (maybe with setting signal handler to SIG_IGN) and in main loop wait on some function until you get SIGINT (I don't remember details), since you are not in signal handler and can do whatever you like
This is beautiful work 👏😎
nice. this could be something that lives in the system tray. all you need are a way to make custom keymaps and a more sophisticated tiling system and it can become a robust tiling system.
Wow this is awesome. Thank you ❤️
The "Hook" method can btw. be used for many other useful applications, such as UI regression testing software.
I simply love your videos! The content, the format, just straight to the point with no swerving or joking around.
Keep up the good work, Nir!
Thanks!
I don't know anything about windows api, but in Linux the api you can call into the signal handler are limited, as described into signal-safety(7). Maybe it's better to check it for windows too. Thanks for the videos, very inspiring
good point.
a safer approach would set a global flag to exit the app loop or using atexit() function
WELL EXPLAINED SIR
My takeaways from the video:
You are a great c dev that knows the windows api way better than me.
The windows api sucks.
Windows hides fully implemented functionality from the user.
What do you mean "hides"? All information about win32api is open and well-documented.
@@diver2048 windows has functionality built in to support a full tiling window manager but it's not supported from the ui.
@@redcrafterlppa303 well yeah, because it isn't a feature they want to support? A toggle on window management behavior would be rather niche and probably confusing to the average user. If anything, I do not get how you can think the Windows API sucks when it allows for this functionality to be created, at least in a fundamental way, in very few lines of codes and a rather straightforward manner.
@@javierflores09 as someone who used their windows api regularly I can tell you that it sucks besides this point. But my point is that the tiling function is basically 70% of the window manager and there is no use of this behavior in the ui. So the function existing but not being used by anything other than probably powertoys that isn't a part of windows is weird.
@@redcrafterlppa303 I think the point of the tiling function is for MDI (which is old) and also as backwards compatibility (for all the Windows 2000 programs you run..)
Hi Nirs, your content are always great. Thank you. I learned about dwm-win32 because of you. I love it and I'm still using it but the crash problem is a little bit annoying sometimes but not to the point where I will stop using it because my productivity has greatly increased.
With the code you presented, is it possible to hook the procedure then exit the executable without unhooking? If yes, can it be unhooked later? E.g.
wm.exe start - hooks the proc and exits process immediately
wm.exe stop - unhook and cleanup resource
Next up we’ve got “Making Windows 12”
In all seriousness you should make a series about making a full Linux distro or maybe a continuation of your simple Linux distro video ;)
Next vid will be the gui distro :)
Bro is G.O.A.T.
where does the algorithm for arranging the windows come from? from the options being vertical and horizontal I was expecting them to just stack in a single row/column
The algorithm comes from the Windows source code (TileWindows is a function from Windows API).
When the number of windows is small it does stack according to the option, but once the # of windows exceeds a certain #, it starts to change the layout since if it would keep squeezing the windows in the chosen stack, it would make the windows too small.
@@nirlichtman It probably adds a new row when the number of tiles reaches a full square number (e.g. 4, 9, 16... ). In other words, (row count = square root(tile count)) And the number of columns is equal to (tile count / row count). The last row can have less than the calculated number of columns if tile count is not full square.
I was searcing for an algorithm for a project to tile some windows and after some research, found this is the usually implemented way and worked like a charm.
this is random but I can't stop staring at your '4' characters in your command prompt. I feel like this is the very first time I've ever seen a 4 that on screen that isn't 'closed' if that makes sense
I'm not a programmer but i find tiling windows very useful so I used you program. Unfortunatelly on my dual 4K monitors it misplaces windows everywhere. I will wait for future updates (if any). Thank you
Have you tried the latest code from Github? it has some new fixes and also I tested on dual monitors and it works good as well.
@@nirlichtman I can see You update your projecy very often. I will try newest version. Thanks.
I remember you had a great video about why you use a tiling manager for Windows, you said that the original version of Windows, DOS, used a tiling windows manager as well. I've been trying to find that video, did you delete it from your channel?
I unlisted it since I no longer recommend dwm-win32 but here is the link for the vid, it still exists: ua-cam.com/video/U0DpD4Y5FN8/v-deo.htmlsi=5zz2s63a5k9u1Mpc
I will make a new similar video soon
@@nirlichtman thank you and I can't wait :)
Remove window titlebars, draw border around and it will look nice))
Cool video
bro is a menace
Can you write some simple program to spawn/relocate all new windows to the center of the current monitor (where mouse cursor is)?
I'm not a programmer, I wish there were more such tools in Windows like in Linux.
What exactly do you mean, which tools like this exist on Linux?
@@nirlichtman On Linux there are lots of ways to manipulate windows placement programmatically, like through wmctrl or xdotool.
I want to put all spawned windows in the center of the screen, there are some shady tools like that for Windows (closed source), or maybe Autohotkey script, but it is not C++/C# can be slow or buggy.
Love it
❤❤❤❤❤😊 amazing 👏
Lately I've been using AutoHotkey again. I can start en close my working environment processes. And I can arrange windows to some specific locations.
It's not perfect. But it works.
I use AutoHotKey on my Lenovo ThinkPad P72 to turn its manually-controlled keyboard backlight into one that turns on and off automatically.
Instead of the busywait I would use Sleep(-1)
Could you explain why? Is there a difference in performance or something?
Performance yes. A for loop that does nothing will take CPU time, while Sleep(-1) does not.
כל הכבוד!
🔥🔥
Would it be possible to do this in another language such as Go? Or the complexity is just not worth it?
Yah it should be possible in pretty much any language as long as you have bindings to Windows API or a way to call functions from DLLs. I am not sure exactly how it works in Go, but in Python for example I know you can use a library called pywin which contains bindings for Windows API, and in C# you can easily call functions from DLLs - and this enables you to basically call any Windows API you need
What are the minimal system requirements? Will it work on Windows 95 OSR2? Windows NT4? XP?
Haven't tested it yet on anything other than Windows 10, but it should work on Windows XP and higher (according to the minimum required Windows version in the API docs)
Do you plan any c++ videos or just c?
Yes also C++ is planned 👍
What font & syntax highlighting are you using in gvim?
The welcome link on the channel has my vimrc
Woooow !!!!!!!!
Not quite related, but I would love you to do a lesson on ncurses, if you are familiar with the library.
On my video about making snake in C I use ncurses :)
please put up a donation page bro, we gotta give something back for your great vids
Appreciate the compliment! I will consider that :)
not work in win11, no response after binary is executed. only work for win10?
It works for Win11 as well, I fixed a few stuff on the Github repo, welcome to try out the latest code from there.
Thx:) it’s appreciated.
Can you help, thanks in advance.
After manually compiling files with CL from github, the program produces:
[!] Error: GetProcAddress failed.
Win32 Last Error: 127
127 means that the procedure was not found ( ref: learn.microsoft.com/en-us/windows/win32/debug/system-error-codes--0-499- ), what do you get when running "dumpbin /exports wm_dll.dll", do you see the export of ShellProc?
Try building with nmake according to the instructions in the README and make sure you are using the x64 Native Tools Command Prompt
@@nirlichtman if use nmake i recive erorr - makefile(21) : fatal error U1034: syntax error : separator missing
@@boom1188 interesting for me it works good with nmake, are you using visual studio 2022 and x64 native tools console? Also make sure you pulled the latest changes
@@boom1188 made a little fix in the make file, welcome to try now maybe it will help
@@nirlichtman Thank you for your help! I managed to compile the project.
I have 2 different displays. I launched the program, on the 1st there are 2 windows horizontally to the left of the center, on the 2nd there are 2 windows vertically to the left of the center.
👍👍!
now tell us how to make dwm/i3 for windows like you have on your other videos
On my previous vids I used dwm-win32, but I decided I want to create a new minimalist tiling window manager for Windows due to a couple of bugs in dwm-win32 and the fact that I feel the code there a little too complicated and my goal for this new project is to keep the code as simple as possible. I plan to improve this project to have more features like multiple workspaces and keyboard navigation.
i tought you made it or something ;)
@@n-uv7vg i contributed to it a bit but the project is someone elses
ok
Graphical linux distro from scratch when?
😂😂
Next one :)
@@nirlichtman cool!
It's actually relatively easier to this, you can use LFS to bundle required packages.
Edit: Apparently this is very simple now that I saw this video.. both are simple :p
Can you make a video about sending mails with C or C++ on Windows
Yes, nice idea :)
we needed this in the 2000s so linux fanatics would'nt hate that much on windows
They don't hate Windows for it, the autists do it for a sense of belonging to some community, like k-pop fangirls
windows API is garbage though. This video was painful to watch.
@@roberthelps8715 So is Xorg, welcome to the real world.
yo what font is that
Lucida Console, welcome link on the channel has my full vimrc
@@nirlichtman thanks man
Plans for Wayland compositor?
I thought it was illegal to mix C and Windows API code 😆
Guy writes c in vim with no lsp damn
Just switch to Linux, if you can do that, your smart enough for Linux
The content is good but the keyboard sound is so loud, "dirty" and annoying. I'd appreciate it if the keyboard noise was lowered in volume.
Thanks for the feedback will work on a fix for next vids 👍
@@nirlichtman thanks, I'd add more context: if it sounded like individual keypresses it would be way much better. But it feels like the whole keyboard resonates and produces a lot of extra noise between actual keypresses. It's felt too distracting and it was hard to focus on your voice.
@@nirlichtman ... however removing typing sound completely would be a loss. Making it less loud should help. As an idea what do you think about not recording _your_ keyboard, but adding simulated key typing sounds instead? You'd probably need to record your keypresses along with your screen recording and then use some software to mix in typing effects.
ok the idea with simulated typewriter effect might not be as good: it does not seem to be common practice. Guys from Reddit actually recommend recording real typing.
But making the keyboard sounds less loud should still be an option.
@@storojilo i am probably just gonna change to a quiter keyboard, another option is to check if kdenlive or audacity can reduce the keystroke sounds without reducing the quality of the audio
but why for(;;){} and not while(true) as normal mortals do an infinite loop?
I like using for ;; instead of while true since sometimes the compiler issues a warning if you use a constant in a while condition
@@nirlichtman makes sense, thanks.
This is lower level code looks like
windows, vim without plugins and a wack font???......come on smart guy figure it out!
Niceeeeeeeeeeee