Skip to content

Commit

Permalink
Merge pull request #647 from wt/remove_GetMonitors
Browse files Browse the repository at this point in the history
Remove get monitors
  • Loading branch information
jp9000 authored Oct 4, 2016
2 parents 5642b7b + f3eb8aa commit f816377
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 156 deletions.
14 changes: 1 addition & 13 deletions UI/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,7 @@ elseif(UNIX)
set(obs_PLATFORM_SOURCES
platform-x11.cpp)

find_package(XCB COMPONENTS XCB REQUIRED RANDR REQUIRED XINERAMA REQUIRED)

include_directories(
${XCB_INCLUDE_DIRS}
${X11_XCB_INCLUDE_DIRS})

add_definitions(
${XCB_DEFINITIONS}
${X11_XCB_DEFINITIONS})

set(obs_PLATFORM_LIBRARIES
${XCB_LIBRARIES}
${X11_XCB_LIBRARIES}
set(obs_PLATFORM_LIBRARIES
Qt5::X11Extras)
endif()

Expand Down
16 changes: 4 additions & 12 deletions UI/obs-app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
#include <obs-config.h>
#include <obs.hpp>

#include <QGuiApplication>
#include <QProxyStyle>
#include <QScreen>

#include "qt-wrappers.hpp"
#include "obs-app.hpp"
Expand Down Expand Up @@ -1520,20 +1522,10 @@ bool GetClosestUnusedFileName(std::string &path, const char *extension)

bool WindowPositionValid(QRect rect)
{
vector<MonitorInfo> monitors;
GetMonitors(monitors);

for (auto &monitor : monitors) {
int left = int(monitor.x);
int top = int(monitor.y);
int right = left + int(monitor.cx);
int bottom = top + int(monitor.cy);

if ((rect.left() - right) < 0 && (left - rect.right()) < 0 &&
(rect.top() - bottom) < 0 && (top - rect.bottom()) < 0)
for (QScreen* screen: QGuiApplication::screens()) {
if (screen->availableGeometry().intersects(rect))
return true;
}

return false;
}

Expand Down
11 changes: 0 additions & 11 deletions UI/platform-osx.mm
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,6 @@ bool GetDataFilePath(const char *data, string &output)
return !access(output.c_str(), R_OK);
}

void GetMonitors(vector<MonitorInfo> &monitors)
{
monitors.clear();
for(NSScreen *screen : [NSScreen screens])
{
NSRect frame = [screen convertRectToBacking:[screen frame]];
monitors.emplace_back(frame.origin.x, frame.origin.y,
frame.size.width, frame.size.height);
}
}

bool InitApplicationBundle()
{
#ifdef OBS_OSX_BUNDLE
Expand Down
22 changes: 0 additions & 22 deletions UI/platform-windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,28 +51,6 @@ bool GetDataFilePath(const char *data, string &output)
return check_path(data, OBS_DATA_PATH "/obs-studio/", output);
}

static BOOL CALLBACK OBSMonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor,
LPRECT rect, LPARAM param)
{
vector<MonitorInfo> &monitors = *(vector<MonitorInfo> *)param;

monitors.emplace_back(
rect->left,
rect->top,
rect->right - rect->left,
rect->bottom - rect->top);

UNUSED_PARAMETER(hMonitor);
UNUSED_PARAMETER(hdcMonitor);
return true;
}

void GetMonitors(vector<MonitorInfo> &monitors)
{
monitors.clear();
EnumDisplayMonitors(NULL, NULL, OBSMonitorEnumProc, (LPARAM)&monitors);
}

