All pastes #280539 Raw Edit

Anonymous

public c v1 · immutable
·published 2006-12-15 23:47 UTC
rendered paste body
/** * * Beryl group plugin * * group.h * * Copyright : (C) 2006 by Patrick Niklaus * E-mail    : patrick.niklaus [ a t ] googlemail.com * * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * * TODO: *      * glow effect *      * tab like switching between the windows *      * a lot of other tab stuff... *      * provide a tree system for groups * **/#include <stdio.h>#include <stdlib.h>#include <string.h>#include <malloc.h>#include <time.h>#include <X11/Xlib.h>#include <beryl.h>#include <beryl_ipcs.h>#include <X11/Xatom.h>#include <math.h>#include "group_glow.h"/* * Constants * */#define PI 3.1415926535897#define NUM_CORNER_POINTS 25//#define GROUP_DEBUG(fmt, args...) printf(fmt, ##args)#define GROUP_DEBUG(fmt, args...)#define GROUP_DISPLAY_OPTION_SELECT           0#define GROUP_DISPLAY_OPTION_SELECT_SINGLE    1#define GROUP_DISPLAY_OPTION_GROUPING         2#define GROUP_DISPLAY_OPTION_UNGROUPING       3#define GROUP_DISPLAY_OPTION_REMOVEING        4#define GROUP_DISPLAY_OPTION_CLOSEING         5#define GROUP_DISPLAY_OPTION_MINIMIZEING      6#define GROUP_DISPLAY_OPTION_IGNORE           7#define GROUP_DISPLAY_OPTION_TABMODE          8#define GROUP_DISPLAY_OPTION_CHANGE_TAB_LEFT  9#define GROUP_DISPLAY_OPTION_CHANGE_TAB_RIGHT 10#define GROUP_DISPLAY_OPTION_NUM              11#define GROUP_SCREEN_OPTION_TYPES               0#define GROUP_SCREEN_OPTION_OPACITY             1#define GROUP_SCREEN_OPTION_SATURATION          2#define GROUP_SCREEN_OPTION_BRIGHTNESS          3#define GROUP_SCREEN_OPTION_GLOW		4#define GROUP_SCREEN_OPTION_MOVE                5#define GROUP_SCREEN_OPTION_RESIZE              6#define GROUP_SCREEN_OPTION_RAISE               7#define GROUP_SCREEN_OPTION_AUTO_UNGROUP        8#define GROUP_SCREEN_OPTION_AUTO_GROUP          9#define GROUP_SCREEN_OPTION_RELATIVE_DISTANCE   10#define GROUP_SCREEN_OPTION_SELECTION_COLOR     11#define GROUP_SCREEN_OPTION_LINE_COLOR          12#define GROUP_SCREEN_OPTION_TOLERANCE           13#define GROUP_SCREEN_OPTION_STEPS               14#define GROUP_SCREEN_OPTION_THUMB_SIZE          15#define GROUP_SCREEN_OPTION_BORDER_WIDTH        16#define GROUP_SCREEN_OPTION_BORDER_RADIUS       17#define GROUP_SCREEN_OPTION_TAB_BORDER_COLOR	18#define GROUP_SCREEN_OPTION_TAB_FILL_COLOR	19#define GROUP_SCREEN_OPTION_TAB_CREATE_MIPMAPS	20#define GROUP_SCREEN_OPTION_GLOW_SIZE		21#define GROUP_SCREEN_OPTION_GLOW_OFFSET		22#define GROUP_SCREEN_OPTION_NUM                 23/* * Helpers * */#define GET_GROUP_DISPLAY(d) ((GroupDisplay *) (d)->privates[displayPrivateIndex].ptr)#define GROUP_DISPLAY(d) GroupDisplay *gd = GET_GROUP_DISPLAY (d)#define GET_GROUP_SCREEN(s, gd) ((GroupScreen *) (s)->privates[ (gd)->screenPrivateIndex].ptr)#define GROUP_SCREEN(s) GroupScreen *gs = GET_GROUP_SCREEN (s, GET_GROUP_DISPLAY (s->display))#define GET_GROUP_WINDOW(w, gs) ((GroupWindow *) (w)->privates[ (gs)->windowPrivateIndex].ptr)#define GROUP_WINDOW(w) GroupWindow *gw = GET_GROUP_WINDOW (w, GET_GROUP_SCREEN  (w->screen, GET_GROUP_DISPLAY (w->screen->display)))#define WIN_X(w) (w->attrib.x)#define WIN_Y(w) (w->attrib.y)#define WIN_WIDTH(w) (w->attrib.width)#define WIN_HEIGHT(w) (w->attrib.height)#define WIN_BORDER(w) (w->attrib.border_width)#define NUM_OPTIONS(s) (sizeof ( (s)->opt) / sizeof (CompOption))#define N_WIN_TYPE (sizeof (groupDefaultTypes) / sizeof (groupDefaultTypes[0]))#define N_SEL_MODE (sizeof (groupSelectionModes) / sizeof (groupSelectionModes[0]))#define REAL_POSITION(x, s) ( (x >= 0)? x: x + (s)->hsize * (s)->width )#define VIEWPORT(x, s) ( ( REAL_POSITION(x, s) / (s)->width ) % (s)->hsize )#define TOP_TAB(g) ((g)->windows[(g)->topTab])#define PREV_TOP_TAB(g) ((g)->windows[(g)->prevTopTab])/* * Structs * *//* * structs for pending callbacks */typedef struct _GroupPendingMoves GroupPendingMoves;struct _GroupPendingMoves {	CompWindow *w;	int dx;	int dy;	Bool sync;	GroupPendingMoves *next;};typedef struct _GroupPendingResizes GroupPendingResizes;struct _GroupPendingResizes {	CompWindow *w;	int x;	int y;	int width;	int height;	int borderWidth;	GroupPendingResizes *next;};typedef struct _GroupPendingGrabs GroupPendingGrabs;struct _GroupPendingGrabs {	CompWindow *w;	int x;	int y;	unsigned int state;	unsigned int mask;	GroupPendingGrabs *next;};typedef struct _GroupPendingUngrabs GroupPendingUngrabs;struct _GroupPendingUngrabs {	CompWindow *w;	GroupPendingUngrabs *next;};/* * pointer to display list */static int displayPrivateIndex;/* * GroupTabBarSlot */typedef struct _GroupTabBarSlot GroupTabBarSlot;struct _GroupTabBarSlot {	GroupTabBarSlot		*prev;	GroupTabBarSlot		*next;	int			rx;	int			ry;	int			height;	int			width;	CompWindow	*window;};/* * GroupTabBar */typedef struct _GroupTabBar {	GroupTabBarSlot		*slots;	GroupTabBarSlot		*revSlots;	int					nSlots;	Bool				visible;	int					rx;	int					ry;	int					height;	int					width;} GroupTabBar;/* * GroupSelection */typedef struct _GroupSelection GroupSelection;struct _GroupSelection {	GroupSelection *prev;	GroupSelection *next;	CompWindow **windows;	int nWins;	int topTab;	int prevTopTab;	Bool tabbed;	GroupTabBar *tabBar;	int animationSteps;	Bool	ungroup;	int dx, dy;	//For tabbed windows.	Bool animated;	GLushort color[4];};/* * GroupDisplay structure */typedef struct _GroupDisplay {	int screenPrivateIndex;	CompOption opt[GROUP_DISPLAY_OPTION_NUM];	HandleEventProc handleEvent;	GroupSelection tmpSel;	GroupSelection *groups;	//GroupSelection *revGroups;	Bool inAction;	GroupSelection *lastActiveGroup;	Bool ignoreMode;	float cornerPointsX[NUM_CORNER_POINTS];	float cornerPointsY[NUM_CORNER_POINTS];} GroupDisplay;/* * GroupScreen structure */typedef struct _GroupScreen {	int windowPrivateIndex;	CompOption opt[GROUP_SCREEN_OPTION_NUM];	WindowMoveNotifyProc windowMoveNotify;	WindowResizeNotifyProc windowResizeNotify;	PreparePaintScreenProc preparePaintScreen;	PaintScreenProc paintScreen;	DrawWindowProc drawWindow;	PaintWindowProc paintWindow;	PaintTransformedScreenProc paintTransformedScreen;	WindowGrabNotifyProc windowGrabNotify;	WindowUngrabNotifyProc windowUngrabNotify;	GroupPendingMoves *pendingMoves;	GroupPendingResizes *pendingResizes;	GroupPendingGrabs *pendingGrabs;	GroupPendingUngrabs *pendingUngrabs;	int wMask;	Bool queued;	// for selection	Bool grab;	Bool wasTransformed;	int grabIndex;	int x1;	int y1;	int x2;	int y2;	CompTexture glowTexture;} GroupScreen;/* * GroupWindow structure */typedef struct _GroupWindow {	GroupSelection *group;	Bool inGroup;	Bool inSelection;	// for the tab bar	GroupTabBarSlot *slot;	// for scale notify...	int oldWidth;	int oldHeight;	int oldX;	int oldY;	GLushort	oldOpacity;	// for tab animation	Bool animate;	int orgPosX; //Relative to the tabbed window.	int orgPosY; //Relative to the tabbed window.	int destinationX;	int destinationY;} GroupWindow;/* * Pre-Definitions * *//* * options.c */static void groupDisplayInitOptions(GroupDisplay * gd);static CompOption *groupGetDisplayOptions(CompDisplay * d, int *count);static Bool groupSetDisplayOption(CompDisplay * d, char *name, CompOptionValue * value);static void groupScreenInitOptions(GroupScreen * gs);static CompOption *groupGetScreenOptions(CompScreen * s, int *count);static Bool groupSetScreenOption(CompScreen * s, char *name, CompOptionValue * value);/* * group.c */static void groupHandleEvent(CompDisplay * d, XEvent * event);static Bool groupGroupWindows(CompDisplay * d, CompAction * action, CompActionState state, CompOption * option, int nOption);static Bool groupUnGroupWindows(CompDisplay * d, CompAction * action, CompActionState state, CompOption * option, int nOption);static void groupUpdatePosBuffer(CompWindow * w, int x, int y, int width, int height);static void groupAddSkipMasks(CompWindow *w);static void groupRemoveSkipMasks(CompWindow *w);static int groupFindWindowIndex(CompWindow *w, GroupSelection *g);static void groupRecalcTabBarPos(GroupSelection *group);static void groupInsertTabBarSlot(GroupTabBar *bar, GroupTabBarSlot *slot);static void groupUnhookTabBarSlot(GroupTabBar *bar, GroupTabBarSlot *slot);static void groupCreateSlot(GroupSelection *group, CompWindow *w);static void	groupInitTabBar(GroupSelection *group);static void groupDeleteTabBar(GroupSelection *group);static void groupTabGroup(CompWindow * main);static void groupUntabGroup(CompDisplay *d, GroupSelection *group);static void groupDeleteGroupWindow(CompDisplay * d, CompWindow * w);static void groupDeleteGroup(CompDisplay * d, GroupSelection *group);static void groupAddWindowToGroup(CompDisplay * d, CompWindow * w, GroupSelection *group);static void groupSyncWindows(GroupSelection *group);static void groupRaiseWindows(CompWindow * top, GroupSelection *group);static Bool groupInitTab(CompDisplay * d, CompAction * action, CompActionState state, CompOption * option, int nOption);static Bool groupChangeTab(CompDisplay * d, Bool direction);static Bool groupChangeTabLeft(CompDisplay * d, CompAction * action, CompActionState state, CompOption * option, int nOption);static Bool groupChangeTabRight(CompDisplay * d, CompAction * action, CompActionState state, CompOption * option, int nOption);static Bool groupRemoveWindow(CompDisplay * d, CompAction * action, CompActionState state, CompOption * option, int nOption);static Bool groupCloseWindows(CompDisplay * d, CompAction * action, CompActionState state, CompOption * option, int nOption);static Bool groupMinimizeWindows(CompDisplay * d, CompAction * action, CompActionState state, CompOption * option, int nOption);static Bool groupSetIgnore(CompDisplay * d, CompAction * action, CompActionState state, CompOption * option, int nOption);static Bool groupUnsetIgnore(CompDisplay * d, CompAction * action, CompActionState state, CompOption * option, int nOption);static void groupWindowResizeNotify(CompWindow * w);static void groupWindowGrabNotify(CompWindow * w, int x, int y, unsigned int state, unsigned int mask);static void groupWindowUngrabNotify(CompWindow * w);static void groupWindowMoveNotify(CompWindow * w, int dx, int dy, Bool immediate);/* * paint.c */static void groupHandleChanges(CompScreen* s);static void groupDrawTabAnimation(CompScreen * s);static void groupTabBarVertices(CompScreen *s, int x, int y, int width, int height);static void groupPaintThumb(GroupSelection *group, GroupTabBarSlot *slot);static void groupPaintTabBar(GroupSelection * group);static void groupPreparePaintScreen(CompScreen * s, int msSinceLastPaint);static Bool groupPaintScreen(CompScreen * s, const ScreenPaintAttrib * sAttrib, Region region, int output, unsigned int mask);static void groupPaintTransformedScreen(CompScreen * s, const ScreenPaintAttrib * sa, Region region, int output, unsigned int mask);static Bool groupDrawWindow(CompWindow * w,	const WindowPaintAttrib * attrib, Region region, unsigned int mask);static Bool groupPaintWindow(CompWindow * w, const WindowPaintAttrib * attrib, Region region, unsigned int mask);static void groupHandleMotionEvent(CompScreen * s, int xRoot, int yRoot);static void initCornerPoints(GroupDisplay * gd);/* * init.c */static Bool groupInitDisplay(CompPlugin * p, CompDisplay * d);static void groupFiniDisplay(CompPlugin * p, CompDisplay * d);static Bool groupInitScreen(CompPlugin * p, CompScreen * s);static void groupFiniScreen(CompPlugin * p, CompScreen * s);static Bool groupInitWindow(CompPlugin * p, CompWindow * w);static void groupFiniWindow(CompPlugin * p, CompWindow * w);static Bool groupInit(CompPlugin * p);static void groupFini(CompPlugin * p);/* * queues.c */static void groupEnqueueMoveNotify (CompWindow *w, int dx, int dy, Bool sync);static void groupDequeueMoveNotifies (CompScreen *s);static void groupEnqueueResizeNotify (CompWindow *w, int x, int y, int width, int height, int border_width);static void groupDequeueResizeNotifies (CompScreen *s);static void groupEnqueueGrabNotify (CompWindow *w, int x, int y, unsigned int state, unsigned int mask);static void groupDequeueGrabNotifies (CompScreen *s);static void groupEnqueueUngrabNotify (CompWindow *w);static void groupDequeueUngrabNotifies (CompScreen *s);/* * selection.c */static CompWindow **groupFindWindowsInRegion(CompScreen * s, REGION reg, int *c)static void groupDeleteSelectionWindow(CompDisplay * d, CompWindow * w);static void groupAddWindowToSelection(CompDisplay * d, CompWindow * w);static void groupSelectWindow(CompDisplay * d, CompWindow * w);static Bool groupSelectSingle(CompDisplay * d, CompAction * action, CompActionState state, CompOption * option, int nOption);static Bool groupSelect(CompDisplay * d, CompAction * action, CompActionState state, CompOption * option, int nOption);static Bool groupSelectTerminate(CompDisplay * d, CompAction * action, CompActionState state, CompOption * option, int nOption);