Changeset 424cd43 in mainline for uspace/srv/console/gcons.c
- Timestamp:
- 2009-06-03T18:39:12Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8dc12ac
- Parents:
- b0a91acb
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/console/gcons.c
rb0a91acb r424cd43 40 40 #include <string.h> 41 41 #include <align.h> 42 #include <bool.h> 42 43 43 44 #include "console.h" … … 55 56 #define MAIN_COLOR 0xffffff 56 57 57 static int use_gcons = 0; 58 static ipcarg_t xres,yres; 58 static bool use_gcons = false; 59 static ipcarg_t xres; 60 static ipcarg_t yres; 59 61 60 62 enum butstate { … … 78 80 static int animation = -1; 79 81 80 static int active_console = 0; 82 static size_t active_console = 0; 83 84 size_t mouse_x; 85 size_t mouse_y; 86 87 bool btn_pressed; 88 size_t btn_x; 89 size_t btn_y; 81 90 82 91 static void vp_switch(int vp) … … 86 95 87 96 /** Create view port */ 88 static int vp_create(unsigned int x, unsigned int y, unsigned int width, 89 unsigned int height) 97 static int vp_create(size_t x, size_t y, size_t width, size_t height) 90 98 { 91 99 return async_req_2_0(fbphone, FB_VIEWPORT_CREATE, (x << 16) | y, … … 98 106 } 99 107 100 static void set_rgb_color( int fgcolor, int bgcolor)108 static void set_rgb_color(uint32_t fgcolor, uint32_t bgcolor) 101 109 { 102 110 async_msg_2(fbphone, FB_SET_RGB_COLOR, fgcolor, bgcolor); … … 104 112 105 113 /** Transparent putchar */ 106 static void tran_putch( char c, int row, int col)107 { 108 async_msg_3(fbphone, FB_PUTCHAR, c , row, col);114 static void tran_putch(wchar_t ch, size_t col, size_t row) 115 { 116 async_msg_3(fbphone, FB_PUTCHAR, ch, col, row); 109 117 } 110 118 111 119 /** Redraw the button showing state of a given console */ 112 static void redraw_state(int consnum) 113 { 114 char data[5]; 115 int i; 116 enum butstate state = console_state[consnum]; 117 118 vp_switch(cstatus_vp[consnum]); 120 static void redraw_state(size_t index) 121 { 122 vp_switch(cstatus_vp[index]); 123 124 enum butstate state = console_state[index]; 125 119 126 if (ic_pixmaps[state] != -1) 120 async_msg_2(fbphone, FB_VP_DRAW_PIXMAP, cstatus_vp[ consnum],127 async_msg_2(fbphone, FB_VP_DRAW_PIXMAP, cstatus_vp[index], 121 128 ic_pixmaps[state]); 122 129 123 if (state != CONS_DISCONNECTED && state != CONS_KERNEL && 124 state != CONS_DISCONNECTED_SEL) { 125 snprintf(data, 5, "%d", consnum + 1); 126 for (i = 0; data[i]; i++) 127 tran_putch(data[i], 1, 2 + i); 130 if ((state != CONS_DISCONNECTED) && (state != CONS_KERNEL) 131 && (state != CONS_DISCONNECTED_SEL)) { 132 133 char data[5]; 134 snprintf(data, 5, "%u", index + 1); 135 136 size_t i; 137 for (i = 0; data[i] != 0; i++) 138 tran_putch(data[i], 2 + i, 1); 128 139 } 129 140 } 130 141 131 142 /** Notification run on changing console (except kernel console) */ 132 void gcons_change_console(int consnum) 133 { 134 int i; 135 143 void gcons_change_console(size_t index) 144 { 136 145 if (!use_gcons) 137 146 return; 138 147 139 148 if (active_console == KERNEL_CONSOLE) { 149 size_t i; 150 140 151 for (i = 0; i < CONSOLE_COUNT; i++) 141 152 redraw_state(i); 153 142 154 if (animation != -1) 143 155 async_msg_1(fbphone, FB_ANIM_START, animation); … … 147 159 else 148 160 console_state[active_console] = CONS_IDLE; 161 149 162 redraw_state(active_console); 150 163 } 151 active_console = consnum; 152 153 if (console_state[consnum] == CONS_DISCONNECTED) { 154 console_state[consnum] = CONS_DISCONNECTED_SEL; 155 redraw_state(consnum); 156 } else 157 console_state[consnum] = CONS_SELECTED; 158 redraw_state(consnum); 159 164 165 active_console = index; 166 167 if ((console_state[index] == CONS_DISCONNECTED) 168 || (console_state[index] == CONS_DISCONNECTED_SEL)) 169 console_state[index] = CONS_DISCONNECTED_SEL; 170 else 171 console_state[index] = CONS_SELECTED; 172 173 redraw_state(index); 160 174 vp_switch(console_vp); 161 175 } 162 176 163 177 /** Notification function that gets called on new output to virtual console */ 164 void gcons_notify_char( int consnum)178 void gcons_notify_char(size_t index) 165 179 { 166 180 if (!use_gcons) 167 181 return; 168 182 169 if (( consnum == active_console) ||170 (console_state[consnum] == CONS_HAS_DATA))171 return; 172 173 console_state[ consnum] = CONS_HAS_DATA;183 if ((index == active_console) 184 || (console_state[index] == CONS_HAS_DATA)) 185 return; 186 187 console_state[index] = CONS_HAS_DATA; 174 188 175 189 if (active_console == KERNEL_CONSOLE) 176 190 return; 177 191 178 redraw_state(consnum); 179 192 redraw_state(index); 180 193 vp_switch(console_vp); 181 194 } 182 195 183 196 /** Notification function called on service disconnect from console */ 184 void gcons_notify_disconnect( int consnum)197 void gcons_notify_disconnect(size_t index) 185 198 { 186 199 if (!use_gcons) 187 200 return; 188 201 189 if ( active_console == consnum)190 console_state[ consnum] = CONS_DISCONNECTED_SEL;202 if (index == active_console) 203 console_state[index] = CONS_DISCONNECTED_SEL; 191 204 else 192 console_state[ consnum] = CONS_DISCONNECTED;205 console_state[index] = CONS_DISCONNECTED; 193 206 194 207 if (active_console == KERNEL_CONSOLE) 195 208 return; 196 209 197 redraw_state( consnum);210 redraw_state(index); 198 211 vp_switch(console_vp); 199 212 } 200 213 201 214 /** Notification function called on console connect */ 202 void gcons_notify_connect( int consnum)215 void gcons_notify_connect(size_t index) 203 216 { 204 217 if (!use_gcons) 205 218 return; 206 219 207 if ( active_console == consnum)208 console_state[ consnum] = CONS_SELECTED;220 if (index == active_console) 221 console_state[index] = CONS_SELECTED; 209 222 else 210 console_state[ consnum] = CONS_IDLE;223 console_state[index] = CONS_IDLE; 211 224 212 225 if (active_console == KERNEL_CONSOLE) 213 226 return; 214 227 215 redraw_state( consnum);228 redraw_state(index); 216 229 vp_switch(console_vp); 217 230 } … … 227 240 } 228 241 229 /** Return x, where left <= x <= right && |a-x| ==min(|a-x|) is smallest */230 static inline int limit( int a, int left, int right)242 /** Return x, where left <= x <= right && |a-x| == min(|a-x|) is smallest */ 243 static inline int limit(size_t a, size_t left, size_t right) 231 244 { 232 245 if (a < left) 233 246 a = left; 247 234 248 if (a >= right) 235 249 a = right - 1; 250 236 251 return a; 237 252 } 238 239 int mouse_x, mouse_y;240 int btn_pressed, btn_x, btn_y;241 253 242 254 /** Handle mouse move … … 245 257 * @param dy Delta Y of mouse move 246 258 */ 247 void gcons_mouse_move( int dx, int dy)259 void gcons_mouse_move(ssize_t dx, ssize_t dy) 248 260 { 249 261 mouse_x = limit(mouse_x + dx, 0, xres); … … 273 285 /** Handle mouse click 274 286 * 275 * @param state New state ( 1-pressed, 0-depressed)276 */ 277 int gcons_mouse_btn( intstate)287 * @param state New state (true - pressed, false - depressed) 288 */ 289 int gcons_mouse_btn(bool state) 278 290 { 279 291 int conbut; … … 282 294 conbut = gcons_find_conbut(mouse_x, mouse_y); 283 295 if (conbut != -1) { 284 btn_pressed = 1;296 btn_pressed = true; 285 297 btn_x = mouse_x; 286 298 btn_y = mouse_y; … … 292 304 return -1; 293 305 294 btn_pressed = 0;306 btn_pressed = false; 295 307 296 308 conbut = gcons_find_conbut(mouse_x, mouse_y); … … 374 386 * @param data PPM data 375 387 * @param size PPM data size 388 * 376 389 * @return Pixmap identification 377 */ 378 static int make_pixmap(char *data, int size) 390 * 391 */ 392 static int make_pixmap(char *data, size_t size) 379 393 { 380 394 char *shm; … … 465 479 void gcons_init(int phone) 466 480 { 467 int rc;468 int i;469 int status_start = STATUS_START;470 471 481 fbphone = phone; 472 482 473 rc = async_req_0_2(phone, FB_GET_RESOLUTION, &xres, &yres);483 int rc = async_req_0_2(phone, FB_GET_RESOLUTION, &xres, &yres); 474 484 if (rc) 475 485 return; … … 484 494 ALIGN_DOWN(xres - 2 * CONSOLE_MARGIN, 8), 485 495 ALIGN_DOWN(yres - (CONSOLE_TOP + CONSOLE_MARGIN), 16)); 496 486 497 if (console_vp < 0) 487 498 return; 488 499 489 500 /* Create status buttons */ 490 status_start += (xres - 800) / 2; 501 size_t status_start = STATUS_START + (xres - 800) / 2; 502 size_t i; 491 503 for (i = 0; i < CONSOLE_COUNT; i++) { 492 504 cstatus_vp[i] = vp_create(status_start + CONSOLE_MARGIN + 493 505 i * (STATUS_WIDTH + STATUS_SPACE), STATUS_TOP, 494 506 STATUS_WIDTH, STATUS_HEIGHT); 507 495 508 if (cstatus_vp[i] < 0) 496 509 return; 510 497 511 vp_switch(cstatus_vp[i]); 498 512 set_rgb_color(0x202020, 0xffffff); … … 502 516 ic_pixmaps[CONS_SELECTED] = 503 517 make_pixmap(_binary_gfx_cons_selected_ppm_start, 504 ( int) &_binary_gfx_cons_selected_ppm_size);518 (size_t) &_binary_gfx_cons_selected_ppm_size); 505 519 ic_pixmaps[CONS_IDLE] = 506 520 make_pixmap(_binary_gfx_cons_idle_ppm_start, 507 ( int) &_binary_gfx_cons_idle_ppm_size);521 (size_t) &_binary_gfx_cons_idle_ppm_size); 508 522 ic_pixmaps[CONS_HAS_DATA] = 509 523 make_pixmap(_binary_gfx_cons_has_data_ppm_start, 510 ( int) &_binary_gfx_cons_has_data_ppm_size);524 (size_t) &_binary_gfx_cons_has_data_ppm_size); 511 525 ic_pixmaps[CONS_DISCONNECTED] = 512 526 make_pixmap(_binary_gfx_cons_idle_ppm_start, 513 ( int) &_binary_gfx_cons_idle_ppm_size);527 (size_t) &_binary_gfx_cons_idle_ppm_size); 514 528 ic_pixmaps[CONS_KERNEL] = 515 529 make_pixmap(_binary_gfx_cons_kernel_ppm_start, 516 ( int) &_binary_gfx_cons_kernel_ppm_size);530 (size_t) &_binary_gfx_cons_kernel_ppm_size); 517 531 ic_pixmaps[CONS_DISCONNECTED_SEL] = ic_pixmaps[CONS_SELECTED]; 518 532 519 533 make_anim(); 520 534 521 use_gcons = 1;535 use_gcons = true; 522 536 console_state[0] = CONS_DISCONNECTED_SEL; 523 537 console_state[KERNEL_CONSOLE] = CONS_KERNEL; 538 524 539 gcons_redraw_console(); 525 540 }
Note:
See TracChangeset
for help on using the changeset viewer.