fixup! Add display server.
This commit is contained in:
parent
b2585414a0
commit
63260a916e
|
@ -17,11 +17,14 @@
|
|||
* Interactive utility functions.
|
||||
*/
|
||||
|
||||
#include <sys/display.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/termmode.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
@ -262,6 +265,36 @@ bool missing_program(const char* program)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool get_video_mode(struct dispmsg_crtc_mode* mode)
|
||||
{
|
||||
struct tiocgdisplay display;
|
||||
struct tiocgdisplays gdisplays;
|
||||
memset(&gdisplays, 0, sizeof(gdisplays));
|
||||
gdisplays.count = 1;
|
||||
gdisplays.displays = &display;
|
||||
struct dispmsg_get_driver_name dgdn = { 0 };
|
||||
if ( ioctl(1, TIOCGDISPLAYS, &gdisplays) < 0 || gdisplays.count == 0 )
|
||||
return false;
|
||||
dgdn.device = display.device;
|
||||
dgdn.msgid = DISPMSG_GET_DRIVER_NAME;
|
||||
dgdn.device = display.device;
|
||||
dgdn.driver_index = 0;
|
||||
dgdn.name.byte_size = 0;
|
||||
dgdn.name.str = NULL;
|
||||
if ( dispmsg_issue(&dgdn, sizeof(dgdn)) < 0 && errno == ENODEV )
|
||||
return false;
|
||||
struct dispmsg_get_crtc_mode get_mode;
|
||||
memset(&get_mode, 0, sizeof(get_mode));
|
||||
get_mode.msgid = DISPMSG_GET_CRTC_MODE;
|
||||
get_mode.device = display.device;
|
||||
get_mode.connector = display.connector;
|
||||
// TODO: Still allow setting the video mode if none was already set.
|
||||
if ( dispmsg_issue(&get_mode, sizeof(get_mode)) < 0 )
|
||||
return false;
|
||||
*mode = get_mode.mode;
|
||||
return true;
|
||||
}
|
||||
|
||||
void gui_shutdown(int code)
|
||||
{
|
||||
if ( getenv("DISPLAY_SOCKET") )
|
||||
|
|
|
@ -42,6 +42,7 @@ void password(char* buffer,
|
|||
size_t buffer_size,
|
||||
const char* question);
|
||||
bool missing_program(const char* program);
|
||||
bool get_video_mode(struct dispmsg_crtc_mode* mode);
|
||||
void gui_shutdown(int code);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -623,38 +623,16 @@ int main(void)
|
|||
text("\n");
|
||||
}
|
||||
|
||||
struct tiocgdisplay display;
|
||||
struct tiocgdisplays gdisplays;
|
||||
memset(&gdisplays, 0, sizeof(gdisplays));
|
||||
gdisplays.count = 1;
|
||||
gdisplays.displays = &display;
|
||||
struct dispmsg_get_driver_name dgdn = { 0 };
|
||||
dgdn.msgid = DISPMSG_GET_DRIVER_NAME;
|
||||
dgdn.device = 0;
|
||||
dgdn.driver_index = 0;
|
||||
dgdn.name.byte_size = 0;
|
||||
dgdn.name.str = NULL;
|
||||
if ( ioctl(1, TIOCGDISPLAYS, &gdisplays) == 0 &&
|
||||
0 < gdisplays.count &&
|
||||
(dgdn.device = display.device, true) &&
|
||||
(dispmsg_issue(&dgdn, sizeof(dgdn)) == 0 || errno != ENODEV) )
|
||||
struct dispmsg_crtc_mode mode;
|
||||
if ( get_video_mode(&mode) )
|
||||
{
|
||||
struct dispmsg_get_crtc_mode get_mode;
|
||||
memset(&get_mode, 0, sizeof(get_mode));
|
||||
get_mode.msgid = DISPMSG_GET_CRTC_MODE;
|
||||
get_mode.device = 0;
|
||||
get_mode.connector = 0;
|
||||
bool good = false;
|
||||
if ( dispmsg_issue(&get_mode, sizeof(get_mode)) == 0 )
|
||||
bool good = (mode.control & DISPMSG_CONTROL_VALID) &&
|
||||
(mode.control & DISPMSG_CONTROL_GOOD_DEFAULT);
|
||||
if ( mode.control & DISPMSG_CONTROL_VM_AUTO_SCALE )
|
||||
{
|
||||
good = (get_mode.mode.control & DISPMSG_CONTROL_VALID) &&
|
||||
(get_mode.mode.control & DISPMSG_CONTROL_GOOD_DEFAULT);
|
||||
if ( get_mode.mode.control & DISPMSG_CONTROL_VM_AUTO_SCALE )
|
||||
{
|
||||
text("The display resolution will automatically change to "
|
||||
"match the size of the virtual machine window.\n\n");
|
||||
good = true;
|
||||
}
|
||||
text("The display resolution will automatically change to "
|
||||
"match the size of the virtual machine window.\n\n");
|
||||
good = true;
|
||||
}
|
||||
const char* def = non_interactive || good ? "no" : "yes";
|
||||
while ( true )
|
||||
|
@ -673,14 +651,12 @@ int main(void)
|
|||
if ( execute((const char*[]) { "chvideomode", r, NULL }, "f") != 0 )
|
||||
continue;
|
||||
input[0] = '\0';
|
||||
if ( dispmsg_issue(&get_mode, sizeof(get_mode)) < 0 ||
|
||||
!(get_mode.mode.control & DISPMSG_CONTROL_VALID) ||
|
||||
get_mode.mode.control & DISPMSG_CONTROL_VGA )
|
||||
break;
|
||||
if ( !get_video_mode(&mode) ||
|
||||
!(mode.control & DISPMSG_CONTROL_VALID) ||
|
||||
mode.control & DISPMSG_CONTROL_VGA )
|
||||
continue;
|
||||
snprintf(input, sizeof(input), "%ux%ux%u",
|
||||
get_mode.mode.view_xres,
|
||||
get_mode.mode.view_yres,
|
||||
get_mode.mode.fb_format);
|
||||
mode.view_xres, mode.view_yres, mode.fb_format);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -509,38 +509,16 @@ int main(void)
|
|||
if ( kblayout_setable )
|
||||
text("\n");
|
||||
|
||||
struct tiocgdisplay display;
|
||||
struct tiocgdisplays gdisplays;
|
||||
memset(&gdisplays, 0, sizeof(gdisplays));
|
||||
gdisplays.count = 1;
|
||||
gdisplays.displays = &display;
|
||||
struct dispmsg_get_driver_name dgdn = { 0 };
|
||||
dgdn.msgid = DISPMSG_GET_DRIVER_NAME;
|
||||
dgdn.device = 0;
|
||||
dgdn.driver_index = 0;
|
||||
dgdn.name.byte_size = 0;
|
||||
dgdn.name.str = NULL;
|
||||
if ( ioctl(1, TIOCGDISPLAYS, &gdisplays) == 0 &&
|
||||
0 < gdisplays.count &&
|
||||
(dgdn.device = display.device, true) &&
|
||||
(dispmsg_issue(&dgdn, sizeof(dgdn)) == 0 || errno != ENODEV) )
|
||||
struct dispmsg_crtc_mode mode;
|
||||
if ( get_video_mode(&mode) )
|
||||
{
|
||||
struct dispmsg_get_crtc_mode get_mode;
|
||||
memset(&get_mode, 0, sizeof(get_mode));
|
||||
get_mode.msgid = DISPMSG_GET_CRTC_MODE;
|
||||
get_mode.device = 0;
|
||||
get_mode.connector = 0;
|
||||
bool good = false;
|
||||
if ( dispmsg_issue(&get_mode, sizeof(get_mode)) == 0 )
|
||||
bool good = (mode.control & DISPMSG_CONTROL_VALID) &&
|
||||
(mode.control & DISPMSG_CONTROL_GOOD_DEFAULT);
|
||||
if ( mode.control & DISPMSG_CONTROL_VM_AUTO_SCALE )
|
||||
{
|
||||
good = (get_mode.mode.control & DISPMSG_CONTROL_VALID) &&
|
||||
(get_mode.mode.control & DISPMSG_CONTROL_GOOD_DEFAULT);
|
||||
if ( get_mode.mode.control & DISPMSG_CONTROL_VM_AUTO_SCALE )
|
||||
{
|
||||
text("The display resolution will automatically change to "
|
||||
"match the size of the virtual machine window.\n\n");
|
||||
good = true;
|
||||
}
|
||||
text("The display resolution will automatically change to "
|
||||
"match the size of the virtual machine window.\n\n");
|
||||
good = true;
|
||||
}
|
||||
const char* def = non_interactive || good ? "no" : "yes";
|
||||
while ( true )
|
||||
|
|
Loading…
Reference in New Issue