Skip to content

Commit

Permalink
Initial stubbing of display backends
Browse files Browse the repository at this point in the history
Hopefully this will lead the way to adding support for things like
Wayland and Haiku graphics, cf. brndnmtthws#56.

We define a display_output_base class that display backends
can derive from to implement display-specific calls.
  • Loading branch information
mmuman committed Oct 14, 2018
1 parent a8b5975 commit a05c2fb
Show file tree
Hide file tree
Showing 12 changed files with 754 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ set(conky_sources
user.cc user.h
luamm.cc luamm.hh
data-source.cc data-source.hh
display-output.cc display-output.hh
display-console.cc display-console.hh
display-ncurses.cc display-ncurses.hh
display-http.cc display-http.hh
display-x11.cc display-x11.hh
lua-config.cc lua-config.hh
setting.cc setting.hh
llua.cc llua.h
Expand Down
7 changes: 7 additions & 0 deletions src/conky.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@

#include "lua-config.hh"
#include "setting.hh"
#include "display-output.hh"

/* check for OS and include appropriate headers */
#if defined(__linux__)
Expand Down Expand Up @@ -3039,6 +3040,10 @@ void initialisation(int argc, char **argv) {
tmpstring2 = static_cast<char *>(malloc(text_buffer_size.get(*state)));
memset(tmpstring2, 0, text_buffer_size.get(*state));

if (!conky::initialize_display_outputs()) {
CRIT_ERR(nullptr, nullptr, "initialize_display_outputs() failed.");
}

#ifdef BUILD_X11
X11_create_window();
#endif /* BUILD_X11 */
Expand Down Expand Up @@ -3169,6 +3174,8 @@ int main(int argc, char **argv) {
return EXIT_FAILURE;
}

conky::shutdown_display_outputs();

#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
kvm_close(kd);
#endif
Expand Down
67 changes: 67 additions & 0 deletions src/display-console.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
*
* Conky, a system monitor, based on torsmo
*
* Please see COPYING for details
*
* Copyright (C) 2010 Pavel Labath et al.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

#include <config.h>

#include "conky.h"
#include "display-console.hh"

#include <iostream>
#include <sstream>
#include <unordered_map>

namespace conky {
namespace {

conky::display_output_console console_output("console");

} // namespace

namespace priv {


} // namespace priv

display_output_console::display_output_console(const std::string &name_)
: display_output_base(name_) {
// lowest priority, it's a fallback
priority = 0;
}

bool display_output_console::detect() {
if (out_to_stdout.get(*state) || out_to_stderr.get(*state)) {
std::cerr << "Display output '" << name << "' enabled in config." << std::endl;
return true;
}
return false;
}

bool display_output_console::initialize() {
return true;
}

bool display_output_console::shutdown() {
return true;
}

} // namespace conky

57 changes: 57 additions & 0 deletions src/display-console.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
*
* Conky, a system monitor, based on torsmo
*
* Please see COPYING for details
*
* Copyright (C) 2010 Pavel Labath et al.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

#ifndef DISPLAY_CONSOLE_HH
#define DISPLAY_CONSOLE_HH

#include <limits>
#include <string>
#include <type_traits>

#include "luamm.hh"
#include "display-output.hh"

namespace conky {

/*
* A base class for console display output.
*/
class display_output_console : public display_output_base {

public:

explicit display_output_console(const std::string &name_);

virtual ~display_output_console() {}

// check if available and enabled in settings
virtual bool detect();
// connect to DISPLAY and other stuff
virtual bool initialize();
virtual bool shutdown();

// console-specific
};

} // namespace conky

#endif /* DISPLAY_CONSOLE_HH */
76 changes: 76 additions & 0 deletions src/display-http.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
*
* Conky, a system monitor, based on torsmo
*
* Please see COPYING for details
*
* Copyright (C) 2010 Pavel Labath et al.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

#include <config.h>

#include "conky.h"
#include "display-http.hh"

#include <iostream>
#include <sstream>
#include <unordered_map>

namespace conky {
namespace {

#ifdef BUILD_HTTP
conky::display_output_http http_output;
#else
conky::disabled_display_output http_output_disabled("http", "BUILD_HTTP");
#endif

} // namespace

namespace priv {


} // namespace priv

#ifdef BUILD_HTTP

display_output_http::display_output_http()
: display_output_base("http") {
priority = 1;
}

bool display_output_http::detect() {
/* TODO:
if (out_to_http.get(*state)) {
std::cerr << "Display output '" << name << "' enabled in config." << std::endl;
return true;
}
*/
return false;
}

bool display_output_http::initialize() {
return false;
}

bool display_output_http::shutdown() {
return false;
}

#endif

} // namespace conky

57 changes: 57 additions & 0 deletions src/display-http.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
*
* Conky, a system monitor, based on torsmo
*
* Please see COPYING for details
*
* Copyright (C) 2010 Pavel Labath et al.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

#ifndef DISPLAY_HTTP_HH
#define DISPLAY_HTTP_HH

#include <limits>
#include <string>
#include <type_traits>

#include "luamm.hh"
#include "display-output.hh"

namespace conky {

/*
* A base class for HTTP display output.
*/
class display_output_http : public display_output_base {

public:

explicit display_output_http();

virtual ~display_output_http() {}

// check if available and enabled in settings
virtual bool detect();
// connect to DISPLAY and other stuff
virtual bool initialize();
virtual bool shutdown();

// HTTP-specific
};

} // namespace conky

#endif /* DISPLAY_HTTP_HH */
75 changes: 75 additions & 0 deletions src/display-ncurses.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
*
* Conky, a system monitor, based on torsmo
*
* Please see COPYING for details
*
* Copyright (C) 2010 Pavel Labath et al.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

#include <config.h>

#include "conky.h"
#include "nc.h"
#include "display-ncurses.hh"

#include <iostream>
#include <sstream>
#include <unordered_map>

namespace conky {
namespace {

#ifdef BUILD_NCURSES
conky::display_output_ncurses ncurses_output;
#else
conky::disabled_display_output ncurses_output_disabled("ncurses", "BUILD_NCURSES");
#endif

} // namespace

namespace priv {


} // namespace priv

#ifdef BUILD_NCURSES

display_output_ncurses::display_output_ncurses()
: display_output_console("ncurses") {
priority = 1;
}

bool display_output_ncurses::detect() {
if (out_to_ncurses.get(*state)) {
std::cerr << "Display output '" << name << "' enabled in config." << std::endl;
return true;
}
return false;
}

bool display_output_ncurses::initialize() {
return false;
}

bool display_output_ncurses::shutdown() {
return false;
}

#endif /* BUILD_NCURSES */

} // namespace conky

Loading

0 comments on commit a05c2fb

Please sign in to comment.