 init_pair(5, Int16(COLOR_WHITE), Int16(COLOR_CYAN))
 
 
-var widgets = [Widget]()
-
-// newwin null check
-var gap : Int32 = 1
+//------------------------------------------------------------------------------
+// MARK: WIDGET SETUP
+//------------------------------------------------------------------------------
+
+
 func computeWidgetLength() -> Int32 {
     return Int32(floor(Double((COLS - (gap * Int32(widgets.count - 1)))) / Double(widgets.count)))
 }
 
 
-
-let  smc = SMC()
+let smc = SMC()
 if (smc.open() == kIOReturnSuccess) {
     HAS_SMC = true
-}
-
-// TODO check if laptop
-let battery = Battery()
-HAS_BATTERY = battery.isLaptop()
-battery.open()
-
-
-if (HAS_SMC) {
     widgets.append(TMPWidget(win: Window()))
     widgets.append(FanWidget(win: Window()))
 }
 
-if (HAS_BATTERY) {
+let battery = Battery()
+if (battery.isLaptop()) {
+    HAS_BATTERY = true
+    battery.open()
     widgets.append(BatteryWidget(win: Window()))
 }
 
+
 var widgetLength = computeWidgetLength()
-
-
 for var i = 0; i < widgets.count; ++i {
     widgets[i].resize(Window(size: (length: widgetLength, width: 1), pos: (x: (widgetLength + gap) * Int32(i), y: 0)))
 }
 
+
+//------------------------------------------------------------------------------
+// MARK: GCD TIMER SETUP
+//------------------------------------------------------------------------------
+
+
+dispatch_source_set_timer(source,
+                          dispatch_time(DISPATCH_TIME_NOW, 0),
+                          FREQ * NSEC_PER_SEC, 0)
 
 dispatch_source_set_event_handler(source, {
     for widget in widgets {

}



setlocale(LC_ALL, "")

// ncurses settings
initscr()                // Init window. Must be first
cbreak()

//nodelay(stdscr, true)    // Make input reads non-blocking

noecho()                 // Don't echo user input
nonl()                   // Disable newline mode
intrflush(stdscr, true) // Prevent flush
keypad(stdscr, true)     // Enable function and arrow keys
//timeout(0)
curs_set(0)              // Set cursor to invisible
//idlok(stdscr, true)
//scrollok(stdscr, true)


if (!has_colors()) {
    println("WARN: Terminal doesn't have support for colours")
}
// do custom colors check

// Init terminal colours
start_color()

    }
}

// Cleanup
smc.close()
battery.close()