bool InitApplicationBundle()
{
return true;
Expand Down
63 changes: 3 additions & 60 deletions UI/platform-x11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,12 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/

/* Here we use xinerama to fetch data about monitor geometry
* Even if there are not multiple monitors, this should still work.
*/

#include <obs-config.h>
#include "obs-app.hpp"

#include <xcb/xcb.h>
#include <xcb/xinerama.h>
#include <xcb/randr.h>
#include <QGuiApplication>
#include <QScreen>

#include <unistd.h>
#include <sstream>
#include <locale.h>
Expand Down Expand Up @@ -63,59 +59,6 @@ bool GetDataFilePath(const char *data, string &output)
return false;
}

void GetMonitors(vector<MonitorInfo> &monitors)
{
xcb_connection_t* xcb_conn;

monitors.clear();
xcb_conn = xcb_connect(NULL, NULL);

bool use_xinerama = false;
if (xcb_get_extension_data(xcb_conn, &xcb_xinerama_id)->present) {
xcb_xinerama_is_active_cookie_t xinerama_cookie;
xcb_xinerama_is_active_reply_t* xinerama_reply = NULL;

xinerama_cookie = xcb_xinerama_is_active(xcb_conn);
xinerama_reply = xcb_xinerama_is_active_reply(xcb_conn,
xinerama_cookie, NULL);

if (xinerama_reply && xinerama_reply->state != 0)
use_xinerama = true;
free(xinerama_reply);
}

if (use_xinerama) {
xcb_xinerama_query_screens_cookie_t screens_cookie;
xcb_xinerama_query_screens_reply_t* screens_reply = NULL;
xcb_xinerama_screen_info_iterator_t iter;

screens_cookie = xcb_xinerama_query_screens(xcb_conn);
screens_reply = xcb_xinerama_query_screens_reply(xcb_conn,
screens_cookie, NULL);
iter = xcb_xinerama_query_screens_screen_info_iterator(
screens_reply);

for(; iter.rem; xcb_xinerama_screen_info_next(&iter)) {
monitors.emplace_back(iter.data->x_org,
iter.data->y_org,
iter.data->width,
iter.data->height);
}
free(screens_reply);
} else {
// no xinerama so fall back to basic x11 calls
xcb_screen_iterator_t iter;

iter = xcb_setup_roots_iterator(xcb_get_setup(xcb_conn));
for(; iter.rem; xcb_screen_next(&iter)) {
monitors.emplace_back(0,0,iter.data->width_in_pixels,
iter.data->height_in_pixels);
}
}

xcb_disconnect(xcb_conn);
}

