summaryrefslogtreecommitdiff
path: root/beryl-plugins/src/place.c
diff options
context:
space:
mode:
authorracarr <racarr@d7aaf104-2d23-0410-ae22-9d23157bf5a3>2006-12-16 02:55:54 +0000
committerracarr <racarr@d7aaf104-2d23-0410-ae22-9d23157bf5a3>2006-12-16 02:55:54 +0000
commita9f2debc0aff4cdec2a6b04fe99ac525589ef286 (patch)
tree057a913adf7337dbf0047139053b963501d1a74c /beryl-plugins/src/place.c
parentc10a0c6c5bbc32767f81b15383ccc59750b320a4 (diff)
downloadmarex-dev-a9f2debc0aff4cdec2a6b04fe99ac525589ef286.tar.gz
marex-dev-a9f2debc0aff4cdec2a6b04fe99ac525589ef286.tar.bz2
racarr: Placement modes, Cascade Centered Random and Intelligent (not very intelligent)
git-svn-id: file:///beryl/trunk@1786 d7aaf104-2d23-0410-ae22-9d23157bf5a3
Diffstat (limited to 'beryl-plugins/src/place.c')
-rw-r--r--beryl-plugins/src/place.c91
1 files changed, 77 insertions, 14 deletions
diff --git a/beryl-plugins/src/place.c b/beryl-plugins/src/place.c
index b1732e5..10c5515 100644
--- a/beryl-plugins/src/place.c
+++ b/beryl-plugins/src/place.c
@@ -22,6 +22,7 @@
#include <math.h>
#include <stdlib.h>
+#include <string.h>
#include <beryl.h>
@@ -37,15 +38,28 @@ typedef struct _PlaceDisplay {
} PlaceDisplay;
#define PLACE_SCREEN_OPTION_WORKAROUND 0
-//#define PLACE_SCREEN_OPTION_CENTER_INITIATE 1
-#define PLACE_SCREEN_OPTION_NUM 1
+#define PLACE_SCREEN_OPTION_MODE 1
+#define PLACE_SCREEN_OPTION_NUM 2
typedef struct _PlaceScreen {
CompOption opt[PLACE_SCREEN_OPTION_NUM];
DamageWindowRectProc damageWindowRect;
+ int placeMode;
} PlaceScreen;
+typedef enum _PlaceMode{
+ PlaceModeCascade,
+ PlaceModeCentered,
+ PlaceModeRandom,
+ PlaceModeIntelligent,
+ } PlaceMode;
+
+char *placeModes[] = { N_("Cascade"),N_("Centered"),N_("Random"),N_("Intelligent") };
+
+#define PLACE_MODE_DEFAULT PlaceModeCascade
+#define NUM_PLACE_MODES 4
+
#define GET_PLACE_DISPLAY(d) \
((PlaceDisplay *) (d)->privates[displayPrivateIndex].ptr)
@@ -86,6 +100,14 @@ placeSetScreenOption(CompScreen * screen,
return TRUE;
} */
break;
+ case PLACE_SCREEN_OPTION_MODE:
+ if (compSetStringOption (o,value))
+ {
+ int i;
+ for (i = 0; i < NUM_PLACE_MODES; i++)
+ if (strcmp (placeModes[i], o->value.s)==0)
+ ps->placeMode = (PlaceMode) i;
+ }
default:
break;
}
@@ -106,18 +128,28 @@ static void placeScreenInitOptions(PlaceScreen * ps)
o->longDesc = N_("Window placement workarounds");
o->type = CompOptionTypeBool;
o->value.b = PLACE_WORKAROUND_DEFAULT;
-
- /*o = &ps->opt[PLACE_SCREEN_OPTION_CENTER_INITIATE];
- o->name = "center_initiate";
- o->group=N_("");
- o->subGroup=N_("");
- o->displayHints="";
- o->shortDesc = "Center Window";
- o->longDesc = "Center window";
- o->type = CompOptionTypeBinding;
- o->value.bind.type = CompBindingTypeButton;
- o->value.bind.u.button.modifiers = 0;
- o->value.bind.u.button.button = 0; */
+
+ o = &ps->opt[PLACE_SCREEN_OPTION_MODE];
+ o->name = "place_mode";
+ o->shortDesc = N_("Placement Mode");
+ o->longDesc = N_("Cascade, Random or Centered");
+ o->type = CompOptionTypeString;
+ o->value.s = strdup (placeModes[PLACE_MODE_DEFAULT]);
+ o->rest.s.string = placeModes;
+ o->rest.s.nString = NUM_PLACE_MODES;
+
+ o = &ps->opt[PLACE_SCREEN_OPTION_MODE];
+ o->name = "place_mode";
+ o->group = N_("");
+ o->subGroup = N_("");
+ o->displayHints = "";
+ o->shortDesc = N_("Placement Mode");
+ o->longDesc = N_("Lawls");
+ o->type = CompOptionTypeString;
+ o->value.s = strdup(placeModes[PLACE_MODE_DEFAULT]);
+ o->rest.s.string = placeModes;
+ o->rest.s.nString = NUM_PLACE_MODES;
+
}
static CompOption *placeGetScreenOptions(CompScreen * screen, int *count)
@@ -223,6 +255,20 @@ static int get_window_height(CompWindow * window)
return window->serverHeight + window->serverBorderWidth * 2;
}
+static void placeCentered(CompWindow *window, int *x, int *y){
+ *x = window->screen->workArea.x + (window->screen->workArea.width
+ - get_window_width(window)) /2;
+ *y = window->screen->workArea.y + (window->screen->workArea.height
+ - get_window_height(window)) /2;
+}
+
+
+
+static void placeRandom(CompWindow *window, int *x, int *y){
+ *x = rand() % (window->screen->workArea.width - window->screen->workArea.x);
+ *y = rand() % (window->screen->workArea.height - window->screen->workArea.y);
+}
+
static void
find_next_cascade(CompWindow * window,
GList * windows, int x, int y, int *new_x, int *new_y)
@@ -438,6 +484,15 @@ find_most_freespace(CompWindow * window,
}
}
+static void placeIntelligent(CompWindow *window, int *x, int *y){
+ int ox,oy;
+ ox=*x;
+ oy=*y;
+ find_most_freespace(window,window,ox,oy,x,y);
+ /*
+ TODO: Make intelligent
+ */
+}
static void
avoid_being_obscured_as_second_modal_dialog(CompWindow * window,
int *x, int *y)
@@ -938,6 +993,7 @@ placeWindow(CompWindow * window, int x, int y, int *new_x, int *new_y)
x = x0;
y = y0;
+ if (ps->placeMode == PlaceModeCascade){
if (find_first_fit(window, windows, x, y, &x, &y))
goto done_check_denied_focus;
@@ -945,6 +1001,13 @@ placeWindow(CompWindow * window, int x, int y, int *new_x, int *new_y)
* cascade it onto the current screen
*/
find_next_cascade(window, windows, x, y, &x, &y);
+ } else if (ps->placeMode == PlaceModeCentered) {
+ placeCentered(window, &x, &y);
+ } else if (ps->placeMode == PlaceModeRandom) {
+ placeRandom(window, &x, &y);
+ } else if (ps->placeMode == PlaceModeIntelligent) {
+ placeIntelligent(window, &x, &y);
+ }
/* Maximize windows if they are too big for their work area (bit of
* a hack here). Assume undecorated windows probably don't intend to