For a game engine, I had to make a windowing library using X11... It was painful. I wish this video existed 2 years ago, but either way, I love your content! Nice work!
I mean, it is very much like the Win32 API. BUUUT, i hate that its names are generic. for example, it overrode "None" which literally fucked up my code. I had to #undef like 8-9 different preprocessors :/
It's kinda like piano vs guitar - sure, it's easier to achieve the basics on X11 (piano) vs. Windows (guitar)... but much like mastering any instrument, building the full Windows GUI takes just as much effort and pain as building something equivalent to KDE or GNOME :D
I wrote a simple X11 GUI (only keyboard input and graphical output) a few months ago and I was pleasantly surprised how easy it was. Almost as easy as writing a gui with ncurses.
good to see people take interest in this type of thing still. i am writing a desktop environment for x11 using xcb for my final year project. even if the technologies are old, and xlib is vastly inferior due to architecture reasons to xcb, this is something people can still very much use to create some perhaps rudimentary applications. thank you for the video.
Interesting! Less code than with the simple GUI window you created on Windows but far more reading of the docs. lol I've never actually written any GUI code in C, so both videos were fun to watch! Thanks for posting!
Love your videos, could you please make the font bigger and change the color scheme for one with a better contrast? It's hard to read on smaller screens
As always great video Nir.. Unless I missed something, it would be great if you can explain how this very example works at a high level. I see the term x11 server thrown around, but couldn't really grok it yet. x11 is like a server between kernel and user-space application which takes the commands and would draw stuff on the window?!
Thanks! Basically, at a high level there is the X11 Server which actually controls the graphics on the display and gets the input from the keyboard and mouse and you have the clients which all connect to the server to request drawing graphics and they also get events from the server for example mouse/keyboard clicks. The program I made in the video is an example of an X11 client.
When I try to compile it, I get an error message (on the #include line) that says "X11/xlib.h: No such file or directory". But I've installed the packages listed in the description. Do you know why this is happening? Edit: Ah! I typed "xlib.h" instead of "Xlib.h". It's hard for me to see the dark magenta text on the black background in the video. Well, hopefully this helps anyone who has the same issue.
Great video, have you considered implementing a simple stack-based virtual machine in one of your videos? I feel like it would be simple and self-contained enough for your style of video.
you make cool coding videos. i would like to know whether you have a video introduce your coding env/ide etc. i like how vim auto-complete and split term and man pages. will you talk about your vim plugins...etc
Thanks! I have a playlist "Vim Tips" where I talk a lot about my workflow, I only use two Vim plugins both related to LSP and I have videos about that as well :)
Hello, I like your videos, they show some concepts in a simple and quick way. Maybe you can help me.I want to create a program that allows me to password protect any program I have installed to run (Chrome, Steam, etc.), that is, when I click on a program to open it, a dialog box appears asking me to enter a password. If it is correct, the program opens, otherwise it does not. I want to do all this for Windows, I have been looking for what processes or libraries I should use to listen to an event when a program starts but I am a little confused, I don't know where to start. Maybe you can help me with that.
there's some serious difficulty with making this in a secure way but a basic, silly way to achieve this and protect your stuff from a non-technical user would be to monitor create window events on the root window using your always-running program, popping up a window that covers the whole screen and asking for a password that will be compared to something you perhaps hardcoded in. if the strings are equal, close window and resume normal operation. otherwise, kill the opened window by taking away a resource (there's this function you can just pass the opened window there and the program will effectively just close).
Hi Nir bro, Bro, how to create a cli-based app that waits for a specific file, if that specific file will be opened by another program or another process, it prints a message to the console, like "hey, that file is being used"? Thanks in advance for your response, good luck for your future videos!
Windows or Linux? For Windows the closest API I can think of is FindFirstChangeNotification ( learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-findfirstchangenotificationw ) but it will notify you only when there is a change in the files, I don't think it can notify when files are just opened. If I think of something more suitable I will update here.
@@AggamRahamim-fs2zm i can't speak for him, but maybe it's just habit? Even if he has a reason I don't think there is much knowledge you can gain from this.
Hi! can you give brief overview. How you can build a small tiling manager or desktop environment on top of X11. Can you please make a brief video, on the architecture or what technology they use.
The lightest ones use pure X11 - I believe in you! You'll learn a ton more just implementing it yourself based on the manual pages, it's a fantastic project to learn how both X Windows and GUIs in general function :)
i started making exactly this 5 years ago. still incomplete but it's advanced far too much and i have reason to complete it. give it a go and don't give up!
@@n_for_n I ment to say there is nothing like "coding a window" in Wayland. A Wayland client sends it's buffer to the Wayland server(typically a window manager) using shared memory. And the Wayland server is responsible for compositing and rendering it. For some reason people are not aware where Wayland fits in the linux graphics stack.
@@DeveshNeneHow do custom window decorations work then? Also wouldn't the analogy then simply be about coding a Wayland compositor, as that is creating the windows for a given input buffer?
Your topic is awesome, and using sources for implementation is a great idea, but the application is terrible, we learn nothing from this way, it's like you're cheating, it's like you're just copy pasting. I hope you use a real board and a style and write a tutorial, so you think step by step like us, from scratch, without constructing ideas without thinking whether it's clear, coherent, and conscious for us or not.
He's not necessarily making tutorials. There's literally TONS of tutorial videos if you want to learn programming. To follow his vids, it helps to know at least the basics: variables, loops, arrays, functions, header files, etc.
It's literally not cheating to check manual pages for a library - how else are you supposed to utilize it? Literally read all of the X11 source code directly? Or reimplement your own windowing system from scratch!?
@CaptTerrific When I watch the Jonathan-Blow programming or @tsoding or sometimes @Teejtv and so on... we watch the high-level programming session, there's never a dull moment, the programming becomes fun. Tsoding and Jonathan don't use any autocompletions like you, but they write the art... For me to build a GUI in C, we discuss why we should use X11 and what it is, and the power of X11, something interesting like that, then start from "hello world", compile it, then the other students, can't wait to see the first step to use X11, as you see the students are excited to watch more... and don't feel this is boring...
For a game engine, I had to make a windowing library using X11...
It was painful.
I wish this video existed 2 years ago, but either way, I love your content!
Nice work!
I mean, it is very much like the Win32 API.
BUUUT, i hate that its names are generic. for example, it overrode "None" which literally fucked up my code. I had to #undef like 8-9 different preprocessors :/
just use glfw brah..
I like how this is easier than Windows API... You know, the operating system known for it's GUI
It's kinda like piano vs guitar - sure, it's easier to achieve the basics on X11 (piano) vs. Windows (guitar)... but much like mastering any instrument, building the full Windows GUI takes just as much effort and pain as building something equivalent to KDE or GNOME :D
@@CaptTerrific now wayland is like learning violin
I wrote a simple X11 GUI (only keyboard input and graphical output) a few months ago and I was pleasantly surprised how easy it was. Almost as easy as writing a gui with ncurses.
@@_denzy_6310 lol that's apt
@@CaptTerrific
no that's pacman
:^)
good to see people take interest in this type of thing still. i am writing a desktop environment for x11 using xcb for my final year project. even if the technologies are old, and xlib is vastly inferior due to architecture reasons to xcb, this is something people can still very much use to create some perhaps rudimentary applications. thank you for the video.
Normal people would never see it that way, but this is really hardcore ! Fascinating !
Wow X11 is shockingly simple!
You made me wanna learn C with this simple video
Such a tight demo. Extraordinary content, thanks so very much.
Interesting! Less code than with the simple GUI window you created on Windows but far more reading of the docs. lol I've never actually written any GUI code in C, so both videos were fun to watch! Thanks for posting!
Love your videos, could you please make the font bigger and change the color scheme for one with a better contrast? It's hard to read on smaller screens
Agree, the color scheme needs changing immediately. I cannot read a single letter on my phone. Love the video though.
do people really watch this stuff on a phone
@@shallex5744i watch these tutorials in free time in my phone. When actually coding it's faster to read docs than following a video
@@shallex5744I do
@@shallex5744 yes
Really Nice Video. And thank you for the references
Can I ask for a simple Wayland GUI Window on Linux? :)
Wow, the best tutorial I ever seen of introduction to GUI in C. Regardless it's x11 anyway :).
Another great vid, as always! Thanks nir!
Thanks! Good content again! Could you eventually also demonstrate the concept of x windows client and server in this context?
Yes, interesting subject!
As always great video Nir..
Unless I missed something, it would be great if you can explain how this very example works at a high level. I see the term x11 server thrown around, but couldn't really grok it yet.
x11 is like a server between kernel and user-space application which takes the commands and would draw stuff on the window?!
Thanks! Basically, at a high level there is the X11 Server which actually controls the graphics on the display and gets the input from the keyboard and mouse and you have the clients which all connect to the server to request drawing graphics and they also get events from the server for example mouse/keyboard clicks. The program I made in the video is an example of an X11 client.
When I try to compile it, I get an error message (on the #include line) that says "X11/xlib.h: No such file or directory". But I've installed the packages listed in the description. Do you know why this is happening?
Edit: Ah! I typed "xlib.h" instead of "Xlib.h". It's hard for me to see the dark magenta text on the black background in the video. Well, hopefully this helps anyone who has the same issue.
Great video, have you considered implementing a simple stack-based virtual machine in one of your videos?
I feel like it would be simple and self-contained enough for your style of video.
Thanks! Could you elaborate what exactly you mean?
@@nirlichtman I mean the type of virtual machine that you might find inside a simple interpreter.
Perhaps it doesn't make much sense on its own
Interesting, this can be a cool project, perhaps make it as minimalist as possible :)
you make cool coding videos. i would like to know whether you have a video introduce your coding env/ide etc. i like how vim auto-complete and split term and man pages. will you talk about your vim plugins...etc
Thanks! I have a playlist "Vim Tips" where I talk a lot about my workflow, I only use two Vim plugins both related to LSP and I have videos about that as well :)
Wow, what distro Linux/DE do you use?
I use Windows WSL with Debian, the terminal emulator I use in this video is xterm
Hello, I like your videos, they show some concepts in a simple and quick way. Maybe you can help me.I want to create a program that allows me to password protect any program I have installed to run (Chrome, Steam, etc.), that is, when I click on a program to open it, a dialog box appears asking me to enter a password. If it is correct, the program opens, otherwise it does not. I want to do all this for Windows, I have been looking for what processes or libraries I should use to listen to an event when a program starts but I am a little confused, I don't know where to start. Maybe you can help me with that.
there's some serious difficulty with making this in a secure way but a basic, silly way to achieve this and protect your stuff from a non-technical user would be to monitor create window events on the root window using your always-running program, popping up a window that covers the whole screen and asking for a password that will be compared to something you perhaps hardcoded in. if the strings are equal, close window and resume normal operation. otherwise, kill the opened window by taking away a resource (there's this function you can just pass the opened window there and the program will effectively just close).
next episode for wayland?
i will be waiting wayland tutorials
Hi Nir bro,
Bro, how to create a cli-based app that waits for a specific file, if that specific file will be opened by another program or another process, it prints a message to the console, like "hey, that file is being used"?
Thanks in advance for your response, good luck for your future videos!
Windows or Linux? For Windows the closest API I can think of is FindFirstChangeNotification ( learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-findfirstchangenotificationw ) but it will notify you only when there is a change in the files, I don't think it can notify when files are just opened. If I think of something more suitable I will update here.
@@nirlichtman thanks bro, it should be for windows only
does this work on wayland?
Hey man I love your videos. I was wondering tho why use for (;;) insted of a while(1) loop?
If I am not wrong the compiler should optimise it to the same thing, so it won't matter.
Got no proof , just guessing based on intuition.
@@pianissimo7121 yeah that makes sense, but why do it in the first place?
@@AggamRahamim-fs2zm i can't speak for him, but maybe it's just habit? Even if he has a reason I don't think there is much knowledge you can gain from this.
umm lol ok@@pianissimo7121
Thanks! I prefer using "for (;;)" over "while (1)" since sometimes compilers issue a warning on while (1) having a constant condition.
general question: where do I learn about all of this stuff, I suppose the decumnetation but that place is a mess.
GOAT !!
👍Great!
Which editor are u using?
Vim, many of my early vids are about it :)
we need one for Wayland
Wayland window next ?
Thanks for the video!
But the high contrast color theme makes it harder to read. Still good video
Great!!!!!
Hi! can you give brief overview. How you can build a small tiling manager or desktop environment on top of X11. Can you please make a brief video, on the architecture or what technology they use.
I have been trying to do the same recently.
Check the source code for dwm?
Check out the source code for tinyWM. It's only ~50 loc and super easy to understand, much easier than dwm.
The lightest ones use pure X11 - I believe in you! You'll learn a ton more just implementing it yourself based on the manual pages, it's a fantastic project to learn how both X Windows and GUIs in general function :)
i started making exactly this 5 years ago. still incomplete but it's advanced far too much and i have reason to complete it. give it a go and don't give up!
Oh hot damn! This will be a fun project!
I wonder if this would work in a text-only environment...
There is the ncurses library for that. You can use unicode characters in order to simulate two pixels in each character on tge screen.
@@ザウアークラウトマン This will be perfect!!!! I have dabbled with Ncurses in the past so this will be fun
Thank you for this good sir!
How does this for loop work and what does it mean
for ( ; ; ) is a for loop with no condition so it acts as an infinite loop
the XCreateSimpleWindow function is giving me a segfault
wow cool
What about Wayland? X11 is actively dying out, and in a couple of years I think it will only be a distant memory
Wayland does not have the concept of windows. It has client and surfaces.lot of boiler plate is required to make it work.
Wayland is also a great subject, I plan on covering it as well (and maybe also using it in the future video I plan about making a GUI distro)
@@DeveshNene I know, but asking about a surface in a comment below a "coding a window" video seemed weird
@@n_for_n I ment to say there is nothing like "coding a window" in Wayland. A Wayland client sends it's buffer to the Wayland server(typically a window manager) using shared memory. And the Wayland server is responsible for compositing and rendering it. For some reason people are not aware where Wayland fits in the linux graphics stack.
@@DeveshNeneHow do custom window decorations work then? Also wouldn't the analogy then simply be about coding a Wayland compositor, as that is creating the windows for a given input buffer?
Just to say was here 👍
terminal name?
I think in this video I used xterm
I FUCKING LOVE C
Minor niggle: The dark purple on black is not the best colour for this.
Thanks for the feedback, will improve for future vids 👍
keyboard clicking is a bit too much. otherwise, great video
thx for the feedback, working on finding the correct position for the mic 👍
You should really use a different color sceme for YT Videos. All of the darker text is barely readable with the video compression
thx for the feedback, will fix for next vids 👍
thx for the feedback, will fix for next vids 👍
Your topic is awesome, and using sources for implementation is a great idea, but the application is terrible, we learn nothing from this way, it's like you're cheating, it's like you're just copy pasting.
I hope you use a real board and a style and write a tutorial, so you think step by step like us, from scratch, without constructing ideas without thinking whether it's clear, coherent, and conscious for us or not.
He's not necessarily making tutorials. There's literally TONS of tutorial videos if you want to learn programming. To follow his vids, it helps to know at least the basics: variables, loops, arrays, functions, header files, etc.
It's literally not cheating to check manual pages for a library - how else are you supposed to utilize it? Literally read all of the X11 source code directly? Or reimplement your own windowing system from scratch!?
@CaptTerrific
When I watch the Jonathan-Blow programming or @tsoding or sometimes @Teejtv and so on... we watch the high-level programming session, there's never a dull moment, the programming becomes fun. Tsoding and Jonathan don't use any autocompletions like you, but they write the art...
For me to build a GUI in C, we discuss why we should use X11 and what it is, and the power of X11, something interesting like that, then start from "hello world", compile it, then the other students, can't wait to see the first step to use X11, as you see the students are excited to watch more... and don't feel this is boring...
_if all else fails, you can do it yourself._