hyprcursor/tests/full_rendering.cpp

76 lines
1.9 KiB
C++
Raw Normal View History

2024-04-06 22:15:43 +02:00
/*
full_rendering.cpp
This example shows probably what you want to do.
Hyprcursor will render a left_ptr shape at 48x48px to a file called /tmp/arrow.png
*/
2024-03-07 04:19:38 +01:00
#include <iostream>
2024-03-07 17:36:26 +01:00
#include <hyprcursor/hyprcursor.hpp>
2024-03-07 04:19:38 +01:00
2024-03-24 21:37:31 +01:00
void logFunction(enum eHyprcursorLogLevel level, char* message) {
std::cout << "[hc] " << message << "\n";
}
2024-03-07 04:19:38 +01:00
int main(int argc, char** argv) {
2024-04-06 22:15:43 +02:00
/*
Create a manager. You can optionally pass a logger function.
*/
Hyprcursor::CHyprcursorManager mgr(nullptr, logFunction);
2024-03-07 04:19:38 +01:00
2024-04-06 22:15:43 +02:00
/*
Manager could be invalid if no themes were found, or
a specified theme was invalid.
*/
if (!mgr.valid()) {
std::cout << "mgr is invalid\n";
return 1;
}
2024-03-11 22:06:13 +01:00
2024-04-06 22:15:43 +02:00
/*
Style describes what pixel size you want your cursor
images to be.
2024-04-05 17:49:17 +02:00
2024-04-06 22:15:43 +02:00
Remember to free styles once you're done with them
(e.g. the user requested to change the cursor size to something else)
*/
Hyprcursor::SCursorStyleInfo style{.size = 48};
2024-03-11 22:06:13 +01:00
if (!mgr.loadThemeStyle(style)) {
2024-03-07 15:50:48 +01:00
std::cout << "failed loading style\n";
return 1;
}
2024-04-06 22:15:43 +02:00
/*
Get a shape. This will return the data about available image(s),
their delay, hotspot, etc.
*/
2024-03-11 22:06:13 +01:00
const auto SHAPEDATA = mgr.getShape("left_ptr", style);
2024-03-07 17:01:45 +01:00
2024-04-06 22:15:43 +02:00
/*
If the size doesn't exist, images will be empty.
*/
2024-03-07 17:21:04 +01:00
if (SHAPEDATA.images.empty()) {
std::cout << "no images\n";
2024-03-07 17:01:45 +01:00
return 1;
2024-03-07 17:21:04 +01:00
}
std::cout << "hyprcursor returned " << SHAPEDATA.images.size() << " images\n";
2024-03-07 04:19:38 +01:00
2024-04-06 22:15:43 +02:00
/*
Save to disk with cairo
*/
2024-03-07 17:01:45 +01:00
const auto RET = cairo_surface_write_to_png(SHAPEDATA.images[0].surface, "/tmp/arrow.png");
2024-03-07 04:19:38 +01:00
std::cout << "Cairo returned for write: " << RET << "\n";
2024-04-06 22:15:43 +02:00
/*
As mentioned before, clean up by releasing the style.
*/
2024-03-11 22:06:13 +01:00
mgr.cursorSurfaceStyleDone(style);
2024-03-07 16:10:45 +01:00
if (RET)
return 1;
2024-03-07 04:19:38 +01:00
return !mgr.valid();
}