From 4e6066a8c8f54266afd65c18f3d6df2f657c7cc5 Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Wed, 4 Jun 2008 16:42:11 -0700 Subject: aspect ratio wm hints --- src/main.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/main.c b/src/main.c index 8a6abf3..f0baad1 100644 --- a/src/main.c +++ b/src/main.c @@ -5,6 +5,7 @@ #include #include +#include #include #include @@ -38,6 +39,14 @@ unsigned int getshift(unsigned int mask){ return popcount((mask - 1) & ~mask) & 31; } +void setaspect(int w, int h){ + XSizeHints *hints = XAllocSizeHints(); + hints->flags = PAspect; + hints->min_aspect.x = hints->max_aspect.x = w; + hints->min_aspect.y = hints->max_aspect.y = h; + XSetWMNormalHints(display, window, hints); +} + XImage *create_image_from_buffer(unsigned char *buf, int width, int height, int bufwidth, int bufheight) { int depth; XImage *img = NULL; @@ -163,12 +172,14 @@ struct imagenode *buildlist(int argc, char *argv[]){ } } + void init(){ display = XOpenDisplay (NULL); assert(display); screen = DefaultScreen(display); window = XCreateWindow(display, DefaultRootWindow(display), 0, 0, 640, 480, 0, DefaultDepth(display, screen), InputOutput, CopyFromParent, 0, NULL); + setaspect(1, 1); gc = XCreateGC(display, window, 0, NULL); XMapRaised(display, window); @@ -193,7 +204,6 @@ void run(struct imagenode *image){ XNextEvent(display, &event); switch(event.type){ case MapNotify: - printf("map\n"); break; case ConfigureNotify: if(width != event.xconfigure.width || height != event.xconfigure.height){ @@ -203,11 +213,9 @@ void run(struct imagenode *image){ width = event.xconfigure.width; height = event.xconfigure.height; } - printf("%i, %i\n", width, height); break; case Expose: redraw = 1; - printf("expose\n"); break; case KeyPress: switch(XLookupKeysym(&event.xkey, 0)){ @@ -259,6 +267,7 @@ void run(struct imagenode *image){ tmp->next->prev = tmp->prev; free(tmp); } + setaspect(bufwidth, bufheight); } if(!img){ if(width * bufheight > height * bufwidth){ -- cgit v1.2.3