🎨 Aswm structure
This commit is contained in:
		
							parent
							
								
									3096ba0637
								
							
						
					
					
						commit
						0923b1bf79
					
				
					 4 changed files with 64 additions and 43 deletions
				
			
		| 
						 | 
					@ -8,6 +8,7 @@ set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fsanitize=address")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
add_executable(aswm
 | 
					add_executable(aswm
 | 
				
			||||||
	src/aswm/main.c
 | 
						src/aswm/main.c
 | 
				
			||||||
 | 
						src/aswm/aswm.c
 | 
				
			||||||
	src/aswm/event_handlers/create.c
 | 
						src/aswm/event_handlers/create.c
 | 
				
			||||||
	src/aswm/event_handlers/configure.c
 | 
						src/aswm/event_handlers/configure.c
 | 
				
			||||||
	src/aswm/event_handlers/reparent.c
 | 
						src/aswm/event_handlers/reparent.c
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										11
									
								
								include/aswm/aswm.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								include/aswm/aswm.h
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,11 @@
 | 
				
			||||||
 | 
					#include <X11/Xlib.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef struct {
 | 
				
			||||||
 | 
						Display *display;
 | 
				
			||||||
 | 
						Window root;
 | 
				
			||||||
 | 
					} aswm;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void AswmOpen();
 | 
				
			||||||
 | 
					void AswmEventLoop();
 | 
				
			||||||
 | 
					void AswmClose();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										48
									
								
								src/aswm/aswm.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								src/aswm/aswm.c
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,48 @@
 | 
				
			||||||
 | 
					#include "aswm/aswm.h"
 | 
				
			||||||
 | 
					#include "aswm/event_handlers/create.h"
 | 
				
			||||||
 | 
					#include "aswm/event_handlers/configure.h"
 | 
				
			||||||
 | 
					#include "aswm/event_handlers/map.h"
 | 
				
			||||||
 | 
					#include "aswm/event_handlers/reparent.h"
 | 
				
			||||||
 | 
					#include "aswm/event_handlers/destroy.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					aswm _aswm;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void AswmOpen() {
 | 
				
			||||||
 | 
						_aswm.display = XOpenDisplay(NULL);
 | 
				
			||||||
 | 
						_aswm.root = DefaultRootWindow(_aswm.display);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						XSelectInput(_aswm.display, _aswm.root, SubstructureRedirectMask | SubstructureNotifyMask);
 | 
				
			||||||
 | 
						XSync(_aswm.display, 0);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void AswmEventLoop() {
 | 
				
			||||||
 | 
						for (;;) {
 | 
				
			||||||
 | 
							XEvent e;
 | 
				
			||||||
 | 
							XNextEvent(_aswm.display, &e);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							switch(e.type) {
 | 
				
			||||||
 | 
								case CreateNotify:
 | 
				
			||||||
 | 
									OnCreateNotify(&e.xcreatewindow);
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								case ConfigureRequest:
 | 
				
			||||||
 | 
									OnConfigureRequest(&e.xconfigurerequest);
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								case MapRequest:
 | 
				
			||||||
 | 
									OnMapRequest(_aswm.root, &e.xmaprequest);
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								case DestroyNotify:
 | 
				
			||||||
 | 
									OnDestroyNotify(&e.xdestroywindow);
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								case ReparentNotify:
 | 
				
			||||||
 | 
									OnReparentNotify(&e.xreparent);
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								default:
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
										/* LOG(WARNING) << "Ignored event"; */
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void AswmClose() {
 | 
				
			||||||
 | 
						XCloseDisplay(_aswm.display);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -1,46 +1,7 @@
 | 
				
			||||||
#include <X11/Xlib.h>
 | 
					#include "aswm/aswm.h"
 | 
				
			||||||
#include "aswm/event_handlers/create.h"
 | 
					 | 
				
			||||||
#include "aswm/event_handlers/configure.h"
 | 
					 | 
				
			||||||
#include "aswm/event_handlers/map.h"
 | 
					 | 
				
			||||||
#include "aswm/event_handlers/reparent.h"
 | 
					 | 
				
			||||||
#include "aswm/event_handlers/destroy.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
Display *display;
 | 
					 | 
				
			||||||
Window root;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
int main(int argc, char** argv) {
 | 
					int main(int argc, char** argv) {
 | 
				
			||||||
	display = XOpenDisplay(NULL);
 | 
						AswmOpen();
 | 
				
			||||||
 | 
						AswmEventLoop();
 | 
				
			||||||
	root = DefaultRootWindow(display);
 | 
						AswmClose();
 | 
				
			||||||
 | 
					 | 
				
			||||||
	XSelectInput(display, root, SubstructureRedirectMask | SubstructureNotifyMask);
 | 
					 | 
				
			||||||
	XSync(display, 0);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	for (;;) {
 | 
					 | 
				
			||||||
		XEvent e;
 | 
					 | 
				
			||||||
		XNextEvent(display, &e);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		switch(e.type) {
 | 
					 | 
				
			||||||
			case CreateNotify:
 | 
					 | 
				
			||||||
				OnCreateNotify(&e.xcreatewindow);
 | 
					 | 
				
			||||||
				break;
 | 
					 | 
				
			||||||
			case ConfigureRequest:
 | 
					 | 
				
			||||||
				OnConfigureRequest(&e.xconfigurerequest);
 | 
					 | 
				
			||||||
				break;
 | 
					 | 
				
			||||||
			case MapRequest:
 | 
					 | 
				
			||||||
				OnMapRequest(root, &e.xmaprequest);
 | 
					 | 
				
			||||||
				break;
 | 
					 | 
				
			||||||
			case DestroyNotify:
 | 
					 | 
				
			||||||
				OnDestroyNotify(&e.xdestroywindow);
 | 
					 | 
				
			||||||
				break;
 | 
					 | 
				
			||||||
			case ReparentNotify:
 | 
					 | 
				
			||||||
				OnReparentNotify(&e.xreparent);
 | 
					 | 
				
			||||||
				break;
 | 
					 | 
				
			||||||
			default:
 | 
					 | 
				
			||||||
				break;
 | 
					 | 
				
			||||||
					/* LOG(WARNING) << "Ignored event"; */
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	XCloseDisplay(display);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue