mirror of
https://github.com/Llewellynvdm/conky.git
synced 2025-01-29 18:18:39 +00:00
Make own_window_hints a lua setting
This commit is contained in:
parent
5b65fce42d
commit
4a4172c92d
51
src/conky.cc
51
src/conky.cc
@ -2118,8 +2118,8 @@ static void main_loop(void)
|
||||
if (own_window.get(*state)) {
|
||||
/* if an ordinary window with decorations */
|
||||
if ((own_window_type.get(*state) == TYPE_NORMAL &&
|
||||
(!TEST_HINT(window.hints,
|
||||
HINT_UNDECORATED))) ||
|
||||
not TEST_HINT(own_window_hints.get(*state),
|
||||
HINT_UNDECORATED)) ||
|
||||
own_window_type.get(*state) == TYPE_DESKTOP) {
|
||||
/* allow conky to hold input focus. */
|
||||
break;
|
||||
@ -2140,9 +2140,8 @@ static void main_loop(void)
|
||||
case ButtonRelease:
|
||||
if (own_window.get(*state)) {
|
||||
/* if an ordinary window with decorations */
|
||||
if ((own_window_type.get(*state) == TYPE_NORMAL)
|
||||
&& (!TEST_HINT(window.hints,
|
||||
HINT_UNDECORATED))) {
|
||||
if ((own_window_type.get(*state) == TYPE_NORMAL) &&
|
||||
not TEST_HINT(own_window_hints.get(*state), HINT_UNDECORATED)) {
|
||||
/* allow conky to hold input focus. */
|
||||
break;
|
||||
} else {
|
||||
@ -2566,9 +2565,6 @@ static void set_default_configurations(void)
|
||||
minimum_width = 5;
|
||||
minimum_height = 5;
|
||||
maximum_width = 0;
|
||||
#ifdef OWN_WINDOW
|
||||
window.hints = 0;
|
||||
#endif
|
||||
stippled_borders = 0;
|
||||
window.border_inner_margin = 3;
|
||||
window.border_outer_margin = 1;
|
||||
@ -3224,40 +3220,6 @@ char load_config_file(const char *f)
|
||||
pad_percents = atoi(value);
|
||||
}
|
||||
#ifdef BUILD_X11
|
||||
#ifdef OWN_WINDOW
|
||||
CONF("own_window_hints") {
|
||||
if (value) {
|
||||
char *p_hint, *p_save;
|
||||
char delim[] = ", ";
|
||||
|
||||
/* tokenize the value into individual hints */
|
||||
if ((p_hint = strtok_r(value, delim, &p_save)) != NULL) {
|
||||
do {
|
||||
/* fprintf(stderr, "hint [%s] parsed\n", p_hint); */
|
||||
if (strncmp(p_hint, "undecorate", 10) == EQUAL) {
|
||||
SET_HINT(window.hints, HINT_UNDECORATED);
|
||||
} else if (strncmp(p_hint, "below", 5) == EQUAL) {
|
||||
SET_HINT(window.hints, HINT_BELOW);
|
||||
} else if (strncmp(p_hint, "above", 5) == EQUAL) {
|
||||
SET_HINT(window.hints, HINT_ABOVE);
|
||||
} else if (strncmp(p_hint, "sticky", 6) == EQUAL) {
|
||||
SET_HINT(window.hints, HINT_STICKY);
|
||||
} else if (strncmp(p_hint, "skip_taskbar", 12) == EQUAL) {
|
||||
SET_HINT(window.hints, HINT_SKIP_TASKBAR);
|
||||
} else if (strncmp(p_hint, "skip_pager", 10) == EQUAL) {
|
||||
SET_HINT(window.hints, HINT_SKIP_PAGER);
|
||||
} else {
|
||||
CONF_ERR;
|
||||
}
|
||||
|
||||
p_hint = strtok_r(NULL, delim, &p_save);
|
||||
} while (p_hint != NULL);
|
||||
}
|
||||
} else {
|
||||
CONF_ERR;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
CONF("stippled_borders") {
|
||||
if (value) {
|
||||
stippled_borders = strtol(value, 0, 0);
|
||||
@ -4116,7 +4078,8 @@ int main(int argc, char **argv)
|
||||
"print(conky.asnumber(conky.variables.zxcv{}));\n"
|
||||
"print(conky.variables.asdf{}.text);\n"
|
||||
"print(conky.variables.asdf{}.xxx);\n"
|
||||
"conky.config = { alignment='bar', asdf=47, [42]=47};\n"
|
||||
"conky.config = { alignment='bar', asdf=47, [42]=47,\n"
|
||||
" own_window_hints='above, undecorated,,below'};\n"
|
||||
);
|
||||
l.call(0, 0);
|
||||
conky::check_config_settings(l);
|
||||
@ -4124,12 +4087,14 @@ int main(int argc, char **argv)
|
||||
l.pushstring("X");
|
||||
text_alignment.lua_set(l);
|
||||
std::cout << "config.alignment = " << text_alignment.get(l) << std::endl;
|
||||
std::cout << "config.own_window_hints = " << own_window_hints.get(l) << std::endl;
|
||||
l.loadstring(
|
||||
"print('config.asdf = ', conky.config.asdf);\n"
|
||||
"conky.config.asdf = -42;\n"
|
||||
"print('config.asdf = ', conky.config.asdf);\n"
|
||||
"conky.config.alignment='asdf';\n"
|
||||
"print('config.alignment = ', conky.config.alignment);\n"
|
||||
"print('config.own_window_hints = ', conky.config.own_window_hints);\n"
|
||||
);
|
||||
l.call(0, 0);
|
||||
}
|
||||
|
57
src/x11.cc
57
src/x11.cc
@ -369,10 +369,12 @@ void init_window(int w, int h, char **argv, int argc)
|
||||
classHint.res_name = const_cast<char *>(class_name.c_str());
|
||||
classHint.res_class = classHint.res_name;
|
||||
|
||||
uint16_t hints = own_window_hints.get(*state);
|
||||
|
||||
wmHint.flags = InputHint | StateHint;
|
||||
/* allow decorated windows to be given input focus by WM */
|
||||
wmHint.input =
|
||||
TEST_HINT(window.hints, HINT_UNDECORATED) ? False : True;
|
||||
TEST_HINT(hints, HINT_UNDECORATED) ? False : True;
|
||||
if (own_window_type.get(*state) == TYPE_DOCK || own_window_type.get(*state) == TYPE_PANEL) {
|
||||
wmHint.initial_state = WithdrawnState;
|
||||
} else {
|
||||
@ -420,7 +422,7 @@ void init_window(int w, int h, char **argv, int argc)
|
||||
/* Set desired hints */
|
||||
|
||||
/* Window decorations */
|
||||
if (TEST_HINT(window.hints, HINT_UNDECORATED)) {
|
||||
if (TEST_HINT(hints, HINT_UNDECORATED)) {
|
||||
/* fprintf(stderr, PACKAGE_NAME": hint - undecorated\n");
|
||||
fflush(stderr); */
|
||||
|
||||
@ -433,7 +435,7 @@ void init_window(int w, int h, char **argv, int argc)
|
||||
}
|
||||
|
||||
/* Below other windows */
|
||||
if (TEST_HINT(window.hints, HINT_BELOW)) {
|
||||
if (TEST_HINT(hints, HINT_BELOW)) {
|
||||
/* fprintf(stderr, PACKAGE_NAME": hint - below\n");
|
||||
fflush(stderr); */
|
||||
|
||||
@ -455,7 +457,7 @@ void init_window(int w, int h, char **argv, int argc)
|
||||
}
|
||||
|
||||
/* Above other windows */
|
||||
if (TEST_HINT(window.hints, HINT_ABOVE)) {
|
||||
if (TEST_HINT(hints, HINT_ABOVE)) {
|
||||
/* fprintf(stderr, PACKAGE_NAME": hint - above\n");
|
||||
fflush(stderr); */
|
||||
|
||||
@ -477,7 +479,7 @@ void init_window(int w, int h, char **argv, int argc)
|
||||
}
|
||||
|
||||
/* Sticky */
|
||||
if (TEST_HINT(window.hints, HINT_STICKY)) {
|
||||
if (TEST_HINT(hints, HINT_STICKY)) {
|
||||
/* fprintf(stderr, PACKAGE_NAME": hint - sticky\n");
|
||||
fflush(stderr); */
|
||||
|
||||
@ -499,7 +501,7 @@ void init_window(int w, int h, char **argv, int argc)
|
||||
}
|
||||
|
||||
/* Skip taskbar */
|
||||
if (TEST_HINT(window.hints, HINT_SKIP_TASKBAR)) {
|
||||
if (TEST_HINT(hints, HINT_SKIP_TASKBAR)) {
|
||||
/* fprintf(stderr, PACKAGE_NAME": hint - skip_taskbar\n");
|
||||
fflush(stderr); */
|
||||
|
||||
@ -513,7 +515,7 @@ void init_window(int w, int h, char **argv, int argc)
|
||||
}
|
||||
|
||||
/* Skip pager */
|
||||
if (TEST_HINT(window.hints, HINT_SKIP_PAGER)) {
|
||||
if (TEST_HINT(hints, HINT_SKIP_PAGER)) {
|
||||
/* fprintf(stderr, PACKAGE_NAME": hint - skip_pager\n");
|
||||
fflush(stderr); */
|
||||
|
||||
@ -963,6 +965,47 @@ conky::lua_traits<window_type>::Map conky::lua_traits<window_type>::map = {
|
||||
};
|
||||
conky::simple_config_setting<window_type> own_window_type("own_window_type", TYPE_NORMAL, false);
|
||||
|
||||
template<>
|
||||
conky::lua_traits<window_hints>::Map conky::lua_traits<window_hints>::map = {
|
||||
{ "undecorated", HINT_UNDECORATED },
|
||||
{ "below", HINT_BELOW },
|
||||
{ "above", HINT_ABOVE },
|
||||
{ "sticky", HINT_STICKY },
|
||||
{ "skip_taskbar", HINT_SKIP_TASKBAR },
|
||||
{ "skip_pager", HINT_SKIP_PAGER }
|
||||
};
|
||||
|
||||
std::pair<uint16_t, bool>
|
||||
window_hints_traits::convert(lua::state &l, int index, const std::string &name)
|
||||
{
|
||||
typedef conky::lua_traits<window_hints> Traits;
|
||||
|
||||
lua::stack_sentry s(l);
|
||||
l.checkstack(1);
|
||||
|
||||
std::string hints = l.tostring(index);
|
||||
// add a sentinel to simplify the following loop
|
||||
hints += ',';
|
||||
size_t pos = 0;
|
||||
size_t newpos;
|
||||
uint16_t ret = 0;
|
||||
while((newpos = hints.find_first_of(", ", pos)) != std::string::npos) {
|
||||
if(newpos > pos) {
|
||||
l.pushstring(hints.substr(pos, newpos-pos));
|
||||
auto t = conky::lua_traits<window_hints>::convert(l, -1, name);
|
||||
if(not t.second)
|
||||
return {0, false};
|
||||
SET_HINT(ret, t.first);
|
||||
l.pop();
|
||||
}
|
||||
pos = newpos+1;
|
||||
}
|
||||
return {ret, true};
|
||||
}
|
||||
|
||||
conky::simple_config_setting<uint16_t, window_hints_traits> own_window_hints("own_window_hints",
|
||||
0, false);
|
||||
|
||||
conky::simple_config_setting<std::string> background_colour("background_colour", "black", false);
|
||||
|
||||
#ifdef BUILD_ARGB
|
||||
|
13
src/x11.h
13
src/x11.h
@ -52,7 +52,7 @@ enum window_type {
|
||||
TYPE_OVERRIDE
|
||||
};
|
||||
|
||||
enum _window_hints {
|
||||
enum window_hints {
|
||||
HINT_UNDECORATED = 0,
|
||||
HINT_BELOW,
|
||||
HINT_ABOVE,
|
||||
@ -61,8 +61,8 @@ enum _window_hints {
|
||||
HINT_SKIP_PAGER
|
||||
};
|
||||
|
||||
#define SET_HINT(mask, hint) (mask |= (1 << hint))
|
||||
#define TEST_HINT(mask, hint) (mask & (1 << hint))
|
||||
#define SET_HINT(mask, hint) (mask |= (1 << (hint)))
|
||||
#define TEST_HINT(mask, hint) (mask & (1 << (hint)))
|
||||
#endif
|
||||
|
||||
struct conky_window {
|
||||
@ -85,7 +85,6 @@ struct conky_window {
|
||||
#ifdef OWN_WINDOW
|
||||
int x;
|
||||
int y;
|
||||
unsigned long hints;
|
||||
#endif
|
||||
};
|
||||
|
||||
@ -155,6 +154,12 @@ extern conky::simple_config_setting<std::string> own_window_class;
|
||||
extern conky::simple_config_setting<std::string> own_window_title;
|
||||
extern conky::simple_config_setting<window_type> own_window_type;
|
||||
|
||||
struct window_hints_traits {
|
||||
static const lua::Type type = lua::TSTRING;
|
||||
static std::pair<uint16_t, bool> convert(lua::state &l, int index, const std::string &name);
|
||||
};
|
||||
extern conky::simple_config_setting<uint16_t, window_hints_traits> own_window_hints;
|
||||
|
||||
// this setting is not checked for validity when set, we leave that to the caller
|
||||
// the reason for that is that we need to have X initialised in order to call XParseColor()
|
||||
extern conky::simple_config_setting<std::string> background_colour;
|
||||
|
Loading…
x
Reference in New Issue
Block a user