Commit be4a6685 authored by abmyii's avatar abmyii
Browse files

Implement basic rotation/screen orientation logic

parent d73f87f6
Pipeline #522115068 passed with stage
in 2 minutes and 51 seconds
Mouse scroll wheel / touchpad scrolling
Tilde (~) appearing as grave (¬) - keysym -> scancode conversion needs to be fully refactored
Replace hardcoded 1920x1080 for mouse boundaries
......@@ -77,6 +77,7 @@ int maxx, maxy;
bool landscape = false;
bool mirror = false;
float scale_factor;
int orientation;
bool lmb;
bool rmb;
......@@ -356,8 +357,6 @@ struct EGLSetup
// https://github.com/hanzelpeter/dispmanx_vnc/blob/master/main.c
static int keysym2scancode(rfbKeySym key)
{
//printf("keysym: %04X\n", key);
int scancode = 0;
int code = (int) key;
......@@ -506,6 +505,39 @@ static int keysym2scancode(rfbKeySym key)
}
// Rotation logic
int mod(int a, int b)
{ return (a%b+b)%b; }
void rotate(int direction, rfbClientPtr cl) {
orientation += direction;
orientation = mod(orientation, 4); // 4 orientations
bool landscape_cp = landscape;
switch (orientation) {
case 0:
mirror = false;
landscape = false;
break;
case 1:
mirror = false;
landscape = true;
break;
case 2:
mirror = true;
landscape = false;
break;
case 3:
mirror = true;
landscape = true;
break;
}
if (landscape != landscape_cp) { // Landscape mode toggled
std::swap(maxx, maxy);
}
}
// vnc key event function, escape to quit
static void dokey(rfbBool down,rfbKeySym key,rfbClientPtr cl)
{
......@@ -514,8 +546,15 @@ static void dokey(rfbBool down,rfbKeySym key,rfbClientPtr cl)
/* rfbShutdownServer(cl->screen,TRUE); */
/* running = 0; */
/* } */
libevdev_uinput_write_event(uidev, EV_KEY, keysym2scancode(key), down);
libevdev_uinput_write_event(uidev, EV_SYN, SYN_REPORT, 0);
// printf("keysym: %04X\n", key);
if (down && key == 0xFF52) // Ctrl+Super+Up
rotate(1, cl);
else if (down && key == 0xFF54) // Ctrl+Super+Down
rotate(-1, cl);
else
libevdev_uinput_write_event(uidev, EV_KEY, keysym2scancode(key), down);
libevdev_uinput_write_event(uidev, EV_SYN, SYN_REPORT, 0);
}
......@@ -589,13 +628,10 @@ void do_screencast(EGLSetup const& egl_setup,
auto capture_period = std::chrono::duration<double>(1.0/capture_fps);
// vnc server
int bpp=4;
int bpp = 4;
maxx = size.width.as_uint32_t();
maxy = size.height.as_uint32_t();
if (landscape)
std::swap(maxx, maxy);
rfbScreenInfoPtr rfbScreen = rfbGetScreen(NULL,NULL,maxx,maxy,8,3,bpp);
rfbScreen->desktopName = "MIR Screen";
// rfbScreen->frameBuffer = (char*)malloc(maxx*maxy*bpp);
......@@ -613,6 +649,23 @@ void do_screencast(EGLSetup const& egl_setup,
read_pixels(bpp, format, size, frame_data);
if (maxx/maxy != rfbScreen->width/rfbScreen->height) {
printf("Ratios don't match\n");
printf("RFB: %dx%d\n", rfbScreen->width, rfbScreen->height);
printf("Screen: %dx%d\n", size.width, size.height);
std::swap(rfbScreen->width, rfbScreen->height);
printf("RFB: %dx%d\n\n", rfbScreen->width, rfbScreen->height);
{
rfbClientIteratorPtr iterator;
rfbClientPtr cl;
iterator = rfbGetClientIterator(rfbScreen);
while ((cl = rfbClientIteratorNext(iterator)) != NULL)
cl->newFBSizePending = 1;
}
rfbMarkRectAsModified(rfbScreen, 0, 0, rfbScreen->width, rfbScreen->height);
}
auto write_out_future = std::async(
std::launch::async,
[rfbScreen, maxx, maxy] {
......@@ -701,9 +754,6 @@ try
po::value<std::string>(&socket_filename), "mir server socket filename")
("file,f",
po::value<std::string>(&output_filename), "output filename (default is /tmp/mir_screencast_<w>x<h>.<rgba|bgra>")
("landscape", po::value<bool>(&landscape)->zero_tokens(), "landscape mode - note width and height are automatically swapped")
("mirror", po::value<bool>(&mirror)->zero_tokens(),
"mirrored image; use alone for upside-down portrait mode and in combination with --landscape for clockwise landscape")
("size,s",
po::value<std::vector<int>>(&requested_size)->multitoken(),
"screencast size [width height]")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment