Subversion Repositories Kolibri OS

Rev

Rev 7229 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #define MEMSIZE 4096*20
  2.  
  3. //===================================================//
  4. //                                                   //
  5. //                       LIB                         //
  6. //                                                   //
  7. //===================================================//
  8.  
  9. #include "../lib/gui.h"
  10. #include "../lib/list_box.h"
  11. #include "../lib/io.h"
  12. #include "../lib/collection.h"
  13. #include "../lib/patterns/restart_process.h"
  14.  
  15. #include "../lib/mem.h"
  16.  
  17. #include "../lib/obj/libio.h"
  18. #include "../lib/obj/libimg.h"
  19. #include "../lib/obj/libini.h"
  20.  
  21. #include "../lib/patterns/libimg_load_skin.h"
  22.  
  23.  
  24. //===================================================//
  25. //                                                   //
  26. //                       DATA                        //
  27. //                                                   //
  28. //===================================================//
  29.  
  30. int current_process_id = 0;
  31. int proc_list[256];
  32. collection attached;
  33.  
  34. llist list;
  35.  
  36. proc_info Form;
  37. proc_info Process;
  38.  
  39. enum {
  40.         ATTACHEMENT_BOTTOM,
  41.         ATTACHEMENT_LEFT,
  42.         ATTACHEMENT_TOP,
  43.         ATTACHEMENT_RIGHT
  44. };
  45. int attachement = ATTACHEMENT_BOTTOM;
  46.  
  47. #define CELLW 40
  48. #define CELLH 40
  49.  
  50. dword COLOR_BG      = 0x3B3B3B;
  51. dword COLOR_MENU_BG = 0x323232;
  52. dword COLOR_OPENED  = 0x999999;
  53. dword COLOR_ACTIVE  = 0x0099FF;
  54. dword COLOR_TEXT    = 0xFFFfff;
  55.  
  56.  
  57. //===================================================//
  58. //                                                   //
  59. //                       CODE                        //
  60. //                                                   //
  61. //===================================================//
  62.  
  63. void main()
  64. {
  65.         byte btn;
  66.         load_dll(libio,  #libio_init,1);
  67.         load_dll(libimg, #libimg_init,1);
  68.         load_dll(libini, #lib_init,1);
  69.  
  70.         Libimg_LoadImage(#skin, "/sys/icons32.png");
  71.         Libimg_FillTransparent(skin.image, skin.w, skin.h, COLOR_BG);
  72.  
  73.         ini_get_int stdcall ("/sys/appicons.ini", "taskbar", "attachement", ATTACHEMENT_BOTTOM);
  74.         attachement = EAX;
  75.  
  76.         SetAttachement();
  77.         GetAttachedItems();
  78.        
  79.         GetProcessInfo(#Form, SelfInfo);
  80.         SetWindowLayerBehaviour(-1, ZPOS_DESKTOP);
  81.         SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);
  82.         loop()
  83.         {
  84.           WaitEventTimeout(50);
  85.           switch(EAX & 0xFF)
  86.           {
  87.                 case evMouse:
  88.                         if (!CheckActiveProcess(Form.ID)) break;
  89.                         mouse.get();
  90.                         if (mouse.down) {}
  91.                         //if (list.ProcessMouse()) DrawProcessList();
  92.                         break;
  93.                 case evKey:
  94.                         GetKeys();
  95.                         if (key_scancode == SCAN_CODE_ESC) {
  96.                                 RunProgram(#program_path, NULL);
  97.                                 ExitProcess();
  98.                         }
  99.                         break;
  100.                 case evButton:
  101.                         btn = GetButtonID();
  102.                         btn -= 100;
  103.                         if (btn < attached.count) RunProgram(attached.get(btn), NULL);
  104.                         else EventSetActiveProcess(btn);
  105.                         break;
  106.                 case evReDraw:
  107.                         DefineUnDragableWindow(NULL, NULL, NULL, NULL);
  108.                         list.SetSizes(0, 0, Form.width+1, Form.height+2, CELLH);
  109.                 default:
  110.                         DrawProcessList();
  111.           }
  112.         }
  113. }
  114.  
  115.  
  116. void GetProcessList()
  117. {
  118.         int i, j;
  119.         list.count=0;
  120.  
  121.         for (i=0; i<attached.count; i++)
  122.         {
  123.                 proc_list[list.count] = 0;
  124.                 list.count++;
  125.         }
  126.  
  127.         for (i=0; i<MAX_PROCESS_COUNT; i++)
  128.         {
  129.                 GetProcessInfo(#Process, i);
  130.                 if (Process.name)
  131.                 {
  132.                         for (j=0; j<11; j++) if (Process.name[j]!=' ') {                               
  133.                                 //do not show system process
  134.                                 if (Process.name[0]=='@') break;
  135.                                 if (!strcmp(#Process.name, "IDLE")) break;
  136.                                 if (!strcmp(#Process.name, "OS")) break;
  137.                                 if (!Process.width) && (!Process.height) break;
  138.                                 proc_list[list.count] = i;
  139.                                 list.count++;
  140.                                 break;
  141.                         }
  142.                 }
  143.         }
  144. }
  145.  
  146. void DrawProcessList()
  147. {
  148.         #define ACTIVE_SIZE 3
  149.         #define CELL_MARGIN_X 10
  150.         #define CELL_MARGIN_Y 4
  151.         #define CELL_PADDING 4
  152.         int i;
  153.         int posy=list.y;
  154.         int posx=list.x;
  155.         int icon_n;
  156.         dword status_color;
  157.  
  158.         GetProcessList();
  159.  
  160.         for (i=0; i<list.count; i++)
  161.         {
  162.                 if (proc_list[i+list.first]==0) {
  163.                         status_color = COLOR_BG;
  164.                         ini_get_int stdcall (
  165.                                 "/sys/appicons.ini",
  166.                                 "icons",
  167.                                 attached.get(i+list.first)+strrchr(attached.get(i+list.first),'/'),
  168.                                 0
  169.                                 );
  170.                         icon_n = EAX;
  171.                 }
  172.                 else {
  173.                         GetProcessInfo(#Process, proc_list[i+list.first]);
  174.                         strlwr(#Process.name);
  175.                         ini_get_int stdcall ("/sys/appicons.ini", "icons", #Process.name, 0);
  176.                         icon_n = EAX;
  177.                         if (CheckActiveProcess(Process.ID)) && (Process.status_window!=2) {
  178.                                 current_process_id = Process.ID;
  179.                                 status_color = COLOR_ACTIVE;
  180.                         }
  181.                         else {
  182.                                 status_color = COLOR_OPENED;
  183.                         }                      
  184.                 }
  185.                 DrawWideRectangle(posx, posy, 40, 40, CELL_PADDING, COLOR_BG);
  186.                 DefineButton(posx, posy, CELLW-1, CELLH, 100+i+BT_HIDE+BT_NOFRAME, NULL);
  187.                 img_draw stdcall(skin.image, posx+CELL_PADDING, posy+CELL_PADDING, 32, 32, 0, 32*icon_n);
  188.  
  189.                 if (ATTACHEMENT_BOTTOM==attachement) DrawBar(posx, posy+CELLH-ACTIVE_SIZE, CELLW, ACTIVE_SIZE, status_color);
  190.                 if (ATTACHEMENT_LEFT  ==attachement) DrawBar(posx, posy, ACTIVE_SIZE, CELLH, status_color);
  191.                 if (ATTACHEMENT_TOP   ==attachement) DrawBar(posx, posy, CELLW, ACTIVE_SIZE, status_color);
  192.                 if (ATTACHEMENT_RIGHT ==attachement) DrawBar(posx+CELLW-ACTIVE_SIZE, posy, ACTIVE_SIZE, CELLH, status_color);
  193.  
  194.                 if (ATTACHEMENT_TOP==attachement) || (ATTACHEMENT_BOTTOM==attachement) {
  195.                         posx += CELLW;
  196.                         DrawBar(posx, posy, CELL_MARGIN_X, list.h, COLOR_BG);
  197.                         posx += CELL_MARGIN_X;
  198.                 }
  199.                 if (ATTACHEMENT_LEFT==attachement) || (ATTACHEMENT_RIGHT==attachement) {
  200.                         posy += CELLH;
  201.                         DrawBar(posx, posy, list.w, CELL_MARGIN_Y, COLOR_BG);
  202.                         posy += CELL_MARGIN_Y;
  203.                 }
  204.         }
  205.         DrawBar(posx, posy, list.w, list.h, COLOR_BG);
  206. }
  207.  
  208. void SetAttachement()
  209. {
  210.         if (attachement==ATTACHEMENT_LEFT) {
  211.                 DefineUnDragableWindow(0, 0, CELLW-1, screen.height);
  212.                 SetClientScreenArea(CELLW, screen.width-CELLW, 0, screen.height);
  213.         }
  214.         if (attachement==ATTACHEMENT_RIGHT) {
  215.                 DefineUnDragableWindow(screen.width - CELLW, 0, CELLW, screen.height);
  216.                 SetClientScreenArea(0, screen.width-CELLW, 0, screen.height);
  217.         }
  218.         if (attachement==ATTACHEMENT_TOP) {
  219.                 DefineUnDragableWindow(0, 0, screen.width, CELLH-1);
  220.                 SetClientScreenArea(0, 0, CELLH, screen.height);
  221.         }
  222.         if (attachement==ATTACHEMENT_BOTTOM) {
  223.                 DefineUnDragableWindow(0, screen.height, screen.width, CELLH);
  224.                 SetClientScreenArea(0, 0, 0, screen.height - CELLH);
  225.         }
  226. }
  227.  
  228. byte draw_icons_from_section(dword key_value, key_name, sec_name, f_name)
  229. {
  230.         attached.add(key_name);
  231.         return true;
  232. }
  233.  
  234. void GetAttachedItems()
  235. {
  236.         attached.drop();
  237.         ini_enum_keys stdcall ("/sys/appicons.ini", "attached", #draw_icons_from_section);
  238. }
  239. //===================================================//
  240. //                                                   //
  241. //                      EVENTS                       //
  242. //                                                   //
  243. //===================================================//
  244.  
  245. //If we clicked on current active process then minimize it
  246. //else set active
  247. void EventSetActiveProcess(dword i)
  248. {
  249.         GetProcessInfo(#Process, proc_list[i+list.first]);
  250.         Process.num_slot = GetProcessSlot(Process.ID);
  251.         if (Process.ID) ActivateWindow(Process.num_slot);
  252.         if (current_process_id == Process.ID) && (Process.status_window!=2) {
  253.                 MinimizeWindow();
  254.                 //TODO: make another window active
  255.         }
  256.         DrawProcessList();
  257. }
  258.  
  259.  
  260. stop: