Draw osd only on the primary monitor if randr extensions are available
This commit is contained in:
		
							parent
							
								
									a0af850b29
								
							
						
					
					
						commit
						5c08e40e12
					
				
					 4 changed files with 72 additions and 11 deletions
				
			
		| 
						 | 
					@ -1,7 +1,7 @@
 | 
				
			||||||
CC		= gcc
 | 
					CC		= gcc
 | 
				
			||||||
CFLAGS		= -std=gnu99 -O3 -W -Wall `pkg-config --cflags alsa`
 | 
					CFLAGS		= -std=gnu99 -O3 -W -Wall `pkg-config --cflags alsa xrandr`
 | 
				
			||||||
LDFLAGS		= -L/usr/X11R6/lib
 | 
					LDFLAGS		= -L/usr/X11R6/lib
 | 
				
			||||||
LIBS		= -lXpm -lXext -lX11 -lm `pkg-config --libs alsa`
 | 
					LIBS		= -lXpm -lXext -lX11 -lm `pkg-config --libs alsa xrandr`
 | 
				
			||||||
OBJECTS		= misc.o config.o mixer-alsa.o mixer-oss.o ui_x.o mmkeys.o wmix.o
 | 
					OBJECTS		= misc.o config.o mixer-alsa.o mixer-oss.o ui_x.o mmkeys.o wmix.o
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# where to install this program (also for packaging stuff)
 | 
					# where to install this program (also for packaging stuff)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -18,11 +18,11 @@
 | 
				
			||||||
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 | 
					 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void		dockapp_init	(Display *x_display);
 | 
					void		dockapp_init	(Display *x_display, Bool randr);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void		new_window	(char *name, int width, int height);
 | 
					void		new_window	(char *name, int width, int height);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void		new_osd		(int width, int height);
 | 
					void		new_osd		(int height);
 | 
				
			||||||
void		update_osd	(float volume, bool up);
 | 
					void		update_osd	(float volume, bool up);
 | 
				
			||||||
void		map_osd		(void);
 | 
					void		map_osd		(void);
 | 
				
			||||||
void		unmap_osd	(void);
 | 
					void		unmap_osd	(void);
 | 
				
			||||||
| 
						 | 
					@ -38,3 +38,5 @@ void		knob_turn	(float delta);
 | 
				
			||||||
void		slider_move	(float delta);
 | 
					void		slider_move	(float delta);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
