set-resolution.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* vim: tabstop=4 shiftwidth=4 noexpandtab
  2. * This file is part of ToaruOS and is released under the terms
  3. * of the NCSA / University of Illinois License - see LICENSE.md
  4. * Copyright (C) 2018 K. Lange
  5. *
  6. * set-resolution - Change the display resolution.
  7. *
  8. * Simple tool to interface with the IO_VID_SET ioctl.
  9. *
  10. * TODO: This is probably something we should request from the
  11. * compositor rather than a separate application...
  12. */
  13. #include <stdio.h>
  14. #include <unistd.h>
  15. #include <fcntl.h>
  16. #include <stdlib.h>
  17. #include <stdint.h>
  18. #include <string.h>
  19. #include <errno.h>
  20. #include <sys/ioctl.h>
  21. #include <kernel/video.h>
  22. int main(int argc, char * argv[]) {
  23. if (argc < 3) {
  24. fprintf(stderr, "Usage: %s [--initialize DRIVER] WIDTH HEIGHT\n", argv[0]);
  25. return 1;
  26. }
  27. /* Open framebuffer */
  28. int fd = open("/dev/fb0", O_RDONLY);
  29. if (fd < 0) {
  30. perror("open");
  31. return 1;
  32. }
  33. int i = 1;
  34. int init = 0;
  35. char * driver = NULL;
  36. if (argc > 4 && !strcmp(argv[1],"--initialize")) {
  37. init = 1;
  38. driver = argv[2];
  39. i += 2;
  40. }
  41. /* Prepare ioctl from arguments */
  42. struct vid_size s;
  43. s.width = atoi(argv[i]);
  44. s.height = atoi(argv[i+1]);
  45. /* Send ioctl */
  46. if (init) {
  47. char tmp[100];
  48. sprintf(tmp, "%s,%lu,%lu", driver, s.width, s.height);
  49. if (ioctl(fd, IO_VID_REINIT, tmp) < 0) {
  50. perror("ioctl");
  51. return 1;
  52. }
  53. } else {
  54. if (ioctl(fd, IO_VID_SET, &s) < 0) {
  55. perror("ioctl");
  56. return 1;
  57. }
  58. }
  59. return 0;
  60. }