forked from awesomeWM/awesome
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwidget.c
123 lines (105 loc) · 2.69 KB
/
widget.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include <confuse.h>
#include "util.h"
#include "widget.h"
#include "statusbar.h"
extern AwesomeConf globalconf;
const NameFuncLink WidgetList[] =
{
{"taglist", taglist_new},
{"layoutinfo", layoutinfo_new},
{"focustitle", focustitle_new},
{"textbox", textbox_new},
{NULL, NULL}
};
void
calculate_alignments(Widget *widget)
{
for(; widget; widget = widget->next)
{
if(widget->alignment == AlignFlex)
{
widget = widget->next;
break;
}
widget->alignment = AlignLeft;
}
if(widget)
for(; widget; widget = widget->next){
if (widget->alignment == AlignFlex)
warn("Multiple flex widgets in panel -"
" ignoring flex for all but the first.");
widget->alignment = AlignRight;
}
}
int
calculate_offset(int barwidth, int widgetwidth, int offset, int alignment)
{
if (alignment == AlignLeft || alignment == AlignFlex)
return offset;
return barwidth - offset - widgetwidth;
}
static Widget *
find_widget(char *name, int screen)
{
Widget *widget;
widget = globalconf.screens[screen].statusbar->widgets;
for(; widget; widget = widget->next)
if (strcmp(name, widget->name) == 0)
return widget;
return NULL;
}
static void
common_tell(Widget *widget, char *command __attribute__ ((unused)))
{
warn("%s widget does not accept commands.\n", widget->name);
}
void
common_new(Widget *widget, Statusbar *statusbar, cfg_t* config)
{
const char *name;
widget->statusbar = statusbar;
name = cfg_title(config);
widget->name = p_new(char, strlen(name)+1);
widget->tell = common_tell;
strncpy(widget->name, name, strlen(name));
}
/** Send command to widget
* \param screen Screen ID
* \param arg Widget command. Syntax depends on specific widget.
* \ingroup ui_callback
*/
void
uicb_widget_tell(int screen, char *arg)
{
Widget *widget;
char *p, *command;
int len;
if (!arg){
warn("Must specify a widget.\n");
return;
}
len = strlen(arg);
p = strtok(arg, " ");
if (!p){
warn("Ignoring malformed widget command.\n");
return;
}
widget = find_widget(p, screen);
if (!widget){
warn("No such widget: %s\n", p);
return;
}
if (p+strlen(p) < arg+len)
{
p = p + strlen(p) + 1;
command = p_new(char, strlen(p)+1);
strncpy(command, p, strlen(p));
widget->tell(widget, command);
p_delete(&command);
}
else
widget->tell(widget, NULL);
statusbar_draw(screen);
return;
}
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80