Subversion Repositories Kolibri OS

Rev

Rev 9453 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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