aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgotmor <gotmor@f2baff5b-bf2c-0410-a398-912abdc3d8b2>2007-12-22 14:35:58 +0000
committergotmor <gotmor@f2baff5b-bf2c-0410-a398-912abdc3d8b2>2007-12-22 14:35:58 +0000
commit67ca34039c1c81c6e0102386c723fd09bbc040e2 (patch)
treeb0d6467742c4a95bfec35baa49792237b27df090
parent8267971cf3e888709413ece5cfd1f73e360a7753 (diff)
downloaddzen-67ca34039c1c81c6e0102386c723fd09bbc040e2.tar.gz
dzen-67ca34039c1c81c6e0102386c723fd09bbc040e2.zip
added "-expand" option. automatically grows/srinks the window to fit the
input width git-svn-id: http://dzen.googlecode.com/svn/trunk@177 f2baff5b-bf2c-0410-a398-912abdc3d8b2
-rw-r--r--draw.c64
-rw-r--r--dzen.h5
-rw-r--r--main.c20
3 files changed, 55 insertions, 34 deletions
diff --git a/draw.c b/draw.c
index 14cf1d0..c56038a 100644
--- a/draw.c
+++ b/draw.c
@@ -15,6 +15,8 @@
#define ARGLEN 256
+int otx;
+
/* command types for the in-text parser */
enum ctype {bg, fg, icon, rect, recto, circle, circleo, pos, abspos, titlewin, ibg};
@@ -257,6 +259,7 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
XpmColorSymbol xpms;
#endif
+
/* parse line and return the text without control commands */
if(nodraw) {
rbuf = emalloc(MAX_LINE_LEN);
@@ -366,7 +369,6 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
case rect:
get_rect_vals(tval, &rectw, &recth, &rectx, &recty);
- //rectw = rectw+px > dzen.w ? dzen.w-px : rectw;
recth = recth > dzen.line_height ? dzen.line_height : recth;
recty = (recty == 0) ? (dzen.line_height - recth)/2 : recty;
px = (rectx == 0) ? px : rectx+px;
@@ -381,7 +383,6 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
get_rect_vals(tval, &rectw, &recth, &rectx, &recty);
if (!rectw) break;
- //rectw = rectw+px > dzen.w ? dzen.w-px : rectw;
recth = recth > dzen.line_height ? dzen.line_height-2 : recth-1;
recty = recty == 0 ? (dzen.line_height - recth)/2 : recty;
px = (rectx == 0) ? px : rectx+px;
@@ -511,7 +512,6 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
case rect:
get_rect_vals(tval, &rectw, &recth, &rectx, &recty);
- //rectw = rectw+px > dzen.w ? dzen.w-px : rectw;
recth = recth > dzen.line_height ? dzen.line_height : recth;
recty = (recty == 0) ? (dzen.line_height - recth)/2 : recty;
px = (rectx == 0) ? px : rectx+px;
@@ -526,7 +526,6 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
get_rect_vals(tval, &rectw, &recth, &rectx, &recty);
if (!rectw) break;
- //rectw = rectw+px > dzen.w ? dzen.w-px : rectw;
recth = recth > dzen.line_height ? dzen.line_height-2 : recth-1;
recty = recty == 0 ? (dzen.line_height - recth)/2 : recty;
px = (rectx == 0) ? px : rectx+px;
@@ -609,36 +608,33 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
px += tw;
/* expand/shrink dynamically */
- /*
- i = px;
- if(lnr == -1)
- XResizeWindow(dzen.dpy, dzen.title_win.win, px, dzen.line_height);
-
- if(align == ALIGNLEFT)
- xorig = 0;
- if(align == ALIGNCENTER) {
- xorig = (lnr != -1) ?
- (dzen.slave_win.width - px)/2 :
- (i - px)/2;
- }
- else if(align == ALIGNRIGHT) {
- xorig = (lnr != -1) ?
- (dzen.slave_win.width - px) :
- (i - px)/2;
- }
- */
-
- if(align == ALIGNLEFT)
- xorig = 0;
- if(align == ALIGNCENTER) {
- xorig = (lnr != -1) ?
- (dzen.slave_win.width - px)/2 :
- (dzen.title_win.width - px)/2;
- }
- else if(align == ALIGNRIGHT) {
- xorig = (lnr != -1) ?
- (dzen.slave_win.width - px) :
- (dzen.title_win.width - px);
+ if(dzen.title_win.expand && lnr == -1){
+ i = px;
+ switch(dzen.title_win.expand) {
+ case left:
+ /* grow left end */
+ otx = dzen.title_win.x_right_corner - i > 0 ?
+ dzen.title_win.x_right_corner - i : dzen.title_win.x;
+ XMoveResizeWindow(dzen.dpy, dzen.title_win.win, otx, dzen.title_win.y, px, dzen.line_height);
+ break;
+ case right:
+ XResizeWindow(dzen.dpy, dzen.title_win.win, px, dzen.line_height);
+ break;
+ }
+
+ } else {
+ if(align == ALIGNLEFT)
+ xorig = 0;
+ if(align == ALIGNCENTER) {
+ xorig = (lnr != -1) ?
+ (dzen.slave_win.width - px)/2 :
+ (dzen.title_win.width - px)/2;
+ }
+ else if(align == ALIGNRIGHT) {
+ xorig = (lnr != -1) ?
+ (dzen.slave_win.width - px) :
+ (dzen.title_win.width - px);
+ }
}
diff --git a/dzen.h b/dzen.h
index 59d2fcf..3488157 100644
--- a/dzen.h
+++ b/dzen.h
@@ -32,6 +32,9 @@
/* gui data structures */
enum { ColFG, ColBG, ColLast };
+/* exapansion directions */
+enum { noexpand, left, right, both };
+
typedef struct DZEN Dzen;
typedef struct Fnt Fnt;
typedef struct TW TWIN;
@@ -53,6 +56,8 @@ struct TW {
Window win;
Drawable drawable;
char alignment;
+ int expand;
+ int x_right_corner;
Bool ishidden;
};
diff --git a/main.c b/main.c
index 46c40ce..3877243 100644
--- a/main.c
+++ b/main.c
@@ -722,6 +722,7 @@ main(int argc, char *argv[]) {
dzen.xinescreen = 0;
dzen.tsupdate = 0;
dzen.line_height = 0;
+ dzen.title_win.expand = noexpand;
/* cmdline args */
for(i = 1; i < argc; i++)
@@ -751,6 +752,23 @@ main(int argc, char *argv[]) {
else if(!strncmp(argv[i], "-u", 3)){
dzen.tsupdate = True;
}
+ else if(!strncmp(argv[i], "-expand", 8)){
+ if(++i < argc) {
+ switch(argv[i][0]){
+ case 'l':
+ dzen.title_win.expand = left;
+ break;
+ case 'c':
+ dzen.title_win.expand = both;
+ break;
+ case 'r':
+ dzen.title_win.expand = right;
+ break;
+ default:
+ dzen.title_win.expand = noexpand;
+ }
+ }
+ }
else if(!strncmp(argv[i], "-p", 3)) {
dzen.ispersistent = True;
if (i+1 < argc) {
@@ -871,7 +889,9 @@ main(int argc, char *argv[]) {
!dzen.slave_win.max_lines)
dzen.slave_win.max_lines = 1;
+
x_create_windows();
+ dzen.title_win.x_right_corner = dzen.title_win.x + dzen.title_win.width;
if(!dzen.slave_win.ishmenu)
x_map_window(dzen.title_win.win);