summaryrefslogtreecommitdiff
path: root/src/resolution.c
blob: ae2136f3c83def36f311960ddc8c542eb6cc818f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "resolution.h"
#include "common.h"

#include <stdio.h>
#include <string.h>

const char *display_resolution() {
  const char *isexist = run_command_s("which xrandr");
  if (
      isexist == NULL ||
      strlen(isexist) == 0 ||
      strncmp(isexist, "xrandr not found", strlen("xrandr not found")) == 0
  ) return NULL;

  return run_command_s("xrandr --nograb --current | "
                       "awk -F 'connected |\\\\+|\\\\(' '/ "
                       "connected.*[0-9]+x[0-9]+\\+/ && $2 {printf $2 "
                       "\", \"}' | sed 's/primary //' | "
                       "sed 's/,\\([^,]*\\)$/\\1/'");
}