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
  • Наука та технологія

КОМЕНТАРІ • 125

  • @Diamonddrake
    @Diamonddrake 4 місяці тому +50

    You make shell programming look easy!

  • @GeorgeSladkovsky
    @GeorgeSladkovsky 4 місяці тому +37

    Incredibly useful video showing that some things on Windows are actually much simpler than you imagine.

    • @Aarch_64
      @Aarch_64 4 місяці тому +2

      And it is, most of the functions you use are already programmed. Don't expect it to be difficult

    • @JamesSmith-ix5jd
      @JamesSmith-ix5jd 3 місяці тому

      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.

  • @madeinhvn
    @madeinhvn 4 місяці тому +3

    Omg Nir what an amazing timing I was literally thinking of writing a wm of my own!

  • @jannatgaoshiqqalb3598
    @jannatgaoshiqqalb3598 4 місяці тому +10

    Thanks bro, I honestly did not know that we can build this kind of app!

  • @Mattdotnfo
    @Mattdotnfo 4 місяці тому +17

    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!

    • @MaxmWotan-hm7zk
      @MaxmWotan-hm7zk 4 місяці тому +1

      Suckless DWM is pretty good and there are Windows builds

    • @xStormyyy
      @xStormyyy 4 місяці тому +1

      ​@@MaxmWotan-hm7zk there's also komorebi which is also quite configurable

    • @f64jcxt8
      @f64jcxt8 3 місяці тому

      @@xStormyyy have you tried glazewm? It's an even more enjoyable experience and has more customization

  • @LeonardoSantos-lp9hp
    @LeonardoSantos-lp9hp 4 місяці тому +1

    Your videos are awesome! I'm glad you decided to do this!

  • @gherbetto
    @gherbetto 2 місяці тому

    Great work! Plain and simple explanation. With great quality.

  • @A9wpd
    @A9wpd 3 місяці тому

    No words for this, you're on par bro 🙏🏻

  • @tmg_beamng
    @tmg_beamng 4 місяці тому +9

    wake up babe, new nir lichtman video dropped

  • @not_kode_kun
    @not_kode_kun 4 місяці тому

    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

  • @byailen
    @byailen 4 місяці тому +2

    i3/sway like configurable wm would be great on windows. Thanks for your effort man.

  • @rick_er2481
    @rick_er2481 4 місяці тому

    Awesome! thanks for sharing. Following your project!

  • @staswisniewski4101
    @staswisniewski4101 4 місяці тому +4

    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

  • @tedburke525
    @tedburke525 4 місяці тому

    This is beautiful work 👏😎

  • @androth1502
    @androth1502 4 місяці тому

    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.

  • @antoniobarbalau1107
    @antoniobarbalau1107 4 місяці тому

    Wow this is awesome. Thank you ❤️

  • @StefanWelebny
    @StefanWelebny 4 місяці тому +2

    The "Hook" method can btw. be used for many other useful applications, such as UI regression testing software.

  • @vitao95
    @vitao95 4 місяці тому

    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!

  • @TemutoDonOmar
    @TemutoDonOmar 4 місяці тому +8

    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

    • @GeorgeTavernKeeper
      @GeorgeTavernKeeper 4 місяці тому

      good point.
      a safer approach would set a global flag to exit the app loop or using atexit() function

  • @twobob
    @twobob 4 місяці тому

    WELL EXPLAINED SIR

  • @redcrafterlppa303
    @redcrafterlppa303 4 місяці тому +26

    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.

    • @diver2048
      @diver2048 4 місяці тому

      What do you mean "hides"? All information about win32api is open and well-documented.

    • @redcrafterlppa303
      @redcrafterlppa303 4 місяці тому

      @@diver2048 windows has functionality built in to support a full tiling window manager but it's not supported from the ui.

    • @javierflores09
      @javierflores09 4 місяці тому +1

      @@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.

    • @redcrafterlppa303
      @redcrafterlppa303 4 місяці тому

      @@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.

    • @tzebruh
      @tzebruh 3 місяці тому

      @@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..)

  • @boy_deploy
    @boy_deploy 3 місяці тому

    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

  • @SystemTomcat
    @SystemTomcat 4 місяці тому +3

    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 ;)

    • @nirlichtman
      @nirlichtman  4 місяці тому +3

      Next vid will be the gui distro :)

  • @ViRuS889
    @ViRuS889 3 місяці тому +1

    Bro is G.O.A.T.

  • @bhavyakukkar
    @bhavyakukkar 4 місяці тому +2

    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

    • @nirlichtman
      @nirlichtman  4 місяці тому +4

      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.

    • @ingilizadam
      @ingilizadam 4 місяці тому +1

      @@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.

  • @mattshu
    @mattshu 4 місяці тому

    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

  • @doukey
    @doukey 4 місяці тому

    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

    • @nirlichtman
      @nirlichtman  4 місяці тому

      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.

    • @doukey
      @doukey 4 місяці тому

      @@nirlichtman I can see You update your projecy very often. I will try newest version. Thanks.

  • @shambles55
    @shambles55 4 місяці тому +1

    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?

    • @nirlichtman
      @nirlichtman  4 місяці тому +2

      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

    • @shambles55
      @shambles55 4 місяці тому

      @@nirlichtman thank you and I can't wait :)

  • @diver2048
    @diver2048 4 місяці тому

    Remove window titlebars, draw border around and it will look nice))

  • @ayoodawg1104
    @ayoodawg1104 4 місяці тому

    Cool video

  • @mzakyr42
    @mzakyr42 4 місяці тому

    bro is a menace

  • @JamesSmith-ix5jd
    @JamesSmith-ix5jd 3 місяці тому +1

    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.

    • @nirlichtman
      @nirlichtman  3 місяці тому

      What exactly do you mean, which tools like this exist on Linux?

    • @JamesSmith-ix5jd
      @JamesSmith-ix5jd 3 місяці тому

      @@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.

  • @pleaseenteraname1215
    @pleaseenteraname1215 4 місяці тому

    Love it

  • @its_code
    @its_code 4 місяці тому

    ❤❤❤❤❤😊 amazing 👏

  • @michelvosje
    @michelvosje 4 місяці тому +1

    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.

    • @davidfrischknecht8261
      @davidfrischknecht8261 Місяць тому

      I use AutoHotKey on my Lenovo ThinkPad P72 to turn its manually-controlled keyboard backlight into one that turns on and off automatically.

  • @AndrewDavidWilson
    @AndrewDavidWilson 4 місяці тому +3

    Instead of the busywait I would use Sleep(-1)

    • @zuctivazenci
      @zuctivazenci 4 місяці тому

      Could you explain why? Is there a difference in performance or something?

    • @AndrewDavidWilson
      @AndrewDavidWilson 4 місяці тому

      Performance yes. A for loop that does nothing will take CPU time, while Sleep(-1) does not.

  • @vaknins33
    @vaknins33 4 місяці тому

    כל הכבוד!

  • @cypherop2608
    @cypherop2608 4 місяці тому

    🔥🔥

  • @fuzzy-02
    @fuzzy-02 2 місяці тому

    Would it be possible to do this in another language such as Go? Or the complexity is just not worth it?

    • @nirlichtman
      @nirlichtman  2 місяці тому +1

      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

  • @bcspm1bcspm158
    @bcspm1bcspm158 3 місяці тому

    What are the minimal system requirements? Will it work on Windows 95 OSR2? Windows NT4? XP?

    • @nirlichtman
      @nirlichtman  3 місяці тому

      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)

  • @rian0xFFF
    @rian0xFFF 4 місяці тому

    Do you plan any c++ videos or just c?

    • @nirlichtman
      @nirlichtman  4 місяці тому

      Yes also C++ is planned 👍

  • @ajko000
    @ajko000 4 місяці тому

    What font & syntax highlighting are you using in gvim?

    • @nirlichtman
      @nirlichtman  3 місяці тому +1

      The welcome link on the channel has my vimrc

  • @angelffg
    @angelffg 4 місяці тому

    Woooow !!!!!!!!

  • @tech477
    @tech477 4 місяці тому

    Not quite related, but I would love you to do a lesson on ncurses, if you are familiar with the library.

    • @nirlichtman
      @nirlichtman  3 місяці тому

      On my video about making snake in C I use ncurses :)

  • @Karivelia
    @Karivelia 4 місяці тому

    please put up a donation page bro, we gotta give something back for your great vids

    • @nirlichtman
      @nirlichtman  4 місяці тому

      Appreciate the compliment! I will consider that :)

  • @wandogma
    @wandogma 4 місяці тому

    not work in win11, no response after binary is executed. only work for win10?

    • @nirlichtman
      @nirlichtman  4 місяці тому

      It works for Win11 as well, I fixed a few stuff on the Github repo, welcome to try out the latest code from there.

    • @wandogma
      @wandogma 4 місяці тому

      Thx:) it’s appreciated.

  • @boom1188
    @boom1188 4 місяці тому

    Can you help, thanks in advance.
    After manually compiling files with CL from github, the program produces:
    [!] Error: GetProcAddress failed.
    Win32 Last Error: 127

    • @nirlichtman
      @nirlichtman  4 місяці тому

      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

    • @boom1188
      @boom1188 4 місяці тому

      ​@@nirlichtman if use nmake i recive erorr - makefile(21) : fatal error U1034: syntax error : separator missing

    • @nirlichtman
      @nirlichtman  4 місяці тому +1

      @@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

    • @nirlichtman
      @nirlichtman  4 місяці тому +1

      @@boom1188 made a little fix in the make file, welcome to try now maybe it will help

    • @boom1188
      @boom1188 4 місяці тому

      @@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.

  • @guilherme5094
    @guilherme5094 4 місяці тому

    👍👍!

  • @n-uv7vg
    @n-uv7vg 4 місяці тому +1

    now tell us how to make dwm/i3 for windows like you have on your other videos

    • @nirlichtman
      @nirlichtman  4 місяці тому +1

      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.

    • @n-uv7vg
      @n-uv7vg 4 місяці тому

      i tought you made it or something ;)

    • @nirlichtman
      @nirlichtman  4 місяці тому +1

      @@n-uv7vg i contributed to it a bit but the project is someone elses

    • @n-uv7vg
      @n-uv7vg 4 місяці тому

      ok

  • @theSoberSobber
    @theSoberSobber 4 місяці тому +2

    Graphical linux distro from scratch when?

    • @cyrilemeka6987
      @cyrilemeka6987 4 місяці тому

      😂😂

    • @nirlichtman
      @nirlichtman  4 місяці тому +1

      Next one :)

    • @theSoberSobber
      @theSoberSobber 4 місяці тому

      @@nirlichtman cool!

    • @jyothishkumar3098
      @jyothishkumar3098 4 місяці тому

      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

  • @trwwrt5687
    @trwwrt5687 4 місяці тому +1

    Can you make a video about sending mails with C or C++ on Windows

  • @gosipdev
    @gosipdev 4 місяці тому

    we needed this in the 2000s so linux fanatics would'nt hate that much on windows

    • @heejadeetorn753
      @heejadeetorn753 4 місяці тому +1

      They don't hate Windows for it, the autists do it for a sense of belonging to some community, like k-pop fangirls

    • @roberthelps8715
      @roberthelps8715 4 місяці тому

      windows API is garbage though. This video was painful to watch.

    • @JamesSmith-ix5jd
      @JamesSmith-ix5jd 3 місяці тому

      ​@@roberthelps8715 So is Xorg, welcome to the real world.

  • @catus7787
    @catus7787 4 місяці тому

    yo what font is that

    • @nirlichtman
      @nirlichtman  4 місяці тому

      Lucida Console, welcome link on the channel has my full vimrc

    • @catus7787
      @catus7787 4 місяці тому

      @@nirlichtman thanks man

  • @jyothishkumar3098
    @jyothishkumar3098 4 місяці тому

    Plans for Wayland compositor?

  • @dorktales254
    @dorktales254 Місяць тому

    I thought it was illegal to mix C and Windows API code 😆

  • @neerajlamsal724
    @neerajlamsal724 4 місяці тому

    Guy writes c in vim with no lsp damn

  • @tenzingyatso5096
    @tenzingyatso5096 3 місяці тому

    Just switch to Linux, if you can do that, your smart enough for Linux

  • @storojilo
    @storojilo 4 місяці тому

    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.

    • @nirlichtman
      @nirlichtman  4 місяці тому

      Thanks for the feedback will work on a fix for next vids 👍

    • @storojilo
      @storojilo 4 місяці тому

      @@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.

    • @storojilo
      @storojilo 4 місяці тому

      @@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.

    • @storojilo
      @storojilo 4 місяці тому

      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.

    • @nirlichtman
      @nirlichtman  4 місяці тому +1

      @@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

  • @gahshunker
    @gahshunker 4 місяці тому

    but why for(;;){} and not while(true) as normal mortals do an infinite loop?

    • @nirlichtman
      @nirlichtman  4 місяці тому +1

      I like using for ;; instead of while true since sometimes the compiler issues a warning if you use a constant in a while condition

    • @gahshunker
      @gahshunker 4 місяці тому

      ​@@nirlichtman makes sense, thanks.

  • @ZAcharyIndy
    @ZAcharyIndy 4 місяці тому

    This is lower level code looks like

  • @_idiot
    @_idiot 4 місяці тому

    windows, vim without plugins and a wack font???......come on smart guy figure it out!

  • @user-gh4lv2ub2j
    @user-gh4lv2ub2j 4 місяці тому

    Niceeeeeeeeeeee