Skip to content

Commit

Permalink
Fix screenshots
Browse files Browse the repository at this point in the history
  • Loading branch information
Eeems committed Feb 2, 2024
1 parent a12f708 commit 2a8bdeb
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
7 changes: 4 additions & 3 deletions applications/system-service/apibase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ int APIBase::getSenderPgid() { return getpgid(getSenderPid()); }

QImage* getFrameBuffer(){
static QImage* image = nullptr;
static QFile* file = nullptr;
if(image == nullptr){
auto compositor = getCompositorDBus();
auto reply = compositor->frameBuffer();
Expand All @@ -49,9 +50,9 @@ QImage* getFrameBuffer(){
O_WARNING("Framebuffer fd is not valid");
return nullptr;
}
QFile file;
file.open(dup(qfd.fileDescriptor()), QFile::ReadOnly);
auto data = file.map(0, file.size());
file = new QFile();
file->open(dup(qfd.fileDescriptor()), QFile::ReadOnly);
uchar* data = file->map(0, file->size());
image = new QImage(data, 1404, 1872, 2808, QImage::Format_RGB16);
}
return image;
Expand Down
3 changes: 1 addition & 2 deletions applications/system-service/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@ int main(int argc, char* argv[]){

Blight::shared_buf_t buffer = createBuffer();
if(buffer != nullptr){
auto frameBuffer = getFrameBuffer();
auto size = frameBuffer->size();
auto size = getFrameBuffer()->size();
int splashWidth = size.width() / 2;
QSize splashSize(splashWidth, splashWidth);
QRect splashRect(QPoint(
Expand Down
11 changes: 5 additions & 6 deletions applications/system-service/screenapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@ QDBusObjectPath ScreenAPI::screenshot(){
""
);
notification->display();
QImage screen = copy();
auto screen = getFrameBuffer();
bool saved = false;
QDBusObjectPath path("/");
if(screen.size().isEmpty()){
if(screen->size().isEmpty()){
O_WARNING("Could not get copy of screen");
}else{
if(systemAPI->landscape()){
screen = screen.transformed(QTransform().rotate(270.0));
saved = screen->transformed(QTransform().rotate(270.0)).save(filePath);
}else{
saved = screen->save(filePath);
}
saved = screen.save(filePath);
if(saved){
path = addScreenshot(filePath)->qPath();
}else if(!saved){
Expand All @@ -47,8 +48,6 @@ QDBusObjectPath ScreenAPI::screenshot(){
return path;
}

QImage ScreenAPI::copy(){ return getFrameBuffer()->copy(); }

QDBusObjectPath ScreenAPI::addScreenshot(QByteArray blob){
if(!hasPermission("screen")){
return QDBusObjectPath("/");
Expand Down
1 change: 0 additions & 1 deletion applications/system-service/screenapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class ScreenAPI : public APIBase {
bool enabled();
QList<QDBusObjectPath> screenshots();
Q_INVOKABLE QDBusObjectPath screenshot();
QImage copy();

public slots:
QDBusObjectPath addScreenshot(QByteArray blob);
Expand Down

0 comments on commit 2a8bdeb

Please sign in to comment.