From 1bb96132376c3039903d13b78196e75cdf22c14b Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Mon, 19 Jul 2021 17:22:43 +0200 Subject: [PATCH] Clean up style in recent monitor code Fix some indentation issues and make sure everything* uses CamelCase. * MonitorArrangement is left as snake_case in order to pretend it is an independent FLTK widget class. --- vncviewer/DesktopWindow.cxx | 22 ++++----- vncviewer/MonitorArrangement.cxx | 26 +++++----- vncviewer/MonitorArrangement.h | 2 +- vncviewer/MonitorIndicesParameter.cxx | 50 +++++++++---------- vncviewer/MonitorIndicesParameter.h | 8 +-- vncviewer/win32.c | 70 +++++++++++++-------------- 6 files changed, 89 insertions(+), 89 deletions(-) diff --git a/vncviewer/DesktopWindow.cxx b/vncviewer/DesktopWindow.cxx index 0fe08707..3b4589c9 100644 --- a/vncviewer/DesktopWindow.cxx +++ b/vncviewer/DesktopWindow.cxx @@ -468,25 +468,25 @@ void DesktopWindow::draw() if (fullscreen_active()) { assert(Fl::screen_count() >= 1); - rfb::Rect window_rect, screen_rect; - window_rect.setXYWH(x(), y(), w(), h()); + rfb::Rect windowRect, screenRect; + windowRect.setXYWH(x(), y(), w(), h()); - bool found_enclosed_screen = false; + bool foundEnclosedScreen = false; for (int i = 0; i < Fl::screen_count(); i++) { Fl::screen_xywh(sx, sy, sw, sh, i); // The screen with the smallest index that are enclosed by // the viewport will be used for showing the overlay. - screen_rect.setXYWH(sx, sy, sw, sh); - if (screen_rect.enclosed_by(window_rect)) { - found_enclosed_screen = true; + screenRect.setXYWH(sx, sy, sw, sh); + if (screenRect.enclosed_by(windowRect)) { + foundEnclosedScreen = true; break; } } // If no monitor inside the viewport was found, // use the one primary instead. - if (!found_enclosed_screen) + if (!foundEnclosedScreen) Fl::screen_xywh(sx, sy, sw, sh, 0); // Adjust the coordinates so they are relative to the viewport. @@ -882,10 +882,10 @@ int DesktopWindow::fltkHandle(int event, Fl_Window *win) void DesktopWindow::fullscreen_on() { - bool all_monitors = !strcasecmp(fullScreenMode, "all"); - bool selected_monitors = !strcasecmp(fullScreenMode, "selected"); + bool allMonitors = !strcasecmp(fullScreenMode, "all"); + bool selectedMonitors = !strcasecmp(fullScreenMode, "selected"); - if (not selected_monitors and not all_monitors) { + if (not selectedMonitors and not allMonitors) { int n = Fl::screen_num(x(), y(), w(), h()); fullscreen_screens(n, n, n, n); } else { @@ -896,7 +896,7 @@ void DesktopWindow::fullscreen_on() std::set monitors; - if (selected_monitors and not all_monitors) { + if (selectedMonitors and not allMonitors) { std::set selected = fullScreenSelectedMonitors.getParam(); monitors.insert(selected.begin(), selected.end()); } else { diff --git a/vncviewer/MonitorArrangement.cxx b/vncviewer/MonitorArrangement.cxx index 2a7bfad6..04c2ab98 100644 --- a/vncviewer/MonitorArrangement.cxx +++ b/vncviewer/MonitorArrangement.cxx @@ -61,7 +61,7 @@ MonitorArrangement::MonitorArrangement( : Fl_Group(x, y, w, h), SELECTION_COLOR(fl_lighter(FL_BLUE)), AVAILABLE_COLOR(fl_lighter(fl_lighter(fl_lighter(FL_BACKGROUND_COLOR)))), - m_monitors() + monitors() { // Used for required monitors. Fl::set_boxtype(FL_CHECKERED_BOX, checkered_pattern_draw, 0, 0, 0, 0); @@ -88,8 +88,8 @@ std::set MonitorArrangement::get() { std::set indices; - for (int i = 0; i < (int) m_monitors.size(); i++) { - if (m_monitors[i]->value() == 1) + for (int i = 0; i < (int) monitors.size(); i++) { + if (monitors[i]->value() == 1) indices.insert(i); } @@ -98,16 +98,16 @@ std::set MonitorArrangement::get() void MonitorArrangement::set(std::set indices) { - for (int i = 0; i < (int) m_monitors.size(); i++) { + for (int i = 0; i < (int) monitors.size(); i++) { bool selected = std::find(indices.begin(), indices.end(), i) != indices.end(); - m_monitors[i]->value(selected ? 1 : 0); + monitors[i]->value(selected ? 1 : 0); } } void MonitorArrangement::draw() { - for (int i = 0; i < (int) m_monitors.size(); i++) { - Fl_Button * monitor = m_monitors[i]; + for (int i = 0; i < (int) monitors.size(); i++) { + Fl_Button * monitor = monitors[i]; if (is_required(i)) { monitor->box(FL_CHECKERED_BOX); @@ -143,11 +143,11 @@ void MonitorArrangement::layout() monitor->callback(monitor_pressed, this); monitor->type(FL_TOGGLE_BUTTON); monitor->when(FL_WHEN_CHANGED); - m_monitors.push_back(monitor); + monitors.push_back(monitor); } - for (int i = 0; i < (int) m_monitors.size(); i++) - m_monitors[i]->copy_tooltip(description(i).c_str()); + for (int i = 0; i < (int) monitors.size(); i++) + monitors[i]->copy_tooltip(description(i).c_str()); } void MonitorArrangement::refresh() @@ -156,7 +156,7 @@ void MonitorArrangement::refresh() // pressed. We need to manually restore the current selection // when the widget is refreshed. std::set indices = get(); - m_monitors.clear(); + monitors.clear(); // FLTK recursively deletes all children for us. clear(); @@ -172,7 +172,7 @@ void MonitorArrangement::refresh() bool MonitorArrangement::is_required(int m) { // A selected monitor is never required. - if (m_monitors[m]->value() == 1) + if (monitors[m]->value() == 1) return false; // If no monitors are selected, none are required. @@ -308,7 +308,7 @@ std::pair MonitorArrangement::origin() std::string MonitorArrangement::description(int m) { - assert(m < (int) m_monitors.size()); + assert(m < (int) monitors.size()); const size_t name_len = 1024; char name[name_len] = {}; int bytes_written = get_monitor_name(m, name, name_len); diff --git a/vncviewer/MonitorArrangement.h b/vncviewer/MonitorArrangement.h index f1ba108d..3a71e5b0 100644 --- a/vncviewer/MonitorArrangement.h +++ b/vncviewer/MonitorArrangement.h @@ -41,7 +41,7 @@ protected: private: const Fl_Color SELECTION_COLOR; const Fl_Color AVAILABLE_COLOR; - std::vector m_monitors; + std::vector monitors; // Layout the monitor arrangement. void layout(); diff --git a/vncviewer/MonitorIndicesParameter.cxx b/vncviewer/MonitorIndicesParameter.cxx index 54764af7..57055f61 100644 --- a/vncviewer/MonitorIndicesParameter.cxx +++ b/vncviewer/MonitorIndicesParameter.cxx @@ -40,27 +40,27 @@ std::set MonitorIndicesParameter::getParam() { bool valid = false; std::set indices; - std::set config_indices; - std::vector monitors = this->monitors(); + std::set configIndices; + std::vector monitors = fetchMonitors(); if (monitors.size() <= 0) { vlog.error(_("Failed to get monitors.")); return indices; } - valid = parse_indices(value, &config_indices); + valid = parseIndices(value, &configIndices); if (!valid) { return indices; } - if (config_indices.size() <= 0) { + if (configIndices.size() <= 0) { return indices; } // Go through the monitors and see what indices are present in the config. for (int i = 0; i < ((int) monitors.size()); i++) { - if (std::find(config_indices.begin(), config_indices.end(), i) != config_indices.end()) - indices.insert(monitors[i].fltk_index); + if (std::find(configIndices.begin(), configIndices.end(), i) != configIndices.end()) + indices.insert(monitors[i].fltkIndex); } return indices; @@ -74,7 +74,7 @@ bool MonitorIndicesParameter::setParam(const char* value) if (strlen(value) < 0) return false; - if (!parse_indices(value, &indices)) { + if (!parseIndices(value, &indices)) { vlog.error(_("Invalid FullScreenSelectedMonitors configuration.")); return false; } @@ -93,8 +93,8 @@ bool MonitorIndicesParameter::setParam(std::set indices) { static const int BUF_MAX_LEN = 1024; char buf[BUF_MAX_LEN] = {0}; - std::set config_indices; - std::vector monitors = this->monitors(); + std::set configIndices; + std::vector monitors = fetchMonitors(); if (monitors.size() <= 0) { vlog.error(_("Failed to get monitors.")); @@ -102,20 +102,20 @@ bool MonitorIndicesParameter::setParam(std::set indices) } for (int i = 0; i < ((int) monitors.size()); i++) { - if (std::find(indices.begin(), indices.end(), monitors[i].fltk_index) != indices.end()) - config_indices.insert(i); + if (std::find(indices.begin(), indices.end(), monitors[i].fltkIndex) != indices.end()) + configIndices.insert(i); } - int bytes_written = 0; + int bytesWritten = 0; char const * separator = ""; - for (std::set::iterator index = config_indices.begin(); - index != config_indices.end(); + for (std::set::iterator index = configIndices.begin(); + index != configIndices.end(); index++) { - bytes_written += snprintf( - buf+bytes_written, - BUF_MAX_LEN-bytes_written, + bytesWritten += snprintf( + buf+bytesWritten, + BUF_MAX_LEN-bytesWritten, "%s%u", separator, (*index)+1 @@ -127,7 +127,7 @@ bool MonitorIndicesParameter::setParam(std::set indices) return setParam(buf); } -static bool parse_number(std::string number, std::set *indices) +static bool parseNumber(std::string number, std::set *indices) { if (number.size() <= 0) return false; @@ -148,7 +148,7 @@ static bool parse_number(std::string number, std::set *indices) return true; } -bool MonitorIndicesParameter::parse_indices(const char* value, std::set *indices) +bool MonitorIndicesParameter::parseIndices(const char* value, std::set *indices) { char d; std::string current; @@ -161,7 +161,7 @@ bool MonitorIndicesParameter::parse_indices(const char* value, std::set *in else if (d >= '0' && d <= '9') current.push_back(d); else if (d == ',') { - if (!parse_number(current, indices)) { + if (!parseNumber(current, indices)) { vlog.error(_("Invalid monitor index '%s' in FullScreenSelectedMonitors"), current.c_str()); return false; } @@ -178,13 +178,13 @@ bool MonitorIndicesParameter::parse_indices(const char* value, std::set *in return true; // Parsing anything we have left. - if (!parse_number(current, indices)) + if (!parseNumber(current, indices)) return false; return true; } -std::vector MonitorIndicesParameter::monitors() +std::vector MonitorIndicesParameter::fetchMonitors() { std::vector monitors; @@ -201,16 +201,16 @@ std::vector MonitorIndicesParameter::monitors( i ); - monitor.fltk_index = i; + monitor.fltkIndex = i; monitors.push_back(monitor); } // Sort the monitors according to the specification in the vncviewer manual. - qsort(&monitors[0], monitors.size(), sizeof(*(&monitors[0])), sort_cb); + qsort(&monitors[0], monitors.size(), sizeof(*(&monitors[0])), compare); return monitors; } -int MonitorIndicesParameter::sort_cb(const void *a, const void *b) +int MonitorIndicesParameter::compare(const void *a, const void *b) { MonitorIndicesParameter::Monitor * monitor1 = (MonitorIndicesParameter::Monitor *) a; MonitorIndicesParameter::Monitor * monitor2 = (MonitorIndicesParameter::Monitor *) b; diff --git a/vncviewer/MonitorIndicesParameter.h b/vncviewer/MonitorIndicesParameter.h index 1737a5b3..1e0925d2 100644 --- a/vncviewer/MonitorIndicesParameter.h +++ b/vncviewer/MonitorIndicesParameter.h @@ -33,12 +33,12 @@ public: private: typedef struct { int x, y, w, h; - int fltk_index; + int fltkIndex; } Monitor; - bool parse_indices(const char* value, std::set *indices); - std::vector monitors(); - static int sort_cb(const void*, const void*); + bool parseIndices(const char* value, std::set *indices); + std::vector fetchMonitors(); + static int compare(const void*, const void*); }; #endif // __MONITOR_INDEX_PARAMETER_H diff --git a/vncviewer/win32.c b/vncviewer/win32.c index dc8cb602..9032f36a 100644 --- a/vncviewer/win32.c +++ b/vncviewer/win32.c @@ -421,52 +421,52 @@ int win32_has_altgr(void) } typedef struct { - int x, y, w, h; - char* name; - size_t name_len; - int bytes_written; + int x, y, w, h; + char* name; + size_t name_len; + int bytes_written; } EnumCallbackData; static BOOL CALLBACK EnumDisplayMonitorsCallback( - HMONITOR monitor, HDC deviceContext, LPRECT rect, LPARAM userData) + HMONITOR monitor, HDC deviceContext, LPRECT rect, LPARAM userData) { - EnumCallbackData *data = (EnumCallbackData *)userData; - MONITORINFOEX info; - info.cbSize = sizeof(info); - GetMonitorInfo(monitor, (LPMONITORINFO)&info); + EnumCallbackData *data = (EnumCallbackData *)userData; + MONITORINFOEX info; + info.cbSize = sizeof(info); + GetMonitorInfo(monitor, (LPMONITORINFO)&info); - int x = info.rcMonitor.left; - int y = info.rcMonitor.top; - int w = info.rcMonitor.right - info.rcMonitor.left; - int h = info.rcMonitor.bottom - info.rcMonitor.top; + int x = info.rcMonitor.left; + int y = info.rcMonitor.top; + int w = info.rcMonitor.right - info.rcMonitor.left; + int h = info.rcMonitor.bottom - info.rcMonitor.top; - if ((data->x == x) && (data->y == y) && (data->w == w) && (data->h == h)) { - data->bytes_written = snprintf(data->name, data->name_len, - "%.*s", (int)(data->name_len - 1), info.szDevice); + if ((data->x == x) && (data->y == y) && (data->w == w) && (data->h == h)) { + data->bytes_written = snprintf(data->name, data->name_len, + "%.*s", (int)(data->name_len - 1), info.szDevice); - if (data->bytes_written < 0) - return FALSE; + if (data->bytes_written < 0) + return FALSE; - // Stop the iteration. - return FALSE; - } + // Stop the iteration. + return FALSE; + } - // Keep iterating. - return TRUE; + // Keep iterating. + return TRUE; } int win32_get_monitor_name(int x, int y, int w, int h, char name[], size_t name_len) { - EnumCallbackData data = { - .x = x, - .y = y, - .w = w, - .h = h, - .name = name, - .name_len = name_len, - .bytes_written = -1 - }; - - EnumDisplayMonitors(NULL, NULL, EnumDisplayMonitorsCallback, (LPARAM) &data); - return data.bytes_written; + EnumCallbackData data = { + .x = x, + .y = y, + .w = w, + .h = h, + .name = name, + .name_len = name_len, + .bytes_written = -1 + }; + + EnumDisplayMonitors(NULL, NULL, EnumDisplayMonitorsCallback, (LPARAM) &data); + return data.bytes_written; } -- 2.39.5