mirror of
https://github.com/Almamu/linux-wallpaperengine.git
synced 2025-09-14 13:56:48 +08:00
Moved display, pm, and gc to class members.
This commit is contained in:
parent
caf79766dc
commit
2d12903185
@ -25,19 +25,19 @@ void CContext::initializeViewports ()
|
|||||||
if (this->m_isRootWindow == false || this->m_screens.empty () == true)
|
if (this->m_isRootWindow == false || this->m_screens.empty () == true)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Display* display = XOpenDisplay (nullptr);
|
m_display = XOpenDisplay (nullptr);
|
||||||
|
|
||||||
int xrandr_result, xrandr_error;
|
int xrandr_result, xrandr_error;
|
||||||
|
|
||||||
if (!XRRQueryExtension (display, &xrandr_result, &xrandr_error))
|
if (!XRRQueryExtension (m_display, &xrandr_result, &xrandr_error))
|
||||||
{
|
{
|
||||||
std::cerr << "XRandr is not present, cannot detect specified screens, running in window mode" << std::endl;
|
std::cerr << "XRandr is not present, cannot detect specified screens, running in window mode" << std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fullWidth = DisplayWidth (display, DefaultScreen (display));
|
int fullWidth = DisplayWidth (m_display, DefaultScreen (m_display));
|
||||||
int fullHeight = DisplayHeight (display, DefaultScreen (display));
|
int fullHeight = DisplayHeight (m_display, DefaultScreen (m_display));
|
||||||
XRRScreenResources* screenResources = XRRGetScreenResources (display, DefaultRootWindow (display));
|
XRRScreenResources* screenResources = XRRGetScreenResources (m_display, DefaultRootWindow (m_display));
|
||||||
|
|
||||||
// there are some situations where xrandr returns null (like screen not using the extension)
|
// there are some situations where xrandr returns null (like screen not using the extension)
|
||||||
if (screenResources == nullptr)
|
if (screenResources == nullptr)
|
||||||
@ -45,7 +45,7 @@ void CContext::initializeViewports ()
|
|||||||
|
|
||||||
for (int i = 0; i < screenResources->noutput; i ++)
|
for (int i = 0; i < screenResources->noutput; i ++)
|
||||||
{
|
{
|
||||||
XRROutputInfo* info = XRRGetOutputInfo (display, screenResources, screenResources->outputs [i]);
|
XRROutputInfo* info = XRRGetOutputInfo (m_display, screenResources, screenResources->outputs [i]);
|
||||||
|
|
||||||
// there are some situations where xrandr returns null (like screen not using the extension)
|
// there are some situations where xrandr returns null (like screen not using the extension)
|
||||||
if (info == nullptr)
|
if (info == nullptr)
|
||||||
@ -58,7 +58,7 @@ void CContext::initializeViewports ()
|
|||||||
{
|
{
|
||||||
if (info->connection == RR_Connected && strcmp (info->name, (*cur).c_str ()) == 0)
|
if (info->connection == RR_Connected && strcmp (info->name, (*cur).c_str ()) == 0)
|
||||||
{
|
{
|
||||||
XRRCrtcInfo* crtc = XRRGetCrtcInfo (display, screenResources, info->crtc);
|
XRRCrtcInfo* crtc = XRRGetCrtcInfo (m_display, screenResources, info->crtc);
|
||||||
|
|
||||||
std::cout << "Found requested screen: " << info->name << " -> " << crtc->x << "x" << crtc->y << ":" << crtc->width << "x" << crtc->height << std::endl;
|
std::cout << "Found requested screen: " << info->name << " -> " << crtc->x << "x" << crtc->y << ":" << crtc->width << "x" << crtc->height << std::endl;
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ void CContext::initializeViewports ()
|
|||||||
XRRFreeScreenResources (screenResources);
|
XRRFreeScreenResources (screenResources);
|
||||||
|
|
||||||
// Cause of issue for issue #59 origial issue
|
// Cause of issue for issue #59 origial issue
|
||||||
// glfwWindowHintPointer (GLFW_NATIVE_PARENT_HANDLE, reinterpret_cast <void*> (DefaultRootWindow (display)));
|
// glfwWindowHintPointer (GLFW_NATIVE_PARENT_HANDLE, reinterpret_cast <void*> (DefaultRootWindow (m_display)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CContext::render ()
|
void CContext::render ()
|
||||||
@ -88,43 +88,40 @@ void CContext::render ()
|
|||||||
|
|
||||||
if (this->m_viewports.empty () == false)
|
if (this->m_viewports.empty () == false)
|
||||||
{
|
{
|
||||||
static Display* display = XOpenDisplay (nullptr);
|
|
||||||
auto cur = this->m_viewports.begin ();
|
auto cur = this->m_viewports.begin ();
|
||||||
auto end = this->m_viewports.end ();
|
auto end = this->m_viewports.end ();
|
||||||
|
|
||||||
Window root = DefaultRootWindow(display);
|
Window root = DefaultRootWindow(m_display);
|
||||||
int windowWidth = 1920, windowHeight = 1080;
|
int windowWidth = 1920, windowHeight = 1080;
|
||||||
int fullWidth = DisplayWidth (display, DefaultScreen (display));
|
int fullWidth = DisplayWidth (m_display, DefaultScreen (m_display));
|
||||||
int fullHeight = DisplayHeight (display, DefaultScreen (display));
|
int fullHeight = DisplayHeight (m_display, DefaultScreen (m_display));
|
||||||
|
|
||||||
Pixmap pm = XCreatePixmap(display, root, fullWidth, fullHeight, 24);
|
m_pm = XCreatePixmap(m_display, root, fullWidth, fullHeight, 24);
|
||||||
GC gc = XCreateGC(display, pm, 0, NULL);
|
m_gc = XCreateGC(m_display, m_pm, 0, NULL);
|
||||||
XFillRectangle(display, pm, gc, 0, 0, fullWidth, fullHeight);
|
XFillRectangle(m_display, m_pm, m_gc, 0, 0, fullWidth, fullHeight);
|
||||||
|
|
||||||
char* image_data;
|
char* image_data;
|
||||||
image_data = new char[windowWidth*windowHeight*4];
|
image_data = new char[windowWidth*windowHeight*4];
|
||||||
|
|
||||||
this->m_wallpaper->render (this->m_defaultViewport, true, image_data);
|
this->m_wallpaper->render (this->m_defaultViewport, true, image_data);
|
||||||
XImage* image = XCreateImage(display, CopyFromParent, 24, ZPixmap, 0, (char *)image_data, windowWidth, windowHeight, 32, 0);
|
XImage* image = XCreateImage(m_display, CopyFromParent, 24, ZPixmap, 0, (char *)image_data, windowWidth, windowHeight, 32, 0);
|
||||||
for (; cur != end; cur ++)
|
for (; cur != end; cur ++)
|
||||||
{
|
{
|
||||||
XPutImage(display, pm, gc, image, 0, 0, (*cur).x, (*cur).y, windowWidth, windowHeight);
|
XPutImage(m_display, m_pm, m_gc, image, 0, 0, (*cur).x, (*cur).y, windowWidth, windowHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
// _XROOTPMAP_ID & ESETROOT_PMAP_ID allow other programs (compositors) to
|
// _XROOTPMAP_ID & ESETROOT_PMAP_ID allow other programs (compositors) to
|
||||||
// edit the background. Without these, other programs will clear the screen.
|
// edit the background. Without these, other programs will clear the screen.
|
||||||
Atom prop_root = XInternAtom(display, "_XROOTPMAP_ID", False);
|
Atom prop_root = XInternAtom(m_display, "_XROOTPMAP_ID", False);
|
||||||
Atom prop_esetroot = XInternAtom(display, "ESETROOT_PMAP_ID", False);
|
Atom prop_esetroot = XInternAtom(m_display, "ESETROOT_PMAP_ID", False);
|
||||||
XChangeProperty(display, root, prop_root, XA_PIXMAP, 32, PropModeReplace, (unsigned char *) &pm, 1);
|
XChangeProperty(m_display, root, prop_root, XA_PIXMAP, 32, PropModeReplace, (unsigned char *) &m_pm, 1);
|
||||||
XChangeProperty(display, root, prop_esetroot, XA_PIXMAP, 32, PropModeReplace, (unsigned char *) &pm, 1);
|
XChangeProperty(m_display, root, prop_esetroot, XA_PIXMAP, 32, PropModeReplace, (unsigned char *) &m_pm, 1);
|
||||||
|
|
||||||
XSetWindowBackgroundPixmap(display, root, pm);
|
XSetWindowBackgroundPixmap(m_display, root, m_pm);
|
||||||
XClearWindow(display, root);
|
XClearWindow(m_display, root);
|
||||||
XFlush(display);
|
XFlush(m_display);
|
||||||
|
|
||||||
XDestroyImage(image);
|
XDestroyImage(image);
|
||||||
XFreePixmap(display, pm);
|
|
||||||
XFreeGC(display, gc);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
this->m_wallpaper->render (this->m_defaultViewport);
|
this->m_wallpaper->render (this->m_defaultViewport);
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <glm/vec4.hpp>
|
#include <glm/vec4.hpp>
|
||||||
|
|
||||||
|
#include <X11/Xlib.h>
|
||||||
|
|
||||||
#include "WallpaperEngine/Input/CMouseInput.h"
|
#include "WallpaperEngine/Input/CMouseInput.h"
|
||||||
#include "CWallpaper.h"
|
#include "CWallpaper.h"
|
||||||
|
|
||||||
@ -30,5 +32,8 @@ namespace WallpaperEngine::Render
|
|||||||
CWallpaper* m_wallpaper;
|
CWallpaper* m_wallpaper;
|
||||||
CMouseInput* m_mouse;
|
CMouseInput* m_mouse;
|
||||||
bool m_isRootWindow;
|
bool m_isRootWindow;
|
||||||
|
Display* m_display;
|
||||||
|
Pixmap m_pm;
|
||||||
|
GC m_gc;
|
||||||
};
|
};
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user