1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-12-28 13:00:45 +00:00

Make nvidia_display a lua setting

This commit is contained in:
Pavel Labath 2010-08-21 14:13:07 +02:00
parent 179a1a15b9
commit 4cb6606ea2
3 changed files with 41 additions and 24 deletions

View File

@ -2537,10 +2537,6 @@ void clean_up_without_threads(void *memtofree1, void* memtofree2)
free(fonts); //in set_default_configurations a font is set but not loaded free(fonts); //in set_default_configurations a font is set but not loaded
font_count = -1; font_count = -1;
} }
#ifdef BUILD_NVIDIA
set_nvidia_display(NULL);
#endif
#endif /* BUILD_X11 */ #endif /* BUILD_X11 */
if (info.first_process) { if (info.first_process) {
@ -2847,12 +2843,6 @@ char load_config_file(const char *f)
// start the whole if-then-else-if cascade // start the whole if-then-else-if cascade
if (false) {} if (false) {}
#ifdef BUILD_NVIDIA
CONF("nvidia_display") {
if(value)
set_nvidia_display(value);
}
#endif
CONF("imap") { CONF("imap") {
if (value) { if (value) {
parse_global_imap_mail_args(value); parse_global_imap_mail_args(value);

View File

@ -59,6 +59,47 @@ struct nvidia_s {
static Display *nvdisplay; static Display *nvdisplay;
namespace {
class nvidia_display_setting: public conky::simple_config_setting<std::string> {
typedef conky::simple_config_setting<std::string> Base;
protected:
virtual void lua_setter(lua::state &l, bool init);
virtual void cleanup(lua::state &l);
public:
nvidia_display_setting()
: Base("nvidia_display", std::string(), false)
{}
};
void nvidia_display_setting::lua_setter(lua::state &l, bool init)
{
lua::stack_sentry s(l, -2);
Base::lua_setter(l, init);
std::string str = do_convert(l, -1).first;
if(str.size()) {
if ((nvdisplay = XOpenDisplay(str.c_str())) == NULL) {
CRIT_ERR(NULL, NULL, "can't open nvidia display: %s", XDisplayName(str.c_str()));
}
}
}
void nvidia_display_setting::cleanup(lua::state &l)
{
lua::stack_sentry s(l, -1);
if(nvdisplay) {
XCloseDisplay(nvdisplay);
nvdisplay = NULL;
}
l.pop();
}
}
static int get_nvidia_value(QUERY_ID qid){ static int get_nvidia_value(QUERY_ID qid){
int tmp; int tmp;
Display *dpy = nvdisplay ? nvdisplay : display; Display *dpy = nvdisplay ? nvdisplay : display;
@ -133,16 +174,3 @@ void free_nvidia(struct text_object *obj)
{ {
free_and_zero(obj->data.opaque); free_and_zero(obj->data.opaque);
} }
void set_nvidia_display(const char *disp)
{
if(nvdisplay) {
XCloseDisplay(nvdisplay);
nvdisplay = NULL;
}
if(disp) {
if ((nvdisplay = XOpenDisplay(disp)) == NULL) {
CRIT_ERR(NULL, NULL, "can't open nvidia display: %s", XDisplayName(disp));
}
}
}

View File

@ -35,6 +35,5 @@
int set_nvidia_type(struct text_object *, const char *); int set_nvidia_type(struct text_object *, const char *);
void print_nvidia_value(struct text_object *, char *, int); void print_nvidia_value(struct text_object *, char *, int);
void free_nvidia(struct text_object *); void free_nvidia(struct text_object *);
void set_nvidia_display(const char *disp);
#endif #endif