bool InitApplicationBundle()
{
return true;
Expand Down
11 changes: 0 additions & 11 deletions UI/platform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,8 @@

class QWidget;

struct MonitorInfo {
int32_t x, y;
uint32_t cx, cy;

inline MonitorInfo() {}
inline MonitorInfo(int32_t x, int32_t y, uint32_t cx, uint32_t cy)
: x(x), y(y), cx(cx), cy(cy)
{}
};

/* Gets the path of obs-studio specific data files (such as locale) */
bool GetDataFilePath(const char *data, std::string &path);
void GetMonitors(std::vector<MonitorInfo> &monitors);

/* Updates the working directory for OSX application bundles */
bool InitApplicationBundle();
Expand Down
31 changes: 16 additions & 15 deletions UI/window-basic-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@

#include <time.h>
#include <obs.hpp>
#include <QGuiApplication>
#include <QMessageBox>
#include <QShowEvent>
#include <QDesktopServices>
#include <QFileDialog>
#include <QDesktopWidget>
#include <QRect>
#include <QScreen>

#include <util/dstr.h>
#include <util/util.hpp>
Expand Down Expand Up @@ -780,17 +783,18 @@ static const double scaled_vals[] =

bool OBSBasic::InitBasicConfigDefaults()
{
vector<MonitorInfo> monitors;
GetMonitors(monitors);
QList<QScreen*> screens = QGuiApplication::screens();

if (!monitors.size()) {
if (!screens.size()) {
OBSErrorBox(NULL, "There appears to be no monitors. Er, this "
"technically shouldn't be possible.");
return false;
}

uint32_t cx = monitors[0].cx;
uint32_t cy = monitors[0].cy;
QScreen *primaryScreen = QGuiApplication::primaryScreen();

uint32_t cx = primaryScreen->size().width();
uint32_t cy = primaryScreen->size().height();

/* ----------------------------------------------------- */
/* move over mixer values in advanced if older config */
Expand Down Expand Up @@ -2768,19 +2772,16 @@ static void AddProjectorMenuMonitors(QMenu *parent, QObject *target,
const char *slot)
{
QAction *action;
std::vector<MonitorInfo> monitors;
GetMonitors(monitors);

for (int i = 0; (size_t)i < monitors.size(); i++) {
const MonitorInfo &monitor = monitors[i];

QList<QScreen*> screens = QGuiApplication::screens();
for (int i = 0; i < screens.size(); i++) {
QRect screenGeometry = screens[i]->availableGeometry();
QString str = QString("%1 %2: %3x%4 @ %5,%6").
arg(QTStr("Display"),
QString::number(i),
QString::number((int)monitor.cx),
QString::number((int)monitor.cy),
QString::number((int)monitor.x),
QString::number((int)monitor.y));
QString::number((int)screenGeometry.width()),
QString::number((int)screenGeometry.height()),
QString::number((int)screenGeometry.x()),
QString::number((int)screenGeometry.y()));

action = parent->addAction(str, target, slot);
action->setProperty("monitor", i);
Expand Down
12 changes: 5 additions & 7 deletions UI/window-basic-settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
#include <initializer_list>
#include <sstream>
#include <QCompleter>
#include <QGuiApplication>
#include <QLineEdit>
#include <QMessageBox>
#include <QCloseEvent>
#include <QFileDialog>
#include <QDirIterator>
#include <QVariant>
#include <QTreeView>
#include <QScreen>
#include <QStandardItemModel>
#include <QSpacerItem>

Expand Down Expand Up @@ -950,8 +952,6 @@ void OBSBasicSettings::LoadRendererList()
#endif
}

Q_DECLARE_METATYPE(MonitorInfo);

static string ResString(uint32_t cx, uint32_t cy)
{
stringstream res;
Expand Down Expand Up @@ -1097,14 +1097,12 @@ void OBSBasicSettings::LoadResolutionLists()
uint32_t cy = config_get_uint(main->Config(), "Video", "BaseCY");
uint32_t out_cx = config_get_uint(main->Config(), "Video", "OutputCX");
uint32_t out_cy = config_get_uint(main->Config(), "Video", "OutputCY");
vector<MonitorInfo> monitors;

ui->baseResolution->clear();

GetMonitors(monitors);

for (MonitorInfo &monitor : monitors) {
string res = ResString(monitor.cx, monitor.cy);
for (QScreen* screen: QGuiApplication::screens()) {
QSize as = screen->availableSize();
string res = ResString(as.width(), as.height());
ui->baseResolution->addItem(res.c_str());
}

Expand Down
9 changes: 4 additions & 5 deletions UI/window-projector.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <QAction>
#include <QGuiApplication>
#include <QMouseEvent>
#include <QMenu>
#include <QScreen>
#include "window-projector.hpp"
#include "display-helpers.hpp"
#include "qt-wrappers.hpp"
Expand Down Expand Up @@ -47,11 +49,8 @@ OBSProjector::~OBSProjector()

void OBSProjector::Init(int monitor)
{
std::vector<MonitorInfo> monitors;
GetMonitors(monitors);
MonitorInfo &mi = monitors[monitor];

setGeometry(mi.x, mi.y, mi.cx, mi.cy);
QScreen *screen = QGuiApplication::screens()[monitor];
setGeometry(screen->availableGeometry());

bool alwaysOnTop = config_get_bool(GetGlobalConfig(),
"BasicWindow", "ProjectorAlwaysOnTop");
Expand Down

0 comments on commit f816377

Please sign in to comment.