Permalink
Browse files

distancefrom parameter for better placement control, patch from Yury …

…Akudovich.
  • Loading branch information...
1 parent 1fbdf9f commit 11e159d3e7a0274bddc852a93d903238f2621287 @sargon committed Apr 1, 2010
Showing with 40 additions and 12 deletions.
  1. +23 −7 misc.c
  2. +2 −1 misc.h
  3. +14 −4 panel.c
  4. +1 −0 panel.h
View
30 misc.c
@@ -74,6 +74,15 @@ pair edge_pair[] = {
{ 0, NULL },
};
+pair distancefrom_pair[] = {
+ { DISTANCEFROM_NONE, "none" },
+ { DISTANCEFROM_LEFT, "left" },
+ { DISTANCEFROM_RIGHT, "right" },
+ { DISTANCEFROM_TOP, "top" },
+ { DISTANCEFROM_BOTTOM, "bottom" },
+ { 0, NULL },
+};
+
pair width_pair[] = {
{ WIDTH_NONE, "none" },
{ WIDTH_REQUEST, "request" },
@@ -531,9 +540,9 @@ calculate_width(int scrw, int wtype, int allign, int margin,
void
-calculate_position(panel *np, int distance)
+calculate_position(panel *np, int distance,int distancefrom)
{
- int sswidth, ssheight, minx, miny;
+ int sswidth, ssheight, minx, miny, distancex, distancey;
GdkScreen *screen;
GdkDisplay *display;
GdkRectangle *monitorGeometry;
@@ -559,27 +568,34 @@ calculate_position(panel *np, int distance)
miny = monitorGeometry->y;
free(monitorGeometry);
-
+
+ if (distancefrom == DISTANCEFROM_TOP || distancefrom == DISTANCEFROM_BOTTOM) {
+ distancex = 0;
+ distancey = (distancefrom == DISTANCEFROM_TOP) ? distance : -distance;
+ } else {
+ distancex = (distancefrom == DISTANCEFROM_LEFT) ? distance : -distance;
+ distancey = 0;
+ }
if (np->edge == EDGE_TOP || np->edge == EDGE_BOTTOM) {
np->aw = np->width;
- np->ax = minx;
+ np->ax = minx + distancex;
calculate_width(sswidth, np->widthtype, np->allign, np->margin,
&np->aw, &np->ax);
np->ah = np->height;
np->ah = MIN(PANEL_HEIGHT_MAX, np->ah);
np->ah = MAX(PANEL_HEIGHT_MIN, np->ah);
- np->ay = miny + ((np->edge == EDGE_TOP) ? 0+distance : (ssheight - np->ah - distance));
+ np->ay = miny + ((np->edge == EDGE_TOP) ? distancey : (ssheight - np->ah - distancey));
} else {
np->ah = np->width;
- np->ay = miny;
+ np->ay = miny + distancey;
calculate_width(ssheight, np->widthtype, np->allign, np->margin,
&np->ah, &np->ay);
np->aw = np->height;
np->aw = MIN(PANEL_HEIGHT_MAX, np->aw);
np->aw = MAX(PANEL_HEIGHT_MIN, np->aw);
- np->ax = minx + ((np->edge == EDGE_LEFT) ? 0+distance : (sswidth - np->aw - distance));
+ np->ax = minx + ((np->edge == EDGE_LEFT) ? distancex : (sswidth - np->aw - distancex));
}
DBG("%s - x=%d y=%d w=%d h=%d\n", __FUNCTION__, np->ax, np->ay, np->aw, np->ah);
RET();
View
3 misc.h
@@ -25,6 +25,7 @@ typedef struct {
extern pair allign_pair[];
extern pair edge_pair[];
+extern pair distancefrom_pair[];
extern pair width_pair[];
extern pair height_pair[];
extern pair bool_pair[];
@@ -47,7 +48,7 @@ int get_wm_state (Window win);
void get_net_wm_state(Window win, net_wm_state *nws);
void get_net_wm_window_type(Window win, net_wm_window_type *nwwt);
-void calculate_position(panel *np, int distance);
+void calculate_position(panel *np, int distance,int distancefrom);
gchar *expand_tilda(gchar *file);
GtkWidget *gtk_image_new_from_file_scaled(const gchar *file, gint width, gint height);
void get_button_spacing(GtkRequisition *req, GtkContainer *parent, gchar *name);
View
18 panel.c
@@ -20,7 +20,7 @@
static gchar *cfgfile = NULL;
static gchar version[] = VERSION;
-int distance=0;
+int distance=0, distancefrom=0;
int expand=1 , padding=0;
@@ -198,7 +198,7 @@ panel_size_req(GtkWidget *widget, GtkRequisition *req, panel *p)
p->width = (p->orientation == ORIENT_HORIZ) ? req->width : req->height;
if (p->heighttype == HEIGHT_REQUEST)
p->height = (p->orientation == ORIENT_HORIZ) ? req->height : req->width;
- calculate_position(p, distance);
+ calculate_position(p, distance,distancefrom);
req->width = p->aw;
req->height = p->ah;
DBG("OUT req=(%d, %d)\n", req->width, req->height);
@@ -215,7 +215,7 @@ panel_size_alloc(GtkWidget *widget, GtkAllocation *a, panel *p)
p->width = (p->orientation == ORIENT_HORIZ) ? a->width : a->height;
if (p->heighttype == HEIGHT_REQUEST)
p->height = (p->orientation == ORIENT_HORIZ) ? a->height : a->width;
- calculate_position(p, distance);
+ calculate_position(p, distance,distancefrom);
DBG("pref alloc: size (%d, %d). pos (%d, %d)\n", p->aw, p->ah, p->ax, p->ay);
if (a->width == p->aw && a->height == p->ah && a->x == p->ax && a->y == p ->ay) {
DBG("actual coords eq to preffered. just returning\n");
@@ -452,7 +452,7 @@ panel_start_gui(panel *p)
*/
gdk_window_add_filter(gdk_get_default_root_window (), (GdkFilterFunc)panel_wm_events, p);
- calculate_position(p, distance);
+ calculate_position(p, distance,distancefrom);
gdk_window_move_resize(p->topgwin->window, p->ax, p->ay, p->aw, p->ah);
if (p->setstrut)
panel_set_wm_strut(p);
@@ -546,6 +546,7 @@ usage()
printf(" --alpha <number>\n");
printf(" --tint <int>\n");
printf(" --distance <number>\n");
+ printf(" --distancefrom <number>\n");
printf(" --expand <false|true>\n");
printf(" --padding <number>\n");
printf(" --monitor <number>\n");
@@ -729,6 +730,15 @@ main(int argc, char *argv[], char *env[])
} else {
distance = atoi(argv[i]);
}
+ } else if (!strcmp(argv[i], "--distancefrom")) {
+ i++;
+ if (i == argc) {
+ ERR( "trayer: missing distancefrom parameter value\n");
+ usage();
+ exit(1);
+ } else {
+ distancefrom = str2num(distancefrom_pair, argv[i], DISTANCEFROM_NONE);
+ }
} else if (!strcmp(argv[i], "--expand")) {
i++;
if (i == argc) {
View
@@ -10,6 +10,7 @@
enum { ALLIGN_NONE, ALLIGN_LEFT, ALLIGN_RIGHT, ALLIGN_CENTER };
enum { EDGE_NONE, EDGE_LEFT, EDGE_RIGHT, EDGE_TOP, EDGE_BOTTOM };
+enum { DISTANCEFROM_NONE, DISTANCEFROM_LEFT, DISTANCEFROM_RIGHT, DISTANCEFROM_TOP, DISTANCEFROM_BOTTOM };
enum { WIDTH_NONE, WIDTH_REQUEST, WIDTH_PIXEL, WIDTH_PERCENT };
enum { HEIGHT_NONE, HEIGHT_PIXEL, HEIGHT_REQUEST };
enum { ORIENT_NONE, ORIENT_VERT, ORIENT_HORIZ };

0 comments on commit 11e159d

Please sign in to comment.