unsigned long	get_color	(Display *display, char *color_name);
 | 
					unsigned long	get_color	(Display *display, char *color_name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void            ui_rrnotify     (void);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										51
									
								
								wmix/ui_x.c
									
									
									
									
									
								
							
							
						
						
									
										51
									
								
								wmix/ui_x.c
									
									
									
									
									
								
							| 
						 | 
					@ -35,6 +35,7 @@
 | 
				
			||||||
#include <X11/extensions/shape.h>
 | 
					#include <X11/extensions/shape.h>
 | 
				
			||||||
#include <X11/xpm.h>
 | 
					#include <X11/xpm.h>
 | 
				
			||||||
#include <X11/cursorfont.h>
 | 
					#include <X11/cursorfont.h>
 | 
				
			||||||
 | 
					#include <X11/extensions/Xrandr.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "include/master.xpm"
 | 
					#include "include/master.xpm"
 | 
				
			||||||
#include "include/led-on.xpm"
 | 
					#include "include/led-on.xpm"
 | 
				
			||||||
| 
						 | 
					@ -70,6 +71,8 @@ struct _Dockapp {
 | 
				
			||||||
    Window osd;
 | 
					    Window osd;
 | 
				
			||||||
    GC osd_gc;
 | 
					    GC osd_gc;
 | 
				
			||||||
    int osd_width;
 | 
					    int osd_width;
 | 
				
			||||||
 | 
					    int osd_x;
 | 
				
			||||||
 | 
					    int osd_y;
 | 
				
			||||||
    bool osd_mapped;
 | 
					    bool osd_mapped;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
| 
						 | 
					@ -103,11 +106,15 @@ static Cursor hand_cursor;
 | 
				
			||||||
static Cursor null_cursor;
 | 
					static Cursor null_cursor;
 | 
				
			||||||
static Cursor norm_cursor;
 | 
					static Cursor norm_cursor;
 | 
				
			||||||
static Cursor bar_cursor;
 | 
					static Cursor bar_cursor;
 | 
				
			||||||
 | 
					static Bool have_randr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* public methods */
 | 
					/* public methods */
 | 
				
			||||||
void dockapp_init(Display *x_display)
 | 
					void dockapp_init(Display *x_display, Bool randr)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    display = x_display;
 | 
					    display = x_display;
 | 
				
			||||||
 | 
					    have_randr = randr;
 | 
				
			||||||
 | 
					    dockapp.osd = 0;
 | 
				
			||||||
 | 
					    dockapp.gc = 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void redraw_window(void)
 | 
					void redraw_window(void)
 | 
				
			||||||
| 
						 | 
					@ -328,7 +335,7 @@ void new_window(char *name, int width, int height)
 | 
				
			||||||
    XMapWindow(display, win);
 | 
					    XMapWindow(display, win);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void new_osd(int width, int height)
 | 
					void new_osd(int height)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    Window osd;
 | 
					    Window osd;
 | 
				
			||||||
    Pixel fg, bg;
 | 
					    Pixel fg, bg;
 | 
				
			||||||
| 
						 | 
					@ -338,20 +345,45 @@ void new_osd(int width, int height)
 | 
				
			||||||
    XSetWindowAttributes xattributes;
 | 
					    XSetWindowAttributes xattributes;
 | 
				
			||||||
    int win_layer = 6;
 | 
					    int win_layer = 6;
 | 
				
			||||||
    XFontStruct *fs = NULL;
 | 
					    XFontStruct *fs = NULL;
 | 
				
			||||||
 | 
					    XRRScreenResources *screen;
 | 
				
			||||||
 | 
					    XRRCrtcInfo *crtc_info;
 | 
				
			||||||
 | 
					    int width;
 | 
				
			||||||
 | 
					    int x;
 | 
				
			||||||
 | 
					    int y;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (have_randr) {
 | 
				
			||||||
 | 
					        screen = XRRGetScreenResources(display, DefaultRootWindow(display));
 | 
				
			||||||
 | 
					        crtc_info = XRRGetCrtcInfo(display, screen, screen->crtcs[0]);
 | 
				
			||||||
 | 
					        width = crtc_info->width - 200;
 | 
				
			||||||
 | 
					        x = crtc_info->x + 100;
 | 
				
			||||||
 | 
					        y = crtc_info->y + crtc_info->height - 120;
 | 
				
			||||||
 | 
					        if (dockapp.osd &&
 | 
				
			||||||
 | 
					            width == dockapp.osd_width &&
 | 
				
			||||||
 | 
					            x == dockapp.osd_x &&
 | 
				
			||||||
 | 
					            y == dockapp.osd_y) {
 | 
				
			||||||
 | 
					            // Nothing important has changed.
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        width = DisplayWidth(display, DefaultScreen(display)) - 200;
 | 
				
			||||||
 | 
					        x = 100;
 | 
				
			||||||
 | 
					        y = DisplayHeight(display, 0) - 120;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    sizehints.flags = USSize | USPosition;
 | 
					    sizehints.flags = USSize | USPosition;
 | 
				
			||||||
    sizehints.x = (DisplayWidth(display, 0) - width) / 2;
 | 
					    sizehints.x = x;
 | 
				
			||||||
    sizehints.y = (DisplayHeight(display, 0) - 120);
 | 
					    sizehints.y = y;
 | 
				
			||||||
    sizehints.width = width;
 | 
					    sizehints.width = width;
 | 
				
			||||||
    sizehints.height = height;
 | 
					    sizehints.height = height;
 | 
				
			||||||
    xattributes.save_under = True;
 | 
					    xattributes.save_under = True;
 | 
				
			||||||
    xattributes.override_redirect = True;
 | 
					    xattributes.override_redirect = True;
 | 
				
			||||||
    xattributes.cursor = None;
 | 
					    xattributes.cursor = None;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
    fg = WhitePixel(display, DefaultScreen(display));
 | 
					    fg = WhitePixel(display, DefaultScreen(display));
 | 
				
			||||||
    bg = BlackPixel(display, DefaultScreen(display));
 | 
					    bg = BlackPixel(display, DefaultScreen(display));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (dockapp.osd)
 | 
				
			||||||
 | 
					        XDestroyWindow(display, dockapp.osd);
 | 
				
			||||||
    osd = XCreateSimpleWindow(display, DefaultRootWindow(display),
 | 
					    osd = XCreateSimpleWindow(display, DefaultRootWindow(display),
 | 
				
			||||||
			      sizehints.x, sizehints.y, width, height,
 | 
								      sizehints.x, sizehints.y, width, height,
 | 
				
			||||||
			      0, fg, bg);
 | 
								      0, fg, bg);
 | 
				
			||||||
| 
						 | 
					@ -398,6 +430,8 @@ void new_osd(int width, int height)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (dockapp.osd_gc)
 | 
				
			||||||
 | 
					        XFreeGC(display, dockapp.osd_gc);
 | 
				
			||||||
    gc =
 | 
					    gc =
 | 
				
			||||||
	XCreateGC(display, osd,
 | 
						XCreateGC(display, osd,
 | 
				
			||||||
		  GCForeground | GCBackground | GCGraphicsExposures,
 | 
							  GCForeground | GCBackground | GCGraphicsExposures,
 | 
				
			||||||
| 
						 | 
					@ -407,6 +441,8 @@ void new_osd(int width, int height)
 | 
				
			||||||
    dockapp.osd = osd;
 | 
					    dockapp.osd = osd;
 | 
				
			||||||
    dockapp.osd_gc = gc;
 | 
					    dockapp.osd_gc = gc;
 | 
				
			||||||
    dockapp.osd_width = width;
 | 
					    dockapp.osd_width = width;
 | 
				
			||||||
 | 
					    dockapp.osd_x = x;
 | 
				
			||||||
 | 
					    dockapp.osd_y = y;
 | 
				
			||||||
    dockapp.osd_mapped = false;
 | 
					    dockapp.osd_mapped = false;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -613,3 +649,8 @@ unsigned long get_color(Display *display, char *color_name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return color.pixel;
 | 
					    return color.pixel;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void ui_rrnotify()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    new_osd(60);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										22
									
								
								wmix/wmix.c
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								wmix/wmix.c
									
									
									
									
									
								
							| 
						 | 
					@ -30,6 +30,7 @@
 | 
				
			||||||
#include <X11/X.h>
 | 
					#include <X11/X.h>
 | 
				
			||||||
#include <X11/Xlib.h>
 | 
					#include <X11/Xlib.h>
 | 
				
			||||||
#include <X11/Xutil.h>
 | 
					#include <X11/Xutil.h>
 | 
				
			||||||
 | 
					#include <X11/extensions/Xrandr.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "include/common.h"
 | 
					#include "include/common.h"
 | 
				
			||||||
#include "include/mixer.h"
 | 
					#include "include/mixer.h"
 | 
				
			||||||
| 
						 | 
					@ -64,6 +65,8 @@ static void choose_api(int api);
 | 
				
			||||||
int main(int argc, char **argv)
 | 
					int main(int argc, char **argv)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    XEvent event;
 | 
					    XEvent event;
 | 
				
			||||||
 | 
					    int rr_event_base, rr_error_base;
 | 
				
			||||||
 | 
					    Bool have_randr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    config_init();
 | 
					    config_init();
 | 
				
			||||||
    parse_cli_options(argc, argv);
 | 
					    parse_cli_options(argc, argv);
 | 
				
			||||||
| 
						 | 
					@ -89,12 +92,21 @@ int main(int argc, char **argv)
 | 
				
			||||||
	fprintf(stderr, "wmix:error: Unable to open display \"%s\"\n", name);
 | 
						fprintf(stderr, "wmix:error: Unable to open display \"%s\"\n", name);
 | 
				
			||||||
	return EXIT_FAILURE;
 | 
						return EXIT_FAILURE;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    have_randr = XRRQueryExtension(display, &rr_event_base, &rr_error_base);
 | 
				
			||||||
 | 
					    if (have_randr) {
 | 
				
			||||||
 | 
					        int rr_mask = RRScreenChangeNotifyMask;
 | 
				
			||||||
 | 
					        XRRSelectInput(display,
 | 
				
			||||||
 | 
					                       RootWindow(display, DefaultScreen(display)),
 | 
				
			||||||
 | 
					                       rr_mask);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    display_width = (float)DisplayWidth(display, DefaultScreen(display)) / 4.0;
 | 
					    display_width = (float)DisplayWidth(display, DefaultScreen(display)) / 4.0;
 | 
				
			||||||
    display_height = (float)DisplayHeight(display, DefaultScreen(display)) / 2.0;
 | 
					    display_height = (float)DisplayHeight(display, DefaultScreen(display)) / 2.0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    dockapp_init(display);
 | 
					    dockapp_init(display, have_randr);
 | 
				
			||||||
    new_window("wmix", 64, 64);
 | 
					    new_window("wmix", 64, 64);
 | 
				
			||||||
    new_osd(DisplayWidth(display, DefaultScreen(display)) - 200, 60);
 | 
					    new_osd(60);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (config.mmkeys)
 | 
					    if (config.mmkeys)
 | 
				
			||||||
	    mmkey_install(display);
 | 
						    mmkey_install(display);
 | 
				
			||||||
| 
						 | 
					@ -152,6 +164,12 @@ int main(int argc, char **argv)
 | 
				
			||||||
		    XCloseDisplay(display);
 | 
							    XCloseDisplay(display);
 | 
				
			||||||
		    return EXIT_SUCCESS;
 | 
							    return EXIT_SUCCESS;
 | 
				
			||||||
		default:
 | 
							default:
 | 
				
			||||||
 | 
					                    if (have_randr) {
 | 
				
			||||||
 | 
					                        if (event.type == rr_event_base + RRScreenChangeNotify) {
 | 
				
			||||||
 | 
					                            XRRUpdateConfiguration(&event);
 | 
				
			||||||
 | 
					                            ui_rrnotify();
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
		    break;
 | 
							    break;
 | 
				
			||||||
	    }
 | 
						    }
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue