Skip to content

Commit

Permalink
rebased on current OSG 3.7.0, support OSG_WINDOWING_SYSTEM environmen…
Browse files Browse the repository at this point in the history
…t variable to select specific system, default to working windowing system, update to wl_output v4 protocol for current sway/weston
  • Loading branch information
phlash committed Oct 15, 2023
1 parent 36b4e17 commit f5ad546
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
30 changes: 23 additions & 7 deletions src/osg/GraphicsContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,28 +75,44 @@ GraphicsContext::WindowingSystemInterface* GraphicsContext::WindowingSystemInter
OSG_WARN<<"Warning: GraphicsContext::WindowingSystemInterfaces::getWindowingSystemInterface() failed, no interfaces available."<<std::endl;
return 0;
}
std::string search = name;
if (getenv("OSG_WINDOWING_SYSTEM") != NULL)
{
search = getenv("OSG_WINDOWING_SYSTEM");
}

if (!name.empty())
if (!search.empty())
{
for(Interfaces::iterator itr = _interfaces.begin();
itr != _interfaces.end();
++itr)
{
if ((*itr)->getName()==name)
if ((*itr)->getName()==search)
{
OSG_INFO<<"found WindowingSystemInterface : "<<search<<std::endl;
return itr->get();
}

OSG_NOTICE<<" tried interface "<<typeid(*itr).name()<<", name= "<<(*itr)->getName()<<std::endl;
}

OSG_WARN<<"Warning: GraphicsContext::WindowingSystemInterfaces::getWindowingSystemInterface() failed, no interfaces matches name : "<<name<<std::endl;
OSG_WARN<<"Warning: GraphicsContext::WindowingSystemInterfaces::getWindowingSystemInterface() failed, no interfaces matches name : "<<search<<std::endl;
return 0;
}
else
{
// no preference provided so just take the first available interface
return _interfaces.front().get();
// no preference provided so just take the first available interface that works
for (Interfaces::iterator itr = _interfaces.begin();
itr != _interfaces.end();
++itr)
{
if ((*itr)->getNumScreens() > 0)
{
OSG_INFO<<"using default WindowingSystemInterface : "<<(*itr)->getName()<<std::endl;
return itr->get();
}
}

OSG_WARN<<"Warning: GraphicsContext::WindowingSystemInterfaces::getWindowingSystemInterface() failed, no working interfaces"<<std::endl;
return 0;
}
}

Expand Down
14 changes: 13 additions & 1 deletion src/osgViewer/GraphicsWindowWayland.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,16 @@ class WLWindowingSystemInterface : public osg::GraphicsContext::WindowingSystemI
WLGWlog(0) << "<output(" << o << ") scale: " << factor << ">" << std::endl;
}
static void output_done(void *data, wl_output *wl_output) {}
static void output_name(void *data, wl_output *wl_output, const char *name) {
WLWindowingSystemInterface* obj = (WLWindowingSystemInterface*) data;
int o = obj->find_output(wl_output);
WLGWlog(0) << "<output(" << o << ") name: " << name << ">" << std::endl;
}
static void output_desc(void *data, wl_output *wl_output, const char *desc) {
WLWindowingSystemInterface* obj = (WLWindowingSystemInterface*) data;
int o = obj->find_output(wl_output);
WLGWlog(0) << "<output(" << o << ") desc: " << desc << ">" << std::endl;
}
// Input handling
WLGraphicsWindow* get_window(struct wl_surface* surface) {
if (surface) {
Expand Down Expand Up @@ -733,7 +743,7 @@ class WLWindowingSystemInterface : public osg::GraphicsContext::WindowingSystemI
wl_registry_add_listener(_gc.registry, &_wl_registry_listener, this);
wl_display_roundtrip(_gc.display);
// ensure we got all required shared objects
if (!_gc.compositor || !_gc.shm || !_gc.output || !_gc.xdg_wm_base || !_gc.zxdg_decoration_manager_v1) {
if (!_gc.compositor || !_gc.shm || _gc.n_outputs < 1 || !_gc.xdg_wm_base || !_gc.zxdg_decoration_manager_v1) {
WLGWlog(0) << "WLwsi::checkInit: missing one of compositor/shm/output/xdg_wm_base/zxdg_decoration_manager_v1" << std::endl;
break;
}
Expand Down Expand Up @@ -776,6 +786,8 @@ class WLWindowingSystemInterface : public osg::GraphicsContext::WindowingSystemI
_wl_output_listener.mode = output_mode;
_wl_output_listener.scale = output_scale;
_wl_output_listener.done = output_done;
_wl_output_listener.name = output_name;
_wl_output_listener.description = output_desc;
for (size_t o=0; o<_gc.n_outputs; o++)
wl_output_add_listener(_gc.output[o], &_wl_output_listener, this);
// attach ping responder
Expand Down

0 comments on commit f5ad546

Please sign in to comment.