system.lua 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. --@author cedlemo
  2. local table = table
  3. local awful = require("awful")
  4. local superproperties = require('blingbling.superproperties')
  5. ---launchers for reboot, shutdown, shutdown, logout or lock menus for your system.
  6. --@module blingbling.system
  7. local system = {}
  8. local shutdown_cmd= 'systemctl poweroff'
  9. local reboot_cmd='systemctl reboot'
  10. local lock_cmd='xscreensaver-command -lock'
  11. ---Main menu launcher.
  12. --Create a button which will spawn a menu allowing the user to shutdown, reboot, logout and lock screen
  13. --Only the first parameter is mandatory. The other values can be nil and specified in the theme.lua via the theme.blingbling table. See the superproperties module documentation.
  14. --@usage mymainmenu = system.mainmenu(main_image, shutdown_image, reboot_image, logout_image, lock_image)
  15. --@param main_image the image that will be displayed with the shutdown option
  16. --@param shutdown_image the image that will be displayed with the shutdown option
  17. --@param reboot_image the image that will be displayed with the reboot option
  18. --@param logout_image the image that will be displayed with the logout option
  19. --@param lock_image the image that will be displayed with the lock option
  20. function system.mainmenu(main_image, shutdown_image, reboot_image, logout_image, lock_image)
  21. if not shutdown_image then
  22. shutdown_image = superproperties.shutdown or nil
  23. end
  24. if not reboot_image then
  25. reboot_image = superproperties.reboot or nil
  26. end
  27. if not logout_image then
  28. logout_image = superproperties.logout or nil
  29. end
  30. if not lock_image then
  31. lock_image = nil
  32. end
  33. powermenu = awful.menu({ items = {
  34. { "Shutdown", shutdown_cmd, shutdown_image },
  35. { "Reboot", reboot_cmd, reboot_image },
  36. { "Logout", function() awesome.quit() end, logout_image },
  37. { "Lock", lock_cmd, lock_image }
  38. }
  39. })
  40. return awful.widget.launcher({ image = main_image,
  41. menu = powermenu })
  42. end
  43. ---Shutdown menu launcher.
  44. --Create a button with an accept/cancel menu for shutdown the system
  45. --No mandatory parameter. All values can be nil and specified in the theme.lua via the theme.blingbling table. See the superproperties module documentation.
  46. --@usage shutdown=blingbling.system.shutdownmenu(launcher_image, menu_dialog_image_ok, menu_.dialog_image_cancel)
  47. --@param button_image an image file that will be displayed in the wibox
  48. --@param accept_image an image file for the accept menu entry
  49. --@param cancel_image an image file for the cancel menu entry
  50. function system.shutdownmenu(button_image, accept_image, cancel_image)
  51. if not button_image then
  52. button_image = superproperties.shutdown or nil
  53. end
  54. if not accept_image then
  55. accept_image = superproperties.accept or nil
  56. end
  57. if not cancel_image then
  58. cancel_image = superproperties.cancel or nil
  59. end
  60. shutdownmenu = awful.menu({ items = {
  61. { "Shutdown", shutdown_cmd, accept_image },
  62. { "Cancel", "", cancel_image }
  63. }
  64. })
  65. shutdownbutton = awful.widget.launcher({ image = button_image,
  66. menu = shutdownmenu })
  67. return shutdownbutton
  68. end
  69. ---Lock menu launcher.
  70. --Create a button with an accept/cancel menu for locking the system:
  71. --No mandatory parameter. All values can be nil and specified in the theme.lua via the theme.blingbling table. See the superproperties module documentation.
  72. --@usage shutdown=blingbling.system.lockmenu(launcher_image, menu_dialog_image_ok, menu_.dialog_image_cancel)
  73. --@param button_image an image file that will be displayed in the wibox
  74. --@param accept_image an image file for the accept menu entry
  75. --@param cancel_image an image file for the cancel menu entry
  76. function system.lockmenu(button_image, accept_image, cancel_image)
  77. if not button_image then
  78. button_image = superproperties.lock or nil
  79. end
  80. if not accept_image then
  81. accept_image = superproperties.accept or nil
  82. end
  83. if not cancel_image then
  84. cancel_image = superproperties.cancel or nil
  85. end
  86. shutdownmenu = awful.menu({ items = {
  87. { "Lock", lock_cmd, accept_image },
  88. { "Cancel", "", cancel_image }
  89. }
  90. })
  91. shutdownbutton = awful.widget.launcher({ image = button_image,
  92. menu = shutdownmenu })
  93. return shutdownbutton
  94. end
  95. ---Reboot menu launcher.
  96. --Create a button with an accept/cancel menu for reboot the system:
  97. --No mandatory parameter. All values can be nil and specified in the theme.lua via the theme.blingbling table. See the superproperties module documentation.
  98. --@usage reboot=blingbling.system.rebootmenu(launcher_image, menu_dialog_image_ok, menu_.dialog_image_cancel)
  99. --@param button_image an image file that will be displayed in the wibox
  100. --@param accept_image an image file for the accept menu entry
  101. --@param cancel_image an image file for the cancel menu entry
  102. function system.rebootmenu(button_image, accept_image, cancel_image)
  103. if not button_image then
  104. button_image = superproperties.reboot or nil
  105. end
  106. if not accept_image then
  107. accept_image = superproperties.accept or nil
  108. end
  109. if not cancel_image then
  110. cancel_image = superproperties.cancel or nil
  111. end
  112. rebootmenu = awful.menu({ items = {
  113. { "Reboot", reboot_cmd, accept_image },
  114. { "Cancel", "" , cancel_image}
  115. }
  116. })
  117. rebootbutton = awful.widget.launcher({ image = button_image,
  118. menu = rebootmenu })
  119. return rebootbutton
  120. end
  121. ---Logout menu launcher.
  122. --Create a button with an accept/cancel menu for reboot the system:
  123. --No mandatory parameter. All values can be nil and specified in the theme.lua via the theme.blingbling table. See the superproperties module documentation.
  124. --@usage logout=blingbling.system.logouttmenu(launcher_image, menu_dialog_image_ok, menu_.dialog_image_cancel)
  125. --@param button_image an image file that will be displayed in the wibox
  126. --@param accept_image an image file for the accept menu entry
  127. --@param cancel_image an image file for the cancel menu entry
  128. function system.logoutmenu(button_image, accept_image, cancel_image)
  129. if not buttom_image then
  130. button_image = superproperties.logout or nil
  131. end
  132. if not accept_image then
  133. accept_image = superproperties.accept or nil
  134. end
  135. if not cancel_image then
  136. cancel_image = superproperties.cancel or nil
  137. end
  138. logoutmenu = awful.menu({ items = {
  139. { "Logout", awesome.quit, accept_image },
  140. { "Cancel", "" , cancel_image}
  141. }
  142. })
  143. logoutbutton = awful.widget.launcher({ image = button_image,
  144. menu = logoutmenu })
  145. return logoutbutton
  146. end
  147. return system