Allow rtorrent to run as a daemon, slightly modified version of the PR provided by sallyswiss

This commit is contained in:
zp
2016-06-19 02:06:30 -05:00
parent 9abcea84c7
commit c01709fa27
4 changed files with 99 additions and 70 deletions
+39 -32
View File
@@ -49,37 +49,37 @@ public:
typedef std::vector<Attributes> attributes_list;
Canvas(int x = 0, int y = 0, int width = 0, int height = 0);
~Canvas() { delwin(m_window); }
~Canvas() { if (!m_isDaemon) { delwin(m_window); } }
void refresh() { wnoutrefresh(m_window); }
static void refresh_std() { wnoutrefresh(stdscr); }
void redraw() { redrawwin(m_window); }
static void redraw_std() { redrawwin(stdscr); }
void refresh() { if (!m_isDaemon) { wnoutrefresh(m_window); } }
static void refresh_std() { if (!m_isDaemon) { wnoutrefresh(stdscr); } }
void redraw() { if (!m_isDaemon) { redrawwin(m_window); } }
static void redraw_std() { if (!m_isDaemon) { redrawwin(stdscr); } }
void resize(int w, int h) { wresize(m_window, h, w); }
void resize(int w, int h) { if (!m_isDaemon) { wresize(m_window, h, w); } }
void resize(int x, int y, int w, int h);
static void resize_term(int x, int y) { resizeterm(y, x); }
static void resize_term(std::pair<int, int> dim) { resizeterm(dim.second, dim.first); }
static void resize_term(int x, int y) { if (!m_isDaemon) { resizeterm(y, x); } }
static void resize_term(std::pair<int, int> dim) { if (!m_isDaemon) { resizeterm(dim.second, dim.first); } }
unsigned int get_x() { int x, __UNUSED y; getyx(m_window, y, x); return x; }
unsigned int get_y() { int x, y; getyx(m_window, y, x); return y; }
unsigned int get_x() { int x, __UNUSED y; if (!m_isDaemon) { getyx(m_window, y, x); } else { x=1; } return x; }
unsigned int get_y() { int x, y; if (!m_isDaemon) { getyx(m_window, y, x); } else { y=1; } return y; }
unsigned int width() { int x, __UNUSED y; getmaxyx(m_window, y, x); return x; }
unsigned int height() { int x, y; getmaxyx(m_window, y, x); return y; }
unsigned int width() { int x, __UNUSED y; if (!m_isDaemon) { getmaxyx(m_window, y, x); } else { x=80; } return x; }
unsigned int height() { int x, y; if (!m_isDaemon) { getmaxyx(m_window, y, x); } else { y=24; } return y; }
void move(unsigned int x, unsigned int y) { wmove(m_window, y, x); }
void move(unsigned int x, unsigned int y) { if (!m_isDaemon) { wmove(m_window, y, x); } }
chtype get_background() { return getbkgd(m_window); }
void set_background(chtype c) { return wbkgdset(m_window, c); }
chtype get_background() { chtype bg=0; if (!m_isDaemon) { bg=getbkgd(m_window); } return bg; }
void set_background(chtype c) { if (!m_isDaemon) { return wbkgdset(m_window, c); } }
void erase() { werase(m_window); }
static void erase_std() { werase(stdscr); }
void erase() { if (!m_isDaemon) { werase(m_window); } }
static void erase_std() { if (!m_isDaemon) { werase(stdscr); } }
void print_border(chtype ls, chtype rs,
chtype ts, chtype bs,
chtype tl, chtype tr,
chtype bl, chtype br) { wborder(m_window, ls, rs, ts, bs, tl, tr, bl, br); }
chtype bl, chtype br) { if (!m_isDaemon) { wborder(m_window, ls, rs, ts, bs, tl, tr, bl, br); } }
// The format string is non-const, but that will not be a problem
// since the string shall always be a C string choosen at
@@ -90,29 +90,32 @@ public:
void print_attributes(unsigned int x, unsigned int y, const char* first, const char* last, const attributes_list* attributes);
void print_char(const chtype ch) { waddch(m_window, ch); }
void print_char(unsigned int x, unsigned int y, const chtype ch) { mvwaddch(m_window, y, x, ch); }
void print_char(const chtype ch) { if (!m_isDaemon) { waddch(m_window, ch); } }
void print_char(unsigned int x, unsigned int y, const chtype ch) { if (!m_isDaemon) { mvwaddch(m_window, y, x, ch); } }
void set_attr(unsigned int x, unsigned int y, unsigned int n, int attr, int color) { mvwchgat(m_window, y, x, n, attr, color, NULL); }
void set_attr(unsigned int x, unsigned int y, unsigned int n, int attr, int color) { if (!m_isDaemon) { mvwchgat(m_window, y, x, n, attr, color, NULL); } }
void set_default_attributes(int attr) { (void)wattrset(m_window, attr); }
void set_default_attributes(int attr) { if (!m_isDaemon) { (void)wattrset(m_window, attr); } }
// Initialize stdscr.
static void initialize();
static void cleanup();
static int get_screen_width() { int x, __UNUSED y; getmaxyx(stdscr, y, x); return x; }
static int get_screen_height() { int x, y; getmaxyx(stdscr, y, x); return y; }
static int get_screen_width() { int x, __UNUSED y; if (!m_isDaemon) { getmaxyx(stdscr, y, x); } else { x=80; } return x; }
static int get_screen_height() { int x, y; if (!m_isDaemon) { getmaxyx(stdscr, y, x); } else { y=24;} return y; }
static std::pair<int, int> term_size();
static void do_update() { doupdate(); }
static void do_update() { if (!m_isDaemon) { doupdate(); } }
static bool daemon() { return m_isDaemon; }
private:
Canvas(const Canvas&);
void operator = (const Canvas&);
static bool m_isInitialized;
static bool m_isDaemon;
WINDOW* m_window;
};
@@ -121,19 +124,23 @@ inline void
Canvas::print(const char* str, ...) {
va_list arglist;
va_start(arglist, str);
vw_printw(m_window, const_cast<char*>(str), arglist);
va_end(arglist);
if (!m_isDaemon) {
va_start(arglist, str);
vw_printw(m_window, const_cast<char*>(str), arglist);
va_end(arglist);
}
}
inline void
Canvas::print(unsigned int x, unsigned int y, const char* str, ...) {
va_list arglist;
va_start(arglist, str);
wmove(m_window, y, x);
vw_printw(m_window, const_cast<char*>(str), arglist);
va_end(arglist);
if (!m_isDaemon) {
va_start(arglist, str);
wmove(m_window, y, x);
vw_printw(m_window, const_cast<char*>(str), arglist);
va_end(arglist);
}
}
}