| 1 | /** |
| 2 | * Copyright © 2011 Red Hat, Inc. |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 21 | * DEALINGS IN THE SOFTWARE. |
| 22 | */ |
| 23 | |
| 24 | #ifdef HAVE_DIX_CONFIG_H |
| 25 | #include <dix-config.h> |
| 26 | #endif |
| 27 | |
| 28 | #include <stdint.h> |
| 29 | #include "misc.h" |
| 30 | #include "scrnintstr.h" |
| 31 | |
| 32 | ScreenInfo screenInfo; |
| 33 | |
| 34 | static void |
| 35 | dix_version_compare(void) |
| 36 | { |
| 37 | int rc; |
| 38 | |
| 39 | rc = version_compare(0, 0, 1, 0); |
| 40 | assert(rc < 0); |
| 41 | rc = version_compare(1, 0, 0, 0); |
| 42 | assert(rc > 0); |
| 43 | rc = version_compare(0, 0, 0, 0); |
| 44 | assert(rc == 0); |
| 45 | rc = version_compare(1, 0, 1, 0); |
| 46 | assert(rc == 0); |
| 47 | rc = version_compare(1, 0, 0, 9); |
| 48 | assert(rc > 0); |
| 49 | rc = version_compare(0, 9, 1, 0); |
| 50 | assert(rc < 0); |
| 51 | rc = version_compare(1, 0, 1, 9); |
| 52 | assert(rc < 0); |
| 53 | rc = version_compare(1, 9, 1, 0); |
| 54 | assert(rc > 0); |
| 55 | rc = version_compare(2, 0, 1, 9); |
| 56 | assert(rc > 0); |
| 57 | rc = version_compare(1, 9, 2, 0); |
| 58 | assert(rc < 0); |
| 59 | } |
| 60 | |
| 61 | static void |
| 62 | dix_update_desktop_dimensions(void) |
| 63 | { |
| 64 | int i; |
| 65 | int x, y, w, h; |
| 66 | int w2, h2; |
| 67 | ScreenRec screens[MAXSCREENS]; |
| 68 | |
| 69 | for (i = 0; i < MAXSCREENS; i++) |
| 70 | screenInfo.screens[i] = &screens[i]; |
| 71 | |
| 72 | x = 0; |
| 73 | y = 0; |
| 74 | w = 10; |
| 75 | h = 5; |
| 76 | w2 = 35; |
| 77 | h2 = 25; |
| 78 | |
| 79 | #define assert_dimensions(_x, _y, _w, _h) \ |
| 80 | update_desktop_dimensions(); \ |
| 81 | assert(screenInfo.x == _x); \ |
| 82 | assert(screenInfo.y == _y); \ |
| 83 | assert(screenInfo.width == _w); \ |
| 84 | assert(screenInfo.height == _h); |
| 85 | |
| 86 | #define set_screen(idx, _x, _y, _w, _h) \ |
| 87 | screenInfo.screens[idx]->x = _x; \ |
| 88 | screenInfo.screens[idx]->y = _y; \ |
| 89 | screenInfo.screens[idx]->width = _w; \ |
| 90 | screenInfo.screens[idx]->height = _h; \ |
| 91 | |
| 92 | /* single screen */ |
| 93 | screenInfo.numScreens = 1; |
| 94 | set_screen(0, x, y, w, h); |
| 95 | assert_dimensions(x, y, w, h); |
| 96 | |
| 97 | /* dualhead rightof */ |
| 98 | screenInfo.numScreens = 2; |
| 99 | set_screen(1, w, 0, w2, h2); |
| 100 | assert_dimensions(x, y, w + w2, h2); |
| 101 | |
| 102 | /* dualhead belowof */ |
| 103 | screenInfo.numScreens = 2; |
| 104 | set_screen(1, 0, h, w2, h2); |
| 105 | assert_dimensions(x, y, w2, h + h2); |
| 106 | |
| 107 | /* triplehead L shape */ |
| 108 | screenInfo.numScreens = 3; |
| 109 | set_screen(1, 0, h, w2, h2); |
| 110 | set_screen(2, w2, h2, w, h); |
| 111 | assert_dimensions(x, y, w + w2, h + h2); |
| 112 | |
| 113 | /* quadhead 2x2 */ |
| 114 | screenInfo.numScreens = 4; |
| 115 | set_screen(1, 0, h, w, h); |
| 116 | set_screen(2, w, h, w, h2); |
| 117 | set_screen(3, w, 0, w2, h); |
| 118 | assert_dimensions(x, y, w + w2, h + h2); |
| 119 | |
| 120 | /* quadhead horiz line */ |
| 121 | screenInfo.numScreens = 4; |
| 122 | set_screen(1, w, 0, w, h); |
| 123 | set_screen(2, 2 * w, 0, w, h); |
| 124 | set_screen(3, 3 * w, 0, w, h); |
| 125 | assert_dimensions(x, y, 4 * w, h); |
| 126 | |
| 127 | /* quadhead vert line */ |
| 128 | screenInfo.numScreens = 4; |
| 129 | set_screen(1, 0, h, w, h); |
| 130 | set_screen(2, 0, 2 * h, w, h); |
| 131 | set_screen(3, 0, 3 * h, w, h); |
| 132 | assert_dimensions(x, y, w, 4 * h); |
| 133 | |
| 134 | /* x overlap */ |
| 135 | screenInfo.numScreens = 2; |
| 136 | set_screen(0, 0, 0, w2, h2); |
| 137 | set_screen(1, w, 0, w2, h2); |
| 138 | assert_dimensions(x, y, w2 + w, h2); |
| 139 | |
| 140 | /* y overlap */ |
| 141 | screenInfo.numScreens = 2; |
| 142 | set_screen(0, 0, 0, w2, h2); |
| 143 | set_screen(1, 0, h, w2, h2); |
| 144 | assert_dimensions(x, y, w2, h2 + h); |
| 145 | |
| 146 | /* negative origin */ |
| 147 | screenInfo.numScreens = 1; |
| 148 | set_screen(0, -w2, -h2, w, h); |
| 149 | assert_dimensions(-w2, -h2, w, h); |
| 150 | |
| 151 | /* dualhead negative origin, overlap */ |
| 152 | screenInfo.numScreens = 2; |
| 153 | set_screen(0, -w2, -h2, w2, h2); |
| 154 | set_screen(1, -w, -h, w, h); |
| 155 | assert_dimensions(-w2, -h2, w2, h2); |
| 156 | } |
| 157 | |
| 158 | int |
| 159 | main(int argc, char **argv) |
| 160 | { |
| 161 | dix_version_compare(); |
| 162 | dix_update_desktop_dimensions(); |
| 163 | |
| 164 | return 0; |
| 165 | } |